📄 gpiointr.c
字号:
/* gpiointr.c
This program does the following:
- Creates a GPIO session with error checking
- Installs an interrupt handler and enables EIR interrupts
- Waits for EIR; invokes the handler for each interrupt
*/
#include <stdio.h>
#include <sicl.h>
void SICLCALLBACK handler(INST id, long reason, long sec)
{
if (reason == I_INTR_GPIO_EIR) {
printf("EIR interrupt detected\n");
/* Proper protocol is for the peripheral device to hold
* EIR asserted until the controller "acknowledges" the
* interrupt. The method for acknowledging and/or responding
* to EIR is very device-dependent. Perhaps a CTLx line is
* pulsed, or data is read, etc. The response should be
* executed at this point in the program.
*/
}
else
printf("Unexpected Interrupt; reason=%d\n", reason);
}
main()
{
INST intf; /* interface session id */
#if defined (__BORLANDC__) && !defined (__WIN32__)
_InitEasyWin(); /* required for Borland EasyWin programs */
#endif
/* log message and exit program on error */
ionerror(I_ERROR_EXIT);
/* open GPIO interface session */
intf = iopen("gpio");
/* suspend interrupts until configured */
iintroff();
/* configure interrupts */
ionintr(intf, handler);
isetintr(intf, I_INTR_GPIO_EIR, 1);
/* wait for interrupts */
printf("Ready for interrupts\n");
while (1) {
iwaithdlr(0); /* optional timeout can be specified here */
}
/* iwaithdlr performs an automatic iintron(). If your program
* does concurrent processing, instead of waiting, then you need
* to execute iintron() when you are ready for interrupts.
*/
/* This simplified example loops forever. Most real applications
* would have termination conditions that cause the loop to exit.
*/
iclose(intf);
/* For WIN16 applications, call _siclcleanup before exiting to release
resources allocated by SICL for this application. This call
is a no-op for WIN32 applications.
*/
_siclcleanup();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -