您好,参考例程,请问hTimer = GPTimerCC26XX_open(CC2650_GPTIMER0A, ¶ms)中,CC2650_GPTIMER0A是什么?取值范围为0-7吗?我填了一个7,提示Error[Li005]: no definition for "GPTimerCC26XX_config" [referenced from GPTimerCC26XX.orm3(drivers_cc26x0r2.arm3)]
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.
/*!
* @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
*/
通过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(¶ms0A);
params0A.width = GPT_CONFIG_16BIT;
params0A.mode = GPT_MODE_EDGE_COUNT_UP;
params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimer0A = GPTimerCC26XX_open(CC2640R2_LAUNCHXL_GPTIMER0A, ¶ms0A);
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);
}
}
把原来的代码改成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(¶ms0A);
params0A.width = GPT_CONFIG_16BIT;
params0A.mode = GPT_MODE_EDGE_TIME;
params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimer0A = GPTimerCC26XX_open(CC2640R2_LAUNCHXL_GPTIMER0A, ¶ms0A);
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();
}
}
}