📄 app_ml675050.c
字号:
/************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ml675050 series */
/* Module Name : ml675050 application layer sample program */
/* File Name : app_ml675050.c */
/* Date : 2006/1/1 initial version */
/* */
/************************************************************************/
#include <string.h>
#include "common.h"
#if defined(__arm)
#include "ml675050.h"
#else
#include "ml675050sim.h"
#endif
#include "intrinsics.h"
#include "hal_api.h"
#include "drv_timer.h"
#include "drv_wdt.h"
#include "drv_api.h"
#include "drv_ftm_art.h"
#include "drv_ftm_cap.h"
#include "app_ml675050.h"
/************************************/
/* Static functions declaration */
/************************************/
#if defined(_WIN32)
//int16_t cmp_data_fn(uint8_t *des_data, uint8_t *src_data, uint16_t len);
int16_t cmp_i2c_data_fn(struct I2CTransForm *des_data, struct I2CTransForm *src_data, uint16_t len);
void AP_WDT_handler( uint16_t dummy );
#else
//static int16_t cmp_data_fn(uint8_t *des_data, uint8_t *src_data, uint16_t len);
static int16_t cmp_i2c_data_fn(struct I2CTransForm *des_data, struct I2CTransForm *src_data, uint16_t len);
static void AP_WDT_handler( uint16_t dummy );
#endif
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_ADC */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of adc. */
/* */
/************************************************************************/
int16_t ML675050smpAP_ADC(void) {
struct uPLAT_UartParam uart_param;
int16_t rtnVal = OK;
int16_t handle_uart,handle_adc;
struct ADCInitParam {
uint8_t mode;
uint16_t channel;
} adc_init_param;
int8_t buff[0x8 - ADCON0_ADSNM4_7][3];
uint8_t i;
smpDrvInitPeripheral init_peripheral;
/* Initialize peripheral. */
init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
init_peripheral.init_xbus.iobw = BWC_IOBW_16;
init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;
init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;
init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;
init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;
init_peripheral.init_xbus.standby = FALSE;
init_peripheral.cache_mode = CACHE_WRITE_BACK;
init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
rtnVal = smpDrv_reset(&init_peripheral);
if (rtnVal != OK) {
return rtnVal;
}
/* 3 bit LED start. */
debug_msg(_3_LED_START, "ADC sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Initailize UART. */
uart_param.baudrate = BPS_115200; /* 115200bps */
uart_param.parity = 0; /* Non parity */
uart_param.data_len = 8; /* 8bit */
uart_param.stop_bit = 1; /* 1 stop bit */
uart_param.flow_ctrl = 0; /* Non flow control */
uart_param.fifo_byte_num = 4; /* 4byte fifo number */
uart_param.fifo_mode = 1; /* fifo mode */
uart_param.dma_mode = 0; /* Non dma */
handle_uart = smpDrv_open(DRVNO_UART, (uint32_t)(&uart_param));
if (handle_uart == HANDLE_ID_1) {
/* Initialize ADC. */
adc_init_param.mode = 0;
adc_init_param.channel = ADCON0_ADSNM4_7;
handle_adc = smpDrv_open(DRVNO_ADC, (uint32_t)(&adc_init_param));
if (handle_adc == HANDLE_ID_1) {
/* ADC start. */
rtnVal = smpDrv_ioctl(DRVNO_ADC, ML675050_HAL_ADC_START, 1, handle_adc);
if (rtnVal == OK) {
/* Read result of ADC. */
for (i = 0; (i < (0x8 - ADCON0_ADSNM4_7)) && (rtnVal == OK); i++) {
rtnVal = smpDrv_ioctl(DRVNO_ADC,
ML675050_HAL_ADC_RX_DATA,
(uint32_t)buff[i], handle_adc);
}
if (rtnVal == OK) {
for (i = 0; i < 0x8 - ADCON0_ADSNM4_7; i++) {
/* Send ADC result to terminal by UART. */
smpDrv_write(DRVNO_UART,
buff[i],
(uint16_t)strlen(buff[i]), handle_adc);
}
}
} /* end of if */
} /* end of if */
/* Close ADC. */
smpDrv_close(DRVNO_ADC, handle_adc);
} /* end of if */
/* Close UART. */
smpDrv_close(DRVNO_UART, handle_uart);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "ADC sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "ADC sample application is end by NG.\n");
}
return rtnVal;
}
static int16_t write_to_vram(ML675050_VramParam *vram_param, int16_t handle) {
int16_t rtnVal = OK;
uint16_t i;
for (i = 0; i < 2; i++) {
if (i == 0) {
/* standard */
vram_param->display_mode = 0;
} else {
/* reverse */
vram_param->display_mode = 1;
if (vram_param->data == 0) {
return rtnVal;
}
} /* end of if */
rtnVal = smpDrv_ioctl(DRVNO_LCDC, ML675050_HAL_LCDC_WRITE_VRAM, (uint32_t)(vram_param), handle);
if (rtnVal != OK) {
return rtnVal;
}
else {
/* Timer start. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle);
if (rtnVal != OK) {
return rtnVal;
}
smpDrv_poll(DRVNO_TIMER, 0, 500, handle);
/* Timer stop. */
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 0, handle);
if (rtnVal != OK) {
return rtnVal;
}
} /* end of if */
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_LCDC */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of LCDC. */
/* */
/************************************************************************/
int16_t ML675050smpAP_LCDC(void) {
int16_t rtnVal = OK;
int16_t handle_timer,handle_lcdc;
struct LCDCInitParam {
uint16_t hPixels;
uint16_t vPixels;
} lcdc_init_param;
ML675050_VramParam vram_param;
int16_t i;
smpDrvInitPeripheral init_peripheral;
/* Initialize peripheral. */
init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
init_peripheral.init_xbus.iobw = BWC_IOBW_16;
init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;
init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;
init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;
init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;
init_peripheral.init_xbus.standby = FALSE;
init_peripheral.cache_mode = CACHE_WRITE_BACK;
init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
rtnVal = smpDrv_reset(&init_peripheral);
if (rtnVal != OK) {
return rtnVal;
}
/* 3 bit LED start. */
debug_msg(_3_LED_START, "LCDC sample application is start.\n");
/* 7 segment LED1 : OFF */
debug_msg(_7_LED1_OFF, NULL);
/* Initailize timer. */
handle_timer = smpDrv_open(DRVNO_TIMER, LCDC_TIME_INTERVAL);
// handle_timer = 1;
if (handle_timer == HANDLE_ID_1) {
/* Initailize LCDC. */
lcdc_init_param.hPixels = LCDC_H_PIXELS;
lcdc_init_param.vPixels = LCDC_V_PIXELS;
handle_lcdc = smpDrv_open(DRVNO_LCDC, (uint32_t)(&lcdc_init_param));
if (handle_lcdc == HANDLE_ID_1) {
/* Clear LCD. */
vram_param.data = 0;
rtnVal = write_to_vram(&vram_param, handle_lcdc);
/* Write data to LCD. */
for (i = 0; (i < 5) && (rtnVal == OK); i++) {
if (rtnVal == OK) {
/* round */
vram_param.data = 1;
rtnVal = write_to_vram(&vram_param, handle_lcdc);
}
if (rtnVal == OK) {
/* quadrangle */
vram_param.data = 2;
rtnVal = write_to_vram(&vram_param, handle_lcdc);
}
if (rtnVal == OK) {
/* triangle */
vram_param.data = 3;
rtnVal = write_to_vram(&vram_param, handle_lcdc);
}
if (rtnVal == OK) {
/* empty */
vram_param.data = 0;
rtnVal = write_to_vram(&vram_param, handle_lcdc);
}
}
} /* end of if */
/* Close LCDC. */
smpDrv_close(DRVNO_LCDC,handle_lcdc);
} /* end of if */
/* Close timer. */
smpDrv_close(DRVNO_TIMER,handle_timer);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "LCDC sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "LCDC sample application is end by NG.\n");
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_I2C */
/* Input : void */
/* Output : OK(1) */
/* : ERROR(-1) */
/* */
/* Note : Sample program of I2C. */
/* */
/************************************************************************/
struct I2CTransForm I2C_SendData[I2C_BUFF_SIZE];
struct I2CTransForm I2C_ReceivData[I2C_BUFF_SIZE];
int16_t ML675050smpAP_I2C(void)
{
int16_t rtnVal = OK;
int16_t handle_i2c;
uint8_t i;
struct ml675050_i2cParam i2c_trans_param;
smpDrvInitPeripheral init_peripheral;
/* Initialize peripheral. */
init_peripheral.init_xbus.rombw = BWC_ROMBW_16;
init_peripheral.init_xbus.srambw = BWC_SRAMBW_16;
init_peripheral.init_xbus.iobw = BWC_IOBW_16;
init_peripheral.init_xbus.romtype = ROMAC_ROMTYPE_0;
init_peripheral.init_xbus.rombrst = ROMAC_ROMBRST_off;
init_peripheral.init_xbus.sramtype = RAMAC_RAMTYPE_1;
init_peripheral.init_xbus.srambrst = RAMAC_RAMBRST_off;
init_peripheral.init_xbus.iotype = IOAC_IOTYPE_2;
init_peripheral.init_xbus.sdrambw = DBWC_DBDRAM16;
init_peripheral.init_xbus.standby = FALSE;
init_peripheral.cache_mode = CACHE_WRITE_BACK;
init_peripheral.init_port.port_sel1 = PORT_CR1_INIT_VALUE;
init_peripheral.init_port.port_sel2 = PORT_CR2_INIT_VALUE;
init_peripheral.init_port.port_sel3 = PORT_CR3_INIT_VALUE;
init_peripheral.init_port.port_sel4 = PORT_CR4_INIT_VALUE;
rtnVal = smpDrv_reset(&init_peripheral);
if (rtnVal != OK) {
return rtnVal;
}
/* 3 bit LED start. */
debug_msg(_3_LED_START, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -