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:
parent
a7006bb53d
commit
83a388e6c8
1 changed files with 11 additions and 5 deletions
|
@ -21,8 +21,6 @@
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
#include <misc/printk.h>
|
#include <misc/printk.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define SPI_DRV_NAME "SPI_0"
|
#define SPI_DRV_NAME "SPI_0"
|
||||||
|
|
||||||
#ifdef CONFIG_SPI_INTEL
|
#ifdef CONFIG_SPI_INTEL
|
||||||
|
@ -67,11 +65,11 @@ static void _spi_show(struct spi_config *spi_conf)
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
struct device *spi;
|
struct device *spi;
|
||||||
|
uint32_t len = 0;
|
||||||
|
|
||||||
printk("==== SPI Test Application ====\n");
|
printk("==== SPI Test Application ====\n");
|
||||||
|
|
||||||
spi = device_get_binding(SPI_DRV_NAME);
|
spi = device_get_binding(SPI_DRV_NAME);
|
||||||
|
|
||||||
if (!spi) {
|
if (!spi) {
|
||||||
printk("SPI device not found\n");
|
printk("SPI device not found\n");
|
||||||
return;
|
return;
|
||||||
|
@ -92,16 +90,24 @@ void main(void)
|
||||||
_spi_show(&spi_conf);
|
_spi_show(&spi_conf);
|
||||||
|
|
||||||
printk("Writing...\n");
|
printk("Writing...\n");
|
||||||
|
|
||||||
if (spi_write(spi, (uint8_t *) wbuf, 6) != 0) {
|
if (spi_write(spi, (uint8_t *) wbuf, 6) != 0) {
|
||||||
printk("SPI write failed\n");
|
printk("SPI write failed\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("SPI sent: %s\n", wbuf);
|
printk("SPI sent: %s\n", wbuf);
|
||||||
print_buf_hex(rbuf, 6);
|
print_buf_hex(wbuf, 6);
|
||||||
|
|
||||||
strcpy((char *)wbuf, "So what then?");
|
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");
|
printk("SPI transceive failed\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue