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.

CC2640R2F GPTimer的使用

Other Parts Discussed in Thread: CC2650, CC2640R2F

您好,参考例程,请问hTimer = GPTimerCC26XX_open(CC2650_GPTIMER0A, &params)中,CC2650_GPTIMER0A是什么?取值范围为0-7吗?我填了一个7,提示Error[Li005]: no definition for "GPTimerCC26XX_config" [referenced from GPTimerCC26XX.orm3(drivers_cc26x0r2.arm3)]

  • /*!
     *  @brief  GPTimer26XX Hardware attributes
     *
     *  These fields are used by the driver to set up underlying GPTimer
     *  driver statically. A sample structure is shown below:
     *
     *  @code
     *  // GPTimer hardware attributes, one per timer unit (Timer 0A, 0B, 1A, 1B..)
     *  const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC2650_GPTIMERPARTSCOUNT] = {
     *    {.baseAddr = GPT0_BASE, .intNum = INT_TIMER0A, .powerMngrId = PERIPH_GPT0, .pinMux = GPT_PIN_0A, },
     *    {.baseAddr = GPT0_BASE, .intNum = INT_TIMER0B, .powerMngrId = PERIPH_GPT0, .pinMux = GPT_PIN_0B, },
     *    {.baseAddr = GPT1_BASE, .intNum = INT_TIMER1A, .powerMngrId = PERIPH_GPT1, .pinMux = GPT_PIN_1A, },
     *    {.baseAddr = GPT1_BASE, .intNum = INT_TIMER1B, .powerMngrId = PERIPH_GPT1, .pinMux = GPT_PIN_1B, },
     *    {.baseAddr = GPT2_BASE, .intNum = INT_TIMER2A, .powerMngrId = PERIPH_GPT2, .pinMux = GPT_PIN_2A, },
     *    {.baseAddr = GPT2_BASE, .intNum = INT_TIMER2B, .powerMngrId = PERIPH_GPT2, .pinMux = GPT_PIN_2B, },
     *    {.baseAddr = GPT3_BASE, .intNum = INT_TIMER3A, .powerMngrId = PERIPH_GPT3, .pinMux = GPT_PIN_3A, },
     *    {.baseAddr = GPT3_BASE, .intNum = INT_TIMER3B, .powerMngrId = PERIPH_GPT3, .pinMux = GPT_PIN_3B, },
     *  };
     *  @endcode
     */

  • 那我第一个参数应该传入什么呢?按例程传入CC2650_GPTIMER0A,会报错
  • CC2640R2F上使用应该是CC2640R2_LAUNCHXL_GPTIMER0A
  • CC2640R2_LAUNCHXL_GPTIMER0A提示我未定义,请问这个是包含在哪个头文件?
  • CC2640R2_LAUNCHXL.h,timer的使用建议参考PWMLED2这个例程
  • 使用边沿计时器的话要参考哪个例程呢?
  • 我添加了CC2640R2_LAUNCHXL.h,提示我no definition for "GPTimerCC26XX_config" [referenced from GPTimerCC26XX.orm3(drivers_cc26x0r2.arm3)],GPTimerCC26XX_config是在哪个文件里定义的?
  • GPTimerCC26XX.h
  • 我要是想使用IOID27与timer0的引脚联系起来,要怎么配置呢?
  • 通过PINCC26XX_setMux();函数

    这是我之前一个下降沿检测的例子,供参考:

    /***** Includes *****/
    /* Standard C Libraries */
    #include <stdlib.h>
    #include <stdio.h>
    
    /* RTOS header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    /* TI Drivers */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    /* Driverlib Header files */
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /* Board Header files */
    #include "Board.h"
    
    /***** Variable declarations *****/
    /* Pin driver handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;
    
    PIN_Config pinTable[] =
    {
        IOID_0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE  ,
        PIN_TERMINATE
    };
    
    GPTimerCC26XX_Handle hTimer0A;
    //static uint8_t counter = 0;
    
    void timerCallback0A(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        printf("!\n");
    }
    
    /***** Function definitions *****/
    
    void *mainThread(void *arg0)
    {
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, pinTable);
        if (ledPinHandle == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_Params params0A;
        GPTimerCC26XX_Params_init(&params0A);
        params0A.width          = GPT_CONFIG_16BIT;
        params0A.mode           = GPT_MODE_EDGE_COUNT_UP;
        params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimer0A = GPTimerCC26XX_open(CC2640R2_LAUNCHXL_GPTIMER0A, &params0A);
        if(hTimer0A == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_registerInterrupt(hTimer0A, timerCallback0A, GPT_INT_CAPTURE_MATCH);
    
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer0A);
        PINCC26XX_setMux(ledPinHandle, IOID_0, pinMux);
    
        GPTimerCC26XX_setCaptureEdge(hTimer0A, GPTimerCC26XX_NEG_EDGE);
        GPTimerCC26XX_setLoadValue(hTimer0A, 0xFFFFFF);
        GPTimerCC26XX_setMatchValue(hTimer0A, 1);
        GPTimerCC26XX_start(hTimer0A);
    
        while(1)
        {
            Task_sleep(BIOS_WAIT_FOREVER);
        }
    }
    

  • 您好,我参考您的代码进行配置,GPT使用是计时器输入捕获计时模式,上升沿输入捕获。如果我要读取时间的话是调用GPTimerCC26XX_getValue来获取时间对吧?

  • 把原来的代码改成input edge timing模式,并读取相应的寄存器值。改动很少,如下:

    /***** Includes *****/
    /* Standard C Libraries */
    #include <stdlib.h>
    #include <stdio.h>
    
    /* RTOS header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    /* TI Drivers */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    /* Driverlib Header files */
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /* Board Header files */
    #include "Board.h"
    
    /***** Variable declarations *****/
    /* Pin driver handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;
    
    PIN_Config pinTable[] =
    {
        IOID_0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE  ,
        PIN_TERMINATE
    };
    
    GPTimerCC26XX_Handle hTimer0A;
    //static uint8_t counter = 0;
    
    void timerCallback0A(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        int i;
        i = GPTimerCC26XX_getValue(hTimer0A);
        printf("%d\n",i);
    }
    
    /***** Function definitions *****/
    
    void *mainThread2(void *arg0)
    {
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, pinTable);
        if (ledPinHandle == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_Params params0A;
        GPTimerCC26XX_Params_init(&params0A);
        params0A.width          = GPT_CONFIG_16BIT;
        params0A.mode           = GPT_MODE_EDGE_TIME;
        params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimer0A = GPTimerCC26XX_open(CC2640R2_LAUNCHXL_GPTIMER0A, &params0A);
        if(hTimer0A == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_registerInterrupt(hTimer0A, timerCallback0A, GPT_INT_CAPTURE);
    
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer0A);
        PINCC26XX_setMux(ledPinHandle, IOID_0, pinMux);
    
        GPTimerCC26XX_setCaptureEdge(hTimer0A, GPTimerCC26XX_NEG_EDGE);
        GPTimerCC26XX_setLoadValue(hTimer0A, 0xFFFF);
       // GPTimerCC26XX_setMatchValue(hTimer0A, 1);
        GPTimerCC26XX_start(hTimer0A);
    
        while(1)
        {
            Task_sleep(BIOS_WAIT_FOREVER);
        }
    }
    

    还写了个裸机版的,供参考

    #include <stdio.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/PWM.h>
    #include <C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\source\ti\devices\cc26x0r2\inc\hw_gpt.h>
    #include <C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\source\ti\devices\cc26x0r2\inc\hw_memmap.h>
    #include <C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\source\ti\drivers\pin\PINCC26XX.h>
    #include <C:\ti\simplelink_cc2640r2_sdk_4_30_00_08\source\ti\drivers\power\PowerCC26XX.h>
    
    static PIN_Handle Pinhandle;
    static PIN_State Pinstate;
    
    PIN_Config Pintable[] = {
        IOID_0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES   ,
        PIN_TERMINATE
    };
    
    void *mainThread3(void *arg0)
    {
        unsigned int value;
        int j;
    
        Pinhandle = PIN_open(&Pinstate, Pintable);
            if (Pinhandle == NULL)
            {
                while (1);
            }
    
        PINCC26XX_setMux(Pinhandle,IOID_0, IOC_PORT_MCU_PORT_EVENT0);
    
        // Turn on PERIPH power domain and clock for GPT0
        Power_setDependency(PowerCC26XX_PERIPH_GPT0);
        //disable timer0A——CTL.TAEN
        *(volatile unsigned int *)0x4001000C = 0x0000;
        //setting the timer0 CFG register to act as a 16-bit timer
        *(volatile unsigned int *)0x40010000 = 0x0004;
        //Setting the TAMR register: TACM=1,TAMR=3
        *(volatile unsigned int *)0x40010004 = 0x0007;
        //Setting CFG register:TAEVENT 0-positive edge;1-negative edge;3-both edge
        *(volatile unsigned int *)0x4001000C = 0x0000;
        //Setting the load value-TAILR
        *(volatile unsigned int *)0x40010028 = 0xFFFF;
        //Setting the interrupt register-IMR.CAEMIS
        //*(volatile unsigned int *)0x40010018 = 0x0004;
        //Enable timer0A——CTL.TAEN
        *(volatile unsigned int *)0x4001000C = 0x0001;
        while(1)
        {
            //poll the MIS.CAECINT bit
            value = *(volatile unsigned int *)0x4001001C & 0x0004;
                if (value)
                {
                    j = *(volatile unsigned int *)0x40010048;
                    //clear the CTL.ICLR CAECINT flag
                    *(volatile unsigned int *)0x40010024 = 0x0004;
                    //read the TAR value
                    printf("%d\n", j);
                }
    
        }
    
    }
    

  • 您好,我目前无法进入GPTimerClose()函数。在实际测试中,GPTimerFlag=5的时候,程序并不会执行GPTimerClose();请问是哪里的问题?

    uint8_t GPTimerFlag = 0;

    void timerCallback0A(GPTimerCC26XX_Handle handle,GPTimerCC26XX_IntMask interruptMask)

    {

       GPTimerFlag = 5;//标志位,用于关闭GPTimer定时器

    }

    修改simple_Peripheral.c

    static void SimplePeripheral_taskFxn(UArg a0,UArg a1)

    {

    .....

    events = (Event_pend(syncEvent,Event_Id_NONE,SBP_ALL_EVENTS,ICALL_TIMEOUT_FOREVER) |  GPTimerFlag);

    if(events){

    .....

    if(events & GPTimerFlag){

    GPTimerClose();

    }

    }

    }

  • 单步调试过没有?卡在哪一步?
  • if(events&GPTimerFlag){
    GPTimerClose();
    }
    卡在这一句,if判断为0
  • 凭上述信息难以判断。建议先调试GPTimer部分,如果没问题,再跟BLE功能组合调试。涉及到整个项目,很多时候是程序内部调度的问题,而不是功能模块的问题,不现场调难以定位
  • 好的,另外就是您有event_post使用的参考例程吗?