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

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-fw/] [firmware/] [src/] [spi_flash.c] - Diff between revs 9 and 13

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 9 Rev 13
Line 40... Line 40...
#include "spi_flash.h"
#include "spi_flash.h"
#include "spi.h"
#include "spi.h"
#include "debugprint.h"
#include "debugprint.h"
#include "stdint.h"
#include "stdint.h"
 
 
 
 
SPI_flash xdata flash_dr;
SPI_flash xdata flash_dr;
 
 
 
 
 /** \brief Internal: Helper function to count the number of active (1) bits in a byte */
 /** \brief Internal: Helper function to count the number of active (1) bits in a byte */
static unsigned char
static unsigned char
Line 67... Line 68...
{
{
  // Software enables are active high.
  // Software enables are active high.
  // Hardware enables are active low.
  // Hardware enables are active low.
 
 
  if(count_bits8(enables) > 1) {
  if(count_bits8(enables) > 1) {
    //print_info("en\n");
    //print_error("en\n");
    return;
    return;
  }
  }
  else {
  else {
    bitSPI_CLK = 0; //make shure spi_clk is low before we activate a device
    bitSPI_CLK = 0; //make shure spi_clk is low before we activate a device
    SPI_OE |= bmSPI_MASK;  //activate spi bus
    SPI_OE |= bmSPI_MASK;  //activate spi bus
    enables &= bmSPI_CS_MASK;
    enables &= bmSPI_CS_MASK;
    SPI_CS_PORT |= bmSPI_CS_MASK;   //disable all chipselect signals
    SPI_CS_PORT |= bmSPI_CS_MASK;   //disable all chipselect signals
    SPI_CS_PORT &= ~enables;
    SPI_CS_PORT &= ~enables;
    SPI_CS_OE |= enables;
    //SPI_CS_OE |= enables;
 
    SPI_CS_OE |= bmSPI_CS_MASK;
  }
  }
}
}
 
 
 
 
/** disables all SPI devices and sets the SPI and SPI CS signals to tri-state */
/** disables all SPI devices and sets the SPI and SPI CS signals to tri-state */
#define disable_all()   {setup_enables (0); SPI_OE &= ~bmSPI_MASK;}  
#define disable_all()   {        \
 
    setup_enables (0);            \
 
    }    /*    SPI_OE &= ~bmSPI_MASK;           \
 
    SPI_CS_OE &= ~bmSPI_CS_MASK; \
 
    }  */
 
 
 
 
/** \brief Internal: Writes one byte to the SPI bus
/** \brief Internal: Writes one byte to the SPI bus
 *
 *
 * \param[in] data to write to the bus
 * \param[in] data to write to the bus
Line 217... Line 223...
 
 
    return GOOD;
    return GOOD;
  }
  }
  else {
  else {
    return UNSUPPORTED_TYPE;
    return UNSUPPORTED_TYPE;
 
    /* debug stuff: */
 
    //return *idPtr;
  }
  }
}
}
 
 
 
 
/** \brief Reads data from the SPI flash */
/** \brief Reads data from the SPI flash */
Line 231... Line 239...
  while(spiflash_is_busy(flashPtr));
  while(spiflash_is_busy(flashPtr));
 
 
  //print_info("r\n");
  //print_info("r\n");
 
 
  /* we do a bit dirty programming here:
  /* we do a bit dirty programming here:
   * the adress of the device is only 24bit long, so we misuse the upper 8bits to send the
   * the adress of the device is only 24bit long, so we misuse the upper 8bits
   * read command to the spi flash. this avoids more complicated constructs. */
   * to send the read command to the spi flash.
 
   * this avoids more complicated constructs. */
  *adress &= 0x00FFFFFF;
  *adress &= 0x00FFFFFF;
  *adress |= 0x03000000; //set the upper 8bit to the READ command
  *adress |= 0x03000000; //set the upper 8bit to the READ command
 
 
  /*printf_tiny("ad: %x,",((uint8_t*)adress)[2]);
  /*printf_tiny("ad: %x,",((uint8_t*)adress)[2]);
  printf_tiny("%x,",((uint8_t*)adress)[1]);
  printf_tiny("%x,",((uint8_t*)adress)[1]);
Line 262... Line 271...
  setup_enables(bmSPI_CS_FLASH);
  setup_enables(bmSPI_CS_FLASH);
  write_byte_msb(WREN);
  write_byte_msb(WREN);
  disable_all();
  disable_all();
 
 
  /* we do a bit dirty programming here:
  /* we do a bit dirty programming here:
   * the adress of the device is only 24bit long, so we misuse the upper 8bits to send the
   * the adress of the device is only 24bit long, so we misuse the upper 8bits
   * read command to the spi flash. this avoids more complicated constructs. */
   * to send the read command to the spi flash.
 
   * this avoids more complicated constructs. */
  *adress &= 0x00FFFFFF;
  *adress &= 0x00FFFFFF;
  *adress |= 0xD8000000; //set the upper 8bit to the SE (sector erase) command
  *adress |= 0xD8000000; //set the upper 8bit to the SE (sector erase) command
 
 
  //print_info("e\n");  
  //print_info("e\n");  
 
 
Line 325... Line 335...
 
 
    //print_info("w\n");
    //print_info("w\n");
    //printf_tiny("%d\n",writeableBytes);    
    //printf_tiny("%d\n",writeableBytes);    
 
 
    /* we do a bit dirty programming here:
    /* we do a bit dirty programming here:
     * the adress of the device is only 24bit long, so we misuse the upper 8bits to send the
     * the adress of the device is only 24bit long, so we misuse the upper 8bits
     * read command to the spi flash. this avoids more complicated constructs. */
     * to send the read command to the spi flash.
 
     * this avoids more complicated constructs. */
    *adress &= 0x00FFFFFF;
    *adress &= 0x00FFFFFF;
    *adress |= 0x02000000; //set the upper 8bit to the PP (page programm) command
    *adress |= 0x02000000; //set the upper 8bit to the PP (page programm) command
 
 
    /*printf_tiny("ad: %x,",((uint8_t*)adress)[3]);
    /*printf_tiny("ad: %x,",((uint8_t*)adress)[3]);
    printf_tiny("%x,",((uint8_t*)adress)[2]);
    printf_tiny("%x,",((uint8_t*)adress)[2]);

powered by: WebSVN 2.1.0

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