Key functions: Osflagcreate, Osflagpost, OSFLAGPEND
Environment: UC / OS-II? 2.52 Pacific C for DOS
Description: A total of 3 markers Engine_oil_pres_ok, engine_oil_temp_ok, engine_start?, 1 process Taskpend, 1 process Taskpost. TaskPost Modify Time Sign Group, Taskpend Wait Time Sign Group.
/ ************************************************** *********************************************************** ******** ???????????????????????????????????? ????? uc / os-II * ?????????????????????????????????????????????? ?? The real-time kernel ** ??????????????????????????? (c) CopyRight 2004, Yuan Fei, Hefei University Of Technology *? ????????????????????????????????? ALL Rights Reserved * *** filename? ???: Test.c * Programmer (s): yuan fei * description?: this file illustrate the usage of flags. ********************** *********************************************************** ***************************************** /
#include "incrudes.h"
/ ************************************************** *********************************************************** ******** ???????????????????????????????????? ???? constants ***************************************************** *********************************************************** *********** /
#define? task_stk_size ????????????????? 128 ?????? * size of each task's stacks (# of words) ??????????? * / # define? n_tasks ?????????????????????????? 2 ??????? * number of identical task ??????? ?????????????????? * /
#define engine_oil_pres_ok ?????????? 0x01 # define engine_oil_temp_ok ??????????? 0x02 # define engine_start ????????????????? 0x04
/ ************************************************** *********************************************************** ******** ???????????????????????????????????? ???? variables ***************************************************** *********************************************************** *********** / OS_STK ??????? taskstk [n_tasks] [task_stk_size]; ??????? / * tasks stacks ??????????? ?????????????????????????????????????? TaskStartStk [task_stk_size];
OS_FLAG_GRP? * EnginesTatus;
INT8U ???????? curline = 0; ?????????????????? *********** *********************************************************** ********************************************???? ???????????????????????????????? function protoypes ********* *********************************************************** ****************************************************** /
??????? void? taskstart (void * data); ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? * / static? void? Taskpend (void * data); ??????????????????? * waiting for the signal ???????????????????????????????????????????? ???????????????????????????? * / static? void? Taskpost (void * data); ?????????????????? / * The process of sending the signal ??????????????????????????????? * /
/ ************************************************** *********************************************************** ******** ???????????????????????????????????? ????? MAIN ****************************************************** *********************************************************** ************ /
Void? main (void) {????? pc_dispclrscr (DISP_FGND_WHITE DISP_BGND_BLACK); ????? / * clear the screen ??????????????????????????????????????????????????? ??? * / ??? ??? ??? osinit (); ????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????????????? * initialize uc / OS-II ????????????????????? * /
??? pc_dossavereturn (); ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????? * / ??? pc_vectset (ucos, osctxsw); ?????????????????????????????????????? * INSTALL UC / OS-II's Context Switch Vector * / ??? ??? ostaskcreate (taskstart, (void *) 0, & taskstartstk [task_startstk [task_stk_size - 1], 0); ??? osstart (); ???????? ??????????????????????????????????????? * start multitasking ????????? ????????????? * /}
/ ************************************************** *********************************************************** ******** ???????????????????????????????????? ??? Startup task ***************************************************** *********************************************************** *********** / void? taskstart (void * pdata) {# if os_critical_method == 3 ???????????????????????????????????????????????????????? ???????? / * allocate storage for cpu status register * / ??? os_cpu_sr? Cpu_sr; #ENDIF ??? INT16S ???? kéy; ??? int8u ????? ERR;
??? pdata = pdata; ????????????????????????????????? * prevent Compiler Warning ???????????????? * /
??? os_enter_critical (); ??? pc_vectset (0x08, ostickism); ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? Ii's clock tick isr ??????? * / ??? pc_settickrate; ?????????????????????? * Reprogram Tick Rate???? ??????????????????? * / ??? os_exit_critical (); ??? ??? Engines = OSFlagcreate (0, & ERR);
??? ostaskcreate (taskpost, 0, & taskstk [0] [task_stk_size - 1], 2); ??? ostaskcreate (taskpend, 0, & taskstk [1] [task_stk_size - 1], 3);
??? for (;;) {??????? IF (pc_getkey (& key) == true) {???????????????????????????????????????????????? IF key HAS been Pressed ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????? ??? pc_dosreturn (); ????????????????????????????????????????????? ????????????????? * / ???????????} ???????????? ?? ostimedlyhmsm (0, 0, 1, 0); ????????????????????????? * wait one second ???????? ?????????????????? * / ???}}
?
?
Static? void? Taskpost (void * pdata) {??? int8u ?? err; ??? INT8U ?? Time = 0; ??? ??? pdata = pdata; ??? ??? for (;;) {????? ??????? f (curline> 24) ??????????? curline = 0; ??????? pc_dispclRrow (curline, disp_bgnd_black); ?? ????? switch (time) {??????????? case 0: ?????????????? OsflagPost (EnginesTatus, Engine_oil_pres_ok, OS_FLAG_SET, & ERR); ??????????????? pc_dispstr (0, curline, "posting engine_oil_pres_ok", DISP_FGND_BLUE); ??????????????? TIME = 1;? ?????????????? breaf; ??????????? case 1: ??????????????? OsflagPost (EnginesTatus, Engine_oil_Temp_ok , Os_flag_set, & err); ??????????????? pc_dispstr (0, curline, "posting engine_oil_temp_ok", DISP_FGND_BLUE); ??????????????? TIME = 1; ??????????????? breaf; ??????????? case 2: ?????????????? ? OSFLAGPOST (EnginesTatus, Engine_Start, OS_FLAG_SET, & ERR); ??????????????? PC_Dispstr (0, Curline, "Posting Engine_Start", DISP_FGND_BLUE); ????????? ?????? Time = 1; ??????????????????? DEFAULT: ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????? osflagpost (EnginesTatus, ????????????????? ????????? eNGINE_OIL_PRES_OK ?????????????????? ENGINE_OIL_TEMP_OK ??????????? ??????????????? eNGINE_START, ????????????????? os_flag_clr, ????? ???????????????????????????????????????????????? pc_dispstr (0, Curline, "Clearing Enginestatus", DISP_FGND_YELLOW); ??????????????????????????} ?????????} = 1; ??????? ostimedlyHMSM (0, 0, 1, 0); ???}}?
Static? void? Taskpend (void * pdata) {??? int8u ?????? err;