Programmable Clock with RTOS 0.0.1
Implementaiton of a programmable clock using RTOS with STM32GO microcontroller.
Loading...
Searching...
No Matches
app_clock.c File Reference

Clock driver source file. More...

#include "app_clock.h"
#include "bsp.h"

Data Structures

struct  StateNode
 Struct for store function for each state of event machine. More...
 

Functions

static MACHINE_State state_serialMsgAlarm (APP_MsgTypeDef *receivedMessage)
 (State) Function executed when Serial Alarm message has been received
 
static MACHINE_State state_serialMsgDate (APP_MsgTypeDef *receivedMessage)
 (State) Function executed when Serial Date message has been received
 
static MACHINE_State state_serialMsgTime (APP_MsgTypeDef *receivedMessage)
 (State) Function executed when Serial Time message has been received
 
static MACHINE_State state_clockMsgPrint (APP_MsgTypeDef *receivedMessage)
 (State) Function executed when Clock Date message has been received
 
static MACHINE_State Clock_EventMachine (APP_MsgTypeDef *receivedMessage)
 Process message according to its type.
 
static void Clock_Update_DateAndTime (TimerHandle_t pxTimer)
 Function executed every second to print data in LCD.
 
void Clock_Init (void)
 Use once to Initialize the clock.
 
void Clock_Task (void)
 Run periodically. It allows to configure the clock.
 
void HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef *hrtc)
 Callback interruption of the ALARM.
 

Variables

RTC_HandleTypeDef RtcHandler
 Struct for handling RTC peripheral Declared in bsp.
 
static uint8_t dateYearH
 Variable for handling date correctly (stores 2 higher digits of year)
 
TimerHandle_t xTimerDisplay
 Struct for handling Software timer.
 
uint8_t Alarm_Active = 0
 Flag that tell us that alarm has been activated.
 
uint8_t Stop_Alarm = 0
 Flag that tell us that will stop the msg of alarm and clean it.
 

Detailed Description

Clock driver source file.

Find here source for interfaces and private functions which allows to initialize and set the clock

Function Documentation

◆ Clock_EventMachine()

MACHINE_State Clock_EventMachine ( APP_MsgTypeDef * receivedMessage)
static

Process message according to its type.

< Macro defined for testing purposes. Use in private members

Parameters
receivedMessageMessage readed from clockQueue which allows to move between states inside machine
Return values
Returnsthe next state that will be executed

The state machine is builded with pointers to functions stored inside a struct (StateNode) which represent a state of the machine

For improve the code reading, an array of StateNode (stateMachine) stores all the nodes (states of the machine)

Every time this function is executed, it calls a process according to the received message's type

< Total states in event machine

◆ Clock_Init()

void Clock_Init ( void )

Use once to Initialize the clock.

Initializes RTC peripheral using 32.768kHz external clock Sets time and date to 12:00:00 JAN 1 1999

< Value for RTC async prediv

< Value for RTC sync prediv

< Initial RTC hour

< Initial RTC minutes

< Initial RTC seconds

< Initial RTC subseconds

< Initial RTC day

< Initial RTC year 2 last digit

< Initial RTC year 2 first dig

< ID for timer used to update display

◆ Clock_Task()

void Clock_Task ( void )

Run periodically. It allows to configure the clock.

Verifies if clockQueue has elements to read, if it's true passes the received message(s) to eventmachine for processing data according to its type

< The maximum amount of time

< Statement is true

< Statement is false

< The maximum amount of time

◆ Clock_Update_DateAndTime()

void Clock_Update_DateAndTime ( TimerHandle_t pxTimer)
static

Function executed every second to print data in LCD.

< Macro defined for testing purposes. Use in private members

Parameters
pxTimerTimer handler

Sends a message every second to clockQueue indicating data must be printed in LCD

◆ HAL_RTC_AlarmAEventCallback()

void HAL_RTC_AlarmAEventCallback ( RTC_HandleTypeDef * hrtc)

Callback interruption of the ALARM.

This interruption activates it when the alarm has been setted, when it happens it will desactivated the alarm and will send us to the case of displaying the ALARM. Also, the timer for displaying each second will stop

Parameters
hrtcA pointer to the RTC structure

< Alarm active

< The maximum amount of time

< The maximum amount of time

◆ state_clockMsgPrint()

MACHINE_State state_clockMsgPrint ( APP_MsgTypeDef * receivedMessage)
static

(State) Function executed when Clock Date message has been received

Parameters
receivedMessageMessage received from clockQueue
Return values
Returnsthe next state that will be executed

Sends a message to display queue indicating data must be printed in LCD Due to event machine implementation, the parameter must be passed but specified as UNUSED

◆ state_serialMsgAlarm()

MACHINE_State state_serialMsgAlarm ( APP_MsgTypeDef * receivedMessage)
static

(State) Function executed when Serial Alarm message has been received

Parameters
receivedMessageMessage received from clockQueue
Return values
Returnsthe next state that will be executed

Sets the RTC with received alarm with interrupt

Sends message to clockQueue everytime a type alarm message has been received

< Alarm active

< The maximum amount of time

< Alarm inactive

< Statement is true

< The maximum amount of time

◆ state_serialMsgDate()

MACHINE_State state_serialMsgDate ( APP_MsgTypeDef * receivedMessage)
static

(State) Function executed when Serial Date message has been received

Parameters
receivedMessageMessage received from clockQueue
Return values
Returnsthe next state that will be executed

Sets the RTC with received date Sends message to clockQueue everytime a type date message has been received

< Alarm active

< The maximum amount of time

< Alarm inactive

< Statement is true

◆ state_serialMsgTime()

MACHINE_State state_serialMsgTime ( APP_MsgTypeDef * receivedMessage)
static

(State) Function executed when Serial Time message has been received

Parameters
receivedMessageMessage received from clockQueue
Return values
Returnsthe next state that will be executed

Sets the RTC with received time Sends message to clockQueue everytime a time date message has been received

< Alarm active

< The maximum amount of time

< Alarm inactive

< Statement is true