Professional Documents
Culture Documents
Bi Qu c B o
BI QU C B O 1
BI QU C B O 2
BI QU C B O 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 QU C B O 4
Compare
Khi khng dng RTOS, trong vng l p chnh ph i c l nh ki m tra serial port. Chng trnh s b block khi ch ng i dng nh p d li u t serial port. V i RTOS, ta khng c n thm code ki m tra serial port. Tc v ProcessSerialPort s b block khi ch ng i dng nh p d li u, nhng chng trnh chnh s khng b block
BI QU C B O 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 QU C B O 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 QU C B O 7
Khi khng dng RTOS, n u chng trnh ang ch serial port, cc phm nh n trn keypad s khng c x l N u dng ISR cho keypad x l phm, ISR s ch y trong th i gian di. i u ny lm gi m t c p ng c a h th ng.
V i FreeRTOS, n u u tin c a ProcessKeypad cao hn ProcessSerialPort, chng trnh s chuy n sang ProcessKeypad ngay khi c phm nh n, x l v quay tr l i
ProcessSerialPort.
BI QU C B O 8
Non-RTOS
void ProcessADC() { if ( SampleReady ) // code to read and store ADC value }
BI QU C B O 9
Non-FreeRTOS
main() { while (1) { if ( SerialCharAvail() ) ProcessSerialPort(); if ( Keypressed ) ProcessKeypad(); if ( SampleReady ) ProcessADC(); } }
D li u c th b m t n u chng trnh cha g i ProcessADC() tr c khi c d li u ti p theo (v ph i ch serialport, ). D li u c th sai n u chng trnh chnh v ng t cng truy c p bi n ton c c lu gi tr c a ADC cng lc.
BI QU C B O 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 QU C B O 11
m b o ADC lun c x l tr c, u tin c a tc v ADC c set cao hn cc tc v cn l i. Thay v ghi gi tr vo 1 bi n, ISR c th ghi gi tr ADC vo 1 queue.
Conclusion
N u khng dng RTOS, programmer ph i thi t k m t scheduler qu n l cc s ki n. Vi c dng FreeRTOS thi t k chng trnh s lm cho vi c thi t k d dng hn. FreeRTOS c debug v m b o bug-free, do s d ng FreeRTOS s lm cho chng trnh n nh hn
BI QU C B O 12