From 54c6e7d1459c2e4e6e4e6249e1700837c3d863a3 Mon Sep 17 00:00:00 2001 From: xieyangrun Date: Wed, 23 Sep 2020 17:17:20 +0800 Subject: [dirver/i2c] i2c driver support bus lock, STOP control --- components/drivers/Kconfig | 2 +- components/drivers/i2c/i2c-bit-ops.c | 14 ++++++++++---- components/drivers/include/drivers/i2c.h | 12 ++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'components') diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 457b8751fe..77c853367f 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -97,7 +97,7 @@ if RT_USING_I2C default y if RT_USING_I2C_BITOPS - config RT_I2C_BITOPS_DEBUG + config RT_I2C_BITOPS_DEBUG bool "Use simulate I2C debug message" default n endif diff --git a/components/drivers/i2c/i2c-bit-ops.c b/components/drivers/i2c/i2c-bit-ops.c index 99338eef54..96af567a1e 100644 --- a/components/drivers/i2c/i2c-bit-ops.c +++ b/components/drivers/i2c/i2c-bit-ops.c @@ -375,8 +375,6 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus, rt_int32_t i, ret; rt_uint16_t ignore_nack; - LOG_D("send start condition"); - i2c_start(ops); for (i = 0; i < num; i++) { msg = &msgs[i]; @@ -387,6 +385,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus, { i2c_restart(ops); } + else + { + LOG_D("send start condition"); + i2c_start(ops); + } ret = i2c_bit_send_address(bus, msg); if ((ret != RT_EOK) && !ignore_nack) { @@ -423,8 +426,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus, ret = i; out: - LOG_D("send stop condition"); - i2c_stop(ops); + if (!(msg->flags & RT_I2C_NO_STOP)) + { + LOG_D("send stop condition"); + i2c_stop(ops); + } return ret; } diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h index 17d57288cd..d93e82fc2b 100644 --- a/components/drivers/include/drivers/i2c.h +++ b/components/drivers/include/drivers/i2c.h @@ -23,6 +23,7 @@ extern "C" { #define RT_I2C_NO_START (1u << 4) #define RT_I2C_IGNORE_NACK (1u << 5) #define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */ +#define RT_I2C_NO_STOP (1u << 7) struct rt_i2c_msg { @@ -83,6 +84,17 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus, rt_uint16_t flags, rt_uint8_t *buf, rt_uint32_t count); + +rt_inline rt_err_t rt_i2c_bus_lock(struct rt_i2c_bus_device *bus, rt_tick_t timeout) +{ + return rt_mutex_take(&bus->lock, timeout); +} + +rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus) +{ + return rt_mutex_release(&bus->lock); +} + int rt_i2c_core_init(void); #ifdef __cplusplus -- cgit v1.3.1 From e8eb74da585ab30aa6f6594056aa92a262512500 Mon Sep 17 00:00:00 2001 From: 张世争 Date: Fri, 20 Nov 2020 09:02:20 +0800 Subject: [rtc.alarm][fix]fix alarm when update datetime --- components/drivers/rtc/alarm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/drivers/rtc/alarm.c b/components/drivers/rtc/alarm.c index 71b6e7236a..53cb538321 100644 --- a/components/drivers/rtc/alarm.c +++ b/components/drivers/rtc/alarm.c @@ -8,6 +8,7 @@ * 2012-10-27 heyuanjie87 first version. * 2013-05-17 aozima initial alarm event & mutex in system init. * 2020-10-15 zhangsz add alarm flags hour minute second. + * 2020-11-09 zhangsz fix alarm set when modify rtc time. */ #include @@ -102,7 +103,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) { alarm->wktime.tm_hour = now->tm_hour; alarm->wktime.tm_min = now->tm_min; - alarm->wktime.tm_sec = alarm->wktime.tm_sec + 1; + alarm->wktime.tm_sec = now->tm_sec + 1; if (alarm->wktime.tm_sec > 59) { alarm->wktime.tm_sec = 0; @@ -125,7 +126,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) alarm->wktime.tm_hour = now->tm_hour; if (alarm->wktime.tm_sec == now->tm_sec) { - alarm->wktime.tm_min = alarm->wktime.tm_min + 1; + alarm->wktime.tm_min = now->tm_min + 1; if (alarm->wktime.tm_min > 59) { alarm->wktime.tm_min = 0; @@ -144,7 +145,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) if ((alarm->wktime.tm_min == now->tm_min) && (alarm->wktime.tm_sec == now->tm_sec)) { - alarm->wktime.tm_hour = alarm->wktime.tm_hour + 1; + alarm->wktime.tm_hour = now->tm_hour + 1; if (alarm->wktime.tm_hour > 23) { alarm->wktime.tm_hour = 0; -- cgit v1.3.1 From 4f99d988d9713e5ebbf35564d55a7b30938c9563 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 12:35:19 +0800 Subject: Update ethernetif.c --- components/net/lwip-2.1.2/src/netif/ethernetif.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'components') diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 10865930c1..52bd0fb7b6 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -163,6 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); + + if(RT_TRUE == is_enabled) + { + dhcp_start((struct netif *)netif->user_data); + } + else + { + dhcp_stop((struct netif *)netif->user_data); + } + return ERR_OK; } #endif /* RT_LWIP_DHCP */ -- cgit v1.3.1 From 88858f216cf2939ce3d8239c2f6cdcd16758952a Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 12:44:14 +0800 Subject: Update ethernetif.c --- components/net/lwip-1.4.1/src/netif/ethernetif.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'components') diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index d31ea813bc..f2570f9e2b 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -156,6 +156,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); + + if(RT_TRUE == is_enabled) + { + dhcp_start((struct netif *)netif->user_data); + } + else + { + dhcp_stop((struct netif *)netif->user_data); + } + return ERR_OK; } #endif /* RT_LWIP_DHCP */ -- cgit v1.3.1 From 626e8537f0d260691eb84816f0f3fef1082137fb Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:25:27 +0800 Subject: [components / drivers]update audio_mic.c 1. delete '#include ', because rtthread.h had include rtservice.h; 2. delete '#include ', because rtdevice.h had include rtthread.h. --- components/drivers/usb/usbdevice/class/audio_mic.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/audio_mic.c b/components/drivers/usb/usbdevice/class/audio_mic.c index 4ac85711ad..c1739453ca 100644 --- a/components/drivers/usb/usbdevice/class/audio_mic.c +++ b/components/drivers/usb/usbdevice/class/audio_mic.c @@ -9,8 +9,6 @@ */ #include -#include -#include #include #include "drivers/usb_device.h" -- cgit v1.3.1 From b73775da85c222029efad6138d41c135372b981b Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:29:45 +0800 Subject: Update audio_mic.c --- components/drivers/usb/usbdevice/class/audio_mic.c | 1 - 1 file changed, 1 deletion(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/audio_mic.c b/components/drivers/usb/usbdevice/class/audio_mic.c index c1739453ca..23ade2d9b6 100644 --- a/components/drivers/usb/usbdevice/class/audio_mic.c +++ b/components/drivers/usb/usbdevice/class/audio_mic.c @@ -10,7 +10,6 @@ #include #include - #include "drivers/usb_device.h" #include "audio.h" -- cgit v1.3.1 From f273e52614fe1789cdbc2efcfca138e585054ff9 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:30:12 +0800 Subject: Update audio_speaker.c --- components/drivers/usb/usbdevice/class/audio_speaker.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/audio_speaker.c b/components/drivers/usb/usbdevice/class/audio_speaker.c index 84c36d2053..e9a3ffaf40 100644 --- a/components/drivers/usb/usbdevice/class/audio_speaker.c +++ b/components/drivers/usb/usbdevice/class/audio_speaker.c @@ -9,10 +9,7 @@ */ #include -#include -#include #include - #include "drivers/usb_device.h" #include "audio.h" -- cgit v1.3.1 From 107b2063c199117c0311d6c668bc076bc68edef9 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:32:09 +0800 Subject: Update winusb.c --- components/drivers/usb/usbdevice/class/winusb.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/winusb.c b/components/drivers/usb/usbdevice/class/winusb.c index 729e39f663..4af6dba3cf 100644 --- a/components/drivers/usb/usbdevice/class/winusb.c +++ b/components/drivers/usb/usbdevice/class/winusb.c @@ -8,8 +8,6 @@ * 2017-11-16 ZYH first version */ #include -#include -#include #include #include #include "winusb.h" -- cgit v1.3.1 From da464e6cc33903638e12fb73e0c69644597170fb Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:35:53 +0800 Subject: Update mstorage.c --- components/drivers/usb/usbdevice/class/mstorage.c | 1 - 1 file changed, 1 deletion(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c index d0a2b7f736..6991d97eae 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.c +++ b/components/drivers/usb/usbdevice/class/mstorage.c @@ -12,7 +12,6 @@ */ #include -#include #include "drivers/usb_device.h" #include "mstorage.h" -- cgit v1.3.1 From cc6b6a6ee3357fa90a960c51de38c9fe485e60aa Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:36:26 +0800 Subject: Update hid.c --- components/drivers/usb/usbdevice/class/hid.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/hid.c b/components/drivers/usb/usbdevice/class/hid.c index a4acce75ea..47788769e8 100644 --- a/components/drivers/usb/usbdevice/class/hid.c +++ b/components/drivers/usb/usbdevice/class/hid.c @@ -11,8 +11,6 @@ */ #include -#include -#include #include #include "drivers/usb_common.h" -- cgit v1.3.1 From b10c9b7b639c9cb2cfdbf49a03dd1c182ed9573f Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:36:56 +0800 Subject: Update hid.c --- components/drivers/usb/usbdevice/class/hid.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/hid.c b/components/drivers/usb/usbdevice/class/hid.c index 47788769e8..52e50296a4 100644 --- a/components/drivers/usb/usbdevice/class/hid.c +++ b/components/drivers/usb/usbdevice/class/hid.c @@ -12,10 +12,8 @@ #include #include - #include "drivers/usb_common.h" #include "drivers/usb_device.h" - #include "hid.h" #ifdef RT_USB_DEVICE_HID -- cgit v1.3.1 From f0867654010fcf4ebac2fe85a4d6731b62ea7d11 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 15:37:45 +0800 Subject: Update cdc_vcom.c --- components/drivers/usb/usbdevice/class/cdc_vcom.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c index 64230533ae..f9ea466bd5 100644 --- a/components/drivers/usb/usbdevice/class/cdc_vcom.c +++ b/components/drivers/usb/usbdevice/class/cdc_vcom.c @@ -13,8 +13,6 @@ */ #include -#include -#include #include #include #include "drivers/usb_device.h" -- cgit v1.3.1 From db71258051c334972a0baecfaa55a2ea4894ba4a Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 16:00:40 +0800 Subject: [components / drivers]fixed re-include of audio --- components/drivers/audio/audio_pipe.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/drivers/audio/audio_pipe.h b/components/drivers/audio/audio_pipe.h index 85a3eb1793..3ae3bc8498 100644 --- a/components/drivers/audio/audio_pipe.h +++ b/components/drivers/audio/audio_pipe.h @@ -12,7 +12,6 @@ /** * Pipe Device */ -#include #include #ifndef RT_PIPE_BUFSZ @@ -71,6 +70,6 @@ rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe); #ifdef RT_USING_HEAP rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size); void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe); -#endif -#endif +#endif /* RT_USING_HEAP */ +#endif /* __AUDIO_PIPE_H__ */ -- cgit v1.3.1 From 7f1aa82a8878cc2f5c2b0b8b279b292b0aa29b87 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 16:05:24 +0800 Subject: Update audio_pipe.c --- components/drivers/audio/audio_pipe.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'components') diff --git a/components/drivers/audio/audio_pipe.c b/components/drivers/audio/audio_pipe.c index d7c37009b6..0a6f090a83 100644 --- a/components/drivers/audio/audio_pipe.c +++ b/components/drivers/audio/audio_pipe.c @@ -9,9 +9,6 @@ */ #include -#include -#include - #include "audio_pipe.h" static void _rt_pipe_resume_writer(struct rt_audio_pipe *pipe) -- cgit v1.3.1 From 9f5d860d044a37a64e8275b185050ca21e4df304 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 21 Nov 2020 16:07:03 +0800 Subject: Update audio.c --- components/drivers/audio/audio.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'components') diff --git a/components/drivers/audio/audio.c b/components/drivers/audio/audio.c index 846dad07cf..6614b75ff5 100644 --- a/components/drivers/audio/audio.c +++ b/components/drivers/audio/audio.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #define DBG_TAG "audio" @@ -590,7 +589,6 @@ int rt_audio_samplerate_to_speed(rt_uint32_t bitValue) speed = 192000; break; default: - break; } -- cgit v1.3.1 From aac5e9da4cc14f88771b3cf34d24e44d7e545ea5 Mon Sep 17 00:00:00 2001 From: longtengmcu Date: Sun, 22 Nov 2020 12:36:07 +0800 Subject: 1、web socket请求数据从服务器回来时,服务器会关闭连接,此时AT socket在读取返回的数据时不应该判断socket为连接的状态 2、sal socket在支持多网卡时,sal_getaddrinfo从A网卡获取的地址信息,在sal_freeaddrinfo释放时必须由A网卡进行释放 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/at/at_socket/at_socket.c | 25 ++++------- components/net/sal_socket/src/sal_socket.c | 72 ++++++++++++++++++++++++------ 2 files changed, 67 insertions(+), 30 deletions(-) (limited to 'components') diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 666b0f509e..ce8559f129 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -821,24 +821,17 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f goto __exit; } else - { - if (sock->state == AT_SOCKET_CONNECT) - { - /* get receive buffer to receiver ring buffer */ - rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *) mem, len); - rt_mutex_release(sock->recv_lock); - if (recv_len > 0) - { - break; - } - } - else + { + + /* get receive buffer to receiver ring buffer */ + rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); + recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *) mem, len); + rt_mutex_release(sock->recv_lock); + if (recv_len > 0) { - LOG_D("received data exit, current socket (%d) is closed by remote.", socket); - result = 0; - goto __exit; + break; } + } } diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index ec0519df02..bf88cfa751 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -41,6 +41,13 @@ struct sal_socket_table struct sal_socket **sockets; }; +/* record the netdev and res table*/ +struct sal_netdev_res_table +{ + struct addrinfo *res; + struct netdev *netdev; +}; + #ifdef SAL_USING_TLS /* The global TLS protocol options */ static struct sal_proto_tls *proto_tls; @@ -50,6 +57,7 @@ static struct sal_proto_tls *proto_tls; static struct sal_socket_table socket_table; static struct rt_mutex sal_core_lock; static rt_bool_t init_ok = RT_FALSE; +static struct sal_netdev_res_table sal_dev_res_tbl[SAL_SOCKETS_NUM]; #define IS_SOCKET_PROTO_TLS(sock) (((sock)->protocol == PROTOCOL_TLS) || \ ((sock)->protocol == PROTOCOL_DTLS)) @@ -90,6 +98,11 @@ do { ((pf) = (struct sal_proto_family *) (netdev)->sal_user_data) != RT_NULL && \ (pf)->netdb_ops->ops) \ +#define SAL_NETDBOPS_VALID(netdev, pf, ops) \ + ((netdev) && \ + ((pf) = (struct sal_proto_family *) (netdev)->sal_user_data) != RT_NULL && \ + (pf)->netdb_ops->ops) \ + /** * SAL (Socket Abstraction Layer) initialize. * @@ -116,6 +129,9 @@ int sal_init(void) return -1; } + /*init the dev_res table */ + rt_memset(sal_dev_res_tbl, 0, sizeof(sal_dev_res_tbl)); + /* create sal socket lock */ rt_mutex_init(&sal_core_lock, "sal_lock", RT_IPC_FLAG_FIFO); @@ -1086,10 +1102,12 @@ int sal_getaddrinfo(const char *nodename, { struct netdev *netdev = netdev_default; struct sal_proto_family *pf; + int ret = 0; + rt_uint32_t i = 0; if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo)) { - return pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); + ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); } else { @@ -1097,30 +1115,56 @@ int sal_getaddrinfo(const char *nodename, netdev = netdev_get_first_by_flags(NETDEV_FLAG_UP); if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo)) { - return pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); + ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res); + } + else + { + ret = -1; } } - return -1; + if(ret == RT_EOK) + { + /*record the netdev and res*/ + for(i = 0; i < SAL_SOCKETS_NUM; i++) + { + if(sal_dev_res_tbl[i].res == RT_NULL) + { + sal_dev_res_tbl[i].res = *res; + sal_dev_res_tbl[i].netdev = netdev; + break; + } + } + + RT_ASSERT((i < SAL_SOCKETS_NUM)); + + } + + return ret; } void sal_freeaddrinfo(struct addrinfo *ai) { - struct netdev *netdev = netdev_default; - struct sal_proto_family *pf; + struct netdev *netdev = RT_NULL; + struct sal_proto_family *pf = RT_NULL; + rt_uint32_t i = 0; - if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, freeaddrinfo)) - { - pf->netdb_ops->freeaddrinfo(ai); - } - else + /*when use the multi netdev, it must free the ai use the getaddrinfo netdev */ + for(i = 0; i < SAL_SOCKETS_NUM; i++) { - /* get the first network interface device with up status */ - netdev = netdev_get_first_by_flags(NETDEV_FLAG_UP); - if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, freeaddrinfo)) + if(sal_dev_res_tbl[i].res == ai) { - pf->netdb_ops->freeaddrinfo(ai); + netdev = sal_dev_res_tbl[i].netdev; + sal_dev_res_tbl[i].res = RT_NULL; + sal_dev_res_tbl[i].netdev = RT_NULL; + break; } } + RT_ASSERT((i < SAL_SOCKETS_NUM)); + + if (SAL_NETDBOPS_VALID(netdev, pf, freeaddrinfo)) + { + pf->netdb_ops->freeaddrinfo(ai); + } } -- cgit v1.3.1 From d6c8b46dad9ea158100c7f31c1f590e96468f1a0 Mon Sep 17 00:00:00 2001 From: malongwei <2544047213@qq.com> Date: Sun, 22 Nov 2020 14:20:02 +0800 Subject: add 'rt_ringbuffer_peak' API --- components/drivers/include/ipc/ringbuffer.h | 1 + components/drivers/src/ringbuffer.c | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'components') diff --git a/components/drivers/include/ipc/ringbuffer.h b/components/drivers/include/ipc/ringbuffer.h index 4487d02c47..2afd2ca213 100644 --- a/components/drivers/include/ipc/ringbuffer.h +++ b/components/drivers/include/ipc/ringbuffer.h @@ -71,6 +71,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *pt rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch); rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch); rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length); +rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr); rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch); rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb); diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index c6a491a7cc..88afd19506 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -193,6 +193,40 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, } RTM_EXPORT(rt_ringbuffer_get); +/** + * peak data from ring buffer + */ +rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) +{ + RT_ASSERT(rb != RT_NULL); + + *ptr = RT_NULL; + + /* whether has enough data */ + rt_size_t size = rt_ringbuffer_data_len(rb); + + /* no data */ + if (size == 0) + return 0; + + *ptr = &rb->buffer_ptr[rb->read_index]; + + if(rb->buffer_size - rb->read_index > size) + { + rb->read_index += size; + return size; + } + + size = rb->buffer_size - rb->read_index; + + /* we are going into the other side of the mirror */ + rb->read_mirror = ~rb->read_mirror; + rb->read_index = 0; + + return size; +} +RTM_EXPORT(rt_ringbuffer_peak); + /** * put a character into ring buffer */ -- cgit v1.3.1 From 962acc3313d611a886b764135db01572e0206c4d Mon Sep 17 00:00:00 2001 From: longtengmcu Date: Sun, 22 Nov 2020 20:05:53 +0800 Subject: 1、修改宏定义的拼写错误,修改打印IMEI号时的打印错误 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/netdev/src/netdev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'components') diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index aa43d8d3db..646d2dfdd1 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -856,7 +856,7 @@ void netdev_low_level_set_dhcp_status(struct netdev *netdev, rt_bool_t is_enable static void netdev_list_if(void) { #define NETDEV_IFCONFIG_MAC_MAX_LEN 6 -#define NETDEV_IFCONFIG_IEMI_MAX_LEN 8 +#define NETDEV_IFCONFIG_IMEI_MAX_LEN 8 rt_ubase_t index; rt_slist_t *node = RT_NULL; @@ -894,9 +894,15 @@ static void netdev_list_if(void) { /* two numbers are displayed at one time*/ if (netdev->hwaddr[index] < 10 && index != netdev->hwaddr_len - 1) - rt_kprintf("0"); - - rt_kprintf("%d", netdev->hwaddr[index]); + { + rt_kprintf("%02d", netdev->hwaddr[index]); + } + else + { + rt_kprintf("%d", netdev->hwaddr[index]); + } + + } } -- cgit v1.3.1 From 54143409cabf799f04ee6ee0480d6ae939087f9f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 23 Nov 2020 01:14:44 +0800 Subject: 增加#include 防止开启termios功能后报错 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/termios.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'components') diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h index ee2b4d5718..414d0c0cb3 100644 --- a/components/libc/compilers/common/termios.h +++ b/components/libc/compilers/common/termios.h @@ -9,6 +9,8 @@ #ifndef _TERMIOS_H__ #define _TERMIOS_H__ +#include + #ifdef RT_USING_POSIX_TERMIOS #include #include -- cgit v1.3.1 From 945053a833cafc9b608a552db252253dbe6657c4 Mon Sep 17 00:00:00 2001 From: 张世争 Date: Mon, 23 Nov 2020 21:41:19 +0800 Subject: [components][PM][Update]优化PM电源模式选择 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/pm/pm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'components') diff --git a/components/drivers/pm/pm.c b/components/drivers/pm/pm.c index dd7cc2ae63..f9190ae9ef 100644 --- a/components/drivers/pm/pm.c +++ b/components/drivers/pm/pm.c @@ -8,6 +8,7 @@ * 2012-06-02 Bernard the first version * 2018-08-02 Tanek split run and sleep modes, support custom mode * 2019-04-28 Zero-Free improve PM mode and device ops interface + * 2020-11-23 zhangsz update pm mode select */ #include @@ -214,8 +215,6 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, rt_uint8_t mode) */ void rt_system_power_manager(void) { - rt_uint8_t mode; - if (_pm_init_flag == 0) return; @@ -223,8 +222,7 @@ void rt_system_power_manager(void) _pm_frequency_scaling(&_pm); /* Low Power Mode Processing */ - mode = _pm_select_sleep_mode(&_pm); - _pm_change_sleep_mode(&_pm, mode); + _pm_change_sleep_mode(&_pm, _pm.sleep_mode); } /** @@ -248,6 +246,7 @@ void rt_pm_request(rt_uint8_t mode) pm = &_pm; if (pm->modes[mode] < 255) pm->modes[mode] ++; + _pm_select_sleep_mode(pm); rt_hw_interrupt_enable(level); } @@ -273,6 +272,7 @@ void rt_pm_release(rt_uint8_t mode) pm = &_pm; if (pm->modes[mode] > 0) pm->modes[mode] --; + _pm_select_sleep_mode(pm); rt_hw_interrupt_enable(level); } @@ -516,6 +516,10 @@ void rt_system_pm_init(const struct rt_pm_ops *ops, pm->device_pm = RT_NULL; pm->device_pm_number = 0; +#if IDLE_THREAD_STACK_SIZE <= 256 + #error "[pm.c ERR] IDLE Stack Size Too Small!" +#endif + _pm_init_flag = 1; } -- cgit v1.3.1 From cb54cda19ebeadcebc87f98bb7a1d32e6bc80840 Mon Sep 17 00:00:00 2001 From: chenjh Date: Tue, 24 Nov 2020 11:18:54 +0800 Subject: [bug] [libc] 修复posix_sem_find中iter->sem的数据类型转换问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/pthreads/semaphore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c index 2bef10022e..2ed93e99b6 100644 --- a/components/libc/pthreads/semaphore.c +++ b/components/libc/pthreads/semaphore.c @@ -64,7 +64,7 @@ static sem_t *posix_sem_find(const char* name) for (iter = posix_sem_list; iter != RT_NULL; iter = iter->next) { - object = (rt_object_t)&(iter->sem); + object = (rt_object_t)iter->sem; if (strncmp(object->name, name, RT_NAME_MAX) == 0) { -- cgit v1.3.1 From bb016927f8a5ef4121e2e0c899291642c0087b71 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Fri, 27 Nov 2020 17:28:49 +0800 Subject: Improve the clock Settings for switching to high speed mode in the SDIO framework. --- components/drivers/sdio/sdio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c index 65bf87b895..f5d97cdd08 100644 --- a/components/drivers/sdio/sdio.c +++ b/components/drivers/sdio/sdio.c @@ -892,9 +892,9 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr) if (card->flags & CARD_FLAG_HIGHSPEED) { - mmcsd_set_clock(host, 50000000); - } - else + mmcsd_set_clock(host, card->host->freq_max > 50000000 ? 50000000 : card->host->freq_max); + } + else { mmcsd_set_clock(host, card->cis.max_tran_speed); } -- cgit v1.3.1 From 9b925fb9c01163d260e4fd9ceb6e3cc878ac2fff Mon Sep 17 00:00:00 2001 From: xingkong121 <40432551+xingkong121@users.noreply.github.com> Date: Sat, 28 Nov 2020 22:47:06 +0800 Subject: Modify comment error Device file system should be registered --- components/dfs/filesystems/devfs/devfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index 7637074dbb..e457f18727 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -326,7 +326,7 @@ static const struct dfs_filesystem_ops _device_fs = int devfs_init(void) { - /* register rom file system */ + /* register device file system */ dfs_register(&_device_fs); return 0; -- cgit v1.3.1 From 7a1f0e0f677d8415b88e80f9f5e7754dac75c30e Mon Sep 17 00:00:00 2001 From: bigmagic Date: Wed, 2 Dec 2020 10:11:38 +0800 Subject: when flag is RT_DEVICE_FLAG_STREAM, paser '\n' break! --- components/drivers/serial/serial.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 2511f18102..c2cc2f615c 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -221,7 +221,10 @@ rt_inline int _serial_poll_rx(struct rt_serial_device *serial, rt_uint8_t *data, *data = ch; data ++; length --; - if (ch == '\n') break; + if(serial->parent.open_flag & RT_DEVICE_FLAG_STREAM) + { + if (ch == '\n') break; + } } return size - length; -- cgit v1.3.1 From c3ba2b07fa94bdacf5b0061becc3620dc90c454c Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Wed, 2 Dec 2020 14:30:31 +0800 Subject: [components][workqueue] Modify system work queue initialization level --- components/drivers/src/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 2e0280df3a..2b5630d8d0 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -424,6 +424,6 @@ int rt_work_sys_workqueue_init(void) return RT_EOK; } -INIT_DEVICE_EXPORT(rt_work_sys_workqueue_init); +INIT_PREV_EXPORT(rt_work_sys_workqueue_init); #endif #endif -- cgit v1.3.1 From 22c47d4b1954e9edd27fad403ab99f4e1eb38d08 Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Thu, 3 Dec 2020 09:59:09 +0800 Subject: Update dfs_romfs.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改一处拼写错误 --- components/dfs/filesystems/romfs/dfs_romfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index dcc34e5830..17dbee52f5 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -62,7 +62,7 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch return root_dirent; } - /* goto root directy entries */ + /* goto root directory entries */ dirent = (struct romfs_dirent *)root_dirent->data; dirent_size = root_dirent->size; -- cgit v1.3.1 From 9609bc032affdf667dea9417c45036b38b16b261 Mon Sep 17 00:00:00 2001 From: 张世争 Date: Thu, 3 Dec 2020 17:52:03 +0800 Subject: [RTC alarm]alarm功能优化,SOFT_RTC增加alarm功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/drivers/alarm.h | 2 + components/drivers/rtc/alarm.c | 94 +++++++++++++++++++++++++----- components/drivers/rtc/soft_rtc.c | 63 +++++++++++++++++--- 3 files changed, 137 insertions(+), 22 deletions(-) (limited to 'components') diff --git a/components/drivers/include/drivers/alarm.h b/components/drivers/include/drivers/alarm.h index dd59f4c1e8..e59c4142c7 100644 --- a/components/drivers/include/drivers/alarm.h +++ b/components/drivers/include/drivers/alarm.h @@ -49,6 +49,8 @@ struct rt_alarm rt_uint32_t flag; rt_alarm_callback_t callback; struct tm wktime; + + void *user_data; }; struct rt_alarm_setup diff --git a/components/drivers/rtc/alarm.c b/components/drivers/rtc/alarm.c index 53cb538321..ea1b150e7a 100644 --- a/components/drivers/rtc/alarm.c +++ b/components/drivers/rtc/alarm.c @@ -14,8 +14,16 @@ #include #include +#ifndef _WIN32 +#include +#endif + #define RT_RTC_YEARS_MAX 137 +#ifdef RT_USING_SOFT_RTC +#define RT_ALARM_DELAY 0 +#else #define RT_ALARM_DELAY 2 +#endif #define RT_ALARM_STATE_INITED 0x02 #define RT_ALARM_STATE_START 0x01 #define RT_ALARM_STATE_STOP 0x00 @@ -41,10 +49,12 @@ static rt_err_t alarm_set(struct rt_alarm *alarm) rt_err_t ret; device = rt_device_find("rtc"); + if (device == RT_NULL) { return (RT_ERROR); } + if (alarm->flag & RT_ALARM_STATE_START) wkalarm.enable = RT_TRUE; else @@ -215,7 +225,11 @@ static void alarm_update(rt_uint32_t event) { /* get time of now */ timestamp = time(RT_NULL); - localtime_r(×tamp, &now); +#ifdef _WIN32 + _gmtime32_s(&now, ×tamp); +#else + gmtime_r(×tamp, &now); +#endif for (next = _container.head.next; next != &_container.head; next = next->next) { @@ -225,7 +239,11 @@ static void alarm_update(rt_uint32_t event) } timestamp = time(RT_NULL); - localtime_r(×tamp, &now); +#ifdef _WIN32 + _gmtime32_s(&now, ×tamp); +#else + gmtime_r(×tamp, &now); +#endif sec_now = alarm_mkdaysec(&now); for (next = _container.head.next; next != &_container.head; next = next->next) @@ -233,7 +251,6 @@ static void alarm_update(rt_uint32_t event) alarm = rt_list_entry(next, struct rt_alarm, list); /* calculate seconds from 00:00:00 */ sec_alarm = alarm_mkdaysec(&alarm->wktime); - if (alarm->flag & RT_ALARM_STATE_START) { sec_tmp = sec_alarm - sec_now; @@ -257,6 +274,7 @@ static void alarm_update(rt_uint32_t event) } } } + /* enable the alarm after now first */ if (sec_next < 24 * 3600) { @@ -329,7 +347,12 @@ static rt_err_t alarm_setup(rt_alarm_t alarm, struct tm *wktime) setup = &alarm->wktime; *setup = *wktime; timestamp = time(RT_NULL); - localtime_r(×tamp, &now); + +#ifdef _WIN32 + _gmtime32_s(&now, ×tamp); +#else + gmtime_r(×tamp, &now); +#endif /* if these are a "don't care" value,we set them to now*/ if ((setup->tm_sec > 59) || (setup->tm_sec < 0)) @@ -526,21 +549,28 @@ rt_err_t rt_alarm_control(rt_alarm_t alarm, int cmd, void *arg) rt_err_t rt_alarm_start(rt_alarm_t alarm) { rt_int32_t sec_now, sec_old, sec_new; - rt_err_t ret = RT_ERROR; + rt_err_t ret = RT_EOK; time_t timestamp; struct tm now; if (alarm == RT_NULL) - return (ret); + return (RT_ERROR); rt_mutex_take(&_container.mutex, RT_WAITING_FOREVER); if (!(alarm->flag & RT_ALARM_STATE_START)) { if (alarm_setup(alarm, &alarm->wktime) != RT_EOK) + { + ret = RT_ERROR; goto _exit; + } timestamp = time(RT_NULL); - localtime_r(×tamp, &now); +#ifdef _WIN32 + _gmtime32_s(&now, ×tamp); +#else + gmtime_r(×tamp, &now); +#endif alarm->flag |= RT_ALARM_STATE_START; @@ -593,10 +623,10 @@ _exit: */ rt_err_t rt_alarm_stop(rt_alarm_t alarm) { - rt_err_t ret = RT_ERROR; + rt_err_t ret = RT_EOK; if (alarm == RT_NULL) - return (ret); + return (RT_ERROR); rt_mutex_take(&_container.mutex, RT_WAITING_FOREVER); if (!(alarm->flag & RT_ALARM_STATE_START)) goto _exit; @@ -695,23 +725,59 @@ static void rt_alarmsvc_thread_init(void *param) } } +struct _alarm_flag +{ + const char* name; + rt_uint32_t flag; +}; + +static const struct _alarm_flag _alarm_flag_tbl[] = +{ + {"N", 0xffff}, /* none */ + {"O", RT_ALARM_ONESHOT}, /* only alarm onece */ + {"D", RT_ALARM_DAILY}, /* alarm everyday */ + {"W", RT_ALARM_WEEKLY}, /* alarm weekly at Monday or Friday etc. */ + {"Mo", RT_ALARM_MONTHLY}, /* alarm monthly at someday */ + {"Y", RT_ALARM_YAERLY}, /* alarm yearly at a certain date */ + {"H", RT_ALARM_HOUR}, /* alarm each hour at a certain min:second */ + {"M", RT_ALARM_MINUTE}, /* alarm each minute at a certain second */ + {"S", RT_ALARM_SECOND}, /* alarm each second */ +}; + +static rt_uint8_t _alarm_flag_tbl_size = sizeof(_alarm_flag_tbl) / sizeof(_alarm_flag_tbl[0]); + +static rt_uint8_t get_alarm_flag_index(rt_uint32_t alarm_flag) +{ + for (rt_uint8_t index = 0; index < _alarm_flag_tbl_size; index++) + { + alarm_flag &= 0xff00; + if (alarm_flag == _alarm_flag_tbl[index].flag) + { + return index; + } + } + + return 0; +} + void rt_alarm_dump(void) { rt_list_t *next; rt_alarm_t alarm; rt_uint8_t index = 0; - rt_kprintf("| alarm_id | YYYY-MM-DD hh:mm:ss | weekday | flags |\n"); - rt_kprintf("+----------+---------------------+---------+---------+\n"); + rt_kprintf("| id | YYYY-MM-DD hh:mm:ss | week | flag | en |\n"); + rt_kprintf("+----+---------------------+------+------+----+\n"); for (next = _container.head.next; next != &_container.head; next = next->next) { alarm = rt_list_entry(next, struct rt_alarm, list); - rt_kprintf("| No %5d | %04d-%02d-%02d %02d:%02d:%02d | %7d | 0x%04x |\n", + rt_uint8_t flag_index = get_alarm_flag_index(alarm->flag); + rt_kprintf("| %2d | %04d-%02d-%02d %02d:%02d:%02d | %2d | %2s | %2d |\n", index++, alarm->wktime.tm_year + 1900, alarm->wktime.tm_mon + 1, alarm->wktime.tm_mday, alarm->wktime.tm_hour, alarm->wktime.tm_min, alarm->wktime.tm_sec, - alarm->wktime.tm_wday, alarm->flag); + alarm->wktime.tm_wday, _alarm_flag_tbl[flag_index].name, alarm->flag & RT_ALARM_STATE_START); } - rt_kprintf("+----------+---------------------+---------+---------+\n"); + rt_kprintf("+----+---------------------+------+------+----+\n"); } FINSH_FUNCTION_EXPORT_ALIAS(rt_alarm_dump, __cmd_alarm_dump, dump alarm info); diff --git a/components/drivers/rtc/soft_rtc.c b/components/drivers/rtc/soft_rtc.c index adcbf81fe3..6a04314675 100644 --- a/components/drivers/rtc/soft_rtc.c +++ b/components/drivers/rtc/soft_rtc.c @@ -11,8 +11,7 @@ #include #include #include - -#include +#include #ifdef RT_USING_SOFT_RTC @@ -28,9 +27,37 @@ static struct rt_device soft_rtc_dev; static rt_tick_t init_tick; static time_t init_time; +#ifdef RT_USING_ALARM + +static struct rt_rtc_wkalarm wkalarm; +static struct rt_timer alarm_time; + +static void alarm_timeout(void *param) +{ + rt_alarm_update(param, 1); +} + +static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm) +{ + rt_tick_t next_tick; + + if (palarm->enable) + { + next_tick = RT_TICK_PER_SECOND; + rt_timer_control(&alarm_time, RT_TIMER_CTRL_SET_TIME, &next_tick); + rt_timer_start(&alarm_time); + } + else + { + rt_timer_stop(&alarm_time); + } +} + +#endif + static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args) { - time_t *time; + time_t *t; struct tm time_temp; RT_ASSERT(dev != RT_NULL); @@ -39,16 +66,27 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args) switch (cmd) { case RT_DEVICE_CTRL_RTC_GET_TIME: - time = (time_t *) args; - *time = init_time + (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND; + t = (time_t *) args; + *t = init_time + (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND; break; - case RT_DEVICE_CTRL_RTC_SET_TIME: { - time = (time_t *) args; - init_time = *time - (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND; + t = (time_t *) args; + init_time = *t - (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND; +#ifdef RT_USING_ALARM + soft_rtc_alarm_update(&wkalarm); +#endif break; } +#ifdef RT_USING_ALARM + case RT_DEVICE_CTRL_RTC_GET_ALARM: + *((struct rt_rtc_wkalarm *)args) = wkalarm; + break; + case RT_DEVICE_CTRL_RTC_SET_ALARM: + wkalarm = *((struct rt_rtc_wkalarm *)args); + soft_rtc_alarm_update(&wkalarm); + break; +#endif } return RT_EOK; @@ -78,6 +116,15 @@ int rt_soft_rtc_init(void) /* make sure only one 'rtc' device */ RT_ASSERT(!rt_device_find("rtc")); +#ifdef RT_USING_ALARM + rt_timer_init(&alarm_time, + "alarm", + alarm_timeout, + &soft_rtc_dev, + 0, + RT_TIMER_FLAG_SOFT_TIMER|RT_TIMER_FLAG_ONE_SHOT); +#endif + init_tick = rt_tick_get(); init_time = mktime(&time_new); -- cgit v1.3.1 From 1ad70b20ad99833d25e0636e7065d8cdcabce388 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 4 Dec 2020 20:16:56 +0800 Subject: [keil][libc]防止开启pthread功能后 keil报错 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/sys/unistd.h | 2 ++ components/libc/compilers/common/sys/time.h | 7 +++++++ components/libc/compilers/dlib/sys/unistd.h | 2 ++ 3 files changed, 11 insertions(+) (limited to 'components') diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h index 524de2cf83..549771e8f4 100644 --- a/components/libc/compilers/armlibc/sys/unistd.h +++ b/components/libc/compilers/armlibc/sys/unistd.h @@ -68,4 +68,6 @@ int isatty (int fd); char * ttyname (int desc); +unsigned int sleep(unsigned int seconds); + #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 22f1c17f5e..952dbf32a5 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -36,6 +36,13 @@ struct timeval { }; #endif /* _TIMEVAL_DEFINED */ +#ifndef _TIMESPEC +#define _TIMESPEC +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h index 9564daba8d..982a29135d 100644 --- a/components/libc/compilers/dlib/sys/unistd.h +++ b/components/libc/compilers/dlib/sys/unistd.h @@ -40,4 +40,6 @@ int isatty (int fd); char * ttyname (int desc); +unsigned int sleep(unsigned int seconds); + #endif /* _SYS_UNISTD_H */ -- cgit v1.3.1 From 1f7a8e46a489724574ed0a51592318d6d00daa26 Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Mon, 7 Dec 2020 11:50:15 +0800 Subject: Update audio.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改注释错误 repaly ---> replay --- components/drivers/audio/audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/drivers/audio/audio.c b/components/drivers/audio/audio.c index 6614b75ff5..12b9b48a43 100644 --- a/components/drivers/audio/audio.c +++ b/components/drivers/audio/audio.c @@ -44,7 +44,7 @@ static rt_err_t _audio_send_replay_frame(struct rt_audio_device *audio) position = audio->replay->pos; dst_size = buf_info->block_size; - /* check repaly queue is empty */ + /* check replay queue is empty */ if (rt_data_queue_peak(&audio->replay->queue, (const void **)&data, &src_size) != RT_EOK) { /* ack stop event */ @@ -236,7 +236,7 @@ static rt_err_t _audio_dev_init(struct rt_device *dev) if (replay->mp == RT_NULL) { rt_free(replay); - LOG_E("create memory pool for repaly failed"); + LOG_E("create memory pool for replay failed"); return -RT_ENOMEM; } -- cgit v1.3.1 From 0f991c2e3e66fae0d0059d79ccc20f9bb0d824b4 Mon Sep 17 00:00:00 2001 From: caixf Date: Tue, 8 Dec 2020 15:48:58 +0800 Subject: [sal] fix --- components/net/sal_socket/src/sal_socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index ec0519df02..1e05aded59 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -309,12 +309,13 @@ struct sal_socket *sal_get_socket(int socket) { struct sal_socket_table *st = &socket_table; + socket = socket - SAL_SOCKET_OFFSET; + if (socket < 0 || socket >= (int) st->max_socket) { return RT_NULL; } - socket = socket - SAL_SOCKET_OFFSET; /* check socket structure valid or not */ RT_ASSERT(st->sockets[socket]->magic == SAL_SOCKET_MAGIC); @@ -975,7 +976,7 @@ int sal_closesocket(int socket) /* clsoesocket operation not need to vaild network interface status */ /* valid the network interface socket opreation */ - SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, socket); + SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, closesocket); if (pf->skt_ops->closesocket((int) sock->user_data) == 0) { -- cgit v1.3.1 From 82eac7106435a5fedf0a267f787b25d33083c2be Mon Sep 17 00:00:00 2001 From: thread-liu Date: Thu, 10 Dec 2020 09:12:55 +0800 Subject: [update] Incorrect macro definition name and update jobs name. --- .github/workflows/action.yml | 1 + components/net/netdev/src/netdev.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 001566c0aa..8335ee1b6a 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -24,6 +24,7 @@ on: jobs: build: runs-on: ubuntu-latest + name: ${{ matrix.legs.RTT_BSP }} strategy: fail-fast: false matrix: diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 646d2dfdd1..04bf6e8ad7 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -887,7 +887,7 @@ static void netdev_list_if(void) rt_kprintf("%02x ", netdev->hwaddr[index]); } } - else if (netdev->hwaddr_len == NETDEV_IFCONFIG_IEMI_MAX_LEN) + else if (netdev->hwaddr_len == NETDEV_IFCONFIG_IMEI_MAX_LEN) { rt_kprintf("IMEI: "); for (index = 0; index < netdev->hwaddr_len; index++) -- cgit v1.3.1 From c827a42a183f65117125d9cc40ea70db60316707 Mon Sep 17 00:00:00 2001 From: thread-liu Date: Thu, 10 Dec 2020 11:41:59 +0800 Subject: [update] audio deficiency head file, compile fail. --- components/drivers/audio/audio_pipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'components') diff --git a/components/drivers/audio/audio_pipe.c b/components/drivers/audio/audio_pipe.c index 0a6f090a83..e9de1ffb74 100644 --- a/components/drivers/audio/audio_pipe.c +++ b/components/drivers/audio/audio_pipe.c @@ -9,6 +9,7 @@ */ #include +#include #include "audio_pipe.h" static void _rt_pipe_resume_writer(struct rt_audio_pipe *pipe) -- cgit v1.3.1 From 1404d208db75a3475039b4d2eec6d0dcbd085170 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Mon, 14 Dec 2020 01:12:24 +0800 Subject: [ioctl] add TIOCSWINSZ --- components/drivers/serial/serial.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'components') diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 2511f18102..3a1c0fa0bb 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -24,6 +24,7 @@ * 2018-12-08 Ernest Chen add DMA choice * 2020-09-14 WillianChan add a line feed to the carriage return character * when using interrupt tx + * 2020-12-14 Meco Man add function of setting window's size(TIOCSWINSZ) */ #include @@ -1009,7 +1010,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev, } break; - +#ifdef RT_USING_POSIX #ifdef RT_USING_POSIX_TERMIOS case TCGETA: { @@ -1101,8 +1102,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev, break; case TCXONC: break; -#endif -#ifdef RT_USING_POSIX +#endif /*RT_USING_POSIX_TERMIOS*/ case FIONREAD: { rt_size_t recved = 0; @@ -1115,7 +1115,15 @@ static rt_err_t rt_serial_control(struct rt_device *dev, *(rt_size_t *)args = recved; } break; -#endif + case TIOCSWINSZ: + { + struct winsize* p_winsize; + + p_winsize = (struct winsize*)args; + rt_kprintf("\x1b[8;%d;%dt", p_winsize->ws_col, p_winsize->ws_row); + } + break; +#endif /*RT_USING_POSIX*/ default : /* control device */ ret = serial->ops->control(serial, cmd, args); -- cgit v1.3.1 From 702103a2037c7958f20b668aa138e4975a802c02 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 15:25:08 +0800 Subject: prepare for usleep --- components/libc/compilers/armlibc/sys/types.h | 14 ++++++++------ components/libc/compilers/armlibc/sys/unistd.h | 5 ++++- components/libc/compilers/dlib/sys/types.h | 13 +++++++------ components/libc/compilers/dlib/sys/unistd.h | 5 +++++ components/libc/time/posix_sleep.c | 8 ++++++-- 5 files changed, 30 insertions(+), 15 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/armlibc/sys/types.h index 2aad77c99d..78fee1bb99 100644 --- a/components/libc/compilers/armlibc/sys/types.h +++ b/components/libc/compilers/armlibc/sys/types.h @@ -5,20 +5,22 @@ * * Change Logs: * Date Author Notes - * 2020-09-05 Meco Man fix bugs + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t */ #ifndef __TYPES_H__ #define __TYPES_H__ #include -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ #ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ #else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ #endif diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h index 549771e8f4..73a73a267e 100644 --- a/components/libc/compilers/armlibc/sys/unistd.h +++ b/components/libc/compilers/armlibc/sys/unistd.h @@ -5,11 +5,13 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ #ifndef _SYS_UNISTD_H #define _SYS_UNISTD_H -#include +#include +#include "types.h" #ifdef RT_USING_DFS @@ -69,5 +71,6 @@ int isatty (int fd); char * ttyname (int desc); unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/dlib/sys/types.h b/components/libc/compilers/dlib/sys/types.h index 001ace4dd2..7dbeddcaa9 100644 --- a/components/libc/compilers/dlib/sys/types.h +++ b/components/libc/compilers/dlib/sys/types.h @@ -5,20 +5,21 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add useconds_t */ #ifndef __TYPES_H__ #define __TYPES_H__ #include -#include -typedef rt_int32_t clockid_t; -typedef rt_int32_t key_t; /* Used for interprocess communication. */ -typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */ +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ #ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ #else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ #endif diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h index 982a29135d..6d99cd6c55 100644 --- a/components/libc/compilers/dlib/sys/unistd.h +++ b/components/libc/compilers/dlib/sys/unistd.h @@ -5,10 +5,14 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ #ifndef _SYS_UNISTD_H #define _SYS_UNISTD_H +#include +#include "types.h" + #ifdef RT_USING_DFS #define STDIN_FILENO 0 /* standard input file descriptor */ @@ -41,5 +45,6 @@ int isatty (int fd); char * ttyname (int desc); unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c index f21b0a7994..d45b3b945f 100644 --- a/components/libc/time/posix_sleep.c +++ b/components/libc/time/posix_sleep.c @@ -5,10 +5,9 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ -#include #include - #include unsigned int sleep(unsigned int seconds) @@ -21,3 +20,8 @@ unsigned int sleep(unsigned int seconds) return seconds - delta_tick/RT_TICK_PER_SECOND; } + +int usleep(useconds_t usec) +{ + +} -- cgit v1.3.1 From 9d004a2892394436e3a07a5dfb3e0fa9e8076433 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 15:34:41 +0800 Subject: 实现 usleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/time/posix_sleep.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c index d45b3b945f..e50bda7d4a 100644 --- a/components/libc/time/posix_sleep.c +++ b/components/libc/time/posix_sleep.c @@ -8,6 +8,7 @@ * 2020-12-16 Meco Man add usleep */ #include +#include #include unsigned int sleep(unsigned int seconds) @@ -23,5 +24,7 @@ unsigned int sleep(unsigned int seconds) int usleep(useconds_t usec) { - + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; } -- cgit v1.3.1 From e5b10628ee001543c6ee8d458b1dde5d4941953c Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 16:05:43 +0800 Subject: update --- components/libc/compilers/common/sys/time.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 952dbf32a5..06add3ba91 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -36,8 +36,7 @@ struct timeval { }; #endif /* _TIMEVAL_DEFINED */ -#ifndef _TIMESPEC -#define _TIMESPEC +#ifndef __GNUC__ struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1 From ab754255407c2af40d6cea61dae1a314947d0886 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Thu, 17 Dec 2020 11:32:10 +0800 Subject: update --- components/libc/compilers/common/sys/time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 06add3ba91..28a977c1f9 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -36,7 +36,7 @@ struct timeval { }; #endif /* _TIMEVAL_DEFINED */ -#ifndef __GNUC__ +#if !defined __GNUC__ && !defined __ICCARM__ struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1 From 963f35e96d9ae16d9e3a66a2760bd5c8138cf211 Mon Sep 17 00:00:00 2001 From: liuduanfei <939763442@qq.com> Date: Fri, 18 Dec 2020 20:53:33 +0800 Subject: Update netdev.c --- components/net/netdev/src/netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 04bf6e8ad7..92d5b188eb 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -78,7 +78,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data) netdev->addr_callback = RT_NULL; /* fill network interface device */ - rt_strncpy(netdev->name, name, rt_strlen(name)); + rt_strncpy(netdev->name, name, RT_NAME_MAX); netdev->user_data = user_data; /* initialize current network interface device single list */ @@ -260,7 +260,7 @@ struct netdev *netdev_get_by_name(const char *name) for (node = &(netdev_list->list); node; node = rt_slist_next(node)) { netdev = rt_slist_entry(node, struct netdev, list); - if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name)) == 0)) + if (netdev && (rt_strncmp(netdev->name, name, RT_NAME_MAX) == 0)) { rt_hw_interrupt_enable(level); return netdev; -- cgit v1.3.1 From e7ed7642540ba97045cd0c717d503431d4eea371 Mon Sep 17 00:00:00 2001 From: Prry <445395670@qq.com> Date: Sat, 19 Dec 2020 12:23:37 +0800 Subject: 添加TOF传感器描述信息 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/sensors/sensor.c | 3 ++- components/drivers/sensors/sensor.h | 1 + components/drivers/sensors/sensor_cmd.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) (limited to 'components') diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index eb5c97a574..07999c73b3 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -35,7 +35,8 @@ static char *const sensor_name_str[] = "forc_", /* Force sensor */ "dust_", /* Dust sensor */ "eco2_", /* eCO2 sensor */ - "gnss_" /* GPS/GNSS sensor */ + "gnss_", /* GPS/GNSS sensor */ + "tof_" /* TOF sensor */ }; /* Sensor interrupt correlation function */ diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index 5a069edc25..b180e36a73 100755 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -48,6 +48,7 @@ extern "C" { #define RT_SENSOR_CLASS_DUST (14) /* Dust sensor */ #define RT_SENSOR_CLASS_ECO2 (15) /* eCO2 sensor */ #define RT_SENSOR_CLASS_GNSS (16) /* GPS/GNSS sensor */ +#define RT_SENSOR_CLASS_TOF (17) /* TOF sensor */ /* Sensor vendor types */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 284db75cf6..09887d4b5f 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -50,6 +50,7 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor LOG_I("num:%3d, light:%5d lux, timestamp:%5d", num, sensor_data->data.light, sensor_data->timestamp); break; case RT_SENSOR_CLASS_PROXIMITY: + case RT_SENSOR_CLASS_TOF: LOG_I("num:%3d, distance:%5d, timestamp:%5d", num, sensor_data->data.proximity, sensor_data->timestamp); break; case RT_SENSOR_CLASS_HR: -- cgit v1.3.1 From a38e7768ac9037b6c530dabdea90747e6dbd2a88 Mon Sep 17 00:00:00 2001 From: Prry <445395670@qq.com> Date: Sun, 20 Dec 2020 22:23:28 +0800 Subject: 缩进由“TAB键”改用为“空格” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/sensors/sensor.c | 2 +- components/drivers/sensors/sensor_cmd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index 07999c73b3..bbfcea97be 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -36,7 +36,7 @@ static char *const sensor_name_str[] = "dust_", /* Dust sensor */ "eco2_", /* eCO2 sensor */ "gnss_", /* GPS/GNSS sensor */ - "tof_" /* TOF sensor */ + "tof_" /* TOF sensor */ }; /* Sensor interrupt correlation function */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 09887d4b5f..cbf7d233c6 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -50,7 +50,7 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor LOG_I("num:%3d, light:%5d lux, timestamp:%5d", num, sensor_data->data.light, sensor_data->timestamp); break; case RT_SENSOR_CLASS_PROXIMITY: - case RT_SENSOR_CLASS_TOF: + case RT_SENSOR_CLASS_TOF: LOG_I("num:%3d, distance:%5d, timestamp:%5d", num, sensor_data->data.proximity, sensor_data->timestamp); break; case RT_SENSOR_CLASS_HR: -- cgit v1.3.1 From 48d7cf4af9f26fc9dcc09283831efa5dbbea269c Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Fri, 25 Dec 2020 17:31:16 +0800 Subject: 【修改】解耦 touch 和 pin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/Kconfig | 5 +++++ components/drivers/touch/touch.c | 26 ++++++++++++++++++-------- components/drivers/touch/touch.h | 5 +++++ 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'components') diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 198f1bbbf8..006497519f 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -291,6 +291,11 @@ endif config RT_USING_TOUCH bool "Using Touch device drivers" default n + if RT_USING_TOUCH + config RT_TOUCH_PIN_IRQ + bool "touch irq use pin irq" + default n + endif menuconfig RT_USING_HWCRYPTO bool "Using Hardware Crypto drivers" diff --git a/components/drivers/touch/touch.c b/components/drivers/touch/touch.c index 80ba6378bb..e9595e9f8f 100644 --- a/components/drivers/touch/touch.c +++ b/components/drivers/touch/touch.c @@ -16,12 +16,9 @@ #include /* ISR for touch interrupt */ -static void irq_callback(void *args) +void rt_hw_touch_isr(rt_touch_t touch) { - rt_touch_t touch; - - touch = (rt_touch_t)args; - + RT_ASSERT(touch); if (touch->parent.rx_indicate == RT_NULL) { return; @@ -35,9 +32,17 @@ static void irq_callback(void *args) touch->parent.rx_indicate(&touch->parent, 1); } +#ifdef RT_TOUCH_PIN_IRQ +static void touch_irq_callback(void *param) +{ + rt_hw_touch_isr((rt_touch_t)param); +} +#endif + /* touch interrupt initialization function */ static rt_err_t rt_touch_irq_init(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin == RT_PIN_NONE) { return -RT_EINVAL; @@ -47,18 +52,19 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch) if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLDOWN) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, touch_irq_callback, (void *)touch); } else if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLUP) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, touch_irq_callback, (void *)touch); } else if (touch->config.irq_pin.mode == PIN_MODE_INPUT) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, touch_irq_callback, (void *)touch); } rt_pin_irq_enable(touch->config.irq_pin.pin, PIN_IRQ_ENABLE); +#endif return RT_EOK; } @@ -66,19 +72,23 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch) /* touch interrupt enable */ static void rt_touch_irq_enable(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin != RT_PIN_NONE) { rt_pin_irq_enable(touch->config.irq_pin.pin, RT_TRUE); } +#endif } /* touch interrupt disable */ static void rt_touch_irq_disable(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin != RT_PIN_NONE) { rt_pin_irq_enable(touch->config.irq_pin.pin, RT_FALSE); } +#endif } static rt_err_t rt_touch_open(rt_device_t dev, rt_uint16_t oflag) diff --git a/components/drivers/touch/touch.h b/components/drivers/touch/touch.h index c33fe17520..be12c24206 100644 --- a/components/drivers/touch/touch.h +++ b/components/drivers/touch/touch.h @@ -66,7 +66,9 @@ struct rt_touch_info struct rt_touch_config { +#ifdef RT_TOUCH_PIN_IRQ struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */ +#endif char *dev_name; /* The name of the communication device */ void *user_data; }; @@ -103,6 +105,9 @@ int rt_hw_touch_register(rt_touch_t touch, rt_uint32_t flag, void *data); +/* if you doesn't use pin device. you must call this function in your touch irq callback */ +void rt_hw_touch_isr(rt_touch_t touch); + #ifdef __cplusplus } #endif -- cgit v1.3.1