Download presentation
Presentation is loading. Please wait.
1
Wireless Networks Lab – Callback Function 2015/6/30
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 1. u32AHI_Init(); 2. u32AppApiInit(NULL, NULL, NULL, NULL, NULL, NULL, NULL); 3. led_init(); 4. btn_init(); 5. 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; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.