Dependencies:   mbed

Fork of FYDP_Final2 by Dave Lu

Committer:
tntmarket
Date:
Wed Mar 25 18:11:09 2015 +0000
Revision:
11:425dff6a4af9
Parent:
8:3d5a84b897be
Working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
majik 0:21019d94ad33 1 /*----------------------------------------------------------------------------
majik 0:21019d94ad33 2 * RL-ARM - RTX
majik 0:21019d94ad33 3 *----------------------------------------------------------------------------
majik 0:21019d94ad33 4 * Name: RT_ROBIN.C
majik 0:21019d94ad33 5 * Purpose: Round Robin Task switching
majik 0:21019d94ad33 6 * Rev.: V4.60
majik 0:21019d94ad33 7 *----------------------------------------------------------------------------
majik 0:21019d94ad33 8 *
majik 0:21019d94ad33 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
majik 0:21019d94ad33 10 * All rights reserved.
majik 0:21019d94ad33 11 * Redistribution and use in source and binary forms, with or without
majik 0:21019d94ad33 12 * modification, are permitted provided that the following conditions are met:
majik 0:21019d94ad33 13 * - Redistributions of source code must retain the above copyright
majik 0:21019d94ad33 14 * notice, this list of conditions and the following disclaimer.
majik 0:21019d94ad33 15 * - Redistributions in binary form must reproduce the above copyright
majik 0:21019d94ad33 16 * notice, this list of conditions and the following disclaimer in the
majik 0:21019d94ad33 17 * documentation and/or other materials provided with the distribution.
majik 0:21019d94ad33 18 * - Neither the name of ARM nor the names of its contributors may be used
majik 0:21019d94ad33 19 * to endorse or promote products derived from this software without
majik 0:21019d94ad33 20 * specific prior written permission.
majik 0:21019d94ad33 21 *
majik 0:21019d94ad33 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
majik 0:21019d94ad33 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
majik 0:21019d94ad33 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
majik 0:21019d94ad33 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
majik 0:21019d94ad33 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
majik 0:21019d94ad33 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
majik 0:21019d94ad33 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
majik 0:21019d94ad33 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
majik 0:21019d94ad33 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
majik 0:21019d94ad33 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
majik 0:21019d94ad33 32 * POSSIBILITY OF SUCH DAMAGE.
majik 0:21019d94ad33 33 *---------------------------------------------------------------------------*/
majik 0:21019d94ad33 34
majik 0:21019d94ad33 35 #include "rt_TypeDef.h"
majik 0:21019d94ad33 36 #include "RTX_Conf.h"
majik 0:21019d94ad33 37 #include "rt_List.h"
majik 0:21019d94ad33 38 #include "rt_Task.h"
majik 0:21019d94ad33 39 #include "rt_Time.h"
majik 0:21019d94ad33 40 #include "rt_Robin.h"
majik 0:21019d94ad33 41 #include "rt_HAL_CM.h"
majik 0:21019d94ad33 42
majik 0:21019d94ad33 43 /*----------------------------------------------------------------------------
majik 0:21019d94ad33 44 * Global Variables
majik 0:21019d94ad33 45 *---------------------------------------------------------------------------*/
majik 0:21019d94ad33 46
majik 0:21019d94ad33 47 struct OS_ROBIN os_robin;
majik 0:21019d94ad33 48
majik 0:21019d94ad33 49
majik 0:21019d94ad33 50 /*----------------------------------------------------------------------------
majik 0:21019d94ad33 51 * Global Functions
majik 0:21019d94ad33 52 *---------------------------------------------------------------------------*/
majik 0:21019d94ad33 53
majik 0:21019d94ad33 54 /*--------------------------- rt_init_robin ---------------------------------*/
majik 0:21019d94ad33 55
majik 0:21019d94ad33 56 __weak void rt_init_robin (void) {
majik 0:21019d94ad33 57 /* Initialize Round Robin variables. */
majik 0:21019d94ad33 58 os_robin.task = NULL;
majik 0:21019d94ad33 59 os_robin.tout = (U16)os_rrobin;
majik 0:21019d94ad33 60 }
majik 0:21019d94ad33 61
majik 0:21019d94ad33 62 /*--------------------------- rt_chk_robin ----------------------------------*/
majik 0:21019d94ad33 63
majik 0:21019d94ad33 64 __weak void rt_chk_robin (void) {
majik 0:21019d94ad33 65 /* Check if Round Robin timeout expired and switch to the next ready task.*/
majik 0:21019d94ad33 66 P_TCB p_new;
majik 0:21019d94ad33 67
majik 0:21019d94ad33 68 if (os_robin.task != os_rdy.p_lnk) {
majik 0:21019d94ad33 69 /* New task was suspended, reset Round Robin timeout. */
majik 0:21019d94ad33 70 os_robin.task = os_rdy.p_lnk;
majik 0:21019d94ad33 71 os_robin.time = (U16)os_time + os_robin.tout - 1;
majik 0:21019d94ad33 72 }
majik 0:21019d94ad33 73 if (os_robin.time == (U16)os_time) {
majik 0:21019d94ad33 74 /* Round Robin timeout has expired, swap Robin tasks. */
majik 0:21019d94ad33 75 os_robin.task = NULL;
majik 0:21019d94ad33 76 p_new = rt_get_first (&os_rdy);
majik 0:21019d94ad33 77 rt_put_prio ((P_XCB)&os_rdy, p_new);
majik 0:21019d94ad33 78 }
majik 0:21019d94ad33 79 }
majik 0:21019d94ad33 80
majik 0:21019d94ad33 81 /*----------------------------------------------------------------------------
majik 0:21019d94ad33 82 * end of file
majik 0:21019d94ad33 83 *---------------------------------------------------------------------------*/
majik 0:21019d94ad33 84