diff options
| author | Bernard Xiong <[email protected]> | 2019-01-21 18:17:51 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-01-21 18:17:51 +0800 |
| commit | dfebb30c91875c52f16fd4e7bb9e5981fd0512b4 (patch) | |
| tree | a5963a4d33a40b9286a6cfc0fc948751e66bb5b1 /components/drivers | |
| parent | 3dd0ebe6e7d8d0ad7605269ef8fffd66a8029931 (diff) | |
| parent | b7996af1862800b80c756329dcbf1a8496651a81 (diff) | |
Merge pull request #2238 from armink/lts-v3.1.x
Sync from master latest version.
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/can/can.c | 2 | ||||
| -rw-r--r-- | components/drivers/serial/serial.c | 2 | ||||
| -rw-r--r-- | components/drivers/spi/spi_flash_sfud.c | 59 | ||||
| -rw-r--r-- | components/drivers/wlan/wlan_dev.c | 19 | ||||
| -rw-r--r-- | components/drivers/wlan/wlan_lwip.c | 18 |
5 files changed, 67 insertions, 33 deletions
diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c index e20fcddcff..81fdf25a1e 100644 --- a/components/drivers/can/can.c +++ b/components/drivers/can/can.c @@ -405,6 +405,7 @@ static rt_err_t rt_can_close(struct rt_device *dev) rt_free(rx_fifo); dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX; + can->can_rx = RT_NULL; /* configure low level device */ can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX); } @@ -418,6 +419,7 @@ static rt_err_t rt_can_close(struct rt_device *dev) rt_free(tx_fifo); dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX; + can->can_tx = RT_NULL; /* configure low level device */ can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_TX); } diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index c5932df7d9..77f2a645a1 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -566,13 +566,11 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag) LOG_D("open serial device: 0x%08x with open flag: 0x%04x", dev, oflag); -#ifdef RT_SERIAL_USING_DMA /* check device flag with the open flag */ if ((oflag & RT_DEVICE_FLAG_DMA_RX) && !(dev->flag & RT_DEVICE_FLAG_DMA_RX)) return -RT_EIO; if ((oflag & RT_DEVICE_FLAG_DMA_TX) && !(dev->flag & RT_DEVICE_FLAG_DMA_TX)) return -RT_EIO; -#endif /* RT_SERIAL_USING_DMA */ if ((oflag & RT_DEVICE_FLAG_INT_RX) && !(dev->flag & RT_DEVICE_FLAG_INT_RX)) return -RT_EIO; if ((oflag & RT_DEVICE_FLAG_INT_TX) && !(dev->flag & RT_DEVICE_FLAG_INT_TX)) diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c index c8ff8f1b3b..fb18b820c0 100644 --- a/components/drivers/spi/spi_flash_sfud.c +++ b/components/drivers/spi/spi_flash_sfud.c @@ -455,6 +455,35 @@ rt_err_t rt_sfud_flash_delete(rt_spi_flash_device_t spi_flash_dev) { return RT_EOK; } +sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name) +{ + rt_spi_flash_device_t rtt_dev = RT_NULL; + struct rt_spi_device *rt_spi_device = RT_NULL; + sfud_flash_t sfud_dev = RT_NULL; + + rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name); + if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice) + { + rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name); + goto error; + } + + rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data); + if (rtt_dev && rtt_dev->user_data) + { + sfud_dev = (sfud_flash_t)(rtt_dev->user_data); + return sfud_dev; + } + else + { + rt_kprintf("ERROR: SFUD flash device not found!\n"); + goto error; + } + +error: + return RT_NULL; +} + #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) #include <finsh.h> @@ -698,36 +727,6 @@ static void sf(uint8_t argc, char **argv) { } } MSH_CMD_EXPORT(sf, SPI Flash operate.); - -sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name) -{ - rt_spi_flash_device_t rtt_dev = RT_NULL; - struct rt_spi_device *rt_spi_device = RT_NULL; - sfud_flash_t sfud_dev = RT_NULL; - - rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name); - if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice) - { - rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name); - goto error; - } - - rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data); - if (rtt_dev && rtt_dev->user_data) - { - sfud_dev = (sfud_flash_t)(rtt_dev->user_data); - return sfud_dev; - } - else - { - rt_kprintf("ERROR: SFUD flash device not found!\n"); - goto error; - } - -error: - return RT_NULL; -} - #endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ #endif /* RT_USING_SFUD */ diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c index 0beac52aae..eac1d0f975 100644 --- a/components/drivers/wlan/wlan_dev.c +++ b/components/drivers/wlan/wlan_dev.c @@ -754,6 +754,18 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args) return err; } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops wlan_ops = +{ + _rt_wlan_dev_init, + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + _rt_wlan_dev_control +}; +#endif + rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data) { rt_err_t err = RT_EOK; @@ -765,13 +777,18 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con } rt_memset(wlan, 0, sizeof(struct rt_wlan_device)); - + +#ifdef RT_USING_DEVICE_OPS + wlan->device.ops = &wlan_ops; +#else wlan->device.init = _rt_wlan_dev_init; wlan->device.open = RT_NULL; wlan->device.close = RT_NULL; wlan->device.read = RT_NULL; wlan->device.write = RT_NULL; wlan->device.control = _rt_wlan_dev_control; +#endif + wlan->device.user_data = RT_NULL; wlan->device.type = RT_Device_Class_NetIf; diff --git a/components/drivers/wlan/wlan_lwip.c b/components/drivers/wlan/wlan_lwip.c index ec6ca23845..2f8bcefd0d 100644 --- a/components/drivers/wlan/wlan_lwip.c +++ b/components/drivers/wlan/wlan_lwip.c @@ -372,6 +372,18 @@ static rt_err_t rt_wlan_lwip_protocol_send(rt_device_t device, struct pbuf *p) #endif } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops wlan_lwip_ops = +{ + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + rt_wlan_lwip_protocol_control +}; +#endif + static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan) { struct eth_device *eth = RT_NULL; @@ -417,12 +429,18 @@ static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot * rt_memset(lwip_prot, 0, sizeof(struct lwip_prot_des)); eth = &lwip_prot->eth; + +#ifdef RT_USING_DEVICE_OPS + eth->parent.ops = &wlan_lwip_ops; +#else eth->parent.init = RT_NULL; eth->parent.open = RT_NULL; eth->parent.close = RT_NULL; eth->parent.read = RT_NULL; eth->parent.write = RT_NULL; eth->parent.control = rt_wlan_lwip_protocol_control; +#endif + eth->parent.user_data = wlan; eth->eth_rx = RT_NULL; eth->eth_tx = rt_wlan_lwip_protocol_send; |
