OpenCores
URL https://opencores.org/ocsvn/layer2/layer2/trunk

Subversion Repositories layer2

[/] [layer2/] [trunk/] [sw/] [void/] [main.c] - Diff between revs 4 and 5

Show entire file | Details | Blame | View Log

Rev 4 Rev 5
Line 1... Line 1...
/******************************************************************************
/******************************************************************************
 * void - Bootloader Version 0.2.1                                            *
 * void - Bootloader Version 0.2.2                                            *
 ******************************************************************************
 ******************************************************************************
 * Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.com>          *
 * Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.com>          *
 *                                                                            *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU General Public License as published by       *
 * it under the terms of the GNU General Public License as published by       *
Line 21... Line 21...
#include "flash.h"
#include "flash.h"
#include "ui.h"
#include "ui.h"
#include "view.h"
#include "view.h"
 
 
#define DDR_ADDRESS ((volatile uint *) 0x20000000)
#define DDR_ADDRESS ((volatile uint *) 0x20000000)
#define NUM_OF_WORDS 77
 
 
 
/******************************************************************************
/******************************************************************************
 * Upload View                                                                *
 * Upload View                                                                *
 ******************************************************************************/
 ******************************************************************************/
 
/* Wait until a flash write is completed and check for errors. */
 
void checkFlashWrite() {
 
 
 
   uchar state;         // Flash state.
 
 
 
   // Error checking.
 
   state = flash_wait();
 
   if(state & FLASH_BLOCK_LOCKED) {
 
      drawErrorWindow(&errErrorFlashLocked);
 
      return 0;
 
   }
 
   if(state & FLASH_PROGRAM_ERROR) {
 
      drawErrorWindow(&errErrorFlashWrite);
 
      return 0;
 
   }
 
}
 
 
/* NOTE: Automatic deduction of the number of blocks, that need to be erased
/* NOTE: Automatic deduction of the number of blocks, that need to be erased
         has not been tested extensive. */
         has not been tested extensive. */
void upload() {
void upload() {
 
 
   uchar state;         // Flash state.
 
   uint size;           // Image size.
   uint size;           // Image size.
   uint step;           // Progress bar step size.
   uint step;           // Progress bar step size.
   uint cval;           // Current progress value.
   uint cval;           // Current progress value.
 
 
   // Clear screen.
   // Clear screen.
Line 78... Line 93...
         drawErrorWindow(&errErrorFlashErase);
         drawErrorWindow(&errErrorFlashErase);
         return 0;
         return 0;
      }
      }
   }
   }
 
 
   // Echoing received image size.
   // Write image size at flash address 0x0.
   rs232_transmit(size >> 24);
   for(uchar i=0; i<4; i++) {
   rs232_transmit(size >> 16);
      flash_write(i, size >> ((3-i) * 8) );
   rs232_transmit(size >> 8);
      checkFlashWrite();
   rs232_transmit(size);
   }
 
 
   // Upload data.
   // Upload data.
   drawMessage(&wUpload, &msgUploadWrite);
   drawMessage(&wUpload, &msgUploadWrite);
   pbUpload.val = 0;                         // Reset progress bar.
   pbUpload.val = 0;                         // Reset progress bar.
   step = size / 64;                         // Calculate progress step size.
   step = size / 64;                         // Calculate progress step size.
   cval = step;
   cval = step;
 
 
 
   // Echoing received image size.
 
   for(uchar i=0; i<4; i++) {
 
      rs232_transmit( size >> ((3-i) * 8) );
 
   }
 
 
   // Write each single byte to Flash.
   // Write each single byte to Flash.
   for(uint i=0; i < size; i++) {
   for(uint i=0; i < size; i++) {
      flash_write(i, rs232_receive());
      flash_write(i + 4, rs232_receive());
 
 
      // Update status bar.
      // Update status bar.
      if(i == cval) {
      if(i == cval) {
         pbUpload.val++;
         pbUpload.val++;
         drawProgressBar(&wUpload, &pbUpload);
         drawProgressBar(&wUpload, &pbUpload);
         cval += step;
         cval += step;
      }
      }
 
 
      // Error checking.
      checkFlashWrite();
      state = flash_wait();
 
      if(state & FLASH_BLOCK_LOCKED) {
 
         drawErrorWindow(&errErrorFlashLocked);
 
         return 0;
 
      }
 
      if(state & FLASH_PROGRAM_ERROR) {
 
         drawErrorWindow(&errErrorFlashWrite);
 
         return 0;
 
      }
 
   }
   }
 
 
   // Copy flash data to DDR2 memory.
 
   // NOTE: Missing bytes, if binary file is not 4 bytes aligned.
 
   // for(uint i=0; i < (size / 4) /* + 1 */; i++) {
 
      // DDR_ADDRESS[i] = flash_read(i);
 
   // }
 
 
 
   // Go back to main menu.
   // Go back to main menu.
   boot();
   boot();
}
}
 
 
 
 
/******************************************************************************
/******************************************************************************
 * DDR Load View                                                              *
 * DDR Load View                                                              *
 ******************************************************************************/
 ******************************************************************************/
