00001 // This file is part of MOS, the MANTIS Operating System 00002 // See http://mantis.cs.colorado.edu/ 00003 // 00004 // Copyright (c) 2002 - 2007 University of Colorado, Boulder 00005 // 00006 // All rights reserved. 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are 00010 // met: 00011 // 00012 // * Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // * Redistributions in binary form must reproduce the above 00015 // copyright notice, this list of conditions and the following 00016 // disclaimer in the documentation and/or other materials provided 00017 // with the distribution. 00018 // * Neither the name of the MANTIS Project nor the names of its 00019 // contributors may be used to endorse or promote products derived 00020 // from this software without specific prior written permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 // POSSIBILITY OF SUCH DAMAGE. 00034 00039 #ifndef _ATMEL_FLASH_H_ 00040 #define _ATMEL_FLASH_H_ 00041 00042 00043 #define ATMEL_FLASH_PORT PORTD 00044 #define ATMEL_FLASH_DIRE DDRD 00045 00046 #define ATMEL_FLASH_SELECT PORTA 00047 #define ATMEL_FLASH_SELECT_PIN 3 00048 00049 #define ATMEL_FLASH_CLK 5 00050 #define ATMEL_FLASH_OUT 2 00051 #define ATMEL_FLASH_IN 3 00052 00053 #define ATMEL_FLASH_PAGE_SIZE 264 00054 #define ATMEL_FLASH_MAX_PAGES 2048 00055 #define ATMEL_FLASH_SIZE 540672 00056 00057 #define ATMEL_FLASH_BUFFER_1 0x1 00058 #define ATMEL_FLASH_BUFFER_2 0x2 00059 00060 #define ATMEL_FLASH_DEFAULT_BUFFER ATMEL_FLASH_BUFFER_1 00061 00062 /* These codes are for setting modes using dev_mode(). 00063 * 00064 * ATMEL_FLASH_MODE_UNBUFFERED is the original way the flash driver worked. 00065 * For backward compatibility, it is the default mode. Unbuffered writing works 00066 * as follows: 00067 * 1. Read a page from flash into the buffer on the flash chip. 00068 * 2. Erase the page in flash. 00069 * 3. Write the data to the buffer. 00070 * 4. Write the buffer to flash. 00071 */ 00072 #define ATMEL_FLASH_MODE_UNBUFFERED 3 00073 00074 /* ATMEL_FLASH_MODE_BUFFERED is a new mode that is more efficient for writing 00075 * lots of sequential data that does not come in page-sized chunks (e.g. Deluge). 00076 * The driver defers writing a page to flash until the on-chip buffer is full. 00077 * Read, seek, CRC, and compare commands still function properly. They will 00078 * flush the unwritten buffer if necessary. However, unwritten data will be 00079 * lost if the node is reset, unless you call 00080 * dev_ioctl(DEV_ATMEL_FLASH, DEV_FLUSH); 00081 */ 00082 #define ATMEL_FLASH_MODE_BUFFERED 4 00083 00084 /* opcodes for the device */ 00085 enum { 00086 C_READ_BUFFER1 = 0xd4, 00087 C_READ_BUFFER2 = 0xd6, 00088 C_WRITE_BUFFER1 = 0x84, 00089 C_WRITE_BUFFER2 = 0x87, 00090 C_FILL_BUFFER1 = 0x53, 00091 C_FILL_BUFFER2 = 0x55, 00092 C_FLUSH_BUFFER1 = 0x83, 00093 C_FLUSH_BUFFER2 = 0x86, 00094 C_QFLUSH_BUFFER1 = 0x88, 00095 C_QFLUSH_BUFFER2 = 0x89, 00096 C_COMPARE_BUFFER1 = 0x60, 00097 C_COMPARE_BUFFER2 = 0x61, 00098 C_WRITE_THROUGH_BUFFER1 = 0x82, 00099 C_WRITE_THROUGH_BUFFER2 = 0x85, 00100 C_READ_THROUGH_MEMORY = 0xE8, 00101 C_REQ_STATUS = 0xd7, 00102 C_ERASE_PAGE = 0x81 00103 }; 00104 00107 void atmel_flash_init(); 00108 00111 uint8_t atmel_flash_compare (uint8_t *p, uint16_t count); 00112 00116 uint16_t atmel_flash_crc(uint32_t count); 00117 00118 #endif
1.4.6