Microchip® Advanced Software Framework

rtt_example.c File Reference

Real-time Timer (RTT) example for SAM.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"
#include "conf_clock.h"

Macros

#define ASCII_BS   8
 ASCII char definition for backspace. More...
 
#define ASCII_CR   13
 ASCII char definition for carriage return. More...
 
#define STATE_MAIN_MENU   0
 Device state: in the main menu. More...
 
#define STATE_SET_ALARM   1
 Device state: user is setting an alarm time. More...
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 

Functions

static void configure_console (void)
 Configure the console UART. More...
 
static void configure_rtt (void)
 RTT configuration function. More...
 
int main (void)
 Application entry point for RTT example. More...
 
static void refresh_display (void)
 Refresh display on terminal. More...
 
void RTT_Handler (void)
 Interrupt handler for the RTT. More...
 

Variables

volatile uint8_t g_uc_alarmed
 Indicate that an alarm has occurred but has not been cleared. More...
 
volatile uint8_t g_uc_state
 Current device state. More...
 
volatile uint32_t g_ul_new_alarm
 New alarm time being currently entered. More...
 

#define ASCII_BS   8

ASCII char definition for backspace.

Referenced by main().

#define ASCII_CR   13

ASCII char definition for carriage return.

Referenced by main().

#define STATE_MAIN_MENU   0

Device state: in the main menu.

Referenced by main(), and refresh_display().

#define STATE_SET_ALARM   1

Device state: user is setting an alarm time.

Referenced by main(), and refresh_display().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"-- RTT Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: fatfs_access_example.c:112
#define STRING_EOL
Definition: rtt_example.c:94

Referenced by main().

static void configure_console ( void  )
static

Configure the console UART.

References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().

Referenced by main().

static void configure_rtt ( void  )
static

RTT configuration function.

Configure the RTT to generate a one second tick, which triggers the RTTINC interrupt.

References rtt_enable_interrupt(), rtt_init(), and rtt_read_timer_value().

Referenced by main().

int main ( void  )

Application entry point for RTT example.

Initialize the RTT, display the current time and allow the user to perform several actions: clear the timer, set an alarm, etc.

Returns
Unused (ANSI-C compatibility).

References ASCII_BS, ASCII_CR, board_init(), configure_console(), configure_rtt(), g_uc_alarmed, g_uc_state, g_ul_new_alarm, refresh_display(), rtt_write_alarm_time(), STATE_MAIN_MENU, STATE_SET_ALARM, STRING_HEADER, and sysclk_init().

static void refresh_display ( void  )
static

Refresh display on terminal.

Update the terminal display to show the current menu and the current time depending on the device state.

References g_uc_alarmed, g_uc_state, g_ul_new_alarm, rtt_read_timer_value(), STATE_MAIN_MENU, and STATE_SET_ALARM.

Referenced by main(), and RTT_Handler().

void RTT_Handler ( void  )

Interrupt handler for the RTT.

Display the current time on the terminal.

References g_uc_alarmed, refresh_display(), and rtt_get_status().

volatile uint8_t g_uc_alarmed

Indicate that an alarm has occurred but has not been cleared.

Referenced by main(), refresh_display(), and RTT_Handler().

volatile uint8_t g_uc_state

Current device state.

Referenced by main(), refresh_display(), and USART0_Handler().

volatile uint32_t g_ul_new_alarm

New alarm time being currently entered.

Referenced by main(), and refresh_display().