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

📄 drv_ftm_cap.c

📁 最新版IAR FOR ARM(EWARM)5.11中的代码例子
💻 C
字号:
/************************************************************************/
/*                                                                      */
/*    Copyright (C) 2006 Oki Electric Industry Co., LTD.                */
/*                                                                      */
/*    System Name    :  ML675050 series                                 */
/*    Module Name    :  ML675050 ftm_cap driver program                 */
/*    File   Name    :  drv_ftm_cap.c                                   */
/*    Date           :  2006/01/18 initial version                      */
/*                                                                      */
/************************************************************************/

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


#define FTM_PORT1_SEL_MASK 0xff00ffff
#define FTM_PORT1_SEL_SET  0x00550000
#define FTM_PORT4_SEL_MASK 0x3fff3fff
#define FTM_PORT4_SEL_SET  0x40004000

/******************************/
/*     Private defines        */
/******************************/
/*--------- variable ---------*/
static volatile uint8_t cap_end;

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


/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_OpenFtm_Cap                                */
/*  Input           : struct ML675050_FtmCap                            */
/*  Output          : DRV_OK(1)                                         */
/*                  : DRV_PARAM_ERROR(-2)                               */
/*                                                                      */
/*  Note : Open the driver of ftm_cap.                                  */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_OpenFtm_Cap(void) 
{
    int16_t rtnVal = DRV_OK;
    uPLAT_PioFunctionParam port_param;
    uPLAT_InterruptParam int_param;

    /* Get port function. */
    rtnVal = uplat7dHAL_PioGetFunction(&port_param);
    if (rtnVal != DRV_OK) {
        return rtnVal;
    }
    /* Set FTM port Secondary function. */
    port_param.port_sel1 = (port_param.port_sel1 & FTM_PORT1_SEL_MASK)
                           | FTM_PORT1_SEL_SET;
    port_param.port_sel4 = (port_param.port_sel4 & FTM_PORT4_SEL_MASK)
                           | FTM_PORT4_SEL_SET;
    rtnVal = uplat7dHAL_PioSetFunction(&port_param);
    if (rtnVal != DRV_OK) {
        return rtnVal;
    }

    int_param.primary = INT_FTM0_CAP;
    int_param.level = EXILCA_ILC16 & INT_LV1;
    int_param.callback = cap0_callback;
    rtnVal = uplat7dHAL_InterruptSetPrimary(&int_param);
    if (rtnVal != DRV_OK) {
        return rtnVal;
    }

    /* Initailize FTM_CAP HAL. */
    rtnVal = ml675050HAL_FtmCapInit();

    /* Enable irq interrupt. */
    __enable_interrupt(); //irq_en();

    return rtnVal;
}

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

    __disable_interrupt(); //irq_dis();                              /* Disable Interrupt */

    return rtnVal;
}
/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_IoctlFtm_Cap                               */
/*  Input           : cmd The number of CAP HAL-API.                    */
/*                    arg The argument of CAP HAL-API.                  */
/*  Output          : DRV_OK(1)                                         */
/*                  : DRV_PARAM_ERROR(-2)                               */
/*                                                                      */
/*  Note : Control the driver of ftm_cap.                               */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_IoctlFtm_Cap(uint16_t cmd, uint32_t arg) {
    int16_t rtnVal = DRV_OK;

    switch (cmd) {
    case ML675050_HAL_FTM_CAP_START:
        rtnVal = ml675050HAL_FtmCapStart((uint16_t)arg);
        break;
    case ML675050_HAL_FTM_CAP_GET:
		while (cap_end == 0) {
			;
		}
		rtnVal = ml675050HAL_FtmCapGet((ML675050_CapParam *)arg);
		break;
    default :
        rtnVal = DRV_PARAM_ERROR;
        break;
    }

    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : cap1_callback                                     */
/*  Input           : state                                             */
/*  Output          : void                                              */
/*                                                                      */
/*  Note : CAP  call back function.                                     */
/*                                                                      */
/************************************************************************/
static void cap0_callback(uint16_t state) {
	cap_end = 1;
}

⌨️ 快捷键说明

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