Definition in file sdramc_example.c.
#include "board.h"
#include "print_funcs.h"
#include "cycle_counter.h"
#include "power_clocks_lib.h"
#include "sdramc.h"
Go to the source code of this file.
Defines | |
LEDs to Use for the Example | |
#define | LED_SDRAM_ERRORS (LED0 | LED1 | LED2 | LED3) |
#define | LED_SDRAM_OK (LED0 | LED1 | LED2 | LED3) |
#define | LED_SDRAM_READ LED1 |
#define | LED_SDRAM_WRITE LED0 |
Functions | |
int | main (void) |
Sets the SDRAM Controller up, initializes the SDRAM found on the board and tests it. |
#define LED_SDRAM_ERRORS (LED0 | LED1 | LED2 | LED3) |
#define LED_SDRAM_OK (LED0 | LED1 | LED2 | LED3) |
#define LED_SDRAM_READ LED1 |
#define LED_SDRAM_WRITE LED0 |
int main | ( | void | ) |
Sets the SDRAM Controller up, initializes the SDRAM found on the board and tests it.
Definition at line 125 of file sdramc_example.c.
References LED_SDRAM_ERRORS, LED_SDRAM_OK, LED_SDRAM_READ, LED_SDRAM_WRITE, SDRAM, SDRAM_SIZE, and sdramc_init().
00126 { 00127 unsigned long sdram_size, progress_inc, i, j, tmp, noErrors = 0; 00128 volatile unsigned long *sdram = SDRAM; 00129 00130 // Switch to external oscillator 0. 00131 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); 00132 00133 // Initialize the debug USART module. 00134 init_dbg_rs232(FOSC0); 00135 00136 // Calculate SDRAM size in words (32 bits). 00137 sdram_size = SDRAM_SIZE >> 2; 00138 print_dbg("\x0CSDRAM size: "); 00139 print_dbg_ulong(SDRAM_SIZE >> 20); 00140 print_dbg(" MB\n"); 00141 00142 // Initialize the external SDRAM chip. 00143 sdramc_init(FOSC0); 00144 print_dbg("SDRAM initialized\n"); 00145 00146 // Determine the increment of SDRAM word address requiring an update of the 00147 // printed progression status. 00148 progress_inc = (sdram_size + 50) / 100; 00149 00150 // Fill the SDRAM with the test pattern. 00151 for (i = 0, j = 0; i < sdram_size; i++) 00152 { 00153 if (i == j * progress_inc) 00154 { 00155 LED_Toggle(LED_SDRAM_WRITE); 00156 print_dbg("\rFilling SDRAM with test pattern: "); 00157 print_dbg_ulong(j++); 00158 print_dbg_char('%'); 00159 } 00160 sdram[i] = i; 00161 } 00162 LED_Off(LED_SDRAM_WRITE); 00163 print_dbg("\rSDRAM filled with test pattern \n"); 00164 00165 // Recover the test pattern from the SDRAM and verify it. 00166 for (i = 0, j = 0; i < sdram_size; i++) 00167 { 00168 if (i == j * progress_inc) 00169 { 00170 LED_Toggle(LED_SDRAM_READ); 00171 print_dbg("\rRecovering test pattern from SDRAM: "); 00172 print_dbg_ulong(j++); 00173 print_dbg_char('%'); 00174 } 00175 tmp = sdram[i]; 00176 if (tmp != i) 00177 { 00178 noErrors++; 00179 } 00180 } 00181 LED_Off(LED_SDRAM_READ); 00182 print_dbg("\rSDRAM tested: "); 00183 print_dbg_ulong(noErrors); 00184 print_dbg(" corrupted word(s) \n"); 00185 if (noErrors) 00186 { 00187 LED_Off(LED_SDRAM_ERRORS); 00188 while (1) 00189 { 00190 LED_Toggle(LED_SDRAM_ERRORS); 00191 cpu_delay_ms(200, FOSC0); // Fast blink means errors. 00192 } 00193 } 00194 else 00195 { 00196 LED_Off(LED_SDRAM_OK); 00197 while (1) 00198 { 00199 LED_Toggle(LED_SDRAM_OK); 00200 cpu_delay_ms(1000, FOSC0); // Slow blink means OK. 00201 } 00202 } 00203 }