ZNKT-ST-M/BSP/Inc/Usart.h

143 lines
4.9 KiB
C
Raw Permalink Normal View History

#ifndef _USART_H_
#define _USART_H_
#include "stdint.h"
#include "Include.h"
#include "user_queue.h"
#define MAX_SLAVE_NUMBER ( 8 )
#define MAC_ADDRESS_LENGTH ( 12 )
#define BLE_USART ( USART1 )
#define BLE_USART_GPIO_CLK ( RCC_AHB1Periph_GPIOB )
#define BLE_USART_CLK ( RCC_APB2Periph_USART1 )
#define BLE_USART_GPIO_PORT ( GPIOB )
#define BLE_USART_TX_GPIO_PIN ( GPIO_Pin_6 )
#define BLE_USART_RX_GPIO_PIN ( GPIO_Pin_7 )
#define BLE_USART_BAUDRATE ( 115200 )
#define BLE_NVIC_IRQChannel ( USART1_IRQn )
/**********************<2A><><EFBFBD><EFBFBD>**************************/
#define BLE_USART_TX_PinSource ( GPIO_PinSource6 )
#define BLE_USART_RX_PinSource ( GPIO_PinSource7 )
#define BLE_GPIO_AF_USART ( GPIO_AF_USART1 )
#define USART1_RX_BUFFER_SIZE ( 50 )
#define FrameHead ( 0xAA )
#define FrameTail ( 0x55 )
/*********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**********/
#define WaveformSet ( 0x71 )
#define AcquisitionCtrl ( 0x72 )
#define CurrentSet ( 0x73 )
#define EMG_DataReport ( 0x74 )
#define EMG_FormatSwitching ( 0x75 )
#define CurrentPreinstallCtrl ( 0x76 )
#define TriggerModeCtrl ( 0x77 )
#define Poll ( 0x78 )
#define SliceFalLSwitch ( 0x79 )
#define ShutDown ( 0x7A )
/***********ƫ<><C6AB>***********/
#define HeadOffset ( 0x00 )
#define LengthOffset ( 0x01 )
#define FunctionCodeOffset ( 0x02 )
#define DeviceNumberOffset ( 0x03 )
#define ChannelOffset ( 0x04 )
/**********<2A><><EFBFBD><EFBFBD>************/
#define ChannelModeAcquisition ( 0x01 )
#define ChannelModeStimulation ( 0x02 )
#define ChannelModeTrigger ( 0x03 )
#define AcquisitionRate4K ( 0x01 )
#define AcquisitionRate8K ( 0x02 )
#define TurnOff ( 0x00 )
#define TurnOn ( 0x01 )
#define Pause ( 0x02 )
#define Continue ( 0x03 )
#define RMS_Data ( 0x00 )
#define OriginalData ( 0x01 )
#define Acquisition ( 0x00 )
#define Stimulation ( 0x01 )
#define SliceFall ( 0x00 )
#define SliceConnect ( 0x01 )
#define SliceUnmonitored ( 0x02 )
#define IdleState ( 0x00 )
#define ClimbState ( 0x01 )
#define DownState ( 0x02 )
#define KeepState ( 0x03 )
#define RestState ( 0x04 )
#define Charging ( 0x00 )
#define BatterySupply ( 0x01 )
#define SlaveConnect ( 0x01 )
#define SlaveDisconnect ( 0x02 )
#define BLE_Disconnect ( 0x01 )
#define BLE_Connect ( 0x02 )
#define Reset ( 0x00 )
#define NotReset ( 0x01 )
typedef struct
{
uint8_t mode; //ģʽ
uint8_t rate; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t EMG_data_mode; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
uint8_t state; //<2F><><EFBFBD><EFBFBD>״̬
}channel_data_t;
typedef struct
{
channel_data_t channel1;
channel_data_t channel2;
uint8_t output_current_mA; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>
uint8_t preinstall_state; //Ԥ<><EFBFBD><E8BFAA>
uint8_t stimulate_state; //<2F>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD>
uint8_t slice_state; //<2F><>Ƭ״̬
uint8_t slice_detect_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2BFAA>
uint8_t formwave_state; //<2F><><EFBFBD><EFBFBD>״̬
uint8_t mac_address[MAC_ADDRESS_LENGTH]; //mac
uint8_t connection_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
uint8_t adapter_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
uint8_t electric_quantity; //<2F><><EFBFBD><EFBFBD>
uint8_t reset_flag; //<2F><>λ<EFBFBD><CEBB>־λ
uint16_t frequency_Hz; //Ƶ<><C6B5>
uint16_t width_us; //<2F><><EFBFBD><EFBFBD>
uint16_t climb_time_ms; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
uint16_t keep_time_ms; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
uint16_t down_time_ms; //<2F>½<EFBFBD>ʱ<EFBFBD><CAB1>
uint16_t rest_time_ms; //<2F><>Ϣʱ<CFA2><CAB1>
}device_state_t;
void ble_usart_init(uint32_t baudrate);
//void ble_usart_send(uint8_t *ucpTx_Data,uint8_t ucTx_length);
uint8_t ble_usart_send(uint8_t ucTx_length);
uint8_t Analysis_data(void);
extern uint8_t usart1_tx_done ;//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
void net_received_data_analysis(void);
void parameters_init(void);
#endif