Nut/OS  4.10.3
API Reference
spi_at45d0.c
Go to the documentation of this file.
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_AT45D0
00050 #define SPI_RATE_AT45D0  33000000
00051 #endif
00052 
00053 #ifndef SPI_MODE_AT45D0
00054 
00055 #ifdef SPI_CSHIGH_AT45D0
00056 #define SPI_MODE_AT45D0 (SPI_MODE_3 | SPI_MODE_CSHIGH)
00057 #else
00058 #define SPI_MODE_AT45D0 SPI_MODE_3
00059 #endif
00060 
00061 #elif defined(SPI_CSHIGH_AT45D0)
00062 
00063 /* This is a tricky problem. Originally we didn't provide mode settings
00064 ** in the Configurator, but used mode 3 only. After experiencing problems
00065 ** with mode switching on the EIR, we need to set mode 0 for that board,
00066 ** which spoils our chip select polarity setting. */
00067 #if SPI_MODE_AT45D0 == SPI_MODE_0
00068 #undef SPI_MODE_AT45D0
00069 #define SPI_MODE_AT45D0 (SPI_MODE_0 | SPI_MODE_CSHIGH)
00070 #elif SPI_MODE_AT45D0 == SPI_MODE_3
00071 #undef SPI_MODE_AT45D0
00072 #define SPI_MODE_AT45D0 (SPI_MODE_3 | SPI_MODE_CSHIGH)
00073 #endif
00074 
00075 #endif /* SPI_MODE_AT45D0 */
00076 
00077 #ifndef MOUNT_OFFSET_AT45D0
00078 #define MOUNT_OFFSET_AT45D0         0
00079 #endif
00080 
00081 #ifndef MOUNT_TOP_RESERVE_AT45D0
00082 #define MOUNT_TOP_RESERVE_AT45D0    0
00083 #endif
00084 
00088 NUTSPINODE nodeSpiAt45d0 = {
00089     NULL,                       
00090     NULL,                       
00091     SPI_RATE_AT45D0,            
00092     SPI_MODE_AT45D0,            
00093     8,                          
00094     0                           
00095 };
00096 
00100 static NUTBLOCKIO blkIoAt45d0 = {
00101     NULL,                       
00102     0,                          
00103     0,                          
00104     MOUNT_OFFSET_AT45D0,        
00105     MOUNT_TOP_RESERVE_AT45D0,   
00106     SpiAt45dPageRead,           
00107     SpiAt45dPageWrite,          
00108 #ifdef __HARVARD_ARCH__
00109     SpiAt45dPageWrite_P,        
00110 #endif
00111     SpiAt45dIOCtl               
00112 };
00113 
00117 NUTDEVICE devSpiAt45d0 = {
00118     NULL,                       
00119     {'A', 'T', '4', '5', 'D', '0', 0, 0, 0},    
00120     IFTYP_BLKIO,                
00121     0,                          
00122     0,                          
00123     &nodeSpiAt45d0,             
00124     &blkIoAt45d0,               
00125     SpiAt45dInit,               
00126     NutBlockDeviceIOCtl,        
00127     NutBlockDeviceRead,         
00128     NutBlockDeviceWrite,        
00129 #ifdef __HARVARD_ARCH__
00130     NutBlockDeviceWrite_P,      
00131 #endif
00132     NutBlockDeviceOpen,         
00133     NutBlockDeviceClose,        
00134     NutBlockDeviceSize          
00135 };