Wireless Networks Lab Callback Function 9102020 Callback v
Wireless Networks Lab – Callback Function 9/10/2020
Callback v. s. Polling n Polling v Using a loop to continuously check object. n Callback v Setup an ISR (Interrupt Service Routine). When an interrupt raises, the ISR will be called automatically to handle follow-up actions.
Callback v. s. Polling n Lab 1 n Lab 2 while (TRUE) { …… if (b. Blink_Flag) { led_on(LED 0); led_off(LED 1); b. Blink_Flag = FALSE; } …… } v v. AHI_Tick. Timer. Init(v. Tick. Timer. ISR);
Sample n Install and Test
Overview n Through Integrated Peripherals API, we can initialize the Button and LED devices. n Through Fontal. BSP, we can control the LEDs and monitor the button status n Through callback mechanism provided by Integrated Peripherals API, we can catch the interrupt event.
Integrated peripherals API n The functions are defined in App. Hardware. Api. h n u 32 AHI_init(void); v This should be called after every reset or wake-up and before any other AHI calls are made. v We can see that in sample codes about Lab 1 and Lab 2.
Board. API n Allow rapid software development by providing a function library for interfacing to the evaluation board components v LED control v Button control v Sensor control n The FT 6250 device provides the Fontal. BSP.
Callback function n Interrupt Handling v Interrupts from peripheral devices are handled by a set of device-specific callbacks. v callback registration PRIVATE void v. Hw. Device. Int. Callback(uint 32 u 32 Device. Id, uint 32 u 32 Item. Bitmap) v u 32 Device. ID is an enumerated value indicating the peripheral that generated the interrupt. v u 32 Item. Bitmap is set for each individual interrupt source within the peripheral.
v. Tick. Timer. ISR PUBLIC void App. Cold. Start(void) { v. AHI_Tick. Timer. Init(v. Tick. Timer. ISR); } PRIVATE void v. Tick. Timer. ISR(uint 32 u 32 Device. Id, uint 32 u 32 Item. Bitmap) { if (b. Blink_Flag) { led_on(LED 0); led_off(LED 1); b. Blink_Flag = FALSE; } else { led_on(LED 1); led_off(LED 0); b. Blink_Flag = TRUE; } }
Callback function n callback registration
Lab 2 n What should you do in this lab v Using the Callback function to handle the buttons interrupt events and control LEDs. n Bonus v Battery limitation ØUsing another ticktimer to save energy. If no one press the buttons for a long time, automatically turn them off. ØOnce each of buttons are pressed, you are required to let LED return the last status.
Lab 2 Flowchart
Lab 2 pseudo code 1. 2. 3. 4. 5. u 32 AHI_Init(); u 32 App. Api. Init(NULL, NULL, NULL); led_init(); btn_init(); v. AHI_Sys. Ctrl. Register. Callback( v. System. ISR);
Callback function PRIVATE void v. System. ISR(uint 32 u 32 Device. Id, uint 32 u 32 Item. Bitmap) { switch (u 32 Device. Id) { case E_AHI_DEVICE_SYSCTRL: if (btn_pressed(BUTTON 0)) …… break; default: break; } }
- Slides: 14