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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [flash.c] - Diff between revs 352 and 414

Show entire file | Details | Blame | View Log

Rev 352 Rev 414
Line 13... Line 13...
 *    ByteOffset and bytes must be a multiple of two.
 *    ByteOffset and bytes must be a multiple of two.
 *--------------------------------------------------------------------*/
 *--------------------------------------------------------------------*/
#include "plasma.h"
#include "plasma.h"
#include "rtos.h"
#include "rtos.h"
 
 
 
static OS_Mutex_t *mutexFlash;
 
 
 
void FlashLock(void)
 
{
 
   if(mutexFlash == NULL)
 
      mutexFlash = OS_MutexCreate("flash");
 
   OS_MutexPend(mutexFlash);
 
}
 
 
 
 
 
void FlashUnlock(void)
 
{
 
   OS_MutexPost(mutexFlash);
 
}
 
 
 
 
void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
{
{
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   FlashLock();
   *ptr = 0xff;                   //read mode
   *ptr = 0xff;                   //read mode
   while(bytes > 0)
   while(bytes > 0)
   {
   {
      *dst++ = (uint16)*ptr++;
      *dst++ = (uint16)*ptr++;
      bytes -= 2;
      bytes -= 2;
   }
   }
 
   FlashUnlock();
}
}
 
 
 
 
void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
{
{
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   FlashLock();
   while(bytes > 0)
   while(bytes > 0)
   {
   {
      *ptr = 0x40;                //write mode
      *ptr = 0x40;                //write mode
      *ptr++ = *src++;            //write data
      *ptr++ = *src++;            //write data
      while((*ptr & 0x80) == 0)   //check status
      while((*ptr & 0x80) == 0)   //check status
         ;
         ;
      bytes -= 2;
      bytes -= 2;
   }
   }
 
   FlashUnlock();
}
}
 
 
 
 
void FlashErase(uint32 byteOffset)
void FlashErase(uint32 byteOffset)
{
{
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
 
   FlashLock();
   *ptr = 0x20;                   //erase block
   *ptr = 0x20;                   //erase block
   *ptr = 0xd0;                   //confirm
   *ptr = 0xd0;                   //confirm
   while((*ptr & 0x80) == 0)      //check status
   while((*ptr & 0x80) == 0)      //check status
      ;
      ;
 
   FlashUnlock();
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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