mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-29 02:20:21 +00:00
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
This commit is contained in:
@@ -141,7 +141,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||
d->fops = dfs_net_get_fops();
|
||||
/* initialize wait head */
|
||||
lwsock = lwip_tryget_socket(new_client);
|
||||
rt_list_init(&(lwsock->wait_head));
|
||||
rt_wqueue_init(&(lwsock->wait_head));
|
||||
|
||||
d->flags = O_RDWR; /* set flags as read and write */
|
||||
d->size = 0;
|
||||
@@ -317,7 +317,7 @@ int socket(int domain, int type, int protocol)
|
||||
d->data = (void *) sock;
|
||||
|
||||
lwsock = lwip_tryget_socket(sock);
|
||||
rt_list_init(&(lwsock->wait_head));
|
||||
rt_wqueue_init(&(lwsock->wait_head));
|
||||
lwsock->conn->callback = event_callback;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -55,8 +55,16 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd);
|
||||
/**
|
||||
* this function will initialize device file system.
|
||||
*/
|
||||
static volatile uint8_t init_ok = 0;
|
||||
int dfs_init(void)
|
||||
{
|
||||
if(init_ok)
|
||||
{
|
||||
rt_kprintf("dfs already init.\n");
|
||||
return 0;
|
||||
}
|
||||
init_ok = 1;
|
||||
|
||||
/* clear filesystem operations table */
|
||||
memset((void *)filesystem_operation_table, 0, sizeof(filesystem_operation_table));
|
||||
/* clear filesystem table */
|
||||
|
||||
@@ -4,6 +4,12 @@ config RT_USING_DEVICE_IPC
|
||||
bool "Using device drivers IPC"
|
||||
default y
|
||||
|
||||
if RT_USING_DEVICE_IPC
|
||||
config RT_PIPE_BUFSZ
|
||||
int "Set pipe buffer size"
|
||||
default 512
|
||||
endif
|
||||
|
||||
config RT_USING_SERIAL
|
||||
bool "Using serial device drivers"
|
||||
select RT_USING_DEVICE_IPC
|
||||
|
||||
@@ -222,26 +222,13 @@ extern "C" {
|
||||
#define USB_EP_DESC_NUM(addr) (addr & USB_EP_DESC_NUM_MASK)
|
||||
#define USB_EP_DIR(addr) ((addr & USB_DIR_MASK)>>7)
|
||||
|
||||
#ifdef RT_USB_DEVICE_HID
|
||||
#ifdef RT_USB_DEVICE_HID_KEYBOARD
|
||||
#define HID_REPORT_ID_KEYBOARD1 1
|
||||
#if RT_USB_DEVICE_HID_KEYBOARD_NUMBER>1
|
||||
#define HID_REPORT_ID_KEYBOARD2 2
|
||||
#if RT_USB_DEVICE_HID_KEYBOARD_NUMBER>2
|
||||
#define HID_REPORT_ID_KEYBOARD3 3
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef RT_USB_DEVICE_HID_MEDIA
|
||||
#define HID_REPORT_ID_MEDIA 4
|
||||
#endif
|
||||
#ifdef RT_USB_DEVICE_HID_GENERAL
|
||||
#define HID_REPORT_ID_GENERAL 5
|
||||
#endif
|
||||
#ifdef RT_USB_DEVICE_HID_MOUSE
|
||||
#define HID_REPORT_ID_MOUSE 6
|
||||
#endif
|
||||
#endif
|
||||
#define HID_REPORT_ID_KEYBOARD1 1
|
||||
#define HID_REPORT_ID_KEYBOARD2 2
|
||||
#define HID_REPORT_ID_KEYBOARD3 3
|
||||
#define HID_REPORT_ID_KEYBOARD4 7
|
||||
#define HID_REPORT_ID_MEDIA 4
|
||||
#define HID_REPORT_ID_GENERAL 5
|
||||
#define HID_REPORT_ID_MOUSE 6
|
||||
|
||||
#define uswap_32(x) \
|
||||
((((x) & 0xff000000) >> 24) | \
|
||||
@@ -473,7 +460,6 @@ typedef struct usb_os_proerty * usb_os_proerty_t;
|
||||
#define HID_SUB_DESCRIPTOR_MAX 1
|
||||
#endif
|
||||
|
||||
#ifdef RT_USB_DEVICE_HID
|
||||
struct uhid_descriptor
|
||||
{
|
||||
rt_uint8_t bLength;
|
||||
@@ -497,7 +483,7 @@ struct hid_report
|
||||
};
|
||||
typedef struct hid_report* hid_report_t;
|
||||
extern void HID_Report_Received(hid_report_t report);
|
||||
#endif
|
||||
|
||||
struct urequest
|
||||
{
|
||||
rt_uint8_t request_type;
|
||||
|
||||
@@ -32,5 +32,5 @@ struct rt_pipe_device
|
||||
typedef struct rt_pipe_device rt_pipe_t;
|
||||
|
||||
rt_pipe_t *rt_pipe_create(const char *name, int bufsz);
|
||||
|
||||
int rt_pipe_delete(const char *name);
|
||||
#endif /* PIPE_H__ */
|
||||
|
||||
@@ -1,25 +1,59 @@
|
||||
/*
|
||||
* File : waitqueue.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
|
||||
* to blocked thread.
|
||||
*/
|
||||
|
||||
#ifndef WAITQUEUE_H__
|
||||
#define WAITQUEUE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
struct rt_wqueue_node;
|
||||
#define RT_WQ_FLAG_CLEAN 0x00
|
||||
#define RT_WQ_FLAG_WAKEUP 0x01
|
||||
|
||||
typedef rt_list_t rt_wqueue_t;
|
||||
struct rt_wqueue_node;
|
||||
typedef int (*rt_wqueue_func_t)(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
struct rt_wqueue_node
|
||||
{
|
||||
rt_thread_t polling_thread;
|
||||
rt_list_t list;
|
||||
rt_thread_t polling_thread;
|
||||
rt_list_t list;
|
||||
|
||||
rt_wqueue_func_t wakeup;
|
||||
rt_uint32_t key;
|
||||
rt_wqueue_func_t wakeup;
|
||||
rt_uint32_t key;
|
||||
};
|
||||
typedef struct rt_wqueue_node rt_wqueue_node_t;
|
||||
|
||||
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
rt_inline void rt_wqueue_init(rt_wqueue_t *queue)
|
||||
{
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
|
||||
queue->flag = RT_WQ_FLAG_CLEAN;
|
||||
rt_list_init(&(queue->waiting_list));
|
||||
}
|
||||
|
||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node);
|
||||
void rt_wqueue_remove(struct rt_wqueue_node *node);
|
||||
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int timeout);
|
||||
|
||||
@@ -438,8 +438,8 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
|
||||
|
||||
rt_memset(pipe, 0, sizeof(rt_pipe_t));
|
||||
rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_FIFO);
|
||||
rt_list_init(&(pipe->reader_queue));
|
||||
rt_list_init(&(pipe->writer_queue));
|
||||
rt_wqueue_init(&(pipe->reader_queue));
|
||||
rt_wqueue_init(&(pipe->writer_queue));
|
||||
|
||||
RT_ASSERT(bufsz < 0xFFFF);
|
||||
pipe->bufsz = bufsz;
|
||||
|
||||
@@ -1,17 +1,40 @@
|
||||
/*
|
||||
* File : waitqueue.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
|
||||
* to blocked thread.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtservice.h>
|
||||
|
||||
extern struct rt_thread *rt_current_thread;
|
||||
|
||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_list_insert_before(queue, &(node->list));
|
||||
rt_list_insert_before(&(queue->waiting_list), &(node->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
@@ -34,23 +57,29 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||
rt_base_t level;
|
||||
register int need_schedule = 0;
|
||||
|
||||
rt_list_t *queue_list;
|
||||
struct rt_list_node *node;
|
||||
struct rt_wqueue_node *entry;
|
||||
|
||||
if (rt_list_isempty(queue))
|
||||
return;
|
||||
queue_list = &(queue->waiting_list);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
for (node = queue->next; node != queue; node = node->next)
|
||||
{
|
||||
entry = rt_list_entry(node, struct rt_wqueue_node, list);
|
||||
if (entry->wakeup(entry, key) == 0)
|
||||
{
|
||||
rt_thread_resume(entry->polling_thread);
|
||||
need_schedule = 1;
|
||||
/* set wakeup flag in the queue */
|
||||
queue->flag = RT_WQ_FLAG_WAKEUP;
|
||||
|
||||
rt_wqueue_remove(entry);
|
||||
break;
|
||||
if (!(rt_list_isempty(queue_list)))
|
||||
{
|
||||
for (node = queue_list->next; node != queue_list; node = node->next)
|
||||
{
|
||||
entry = rt_list_entry(node, struct rt_wqueue_node, list);
|
||||
if (entry->wakeup(entry, key) == 0)
|
||||
{
|
||||
rt_thread_resume(entry->polling_thread);
|
||||
need_schedule = 1;
|
||||
|
||||
rt_wqueue_remove(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
@@ -62,7 +91,7 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
|
||||
{
|
||||
int tick;
|
||||
rt_thread_t tid = rt_current_thread;
|
||||
rt_thread_t tid = rt_thread_self();
|
||||
rt_timer_t tmr = &(tid->thread_timer);
|
||||
struct rt_wqueue_node __wait;
|
||||
rt_base_t level;
|
||||
@@ -81,6 +110,12 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
|
||||
rt_list_init(&__wait.list);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
if (queue->flag == RT_WQ_FLAG_WAKEUP)
|
||||
{
|
||||
/* already wakeup */
|
||||
goto __exit_wakeup;
|
||||
}
|
||||
|
||||
rt_wqueue_add(queue, &__wait);
|
||||
rt_thread_suspend(tid);
|
||||
|
||||
@@ -97,6 +132,12 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
|
||||
|
||||
rt_schedule();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
__exit_wakeup:
|
||||
queue->flag = 0;
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
rt_wqueue_remove(&__wait);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -129,6 +129,34 @@ const rt_uint8_t _report_desc[]=
|
||||
USAGE_MAXIMUM(1), 0x65,
|
||||
INPUT(1), 0x00,
|
||||
END_COLLECTION(0),
|
||||
#if RT_USB_DEVICE_HID_KEYBOARD_NUMBER>3
|
||||
USAGE_PAGE(1), 0x01,
|
||||
USAGE(1), 0x06,
|
||||
COLLECTION(1), 0x01,
|
||||
REPORT_ID(1), HID_REPORT_ID_KEYBOARD4,
|
||||
|
||||
USAGE_PAGE(1), 0x07,
|
||||
USAGE_MINIMUM(1), 0xE0,
|
||||
USAGE_MAXIMUM(1), 0xE7,
|
||||
LOGICAL_MINIMUM(1), 0x00,
|
||||
LOGICAL_MAXIMUM(1), 0x01,
|
||||
REPORT_SIZE(1), 0x01,
|
||||
REPORT_COUNT(1), 0x08,
|
||||
INPUT(1), 0x02,
|
||||
REPORT_COUNT(1), 0x01,
|
||||
REPORT_SIZE(1), 0x08,
|
||||
INPUT(1), 0x01,
|
||||
|
||||
REPORT_COUNT(1), 0x06,
|
||||
REPORT_SIZE(1), 0x08,
|
||||
LOGICAL_MINIMUM(1), 0x00,
|
||||
LOGICAL_MAXIMUM(1), 0x65,
|
||||
USAGE_PAGE(1), 0x07,
|
||||
USAGE_MINIMUM(1), 0x00,
|
||||
USAGE_MAXIMUM(1), 0x65,
|
||||
INPUT(1), 0x00,
|
||||
END_COLLECTION(0),
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -117,7 +117,18 @@ int rt_wlan_softap(struct rt_wlan_device *device, struct rt_wlan_info *info, cha
|
||||
rt_wlan_set_info(device, info);
|
||||
}
|
||||
|
||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||
if (password == NULL)
|
||||
{
|
||||
memset(device->key, 0, sizeof(device->key));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rt_strlen(password) > sizeof(device->key) - 1)
|
||||
{
|
||||
rt_kprintf("WARN input password is longer than %d bytes.", sizeof(device->key) - 1);
|
||||
}
|
||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||
}
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SOFTAP, (void *)password);
|
||||
|
||||
|
||||
@@ -313,6 +313,44 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(RT_USING_LWP) && defined(RT_USING_DFS)
|
||||
static int _msh_exec_lwp(char *cmd, rt_size_t length)
|
||||
{
|
||||
int argc;
|
||||
int cmd0_size = 0;
|
||||
char *argv[FINSH_ARG_MAX];
|
||||
int fd = -1;
|
||||
char *pg_name;
|
||||
|
||||
extern int exec(char*, int, char**);
|
||||
|
||||
/* find the size of first command */
|
||||
while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
|
||||
cmd0_size ++;
|
||||
if (cmd0_size == 0)
|
||||
return -1;
|
||||
|
||||
/* split arguments */
|
||||
rt_memset(argv, 0x00, sizeof(argv));
|
||||
argc = msh_split(cmd, length, argv);
|
||||
if (argc == 0)
|
||||
return -1;
|
||||
|
||||
pg_name = argv[0];
|
||||
/* try to open program */
|
||||
fd = open(pg_name, O_RDONLY, 0);
|
||||
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
/* found program */
|
||||
close(fd);
|
||||
exec(pg_name, argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int msh_exec(char *cmd, rt_size_t length)
|
||||
{
|
||||
int cmd_ret;
|
||||
@@ -356,6 +394,13 @@ int msh_exec(char *cmd, rt_size_t length)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RT_USING_LWP) && defined(RT_USING_DFS)
|
||||
if (_msh_exec_lwp(cmd, length) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* truncate the cmd at the first space. */
|
||||
{
|
||||
char *tcmd;
|
||||
|
||||
@@ -381,14 +381,19 @@ int cmd_dns(int argc, char **argv)
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_dns, __cmd_dns, list the information of dns);
|
||||
#endif
|
||||
|
||||
#ifdef RT_LWIP_TCP
|
||||
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
|
||||
int cmd_netstat(int argc, char **argv)
|
||||
{
|
||||
extern void list_tcps(void);
|
||||
extern void list_udps(void);
|
||||
|
||||
#ifdef RT_LWIP_TCP
|
||||
list_tcps();
|
||||
#endif
|
||||
#ifdef RT_LWIP_UDP
|
||||
list_udps();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(cmd_netstat, __cmd_netstat, list the information of TCP / IP);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
* 2011-02-23 Bernard fix variable section end issue of finsh shell
|
||||
* initialization when use GNU GCC compiler.
|
||||
* 2016-11-26 armink add password authentication
|
||||
* 2018-07-02 aozima add custome prompt support.
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -56,17 +57,54 @@ ALIGN(RT_ALIGN_SIZE)
|
||||
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
||||
#endif
|
||||
struct finsh_shell *shell;
|
||||
static char *finsh_prompt_custom = RT_NULL;
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
int finsh_set_prompt(const char * prompt)
|
||||
{
|
||||
if(finsh_prompt_custom)
|
||||
{
|
||||
rt_free(finsh_prompt_custom);
|
||||
finsh_prompt_custom = RT_NULL;
|
||||
}
|
||||
|
||||
/* strdup */
|
||||
if(prompt)
|
||||
{
|
||||
finsh_prompt_custom = rt_malloc(strlen(prompt)+1);
|
||||
if(finsh_prompt_custom)
|
||||
{
|
||||
strcpy(finsh_prompt_custom, prompt);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
|
||||
#if defined(RT_USING_DFS)
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
#endif /* RT_USING_DFS */
|
||||
|
||||
const char *finsh_get_prompt()
|
||||
{
|
||||
#define _MSH_PROMPT "msh "
|
||||
#define _PROMPT "finsh "
|
||||
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
|
||||
|
||||
/* check prompt mode */
|
||||
if (!shell->prompt_mode)
|
||||
{
|
||||
finsh_prompt[0] = '\0';
|
||||
return finsh_prompt;
|
||||
}
|
||||
|
||||
if(finsh_prompt_custom)
|
||||
{
|
||||
strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt)-1);
|
||||
return finsh_prompt;
|
||||
}
|
||||
|
||||
#ifdef FINSH_USING_MSH
|
||||
if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
|
||||
else
|
||||
@@ -82,7 +120,34 @@ const char *finsh_get_prompt()
|
||||
|
||||
return finsh_prompt;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup finsh
|
||||
*
|
||||
* This function get the prompt mode of finsh shell.
|
||||
*
|
||||
* @return prompt the prompt mode, 0 disable prompt mode, other values enable prompt mode.
|
||||
*/
|
||||
rt_uint32_t finsh_get_prompt_mode(void)
|
||||
{
|
||||
RT_ASSERT(shell != RT_NULL);
|
||||
return shell->prompt_mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup finsh
|
||||
*
|
||||
* This function set the prompt mode of finsh shell.
|
||||
*
|
||||
* The parameter 0 disable prompt mode, other values enable prompt mode.
|
||||
*
|
||||
* @param prompt the prompt mode
|
||||
*/
|
||||
void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
|
||||
{
|
||||
RT_ASSERT(shell != RT_NULL);
|
||||
shell->prompt_mode = prompt_mode;
|
||||
}
|
||||
|
||||
static char finsh_getchar(void)
|
||||
{
|
||||
@@ -726,6 +791,12 @@ int finsh_system_init(void)
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_thread_t tid;
|
||||
|
||||
if(shell)
|
||||
{
|
||||
rt_kprintf("finsh shell already init.\n");
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
#ifdef FINSH_USING_SYMTAB
|
||||
#ifdef __CC_ARM /* ARM C Compiler */
|
||||
extern const int FSymTab$$Base;
|
||||
@@ -789,6 +860,7 @@ int finsh_system_init(void)
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
|
||||
finsh_set_prompt_mode(1);
|
||||
|
||||
if (tid != NULL && result == RT_EOK)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
@@ -44,12 +44,10 @@
|
||||
#endif
|
||||
|
||||
#define FINSH_OPTION_ECHO 0x01
|
||||
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
|
||||
|
||||
#define FINSH_PROMPT finsh_get_prompt()
|
||||
const char* finsh_get_prompt(void);
|
||||
#else
|
||||
#define FINSH_PROMPT "finsh>>"
|
||||
#endif
|
||||
int finsh_set_prompt(const char * prompt);
|
||||
|
||||
#ifdef FINSH_USING_HISTORY
|
||||
#ifndef FINSH_HISTORY_LINES
|
||||
@@ -86,6 +84,7 @@ struct finsh_shell
|
||||
enum input_stat stat;
|
||||
|
||||
rt_uint8_t echo_mode:1;
|
||||
rt_uint8_t prompt_mode: 1;
|
||||
|
||||
#ifdef FINSH_USING_HISTORY
|
||||
rt_uint16_t current_history;
|
||||
@@ -118,6 +117,9 @@ int finsh_system_init(void);
|
||||
void finsh_set_device(const char* device_name);
|
||||
const char* finsh_get_device(void);
|
||||
|
||||
rt_uint32_t finsh_get_prompt_mode(void);
|
||||
void finsh_set_prompt_mode(rt_uint32_t prompt_mode);
|
||||
|
||||
#ifdef FINSH_USING_AUTH
|
||||
rt_err_t finsh_set_password(const char *password);
|
||||
const char *finsh_get_password(void);
|
||||
|
||||
@@ -34,33 +34,33 @@
|
||||
IMPORT lwp_set_kernel_sp
|
||||
|
||||
;/*
|
||||
; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr);
|
||||
; * void lwp_user_entry(args, text, data);
|
||||
; */
|
||||
lwp_user_entry PROC
|
||||
EXPORT lwp_user_entry
|
||||
|
||||
PUSH {R0-R1} ; push text&data addr.
|
||||
PUSH {R0-R3} ; push text&data addr.
|
||||
|
||||
MOV R0, SP ; v1 = SP
|
||||
BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1)
|
||||
|
||||
POP {R0-R1} ; pop app address to R1.
|
||||
|
||||
; set CPU to user-thread mode.
|
||||
MRS R2, CONTROL
|
||||
ORR R2, R2, #0x03 ; use PSP, user-thread mode.
|
||||
MSR CONTROL, R2
|
||||
|
||||
POP {R0-R3} ; pop app address to R1.
|
||||
; set data address.
|
||||
MOV R9, R1
|
||||
MOV R9, R2
|
||||
|
||||
; run app, only Thumb-mode.
|
||||
ORR R0, R0, #0x01
|
||||
BX R0
|
||||
ORR R1, R1, #0x01
|
||||
BX R1
|
||||
|
||||
; never reach here!
|
||||
ENDP
|
||||
|
||||
|
||||
;/*
|
||||
; * void SVC_Handler(void);
|
||||
; */
|
||||
|
||||
@@ -34,33 +34,33 @@
|
||||
IMPORT lwp_set_kernel_sp
|
||||
|
||||
;/*
|
||||
; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr);
|
||||
; * void lwp_user_entry(args, text, data);
|
||||
; */
|
||||
lwp_user_entry PROC
|
||||
EXPORT lwp_user_entry
|
||||
|
||||
PUSH {R0-R1} ; push text&data addr.
|
||||
PUSH {R0-R3} ; push text&data addr.
|
||||
|
||||
MOV R0, SP ; v1 = SP
|
||||
BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1)
|
||||
|
||||
POP {R0-R1} ; pop app address to R1.
|
||||
|
||||
; set CPU to user-thread mode.
|
||||
MRS R2, CONTROL
|
||||
ORR R2, R2, #0x03 ; use PSP, user-thread mode.
|
||||
MSR CONTROL, R2
|
||||
|
||||
POP {R0-R3} ; pop app address to R1.
|
||||
; set data address.
|
||||
MOV R9, R1
|
||||
MOV R9, R2
|
||||
|
||||
; run app, only Thumb-mode.
|
||||
ORR R0, R0, #0x01
|
||||
BX R0
|
||||
ORR R1, R1, #0x01
|
||||
BX R1
|
||||
|
||||
; never reach here!
|
||||
ENDP
|
||||
|
||||
|
||||
;/*
|
||||
; * void SVC_Handler(void);
|
||||
; */
|
||||
|
||||
@@ -34,29 +34,28 @@
|
||||
IMPORT lwp_set_kernel_sp
|
||||
|
||||
;/*
|
||||
; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr);
|
||||
; * void lwp_user_entry(args, text, data);
|
||||
; */
|
||||
lwp_user_entry PROC
|
||||
EXPORT lwp_user_entry
|
||||
|
||||
PUSH {R0-R1} ; push text&data addr.
|
||||
PUSH {R0-R3} ; push text&data addr.
|
||||
|
||||
MOV R0, SP ; v1 = SP
|
||||
BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1)
|
||||
|
||||
POP {R0-R1} ; pop app address to R1.
|
||||
|
||||
; set CPU to user-thread mode.
|
||||
MRS R2, CONTROL
|
||||
ORR R2, R2, #0x03 ; use PSP, user-thread mode.
|
||||
MSR CONTROL, R2
|
||||
|
||||
POP {R0-R3} ; pop app address to R1.
|
||||
; set data address.
|
||||
MOV R9, R1
|
||||
MOV R9, R2
|
||||
|
||||
; run app, only Thumb-mode.
|
||||
ORR R0, R0, #0x01
|
||||
BX R0
|
||||
ORR R1, R1, #0x01
|
||||
BX R1
|
||||
|
||||
; never reach here!
|
||||
ENDP
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
#include <rthw.h>
|
||||
#include <dfs_posix.h>
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
#endif
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
#error "lwp need file system(RT_USING_DFS)"
|
||||
#endif
|
||||
@@ -38,11 +34,11 @@
|
||||
#define DBG_ENABLE
|
||||
#define DBG_SECTION_NAME "[LWP]"
|
||||
#define DBG_COLOR
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#define DBG_LEVEL DBG_WARNING
|
||||
#include <rtdbg.h>
|
||||
|
||||
extern rt_thread_t rt_current_thread;
|
||||
extern void lwp_user_entry(const void *text, void *data);
|
||||
extern void lwp_user_entry(void *args, const void *text, void *data);
|
||||
|
||||
/**
|
||||
* RT-Thread light-weight process
|
||||
@@ -62,6 +58,43 @@ uint32_t *lwp_get_kernel_sp(void)
|
||||
return user_data->kernel_sp;
|
||||
}
|
||||
|
||||
static int lwp_argscopy(struct rt_lwp *lwp, int argc, char **argv)
|
||||
{
|
||||
int size = sizeof(int)*3; /* store argc, argv, NULL */
|
||||
int *args;
|
||||
char *str;
|
||||
char **new_argv;
|
||||
int i;
|
||||
int len;
|
||||
|
||||
for (i = 0; i < argc; i ++)
|
||||
{
|
||||
size += (rt_strlen(argv[i]) + 1);
|
||||
}
|
||||
size += (sizeof(int) * argc);
|
||||
|
||||
args = (int*)rt_malloc(size);
|
||||
if (args == RT_NULL)
|
||||
return -1;
|
||||
|
||||
str = (char*)((int)args + (argc + 3) * sizeof(int));
|
||||
new_argv = (char**)&args[2];
|
||||
args[0] = argc;
|
||||
args[1] = (int)new_argv;
|
||||
|
||||
for (i = 0; i < argc; i ++)
|
||||
{
|
||||
len = rt_strlen(argv[i]) + 1;
|
||||
new_argv[i] = str;
|
||||
rt_memcpy(str, argv[i], len);
|
||||
str += len;
|
||||
}
|
||||
new_argv[i] = 0;
|
||||
lwp->args = args;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_t addr_size)
|
||||
{
|
||||
int fd;
|
||||
@@ -76,8 +109,6 @@ static int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr
|
||||
/* check lwp control block */
|
||||
RT_ASSERT(lwp != RT_NULL);
|
||||
|
||||
memset(lwp, 0x00, sizeof(struct rt_lwp));
|
||||
|
||||
if (load_addr != RT_NULL)
|
||||
{
|
||||
lwp->lwp_type = LWP_TYPE_FIX_ADDR;
|
||||
@@ -279,6 +310,15 @@ static void lwp_cleanup(struct rt_thread *tid)
|
||||
dbg_log(DBG_LOG, "lwp free memory pages\n");
|
||||
rt_lwp_mem_deinit(lwp);
|
||||
|
||||
/* cleanup fd table */
|
||||
while (lwp->fdt.maxfd > 0)
|
||||
{
|
||||
lwp->fdt.maxfd --;
|
||||
close(lwp->fdt.maxfd);
|
||||
}
|
||||
rt_free(lwp->fdt.fds);
|
||||
rt_free(lwp->args);
|
||||
|
||||
dbg_log(DBG_LOG, "lwp free: %p\n", lwp);
|
||||
rt_free(lwp);
|
||||
|
||||
@@ -299,7 +339,7 @@ static void lwp_thread(void *parameter)
|
||||
tid->user_data = (rt_uint32_t)lwp;
|
||||
tid->cleanup = lwp_cleanup;
|
||||
|
||||
lwp_user_entry(lwp->text_entry, lwp->data);
|
||||
lwp_user_entry(lwp->args, lwp->text_entry, lwp->data);
|
||||
}
|
||||
|
||||
struct rt_lwp *rt_lwp_self(void)
|
||||
@@ -307,7 +347,7 @@ struct rt_lwp *rt_lwp_self(void)
|
||||
return (struct rt_lwp *)rt_thread_self()->user_data;
|
||||
}
|
||||
|
||||
int exec(char *filename)
|
||||
int exec(char *filename, int argc, char **argv)
|
||||
{
|
||||
struct rt_lwp *lwp;
|
||||
int result;
|
||||
@@ -324,6 +364,12 @@ int exec(char *filename)
|
||||
dbg_log(DBG_INFO, "lwp malloc : %p, size: %d!\n", lwp, sizeof(struct rt_lwp));
|
||||
|
||||
rt_memset(lwp, 0, sizeof(*lwp));
|
||||
if (lwp_argscopy(lwp, argc, argv) != 0)
|
||||
{
|
||||
rt_free(lwp);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
result = lwp_load(filename, lwp, RT_NULL, 0);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
@@ -348,6 +394,7 @@ int exec(char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
rt_free(lwp->args);
|
||||
rt_free(lwp);
|
||||
|
||||
return -RT_ERROR;
|
||||
|
||||
@@ -52,6 +52,7 @@ struct rt_lwp
|
||||
|
||||
uint32_t *kernel_sp; /**< kernel stack point */
|
||||
struct dfs_fdtable fdt;
|
||||
void *args;
|
||||
};
|
||||
|
||||
struct lwp_header
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define DBG_ENABLE
|
||||
#define DBG_SECTION_NAME "[LWPMEM]"
|
||||
#define DBG_COLOR
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#define DBG_LEVEL DBG_WARNING
|
||||
#include <rtdbg.h>
|
||||
|
||||
// todo: remove repleat code
|
||||
@@ -117,13 +117,18 @@ void rt_lwp_mem_deinit(struct rt_lwp *lwp)
|
||||
|
||||
RT_ASSERT(lwp != RT_NULL);
|
||||
|
||||
for (node = lwp->hlist.next; node != &(lwp->hlist); node = node->next)
|
||||
node = lwp->hlist.next;
|
||||
|
||||
while (node != &(lwp->hlist))
|
||||
{
|
||||
struct rt_lwp_memheap *lwp_heap;
|
||||
|
||||
lwp_heap = rt_list_entry(node, struct rt_lwp_memheap, mlist);
|
||||
|
||||
RT_ASSERT(lwp_heap != RT_NULL);
|
||||
|
||||
/* update note before free page*/
|
||||
node = node->next;
|
||||
|
||||
rt_lwp_free_page(lwp, lwp_heap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@ config RT_USING_MODBUS
|
||||
config RT_MODBUS_SLAVE_RTU
|
||||
bool "RTU slave mode"
|
||||
default n
|
||||
if RT_MODBUS_SLAVE_RTU
|
||||
config RT_MODBUS_SLAVE_USE_CONTROL_PIN
|
||||
bool "Use Contorl Pin"
|
||||
default n
|
||||
if RT_MODBUS_SLAVE_USE_CONTROL_PIN
|
||||
config MODBUS_SLAVE_RT_CONTROL_PIN_INDEX
|
||||
int "pin index for RS485 TX/RX select"
|
||||
default 10
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -53,8 +53,8 @@ xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits,
|
||||
USHORT usNPreBits;
|
||||
USHORT usValue = ucValue;
|
||||
|
||||
assert_param( ucNBits <= 8 );
|
||||
assert_param( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
|
||||
RT_ASSERT( ucNBits <= 8 );
|
||||
RT_ASSERT( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
|
||||
|
||||
/* Calculate byte offset for first byte containing the bit values starting
|
||||
* at usBitOffset. */
|
||||
|
||||
@@ -153,7 +153,7 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
|
||||
ENTER_CRITICAL_SECTION( );
|
||||
assert_param( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
|
||||
RT_ASSERT( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
|
||||
|
||||
/* Length and CRC check */
|
||||
if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
|
||||
@@ -226,7 +226,7 @@ xMBRTUReceiveFSM( void )
|
||||
BOOL xTaskNeedSwitch = FALSE;
|
||||
UCHAR ucByte;
|
||||
|
||||
assert_param( eSndState == STATE_TX_IDLE );
|
||||
RT_ASSERT( eSndState == STATE_TX_IDLE );
|
||||
|
||||
/* Always read the character. */
|
||||
( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
|
||||
@@ -285,7 +285,7 @@ xMBRTUTransmitFSM( void )
|
||||
{
|
||||
BOOL xNeedPoll = FALSE;
|
||||
|
||||
assert_param( eRcvState == STATE_RX_IDLE );
|
||||
RT_ASSERT( eRcvState == STATE_RX_IDLE );
|
||||
|
||||
switch ( eSndState )
|
||||
{
|
||||
@@ -342,7 +342,7 @@ xMBRTUTimerT35Expired( void )
|
||||
|
||||
/* Function called in an illegal state. */
|
||||
default:
|
||||
assert_param( ( eRcvState == STATE_RX_INIT ) ||
|
||||
RT_ASSERT( ( eRcvState == STATE_RX_INIT ) ||
|
||||
( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,9 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
|
||||
* set 485 mode receive and transmit control IO
|
||||
* @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
|
||||
*/
|
||||
#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
|
||||
rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
|
||||
|
||||
#endif
|
||||
/* set serial name */
|
||||
if (ucPORT == 1) {
|
||||
#if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
|
||||
@@ -127,12 +128,16 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
|
||||
/* enable RX interrupt */
|
||||
serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||
/* switch 485 to receive mode */
|
||||
#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
|
||||
rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* switch 485 to transmit mode */
|
||||
#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
|
||||
rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
|
||||
#endif
|
||||
/* disable RX interrupt */
|
||||
serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
|
||||
}
|
||||
|
||||
@@ -136,11 +136,19 @@ static void tcpip_init_done_callback(void *arg)
|
||||
* LwIP system initialization
|
||||
*/
|
||||
extern int eth_system_device_init_private(void);
|
||||
static volatile uint8_t init_ok = 0;
|
||||
int lwip_system_init(void)
|
||||
{
|
||||
rt_err_t rc;
|
||||
struct rt_semaphore done_sem;
|
||||
|
||||
|
||||
if(init_ok)
|
||||
{
|
||||
rt_kprintf("lwip system already init.\n");
|
||||
return 0;
|
||||
}
|
||||
init_ok = 1;
|
||||
|
||||
eth_system_device_init_private();
|
||||
|
||||
/* set default netif to NULL */
|
||||
|
||||
Reference in New Issue
Block a user