Академический Документы
Профессиональный Документы
Культура Документы
Application Overview
The interrupt handling mechanisms described in this document are demonstrated in the example source files supplied in the .zip file for this Application Note: example1.c uses the Application Queue API example2.c uses Application Callbacks
Application Callbacks
Callbacks are functions defined by the user that are passed to the Integrated Peripherals API. When an interrupt occurs, these functions are called directly by the underlying software. However, since the callback functions operate in interrupt context, they must return quickly so as not to delay program execution. This can mean that the Application Queue API is sometimes more suitable, since it takes interrupt processing out of interrupt context. Reference material for registering callbacks is available in the Integrated Peripherals API Reference Manual (JN-RM-2001).
Jennic 2006
Jennic
Initialisation and Enabling Interrupts
The application initialisation process varies slightly depending on which method is used to handle interrupts. Using Application Callbacks: In this case, the function u32AppApiInit() must be called (parameters that are not used can be set to NULL as seen in the source code example2.c). This call ensures that the interrupt vector tables are initialised correctly - for more details of the parameters to this call, see the 802.15.4 Stack API Reference Manual (JN-RM-2002). The callback function also needs to be registered. This function will then be called when an interrupt occurs. The process for this registration is described in the next section of this Application Note. Using Application Queue API: In this case, the function u32AppQApiInit() must be called, which initialises the Application Queue API interfaces (as seen in the source code example1.c). Apart from the above differences, the initialisation code in the examples is identical in the following aspects: Setting the direction of the required pins in this case, DIO9 is connected to SW1 and will therefore be an input, while DIO14 is connected LED1 and will be an output:
vAHI_DioSetDirection(E_AHI_DIO9_INT, 0); vAHI_DioSetDirection(0, E_AHI_DIO14_INT);
Initialising the state of input and output pins that is, enabling pull-ups for inputs and turning the LED off by driving the output DIO14 high:
vAHI_DioSetPullup(!E_AHI_DIO14_INT, E_AHI_DIO14_INT); vAHI_DioSetOutput(E_AHI_DIO14_INT, 0);
Setting the interrupt condition that is, whether the interrupt occurs on a rising edge or a falling edge. In the example, the interrupt is triggered on a rising edge:
vAHI_DioInterruptEdge(E_AHI_DIO9_INT, 0);
Here, a pointer to vDIOInterruptCallback() is passed as the parameter. The function vDIOInterruptCallback() is now responsible for interrupt handling, and must also conform to the PR_HWINT_APPCALLBACK type. This means that it must not have a return value and must accept two uint32 parameters. Therefore, vDIOInterruptCallback() is defined as:
PRIVATE void vDIOInterruptCallback (uint32 u32Device, uint32 u32ItemBitmap);
Jennic 2006
Jennic
Here the code is filtering for system controller interrupts caused by DIO9. The system controller handles interrupts from the comparator, wake timers and DIO. Therefore, to determine the source, the item bitmap is compared against the mask for DIO9. Once the source has been determined, the interrupt can be processed as appropriate.
3.
Caution: If problems occur when using your current Code::Blocks version, download the new version along with the latest version of this Application Note from the Support area of the Jennic web site (www.jennic.com/support).
Jennic 2006
Jennic
Revision History
Version 1.0 Notes Initial release
Corporate Headquarters Furnival Street Sheffield S1 4QT United Kingdom Tel +44 (0)114 281 2655 Fax +44 (0)114 281 2951 E-mail info@jennic.com United States Sales Office 1322 Scott Street, Suite 203 Point Loma CA 92106 USA Tel +1 619 223 2215 Fax +1 619 223 2081 E-mail info@us.jennic.com
Japan Sales Office Osakaya building 4F 1-11-8 Higashigotanda Shinagawa-ku, Tokyo 141-0022, Japan Tel +81 3 5449 7501 Fax +81 3 5449 0741 E-mail info@jp.jennic.com United States Sales Office 1060 First Avenue, Suite 400 King of Prussia PA 19406 USA Tel +1 619 223 2215 Fax +1 619 223 2081 E-mail info@us.jennic.com
Taiwan Sales Office 19F-1, 182, Sec.2 Tun Hwa S. Road Taipei 106 Taiwan Tel +886 2 2735 7357 Fax +886 2 2739 5687 E-mail info@tw.jennic.com
Jennic 2006