заработало чтение, надо привести в порядок код
This commit is contained in:
88
rs_message.h
88
rs_message.h
@@ -29,69 +29,42 @@
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////---DEFINES---////////////////////////////
|
||||
|
||||
/* Check that all defines required by RS are defined */
|
||||
#ifndef MSG_SIZE_MAX
|
||||
#error Define MSG_SIZE_MAX (Maximum size of message). This is necessary to create buffer for UART.
|
||||
#error "Define MSG_SIZE_MAX (Maximum size of message)"
|
||||
#endif
|
||||
|
||||
#ifndef RX_FIRST_PART_SIZE
|
||||
#error Define RX_FIRST_PART_SIZE (Size of first part of message). This is necessary to receive the first part of the message, from which determine the size of the remaining part of the message.
|
||||
#error "Define RX_FIRST_PART_SIZE (Size of first part of message)"
|
||||
#endif
|
||||
|
||||
/* Clear message-uart buffer */
|
||||
#define RS_Clear_Buff(_buff_) for(int i=0; i<MSG_SIZE_MAX;i++) _buff_[i] = 0
|
||||
#define RS_Clear_Buff(_buff_) for(int i=0;i<MSG_SIZE_MAX;i++) _buff_[i]=0
|
||||
|
||||
/* Set/Reset flags */
|
||||
#define RS_Set_Free(_hRS_) (_hRS_->f.RS_Busy = 0)
|
||||
#define RS_Set_Busy(_hRS_) (_hRS_->f.RS_Busy = 1)
|
||||
#define RS_Set_Free(_hRS_) _hRS_->f.RS_Busy=0
|
||||
#define RS_Set_Busy(_hRS_) _hRS_->f.RS_Busy=1
|
||||
|
||||
#define RS_Set_RX_Flags(_hRS_) do { \
|
||||
_hRS_->f.RX_Busy = 1; \
|
||||
_hRS_->f.RX_Done = 0; \
|
||||
_hRS_->f.RX_Half = 0; \
|
||||
} while(0)
|
||||
#define RS_Set_RX_Flags(_hRS_) _hRS_->f.RX_Busy=1; _hRS_->f.RX_Done=0; _hRS_->f.RX_Half=0
|
||||
#define RS_Set_RX_Active_Flags(_hRS_) _hRS_->f.RX_Ongoing=1
|
||||
|
||||
#define RS_Set_RX_Active_Flags(_hRS_) (_hRS_->f.RX_Ongoing = 1)
|
||||
#define RS_Set_TX_Flags(_hRS_) do { \
|
||||
_hRS_->f.TX_Busy = 1; \
|
||||
_hRS_->f.TX_Done = 0; \
|
||||
} while(0)
|
||||
#define RS_Set_TX_Flags(_hRS_) _hRS_->f.TX_Busy=1; _hRS_->f.TX_Done=0
|
||||
|
||||
#define RS_Reset_RX_Active_Flags(_hRS_) (_hRS_->f.RX_Ongoing = 0)
|
||||
#define RS_Reset_RX_Active_Flags(_hRS_) _hRS_->f.RX_Ongoing=0
|
||||
#define RS_Reset_RX_Flags(_hRS_) RS_Reset_RX_Active_Flags(_hRS_); _hRS_->f.RX_Busy=0; _hRS_->f.RX_Done=0; _hRS_->f.RX_Half=0
|
||||
#define RS_Reset_TX_Flags(_hRS_) _hRS_->f.TX_Busy=0; _hRS_->f.TX_Done=0
|
||||
|
||||
#define RS_Reset_RX_Flags(_hRS_) do { \
|
||||
RS_Reset_RX_Active_Flags(_hRS_); \
|
||||
_hRS_->f.RX_Busy = 0; \
|
||||
_hRS_->f.RX_Done = 0; \
|
||||
_hRS_->f.RX_Half = 0; \
|
||||
} while(0)
|
||||
#define RS_Set_RX_End_Flag(_hRS_) _hRS_->f.RX_Done=1
|
||||
#define RS_Set_TX_End_Flag(_hRS_) _hRS_->f.TX_Done=1
|
||||
|
||||
#define RS_Reset_TX_Flags(_hRS_) do { \
|
||||
_hRS_->f.TX_Busy = 0; \
|
||||
_hRS_->f.TX_Done = 0; \
|
||||
} while(0)
|
||||
#define RS_Set_RX_End(_hRS_) RS_Reset_RX_Flags(_hRS_); RS_Set_RX_End_Flag(_hRS_)
|
||||
#define RS_Set_TX_End(_hRS_) RS_Reset_TX_Flags(_hRS_); RS_Set_TX_End_Flag(_hRS_)
|
||||
|
||||
#define RS_Set_RX_End_Flag(_hRS_) (_hRS_->f.RX_Done = 1)
|
||||
#define RS_Set_TX_End_Flag(_hRS_) (_hRS_->f.TX_Done = 1)
|
||||
#define RS_Clear_All(_hRS_) RS_Clear_Buff(_hRS_->pBufferPtr); RS_Reset_RX_Flags(_hRS_); RS_Reset_TX_Flags(_hRS_)
|
||||
|
||||
#define RS_Set_RX_End(_hRS_) do { RS_Reset_RX_Flags(_hRS_); RS_Set_RX_End_Flag(_hRS_); } while(0)
|
||||
#define RS_Set_TX_End(_hRS_) do { RS_Reset_TX_Flags(_hRS_); RS_Set_TX_End_Flag(_hRS_); } while(0)
|
||||
#define RS_Is_RX_Busy(_hRS_) (_hRS_->f.RX_Busy==1)
|
||||
#define RS_Is_TX_Busy(_hRS_) (_hRS_->f.TX_Busy==1)
|
||||
|
||||
/* Clear all RS stuff */
|
||||
#define RS_Clear_All(_hRS_) do { \
|
||||
RS_Clear_Buff(_hRS_->pBufferPtr); \
|
||||
RS_Reset_RX_Flags(_hRS_); \
|
||||
RS_Reset_TX_Flags(_hRS_); \
|
||||
} while(0)
|
||||
|
||||
#define RS_Is_RX_Busy(_hRS_) (_hRS_->f.RX_Busy == 1)
|
||||
#define RS_Is_TX_Busy(_hRS_) (_hRS_->f.TX_Busy == 1)
|
||||
|
||||
/* For Arduino we can redefine later if needed */
|
||||
#ifndef RS_EnableReceive
|
||||
#define RS_EnableReceive()
|
||||
#define RS_EnableReceive()
|
||||
#endif
|
||||
|
||||
#ifndef RS_EnableTransmit
|
||||
#define RS_EnableTransmit()
|
||||
#endif
|
||||
@@ -182,7 +155,6 @@ typedef struct // RS_HandleTypeDef
|
||||
|
||||
/* HANDLERS and SETTINGS */
|
||||
HUART_TypeDef *huart; ///< handler for used uart
|
||||
void *htim; ///< handler for used tim
|
||||
RS_ModeTypeDef sRS_Mode; ///< setting: slave or master @ref RS_ModeTypeDef
|
||||
uint16_t sRS_Timeout; ///< setting: timeout in ms
|
||||
RS_RX_SizeTypeDef sRS_RX_Size_Mode; ///< setting: 1 - not const, 0 - const
|
||||
@@ -217,32 +189,14 @@ RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hRS, uint32_t *r
|
||||
|
||||
//-------------------------GENERAL FUNCTIONS-------------------------
|
||||
/*-----------------Should be called from main code-----------------*/
|
||||
void RS_Process(RS_HandleTypeDef *hRS);
|
||||
/* Initialize UART and handle RS stucture */
|
||||
RS_StatusTypeDef RS_Init(RS_HandleTypeDef *hRS, HUART_TypeDef *huart, uint8_t *pRS_BufferPtr);
|
||||
/* Start receive IT */
|
||||
RS_StatusTypeDef RS_Receive_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
|
||||
/* Start transmit IT */
|
||||
RS_StatusTypeDef RS_Transmit_IT(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
|
||||
/* Abort RS/UART */
|
||||
RS_StatusTypeDef RS_Abort(RS_HandleTypeDef *hRS, RS_AbortTypeDef AbortMode);
|
||||
//-------------------------GENERAL FUNCTIONS-------------------------
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
|
||||
/* Handle for starting receive */
|
||||
RS_StatusTypeDef RS_Handle_Receive_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
|
||||
/* Handle for starting transmit */
|
||||
RS_StatusTypeDef RS_Handle_Transmit_Start(RS_HandleTypeDef *hRS, RS_MsgTypeDef *RS_msg);
|
||||
/* UART RX Callback: define behaviour after receiving parts of message */
|
||||
RS_StatusTypeDef RS_UART_RxCpltCallback(RS_HandleTypeDef *hRS);
|
||||
/* UART TX Callback: define behaviour after transmiting message */
|
||||
RS_StatusTypeDef RS_UART_TxCpltCallback(RS_HandleTypeDef *hRS);
|
||||
/* Handler for UART */
|
||||
void RS_UART_Handler(RS_HandleTypeDef *hRS);
|
||||
/* Handler for TIM */
|
||||
void RS_TIM_Handler(RS_HandleTypeDef *hRS);
|
||||
//--------------------CALLBACK/HANDLER FUNCTIONS---------------------
|
||||
|
||||
///////////////////////////---FUNCTIONS---///////////////////////////
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user