update uart device

develop
esea_info 2 years ago
parent 7ce92a9ae6
commit 6869cb71fa
  1. 9
      bsp/Src/bsp_uart.c
  2. 366
      device/Inc/Ramses.h
  3. 354
      device/Inc/oscar.h
  4. 288
      device/Inc/sc6.h
  5. 165
      device/Inc/temperature.h
  6. 365
      device/Inc/viper.h
  7. 257
      device/Inc/wh_lte_7s4_v2.h
  8. 134
      device/Inc/wh_lte_7s4_v2_2.h
  9. 15
      device/Inc/wk2114.h
  10. 346
      device/Inc/wk2xxx.h
  11. 1022
      device/Src/Ramses.c
  12. 1
      device/Src/bsp_i2c_soft.c
  13. 1108
      device/Src/oscar.c
  14. 18
      device/Src/pH.c
  15. 279
      device/Src/ramses_utils.c
  16. 749
      device/Src/sc6.c
  17. 407
      device/Src/temperature.c
  18. 1095
      device/Src/viper.c
  19. 1462
      device/Src/wh_lte_7s4_v2.c
  20. 737
      device/Src/wh_lte_7s4_v2_2.c
  21. 301
      device/Src/wh_lte_utils.c
  22. 4
      device/Src/wk2114.c
  23. 870
      device/Src/wk2xxx.c

@ -123,7 +123,7 @@ int UART_HELPER_Start_Rcv(UART_HELPER_TypeDef * uarthelper, uint8_t *buf, uint16
/* 会出现 st ==2 huart->gState != HAL_UART_STATE_READY */
if (uarthelper->enable_idle_it == 1)
{
// log_i("dma rcv idle en... ");
// log_d("dma rcv idle en... ");
__HAL_UART_ENABLE_IT(uarthelper->huart, UART_IT_IDLE);
}
st = HAL_UART_Receive_DMA(uarthelper->huart, buf, size);
@ -169,7 +169,7 @@ int UART_HELPER_Trans(UART_HELPER_TypeDef * uarthelper, uint8_t *buf, uint16_t s
int UART_HELPER_Trans_TxCplt_Callback( UART_HELPER_TypeDef * uarthelper )
{
// log_i( " uarthelper tc callback...........");
// log_d( " uarthelper tc callback...........");
uarthelper->transferring = 0;
if (uarthelper->enable_trans_cplt_gpio != NULL)
{
@ -204,9 +204,10 @@ int UART_HELPER_RCV_IDLE_Callback( UART_HELPER_TypeDef * uarthelper, uint16_t si
// {
// HAL_UART_DMAStop( uarthelper->huart );
// }
// 包含停止DMA 开始新的接收
HAL_UART_DMAStop( uarthelper->huart );
uarthelper->callback( uarthelper->obj, uarthelper->rcv_buf, size);
UART_HELPER_Start_Rcv(uarthelper, uarthelper->rcv_buf, uarthelper->rcv_size);
return 0;
}
}

@ -1,20 +1,31 @@
/**
* @file Ramses.h
* @author Esea (info@eseaoptics.com)
* @brief Ramses
* @version 1.0
* @date 2023-08-27
*
* @copyright ESEA (c) 2020
*
*/
#ifndef TRIOS_REMSES_H_
#define TRIOS_REMSES_H_
#include <stddef.h>
#include <stdint.h>
/*
*/
#ifndef __RAMSES__H
#define __RAMSES__H
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include "elog.h"
#include <string.h>
#include "uart_helper.h"
#include "uart_interface.h"
#include "bsp_uart.h"
static void Ramses_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
#define Ramses_CMD_SIZE (8)
#define Ramses_DATA_SIZE (64+8)
@ -34,15 +45,19 @@ typedef int (*Ramses_send_fun)(void *send_class,uint8_t *buf,uint32_t size);
typedef enum
{
MODULE_RAMSESE_STATE_WAIT,
MODULE_RAMSESE_STATE_START,
MODULE_RAMSESE_STATE_SEND_CMD,
MODULE_RAMSESE_STATE_CHECK_SENSOR,
MODULE_RAMSESE_STATE_GET_DATA,
MODULE_RAMSESE_STATE_OK,
MODULE_RAMSESE_STATE_ERROR,
MODULE_RAMSESE_STATE_STOP
} MODULE_RAMSESE_WORK_STATE;
MODULE_RAMSES_STATE_WAIT,
MODULE_RAMSES_STATE_TEST,
MODULE_RAMSES_STATE_TESTING,
MODULE_RAMSES_STATE_TEST_OK,
MODULE_RAMSES_STATE_READY,
MODULE_RAMSES_STATE_START,
MODULE_RAMSES_STATE_SEND_CMD,
MODULE_RAMSES_STATE_CHECK_SENSOR,
MODULE_RAMSES_STATE_GET_DATA,
MODULE_RAMSES_STATE_OK,
MODULE_RAMSES_STATE_ERROR,
MODULE_RAMSES_STATE_STOP
} MODULE_RAMSES_WORK_STATE;
enum trios_integration_time{
TRIOS_INTEGRATION_TIME_AUTO,
@ -59,7 +74,8 @@ enum trios_integration_time{
TRIOS_INTEGRATION_TIME_4096MS,
TRIOS_INTEGRATION_TIME_8192MS
};
struct Ramses_data
typedef struct Ramses_data
{
uint16_t dev_id;
uint8_t module_id;
@ -67,8 +83,9 @@ struct Ramses_data
uint8_t data_size;
uint8_t *data;
uint8_t raw[Ramses_DATA_SIZE];
};
struct Ramses_ip
}RAMSES_Data_TypeDef;
typedef struct Ramses_ip
{
uint16_t dev_id;
uint8_t module_id;
@ -76,188 +93,175 @@ struct Ramses_ip
uint8_t data_size;
uint8_t *data;
uint8_t raw[Ramses_IP_SIZE];
};
}RAMSES_IP_TypeDef;
struct Ramses_infomation
typedef struct Ramses_infomation
{
uint16_t dev_id;
uint8_t module_id;
uint16_t serial_number;
uint8_t firmware_number[2];
uint8_t individual_information[Ramses_INFO_SIZE-8];
};
}RAMSES_Info_TypeDef;
typedef struct trios_ramses
typedef enum
{
// UartHelper_TypeDef *uarthelper;
volatile MODULE_RAMSESE_WORK_STATE state;
volatile uint8_t send_flag; /* 发送标志位 */
volatile Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
volatile uint8_t step; /* 0 : normal , 1 : get wavelength , 2 : get sn 3: 空*/
// volatile uint8_t command_seq ; /* 命令序号 */
uint8_t flag;
uint8_t flag_ip;
uint8_t data_index;
uint8_t recv_buf_p;
uint8_t data_size;
uint8_t recv_flag_40;
uint8_t cmd_buf[Ramses_CMD_SIZE];
struct Ramses_infomation infomation;
struct Ramses_ip ip;
struct Ramses_data data[Ramses_DATA_NUM];
uint8_t recv_buf[Ramses_DATA_SIZE];
uint16_t sn;
uint8_t error;
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint64_t timeout_ms;
uint64_t timeout_enable;
void *send_class;
Ramses_send_fun send_fun;
}Ramses_TypeDef;
extern Ramses_TypeDef *ramses ;
Ramses_Event_Ready ,
Ramses_Event_Test,
Ramses_Event_Test_OK ,
Ramses_Event_Get_Data,
Ramses_Event_Check_Data ,
} Module_Ramses_Event_TypeDef;
// typedef enum
// {
// Ramses_State_Waiting ,
// Ramses_State_Test ,
// Ramses_State_Test_Start ,
// Ramses_State_SN_Getting ,
// Ramses_State_SN_OK ,
// Ramses_State_Ready ,
// Ramses_State_Get_WAVELENGTH ,
// // Ramses_State_Get_WAVELENGTH_Wait ,
// // Ramses_State_Get_WAVELENGTH_OK,
// // Ramses_State_Get_WAVELENGTH_Check ,
// Ramses_State_Get_DATA ,
// Ramses_State_Get_DATA_Trans,
// Ramses_State_Get_DATA_Wait ,
// Ramses_State_Get_DATA_OK,
// Ramses_State_Get_DATA_Check ,
// Ramses_State_Get_Queue_MSG ,
// Ramses_State_Stop ,
// Ramses_State_Timeout ,
// Ramses_State_Error ,
// } Module_Ramses_State_TypeDef;
static inline void Ramses_clean_data_recved_flag(Ramses_TypeDef *ramses)
{
ramses->flag&=~Ramses_FLAG_MASK_RECVED_DATA;
}
static inline void Ramses_clean_ip_recved_flag(Ramses_TypeDef *ramses)
{
ramses->flag&=~Ramses_FLAG_MASK_RECVED_IP;
}
static inline void Ramses_clean_info_recved_flag(Ramses_TypeDef *ramses)
{
ramses->flag&=~Ramses_FLAG_MASK_RECVED_INFO;
}
int Ramses_init( );
int Ramses_send_cmd(Ramses_TypeDef *ramses,uint16_t dev_id,uint8_t module_id,uint8_t instruction,uint8_t parameter1,uint8_t parameter2);
int Ramses_cmd_messung(Ramses_TypeDef *ramses,uint8_t module_id);
int Ramses_cmd_set_integration_time(Ramses_TypeDef *ramses,enum trios_integration_time integration_time);
int Ramses_cmd_get_infomation(Ramses_TypeDef *ramses,uint8_t module_id);
uint32_t Ramses_get_ip_raw(Ramses_TypeDef *ramses,uint8_t *buf,uint32_t size);
uint32_t Ramses_get_data_raw(Ramses_TypeDef *ramses,uint8_t *buf,uint32_t size);
uint32_t Ramses_get_data(Ramses_TypeDef *ramses,int16_t *data,uint32_t num);
double Ramses_get_x_inclination_angle(Ramses_TypeDef *ramses,double incl_xgain,double incl_xoffset);
double Ramses_get_y_inclination_angle(Ramses_TypeDef *ramses,double incl_ygain,double incl_yoffset);
double Ramses_get_inclination_angle(double x_inclination_angle,double y_inclination_angle);
double Ramses_get_pressure(Ramses_TypeDef *ramses,double incl_kref,double incl_kbg,double press_gain,double press_surface_bar,double press_sens_mv_bar_1ma,double press_sens_mv_bar_4ma);
double Ramses_get_depth_m(double pressure);
uint16_t Ramses_get_serial_number(Ramses_TypeDef *ramses);
void Ramses_receive_callback(Ramses_TypeDef *ramses,uint8_t *buf,uint32_t size);
void Ramses_clean_flag(Ramses_TypeDef *ramses,uint8_t mask);
uint8_t Ramses_get_flag(Ramses_TypeDef *ramses,uint8_t mask);
void Ramses_Set_Timeout(Ramses_TypeDef *ramses, uint16_t timeout_ms );
int Ramses_Get_Timeout( Ramses_TypeDef *ramses );
void Ramses_Set_Sendbuf( Ramses_TypeDef *ramses, uint8_t * buf, uint16_t size );
void Ramses_Set_Rcvbuf( Ramses_TypeDef *ramses, uint8_t * buf, uint16_t size );
void Ramses_Set_State (Ramses_TypeDef *ramses, MODULE_RAMSESE_WORK_STATE state);
// void Ramses_Setup ();
void Ramses_Port ();
void Ramses_Task(void * argument);
int Ramses_copy(Ramses_TypeDef *ramses ,uint16_t size);
/* 再封装演示 */
typedef struct
{
uint8_t (*init)( );
uint8_t (*port)(void);
GPIO_TypeDef *sel_gpio;
GPIO_TypeDef *dplx_gpio;
GPIO_TypeDef *de_gpio;
uint16_t sel_pin;
uint16_t dplx_pin;
uint16_t de_pin;
Uart_Interface_Type_Typedef interface_type; /* 0: common, 1: 485 ,2:3160*/
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲/
SC6_TypeDef *sample; /*不是常量 不能直接初始化*/
}My_Ramses_TypeDef;
extern My_Ramses_TypeDef myramses ;
#endif
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
osMessageQueueId_t transQueue; // 队列可选
volatile MODULE_RAMSES_WORK_STATE state;
uint8_t data_ok; /* 接收数据完整可以处理 */
uint8_t result_buf[1024];
uint16_t size_received;
volatile uint8_t flag;
volatile uint8_t flag_ip;
volatile uint8_t data_index;
volatile uint8_t recv_buf_p;
volatile uint8_t data_size;
volatile uint8_t recv_flag_40;
uint8_t cmd_buf[Ramses_CMD_SIZE];
RAMSES_Info_TypeDef information;
RAMSES_IP_TypeDef ip;
RAMSES_Data_TypeDef data[Ramses_DATA_NUM];
uint8_t recv_buf[Ramses_DATA_SIZE]; // 每帧的数据
uint16_t sn;
uint8_t error;
uint64_t timebase_ticks;
uint64_t timeout_ticks;
// typedef struct
// {
// UartHelper_TypeDef *uarthelper;
// UART_HandleTypeDef *huart;
// uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/
// uint8_t mode_232_485; /* 0: common, 1: 485 */
// uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/
// uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/
// uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */
// uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
}Ramses_TypeDef;
// uint8_t *send_buf;
// uint16_t size_send;
// uint8_t *rcv_buf;
// uint16_t size_rcv;
extern UART_HELPER_TypeDef *Ramses_uart_helper;
extern Ramses_TypeDef ramses ;
// volatile uint8_t send_flag; /* 发送标志位 */
// Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
// Uart_Status_TypeDef status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
int Ramses_Init( void );
void Ramses_Port( void);
void Ramses_Task( void *arg);
int Ramses_Test( );
void Ramses_Start( );
void Ramses_Stop( );
// uint8_t command_seq ; /* 命令序号 */
// uint8_t mode; /* 0 : normal , 1 : get wavelength , 2 : get sn */
void Ramses_Set_Sendbuf( uint8_t * buf, uint16_t size );
void Ramses_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void Ramses_Set_Timeout_ms( uint64_t ms_ticks );
int Ramses_Validate( );
// uint8_t result_Buf[SC6_Rcv_Buf_Size];
// uint8_t SC6_Data_Buf[SC6_Rcv_Buf_Size*2];
// uint8_t SC6_Raw_Buf[SC6_Rcv_Buf_Size*3];
// uint8_t *data_start_tag;
// uint8_t *data_end_tag;
int Ramses_Transmit();
int Ramses_Receive();
// uint8_t start_cmd_valid ;
// uint8_t stop_cmd_valid ;
// uint8_t *start_cmd_buf;
// uint8_t *stop_cmd_buf;
void Ramses_Trans_GPIO(void) ;
// uint8_t rcv_ok; /* 接收数据完整可以处理 */
// uint8_t data_begin_flag; /* 接收数据完整可以处理 */
// uint8_t data_ok; /* 接收数据完整可以处理 */
// uint16_t size_received;
void Ramses_Trans_Cplt_GPIO(void) ;
int Ramses_CallBack( Ramses_TypeDef *pRamses , uint8_t *buf, uint16_t size );
// uint32_t timebase;
// uint16_t timeout_ms;
#ifdef __cplusplus
}
#endif
#endif
// uint8_t (*Init)(void); //初始化触摸屏控制器
// // uint8_t (*Setup)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标;
// uint8_t (*Port)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标;
// }SC6_TypeDef;
/*
temp.init();
temp.port();
temp.test();
uint64_t ticks = osKernelGetTickCount();
while ( temp.state != PH_State_Ready )
{
if ( ( osKernelGetTickCount() -ticks) > 3000 )
{
log_e(" pH test error.... ") ;
break;
}
}
log_w(" pH test ok.... ") ;
// osMessageQueueId_t TestQQueueueueHandle;
// osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
// osMessageQueueGet(TestQueueHandle,osWaitForever);
// osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id,
// void * msg_ptr, //储存读取结果的变量地址
// uint8_t * msg_prio, // ==NULL
// uint32_t timeout //阻塞超时时间
// );
// osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id,
// const void * msg_ptr, //储存写入内容的变量地址
// uint8_t msg_prio, //==0U
// uint32_t timeout //阻塞超时时间
// );
// uint8_t Ramses_SN_command[8] = {0x01, 0x03, 0x00, 0x0A, 0x00, 0x05, 0xA5, 0xCB};
// uint8_t Ramses_Wavelength_sendbuf[3][8] = {
//
// // 01 03 08 36 00 7A 26 47 (2102 122)
// // 01 03 08 B0 00 7A C7 AE (2224 122)
// // 01 03 09 2A 00 7A E6 7D (2346 122)
//
// { 0x01, 0x03, 0x08, 0x36, 0x00, 0x7A, 0x26, 0x47 },
// { 0x01, 0x03, 0x08, 0xB0, 0x00, 0x7A, 0xC7, 0xAE },
// { 0x01, 0x03, 0x09, 0x2A, 0x00, 0x7A, 0xE6, 0x7D }
// };
// uint8_t Ramses_Data_sendbuf[3][8] = {
//
// //01 03 0A 36 00 7A 27 FF (2614 122)
// //01 03 0A B0 00 7A C6 16 (2736 122)
// //01 03 0B 2A 00 7A E7 C5 (2858 122)
//
// { 0x01, 0x03, 0x0A, 0x36, 0x00, 0x7A, 0x27, 0xFF },
// { 0x01, 0x03, 0x0A, 0xB0, 0x00, 0x7A, 0xC6, 0x16 },
// { 0x01, 0x03, 0x0B, 0x2A, 0x00, 0x7A, 0xE7, 0xC5 }
// };
// uint8_t Ramses_sn_buf[15] = {0};
*/

