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

📄 drv_adc.c

📁 最新版IAR FOR ARM(EWARM)5.11中的代码例子
💻 C
字号:
/**************************************************************************/
/*                                                                        */
/*     Copyright (C) 2005 Oki Electric Industry Co., LTD.                 */
/*                                                                        */
/*     System Name  :  ML675050 series                                    */
/*     Module Name  :  ML675050 iccc driver program                       */
/*     File   Name  :  drv_adc.c                                          */
/*     Revision     :  01.00                                              */
/*     Create       :  LXF 05/12/15                                       */
/*                                                                        */
/**************************************************************************/

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

/******************************/
/*     Private defines        */
/******************************/
/*--------- variable ---------*/
static volatile uint16_t adc_end;

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


/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_OpenAdc                                    */
/*  Input           : mode Scan mode or select mode.                    */
/*                    channel Channel number.                           */
/*  Output          : DRV_OK(1)                                         */
/*                  : DRV_PARAM_ERROR(-2)                               */
/*                                                                      */
/*  Note : Open the driver of adc.                                      */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_OpenAdc(uint16_t mode, uint16_t channel) {
    int16_t rtnVal = DRV_OK;
    uPLAT_InterruptParam int_param;
    
    if (mode != 0) {
        return DRV_PARAM_ERROR;
    }

    if (channel != ADCON0_ADSNM4_7) {
        return DRV_PARAM_ERROR;
    }

    /* Interrupt setting. */
    int_param.primary = INT_ADC;
    int_param.level = ILC1_ILR11 & INT_LV7;
    int_param.callback = adc_callback;
    rtnVal = uplat7dHAL_InterruptSetPrimary(&int_param);
    if (rtnVal != DRV_OK) {
        return rtnVal;
    }

    /* Initailize ADC HAL. */
    rtnVal = ml675050HAL_AdcInit(mode, channel);
    
    /* Enable irq interrupt. */
    __enable_interrupt(); //irq_en();
    
    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : smpDrv_CloseAdc                                   */
/*  Input           : void                                              */
/*  Output          : DRV_OK(1)                                         */
/*                                                                      */
/*  Note : Close the driver of adc.                                     */
/*                                                                      */
/************************************************************************/
int16_t smpDrv_CloseAdc(void) {
    int16_t rtnVal = DRV_OK;
    
    /* Disable irq interrupt. */
    __disable_interrupt(); //irq_dis();                              /* Disable Interrupt */
    
    return rtnVal;
}

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

    switch (cmd) {
    case ML675050_HAL_ADC_START:             /* Start ADC. */
        if ((arg != 0) && (arg != 1)) {
            rtnVal = DRV_PARAM_ERROR;
        }
        else {
            rtnVal = ml675050HAL_AdcStart((uint16_t)arg);
            if (rtnVal == DRV_OK) {
                while (adc_end == 0) {
                    ;
                }
                adc_end = 0;
            }
        }
        break;
    case ML675050_HAL_ADC_RX_DATA:          /* Read result of adc */
        rtnVal = ml675050HAL_AdcRxData((int8_t *)arg);
        break;
    default :
        rtnVal = DRV_PARAM_ERROR;
        break;
    }

    return rtnVal;
}

/************************************************************************/
/*                                                                      */
/*  Function Name   : adc_callback                                      */
/*  Input           : state                                             */
/*  Output          : void                                              */
/*                                                                      */
/*  Note : Adc call back function.                                      */
/*                                                                      */
/************************************************************************/
static void adc_callback(uint16_t state){
    adc_end = 1;
}

⌨️ 快捷键说明

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