From f8fe78d5ec576e2d3efc4333bacd9677c96ca6c8 Mon Sep 17 00:00:00 2001 From: edolomb Date: Thu, 14 Sep 2017 14:37:03 +0000 Subject: [PATCH] Added Blinking and Serial Thread git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10586 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/.project | 4 +- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/Makefile | 3 +- .../RT-SAMA5D2-XPLAINED (Load and Run).launch | 106 +++++++++--------- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/halconf.h | 2 +- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c | 45 +++++++- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/mcuconf.h | 2 +- 6 files changed, 99 insertions(+), 63 deletions(-) diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/.project b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/.project index b7c1d13b0..d11db2ca4 100644 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/.project +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/.project @@ -79,12 +79,12 @@ board 2 - CHIBIOS/os/hal/boards/ATSAMA5D2_XULT + /home/chibi/Chibilogic/ChibiOS_trunk/os/hal/boards/ATSAMA5D2_XULT os 2 - CHIBIOS/os + /home/chibi/Chibilogic/ChibiOS_trunk/os diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/Makefile b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/Makefile index 6a722d3c8..8d6601400 100755 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/Makefile +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/Makefile @@ -137,6 +137,7 @@ CSRC = $(STARTUPSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(TESTSRC) \ + $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -170,7 +171,7 @@ ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(CHIBIOS)/os/license \ $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(CHIBIOS)/os/various + $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various # # Project, sources and paths diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/debug/RT-SAMA5D2-XPLAINED (Load and Run).launch b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/debug/RT-SAMA5D2-XPLAINED (Load and Run).launch index b9d906be2..5fcdb7cf0 100644 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/debug/RT-SAMA5D2-XPLAINED (Load and Run).launch +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/debug/RT-SAMA5D2-XPLAINED (Load and Run).launch @@ -1,52 +1,54 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/halconf.h b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/halconf.h index d4775ae08..d1d69ab8f 100644 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/halconf.h +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/halconf.h @@ -139,7 +139,7 @@ * @brief Enables the SERIAL subsystem. */ #if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL FALSE +#define HAL_USE_SERIAL TRUE #endif /** diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c index 4009917da..aeeb6f006 100755 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c @@ -16,9 +16,9 @@ #include "ch.h" #include "hal.h" +#include "chprintf.h" -static uint32_t seconds_counter; -static uint32_t minutes_counter; +#define AICREDIR_KEY 0x5B6C0E26u /* * Seconds counter thread. @@ -27,12 +27,21 @@ static THD_WORKING_AREA(waThread1, 128); static THD_FUNCTION(Thread1, arg) { (void)arg; - + bool ld = true; chRegSetThreadName("counter"); while (true) { + /* TODO: Replace with toggle function of GPIO */ + if(ld){ + PIOA->PIO_PIO_[1].S_PIO_CODR = S_PIO_CODR_P5; + ld = false; + } + else{ + PIOA->PIO_PIO_[1].S_PIO_SODR = S_PIO_SODR_P5; + ld = true; + } + chprintf((BaseSequentialStream *)&SD0, "ChibiOS is running!\r\n\n"); chThdSleepMilliseconds(1000); - seconds_counter++; } } @@ -51,6 +60,31 @@ int main(void) { halInit(); chSysInit(); + /* Redirect interrupts */ + uint32_t aicredir = SFR_AICREDIR_AICREDIRKEY((uint32_t)(AICREDIR_KEY)); + SFR->SFR_AICREDIR = (aicredir ^ SFR->SFR_SN1); + + /* + * TODO: Replace with PAL functions + * Led green + */ + PIOA->PIO_PIO_[1].S_PIO_SIOSR |= S_PIO_SIOSR_P5; + PIOA->PIO_PIO_[1].S_PIO_MSKR = S_PIO_MSKR_MSK5_ENABLED; + PIOA->PIO_PIO_[1].S_PIO_CFGR = S_PIO_CFGR_DIR_OUTPUT; + PIOA->PIO_PIO_[1].S_PIO_SODR = S_PIO_SODR_P5 ; + + /* + * TODO: Replace with PAL functions + * Uart0 pins PB26 rx and PB27 tx (J18) + */ + PIOA->PIO_PIO_[1].S_PIO_SIOSR |= S_PIO_SIOSR_P26 | S_PIO_SIOSR_P27; + /* select pins */ + PIOA->PIO_PIO_[1].S_PIO_MSKR = S_PIO_MSKR_MSK26 | S_PIO_MSKR_MSK27; + /* pins are driven by func_periph_c (uart0 mode) */ + PIOA->PIO_PIO_[1].S_PIO_CFGR = S_PIO_CFGR_FUNC_PERIPH_C; + + sdStart(&SD0, NULL); + /* * Creates the example thread. */ @@ -61,7 +95,6 @@ int main(void) { * increasing the minutes counter. */ while (true) { - chThdSleepSeconds(60); - minutes_counter++; + chThdSleepMilliseconds(500); } } diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/mcuconf.h b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/mcuconf.h index d22565cb2..c633e5454 100644 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/mcuconf.h +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/mcuconf.h @@ -46,7 +46,7 @@ /* * SERIAL driver system settings. */ -#define SAMA_SERIAL_USE_UART0 FALSE +#define SAMA_SERIAL_USE_UART0 TRUE #define SAMA_SERIAL_USE_UART1 FALSE #define SAMA_SERIAL_USE_UART2 FALSE #define SAMA_SERIAL_USE_UART3 FALSE