Programmable Clock with RTOS 0.0.1
Implementaiton of a programmable clock using RTOS with STM32GO microcontroller.
|
Board Support Package. More...
Macros | |
#define | SINGLE_FRAME_TYPE 0u |
#define | FIRST_FRAME_TYPE 1u |
#define | CONSECUTIVE_FRAME_TYPE 2u |
#define | FLOW_CONTROL_FRAME_TYPE 3u |
#define | CONTINUE_TO_SEND 0u |
#define | WAIT 1u |
#define | OVERFLOW_ABORT 2u |
#define | FLAG_CAN_TP_ON 1u |
#define | FLAG_CAN_TP_OFF 0u |
#define | CTS_ON 1u |
#define | CTS_OFF 0u |
#define | WAIT_ON 1u |
#define | WAIT_OFF 0u |
#define | OVERFLOW_ABORT_ON 1u |
#define | OVERFLOW_ABORT_OFF 0u |
#define | OFFSET_FIRST_FRAME 6u |
Functions | |
void | CAN_TP_Tick (void) |
Timing function for CAN_TP. | |
void | CAN_TP_RxMessageBufferSet (CAN_TP_Header *header, uint8_t *buffer, uint32_t bufferSize) |
Sets the received message buffer and its size. | |
void | CAN_TP_RxSeparationTimeSet (CAN_TP_Header *header, uint8_t separationTime) |
Sets the separation time between received messages. | |
void | CAN_TP_RxBlockSizeSet (CAN_TP_Header *header, uint8_t blockSize) |
Sets the block size for received messages. | |
void | CAN_TP_NewMessage (CAN_TP_Header *header, void *data) |
Handles a new message received by CAN_TP. | |
void | CAN_TP_TransmitMessage (CAN_TP_Header *header, const uint8_t *data, uint32_t length) |
Initiates the transmission of a CAN_TP_Transmited message. | |
static void | CAN_TP_TxTransmit_Period_Task (CAN_TP_Header *header) |
Transmits CAN_TP messages based on the current state. | |
static void | CAN_TP_RxReceive_Period_Task (CAN_TP_Header *header) |
Handles the received CAN_TP messages. | |
uint8_t | CAN_TP_IsMessageReady (const CAN_TP_Header *header) |
Checks if the message is ready to be processed. | |
void | CAN_TP_MessageGet (CAN_TP_Header *header, uint8_t *data, uint8_t data_length) |
Gets the processed message. | |
void | CAN_TP_Init (CAN_TP_Header *header) |
Initializes the CAN_TP configuration for the CAN_TP_Periodic_Task. | |
void | CAN_TP_Periodic_Task (CAN_TP_Header *header) |
Task process for CAN_TP. | |
void | CAN_TP_TransmitInterruptMessage (CAN_TP_Header *header) |
Message transmission with interruption. | |
Variables | |
static uint8_t | flag_can_tp_flowcontrol_status [3] = { 0u , 0u , 0u } |
Array to store CAN_TP flow control status flags. | |
Board Support Package.
File provides the neccesary drivers, libraries, and configurations for the CAN BUS.
============================================================================== ##### How to use this driver ##### ============================================================================== Interruption necessary: - HAL_FDCAN_RxFifo0Callback( FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs ) - HAL_FDCAN_TxFifoEmptyCallback( FDCAN_HandleTypeDef *hfdcan ) In the interrupcion HAL_FDCAN_RxFifo0Callback, you need to put the function CAN_TP_NewMessage( CAN_TP_Header *header, void *data ); For example: void HAL_FDCAN_RxFifo0Callback( FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs ) { FDCAN_RxHeaderTypeDef CANRxHeader; static uint8_t RxData[ 8 ] = { 0 }; HAL_FDCAN_GetRxMessage( hfdcan, FDCAN_RX_FIFO0, &CANRxHeader, RxData ); CAN_TP_NewMessage( &features_packet, (void *)RxData ); } In the interrupcion HAL_FDCAN_TxFifoEmptyCallback, you need to put the function void CAN_TP_TransmitInterruptMessage( CAN_TP_Header *header ); For example: void HAL_FDCAN_TxFifoEmptyCallback( FDCAN_HandleTypeDef *hfdcan ) { CAN_TP_TransmitInterruptMessage(&features_packet); } Important!!! You must select the size of message that your bufferRx will receive: #define MAX_ARRAY_SIZE 25 For the receiving this is a example: static CAN_TP_Header features_packet; void vTask1( void *pvParameters ) { uint8_t rxBuffer[ 22 ] = { 0 }; uint8_t messageRx[ 22 ] = { 0 }; uint8_t value = 1u; CAN_TP_Init( &features_packet ); CAN_TP_RxBlockSizeSet( &features_packet, 10 ); CAN_TP_RxSeparationTimeSet( &features_packet, 10 ); CAN_TP_RxMessageBufferSet( &features_packet, rxBuffer, sizeof( rxBuffer ) ); for( ;; ) { CAN_TP_Periodic_Task( &features_packet ); if( value == CAN_TP_IsMessageReady( &features_packet ) ) { CAN_TP_MessageGet( &features_packet, messageRx, sizeof( messageRx ) ); SEGGER_RTT_printf( 0, "Message:" ); for( uint8_t i = 0; i < sizeof( messageRx ); i++ ) { SEGGER_RTT_printf( 0, " %x", messageRx[ i ] ); } SEGGER_RTT_printf( 0, "\n" ); } vTaskDelay( 100 ); } (void)pvParameters; } For the transmision this is a example:
#define CONSECUTIVE_FRAME_TYPE 2u |
Frame type to mark consecutive frame
#define CONTINUE_TO_SEND 0u |
Indicate the flow control flag 0
#define CTS_OFF 0u |
Indicate the number when the flow control flag 0 is not ready
#define CTS_ON 1u |
Indicate the number when the flow control flag 0 is ready
#define FIRST_FRAME_TYPE 1u |
Frame type to mark the first frame
#define FLAG_CAN_TP_OFF 0u |
The flag indicates when CAN TP is not ready to transmit a message
#define FLAG_CAN_TP_ON 1u |
The flag indicates when CAN TP is ready to transmit a message
#define FLOW_CONTROL_FRAME_TYPE 3u |
Frame type to mark the flow control frame
#define OFFSET_FIRST_FRAME 6u |
Offset data of the first frame because it transmitted 6 bytes of data
#define OVERFLOW_ABORT 2u |
Indicate the flow control flag 2
#define OVERFLOW_ABORT_OFF 0u |
Indicate the number when the flow control flag 2 is not ready
#define OVERFLOW_ABORT_ON 1u |
Indicate the number when the flow control flag 2 is ready
#define SINGLE_FRAME_TYPE 0u |
Frame type to mark a single frame
#define WAIT 1u |
Indicate the flow control flag 1
#define WAIT_OFF 0u |
Indicate the number when the flow control flag 1 is not ready
#define WAIT_ON 1u |
Indicate the number when the flow control flag 1 is ready
void CAN_TP_Init | ( | CAN_TP_Header * | header | ) |
Initializes the CAN_TP configuration for the CAN_TP_Periodic_Task.
Function necessary for work with normality
header | CAN_TP header data structure. |
< The flag indicates when CAN TP is not ready to transmit a message
< The flag indicates when CAN TP is not ready to transmit a message
uint8_t CAN_TP_IsMessageReady | ( | const CAN_TP_Header * | header | ) |
Checks if the message is ready to be processed.
Function that tells us if we can read the complete message received through CAN_TP
header | CAN_TP header data structure. |
void CAN_TP_MessageGet | ( | CAN_TP_Header * | header, |
uint8_t * | data, | ||
uint8_t | data_length ) |
Gets the processed message.
Function to extract all the message received by CAN TP into a variable and then delete all the message received in the Rx buffer.
header | CAN_TP header data structure. |
data | Pointer to the message data. |
data_length | Length of the data to retrieve. |
void CAN_TP_NewMessage | ( | CAN_TP_Header * | header, |
void * | data ) |
Handles a new message received by CAN_TP.
Function to implement in HAL_FDCAN_RxFifo0Callback. This function tells us when to enter CAN_TP_RxReceive_Period_Task
header | CAN_TP header data structure. |
data | Pointer to the received message data. |
void CAN_TP_Periodic_Task | ( | CAN_TP_Header * | header | ) |
Task process for CAN_TP.
Function switches the CAN TP periodically if it transmits or receives.
header | CAN_TP header data structure. |
< The flag indicates when CAN TP is ready to transmit a message
< The flag indicates when CAN TP is not ready to transmit a message
void CAN_TP_RxBlockSizeSet | ( | CAN_TP_Header * | header, |
uint8_t | blockSize ) |
Sets the block size for received messages.
Function to indicate the blocks that will be received in the transmission of messages. If kept at 0, message limits will not be taken into account for transmission.
header | CAN_TP header data structure. |
blockSize | Block size. |
void CAN_TP_RxMessageBufferSet | ( | CAN_TP_Header * | header, |
uint8_t * | buffer, | ||
uint32_t | bufferSize ) |
Sets the received message buffer and its size.
Function to indicate the size and memory space of the Rx buffer where the messages received from the data transmission will be saved.
header | CAN_TP header data structure. |
buffer | Received message buffer. |
bufferSize | Size of the message buffer. |
|
static |
Handles the received CAN_TP messages.
This function processes the received CAN_TP messages, including flow control frames, first frames, and consecutive frames. It updates the transmission state accordingly. Also save the decoded message from the reception.
header | CAN_TP header data structure. |
< Frame type to mark the flow control frame
< Indicate the flow control flag 0
< Indicate the flow control flag 0
< Indicate the number when the flow control flag 0 is ready
< Indicate the flow control flag 1
< Indicate the flow control flag 1
< Indicate the number when the flow control flag 1 is ready
< Indicate the flow control flag 2
< Indicate the flow control flag 2
< Indicate the number when the flow control flag 2 is ready
< Frame type to mark a single frame
< Frame type to mark the first frame
< Frame type to mark consecutive frame
void CAN_TP_RxSeparationTimeSet | ( | CAN_TP_Header * | header, |
uint8_t | separationTime ) |
Sets the separation time between received messages.
Function to indicate the separation time of message transmission for the Rx buffer. If kept at 0, no waiting limits will apply between received messages.
header | CAN_TP header data structure. |
separationTime | Separation time between messages. |
void CAN_TP_Tick | ( | void | ) |
Timing function for CAN_TP.
Function that counts CAN TP ticks to ensure separation time and sending of a wait, overflow/abort.
void CAN_TP_TransmitInterruptMessage | ( | CAN_TP_Header * | header | ) |
Message transmission with interruption.
Function that calls CAN_TP_TxTransmit_Period_Task when the flag_interruption is activated, this happens when a flowcontrol typeframe CTS is received.
header | CAN_TP header data structure. |
< The flag indicates when CAN TP is ready to transmit a message
void CAN_TP_TransmitMessage | ( | CAN_TP_Header * | header, |
const uint8_t * | data, | ||
uint32_t | length ) |
Initiates the transmission of a CAN_TP_Transmited message.
The function analyzes whether to send a single frame or multiple consecutive frames depending on the length of the data. In the case of multiple consecutive frames, the number of consecutive frames that will be sent is calculated.
header | CAN_TP header data structure. |
data | Pointer to the message data. |
length | Length of the message. |
< The flag indicates when CAN TP is ready to transmit a message
< Offset data of the first frame because it transmitted 6 bytes of data
< Offset data of the first frame because it transmitted 6 bytes of data
< Offset data of the first frame because it transmitted 6 bytes of data
< Offset data of the first frame because it transmitted 6 bytes of data
< Offset data of the first frame because it transmitted 6 bytes of data
< The flag indicates when CAN TP is ready to transmit a message
|
static |
Transmits CAN_TP messages based on the current state.
This function manages the transmission of CAN_TP messages, including first frames and consecutive frames. It handles the flow control logic and updates the state for transmission. To make the transmissions, right shifts are made depending on the type of frame for the general data bytes of the frame and in the data bytes a while is used to extract the message sent by the user and encode it in the corresponding variable.
header | CAN_TP header data structure. |
< Frame type to mark the first frame
< Frame type to mark a single frame
< Frame type to mark a single frame
< Frame type to mark the first frame
< The flag indicates when CAN TP is not ready to transmit a message
< Frame type to mark the first frame
< Frame type to mark the flow control frame
< Frame type to mark consecutive frame
< Offset data of the first frame because it transmitted 6 bytes of data
< Frame type to mark consecutive frame
< Offset data of the first frame because it transmitted 6 bytes of data
< Frame type to mark consecutive frame
< Offset data of the first frame because it transmitted 6 bytes of data
< Frame type to mark the first frame
< The flag indicates when CAN TP is not ready to transmit a message
< The flag indicates when CAN TP is not ready to transmit a message
< Frame type to mark the flow control frame
< Indicate the flow control flag 0
< Indicate the number when the flow control flag 0 is ready
< Frame type to mark consecutive frame
< The flag indicates when CAN TP is ready to transmit a message
< The flag indicates when CAN TP is not ready to transmit a message
< Indicate the flow control flag 1
< Indicate the number when the flow control flag 1 is ready
< Indicate the flow control flag 2
< Indicate the number when the flow control flag 2 is ready
|
static |
Array to store CAN_TP flow control status flags.
This array holds the status flags indicating the flow control conditions for CAN_TP transmission. Index 0 represents 'Continue to Send' (CTS), index 1 represents 'Wait', and index 2 represents 'Overflow Abort'. Initial values are set to indicate OFF states for all conditions.