spicmds: Check for an incorrect mode in spicmds.c

Check the mode parameter in spicmds.c so that the mcu code does not
need to check it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-11-26 22:38:46 -05:00
parent 6b108aa885
commit db4f0c24cd
6 changed files with 12 additions and 10 deletions

View File

@ -39,7 +39,7 @@ spi_init(void)
struct spi_config
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
if (bus || mode > 3)
if (bus)
shutdown("Invalid spi_setup parameters");
// Make sure the SPI interface is enabled

View File

@ -35,7 +35,7 @@ spi_init(void)
struct spi_config
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
if (bus || mode > 3)
if (bus)
shutdown("Invalid spi_setup parameters");
// Make sure bus is enabled

View File

@ -54,7 +54,7 @@ spi_init(void)
struct spi_config
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
if (bus != CHANNEL || mode > 3)
if (bus != CHANNEL)
shutdown("Invalid spi_setup parameters");
// Make sure bus is enabled

View File

@ -21,7 +21,7 @@ struct spi_config
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
Usart *p_usart = USART0;
if (bus > 2 || mode > 3) {
if (bus > 2) {
shutdown("Invalid spi_setup parameters");
}

View File

@ -26,12 +26,14 @@ enum {
void
command_config_spi(uint32_t *args)
{
uint8_t shutdown_msg_len = args[5];
uint8_t mode = args[3], shutdown_msg_len = args[5];
if (mode > 3)
shutdown("Invalid spi mode");
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
, sizeof(*spi) + shutdown_msg_len);
spi->pin = gpio_out_setup(args[2], 1);
spi->flags = SF_HAVE_PIN;
spi->spi_config = spi_setup(args[1], args[3], args[4]);
spi->spi_config = spi_setup(args[1], mode, args[4]);
spi->shutdown_msg_len = shutdown_msg_len;
uint8_t *shutdown_msg = (void*)(size_t)args[6];
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);
@ -42,10 +44,12 @@ DECL_COMMAND(command_config_spi,
void
command_config_spi_without_cs(uint32_t *args)
{
uint8_t shutdown_msg_len = args[4];
uint8_t mode = args[2], shutdown_msg_len = args[4];
if (mode > 3)
shutdown("Invalid spi mode");
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
, sizeof(*spi) + shutdown_msg_len);
spi->spi_config = spi_setup(args[1], args[2], args[3]);
spi->spi_config = spi_setup(args[1], mode, args[3]);
spi->shutdown_msg_len = shutdown_msg_len;
uint8_t *shutdown_msg = (void*)(size_t)args[5];
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);

View File

@ -30,8 +30,6 @@ static void spi_set_mode(SPI_TypeDef *spi, uint8_t mode)
LL_SPI_SetClockPolarity(spi, LL_SPI_POLARITY_HIGH);
LL_SPI_SetClockPhase(spi, LL_SPI_PHASE_2EDGE);
break;
default:
shutdown("Invalid SPI mode");
}
}