Programmable Clock with RTOS 0.0.1
Implementaiton of a programmable clock using RTOS with STM32GO microcontroller.
|
Message processing implementation More...
Data Structures | |
struct | SerialStates |
Struct with pointer to function. More... | |
Functions | |
static void | CanTp_SingleFrameTx (uint8_t *data, uint8_t size) |
Transmition in CAN-TP single frame format | |
static uint8_t | CanTp_SingleFrameRx (uint8_t *data, uint8_t *size) |
CAN-TP single frame format | |
static uint8_t | Validate_Time (uint8_t hour, uint8_t minutes, uint8_t seconds) |
Validate time | |
static uint8_t | Validate_Alarm (uint8_t hour, uint8_t minutes) |
Validate alarm | |
static uint8_t | Validate_Date (uint8_t days, uint8_t month, uint16_t year) |
Validate date | |
static uint8_t | WeekDay (uint8_t days, uint8_t month, uint16_t year) |
Validate the day of the week | |
static MACHINE_SERIAL | Serial_StMachine (NEW_MsgTypeDef *pdata) |
Main state machine | |
static MACHINE_SERIAL | SerialTimeState (NEW_MsgTypeDef *pmsg) |
Serial time function | |
static MACHINE_SERIAL | SerialDateState (NEW_MsgTypeDef *pmsg) |
Serial date function | |
static MACHINE_SERIAL | SerialAlarmState (NEW_MsgTypeDef *pmsg) |
Serial alarm function | |
static MACHINE_SERIAL | SerialOkState (NEW_MsgTypeDef *pmsg) |
Serial ok function | |
static MACHINE_SERIAL | SerialErrorState (NEW_MsgTypeDef *pmsg) |
Serial error function | |
static uint8_t | BCD_conver (uint8_t data) |
BCD converter Function to unpacked from CAN-TP single frame format to BCD. | |
void | Serial_Init (void) |
Initialize of CAN port | |
void | HAL_FDCAN_RxFifo0Callback (FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) |
Reception of CAN messages | |
void | Serial_Task (void) |
Call of the serial state machine | |
Variables | |
FDCAN_HandleTypeDef | CANHandler |
Structure type variable for CAN handler. | |
static FDCAN_TxHeaderTypeDef | CANTxHeader |
Structure type variable for CAN transmissin initialization. | |
Message processing implementation
Contains the functions to initialize the CAN port with the apropiate parameters, the callback to the CAN interruption, also the main state machine to message processing were the CAN frame will be evaluate to aprove it or not and to be assigned to the struct variable by the fuction in charge of it.
|
static |
BCD converter Function to unpacked from CAN-TP single frame format to BCD.
< Macro defined for testing purposes.
data | [in] value to convert |
Returns | an unsigned integer |
< Macro defined for testing purposes.
|
static |
CAN-TP single frame format
< Macro defined for testing purposes.
The function validate if the message received complies with CAN-TP single frame format.
data | [in] Pointer to data |
size | [in] Size of data |
The | function returns 1 when a certain number of bytes were received, otherwise, no message was received |
< Macro defined for testing purposes.
|
static |
Transmition in CAN-TP single frame format
< Macro defined for testing purposes.
This function transmit the ok or error messages through the terminal when the data is already procesed, will be send 0x55 if the data was in range and the 0xAA if the data was not in range with CAN-ID of 0x122
data | [in] Pointer to data |
size | [in] Size of data |
< Macro defined for testing purposes.
void HAL_FDCAN_RxFifo0Callback | ( | FDCAN_HandleTypeDef * | hfdcan, |
uint32_t | RxFifo0ITs ) |
Reception of CAN messages
Callback to the CAN interrup, it is activated when a message is recieve then is store in the variable NewMessage
hfdcan | [in] To handle CAN |
RxFifo0ITs | [in] void Valid_Time( uint8_t *data ); |
< Number 0
< Single frame element recieved
< Single frame element recieved
void Serial_Init | ( | void | ) |
Initialize of CAN port
Is the function to initialize all the required to start working with the CAN port and the messages reception processing
< Value for ExtFiltersNbr
< Value for StdFiltersNbr
< Value for NominalPrescaler
< Value for NominalSyncJumpWidth
< Value for NominalTimeSeg1
< Value for NominalTimeSeg2
< Value for Identifier
< Value for FilterIndex
< Value for FilterID1
< Value for FilterID2
< Value for BufferIndexes
|
static |
Main state machine
< Macro defined for testing purposes.
Is going to implement the state machine in charge of calling the function for the new message, after the interruption of CAN is trigger, depending if it is a message of time, date and alarm.
pdata | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Number 5
< Number 0
< Number 0
< Number 0
< Number 1
void Serial_Task | ( | void | ) |
Call of the serial state machine
This function calls the serial state machine every 10ms with the help of queues, therefore it won't be execute all the time
< Single frame element recieved
< True in a comparison
|
static |
Serial alarm function
< Macro defined for testing purposes.
Is going to evaluate if the data for alarm is valid and send the message to the queue.
pmsg | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Macro defined for testing purposes.
< Message location
< Alarm hour element recieved
< Alarm min element recieved
< True in a comparison
< The maximum amount of time
< Message location
< The maximum amount of time
|
static |
Serial date function
< Macro defined for testing purposes.
Is going to evaluate if the data for date is valid and send the message to the queue.
pmsg | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Macro defined for testing purposes.
< Message location
< Date day element recieved
< Date month element recieved
< Date MSB year element recieved
< Number 100
< Date MSB year element recieved
< True in a comparison
< The maximum amount of time
< Message location
< The maximum amount of time
|
static |
Serial error function
< Macro defined for testing purposes.
Is going to transmit a message through CAN to indicate the data is not valid.
pmsg | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Macro defined for testing purposes.
< Number 0
< Message for error in data in hexa
< Single frame element recieved
|
static |
Serial ok function
< Macro defined for testing purposes.
Is going to assign the data to the variable clockMsg and send it to the queue of the clock, then it will transmit a message through CAN to indicate the data is valid.
pmsg | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Macro defined for testing purposes.
< Number 0
< Message for ok data in hexa
< Single frame element recieved
|
static |
Serial time function
< Macro defined for testing purposes.
Is going to evaluate if the data for time is valid and send the message to the queue.
pmsg | [in] Pointer to data struct |
Returns | the next state that will be executed |
< Macro defined for testing purposes.
< Message location
< Time hour element recieved
< Time min element recieved
< Time sec element recieved
< True in a comparison
< The maximum amount of time
< Message location
< The maximum amount of time
|
static |
Validate alarm
< Macro defined for testing purposes.
This function validates if the Alarm message is in range, from 0 to 23 for hours and from 0 to 59 to minutes, no seconds nedded, and then returns the result.
hour | [in] Hour value |
minutes | [in] Minutes value |
The | function returns 1 if the alarm is correct and 0 if not |
< Macro defined for testing purposes.
< Number 0
< Max hour 23 in hexa
< Max seconds 59 in hexa
< Number 1
|
static |
Validate date
< Macro defined for testing purposes.
This function validates if the date message is in range, from 1 to 31 for days, from 1 to 12 for months and from 1901 to 2099 for years and returns the result. In addition it also vaidates if the date is in a leap-year and adjust the month of February to manage 29 days.
days | [in] Day value |
month | [in] Month value |
year | [in] Year value |
The | function returns 1 if the date is correct and 0 if not |
< Macro defined for testing purposes.
< Min day, 1 in hexa
< Max days 31 in hexa
< January in hexa
< December in hexa
< Min year, 1901 in hexa
< Max year, 2099 in hexa
< Number 4
< Number 0
< February in hexa
< Days in leap year in february, 29 in hexa
< Number 1
< Number 0
< February in hexa
< Days in february, 28 in hexa
< Number 1
< April in hexa
< June in hexa
< September in hexa
< November in hexa
< Max days 30 in hexa
< Number 1
< January in hexa
< March in hexa
< May in hexa
< July in hexa
< August in hexa
< October in hexa
< December in hexa
< Number 1
< Number 0
< Number 0
|
static |
Validate time
< Macro defined for testing purposes.
This function validates if the time message is in range, from 0 to 23 for hours, from 0 to 59 for minutes and from 0 to 59 for seconds and returns the result.
hour | [in] Hour value |
minutes | [in] Minutes value |
seconds | [in] Seconds value |
The | function returns 1 if time is correct and 0 if not |
< Macro defined for testing purposes.
< Number 0
< Max hour 23 in hexa
< Max minutes 59 in hexa
< Max seconds 59 in hexa
< Number 1
|
static |
Validate the day of the week
< Macro defined for testing purposes.
This function calculates the day of the week according to the date, to do this, we will use Zeller's congruence. Taking the day, month and year to calculate the year of the century and the century. In this algorithm January and February are counted as months 13 and 14 of the previous year. With this data we use the formula for the Gregorian calendar.
days | [in] Day value |
month | [in] Month value |
year | [in] Year value |
The | function returns the values 0-Saturday, 1-Sunday, 2-Monday, 3-Tuesday, 4-Wednesday, 5-Thursday, 6-Friday |
< Macro defined for testing purposes.