Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/rtos/rt_Timer.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 rt_Timer.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, 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 "rt_TypeDef.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "RTX_Config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "rt_Timer.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "rt_MemBox.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | |
Pawel Zarembski |
0:01f31e923fe2 | 28 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 29 | * Global Variables |
Pawel Zarembski |
0:01f31e923fe2 | 30 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 31 | |
Pawel Zarembski |
0:01f31e923fe2 | 32 | /* User Timer list pointer */ |
Pawel Zarembski |
0:01f31e923fe2 | 33 | struct OS_XTMR os_tmr; |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 36 | * Functions |
Pawel Zarembski |
0:01f31e923fe2 | 37 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 38 | |
Pawel Zarembski |
0:01f31e923fe2 | 39 | /*--------------------------- rt_tmr_tick -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 40 | |
Pawel Zarembski |
0:01f31e923fe2 | 41 | void rt_tmr_tick (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 42 | /* Decrement delta count of timer list head. Timers having the value of */ |
Pawel Zarembski |
0:01f31e923fe2 | 43 | /* zero are removed from the list and the callback function is called. */ |
Pawel Zarembski |
0:01f31e923fe2 | 44 | P_TMR p; |
Pawel Zarembski |
0:01f31e923fe2 | 45 | |
Pawel Zarembski |
0:01f31e923fe2 | 46 | if (os_tmr.next == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 47 | return; |
Pawel Zarembski |
0:01f31e923fe2 | 48 | } |
Pawel Zarembski |
0:01f31e923fe2 | 49 | os_tmr.tcnt--; |
Pawel Zarembski |
0:01f31e923fe2 | 50 | while (os_tmr.tcnt == 0 && (p = os_tmr.next) != NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 51 | /* Call a user provided function to handle an elapsed timer */ |
Pawel Zarembski |
0:01f31e923fe2 | 52 | os_tmr_call (p->info); |
Pawel Zarembski |
0:01f31e923fe2 | 53 | os_tmr.tcnt = p->tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 54 | os_tmr.next = p->next; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | rt_free_box ((U32 *)m_tmr, p); |
Pawel Zarembski |
0:01f31e923fe2 | 56 | } |
Pawel Zarembski |
0:01f31e923fe2 | 57 | } |
Pawel Zarembski |
0:01f31e923fe2 | 58 | |
Pawel Zarembski |
0:01f31e923fe2 | 59 | /*--------------------------- rt_tmr_create ---------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 60 | |
Pawel Zarembski |
0:01f31e923fe2 | 61 | OS_ID rt_tmr_create (U16 tcnt, U16 info) { |
Pawel Zarembski |
0:01f31e923fe2 | 62 | /* Create an user timer and put it into the chained timer list using */ |
Pawel Zarembski |
0:01f31e923fe2 | 63 | /* a timeout count value of "tcnt". User parameter "info" is used as a */ |
Pawel Zarembski |
0:01f31e923fe2 | 64 | /* parameter for the user provided callback function "os_tmr_call ()". */ |
Pawel Zarembski |
0:01f31e923fe2 | 65 | P_TMR p_tmr, p; |
Pawel Zarembski |
0:01f31e923fe2 | 66 | U32 delta,itcnt = tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 67 | |
Pawel Zarembski |
0:01f31e923fe2 | 68 | if (tcnt == 0 || m_tmr == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 69 | return (NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 70 | } |
Pawel Zarembski |
0:01f31e923fe2 | 71 | p_tmr = rt_alloc_box ((U32 *)m_tmr); |
Pawel Zarembski |
0:01f31e923fe2 | 72 | if (!p_tmr) { |
Pawel Zarembski |
0:01f31e923fe2 | 73 | return (NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 74 | } |
Pawel Zarembski |
0:01f31e923fe2 | 75 | p_tmr->info = info; |
Pawel Zarembski |
0:01f31e923fe2 | 76 | p = (P_TMR)&os_tmr; |
Pawel Zarembski |
0:01f31e923fe2 | 77 | delta = p->tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 78 | while (delta < itcnt && p->next != NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 79 | p = p->next; |
Pawel Zarembski |
0:01f31e923fe2 | 80 | delta += p->tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 81 | } |
Pawel Zarembski |
0:01f31e923fe2 | 82 | /* Right place found, insert timer into the list */ |
Pawel Zarembski |
0:01f31e923fe2 | 83 | p_tmr->next = p->next; |
Pawel Zarembski |
0:01f31e923fe2 | 84 | p_tmr->tcnt = (U16)(delta - itcnt); |
Pawel Zarembski |
0:01f31e923fe2 | 85 | p->next = p_tmr; |
Pawel Zarembski |
0:01f31e923fe2 | 86 | p->tcnt -= p_tmr->tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | return (p_tmr); |
Pawel Zarembski |
0:01f31e923fe2 | 88 | } |
Pawel Zarembski |
0:01f31e923fe2 | 89 | |
Pawel Zarembski |
0:01f31e923fe2 | 90 | /*--------------------------- rt_tmr_kill -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 91 | |
Pawel Zarembski |
0:01f31e923fe2 | 92 | OS_ID rt_tmr_kill (OS_ID timer) { |
Pawel Zarembski |
0:01f31e923fe2 | 93 | /* Remove user timer from the chained timer list. */ |
Pawel Zarembski |
0:01f31e923fe2 | 94 | P_TMR p, p_tmr; |
Pawel Zarembski |
0:01f31e923fe2 | 95 | |
Pawel Zarembski |
0:01f31e923fe2 | 96 | p_tmr = (P_TMR)timer; |
Pawel Zarembski |
0:01f31e923fe2 | 97 | p = (P_TMR)&os_tmr; |
Pawel Zarembski |
0:01f31e923fe2 | 98 | /* Search timer list for requested timer */ |
Pawel Zarembski |
0:01f31e923fe2 | 99 | while (p->next != p_tmr) { |
Pawel Zarembski |
0:01f31e923fe2 | 100 | if (p->next == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 101 | /* Failed, "timer" is not in the timer list */ |
Pawel Zarembski |
0:01f31e923fe2 | 102 | return (p_tmr); |
Pawel Zarembski |
0:01f31e923fe2 | 103 | } |
Pawel Zarembski |
0:01f31e923fe2 | 104 | p = p->next; |
Pawel Zarembski |
0:01f31e923fe2 | 105 | } |
Pawel Zarembski |
0:01f31e923fe2 | 106 | /* Timer was found, remove it from the list */ |
Pawel Zarembski |
0:01f31e923fe2 | 107 | p->next = p_tmr->next; |
Pawel Zarembski |
0:01f31e923fe2 | 108 | p->tcnt += p_tmr->tcnt; |
Pawel Zarembski |
0:01f31e923fe2 | 109 | rt_free_box ((U32 *)m_tmr, p_tmr); |
Pawel Zarembski |
0:01f31e923fe2 | 110 | /* Timer killed */ |
Pawel Zarembski |
0:01f31e923fe2 | 111 | return (NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 112 | } |
Pawel Zarembski |
0:01f31e923fe2 | 113 | |
Pawel Zarembski |
0:01f31e923fe2 | 114 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 115 | * end of file |
Pawel Zarembski |
0:01f31e923fe2 | 116 | *---------------------------------------------------------------------------*/ |