CC3200开发模块的笔记—定时器中断(timer)

CC3200开发模块的笔记—定时器中断

作者:Tiger
在2017年圣诞节时,TI公司搞活动时我弄了一块CC3200的开发板,一起弄弄这个开发模块
产品名称:WIFI实训开发套件
产品名称:OURS-SDK-WFB
首先从官网上搞到了代码和开发环境。

代码块

// Standard include
#include 

// Driverlib includes
#include "hw_types.h"
#include "interrupt.h"
#include "hw_ints.h"
#include "hw_apps_rcm.h"
#include "hw_common_reg.h"
#include "prcm.h"
#include "rom.h"
#include "rom_map.h"
#include "hw_memmap.h"
#include "timer.h"
#include "utils.h"

// Common interface includes
#include "timer_if.h"
#include "gpio_if.h"

#include "pinmux.h"


//*****************************************************************************
//                      MACRO DEFINITIONS
//*****************************************************************************
#define APPLICATION_VERSION        "1.1.1"
#define FOREVER                    1

//*****************************************************************************
//                      Global Variables for Vector Table
//*****************************************************************************
#if defined(ccs)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif

//*****************************************************************************
//
// Globals used by the timer interrupt handler.
//定时器中断处理程序使用的全局变量。
//
//*****************************************************************************
static volatile unsigned long g_ulSysTickValue;
static volatile unsigned long g_ulBase;
static volatile unsigned long g_ulRefBase;
static volatile unsigned long g_ulRefTimerInts = 0;
static volatile unsigned long g_ulIntClearVector;
unsigned long g_ulTimerInts;

//*****************************************************************************
//
//! The interrupt handler for the first timer interrupt.
//!第一个定时器中断的中断处理程序。
//! \param  None
//!
//! \return none
//
//*****************************************************************************
void
TimerBaseIntHandler(void)
{
    //
    // Clear the timer interrupt.
    //
    Timer_IF_InterruptClear(g_ulBase);

    g_ulTimerInts ++;
    GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
}

//*****************************************************************************
//
//! The interrupt handler for the second timer interrupt.
//第二个定时器中断的中断处理程序。
//!
//! \param  None
//!
//! \return none
//
//*****************************************************************************
void
TimerRefIntHandler(void)
{
    //
    // Clear the timer interrupt.
    //
    Timer_IF_InterruptClear(g_ulRefBase);

    g_ulRefTimerInts ++;
    GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
}

//*****************************************************************************
//
//! Board Initialization & Configuration
//!电路板初始化和配置
//! \param  None
//!
//! \return None
//
//*****************************************************************************
static void
BoardInit(void)
{
/* In case of TI-RTOS vector table is initialize by OS itself */
#ifndef USE_TIRTOS
  //
  // Set vector table base
  //
#if defined(ccs)
    MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
#endif
#if defined(ewarm)
    MAP_IntVTableBaseSet((unsigned long)&__vector_table);
#endif
#endif
    //
    // Enable Processor
    //
    MAP_IntMasterEnable();
    MAP_IntEnable(FAULT_SYSTICK);

    PRCMCC3200MCUInit();
}

//*****************************************************************************
//
//!    main function demonstrates the use of the timers to generate
//main函数演示了使用定时器生成
//! periodic interrupts.
//!周期性中断
//! \param  None
//!
//! \return none
//
//*****************************************************************************
int
main(void)
{
    //
    // Initialize board configurations
    BoardInit();
    //
    // Pinmuxing for LEDs
    //
    PinMuxConfig();
    //
    // configure the LED RED and GREEN
    //GPIO_IF_LedConfigure(LED1|LED3);//2018-8-28,删除
    //2018-8-28,修改
    GPIO_IF_LedConfigure(LED1|LED3|LED2);

    GPIO_IF_LedOff(MCU_RED_LED_GPIO);//2018-8-28,类似于初始化LED灯
    GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); //2018-8-28,类似于初始化LED灯
    GPIO_IF_LedOn(MCU_BLUE_LED_GPIO); //2018-8-28,类似于初始化LED灯

    //
    // Base address for first timer
    //
    g_ulBase = TIMERA0_BASE;
    //
    // Base address for second timer
    //
    g_ulRefBase = TIMERA1_BASE;
    //
    // Configuring the timers
    //
    Timer_IF_Init(PRCM_TIMERA0, g_ulBase, TIMER_CFG_PERIODIC, TIMER_A, 0);
    //初始化定时器A0,地址为g_ulBase,全宽周期定时器,定时器
    Timer_IF_Init(PRCM_TIMERA1, g_ulRefBase, TIMER_CFG_PERIODIC, TIMER_A, 0);

    //
    // Setup the interrupts for the timer timeouts.
    //  设置定时器超时的中断。
    Timer_IF_IntSetup(g_ulBase, TIMER_A, TimerBaseIntHandler);//2018-8-28,笔记,当计数器值为g_ulBase时,定时器A组,执行TimerBaseIntHandler函数中的内容
    Timer_IF_IntSetup(g_ulRefBase, TIMER_A, TimerRefIntHandler);

    //
    // Turn on the timers feeding values in mSec
    //
    Timer_IF_Start(g_ulBase, TIMER_A, 500);
    Timer_IF_Start(g_ulRefBase, TIMER_A, 1000);

    //
    // Loop forever while the timers run.
    //
    while(FOREVER)//2018-8-28,宏定义,即1
    {
    }
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

你可能感兴趣的:(CC3200)