■시간관리 함수■
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #include "includes.h" /* ........................................................................... * * 태스크 스택 정의 * =================== */ OS_STK TaskStartStk[TASK_STK_SIZE]; /* START task stack */ OS_STK Task1Stk[TASK_STK_SIZE]; /* Task #1 stack */ OS_STK Task2Stk[TASK_STK_SIZE]; /* Task #2 stack */ //OS_STK Task3Stk[TASK_STK_SIZE]; /* Task #3 stack */ //OS_STK Task4Stk[TASK_STK_SIZE]; /* Task #4 stack */ /* ........................................................................... * * 사용자 메모리 정의 * =================== */ TASK_USER_DATA TaskUserData[7]; /* ........................................................................... * * 이벤트 컨트롤 & 사용자 정의 블럭 정의 * =================== */ struct tm { int tm_msec; /* milli seconds */ int tm_sec; /* seconds after the minute, 0 to 60 (0 - 60 allows for the occasional leap second) */ int tm_min; /* minutes after the hour, 0 to 59 */ int tm_hour; /* hours since midnight, 0 to 23 */ }; // 1초마다 콘솔에 동작중을 표시(.) extern INT32U USE_OSTimeTickHook; void OSTimeDlyCustom( struct tm *t ); /* ........................................................................... * * 태스크 함수 원형 * =================== */ void TaskStart(void *pdata); /* Function prototypes of Startup task */ void Task1(void *pdata); void Task2(void *pdata); void Task3(void *pdata); void Task4(void *pdata); // // 어플리케이션 메인 루틴 // int main(void) { OSInit(); /* microC/OS-II 초기화 */ PC_ElapsedInit(); /* Initialized elapsed time measurement */ strcpy(TaskUserData[TASK_START_ID].TaskName, "TaskStart"); // TASK CREATE OSTaskCreateExt(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE-1], TASK_START_PRIO, TASK_START_ID, &TaskStartStk[0], TASK_STK_SIZE, &TaskUserData[TASK_START_ID], OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); OSStart(); /* start scheduler */ return 0; } // // 태스크 'START' // void TaskStart (void *pdata) { INT8U err; pdata = pdata; /* 컴파일러 경고를 막기 위함 */ // 시스템 초기화(UART, LCD, TimeTick) InitSystem(); OSStatInit(); /* Initialize uC/OS-II's 통계 함수 */ // 1초마다 콘솔에 동작중을 표시(.) USE_OSTimeTickHook = 1; // refer to 'OS_CPU_C.C' strcpy(TaskUserData[TASK_1_ID].TaskName, "Task1"); OSTaskCreateExt(Task1, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], TASK_1_PRIO, TASK_1_ID, &Task1Stk[0], TASK_STK_SIZE, &TaskUserData[TASK_1_ID], 0); if (err) printf("OSTaskCreate error found, code[0x%X]\n",err); #if 1 // No comment err = OSTaskSuspend(OS_PRIO_SELF); if (err) printf("OSTaskSuspend error found, code[0x%X]\n",err); #endif // TODO #3 /* delete self task */ err = OSTaskDel(OS_PRIO_SELF); if (err) printf("OSTaskDel(OS_PRIO_SELF) error found, code[0x%X]\n",err); } // // 태스크 1 // void Task1(void *pdata) { INT8U err; struct tm time_s; // USER defined time structure pdata = pdata; /* 컴파일러 경고를 막기 위함 */ printf("\n\nTask1 TASK created,\n"); /* TODO #1: Wait 5 Second from now on use 'OSTimeDly()' */ printf("Wait 5 Second From now on\n"); #if 1 OSTimeDly(500);//5 sec #endif // TODO #1 printf("finished\n\n"); /* TODO #2: Wait 10 Second from now on use 'OSTimeDlyCustom()' : 5 line */ printf("Wait 10 Second From now on\n"); #if 1 time_s.tm_msec=0; time_s.tm_sec=10; time_s.tm_min=0; time_s.tm_hour=0; OSTimeDlyCustom(&time_s); #endif // TODO #2 printf("finished\n"); #if 1 // No comment err = OSTaskSuspend(OS_PRIO_SELF); if (err) printf("OSTaskSuspend error found, code[0x%X]\n",err); #endif // TODO #3 // 1초마다 콘솔 출력 '중지' USE_OSTimeTickHook = 0; // refer to 'OS_CPU_C.C' printf("\n\ntask1 terminated,\n"); err = OSTaskDel(OS_PRIO_SELF); /* delete self task */ if (err) printf("OSTaskDel(OS_PRIO_SELF) error found, code[0x%X]\n",err); } // // OSTimeDlyCustom // void OSTimeDlyCustom( struct tm *t ) { OSTimeDlyHMSM (t->tm_hour, t->tm_min, t->tm_sec, t->tm_msec); } /*----------------------------------------------------------------------------- * Program : 02_TIMER.C -----------------------------------------------------------------------------*/ | cs |
*Makefile 설정
*TODO 1 , 2
*TODO 3
=>테스크 일시 중단 prio : 중지시킬 데스크의 우선순위
OSTaskResume()으로 다시 동작할 수 있다.
'RTOS' 카테고리의 다른 글
[RTOS_Day5]RTOS 포팅 진행 기록_2 (0) | 2018.12.27 |
---|---|
[RTOS_Day4]RTOS 포팅 진행 기록 (0) | 2018.12.26 |
[RTOS_Day3]통계 테스크 (0) | 2018.12.19 |
[RTOS_Day2]임계영역 보호 (0) | 2018.12.18 |
[RTOS_Day1]테스크 생성 및 운용 (0) | 2018.12.17 |