微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > CC1310中定时器怎么用?

CC1310中定时器怎么用?

时间:12-23 整理:3721RD 点击:

向各位大神请教一下,我想实现用cc1310开启定时器定时执行某个任务,定时器相关配置设置怎么弄?又可以参考的例子吗,谢谢了!

http://www.deyisupport.com/question_answer/wireless_connectivity/f/45/t/114594.aspx

clock_CC1310_LAUNCHXL_TI_CC1310F128

TI RTOS for CC13XX and CC26XX 下的Clock例程。

Int main() { /* Construct BIOS Objects */ Clock_Params clkParams; /* Call board init functions */ Board_initGeneral(); Clock_Params_init(&clkParams); clkParams.period = 5000/Clock_tickPeriod; clkParams.startFlag = TRUE; /* Construct a periodic Clock Instance */ Clock_construct(&clk0Struct, (Clock_FuncPtr)clk0Fxn, 5000/Clock_tickPeriod, &clkParams); clkParams.period = 0; clkParams.startFlag = FALSE; /* Construct a one-shot Clock Instance */ Clock_construct(&clk1Struct, (Clock_FuncPtr)clk1Fxn, 11000/Clock_tickPeriod, &clkParams); clk2Handle = Clock_handle(&clk1Struct); Clock_start(clk2Handle); BIOS_start(); /* does not return */ return(0); }

请教一下,这里的周期事件运行两次,一次性事件运行一次是怎么设置?1)定时时间间隔,在哪设置?2)如果要一直定时执行某个任务,而非只执行两次,怎么做?谢谢了

没有研究clock

#include <stdlib.h>

#include <xdc/std.h>

#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>

#include <ti/sysbios/knl/Task.h>

#include <ti/sysbios/knl/Mailbox.h>

#include <ti/sysbios/knl/Event.h>

/* Drivers */

#include <ti/drivers/rf/RF.h>

#include <ti/drivers/PIN.h>

#include <driverlib/timer.h>

#include <ti/drivers/Power.h>

#include <ti/drivers/power/PowerCC26XX.h>

/* Board Header files */

#include "Board.h"

PIN_Handle ledPinHandle;

PIN_State ledPinState;

#define TASK_STACK_SIZE 1024

#define TASK_PRIORITY   2

Hwi_Struct timerHwi;

void waitingTaskFunction(UArg arg0, UArg arg1);

static Task_Params waitingTaskParams;

Task_Struct waitingTask;

static uint8_t waitingTaskStack[TASK_STACK_SIZE];

void interruptTimerA(UArg arg0)

{

  uint32_t status = TimerIntStatus(GPT0_BASE, true);

  PIN_setOutputValue(ledPinHandle, Board_LED3,1);

  if (TIMER_TIMA_TIMEOUT & status) {

    TimerIntClear(GPT0_BASE, TIMER_TIMA_TIMEOUT);

  }

  PIN_setOutputValue(ledPinHandle, Board_LED3,0);

}

void timerInit(void)

{

  /* Switches the peripheral power domain on */

  Power_setDependency(PowerCC26XX_PERIPH_GPT0);

  /* Prevents the controller from going to standby */

  Power_setConstraint(PowerCC26XX_SB_DISALLOW);

  // register ISR and enable hardware interrupt for timer

  Hwi_Params params;

  Hwi_Params_init(&params);

  params.enableInt = TRUE;

  Hwi_construct(&timerHwi, INT_GPT0A, &interruptTimerA, &params, NULL);

  /* Configure the timer hardware */

  TimerDisable(GPT0_BASE, TIMER_A);

  TimerConfigure(GPT0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);

  TimerPrescaleSet(GPT0_BASE, TIMER_A, 255); // prescaler is 256 - 187.5 kHz

  TimerLoadSet(GPT0_BASE, TIMER_A, 313); // a random number

  TimerIntClear(GPT0_BASE, TIMER_TIMA_TIMEOUT);

  TimerIntEnable(GPT0_BASE, TIMER_TIMA_TIMEOUT);

  TimerEnable(GPT0_BASE, TIMER_A);

}

void WaitingTask_init(void)

{

  Task_Params_init(&waitingTaskParams);

  waitingTaskParams.stackSize = TASK_STACK_SIZE;

  waitingTaskParams.priority = TASK_PRIORITY;

  waitingTaskParams.stack = &waitingTaskStack;

  Task_construct(&waitingTask, waitingTaskFunction, &waitingTaskParams, NULL);

}

void waitingTaskFunction(UArg arg0, UArg arg1)

{

  timerInit();

  for (;;) {

    Task_sleep(30 *1000 / Clock_tickPeriod);               // 30 ms wait

    PIN_setOutputValue(ledPinHandle, Board_LED2, 1);

    PIN_setOutputValue(ledPinHandle, Board_LED2, 0);

  }

}

int main(void)

{

  Board_initGeneral();

  ledPinHandle = PIN_open(&ledPinState, BoardGpioInitTable);

  if (!ledPinHandle) {

    System_abort("Error initializing board LED pins\n");

  }

  WaitingTask_init();

  BIOS_start();

  return (0);

}

亲测可用,而且更加直观

好的,多谢大侠,我看看!

有些地方不太明白什么意思,可否解释一下?

1)在for循环里面,是每隔30ms让led2亮灭一下吗?
2)timeInit()定时器初始化之后,定时器进入中断是让led3亮灭一下吗?
3)

TimerPrescaleSet(GPT0_BASE, TIMER_A, 255); // prescaler is 256 - 187.5 kHz

  TimerLoadSet(GPT0_BASE, TIMER_A, 313); // a random number

这两句的作用是什么?

4)定时器定时时间间隔怎么设置?

谢谢了

 TimerConfigure(GPT0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);

  TimerPrescaleSet(GPT0_BASE, TIMER_A, 255); // prescaler is 256 - 187.5 kHz

  TimerLoadSet(GPT0_BASE, TIMER_A, 313); // a random number

这三句决定了计时时间,分别是模式、分频、计时初值

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top