我用的平台是k64,mqx4.1操作系统,我运行自带的例子,lwgpio的中断例子,当我按键的时候,如期调用中断方式,于是,我复制这个例子的代码,放到我自己的工程里面去,说明一下,我工程是K60,现在考虑移植。
当我主函数调用的时候,我还未按键,它自动调用一次中断函数,后续,就正常了,我不知道其原因。
void int_service_routine(void *pin)
{
lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}
void main_task
(
uint32_t initial_data
)
{
/* Structures holding information about specific pin */
LWGPIO_STRUCT led1, btn1;
// button_state_t button_state, button_last_state;
_mqx_uint result;
if (!lwgpio_init(&btn1, (GPIO_PORT_B | GPIO_PIN5), LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))//(GPIO_PORT_B | GPIO_PIN4)(GPIO_PORT_B | GPIO_PIN7)
{
printf("Initializing button GPIO as input failed.\n");
_task_block();
}
lwgpio_set_functionality(&btn1, 1);
lwgpio_set_attribute(&btn1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);
if (!lwgpio_int_init(&btn1, LWGPIO_INT_MODE_FALLING))
{
printf("Initializing button GPIO for interrupt failed.\n");
_task_block();
}
_int_install_isr(lwgpio_int_get_vector(&btn1), int_service_routine, (void *) &btn1);
lwgpio_int_clear_flag(&btn1);
lwgpio_int_enable(&btn1, TRUE);
_bsp_int_init(lwgpio_int_get_vector(&btn1), 3, 0, TRUE);
printf("\n====================== GPIO Example ======================\n");
printf("The (SW1) button is configured to trigger GPIO interrupt.\n");
printf("Press the (SW1) button 3x to continue.\n\n");
button_press_count = 1;
while(button_press_count < 4) {
/* wait for button press, lwsem is set in button isr */
// _lwsem_wait(&lwsem);
printf("Button pressed %dx\r", button_press_count);
}
int value=1;
while(!value)
value = lwgpio_get_value(&btn1);
printf("test passed\n");
printf("test passed 0\n");
/* disable interrupt on GPIO peripheral module */
lwgpio_int_enable(&btn1, FALSE); |