SAMA5 I2S: Driver is code complete, untested and subject to some rethinking

This commit is contained in:
Gregory Nutt 2013-11-09 13:08:20 -06:00
parent f32dc8426b
commit ac120d60c3
4 changed files with 965 additions and 399 deletions

View File

@ -5999,4 +5999,6 @@
provided by David Sidrane (2013-11-7).
* configs/spark/usbserial.c: Add an apps/examples/usbserial
configuration for the Spark. From David Sidran (2013-11-7).
* arch/arm/src/sama5/sam_ssc.c and .h: First cut of SAMA5
SSC/I2S driver is code complete (2013-11-9).

View File

@ -1402,7 +1402,8 @@ config SAMA5_SSC0_DATALEN
int "Data width (bits)"
default 16
---help---
Data width in bits.
Data width in bits. This is a default value and may be change
via the I2S interface
config SAMA5_SSC0_RX
bool "Enable I2C receiver"
@ -1516,16 +1517,16 @@ endchoice # Receiver output clock
endif # !SAMA5_SSC0_TX_TKINPUT
endif # SAMA5_SSC0_TX
config SAMA5_SSC0_MCKDIV_FREQUENCY
config SAMA5_SSC0_MCKDIV_SAMPLERATE
int "Internal transmitter clock frequency"
default 100
depends on SAMA5_SSC0_RX_MCKDIV || SAMA5_SSC0_TX_MCKDIV
---help---
If the either the receiver or transmitter clock is provided by MCK/2 divided
down, then the target frequency must be provided. The SSC driver will
determine the best divider to obtain that frequency (up to 4095). If the
frequency is too low to be obtained by dividing down the MCK/2, a compile
time error will occur.
down, then the samplerate must be provided. The bitrate will be the product
of the sample rate and the data width. The SSC driver will determine the best
divider to obtain that bitrate (up to 4095). If the bitrate can be realized
by dividing down the MCK/2, a compile time error will occur.
endif # SAMA5_SSC0
@ -1542,7 +1543,8 @@ config SAMA5_SSC1_DATALEN
int "Data width (bits)"
default 16
---help---
Data width in bits.
Data width in bits. This is a default value and may be change
via the I2S interface
config SAMA5_SSC1_RX
bool "Enable I2C receiver"
@ -1656,16 +1658,16 @@ endchoice # Receiver output clock
endif # !SAMA5_SSC1_TX_TKINPUT
endif # SAMA5_SSC1_TX
config SAMA5_SSC1_MCKDIV_FREQUENCY
config SAMA5_SSC1_MCKDIV_SAMPLERATE
int "Internal transmitter clock frequency"
default 100
depends on SAMA5_SSC1_RX_MCKDIV || SAMA5_SSC1_TX_MCKDIV
---help---
If the either the receiver or transmitter clock is provided by MCK/2 divided
down, then the target frequency must be provided. The SSC driver will
determine the best divider to obtain that frequency (up to 4095). If the
frequency is too low to be obtained by dividing down the MCK/2, a compile
time error will occur.
down, then the samplerate must be provided. The bitrate will be the product
of the sample rate and the data width. The SSC driver will determine the best
divider to obtain that bitrate (up to 4095). If the bitrate can be realized
by dividing down the MCK/2, a compile time error will occur.
endif # SAMA5_SSC1

File diff suppressed because it is too large Load Diff

View File

