diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 53bb7284faafb375793e33328e0b125b12959f08..1f48f183f0bc9db8a4a5478f42df600254fc4478 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -26,6 +26,25 @@ extern rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name); extern rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name); +static rt_err_t rt_spi_check_ops(const struct rt_spi_ops *ops) +{ + if(ops == RT_NULL) + { + return -RT_EINVAL; + } + + else if(ops->configure == RT_NULL || ops->xfer == RT_NULL) + { + return -RT_EINVAL; + } + + else + { + return RT_EOK; + } + +} + rt_err_t spi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops) @@ -36,6 +55,11 @@ rt_err_t spi_bus_register(struct rt_spi_bus *bus, if (result != RT_EOK) return result; + /* check ops */ + result = rt_spi_check_ops(ops); + if(result) + return result; + /* initialize mutex lock */ rt_mutex_init(&(bus->lock), name, RT_IPC_FLAG_PRIO); /* set ops */