This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1310 双引脚同时中断问题

Other Parts Discussed in Thread: CC1310

我同时使用了两个中断引脚,均映射到同一个中断回调函数,但是产生了一次中断就不再响应切换了,这样做存在问题吗?我想知道两个引脚同时产生中断时,CC1310的中断系统是如何处理到来的多个中断的?

#define  SEL_PIN_A   IOID_25 
#define  SEL_PIN_B   IOID_26

/* Shutdown Button pin table */
PIN_Config ButtonTableShutdown[] = {
    SEL_PIN_A   | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES,
    SEL_PIN_B   | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES,
    PIN_TERMINATE                                 /* Terminate list */
};

/* Pin interrupt Callback function board buttons configured in the pinTable. */
static void buttonCallbackFunction(PIN_Handle handle, PIN_Id pinId) 
{
  /* Set current pinId to active */
  activeButtonPinId = pinId;

  /* Disable interrupts during debounce */
  PIN_setConfig(handle, PIN_BM_IRQ, activeButtonPinId | PIN_IRQ_DIS);
      
  /* Debounce logic, only toggle if the button is still pushed (low) */
  CPUdelay((uint32_t)((48000000/3)*0.1f)); /* 10ms 延时 */

  switch (activeButtonPinId) {
      case SEL_PIN_A:
        HAL_UART_Transmit("PIN_A",5);
       break;

     case SEL_PIN_B:
        HAL_UART_Transmit("PIN_B",5);
     break;

     default:break;
        }
}

  • /******************************************************************************
    
     @file board_key.c
    
     @brief This file contains the interface to the Launchpad Key Service
    
     <BR>
     NOTE:  The launchpad only has 2 buttons, so only KEY_LEFT and KEY_RIGHT are
            enabled.
     <BR>
     Group: WCS LPC
     Target Device: CC2652
    
     ******************************************************************************
     
     Copyright (c) 2016-2018, Texas Instruments Incorporated
     All rights reserved.
    
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions
     are met:
    
     *  Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    
     *  Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    
     *  Neither the name of Texas Instruments Incorporated nor the names of
        its contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
    
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
     ******************************************************************************
     Release Name: simplelink_cc26x2_sdk_2_10_00_44_s
     Release Date: 2018-04-09 12:59:57
     *****************************************************************************/
    
    /******************************************************************************
     Includes
     *****************************************************************************/
    
    #include <stdbool.h>
    #include <chipinfo.h>
    #include "util_timer.h"
    #include "board_key.h"
    
    /******************************************************************************
     Local Variables
     *****************************************************************************/
    
    /* Value of keys Pressed */
    static uint8_t keysPressed;
    
    /* Key debounce clock */
    static Clock_Struct keyChangeClock;
    
    /* Pointer to application callback */
    static Board_Key_keysPressedCB_t appKeyChangeHandler = NULL;
    
    /*
     Create the MSA KEY pin table. This will override the key attributes in
     BoardGpioInitTable[].
     */
    static PIN_Config keyPinTable[] = {
          Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
          Board_PIN_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
          PIN_TERMINATE /* Terminate list */
        };
    
    #if defined(CC13X2R1_LAUNCHXL) && !defined(NO_CC1312R1_SUPPORT)
    static PIN_Config keyPinTable_CC1312R1[] = {
          Board_PIN_BUTTON0_CC1312R1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
          Board_PIN_BUTTON1_CC1312R1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
          PIN_TERMINATE /* Terminate list */
        };
    #endif
    
    /* KEY pin state */
    static PIN_State keyPinState;
    
    /* KEY Pin Handle */
    static PIN_Handle keyPinHandle;
    
    /* KEY Pid Id */
    static PIN_Id keyButton0;
    static PIN_Id keyButton1;
    
    /******************************************************************************
     Local Functions
     *****************************************************************************/
    static void board_key_changeHandler(UArg a0);
    static void board_key_keyFxn(PIN_Handle keyPinHandle, PIN_Id keyPinId);
    
    
    /******************************************************************************
     Public Functions
     *****************************************************************************/
    
    /*!
     Enable interrupts for keys on PIN.
    
     Public function defined in board_key.h
     */
    uint8_t Board_Key_initialize(Board_Key_keysPressedCB_t appKeyCB)
    {
        uint8_t keyState;
    
        /* Setup KEY ISR */
    #if defined(CC13X2R1_LAUNCHXL) && !defined(NO_CC1312R1_SUPPORT)
    #ifndef TIMAC_AGAMA_FPGA
        if (ChipInfo_GetChipType() == CHIP_TYPE_CC1312)
        {
            keyButton0 = Board_PIN_BUTTON0_CC1312R1;
            keyButton1 = Board_PIN_BUTTON1_CC1312R1;
            keyPinHandle = PIN_open(&keyPinState, keyPinTable_CC1312R1);
        }
        else
    #endif
        {
            keyButton0 = Board_PIN_BUTTON0;
            keyButton1 = Board_PIN_BUTTON1;
            keyPinHandle = PIN_open(&keyPinState, keyPinTable);
        }
    #else
        keyButton0 = Board_PIN_BUTTON0;
        keyButton1 = Board_PIN_BUTTON1;
        keyPinHandle = PIN_open(&keyPinState, keyPinTable);
    #endif
        /* Get current key state */
        keyState = board_key_getValues();
    
        /* Register Callbacks */
        PIN_registerIntCb(keyPinHandle, board_key_keyFxn);
    
        /* Setup keycallback for keys */
        Timer_construct(&keyChangeClock, board_key_changeHandler,
                        (KEY_DEBOUNCE_TIMEOUT),
                        0, false, 0);
    
        /* Set the application callback */
        appKeyChangeHandler = appKeyCB;
    
        return(keyState);
    }
    
    /*!
     * @brief       Interrupt handler for a Key press
     *
     * @param       keyPinHandle - PIN Handle
     * @param       keyPinId - PIN ID
     */
    static void board_key_keyFxn(PIN_Handle keyPinHandle, PIN_Id keyPinId)
    {
        (void)keyPinHandle;
    
        if(keyPinId == keyButton0)
        {
            keysPressed |= KEY_LEFT;
        }
        else if(keyPinId == keyButton1)
        {
            keysPressed |= KEY_RIGHT;
        }
    
        if(Timer_isActive(&keyChangeClock) != true)
        {
            Timer_start(&keyChangeClock);
        }
    }
    
    /*!
     * @brief       Handler for key change
     *
     * @param       UArg a0 - ignored
     */
    static void board_key_changeHandler(UArg a0)
    {
        if(appKeyChangeHandler != NULL)
        {
            /* Notify the application */
            (*appKeyChangeHandler)(keysPressed);
    
            /* Clear keys */
            keysPressed = 0;
        }
    }
    
    /*!
     * @brief       Get the current value for all the keys
     *
     * @return      bit mapped representation of all keys
     */
    uint8_t board_key_getValues(void)
    {
        uint8_t keys = 0;
    
        if(PIN_getInputValue(keyButton0) == false)
        {
            keys |= KEY_LEFT;
        }
    
        if(PIN_getInputValue(keyButton1) == false)
        {
            keys |= KEY_RIGHT;
        }
    
        return(keys);
    }


    请参考上面的code。

  • 代码思路差不多的,我中断函数里还发送了事件解锁任务,实质上是一个事件要与两个中断同步,这里有两个疑问:
    1.两个同优先级中断,一个中断执行完毕,另一个中断继续执行,它们之间是无缝执行吗?在中断切换之间任务能不能得到执行?
    2.我第一个中断来了就能确定可以同步任务了,但另一个中断还要执行,所以会发送两次事件,如果中断切换时任务得不到执行,那么跟事件有关的任务会连续得到两个事件,这会导致异常吗?
  • 没看懂你的意思,你如果想用中断控制两个任务同步,建议用中断加上信号量去操作,或者mutex。
x 出现错误。请重试或与管理员联系。