CC2650 按键中断程序

在Pin_init() 函数中构建了 Hwi 和Swi 线程

 // Setup HWI handler
    Hwi_Params_init(&hwiParams);
    hwiParams.priority = PINCC26XX_hwAttrs.intPriority;
    Hwi_construct(&PinHwi, INT_AON_GPIO_EDGE,           PIN_hwi,&hwiParams, NULL);
      // Setup SWI handler
    Swi_Params_init(&(swiParams));
    swiParams.priority = PINCC26XX_hwAttrs.swiPriority;
    swiParams.trigger = 0;
    Swi_construct(&PinSwi, PIN_swi, &(swiParams), NULL);

Hwi的中断号对应着GPIO的中断向量号
中断发生时,Hwi响应。清除中断标准位,并唤醒Swi线程。

// I/O HWI service routine
static void PIN_hwi(UArg arg) {
    uint32_t iEvent;

    // Get event flag with lowest index (also pin ID)
    iEvent = HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0);

    // Clear this event flag
    HWREG(GPIO_NONBUF_BASE + GPIO_O_EVFLAGS31_0) = iEvent;

    // Include all GPIO's currently triggered in the SWI
    Swi_or(Swi_handle(&(PinSwi)), iEvent);
}

Swi查询中断来源并执行应用层程序传来的回调函数。

// I/O SWI service routine that posts the callback in a SWI context
static void PIN_swi(UArg arg0, UArg arg1){

    uint32_t iEvent;
    unsigned char iEventCounter;
    PIN_Handle handle;
    PIN_IntCb  pCb;

    // Get the OR'd trigger value representing all iEvent values prior to running the SWI
    iEvent = Swi_getTrigger();

    // iEventCounter cycles through all pins on the device up to the max number of pins
    for(iEventCounter = 0; iEventCounter < PIN_NumPins; iEventCounter++){
        // Check if current iEventCounter bit is set in iEvent
        if(iEvent & (1 << iEventCounter)){
            // Get pin handle and registered callback function
            // Double paranthesis to supress GCC warning
            // Intentional assignment is intended, not the equality comparison
            if((handle = PIN_HandleTable[iEventCounter])) {
                if((pCb = handle->pCbFunc)) {
                    // Event from existing pin, with an associated handle and a
                    // registered callback -> call callback
                    // Run the callback function in a SWI context.
                    pCb(handle, iEventCounter);
                }
            }
        }
    }
}

应用层完成的就是回调函数的注册

PIN_registerIntCb(PIN_Handle,*callback);

注册工作就是完成Pin_Handle结构体的的pCbFunc域赋值。

PIN_Status PIN_registerIntCb(PIN_Handle handle, PIN_IntCb pCb) {
    if (handle) {
        handle->pCbFunc = pCb;
        return PIN_SUCCESS;
    } else {
        return PIN_NO_ACCESS;
    }
}

另外按键PIO的配置和中断使能是在Pin_open()函数中实现的。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值