tests: spi: correct a spi buffer length issue

Make the buffer length for tx and rx are the same for
spi_transceive API call. QMSI only supports equal length.
This is clearly specifed in spi header file.

Also correct some coding style issues.

Change-Id: Ifd34683e8813dae9b692ad453176a93cb3848427
Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
Baohong Liu 2016-12-15 11:44:32 -08:00 committed by Anas Nashif
commit 83a388e6c8

View file

@ -21,8 +21,6 @@
#include <spi.h>
#include <misc/printk.h>
#define SPI_DRV_NAME "SPI_0"
#ifdef CONFIG_SPI_INTEL
@ -67,11 +65,11 @@ static void _spi_show(struct spi_config *spi_conf)
void main(void)
{
struct device *spi;
uint32_t len = 0;
printk("==== SPI Test Application ====\n");
spi = device_get_binding(SPI_DRV_NAME);
if (!spi) {
printk("SPI device not found\n");
return;
@ -92,16 +90,24 @@ void main(void)
_spi_show(&spi_conf);
printk("Writing...\n");
if (spi_write(spi, (uint8_t *) wbuf, 6) != 0) {
printk("SPI write failed\n");
return;
}
printk("SPI sent: %s\n", wbuf);
print_buf_hex(rbuf, 6);
print_buf_hex(wbuf, 6);
strcpy((char *)wbuf, "So what then?");
if (spi_transceive(spi, wbuf, 14, rbuf, 16) != 0) {
len = strlen(wbuf);
/*
* len does not include string terminator.
* Let's sent the terminator as well.
* Also make sure tx and rx have the same length.
*/
if (spi_transceive(spi, wbuf, len + 1, rbuf, len + 1) != 0) {
printk("SPI transceive failed\n");
return;
}