@ -1,228 +1,190 @@
#ifndef __Oscar_H
#define __Oscar_H
/*
*/
#ifndef __OSCAR__H
#define __OSCAR__H
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include "uart_helper.h"
#include "uart_interface.h"
// #include "config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include "elog.h"
#define Oscar_DEMO 1 /*sn 读取位置不一样*/
#define Oscar_Rcv_Buf_Size (3+244+2)
#define Oscar_Command_Number 2
#define Oscar_FLAG_MASK_BUSY ((uint32_t)1<<(uint32_t)0)
#define Oscar_FLAG_MASK_RECVED_SN ((uint32_t)1<<(uint32_t)1)
#define Oscar_FLAG_MASK_RECVED_WL ((uint32_t)1<<(uint32_t)2)
#define Oscar_FLAG_MASK_RECVED_DATA ((uint32_t)1<<(uint32_t)3)
// #define Oscar_FLAG_MASK_RECVED_WL_1 ((uint32_t)1<<(uint32_t)3)
// #define Oscar_FLAG_MASK_RECVED_DATA_0 ((uint32_t)1<<(uint32_t)4)
// #define Oscar_FLAG_MASK_RECVED_DATA_1 ((uint32_t)1<<(uint32_t)5)
#include <string.h>
#include "bsp_uart.h"
#define Oscar_USE_MAX485 0
#define Oscar_USE_MAX3160_232 0
#define Oscar_USE_MAX3160_485 1
#define Oscar_Rcv_Buf_Size (3+244+2)
// #define Oscar_Command_Number 1
static void Oscar_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
typedef enum
{
MODULE_Oscar_STATE_WAIT,
MODULE_Oscar_STATE_START,
MODULE_Oscar_STATE_GET_SN,
MODULE_Oscar_STATE_CHECK_SN,
MODULE_Oscar_STATE_GET_WL_0,
MODULE_Oscar_STATE_GET_WL_1,
MODULE_Oscar_STATE_CHECK_WL,
MODULE_Oscar_STATE_Ready_GET_DATA,
MODULE_Oscar_STATE_START_DATA,
MODULE_Oscar_STATE_GET_DATA_0,
MODULE_Oscar_STATE_GET_DATA_1,
MODULE_Oscar_STATE_CHECK_DATA,
MODULE_Oscar_STATE_OK,
MODULE_Oscar_STATE_ERROR,
MODULE_Oscar_STATE_STOP
} MODULE_Oscar_WORK_STATE;
Oscar_Event_Ready ,
Oscar_Event_Test,
Oscar_Event_Test_OK ,
Oscar_Event_Get_Data,
Oscar_Event_Check_Data ,
} Module_Oscar_Event_TypeDef;
typedef enum
{
Oscar_State_Waiting ,
Oscar_State_Test ,
Oscar_State_Test_Start ,
Oscar_State_SN_Getting ,
Oscar_State_SN_OK ,
Oscar_State_Ready ,
Oscar_State_Get_WAVELENGTH ,
// Oscar_State_Get_WAVELENGTH_Wait ,
// Oscar_State_Get_WAVELENGTH_OK,
// Oscar_State_Get_WAVELENGTH_Check ,
Oscar_State_Get_DATA ,
Oscar_State_Get_DATA_Trans,
Oscar_State_Get_DATA_Wait ,
Oscar_State_Get_DATA_OK,
Oscar_State_Get_DATA_Check ,
Oscar_State_Get_Queue_MSG ,
Oscar_State_Stop ,
Oscar_State_Timeout ,
Oscar_State_Error ,
} Module_Oscar_State_TypeDef;
extern UART_HELPER_TypeDef *Oscar_uart_helper;
typedef struct
{
UartHelper_TypeDef *uarthelper;
volatile MODULE_Oscar_WORK_STATE state;
volatile uint8_t flag; /* Oscar_FLAG_MASK_ SN WL1 WL2 DATA1 DATA2 ,*/
volatile uint8_t send_flag; /* 发送标志位 */
volatile Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/
uint8_t *send_buf;
uint16_t size_send;
uint8_t *rcv_buf;
uint16_t size_rcv;
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
uint8_t mode_232_485; /* 0: common, 1: 485 */
uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
osMessageQueueId_t transQueue; // 队列可选
volatile uint8_t step; /* 0 : normal , 1 : get wavelength , 2 : get sn 3: 空*/
volatile uint8_t command_seq ; /* 命令序号 */
uint16_t sn;
uint8_t sn_buf[15];
uint8_t Oscar_Wavelength_Buf[2][ Oscar_Rcv_Buf_Size ];
uint8_t Oscar_Data_Buf[2][ Oscar_Rcv_Buf_Size ];
// uint8_t rcv_ok; /* 接收数据完整可以处理 */
// uint8_t data_begin_flag; /* 接收数据完整可以处理 */
uint8_t error; /* 接收数据完整可以处理 */
volatile Module_Oscar_State_TypeDef state;
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint64_t timeout_ms;
uint64_t timeout_enable;
}Oscar_TypeDef;
uint8_t result_buf[1024];
uint16_t size_received;
extern Oscar_TypeDef *oscar ;
uint8_t Oscar_Init( );
void Oscar_Set_Uarthelper(Oscar_TypeDef *oscar, UartHelper_TypeDef *uarthelper);
void Oscar_Set_Interface(Oscar_TypeDef *oscar, UartInterface_TypeDef *interface);
void Oscar_Set_Huart( Oscar_TypeDef * oscar, UART_HandleTypeDef * huart );
void Oscar_Set_RsMode_232_485( Oscar_TypeDef * oscar, Uart_RS_Mode_TypeDef rs_232_485 );
void Oscar_Set_Trans_Type( Oscar_TypeDef *oscar, Uart_Transmode_TypeDef trans_type );
void Oscar_Set_Rcv_Type( Oscar_TypeDef *oscar, Uart_Transmode_TypeDef rcv_type );
void Oscar_Set_Idle_Enable( Oscar_TypeDef *oscar, Uart_IDLE_Enable_TypeDef idle_enable_disable );
void Oscar_Set_TransMode( Oscar_TypeDef *oscar, Uart_Transmode_TypeDef trans_mode );
void Oscar_Set_Timeout( Oscar_TypeDef *oscar, uint16_t timeout_ms );
void Oscar_Set_Sendbuf( Oscar_TypeDef *oscar, uint8_t * buf, uint16_t size );
void Oscar_Set_Rcvbuf( Oscar_TypeDef *oscar, uint8_t * buf, uint16_t size );
uint64_t timebase_ticks;
uint64_t timeout_ticks;
uint8_t event_flag;
uint8_t wavelength_ok;
Record_Trans_Rcv_TypeDef transRecord[3];
uint8_t oscarsn_buf[15];
uint8_t Oscar_Wavelength_Buf[3][ Oscar_Rcv_Buf_Size ];
uint8_t Oscar_Data_Buf[3][ Oscar_Rcv_Buf_Size ];
}Oscar_TypeDef;
void Oscar_Set_Timeout( Oscar_TypeDef * oscar, uint16_t timeout_ms );
extern Oscar_TypeDef oscar ;
// void Oscar_Set_Sendbuf( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
// void Oscar_Set_Rcvbuf( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
int Oscar_Init( void );
void Oscar_Task( void);
void Oscar_Port( void);
int Oscar_Test( );
void Oscar_Start( );
void Oscar_Stop( );
int Oscar_Get_Timeout( Oscar_TypeDef * oscar );
void Oscar_Wavelength( );
int Oscar_Transmit( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
int Oscar_Begin_Rcv( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
void Oscar_Set_Sendbuf( uint8_t * buf, uint16_t size );
void Oscar_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void Oscar_Set_Timeout_ms( uint64_t ms_ticks );
int Oscar_Validate( );
int Oscar_Set_UartHelper_Status( Oscar_TypeDef * oscar ,Uart_Status_TypeDef status);
Uart_Status_TypeDef Oscar_Get_UartHelper_Status( Oscar_TypeDef * oscar );
int Oscar_Get_Data_OK(Oscar_TypeDef * oscar );
void Oscar_Set_Send_Flag( Oscar_TypeDef * oscar );
int Oscar_Transmit();
int Oscar_Receive();
void Oscar_callback( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
void Oscar_Set_GPIO_For_TC_Cplt( Oscar_TypeDef * oscar );
void Oscar_Trans_GPIO(void) ;
void Oscar_clean_flag(Oscar_TypeDef * oscar,uint8_t mask);
uint8_t Oscar_get_flag(Oscar_TypeDef * oscar,uint8_t mask);
void Oscar_Trans_Cplt_GPIO(void) ;
uint16_t Oscar_get_serial_number(Oscar_TypeDef * oscar );
int Oscar_CallBack( Oscar_TypeDef *pOscar , uint8_t *buf, uint16_t size );
// int Oscar_copy(uint8_t *targer_buf, uint8_t *src_buf,uint32_t buf_size);
int Oscar_copy(Oscar_TypeDef * oscar ,uint16_t size);
void Oscar_Error( Oscar_TypeDef * oscar, char* str );
// MODULE_Oscar_WORK_STATE Set_State( MODULE_Oscar_WORK_STATE state );
void Oscar_Set_State( MODULE_Oscar_WORK_STATE state );
int Oscar_Init_Ok();
// extern void Oscar_Setup( );
extern void Oscar_Port( );
void Oscar_Task( void* argument);
/* 再封装演示 */
typedef struct
{
uint8_t (*init)( );
void (*port)(void);
void (*Set_State)(MODULE_Oscar_WORK_STATE state );
// MODULE_Oscar_WORK_STATE (*Set_State)( MODULE_Oscar_WORK_STATE state );
GPIO_TypeDef *sel_gpio;
GPIO_TypeDef *dplx_gpio;
GPIO_TypeDef *de_gpio;
uint16_t sel_pin;
uint16_t dplx_pin;
uint16_t de_pin;
Uart_Interface_Type_Typedef interface_type; /* 0: default(ttl 232), 1: 485 ,2:3160*/
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/
Oscar_TypeDef *oscar; /*不是常量 不能直接初始化*/
}My_Oscar_TypeDef;
extern My_Oscar_TypeDef myoscar;
#ifdef __cplusplus
}
#endif
#endif
/**
*
* init: Oscar_Setup( ); Oscar_SN( ); Oscar_Wavelength( );
* call: Oscar_Port( );
*
* sn
*
* @register: viper
DataBeginAddress: 2614
SNAddress: 2980,10
SNLen: 5
WLBeginAddress: 2102
count: 3
functioncode: 3
slaveaddress: 1
122 122*4+5 = 493
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
01 03 09 2A 00 7A E6 7D (2346 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 2A 00 7A E7 C5 (2758 122)
01 03 0B A4 00 05 C6 0E (SN 2980 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/**
* @register: viper
DataBeginAddress: 2614
SNAddress: 2840
SNLen: 5
WLBeginAddress: 2102
count: 2
functioncode: 3
slaveaddress: 1
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 18 00 05 07 EA (SN 2840 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/*
temp.init();
temp.port();
temp.test();
uint64_t ticks = osKernelGetTickCount();
while ( temp.state != PH_State_Ready )
{
if ( ( osKernelGetTickCount() -ticks) > 3000 )
{
log_e(" pH test error.... ") ;
break;
}
}
log_w(" pH test ok.... ") ;
// osMessageQueueId_t TestQQueueueueHandle;
// osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
// osMessageQueueGet(TestQueueHandle,osWaitForever);
// osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id,
// void * msg_ptr, //储存读取结果的变量地址
// uint8_t * msg_prio, // ==NULL
// uint32_t timeout //阻塞超时时间
// );
// osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id,
// const void * msg_ptr, //储存写入内容的变量地址
// uint8_t msg_prio, //==0U
// uint32_t timeout //阻塞超时时间
// );
// uint8_t Oscar_SN_command[8] = {0x01, 0x03, 0x00, 0x0A, 0x00, 0x05, 0xA5, 0xCB};
// uint8_t Oscar_Wavelength_sendbuf[3][8] = {
//
// // 01 03 08 36 00 7A 26 47 (2102 122)
// // 01 03 08 B0 00 7A C7 AE (2224 122)
// // 01 03 09 2A 00 7A E6 7D (2346 122)
//
// { 0x01, 0x03, 0x08, 0x36, 0x00, 0x7A, 0x26, 0x47 },
// { 0x01, 0x03, 0x08, 0xB0, 0x00, 0x7A, 0xC7, 0xAE },
// { 0x01, 0x03, 0x09, 0x2A, 0x00, 0x7A, 0xE6, 0x7D }
// };
// uint8_t Oscar_Data_sendbuf[3][8] = {
//
// //01 03 0A 36 00 7A 27 FF (2614 122)
// //01 03 0A B0 00 7A C6 16 (2736 122)
// //01 03 0B 2A 00 7A E7 C5 (2858 122)
//
// { 0x01, 0x03, 0x0A, 0x36, 0x00, 0x7A, 0x27, 0xFF },
// { 0x01, 0x03, 0x0A, 0xB0, 0x00, 0x7A, 0xC6, 0x16 },
// { 0x01, 0x03, 0x0B, 0x2A, 0x00, 0x7A, 0xE7, 0xC5 }
// };
// uint8_t Oscar_sn_buf[15] = {0};
*/

@ -1,220 +1,138 @@
#ifndef __SC6_H
#define __SC6_H
#ifndef __SC6__H
#define __SC6__H
#include <string.h>
#include "uart_helper.h"
#include "uart_interface.h"
// #include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#define SC6_DEMO 1 /*sn 读取位置不一样*/
#include "elog.h"
#include <string.h>
#include "bsp_uart.h"
#define SC6_USE_MAX485 0
#define SC6_USE_MAX3160_232 0
#define SC6_USE_MAX3160_485 1
#define SC6_RESUMED_Buf_Size (12)
#define SC6_PAUSEED_Buf_Size (11)
#define SC6_Result_Buf_Size (286 )
#define SC6_Result_Buf_Size (286 )
#define SC6_Rcv_Buf_Size (2*SC6_Result_Buf_Size +2*SC6_RESUMED_Buf_Size )
#define SC6_Command_Number 2
#define SC6_FLAG_MASK_BUSY ((uint32_t)1<<(uint32_t)0)
#define SC6_FLAG_MASK_RECVED_DATA ((uint32_t)1<<(uint32_t)1)
// #define SC6_FLAG_MASK_RECVED_WL_1 ((uint32_t)1<<(uint32_t)3)
// #define SC6_FLAG_MASK_RECVED_DATA_0 ((uint32_t)1<<(uint32_t)4)
// #define SC6_FLAG_MASK_RECVED_DATA_1 ((uint32_t)1<<(uint32_t)5)
static void SC6_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
typedef enum
{
MODULE_SC6_STATE_WAIT,
MODULE_SC6_STATE_START,
MODULE_SC6_STATE_CHECK_DATA,
MODULE_SC6_STATE_OK,
MODULE_SC6_STATE_ERROR,
MODULE_SC6_STATE_STOP
} MODULE_SC6_WORK_STATE;
SC6_Event_Ready ,
SC6_Event_Test,
SC6_Event_Test_OK ,
SC6_Event_Get_Data,
SC6_Event_Check_Data ,
} Module_SC6_Event_TypeDef;
typedef enum
{
SC6_State_Waiting,
SC6_State_Test,
SC6_State_Test_Data_Getting,
SC6_State_Test_OK,
SC6_State_Ready,
SC6_State_Start,
SC6_State_Start_Trans,
SC6_State_Data_Getting,
SC6_State_Check_Data,
SC6_State_OK,
SC6_State_Stop ,
SC6_State_Timeout ,
SC6_State_Error ,
} Module_SC6_State_TypeDef;
extern UART_HELPER_TypeDef *SC6_uart_helper;
typedef struct
{
UartHelper_TypeDef *uarthelper;
volatile MODULE_SC6_WORK_STATE state;
volatile uint8_t flag; /* SC6_FLAG_MASK_ SN WL1 WL2 DATA1 DATA2 ,*/
volatile uint8_t send_flag; /* 发送标志位 */
volatile Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/
uint8_t *send_buf;
uint16_t size_send;
uint8_t *rcv_buf;
uint16_t size_rcv;
uint8_t mode_232_485; /* 0: common, 1: 485 */
uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
osMessageQueueId_t cmdQueue; // 队列可选
volatile Module_SC6_State_TypeDef state;
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint8_t step; /* 0 : normal , 1 : get wavelength , 2 : get sn 3: 空*/
volatile uint8_t command_seq ; /* 命令序号 */
uint8_t result_buf[1024];
uint16_t size_received;
// uint16_t sn;
uint64_t timebase_ticks;
uint64_t timeout_ticks;
uint8_t event_flag;
uint16_t sn_buf[4];
uint8_t SC6_sn_buf[4];
uint8_t SC6_Result_Buf[ SC6_Rcv_Buf_Size ];
uint8_t SC6_Data_Buf[ SC6_Rcv_Buf_Size ];
// uint8_t rcv_ok; /* 接收数据完整可以处理 */
// uint8_t data_begin_flag; /* 接收数据完整可以处理 */
uint8_t error; /* 接收数据完整可以处理 */
uint16_t index_SC6_LPT;
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint64_t timeout_ms;
uint64_t timeout_enable;
uint16_t index_SC6_LPT; // 记录出现开始标记的位置
}SC6_TypeDef;
extern SC6_TypeDef *sc6 ;
uint8_t SC6_Init( );
void SC6_Set_Uarthelper(SC6_TypeDef *sc6, UartHelper_TypeDef *uarthelper);
void SC6_Set_Interface(SC6_TypeDef *sc6, UartInterface_TypeDef *interface);
extern SC6_TypeDef sc6 ;
void SC6_Set_Huart( SC6_TypeDef * sc6, UART_HandleTypeDef * huart );
void SC6_Set_RsMode_232_485( SC6_TypeDef * sc6, Uart_RS_Mode_TypeDef rs_232_485 );
int SC6_Init( void );
void SC6_Task( void);
void SC6_Port( void);
int SC6_Test( );
void SC6_Start( );
void SC6_Stop( );
void SC6_Set_Trans_Type( SC6_TypeDef *sc6, Uart_Transmode_TypeDef trans_type );
void SC6_Set_Rcv_Type( SC6_TypeDef *sc6, Uart_Transmode_TypeDef rcv_type );
void SC6_Set_Idle_Enable( SC6_TypeDef *sc6, Uart_IDLE_Enable_TypeDef idle_enable_disable );
void SC6_Set_TransMode( SC6_TypeDef *sc6, Uart_Transmode_TypeDef trans_mode );
void SC6_Set_Timeout( SC6_TypeDef *sc6, uint16_t timeout_ms );
void SC6_Set_Sendbuf( SC6_TypeDef *sc6, uint8_t * buf, uint16_t size );
void SC6_Set_Rcvbuf( SC6_TypeDef *sc6, uint8_t * buf, uint16_t size );
void SC6_Set_Timeout( SC6_TypeDef * sc6, uint16_t timeout_ms );
// void SC6_Set_Sendbuf( SC6_TypeDef * sc6, uint8_t * buf, uint16_t size );
// void SC6_Set_Rcvbuf( SC6_TypeDef * sc6, uint8_t * buf, uint16_t size );
int SC6_Get_Timeout( SC6_TypeDef * sc6 );
int SC6_Transmit( SC6_TypeDef * sc6, uint8_t * buf, uint16_t size );
int SC6_Begin_Rcv( SC6_TypeDef * sc6, uint8_t * buf, uint16_t size );
int SC6_Set_UartHelper_Status( SC6_TypeDef * sc6 ,Uart_Status_TypeDef status);
Uart_Status_TypeDef SC6_Get_UartHelper_Status( SC6_TypeDef * sc6 );
void SC6_Set_Sendbuf( uint8_t * buf, uint16_t size );
void SC6_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void SC6_Set_Timeout_ms( uint64_t ms_ticks );
int SC6_Validate( );
int SC6_Get_Data_OK(SC6_TypeDef * sc6 );
void SC6_Set_Send_Flag( SC6_TypeDef * sc6 );
void SC6_callback( SC6_TypeDef * sc6, uint8_t * buf, uint16_t size );
void SC6_Set_GPIO_For_TC_Cplt( SC6_TypeDef * sc6 );
int SC6_Transmit();
int SC6_Receive();
void SC6_clean_flag(SC6_TypeDef * sc6,uint8_t mask);
uint8_t SC6_get_flag(SC6_TypeDef * sc6,uint8_t mask);
void SC6_Trans_GPIO(void) ;
uint16_t SC6_get_serial_number(SC6_TypeDef * sc6 );
void SC6_Trans_Cplt_GPIO(void) ;
// int SC6_copy(uint8_t *targer_buf, uint8_t *src_buf,uint32_t buf_size);
int SC6_copy(SC6_TypeDef * sc6 ,uint16_t size);
void SC6_Error( SC6_TypeDef * sc6, char* str );
// MODULE_SC6_WORK_STATE Set_State( MODULE_SC6_WORK_STATE state );
void SC6_Set_State( MODULE_SC6_WORK_STATE state );
int SC6_Init_Ok();
int SC6_CallBack( SC6_TypeDef *pPH, uint8_t *buf, uint16_t size );
// extern void SC6_Setup( );
extern void SC6_Port( );
void SC6_Task( void* argument);
/* 再封装演示 */
typedef struct
{
uint8_t (*init)( );
void (*port)(void);
void (*Set_State)(MODULE_SC6_WORK_STATE state );
// MODULE_SC6_WORK_STATE (*Set_State)( MODULE_SC6_WORK_STATE state );
GPIO_TypeDef *sel_gpio;
GPIO_TypeDef *dplx_gpio;
GPIO_TypeDef *de_gpio;
uint16_t sel_pin;
uint16_t dplx_pin;
uint16_t de_pin;
Uart_Interface_Type_Typedef interface_type; /* 0: default(ttl 232), 1: 485 ,2:3160*/
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/
SC6_TypeDef *sc6; /*不是常量 不能直接初始化*/
}My_SC6_TypeDef;
extern My_SC6_TypeDef mysc6;
#ifdef __cplusplus
}
#endif
#endif
/**
*
* init: SC6_Setup( ); SC6_SN( ); SC6_Wavelength( );
* call: SC6_Port( );
*
* sn
*
* @register: viper
DataBeginAddress: 2614
SNAddress: 2980,10
SNLen: 5
WLBeginAddress: 2102
count: 3
functioncode: 3
slaveaddress: 1
122 122*4+5 = 493
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
01 03 09 2A 00 7A E6 7D (2346 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 2A 00 7A E7 C5 (2758 122)
01 03 0B A4 00 05 C6 0E (SN 2980 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/**
* @register: viper
DataBeginAddress: 2614
SNAddress: 2840
SNLen: 5
WLBeginAddress: 2102
count: 2
functioncode: 3
slaveaddress: 1
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 18 00 05 07 EA (SN 2840 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/*
ph.init();
ph.port();
ph.test();
// uint64_t ticks = osKernelGetTickCount();
// while ( ph.state != SC6_State_Ready )
// {
// if ( ( osKernelGetTickCount() -ticks) > 5000 )
// {
// log_e(" pH test error.... %d", ph.state) ;
// break;
// }
// }
osDelay(1000);
log_w(" pH test ok.... %d", ph.state) ;
*/

@ -1,165 +0,0 @@
/*
*/
#ifndef __TEMPERATURE_H
#define __TEMPERATURE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include "elog.h"
#include <string.h>
#include "bsp_uart.h"
#define TEMP_USE_MAX485 0
#define TEMP_USE_MAX3160_232 0
#define TEMP_USE_MAX3160_485 1
#define TEMP_Rcv_Buf_Size 9
#define TEMP_Command_Number 1
static void TEMP_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
typedef enum
{
TEMP_Event_Ready ,
TEMP_Event_Test,
TEMP_Event_Test_OK ,
TEMP_Event_Get_Data,
TEMP_Event_Check_Data ,
} Module_TEMP_Event_TypeDef;
typedef enum
{
TEMP_State_Waiting ,
TEMP_State_Test ,
TEMP_State_Test_Start ,
TEMP_State_Testing ,
TEMP_State_Test_OK ,
TEMP_State_Ready ,
TEMP_State_Get_DATA ,
TEMP_State_Get_DATA_Wait ,
TEMP_State_Get_DATA_OK,
TEMP_State_Get_DATA_Check ,
TEMP_State_Stop ,
TEMP_State_Timeout ,
TEMP_State_Error ,
} Module_TEMP_State_TypeDef;
extern UART_HELPER_TypeDef *temp_uart_helper;
typedef struct
{
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
osMessageQueueId_t transQueue; // 队列可选
volatile Module_TEMP_State_TypeDef state;
uint8_t data_ok; /* 接收数据完整可以处理 */
uint8_t result_buf[1024];
uint8_t size_received;
uint64_t timebase_ticks;
uint64_t timeout_ticks;
uint8_t event_flag;
Record_Trans_Rcv_TypeDef transRecord[3];
// uint64_t timebase;
// uint16_t timeout_ms;
// volatile uint8_t send_flag; /* 发送标志位 */
// Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
// Uart_Status_TypeDef status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
// uint8_t command_seq ; /* 命令序号 */
// uint8_t mode; /* 0 : normal , 1 : get wavelength , 2 : get sn */
// uint8_t vipersn_buf[15];
// uint8_t TEMP_Wavelength_Buf[2][ TEMP_Rcv_Buf_Size ];
// uint8_t TEMP_Data_Buf[2][ TEMP_Rcv_Buf_Size ];
}TEMP_TypeDef;
extern TEMP_TypeDef temp ;
int TEMP_Init( void );
void TEMP_Task( void);
void TEMP_Port( void);
int TEMP_Test( );
void TEMP_Start( );
void TEMP_Stop( );
void TEMP_Set_Sendbuf( uint8_t * buf, uint16_t size );
void TEMP_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void TEMP_Set_Timeout_ms( uint64_t ms_ticks );
int TEMP_Validate( );
int TEMP_Transmit();
int TEMP_Receive();
void TEMP_Trans_GPIO(void) ;
void TEMP_Trans_Cplt_GPIO(void) ;
int TEMP_CallBack( TEMP_TypeDef *pPH, uint8_t *buf, uint16_t size );
#ifdef __cplusplus
}
#endif
#endif
/*
temp.init();
temp.port();
temp.test();
uint64_t ticks = osKernelGetTickCount();
while ( temp.state != PH_State_Ready )
{
if ( ( osKernelGetTickCount() -ticks) > 3000 )
{
log_e(" pH test error.... ") ;
break;
}
}
log_w(" pH test ok.... ") ;
// osMessageQueueId_t TestQQueueueueHandle;
// osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
// osMessageQueueGet(TestQueueHandle,osWaitForever);
// osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id,
// void * msg_ptr, //储存读取结果的变量地址
// uint8_t * msg_prio, // ==NULL
// uint32_t timeout //阻塞超时时间
// );
// osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id,
// const void * msg_ptr, //储存写入内容的变量地址
// uint8_t msg_prio, //==0U
// uint32_t timeout //阻塞超时时间
// );
*/

@ -1,243 +1,190 @@
#ifndef __Viper_H
#define __Viper_H
/*
*/
#ifndef __VIPER__H
#define __VIPER__H
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include "uart_helper.h"
#include "uart_interface.h"
// #include "config.h"
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include "elog.h"
#define Viper_DEMO 0 /*sn 读取位置不一样*/
#define Viper_Rcv_Buf_Size (3+244+2)
#define Viper_Command_Number 3
#define Viper_FLAG_MASK_BUSY ((uint32_t)1<<(uint32_t)0)
#define Viper_FLAG_MASK_RECVED_SN ((uint32_t)1<<(uint32_t)1)
#define Viper_FLAG_MASK_RECVED_WL ((uint32_t)1<<(uint32_t)2)
#define Viper_FLAG_MASK_RECVED_DATA ((uint32_t)1<<(uint32_t)3)
// #define Viper_FLAG_MASK_RECVED_WL_1 ((uint32_t)1<<(uint32_t)3)
// #define Viper_FLAG_MASK_RECVED_DATA_0 ((uint32_t)1<<(uint32_t)4)
// #define Viper_FLAG_MASK_RECVED_DATA_1 ((uint32_t)1<<(uint32_t)5)
#include <string.h>
#include "bsp_uart.h"
#define Viper_USE_MAX485 0
#define Viper_USE_MAX3160_232 0
#define Viper_USE_MAX3160_485 1
#define Viper_Rcv_Buf_Size (3+244+2)
// #define Viper_Command_Number 1
static void Viper_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
typedef enum
{
MODULE_Viper_STATE_WAIT,
MODULE_Viper_STATE_START,
MODULE_Viper_STATE_GET_SN,
MODULE_Viper_STATE_CHECK_SN,
MODULE_Viper_STATE_GET_WL_0,
MODULE_Viper_STATE_GET_WL_1,
MODULE_Viper_STATE_GET_WL_2,
MODULE_Viper_STATE_CHECK_WL,
MODULE_Viper_STATE_Ready_GET_DATA,
MODULE_Viper_STATE_START_DATA,
MODULE_Viper_STATE_GET_DATA_0,
MODULE_Viper_STATE_GET_DATA_1,
MODULE_Viper_STATE_GET_DATA_2,
MODULE_Viper_STATE_CHECK_DATA,
MODULE_Viper_STATE_OK,
MODULE_Viper_STATE_ERROR,
MODULE_Viper_STATE_STOP
} MODULE_Viper_WORK_STATE;
Viper_Event_Ready ,
Viper_Event_Test,
Viper_Event_Test_OK ,
Viper_Event_Get_Data,
Viper_Event_Check_Data ,
} Module_Viper_Event_TypeDef;
typedef enum
{
Viper_State_Waiting ,
Viper_State_Test ,
Viper_State_Test_Start ,
Viper_State_SN_Getting ,
Viper_State_SN_OK ,
Viper_State_Ready ,
Viper_State_Get_WAVELENGTH ,
// Viper_State_Get_WAVELENGTH_Wait ,
// Viper_State_Get_WAVELENGTH_OK,
// Viper_State_Get_WAVELENGTH_Check ,
Viper_State_Get_DATA ,
Viper_State_Get_DATA_Trans,
Viper_State_Get_DATA_Wait ,
Viper_State_Get_DATA_OK,
Viper_State_Get_DATA_Check ,
Viper_State_Get_Queue_MSG ,
Viper_State_Stop ,
Viper_State_Timeout ,
Viper_State_Error ,
} Module_Viper_State_TypeDef;
extern UART_HELPER_TypeDef *Viper_uart_helper;
typedef struct
{
UartHelper_TypeDef *uarthelper;
volatile MODULE_Viper_WORK_STATE state;
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
volatile uint8_t flag; /* Viper_FLAG_MASK_ SN WL1 WL2 DATA1 DATA2 ,*/
volatile uint8_t send_flag; /* 发送标志位 */
volatile Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/
volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
osMessageQueueId_t transQueue; // 队列可选
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/
uint8_t *send_buf;
uint16_t size_send;
uint8_t *rcv_buf;
uint16_t size_rcv;
volatile Module_Viper_State_TypeDef state;
uint8_t data_ok; /* 接收数据完整可以处理 */
uint8_t result_buf[1024];
uint8_t size_received;
uint8_t mode_232_485; /* 0: common, 1: 485 */
uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/
uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
uint64_t timebase_ticks;
uint64_t timeout_ticks;
volatile uint8_t step; /* 0 : normal , 1 : get wavelength , 2 : get sn 3: 空*/
volatile uint8_t command_seq ; /* 命令序号 */
uint8_t event_flag;
uint8_t wavelength_ok;
uint16_t sn;
Record_Trans_Rcv_TypeDef transRecord[3];
uint8_t sn_buf[15];
uint8_t vipersn_buf[15];
uint8_t Viper_Wavelength_Buf[3][ Viper_Rcv_Buf_Size ];
uint8_t Viper_Data_Buf[3][ Viper_Rcv_Buf_Size ];
// uint8_t rcv_ok; /* 接收数据完整可以处理 */
// uint8_t data_begin_flag; /* 接收数据完整可以处理 */
uint8_t error; /* 接收数据完整可以处理 */
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint64_t timeout_ms;
uint64_t timeout_enable;
}Viper_TypeDef;
extern Viper_TypeDef *viper ;
uint8_t Viper_Init( );
extern Viper_TypeDef viper ;
void Viper_Set_Uarthelper(Viper_TypeDef *viper, UartHelper_TypeDef *uarthelper);
void Viper_Set_Interface(Viper_TypeDef *viper, UartInterface_TypeDef *interface);
int Viper_Init( void );
void Viper_Task( void);
void Viper_Port( void);
int Viper_Test( );
void Viper_Start( );
void Viper_Stop( );
void Viper_Set_Huart( Viper_TypeDef * oscar, UART_HandleTypeDef * huart );
void Viper_Set_RsMode_232_485( Viper_TypeDef * oscar, Uart_RS_Mode_TypeDef rs_232_485 );
void Viper_Set_Trans_Type( Viper_TypeDef *viper, Uart_Transmode_TypeDef trans_type );
void Viper_Set_Rcv_Type( Viper_TypeDef *viper, Uart_Transmode_TypeDef rcv_type );
void Viper_Set_Idle_Enable( Viper_TypeDef *viper, Uart_IDLE_Enable_TypeDef idle_enable_disable );
void Viper_Set_TransMode( Viper_TypeDef *viper, Uart_Transmode_TypeDef trans_mode );
void Viper_Set_Timeout( Viper_TypeDef *viper, uint16_t timeout_ms );
void Viper_Set_Sendbuf( Viper_TypeDef *viper, uint8_t * buf, uint16_t size );
void Viper_Set_Rcvbuf( Viper_TypeDef *viper, uint8_t * buf, uint16_t size );
void Viper_Wavelength( );
void Viper_Set_Sendbuf( uint8_t * buf, uint16_t size );
void Viper_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void Viper_Set_Timeout_ms( uint64_t ms_ticks );
int Viper_Validate( );
int Viper_Transmit();
int Viper_Receive();
void Viper_Trans_GPIO(void) ;
void Viper_Set_Timeout( Viper_TypeDef * oscar, uint16_t timeout_ms );
void Viper_Trans_Cplt_GPIO(void) ;
// void Viper_Set_Sendbuf( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size );
// void Viper_Set_Rcvbuf( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size );
int Viper_CallBack( Viper_TypeDef *pViper , uint8_t *buf, uint16_t size );
int Viper_Get_Timeout( Viper_TypeDef * oscar );
int Viper_Transmit( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size );
int Viper_Begin_Rcv( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size );
int Viper_Set_UartHelper_Status( Viper_TypeDef * oscar ,Uart_Status_TypeDef status);
Uart_Status_TypeDef Viper_Get_UartHelper_Status( Viper_TypeDef * oscar );
int Viper_Get_Data_OK(Viper_TypeDef * oscar );
void Viper_Set_Send_Flag( Viper_TypeDef * oscar );
void Viper_callback( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size );
void Viper_Set_GPIO_For_TC_Cplt( Viper_TypeDef * oscar );
void Viper_clean_flag(Viper_TypeDef * oscar,uint8_t mask);
uint8_t Viper_get_flag(Viper_TypeDef * oscar,uint8_t mask);
uint16_t Viper_get_serial_number(Viper_TypeDef * oscar );
// int Viper_copy(uint8_t *targer_buf, uint8_t *src_buf,uint32_t buf_size);
int Viper_copy(Viper_TypeDef * oscar ,uint16_t size);
void Viper_Error( Viper_TypeDef * oscar, char* str );
// MODULE_Viper_WORK_STATE Set_State( MODULE_Viper_WORK_STATE state );
void Viper_Set_State( MODULE_Viper_WORK_STATE state );
// int Viper_Send( Viper_TypeDef * oscar, uint8_t * buf, uint16_t size);
// void Viper_Begin_Rcv(Viper_TypeDef * oscar, uint8_t * buf, uint16_t size);
// extern void Viper_Rcv_Cplt_Callback( Viper_TypeDef * oscar );
// extern void Viper_Send_Cplt_Callback( Viper_TypeDef * oscar );
// void Viper_Set_Interface_Type( Viper_TypeDef * oscar, Uart_Interface_Typedef interface_type );
// void Viper_Set_Trans_Type( Viper_TypeDef * oscar, Uart_Transmode_TypeDef trans_type );
// void Viper_Set_Rcv_Type( Viper_TypeDef * oscar, Uart_Transmode_TypeDef rcv_type );
// void Viper_Set_Idle_Enable( Viper_TypeDef * oscar, Uart_IDLE_Enable_TypeDef idle_enable_disable );
// void Viper_Set_TransMode( Viper_TypeDef * oscar, Uart_Transmode_TypeDef trans_mode );
// void Viper_Set_RsMode_232_485( Viper_TypeDef * oscar, Uart_RS_Mode_TypeDef rs_232_485 );
// extern void Viper_Setup( );
extern void Viper_Port( );
// extern void Viper_SN( );
// extern void Viper_Wavelength( );
void Viper_Task( void* argument);
/* 再封装演示 */
typedef struct
{
uint8_t (*init)( );
void (*port)(void);
void (*Set_State)(MODULE_Viper_WORK_STATE state );
// MODULE_Viper_WORK_STATE (*Set_State)( MODULE_Viper_WORK_STATE state );
GPIO_TypeDef *sel_gpio;
GPIO_TypeDef *dplx_gpio;
GPIO_TypeDef *de_gpio;
uint16_t sel_pin;
uint16_t dplx_pin;
uint16_t de_pin;
Uart_Interface_Type_Typedef interface_type; /* 0: default(ttl 232), 1: 485 ,2:3160*/
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/
Viper_TypeDef *viper; /*不是常量 不能直接初始化*/
}My_Viper_TypeDef;
extern My_Viper_TypeDef myviper;
#ifdef __cplusplus
}
#endif
#endif
/**
*
* init: Viper_Setup( ); Viper_SN( ); Viper_Wavelength( );
* call: Viper_Port( );
*
* sn
*
* @register: viper
DataBeginAddress: 2614
SNAddress: 2980,10
SNLen: 5
WLBeginAddress: 2102
count: 3
functioncode: 3
slaveaddress: 1
122 122*4+5 = 493
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
01 03 09 2A 00 7A E6 7D (2346 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 2A 00 7A E7 C5 (2758 122)
01 03 0B A4 00 05 C6 0E (SN 2980 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/**
* @register: viper
DataBeginAddress: 2614
SNAddress: 2840
SNLen: 5
WLBeginAddress: 2102
count: 2
functioncode: 3
slaveaddress: 1
wl:
01 03 08 36 00 7A 26 47 (2102 122)
01 03 08 B0 00 7A C7 AE (2224 122)
data:
01 03 0A 36 00 7A 27 FF (2614 122)
01 03 0A B0 00 7A C6 16 (2736 122)
01 03 0B 18 00 05 07 EA (SN 2840 5 demo)
01 03 00 0A 00 05 A5 CB (SN 10 5 )
*
*/
/*
temp.init();
temp.port();
temp.test();
uint64_t ticks = osKernelGetTickCount();
while ( temp.state != PH_State_Ready )
{
if ( ( osKernelGetTickCount() -ticks) > 3000 )
{
log_e(" pH test error.... ") ;
break;
}
}
log_w(" pH test ok.... ") ;
// osMessageQueueId_t TestQQueueueueHandle;
// osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
// osMessageQueueGet(TestQueueHandle,osWaitForever);
// osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id,
// void * msg_ptr, //储存读取结果的变量地址
// uint8_t * msg_prio, // ==NULL
// uint32_t timeout //阻塞超时时间
// );
// osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id,
// const void * msg_ptr, //储存写入内容的变量地址
// uint8_t msg_prio, //==0U
// uint32_t timeout //阻塞超时时间
// );
// uint8_t Viper_SN_command[8] = {0x01, 0x03, 0x00, 0x0A, 0x00, 0x05, 0xA5, 0xCB};
// uint8_t Viper_Wavelength_sendbuf[3][8] = {
//
// // 01 03 08 36 00 7A 26 47 (2102 122)
// // 01 03 08 B0 00 7A C7 AE (2224 122)
// // 01 03 09 2A 00 7A E6 7D (2346 122)
//
// { 0x01, 0x03, 0x08, 0x36, 0x00, 0x7A, 0x26, 0x47 },
// { 0x01, 0x03, 0x08, 0xB0, 0x00, 0x7A, 0xC7, 0xAE },
// { 0x01, 0x03, 0x09, 0x2A, 0x00, 0x7A, 0xE6, 0x7D }
// };
// uint8_t Viper_Data_sendbuf[3][8] = {
//
// //01 03 0A 36 00 7A 27 FF (2614 122)
// //01 03 0A B0 00 7A C6 16 (2736 122)
// //01 03 0B 2A 00 7A E7 C5 (2858 122)
//
// { 0x01, 0x03, 0x0A, 0x36, 0x00, 0x7A, 0x27, 0xFF },
// { 0x01, 0x03, 0x0A, 0xB0, 0x00, 0x7A, 0xC6, 0x16 },
// { 0x01, 0x03, 0x0B, 0x2A, 0x00, 0x7A, 0xE7, 0xC5 }
// };
// uint8_t Viper_sn_buf[15] = {0};
*/

