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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [flash.c] - Blame information for rev 414

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 300 rhoads
/*--------------------------------------------------------------------
2
 * TITLE: Plasma Flash
3
 * AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
 * DATE CREATED: 12/17/05
5
 * FILENAME: plasma.h
6
 * PROJECT: Plasma CPU core
7
 * COPYRIGHT: Software placed into the public domain by the author.
8
 *    Software 'as is' without warranty.  Author liable for nothing.
9
 * DESCRIPTION:
10
 *    Plasma flash controller
11
 *    Only the lower 16-bits of each 32-bit word are connected --
12
 *    this changes the address mapping to the flash.
13
 *    ByteOffset and bytes must be a multiple of two.
14
 *--------------------------------------------------------------------*/
15
#include "plasma.h"
16
#include "rtos.h"
17
 
18 414 rhoads
static OS_Mutex_t *mutexFlash;
19 300 rhoads
 
20 414 rhoads
void FlashLock(void)
21
{
22
   if(mutexFlash == NULL)
23
      mutexFlash = OS_MutexCreate("flash");
24
   OS_MutexPend(mutexFlash);
25
}
26
 
27
 
28
void FlashUnlock(void)
29
{
30
   OS_MutexPost(mutexFlash);
31
}
32
 
33
 
34 300 rhoads
void FlashRead(uint16 *dst, uint32 byteOffset, int bytes)
35
{
36
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
37 414 rhoads
   FlashLock();
38 300 rhoads
   *ptr = 0xff;                   //read mode
39
   while(bytes > 0)
40
   {
41
      *dst++ = (uint16)*ptr++;
42
      bytes -= 2;
43
   }
44 414 rhoads
   FlashUnlock();
45 300 rhoads
}
46
 
47
 
48
void FlashWrite(uint16 *src, uint32 byteOffset, int bytes)
49
{
50
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
51 414 rhoads
   FlashLock();
52 300 rhoads
   while(bytes > 0)
53
   {
54
      *ptr = 0x40;                //write mode
55
      *ptr++ = *src++;            //write data
56
      while((*ptr & 0x80) == 0)   //check status
57
         ;
58
      bytes -= 2;
59
   }
60 414 rhoads
   FlashUnlock();
61 300 rhoads
}
62
 
63
 
64
void FlashErase(uint32 byteOffset)
65
{
66
   volatile uint32 *ptr=(uint32*)(FLASH_BASE + (byteOffset << 1));
67 414 rhoads
   FlashLock();
68 300 rhoads
   *ptr = 0x20;                   //erase block
69
   *ptr = 0xd0;                   //confirm
70
   while((*ptr & 0x80) == 0)      //check status
71
      ;
72 414 rhoads
   FlashUnlock();
73 300 rhoads
}

powered by: WebSVN 2.1.0

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