Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Committer:
mbed_official
Date:
Thu May 05 20:45:13 2016 +0100
Revision:
112:53ace74b190c
Child:
114:031a41d65add
Synchronized with git revision 860fdd282b0dc3631a6c46b39442d4ab5343e534

Full URL: https://github.com/mbedmicro/mbed/commit/860fdd282b0dc3631a6c46b39442d4ab5343e534/

rtx update to v4.79

Who changed what in which revision?

UserRevisionLine numberNew 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 112:53ace74b190c 39
mbed_official 112:53ace74b190c 40 #ifndef __CMSIS_RTOS
mbed_official 112:53ace74b190c 41
mbed_official 112:53ace74b190c 42
mbed_official 112:53ace74b190c 43 /*----------------------------------------------------------------------------
mbed_official 112:53ace74b190c 44 * Global Variables
mbed_official 112:53ace74b190c 45 *---------------------------------------------------------------------------*/
mbed_official 112:53ace74b190c 46
mbed_official 112:53ace74b190c 47 /* User Timer list pointer */
mbed_official 112:53ace74b190c 48 struct OS_XTMR os_tmr;
mbed_official 112:53ace74b190c 49
mbed_official 112:53ace74b190c 50 /*----------------------------------------------------------------------------
mbed_official 112:53ace74b190c 51 * Functions
mbed_official 112:53ace74b190c 52 *---------------------------------------------------------------------------*/
mbed_official 112:53ace74b190c 53
mbed_official 112:53ace74b190c 54 /*--------------------------- rt_tmr_tick -----------------------------------*/
mbed_official 112:53ace74b190c 55
mbed_official 112:53ace74b190c 56 void rt_tmr_tick (void) {
mbed_official 112:53ace74b190c 57 /* Decrement delta count of timer list head. Timers having the value of */
mbed_official 112:53ace74b190c 58 /* zero are removed from the list and the callback function is called. */
mbed_official 112:53ace74b190c 59 P_TMR p;
mbed_official 112:53ace74b190c 60
mbed_official 112:53ace74b190c 61 if (os_tmr.next == NULL) {
mbed_official 112:53ace74b190c 62 return;
mbed_official 112:53ace74b190c 63 }
mbed_official 112:53ace74b190c 64 os_tmr.tcnt--;
mbed_official 112:53ace74b190c 65 while ((os_tmr.tcnt == 0U) && ((p = os_tmr.next) != NULL)) {
mbed_official 112:53ace74b190c 66 /* Call a user provided function to handle an elapsed timer */
mbed_official 112:53ace74b190c 67 os_tmr_call (p->info);
mbed_official 112:53ace74b190c 68 os_tmr.tcnt = p->tcnt;
mbed_official 112:53ace74b190c 69 os_tmr.next = p->next;
mbed_official 112:53ace74b190c 70 rt_free_box ((U32 *)m_tmr, p);
mbed_official 112:53ace74b190c 71 }
mbed_official 112:53ace74b190c 72 }
mbed_official 112:53ace74b190c 73
mbed_official 112:53ace74b190c 74 /*--------------------------- rt_tmr_create ---------------------------------*/
mbed_official 112:53ace74b190c 75
mbed_official 112:53ace74b190c 76 OS_ID rt_tmr_create (U16 tcnt, U16 info) {
mbed_official 112:53ace74b190c 77 /* Create an user timer and put it into the chained timer list using */
mbed_official 112:53ace74b190c 78 /* a timeout count value of "tcnt". User parameter "info" is used as a */
mbed_official 112:53ace74b190c 79 /* parameter for the user provided callback function "os_tmr_call ()". */
mbed_official 112:53ace74b190c 80 P_TMR p_tmr, p;
mbed_official 112:53ace74b190c 81 U32 delta,itcnt = tcnt;
mbed_official 112:53ace74b190c 82
mbed_official 112:53ace74b190c 83 if ((tcnt == 0U) || (m_tmr == NULL)) {
mbed_official 112:53ace74b190c 84 return (NULL);
mbed_official 112:53ace74b190c 85 }
mbed_official 112:53ace74b190c 86 p_tmr = rt_alloc_box ((U32 *)m_tmr);
mbed_official 112:53ace74b190c 87 if (!p_tmr) {
mbed_official 112:53ace74b190c 88 return (NULL);
mbed_official 112:53ace74b190c 89 }
mbed_official 112:53ace74b190c 90 p_tmr->info = info;
mbed_official 112:53ace74b190c 91 p = (P_TMR)&os_tmr;
mbed_official 112:53ace74b190c 92 delta = p->tcnt;
mbed_official 112:53ace74b190c 93 while ((delta < itcnt) && (p->next != NULL)) {
mbed_official 112:53ace74b190c 94 p = p->next;
mbed_official 112:53ace74b190c 95 delta += p->tcnt;
mbed_official 112:53ace74b190c 96 }
mbed_official 112:53ace74b190c 97 /* Right place found, insert timer into the list */
mbed_official 112:53ace74b190c 98 p_tmr->next = p->next;
mbed_official 112:53ace74b190c 99 p_tmr->tcnt = (U16)(delta - itcnt);
mbed_official 112:53ace74b190c 100 p->next = p_tmr;
mbed_official 112:53ace74b190c 101 p->tcnt -= p_tmr->tcnt;
mbed_official 112:53ace74b190c 102 return (p_tmr);
mbed_official 112:53ace74b190c 103 }
mbed_official 112:53ace74b190c 104
mbed_official 112:53ace74b190c 105 /*--------------------------- rt_tmr_kill -----------------------------------*/
mbed_official 112:53ace74b190c 106
mbed_official 112:53ace74b190c 107 OS_ID rt_tmr_kill (OS_ID timer) {
mbed_official 112:53ace74b190c 108 /* Remove user timer from the chained timer list. */
mbed_official 112:53ace74b190c 109 P_TMR p, p_tmr;
mbed_official 112:53ace74b190c 110
mbed_official 112:53ace74b190c 111 p_tmr = (P_TMR)timer;
mbed_official 112:53ace74b190c 112 p = (P_TMR)&os_tmr;
mbed_official 112:53ace74b190c 113 /* Search timer list for requested timer */
mbed_official 112:53ace74b190c 114 while (p->next != p_tmr) {
mbed_official 112:53ace74b190c 115 if (p->next == NULL) {
mbed_official 112:53ace74b190c 116 /* Failed, "timer" is not in the timer list */
mbed_official 112:53ace74b190c 117 return (p_tmr);
mbed_official 112:53ace74b190c 118 }
mbed_official 112:53ace74b190c 119 p = p->next;
mbed_official 112:53ace74b190c 120 }
mbed_official 112:53ace74b190c 121 /* Timer was found, remove it from the list */
mbed_official 112:53ace74b190c 122 p->next = p_tmr->next;
mbed_official 112:53ace74b190c 123 p->tcnt += p_tmr->tcnt;
mbed_official 112:53ace74b190c 124 rt_free_box ((U32 *)m_tmr, p_tmr);
mbed_official 112:53ace74b190c 125 /* Timer killed */
mbed_official 112:53ace74b190c 126 return (NULL);
mbed_official 112:53ace74b190c 127 }
mbed_official 112:53ace74b190c 128
mbed_official 112:53ace74b190c 129
mbed_official 112:53ace74b190c 130 #endif
mbed_official 112:53ace74b190c 131
mbed_official 112:53ace74b190c 132 /*----------------------------------------------------------------------------
mbed_official 112:53ace74b190c 133 * end of file
mbed_official 112:53ace74b190c 134 *---------------------------------------------------------------------------*/