/* Load Flash contents into DDR. */
/* Load Flash contents into DDR.
void load() {
 
 
   Input:
 
      start    Image start address on flash.
 
      size     Image size.
 
 */
 
void load(uint start, uint size) {
 
 
   uint step;           // Progress bar step size.
   uint step;           // Progress bar step size.
   uint cval;           // Current progress value.
   uint cval;           // Current progress value.
 
 
   cls();
   cls();
Line 142... Line 152...
 
 
   // Upload Initialization.
   // Upload Initialization.
   pbUpload.val = 0;
   pbUpload.val = 0;
   drawProgressBar(&wDDRUpload, &pbUpload);
   drawProgressBar(&wDDRUpload, &pbUpload);
 
 
   step = FLASH_BLOCK_SIZE * 2;
   step = size / 64;
   cval = step;
   cval = step;
 
 
   // Copy flash data to DDR2 memory.
   // Copy flash data to DDR2 memory.
   for(uint i=0; i < FLASH_BLOCKS * FLASH_BLOCK_SIZE; i++) {
   // NOTE: Missing bytes, if binary file is not 4 bytes aligned.
 
   for(uint i=0; i < (size / 4); i++) {
 
 
      DDR_ADDRESS[i] = flash_read(i);
      DDR_ADDRESS[i] = flash_read(i + start);
 
 
      // Update status bar.
      // Update status bar.
      if(i == cval) {
      if(i == cval) {
         pbUpload.val++;
         pbUpload.val++;
         drawProgressBar(&wUpload, &pbUpload);
         drawProgressBar(&wUpload, &pbUpload);
Line 163... Line 174...
 
 
 
 
/******************************************************************************
/******************************************************************************
 * Memory View                                                                *
 * Memory View                                                                *
 ******************************************************************************/
 ******************************************************************************/
 
#define NUM_OF_WORDS 77
/* TODO: Cleaner generic version.
/* TODO: Cleaner generic version.
   Quick and dirty implementation of an memory matrix view. Shows the next
   Quick and dirty implementation of an memory matrix view. Shows the next
   'NUM_OF_WORDS' starting at location 'adr' of the Flash and the DDR memory
   'NUM_OF_WORDS' starting at location 'adr' of the Flash and the DDR memory
   device. */
   device. */
void show_memory_contents(uint adr) {
void show_memory_contents(uint adr) {
Line 239... Line 251...
 * Boot View                                                                  *
 * Boot View                                                                  *
 ******************************************************************************/
 ******************************************************************************/
/* Wait for completed flash initialization. Set up main menu box. */
/* Wait for completed flash initialization. Set up main menu box. */
int main() {
int main() {
 
 
 
   uchar s;
 
 
   // Clear screen.
   // Clear screen.
   cls();
   cls();
 
 
   // Wait for flash hardware initialization end.
   // Wait for flash hardware initialization end.
   uchar s = flash_wait();
   s = flash_wait();
 
 
   // Flash not ready.
   // Flash not ready.
   if( !(s & FLASH_READY) ) {
   if( !(s & FLASH_READY) ) {
      drawErrorWindow(&errFlashNotReady);
      drawErrorWindow(&errFlashNotReady);
      return 0;
      return 0;
Line 283... Line 297...
               case OPTION_MEMORY:
               case OPTION_MEMORY:
                  view_memories();
                  view_memories();
                  break;
                  break;
 
 
               case OPTION_START:
               case OPTION_START:
                  load();
                  load(1, flash_read(0));
                  start();
                  start();
                  break;
                  break;
 
 
               default:
               default:
                  break;
                  break;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.