不含stm32 底层的代码
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.
MyStm32Code/device/Inc/oscar.h

228 lines
7.4 KiB

2 years ago
#ifndef __Oscar_H
#define __Oscar_H
#include <string.h>
#include "uart_helper.h"
#include "uart_interface.h"
// #include "config.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)
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;
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;
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;
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; /* 接收数据完整可以处理 */
uint8_t data_ok; /* 接收数据完整可以处理 */
volatile uint16_t size_received;
uint64_t timebase;
uint64_t timeout_ms;
uint64_t timeout_enable;
}Oscar_TypeDef;
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 );
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 );
int Oscar_Get_Timeout( Oscar_TypeDef * oscar );
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 );
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 );
void Oscar_callback( Oscar_TypeDef * oscar, uint8_t * buf, uint16_t size );
void Oscar_Set_GPIO_For_TC_Cplt( Oscar_TypeDef * oscar );
void Oscar_clean_flag(Oscar_TypeDef * oscar,uint8_t mask);
uint8_t Oscar_get_flag(Oscar_TypeDef * oscar,uint8_t mask);
uint16_t Oscar_get_serial_number(Oscar_TypeDef * oscar );
// 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;
#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 )
*
*/