@ -1,29 +1,40 @@
/**
* @file wh_lte_7s4_v2.h
* @author Chen Jihang (embedded@eseaoptics.com)
* @brief WH LTE 7S4 V2驱动
* @version 0.1
* @date 2022-07-18
*
* @copyright ESEA (c) 2020
*
*/
#ifndef WH_LTE_7S4_V2_H_
#define WH_LTE_7S4_V2_H_
#include "stdint.h"
// #include "config.h"
#include "uart_helper.h"
#include "uart_interface.h"
// #include "platform.h"
#define WH_LTE_Rcv_Buf_Size (1024)
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include "elog.h"
#include <string.h>
#include "bsp_uart.h"
#define WH_LTE_USE_MAX485 0
#define WH_LTE_USE_MAX3160_232 0
#define WH_LTE_USE_MAX3160_485 1
#define WH_LTE_Rcv_Buf_Size (3+244+2)
// #define WH_LTE_Command_Number 1
static void WH_LTE_MAX3160_232(void)
{
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
}
#define WH_LTE_FLAG_MASK_BUSY ((uint32_t)1<<(uint32_t)0)
#define WH_LTE_FLAG_MASK_RECVED_SN ((uint32_t)1<<(uint32_t)1)
#define WH_LTE_FLAG_MASK_RECVED_WL ((uint32_t)1<<(uint32_t)2)
#define WH_LTE_FLAG_MASK_RECVED_DATA ((uint32_t)1<<(uint32_t)3)
typedef enum
{
MODULE_WH_LTE_EVENT_READY,
@ -39,7 +50,6 @@ typedef enum
MODULE_WH_LTE_EVENT_SEND_DATA,
} MODULE_WH_LTE_EVENT_TypeDef;
typedef enum
{
MODULE_WH_LTE_7S4_INIT_STATE_WAIT,
@ -59,38 +69,6 @@ typedef enum
} MODULE_WH_LTE_WORK_STATE;
typedef int (*wh_lte_7s4_send_fun)(void *send_obj,char *buf,uint32_t size);
typedef struct
{
// UartHelper_TypeDef *uarthelper;
volatile MODULE_WH_LTE_WORK_STATE state;
uint8_t receive_err_code;
uint8_t receive_ok_flag;
uint8_t receive_a_flag;
uint8_t receive_para_num;
uint32_t receive_size;
char receive_para[8][32];
char send_args_buf[64];
uint8_t receive_buf[1024];
void *send_obj;
wh_lte_7s4_send_fun send_fun;
uint8_t error; /* 接收数据完整可以处理 */
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint32_t timeout_ms;
uint8_t timeout_enable;
// f服务器信息
char server_ip_domain[64];
uint16_t server_port;
}WH_LTE_7S4_Typedef;
enum wh_lte_7s4_cmd_state{
WH_LTE_7S4_CMD_STATE_OFF=0,
WH_LTE_7S4_CMD_STATE_ON=1
@ -114,131 +92,76 @@ enum wh_lte_7s4_cmd_protocol{
WH_LTE_7S4_CMD_PROTOCOL_UDP
};
extern WH_LTE_7S4_Typedef *wh_lte_7s4;
extern UART_HELPER_TypeDef *WH_LTE_uart_helper;
/* 再封装演示 */
typedef struct
{
uint8_t (*init)( );
void (*port)( );
void (*setstate)( MODULE_WH_LTE_WORK_STATE state);
// MODULE_WH_LTE_WORK_STATE (*Set_State)( MODULE_WH_LTE_WORK_STATE state );
GPIO_TypeDef *sel_gpio;
GPIO_TypeDef *dplx_gpio;
GPIO_TypeDef *de_gpio;
uint16_t sel_pin;
uint16_t dplx_pin;
uint16_t de_pin;
Uart_Interface_Type_Typedef interface_type; /* 0: default(ttl 232), 1: 485 ,2:3160*/
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/
WH_LTE_7S4_Typedef *sample; /*不是常量 不能直接初始化*/
}My_WH_LTE_TypeDef;
extern My_WH_LTE_TypeDef my_wh_lte;
void WH_LTE_Port(void);
void WH_LTE_Task(void* argument);
void WH_LTE_Set_State(MODULE_WH_LTE_WORK_STATE state);
void WH_LTE_Set_Timeout( WH_LTE_7S4_Typedef * wh_lte_7s4, uint16_t timeout_ms );
int WH_LTE_Get_Timeout( WH_LTE_7S4_Typedef * wh_lte_7s4 );
int WH_LTE_Transmit( WH_LTE_7S4_Typedef * wh_lte_7s4, uint8_t * buf, uint16_t size );
int WH_LTE_Begin_Rcv( WH_LTE_7S4_Typedef * wh_lte_7s4, uint8_t * buf, uint16_t size );
void WH_LTE_Set_GPIO_For_TC_Cplt( WH_LTE_7S4_Typedef * wh_lte_7s4 );
int WH_LTE_copy(WH_LTE_7S4_Typedef * wh_lte_7s4 ,uint16_t size);
int wh_lte_7s4_init( );
int wh_lte_7s4_ppp(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_a(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_test(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_inquire(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_run(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_set(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size);
int wh_lte_7s4_at_help(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_z(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reboot(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_echo(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_echo(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state);
int wh_lte_7s4_at_entm(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode);
int wh_lte_7s4_at_get_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_csq(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_system_info(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reload(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_clear(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sn(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_iccid(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_imei(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_local_ip(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_uart(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uart(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t buad,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity);
int wh_lte_7s4_at_get_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t ft);
int wh_lte_7s4_at_get_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t len);
int wh_lte_7s4_at_get_socka(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockalk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sockblk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state);
int wh_lte_7s4_at_get_cclk(WH_LTE_7S4_Typedef *wh_lte_7s4);
void wh_lte_7s4_receive_callback(WH_LTE_7S4_Typedef *wh_lte_7s4, uint32_t size);
void wh_lte_7s4_receive_unpack(WH_LTE_7S4_Typedef *wh_lte_7s4,char *buf,uint32_t size);
int Compare_RcvBuf_And_Procedure_Table(int seq, uint8_t *buf, uint16_t size);
unsigned wh_lte_convert_u2s(unsigned integer,char *str,unsigned length);
#endif
int (*init)(void);
void (*port)(void);
int (*test)(void);
void (*start)(void);
void (*stop)(void);
/*
AT+CCLK?
+CCLK: 20/06/19,20:05:19+32
osMessageQueueId_t transQueue; // 队列可选
AT+LBS
+LBS:"520C","03207502"
volatile MODULE_WH_LTE_WORK_STATE state;
uint8_t data_ok; /* 接收数据完整可以处理 */
AT+APN=3gnet,admin,admin,0
OK
uint8_t receive_buf[1024];
uint16_t size_received;
[CR][LF][+CMD][OP][PARA][CR][LF]<CR><LF>[OK]<CR><LF>
uint64_t timebase_ticks;
uint64_t timeout_ticks;
AT+ENTM OK
uint8_t event_flag;
uint8_t wavelength_ok;
AT+ID=0001
Record_Trans_Rcv_TypeDef transRecord[3];
1 +++a
2 AT+WKMOD=UDC UDC
3 AT+SOCKAEN=ON socket A 使
4 AT+SOCKA=TCP,test.usr.cn,2317 socket A TCP Client
5 AT+SOCKASL=LONG socket A
6 AT+REGEN=ON 使
7 AT+ID=0001 UDC的设备ID为000111
8 AT+Z
char receive_para[8][32];
char send_args_buf[64];
uint8_t WH_LTE_Data_Buf[3][ WH_LTE_Rcv_Buf_Size ];
1 +++a
2 AT+WKMOD=NET NET
3 AT+REGEN=ON
4 AT+REGTP=CLOUD CLOUD
5 AT+CLOUD=0123456789012345678912345678
6 AT+Z
*/
uint8_t receive_err_code;
uint8_t receive_ok_flag;
uint8_t receive_a_flag;
uint8_t receive_para_num;
uint32_t receive_size;
uint8_t error;
// 服务器信息
char server_ip_domain[64];
uint16_t server_port;
}WH_LTE_TypeDef;
extern WH_LTE_TypeDef wh_lte ;
int WH_LTE_Init( void );
void WH_LTE_Task( void);
void WH_LTE_Port( void);
int WH_LTE_Test( );
void WH_LTE_Start( );
void WH_LTE_Stop( );
void WH_LTE_Wavelength( );
void WH_LTE_Set_Sendbuf( uint8_t * buf, uint16_t size );
void WH_LTE_Set_Rcvbuf( uint8_t * buf, uint16_t size );
void WH_LTE_Set_Timeout_ms( uint64_t ms_ticks );
int WH_LTE_Validate( );
int WH_LTE_Transmit();
int WH_LTE_Receive();
void WH_LTE_Trans_GPIO(void) ;
void WH_LTE_Trans_Cplt_GPIO(void) ;
int WH_LTE_CallBack( WH_LTE_TypeDef *pWHLTE , uint8_t *buf, uint16_t size );
unsigned wh_lte_convert_u2s(unsigned integer,char *str,unsigned length);
unsigned wh_let_7s4_get_work_state(void);
#endif

@ -1,134 +0,0 @@
/**
* @file wh_lte_7s4_v2.h
* @author Chen Jihang (embedded@eseaoptics.com)
* @brief WH LTE 7S4 V2驱动
* @version 0.1
* @date 2022-07-18
*
* @copyright ESEA (c) 2020
*
*/
#ifndef WH_LTE_7S4_V2_H_
#define WH_LTE_7S4_V2_H_
#include "stdint.h"
#include "config.h"
#include "myuart.h"
// typedef int (*wh_lte_7s4_send_fun)(void *send_obj,char *buf,uint32_t size);
// typedef struct wh_lte_7s4_buff
typedef struct
{
MYUART_TypeDef *myuart;
uint8_t receive_err_code;
uint8_t receive_ok_flag;
uint8_t receive_a_flag;
uint8_t receive_para_num;
uint32_t receive_size;
char receive_para[8][32];
char send_args_buf[64]; /* 组装命令 */
uint8_t receive_buf[1024];
uint32_t timebase;
uint32_t timeout;
uint8_t step;
// void *send_obj;
// wh_lte_7s4_send_fun send_fun;
}WH_LTE_7S4_Typedef;
enum wh_lte_7s4_cmd_state{
WH_LTE_7S4_CMD_STATE_OFF=0,
WH_LTE_7S4_CMD_STATE_ON=1
};
enum wh_lte_7s4_cmd_work_mode{
WH_LTE_7S4_CMD_WORK_MODE_NET=0,
WH_LTE_7S4_CMD_WORK_MODE_HTTPD=1,
WH_LTE_7S4_CMD_WORK_MODE_UDC=0,
};
enum wh_lte_7s4_cmd_uart_parity{
WH_LTE_7S4_CMD_UART_PARITY_NONE=0,
WH_LTE_7S4_CMD_UART_PARITY_ODD=1,
WH_LTE_7S4_CMD_UART_PARITY_EVEN=2
};
enum wh_lte_7s4_cmd_sockasl{
WH_LTE_7S4_CMD_SOCKASL_SHORT=0,
WH_LTE_7S4_CMD_SOCKASL_LONG=1
};
enum wh_lte_7s4_cmd_protocol{
WH_LTE_7S4_CMD_PROTOCOL_TCP,
WH_LTE_7S4_CMD_PROTOCOL_UDP
};
WH_LTE_7S4_Typedef *wh_lte_7s4_init( );
int __wh_lte_7s4_send(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size);
int __wh_lte_7s4_receive(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size);
void wh_lte_7s4_receive_callback(WH_LTE_7S4_Typedef *wh_lte_7s4 );
void wh_lte_7s4_receive_error_callback(WH_LTE_7S4_Typedef *wh_lte_7s4 );
int wh_lte_7s4_ppp(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_a(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_test(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_inquire(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_run(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_set(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size);
int wh_lte_7s4_at_help(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_z(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reboot(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_echo(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_echo(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state);
int wh_lte_7s4_at_entm(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode);
int wh_lte_7s4_at_get_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_csq(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_system_info(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reload(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_clear(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sn(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_iccid(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_imei(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_local_ip(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_uart(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uart(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t baud,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity);
int wh_lte_7s4_at_get_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t ft);
int wh_lte_7s4_at_get_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t len);
int wh_lte_7s4_at_get_socka(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockalk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sockblk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state);
int wh_lte_7s4_at_get_cclk(WH_LTE_7S4_Typedef *wh_lte_7s4);
void wh_lte_7s4_receive_unpack(WH_LTE_7S4_Typedef *wh_lte_7s4,char *buf,uint32_t size);
unsigned convert_u_2_s(unsigned integer,char *str,unsigned length);
#endif
/**
* wh_lte_7s4
*
at : AT\r
test : AT+[cmd]+?\r\n
inquire: AT+[cmd]=?\r\n
run: AT+[cmd]\r\n
set: AT+[cmd]=[args]\r\n
wh_lte_7s4_buff :
myuart
port
-
*/

@ -198,4 +198,17 @@ void wk2114_recv_callback(WK2114_TypeDef *wk2114,uint8_t *buf,uint32_t size);
void wk2114_inter_callback(WK2114_TypeDef *wk2114);
void wk2114_send_completed_callback(WK2114_TypeDef *wk2114);
#endif
#endif
/*
pH 使 1
pH里面回调函数 PH_Callback 1
1. 1
2. PH_callback
*/

@ -1,346 +0,0 @@
#ifndef _WK2XXX_H_
#define _WK2XXX_H_
#include "main.h"
#define WK2XXX_GPORT 1// /wkxxxx Global rigister of PORT
#define WK2XXX_GENA 0X00
#define WK2XXX_GRST 0X01
#define WK2XXX_GMUT 0X02
#define WK2XXX_GIER 0X10
#define WK2XXX_GIFR 0X11
#define WK2XXX_GPDIR 0X21
#define WK2XXX_GPDAT 0X31
//wkxxxx slave uarts rigister address defines
#define WK2XXX_SPAGE 0X03
//PAGE0
#define WK2XXX_SCR 0X04
#define WK2XXX_LCR 0X05
#define WK2XXX_FCR 0X06
#define WK2XXX_SIER 0X07
#define WK2XXX_SIFR 0X08
#define WK2XXX_TFCNT 0X09
#define WK2XXX_RFCNT 0X0A
#define WK2XXX_FSR 0X0B
#define WK2XXX_LSR 0X0C
#define WK2XXX_FDAT 0X0D
#define WK2XXX_FWCR 0X0E
#define WK2XXX_RS485 0X0F
//PAGE1
#define WK2XXX_BAUD1 0X04
#define WK2XXX_BAUD0 0X05
#define WK2XXX_PRES 0X06
#define WK2XXX_RFTL 0X07
#define WK2XXX_TFTL 0X08
#define WK2XXX_FWTH 0X09
#define WK2XXX_FWTL 0X0A
#define WK2XXX_XON1 0X0B
#define WK2XXX_XOFF1 0X0C
#define WK2XXX_SADR 0X0D
#define WK2XXX_SAEN 0X0E
#define WK2XXX_RTSDLY 0X0F
//WK串口扩展芯片的寄存器的位定义
//wkxxx register bit defines
// GENA
#define WK2XXX_UT4EN 0x08
#define WK2XXX_UT3EN 0x04
#define WK2XXX_UT2EN 0x02
#define WK2XXX_UT1EN 0x01
//GRST
#define WK2XXX_UT4SLEEP 0x80
#define WK2XXX_UT3SLEEP 0x40
#define WK2XXX_UT2SLEEP 0x20
#define WK2XXX_UT1SLEEP 0x10
#define WK2XXX_UT4RST 0x08
#define WK2XXX_UT3RST 0x04
#define WK2XXX_UT2RST 0x02
#define WK2XXX_UT1RST 0x01
//GIER
#define WK2XXX_UT4IE 0x08
#define WK2XXX_UT3IE 0x04
#define WK2XXX_UT2IE 0x02
#define WK2XXX_UT1IE 0x01
//GIFR
#define WK2XXX_UT4INT 0x08
#define WK2XXX_UT3INT 0x04
#define WK2XXX_UT2INT 0x02
#define WK2XXX_UT1INT 0x01
//SPAGE
#define WK2XXX_SPAGE0 0x00
#define WK2XXX_SPAGE1 0x01
//SCR
#define WK2XXX_SLEEPEN 0x04
#define WK2XXX_TXEN 0x02
#define WK2XXX_RXEN 0x01
//LCR
#define WK2XXX_BREAK 0x20
#define WK2XXX_IREN 0x10
#define WK2XXX_PAEN 0x08
#define WK2XXX_PAM1 0x04
#define WK2XXX_PAM0 0x02
#define WK2XXX_STPL 0x01
//FCR
//SIER
#define WK2XXX_FERR_IEN 0x80
#define WK2XXX_CTS_IEN 0x40
#define WK2XXX_RTS_IEN 0x20
#define WK2XXX_XOFF_IEN 0x10
#define WK2XXX_TFEMPTY_IEN 0x08
#define WK2XXX_TFTRIG_IEN 0x04
#define WK2XXX_RXOUT_IEN 0x02
#define WK2XXX_RFTRIG_IEN 0x01
//SIFR
#define WK2XXX_FERR_INT 0x80 /* 接收FIFO数据错误中断标志位 */
#define WK2XXX_CTS_INT 0x40
#define WK2XXX_RTS_INT 0x20
#define WK2XXX_XOFF_INT 0x10
#define WK2XXX_TFEMPTY_INT 0x08 /* 发送FIFO空中断标志位 */
#define WK2XXX_TFTRIG_INT 0x04 /* 发送FIFO触点中断标志位 */
#define WK2XXX_RXOVT_INT 0x02 /* 接收FIFO超时中断标志位 */
#define WK2XXX_RFTRIG_INT 0x01 /* 接收FIFO触点中断标志位 */
//TFCNT
//RFCNT
//FSR FIFO
#define WK2XXX_RFOE 0x80 /* 子串口溢出 */
#define WK2XXX_RFBI 0x40 /* 子串口 break line */
#define WK2XXX_RFFE 0x20 /* 子串口数据帧错误 */
#define WK2XXX_RFPE 0x10 /* 子串口数据校验错误 */
#define WK2XXX_RDAT 0x08 /* 子串口接收为空 0:非空 1:空*/
#define WK2XXX_TDAT 0x04 /* 子串口发送为空 */
#define WK2XXX_TFULL 0x02 /* 子串口发送满 */
#define WK2XXX_TBUSY 0x01 /* 子串口发送忙 */
//LSR 接收状态
#define WK2XXX_OE 0x08 /* 子串口接收溢出 */
#define WK2XXX_BI 0x04 /* 子串口接收 line-break */
#define WK2XXX_FE 0x02 /* 子串口数据接收帧错误 */
#define WK2XXX_PE 0x01 /* 子串口数据接收校验错误 */
//FWCR
uint16_t WK_PortSendData(uint8_t port, const void* buf, uint16_t len);
uint16_t WK_PortRecvData(uint8_t port, void* buf, uint16_t len);
void WK_PortInit(uint8_t port, uint32_t fosc, uint32_t baudrate);
void WK_IRQHandler(void);
void WK_Rst(void);
uint8_t Wk2xxx_Test(void);
/* 切换子串口回调函数 */
// int wk2114_sub_uart_chenge_recv_fun(struct wk2114_sub_uart *sub_uart,void *recv_class,wk2114_sub_uart_recv_fun recv_fun);
#endif /* _WK2XXX_H_ */
// // #include "sys.h"
// #include "myuart.h"
// #include "main.h"
// static uint8_t init_buf=0x55;
// //如下为WK系列串口扩展芯片的寄存器地址定义,不同的芯片,可能寄存器少一些,所以具体的寄存器请看数据手册
// //wkxxxx Global rigister address defines
// #define WK2XXX_GENA 0X00
// #define WK2XXX_GRST 0X01
// #define WK2XXX_GMUT 0X02
// #define WK2XXX_GIER 0X10
// #define WK2XXX_GIFR 0X11
// #define WK2XXX_GPDIR 0X21
// #define WK2XXX_GPDAT 0X31
// #define WK2XXX_GPORT 1// /wkxxxx Global rigister of PORT
// //wkxxxx slave uarts rigister address defines
// #define WK2XXX_SPAGE 0X03
// //PAGE0
// #define WK2XXX_SCR 0X04
// #define WK2XXX_LCR 0X05
// #define WK2XXX_FCR 0X06
// #define WK2XXX_SIER 0X07
// #define WK2XXX_SIFR 0X08
// #define WK2XXX_TFCNT 0X09
// #define WK2XXX_RFCNT 0X0A
// #define WK2XXX_FSR 0X0B
// #define WK2XXX_LSR 0X0C
// #define WK2XXX_FDAT 0X0D
// #define WK2XXX_FWCR 0X0E
// #define WK2XXX_RS485 0X0F
// //PAGE1
// #define WK2XXX_BAUD1 0X04
// #define WK2XXX_BAUD0 0X05
// #define WK2XXX_PRES 0X06
// #define WK2XXX_RFTL 0X07
// #define WK2XXX_TFTL 0X08
// #define WK2XXX_FWTH 0X09
// #define WK2XXX_FWTL 0X0A
// #define WK2XXX_XON1 0X0B
// #define WK2XXX_XOFF1 0X0C
// #define WK2XXX_SADR 0X0D
// #define WK2XXX_SAEN 0X0E
// #define WK2XXX_RRSDLY 0X0F
// //WK串口扩展芯片的寄存器的位定义
// //wkxxx register bit defines
// // GENA
// #define WK2XXX_UT4EN 0x08
// #define WK2XXX_UT3EN 0x04
// #define WK2XXX_UT2EN 0x02
// #define WK2XXX_UT1EN 0x01
// //GRST
// #define WK2XXX_UT4SLEEP 0x80
// #define WK2XXX_UT3SLEEP 0x40
// #define WK2XXX_UT2SLEEP 0x20
// #define WK2XXX_UT1SLEEP 0x10
// #define WK2XXX_UT4RST 0x08
// #define WK2XXX_UT3RST 0x04
// #define WK2XXX_UT2RST 0x02
// #define WK2XXX_UT1RST 0x01
// //GIER
// #define WK2XXX_UT4IE 0x08
// #define WK2XXX_UT3IE 0x04
// #define WK2XXX_UT2IE 0x02
// #define WK2XXX_UT1IE 0x01
// //GIFR
// #define WK2XXX_UT4INT 0x08
// #define WK2XXX_UT3INT 0x04
// #define WK2XXX_UT2INT 0x02
// #define WK2XXX_UT1INT 0x01
// //SPAGE
// #define WK2XXX_SPAGE0 0x00
// #define WK2XXX_SPAGE1 0x01
// //SCR
// #define WK2XXX_SLEEPEN 0x04
// #define WK2XXX_TXEN 0x02
// #define WK2XXX_RXEN 0x01
// //LCR
// #define WK2XXX_BREAK 0x20
// #define WK2XXX_IREN 0x10
// #define WK2XXX_PAEN 0x08
// #define WK2XXX_PAM1 0x04
// #define WK2XXX_PAM0 0x02
// #define WK2XXX_STPL 0x01
// //FCR
// //SIER
// #define WK2XXX_FERR_IEN 0x80
// #define WK2XXX_CTS_IEN 0x40
// #define WK2XXX_RTS_IEN 0x20
// #define WK2XXX_XOFF_IEN 0x10
// #define WK2XXX_TFEMPTY_IEN 0x08
// #define WK2XXX_TFTRIG_IEN 0x04
// #define WK2XXX_RXOVT_IEN 0x02
// #define WK2XXX_RFTRIG_IEN 0x01
// //SIFR
// #define WK2XXX_FERR_INT 0x80
// #define WK2XXX_CTS_INT 0x40
// #define WK2XXX_RTS_INT 0x20
// #define WK2XXX_XOFF_INT 0x10
// #define WK2XXX_TFEMPTY_INT 0x08
// #define WK2XXX_TFTRIG_INT 0x04
// #define WK2XXX_RXOVT_INT 0x02
// #define WK2XXX_RFTRIG_INT 0x01
// //TFCNT
// //RFCNT
// //FSR
// #define WK2XXX_RFOE 0x80
// #define WK2XXX_RFBI 0x40
// #define WK2XXX_RFFE 0x20
// #define WK2XXX_RFPE 0x10
// #define WK2XXX_RDAT 0x08
// #define WK2XXX_TDAT 0x04
// #define WK2XXX_TFULL 0x02
// #define WK2XXX_TBUSY 0x01
// //LSR
// #define WK2XXX_OE 0x08
// #define WK2XXX_BI 0x04
// #define WK2XXX_FE 0x02
// #define WK2XXX_PE 0x01
// //FWCR
// //RS485
// //常用波特率宏定义
// #define B600 1
// #define B1200 2
// #define B2400 3
// #define B4800 4
// #define B9600 5
// #define B19200 6
// #define B38400 7
// #define B76800 8
// #define B1800 9
// #define B3600 10
// #define B7200 11
// #define B14400 12
// #define B28800 13
// #define B57600 14
// #define B115200 15
// #define B230400 16
// // typedef int (*wk2xxx_send_fun)(void *send_obj,char *buf,uint32_t size);
// typedef void (*wk2xxx_sub_uart_recv_fun)( void *recv_obj, uint8_t *buf, uint32_t size ); //< 子串口接收数据回调函数
// typedef int (*wk2xxx_send_fun)( void *send_obj, uint8_t *buf, uint32_t size ); //< wk2114发送函数
// /* 发送数据的buf size*/
// struct wk2114_send_record
// {
// uint32_t size;
// uint8_t *p_data;
// };
// /*子串口*/
// struct wk2114_sub_uart
// {
// uint8_t flag; //< 标志位
// uint8_t cmd; //< 上一次的子串口寄存器读命令
// uint8_t reg; //< 上一次接收到的子串口寄存器
// uint8_t uart_index; //< 串口地址
// void *recv_obj; //< 接收回调函数的第一个参数
// wk2xxx_sub_uart_recv_fun recv_fun; //< 接收回调函数
// uint8_t *recv_buf; //< 接收缓冲区
// uint8_t *send_buf; //< 当前发送数据指针
// uint32_t recv_buf_p; //< 接收缓冲区计数
// uint32_t recv_buf_size; //< 接收缓冲区大小
// uint32_t send_buf_p; //< 发送缓冲区计数
// struct wk2114_send_record send_record[8]; //< 发送记录
// WK2xxx_TypeDef *wk2114; //< wk2114结构指针
// };
// /*主串口 主spi*/
// typedef struct
// {
// // UART_HandleTypeDef *huart;
// uint8_t flag; //< 标志位
// uint8_t cmd; //< 上一次的全局寄存器读命令
// uint8_t reg; //< 上一次接收到的全局寄存器
// uint32_t dev_clock_hz; //< wk2114时钟源频率
// uint8_t cmd_buf[64][2]; //< 命令队列缓冲区
// uint8_t send_buf[18]; //< 发送缓冲区
// void *send_obj; //< 主spi
// wk2xxx_send_fun send;
// EXTI_HandleTypeDef *exti;
// uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/
// struct wk2114_sub_uart *sub_uart[4]; //< 子串口
// }WK2xxx_TypeDef;
// WK2xxx_TypeDef* WK2XXX_Init( void );
// void WK2xxx_EXTI_callback( WK2xxx_TypeDef *wk2xxx );
// void Wk2xxxWriteReg( unsigned char port, unsigned char reg, unsigned char dat );
// unsigned char Wk2xxxReadReg( unsigned char port, unsigned char reg );
// void Wk2xxxWriteFifo( unsigned char port,unsigned char *wbuf,unsigned int len );
// void Wk2xxxReadFifo( unsigned char port,unsigned char *rbuf,unsigned int len );
// void Wk2xxxInit( unsigned char port );
// void Wk2xxxClose( unsigned char port );
// void Wk2xxxSetBaud( unsigned char port, int baud );
// unsigned int Wk2xxxGetBuf( unsigned char port,unsigned char *getbuf );
// unsigned int Wk2xxxSendBuf( unsigned char port,unsigned char *sendbuf,unsigned int len );
// extern void WK2XXX_SPI_Init(void);
// extern void WK2XXX_Reset_Init(void);
// extern void WK2XXX_RST_Init(void);

File diff suppressed because it is too large Load Diff

@ -247,6 +247,7 @@ int IIC_Send_Receive_One_Reg_Value( const IIC_SOFT_TypeDef *pSoftIIC, uint32_t*
{
IIC_Send_Byte(pSoftIIC,*buf);
if(IIC_Wait_Ack(pSoftIIC)) { IIC_Stop(pSoftIIC); return -1;};
*buf++;
}
IIC_Stop(pSoftIIC);//产生一个停止条件

File diff suppressed because it is too large Load Diff

@ -13,10 +13,11 @@ const osEventFlagsAttr_t PH_Event_attributes = {
.name = "PH_Event"
};
extern UART_HandleTypeDef huart3;
UART_HandleTypeDef *pPHUart = &huart3;
extern UART_HandleTypeDef huart1;
UART_HandleTypeDef *pPHUart = &huart1;
uint8_t PH_TEST_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
// uint8_t PH_TEST_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
uint8_t PH_TEST_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
uint8_t PH_TRANS_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
uint8_t PH_RCV_BUF[13] ={0};
@ -128,6 +129,10 @@ void PH_Task( )
continue;
case PH_State_Test_Start:
UART_HELPER_Set_Trans_Buf( ph_uart_helper, PH_TEST_BUF, sizeof(PH_TEST_BUF) );
// HAL_UARTEx_ReceiveToIdle_DMA(&huart1, PH_RCV_BUF,13);
// __HAL_UART_ENABLE_IT( &huart1, UART_IT_IDLE );
// HAL_UART_Receive_DMA( &huart1, PH_RCV_BUF, 13 );
PH_Receive();
PH_Transmit();
ticks = osKernelGetTickCount();
@ -201,7 +206,7 @@ void PH_Task( )
osDelay(10);
continue;
case PH_State_Stop:
log_d(" ph stop, aftetr deal, change to ready....");
log_d(" ph stop, aftetr deal, wait to change status....");
osDelay(10);
continue;
@ -263,6 +268,7 @@ int PH_Transmit()
int PH_Receive()
{
return UART_HELPER_Start_Rcv(ph_uart_helper, ph_uart_helper->rcv_buf, ph_uart_helper->rcv_size);
// return UART_HELPER_Start_Rcv(ph_uart_helper, PH_RCV_BUF, 13);
// return 0;
}
@ -273,7 +279,7 @@ void PH_Set_Timeout_ms( uint64_t ms_ticks )
int PH_Validate( )
{
return 0;
return CRC16_Check(ph.result_buf ,ph.size_received);
}
@ -296,7 +302,7 @@ int PH_CallBack( PH_TypeDef *pPH, uint8_t *buf, uint16_t size )
{
size_tmp = sizeof(ph.result_buf) - ph.size_received;
}
memcpy( (uint32_t)(ph.result_buf+ph.size_received), ph_uart_helper->rcv_buf,size_tmp);
memcpy( (uint32_t)(ph.result_buf+ph.size_received), ph_uart_helper->rcv_buf, size_tmp );
ph.size_received += size_tmp;
if ( ph_uart_helper->enable_idle_it == 0 )

@ -0,0 +1,279 @@
#include "ramses.h"
#include "elog.h"
/* 进一步对RAMSES 信息进行处理 */
// /**
// * @brief 获取转换后的光谱数据
// *
// * @param trios_ramses 设备描述符
// * @param data 数据缓冲区
// * @param num 缓冲区长度
// * @return uint32_t 成功:数据长度 失败:0xffffffff
// */
// uint32_t trios_ramses_get_data(struct trios_ramses *trios_ramses,int16_t *data,uint32_t num)
// {
// int i;
// int j;
// uint8_t endian_mask;
// endian_mask=endian_get_local_endian_mask(ENDIAN_MASK_LITTLE_ENDIAN);
// if(num<(TRIOS_RAMSES_DATA_SIZE-8)*TRIOS_RAMSES_DATA_NUM/2)
// {
// return 0;
// }
// if((trios_ramses->flag&TRIOS_RAMSES_FLAG_MASK_RECVED_DATA)==0){
// return 0;
// }
// for(i=0,j=0;i<TRIOS_RAMSES_DATA_NUM;i++){
// if(endian_write(endian_mask,ENDIAN_WIDTH_MASK_2BYTE,&((uint8_t*)data)[j],trios_ramses->data[i].data,trios_ramses->data[i].data_size)!=0){
// trios_ramses_clean_data_recved_flag(trios_ramses);
// return 0xffffffff;
// }
// j+=trios_ramses->data[i].data_size;
// }
// return j/2;
// }
// /**
// * @brief 获取X轴倾斜角度
// *
// * @param trios_ramses 设备描述符
// * @param incl_xgain 标定数据
// * @param incl_xoffset 标定数据
// * @return double 成功:X轴倾角 失败:NAN
// */
// double trios_ramses_get_x_inclination_angle(struct trios_ramses *trios_ramses,double incl_xgain,double incl_xoffset)
// {
// if((trios_ramses->flag&TRIOS_RAMSES_FLAG_MASK_RECVED_IP)==0){
// return NAN;
// }
// return (trios_ramses->ip.data[4]-incl_xoffset)*incl_xgain;
// }
// /**
// * @brief 获取Y轴倾斜角度
// *
// * @param trios_ramses 设备描述符
// * @param incl_ygain 标定数据
// * @param incl_yoffset 标定数据
// * @return double 成功:Y轴倾角 失败:NAN
// */
// double trios_ramses_get_y_inclination_angle(struct trios_ramses *trios_ramses,double incl_ygain,double incl_yoffset)
// {
// if((trios_ramses->flag&TRIOS_RAMSES_FLAG_MASK_RECVED_IP)==0){
// return NAN;
// }
// return (trios_ramses->ip.data[5]-incl_yoffset)*incl_ygain;
// }
// /**
// * @brief 获取设备倾角
// *
// * @param x_inclination_angle X轴倾角
// * @param y_inclination_angle Y轴倾角
// * @return double 成功:设备倾角 失败:NAN
// */
// double trios_ramses_get_inclination_angle(double x_inclination_angle,double y_inclination_angle)
// {
// if(x_inclination_angle==NAN || y_inclination_angle==NAN){
// return NAN;
// }
// return atan(sqrt(pow(tan(x_inclination_angle*M_PI/180),2)+pow(tan(y_inclination_angle*M_PI/180),2)));
// }
// /**
// * @brief 获取压力
// *
// * @param trios_ramses 设备描述符
// * @param incl_kref 标定数据
// * @param incl_kbg 标定数据
// * @param press_gain 标定数据
// * @param press_surface_bar 标定数据
// * @param press_sens_mv_bar_1ma 标定数据
// * @param press_sens_mv_bar_4ma 标定数据
// * @return double 压力
// */
// double trios_ramses_get_pressure(struct trios_ramses *trios_ramses,double incl_kref,double incl_kbg,double press_gain,double press_surface_bar,double press_sens_mv_bar_1ma,double press_sens_mv_bar_4ma)
// {
// uint16_t npress;
// uint16_t nbg;
// uint16_t nrefh;
// uint16_t nrefl;
// double noffset;
// double press_sens;
// double vpress_v;
// double p_bar;
// if((trios_ramses->flag&TRIOS_RAMSES_FLAG_MASK_RECVED_IP)==0){
// return NAN;
// }
// npress=((uint16_t)trios_ramses->ip.data[7]<<8)+trios_ramses->ip.data[6];
// nbg=((uint16_t)trios_ramses->ip.data[11]<<8)+trios_ramses->ip.data[10];
// nrefh=((uint16_t)trios_ramses->ip.data[13]<<8)+trios_ramses->ip.data[12];
// nrefl=((uint16_t)trios_ramses->ip.data[15]<<8)+trios_ramses->ip.data[14];
// noffset=nrefl-(incl_kref*(nrefh-nrefl));
// vpress_v=incl_kbg*(npress-noffset)/(nbg-noffset);
// press_sens=(press_sens_mv_bar_4ma<=0?press_sens_mv_bar_1ma:press_sens_mv_bar_4ma);
// p_bar=1000.0*vpress_v/(press_sens*press_gain);
// return p_bar-1.021;
// }
// /**
// * @brief 获取深度(米)
// *
// * @param pressure 压力
// * @return double 成功:深度 失败:NAN
// */
// double trios_ramses_get_depth_m(double pressure)
// {
// if(pressure==NAN){
// return NAN;
// }
// return pressure*10;
// }
// /**
// * @brief 获取设备序列号
// *
// * @param trios_ramses 设备描述符
// * @return uint16_t 成功:设备序列号 失败:0xffff
// */
// uint16_t trios_ramses_get_serial_number(struct trios_ramses *trios_ramses)
// {
// if((trios_ramses->flag&TRIOS_RAMSES_FLAG_MASK_RECVED_INFO)==0){
// return 0xffff;
// }
// return trios_ramses->infomation.serial_number;
// }
// extern int Ramses_Deal_Data_Frame(Ramses_TypeDef *pRamses, uint8_t *buf, uint16_t size);
// int Ramses_Deal_Data_Frame(Ramses_TypeDef *pRamses, uint8_t *buf, uint16_t size)
// {
// int i;
// int j = 0;
// for(i=0;i<size;i++){
// log_i("recv_buf i %d %02X, recv_buf_p %d",i, buf[i], ramses.recv_buf_p);
// if ( ramses.recv_buf_p==0 && buf[i]!=0x23 ){ // 下标为0,找0x23 可以过滤0x13 0x11
// log_i("recv_buf i 0x23" );
// continue;
// }
// if(ramses.recv_flag_40==1){
// if(buf[i]==0x64){
// ramses.recv_buf[ramses.recv_buf_p++]=0x40;
// }
// else if(buf[i]==0x65){
// ramses.recv_buf[ramses.recv_buf_p++]=0x23;
// }
// else if(buf[i]==0x66){
// ramses.recv_buf[ramses.recv_buf_p++]=0x11;
// }
// else if(buf[i]==0x67){
// ramses.recv_buf[ramses.recv_buf_p++]=0x13;
// }
// else{
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// ramses.recv_flag_40=0;
// }
// else if(buf[i]==0x40){
// ramses.recv_flag_40=1;
// }
// else{ // 每帧 recv_buf中的 数组下标
// // log_i("buf[i] -> %d %02X" ,i, buf[i]);
// ramses.recv_buf[ramses.recv_buf_p++]=buf[i];
// j++ ;
// }
// // 每帧数据数量 大于7 判断类型,且长度校验通过
// if(ramses.recv_buf_p>7 && ramses.recv_buf_p==8+(2<<(ramses.recv_buf[1]>>5))){
// // j++ ;
// if(ramses.recv_buf[4]==0xff){ // 0xff 表征 SN信息帧
// log_i(" info frame .... ") ;
// if(ramses.recv_buf_p!=Ramses_INFO_SIZE){
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// ramses.information.dev_id=((uint16_t)ramses.recv_buf[1]<<8)+ramses.recv_buf[2];
// ramses.information.module_id=ramses.recv_buf[3];
// ramses.information.serial_number=((uint16_t)ramses.recv_buf[8]<<8)+ramses.recv_buf[7];
// ramses.information.firmware_number[0]=ramses.recv_buf[10];
// ramses.information.firmware_number[1]=ramses.recv_buf[9];
// memcpy(ramses.information.individual_information,&ramses.recv_buf[7],Ramses_INFO_SIZE-12);
// ramses.recv_buf_p=0;
// ramses.flag|=Ramses_FLAG_MASK_RECVED_INFO;
// ramses.flag&=~Ramses_FLAG_MASK_BUSY;
// }
// else if(ramses.recv_buf[4]==0xfe){ // 0xfe错误
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// else{
// if(ramses.recv_buf[3]==0x80 || ramses.recv_buf[3]==0x30 || ramses.recv_buf[3]==0x00){
// // log_i(".... 0x80 0x 30 0x00");
// if((ramses.flag&Ramses_FLAG_MASK_RECVED_DATA)!=0){ // 判断为数据帧
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// if(ramses.recv_buf_p!=Ramses_DATA_SIZE){
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// if(ramses.recv_buf[4]!=Ramses_DATA_NUM-1-ramses.data_index){
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// memcpy(ramses.data[ramses.data_index].raw,ramses.recv_buf,Ramses_DATA_SIZE);
// ramses.data[ramses.data_index].dev_id=((uint16_t)ramses.recv_buf[1]<<8)+ramses.recv_buf[2];
// ramses.data[ramses.data_index].module_id=ramses.recv_buf[3];
// ramses.data[ramses.data_index].framebyte=ramses.recv_buf[4];
// ramses.data[ramses.data_index].data=&ramses.data[ramses.data_index].raw[7];
// ramses.data[ramses.data_index].data_size=Ramses_DATA_SIZE-8;
// ramses.data_index++;
// ramses.recv_buf_p=0;
// if(ramses.data_index==Ramses_DATA_NUM){
// ramses.data_index=0;
// ramses.flag|=Ramses_FLAG_MASK_RECVED_DATA;
// ramses.flag&=~Ramses_FLAG_MASK_BUSY;
// }
// }
// else if(ramses.recv_buf[3]==0x20){
// if((ramses.flag&Ramses_FLAG_MASK_RECVED_IP)!=0){ // 判断为IP帧
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// if(ramses.recv_buf_p!=Ramses_IP_SIZE){
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// memcpy(ramses.ip.raw,ramses.recv_buf,Ramses_IP_SIZE);
// ramses.ip.dev_id=((uint16_t)ramses.recv_buf[1]<<8)+ramses.recv_buf[2];
// ramses.ip.module_id=ramses.recv_buf[3];
// ramses.ip.framebyte=ramses.recv_buf[4];
// ramses.ip.data=&ramses.ip.raw[7];
// ramses.ip.data_size=Ramses_IP_SIZE-8;
// ramses.recv_buf_p=0;
// ramses.flag|=Ramses_FLAG_MASK_RECVED_IP;
// }
// else{
// ramses.data_index=0;
// ramses.recv_flag_40=0;
// ramses.recv_buf_p=0;
// continue;
// }
// }
// }
// }
// log_i("cb i %d j %d",i,j);
// return 0;
// }

@ -1,273 +1,250 @@
#include "sc6.h"
#include "elog.h"
#include "FreeRTOS.h"
#include "cmsis_os.h"
#include "usart.h"
/****** Port ***************/
#if 1
My_SC6_TypeDef mysc6 =
{
SC6_Init,
SC6_Port,
SC6_Set_State,
// SEL_232_485_GPIO_Port,
// HDPLX_GPIO_Port,
// DE485_GPIO_Port,
// SEL_232_485_Pin,
// HDPLX_Pin,
// DE485_Pin,
NULL,
NULL,
NULL,
0,
0,
0,
Uart_Interface_Default, /* 接口类型 0: common, 1: 485 ,2:3160*/
Uart_RSMODE_232, /* mode_232_485 0 commome 1:485*/
Uart_Trans_DMA, /* trans_type0 :polling, 1: IT 2: DMA*/
Uart_Trans_DMA, /* rcv_type 0 :polling, 1: IT 2: DMA*/
Uart_IDLE_IT_ENABLE, /* idle_enable_disable 0 :不启用空闲 , 1: 启用空闲*/
NULL, /* pointer huart*/
osThreadId_t SC6_Handle;
const osThreadAttr_t SC6_attributes = {
.name = "SC6",
.stack_size = 1024,
.priority = (osPriority_t) osPriorityBelowNormal,
};
UART_HandleTypeDef *psc6Uart = &huart2;
#define SC6_Uart_IRQHandler USART2_IRQHandler
// 事件
osEventFlagsId_t SC6_EventHandle;
const osEventFlagsAttr_t SC6_Event_attributes = {
.name = "SC6_Event"
};
extern volatile uint8_t measure_flag;
SC6_TypeDef *sc6;
extern UART_HandleTypeDef huart1;
UART_HandleTypeDef *pSC6Uart = &huart1;
static uint8_t start_buf[8] = { 0x52, 0x45, 0x53, 0x55, 0x4D, 0x45, 0x0D, 0x0A }; /* RESUME\r\n*/
static uint8_t stop_buf[7] = { 0x50, 0x41, 0x55, 0x53, 0x45, 0x0D, 0x0A }; /* PAUSE\r\n*/
static uint8_t SC6_TRANS_BUF[8] = { 0x52, 0x45, 0x53, 0x55, 0x4D, 0x45, 0x0D, 0x0A };
static uint8_t SC6_start_buf[8] = { 0x52, 0x45, 0x53, 0x55, 0x4D, 0x45, 0x0D, 0x0A }; /* RESUME\r\n*/
static uint8_t SC6_stop_buf[7] = { 0x50, 0x41, 0x55, 0x53, 0x45, 0x0D, 0x0A }; /* PAUSE\r\n*/
static uint8_t start_rcv_buf[12] = { 0x52, 0x45, 0x53, 0x55, 0x4D, 0x45, 0x44, 0x2E, 0x2E, 0x2E, 0x0D, 0x0A }; /* RESUMED...\r\n*/
static uint8_t stop_rcv_buf[11] = { 0x50, 0x41, 0x55, 0x53, 0x45, 0x44, 0x2E, 0x2E, 0x2E, 0x0D, 0x0A }; /* PAUSED...\r\n*/
static uint8_t SC6_start_rcv_buf[12] = { 0x52, 0x45, 0x53, 0x55, 0x4D, 0x45, 0x44, 0x2E, 0x2E, 0x2E, 0x0D, 0x0A }; /* RESUMED...\r\n*/
static uint8_t SC6_stop_rcv_buf[11] = { 0x50, 0x41, 0x55, 0x53, 0x45, 0x44, 0x2E, 0x2E, 0x2E, 0x0D, 0x0A }; /* PAUSED...\r\n*/
// uint8_t SC6_Data_Buf[SC6_Rcv_Buf_Size*2] = {0};
static uint8_t data_start_tag[7] = {0x53, 0x43, 0x36 ,0x2d , 0x4c , 0x50 , 0x54}; //, "SC6-LPT"
static uint8_t data_end_tag[2] = {0x0D, 0x0A};
// uint8_t SC6_sn_buf[15] = {0};
// uint8_t SC6_rcvbuf[2][SC6_Rcv_Buf_Size] = {0};
static uint8_t SC6_Rcv_Buf[ 2* SC6_Result_Buf_Size ] = {0};
osThreadId_t sc6Handle;
const osThreadAttr_t SC6_attributes = {
.name = "sc6",
.stack_size = 1024,
.priority = (osPriority_t)osPriorityBelowNormal,
static uint8_t SC6_RCV_BUF[ 2* SC6_Result_Buf_Size ] = {0};
UART_HELPER_TypeDef *SC6_uart_helper;
SC6_TypeDef sc6 ={
SC6_Init,
SC6_Port,
SC6_Test,
SC6_Start,
SC6_Stop,
NULL,
0, // state
0, // data_ok
{0}, // buf
0, // size_received
0, // time base
1000, // timeout ticks, 1000ms = 1S
0, // event_flag
{0},
{0},
{0},
0xFFFF,
};
void SC6_Uart_IRQHandler(void)
int SC6_Init( )
{
uint16_t count = 0;
uint16_t data_length = 0;
if (__HAL_UART_GET_FLAG(psc6Uart, UART_FLAG_TC) != RESET)
{
log_i("SC6_.... TC IT ...");
// sc6->uarthelper ->status = Uart_Status_Send_Cplt ;
// SC6_Set_UartHelper_Status( sc6, Uart_Status_Send_Cplt);
SC6_Set_GPIO_For_TC_Cplt(sc6);
sc6->uarthelper->huart->gState = HAL_UART_STATE_READY;
// psc6Uart->gState = HAL_UART_STATE_READY;
// UartHelper_Trans_Cplt_Callback( sc6->uarthelper );
// log_i("Send SC6_Uart_IRQHandler-> interface_type %d, 232-485 %d , sel: %d ,de485 %d , duplx %d "
// ,sc6->uarthelper->interface->interface_type
// ,sc6->uarthelper->interface->mode_232_485
// ,HAL_GPIO_ReadPin(sc6->uarthelper->interface->sel_gpio,sc6->uarthelper->interface->sel_pin)
// ,HAL_GPIO_ReadPin(sc6->uarthelper->interface->de485_gpio,sc6->uarthelper->interface->de485_pin)
// ,HAL_GPIO_ReadPin(sc6->uarthelper->interface->dplx_gpio,sc6->uarthelper->interface->dplx_pin)
// );
// sc6->status = Uart_Status_Send_Cplt;
// huart3.gState = HAL_UART_STATE_READY;
__HAL_UART_CLEAR_FLAG(sc6->uarthelper->huart, UART_FLAG_TC);
}
SC6_uart_helper = UART_HELPER_Init( );
if (__HAL_UART_GET_FLAG(psc6Uart, UART_FLAG_IDLE) != RESET )
{
log_i("SC6_.... IDLE IT .... ");
// TODO ...处理空闲 ,最后一位 datalength-1
if (SC6_uart_helper ==NULL) return -1;
count = __HAL_DMA_GET_COUNTER(sc6->uarthelper->huart->hdmarx);
data_length = 2* SC6_Result_Buf_Size - count;
if (data_length > 0)
{
log_i("SC6_. IDLE..data_length %d", data_length);
SC6_copy(sc6, data_length);
// log_i("SC6_. IDLE..res %02X %d %02X", sc6->uarthelper ->receive_buf[0], sc6->uarthelper ->receive_buf[2], sc6->uarthelper ->receive_buf[data_length-1]);
}
__HAL_UART_CLEAR_IDLEFLAG(psc6Uart);
}
// TODO 接口
UART_HELPER_Set_Huart( SC6_uart_helper, pSC6Uart );
UART_HELPER_Set_Interface_Type(SC6_uart_helper, Uart_Interface_Max3160_485);
if (__HAL_UART_GET_FLAG(psc6Uart, UART_FLAG_ORE) != RESET)
{
log_i("SC6_....ORE");
// 传输
UART_HELPER_Setup_Trans_mode( SC6_uart_helper, Uart_Trans_DMA);
// UART_HELPER_Setup_Rcv_mode( SC6_uart_helper, Uart_Trans_IT );
UART_HELPER_Set_enable_idle( SC6_uart_helper, Uart_IDLE_IT_ENABLE);
__HAL_UART_CLEAR_FLAG(psc6Uart, UART_FLAG_ORE);
}
if (__HAL_UART_GET_FLAG(psc6Uart, UART_FLAG_FE) != RESET)
{
log_i("SC6_....FE");
// 回调GPIO 操作 数据操作
UART_HELPER_Set_trans_GPIO( SC6_uart_helper, SC6_Trans_GPIO ); // enbale rcv
UART_HELPER_Set_trans_cplt_GPIO( SC6_uart_helper, SC6_Trans_Cplt_GPIO );
__HAL_UART_CLEAR_FLAG(psc6Uart, UART_FLAG_FE);
}
if (__HAL_UART_GET_FLAG(psc6Uart, UART_FLAG_PE) != RESET)
{
log_i("SC6_....PE");
UART_HELPER_Set_Callback( SC6_uart_helper,&sc6, SC6_CallBack );
__HAL_UART_CLEAR_FLAG(psc6Uart, UART_FLAG_PE);
}
HAL_UART_IRQHandler(psc6Uart);
}
// 设置 Buf
UART_HELPER_Set_Rcv_Buf(SC6_uart_helper, SC6_RCV_BUF, sizeof(SC6_RCV_BUF));
UART_HELPER_Set_Trans_Buf( SC6_uart_helper, SC6_TRANS_BUF, sizeof(SC6_TRANS_BUF) );
int SC6_copy(SC6_TypeDef *sc6 ,uint16_t size)
{
log_i( "*** SC6_ copy state %d size :%d size_rcv %d ", sc6->state,size,sc6->size_received );
// log_i( "SC6_ idle copy %02x %02x %02x %02x ", SC6_Rcv_Buf[0], SC6_Rcv_Buf[1], SC6_Rcv_Buf[11], SC6_Rcv_Buf[size-1]);
if ( sc6->state == MODULE_SC6_STATE_CHECK_DATA )
// GPIO 操作
switch (SC6_uart_helper->interface_type)
{
__disable_irq();
memcpy(sc6->SC6_Data_Buf , sc6->uarthelper->receive_buf, size);
__enable_irq();
sc6->size_received = sc6->size_received + size;
log_w("SC6_. copy after %02X %02X %02X %02X %d %d"
, sc6->SC6_Data_Buf[0], sc6->SC6_Data_Buf[12], sc6->SC6_Data_Buf[13], sc6->SC6_Data_Buf[sc6->size_received-1]
, size,sc6->size_received);
return 0;
case Uart_Interface_Default:
break;
case Uart_Interface_485:
usart6_send_enable();
break;
case Uart_Interface_Max3160_232:
SC6_MAX3160_232();
break;
case Uart_Interface_Max3160_485:
max3160_485_receive_mode();
break;
default:
break;
}
return 0;
sc6.state = SC6_State_Waiting;
sc6.timebase_ticks = osKernelGetTickCount( );
}
void SC6_Set_State( MODULE_SC6_WORK_STATE state )
void SC6_Port( )
{
// log_i( "Set_State...sc6->state .%d ", sc6->state);
sc6->state = state;
SC6_Handle = osThreadNew( SC6_Task, NULL, &SC6_attributes );
// SC6_EventHandle = osEventFlagsNew(&SC6_Event_attributes);
}
uint8_t SC6_Init()
int SC6_Test( )
{
sc6.state = SC6_State_Test; // 操作状态
return 0;
}
sc6 = (SC6_TypeDef *)malloc(sizeof(SC6_TypeDef));
UartInterface_TypeDef *interface = UartInterface_Init( );
UartHelper_TypeDef *uarthelper = UartHelper_Init();
SC6_Set_Uarthelper( sc6, uarthelper );
SC6_Set_Interface( sc6, interface );
SC6_Set_Huart( sc6, psc6Uart );
/* set_GPIO UartInterface */
UartInterface_Set_Sel_GPIO_Pin( sc6->uarthelper->interface, mysc6.sel_gpio, mysc6.sel_pin );
UartInterface_Set_Dplx_GPIO_Pin( sc6->uarthelper->interface, mysc6.dplx_gpio, mysc6.dplx_pin );
UartInterface_Set_DE485_GPIO_Pin( sc6->uarthelper->interface, mysc6.de_gpio, mysc6.de_pin );
/* interface type */
SC6_Set_Interface_Type( sc6, mysc6.interface_type );
SC6_Set_RsMode_232_485 ( sc6, mysc6.mode_232_485 ); // max3160 的232 485选择
SC6_Set_Trans_Type( sc6, mysc6.trans_type ) ;
SC6_Set_Rcv_Type ( sc6, mysc6.rcv_type ) ;
SC6_Set_Idle_Enable (sc6, mysc6.idle_enable_disable ) ;
// UartHelper_Setup_Interface_type( sc6 ,mysc6.interface_type);
void SC6_Start( )
{
sc6.state = SC6_State_Start; // 操作状态
// check
if ( sc6->uarthelper->huart == psc6Uart ){
log_i ( "sc6 set huart ok. trans_type -> %d rcv_type -> %d ( 0 :polling, 1: IT 2: DMA) ",sc6->trans_type ,sc6->rcv_type ) ;
log_i( " interface-> %d %d (0:default, 1:485, 2:3160) " ,sc6->uarthelper->interface_type ,sc6->uarthelper->interface->interface_type );
log_i( "sc6 232_485 -> %d %d (0:232 ,1: 485) " ,sc6->uarthelper->mode_232_485, sc6->uarthelper->interface->mode_232_485 );
}else{
log_e ( "sc6 set huart failure " ) ;
}
// sc6 send rcv buf 是动态的
SC6_Set_Timeout( sc6, 1000 );
// SC6_Set_Sendbuf( sc6, SC6_SND_Buf, 8 );
// SC6_Set_Rcvbuf( sc6, SC6_RCV_Buf, sizeof(SC6_RCV_Buf) );
// set paras;
sc6->timebase = 0;
// sc6->timeout_ms = 1000;
sc6->send_status = Uart_Status_Ready;
sc6->send_flag = 0;
sc6->command_seq = 4;
// sc6->mode = 2;
// sc6->data_begin_flag = 0;
sc6->state = MODULE_SC6_STATE_WAIT;
return 0;
}
void SC6_Port()
void SC6_Stop( )
{
sc6Handle = osThreadNew(SC6_Task, (void*)(&sc6->state), &SC6_attributes);
sc6.state = SC6_State_Stop;
// TODO stop task?
}
void SC6_Task(void* argument)
void SC6_Task( )
{
MODULE_SC6_WORK_STATE *state = argument;
// FLAG 发送后进入 busy, 接收sn后就rcved_flag
for (;;)
{
// log_i( " SC6_ state %d " , *state );
switch (*state)
// memset( SC6_RCV_Buf, 0, 2*SC6_Rcv_Buf_Size ); /* ph*3 ph *2 否则内存泄漏 */
sc6.event_flag = 0;
static uint64_t ticks;
static int err_con = 0;
static int st;
for ( ; ; )
{
switch (sc6.state)
{
case MODULE_SC6_STATE_WAIT:
case SC6_State_Waiting:
log_i( " SC6_ task..... : %d %d " , sc6.state , sc6.state );
osDelay(20);
break;
case MODULE_SC6_STATE_START:
log_i( " SC6_Task start %d " , *state );
sc6->timebase = osKernelGetTickCount();
sc6->flag |= SC6_FLAG_MASK_BUSY;
sc6->uarthelper->huart->gState = HAL_UART_STATE_READY;
HAL_UART_DMAStop(sc6->uarthelper->huart );
memset(SC6_Rcv_Buf, 0, sizeof(SC6_Rcv_Buf));
UartHelper_Set_rcv_buf(sc6->uarthelper , SC6_Rcv_Buf, sizeof(SC6_Rcv_Buf));
sc6->size_received = 0;
sc6->index_SC6_LPT = 0;
UartHelper_Set_Trans_Buf( sc6->uarthelper , start_buf, sizeof(start_buf) );
// SC6_Begin_Rcv( sc6, sc6->uarthelper->receive_buf, 2 * sc6->uarthelper->receive_buf_half_len );
SC6_Begin_Rcv( sc6, SC6_Rcv_Buf, sizeof(SC6_Rcv_Buf) );
int st =SC6_Transmit(sc6, sc6->uarthelper->trans_buf, sc6->uarthelper ->trans_size);
log_w(" st :%d %d" ,st , sc6->uarthelper->huart->gState),
*state=MODULE_SC6_STATE_CHECK_DATA;
break;
case SC6_State_Test:
log_d( " SC6_ test ... " );
ticks = osKernelGetTickCount();
sc6.size_received = 0;
sc6.index_SC6_LPT = 0xFFFF;
sc6.state = SC6_State_Test_Data_Getting;
ticks = osKernelGetTickCount();
UART_HELPER_Set_Trans_Buf( SC6_uart_helper, SC6_TRANS_BUF, sizeof(SC6_TRANS_BUF) );
SC6_Receive();
SC6_Transmit();
case MODULE_SC6_STATE_CHECK_DATA:
log_i( " SC6_Task check %d rcvsize %d sc6->index_SC6_LPT %d" , *state ,sc6->size_received,sc6->index_SC6_LPT);
log_i( " SC6_Task %s " , sc6->SC6_Data_Buf );
// find SC6_LPT
if ( sc6->index_SC6_LPT==0 && sc6->size_received > 2*SC6_Rcv_Buf_Size +SC6_RESUMED_Buf_Size)
sc6.state = SC6_State_Test_Data_Getting;
continue;
case SC6_State_Test_Data_Getting:
if ( osKernelGetTickCount() - ticks > 2000 )
{
sc6->error++;
if( sc6->error > 2)
err_con++;
if( err_con >3)
{
HAL_UART_DMAStop(sc6->uarthelper ->huart );
*state=MODULE_SC6_STATE_ERROR;;
sc6->size_received = 0;
sc6->index_SC6_LPT =0;
sc6->error = 0;
log_w( " SC6_ Test data gettting ... error " );
sc6.state = SC6_State_Error;
}
sc6.state = SC6_State_Test;
}
osDelay(1);
continue;
case SC6_State_Test_OK:
HAL_UART_DMAStop(SC6_uart_helper->huart );
sc6.state = SC6_State_Error;
sc6.size_received = 0;
sc6.index_SC6_LPT =0xFFFF;
err_con = 0;
sc6.state = SC6_State_Ready;
continue;
case SC6_State_Ready:
osDelay(1);
continue;
case SC6_State_Start:
ticks = osKernelGetTickCount();
sc6.size_received = 0;
sc6.index_SC6_LPT = 0xFFFF;
sc6.state = SC6_State_Start_Trans;
continue;
case SC6_State_Start_Trans:
UART_HELPER_Set_Trans_Buf( SC6_uart_helper, SC6_TRANS_BUF, sizeof(SC6_TRANS_BUF) );
// HAL_UARTEx_ReceiveToIdle_DMA(&huart1, SC6_RCV_BUF,13);
// __HAL_UART_ENABLE_IT( &huart1, UART_IT_IDLE );
// HAL_UART_Receive_DMA( &huart1, SC6_RCV_BUF, 13 );
SC6_Receive();
SC6_Transmit();
ticks = osKernelGetTickCount();
err_con = 0;
sc6.state = SC6_State_Check_Data;
continue;
// case SC6_State_Data_Getting:
// if ( osKernelGetTickCount() - ticks > 2000 )
// {
// err_con++;
// if( err_con >3)
// {
// log_w( " SC6_ gettting ... error " );
// sc6.state = SC6_State_Error;
// }
// sc6.state = SC6_State_Start_Trans;
// }
// osDelay(1);
// continue;
case SC6_State_Check_Data:
// log_d( " SC6_ _Check_Data %d size_received %d sc6.index_SC6_LPT site -> %d" ,
// sc6.state ,sc6.size_received, sc6.index_SC6_LPT );
// log_d( " SC6_Task %s " , sc6.SC6_Data_Buf );
// find begin tag "SC6_LPT" ,index_SC6_LPT 为出现 "SC6_LPT" 的位置编号
if ( sc6.index_SC6_LPT==0xFFFF && sc6.size_received > 2*SC6_Rcv_Buf_Size +SC6_RESUMED_Buf_Size)
{
log_d( " SC6_Task check ....bytes overflow " );
err_con++;
if( err_con > 2)
{
HAL_UART_DMAStop(SC6_uart_helper->huart );
sc6.state = SC6_State_Error;
sc6.size_received = 0;
sc6.index_SC6_LPT =0xFFFF;
err_con = 0;
break;
}
// 重新测量
log_w( " SC6_ Get Data Error %d, Retrying...",sc6->error );
HAL_UART_DMAStop(sc6->uarthelper ->huart );
log_w( " SC6_ Get Data Error %d, Retrying...", err_con );
HAL_UART_DMAStop(SC6_uart_helper->huart );
}
sc6->index_SC6_LPT = 0;
// if ( sc6->index_SC6_LPT==0 && sc6->size_received <= 2*SC6_Rcv_Buf_Size +SC6_RESUMED_Buf_Size && sc6->size_received!=0)
if ( sc6->index_SC6_LPT==0 && sc6->size_received!=0)
sc6.index_SC6_LPT = 0xFFFF;
// if ( sc6.index_SC6_LPT==0xFFFF && sc6.size_received <= 2*SC6_Rcv_Buf_Size +SC6_RESUMED_Buf_Size && sc6.size_received!=0)
if ( sc6.index_SC6_LPT==0xFFFF && sc6.size_received!=0 )
{
for (size_t i = 0; i < sc6->size_received; i++)
// log_d( " SC6_Task check .... " );
for (size_t i = 0; i < sc6.size_received; i++)
{
if (sc6->SC6_Data_Buf[i] == data_start_tag[0] )
if (sc6.result_buf[i] == data_start_tag[0] )
{
log_i( " ....i %d %02X %02X", i ,data_start_tag[0], sc6->SC6_Data_Buf[i] );
if ( sc6->SC6_Data_Buf[i+1] == data_start_tag[1] && sc6->SC6_Data_Buf[i+2] == data_start_tag[2]
&& sc6->SC6_Data_Buf[i+3] == data_start_tag[3] && sc6->SC6_Data_Buf[i+4] == data_start_tag[4]
&& sc6->SC6_Data_Buf[i+5] == data_start_tag[5] && sc6->SC6_Data_Buf[i+6] == data_start_tag[6])
// log_d( " ....i %d %02X %02X", i ,data_start_tag[0], sc6.result_buf[i] );
if ( sc6.result_buf[i+1] == data_start_tag[1] && sc6.result_buf[i+2] == data_start_tag[2]
&& sc6.result_buf[i+3] == data_start_tag[3] && sc6.result_buf[i+4] == data_start_tag[4]
&& sc6.result_buf[i+5] == data_start_tag[5] && sc6.result_buf[i+6] == data_start_tag[6])
{
sc6->index_SC6_LPT = i;
sc6.index_SC6_LPT = i;
break;
}
@ -275,232 +252,180 @@ void SC6_Task(void* argument)
}
}
if ( sc6->index_SC6_LPT!=0 )
if ( sc6.index_SC6_LPT!=0xFFFF )
{
// log_w( " SC6_LPT was found %d %d %d " ,sc6->size_received,sc6->index_SC6_LPT,SC6_Rcv_Buf_Size );
// log_w( " SC6_LPT %02X %02X %02X %02X"
// ,sc6->SC6_Data_Buf[0] ,sc6->SC6_Data_Buf[12], sc6->SC6_Data_Buf[13],sc6->SC6_Data_Buf[309]);
// log_w( " SC6_LPT %02X %02X %02X %02X"
// ,sc6->SC6_Data_Buf[306] ,sc6->SC6_Data_Buf[307], sc6->SC6_Data_Buf[308],sc6->SC6_Data_Buf[309]);
// TODO 拷贝后数据 。。。
if ( (sc6->size_received - sc6->index_SC6_LPT >= SC6_Result_Buf_Size)
&& sc6->SC6_Data_Buf[sc6->index_SC6_LPT+SC6_Result_Buf_Size-1] == data_end_tag[1] )
// log_d( " SC6_LPT was found %d %d %d " ,sc6.size_received,sc6.index_SC6_LPT,SC6_Rcv_Buf_Size );
// log_d( " sc6.result_buf[sc6.index_SC6_LPT+SC6_Result_Buf_Size-1] %02X " ,sc6.result_buf[sc6.index_SC6_LPT+SC6_Result_Buf_Size-1] );
if ( (sc6.size_received - sc6.index_SC6_LPT >= SC6_Result_Buf_Size)
&& sc6.result_buf[sc6.index_SC6_LPT+SC6_Result_Buf_Size-1] == data_end_tag[1] )
{
log_w("SC6_ Get Data OK..." );
HAL_UART_DMAStop(sc6->uarthelper ->huart );
memset(SC6_Rcv_Buf, 0, sizeof(SC6_Rcv_Buf));
log_i("SC6_ Get Data OK..." );
HAL_UART_DMAStop(SC6_uart_helper ->huart );
memset(SC6_RCV_BUF, 0, sizeof(SC6_RCV_BUF));
// result sn
memcpy( sc6->SC6_Result_Buf, sc6->SC6_Data_Buf[sc6->index_SC6_LPT], SC6_Result_Buf_Size);
memcpy( sc6->sn_buf, sc6->SC6_Data_Buf[sc6->index_SC6_LPT+4], 4);
sc6->size_received = 0;
sc6->index_SC6_LPT =0;
sc6->error = 0;
UartHelper_Set_Trans_Buf( sc6->uarthelper , stop_buf, sizeof(stop_buf) );
SC6_Transmit(sc6, sc6->uarthelper->trans_buf, sc6->uarthelper ->trans_size);
*state = MODULE_SC6_STATE_OK;
memcpy( sc6.SC6_Result_Buf, sc6.result_buf[sc6.index_SC6_LPT], SC6_Result_Buf_Size);
memcpy( sc6.SC6_sn_buf, sc6.result_buf[sc6.index_SC6_LPT+4], 4);
sc6.size_received = 0;
sc6.index_SC6_LPT =0xFFFF;
err_con = 0;
UART_HELPER_Set_Trans_Buf( SC6_uart_helper , SC6_stop_buf, sizeof(SC6_stop_buf) );
SC6_Receive();
SC6_Transmit();
sc6.state = SC6_State_Stop;
break;
}
}
if( (osKernelGetTickCount()- sc6->timebase) >=4000){
log_w("SC6_ Get Data Timeout Failed %d,Retrying...",sc6->error);
*state=MODULE_SC6_STATE_ERROR;
if( (osKernelGetTickCount()- ticks) >=4000){
log_w("SC6_ Get Data Timeout Failed %d,Retrying...",err_con);
sc6.state=SC6_State_Error;
break;
}
}
// sc6.state = SC6_State_Stop;
osDelay(1);
break;
case MODULE_SC6_STATE_OK:
// log_i( " SC6_Task ok %d " , *state );
HAL_UART_DMAStop(sc6->uarthelper ->huart );
memset(SC6_Rcv_Buf, 0, sizeof(SC6_Rcv_Buf));
sc6->size_received = 0;
UartHelper_Set_Trans_Buf(sc6->uarthelper , stop_buf, sizeof(stop_buf));
break;
case MODULE_SC6_STATE_ERROR:
log_e( " SC6_Task error " );
SC6_clean_flag( sc6 ,SC6_FLAG_MASK_BUSY);
HAL_UART_DMAStop(sc6->uarthelper ->huart );
memset(SC6_Rcv_Buf, 0, sizeof(SC6_Rcv_Buf));
sc6->size_received = 0;
*state=MODULE_SC6_STATE_WAIT;
break;
case MODULE_SC6_STATE_STOP:
break;
default:
SC6_clean_flag( sc6 ,SC6_FLAG_MASK_BUSY);
*state=MODULE_SC6_STATE_WAIT;
case SC6_State_Stop:
// log_d(" SC6_ stop, aftetr deal, wait to change status....");
osDelay(10);
continue;
case SC6_State_Timeout:
log_e( " SC6_ timeout ..... " );
sc6.state = SC6_State_Waiting ;
// TODO 停止DMA
if (SC6_uart_helper->rcv_mode == Uart_Trans_DMA)
{
HAL_UART_DMAStop( SC6_uart_helper->huart );
}
osDelay(5);
break;
case SC6_State_Error:
log_e( " SC6_ error ..... " );
sc6.state = SC6_State_Waiting ;
// TODO 停止DMA
if (SC6_uart_helper->rcv_mode == Uart_Trans_DMA)
{
HAL_UART_DMAStop( SC6_uart_helper->huart );
}
osDelay(5);
break;
}
osDelay(300);
osDelay(20);
}
}
/****************** 接口 *******************/
void SC6_Set_Uarthelper(SC6_TypeDef *sc6, UartHelper_TypeDef *uarthelper)
{
sc6->uarthelper = uarthelper;
}
void SC6_Set_Interface(SC6_TypeDef *sc6, UartInterface_TypeDef *interface)
{
sc6->uarthelper->interface = interface;
}
void SC6_Set_Huart( SC6_TypeDef * sc6, UART_HandleTypeDef * huart )
void SC6_Trans_GPIO(void)
{
sc6->uarthelper->huart = huart;
// HAL_GPIO_WritePin(R_W_GPIO_Port,R_W_Pin, SET);
// HAL_GPIO_WritePin(NULL,0, SET);
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, SET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
HAL_GPIO_WritePin(DE485_GPIO_Port, DE485_Pin, SET);
}
void SC6_Set_Interface_Type( SC6_TypeDef *sc6, Uart_Interface_Type_Typedef interface_type )
void SC6_Trans_Cplt_GPIO(void)
{
sc6->interface_type = interface_type;
sc6->uarthelper->interface_type = interface_type;
UartInterface_Setup_Interface_type( sc6->uarthelper->interface ,sc6->interface_type);
}
// HAL_GPIO_WritePin(R_W_GPIO_Port,R_W_Pin, RESET);
// HAL_GPIO_WritePin(NULL,0, RESET);
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, SET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, SET);
HAL_GPIO_WritePin(DE485_GPIO_Port, DE485_Pin, RESET);
}
void SC6_Set_RsMode_232_485(SC6_TypeDef *sc6, Uart_RS_Mode_TypeDef rs_232_485)
int SC6_Transmit()
{
// TODO理清逻辑
sc6->mode_232_485 = rs_232_485;
sc6->uarthelper->mode_232_485 = rs_232_485;
UartInterface_Setup_Mode_232_485( sc6->uarthelper->interface, rs_232_485 );
}
void SC6_Set_Trans_Type( SC6_TypeDef *sc6, Uart_Transmode_TypeDef trans_type )
{
sc6->trans_type = trans_type;
}
void SC6_Set_Rcv_Type( SC6_TypeDef *sc6, Uart_Transmode_TypeDef rcv_type )
{
sc6->rcv_type = rcv_type;
}
void SC6_Set_Idle_Enable( SC6_TypeDef *sc6, Uart_IDLE_Enable_TypeDef idle_enable_disable )
{
sc6->idle_enable_disable = idle_enable_disable;
}
void SC6_Set_TransMode( SC6_TypeDef *sc6, Uart_Transmode_TypeDef trans_mode )
{
sc6->trans_type = trans_mode;
sc6->rcv_type = trans_mode;
}
void SC6_Set_Timeout( SC6_TypeDef *sc6, uint16_t timeout_ms )
{
sc6->timeout_ms = timeout_ms;
sc6->timeout_enable = 1;
}
void SC6_Set_Sendbuf( SC6_TypeDef *sc6, uint8_t * buf, uint16_t size )
{
sc6->send_buf = buf;
sc6->size_send = size;
}
void SC6_Set_Rcvbuf( SC6_TypeDef *sc6, uint8_t * buf, uint16_t size )
{
sc6->rcv_buf = buf;
sc6->size_rcv = size;
}
int SC6_Get_Timeout(SC6_TypeDef *sc6)
{
if ((osKernelGetTickCount() - sc6->timebase) > sc6->timeout_ms)
return 1;
return 0;
}
int SC6_Transmit(SC6_TypeDef *sc6, uint8_t *buf, uint16_t size)
{
if (sc6->timeout_enable == 1)
// TODO 结合队列
sc6.size_received =0;
if( SC6_uart_helper->transferring == 0)
{
sc6->timebase = osKernelGetTickCount();
return UART_HELPER_Trans(SC6_uart_helper, SC6_uart_helper->trans_record->buf, SC6_uart_helper->trans_record->size );
}
return UartHelper_Transmit(sc6->uarthelper , buf, size);
}
int SC6_Begin_Rcv(SC6_TypeDef *sc6, uint8_t *buf, uint16_t size)
{
return UartHelper_Begin_Rcv(sc6->uarthelper , buf, size);
}
Uart_Status_TypeDef SC6_Get_UartHelper_Status(SC6_TypeDef *sc6)
{
return sc6->uarthelper ->status;
}
int SC6_Set_UartHelper_Status(SC6_TypeDef *sc6, Uart_Status_TypeDef status)
{
sc6->uarthelper ->status = status;
return 0;
}
int SC6_Init_Ok()
{
// uint64_t timebase = osKernelGetTickCount( );
// while (1)
// {
// log_i( " flag : %d %d ",sc6->flag , (sc6->flag & SC6_FLAG_MASK_RECVED_WL));
// if (count > 50) break;
// if ( sc6->flag & SC6_FLAG_MASK_RECVED_WL != 0 ) return 0;
// osDelay ( 20 );
// count++;
// }
// return -1;
}
int SC6_Get_Data_OK(SC6_TypeDef *sc6)
{
return sc6->data_ok;
}
void SC6_Set_Send_Flag(SC6_TypeDef *sc6)
int SC6_Receive()
{
// vPortEnterCritical();
sc6->send_flag = 1;
sc6->command_seq = 0;
sc6->data_ok = 0;
// vPortExitCritical( );
return UART_HELPER_Start_Rcv(SC6_uart_helper, SC6_uart_helper->rcv_buf, SC6_uart_helper->rcv_size);
// return UART_HELPER_Start_Rcv(SC6_uart_helper, SC6_RCV_BUF, 13);
// return 0;
}
void SC6_callback(SC6_TypeDef *sc6, uint8_t *buf, uint16_t size)
void SC6_Set_Timeout_ms( uint64_t ms_ticks )
{
sc6.timeout_ticks = ms_ticks;
}
void SC6_Set_GPIO_For_TC_Cplt(SC6_TypeDef *sc6)
int SC6_Validate( )
{
// sc6->status = 2;
UartHelper_Set_GPIO_For_Trans_Cplt(sc6->uarthelper );
return CRC16_Check(sc6.result_buf ,sc6.size_received);
}
void SC6_clean_flag(SC6_TypeDef *sc6,uint8_t mask)
{
sc6->flag&=~mask;
}
uint8_t SC6_get_flag(SC6_TypeDef *sc6,uint8_t mask)
{
return sc6->flag&mask;
}
uint16_t SC6_get_serial_number(SC6_TypeDef * sc6 )
int SC6_CallBack( SC6_TypeDef *pPH, uint8_t *buf, uint16_t size )
{
// if((sc6->flag&SC6_FLAG_MASK_RECVED_SN)==0){
// return 0xffff;
// }
// return sc6->sn;
}
void SC6_Error(SC6_TypeDef *sc6, char *str)
{
log_e(str);
while (1)
;
log_d( " SC6_CallBack -- state %d size %d" , sc6.state, size);
uint16_t size_tmp;
size_tmp =size;
switch (sc6.state)
{
case SC6_State_Test_Data_Getting:
if (size>0)
{
sc6.state++;
}
break;
case SC6_State_Check_Data:
if (size == 0) return 0;
if ((size + sc6.size_received) >= sizeof(sc6.result_buf) )
{
size_tmp = sizeof(sc6.result_buf) - sc6.size_received;
}
memcpy( (uint32_t)(sc6.result_buf+sc6.size_received), SC6_uart_helper->rcv_buf, size_tmp );
sc6.size_received = sc6.size_received+size_tmp;
// if ( SC6_uart_helper->enable_idle_it == 0 )
// {
// // Modbus 长度校验,拷贝数据?
// if( sc6.size_received == ( sc6.result_buf[2]+ 5 ) )
// {
// sc6.state++;
// }
// return 0;
// }
// if ( SC6_uart_helper->enable_idle_it == 1 )
// {
// // 长度校验,拷贝数据?
// if( sc6.size_received == ( sc6.result_buf[2]+ 5 ) )
// {
// sc6.state++;
// }
// return 0;
// }
break;
default:
break;
}
return 0;
}
#endif
// CRCValue = HAL_CRC_Calculate(&hcrc, (uint32_t *)dataBuffer, BUFFER_SIZE);
// void SC6_Set_Interface( SC6_TypeDef *ph, UartInterface_TypeDef * interface )
// {
// UartHelper_Set_Interface( sc6.uarthelper, interface );
// }
// void SC6_Set_Huart( SC6_TypeDef *ph, UART_HandleTypeDef * huart )
// {
// sc6.uarthelper->huart = huart;
// // UartHelper_Set_Huart( sc6.uarthelper, huart );
// }
// void SC6_Set_Interface_Type( SC6_TypeDef *ph, Uart_Interface_Type_Typedef interface_type )
// {
// sc6.interface_type = interface_type;
// sc6.uarthelper->interface_type = interface_type;
// UartInterface_Setup_Interface_type( sc6.uarthelper->interface ,sc6.interface_type);
// }

@ -1,407 +0,0 @@
#include "temperature.h"
osThreadId_t TEMP_Handle;
const osThreadAttr_t TEMP_attributes = {
.name = "TEMP",
.stack_size = 1024,
.priority = (osPriority_t) osPriorityBelowNormal,
};
// 事件
osEventFlagsId_t TEMP_EventHandle;
const osEventFlagsAttr_t TEMP_Event_attributes = {
.name = "TEMP_Event"
};
extern UART_HandleTypeDef huart3;
UART_HandleTypeDef *pTEMPUart = &huart3;
uint8_t TEMP_TEST_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
uint8_t TEMP_TEST_BUF2[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
uint8_t TEMP_TRANS_BUF[8] ={0x01, 0x03, 0x00, 0x00, 0x00, 0x04, 0x44, 0x09};
uint8_t TEMP_RCV_BUF[14] ={0};
UART_HELPER_TypeDef *temp_uart_helper;
TEMP_TypeDef temp ={
TEMP_Init,
TEMP_Port,
TEMP_Test,
TEMP_Start,
TEMP_Stop,
NULL,
0, // state
0, // data_ok
{0}, // buf
0, // size_received
0, // time base
1000, // timeout ticks, 1000ms = 1S
0, // event_flag
NULL, // transRecord[3]
};
int TEMP_Init( )
{
temp_uart_helper = UART_HELPER_Init( );
if (temp_uart_helper ==NULL) return -1;
// TODO 接口
UART_HELPER_Set_Huart( temp_uart_helper, pTEMPUart );
UART_HELPER_Set_Interface_Type(temp_uart_helper, Uart_Interface_Max3160_485);
// 传输
UART_HELPER_Setup_Trans_mode( temp_uart_helper, Uart_Trans_DMA);
// UART_HELPER_Setup_Rcv_mode( temp_uart_helper, Uart_Trans_IT );
UART_HELPER_Set_enable_idle( temp_uart_helper, Uart_IDLE_IT_ENABLE);
// 回调GPIO 操作 数据操作
UART_HELPER_Set_trans_GPIO( temp_uart_helper, TEMP_Trans_GPIO ); // enbale rcv
UART_HELPER_Set_trans_cplt_GPIO( temp_uart_helper, TEMP_Trans_Cplt_GPIO );
UART_HELPER_Set_Callback( temp_uart_helper,&temp, TEMP_CallBack );
// 设置 Buf
UART_HELPER_Set_Rcv_Buf(temp_uart_helper, TEMP_RCV_BUF, sizeof(TEMP_RCV_BUF));
UART_HELPER_Set_Trans_Buf( temp_uart_helper, TEMP_TRANS_BUF, sizeof(TEMP_TRANS_BUF) );
// GPIO 操作
switch (temp_uart_helper->interface_type)
{
case Uart_Interface_Default:
break;
case Uart_Interface_485:
usart6_send_enable();
break;
case Uart_Interface_Max3160_232:
TEMP_MAX3160_232();
break;
case Uart_Interface_Max3160_485:
max3160_485_receive_mode();
break;
default:
break;
}
temp.state = TEMP_State_Waiting;
temp.timebase_ticks = osKernelGetTickCount( );
// TODO enable trans queue
// 最大队列数 8, 消息类型, 值传递(内含的buf为指针,如何包含大空间的buf,可选择指针传递 )
temp.transQueue = osMessageQueueNew( 8, sizeof(Record_Trans_Rcv_TypeDef), NULL);
}
void TEMP_Port( )
{
TEMP_Handle = osThreadNew( TEMP_Task, NULL, &TEMP_attributes );
// TEMP_EventHandle = osEventFlagsNew( &TEMP_Event_attributes );
}
int TEMP_Test( )
{
// 装载要发送的消息队列
temp.transRecord[0].size = sizeof(TEMP_TEST_BUF);
temp.transRecord[0].buf = TEMP_TEST_BUF;
// log_i( " temp.transRecord[0] buf %d, addr %d " , temp.transRecord[0].buf[0], temp.transRecord[0].buf );
// log_i( " TEMP_TEST_BUF buf %d, addr %d " ,TEMP_TEST_BUF[0], TEMP_TEST_BUF );
osMessageQueuePut( temp.transQueue, (void*)&temp.transRecord[0], 0, osWaitForever );
// 改变操作状态
temp.state = TEMP_State_Test; // 操作状态
return 0;
}
void TEMP_Start( )
{
// 装载要发送的消息队列 , 注意队列大小及
temp.transRecord[0].size = sizeof(TEMP_TEST_BUF);
temp.transRecord[0].buf = TEMP_TEST_BUF;
osMessageQueuePut( temp.transQueue, (void*)&temp.transRecord[0], 0, osWaitForever );
temp.transRecord[1].size = sizeof(TEMP_TEST_BUF2);
temp.transRecord[1].buf = TEMP_TEST_BUF2;
osMessageQueuePut( temp.transQueue, (void*)&temp.transRecord[1], 0, osWaitForever );
temp.state = TEMP_State_Get_DATA; // 操作状态
// osEventFlagsSet( TEMP_EventHandle, TEMP_Event_Get_Data ); // 事件
}
void TEMP_Stop( )
{
temp.state = TEMP_State_Stop;
// TODO stop task?
}
void TEMP_Task( )
{
// log_i( " ph tran mode : %d ", temp.->trans_mode );
// memset( TEMP_RCV_Buf, 0, 2*TEMP_Rcv_Buf_Size ); /* ph*3 ph *2 否则内存泄漏 */
temp.event_flag = 0;
uint64_t ticks;
int err_con = 0;
int st;
Record_Trans_Rcv_TypeDef msgQueue;
int count_msg;
for ( ; ; )
{
switch (temp.state)
{
case TEMP_State_Waiting:
log_i( " temp task..... : %d %d " , temp.state , temp.state );
osDelay(20);
break;
case TEMP_State_Test:
// log_i( " temp test..... : %d QueueGetCount %d " , temp.state , osMessageQueueGetCount(temp.transQueue) );
if (osMessageQueueGetCount(temp.transQueue) == 0){
temp.state = TEMP_State_Error;
break;
}
// 取队列 值传递, 第三个参数为NULL 否则为消息长度
osMessageQueueGet( temp.transQueue, &msgQueue, sizeof(Record_Trans_Rcv_TypeDef), osWaitForever );
// log_i( " msgQueue %d %d " , msgQueue.size, msgQueue.buf );
// log_i( " msgQueue %d " , TEMP_TEST_BUF );
temp.state = TEMP_State_Test_Start;
continue;
case TEMP_State_Test_Start:
// log_i( " temp TEMP_State_Test_Start..... : %d %d " , temp.state , temp.state );
UART_HELPER_Set_Trans_Buf( temp_uart_helper, msgQueue.buf, msgQueue.size );
TEMP_Receive();
TEMP_Transmit();
temp.state = TEMP_State_Testing;
continue;
case TEMP_State_Testing:
if ( osKernelGetTickCount() - ticks > 2000 )
{
err_con++;
if( err_con >3)
{
log_w( " TEMP testing ******** error " );
temp.state = TEMP_State_Error;
}
temp.state = TEMP_State_Test;
}
osDelay(1);
continue;
case TEMP_State_Test_OK:
log_i( " temp test ok..... : %d %d " , temp.state , temp.state );
// TODO 判断队列是否有元素
if (osMessageQueueGetCount(temp.transQueue) == 0)
{
temp.state = TEMP_State_Ready;
// TODO 停止DMA
if (temp_uart_helper->rcv_mode == Uart_Trans_DMA)
{
HAL_UART_DMAStop( temp_uart_helper->huart );
}
osEventFlagsSet(TEMP_EventHandle,TEMP_Event_Ready);
continue;
}else{
osMessageQueueGet( temp.transQueue, &msgQueue, sizeof(Record_Trans_Rcv_TypeDef), osWaitForever );
// osEventFlagsClear(TEMP_EventHandle,TEMP_Event_Test_OK);
temp.state = TEMP_State_Testing;
continue;
}
break;
case TEMP_State_Ready:
// log_i( " temp TEMP_State_Ready ..... " );
osDelay(1);
continue;
case TEMP_State_Get_DATA:
log_i( " temp TEMP_State_Get_DATA ..... " );
temp.data_ok = 0 ;
temp.size_received = 0 ;
memset( temp.result_buf, 0, sizeof(temp.result_buf) );
osEventFlagsClear(TEMP_EventHandle,TEMP_Event_Get_Data);
// 队列是否有值
if (osMessageQueueGetCount(temp.transQueue) == 0){
temp.state = TEMP_State_Error;
break;
}
osMessageQueueGet( temp.transQueue, &msgQueue, sizeof(Record_Trans_Rcv_TypeDef), osWaitForever );
UART_HELPER_Set_Trans_Buf( temp_uart_helper, msgQueue.buf, msgQueue.size );
TEMP_Receive();
TEMP_Transmit();
temp.state = TEMP_State_Get_DATA_OK;
continue;
case TEMP_State_Get_DATA_Wait:
if ( osKernelGetTickCount() - ticks > 2000 )
{
err_con++;
if( err_con >3)
{
log_w( " TEMP testing ******** error " );
temp.state = TEMP_State_Error;
}
temp.state = TEMP_State_Get_DATA;
}
osDelay(1);
continue;
case TEMP_State_Get_DATA_OK:
log_w( " TEMP data ok ******** " );
// TODO 停止DMA
// if (ph_uart_helper->rcv_mode == Uart_Trans_DMA)
// {
// HAL_UART_DMAStop( ph_uart_helper->huart );
// }
temp.data_ok = 0 ;
temp.state = TEMP_State_Get_DATA_Check ;
continue;
case TEMP_State_Get_DATA_Check:
log_w( " PH data check ******** " );
if(TEMP_Validate( )== 0)
{
temp.state = TEMP_State_Stop;
}else{
temp.state = TEMP_State_Error;
}
osDelay(10);
continue;
case TEMP_State_Stop:
osDelay(10);
continue;
case TEMP_State_Timeout:
log_e( " pH timeout ..... " );
temp.state = TEMP_State_Waiting ;
// TODO 停止DMA
if (temp_uart_helper->rcv_mode == Uart_Trans_DMA)
{
HAL_UART_DMAStop( temp_uart_helper->huart );
}
osDelay(5);
break;
case TEMP_State_Error:
log_e( " temp error ..... " );
temp.state = TEMP_State_Waiting ;
// TODO 停止DMA
if (temp_uart_helper->rcv_mode == Uart_Trans_DMA)
{
HAL_UART_DMAStop( temp_uart_helper->huart );
}
osDelay(5);
break;
}
osDelay(20);
}
}
void TEMP_Trans_GPIO(void)
{
// HAL_GPIO_WritePin(R_W_GPIO_Port,R_W_Pin, SET);
// HAL_GPIO_WritePin(NULL,0, SET);
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, SET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET);
HAL_GPIO_WritePin(DE485_GPIO_Port, DE485_Pin, SET);
}
void TEMP_Trans_Cplt_GPIO(void)
{
// HAL_GPIO_WritePin(R_W_GPIO_Port,R_W_Pin, RESET);
// HAL_GPIO_WritePin(NULL,0, RESET);
HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, SET);
HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, SET);
HAL_GPIO_WritePin(DE485_GPIO_Port, DE485_Pin, RESET);
}
int TEMP_Transmit()
{
// TODO 结合队列
temp.size_received =0;
if( temp_uart_helper->transferring == 0)
{
return UART_HELPER_Trans(temp_uart_helper, temp_uart_helper->trans_record->buf, temp_uart_helper->trans_record->size );
}
return 0;
}
int TEMP_Receive()
{
return UART_HELPER_Start_Rcv(temp_uart_helper, temp_uart_helper->rcv_buf, temp_uart_helper->rcv_size);
// return 0;
}
void TEMP_Set_Timeout_ms( uint64_t ms_ticks )
{
temp.timeout_ticks = ms_ticks;
}
int TEMP_Validate( )
{
return 0;
}
int TEMP_CallBack( TEMP_TypeDef *pPH, uint8_t *buf, uint16_t size )
{
log_i( " TEMP_CallBack -- state %d " , temp.state);
uint16_t size_tmp;
size_tmp =size;
switch (temp.state)
{
case TEMP_State_Testing:
if (size>0)
{
temp.state++;
}
break;
case TEMP_State_Get_DATA_Wait:
if (size == 0) return 0;
if ((size + temp.size_received) >= sizeof(temp.result_buf) )
{
size_tmp = sizeof(temp.result_buf) - temp.size_received;
}
memcpy( (uint32_t)(temp.result_buf+temp.size_received), temp_uart_helper->rcv_buf,size_tmp);
temp.size_received += size_tmp;
if ( temp_uart_helper->enable_idle_it == 0 )
{
// Modbus 长度校验,拷贝数据?
if( temp.size_received == ( temp.result_buf[2]+ 5 ) )
{
temp.state++;
}
return 0;
}
if ( temp_uart_helper->enable_idle_it == 1 )
{
// 长度校验,拷贝数据?
if( temp.size_received == ( temp.result_buf[2]+ 5 ) )
{
temp.state++;
}
return 0;
}
break;
default:
break;
}
return 0;
}
// void TEMP_Set_Interface( TEMP_TypeDef *ph, UartInterface_TypeDef * interface )
// {
// UartHelper_Set_Interface( temp.uarthelper, interface );
// }
// void TEMP_Set_Huart( TEMP_TypeDef *ph, UART_HandleTypeDef * huart )
// {
// temp.uarthelper->huart = huart;
// // UartHelper_Set_Huart( temp.uarthelper, huart );
// }
// void TEMP_Set_Interface_Type( TEMP_TypeDef *ph, Uart_Interface_Type_Typedef interface_type )
// {
// temp.interface_type = interface_type;
// temp.uarthelper->interface_type = interface_type;
// UartInterface_Setup_Interface_type( temp.uarthelper->interface ,temp.interface_type);
// }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,737 +0,0 @@
/**
* @file wh_lte_7s4_v2.c
* @author Chen Jihang (embedded@eseaoptics.com)
* @brief WH LTE 7S4 V2驱动
* @version 0.1
* @date 2022-07-18
*
* @copyright ESEA (c) 2020
*
*/
#include "wh_lte_7s4_v2.h"
// #include "convert.h"
#include "string.h"
#include "usart.h"
WH_LTE_7S4_Typedef *wh_lte_7s4;
void wh_lte_7s4_port( )
{
wh_lte_7s4 = wh_lte_7s4_init();
// Oscar_Set_myuart( wh_lte_7s4, NULL );
// Oscar_Set_Timeout( oscar, 1000 );
// Oscar_Set_Sendbuf( oscar, Oscar_sendbuf, sizeof(Oscar_sendbuf) );
// Oscar_Set_Rcvbuf( oscar, Oscar_rcvbuf, sizeof(Oscar_rcvbuf) );
wh_lte_7s4->myuart = Myuart_Init();
// MYUART_TypeDef *myuart_handle = Myuart_Init();
Myuart_Set_Huart( wh_lte_7s4->myuart, &huart3);
Myuart_Set_Sel_GPIO_Pin( wh_lte_7s4->myuart, SEL_232_485_GPIO_Port, SEL_232_485_Pin );
Myuart_Set_DE485_GPIO_Pin( wh_lte_7s4->myuart, DE_485_GPIO_Port, DE_485_Pin );
Myuart_Set_Dplx_GPIO_Pin( wh_lte_7s4->myuart, DUPLEX_GPIO_Port, DUPLEX_Pin );
log_i( "myuart->sel : %d interface %d ",wh_lte_7s4->myuart->sel , wh_lte_7s4->myuart->interface_type );
Myuart_Set_232( wh_lte_7s4->myuart );
/* DMA 模式*/
Myuart_Setup_Transmod( wh_lte_7s4->myuart, 2);
/* ppp */
wh_lte_7s4_install( wh_lte_7s4);
}
/* 定义要发送的命令,及返回值长度不固定 ?????? */
void wh_lte_7s4_install_task( )
{
/* Polling 模式*/
Myuart_Setup_Transmod( wh_lte_7s4->myuart, 2);
wh_lte_7s4->step = 0;
/* 超时 回退上一步状态
ppp a
a +ok
workmode AT+WKMOD=NET\r\n () OK\r\n
sockasl AT+SOCKASL=LONG\r\n SocketA OK\r\n
sockeaen AT+SOCKAEN=ON\r\n SocketA 使 OK\r\n
socka AT+SOCKA=TCP,test.usr.cn,2317 SocketA IP OK\r\n
reboot AT+Z\r\n OK\r\n
:
gettime AT+CCLK\r\n
apn
*/
wh_lte_7s4_ppp( wh_lte_7s4);
__wh_lte_7s4_receive( wh_lte_7s4, wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
for ( ; ; )
{
/* ppp */
if ( wh_lte_7s4->step == 0 )
{
wh_lte_7s4_ppp( wh_lte_7s4);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
wh_lte_7s4->step++;
continue;
};
/* ppp -> a */
if ( wh_lte_7s4->step == 1 && wh_lte_7s4->receive_a_flag == 0 )
{
/* 未收到a , 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
// wh_lte_7s4_ppp( wh_lte_7s4 ,wh_lte_7s4);
// __wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step == 0;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 1 && wh_lte_7s4->receive_a_flag == 1)
{
/* 已经接收到a */
wh_lte_7s4_a( wh_lte_7s4 );
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->receive_a_flag == 0;
wh_lte_7s4->step++;
continue;
}
/* +ok -> workmode */
if ( wh_lte_7s4->step == 2 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到+ok , 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
/* 超时,从ppp 开始*/
// wh_lte_7s4_ppp( wh_lte_7s4 );
// __wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step == 0;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 2 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到+ok */
wh_lte_7s4_at_set_workmode(wh_lte_7s4 ,WH_LTE_7S4_CMD_WORK_MODE_NET);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step++;
continue;
}
/* OK -> Sockasl set long */
if ( wh_lte_7s4->step == 3 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到OK, 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
// wh_lte_7s4_a( wh_lte_7s4 );
wh_lte_7s4_at_set_workmode(wh_lte_7s4 ,WH_LTE_7S4_CMD_WORK_MODE_NET);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 3 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到 OK */
wh_lte_7s4_at_set_sockasl( wh_lte_7s4 ,WH_LTE_7S4_CMD_SOCKASL_LONG );
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step++;
continue;
}
/* OK -> SockaEN , socketa enable */
if ( wh_lte_7s4->step == 4 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到OK, 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
wh_lte_7s4_at_set_workmode(wh_lte_7s4 ,WH_LTE_7S4_CMD_WORK_MODE_NET);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 4 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到 OK */
wh_lte_7s4_at_set_socka_en(wh_lte_7s4 ,WH_LTE_7S4_CMD_STATE_ON);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step++;
continue;
}
/* OK -> Socka ip port , socketa enable */
if ( wh_lte_7s4->step == 5 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到OK, 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
wh_lte_7s4_at_set_socka_en(wh_lte_7s4 ,WH_LTE_7S4_CMD_STATE_ON);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 5 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到 OK */
// wh_lte_7s4_at_set_socka(&wh_lte_7s4_buf,WH_LTE_7S4_CMD_PROTOCOL_TCP,buf,len,config.tcp.server_port);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step++;
continue;
}
/* OK -> other APN CCLk .... wh_lte_7s4_at_get_cclk(); */
/* OK -> other APN CCLk .... */
/* OK -> Socka reboot z , socketa enable */
if ( wh_lte_7s4->step == 6 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到OK, 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
// wh_lte_7s4_at_set_socka(&wh_lte_7s4_buf,WH_LTE_7S4_CMD_PROTOCOL_TCP,buf,len,config.tcp.server_port);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 6 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到 OK */
wh_lte_7s4_at_z(wh_lte_7s4);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->step++;
continue;
}
/* OK -> Socka reboot z , socketa enable */
if ( wh_lte_7s4->step == 6 && wh_lte_7s4->receive_ok_flag == 0 )
{
/* 未收到OK, 是否超时 */
if ( (HAL_GetTick() - wh_lte_7s4->timebase) > wh_lte_7s4->timeout)
{
wh_lte_7s4_at_z(wh_lte_7s4);
__wh_lte_7s4_receive( wh_lte_7s4 ,wh_lte_7s4->receive_buf, sizeof(wh_lte_7s4->receive_buf) ) ;
wh_lte_7s4->timebase = HAL_GetTick();
}
continue;
}
if ( wh_lte_7s4->step == 7 && wh_lte_7s4->receive_ok_flag == 1)
{
/* 已经接收到 OK */
wh_lte_7s4->step++;
break;
}
/* OK -> error */
if ( wh_lte_7s4->receive_err_code == 1 )
{
wh_lte_7s4->step = 0;
wh_lte_7s4->receive_ok_flag = 0;
break;
}
osDelay(20);
}
}
/* 发送字节数 >0 发送 */
void wh_lte_7s4_task( )
{
Myuart_Setup_Transmod( wh_lte_7s4->myuart, 2 ); /* 2 DMA */
for ( ; ; )
{
osDelay(2000);
}
}
const static char *wh_lte_7s4_cmd_state_table[]={"OFF","ON"};
const static char *wh_lte_7s4_cmd_work_mode_table[]={"NET","HTTPD","UDC"};
const static char *wh_lte_7s4_cmd_uart_parity_table[]={"NONE","ODD","EVEN"};
const static char *wh_lte_7s4_cmd_sockasl_table[]={"SHORT","LONG"};
const static char *wh_lte_7s4_cmd_protocol_table[]={"TCP","UDP"};
WH_LTE_7S4_Typedef *wh_lte_7s4_init( )
{
WH_LTE_7S4_Typedef *Handle = (WH_LTE_7S4_Typedef *)malloc(sizeof(WH_LTE_7S4_Typedef));
if (Handle == NULL)
{
return NULL;
}
Handle->receive_a_flag=0;
Handle->receive_err_code=0;
Handle->receive_ok_flag=0;
Handle->receive_para_num=0;
return Handle;
}
int __wh_lte_7s4_send(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size)
{
return Myuart_Send( wh_lte_7s4->myuart, buf, size);
// return 0;
}
int __wh_lte_7s4_receive(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size)
{
return Myuart_Start_Rcv( wh_lte_7s4->myuart, buf, size);
// return 0;
}
void wh_lte_7s4_receive_callback( WH_LTE_7S4_Typedef *wh_lte_7s4 )
{
/*接收回调 判断 a */
if( wh_lte_7s4->receive_buf[0] == 'a' )
{
wh_lte_7s4->receive_a_flag = 1;
}
if( wh_lte_7s4->receive_buf[0] == '+' )
{
if( wh_lte_7s4->receive_buf[1] == 'o' && wh_lte_7s4->receive_buf[2] == 'k' )
wh_lte_7s4->receive_ok_flag = 1;
}
if( wh_lte_7s4->receive_buf[0] == 'O' )
{
if( wh_lte_7s4->receive_buf[1] == 'K' )
wh_lte_7s4->receive_ok_flag = 1;
}
// return Myuart_Start_Rcv( wh_lte_7s4->myuart, buf, size);
// return 0;
}
void wh_lte_7s4_receive_error_callback(WH_LTE_7S4_Typedef *wh_lte_7s4 )
{
/*接收发生错误回调*/
wh_lte_7s4->receive_err_code = 1;
}
int wh_lte_7s4_ppp(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
__wh_lte_7s4_send(wh_lte_7s4,"+++",3);
return 0;
}
int wh_lte_7s4_a(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
__wh_lte_7s4_send(wh_lte_7s4,"a",1);
return 0;
}
int wh_lte_7s4_at(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
__wh_lte_7s4_send(wh_lte_7s4,"AT\r",3);
return 0;
}
int wh_lte_7s4_test(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size)
{
__wh_lte_7s4_send(wh_lte_7s4,"AT+",3);
__wh_lte_7s4_send(wh_lte_7s4,cmd,size);
__wh_lte_7s4_send(wh_lte_7s4,"?\r\n",3);
return 0;
}
int wh_lte_7s4_inquire(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size)
{
__wh_lte_7s4_send(wh_lte_7s4,"AT+",3);
__wh_lte_7s4_send(wh_lte_7s4,cmd,size);
__wh_lte_7s4_send(wh_lte_7s4,"=?\r\n",4);
return 0;
}
int wh_lte_7s4_run(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size)
{
__wh_lte_7s4_send(wh_lte_7s4,"AT+",3);
__wh_lte_7s4_send(wh_lte_7s4,cmd,size);
__wh_lte_7s4_send(wh_lte_7s4,"\r\n",2);
return 0;
}
int wh_lte_7s4_set(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size)
{
__wh_lte_7s4_send(wh_lte_7s4,"AT+",3);
__wh_lte_7s4_send(wh_lte_7s4,cmd,cmd_size);
__wh_lte_7s4_send(wh_lte_7s4,"=",1);
__wh_lte_7s4_send(wh_lte_7s4,args,args_size);
__wh_lte_7s4_send(wh_lte_7s4,"\r\n",2);
return 0;
}
int wh_lte_7s4_at_help(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"H",1);
}
int wh_lte_7s4_at_z(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"Z",1);
}
int wh_lte_7s4_at_reboot(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"REBOOT",6);
}
int wh_lte_7s4_at_get_echo(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"E",1);
}
int wh_lte_7s4_at_set_echo(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state)
{
return wh_lte_7s4_set(wh_lte_7s4,"E",1,(char*)wh_lte_7s4_cmd_state_table[echo_state],strlen(wh_lte_7s4_cmd_state_table[echo_state]));
}
int wh_lte_7s4_at_entm(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"ENTM",4);
}
int wh_lte_7s4_at_set_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode)
{
return wh_lte_7s4_set(wh_lte_7s4,"WKMOD",5,(char*)wh_lte_7s4_cmd_work_mode_table[work_mode],strlen(wh_lte_7s4_cmd_work_mode_table[work_mode]));
}
int wh_lte_7s4_at_get_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"WKMOD",5);
}
int wh_lte_7s4_at_get_csq(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CSQ",3);
}
int wh_lte_7s4_at_get_system_info(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SYSINFO",7);
}
int wh_lte_7s4_at_reload(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"RELD",4);
}
int wh_lte_7s4_at_clear(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CLEAR",5);
}
int wh_lte_7s4_at_get_sn(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SN",2);
}
int wh_lte_7s4_at_get_iccid(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"ICCID",5);
}
int wh_lte_7s4_at_get_imei(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"IMEI",4);
}
int wh_lte_7s4_at_get_local_ip(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"LOCIP",5);
}
int wh_lte_7s4_at_get_uart(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UART",4);
}
int wh_lte_7s4_at_set_uart(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t baud,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity)
{
int i=0;
i+=convert_u_2_s(baud,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u_2_s(data,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u_2_s(stop,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
strcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_uart_parity_table[parity]);
i+=strlen(wh_lte_7s4_cmd_uart_parity_table[parity]);
wh_lte_7s4->send_args_buf[i++]=',';
strcpy(&wh_lte_7s4->send_args_buf[i],"NFC");
i+=3;
return wh_lte_7s4_set(wh_lte_7s4,"UART",4,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UARTFT",6);
}
int wh_lte_7s4_at_set_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t ft)
{
int i=0;
i+=convert_u_2_s(ft,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"UARTFT",6,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UARTFL",6);
}
int wh_lte_7s4_at_set_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t len)
{
int i=0;
i+=convert_u_2_s(len,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"UARTFL",6,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_socka(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKA",5);
}
/**
* @brief
*
* @param wh_lte_7s4
* @param protocol
* @param remote_ip char *
* @param remote_ip_size
* @param port
* @return int
*/
int wh_lte_7s4_at_set_socka(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port)
{
int i=0;
memcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_protocol_table[protocol],3);
i+=3;
wh_lte_7s4->send_args_buf[i++]=',';
memcpy(&wh_lte_7s4->send_args_buf[i],remote_ip,remote_ip_size);
i+=remote_ip_size;
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u_2_s(port,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"SOCKA",5,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKB",5);
}
/**
* @brief
*
* @param wh_lte_7s4
* @param protocol
* @param remote_ip
* @param remote_ip_size
* @param port
* @return int
*/
int wh_lte_7s4_at_set_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port)
{
int i=0;
memcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_protocol_table[protocol],3);
i+=3;
wh_lte_7s4->send_args_buf[i++]=',';
memcpy(&wh_lte_7s4->send_args_buf[i],remote_ip,remote_ip_size);
i+=remote_ip_size;
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u_2_s(port,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"SOCKB",5,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKAEN",7);
}
int wh_lte_7s4_at_set_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKAEN",7,(char*)wh_lte_7s4_cmd_state_table[state],strlen(wh_lte_7s4_cmd_state_table[state]));
}
int wh_lte_7s4_at_get_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBEN",7);
}
int wh_lte_7s4_at_set_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKBEN",7,(char*)wh_lte_7s4_cmd_state_table[state],strlen(wh_lte_7s4_cmd_state_table[state]));
}
int wh_lte_7s4_at_get_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKASL",7);
}
int wh_lte_7s4_at_set_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKASL",7,(char*)wh_lte_7s4_cmd_sockasl_table[type],strlen(wh_lte_7s4_cmd_sockasl_table[type]));
}
int wh_lte_7s4_at_get_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBSL",7);
}
int wh_lte_7s4_at_set_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKBSL",7,(char*)wh_lte_7s4_cmd_sockasl_table[type],strlen(wh_lte_7s4_cmd_sockasl_table[type]));
}
int wh_lte_7s4_at_get_sockalk(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKALK",7);
}
int wh_lte_7s4_at_get_sockblk(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBLK",7);
}
int wh_lte_7s4_at_get_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SDPEN",5);
}
int wh_lte_7s4_at_set_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SDPEN",5,(char*)wh_lte_7s4_cmd_state_table[new_state],strlen(wh_lte_7s4_cmd_state_table[new_state]));
}
int wh_lte_7s4_at_get_cclk(WH_LTE_7S4_Typedef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CCLK",4);
}
void wh_lte_7s4_receive_unpack(WH_LTE_7S4_Typedef *wh_lte_7s4, char *buf, uint32_t size)
{
int state;
int i=0;
int j=0;
while(i<size){
state=0;
uint32_t size_tmp=size+wh_lte_7s4->receive_size>1024?1024-wh_lte_7s4->receive_size:size;
memcpy(&wh_lte_7s4->receive_buf[wh_lte_7s4->receive_size],buf,size_tmp);
wh_lte_7s4->receive_size+=size_tmp;
while(i<size){
switch(state){
case 0:
if(buf[i]=='a'){
wh_lte_7s4->receive_a_flag=1;
state=0;
i++;
continue;
}
if(buf[i]=='\r'){
state=1;
break;
}
if(buf[i]=='+'){
state=9;
break;
}
if(buf[i]=='A'){
state=11;
break;
}
break;
case 1:
if(buf[i]=='\n'){
state=2;
break;
}
i--;
state=0;
break;
case 2:
if(buf[i]=='O'){
state=3;
break;
}
if(buf[i]=='+'){
state=6;
break;
}
i--;
state=0;
break;
case 3:
if(buf[i]=='K'){
state=4;
break;
}
i--;
state=0;
break;
case 4:
if(buf[i]=='\r'){
state=5;
break;
}
i--;
state=0;
break;
case 5:
if(buf[i]=='\n'){
wh_lte_7s4->receive_ok_flag=1;
state=0;
i++;
continue;
}
i--;
state=0;
break;
case 6:
if(buf[i]==':'){
state=7;
break;
}
break;
case 7:
if(buf[i]==','){
j=0;
wh_lte_7s4->receive_para[wh_lte_7s4->receive_para_num][j++]='\0';
wh_lte_7s4->receive_para_num++;
break;
}
if(buf[i]=='\r')
{
wh_lte_7s4->receive_para_num++;
state=8;
break;
}
if(j>=32 || wh_lte_7s4->receive_para_num>=8){
wh_lte_7s4->receive_para_num=0;
state=0;
break;
}
wh_lte_7s4->receive_para[wh_lte_7s4->receive_para_num][j++]=buf[i];
break;
case 8:
if(buf[i]=='\n')
{
state=0;
break;
}
wh_lte_7s4->receive_para_num=0;
break;
case 9:
if(buf[i]=='o'){
state=10;
break;
}
i--;
state=0;
break;
case 10:
if(buf[i]=='k'){
wh_lte_7s4->receive_ok_flag=1;
state=0;
i++;
continue;
}
i--;
state=0;
break;
case 11:
if(buf[i]=='T'){
state=2;
break;
}
i--;
state=0;
break;
}
i++;
}
}
}
/**
* @brief unsigned数据转换为字符串
*
* @param integer
* @param str
* @param length
* @return unsigned
*/
unsigned convert_u_2_s(unsigned integer,char *str,unsigned length)
{
unsigned i;
unsigned j=length-1;
while(j<length){
str[j]=integer%10+'0';
integer/=10;
if(integer==0)
break;
j--;
}
if(integer!=0)
return 0;
for(i=0;j<length;i++,j++){
str[i]=str[j];
}
return i;
}

@ -0,0 +1,301 @@
#include "wh_lte_7s4_v2.h"
#include "wh_lte_7s4_v2.h"
const static char *wh_lte_7s4_cmd_state_table[]={"OFF","ON"};
const static char *wh_lte_7s4_cmd_work_mode_table[]={"NET","HTTPD","UDC"};
const static char *wh_lte_7s4_cmd_uart_parity_table[]={"NONE","ODD","EVEN"};
const static char *wh_lte_7s4_cmd_sockasl_table[]={"SHORT","LONG"};
const static char *wh_lte_7s4_cmd_protocol_table[]={"TCP","UDP"};
const static char *wh_lte_7s4_procedure_table[]={
"+++", "a", "WKMOD", "SOCKASL", "SOCKAEN", "SOCKA","CCLK", "Z" };
const static char *wh_lte_7s4_procedure_rcv_table[]={
"a", "+ok", "OK", "OK", "OK", "OK", "+CCLK:", "OK" };
extern int WH_LTE_Send( WH_LTE_TypeDef * wh_lte_7s4, uint8_t * buf, uint16_t size );
extern int wh_lte_7s4_ppp(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_a(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_test(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size);
extern int wh_lte_7s4_inquire(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size);
extern int wh_lte_7s4_run(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size);
extern int wh_lte_7s4_set(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size);
extern int wh_lte_7s4_at_help(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_z(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_reboot(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_echo(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_echo(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state);
extern int wh_lte_7s4_at_entm(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_workmode(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode);
extern int wh_lte_7s4_at_get_workmode(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_csq(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_system_info(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_reload(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_clear(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_sn(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_iccid(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_imei(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_local_ip(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_uart(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_uart(WH_LTE_TypeDef *wh_lte_7s4,uint32_t buad,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity);
extern int wh_lte_7s4_at_get_uartft(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_uartft(WH_LTE_TypeDef *wh_lte_7s4,uint32_t ft);
extern int wh_lte_7s4_at_get_uartfl(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_uartfl(WH_LTE_TypeDef *wh_lte_7s4,uint32_t len);
extern int wh_lte_7s4_at_get_socka(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_socka(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
extern int wh_lte_7s4_at_get_sockb(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_sockb(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
extern int wh_lte_7s4_at_get_socka_en(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_socka_en(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
extern int wh_lte_7s4_at_get_sockb_en(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_sockb_en(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
extern int wh_lte_7s4_at_get_sockasl(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_sockasl(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
extern int wh_lte_7s4_at_get_sockbsl(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_sockbsl(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
extern int wh_lte_7s4_at_get_sockalk(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_sockblk(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_get_sdpen(WH_LTE_TypeDef *wh_lte_7s4);
extern int wh_lte_7s4_at_set_sdpen(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state);
extern int wh_lte_7s4_at_get_cclk(WH_LTE_TypeDef *wh_lte_7s4);
int WH_LTE_Send( WH_LTE_TypeDef * wh_lte_7s4, uint8_t * buf, uint16_t size )
{
return UART_HELPER_Trans(WH_LTE_uart_helper, buf, size);
}
int wh_lte_7s4_ppp(WH_LTE_TypeDef *wh_lte_7s4)
{
// WH_LTE_Send( wh_lte_7s4,"+++",3);
WH_LTE_Send( wh_lte_7s4, (uint8_t*)"+++",3);
return 0;
}
int wh_lte_7s4_a(WH_LTE_TypeDef *wh_lte_7s4)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"a",1);
return 0;
}
int wh_lte_7s4_at(WH_LTE_TypeDef *wh_lte_7s4)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"AT\r",3);
return 0;
}
int wh_lte_7s4_test(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"AT+",3);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)cmd,size);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"?\r\n",3);
return 0;
}
int wh_lte_7s4_inquire(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"AT+",3);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)cmd,size);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"=?\r\n",4);
return 0;
}
int wh_lte_7s4_run(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t size)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"AT+",3);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)cmd,size);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"\r\n",2);
return 0;
}
int wh_lte_7s4_set(WH_LTE_TypeDef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size)
{
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"AT+",3);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)cmd, cmd_size);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"=",1);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)args,args_size);
WH_LTE_Send( wh_lte_7s4,(uint8_t*)"\r\n",2);
return 0;
}
int wh_lte_7s4_at_help(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"H",1);
}
int wh_lte_7s4_at_z(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"Z",1);
}
int wh_lte_7s4_at_reboot(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"REBOOT",6);
}
int wh_lte_7s4_at_get_echo(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"E",1);
}
int wh_lte_7s4_at_set_echo(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state)
{
return wh_lte_7s4_set(wh_lte_7s4,"E",1,(char*)wh_lte_7s4_cmd_state_table[echo_state],strlen(wh_lte_7s4_cmd_state_table[echo_state]));
}
int wh_lte_7s4_at_entm(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"ENTM",4);
}
int wh_lte_7s4_at_set_workmode(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode)
{
return wh_lte_7s4_set(wh_lte_7s4,"WKMOD",5,(char*)wh_lte_7s4_cmd_work_mode_table[work_mode],strlen(wh_lte_7s4_cmd_work_mode_table[work_mode]));
}
int wh_lte_7s4_at_get_workmode(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_test(wh_lte_7s4,"WKMOD",5);
}
int wh_lte_7s4_at_get_csq(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CSQ",3);
}
int wh_lte_7s4_at_get_system_info(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SYSINFO",7);
}
int wh_lte_7s4_at_reload(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"RELD",4);
}
int wh_lte_7s4_at_clear(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CLEAR",5);
}
int wh_lte_7s4_at_get_sn(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SN",2);
}
int wh_lte_7s4_at_get_iccid(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"ICCID",5);
}
int wh_lte_7s4_at_get_imei(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"IMEI",4);
}
int wh_lte_7s4_at_get_local_ip(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"LOCIP",5);
}
int wh_lte_7s4_at_get_uart(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UART",4);
}
int wh_lte_7s4_at_set_uart(WH_LTE_TypeDef *wh_lte_7s4,uint32_t buad,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity)
{
int i=0;
i+=convert_u2s(buad,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u2s(data,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
i+=convert_u2s(stop,&wh_lte_7s4->send_args_buf[i],64-i);
wh_lte_7s4->send_args_buf[i++]=',';
strcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_uart_parity_table[parity]);
i+=strlen(wh_lte_7s4_cmd_uart_parity_table[parity]);
wh_lte_7s4->send_args_buf[i++]=',';
strcpy(&wh_lte_7s4->send_args_buf[i],"NFC");
i+=3;
return wh_lte_7s4_set(wh_lte_7s4,"UART",4,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_uartft(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UARTFT",6);
}
int wh_lte_7s4_at_set_uartft(WH_LTE_TypeDef *wh_lte_7s4,uint32_t ft)
{
int i=0;
i+=convert_u2s(ft,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"UARTFT",6,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_uartfl(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"UARTFL",6);
}
int wh_lte_7s4_at_set_uartfl(WH_LTE_TypeDef *wh_lte_7s4,uint32_t len)
{
int i=0;
i+=convert_u2s(len,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"UARTFL",6,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_socka(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKA",5);
}
int wh_lte_7s4_at_set_socka(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port)
{
int i=0;
memcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_protocol_table[protocol],3);
i+=3;
wh_lte_7s4->send_args_buf[i++]=',';
memcpy(&wh_lte_7s4->send_args_buf[i],remote_ip,remote_ip_size);
i+=remote_ip_size;
wh_lte_7s4->send_args_buf[i++]=',';
i+=wh_lte_convert_u2s(port,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"SOCKA",5,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_sockb(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKB",5);
}
int wh_lte_7s4_at_set_sockb(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port)
{
int i=0;
memcpy(&wh_lte_7s4->send_args_buf[i],wh_lte_7s4_cmd_protocol_table[protocol],3);
i+=3;
wh_lte_7s4->send_args_buf[i++]=',';
memcpy(&wh_lte_7s4->send_args_buf[i],remote_ip,remote_ip_size);
i+=remote_ip_size;
wh_lte_7s4->send_args_buf[i++]=',';
i+=wh_lte_convert_u2s(port,&wh_lte_7s4->send_args_buf[i],64-i);
return wh_lte_7s4_set(wh_lte_7s4,"SOCKB",5,wh_lte_7s4->send_args_buf,i);
}
int wh_lte_7s4_at_get_socka_en(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKAEN",7);
}
int wh_lte_7s4_at_set_socka_en(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKAEN",7,(char*)wh_lte_7s4_cmd_state_table[state],strlen(wh_lte_7s4_cmd_state_table[state]));
}
int wh_lte_7s4_at_get_sockb_en(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBEN",7);
}
int wh_lte_7s4_at_set_sockb_en(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKBEN",7,(char*)wh_lte_7s4_cmd_state_table[state],strlen(wh_lte_7s4_cmd_state_table[state]));
}
int wh_lte_7s4_at_get_sockasl(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKASL",7);
}
int wh_lte_7s4_at_set_sockasl(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKASL",7,(char*)wh_lte_7s4_cmd_sockasl_table[type],strlen(wh_lte_7s4_cmd_sockasl_table[type]));
}
int wh_lte_7s4_at_get_sockbsl(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBSL",7);
}
int wh_lte_7s4_at_set_sockbsl(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type)
{
return wh_lte_7s4_set(wh_lte_7s4,"SOCKBSL",7,(char*)wh_lte_7s4_cmd_sockasl_table[type],strlen(wh_lte_7s4_cmd_sockasl_table[type]));
}
int wh_lte_7s4_at_get_sockalk(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKALK",7);
}
int wh_lte_7s4_at_get_sockblk(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SOCKBLK",7);
}
int wh_lte_7s4_at_get_sdpen(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"SDPEN",5);
}
int wh_lte_7s4_at_set_sdpen(WH_LTE_TypeDef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state)
{
return wh_lte_7s4_set(wh_lte_7s4,"SDPEN",5,(char*)wh_lte_7s4_cmd_state_table[new_state],strlen(wh_lte_7s4_cmd_state_table[new_state]));
}
int wh_lte_7s4_at_get_cclk(WH_LTE_TypeDef *wh_lte_7s4)
{
return wh_lte_7s4_run(wh_lte_7s4,"CCLK",4);
}

@ -16,8 +16,8 @@
static uint8_t init_buf=0x55;
UART_HandleTypeDef *pWK2114Uart = &huart2;
#define WK2114_Uart_IRQHandler USART2_IRQHandler
UART_HandleTypeDef *pWK2114Uart = &huart1;
#define WK2114_Uart_IRQHandler USART1_IRQHandler
WK2114_TypeDef *wk2114;

@ -1,870 +0,0 @@
/*
* wk2xxx.c
*/
#include "wk2xxx.h"
// #define WK2124
#define WK2114
/// 移植修改区域
#define WK2124_RST1_GPIO_Port GPIOA
#define WK2124_RST1_Pin GPIO_PIN_15
#define WK2124_CS1_GPIO_Port GPIOA
#define WK2124_CS1_Pin GPIO_PIN_15
// 拉低RST引脚
#define WK_GPIO_RST_L() HAL_GPIO_WritePin( WK2124_RST1_GPIO_Port, WK2124_RST1_Pin, GPIO_PIN_RESET )
// 拉高RST引脚
#define WK_GPIO_RST_H() HAL_GPIO_WritePin( WK2124_RST1_GPIO_Port, WK2124_RST1_Pin, GPIO_PIN_SET )
#ifdef WK2124
#include "spi.h"
#define WK_SPI_Handle ( &hspi2 )
#endif
#ifdef WK2114
#include "usart.h"
#define WK_Uart_Handle ( &huart2 )
#endif
// 片选引脚 拉低 拉高
#ifdef WK2124
#define WK_GPIO_SEL_L() HAL_GPIO_WritePin( WK2124_CS1_GPIO_Port, WK2124_CS1_Pin, GPIO_PIN_RESET )
#define WK_GPIO_SEL_H() HAL_GPIO_WritePin( WK2124_CS1_GPIO_Port, WK2124_CS1_Pin, GPIO_PIN_SET )
#endif
#ifdef WK2114
#define WK_GPIO_SEL_L()
#define WK_GPIO_SEL_H()
#endif
static void wk_delay_ms(uint32_t nms)
{
HAL_Delay(nms);
}
static uint8_t WK_SPI_ReadWriteByte(uint8_t TxData)
{
uint8_t RxData = 0X00;
#ifdef WK2124
if ( HAL_SPI_TransmitReceive(WK_SPI_Handle, &TxData, &RxData, 1, 10) != HAL_OK )
{
RxData = 0XFF;
}
#endif
#ifdef WK2114
/* ???? */
if ( HAL_Uart_Transmit(WK_Uart_Handle, &TxData, 1, 10) != HAL_OK )
{
RxData = 0XFF;
}
if ( HAL_UART_Receive(WK_Uart_Handle, &RxData, 1, 100) != HAL_OK )
{
RxData = 0XFF;
}
#endif
return RxData;
}
/// 驱动程序代码
void WK_Port(void)
{
/* Hard Reset */
WK_Rst();
/* uart 需要自适应串口, spi无需此操作*/
WK_SPI_ReadWriteByte( 0x55 );
// init ports
WK_PortInit(1, 11059200, 9600); // 晶振 = 11.0592MHz ,这个值根据实际进行修改
WK_PortInit(2, 11059200, 9600);
WK_PortInit(3, 11059200, 9600);
WK_PortInit(4, 11059200, 9600);
}
/// 硬件复位(拉低复位引脚最低10毫秒进行复位)
void WK_Rst(void)
{
WK_GPIO_RST_L( );
wk_delay_ms( 50 );
WK_GPIO_RST_H( );
wk_delay_ms( 50 );
}
void WK_WriteGReg( uint8_t reg, uint8_t value )
{
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte( reg );
WK_SPI_ReadWriteByte( value );
WK_GPIO_SEL_H( );
}
uint8_t WK_ReadGReg( uint8_t reg )
{
uint8_t value = 0X00;
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte( 0X40 | reg );
value = WK_SPI_ReadWriteByte( 0X00 );
WK_GPIO_SEL_H( );
return value;
}
void WK_WriteSReg( uint8_t port, uint8_t reg, uint8_t value )
{
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte( ((port - 1) << 4) | reg );
WK_SPI_ReadWriteByte( value );
WK_GPIO_SEL_H( );
}
uint8_t WK_ReadSReg( uint8_t port, uint8_t reg )
{
uint8_t value = 0X00;
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte(0X40 | ((port - 1) << 4) | reg);
value = WK_SPI_ReadWriteByte( 0X00 );
WK_GPIO_SEL_H( );
return value;
}
void WK_WriteFIFO( uint8_t port, const void* buf, uint16_t len )
{
const uint8_t* p = (const uint8_t *)buf;
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte(0X80 | ((port - 1) << 4));
while (len--)
{
WK_SPI_ReadWriteByte(*p++);
}
WK_GPIO_SEL_H( );
}
void WK_ReadFIFO( uint8_t port, void* buf, uint16_t len )
{
uint8_t* p = (uint8_t *)buf;
WK_GPIO_SEL_L( );
WK_SPI_ReadWriteByte(0XC0 | ((port - 1) << 4));
while (len--)
{
*p++ = WK_SPI_ReadWriteByte(0X00);
}
WK_GPIO_SEL_H( );
}
void WK_PortCalcBaudrate( uint32_t fosc, uint32_t baudrate, uint8_t* BAUD0, uint8_t* BAUD1, uint8_t* PRES )
{
float value = (float)fosc / (float)(baudrate << 4);
*BAUD0 = (((uint32_t)value) - 1) & 0XFF;
*BAUD1 = ((((uint32_t)value) - 1) >> 8) & 0XFF;
*PRES = ((uint32_t)(value * 10)) % 10;
}
uint16_t WK_PortSendData( uint8_t port, const void* buf, uint16_t len )
{
uint8_t state = 0;
uint16_t nsend = 0;
state = WK_ReadSReg( port, WK2XXX_FSR );
if (state & WK2XXX_TFULL) // 发送FIFO满
{
nsend = 0;
} else
{
state = WK_ReadSReg( port, WK2XXX_TFCNT ); // 读取发送FIFO已用空间
nsend = 256 - state;
nsend = nsend >= len ? len : nsend;
WK_WriteFIFO(port, buf, nsend); // 将待发送的数据写入FIFO
}
return nsend; // 返回实际发送成功的数据量
}
uint16_t WK_PortRecvData( uint8_t port, void* buf, uint16_t len )
{
uint8_t state = 0;
uint8_t nread = 0;
state = WK_ReadSReg( port, WK2XXX_FSR );
if ( state & WK2XXX_RDAT ) // 接收FIFO非空
{
nread = WK_ReadSReg( port, WK2XXX_RFCNT ); // 查询FIFO中的数据量 ?恰好256个?
if ( nread == 0 )
{
nread= 256;
}else{
nread = len >= nread ? nread : len;
}
WK_ReadFIFO( port, buf, nread ); // 读取FIFO中的数据
}
return nread; // 返回实际读取到的数据量
}
void WK_PortInit( uint8_t port, uint32_t fosc, uint32_t baudrate )
{
uint8_t BAUD0 = 0, BAUD1 = 0, PRES = 0, value = 0, ret = 0;
/* 使能子串口时钟 */
value = WK_ReadGReg( WK2XXX_GENA );
value |= (1 << (port - 1));
WK_WriteGReg( WK2XXX_GENA, value );
ret = WK_ReadGReg( WK2XXX_GENA );
/* 软件复位子串口 */
value = WK_ReadGReg( WK2XXX_GRST );
value |= (1 << (port - 1));
WK_WriteGReg( WK2XXX_GRST, value );
ret = WK_ReadGReg( WK2XXX_GRST );
/* 使能子串口总中断 */
value = WK_ReadGReg( WK2XXX_GIER );
value |= (1 << (port - 1));
WK_WriteGReg( WK2XXX_GIER, value );
ret = WK_ReadGReg( WK2XXX_GIER );
/* 使能子串口FIFO相关中断 */
value = WK_ReadSReg( port, WK2XXX_SIER );
value |= WK2XXX_RFTRIG_IEN; // 接收FIFO触点中断
// value |= WK2XXX_TFTRIG_IEN; // 发送FIFO触点中断
// value |= WK2XXX_RXOUT_IEN; // 接收FIFO超时中断
WK_WriteSReg( port, WK2XXX_SIER, value );
ret = WK_ReadSReg( port, WK2XXX_SIER );
/* 设置FCR寄存器 */
value = 0;
value |= (1 << 0); // 复位接收FIFO
value |= (1 << 1); // 复位发送FIFO
value |= (1 << 2); // 使能接收FIFO(这一步必须)
value |= (1 << 3); // 使能发送FIFO(这一步必须)
value |= (0 << 4); // 设置接收FIFO触点固定为8字节
value |= (0 << 6); // 设置发送FIFO触点固定为8字节
WK_WriteSReg( port, WK2XXX_FCR, value );
ret = WK_ReadSReg( port, WK2XXX_FCR );
/* 切换到 page1 设置中断触点和波特率 */
WK_WriteSReg( port, WK2XXX_SPAGE, 1 );
ret = WK_ReadSReg( port, WK2XXX_SPAGE );
WK_WriteSReg( port, WK2XXX_RFTL, 10 ); // 设置接收触点为10个字节
ret = WK_ReadSReg( port, WK2XXX_RFTL );
WK_WriteSReg( port, WK2XXX_TFTL, 10 ); // 设置发送触点为10个字节
ret = WK_ReadSReg( port, WK2XXX_TFTL );
WK_PortCalcBaudrate( fosc, baudrate, &BAUD0, &BAUD1, &PRES ); // 计算波特率
WK_WriteSReg( port, WK2XXX_BAUD1, BAUD1 ); // 设置BAUD1
ret = WK_ReadSReg( port, WK2XXX_BAUD1 );
WK_WriteSReg( port, WK2XXX_BAUD0, BAUD0 ); // 设置BAUD0
ret = WK_ReadSReg( port, WK2XXX_BAUD0 );
WK_WriteSReg( port, WK2XXX_PRES, PRES ); // 设置PRES
ret = WK_ReadSReg( port, WK2XXX_PRES );
/* 切换回page0 */
WK_WriteSReg( port, WK2XXX_SPAGE, 0 );
ret = WK_ReadSReg( port, WK2XXX_SPAGE );
/* 使能子串口收发 */
value = WK_ReadSReg( port, WK2XXX_SCR );
value |= WK2XXX_TXEN;
value |= WK2XXX_RXEN;
WK_WriteSReg( port, WK2XXX_SCR, value );
ret = WK_ReadSReg( port, WK2XXX_SCR );
}
// 如果irq引脚接入了单片机的外部中断引脚,将该函数放入外部中断处理函数内。
// 对于WK2124所开启的中断可以这么处理:
void WK_IRQHandler( void )
{
int i = 0;
uint8_t GIFR = 0, SIFR = 0;
/* 读取子串口全局中断寄存器 , 返回子串口
GIFR : Global Interupt Flag Register,
*/
GIFR = WK_ReadGReg( WK2XXX_GIFR );
// 查询4个子串口是否发生中断
for (i = 0; i < 4; i++)
{
if ((GIFR >> i) & 0X01)
{
/* 子串口中断标志寄存器
SIFR Sub Uart Interupt Flag Register
*/
SIFR = WK_ReadSReg((i + 1), WK2XXX_SIFR);
// 有接收FIFO触点中断, 置位,接收非空
if ( SIFR & WK2XXX_RFTRIG_INT )
{
/* 调用WK_PortRecvData接收数据, 映射到指定的buff , */
}
// 有接收FIFO超时中断, 接收超时
if ( SIFR & WK2XXX_RXOVT_INT )
{
}
// 有发送FIFO触点中断, 置位子串口标记有发送
if ( SIFR & WK2XXX_TFTRIG_INT )
{
}
// 有发送FIFO空中断,置位子串口标记
if ( SIFR & WK2XXX_TFEMPTY_INT )
{
}
/* 有接收FIFO数据错误中断, 置位子串口标记
FIFO
*/
if ( SIFR & WK2XXX_FERR_INT )
{
}
}
}
}
/*************************************************************************/
// 函数功能: 此函数主要是通过读写wk2xxx的寄存器来判断主接口的通信时序是否有问题
// 参数: 无
// 返回值: rv表示返回值,0成功
/*************************************************************************/
uint8_t Wk2xxx_Test(void)
{
uint8_t rec_data,rv;
//主接口为SPI
rec_data = WK_ReadSReg( WK2XXX_GPORT, WK2XXX_GENA );
if ( rec_data == 0x30 )
return rv;
else
{
rv = 1;
return rv;
}
}
/* 初始化
int main()
{
int nrecv = 0;
uint8_t buffer[256];
// 硬件复位一下
WK_Rst();
// 初始化四个端口
WK_PortInit(1, 11059200, 9600); // WK2124晶振我用的是11.0592MHz的,这个值根据实际进行修改
WK_PortInit(2, 11059200, 9600);
WK_PortInit(3, 11059200, 9600);
WK_PortInit(4, 11059200, 9600);
// 发送数据
WK_PortSendData(1, "helloworld\r\n", 12);
WK_PortSendData(2, "helloworld\r\n", 12);
WK_PortSendData(3, "helloworld\r\n", 12);
WK_PortSendData(4, "helloworld\r\n", 12);
// 接收数据,轮询方式
nrecv = WK_PortRecvData(1, buffer, sizeof(buffer));
if(nrecv != 0)
{
// 处理数据
}
}
*/
// /***************************************************************************/
// //本文件为WK2XXX系列串口扩展芯片的设备驱动程序,作为驱动参开demo。使用者可以根据自身的情况加以修改,完善。
// /***************************************************************************/
// #include "wk2xxx.h"
// // #include "spi.h"
// // #include "usart.h"
// // #include "delay.h"
// void WK2XXX_RST_Init(void)
// {
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PA,PD端口时钟
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //PA.3 端口配置
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
// GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIOA.3
// GPIO_SetBits(GPIOA,GPIO_Pin_3); //PA.3 输出高
// }
// void WK2XXX_Reset_Init(void)
// {
// GPIO_SetBits(GPIOA,GPIO_Pin_3);//1
// GPIO_ResetBits(GPIOA,GPIO_Pin_3);//0
// delay_ms(10);
// GPIO_SetBits(GPIOA,GPIO_Pin_3);//1
// delay_ms(100);
// }
// /*************************************************************************/
// //函数功能:初始化SPI片选信号CS,并把CS的默认状态设置为高电平
// //
// //
// /*************************************************************************/
// void SPI_CS_Init(void)
// {
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PA,PD端口时钟
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3; //PA.4 端口配置
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
// GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIOA.4
// GPIO_SetBits(GPIOA,GPIO_Pin_4); //PA.4 输出高
// }
// /*************************************************************************/
// //函数功能:初始化SPI总线,设置SPI总线为0模式
// /*************************************************************************/
// void SPI_BUS_Init(void)
// {
// SPI1_Init(); //初始化SPI
// SPI1_SetSpeed(SPI_BaudRatePrescaler_8); //设置为10M时钟,高速模式
// }
// /*************************************************************************/
// //函数功能:设置CS信号为高电平
// /*************************************************************************/
// void SPI_CS_H(void)
// {
// GPIO_SetBits(GPIOA,GPIO_Pin_4);
// }
// /*************************************************************************/
// //函数功能:设置CS信号为低电平
// /*************************************************************************/
// void SPI_CS_L(void)
// {
// GPIO_ResetBits(GPIOA,GPIO_Pin_4);
// }
// /*************************************************************************/
// //函数功能:初始化SPI接口
// /*************************************************************************/
// void WK2XXX_SPI_Init(void)
// {
// SPI_CS_Init();
// SPI_BUS_Init();
// }
// /*************************************************************************/
// //函数功能:写寄存器函数(前提是该寄存器可写,某些寄存器如果你写1,可能会自动置1,具体见数据手册)
// //参数:port:为子串口的数(C0C1)
// // reg:为寄存器的地址(A3A2A1A0)
// // dat:为写入寄存器的数据
// //注意:在子串口被打通的情况下,向FDAT写入的数据会通过TX引脚输出
// //*************************************************************************/
// void Wk2xxxWriteReg(unsigned char port,unsigned char reg,unsigned char dat)
// {
// SPI_CS_L();//片选使能
// SPI1_ReadWriteByte(((port-1)<<4)+reg); //写控制字节
// SPI1_ReadWriteByte(dat); //写数据
// SPI_CS_H();//片选无效
// }
// /*************************************************************************/
// //函数功能:读寄存器函数
// //参数:port:为子串口的数(C0C1)
// // reg:为寄存器的地址(A3A2A1A0)
// // rec_data:为读取到的寄存器值
// //注意:在子串口被打通的情况下,读FDAT,实际上就是读取uart的rx接收的数据
// /*************************************************************************/
// unsigned char Wk2xxxReadReg(unsigned char port,unsigned char reg)
// {
// unsigned char rec_data;
// SPI_CS_L(); //片选使能
// SPI1_ReadWriteByte(0x40+((port-1)<<4)+reg);//写控制字节,控制命令构成见数据手册
// rec_data=SPI1_ReadWriteByte(0);//接收返回的数据
// SPI_CS_H(); //片选无效
// return rec_data;
// }
// /**************************** Wk2xxxWriteFifo*********************************************/
// //函数功能:该函数为写FIFO函数,通过该函数写入的数据会直接进入子串口的发送FIFO,然后通过TX引脚发送
// //参数:port:为子串口的端口号(C0\C1)
// // *wbuf:写入数据部分
// // len: 写入数据长度
// //
// /*************************************************************************/
// void Wk2xxxWriteFifo(unsigned char port,unsigned char *wbuf,unsigned int len)
// { unsigned char n;
// SPI_CS_L(); // 片选有效
// SPI1_ReadWriteByte(0x80+((port-1)<<4)); //写FIFO控制指令
// for(n=0;n<len;n++)
// {
// SPI1_ReadWriteByte(*(wbuf+n));
// }
// SPI_CS_H(); //片选无效
// }
// /**************************** Wk2xxxReadFifo*********************************************/
// //函数功能:该函数为读FIFO函数,通过该函数可以一次读出多个接收FIFO中的数据,最多256个字节
// //参数:port:为子串口的端口号(C0\C1)
// // *rbuf:写入数据部分
// // len: 写入数据长度
// //
// /*************************************************************************/
// void Wk2xxxReadFifo(unsigned char port,unsigned char *rbuf,unsigned int len)
// { unsigned char n;
// SPI_CS_L();//片选有效
// SPI1_ReadWriteByte(0xc0+((port-1)<<4)); //写读fifo控制指令
// for(n=0;n<len;n++)
// {
// *(rbuf+n)=SPI1_ReadWriteByte(0);
// }
// SPI_CS_H();//片选无效
// //return 0;
// }
// /*************************************************************************/
// //函数功能:此函数主要是通过读写wk2xxx的寄存器来判断主接口的通信时序是否有问题
// //参数:无
// //返回值:rv表示返回值,0成功
// /*************************************************************************/
// unsigned char Wk2xxxTest(void)
// {
// unsigned char rec_data,rv;
// //主接口为SPI
// rec_data=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GENA);
// if(rec_data==0x30)
// return rv;
// else
// {
// rv=1;
// return rv;
// }
// }
// /******************************Wk2xxxInit*******************************************/
// //函数功能:本函数主要会初始化一些芯片基本寄存器;
// /*********************************************************************************/
// void Wk2xxxInit(unsigned char port)
// {
// unsigned char gena,grst,gier,sier,scr;
// //使能子串口时钟
// gena=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GENA);
// switch (port)
// {
// case 1://使能子串口1的时钟
// gena|=WK2XXX_UT1EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 2://使能子串口2的时钟
// gena|=WK2XXX_UT2EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 3://使能子串口3的时钟
// gena|=WK2XXX_UT3EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 4://使能子串口4的时钟
// gena|=WK2XXX_UT4EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// }
// //软件复位子串口
// grst=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GRST);
// switch (port)
// {
// case 1://软件复位子串口1
// grst|=WK2XXX_UT1RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 2://软件复位子串口2
// grst|=WK2XXX_UT2RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 3://软件复位子串口3
// grst|=WK2XXX_UT3RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 4://软件复位子串口4
// grst|=WK2XXX_UT4RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// }
// //使能子串口中断,包括子串口总中断和子串口内部的接收中断,和设置中断触点
// gier=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GIER);
// switch (port)
// {
// case 1://软件复位子串口1
// gier|=WK2XXX_UT1RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GIER,gier);
// break;
// case 2://软件复位子串口2
// gier|=WK2XXX_UT2RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GIER,gier);
// break;
// case 3://软件复位子串口3
// gier|=WK2XXX_UT3RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GIER,gier);
// break;
// case 4://软件复位子串口4
// gier|=WK2XXX_UT4RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GIER,gier);
// break;
// }
// //使能子串口接收触点中断和超时中断
// sier=Wk2xxxReadReg(port,WK2XXX_SIER);
// sier |= WK2XXX_RFTRIG_IEN|WK2XXX_RXOVT_IEN;
// Wk2xxxWriteReg(port,WK2XXX_SIER,sier);
// // 初始化FIFO和设置固定中断触点
// Wk2xxxWriteReg(port,WK2XXX_FCR,0XFF);
// //设置任意中断触点,如果下面的设置有效,那么上面FCR寄存器中断的固定中断触点将失效
// Wk2xxxWriteReg(port,WK2XXX_SPAGE,1);//切换到page1
// Wk2xxxWriteReg(port,WK2XXX_RFTL,0X40);//设置接收触点为64个字节
// Wk2xxxWriteReg(port,WK2XXX_TFTL,0X10);//设置发送触点为16个字节
// Wk2xxxWriteReg(port,WK2XXX_SPAGE,0);//切换到page0
// //使能子串口的发送和接收使能
// scr=Wk2xxxReadReg(port,WK2XXX_SCR);
// scr|=WK2XXX_TXEN|WK2XXX_RXEN;
// Wk2xxxWriteReg(port,WK2XXX_SCR,scr);
// }
// /******************************Wk2xxxClose*******************************************/
// //函数功能:本函数会关闭当前子串口,和复位初始值;
// /*********************************************************************************/
// void Wk2xxxClose(unsigned char port)
// {
// unsigned char gena,grst;
// //复位子串口
// grst=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GRST);
// switch (port)
// {
// case 1://软件复位子串口1
// grst|=WK2XXX_UT1RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 2://软件复位子串口2
// grst|=WK2XXX_UT2RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 3://软件复位子串口3
// grst|=WK2XXX_UT3RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// case 4://软件复位子串口4
// grst|=WK2XXX_UT4RST;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GRST,grst);
// break;
// }
// //关闭子串口时钟
// gena=Wk2xxxReadReg(WK2XXX_GPORT,WK2XXX_GENA);
// switch (port)
// {
// case 1://使能子串口1的时钟
// gena&=~WK2XXX_UT1EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 2://使能子串口2的时钟
// gena&=~WK2XXX_UT2EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 3://使能子串口3的时钟
// gena&=~WK2XXX_UT3EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// case 4://使能子串口4的时钟
// gena&=~WK2XXX_UT4EN;
// Wk2xxxWriteReg(WK2XXX_GPORT,WK2XXX_GENA,gena);
// break;
// }
// }
// /**************************Wk2xxxSetBaud*******************************************************/
// //函数功能:设置子串口波特率函数、此函数中波特率的匹配值是根据11.0592Mhz下的外部晶振计算的
// // port:子串口号
// // baud:波特率大小.波特率表示方式,
// //
// /**************************Wk2xxxSetBaud*******************************************************/
// void Wk2xxxSetBaud(unsigned char port,int baud)
// {
// unsigned char baud1,baud0,pres,scr;
// //如下波特率相应的寄存器值,是在外部时钟为11.0592的情况下计算所得,如果使用其他晶振,需要重新计算
// switch (baud)
// {
// case 1:
// baud1=0x4;
// baud0=0x7f;
// pres=0;
// break;
// case 2:
// baud1=0x2;
// baud0=0x3F;
// pres=0;
// break;
// case 3:
// baud1=0x1;
// baud0=0x1f;
// pres=0;
// break;
// case 4:
// baud1=0x00;
// baud0=0x8f;
// pres=0;
// break;
// case 5:
// baud1=0x00;
// baud0=0x47;
// pres=0;
// break;
// case 6:
// baud1=0x00;
// baud0=0x23;
// pres=0;
// break;
// case 7:
// baud1=0x00;
// baud0=0x11;
// pres=0;
// break;
// case 8:
// baud1=0x00;
// baud0=0x08;
// pres=0;
// break;
// case 9:
// baud1=0x01;
// baud0=0x7f;
// pres=0;
// break;
// case 10:
// baud1=0x00;
// baud0=0xbf;
// pres=0;
// break;
// case 11:
// baud1=0x00;
// baud0=0x5f;
// pres=0;
// break;
// case 12:
// baud1=0x00;
// baud0=0x2f;
// pres=0;
// break;
// case 13:
// baud1=0x00;
// baud0=0x17;
// pres=0;
// break;
// case 14:
// baud1=0x00;
// baud0=0x0b;
// pres=0;
// break;
// case 15:
// baud1=0x00;
// baud0=0x05;
// pres=0;
// break;
// case 16:
// baud1=0x00;
// baud0=0x02;
// pres=0;
// break;
// default:
// baud1=0x00;
// baud0=0x00;
// pres=0;
// }
// //关掉子串口收发使能
// scr=Wk2xxxReadReg(port,WK2XXX_SCR);
// Wk2xxxWriteReg(port,WK2XXX_SCR,0);
// //设置波特率相关寄存器
// Wk2xxxWriteReg(port,WK2XXX_SPAGE,1);//切换到page1
// Wk2xxxWriteReg(port,WK2XXX_BAUD1,baud1);
// Wk2xxxWriteReg(port,WK2XXX_BAUD0,baud0);
// Wk2xxxWriteReg(port,WK2XXX_PRES,pres);
// Wk2xxxWriteReg(port,WK2XXX_SPAGE,0);//切换到page0
// //使能子串口收发使能
// Wk2xxxWriteReg(port,WK2XXX_SCR,scr);
// }
// /*****************************Wk2xxxSendBuf****************************************/
// //本函数为子串口发送数据的函数,发送数据到子串口的FIFO.然后通过再发送
// //参数说明:port:子串口端口号
// // *sendbuf:需要发送的数据buf
// // len:需要发送数据的长度
// // 函数返回值:实际成功发送的数据
// //说明:调用此函数只是把数据写入子串口的发送FIFO,然后再发送。1、首先确认子串口的发送FIFO有多少数据,根据具体情况、
// //确定写入FIFO数据的个数,
// /*********************************************************************/
// unsigned int Wk2xxxSendBuf(unsigned char port,unsigned char *sendbuf,unsigned int len)
// {
// unsigned int ret,tfcnt,sendlen;
// unsigned char fsr;
// fsr=Wk2xxxReadReg(port,WK2XXX_FSR);
// if(~fsr&WK2XXX_TFULL )//子串口发送FIFO未满
// {
// tfcnt=Wk2xxxReadReg(port,WK2XXX_TFCNT);//读子串口发送fifo中数据个数
// sendlen=256-tfcnt;//FIFO能写入的最多字节数
// if(sendlen<len)
// {
// ret=sendlen;
// Wk2xxxWriteFifo(port,sendbuf,sendlen);
// }
// else
// {
// Wk2xxxWriteFifo(port,sendbuf,len);
// ret=len;
// }
// }
// return ret;
// }
// /*****************************Wk2xxxGetBuf****************************************/
// //本函数为子串口接收数据函数
// //参数说明:port:子串口端口号
// // *getbuf:接收到的数据buf
// // 函数返回值:实际接收到的数据个数
// /*********************************************************************/
// unsigned int Wk2xxxGetBuf(unsigned char port,unsigned char *getbuf)
// {
// unsigned int ret=0,rfcnt;
// unsigned char fsr;
// fsr=Wk2xxxReadReg(port,WK2XXX_FSR);
// if(fsr&WK2XXX_RDAT )//子串口接收FIFO未空
// {
// rfcnt=Wk2xxxReadReg(port,WK2XXX_RFCNT);//读子串口发送fifo中数据个数
// if(rfcnt==0)//当RFCNT寄存器为0的时候,有两种情况,可能是256或者是0,这个时候通过FSR来判断,如果FSR显示接收FIFO不为空,就为256个字节
// {rfcnt=256;}
// Wk2xxxReadFifo(port,getbuf,rfcnt);
// ret=rfcnt;
// }
// return ret;
// }
Loading…
Cancel
Save