diff --git a/ChangeLog b/ChangeLog index 8893499c99..37a4b8cd75 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10789,3 +10789,11 @@ * drivers/sensors/lm92.c and include/nuttx/sensors/lm92.h: Add a driver for the LM92 temperature sensor. Contributed by Paul Patience (2015-08-06). + * drivers/sensors/as5048b.c and include/nuttx/sensors/as5048b.h: Add + support for an AS5048B rotary magnetic sensor. From Paul Patience + (2015-08-06). + * include/nuttx/spi/slave.h: Add a definition of an SPI slave + interface (2015-08-08). + * arch/arm/src/samv7: Add the framework for an SPI slave drvier. This + driver has a lot of missing logic on initial commit (2015-08-09). + diff --git a/arch b/arch index 5102f81589..1efba67cba 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5102f815891b899f87a718ab85d3913015a015ea +Subproject commit 1efba67cba08b28a2a4a1a4649daf2df93b2d596 diff --git a/configs b/configs index abab21dfa5..ac4035687c 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit abab21dfa553656a0ce40423931a2af2c61f3466 +Subproject commit ac4035687c824bb4a573e06feb017cb4f3ce7626 diff --git a/drivers/can.c b/drivers/can.c index f1eb4d195a..f37557205b 100644 --- a/drivers/can.c +++ b/drivers/can.c @@ -911,10 +911,14 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, if (msg && hdr->ch_id == rtr->cr_id) { + int nbytes; + /* We have the response... copy the data to the user's buffer */ memcpy(&msg->cm_hdr, hdr, sizeof(struct can_hdr_s)); - for (i = 0, dest = msg->cm_data; i < hdr->ch_dlc; i++) + + nbytes = can_dlc2bytes(hdr->ch_dlc); + for (i = 0, dest = msg->cm_data; i < nbytes; i++) { *dest++ = *data++; } @@ -935,6 +939,8 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, if (nexttail != fifo->rx_head) { + int nbytes; + /* Add the new, decoded CAN message at the tail of the FIFO. * * REVISIT: In the CAN FD format, the coding of the DLC differs from @@ -946,7 +952,9 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, */ memcpy(&fifo->rx_buffer[fifo->rx_tail].cm_hdr, hdr, sizeof(struct can_hdr_s)); - for (i = 0, dest = fifo->rx_buffer[fifo->rx_tail].cm_data; i < hdr->ch_dlc; i++) + + nbytes = can_dlc2bytes(hdr->ch_dlc); + for (i = 0, dest = fifo->rx_buffer[fifo->rx_tail].cm_data; i < nbytes; i++) { *dest++ = *data++; } diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 6bef9b5694..488c08c251 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -5,6 +5,23 @@ if SPI +config SPI_SLAVE + bool "SPI slave" + default n + ---help--- + Enable support for SPI slave features + +if SPI_SLAVE + +config SPI_SLAVE_DMA + bool "SPI slave DMA" + default n + depends on ARCH_DMA && EXPERIMENTAL + ---help--- + Enable support for DMA data transfers (not yet implemented). + +endif + config SPI_OWNBUS bool "SPI single device" default n diff --git a/include/nuttx/can.h b/include/nuttx/can.h index 2787750ace..3235b9de54 100644 --- a/include/nuttx/can.h +++ b/include/nuttx/can.h @@ -91,27 +91,7 @@ # define CONFIG_CAN_NPENDINGRTR 255 #endif -/* Convenience macros */ - -#define dev_reset(dev) dev->cd_ops->co_reset(dev) -#define dev_setup(dev) dev->cd_ops->co_setup(dev) -#define dev_shutdown(dev) dev->cd_ops->co_shutdown(dev) -#define dev_txint(dev,enable) dev->cd_ops->co_txint(dev,enable) -#define dev_rxint(dev,enable) dev->cd_ops->co_rxint(dev,enable) -#define dev_ioctl(dev,cmd,arg) dev->cd_ops->co_ioctl(dev,cmd,arg) -#define dev_remoterequest(dev,id) dev->cd_ops->co_remoterequest(dev,id) -#define dev_send(dev,m) dev->cd_ops->co_send(dev,m) -#define dev_txready(dev) dev->cd_ops->co_txready(dev) -#define dev_txempty(dev) dev->cd_ops->co_txempty(dev) - -/* CAN message support */ - -#define CAN_MAXDATALEN 8 -#define CAN_MAX_MSGID 0x07ff -#define CAN_MAX_EXTMSGID 0x1fffffff - -#define CAN_MSGLEN(nbytes) (sizeof(struct can_msg_s) - CAN_MAXDATALEN + (nbytes)) - +/* Ioctl Commands *******************************************************************/ /* Ioctl commands supported by the upper half CAN driver. * * CANIOC_RTR: @@ -167,29 +147,70 @@ #define CANIOC_USER _CANIOC(6) +/* Convenience macros ***************************************************************/ + +#define dev_reset(dev) dev->cd_ops->co_reset(dev) +#define dev_setup(dev) dev->cd_ops->co_setup(dev) +#define dev_shutdown(dev) dev->cd_ops->co_shutdown(dev) +#define dev_txint(dev,enable) dev->cd_ops->co_txint(dev,enable) +#define dev_rxint(dev,enable) dev->cd_ops->co_rxint(dev,enable) +#define dev_ioctl(dev,cmd,arg) dev->cd_ops->co_ioctl(dev,cmd,arg) +#define dev_remoterequest(dev,id) dev->cd_ops->co_remoterequest(dev,id) +#define dev_send(dev,m) dev->cd_ops->co_send(dev,m) +#define dev_txready(dev) dev->cd_ops->co_txready(dev) +#define dev_txempty(dev) dev->cd_ops->co_txempty(dev) + +/* CAN message support **************************************************************/ + +#ifdef CONFIG_CAN_FD +# define CAN_MAXDATALEN 64 +#else +# define CAN_MAXDATALEN 8 +#endif + +#define CAN_MAX_STDMSGID 0x07ff +#define CAN_MAX_EXTMSGID 0x1fffffff + +#define CAN_MSGLEN(nbytes) (sizeof(struct can_msg_s) - CAN_MAXDATALEN + (nbytes)) + +/* CAN filter support ***************************************************************/ +/* Some CAN hardware supports a notion of prioritizing messages that match filters. + * Only two priority levels are currently supported and are encoded as defined + * below: + */ + +#define CAN_MSGPRIO_LOW 0 +#define CAN_MSGPRIO_HIGH 1 + +/* Filter type. Not all CAN hardware will support all filter types. */ + +#define CAN_FILTER_MASK 0 /* Address match under a mask */ +#define CAN_FILTER_DUAL 1 /* Dual address match */ +#define CAN_FILTER_RANGE 2 /* Match a range of addresses */ + /************************************************************************************ * Public Types ************************************************************************************/ -/* CAN-message Format (without Extended ID suppport) +/* CAN-message Format (without Extended ID support) * * One based CAN-message is represented with a maximum of 10 bytes. A message is * composed of at least the first 2 bytes (when there are no data bytes present). * * Bytes 0-1: Hold a 16-bit value in host byte order * Bits 0-3: Data Length Code (DLC) - * Bit 4: Remote Tranmission Request (RTR) + * Bit 4: Remote Transmission Request (RTR) * Bits 5-15: The 11-bit CAN identifier * * Bytes 2-9: CAN data * - * CAN-message Format (with Extended ID suppport) + * CAN-message Format (with Extended ID support) * * One CAN-message consists of a maximum of 13 bytes. A message is composed of at * least the first 5 bytes (when there are no data bytes). * * Bytes 0-3: Hold 11- or 29-bit CAN ID in host byte order * Byte 4: Bits 0-3: Data Length Code (DLC) - * Bit 4: Remote Tranmission Request (RTR) + * Bit 4: Remote Transmission Request (RTR) * Bit 5: Extended ID indication * Bits 6-7: Unused * Bytes 5-12: CAN data @@ -350,14 +371,22 @@ struct canioc_rtr_s #ifdef CONFIG_CAN_EXTID struct canioc_extfilter_s { - uint32_t xf_id; /* 29-bit ID (3-bits unused) */ - uint32_t xf_mask; /* 29-bit address mask (3-bits unused) */ + uint32_t xf_id1; /* 29-bit ID. For dual match or for the + * lower address in a range of addresses */ + uint32_t xf_id2; /* 29-bit ID. For dual match, address mask + * or for upper address in address range */ + uint8_t xf_type; /* See CAN_FILTER_* definitions */ + uint8_t xf_prio; /* See CAN_MSGPRIO_* definitions */ }; #else struct canioc_stdfilter_s { - uint16_t sf_id; /* 11-bit ID (5-bits unused) */ - uint16_t sf_mask; /* 11-bit address mask (5-bits unused) */ + uint16_t sf_id1; /* 11-bit ID. For dual match or for the + * lower address in a range of addresses */ + uint16_t sf_id2; /* 11-bit ID. For dual match, address mask + * or for upper address in address range */ + uint8_t sf_type; /* See CAN_FILTER_* definitions */ + uint8_t sf_prio; /* See CAN_MSGPRIO_* definitions */ }; #endif diff --git a/include/nuttx/spi/slave.h b/include/nuttx/spi/slave.h new file mode 100644 index 0000000000..f57493fa53 --- /dev/null +++ b/include/nuttx/spi/slave.h @@ -0,0 +1,474 @@ +/**************************************************************************** + * include/nuttx/spi/slave.h + * + * Copyright(C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SPI_SLAVE_H +#define __INCLUDE_NUTTX_SPI_SLAVE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* CONFIG_SPI_SLAVE - Enable support for SPI slave features + * CONFIG_SPI_SLAVE_DMA - Enable support for DMA data transfers (not + * implemented in initial version). + */ + +/* Access macros ************************************************************/ + +/**************************************************************************** + * Name: SPI_SCTRLR_BIND + * + * Description: + * Bind the SPI slave device interface to the SPI slave controller + * interface and configure the SPI interface. Upon return, the SPI + * slave controller driver is fully operational and ready to perform + * transfers. + * + * Input Parameters: + * sctrlr - SPI slave controller interface instance + * sdev - SPI slave device interface instance + * mode - The SPI mode requested + * nbits - The number of bits requests. + * If value is greater > 0 then it implies MSB first + * If value is below < 0, then it implies LSB first with -nbits + * + * Returned Value: + * none + * + ****************************************************************************/ + +#define SPI_SCTRLR_BIND(c,d,m,n) ((c)->ops->bind(c,d,m,n)) + +/**************************************************************************** + * Name: SPI_SCTRLR_UNBIND + * + * Description: + * Un-bind the SPI slave device interface from the SPI slave controller + * interface. Reset the SPI interface and restore the SPI slave + * controller driver to its initial state, + * + * Input Parameters: + * sctrlr - SPI slave controller interface instance + * + * Returned Value: + * none + * + ****************************************************************************/ + +#define SPI_SCTRLR_UNBIND(c) ((c)->ops->unbind(c)) + +/**************************************************************************** + * Name: SPI_SCTRLR_ENQUEUE + * + * Description: + * Enqueue the next value to be shifted out from the interface. This adds + * the word the controller driver for a subsequent transfer but has no + * effect on any in-process or currently "committed" transfers + * + * Input Parameters: + * sctrlr - SPI slave controller interface instance + * data - Command/data mode data value to be shifted out. The width of + * the data must be the same as the nbits parameter previously + * provided to the bind() methods. + * + * Returned Value: + * Zero if the word was successfully queue; A negated errno valid is + * returned on any failure to enqueue the word (such as if the queue is + * full). + * + ****************************************************************************/ + +#define SPI_SCTRLR_ENQUEUE(c,v) ((c)->ops->enqueue(c,v)) + +/**************************************************************************** + * Name: SPI_SCTRLR_QFULL + * + * Description: + * Return true if the queue is full or false if there is space to add an + * additional word to the queue. + * + * Input Parameters: + * sctrlr - SPI slave controller interface instance + * + * Returned Value: + * true if the output wueue is full + * + ****************************************************************************/ + +#define SPI_SCTRLR_QFULL(c) ((c)->ops->qfull(c)) + +/**************************************************************************** + * Name: SPI_SCTRLR_QFLUSH + * + * Description: + * Discard all saved values in the output queue. On return from this + * function the output queue will be empty. Any in-progress or otherwise + * "committed" output values may not be flushed. + * + * Input Parameters: + * sctrlr - SPI slave controller interface instance + * + * Returned Value: + * None + * + ****************************************************************************/ + +#define SPI_SCTRLR_QFLUSH(c) ((c)->ops->qflush(c)) + +/**************************************************************************** + * Name: SPI_SDEV_SELECT + * + * Description: + * This is a SPI device callback that used when the SPI device controller + * driver detects any change in the chip select pin. + * + * Input Parameters: + * sdev - SPI device interface instance + * selected - True: chip select is low (selected); + * + * Returned Value: + * none + * + * Assumptions: + * May be called from an interrupt handler. + * + ****************************************************************************/ + +#define SPI_SDEV_SELECT(d,s) ((c)->ops->select(d,s)) + +/**************************************************************************** + * Name: SPI_SDEV_CMDDATA + * + * Description: + * This is a SPI device callback that used when the SPI device controller + * driver detects any change command/data condition. + * + * Normally only LCD devices distinguish command and data. For devices + * that do not distinguish between command and data, this method may be + * a stub.; For devices that do make that distinction, they should treat + * all subsequent calls to enqueue() or rece() appropriately for the + * current command/data selection. + * + * Input Parameters: + * sdev - SPI device interface instance + * data - True: Data is selected + * + * Returned Value: + * none + * + * Assumptions: + * May be called from an interrupt handler. + * + ****************************************************************************/ + +#define SPI_SDEV_CMDDATA(d,i) ((d)->ops->cmddata(d,i)) + +/**************************************************************************** + * Name: SPI_SDEV_GETDATA + * + * Description: + * This is a SPI device callback that used when the SPI device controller + * requires data be shifted out at the next leading clock edge. This + * is necessary to "prime the pump" so that the SPI controller driver + * can keep pace with the shifted-in data. + * + * The SPI controller driver will prime for both command and data + * transfers as determined by a preceding call to the device cmddata() + * method. Normally only LCD devices distinguish command and data. + * + * Input Parameters: + * sdev - SPI device interface instance + * + * Returned Value: + * The next data value to be shifted out + * + * Assumptions: + * May be called from an interrupt handler. + * + ****************************************************************************/ + +#define SPI_SDEV_GETDATA(d) ((d)->ops->getdata(d)) + +/**************************************************************************** + * Name: SPI_SDEV_RECEIVE + * + * Description: + * This is a SPI device callback that used when the SPI device controller + * receives a new value shifted in and requires the next value to be + * shifted out. Notice that these values my be out of synchronization by + * several words. + * + * Input Parameters: + * sdev - SPI device interface instance + * data - The last command/data value that was shifted in + * + * Returned Value: + * None + * + * Assumptions: + * May be called from an interrupt handler. + * + ****************************************************************************/ + +#define SPI_SDEV_RECEIVE(d,v) ((d)->ops->receive(d,v)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* There are two interfaces defined for the implementation of SPI slave: + * + * 1) struct spi_sctrlr_s: Defines one interface between the SPI + * slave device and the SPI slave controller hardware. This interface + * is implemented by the SPI slave device controller lower-half driver + * and is provided to the the SPI slave device driver when that driver + * is initialized. That SPI slave device initialization function has + * the prototype: + * + * FAR struct spi_sctrlr_s *up_spi_slave_initialize(int port); + * + * Given an SPI port number, this function returns an instance of the + * SPI slave controller interface. + * + * 2) struct spi_sdev_s: Defines the second interface between the SPI + * slave device and the SPI slave controller hardware. This interface + * is implemented by the SPI slave device. The slave device passes this + * interface to the struct spi_sctrlr_s during initialization + * be calling the bind() method of the struct spi_sctrlr_s + * interface. + * + * The basic initialization steps are: + * + * 1) Board-specific logic calls board- or chip-specific logic to create an + * instance of the SPI slave controller interface, struct spi_sctrlr_s. + * + * 2) Board-specific logic then calls up_dev_initialize() to initialize + * the SPI slave device. The board-specific logic passes the instance + * of struct spi_sctrlr_s to support the initialization. + * + * 3) The SPI slave device driver creates and initializes an instance of + * struct spi_sdev_s; it passes this instance to the bind() method of + * of the SPI slave controller interface. + * + * 4) The SPI slave controller will (1) call the slaved device's select() + * and cmddata() methods to indicate the initial state of the chip select + * and any command/data selection, then (2) call the slave device's + * getdata() method to get the value that will be shifted out the SPI + * clock is detected. The kind of data returned the getdata() method + * may be contingent on the current command/data setting reported the + * device cmddata() method. The driver may enqueue additional words + * to be shifted out at any time by The calling the SPI slave + * controller's enqueue() method. + * + * 5) Upon return from the bind method, the SPI slave controller will be + * fully "armed" and ready to begin normal SPI data transfers. + * + * A typical (non-DMA) data transfer proceeds as follows: + * + * 1) Internally, the SPI slave driver detects that the SPI chip select + * has gone low, selecting this device for data transfer. The SPI + * slave controller will notify the slave device by called its + * select() method. + * + * 2) If a change in the command/data state changes any time before, + * during, or after the chip is selected, that new command/data state + * will reported to the device driver via the cmddata() method. + * + * 3) As the first word is shifted in, the command or data word obtained + * by the initial call to getdata() will be shifted out. As soon as + * the clock is detected, the SPI controller driver will call the + * getdata() method again to get a default second word to be shifted + * out. NOTES: (1) the SPI slave device has only one word in bit + * times to provide this value! (2) The SPI device probably cannot + * really output anything meaning until it receives a decodes the + * first word received from the master. + * + * 4) When the first word from the master is shifted in, the SPI + * controller driver will call the device's receive() method to + * provide the master with the command word that was just shifted + * in. + * + * For the case of bi-directional data transfer or of a transfer of + * data from the SPI device to the master, the SPI device driver + * should call the controller's enqueue() method to provide the next + * value(s) to be shifted out. If the SPI device responds with this + * value before clocking begins for the next word, that that value + * will be used. Otherwise, the value obtained from getdata() in + * step 3 will be shifted out. + * + * 5) The SPI device's receive() method will be called in a similar + * way after each subsequent word is clocked in. + * + * For the case of bi-directional data transfer or of a uni-directional + * transfer of data from the SPI device to the master, the SPI device + * driver can call the enqueue() methods as it has new data to be shifted + * out. The goal of the SPI device driver for this kind of transfer is + * to supply valid output data at such a rate that data underruns do not + * occur. In the event of a data underrun, the SPI slave controller + * driver will fallback to the default output value obtained from the + * last getdata() call. + * + * The SPI device driver can detect if there is space to enqueue + * additional data by calling the qfull() method. + * + * For the case of uni-directional transfer of data from the master to + * the SPI device, there is no need to call the enqueue() method at all; + * the value that is shifted out is not important that fallback behavior + * is suficient. + * + * 6) The activity of 5) will continue until the master raises the chip + * select signal. In that case, the SPI slave controller driver will + * again call the SPI device's select() method. At this point, the SPI + * controller driver may have several words enqueued. It will not + * discard these unless the SPI device driver calls the qflush() + * method. + * + * Some master side implementations may simply tie the chip select signal + * to ground if there are no other devices on the SPI bus. In that case, + * the initial indication of chip selected will be the only call to the + * select() method that is made. + * + * A typical DMA data transfer processes as follows: + * To be provided + */ + +enum spi_smode_e +{ + SPISLAVE_MODE0 = 0, /* CPOL=0 CHPHA=0 */ + SPISLAVE_MODE1, /* CPOL=0 CHPHA=1 */ + SPISLAVE_MODE2, /* CPOL=1 CHPHA=0 */ + SPISLAVE_MODE3 /* CPOL=1 CHPHA=1 */ +}; + +/* The SPI slave controller driver vtable */ + +struct spi_sctrlr_s; /* Forward reference */ +struct spi_sdev_s; /* Forward reference */ + +struct spi_sctrlrops_s +{ + CODE void (*bind)(FAR struct spi_sctrlr_s *sctrlr, + FAR struct spi_sdev_s *sdev, enum spi_smode_e mode, + int nbits); + CODE void (*unbind)(FAR struct spi_sctrlr_s *sctrlr); + CODE int (*enqueue)(FAR struct spi_sctrlr_s *sctrlr, uint16_t data); + CODE bool (*qfull)(FAR struct spi_sctrlr_s *sctrlr); + CODE void (*qflush)(FAR struct spi_sctrlr_s *sctrlr); +}; + +/* SPI slave controller private data. This structure only defines the + * initial fields of the structure visible to the SPI device driver. The + * specific implementation may add additional, device specific fields after + * the vtable structure pointer. + */ + +struct spi_sctrlr_s +{ + FAR const struct spi_sctrlrops_s *ops; + + /* Private SPI slave controller driver data may follow */ +}; + +/* The SPI slave device driver vtable */ + +struct spi_sdevops_s +{ + CODE void (*select)(FAR struct spi_sdev_s *sdev, bool selected); + CODE void (*cmddata)(FAR struct spi_sdev_s *sdev, bool data); + CODE uint16_t (*getdata)(FAR struct spi_sdev_s *sdev); + CODE void (*receive)(FAR struct spi_sdev_s *sdev, uint16_t cmd); +}; + +/* SPI slave device private data. This structure only defines the initial + * fields of the structure visible to the SPI slave controller driver. The + * specific implementation may add additional, device specific fields after + * the vtable structure pointer. + */ + +struct spi_sdev_s +{ + FAR const struct spi_sdevops_s *ops; + + /* Private SPI slave device driver data may follow */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_spi_slave_initialize + * + * Description: + * Initialize the selected SPI port in slave mode. + * + * Input Parameter: + * port - Chip select number identifying the "logical" SPI port. Includes + * encoded port and chip select information. + * + * Returned Value: + * Valid SPI device structure reference on success; a NULL on failure + * + ****************************************************************************/ + +FAR struct spi_sctrlr_s *up_spi_slave_initialize(int port); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __INCLUDE_NUTTX_SPI_SLAVE_H */ diff --git a/include/nuttx/spi/spi.h b/include/nuttx/spi/spi.h index 544afaa3ca..2a6e25ed03 100644 --- a/include/nuttx/spi/spi.h +++ b/include/nuttx/spi/spi.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/spi/spi.h * - * Copyright(C) 2008-2013 Gregory Nutt. All rights reserved. + * Copyright(C) 2008-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -271,7 +271,7 @@ * * Input Parameters: * dev - Device-specific state data - * buffer - A pointer to the buffer in which to recieve data + * buffer - A pointer to the buffer in which to receive data * nwords - the length of data that can be received in the buffer in number * of words. The wordsize is determined by the number of bits- * per-word selected for the SPI interface. If nbits <= 8, the @@ -298,7 +298,7 @@ * Input Parameters: * dev - Device-specific state data * txbuffer - A pointer to the buffer of data to be sent - * rxbuffer - A pointer to the buffer in which to recieve data + * rxbuffer - A pointer to the buffer in which to receive data * nwords - the length of data that to be exchanged in units of words. * The wordsize is determined by the number of bits-per-word * selected for the SPI interface. If nbits <= 8, the data is @@ -324,7 +324,7 @@ * * Input Parameters: * dev - Device-specific state data - * callback - The funtion to call on the media change + * callback - The function to call on the media change * arg - A caller provided value to return with the callback * * Returned Value: @@ -367,7 +367,7 @@ enum spi_dev_e SPIDEV_USER /* Board-specific values start here */ }; -/* Certain SPI devices may required differnt clocking modes */ +/* Certain SPI devices may required different clocking modes */ enum spi_mode_e { @@ -383,29 +383,31 @@ struct spi_dev_s; struct spi_ops_s { #ifndef CONFIG_SPI_OWNBUS - int (*lock)(FAR struct spi_dev_s *dev, bool lock); + CODE int (*lock)(FAR struct spi_dev_s *dev, bool lock); #endif - void (*select)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, - bool selected); - uint32_t (*setfrequency)(FAR struct spi_dev_s *dev, uint32_t frequency); - void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode); - void (*setbits)(FAR struct spi_dev_s *dev, int nbits); - uint8_t (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); + CODE void (*select)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, + bool selected); + CODE uint32_t (*setfrequency)(FAR struct spi_dev_s *dev, uint32_t frequency); + CODE void (*setmode)(FAR struct spi_dev_s *dev, enum spi_mode_e mode); + CODE void (*setbits)(FAR struct spi_dev_s *dev, int nbits); + CODE uint8_t (*status)(FAR struct spi_dev_s *dev, enum spi_dev_e devid); #ifdef CONFIG_SPI_CMDDATA - int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); + CODE int (*cmddata)(FAR struct spi_dev_s *dev, enum spi_dev_e devid + bool cmd); #endif - uint16_t (*send)(FAR struct spi_dev_s *dev, uint16_t wd); + CODE uint16_t (*send)(FAR struct spi_dev_s *dev, uint16_t wd); #ifdef CONFIG_SPI_EXCHANGE - void (*exchange)(FAR struct spi_dev_s *dev, FAR const void *txbuffer, - FAR void *rxbuffer, size_t nwords); + CODE void (*exchange)(FAR struct spi_dev_s *dev, + FAR const void *txbuffer, FAR void *rxbuffer, + size_t nwords); #else - void (*sndblock)(FAR struct spi_dev_s *dev, FAR const void *buffer, - size_t nwords); - void (*recvblock)(FAR struct spi_dev_s *dev, FAR void *buffer, - size_t nwords); + CODE void (*sndblock)(FAR struct spi_dev_s *dev, + FAR const void *buffer, size_t nwords); + CODE void (*recvblock)(FAR struct spi_dev_s *dev, FAR void *buffer, + size_t nwords); #endif - int (*registercallback)(FAR struct spi_dev_s *dev, spi_mediachange_t callback, - void *arg); + CODE int (*registercallback)(FAR struct spi_dev_s *dev, + spi_mediachange_t callback, void *arg); }; /* SPI private data. This structure only defines the initial fields of the @@ -435,7 +437,7 @@ extern "C" * Name: up_spiinitialize * * Description: - * Initialize the selected SPI port. + * Initialize the selected SPI port in master mode. * * This is a generic prototype for the SPI initialize logic. Specific * architectures may support different SPI initialization functions if, @@ -454,14 +456,14 @@ extern "C" * * Another example would be the STM32 families that support both SPI * blocks as well as USARTs that can be configured to perform the SPI - * function as well (the STM32 USARTs do not suppor SPI as of this + * function as well (the STM32 USARTs do not support SPI as of this * writing). * * Input Parameter: - * Port number (for hardware that has mutiple SPI interfaces) + * Port number (for hardware that has multiple SPI interfaces) * * Returned Value: - * Valid SPI device structure reference on succcess; a NULL on failure + * Valid SPI device structure reference on success; a NULL on failure * ****************************************************************************/