rt_sem_t binary_sem;
void beep_on(void *args)
{
rt_kprintf("turn off beep!\n");
rt_sem_release(binary_sem);
}
int main( void )
{
rt_uint8_t i=0;
/* 按键0引脚为输入模式 */
rt_pin_mode(GET_PIN(B,8), PIN_MODE_INPUT_PULLUP);
/* 绑定中断,下降沿模式,回调函数名为beep_on */
rt_pin_attach_irq(GET_PIN(B,8), PIN_IRQ_MODE_FALLING, beep_on, RT_NULL);
/* 使能中断 */
rt_pin_irq_enable(GET_PIN(B,8), PIN_IRQ_ENABLE);
binary_sem = rt_sem_create("binary_sem",
0,
RT_IPC_FLAG_FIFO);
while(1)
{
rt_sem_take(binary_sem, RT_WAITING_FOREVER);
rt_kprintf("RT-Thread interrupt send semaphore test\r\n");
}
}
RTT线程与外部中断同步
最新推荐文章于 2024-02-15 20:59:39 发布