From 0f1b36f0aefbf40521e697bb0a63cc3a17ec6cc4 Mon Sep 17 00:00:00 2001 From: Christina Quast Date: Tue, 16 Dec 2014 10:54:59 +0100 Subject: [PATCH] Using existing atmel led routines There is a config file called led.c in the atmel softpack source code which provides routines for configuring, setting and clearing the LEDs. --- sam3s_example/Makefile | 4 ++-- sam3s_example/include/board.h | 8 +++++++ sam3s_example/mains/debug_uart_stdlib.c | 28 +++++++++---------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sam3s_example/Makefile b/sam3s_example/Makefile index b5097bc3..c96f6d12 100644 --- a/sam3s_example/Makefile +++ b/sam3s_example/Makefile @@ -48,7 +48,7 @@ MEMORIES = flash # TRACE_LEVEL_ERROR 2 # TRACE_LEVEL_FATAL 1 # TRACE_LEVEL_NO_TRACE 0 -TRACE_LEVEL = 4 +TRACE_LEVEL = 5 # Optimization level, put in comment for debugging OPTIMIZATION = -O0 @@ -126,7 +126,7 @@ VPATH += src_board src_sam3s cmsis # Objects built from C source files C_CMSIS = core_cm3.o C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o -C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o +C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o led.o C_APPLEVEL = main.o C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) diff --git a/sam3s_example/include/board.h b/sam3s_example/include/board.h index 2ddd2ff8..5554d6ed 100644 --- a/sam3s_example/include/board.h +++ b/sam3s_example/include/board.h @@ -8,6 +8,7 @@ #include "board_lowlevel.h" #include "uart_console.h" #include "iso7816_4.h" +#include "led.h" /** Highlevel */ #include "trace.h" @@ -34,6 +35,13 @@ #define LED_RED PIO_PA17 #define LED_GREEN PIO_PA18 +#define PIN_LED_RED {LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +#define PIN_LED_GREEN {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT} +#define PINS_LEDS PIN_LED_RED, PIN_LED_GREEN + +#define LED_NUM_RED 0 +#define LED_NUM_GREEN 1 + /** USART0 pin RX */ #define PIN_USART0_RXD {PIO_PA9A_URXD0, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT} /** USART0 pin TX */ diff --git a/sam3s_example/mains/debug_uart_stdlib.c b/sam3s_example/mains/debug_uart_stdlib.c index bcc9f86a..1eb20149 100644 --- a/sam3s_example/mains/debug_uart_stdlib.c +++ b/sam3s_example/mains/debug_uart_stdlib.c @@ -5,33 +5,25 @@ extern void UART_PutString(const char *str, int len); -/*---------------------------------------------------------------------------- - * * Variables - * *----------------------------------------------------------------------------*/ - -const Pin redled = {LED_RED, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; -const Pin greenled = {LED_GREEN, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}; - -static const Pin *led; - -void Configure_LED() { - PIO_Configure(&greenled, PIO_LISTSIZE(greenled)); - PIO_Configure(&redled, PIO_LISTSIZE(redled)); - PIO_Set(&redled); - PIO_Set(&greenled); - led = &redled; +void Configure_LEDs() { + LED_Configure(LED_NUM_RED); + LED_Configure(LED_NUM_GREEN); } int main() { size_t ret = 0; - Configure_LED(); + + Configure_LEDs(); ret = printf("Clockval: %d\r\n", BOARD_MCK); if (ret < 0){ - PIO_Clear(&redled); + LED_Clear(LED_NUM_GREEN); + LED_Set(LED_NUM_RED); } else { - PIO_Clear(&greenled); + LED_Clear(LED_NUM_RED); + LED_Set(LED_NUM_GREEN); + while (1) { printf("Clockval**++????: %d\r\n", BOARD_MCK); }