?? bbu_dd_timeradl.c
字號:
/*******************************************************************************
* COPYRIGHT (C) 中國普天研究院 *
********************************************************************************
* 源文件名: BBU_DD_TimerAdl.c *
* 功能描述:API Function Description for TIMER in TMS320C6414 and TMS320C6416 *
* 編寫者:louyj *
* 版本:1.0.0 *
* 編制日期:07/26/2004 www.tiengineer.com *
* 說明: *
* 修改歷史: *
* *
*******************************************************************************/
#include "BBU_DD_TimerCsl.h"
#include "BBU_DD_Post.h"
/******************************************************************************\
* TIMER Static Global Variable Definitions
\******************************************************************************/
#pragma DATA_SECTION(timerDevHandle,".gvariable");
static TIMER_Handle timerDevHandle[TIMER_DEVICE_CNT] ={TIMER_DEVICE_ENTRY(0),
TIMER_DEVICE_ENTRY(1),
TIMER_DEVICE_ENTRY(2)
};
/* Timer Device config structures for CPB POST */
#pragma DATA_SECTION(timerConfig,".gvariable");
static TIMER_Config timerConfig[TIMER_DEVICE_CNT] = {
/* CTL PRD CNT */
{0x00008200, 0x0005B8D8, 0x00000000}, /* 5ms */
{0x00008200, 0x0005B8D8, 0x00000000}, /* 5ms */
{0x00008200, 0x0005B8D8, 0x00000000}}; /* 5ms */
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* TIMER API function declarations
\******************************************************************************/
CSLAPI void TIMER_config(TIMER_Handle *hTimer, TIMER_Config *config);
CSLAPI void TIMER_getConfig(TIMER_Handle *hTimer, TIMER_Config *config);
CSLAPI void TIMER_reset(TIMER_Handle *hTimer);
CSLAPI TIMER_Handle *TIMER_open(Sint32 timerNum);
CSLAPI void TIMER_close(TIMER_Handle *hTimer);
CSLAPI TIMER_Handle *TIMER_init(Sint32 timerNum);
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* TIMER API Function Declarations
\******************************************************************************/
/*******************************************************************************
* 函數名稱: TIMER_config *
* 函數描述: Setup the TIMER Device using the configuration structure *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* hTimer TIMER_Handle* in Handle for TIMER Device *
* config TIMER_Config* in Configuration structure for TIMER *
* *
* 返回值: 無 *
* 說明: *
*******************************************************************************/
CSLAPI void TIMER_config(TIMER_Handle *hTimer, TIMER_Config *config)
{
Uint32 gie;
volatile Uint32 *base = (volatile Uint32 *)(hTimer->baseAddr);
register Uint32 x0,x1,x2;
gie = IRQ_globalDisable();
x0 = config->ctl;
x1 = config->prd;
x2 = config->cnt;
base[TIMER_CTL_OFFSET] = TIMER_CTL_DEFAULT;
base[TIMER_PRD_OFFSET] = x1;
base[TIMER_CNT_OFFSET] = x2;
base[TIMER_CTL_OFFSET] = x0;
IRQ_globalRestore(gie);
}
/*----------------------------------------------------------------------------*/
/*******************************************************************************
* 函數名稱: TIMER_getConfig *
* 函數描述: Get a TIMER Device Configuration *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* hTimer TIMER_Handle* in Handle for TIMER Device *
* config TIMER_Config* out Configuration structure for TIMER *
* *
* 返回值: 無 *
* 說明: *
*******************************************************************************/
CSLAPI void TIMER_getConfig(TIMER_Handle *hTimer, TIMER_Config *config)
{
Uint32 gie;
volatile Uint32 *base = (volatile Uint32 *)(hTimer->baseAddr);
volatile TIMER_Config *cfg = (volatile TIMER_Config*)config;
register Uint32 x0,x1,x2;
gie = IRQ_globalDisable();
x0 = base[TIMER_CTL_OFFSET];
x1 = base[TIMER_PRD_OFFSET];
x2 = base[TIMER_CNT_OFFSET];
cfg->ctl = x0;
cfg->prd = x1;
cfg->cnt = x2;
IRQ_globalRestore(gie);
}
/*----------------------------------------------------------------------------*/
/*******************************************************************************
* 函數名稱: TIMER_reset *
* 函數描述: This function resets the timer device. Disables and clears the *
* interrupt event and sets the timer registers to default values *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* hTimer TIMER_Handle* in Handle for TIMER *
* *
* 返回值: 無 *
* 說明: *
*******************************************************************************/
CSLAPI void TIMER_reset(TIMER_Handle *hTimer)
{
Uint32 gie;
gie = IRQ_globalDisable();
if (hTimer == TIMER_HINV)
{
return;
}
else
{
TIMER_RSETH(hTimer,CTL,TIMER_CTL_DEFAULT);
TIMER_RSETH(hTimer,PRD,TIMER_PRD_DEFAULT);
TIMER_RSETH(hTimer,CNT,TIMER_CNT_DEFAULT);
IRQ_reset(hTimer->eventId);
}
IRQ_globalRestore(gie);
}
/*----------------------------------------------------------------------------*/
/*******************************************************************************
* 函數名稱: TIMER_open *
* 函數描述: Before a TIMER device can be used, it must first be opened by *
* this function. *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* timerNum Sint32 in Timer Device Number *
* *
* 返回值: hTimer, pointer to TIMER Handle *
* 說明: *
*******************************************************************************/
CSLAPI TIMER_Handle *TIMER_open(Sint32 timerNum)
{
Uint32 gie;
TIMER_Handle *hTimer = TIMER_HINV;
gie = IRQ_globalDisable();
if (timerDevHandle[timerNum].allocated == FALSE)
{
hTimer = &(timerDevHandle[timerNum]);
timerDevHandle[timerNum].allocated = TRUE;
TIMER_reset(hTimer);
}
IRQ_globalRestore(gie);
return hTimer;
}
/*----------------------------------------------------------------------------*/
/*******************************************************************************
* 函數名稱: TIMER_close *
* 函數描述: This function closes a previously opened timer device. *
* The following tasks are performed: *
* The timer event is disabled and cleared *
* The timer registers are set to their default values *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* hTimer TIMER_Handle* in Handle for TIMER *
* *
* 返回值: 無 *
* 說明: *
*******************************************************************************/
CSLAPI void TIMER_close(TIMER_Handle *hTimer)
{
Uint32 gie;
gie = IRQ_globalDisable();
if (hTimer != TIMER_HINV)
{
TIMER_reset(hTimer);
hTimer->allocated = FALSE;
IRQ_disable(hTimer->eventId);
}
IRQ_globalRestore(gie);
}
/*----------------------------------------------------------------------------*/
/*******************************************************************************
* 函數名稱: TIMER_init *
* 函數描述: This function initialize the Timer device. *
* 相關文檔: *
* 參數描述: *
* 參數名 類型 輸入/輸出 描述 *
* -------- ---- --------- ----------- *
* timerNum Sint32 in TIMER Device Number *
* *
* 返回值: hTimer, pointer to TIMER Handle *
* 說明: *
*******************************************************************************/
CSLAPI TIMER_Handle *TIMER_init(Sint32 timerNum)
{
TIMER_Handle *hTimer;
hTimer = (TIMER_Handle *)TIMER_open(timerNum);
if (hTimer == TIMER_HINV)
{
return hTimer;
}
TIMER_config(hTimer,&timerConfig[timerNum]);
IRQ_enable(hTimer->eventId);
return hTimer;
}
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* End of BBU_DD_TimerAdl.c
\******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -