Nut/OS  4.10.3
API Reference
spibus.h
Go to the documentation of this file.
00001 #ifndef _DEV_SPIBUS_H_
00002 #define _DEV_SPIBUS_H_
00003 /*
00004  * Copyright (C) 2008-2009 by egnite GmbH
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
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of the copyright holders nor the names of
00018  *    contributors may be used to endorse or promote products derived
00019  *    from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00028  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00029  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00031  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * For additional information see http://www.ethernut.de/
00035  */
00036 
00046 #include <dev/irqreg.h>
00047 #include <sys/device.h>
00048 #include <sys/event.h>
00049 
00050 #define SPI_CURRENT_MODE    ((uint16_t)-1)
00051 
00052 #define SPI_MODE_CPHA       0x0001  /* Data updated on leading edge. */
00053 #define SPI_MODE_CPOL       0x0002  /* Idle clock is high. */
00054 #define SPI_MODE_FAULT      0x0004  /* Enables mode fault detection. */
00055 #define SPI_MODE_LOOPBACK   0x0400  /* Loopback mode. */
00056 #define SPI_MODE_SLAVE      0x0800  /* Slave mode. */
00057 #define SPI_MODE_CSKEEP     0x1000  /* Chip select remains active after transfer. */
00058 #define SPI_MODE_CSDEC      0x2000  /* Decoded chip selects. */
00059 #define SPI_MODE_CSHIGH     0x4000  /* Chip select is high active. */
00060 #define SPI_MODE_UPDATE     0x8000  /* Mode update required. */
00061 
00062 #define SPI_MODE_0          0x0000
00063 #define SPI_MODE_1          SPI_MODE_CPHA
00064 #define SPI_MODE_2          SPI_MODE_CPOL
00065 #define SPI_MODE_3          (SPI_MODE_CPOL | SPI_MODE_CPHA)
00066 
00067 
00068 #define SPI_CURRENT_RATE    ((uint32_t)-1)
00069 
00070 #define SPI_CURRENT_BITS    ((uint8_t)-1)
00071 
00072 
00073 typedef struct _NUTSPIBUS NUTSPIBUS;
00074 typedef struct _NUTSPINODE NUTSPINODE;
00075 
00079 struct _NUTSPIBUS {
00082     HANDLE bus_mutex;
00083 
00086     HANDLE bus_ready;
00087 
00090     uintptr_t bus_base;
00091 
00094     IRQ_HANDLER *bus_sig;
00095 
00100     int (*bus_initnode) (NUTSPINODE *);
00101 
00106     int (*bus_alloc) (NUTSPINODE *, uint32_t);
00107 
00112     int (*bus_release) (NUTSPINODE *);
00113 
00116     int (*bus_transfer) (NUTSPINODE *, CONST void *, void *, int);
00117 
00120     int (*bus_wait) (NUTSPINODE *, uint32_t);
00121 
00124     uint_fast16_t (*bus_set_mode) (NUTSPINODE *, uint_fast16_t);
00125 
00128      uint_fast32_t (*bus_set_rate) (NUTSPINODE *, uint_fast32_t);
00129 
00132      uint_fast8_t (*bus_set_bits) (NUTSPINODE *, uint_fast8_t);
00133 };
00134 
00138 struct _NUTSPINODE {
00143     NUTSPIBUS *node_bus;
00144 
00149     void *node_stat;
00150 
00155     uint_fast32_t node_rate;
00156 
00161     uint_fast16_t node_mode;
00162 
00167     uint_fast8_t node_bits;
00168 
00173     uint_fast8_t node_cs;
00174 
00179     void *node_dcb;
00180 };
00181 
00182 __BEGIN_DECLS
00183 /* Prototypes */
00184 extern int NutRegisterSpiDevice(NUTDEVICE * dev, NUTSPIBUS * bus, int cs);
00185 extern uint_fast16_t NutSpiBusSetMode(NUTSPINODE * node, uint_fast16_t mode);
00186 extern uint_fast32_t NutSpiBusSetRate(NUTSPINODE * node, uint_fast32_t rate);
00187 extern uint_fast8_t NutSpiBusSetBits(NUTSPINODE * node, uint_fast8_t bits);
00188 extern int NutSpiBusWait(NUTSPINODE * node, uint32_t tmo);
00189 /* Prototypes */
00190 __END_DECLS
00191 #endif