Daoyu_Sofiane Yao_Belouka / mbed-rtos

Dependents:   Mecatro_Gyro_Programme_Codeur_HC06

Committer:
daoyu_sofiane
Date:
Fri Apr 16 09:25:33 2021 +0000
Revision:
0:a8ed743bc1e1
Projet Gyropode

Who changed what in which revision?

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