@ -51,59 +51,45 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Access macros ************************************************************/
/****************************************************************************
* Name: I2S_FREQUENCY
* Name: I2S_RXSAMPLERATE
*
* Description:
* Set the I2S frequency. Required.
* Set the I2S RX sample rate. NOTE: This will have no effect if (1) the
* driver does not support an I2C receiver or if (2) the sample rate is
* driven by the I2C frame clock. This may also have unexpected side-
* effects of the RX sample is coupled with the TX sample rate.
*
* Input Parameters:
* dev - Device-specific state data
* frequency - The I2S frequency requested
* dev - Device-specific state data
* rate - The I2S sample rate in samples (not bits) per second
*
* Returned Value:
* Returns the actual frequency selected
* Returns the resulting bitrate
*
****************************************************************************/
#define I2S_FREQUENCY(d,f) ((d)->ops->i2s_frequency(d,f))
#define I2S_RXSAMPLERATE(d,f) ((d)->ops->i2s_rxsamplerate(d,r))
/****************************************************************************
* Name: I2S_SEND
* Name: I2S_RXDATAWIDTH
*
* Description:
* Send a block of data on I2S.
* Set the I2S RX data width. The RX bitrate is determined by
* sample_rate * data_width.
*
* Input Parameters:
* dev - Device-specific state data
* buffer - A pointer to the buffer of data to be sent
* nbytes - the length of data to send from the buffer in number of bytes.
* callback - A user provided callback function that will be called at
* the completion of the transfer. The callback will be
* performed in the context of the worker thread.
* arg - An opaque argument that will be provided to the callback
* when the transfer complete.
* timeout - The timeout value to use. The transfer will be canceled
* and an ETIMEDOUT error will be reported if this timeout
* elapsed without completion of the DMA transfer. Units
* are system clock ticks. Zero means no timeout.
* dev - Device-specific state data
* width - The I2S data with in bits.
*
* Returned Value:
* OK on success; a negated errno value on failure. NOTE: This function
* only enqueues the transfer and returns immediately. Success here only
* means that the transfer was enqueued correctly.
*
* When the transfer is complete, a 'result' value will be provided as
* an argument to the callback function that will indicate if the transfer
* failed.
* Returns the resulting bitrate
*
****************************************************************************/
#define I2S_SEND(d,b,n,c,a,t) ((d)->ops->i2s_send(d,b,n,c,a,t))
#define I2S_RXDATAWIDTH(d,b) ((d)->ops->i2s_rxdatawidth(d,b))
/****************************************************************************
* Name: I2S_RECEIVE
@ -139,6 +125,77 @@
#define I2S_RECEIVE(d,b,n,c,a,t) ((d)->ops->i2s_receive(d,b,n,c,a,t))
/****************************************************************************
* Name: I2S_TXSAMPLERATE
*
* Description:
* Set the I2S TX sample rate. NOTE: This will have no effect if (1) the
* driver does not support an I2C transmitter or if (2) the sample rate is
* driven by the I2C frame clock. This may also have unexpected side-
* effects of the TX sample is coupled with the RX sample rate.
*
* Input Parameters:
* dev - Device-specific state data
* rate - The I2S sample rate in samples (not bits) per second
*
* Returned Value:
* Returns the resulting bitrate
*
****************************************************************************/
#define I2S_TXSAMPLERATE(d,f) ((d)->ops->i2s_txsamplerate(d,r))
/****************************************************************************
* Name: I2S_TXDATAWIDTH
*
* Description:
* Set the I2S TX data width. The TX bitrate is determined by
* sample_rate * data_width.
*
* Input Parameters:
* dev - Device-specific state data
* width - The I2S data with in bits.
*
* Returned Value:
* Returns the resulting bitrate
*
****************************************************************************/
#define I2S_TXDATAWIDTH(d,b) ((d)->ops->i2s_txdatawidth(d,b))
/****************************************************************************
* Name: I2S_SEND
*
* Description:
* Send a block of data on I2S.
*
* Input Parameters:
* dev - Device-specific state data
* buffer - A pointer to the buffer of data to be sent
* nbytes - the length of data to send from the buffer in number of bytes.
* callback - A user provided callback function that will be called at
* the completion of the transfer. The callback will be
* performed in the context of the worker thread.
* arg - An opaque argument that will be provided to the callback
* when the transfer complete.
* timeout - The timeout value to use. The transfer will be canceled
* and an ETIMEDOUT error will be reported if this timeout
* elapsed without completion of the DMA transfer. Units
* are system clock ticks. Zero means no timeout.
*
* Returned Value:
* OK on success; a negated errno value on failure. NOTE: This function
* only enqueues the transfer and returns immediately. Success here only
* means that the transfer was enqueued correctly.
*
* When the transfer is complete, a 'result' value will be provided as
* an argument to the callback function that will indicate if the transfer
* failed.
*
****************************************************************************/
#define I2S_SEND(d,b,n,c,a,t) ((d)->ops->i2s_send(d,b,n,c,a,t))
/****************************************************************************
* Public Types
****************************************************************************/
@ -152,13 +209,21 @@ typedef CODE void (*i2s_callback_t)(FAR struct i2s_dev_s *dev,
struct i2s_dev_s;
struct i2s_ops_s
{
uint32_t (*i2s_frequency)(FAR struct i2s_dev_s *dev, uint32_t frequency);
int (*i2s_send)(FAR struct i2s_dev_s *dev, FAR const void *buffer,
size_t nbytes, i2s_callback_t callback,
FAR void *arg, uint32_t timeout);
/* Receiver methods */
uint32_t (*i2s_rxsamplerate)(FAR struct i2s_dev_s *dev, uint32_t rate);
uint32_t (*i2s_rxdatawidth)(FAR struct i2s_dev_s *dev, int bits);
int (*i2s_receive)(FAR struct i2s_dev_s *dev, FAR void *buffer,
size_t nbytes, i2s_callback_t callback,
FAR void *arg, uint32_t timeout);
size_t nbytes, i2s_callback_t callback, FAR void *arg,
uint32_t timeout);
/* Transmitter methods */
uint32_t (*i2s_txsamplerate)(FAR struct i2s_dev_s *dev, uint32_t rate);
uint32_t (*i2s_txdatawidth)(FAR struct i2s_dev_s *dev, int bits);
int (*i2s_send)(FAR struct i2s_dev_s *dev, FAR const void *buffer,
size_t nbytes, i2s_callback_t callback, FAR void *arg,
uint32_t timeout);
};
/* I2S private data. This structure only defines the initial fields of the