⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drv_timer.c

📁 最新版IAR FOR ARM(EWARM)5.11中的代码例子
💻 C
字号:
/************************************************************************/
/*                                                                      */
/*    Copyright (C) 2006 Oki Electric Industry Co., LTD.                */
/*                                                                      */
/*    System Name    :  uPLAT7D series                                  */
/*    Module Name    :  uPLAT7D system timer drivers program            */
/*    File   Name    :  drv_timer.c                                     */
/*    Date           :  2005/12/24 initial version                      */
/*                                                                      */
/************************************************************************/

#include "common.h"
#if defined(__arm)
#include "ml675050.h"
#else
#include "ml675050sim.h"
#endif
#include "drv_common.h"
#include "hal_api.h"
#include "drv_timer.h"
#include "intrinsics.h"


/******************************/
/*     Private defines        */
/******************************/
/*--------- variable ---------*/
static volatile uint16_t timer_counter = 0;

/*--------- function ---------*/
static void timer_callback(uint16_t state);


/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_OpenTimer                                  */
/*  Input           : cycle                                             */
/*  Output          : DRV_OK(1)                                         */
/*                  : DRV_PARAM_ERROR(-2)                               */
/*                                                                      */
/*  Note : Open the driver of system timer.                             */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_OpenTimer(uint16_t cycle) {
    int16_t rtnVal = DRV_OK;
    uPLAT_InterruptParam int_param;
    
    /* Check timer cycle. */
    if (cycle == 0) {
        return DRV_PARAM_ERROR;
    }
    
    /* Interrupt setting. */
    int_param.primary  = INT_SYSTIMER;
    int_param.level    = ILC0_ILR0 & INT_LV1;
    int_param.callback = timer_callback;
    rtnVal = uplat7dHAL_InterruptSetPrimary(&int_param);
    if (rtnVal != DRV_OK) {
        return rtnVal;
    }
    
    /* Initailize system timer HAL. */
    rtnVal = uplat7dHAL_TimerInit(cycle);
    
    /* Enable irq interrupt. */
    __enable_interrupt(); //irq_en();
    
    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_CloseTimer                                 */
/*  Input           : void                                              */
/*  Output          : DRV_OK(1)                                         */
/*                                                                      */
/*  Note : Close the driver of system timer.                            */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_CloseTimer(void) {
    int16_t rtnVal = DRV_OK;

    /* Disable irq interrupt. */
    __disable_interrupt(); //irq_dis();                              /* Disable Interrupt */

    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_IoctlTimer                                 */
/*  Input           : cmd The number of Timer HAL-API.                  */
/*                    arg The argument of Timer HAL-API.                */
/*  Output          : DRV_OK(1)                                         */
/*                  : DRV_PARAM_ERROR(-2)                               */
/*                                                                      */
/*  Note : Control the hal of system timer.                             */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_IoctlTimer(uint16_t cmd, uint32_t arg) {
    int16_t rtnVal = DRV_OK;

    switch (cmd) {
    case UPLAT7D_HAL_TIMER_SET_START:        /* Start system timer. */
        if ((arg != 1) && (arg != 0)) {
            rtnVal = DRV_PARAM_ERROR;
        }
        if (rtnVal == DRV_OK) {
            rtnVal = uplat7dHAL_TimerSetStart((uint16_t)arg);
        }
        break;
    default :
        rtnVal = DRV_PARAM_ERROR;
        break;
    }

    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_PollTimer                                  */
/*  Input           : cmd   None                                        */
/*                    count Count of waiting cycle.                     */
/*  Output          : void                                              */
/*                                                                      */
/*  Note : Delay to wait.                                               */
/*                                                                      */
/************************************************************************/
void smpDrv_PollTimer(uint16_t cmd, uint16_t count) {
    timer_counter = 0;
    while (timer_counter < count) {
        ;
    }
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : timer_callback                                    */
/*  Input           : state                                             */
/*  Output          : void                                              */
/*                                                                      */
/*  Note : Timer call back function.                                    */
/*                                                                      */
/************************************************************************/
static void timer_callback(uint16_t state) {
    timer_counter++;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -