📄 hal_ftm_art.c
字号:
/************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : ML675050 series */
/* Module Name : ML675050 FTM_ART HAL program */
/* File Name : hal_ftm_art.c */
/* Date : 2005/1/4 initial version */
/* */
/************************************************************************/
#include "common.h"
#if defined(__arm)
#include "ml675050.h"
#else
#include "ml675050sim.h"
#endif
#include "hal_common.h"
#include "hal_interrupt.h"
#include "hal_ftm_art.h"
/******************************/
/* Private defines */
/******************************/
/*--------- function ---------*/
static void _art0_handler(void);
static void _art1_handler(void);
static void _art3_handler(void);
static void _art4_handler(void);
static void _art5_handler(void);
/******************************/
/* Public defines */
/******************************/
FP art0_handler = _art0_handler;
FP art1_handler = _art1_handler;
FP art3_handler = _art3_handler;
FP art4_handler = _art4_handler;
FP art5_handler = _art5_handler;
/************************************************************************/
/* */
/* Function Name : HALArt_FtmArtInit */
/* Input : Art */
/* Output : int16_t HAL_OK(1) */
/* HAL_PARAM_ERROR(-2) */
/* Note : Initialize ftm_art. */
/* */
/************************************************************************/
void HALArt_FtmArtInit(Art *art)
{
OkiCLib_write16(FTM0CON,FTM0CON_ART | FTMCON_FTMCLK16); /* Ftm0 mode set. */
OkiCLib_write16(FTM0R, art->cycle0); /* Ftm0 interrupt cycle.*/
OkiCLib_set16bit(FTM0IER, FTM0IER_OVFIE); /* Ftm0 interrupt enable .*/
OkiCLib_write16(FTM1CON,FTM1CON_ART | FTMCON_FTMCLK16); /* Ftm1 mode set. */
OkiCLib_write16(FTM1R, art->cycle1); /* Ftm1 interrupt cycle.*/
OkiCLib_set16bit(FTM1IER, FTM1IER_OVFIE); /* Ftm1 interrupt enable .*/
OkiCLib_write16(FTM3CON,FTM3CON_ART | FTMCON_FTMCLK16); /* Ftm3 mode set. */
OkiCLib_write16(FTM3R, art->cycle3); /* Ftm3 interrupt cycle.*/
OkiCLib_set16bit(FTM3IER, FTM3IER_OVFIE); /* Ftm3 interrupt enable .*/
OkiCLib_write16(FTM4CON,FTM4CON_ART | FTMCON_FTMCLK16); /* Ftm4 mode set. */
OkiCLib_write16(FTM4R, art->cycle4); /* Ftm4 interrupt cycle.*/
OkiCLib_set16bit(FTM4IER, FTM4IER_OVFIE); /* Ftm4 interrupt enable .*/
OkiCLib_write16(FTM5CON,FTM5CON_ART | FTMCON_FTMCLK16); /* Ftm5 mode set. */
OkiCLib_write16(FTM5R, art->cycle5); /* Ftm5 interrupt cycle.*/
OkiCLib_set16bit(FTM5IER, FTM5IER_OVFIE); /* Ftm5 interrupt enable .*/
}
/************************************************************************/
/* */
/* Function Name : HALArt_FtmArtStart */
/* Input : start 1: start 0: stop. */
/* Output : int16_t HAL_OK(1) */
/* HAL_PARAM_ERROR(-2) */
/* Note : ftm_art start or stop. */
/* */
/************************************************************************/
void HALArt_FtmArtStart(uint16_t *start) {
boolean req_start = FALSE;
boolean req_stop = FALSE;
uint16_t ftm_en = 0x0;
uint16_t ftm_dis = 0x0;
uint16_t i;
for (i = 0; i < 6; i++) {
if (start[i] == 1) {
req_start = TRUE;
ftm_en |= (FTMEN_FTMEN0 << i);
}
else {
req_stop = TRUE;
ftm_dis |= (FTMDIS_FTMDIS0 << i);
}
}
ftm_en &=0x3B;
ftm_dis &=0x3B;
/* enable FTM. */
if (req_start == TRUE) {
OkiCLib_write16(FTMEN, ftm_en);
}
/* disable FTM. */
if (req_stop == TRUE) {
OkiCLib_write16(FTMDIS, ftm_dis);
}
}
/************************************************************************/
/* */
/* Function Name : _art_handler */
/* Input : void */
/* Output : void */
/* */
/* Note : ART handler. */
/* */
/************************************************************************/
static void _art0_handler(void)
{
OkiCLib_set16bit(FTM0ST,FTM0ST_OVF);
CALL_BACK_TABLE[INT_FTM0](CALLBACK_STATE_ART);
}
static void _art1_handler(void)
{
OkiCLib_set16bit(FTM1ST,FTM1ST_OVF);
CALL_BACK_TABLE[INT_FTM1](CALLBACK_STATE_ART);
}
static void _art3_handler(void)
{
OkiCLib_set16bit(FTM3ST,FTM3ST_OVF);
CALL_BACK_TABLE[INT_FTM3](CALLBACK_STATE_ART);
}
static void _art4_handler(void)
{
OkiCLib_set16bit(FTM4ST,FTM4ST_OVF);
CALL_BACK_TABLE[INT_FTM4](CALLBACK_STATE_ART);
}
static void _art5_handler(void)
{
OkiCLib_set16bit(FTM5ST,FTM5ST_OVF);
CALL_BACK_TABLE[INT_FTM5](CALLBACK_STATE_ART);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -