You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
6.9 KiB
220 lines
6.9 KiB
2 years ago
|
#ifndef __SC6_H
|
||
|
#define __SC6_H
|
||
|
|
||
|
#include <string.h>
|
||
|
#include "uart_helper.h"
|
||
|
#include "uart_interface.h"
|
||
|
// #include "config.h"
|
||
|
|
||
|
#define SC6_DEMO 1 /*sn 读取位置不一样*/
|
||
|
#define SC6_RESUMED_Buf_Size (12)
|
||
|
#define SC6_PAUSEED_Buf_Size (11)
|
||
|
#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)
|
||
|
|
||
|
|
||
|
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;
|
||
|
|
||
|
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*/
|
||
|
|
||
|
volatile uint8_t step; /* 0 : normal , 1 : get wavelength , 2 : get sn 3: 空*/
|
||
|
volatile uint8_t command_seq ; /* 命令序号 */
|
||
|
|
||
|
// uint16_t sn;
|
||
|
|
||
|
uint16_t 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;
|
||
|
|
||
|
}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);
|
||
|
|
||
|
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 );
|
||
|
|
||
|
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 );
|
||
|
|
||
|
|
||
|
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 );
|
||
|
|
||
|
void SC6_clean_flag(SC6_TypeDef * sc6,uint8_t mask);
|
||
|
uint8_t SC6_get_flag(SC6_TypeDef * sc6,uint8_t mask);
|
||
|
|
||
|
uint16_t SC6_get_serial_number(SC6_TypeDef * sc6 );
|
||
|
|
||
|
// 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();
|
||
|
|
||
|
|
||
|
// 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;
|
||
|
|
||
|
#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 实际)
|
||
|
*
|
||
|
*/
|