📄 app_ml675050.c
字号:
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, "Ftm_art sample application is start.\n");
/* Initailize FIQ . */
int_param.primary = INT_FIQ;
int_param.callback = AP_FIQ_handler;
handle_fiq = smpDrv_open(DRVNO_INTFIQ, (uint32_t)(&int_param));
if (handle_fiq == HANDLE_ID_1) {
/* Initailize ART. */
art.cycle0 = ART0CYC; /* Ftm0 interrupt cycle.*/
art.cycle1 = ART1CYC; /* Ftm1 interrupt cycle.*/
art.cycle3 = ART3CYC; /* Ftm3 interrupt cycle.*/
art.cycle4 = ART4CYC; /* Ftm4 interrupt cycle.*/
art.cycle5 = ART5CYC; /* Ftm5 interrupt cycle.*/
handle_art = smpDrv_open(DRVNO_ART, (uint32_t)(&art));
if (rtnVal== HANDLE_ID_1){
/* ART start. */
for (i = 0; i < 6; i++) {
start[i] = 1;
}
rtnVal = smpDrv_ioctl(DRVNO_ART,
ML675050_HAL_FTM_ART_START,
(uint32_t)start, handle_art);
if (rtnVal == OK) {
/* Wait for FIQ interrupt. */
AP_FIQ_Flag = 0;
while (AP_FIQ_Flag == 0) {
;
}
__disable_interrupt(); //irq_dis();
/* ART stop. */
for (i = 0; i < 6; i++) {
start[i] = 0;
}
rtnVal = smpDrv_ioctl(DRVNO_ART,
ML675050_HAL_FTM_ART_START,
(uint32_t)start, handle_art);
}
}
/* Close ART. */
smpDrv_close(DRVNO_ART, handle_art);
}
/* Close FIQ. */
smpDrv_close(DRVNO_INTFIQ, handle_fiq);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "Ftm_art sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "Ftm_art sample application is end by NG.\n");
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_FTM_PWM */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of PWM. */
/* */
/************************************************************************/
int16_t ML675050smpAP_FTM_PWM(void) {
int16_t rtnVal = OK;
int16_t handle_pwm;
uint16_t i;
uint16_t j;
uint8_t duty[500];
struct ML675050_FtmPwm pwm;
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, "Ftm_pwm sample application is start.\n");
pwm.cycle = 65536 - (10 * FTM_APB_CLK * 1000) / 16 ; /* Ftm0 interrupt cycle.*/
for(i=0; i<(CYCLE/2); i++){
duty[i] = (uint8_t)(((De-Ds)*i+Ds*(CYCLE/2-1))/(CYCLE/2-1));
}
for(i=(CYCLE/2); i<CYCLE; i++){
duty[i] = duty[CYCLE-i];
}
handle_pwm = smpDrv_open(DRVNO_PWM, FTM0CON_PWM);
if (handle_pwm== HANDLE_ID_1){
for(j=0;j<5;j++){
for(i=0; i<500; i++){
pwm.value = (uint16_t)(((65536-pwm.cycle)*(duty[i])+pwm.cycle*100)/100);
rtnVal = smpDrv_ioctl(DRVNO_PWM, ML675050_HAL_FTM_PWM_SET,(uint32_t)(&pwm), handle_pwm);
if (rtnVal== OK){
rtnVal = smpDrv_ioctl(DRVNO_PWM, ML675050_HAL_FTM_PWM_START,1, handle_pwm);
if (rtnVal== OK){
smpDrv_poll(DRVNO_PWM, 0, 1, handle_pwm);
rtnVal = smpDrv_ioctl(DRVNO_PWM, ML675050_HAL_FTM_PWM_START,0, handle_pwm);
}
}
}
}
}
smpDrv_close(DRVNO_PWM, handle_pwm) ;
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "Ftm_pwm sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "Ftm_pwm sample application is end by NG.\n");
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_FTM_CAP */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of CAP. */
/* */
/************************************************************************/
uint16_t pw_value_time;
int16_t ML675050smpAP_FTM_CAP(void) {
int16_t rtnVal = OK;
int16_t handle_cap;
smpDrvInitPeripheral init_peripheral;
ML675050_CapParam cap_param;
uint16_t pulse_start = 0;
uint16_t pulse_end = 0;
uint16_t pw_value = 0;
/* 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, "Ftm_art sample application is start.\n");
handle_cap = smpDrv_open(DRVNO_CAP, CAPCYC);
if (handle_cap== HANDLE_ID_1){
/* CAP start. */
rtnVal = smpDrv_ioctl(DRVNO_CAP, ML675050_HAL_FTM_CAP_START,1, handle_cap);
if (rtnVal == OK) {
rtnVal = smpDrv_ioctl(DRVNO_CAP, ML675050_HAL_FTM_CAP_GET,(uint32_t)(&cap_param), handle_cap);
pulse_start = cap_param.start_time ;
pulse_end = cap_param.end_time ;
}
rtnVal = smpDrv_ioctl(DRVNO_CAP, ML675050_HAL_FTM_CAP_START,0, handle_cap);
}
smpDrv_close(DRVNO_CAP, handle_cap);
if (rtnVal == OK) {
debug_msg(_3_LED_OK, "Ftm_pwm sample application is end by OK.\n");
}
else {
debug_msg(_3_LED_NG, "Ftm_pwm sample application is end by NG.\n");
}
if (rtnVal == OK) {
pw_value = pulse_end - pulse_start ;
pw_value_time = 10 * pw_value / (65536 - VALUE_OF_FTMnR) ;
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : ML675050smpAP_WDT */
/* Input : void */
/* Output : int16_t OK(1) */
/* ERROR(-1) */
/* */
/* Note : Sample program of WDT. */
/* */
/************************************************************************/
volatile int16_t wdt_overflow_flag;
int16_t ML675050smpAP_WDT(void)
{
int16_t rtnVal = OK;
int16_t handle_wdt = HANDLE_ID_INIT;
int16_t handle_timer = HANDLE_ID_INIT;
int16_t cnt;
ML675050_WDTParam wdt_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;
}
debug_msg(_3_LED_START, NULL); /* 3 bit LED start. */
debug_msg(_7_LED1_OFF, NULL); /* 7 segment LED : ALL OFF */
wdt_param.mode = WDT_OVF_INT_MODE; /* Setting interrupt mode(WDT Overflow). */
wdt_param.callback = AP_WDT_handler; /* Setting interrupt function(WDT Overflow). */
handle_wdt = smpDrv_open(DRVNO_WDT, (uint32_t)(&wdt_param)); /* WDT Open */
if (handle_wdt == HANDLE_ID_1) {
handle_timer = smpDrv_open(DRVNO_TIMER, TIME_INTERVAL_10MS); /* Timer Open */
}
if (handle_wdt == OK) {
ml675050HAL_WDTStart(); /* WDT Start<<Macro>> */
}
wdt_overflow_flag = 0; /* Clear wdt overflow flag */
for(cnt=0; (cnt<100)&&(rtnVal==OK)&&(wdt_overflow_flag == 0); cnt++){
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle_timer); /* Timer start */
if (rtnVal == OK) {
smpDrv_poll(DRVNO_TIMER, 0, 3, handle_timer);
}
if (rtnVal == OK) {
rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 0, handle_timer); /* Timer stop */
}
if (rtnVal == OK) {
ml675050HAL_WDTclear(); /* WDT Clear<<Macro>> */
}
}
if(rtnVal == OK){
if(cnt < 100){
debug_msg(_7_LED1_L0|_7_LED1_L3|_7_LED1_L4|_7_LED1_L5|_7_LED1_L6, NULL); /* 7 segment LED : "E" */
rtnVal = ERROR;
}else{
while(wdt_overflow_flag == 0){ /* Wait WDT over flow */
;
}
debug_msg(_7_LED1_L0|_7_LED1_L1|_7_LED1_L2|_7_LED1_L3|_7_LED1_L4|_7_LED1_L5, NULL); /* 7 segment LED : "O" */
}
}
smpDrv_close(DRVNO_TIMER, handle_timer); /* Timer Close */
smpDrv_close(DRVNO_WDT, handle_wdt); /* WDT Close */
/* Execution result */
if(rtnVal == OK){
debug_msg(_3_LED_OK, NULL); /* 3 bit LED : OK */
}else{
debug_msg(_3_LED_NG, NULL); /* 3 bit LED : NG */
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : void AP_WDT_handler( void ) */
/* Input : dummy(Unused) */
/* Output : Noting */
/* */
/* Note : AP WDT handler. */
/* */
/************************************************************************/
#if defined(_WIN32)
void AP_WDT_handler( uint16_t dummy )
#else
static void AP_WDT_handler( uint16_t dummy )
#endif
{
wdt_overflow_flag = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -