📄 timers.c
字号:
/*=============================================================================
=
= Name: QVGA Display and Timer Verification and Example Code
=
===============================================================================
=
= (C) Copyright 2006 - Analog Devices, Inc. All rights reserved.
=
= File Name : timers.c
=
= Date : 12/21/06
=
= Target : ADSP-BF537
=
= Version : 1.0
=
= Purpose : Test the display with a bitmap
=
=
=
==============================================================================*/
#include <services/services.h>
#include <services/tmr/adi_tmr.h>
#include "debug.h"
#include "timers.h"
#define DCLKS_PER_FRAME (FREQ_PPI_CLK/FRAMES_PER_SEC) // 6*1000*1000/60=100000
#define DCLKS_PER_LINE (DCLKS_PER_FRAME/(320+START_LINES+U_LINES)) // 303/329=
// LCD Timers
#define BF537_EZKIT_TMR_LP_LCD ADI_TMR_GP_TIMER_6
#define BF537_EZKIT_TMR_SPS_LCD ADI_TMR_GP_TIMER_1
#define BF537_EZKIT_TMR_PS_LCD ADI_TMR_GP_TIMER_7
#define BF537_EZKIT_TMR_REV_LCD ADI_TMR_GP_TIMER_5
#define BF537_EZKIT_TMR_SP_LCD ADI_TMR_GP_TIMER_0
#define BF537_EZKIT_NUM_TIMERS_FOR_LCD 5
#define BF537_EZKIT_TMR_HSYNC BF537_EZKIT_TMR_SP_LCD
#define BF537_EZKIT_TMR_VSYNC BF537_EZKIT_TMR_SPS_LCD
// Macro for readibility
#define CHECK(X) ret = X; \
if (ret != ADI_TMR_RESULT_SUCCESS) \
BF537_EZKIT_Throw ("adi_tmr_GPControl error\n");
void InitTimers (void)
{
// Initialize the timer services
int ret = adi_tmr_Init (NULL);
if (ret != 0)
BF537_EZKIT_Throw ("adi_tmr_Init error\n");
ret = adi_ports_Init (NULL);
if (ret != 0)
BF537_EZKIT_Throw ("adi_ports_Init error\n");
}
void OpenTimersForLCD (void)
{
/* int ret;
*
* static ADI_TMR_GP_CMD_VALUE_PAIR GPTableTimerCommonCommands[] =
* {
* { ADI_TMR_GP_CMD_SET_TIMER_MODE, (void*) PWM_OUT },
* { ADI_TMR_GP_CMD_SET_COUNT_METHOD, (void*) TRUE }, // Count to end of period. Required by PWM_OUT
* { ADI_TMR_GP_CMD_SET_INTERRUPT_ENABLE, (void*) FALSE }, // No timer interrupts
* { ADI_TMR_GP_CMD_SET_INPUT_SELECT, (void*) TRUE }, // UART_RX or PPI_CLK (PPI_CLK)
* { ADI_TMR_GP_CMD_SET_OUTPUT_PAD_DISABLE, (void*) FALSE }, // Enable the pin of TimerID
* { ADI_TMR_GP_CMD_SET_CLOCK_SELECT, (void*) TRUE }, // Use PWM clock (PPI_CLK)
* { ADI_TMR_GP_CMD_SET_TOGGLE_HI, (void*) FALSE }, // Do not toggle active high
* { ADI_TMR_GP_CMD_RUN_DURING_EMULATION, (void*) FALSE }, // Keep running during emulator interrupts
* { ADI_TMR_GP_CMD_END, NULL }
* };
*
* // Open and set the configuration values for each timer
* // Only for coherence with the device drivers model. See StartTimersForLCD for actual initialization
* adi_tmr_Open (BF537_EZKIT_TMR_VSYNC); // SPS timer 1
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_VSYNC, ADI_TMR_GP_CMD_TABLE, GPTableTimerCommonCommands) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_VSYNC, ADI_TMR_GP_CMD_SET_PULSE_HI, (void*) TRUE) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_VSYNC, ADI_TMR_GP_CMD_SET_PERIOD, (void*) (DCLKS_PER_LINE*(320+START_LINES+U_LINES))) ); // 1 frame
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_VSYNC, ADI_TMR_GP_CMD_SET_WIDTH, (void*) (27)) ); // 1 frame - (7 lines - 4 PPI_CLK + 1 PPI_CLK)
*
* adi_tmr_Open (BF537_EZKIT_TMR_PS_LCD); // PS & CLS timer 7
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_PS_LCD, ADI_TMR_GP_CMD_TABLE, GPTableTimerCommonCommands) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_PS_LCD, ADI_TMR_GP_CMD_SET_PULSE_HI, (void*) TRUE) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_PS_LCD, ADI_TMR_GP_CMD_SET_PERIOD, (void*) (DCLKS_PER_LINE)) ); // 1 line
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_PS_LCD, ADI_TMR_GP_CMD_SET_WIDTH, (void*) (25)) ); // 1 line - ((21+PPI_X) + 4)
*
* adi_tmr_Open (BF537_EZKIT_TMR_REV_LCD); // REV timer 5
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_REV_LCD, ADI_TMR_GP_CMD_TABLE, GPTableTimerCommonCommands) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_REV_LCD, ADI_TMR_GP_CMD_SET_PULSE_HI, (void*) TRUE) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_REV_LCD, ADI_TMR_GP_CMD_SET_PERIOD, (void*) (DCLKS_PER_LINE*2)) ); // 2 lines
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_REV_LCD, ADI_TMR_GP_CMD_SET_WIDTH, (void*) (DCLKS_PER_LINE)) ); // 1 line
*
* adi_tmr_Open (BF537_EZKIT_TMR_LP_LCD); // LP timer 6
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_LP_LCD, ADI_TMR_GP_CMD_TABLE, GPTableTimerCommonCommands) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_LP_LCD, ADI_TMR_GP_CMD_SET_PULSE_HI, (void*) TRUE) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_LP_LCD, ADI_TMR_GP_CMD_SET_PERIOD, (void*) (DCLKS_PER_LINE)) ); // 1 line
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_LP_LCD, ADI_TMR_GP_CMD_SET_WIDTH, (void*) (1)) ); // 1 PPI_CLK
*
* adi_tmr_Open (BF537_EZKIT_TMR_HSYNC); // SP timer 0
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_HSYNC, ADI_TMR_GP_CMD_TABLE, GPTableTimerCommonCommands) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_HSYNC, ADI_TMR_GP_CMD_SET_PULSE_HI, (void*) TRUE) );
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_HSYNC, ADI_TMR_GP_CMD_SET_PERIOD, (void*) (DCLKS_PER_LINE)) ); // 1 line
* CHECK( adi_tmr_GPControl (BF537_EZKIT_TMR_HSYNC, ADI_TMR_GP_CMD_SET_WIDTH, (void*) (1)) ); // 1 line - 1 PPI_CLK
*/
}
void StartTimersForLCD (void)
{
u32 timer_ports_config[BF537_EZKIT_NUM_TIMERS_FOR_LCD] = { ADI_PORTS_DIR_TMR_6, ADI_PORTS_DIR_TMR_1, ADI_PORTS_DIR_TMR_7, ADI_PORTS_DIR_TMR_5, ADI_PORTS_DIR_TMR_0 };
int ret;
adi_ports_EnableTimer (timer_ports_config, BF537_EZKIT_NUM_TIMERS_FOR_LCD, TRUE);
*pTIMER1_CONFIG = PWM_OUT | PERIOD_CNT | TIN_SEL | CLK_SEL | PULSE_HI | EMU_RUN;
*pTIMER1_PERIOD = DCLKS_PER_LINE*(320+START_LINES+U_LINES);
*pTIMER1_WIDTH = 27+100;
*pTIMER7_CONFIG = PWM_OUT | PERIOD_CNT | TIN_SEL | CLK_SEL | PULSE_HI | EMU_RUN;
*pTIMER7_PERIOD = DCLKS_PER_LINE;
*pTIMER7_WIDTH = 25+100;
*pTIMER5_CONFIG = PWM_OUT | PERIOD_CNT | TIN_SEL | CLK_SEL | PULSE_HI | EMU_RUN;
*pTIMER5_PERIOD = DCLKS_PER_LINE*2;
*pTIMER5_WIDTH = DCLKS_PER_LINE;
*pTIMER6_CONFIG = PWM_OUT | PERIOD_CNT | TIN_SEL | CLK_SEL | PULSE_HI | EMU_RUN;
*pTIMER6_PERIOD = DCLKS_PER_LINE;
*pTIMER6_WIDTH = 1;
*pTIMER0_CONFIG = PWM_OUT | PERIOD_CNT | TIN_SEL | CLK_SEL | PULSE_HI | EMU_RUN;
*pTIMER0_PERIOD = DCLKS_PER_LINE;
*pTIMER0_WIDTH = 1;
// Enable HSYNC and VSYNC timers for the LCD
CHECK( adi_tmr_GPGroupEnable (BF537_EZKIT_TMR_VSYNC, TRUE) );
// Precisely delay the start of the other timers
while (*pTIMER1_COUNTER < 1);
*pTIMER_ENABLE = TIMEN7;
while (*pTIMER1_COUNTER < 9+100);
*pTIMER_ENABLE = TIMEN5;
while (*pTIMER1_COUNTER < 24+100);
*pTIMER_ENABLE = TIMEN6;
while (*pTIMER1_COUNTER < 26+100);
*pTIMER_ENABLE = TIMEN0;
}
void CloseTimers (void)
{
int ret;
// Terminate all the timers
ret = adi_tmr_Terminate ();
ret = adi_ports_Terminate ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -