Clone of mbed rtos 2 for easy accessibility.
Fork of mbed-rtos by
rtx/TARGET_CORTEX_M/rt_Timer.c@125:5713cbbdb706, 2017-07-04 (annotated)
- Committer:
- Kojto
- Date:
- Tue Jul 04 13:32:20 2017 +0100
- Revision:
- 125:5713cbbdb706
- Parent:
- 114:031a41d65add
replace mbed_rtx by mbed_rtx4
Not causing a conflict with mbed_rtx that is for newer rtos
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 112:53ace74b190c | 1 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 2 | * CMSIS-RTOS - RTX |
mbed_official | 112:53ace74b190c | 3 | *---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 4 | * Name: RT_TIMER.C |
mbed_official | 112:53ace74b190c | 5 | * Purpose: User timer functions |
mbed_official | 112:53ace74b190c | 6 | * Rev.: V4.70 |
mbed_official | 112:53ace74b190c | 7 | *---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 8 | * |
mbed_official | 112:53ace74b190c | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH |
mbed_official | 112:53ace74b190c | 10 | * All rights reserved. |
mbed_official | 112:53ace74b190c | 11 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 112:53ace74b190c | 12 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 112:53ace74b190c | 13 | * - Redistributions of source code must retain the above copyright |
mbed_official | 112:53ace74b190c | 14 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 112:53ace74b190c | 15 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 112:53ace74b190c | 16 | * notice, this list of conditions and the following disclaimer in the |
mbed_official | 112:53ace74b190c | 17 | * documentation and/or other materials provided with the distribution. |
mbed_official | 112:53ace74b190c | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 112:53ace74b190c | 19 | * to endorse or promote products derived from this software without |
mbed_official | 112:53ace74b190c | 20 | * specific prior written permission. |
mbed_official | 112:53ace74b190c | 21 | * |
mbed_official | 112:53ace74b190c | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 112:53ace74b190c | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 112:53ace74b190c | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
mbed_official | 112:53ace74b190c | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
mbed_official | 112:53ace74b190c | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
mbed_official | 112:53ace74b190c | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 112:53ace74b190c | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 112:53ace74b190c | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 112:53ace74b190c | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
mbed_official | 112:53ace74b190c | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 112:53ace74b190c | 32 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 112:53ace74b190c | 33 | *---------------------------------------------------------------------------*/ |
mbed_official | 112:53ace74b190c | 34 | |
mbed_official | 112:53ace74b190c | 35 | #include "rt_TypeDef.h" |
mbed_official | 112:53ace74b190c | 36 | #include "RTX_Config.h" |
mbed_official | 112:53ace74b190c | 37 | #include "rt_Timer.h" |
mbed_official | 112:53ace74b190c | 38 | #include "rt_MemBox.h" |
mbed_official | 114:031a41d65add | 39 | #include "cmsis_os.h" |
mbed_official | 112:53ace74b190c | 40 | |
mbed_official | 112:53ace74b190c | 41 | #ifndef __CMSIS_RTOS |
mbed_official | 112:53ace74b190c | 42 | |
mbed_official | 112:53ace74b190c | 43 | |
mbed_official | 112:53ace74b190c | 44 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 45 | * Global Variables |
mbed_official | 112:53ace74b190c | 46 | *---------------------------------------------------------------------------*/ |
mbed_official | 112:53ace74b190c | 47 | |
mbed_official | 112:53ace74b190c | 48 | /* User Timer list pointer */ |
mbed_official | 112:53ace74b190c | 49 | struct OS_XTMR os_tmr; |
mbed_official | 112:53ace74b190c | 50 | |
mbed_official | 112:53ace74b190c | 51 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 52 | * Functions |
mbed_official | 112:53ace74b190c | 53 | *---------------------------------------------------------------------------*/ |
mbed_official | 112:53ace74b190c | 54 | |
mbed_official | 112:53ace74b190c | 55 | /*--------------------------- rt_tmr_tick -----------------------------------*/ |
mbed_official | 112:53ace74b190c | 56 | |
mbed_official | 112:53ace74b190c | 57 | void rt_tmr_tick (void) { |
mbed_official | 112:53ace74b190c | 58 | /* Decrement delta count of timer list head. Timers having the value of */ |
mbed_official | 112:53ace74b190c | 59 | /* zero are removed from the list and the callback function is called. */ |
mbed_official | 112:53ace74b190c | 60 | P_TMR p; |
mbed_official | 112:53ace74b190c | 61 | |
mbed_official | 112:53ace74b190c | 62 | if (os_tmr.next == NULL) { |
mbed_official | 112:53ace74b190c | 63 | return; |
mbed_official | 112:53ace74b190c | 64 | } |
mbed_official | 112:53ace74b190c | 65 | os_tmr.tcnt--; |
mbed_official | 112:53ace74b190c | 66 | while ((os_tmr.tcnt == 0U) && ((p = os_tmr.next) != NULL)) { |
mbed_official | 112:53ace74b190c | 67 | /* Call a user provided function to handle an elapsed timer */ |
mbed_official | 112:53ace74b190c | 68 | os_tmr_call (p->info); |
mbed_official | 112:53ace74b190c | 69 | os_tmr.tcnt = p->tcnt; |
mbed_official | 112:53ace74b190c | 70 | os_tmr.next = p->next; |
mbed_official | 112:53ace74b190c | 71 | rt_free_box ((U32 *)m_tmr, p); |
mbed_official | 112:53ace74b190c | 72 | } |
mbed_official | 112:53ace74b190c | 73 | } |
mbed_official | 112:53ace74b190c | 74 | |
mbed_official | 112:53ace74b190c | 75 | /*--------------------------- rt_tmr_create ---------------------------------*/ |
mbed_official | 112:53ace74b190c | 76 | |
mbed_official | 112:53ace74b190c | 77 | OS_ID rt_tmr_create (U16 tcnt, U16 info) { |
mbed_official | 112:53ace74b190c | 78 | /* Create an user timer and put it into the chained timer list using */ |
mbed_official | 112:53ace74b190c | 79 | /* a timeout count value of "tcnt". User parameter "info" is used as a */ |
mbed_official | 112:53ace74b190c | 80 | /* parameter for the user provided callback function "os_tmr_call ()". */ |
mbed_official | 112:53ace74b190c | 81 | P_TMR p_tmr, p; |
mbed_official | 112:53ace74b190c | 82 | U32 delta,itcnt = tcnt; |
mbed_official | 112:53ace74b190c | 83 | |
mbed_official | 112:53ace74b190c | 84 | if ((tcnt == 0U) || (m_tmr == NULL)) { |
mbed_official | 112:53ace74b190c | 85 | return (NULL); |
mbed_official | 112:53ace74b190c | 86 | } |
mbed_official | 112:53ace74b190c | 87 | p_tmr = rt_alloc_box ((U32 *)m_tmr); |
mbed_official | 112:53ace74b190c | 88 | if (!p_tmr) { |
mbed_official | 112:53ace74b190c | 89 | return (NULL); |
mbed_official | 112:53ace74b190c | 90 | } |
mbed_official | 112:53ace74b190c | 91 | p_tmr->info = info; |
mbed_official | 112:53ace74b190c | 92 | p = (P_TMR)&os_tmr; |
mbed_official | 112:53ace74b190c | 93 | delta = p->tcnt; |
mbed_official | 112:53ace74b190c | 94 | while ((delta < itcnt) && (p->next != NULL)) { |
mbed_official | 112:53ace74b190c | 95 | p = p->next; |
mbed_official | 112:53ace74b190c | 96 | delta += p->tcnt; |
mbed_official | 112:53ace74b190c | 97 | } |
mbed_official | 112:53ace74b190c | 98 | /* Right place found, insert timer into the list */ |
mbed_official | 112:53ace74b190c | 99 | p_tmr->next = p->next; |
mbed_official | 112:53ace74b190c | 100 | p_tmr->tcnt = (U16)(delta - itcnt); |
mbed_official | 112:53ace74b190c | 101 | p->next = p_tmr; |
mbed_official | 112:53ace74b190c | 102 | p->tcnt -= p_tmr->tcnt; |
mbed_official | 112:53ace74b190c | 103 | return (p_tmr); |
mbed_official | 112:53ace74b190c | 104 | } |
mbed_official | 112:53ace74b190c | 105 | |
mbed_official | 112:53ace74b190c | 106 | /*--------------------------- rt_tmr_kill -----------------------------------*/ |
mbed_official | 112:53ace74b190c | 107 | |
mbed_official | 112:53ace74b190c | 108 | OS_ID rt_tmr_kill (OS_ID timer) { |
mbed_official | 112:53ace74b190c | 109 | /* Remove user timer from the chained timer list. */ |
mbed_official | 112:53ace74b190c | 110 | P_TMR p, p_tmr; |
mbed_official | 112:53ace74b190c | 111 | |
mbed_official | 112:53ace74b190c | 112 | p_tmr = (P_TMR)timer; |
mbed_official | 112:53ace74b190c | 113 | p = (P_TMR)&os_tmr; |
mbed_official | 112:53ace74b190c | 114 | /* Search timer list for requested timer */ |
mbed_official | 112:53ace74b190c | 115 | while (p->next != p_tmr) { |
mbed_official | 112:53ace74b190c | 116 | if (p->next == NULL) { |
mbed_official | 112:53ace74b190c | 117 | /* Failed, "timer" is not in the timer list */ |
mbed_official | 112:53ace74b190c | 118 | return (p_tmr); |
mbed_official | 112:53ace74b190c | 119 | } |
mbed_official | 112:53ace74b190c | 120 | p = p->next; |
mbed_official | 112:53ace74b190c | 121 | } |
mbed_official | 112:53ace74b190c | 122 | /* Timer was found, remove it from the list */ |
mbed_official | 112:53ace74b190c | 123 | p->next = p_tmr->next; |
mbed_official | 112:53ace74b190c | 124 | p->tcnt += p_tmr->tcnt; |
mbed_official | 112:53ace74b190c | 125 | rt_free_box ((U32 *)m_tmr, p_tmr); |
mbed_official | 112:53ace74b190c | 126 | /* Timer killed */ |
mbed_official | 112:53ace74b190c | 127 | return (NULL); |
mbed_official | 112:53ace74b190c | 128 | } |
mbed_official | 112:53ace74b190c | 129 | |
mbed_official | 112:53ace74b190c | 130 | |
mbed_official | 112:53ace74b190c | 131 | #endif |
mbed_official | 112:53ace74b190c | 132 | |
mbed_official | 112:53ace74b190c | 133 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 134 | * end of file |
mbed_official | 112:53ace74b190c | 135 | *---------------------------------------------------------------------------*/ |