mbed-rtos

Dependents:   YOZAKURA_ARM

Fork of mbed-rtos by mbed official

Committer:
mbed_official
Date:
Thu Nov 06 11:00:33 2014 +0000
Revision:
48:e9a2c7cb57a4
Synchronized with git revision 8724eb616b6e07a3bd111d3022652eb5bbefe9b7

Full URL: https://github.com/mbedmicro/mbed/commit/8724eb616b6e07a3bd111d3022652eb5bbefe9b7/

[RZ/A1H] mbed-RZ first release

Who changed what in which revision?

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