Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/rtos_none/SysTick_Handler.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file SysTick_Handler.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief No RTOS port only needs a systick handler |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2019, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "SysTick_Handler.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "device.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | //SysTick Timer Configuration |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #ifndef OS_CLOCK |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #error "OS_CLOCK should be defined by HIC configuration" |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 29 | |
Pawel Zarembski |
0:01f31e923fe2 | 30 | //Set the timer tick value for selected timer. |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #ifndef OS_TICK |
Pawel Zarembski |
0:01f31e923fe2 | 32 | #error "OS_TICK should be defined by RTOS configuration" |
Pawel Zarembski |
0:01f31e923fe2 | 33 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | |
Pawel Zarembski |
0:01f31e923fe2 | 38 | static volatile uint32_t tick_counter = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 39 | static volatile uint32_t event_flags =0; |
Pawel Zarembski |
0:01f31e923fe2 | 40 | static volatile uint32_t wait_counter = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 41 | |
Pawel Zarembski |
0:01f31e923fe2 | 42 | static osTimerFunc_t sysTickCb = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 43 | static uint32_t tickFreq = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 44 | static osThreadFunc_t mainFuncCb = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 45 | |
Pawel Zarembski |
0:01f31e923fe2 | 46 | void sysTickInit(void) |
Pawel Zarembski |
0:01f31e923fe2 | 47 | { |
Pawel Zarembski |
0:01f31e923fe2 | 48 | tick_counter = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 49 | event_flags=0; |
Pawel Zarembski |
0:01f31e923fe2 | 50 | wait_counter = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 51 | sysTickCb = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 52 | tickFreq = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 53 | mainFuncCb = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 54 | SysTick_Config(OS_TRV); |
Pawel Zarembski |
0:01f31e923fe2 | 55 | } |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | |
Pawel Zarembski |
0:01f31e923fe2 | 58 | void SysTick_Handler(void) |
Pawel Zarembski |
0:01f31e923fe2 | 59 | { |
Pawel Zarembski |
0:01f31e923fe2 | 60 | if (sysTickCb && tickFreq && (tick_counter % tickFreq)==0) { |
Pawel Zarembski |
0:01f31e923fe2 | 61 | sysTickCb(NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 62 | } |
Pawel Zarembski |
0:01f31e923fe2 | 63 | tick_counter++; |
Pawel Zarembski |
0:01f31e923fe2 | 64 | if(wait_counter){ |
Pawel Zarembski |
0:01f31e923fe2 | 65 | --wait_counter; |
Pawel Zarembski |
0:01f31e923fe2 | 66 | } |
Pawel Zarembski |
0:01f31e923fe2 | 67 | } |
Pawel Zarembski |
0:01f31e923fe2 | 68 | |
Pawel Zarembski |
0:01f31e923fe2 | 69 | void sysTickRegCallback(osTimerFunc_t callback) |
Pawel Zarembski |
0:01f31e923fe2 | 70 | { |
Pawel Zarembski |
0:01f31e923fe2 | 71 | sysTickCb = callback; |
Pawel Zarembski |
0:01f31e923fe2 | 72 | } |
Pawel Zarembski |
0:01f31e923fe2 | 73 | |
Pawel Zarembski |
0:01f31e923fe2 | 74 | void sysTickFreqSet(uint32_t ticks) |
Pawel Zarembski |
0:01f31e923fe2 | 75 | { |
Pawel Zarembski |
0:01f31e923fe2 | 76 | tickFreq = ticks; |
Pawel Zarembski |
0:01f31e923fe2 | 77 | } |
Pawel Zarembski |
0:01f31e923fe2 | 78 | |
Pawel Zarembski |
0:01f31e923fe2 | 79 | void sysTickWait(uint32_t wait) |
Pawel Zarembski |
0:01f31e923fe2 | 80 | { |
Pawel Zarembski |
0:01f31e923fe2 | 81 | wait_counter = wait; |
Pawel Zarembski |
0:01f31e923fe2 | 82 | while(wait_counter); |
Pawel Zarembski |
0:01f31e923fe2 | 83 | } |
Pawel Zarembski |
0:01f31e923fe2 | 84 | |
Pawel Zarembski |
0:01f31e923fe2 | 85 | void sysTickEvtSet(uint32_t flag) |
Pawel Zarembski |
0:01f31e923fe2 | 86 | { |
Pawel Zarembski |
0:01f31e923fe2 | 87 | __disable_irq(); |
Pawel Zarembski |
0:01f31e923fe2 | 88 | event_flags |= flag; |
Pawel Zarembski |
0:01f31e923fe2 | 89 | __enable_irq(); |
Pawel Zarembski |
0:01f31e923fe2 | 90 | } |
Pawel Zarembski |
0:01f31e923fe2 | 91 | |
Pawel Zarembski |
0:01f31e923fe2 | 92 | uint32_t sysTickEvtWaitOr(uint32_t flag) |
Pawel Zarembski |
0:01f31e923fe2 | 93 | { |
Pawel Zarembski |
0:01f31e923fe2 | 94 | uint32_t return_flags=0; |
Pawel Zarembski |
0:01f31e923fe2 | 95 | while ((flag&event_flags)==0); |
Pawel Zarembski |
0:01f31e923fe2 | 96 | return_flags = event_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 97 | __disable_irq(); |
Pawel Zarembski |
0:01f31e923fe2 | 98 | event_flags &= ~return_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 99 | __enable_irq(); |
Pawel Zarembski |
0:01f31e923fe2 | 100 | return return_flags; |
Pawel Zarembski |
0:01f31e923fe2 | 101 | } |
Pawel Zarembski |
0:01f31e923fe2 | 102 | |
Pawel Zarembski |
0:01f31e923fe2 | 103 | uint32_t sysTickTime(void) |
Pawel Zarembski |
0:01f31e923fe2 | 104 | { |
Pawel Zarembski |
0:01f31e923fe2 | 105 | return tick_counter; |
Pawel Zarembski |
0:01f31e923fe2 | 106 | } |
Pawel Zarembski |
0:01f31e923fe2 | 107 | |
Pawel Zarembski |
0:01f31e923fe2 | 108 | void sysTickRegMainFunc(osThreadFunc_t func) |
Pawel Zarembski |
0:01f31e923fe2 | 109 | { |
Pawel Zarembski |
0:01f31e923fe2 | 110 | mainFuncCb = func; |
Pawel Zarembski |
0:01f31e923fe2 | 111 | } |
Pawel Zarembski |
0:01f31e923fe2 | 112 | |
Pawel Zarembski |
0:01f31e923fe2 | 113 | void sysTickStartMain(void) |
Pawel Zarembski |
0:01f31e923fe2 | 114 | { |
Pawel Zarembski |
0:01f31e923fe2 | 115 | if(mainFuncCb){ |
Pawel Zarembski |
0:01f31e923fe2 | 116 | mainFuncCb(NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 117 | } |
Pawel Zarembski |
0:01f31e923fe2 | 118 | } |
Pawel Zarembski |
0:01f31e923fe2 | 119 |