1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/hardware/sam/system/libsam/cmsis/cmsis_example/main.c

96 lines
1.5 KiB
C
Raw Normal View History

2011-09-06 21:05:41 +02:00
/*
%atmel_license%
*/
/** \file cmsis example */
#include <stdlib.h>
#include <compiler.h>
#include <board.h>
#include "conf_board.h"
2011-09-06 21:05:41 +02:00
//! counts 1ms timeTicks
volatile uint32_t dw_ms_ticks = 0;
2011-09-06 21:05:41 +02:00
/**
* \brief SysTick_Handler.
*/
void SysTick_Handler(void)
{
2011-09-06 21:05:41 +02:00
// increment counter necessary in delay()
dw_ms_ticks++;
}
2011-09-06 21:05:41 +02:00
/**
* \brief delays number of tick Systicks (happens every 1 ms)
*/
__INLINE static void delay_ms(uint32_t dw_dly_ticks)
{
2011-09-06 21:05:41 +02:00
uint32_t dw_cur_ticks;
2011-09-06 21:05:41 +02:00
dw_cur_ticks = dw_ms_ticks;
while ((dw_ms_ticks - dw_cur_ticks) < dw_dly_ticks);
}
2011-09-06 21:05:41 +02:00
/**
* \brief configer LED pins
*/
__INLINE static void led_config(void)
{
2011-09-06 21:05:41 +02:00
// Setup LED Pin
LED0_PIO->PIO_PER = LED0_MASK;
LED0_PIO->PIO_OER = LED0_MASK;
LED0_PIO->PIO_PUDR = LED0_MASK;
}
2011-09-06 21:05:41 +02:00
/**
* \brief Switch on LED
*/
__INLINE static void led_on(uint32_t dw_led)
{
2011-09-06 21:05:41 +02:00
// Turn On LED
LED0_PIO->PIO_CODR = dw_led;
}
2011-09-06 21:05:41 +02:00
/**
* \brief Switch off LED
*/
__INLINE static void led_off(uint32_t dw_led)
{
2011-09-06 21:05:41 +02:00
// Turn Off LED
LED0_PIO->PIO_SODR = dw_led;
}
2011-09-06 21:05:41 +02:00
/**
* \brief Application entry point.
*
* \return Unused (ANSI-C compatibility).
*/
int main(void)
{
2011-09-06 21:05:41 +02:00
SystemInit();
WDT->WDT_MR = WDT_MR_WDDIS;
// Setup SysTick Timer for 1 msec interrupts
if (SysTick_Config(SystemCoreClock / 1000)) {
// Capture error
while (1);
}
led_config();
// Flash the LED
while(1) {
2011-09-06 21:05:41 +02:00
// Turn on the LED.
led_on (LED0_MASK);
// delay 1000 Msec.
delay_ms (1000);
// Turn off the LED.
led_off(LED0_MASK);
// delay 1000 Msec.
delay_ms (1000);
}
}