00001 /* 00002 * Copyright (C) 2008-2009 by egnite GmbH 00003 * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 3. Neither the name of the copyright holders nor the names of 00016 * contributors may be used to endorse or promote products derived 00017 * from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00022 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00023 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00025 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00026 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00027 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00028 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00029 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 * For additional information see http://www.ethernut.de/ 00033 */ 00034 00044 #include <cfg/memory.h> 00045 00046 #include <dev/blockdev.h> 00047 #include <dev/spi_at45d.h> 00048 00049 #ifndef SPI_RATE_AT45D3 00050 #define SPI_RATE_AT45D3 1000000 00051 #endif 00052 00053 #ifndef SPI_MODE_AT45D3 00054 #ifndef SPI_CSHIGH_AT45D3 00055 #define SPI_MODE_AT45D3 (SPI_MODE_3 | SPI_MODE_CSHIGH) 00056 #else 00057 #define SPI_MODE_AT45D3 SPI_MODE_3 00058 #endif 00059 #endif 00060 00061 #ifndef MOUNT_OFFSET_AT45D3 00062 #define MOUNT_OFFSET_AT45D3 0 00063 #endif 00064 00065 #ifndef MOUNT_TOP_RESERVE_AT45D3 00066 #define MOUNT_TOP_RESERVE_AT45D3 0 00067 #endif 00068 00072 NUTSPINODE nodeSpiAt45d3 = { 00073 NULL, 00074 NULL, 00075 SPI_RATE_AT45D3, 00076 SPI_MODE_AT45D3, 00077 8, 00078 0 00079 }; 00080 00084 static NUTBLOCKIO blkIoAt45d3 = { 00085 NULL, 00086 0, 00087 0, 00088 MOUNT_OFFSET_AT45D3, 00089 MOUNT_TOP_RESERVE_AT45D3, 00090 SpiAt45dPageRead, 00091 SpiAt45dPageWrite, 00092 #ifdef __HARVARD_ARCH__ 00093 SpiAt45dPageWrite_P, 00094 #endif 00095 SpiAt45dIOCtl 00096 }; 00097 00101 NUTDEVICE devSpiAt45d3 = { 00102 NULL, /* Pointer to next device, dev_next. */ 00103 {'A', 'T', '4', '5', 'D', '3', 0, 0, 0}, /* Unique device name, dev_name. */ 00104 IFTYP_BLKIO, /* Type of device, dev_type. */ 00105 0, /* Base address, dev_base (not used). */ 00106 0, /* First interrupt number, dev_irq (not used). */ 00107 &nodeSpiAt45d3, /* Interface control block, dev_icb. */ 00108 &blkIoAt45d3, /* Driver control block, dev_dcb. */ 00109 SpiAt45dInit, /* Driver initialization routine, dev_init. */ 00110 NutBlockDeviceIOCtl, /* Driver specific control function, dev_ioctl. */ 00111 NutBlockDeviceRead, /* Read from device, dev_read. */ 00112 NutBlockDeviceWrite, /* Write to device, dev_write. */ 00113 #ifdef __HARVARD_ARCH__ 00114 NutBlockDeviceWrite_P, /* Write data from program space to device, dev_write_P. */ 00115 #endif 00116 NutBlockDeviceOpen, /* Open a device or file, dev_open. */ 00117 NutBlockDeviceClose, /* Close a device or file, dev_close. */ 00118 NutBlockDeviceSize /* Request file size, dev_size. */ 00119 };