Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SysTick_Handler.c
00001 /** 00002 * @file SysTick_Handler.c 00003 * @brief No RTOS port only needs a systick handler 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2019, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include "SysTick_Handler.h" 00023 #include "device.h" 00024 00025 //SysTick Timer Configuration 00026 #ifndef OS_CLOCK 00027 #error "OS_CLOCK should be defined by HIC configuration" 00028 #endif 00029 00030 //Set the timer tick value for selected timer. 00031 #ifndef OS_TICK 00032 #error "OS_TICK should be defined by RTOS configuration" 00033 #endif 00034 00035 #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1) 00036 00037 00038 static volatile uint32_t tick_counter = 0; 00039 static volatile uint32_t event_flags =0; 00040 static volatile uint32_t wait_counter = 0; 00041 00042 static osTimerFunc_t sysTickCb = NULL; 00043 static uint32_t tickFreq = 0; 00044 static osThreadFunc_t mainFuncCb = NULL; 00045 00046 void sysTickInit(void) 00047 { 00048 tick_counter = 0; 00049 event_flags=0; 00050 wait_counter = 0; 00051 sysTickCb = NULL; 00052 tickFreq = 0; 00053 mainFuncCb = NULL; 00054 SysTick_Config(OS_TRV); 00055 } 00056 00057 00058 void SysTick_Handler(void) 00059 { 00060 if (sysTickCb && tickFreq && (tick_counter % tickFreq)==0) { 00061 sysTickCb(NULL); 00062 } 00063 tick_counter++; 00064 if(wait_counter){ 00065 --wait_counter; 00066 } 00067 } 00068 00069 void sysTickRegCallback(osTimerFunc_t callback) 00070 { 00071 sysTickCb = callback; 00072 } 00073 00074 void sysTickFreqSet(uint32_t ticks) 00075 { 00076 tickFreq = ticks; 00077 } 00078 00079 void sysTickWait(uint32_t wait) 00080 { 00081 wait_counter = wait; 00082 while(wait_counter); 00083 } 00084 00085 void sysTickEvtSet(uint32_t flag) 00086 { 00087 __disable_irq(); 00088 event_flags |= flag; 00089 __enable_irq(); 00090 } 00091 00092 uint32_t sysTickEvtWaitOr(uint32_t flag) 00093 { 00094 uint32_t return_flags=0; 00095 while ((flag&event_flags)==0); 00096 return_flags = event_flags; 00097 __disable_irq(); 00098 event_flags &= ~return_flags; 00099 __enable_irq(); 00100 return return_flags; 00101 } 00102 00103 uint32_t sysTickTime(void) 00104 { 00105 return tick_counter; 00106 } 00107 00108 void sysTickRegMainFunc(osThreadFunc_t func) 00109 { 00110 mainFuncCb = func; 00111 } 00112 00113 void sysTickStartMain(void) 00114 { 00115 if(mainFuncCb){ 00116 mainFuncCb(NULL); 00117 } 00118 } 00119
Generated on Tue Jul 12 2022 15:37:24 by
1.7.2