diff options
Diffstat (limited to 'lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_st_lld.c')
-rw-r--r-- | lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_st_lld.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_st_lld.c b/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_st_lld.c new file mode 100644 index 000000000..1989da0b1 --- /dev/null +++ b/lib/chibios/os/hal/ports/ADUCM/ADUCM36x/hal_st_lld.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2019 Rocco Marco Guglielmi | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file ADUCM36x/hal_st_lld.c | ||
19 | * @brief ST Driver subsystem low level driver code. | ||
20 | * | ||
21 | * @addtogroup ST | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | #if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__) | ||
28 | |||
29 | /*===========================================================================*/ | ||
30 | /* Driver local definitions. */ | ||
31 | /*===========================================================================*/ | ||
32 | |||
33 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC | ||
34 | |||
35 | #if defined(ADUCM_FCLK) | ||
36 | #define SYSTICK_CK ADUCM_FCLK | ||
37 | #else | ||
38 | #define SYSTICK_CK (ADUCM_HFOSC / 8) | ||
39 | #endif | ||
40 | |||
41 | #if SYSTICK_CK % OSAL_ST_FREQUENCY != 0 | ||
42 | #error "the selected ST frequency is not obtainable because integer rounding" | ||
43 | #endif | ||
44 | |||
45 | #if (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1 > 0xFFFFFF | ||
46 | #error "the selected ST frequency is not obtainable because SysTick timer counter limits" | ||
47 | #endif | ||
48 | |||
49 | #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ | ||
50 | |||
51 | /*===========================================================================*/ | ||
52 | /* Driver exported variables. */ | ||
53 | /*===========================================================================*/ | ||
54 | |||
55 | /*===========================================================================*/ | ||
56 | /* Driver local types. */ | ||
57 | /*===========================================================================*/ | ||
58 | |||
59 | /*===========================================================================*/ | ||
60 | /* Driver local variables and types. */ | ||
61 | /*===========================================================================*/ | ||
62 | |||
63 | /*===========================================================================*/ | ||
64 | /* Driver local functions. */ | ||
65 | /*===========================================================================*/ | ||
66 | |||
67 | /*===========================================================================*/ | ||
68 | /* Driver interrupt handlers. */ | ||
69 | /*===========================================================================*/ | ||
70 | |||
71 | #if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__) | ||
72 | /** | ||
73 | * @brief System Timer vector. | ||
74 | * @details This interrupt is used for system tick in periodic mode. | ||
75 | * | ||
76 | * @isr | ||
77 | */ | ||
78 | OSAL_IRQ_HANDLER(SysTick_Handler) { | ||
79 | |||
80 | OSAL_IRQ_PROLOGUE(); | ||
81 | |||
82 | osalSysLockFromISR(); | ||
83 | osalOsTimerHandlerI(); | ||
84 | osalSysUnlockFromISR(); | ||
85 | |||
86 | OSAL_IRQ_EPILOGUE(); | ||
87 | } | ||
88 | #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ | ||
89 | |||
90 | /*===========================================================================*/ | ||
91 | /* Driver exported functions. */ | ||
92 | /*===========================================================================*/ | ||
93 | |||
94 | /** | ||
95 | * @brief Low level ST driver initialization. | ||
96 | * | ||
97 | * @notapi | ||
98 | */ | ||
99 | void st_lld_init(void) { | ||
100 | |||
101 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC | ||
102 | /* Periodic systick mode, the Cortex-Mx internal systick timer is used | ||
103 | in this mode.*/ | ||
104 | SysTick->LOAD = (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1; | ||
105 | SysTick->VAL = 0; | ||
106 | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | | ||
107 | SysTick_CTRL_ENABLE_Msk | | ||
108 | SysTick_CTRL_TICKINT_Msk; | ||
109 | |||
110 | /* IRQ enabled.*/ | ||
111 | nvicSetSystemHandlerPriority(HANDLER_SYSTICK, ADUCM_ST_IRQ_PRIORITY); | ||
112 | #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ | ||
113 | } | ||
114 | |||
115 | #endif /* OSAL_ST_MODE != OSAL_ST_MODE_NONE */ | ||
116 | |||
117 | /** @} */ | ||