📄 hal_timer.c
字号:
/************************************************************************/
/* */
/* Copyright (C) 2006 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT7D series */
/* Module Name : uPLAT7D system timer HAL program */
/* File Name : hal_timer.c */
/* Date : 2005/12/14 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_timer.h"
#define TIMER_CGBGR 8 /* clock gear */
/******************************/
/* Private defines */
/******************************/
/*--------- variable ---------*/
/*--------- function ---------*/
static void _timer_handler(void); /* The handler of system timer. */
/******************************/
/* Public defines */
/******************************/
FP timer_handler = _timer_handler;
/************************************************************************/
/* */
/* Function Name : HALTimer_Init */
/* Input : cycle Timer cycle. */
/* Output : int16_t HAL_OK(1) */
/* HAL_PARAM_ERROR(-2) */
/* */
/* Note : Initialize system timer. */
/* */
/************************************************************************/
int16_t HALTimer_Init(uint16_t cycle)
{
int16_t rtnVal = HAL_OK;
uint32_t reloadVal;
uint32_t temp;
OkiCLib_write32(TMEN, TMEN_TCEN >> 1); /* System timer stop. */
OkiCLib_write32(TMOVF, TMOVF_OVF); /* Clear overflow. */
temp = (uint32_t)(cycle * (SYSCLK / TIMER_CGBGR) * 1000 / 16);
if (65536 <= temp) {
return HAL_PARAM_ERROR;
}
reloadVal = 65536 - temp;
OkiCLib_write32(TMRLR, reloadVal); /* Set timer reload value. */
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : HALTimer_SetStart */
/* Input : start 1: start 0: stop */
/* Output : void */
/* */
/* Note : Start or stop system timer. */
/* */
/************************************************************************/
void HALTimer_SetStart(uint16_t start) {
if (start == 1) {
OkiCLib_write32(TMEN, TMEN_TCEN); /* System timer start. */
}
else {
OkiCLib_write32(TMEN, TMEN_TCEN >> 1); /* System timer stop. */
}
}
/************************************************************************/
/* */
/* Function Name : _timer_handler */
/* Input : void */
/* Output : void */
/* */
/* Note : System timer handler. */
/* */
/************************************************************************/
static void _timer_handler(void)
{
OkiCLib_write32(TMOVF, TMOVF_OVF);
CALL_BACK_TABLE[INT_SYSTIMER](CALLBACK_STATE_NON);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -