aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c')
-rw-r--r--os/hal/ports/SAMA/SAMA5D2x/hal_st_lld.c38
1 files changed, 38 insertions, 0 deletions
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 */
}
/** @} */