From 58e167350f007cfdc33bbb67e8042ffd9dee4297 Mon Sep 17 00:00:00 2001 From: Rocco Marco Guglielmi Date: Fri, 11 Aug 2017 18:45:50 +0000 Subject: Added PIT implementation for ATSAMA5D2 (Still incomplete) git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10404 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c | 32 +++++++++++++++++++++++-- os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c | 38 ++++++++++++++++++++++++++++++ os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.h | 12 ++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c index 44b9c0f4b..4009917da 100755 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED/main.c @@ -17,7 +17,25 @@ #include "ch.h" #include "hal.h" -static uint32_t counter = 0; +static uint32_t seconds_counter; +static uint32_t minutes_counter; + +/* + * Seconds counter thread. + */ +static THD_WORKING_AREA(waThread1, 128); +static THD_FUNCTION(Thread1, arg) { + + (void)arg; + + chRegSetThreadName("counter"); + + while (true) { + chThdSleepMilliseconds(1000); + seconds_counter++; + } +} + /* * Application entry point. */ @@ -33,7 +51,17 @@ int main(void) { halInit(); chSysInit(); + /* + * Creates the example thread. + */ + chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); + + /* + * Normal main() thread activity, in this demo it does nothing except + * increasing the minutes counter. + */ while (true) { - counter++; + chThdSleepSeconds(60); + minutes_counter++; } } diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c b/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c index cc1b46250..14e82a31d 100644 --- a/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c +++ b/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c @@ -28,6 +28,11 @@ /* Driver local definitions. */ /*===========================================================================*/ +/** + * @brief Periodic Interrupt Timer frequency. + */ +#define SAMA_PIT (SAMA_MCK / 16) + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ @@ -48,6 +53,25 @@ /* Driver interrupt handlers. */ /*===========================================================================*/ +#if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__) +/** + * @brief System Timer vector. + * @details This interrupt is used for system tick in periodic mode. + * + * @isr + */ +OSAL_IRQ_HANDLER(PIT_Handler) { + + OSAL_IRQ_PROLOGUE(); + + osalSysLockFromISR(); + osalOsTimerHandlerI(); + osalSysUnlockFromISR(); + + OSAL_IRQ_EPILOGUE(); +} +#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -58,6 +82,20 @@ * @notapi */ void st_lld_init(void) { + +#if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) + /* Enabling PIT.*/ + pmcEnablePIT(); + + PIT->PIT_MR = PIT_MR_PIV((SAMA_PIT / OSAL_ST_FREQUENCY) - 1); + PIT->PIT_MR |= PIT_MR_PITEN | PIT_MR_PITIEN; + + + /* IRQ enabled.*/ + aicSetSourcePriority(ID_PIT, SAMA_ST_IRQ_PRIORITY); + aicSetSourceHandler(ID_PIT, PIT_Handler); + aicEnableInt(ID_PIT); +#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ } /** @} */ diff --git a/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.h b/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.h index 055433614..328d929ed 100644 --- a/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.h +++ b/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.h @@ -37,6 +37,18 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +/** + * @name Configuration options + * @{ + */ +/** + * @brief SysTick timer IRQ priority. + */ +#if !defined(SAMA_ST_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define SAMA_ST_IRQ_PRIORITY 7 +#endif +/** @} */ + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ -- cgit v1.2.3