skeleton for lab1
Dependencies: AvailableMemory mbed-rtos mbed
Fork of helloaabbc by
mbed-rtos/rtx/rt_Time.c@0:1c8f2727e9f5, 2014-04-03 (annotated)
- Committer:
- y7jin
- Date:
- Thu Apr 03 22:56:32 2014 +0000
- Revision:
- 0:1c8f2727e9f5
hello
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y7jin | 0:1c8f2727e9f5 | 1 | /*---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 2 | * RL-ARM - RTX |
y7jin | 0:1c8f2727e9f5 | 3 | *---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 4 | * Name: RT_TIME.C |
y7jin | 0:1c8f2727e9f5 | 5 | * Purpose: Delay and interval wait functions |
y7jin | 0:1c8f2727e9f5 | 6 | * Rev.: V4.60 |
y7jin | 0:1c8f2727e9f5 | 7 | *---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 8 | * |
y7jin | 0:1c8f2727e9f5 | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH |
y7jin | 0:1c8f2727e9f5 | 10 | * All rights reserved. |
y7jin | 0:1c8f2727e9f5 | 11 | * Redistribution and use in source and binary forms, with or without |
y7jin | 0:1c8f2727e9f5 | 12 | * modification, are permitted provided that the following conditions are met: |
y7jin | 0:1c8f2727e9f5 | 13 | * - Redistributions of source code must retain the above copyright |
y7jin | 0:1c8f2727e9f5 | 14 | * notice, this list of conditions and the following disclaimer. |
y7jin | 0:1c8f2727e9f5 | 15 | * - Redistributions in binary form must reproduce the above copyright |
y7jin | 0:1c8f2727e9f5 | 16 | * notice, this list of conditions and the following disclaimer in the |
y7jin | 0:1c8f2727e9f5 | 17 | * documentation and/or other materials provided with the distribution. |
y7jin | 0:1c8f2727e9f5 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
y7jin | 0:1c8f2727e9f5 | 19 | * to endorse or promote products derived from this software without |
y7jin | 0:1c8f2727e9f5 | 20 | * specific prior written permission. |
y7jin | 0:1c8f2727e9f5 | 21 | * |
y7jin | 0:1c8f2727e9f5 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
y7jin | 0:1c8f2727e9f5 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
y7jin | 0:1c8f2727e9f5 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
y7jin | 0:1c8f2727e9f5 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
y7jin | 0:1c8f2727e9f5 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
y7jin | 0:1c8f2727e9f5 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
y7jin | 0:1c8f2727e9f5 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
y7jin | 0:1c8f2727e9f5 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
y7jin | 0:1c8f2727e9f5 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
y7jin | 0:1c8f2727e9f5 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
y7jin | 0:1c8f2727e9f5 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
y7jin | 0:1c8f2727e9f5 | 33 | *---------------------------------------------------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 34 | |
y7jin | 0:1c8f2727e9f5 | 35 | #include "rt_TypeDef.h" |
y7jin | 0:1c8f2727e9f5 | 36 | #include "RTX_Config.h" |
y7jin | 0:1c8f2727e9f5 | 37 | #include "rt_Task.h" |
y7jin | 0:1c8f2727e9f5 | 38 | #include "rt_Time.h" |
y7jin | 0:1c8f2727e9f5 | 39 | |
y7jin | 0:1c8f2727e9f5 | 40 | /*---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 41 | * Global Variables |
y7jin | 0:1c8f2727e9f5 | 42 | *---------------------------------------------------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 43 | |
y7jin | 0:1c8f2727e9f5 | 44 | /* Free running system tick counter */ |
y7jin | 0:1c8f2727e9f5 | 45 | U32 os_time; |
y7jin | 0:1c8f2727e9f5 | 46 | |
y7jin | 0:1c8f2727e9f5 | 47 | |
y7jin | 0:1c8f2727e9f5 | 48 | /*---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 49 | * Functions |
y7jin | 0:1c8f2727e9f5 | 50 | *---------------------------------------------------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 51 | |
y7jin | 0:1c8f2727e9f5 | 52 | |
y7jin | 0:1c8f2727e9f5 | 53 | /*--------------------------- rt_time_get -----------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 54 | |
y7jin | 0:1c8f2727e9f5 | 55 | U32 rt_time_get (void) { |
y7jin | 0:1c8f2727e9f5 | 56 | /* Get system time tick */ |
y7jin | 0:1c8f2727e9f5 | 57 | return (os_time); |
y7jin | 0:1c8f2727e9f5 | 58 | } |
y7jin | 0:1c8f2727e9f5 | 59 | |
y7jin | 0:1c8f2727e9f5 | 60 | |
y7jin | 0:1c8f2727e9f5 | 61 | /*--------------------------- rt_dly_wait -----------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 62 | |
y7jin | 0:1c8f2727e9f5 | 63 | void rt_dly_wait (U16 delay_time) { |
y7jin | 0:1c8f2727e9f5 | 64 | /* Delay task by "delay_time" */ |
y7jin | 0:1c8f2727e9f5 | 65 | rt_block (delay_time, WAIT_DLY); |
y7jin | 0:1c8f2727e9f5 | 66 | } |
y7jin | 0:1c8f2727e9f5 | 67 | |
y7jin | 0:1c8f2727e9f5 | 68 | |
y7jin | 0:1c8f2727e9f5 | 69 | /*--------------------------- rt_itv_set ------------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 70 | |
y7jin | 0:1c8f2727e9f5 | 71 | void rt_itv_set (U16 interval_time) { |
y7jin | 0:1c8f2727e9f5 | 72 | /* Set interval length and define start of first interval */ |
y7jin | 0:1c8f2727e9f5 | 73 | os_tsk.run->interval_time = interval_time; |
y7jin | 0:1c8f2727e9f5 | 74 | os_tsk.run->delta_time = interval_time + (U16)os_time; |
y7jin | 0:1c8f2727e9f5 | 75 | } |
y7jin | 0:1c8f2727e9f5 | 76 | |
y7jin | 0:1c8f2727e9f5 | 77 | |
y7jin | 0:1c8f2727e9f5 | 78 | /*--------------------------- rt_itv_wait -----------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 79 | |
y7jin | 0:1c8f2727e9f5 | 80 | void rt_itv_wait (void) { |
y7jin | 0:1c8f2727e9f5 | 81 | /* Wait for interval end and define start of next one */ |
y7jin | 0:1c8f2727e9f5 | 82 | U16 delta; |
y7jin | 0:1c8f2727e9f5 | 83 | |
y7jin | 0:1c8f2727e9f5 | 84 | delta = os_tsk.run->delta_time - (U16)os_time; |
y7jin | 0:1c8f2727e9f5 | 85 | os_tsk.run->delta_time += os_tsk.run->interval_time; |
y7jin | 0:1c8f2727e9f5 | 86 | if ((delta & 0x8000) == 0) { |
y7jin | 0:1c8f2727e9f5 | 87 | rt_block (delta, WAIT_ITV); |
y7jin | 0:1c8f2727e9f5 | 88 | } |
y7jin | 0:1c8f2727e9f5 | 89 | } |
y7jin | 0:1c8f2727e9f5 | 90 | |
y7jin | 0:1c8f2727e9f5 | 91 | /*---------------------------------------------------------------------------- |
y7jin | 0:1c8f2727e9f5 | 92 | * end of file |
y7jin | 0:1c8f2727e9f5 | 93 | *---------------------------------------------------------------------------*/ |
y7jin | 0:1c8f2727e9f5 | 94 |