Professional Documents
Culture Documents
Bi Quc Bo
BI QUC BO 1
BI QUC BO 2
BI QUC BO 3
Non-RTOS
void ProcessSerialPort() { // serial port code goes here }
Using FreeRTOS
void ProcessSerialPort(void *pvParameters ) { // serial port code goes here } void Main(void) { xTaskCreate(ProcessSerialPort, serial Task", 1000, NULL, serialPri, NULL ); while (1) { // no code yet } }
BI QUC BO 4
Compare
Khi khng dng RTOS, trong vng lp chnh phi c lnh kim tra serial port. Chng trnh s b block khi ch ngi dng nhp d liu t serial port. Vi RTOS, ta khng cn thm code kim tra serial port. Tc v ProcessSerialPort s b block khi ch ngi dng nhp d liu, nhng chng trnh chnh s khng b block
BI QUC BO 5
Non-RTOS
void ProcessKeypad() { char key = ScanKeypad(); // code to process key goes here }
Free-RTOS
void ProcessKeypad(void *pvParameters ) { while (1) { xSemaphoreTake( xKeyPadSemaphore, portMAX_DELAY ); char key = ScanKeypad(); // code to process key goes here } }
BI QUC BO 6
Non-FreeRTOS
main() { while (1) { if ( SerialCharAvail() ) ProcessSerialPort(); if ( Keypressed ) ProcessKeypad(); } }
Void main(void) { xTaskCreate(ProcessSerialPort, serial Task", 1000, NULL, serialPri, NULL ); xTaskCreate(ProcessKeypad, keypad Task", 1000, NULL, keyPadPri, NULL ); while (1) { // no code yet } }
BI QUC BO 7
Khi khng dng RTOS, nu chng trnh ang ch serial port, cc phm nhn trn keypad s khng c x l Nu dng ISR cho keypad x l phm, ISR s chy trong thi gian di. iu ny lm gim tc p ng ca h thng.
Vi FreeRTOS, nu u tin ca ProcessKeypad cao hn ProcessSerialPort, chng trnh s chuyn sang ProcessKeypad ngay khi c phm nhn, x l v quay tr li
ProcessSerialPort.
BI QUC BO 8
Non-RTOS
void ProcessADC() { if ( SampleReady ) // code to read and store ADC value }
BI QUC BO 9
Non-FreeRTOS
main() { while (1) { if ( SerialCharAvail() ) ProcessSerialPort(); if ( Keypressed ) ProcessKeypad(); if ( SampleReady ) ProcessADC(); } }
D liu c th b mt nu chng trnh cha gi ProcessADC() trc khi c d liu tip theo (v phi ch serialport, ). D liu c th sai nu chng trnh chnh v ngt cng truy cp bin ton cc lu gi tr ca ADC cng lc.
BI QUC BO 10
With FreeRTOS
void ProcessADC(void *pvParameters) { while (1) { xSemaphoreTake( xADCSemaphore, portMAX_DELAY ); // code to read and store ADC value } }
With FreeRTOS
Void main(void) { xTaskCreate(ProcessSerialPort, serial Task", 1000, NULL, serialPri, NULL ); xTaskCreate(ProcessKeypad, keypad Task", 1000, NULL, keyPadPri, NULL ); xTaskCreate(ProcessADC, ADC Task", 1000, NULL, ADCPri, NULL ); while (1) { // no code yet } }
BI QUC BO 11
m bo ADC lun c x l trc, u tin ca tc v ADC c set cao hn cc tc v cn li. Thay v ghi gi tr vo 1 bin, ISR c th ghi gi tr ADC vo 1 queue.
Conclusion
Nu khng dng RTOS, programmer phi thit k mt scheduler qun l cc s kin. Vic dng FreeRTOS thit k chng trnh s lm cho vic thit k d dng hn. FreeRTOS c debug v m bo bug-free, do s dng FreeRTOS s lm cho chng trnh n nh hn
BI QUC BO 12