11#include "app_PBV_UART.h"
23#define PBV_CRC_POLYNOM 0x8005
30#define PBV_CRC_POLYNOM_REV 0xA001
37#define PBV_ReadyToSend UART1_IsTxReady
44#define PBV_Write UART1_Write
51#define PBV_IsRxReady UART1_IsRxReady
58#define PBV_Read UART1_Read
65#define PBV_START_OF_FRAME 0x55
72#define PBV_END_OF_FRAME 0x0d
80#define RCV_WAIT_FOR_STARTBYTE 0
81#define RCV_READ_ID_HIGHBYTE 1
82#define RCV_READ_ID_LOWBYTE 2
83#define RCV_READ_LENGTH_HIGHBYTE 3
84#define RCV_READ_LENGTH_LOWBYTE 4
85#define RCV_READ_DATA 5
86#define RCV_READ_CRC_HIGHBYTE 6
87#define RCV_READ_CRC_LOWBYTE 7
89#define RCV_MESSAGE_RECEIVED 9
96#define PBV_RCV_DATABUFFER_SIZE 64
103#define PBV_HEADER_SIZE 5
117 uint8_t
data[PBV_RCV_DATABUFFER_SIZE];
135uint32_t PBV_calculated_CRC = 0;
137static bool uartActiveTx;
138static bool uartActiveTxAscii;
141uint16_t PBV_Calculate_CRC(uint8_t *message, uint16_t length);
185 uartActiveTx =
false;
186 uartActiveTxAscii =
false;
199 static uint16_t rcv_data_index = 0;
200 static uint16_t rcv_CRC = 0;
201 static uint16_t rcv_timeout = 0;
202 static uint8_t rcv_copy_for_CRC[PBV_RCV_DATABUFFER_SIZE + PBV_HEADER_SIZE];
209 if (++rcv_timeout >= 10000)
221 case RCV_WAIT_FOR_STARTBYTE:
222 if (data == PBV_START_OF_FRAME)
227 rcv_copy_for_CRC[rcv_data_index] = data;
233 case RCV_READ_ID_HIGHBYTE:
237 rcv_copy_for_CRC[rcv_data_index] = data;
242 case RCV_READ_ID_LOWBYTE:
246 rcv_copy_for_CRC[rcv_data_index] = data;
251 case RCV_READ_LENGTH_HIGHBYTE:
256 rcv_copy_for_CRC[rcv_data_index] = data;
264 case RCV_READ_LENGTH_LOWBYTE:
267 rcv_copy_for_CRC[rcv_data_index] = data;
279 rcv_copy_for_CRC[rcv_data_index] = data;
288 case RCV_READ_CRC_HIGHBYTE:
293 case RCV_READ_CRC_LOWBYTE:
303 if (PBV_calculated_CRC == rcv_CRC)
307 PBV_calculated_CRC = 0;
330 if (uartActiveTx ==
true)
345 uartActiveTxAscii =
true;
395 uartActiveTxAscii =
false;
413 if (uartActiveTxAscii ==
true)
478 uartActiveTx =
false;
555uint16_t PBV_Calculate_CRC(uint8_t *message, uint16_t length)
558 uint8_t message_odd = (uint8_t) (length & 0x01);
559 uint16_t length_t = 0;
562 uint32_t trycount = 0;
563 uint16_t resultCRC = 0;
564 uint16_t message16bit[PBV_RCV_DATABUFFER_SIZE];
569 length_t = (length & 0xFFFE);
573 for (i = 0, j = 0; i < length_t; i += 2, j++)
576 message16bit[j] = (message[i + 1 ] << 8) | message[i];
591 resultCRC ^= message[length - 1];
592 for (i = 0; i < 8; ++i)
594 if (resultCRC & 0x0001)
600 resultCRC = (resultCRC >> 1);
This is the generated driver header file for the CRC driver.
This is the generated driver header file for the UART1 driver.
struct UART_MSG_TX_OBJ UART_MSG_TX_OBJ_t
UART msg Transmit object.
UART_MSG_TX_OBJ_t PBV_UART_Object_TX
UART object for numeric tx.
struct UART_MSG_RX_OBJ UART_MSG_RX_OBJ_t
UART msg receive object.
#define PBV_ReadyToSend
linking functions with UART mcc driver functions
uint8_t PBV_UART_Transmit_to_GUI()
void PBV_UART_Init(PBV_Datatype_TX_t *Board_To_PBV, PBV_Datatype_TX_t *Board_To_PBVAscii, PBV_Datatype_RX_t *Pbv_To_Board)
uint8_t PBV_UART_Transmit_Ascii_to_GUI()
uint8_t PBV_UART_Receive_from_GUI()
implements the state machine for UART Frame receiving from PBV.
UART_MSG_TX_OBJ_t PBV_UART_Object_ASCII
UART object for ascii tx.
#define PBV_CRC_POLYNOM_REV
Reversed polynomial. needed for odd byte in the data stream.
UART_MSG_RX_OBJ_t PBV_UART_Object_RX
UART object for numeric rx.
#define PBV_Read
linking functions with UART mcc driver functions
#define PBV_Write
linking functions with UART mcc driver functions
#define PBV_IsRxReady
linking functions with UART mcc driver functions
@ PBV_MESSAGE_READY_TO_RECEIVE
Message Reception triggered.
@ PBV_STATE_RECEIVING
Message beinf received.
@ PBV_MESSAGE_RECEIVED
Message Received.
@ PBV_MESSAGE_RX_ERROR
if some error happens (CRC ?)
@ PBV_SIGNAL_MODE
Object will transmit/receive signals.
@ PBV_MESSAGE_TRANSMITTED
Message transmitted. successful transmit.
@ PBV_MESSAGE_TX_ERROR
if some error happens. unsuccessful transmit
@ PBV_MESSAGE_TRANSMITTING
Transmitting Message.
void CRC_CalculateBufferStart(void *buffer, uint32_t sizeBytes)
CRC module calculation on a buffer in data space.
void CRC_Tasks(void)
This function cycles through the CRC calculations. This function will load the CRC module FIFO with...
uint32_t CRC_CalculationResultReverseGet(void)
Gets the CRC reversed value of result if the calculation is done.
bool CRC_CalculationIsDone(void)
Returns the CRC calculation complete status
uint32_t PBV_Protcol_ID
Protocol ID.
uint8_t * Data_Buffer
Pointer to the data to be transmitted.
enum PBV_SIGNAL_ASCII_MODE PBV_Signal_Ascii
Object will transmit Signals or ASCII.
uint16_t Length
Length of transmitted message in Bytes.
uint32_t PBV_Protcol_ID
Protocol ID of the received message.
PBV_MESSAGE_RX_STATE_t PBV_Message_State
State of the received message.
uint8_t * Data_Buffer
Received Data pointer.
uint16_t Length
Length of received message in Bytes.
uint8_t Length_in_Bytes
UART bytes Received
uint8_t PBV_Header[PBV_HEADER_SIZE]
recived Header. 5bytes ( SOF + ID + Length)
uint8_t UART_Frame_State
UART Receive Frame states.
uint16_t Protocol_ID
Received Frame ID.
uint16_t offset
Offset needed to store data in data
uint8_t data[PBV_RCV_DATABUFFER_SIZE]
data buffer. linked by the calling application. STATIC(64) bytes for now.
UART msg Transmit object.
uint8_t Length_in_Bytes
UART Bytes to be Transmitted.
uint8_t PBV_Header[PBV_HEADER_SIZE]
sent Header. 5bytes ( SOF + ID + Length)
uint8_t UART_Frame_State
UART Transmit Frame states.
uint8_t * data
data buffer. linked by the calling application. STATIC(64) bytes for now.
uint16_t Protocol_ID
Frame ID to be appended.
uint16_t offset
Offset needed for data transmission.
uint16_t CRC
calculated CRC