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

This example is to manage the low power modes for the microcontroler

/*
* @file pwr.c
* @author TST
* @version V0.0
* @date 00/00/0000
* @brief PWR example.
*/
#include "tsmart.h"
#define LED tsmart_dio0a
#define BUTTON tsmart_dio1a
#define REPLAY 1
/*
* Task function.
* Main process Entering in Stop Mode in 10 Seconds
* Exit from Stop Mode with Any EXTI line (configured in the EXTI registers) [BUTTON]
* Replay
* Main process Entering in Standby Mode in 10 Seconds
* 5 seconds later RTC Almarm Wake Up and Re-Start the System
*
*/
void vPWR_EXAMPLE(void *pvParameters){
/* Variables */
uint8_t replay = REPLAY;
tsmart_rtc_time_t time_alarm;
/* Load time_alarm structure 5 seconds */
time_alarm.year = 0;
time_alarm.month = 0;
time_alarm.day = 0;
time_alarm.hour = 0;
time_alarm.minute = 0;
time_alarm.second = 10;
do{
vTaskDelay(5000/portTICK_RATE_MS);
if (replay!=0){
TSMART_UART_Send(&tsmart_uart1, "\r\nEntering STOP Mode\r\n", strlen("\r\nEntering STOP Mode\r\n"), 1000/portTICK_RATE_MS);
TSMART_UART_Send(&tsmart_uart1, "\r\nExit STOP Mode\r\n", strlen("\r\nExit STOP Mode\r\n"), 1000/portTICK_RATE_MS);
}else{
/* Set the time alarm */
TSMART_RTC_SetAlarmIn(&time_alarm);
TSMART_UART_Send(&tsmart_uart1, "\r\nEntering STANDBY Mode\r\n", strlen("\r\nEntering STANDBY Mode\r\n"), 1000/portTICK_RATE_MS);
BKP_WriteBackupRegister(BKP_DR1,0x01);
}
replay --;
}while(1);
}
/*
* Task function. Back process Blink LED every second
*
*/
void vBACK(void *pvParameters){
do{
vTaskDelay(500/portTICK_RATE_MS);
}while(1);
}
/*
* @brief Task function. User writes data through the hyperterminal. The UART sends the data and
* read the same values that were written (echo), printing them in the hyperterminal
*
* @param pvParameters
*
*/
void vUART_EXAMPLE(void *pvParameters){
/* Variables */
uint8_t echo;
uint8_t title1[64]="\r\n\r\n\t\t\tLow Power Example\r\n\t\t\r\n\r\n";
uint8_t title2[64]="\r\n\r\n\t\t\tRe-Start from Standby\r\n\t\t\r\n\r\n";
/* A title is sent through the UART and printed on the hyperterminal */
if (BKP_ReadBackupRegister(BKP_DR1) == 0){
TSMART_UART_Send(&tsmart_uart1, title1, strlen(title1), 1000/portTICK_RATE_MS);
}
else{
TSMART_UART_Send(&tsmart_uart1, title2, strlen(title2), 1000/portTICK_RATE_MS);
BKP_WriteBackupRegister(BKP_DR1,0x00);
}
for(;;){
/* User types any character with the keyboard through the hyperterminal */
TSMART_UART_Receive(&tsmart_uart1, &echo, 1, portMAX_DELAY);
/* The UART sends the character previously written and is printed on the hyperterminal */
TSMART_UART_Send(&tsmart_uart1, &echo, 1, 1000/portTICK_RATE_MS);
}
}
/*
* @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() {
/* Variables */
tsmart_dio_config_t tsmart_dio_config;
tsmart_dio_config_t tsmart_dio_config_read;
tsmart_dio_config_t tsmart_dio_config_wakeup;
tsmart_uart_config_t tsmart_uart_config;
/* Reception buffer UART. Size must be the same as rx_buf_sz */
static uint8_t app_rx_buf[50];
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* Enable Wake Up Pin (M1 pin 12) for standby mode */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_WakeUpPinCmd(ENABLE);
/* DIO configuration. User needs to configure the DIO to connect a LED */
tsmart_dio_config.mode = TSMART_DIO_OD;
tsmart_dio_config.irq_mode = TSMART_DIO_IRQ_NULL;
/* DIO configuration for reading. User needs to define the DIO as an input */
tsmart_dio_config_read.mode = TSMART_DIO_IPU;
tsmart_dio_config_read.irq_mode = TSMART_DIO_IRQ_FALLING;
/* Initialize DIOs
* User must initialize the DIOs to use. In this example one for reading a value and another one for
* connecting a LED */
TSMART_DIO_Init(&LED, &tsmart_dio_config);
TSMART_DIO_Init(&BUTTON, &tsmart_dio_config_read);
/* UART configuration. */
/* Baud rate */
tsmart_uart_config.baud_rate = 19200;
/* Flow control */
tsmart_uart_config.flow_control = TSMART_UART_FC_NONE;
/* Parity bit */
tsmart_uart_config.parity_bit = TSMART_UART_PARITY_NONE;
/* Word length */
tsmart_uart_config.word_length = TSMART_UART_WORDLENGTH_8B;
/* Stop bit */
tsmart_uart_config.stop_bit = TSMART_UART_STOPBITS_1;
/* Buffer size for our UART */
tsmart_uart_config.rx_buf_sz = 50;
/* Buffer for our UART */
tsmart_uart_config.rx_buf = app_rx_buf;
/* UART DMA */
tsmart_uart_config.use_dma = TSMART_UART_DMA_RX_TX;
/* UART time out */
tsmart_uart_config.use_tim = TSMART_UART_TIM_SW;
/* Initialize UART. UART 1 is selected */
TSMART_UART_Init(&tsmart_uart1, &tsmart_uart_config);
/* Initialize RTC */
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create the DIO_READ_EXAMPLE task */
if(xTaskCreate(vPWR_EXAMPLE, "PWR_EXAMPLE", 512, NULL, 8, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Create the BackGroud task */
if(xTaskCreate(vBACK, "BACK_EXAMPLE", 512, NULL, 1, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Create the UART task */
if(xTaskCreate(vUART_EXAMPLE, "UART_EXAMPLE", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}