API  2.3.0
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
rtc.c

This is an example showing how to use the real time clock (RTC) process. User sets a date an a time from which the clock will start counting. User also sets a date and a time alarm. When the clock reaches the time alarm, a LED will switch on.

/*
* @file rtc.c
* @author TST
* @version V0.0
* @date 14/06/2012
* @brief RTC example. Set a date and an hour. Then set an alarm. When the time alarm is reached,
* switch on a LED
*
*/
#include "tsmart.h"
/*
* @brief Task function. Main process to set a date and an hour. We also set an alarm time, when it is reached, a LED
* will switch on.
*
* @param pvParameters
*/
void vRTC_EXAMPLE(void *pvParameters){
tsmart_rtc_time_t time_alarm;
/* Load the date and time structure parameters by setting a date and a time */
/* Load time structure */
time.year = 2012;
time.month = 06;
time.day = 14;
time.hour = 11;
time.minute = 00;
time.second = 00;
/* Load the time_alarm structure parameters with the date and time for our alarm.
* In this example the alarm is set 5 seconds later from the starting time */
/* Load time_alarm structure */
time_alarm.year = 2012;
time_alarm.month = 06;
time_alarm.day = 14;
time_alarm.hour = 11;
time_alarm.minute = 00;
time_alarm.second = 05;
/* Set the time. The clock starts counting from the time previously set */
/* Set the time alarm */
TSMART_RTC_SetAlarm(&time_alarm);
for(;;){
/* User waits until the time alarm is reached. When it happens, a LED is switched on */
if(TSMART_RTC_WaitForAlarm(portMAX_DELAY) == TSMART_PASS){
/* Switch on the LED through its associated DIO */
}
}
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
tsmart_dio_config_t tsmart_dio_config;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* Set DIO configuration for its operation mode */
tsmart_dio_config.mode = TSMART_DIO_OD;
tsmart_dio_config.irq_mode = TSMART_DIO_IRQ_NULL;
/* Initialize the selected DIO where our LED is connected */
TSMART_DIO_Init(&tsmart_dio7, &tsmart_dio_config);
/* Initialize RTC */
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* We create the RTC task */
if(xTaskCreate(vRTC_EXAMPLE, "RTC_EXAMPLE", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}