📄 ezkitutilities.c
字号:
#include <services/services.h> // system service includes
#include "system.h"
#include <sysreg.h> // system config definitions
#include "ezkitutilities.h" // EZ-Kit utility definitions
#define pFlashA_PortA_In ((volatile unsigned char *)0x20270000) // address of flash A port A input data register
#define pFlashA_PortA_Out ((volatile unsigned char *)0x20270004) // address of flash A port A output data register
#define pFlashA_PortA_Dir ((volatile unsigned char *)0x20270006) // address of flash A port A direction register
#define pFlashA_PortB_In ((volatile unsigned char *)0x20270001) // address of flash A port B input data register
#define pFlashA_PortB_Out ((volatile unsigned char *)0x20270005) // address of flash A port B output data register
#define pFlashA_PortB_Dir ((volatile unsigned char *)0x20270007) // address of flash A port B direction register
#define RST_7183 (0x8) //decoder reset bit #3 in flashA portA
#define PPICLK_ADV7183_SELECT (0x10) //decoder clock to PPI bit #4 in flashA portA
#define ADV7183_OE (0x4) //ADV7183 /OE = PF2
/*********************************************************************
Function: ezConfigurePLL
Description: Initializes and sets the PLL to 594 for CCLK and
118 for SCLCK.
*********************************************************************/
void ezConfigurePLL(void) // sets processor to 594 MHz CCLK, 118,8 MHz SCLK
{
sysreg_write(reg_SYSCFG, 0x32);
*pSIC_IWR = 0x1;
*pPLL_CTL = 0x2C00;
ssync();
// idle();
}
/*********************************************************************
Function: ezConfigureSDRAM
Description: Initializes and sets SDRAM parameters on the EZ-Kit.
*********************************************************************/
void ezConfigureSDRAM(void) // sets up SDRAM for use
{
unsigned short tempReg=0;
tempReg = *pEBIU_SDSTAT;
tempReg = tempReg & SDRS;
//SDRS is bit 8 of EBIU_SDSTAT register.
//If SDRS (bit 8) is set (tempReg reads value 8),
//then SDRAM registers haven't been initialized
//yet and needs to be configured.
/* if (tempReg == 8)
{
//SDRAM Refresh Rate Control Register
// *pEBIU_SDRRC = 0x0817;
// *pEBIU_SDRRC = 0x0399;
*pEBIU_SDRRC = 0x0397;
//SDRAM Memory Bank Control Register
//*pEBIU_SDBCTL = 0x0013;
*pEBIU_SDBCTL = 0x0025;
//SDRAM Memory Global Control Register
*pEBIU_SDGCTL = 0x0091998d;
}
*/
if (*pEBIU_SDSTAT & SDRS) {
//SDRAM Refresh Rate Control Register
*pEBIU_SDRRC = 0x00000817;
//SDRAM Memory Bank Control Register
*pEBIU_SDBCTL = 0x00000013;
//SDRAM Memory Global Control Register
*pEBIU_SDGCTL = 0x0091998d;
ssync();
}
}
/*********************************************************************
Function: ezConfigureAsync
Description: Initializes and sets the appropriate wait states for
the async memories on the EZKit.
*********************************************************************/
void ezConfigureAsync(void) // configures async memory for use
{
/* *pEBIU_AMBCTL0 = 0x7bb07bb0; // Write access time = 7 cycles, read access time = 11 cycles, no ARDY
*pEBIU_AMBCTL1 = 0x13d07bb0; // bank 3 for NETCHIP device
*pEBIU_AMGCTL = 0x00FF;
*/
*pEBIU_AMBCTL0 = 0x7bb07bb0; // <--|Write access time = 7 cycles, read access time = 11 cycles, no ARDY
*pEBIU_AMBCTL1 = 0x7bb07bb0; // |Hold time = 2 cycles, setup time = 3 cycles, transition time = 4 cycles
*pEBIU_AMGCTL = 0x000F; // |Enable all memory banks
}
/*********************************************************************
Function: ezConfigureFlashA
Description: Sets up the A flash on the board for use.
*********************************************************************/
void ezConfigureFlashA(void) // sets up the flash
{
*pFlashA_PortA_Out = 0; // resets port A to initial value
*pFlashA_PortA_Dir = 0xFF; // configure everything on port A as outputs
*pFlashA_PortB_Out = 0; // resets port B to initial value
*pFlashA_PortB_Dir = 0x3f; // configure everything on port B as outputs
/*
*pFlashA_PortA_Out = 0x0; // clear data registers
*pFlashA_PortA_Dir = 0xFFFF; // set dir=output
*/
}
/*********************************************************************
Function: ezEnableVideoDecoder
Description: Connects up the bus, sets up the video clocking and
enables the AD7183.
*********************************************************************/
void ezEnableVideoDecoder(void) // connects bus, sets up video clock and enables the 7183
{
unsigned short tempReg;
//The GPIOs of the flash are linked to the ADV7183 reset pin as well as to the
//switch that drives the PPI clock. De-assert the ADV7183 reset and link the ADV7183
//Clock "LLC1" to the Blackfin PPI clock input. See EZ-KIT schematics for more details.
tempReg = *pFlashA_PortA_Out;
*pFlashA_PortA_Out = tempReg | RST_7183 | PPICLK_ADV7183_SELECT;
//Setup the Blackfin PF registers
if ( ((*pDSPID) & 0xFFFF) < 0x2 ) { // Workaround for anomaly ID# 05000079 for rev 0.1
tempReg = *pFIO_INEN;
*pFIO_INEN = tempReg | ADV7183_OE;
}
//Blackfin PF2 pin must be set as output
tempReg = *pFIO_DIR;
*pFIO_DIR = tempReg | ADV7183_OE;
//Set the Blackfin pin PF2 to output enable the ADV7183 data bus
tempReg = *pFIO_FLAG_C;
*pFIO_FLAG_C = tempReg | ADV7183_OE;
// *pFIO_FLAG_C = ADV7183_OE;
/*
unsigned char tempReg;
//De-assert the ADV7183 reset and link the ADV7183 Clock "LLC1" to the Blackfin PPI
//clock input.
tempReg = *pFlashA_PortA_Out;
*pFlashA_PortA_Out = tempReg | RST_7183 | PPICLK_ADV7183_SELECT;
//Setup the Blackfin PF registers
if ( ((*pDSPID) & 0xFFFF) < 0x2 ) { // Workaround for anomaly ID# 05000079 for rev 0.1
tempReg = *pFIO_INEN;
*pFIO_INEN = tempReg | ADV7183_OE;
}
//Blackfin PF2 pin must be set as output
tempReg = *pFIO_DIR;
*pFIO_DIR = tempReg | ADV7183_OE;
//Set the Blackfin pin PF2 to output enable the ADV7183 data bus
tempReg = *pFIO_FLAG_C;
*pFIO_FLAG_C = tempReg | ADV7183_OE;
*/
}
void ezTurnOnLED(u32 LEDNumber) // turns on an LED
{
switch(LEDNumber) {
case 4:
*pFlashA_PortB_Out |= 0x0001;
break;
case 5:
*pFlashA_PortB_Out |= 0x0002;
break;
case 6:
*pFlashA_PortB_Out |= 0x0004;
break;
case 7:
*pFlashA_PortB_Out |= 0x0008;
break;
case 8:
*pFlashA_PortB_Out |= 0x0010;
break;
case 9:
*pFlashA_PortB_Out |= 0x0020;
break;
}
}
/*********************************************************************
Function: ezTurnOffLED
Description: Turns an LED off.
*********************************************************************/
void ezTurnOffLED(u32 LEDNumber) // turns on an LED
{
switch(LEDNumber) {
case 4:
*pFlashA_PortB_Out &= ~0x0001;
break;
case 5:
*pFlashA_PortB_Out &= ~0x0002;
break;
case 6:
*pFlashA_PortB_Out &= ~0x0004;
break;
case 7:
*pFlashA_PortB_Out &= ~0x0008;
break;
case 8:
*pFlashA_PortB_Out &= ~0x0010;
break;
case 9:
*pFlashA_PortB_Out &= ~0x0020;
break;
}
}
/*********************************************************************
Function: ezToggleLED
Description: Toggles the state of an LED.
*********************************************************************/
void ezToggleLED(u32 LEDNumber) // toggles an LED
{
if (ezIsLEDOn(LEDNumber)) {
ezTurnOffLED(LEDNumber);
} else {
ezTurnOnLED(LEDNumber);
}
}
/*********************************************************************
Function: ezTurnOnAllLEDs
Description: Turns on all LEDs.
*********************************************************************/
void ezTurnOnAllLEDs(void) // turns on all LEDs
{
*pFlashA_PortB_Out = 0x3f;
}
/*********************************************************************
Function: ezTurnOffAllLEDs
Description: Turns off all LEDs.
*********************************************************************/
void ezTurnOffAllLEDs(void) // turns off all LEDs
{
*pFlashA_PortB_Out = 0x0;
}
/*********************************************************************
Function: ezCycleLEDs
Description: Cycles through each LED in turn.
*********************************************************************/
void ezCycleLEDs(void) // cycles through LEDS
{ // changes each time called
static int LED = EZ_FIRST_LED;
ezTurnOffLED(LED);
LED++;
if (LED > EZ_LAST_LED) LED = EZ_FIRST_LED;
ezTurnOnLED(LED);
}
/*********************************************************************
Function: ezIsLEDOn
Description: Returns TRUE if an LED is lit, FALSE otherwise.
*********************************************************************/
u32 ezIsLEDOn(u32 LEDNumber) // test to see if an LED is lit
{
switch(LEDNumber) {
case 4:
if (*pFlashA_PortB_In & 0x0001) return (TRUE);
break;
case 5:
if (*pFlashA_PortB_In & 0x0002) return (TRUE);
break;
case 6:
if (*pFlashA_PortB_In & 0x0004) return (TRUE);
break;
case 7:
if (*pFlashA_PortB_In & 0x0008) return (TRUE);
break;
case 8:
if (*pFlashA_PortB_In & 0x0010) return (TRUE);
break;
case 9:
if (*pFlashA_PortB_In & 0x0020) return (TRUE);
break;
}
return (FALSE);
}
/*********************************************************************
Function: ezGetDisplay
Description: Returns the current status of the LED display
*********************************************************************/
u8 ezGetDisplay()
{
return *pFlashA_PortB_In;
}
/*********************************************************************
Function: ezSetDisplay
Description: Sets the LED display
*********************************************************************/
void ezSetDisplay(u8 display)
{
*pFlashA_PortB_Out = display;
}
/*********************************************************************
Function: ezErrorCheck
Description: This function is intended to be used as a means to
quickly determine if a function has returned a non-zero
(hence an error) return code. All driver and system
services functions return a value of zero for success and
a non-zero value when a failure occurs. This function
lights all the LEDs and spins when a non-zero value is
passed to it.
*********************************************************************/
void ezErrorCheck(u32 Result) // lights all LEDS and spins on nonzero value
{
if (Result != 0)
{
// PRINT_DEBUG(("Error: 0x%x\n", Result));
PRINT_DEBUG(("Error: 0x%x\n", Result));
// while (1) ezTurnOnAllLEDs();
}
//printf(("Carried out:0x%x\n",Result));
}
void ezInitButtons(void)
{
*pFIO_INEN = 0x0f48; // enable flagsPF3PF4,PF6,PF8PF9PF10PF11;
*pFIO_DIR = 0xF0B7; // input:PF3,PF6,8,9,10,11
// *pFIO_DIR = 0x0000; // set the flag direction as input
*pFIO_EDGE = 0x0f08; // set to high level votage sensitive (when enabled)
//*pFIO_BOTH =0x0048;
/* *pFIO_INEN|=0x0002; //enable pf3 interrupt
*pFIO_DIR&=0xfffD; //pf3 direction is input
*pFIO_EDGE = 0x0000;
*pFIO_MASKA_S = 0x0002;
*/
}
void ezEnableButtonInterrupt (u32 ButtonNumber) // enables generation of a push button interrupt
{
switch (ButtonNumber) {
case 4:
*pFIO_MASKA_S = 0x0100;
break;
case 5:
*pFIO_MASKA_S = 0x0200;
break;
case 6:
*pFIO_MASKA_S = 0x0400;
break;
case 7:
*pFIO_MASKA_S = 0x0800;
break;
}
}
/*********************************************************************
Function: ezDelay
Description: Delays for approximately 1 msec when running at 600 MHz
*********************************************************************/
void ezDelay(u32 msec) {
volatile u32 i,j;
// value of 0x3000000 is about 1 sec so 0xc49b is about 1msec
for (j = 0; j < msec; j++) {
for (i = 0; i < 0xc49b; i++) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -