24#define PBV_CRC_POLYNOM 0x8005
30#define PBV_CRC_POLYNOM_REV 0xA001
36#define PBV_ReadyToSend UART1_IsTxReady
42#define PBV_Write UART1_Write
48#define PBV_IsRxReady UART1_IsRxReady
54#define PBV_Read UART1_Read
60#define PBV_START_OF_FRAME 0x55
66#define PBV_END_OF_FRAME 0x0d
74#define RCV_WAIT_FOR_STARTBYTE 0
75#define RCV_READ_ID_HIGHBYTE 1
76#define RCV_READ_ID_LOWBYTE 2
77#define RCV_READ_LENGTH_HIGHBYTE 3
78#define RCV_READ_LENGTH_LOWBYTE 4
79#define RCV_READ_DATA 5
80#define RCV_READ_CRC_HIGHBYTE 6
81#define RCV_READ_CRC_LOWBYTE 7
83#define RCV_MESSAGE_RECEIVED 9
91#define PBV_RCV_DATABUFFER_SIZE 64
98#define PBV_HEADER_SIZE 5
130uint32_t PBV_calculated_CRC = 0;
132static bool uartActiveTx;
133static bool uartActiveTxAscii;
179 uartActiveTx =
false;
180 uartActiveTxAscii =
false;
191 static uint16_t rcv_data_index = 0;
192 static uint16_t rcv_CRC = 0;
193 static uint16_t rcv_timeout = 0;
201 if (++rcv_timeout >= 10000)
219 rcv_copy_for_CRC[rcv_data_index] = data;
229 rcv_copy_for_CRC[rcv_data_index] = data;
238 rcv_copy_for_CRC[rcv_data_index] = data;
248 rcv_copy_for_CRC[rcv_data_index] = data;
259 rcv_copy_for_CRC[rcv_data_index] = data;
271 rcv_copy_for_CRC[rcv_data_index] = data;
295 if (PBV_calculated_CRC == rcv_CRC)
299 PBV_calculated_CRC = 0;
324 if (uartActiveTx ==
true)
340 uartActiveTxAscii =
true;
399 uartActiveTxAscii =
false;
426 if (uartActiveTxAscii ==
true)
501 uartActiveTx =
false;
586 uint8_t message_odd = (uint8_t) (length & 0x01);
587 uint16_t length_t = 0;
590 uint32_t trycount = 0;
591 uint16_t resultCRC = 0;
597 length_t = (length & 0xFFFE);
601 for (i = 0, j = 0; i < length_t; i += 2, j++)
604 message16bit[j] = (message[i + 1 ] << 8) | message[i];
619 resultCRC ^= message[length - 1];
620 for (i = 0; i < 8; ++i)
622 if (resultCRC & 0x0001)
628 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 pbvUartObjectAscii
UART object for ascii tx.
void PBV_UART_Init(PBV_Datatype_TX_t *boardToPbv, PBV_Datatype_TX_t *boardToPbvAscii, PBV_Datatype_RX_t *pbvToBoard)
initializes UART objects
#define RCV_READ_LENGTH_HIGHBYTE
void PBV_UART_Reinit(PBV_Datatype_TX_t *ptr)
reinitializes the UART object with new protocol id.
uint16_t PBV_Calculate_CRC(uint8_t *message, uint16_t length)
Calculates the CRC on 16 bit stream of data.
#define RCV_READ_CRC_HIGHBYTE
struct UART_MSG_RX_OBJ UART_MSG_RX_OBJ_t
UART msg receive object.
#define PBV_ReadyToSend
linking functions with UART mcc driver functions
#define RCV_MESSAGE_RECEIVED
#define PBV_END_OF_FRAME
Standard End of frame for PBV UART frames.
#define PBV_RCV_DATABUFFER_SIZE
Maximum UART buffer. The max data that could be received is 64 bytes.
uint8_t PBV_UART_Transmit_to_GUI()
implements the state machine for UART numerical TX
UART_MSG_TX_OBJ_t pbvUartObjectTx
UART object for numeric tx.
#define RCV_WAIT_FOR_STARTBYTE
Internal STATES for RX State machine for PBV UART Frames.
uint8_t PBV_UART_Transmit_Ascii_to_GUI()
implements the state machine for UART ascii TX
uint8_t PBV_UART_Receive_from_GUI()
implements the state machine for UART Frame receiving from PBV.
#define RCV_READ_LENGTH_LOWBYTE
#define PBV_HEADER_SIZE
Maximum UART buffer. The max data that could be received is 64 bytes.
void PBV_UART_Link_Data_TX(PBV_Datatype_TX_t *ptr)
links the data from the calling application to the UART TX object
int PBV_UART_Link_Data_RX(PBV_Datatype_RX_t *ptr)
Links the data from received frame to the calling application
#define RCV_READ_ID_HIGHBYTE
#define PBV_CRC_POLYNOM_REV
Reversed polynomial. needed for odd byte in the data stream.
#define RCV_READ_CRC_LOWBYTE
#define PBV_START_OF_FRAME
Standard Start of frame for PBV UART frames.
#define PBV_Read
linking functions with UART mcc driver functions
#define RCV_READ_ID_LOWBYTE
#define PBV_Write
linking functions with UART mcc driver functions
#define PBV_IsRxReady
linking functions with UART mcc driver functions
UART_MSG_RX_OBJ_t pbvUartObjectRx
UART object for numeric rx.
@ 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