From cec60fc9601d0fdc31c5254f54eaadd444fa2eab Mon Sep 17 00:00:00 2001 From: Oliver Schinagl Date: Thu, 6 Jan 2005 14:17:55 +0000 Subject: Added lots of comments. Doxygen tags are still needed. --- Graphic_Equalizer/src/smartmedia.hcc | 102 +++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 5 deletions(-) diff --git a/Graphic_Equalizer/src/smartmedia.hcc b/Graphic_Equalizer/src/smartmedia.hcc index e87c852..f52db79 100644 --- a/Graphic_Equalizer/src/smartmedia.hcc +++ b/Graphic_Equalizer/src/smartmedia.hcc @@ -46,10 +46,15 @@ unsigned 1 smartmedia_init(void) { unsigned 1 retval; /* - * Firstly we enable both the CPLD and the SmartMedia. + * Firstly we enable both the CPLD. */ RC200CPLDEnable(); + /* + * We must reset the Smart Media before initializing it. If we don't reset it + * we get a lot of Init failures. If we don't use the delay, we get a lot of + * init failures. + */ RC200SmartMediaReset(&retval); delay; RC200SmartMediaInit(&retval); @@ -70,6 +75,11 @@ unsigned 1 smartmedia_init(void) { void smartmedia_loaddata(skindata_t *skindata) { /* * Setup RAM Handle, and determin maximum Data and Address widths + * + * FIXME: Currently we set the Ram handle here and in the main. If we + * would want to change it here, also change it elsewhere. A better + * solution would be to have the RAM_BANK0 macro defined somewhere + * globally. */ macro expr RAM_BANK0 = PalPL2RAMCT(0); macro expr DW = PalPL2RAMGetMaxDataWidthCT(); @@ -85,9 +95,21 @@ void smartmedia_loaddata(skindata_t *skindata) { extern ram unsigned 8 presets_default_values[768]; + /* + * Before we enter our main Smart Media read loop we verify the format + * of the SMC. This to ensure we use the correct functions later. + */ RC200SmartMediaCheckLogicalFormat(&physical_format); + /* + * We have several stages to go through. We stop once we pass the last + * one. + */ while ((STAGE_LOAD_ABOUT_BOTTOM +1) != stage) { + /* + * For each iteration of the main loop we set a different + * start and end variables. + */ switch (stage) { case STAGE_LOAD_DEMO_PRESET: sm_address = SMARTMEDIA_ADDRESS_PRESET_DEMO_START; @@ -149,29 +171,79 @@ void smartmedia_loaddata(skindata_t *skindata) { default: break; } + /* + * TODO: Replace the above switch-case with a lookuptables. + */ + /* + * The only difference between logical and phyiscally formated + * SMCs codewise is how they are addressed. + */ if (physical_format) { RC200SmartMediaSetAddress(READ, sm_address); } else { RC200SmartMediaSetLogicalAddress(READ, sm_address); } + /* + * While the address hasn't reached the end, continue loading data. + */ while (address != address_end) { + /* + * No matter what we read from the SMC, we aways need to + * read at least one byte per iteration. (Otherwise there + * would be no point in entering this loop. + */ RC200SmartMediaRead(&mask, FALSE); + + /* + * The difference when loading data from the SMC is + * when we load the presets. These aren't stored in + * external RAM but in an array on the FPGA. + */ if ((STAGE_LOAD_DEMO_PRESET == stage) || (STAGE_LOAD_RESET_PRESET == stage)) { + /* + * We only read one byte from the SMC and thus + * we only store one byte. We re-use the 'mask' + * variable here. The address is also re-used + * and thus we only use the last 10 bits to fit + * the address in our index. + * + */ presets_default_values[address <- 10] = mask; } else { + /* + * There needs to be atleast one clock cycle + * between setting the address and reading + * from it. We therefore set the address before + * reading from the SmartMedia as 'delay'. + */ + PalPL2RAMSetWriteAddress(RAM_BANK0, address); + + /* + * All other data has RGB image data and thus + * we read those additional bytes from the SMC. + * The image used for the graphic visualization + * is packed together however and thus we + * re-use the rgb variables here. + */ RC200SmartMediaRead(&r, FALSE); RC200SmartMediaRead(&g, FALSE); RC200SmartMediaRead(&b, FALSE); - PalPL2RAMSetWriteAddress(RAM_BANK0, address); + /* + * FIXME: Do we need this even? + */ data = 0 @ mask @ r @ g @ b; + + /* + * Now that we read a while 32bit wide word + * we can store it in the main memory bank. + */ PalPL2RAMWrite(RAM_BANK0, data); } - address++; #if HAVE_DEBUG /* * Print some indication about data loading. @@ -180,16 +252,36 @@ void smartmedia_loaddata(skindata_t *skindata) { print_string("."); } #endif + /* + * Finally we increase our address to prepare for the + * next iteration. + */ + address++; } + /* + * We need to tell the SmartMedia that the last byte was read + * however to check wether it is the last byte during each + * iteration of the loop would unecasserly 'a lot' of + * resources. We therefore read a dummy byte here. It doesn't + * matter where it comes from (from the SMC) as we don't use + * it. + */ RC200SmartMediaRead(&mask, TRUE); + /* + * Because we need to set a new starting address in the next + * iteration we need to 'end' the SmartMedia Operation. + */ RC200SmartMediaOperationEnd(&result); + /* + * We are done with this 'stage' and continue to the next one. + */ stage++; } /* - * This block needs to probably move up into the for loop where we - * calculate these settings determind by the image data.. + * TODO: This block needs to move up into the loop where we calculate + * these settings determind by the image data. */ skindata->spectrum.top = 200; skindata->spectrum.bottom = 335; -- cgit v0.12