?? flashblink.c
字號:
/*******************************************************************************
* FILENAME
* FlashBlink.c
*
* DESCRIPTION
* DSP Program intended as a demo for
* DSK 6211 Flash Memory Downloader, called
* FlashBurn.
* This was adapted from the blink example
* which is shipped with the DSK 6211 package.
*
*******************************************************************************/
#include <c6x.h>
#include <c6211dsk.h>
/*******************************************************************************
* Function prototypes
*******************************************************************************/
void led_blink(int count, int ms_period);
void delay_msec(short msec);
int timer0_read();
void timer0_start();
void timer0_init();
/*******************************************************************************
* FUNCTION : main
*
* ARGUMENTS :
* VOID
*
* DESCRIPTION :
* The code is just a blinker test function
*
*******************************************************************************/
int main()
{
/* DSP initialization */
CSR=0x100; /* Disable all interrupts */
IER=1; /* Disable all interrupts except NMI */
ICR=0xffff; /* Clear all pending interrupts */
/*************************************************************************
* Standard 6211/6711 DSK includes 2 MT48LC1M16A1-7 devices = 4MB SDRAM *
* For these devices use the following parameter: *
* EMIF_SDCTRL=0x07126000 *
* If MT48LC1M16A1-10 devices are installed use the following parameter: *
* EMIF_SDCTRL=0x07227000 *
* /|\ 16Mb parts = 4MB SDRAM /|\ *-------------------------------------*
*----------------------------------* \|/ 64Mb parts = 16MB SDRAM \|/ *
* If MT48LC4M16A2-10 devices are installed use the following parameter: *
* EMIF_SDCTRL=0x57227000 *
*************************************************************************/
*(unsigned volatile int *)EMIF_GCR = 0x3300; /* EMIF global control */
*(unsigned volatile int *)EMIF_CE1 = CE1_32; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_SDCTRL = 0x07126000; /* EMIF SDRAM control */
*(unsigned volatile int *)EMIF_CE0 = 0x30; /* EMIF CE0 control */
*(unsigned volatile int *)EMIF_SDRP = 0x61a; /* EMIF SDRM refresh period */
*(unsigned volatile int *)EMIF_SDEXT= 0x54529; /* EMIF SDRM extension */
/*****************************************************************************
* Start state
****************************************************************************/
delay_msec(50);
*(unsigned volatile int *)IO_PORT = 0x07000000; /* Turn off all user LEDs*/
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x0e000000; /* Display 1 on LEDs */
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x0D000000; /* Display 2 on LEDs */
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x0C000000; /* Display 3 on LEDs */
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x0B000000; /* Display 4 on LEDs */
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x0A000000; /* Display 5 on LEDs */
delay_msec(500);
*(unsigned volatile int *)IO_PORT = 0x09000000; /* Display 6 on LEDs */
delay_msec(500);
/*
****************************************************************************
* Flash LEDS forever, 3 blinks, then 1/2 sec. off.
* THis makes it a different pattern from the
* blink example shipped with the DSK.
****************************************************************************
*/
for (;;)
{
led_blink(3, 200);
delay_msec(500);
}
}
/*******************************************************************************
* FUNCTION : led_blink
*
* ARGUMENTS :
* INT count <-- Number of times to blink the LEDs
* INT ms_period <-- Time the LED(s) is(are) active (illuminated)
*
* DESCRIPTION :
* Toggles the user LEDs for a given count and period (in milliseconds).
*
* OUTPUTS :
* VOID
*
*******************************************************************************/
void led_blink(int count, int ms_period)
{
int i;
for (i=0;i<count;i++)
{
*(unsigned volatile int *)IO_PORT = 0x0; /* Turn on all user LEDs */
delay_msec(ms_period/2);
*(unsigned volatile int *)IO_PORT = 0x07000000; /* Turn off all user LEDs*/
delay_msec(ms_period/2);
}
*(unsigned volatile int *)IO_PORT = 0x07000000; /* Turn off all user LEDs */
}
/*******************************************************************************
* FUNCTION : delay_msec
*
* ARGUMENTS :
* SHORT msec <-- Period to delay in milliseconds
*
* DESCRIPTION :
*
*
* OUTPUTS :
* VOID
*
*******************************************************************************/
void delay_msec(short msec)
{
/* Assume 150 MHz CPU, timer peirod = 4/150 MHz */
int timer_limit = (msec*9375)<<2;
int time_start;
timer0_start();
time_start = timer0_read();
while ((timer0_read()-time_start) < timer_limit);
}
/*******************************************************************************
* FUNCTION : timer0_read
*
* ARGUMENTS :
* VOID
*
* DESCRIPTION :
* Read and return the count in timer 0.
*
* OUTPUTS :
* INT <-- Returns the count in timer 0
*
*******************************************************************************/
int timer0_read()
{
int i;
i = *(unsigned volatile int *)TIMER0_COUNT;
return i;
}
/*******************************************************************************
* FUNCTION : timer0_start
*
* ARGUMENTS :
* VOID
*
* DESCRIPTION :
* Start timer 0 after initializing it for 32-bit count and no interrupt.
*
* OUTPUTS :
* VOID
*
*******************************************************************************/
void timer0_start()
{
/* Hold the timer */
*(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;
/* Use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_CTRL |= 0x200;
/* Set for 32 bit counter */
*(unsigned volatile int *)TIMER0_PRD |= 0xffffffff;
/* Start the timer */
*(unsigned volatile int *)TIMER0_CTRL |= 0xC0;
}
/*******************************************************************************
* FUNCTION : timer0_init
*
* ARGUMENTS :
* VOID
*
* DESCRIPTION :
* Start timer 0 after initializing it for a short period (~13.7 micro seconds)
* with interrupt.
*
* OUTPUTS :
* VOID
*
*******************************************************************************/
void timer0_init()
{
/* Hold the timer */
*(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;
/* Use CPU CLK/4 */
*(unsigned volatile int *)TIMER0_CTRL |= 0x200;
/* Set for a short period */
*(unsigned volatile int *)TIMER0_PRD = 0x200;
/* Start the timer, enable timer0 int */
*(unsigned volatile int *)TIMER0_CTRL |= 0x3C0;
}
/* END OF FILE */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -