亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? simple cooperative multitasking.c

?? It show how to implement simple cooperative multitasking in PIC18.
?? C
字號:
// main.c
// SIMPLE COOPERATIVE MULTITASKING SYSTEM
// Harold Hallikainen
// harold@hallikainen.org
// December 2006
// This is a test of a SIMPLE cooperative multitasker. For each task, the system keeps a copy of the
// stack pointer and a copy of the stack.
// Initialization -
// Each task starts with a call of InitTask(n) where n is the task number. The task follows the InitTask
// call with any other required initialization, then enters a loop. InitTask saves the return address into
// the task in the SavedStack array. It then pops the return address off the stack so we return to main()
// instead of the function that called InitTask(). This allows us to continue setting up other tasks in main().
// Running-
// After each task has been initialized, main calls StartMultiTask(). This loads the stack with the values
// stored for task 0 by InitTask(). 
// Task Switching-
// Whenever a task is waiting for something (typically input, perhaps waiting for an output device to be ready),
// the loop contains a call of NextTask(). NextTask saves the current stack, loads the stack for the next task,
// then returns into that function where IT had called NextTask. Note that this return may be several 
// function call levels down. It need not be in the original task loop, but, instead, in a function called
// by that loop. This is makes multitasking much simpler than use of state machines for each task and function
// within that task.
// Variables and Function Parameters
// If a particular function contains a NextTask call, local variables and parameters to the function MUST
// be static. This keeps them from being located on the software stack (as automatic variables would be).
// Automatic variables and function parameters are lost during a task switch. In addition, the software stack
// may undeflow or overflow if you do a task switch while automatic variables or parameters exist. However,
// functions that do NOT include a task switch may use automatic parameters and functions since these are
// destroyed before the NextTask is called.
 
#include <p18f8627.h>
#include "types.h"
 
#define MaxTask 3
 
// Function Prototypes
void InitTask(static uint8_t TaskNum); 	// Save return address for this function to continue,
				//   then throw it out, dropping to main()
void StartMultiTask(void); 		// loads stack with initial data for task 0, then returns to task 0.
void NextTask(void); 			// save current stack and load stack for next task
void task0(void);
void task1(void);
void task2(void);
void task3(void);
uint8_t Task3SubFunction(static uint8_t n); // testing a subfunction
uint8_t Task3subSub(uint8_t n);
 
#pragma udata MultiTask 		// generally requires more than 256 bytes or ram, so put in bigger section
union{
    uint24_t u24b; 			// access as 24 bit unsigned int
    uint8_t u8b[sizeof(uint24_t)]; 	// or array of bytes
}SavedStack[MaxTask+1][31]; 		// Each stack entry is 3 bytes and there are 31 of them in each stack.
// MaxTask is highest task number. Since they start at zero, dimension to MaxTask+1 
 
static uint8_t SavedStackPointer[MaxTask+1]; // stack pointer saved for a particular task
#pragma udata 			// let linker allocate rest of stuff
 
void main(void){
    task0(); 
    task1();
    task2();
    task3(); 			// init each task
    StartMultiTask(); 		// go run multitask
}
 
void InitTask(static uint8_t TaskNum){
// Call from within a task. Puts the Saves the return address in SavedStack[TaskNum][1] so a later call
// of NextTask will continue from this address. Uses static parameter to avoid use of parameter stack which
// would be messed up when we do a return to main instead of calling function.
    INTCONbits.GIEH=0; 		// disable high priority interrupts
    INTCONbits.GIEL=0; 		// and low priority interrupts while messing with stack
    SavedStackPointer[TaskNum]=STKPTR; 	// save the current stack pointer
    SavedStack[TaskNum][STKPTR & 0b11111].u24b=TOS; // save current tos, which is where this function should start
    _asm POP _endasm; 		// remove return address so we drop back to main()
    INTCONbits.GIEL=1; 		// interrupts ok now
    INTCONbits.GIEH=1;
} 
 
void StartMultiTask(void){
// loads stack with initial data for task 0, then returns to task 0.
    INTCONbits.GIEH=0; 		// disable high priority interrupts
    INTCONbits.GIEL=0; 		// and low priority interrupts while messing with stack
    STKPTR=0; 			// start with clear stack pointer
    while(STKPTR<=SavedStackPointer[0]){
        //TOS=SavedStack[0][STKPTR & 0b11111]; // restore stack value - use below code to avoid movff to tos
        WREG=SavedStack[0][STKPTR & 0b11111].u8b[0];
        TOSL=WREG;
        WREG=SavedStack[0][STKPTR & 0b11111].u8b[1];
        TOSH=WREG;
        WREG=SavedStack[0][STKPTR & 0b11111].u8b[2];
        TOSU=WREG;
        _asm PUSH _endasm; 		// and increment stack pointer
    }
    _asm POP _endasm; 		// get rid of extra stack pointer increment at end 
    INTCONbits.GIEL=1; 		// interrupts ok now
    INTCONbits.GIEH=1;
} 
 
 
void NextTask(void){
// save away the current stack, load the one for the next task, then exit
static uint8_t TaskNum=0; 
    INTCONbits.GIEH=0; 		// disable high priority interrupts
    INTCONbits.GIEL=0; 		// and low priority interrupts while messing with stack
    SavedStackPointer[TaskNum]=STKPTR; 	// save the current stack pointer
    while(STKPTR & 0b11111){ 		// while stuff still on the stack
        SavedStack[TaskNum][STKPTR & 0b11111].u24b=TOS; // save current tos
       _asm POP _endasm; 		// decrement the stack pointer
    }
    TaskNum++; 			// on to next task
    if(TaskNum>MaxTask)
    TaskNum=0; 			// roll over if past last
    while(STKPTR<=SavedStackPointer[TaskNum]){
        //TOS=SavedStack[TaskNum][STKPTR & 0b11111]; // restore stack value - use below code to avoid movff to tos
        WREG=SavedStack[TaskNum][STKPTR & 0b11111].u8b[0];
        TOSL=WREG;
        WREG=SavedStack[TaskNum][STKPTR & 0b11111].u8b[1];
        TOSH=WREG;
        WREG=SavedStack[TaskNum][STKPTR & 0b11111].u8b[2];
        TOSU=WREG;
        _asm PUSH _endasm; 		// and increment stack pointer
     }
    _asm POP _endasm; 		// get rid of extra stack pointer increment at end 
    INTCONbits.GIEL=1; 		// interrupts ok now
    INTCONbits.GIEH=1;
    } 
 
 
 
void task0(void){
static uint8_t n=0;
    InitTask(0); 			// set up return address for here
    while(1){ 			// task loop
        ClrWdt();
        n++;
        NextTask();
    } // end while
} // end function 
 
void task1(void){
static uint8_t n=0;
    InitTask(1); 			// set up return address for here
    while(1){ 			// task loop
        ClrWdt();
        n++;
        NextTask();
    } // end while
}
 
