Skip to content

Commit

Permalink
Adding support for SPI mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilson committed Apr 12, 2016
1 parent eb31fb6 commit cbe0168
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/dev_fs_lib_spi.h
Expand Up @@ -88,6 +88,7 @@ enum DSPAL_SPI_IOCTLS {
SPI_IOCTL_LOOPBACK_TEST, /**< activate the internal loopback test mode of the spi bus */
SPI_IOCTL_RDWR, /**< used to initiate a write/read batch transfer */
SPI_IOCTL_SET_BUS_FREQUENCY_IN_HZ, /**< use this to set the SPI bus speed in HZ */
SPI_IOCTL_SET_SPI_MODE, /**< use this to set the SPI mode */
SPI_IOCTL_MAX_NUM, /**< number of valid IOCTL codes defined for the I2C bus */
};

Expand All @@ -101,6 +102,23 @@ enum DSPAL_SPI_LOOPBACK_TEST_STATE {
SPI_LOOPBACK_STATE_ENABLED, /**< specifies that the loopback state should be enabled */
};

/**
* In the idle state whether the SPI clk is high or low.
*/
enum SPI_CLOCK_POLARITY_TYPE {
SPI_CLOCK_IDLE_LOW, /**< CLK signal is low when idle.*/
SPI_CLOCK_IDLE_HIGH /**< CLK signal is high when idle.*/
};


/**
* Shift mode, detemines which signal (input or output) is sampled first.
*/
enum SPI_SHIFT_MODE_TYPE {
SPI_INPUT_FIRST, /**< In both Master and slave input Bit is shifted in first.*/
SPI_OUTPUT_FIRST /**< In both Master and slave output Bit is shifted in first*/
};

/**
* Callback function indicating that new data has been received and is ready to be read.
* @param event
Expand Down Expand Up @@ -129,6 +147,19 @@ struct dspal_spi_ioctl_set_bus_frequency {
uint32_t bus_frequency_in_hz; /**< the maximum speed of the bus for high speed data transfers */
};

/**
* Structure passed to the SPI_IOCTL_SET_SPI_MODE IOCTL call. Specifies
* the SPI bus mode to the slave device. if not set, use the default mode 3.
*/
struct dspal_spi_ioctl_set_spi_mode {
enum SPI_CLOCK_POLARITY_TYPE eClockPolarity;/**< Clock polarity type to be used for the SPI core.*/

/* This parameter specifies whether the SPI core operates in OUTPUT
* or INPUT FIRST Mode. This specifies whether the shift register
* latches the DATA at the input pin on the rising or falling edge */
enum SPI_SHIFT_MODE_TYPE eShiftMode;/**< Shift mode type to be used for SPI core.*/
};

/**
* Structure passed to the SPI_IOCTL_SET_OPTIONS IOCTL call. Specifies certain SPI bus options and capabilities.
*
Expand Down
20 changes: 20 additions & 0 deletions test/dspal_tester/adsp_proc/spi_test_imp.c
Expand Up @@ -126,6 +126,7 @@ int dspal_tester_spi_loopback_test(void)
int test_data_length_in_bytes = SPI_LOOPBACK_TEST_TRANSMIT_BUFFER_LENGTH - 1;
struct dspal_spi_ioctl_loopback loopback;
struct dspal_spi_ioctl_read_write read_write;
struct dspal_spi_ioctl_set_spi_mode bus_mode;

LOG_DEBUG("testing spi open for: %s", SPI_DEVICE_PATH);
spi_fildes = open(SPI_DEVICE_PATH, 0);
Expand Down Expand Up @@ -154,6 +155,15 @@ int dspal_tester_spi_loopback_test(void)
goto exit;
}

/* set bus mode, don't goto exit for downward compatible */
bus_mode.eClockPolarity = SPI_CLOCK_IDLE_HIGH;
bus_mode.eShiftMode = SPI_OUTPUT_FIRST;
result = ioctl(spi_fildes, SPI_IOCTL_SET_SPI_MODE, &bus_mode);
if (result < SUCCESS)
{
LOG_ERR("error: unable to set bus mode");
}

/*
* Test loopback mode using combined read/write mode.
*/
Expand Down Expand Up @@ -204,6 +214,7 @@ int dspal_tester_spi_exceed_max_length_test(void)
uint8_t read_data_buffer[DSPAL_SPI_RECEIVE_BUFFER_LENGTH + 1];
struct dspal_spi_ioctl_loopback loopback;
struct dspal_spi_ioctl_read_write read_write;
struct dspal_spi_ioctl_set_spi_mode bus_mode;

LOG_DEBUG("testing spi open for: %s", SPI_DEVICE_PATH);
spi_fildes = open(SPI_DEVICE_PATH, 0);
Expand All @@ -226,6 +237,15 @@ int dspal_tester_spi_exceed_max_length_test(void)
goto exit;
}

/* set bus mode, don't goto exit for downward compatible */
bus_mode.eClockPolarity = SPI_CLOCK_IDLE_HIGH;
bus_mode.eShiftMode = SPI_OUTPUT_FIRST;
result = ioctl(spi_fildes, SPI_IOCTL_SET_SPI_MODE, &bus_mode);
if (result < SUCCESS)
{
LOG_ERR("error: unable to set bus mode");
}

read_write.read_buffer = &read_data_buffer[0];
read_write.read_buffer_length = sizeof(read_data_buffer);
read_write.write_buffer = &write_data_buffer[0];
Expand Down

0 comments on commit cbe0168

Please sign in to comment.