1 / 14

Wireless Networks Lab – Callback Function

Wireless Networks Lab – Callback Function. 2020/1/5. Callback v.s. Polling. Polling Using a loop to continuously check object. Callback Setup an ISR (Interrupt Service Routine). When an interrupt raises, the ISR will be called automatically to handle follow-up actions.

aschreiner
Télécharger la présentation

Wireless Networks Lab – Callback Function

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Wireless Networks Lab – Callback Function 2020/1/5

  2. Callback v.s. Polling • Polling • Using a loop to continuously check object. • Callback • Setup an ISR (Interrupt Service Routine). When an interrupt raises, the ISR will be called automatically to handle follow-up actions.

  3. Callback v.s. Polling • Lab1 • Lab2 • vAHI_TickTimerInit(vTickTimerISR); while (TRUE) { …… if (bBlink_Flag) { led_on(LED0); led_off(LED1); bBlink_Flag = FALSE; } …… }

  4. Sample • Install and Test

  5. Overview • Through Integrated Peripherals API, we can initialize the Button and LED devices. • Through FontalBSP, we can control the LEDs and monitor the button status • Through callback mechanism provided by Integrated Peripherals API, we can catch the interrupt event.

  6. Integrated peripherals API • The functions are defined in AppHardwareApi.h • u32AHI_init(void); • This should be called after every reset or wake-up and before any other AHI calls are made. • We can see that in sample codes about Lab1 and Lab2.

  7. BoardAPI • Allow rapid software development by providing a function library for interfacing to the evaluation board components • LED control • Button control • Sensor control • The FT 6250 device provides the FontalBSP.

  8. Callback function • Interrupt Handling • Interrupts from peripheral devices are handled by a set of device-specific callbacks. • callback registration PRIVATE void vHwDeviceIntCallback(uint32 u32DeviceId, uint32 u32ItemBitmap) • u32DeviceID is an enumerated value indicating the peripheral that generated the interrupt. • u32ItemBitmap is set for each individual interrupt source within the peripheral.

  9. vTickTimerISR PUBLIC void AppColdStart(void) { vAHI_TickTimerInit(vTickTimerISR); } PRIVATE void vTickTimerISR(uint32 u32DeviceId, uint32 u32ItemBitmap) { if (bBlink_Flag) { led_on(LED0); led_off(LED1); bBlink_Flag = FALSE; } else { led_on(LED1); led_off(LED0); bBlink_Flag = TRUE; } }

  10. Callback function • callback registration

  11. Lab2 • What should you do in this lab • Using the Callback function to handle the buttons interrupt events and control LEDs. • Bonus • 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.

  12. Lab2 Flowchart

  13. Lab2 pseudo code • u32AHI_Init(); • u32AppApiInit(NULL, NULL, NULL, NULL, NULL, NULL, NULL); • led_init(); • btn_init(); • vAHI_SysCtrlRegisterCallback(vSystemISR);

  14. Callback function PRIVATE void vSystemISR(uint32 u32DeviceId, uint32 u32ItemBitmap) { switch (u32DeviceId) { case E_AHI_DEVICE_SYSCTRL: if (btn_pressed(BUTTON0)) …… break; default: break; } }

More Related