drv_api.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 568 行 · 第 1/2 页
C
568 行
/**************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT7D series */
/* Module Name : uPLAT7D drivers api program */
/* File Name : drv_API.c */
/* Revision : 01.00 */
/* Date : 2006/1/1 */
/* */
/**************************************************************************/
#include "common.h"
#if defined(__arm)
#include "ml675050.h"
#else
#include "ml675050sim.h"
#endif
#include "hal_api.h"
#include "drv_interrupt.h"
#include "drv_timer.h"
#include "drv_xbus.h"
#include "drv_lcdc.h"
#include "drv_adc.h"
#include "drv_sio.h"
#include "drv_i2c.h"
#include "drv_pio.h"
#include "drv_rtc.h"
#include "drv_spi.h"
#include "drv_uart.h"
#include "drv_ftm_art.h"
#include "drv_ftm_pwm.h"
#include "drv_ftm_cap.h"
#include "drv_remap.h"
#include "drv_dmac.h"
#include "drv_wdt.h"
#include "drv_pm.h"
#include "drv_common.h"
#include "drv_api.h"
#include "drv_state.h"
/************************************************************************/
/* */
/* Function Name : smpDrv_reset */
/* Input : arg */
/* Output : int16_t DRV_OK(1) */
/* DRV_PARAM_ERROR(-2) */
/* */
/* Note : Reset all drivers. */
/* */
/************************************************************************/
int16_t smpDrv_reset(smpDrvInitPeripheral *arg) {
int16_t rtnVal = DRV_OK;
/* Set system clock = 8MHz. */
OkiCLib_set32bit(CLKCNT, CLKCNT_SYSCLKSEL);
/* Check for SRAM bus width. */
if (arg->init_xbus.srambw != BWC_SRAMBW_16) {
return DRV_PARAM_ERROR;
}
/* Check for SDRAM bus width. */
if (arg->init_xbus.sdrambw != DBWC_DBDRAM16) {
return DRV_PARAM_ERROR;
}
/* Initialize xbus. */
rtnVal = uplat7dHAL_XbusInitMem(&arg->init_xbus);
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Check for cache mode. */
if (arg->cache_mode != CACHE_WRITE_BACK) {
return DRV_PARAM_ERROR;
}
/* Initialize cache. */
rtnVal = uplat7dHAL_CacheInit(arg->cache_mode);
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Check for initalized value of port control register. */
if (arg->init_port.port_sel1 != PORT_CR1_INIT_VALUE) {
return DRV_PARAM_ERROR;
}
if (arg->init_port.port_sel2 != PORT_CR2_INIT_VALUE) {
return DRV_PARAM_ERROR;
}
if (arg->init_port.port_sel3 != PORT_CR3_INIT_VALUE) {
return DRV_PARAM_ERROR;
}
if (arg->init_port.port_sel4 != PORT_CR4_INIT_VALUE) {
return DRV_PARAM_ERROR;
}
/* Initialize port control register. */
rtnVal = uplat7dHAL_PioSetFunction(&arg->init_port);
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Initialize all interrupts. */
rtnVal = uplat7dHAL_InterruptInitAll();
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Driver STM Initialization. */
smpDrv_InitmanageStateMachine();
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : smpDrv_open */
/* Input : drv_no Device drivers number. */
/* init_data Initialized data. */
/* Output : int16_t HANDLE_ID_1 */
/* DRV_PARAM_ERROR(-2) */
/* */
/* Note : Initialize each driver. */
/* */
/************************************************************************/
int16_t smpDrv_open(uint16_t drv_no, uint32_t init_data)
{
volatile int16_t rtnVal = DRV_OK;
struct ADCInitParam {
uint16_t mode;
uint16_t channel;
} *adc_init_param;
struct LCDCInitParam {
uint16_t hPixels;
uint16_t vPixels;
} *lcdc_init_param;
rtnVal = smpDrv_manageStateMachine(drv_no, DRVEVENT_OPEN, HANDLE_ID_INIT);
if(rtnVal == DRV_OK) {
switch (drv_no) {
case DRVNO_INTFIQ:
case DRVNO_INTEXINT:
rtnVal = smpDrv_OpenInterrupt((const uPLAT_InterruptParam *)init_data);
break;
case DRVNO_TIMER:
rtnVal = smpDrv_OpenTimer((uint16_t)init_data);
break;
case DRVNO_SIO:
rtnVal = smpDrv_OpenSIO((struct uPLAT_SioParam *)init_data);
break;
case DRVNO_DMAC:
rtnVal = smpDrv_OpenDmac((uPLAT_DmacParam *)init_data);
break;
case DRVNO_PIO:
break;
case DRVNO_UART:
rtnVal = smpDrv_OpenUART((struct uPLAT_UartParam *)init_data);
break;
case DRVNO_PM:
rtnVal = smpDrv_OpenPM();
break;
case DRVNO_XBUS:
rtnVal = smpDrv_OpenXbus((uPLAT_XbusParam *)init_data);
break;
case DRVNO_REMAP:
rtnVal = smpDrv_OpenRemap((const uint8_t)init_data);
break;
case DRVNO_ICCC:
rtnVal = DRV_OK;
break;
case DRVNO_LCDC:
lcdc_init_param = (struct LCDCInitParam *)init_data;
rtnVal = smpDrv_OpenLcdc(lcdc_init_param->hPixels, lcdc_init_param->vPixels);
break;
case DRVNO_WDT:
rtnVal = smpDrv_OpenWDT((ML675050_WDTParam*)init_data);
break;
case DRVNO_ADC:
adc_init_param = (struct ADCInitParam *)init_data;
rtnVal = smpDrv_OpenAdc(adc_init_param->mode, adc_init_param->channel);
break;
case DRVNO_I2C:
rtnVal = smpDrv_OpenI2C((struct ml675050_i2cParam *)init_data);
break;
case DRVNO_RTC:
rtnVal = smpDrv_OpenRtc((ML675050_RtcInitParam *)init_data);
break;
case DRVNO_SPI:
rtnVal = smpDrv_OpenSpi((struct ML675050_SpiParam *)init_data);
break;
case DRVNO_ART:
rtnVal = smpDrv_OpenFtm_Art((Art *)init_data);
break;
case DRVNO_PWM:
rtnVal = smpDrv_OpenFtm_Pwm();
break;
case DRVNO_CAP:
rtnVal = smpDrv_OpenFtm_Cap();
break;
default :
rtnVal = DRV_PARAM_ERROR;
break;
}
}
if( rtnVal == DRV_OK) {
rtnVal = HANDLE_ID_1;
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : smpDrv_close */
/* Input : drv_no Device drivers number. */
/* Output : int16_t DRV_OK(1) */
/* DRV_PARAM_ERROR(-2) */
/* */
/* Note : Close each driver. */
/* */
/************************************************************************/
int16_t smpDrv_close(uint16_t drv_no, int16_t handle)
{
int16_t rtnVal = DRV_OK;
switch (drv_no) {
case DRVNO_INTFIQ:
case DRVNO_INTEXINT:
rtnVal = smpDrv_CloseInterrupt();
break;
case DRVNO_TIMER:
rtnVal = smpDrv_CloseTimer();
break;
case DRVNO_SIO:
rtnVal = smpDrv_CloseSIO();
break;
case DRVNO_DMAC:
rtnVal = smpDrv_CloseDmac();
break;
case DRVNO_PIO:
break;
case DRVNO_UART:
rtnVal = smpDrv_CloseUART();
break;
case DRVNO_PM:
rtnVal = smpDrv_ClosePM();
break;
case DRVNO_XBUS:
rtnVal = smpDrv_CloseXbus();
break;
case DRVNO_REMAP:
rtnVal = smpDrv_CloseRemap();
break;
case DRVNO_ICCC:
rtnVal = DRV_OK;
break;
case DRVNO_LCDC:
rtnVal = smpDrv_CloseLcdc();
break;
case DRVNO_WDT:
rtnVal = smpDrv_CloseWDT();
break;
case DRVNO_ADC:
rtnVal = smpDrv_CloseAdc();
break;
case DRVNO_I2C:
rtnVal = smpDrv_CloseI2C();
break;
case DRVNO_RTC:
rtnVal = smpDrv_CloseRtc();
break;
case DRVNO_SPI:
rtnVal = smpDrv_CloseSpi();
break;
case DRVNO_ART:
rtnVal = smpDrv_CloseFtm_Art();
break;
case DRVNO_PWM:
rtnVal = smpDrv_CloseFtm_Pwm();
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?