1 /**************************************************************************//**
3 * @brief CMSIS OS Tick SysTick implementation
6 ******************************************************************************/
8 * Copyright (c) 2017-2017 ARM Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
27 #include "RTE_Components.h"
28 #include CMSIS_device_header
32 #ifndef SYSTICK_IRQ_PRIORITY
33 #define SYSTICK_IRQ_PRIORITY 0xFFU
36 static uint8_t PendST;
39 __WEAK int32_t OS_Tick_Setup (uint32_t freq, IRQHandler_t handler) {
47 load = (SystemCoreClock / freq) - 1U;
48 if (load > 0x00FFFFFFU) {
52 NVIC_SetPriority(SysTick_IRQn, SYSTICK_IRQ_PRIORITY);
54 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk;
64 __WEAK int32_t OS_Tick_Enable (void) {
68 SCB->ICSR = SCB_ICSR_PENDSTSET_Msk;
71 SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
77 __WEAK int32_t OS_Tick_Disable (void) {
79 SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
81 if ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) != 0U) {
82 SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
89 // Acknowledge OS Tick IRQ.
90 __WEAK int32_t OS_Tick_AcknowledgeIRQ (void) {
95 // Get OS Tick IRQ number.
96 __WEAK int32_t OS_Tick_GetIRQn (void) {
97 return (SysTick_IRQn);
100 // Get OS Tick clock.
101 __WEAK uint32_t OS_Tick_GetClock (void) {
102 return (SystemCoreClock);
105 // Get OS Tick interval.
106 __WEAK uint32_t OS_Tick_GetInterval (void) {
107 return (SysTick->LOAD + 1U);
110 // Get OS Tick count value.
111 __WEAK uint32_t OS_Tick_GetCount (void) {
112 uint32_t load = SysTick->LOAD;
113 return (load - SysTick->VAL);
116 // Get OS Tick overflow status.
117 __WEAK uint32_t OS_Tick_GetOverflow (void) {
118 return ((SysTick->CTRL >> 16) & 1U);