void task2(void){
static uint8_t n=0;
    InitTask(2); 			// set up return address for here
    while(1){ 			// task loop
        ClrWdt();
        n++;
        NextTask();
    } // end while
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜桃精品在线观看| 亚洲成年人网站在线观看| 欧美精品欧美精品系列| 日本精品免费观看高清观看| 暴力调教一区二区三区| 国产成人免费在线| 国产69精品久久99不卡| 国产精品一品视频| 成人高清免费观看| 91美女片黄在线观看| 日本高清无吗v一区| 在线亚洲+欧美+日本专区| 在线观看91精品国产入口| 欧美精品一级二级| 欧美xxxx老人做受| 久久久综合激的五月天| 国产精品久久夜| 亚洲欧美激情视频在线观看一区二区三区| 国产精品麻豆视频| 亚洲一区在线免费观看| 免费亚洲电影在线| 国产一区美女在线| 91小视频免费看| 欧美嫩在线观看| 久久先锋资源网| 亚洲精品中文在线影院| 天天操天天干天天综合网| 国内精品嫩模私拍在线| 成人美女在线视频| 欧美肥妇毛茸茸| 欧美极品美女视频| 亚洲第一狼人社区| 国产.欧美.日韩| 欧美日韩在线三级| 久久久综合网站| 亚洲成人自拍偷拍| 高清免费成人av| 欧美精品日韩综合在线| 中文字幕精品三区| 亚洲一区日韩精品中文字幕| 久久综合综合久久综合| 97久久精品人人爽人人爽蜜臀| 91精品国产麻豆国产自产在线 | av在线一区二区三区| 欧美在线小视频| 欧美国产日本视频| 日韩国产欧美在线观看| 成人激情免费网站| 欧美一级国产精品| 亚洲精品国久久99热| 激情综合亚洲精品| 7799精品视频| 一区二区三区国产精华| 国产成人啪午夜精品网站男同| 欧美三级韩国三级日本一级| 中文字幕第一区| 激情欧美日韩一区二区| 欧美乱妇23p| 一区二区三区日韩欧美| 久久99精品久久久久| 欧美猛男超大videosgay| 综合久久给合久久狠狠狠97色| 极品美女销魂一区二区三区免费| 欧美日韩视频在线观看一区二区三区| 国产精品久久久久久久久免费桃花| 理论电影国产精品| 正在播放亚洲一区| 水蜜桃久久夜色精品一区的特点| 欧美中文字幕一区二区三区| 国产精品久久综合| jizzjizzjizz欧美| 国产精品国产三级国产普通话蜜臀 | 国产精品不卡一区| 国产成人免费视| 久久久久久久久久看片| 麻豆一区二区三| 日韩一区二区免费电影| 日韩国产一二三区| 欧美成人激情免费网| 狠狠狠色丁香婷婷综合久久五月| 日韩欧美国产系列| 久久99精品国产麻豆婷婷洗澡| 日韩一区二区免费在线电影| 日本韩国一区二区| 欧美国产精品久久| 99re6这里只有精品视频在线观看| 国产欧美一区二区精品性色超碰| 国产精品羞羞答答xxdd| 欧美—级在线免费片| 91女厕偷拍女厕偷拍高清| 亚洲精品视频在线| 欧美欧美欧美欧美| 黑人巨大精品欧美黑白配亚洲| 久久婷婷色综合| www.欧美色图| 亚洲一区二区三区三| 制服丝袜亚洲网站| 国内成人精品2018免费看| 国产欧美一区二区精品性| 一区二区三区色| 亚洲午夜免费电影| 2023国产精华国产精品| 99精品视频一区二区| 午夜精品福利一区二区三区av| 日韩欧美精品三级| 99re亚洲国产精品| 免费在线观看精品| 中文字幕在线不卡一区| 欧美片在线播放| 国产成人av自拍| 五月激情六月综合| 国产欧美日韩精品a在线观看| 99久久99久久久精品齐齐| 日本vs亚洲vs韩国一区三区二区| 国产日韩欧美综合在线| 欧美天堂一区二区三区| 国产精品一区三区| 亚洲一区二区三区在线| 中文字幕二三区不卡| 欧美精品久久一区| 99久久99久久免费精品蜜臀| 麻豆91精品91久久久的内涵| 亚洲人快播电影网| 精品久久国产97色综合| 欧美在线观看视频一区二区三区| 国产在线精品免费av| 亚洲国产精品尤物yw在线观看| 久久久久久久av麻豆果冻| 欧美日本一道本| www.欧美亚洲| 国产精品系列在线播放| 三级欧美韩日大片在线看| 亚洲欧美国产三级| 国产精品区一区二区三| 26uuu精品一区二区| 欧美亚洲综合色| 91玉足脚交白嫩脚丫在线播放| 国产综合一区二区| av在线播放一区二区三区| 麻豆精品久久精品色综合| 亚洲午夜电影在线| 一区二区三区精品| 亚洲欧美日韩电影| 日韩美女视频一区二区| 中文字幕乱码久久午夜不卡| 久久综合中文字幕| 欧美大片顶级少妇| 日韩一区二区视频在线观看| 欧美偷拍一区二区| 欧美日韩久久一区| 欧美日韩免费观看一区三区| 色噜噜狠狠成人网p站| 色婷婷综合视频在线观看| av一区二区三区四区| av爱爱亚洲一区| 99国产精品99久久久久久| 99精品桃花视频在线观看| 99精品热视频| 色诱亚洲精品久久久久久| 在线看国产一区二区| 欧美在线短视频| 6080国产精品一区二区| 欧美一级黄色片| 精品国产一区二区三区久久影院| 精品国产凹凸成av人网站| 亚洲精品一区二区三区蜜桃下载 | 色婷婷精品久久二区二区蜜臂av | 色婷婷久久久久swag精品| 色噜噜狠狠色综合欧洲selulu| 99riav久久精品riav| 色婷婷综合久色| 欧美一二三区在线观看| 精品久久久久久久久久久久包黑料 | 久久一夜天堂av一区二区三区| 精品裸体舞一区二区三区| 国产日韩av一区二区| 亚洲国产精品v| 亚洲美腿欧美偷拍| 五月天亚洲婷婷| 国产一区二区精品久久91| 成人免费毛片片v| 欧美日韩精品一二三区| 日韩女优视频免费观看| 国产精品久久久久一区| 亚洲va欧美va人人爽| 奇米精品一区二区三区在线观看| 国模娜娜一区二区三区| 99久久国产综合精品色伊| 欧美一区二区国产| 国产精品久久久久久久久快鸭 | 欧美日韩一区二区三区四区| 欧美一级日韩免费不卡| 国产精品嫩草99a| 日本亚洲免费观看| 成人黄色电影在线| 日韩一区二区三区免费看| 国产精品成人一区二区艾草 | 在线不卡中文字幕| 亚洲va国产天堂va久久en| 国产精品一卡二卡|