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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [sw/] [lib/] [include/] [flash.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
/******************************************************************************
2
 * Numonyx™ 128 Mbit EMBEDDED FLASH MEMORY J3 Version D                       *
3
 ******************************************************************************
4
 * REFERENCES                                                                 *
5
 *  [1] Numonyx™ Embedded Flash Memory(J3 v. D) Datasheet Revision 5          *
6
 *                                                                            *
7
 ******************************************************************************
8
 * Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.com>          *
9
 *                                                                            *
10
 * This program is free software: you can redistribute it and/or modify       *
11
 * it under the terms of the GNU General Public License as published by       *
12
 * the Free Software Foundation, either version 3 of the License, or          *
13
 * (at your option) any later version.                                        *
14
 *                                                                            *
15
 * This program is distributed in the hope that it will be useful,            *
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
18
 * GNU General Public License for more details.                               *
19
 *                                                                            *
20
 * You should have received a copy of the GNU General Public License          *
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
22
 ******************************************************************************/
23
#include "stddef.h"
24
 
25
#ifndef _FLASH_H
26
#define _FLASH_H
27
 
28
/* Flash memory location */
29
#define FLASH_MEMORY ((volatile uchar *) 0x10000000)
30
 
31
/* Flash status register flags. */
32
#define FLASH_READY             ((uint) 0x80) // Bit 8: Flash is ready. 
33
#define FLASH_ERASE_ERROR       ((uint) 0x20) // Bit 5: Error while errasing.
34
#define FLASH_PROGRAM_ERROR     ((uint) 0x10) // Bit 4: Error while programming.
35
#define FLASH_CMD_ERROR         (FLASH_ERASE_ERROR | FLASH_PROGRAM_ERROR)
36
#define FLASH_BLOCK_LOCKED      ((uint) 0x02) // Bit 2: Block is locked.
37
 
38
/* Status register commands */
39
#define CMD_READ_SR             ((uint) 0x70) // Read the status register.
40
#define CMD_CLEAR_SR            ((uint) 0x50) // Clear error states.
41
 
42
/* Memory operations */
43
#define CMD_READ_ARRAY          ((uint) 0xff) // Read 32bit of data.
44
#define CMD_BYTE_PROGRAM        ((uint) 0x10) // Write one byte of data.
45
#define CMD_BLOCK_ERASE_SETUP   ((uint) 0x20) // Setup erase command.
46
#define CMD_BLOCK_ERASE_CONFIRM ((uint) 0xd0) // Confirm errase command.
47
 
48
/* Memory size */
49
#define FLASH_BLOCK_SIZE         131072       // Size of one block in bytes.
50
#define FLASH_BLOCKS             128          // Number of blocks available.
51
 
52
/* Read the status register. */
53
extern uchar flash_read_status();
54
 
55
/* Clear the status register.
56
   The Status Register (SR) contain status and error bits which are set by the
57
   device. SR status bits are cleared by the device, however SR error bits are
58
   cleared by issuing the Clear Status Register command. Resetting the device
59
   also clears the Status Register. */
60
extern void flash_clear_sr();
61
 
62
/* Write a byte of data to a specific device address.
63
   Writing only changes '1' to '0'. If you overwrite data that would change '0'
64
   to '1', erase the block beforhand.
65
   Issuing the Read Array command to the device while it is actively programming
66
   causes subsequent reads from the device to output invalid data. [1] */
67
extern void flash_write(uint adr, uchar b);
68
 
69
/* Read 32bit of data from a specific device address.
70
   Issues a Read Array Command each time, although device stays in Array Read
71
   mode until another command operation takes place. */
72
extern uint flash_read(uint adr);
73
 
74
/* Erase block. Point to an address within the block address space you want to
75
   erase. 16 Mbytes or 8 Mword (128-Mbit), organized as 128-Kbyte erase blocks.
76
   Erasing is performed on a block basis - an entire block is erased each time
77
   an erase command sequence is issued. Once a block is fully erased, all
78
   addressable locations within that block read as logical ones (FFFFh). [1] */
79
extern void flash_block_erase(uint blk);
80
 
81
/* Wait for the end of a operation and return the status register when ready.
82
   Block erasure and writing data takes longer than a WB write operation.
83
   So after each erase or write call flash_wait() or do something else
84
   meanwhile. */
85
extern uchar flash_wait();
86
 
87
#endif

powered by: WebSVN 2.1.0

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