Microchip® Advanced Software Framework

sam/applications/getting-started/main.c File Reference

Getting Started Application.

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 BLINK_PERIOD   1000
 LED0 blink time, LED1 blink half this time, in ms. More...
 
#define IRQ_PRIOR_PIO   0
 IRQ priority for PIO (The lower the value, the greater the priority) More...
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 

Functions

static void Button1_Handler (uint32_t id, uint32_t mask)
 Handler for Button 1 rising edge interrupt. More...
 
static void Button2_Handler (uint32_t id, uint32_t mask)
 Handler for Button 2 falling edge interrupt. More...
 
static void configure_buttons (void)
 Configure the Pushbuttons. More...
 
static void configure_console (void)
 Configure UART console. More...
 
static void configure_tc (void)
 Configure Timer Counter 0 to generate an interrupt every 250ms. More...
 
int main (void)
 getting-started Application entry point. More...
 
static void mdelay (uint32_t ul_dly_ticks)
 Wait for the given number of milliseconds (using the g_ul_ms_ticks generated by the SAM's microcontrollers's system tick). More...
 
static void ProcessButtonEvt (uint8_t uc_button)
 Process Buttons Events. More...
 
void SysTick_Handler (void)
 Handler for System Tick interrupt. More...
 
void TC0_Handler (void)
 Interrupt handler for TC0 interrupt. More...
 

Variables

volatile bool g_b_led0_active = true
 LED0 blinking control. More...
 
volatile uint32_t g_ul_ms_ticks = 0
 Global g_ul_ms_ticks in milliseconds since start of application. More...
 

#define BLINK_PERIOD   1000

LED0 blink time, LED1 blink half this time, in ms.

#define IRQ_PRIOR_PIO   0

IRQ priority for PIO (The lower the value, the greater the priority)

Referenced by configure_buttons().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"-- Getting Started 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: sam/applications/getting-started/main.c:94

Referenced by main().

static void Button1_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 1 rising edge interrupt.

Handle process led1 status change.

References ProcessButtonEvt().

Referenced by configure_buttons().

static void Button2_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 2 falling edge interrupt.

Handle process led2 status change.

References ProcessButtonEvt().

Referenced by configure_buttons().

static void configure_buttons ( void  )
static

Configure the Pushbuttons.

Configure the PIO as inputs and generate corresponding interrupt when pressed or released.

References Button1_Handler(), Button2_Handler(), IRQ_PRIOR_PIO, pio_enable_interrupt(), pio_set_debounce_filter(), and pmc_enable_periph_clk().

Referenced by main().

static void configure_console ( void  )
static

Configure UART console.

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

Referenced by main().

static void configure_tc ( void  )
static

Configure Timer Counter 0 to generate an interrupt every 250ms.

Configure TC for a 4Hz frequency and trigger on RC compare.

References pmc_disable_pck(), pmc_enable_pck(), pmc_enable_periph_clk(), pmc_switch_pck_to_sclk(), sysclk_get_cpu_hz(), tc_enable_interrupt(), tc_find_mck_divisor(), tc_init(), tc_start(), and tc_write_rc().

Referenced by main().

int main ( void  )

getting-started Application entry point.

Returns
Unused (ANSI-C compatibility).

[main_step_sys_init]

[main_step_sys_init]

[main_step_console_init]

[main_step_console_init]

[main_step_systick_init]

[main_step_systick_init]

[main_step_tc_init]

[main_step_tc_init]

[main_step_btn_init]

[main_step_btn_init]

[main_step_loop]

[main_step_loop]

References board_init(), configure_buttons(), configure_console(), configure_tc(), g_b_led0_active, IOPORT_DIR_INPUT, ioport_set_pin_dir(), ioport_set_pin_mode(), ioport_set_pin_sense_mode(), ioport_toggle_pin_level(), mdelay(), STRING_HEADER, sysclk_get_cpu_hz(), and sysclk_init().

static void mdelay ( uint32_t  ul_dly_ticks)
static

Wait for the given number of milliseconds (using the g_ul_ms_ticks generated by the SAM's microcontrollers's system tick).

Parameters
ul_dly_ticksDelay to wait for, in milliseconds.

References g_ul_ms_ticks.

Referenced by main().

static void ProcessButtonEvt ( uint8_t  uc_button)
static

Process Buttons Events.

Change active states of LEDs when corresponding button events happened.

References g_b_led0_active, IOPORT_PIN_LEVEL_HIGH, IOPORT_PIN_LEVEL_LOW, ioport_set_pin_level(), tc_start(), and tc_stop().

Referenced by Button1_Handler(), and Button2_Handler().

void SysTick_Handler ( void  )

Handler for System Tick interrupt.

Process System Tick Event Increments the g_ul_ms_ticks counter.

References g_ul_ms_ticks.

void TC0_Handler ( void  )

Interrupt handler for TC0 interrupt.

Toggles the state of LED#2.

References ioport_toggle_pin_level(), tc_get_status(), and UNUSED.

volatile bool g_b_led0_active = true

LED0 blinking control.

Referenced by main(), and ProcessButtonEvt().

volatile uint32_t g_ul_ms_ticks = 0

Global g_ul_ms_ticks in milliseconds since start of application.