summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2019-01-21 18:17:51 +0800
committerGitHub <[email protected]>2019-01-21 18:17:51 +0800
commitdfebb30c91875c52f16fd4e7bb9e5981fd0512b4 (patch)
treea5963a4d33a40b9286a6cfc0fc948751e66bb5b1 /components
parent3dd0ebe6e7d8d0ad7605269ef8fffd66a8029931 (diff)
parentb7996af1862800b80c756329dcbf1a8496651a81 (diff)
Merge pull request #2238 from armink/lts-v3.1.x
Sync from master latest version.
Diffstat (limited to 'components')
-rw-r--r--components/dfs/filesystems/romfs/dfs_romfs.h11
-rw-r--r--components/dfs/filesystems/romfs/mkromfs.py252
-rw-r--r--components/dfs/include/dfs_file.h1
-rw-r--r--components/dfs/src/dfs.c6
-rw-r--r--components/dfs/src/dfs_file.c5
-rw-r--r--components/dfs/src/poll.c2
-rw-r--r--components/drivers/can/can.c2
-rw-r--r--components/drivers/serial/serial.c2
-rw-r--r--components/drivers/spi/spi_flash_sfud.c59
-rw-r--r--components/drivers/wlan/wlan_dev.c19
-rw-r--r--components/drivers/wlan/wlan_lwip.c18
-rw-r--r--components/libc/pthreads/pthread.h9
12 files changed, 90 insertions, 296 deletions
diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h
index 74b256c8a6..efb6d44caf 100644
--- a/components/dfs/filesystems/romfs/dfs_romfs.h
+++ b/components/dfs/filesystems/romfs/dfs_romfs.h
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
+ * 2019/01/13 Bernard code cleanup
*/
#ifndef __DFS_ROMFS_H__
@@ -17,11 +18,11 @@
struct romfs_dirent
{
- rt_uint32_t type; /* dirent type */
+ rt_uint32_t type; /* dirent type */
- const char *name; /* dirent name */
- const rt_uint8_t *data; /* file date ptr */
- rt_size_t size; /* file size */
+ const char *name; /* dirent name */
+ const rt_uint8_t *data; /* file date ptr */
+ rt_size_t size; /* file size */
};
int dfs_romfs_init(void);
diff --git a/components/dfs/filesystems/romfs/mkromfs.py b/components/dfs/filesystems/romfs/mkromfs.py
deleted file mode 100644
index f3c12876d2..0000000000
--- a/components/dfs/filesystems/romfs/mkromfs.py
+++ /dev/null
@@ -1,252 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import os
-
-import struct
-from collections import namedtuple
-import StringIO
-
-import argparse
-parser = argparse.ArgumentParser()
-parser.add_argument('rootdir', type=str, help='the path to rootfs')
-parser.add_argument('output', type=argparse.FileType('wb'), nargs='?', help='output file name')
-parser.add_argument('--dump', action='store_true', help='dump the fs hierarchy')
-parser.add_argument('--binary', action='store_true', help='output binary file')
-parser.add_argument('--addr', default='0', help='set the base address of the binary file, default to 0.')
-
-class File(object):
- def __init__(self, name):
- self._name = name
- self._data = open(name, 'rb').read()
-
- @property
- def name(self):
- return self._name
-
- @property
- def c_name(self):
- return '_' + self._name.replace('.', '_')
-
- @property
- def bin_name(self):
- # Pad to 4 bytes boundary with \0
- pad_len = 4
- bn = self._name + '\0' * (pad_len - len(self._name) % pad_len)
- return bn
-
- def c_data(self, prefix=''):
- '''Get the C code represent of the file content.'''
- head = 'static const rt_uint8_t %s[] = {\n' % \
- (prefix + self.c_name)
- tail = '\n};'
- return head + ','.join(('0x%02x' % ord(i) for i in self._data)) + tail
-
- @property
- def entry_size(self):
- return len(self._data)
-
- def bin_data(self, base_addr=0x0):
- return bytes(self._data)
-
- def dump(self, indent=0):
- print('%s%s' % (' ' * indent, self._name))
-
-class Folder(object):
- bin_fmt = struct.Struct('IIII')
- bin_item = namedtuple('dirent', 'type, name, data, size')
-
- def __init__(self, name):
- self._name = name
- self._children = []
-
- @property
- def name(self):
- return self._name
-
- @property
- def c_name(self):
- # add _ to avoid conflict with C key words.
- return '_' + self._name
-
- @property
- def bin_name(self):
- # Pad to 4 bytes boundary with \0
- pad_len = 4
- bn = self._name + '\0' * (pad_len - len(self._name) % pad_len)
- return bn
-
- def walk(self):
- # os.listdir will return unicode list if the argument is unicode.
- # TODO: take care of the unicode names
- for ent in os.listdir(u'.'):
- if os.path.isdir(ent):
- cwd = os.getcwdu()
- d = Folder(ent)
- # depth-first
- os.chdir(os.path.join(cwd, ent))
- d.walk()
- # restore the cwd
- os.chdir(cwd)
- self._children.append(d)
- else:
- self._children.append(File(ent))
-
- def sort(self):
- def _sort(x, y):
- if x.name == y.name:
- return 0
- elif x.name > y.name:
- return 1
- else:
- return -1
- self._children.sort(cmp=_sort)
-
- # sort recursively
- for c in self._children:
- if isinstance(c, Folder):
- c.sort()
-
- def dump(self, indent=0):
- print('%s%s' % (' ' * indent, self._name))
- for c in self._children:
- c.dump(indent + 1)
-
- def c_data(self, prefix=''):
- '''get the C code represent of the folder.
-
- It is recursive.'''
- # make the current dirent
- # static is good. Only root dirent is global visible.
- dhead = 'static const struct romfs_dirent %s[] = {\n' % (prefix + self.c_name)
- dtail = '\n};'
- body_fmt = ' {{{type}, "{name}", (rt_uint8_t *){data}, sizeof({data})/sizeof({data}[0])}}'
- # prefix of children
- cpf = prefix+self.c_name
- body_li = []
- payload_li = []
- for c in self._children:
- if isinstance(c, File):
- tp = 'ROMFS_DIRENT_FILE'
- elif isinstance(c, Folder):
- tp = 'ROMFS_DIRENT_DIR'
- else:
- assert False, 'Unkown instance:%s' % str(c)
- body_li.append(body_fmt.format(type=tp,
- name=c.name,
- data=cpf+c.c_name))
- payload_li.append(c.c_data(prefix=cpf))
-
- # All the data we need is defined in payload so we should append the
- # dirent to it. It also meet the depth-first policy in this code.
- payload_li.append(dhead + ',\n'.join(body_li) + dtail)
-
- return '\n\n'.join(payload_li)
-
- @property
- def entry_size(self):
- return len(self._children)
-
- def bin_data(self, base_addr=0x0):
- '''Return StringIO object'''
- # The binary layout is different from the C code layout. We put the
- # dirent before the payload in this mode. But the idea is still simple:
- # Depth-First.
-
- #{
- # rt_uint32_t type;
- # const char *name;
- # const rt_uint8_t *data;
- # rt_size_t size;
- #}
- d_li = []
- # payload base
- p_base = base_addr + self.bin_fmt.size * self.entry_size
- # the length to record how many data is in
- v_len = p_base
- # payload
- p_li = []
- for c in self._children:
- if isinstance(c, File):
- # ROMFS_DIRENT_FILE
- tp = 0
- elif isinstance(c, Folder):
- # ROMFS_DIRENT_DIR
- tp = 1
- else:
- assert False, 'Unkown instance:%s' % str(c)
-
- name = bytes(c.bin_name)
- name_addr = v_len
- v_len += len(name)
-
- data = c.bin_data(base_addr=v_len)
- data_addr = v_len
- # pad the data to 4 bytes boundary
- pad_len = 4
- if len(data) % pad_len != 0:
- data += '\0' * (pad_len - len(data) % pad_len)
- v_len += len(data)
-
- d_li.append(self.bin_fmt.pack(*self.bin_item(
- type=tp,
- name=name_addr,
- data=data_addr,
- size=c.entry_size)))
-
- p_li.extend((name, data))
-
- return bytes().join(d_li) + bytes().join(p_li)
-
-def get_c_data(tree):
- # Handle the root dirent specially.
- root_dirent_fmt = '''/* Generated by mkromfs. Edit with caution. */
-#include <rtthread.h>
-#include <dfs_romfs.h>
-
-{data}
-
-const struct romfs_dirent {name} = {{
- ROMFS_DIRENT_DIR, "/", (rt_uint8_t *){rootdirent}, sizeof({rootdirent})/sizeof({rootdirent}[0])
-}};
-'''
-
- return root_dirent_fmt.format(name='romfs_root',
- rootdirent=tree.c_name,
- data=tree.c_data())
-
-def get_bin_data(tree, base_addr):
- v_len = base_addr + Folder.bin_fmt.size
- name = bytes('/\0\0\0')
- name_addr = v_len
- v_len += len(name)
- data_addr = v_len
- # root entry
- data = Folder.bin_fmt.pack(*Folder.bin_item(type=1,
- name=name_addr,
- data=data_addr,
- size=tree.entry_size))
- return data + name + tree.bin_data(v_len)
-
-if __name__ == '__main__':
- args = parser.parse_args()
-
- os.chdir(args.rootdir)
-
- tree = Folder('romfs_root')
- tree.walk()
- tree.sort()
-
- if args.dump:
- tree.dump()
-
- if args.binary:
- data = get_bin_data(tree, int(args.addr, 16))
- else:
- data = get_c_data(tree)
-
- output = args.output
- if not output:
- output = sys.stdout
-
- output.write(data)
diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h
index 7ef681a247..aaff3f6e9c 100644
--- a/components/dfs/include/dfs_file.h
+++ b/components/dfs/include/dfs_file.h
@@ -44,6 +44,7 @@ struct dfs_fd
char *path; /* Name (below mount point) */
int ref_count; /* Descriptor reference count */
+ struct dfs_filesystem *fs;
const struct dfs_file_ops *fops;
uint32_t flags; /* Descriptor flags */
diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c
index 12ae8e9d95..066c800568 100644
--- a/components/dfs/src/dfs.c
+++ b/components/dfs/src/dfs.c
@@ -18,7 +18,7 @@
#include <lwp.h>
#endif
-#ifdef RT_USING_DFS_DEVFS
+#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
#include <libc.h>
#endif
@@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd)
struct dfs_fd *d;
struct dfs_fdtable *fdt;
-#ifdef RT_USING_DFS_DEVFS
+#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX)
if ((0 <= fd) && (fd <= 2))
fd = libc_stdio_get_console();
#endif
@@ -320,7 +320,7 @@ int fd_is_open(const char *pathname)
fd = fdt->fds[index];
if (fd == NULL || fd->fops == NULL || fd->path == NULL) continue;
- if (fd->fops == fs->ops->fops && strcmp(fd->path, mountpath) == 0)
+ if (fd->fs == fs && strcmp(fd->path, mountpath) == 0)
{
/* found file in file descriptor table */
rt_free(fullpath);
diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c
index 646ae58e36..4505667738 100644
--- a/components/dfs/src/dfs_file.c
+++ b/components/dfs/src/dfs_file.c
@@ -66,7 +66,8 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
}
LOG_D("open in filesystem:%s", fs->ops->name);
- fd->fops = fs->ops->fops; /* set file ops */
+ fd->fs = fs; /* set file system */
+ fd->fops = fs->ops->fops; /* set file ops */
/* initialize the fd item */
fd->type = FT_REGULAR;
@@ -171,7 +172,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
return fd->flags; /* return flags */
case F_SETFL:
{
- int flags = (int)args;
+ int flags = (int)(rt_base_t)args;
int mask = O_NONBLOCK | O_APPEND;
flags &= mask;
diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c
index 6655a8a667..6f83762082 100644
--- a/components/dfs/src/poll.c
+++ b/components/dfs/src/poll.c
@@ -40,7 +40,7 @@ static int __wqueue_pollwake(struct rt_wqueue_node *wait, void *key)
{
struct rt_poll_node *pn;
- if (key && !((rt_uint32_t)key & wait->key))
+ if (key && !((rt_ubase_t)key & wait->key))
return -1;
pn = rt_container_of(wait, struct rt_poll_node, wqn);
diff --git a/components/drivers/can/can.c b/components/drivers/can/can.c
index e20fcddcff..81fdf25a1e 100644
--- a/components/drivers/can/can.c
+++ b/components/drivers/can/can.c
@@ -405,6 +405,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
rt_free(rx_fifo);
dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX;
+ can->can_rx = RT_NULL;
/* configure low level device */
can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
}
@@ -418,6 +419,7 @@ static rt_err_t rt_can_close(struct rt_device *dev)
rt_free(tx_fifo);
dev->open_flag &= ~RT_DEVICE_FLAG_INT_TX;
+ can->can_tx = RT_NULL;
/* configure low level device */
can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_TX);
}
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index c5932df7d9..77f2a645a1 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -566,13 +566,11 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
LOG_D("open serial device: 0x%08x with open flag: 0x%04x",
dev, oflag);
-#ifdef RT_SERIAL_USING_DMA
/* check device flag with the open flag */
if ((oflag & RT_DEVICE_FLAG_DMA_RX) && !(dev->flag & RT_DEVICE_FLAG_DMA_RX))
return -RT_EIO;
if ((oflag & RT_DEVICE_FLAG_DMA_TX) && !(dev->flag & RT_DEVICE_FLAG_DMA_TX))
return -RT_EIO;
-#endif /* RT_SERIAL_USING_DMA */
if ((oflag & RT_DEVICE_FLAG_INT_RX) && !(dev->flag & RT_DEVICE_FLAG_INT_RX))
return -RT_EIO;
if ((oflag & RT_DEVICE_FLAG_INT_TX) && !(dev->flag & RT_DEVICE_FLAG_INT_TX))
diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c
index c8ff8f1b3b..fb18b820c0 100644
--- a/components/drivers/spi/spi_flash_sfud.c
+++ b/components/drivers/spi/spi_flash_sfud.c
@@ -455,6 +455,35 @@ rt_err_t rt_sfud_flash_delete(rt_spi_flash_device_t spi_flash_dev) {
return RT_EOK;
}
+sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
+{
+ rt_spi_flash_device_t rtt_dev = RT_NULL;
+ struct rt_spi_device *rt_spi_device = RT_NULL;
+ sfud_flash_t sfud_dev = RT_NULL;
+
+ rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
+ if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice)
+ {
+ rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
+ goto error;
+ }
+
+ rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data);
+ if (rtt_dev && rtt_dev->user_data)
+ {
+ sfud_dev = (sfud_flash_t)(rtt_dev->user_data);
+ return sfud_dev;
+ }
+ else
+ {
+ rt_kprintf("ERROR: SFUD flash device not found!\n");
+ goto error;
+ }
+
+error:
+ return RT_NULL;
+}
+
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
#include <finsh.h>
@@ -698,36 +727,6 @@ static void sf(uint8_t argc, char **argv) {
}
}
MSH_CMD_EXPORT(sf, SPI Flash operate.);
-
-sfud_flash_t rt_sfud_flash_find(const char *spi_dev_name)
-{
- rt_spi_flash_device_t rtt_dev = RT_NULL;
- struct rt_spi_device *rt_spi_device = RT_NULL;
- sfud_flash_t sfud_dev = RT_NULL;
-
- rt_spi_device = (struct rt_spi_device *) rt_device_find(spi_dev_name);
- if (rt_spi_device == RT_NULL || rt_spi_device->parent.type != RT_Device_Class_SPIDevice)
- {
- rt_kprintf("ERROR: SPI device %s not found!\n", spi_dev_name);
- goto error;
- }
-
- rtt_dev = (rt_spi_flash_device_t)(rt_spi_device->user_data);
- if (rtt_dev && rtt_dev->user_data)
- {
- sfud_dev = (sfud_flash_t)(rtt_dev->user_data);
- return sfud_dev;
- }
- else
- {
- rt_kprintf("ERROR: SFUD flash device not found!\n");
- goto error;
- }
-
-error:
- return RT_NULL;
-}
-
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
#endif /* RT_USING_SFUD */
diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c
index 0beac52aae..eac1d0f975 100644
--- a/components/drivers/wlan/wlan_dev.c
+++ b/components/drivers/wlan/wlan_dev.c
@@ -754,6 +754,18 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args)
return err;
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops wlan_ops =
+{
+ _rt_wlan_dev_init,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ _rt_wlan_dev_control
+};
+#endif
+
rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data)
{
rt_err_t err = RT_EOK;
@@ -765,13 +777,18 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con
}
rt_memset(wlan, 0, sizeof(struct rt_wlan_device));
-
+
+#ifdef RT_USING_DEVICE_OPS
+ wlan->device.ops = &wlan_ops;
+#else
wlan->device.init = _rt_wlan_dev_init;
wlan->device.open = RT_NULL;
wlan->device.close = RT_NULL;
wlan->device.read = RT_NULL;
wlan->device.write = RT_NULL;
wlan->device.control = _rt_wlan_dev_control;
+#endif
+
wlan->device.user_data = RT_NULL;
wlan->device.type = RT_Device_Class_NetIf;
diff --git a/components/drivers/wlan/wlan_lwip.c b/components/drivers/wlan/wlan_lwip.c
index ec6ca23845..2f8bcefd0d 100644
--- a/components/drivers/wlan/wlan_lwip.c
+++ b/components/drivers/wlan/wlan_lwip.c
@@ -372,6 +372,18 @@ static rt_err_t rt_wlan_lwip_protocol_send(rt_device_t device, struct pbuf *p)
#endif
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops wlan_lwip_ops =
+{
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ rt_wlan_lwip_protocol_control
+};
+#endif
+
static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan)
{
struct eth_device *eth = RT_NULL;
@@ -417,12 +429,18 @@ static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *
rt_memset(lwip_prot, 0, sizeof(struct lwip_prot_des));
eth = &lwip_prot->eth;
+
+#ifdef RT_USING_DEVICE_OPS
+ eth->parent.ops = &wlan_lwip_ops;
+#else
eth->parent.init = RT_NULL;
eth->parent.open = RT_NULL;
eth->parent.close = RT_NULL;
eth->parent.read = RT_NULL;
eth->parent.write = RT_NULL;
eth->parent.control = rt_wlan_lwip_protocol_control;
+#endif
+
eth->parent.user_data = wlan;
eth->eth_rx = RT_NULL;
eth->eth_tx = rt_wlan_lwip_protocol_send;
diff --git a/components/libc/pthreads/pthread.h b/components/libc/pthreads/pthread.h
index 6a82375de4..f9a0a92b68 100644
--- a/components/libc/pthreads/pthread.h
+++ b/components/libc/pthreads/pthread.h
@@ -12,6 +12,11 @@
#define __PTHREAD_H__
#include <rtthread.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <posix_types.h>
#include <sched.h>
@@ -262,4 +267,8 @@ int pthread_barrier_init(pthread_barrier_t *barrier,
int pthread_barrier_wait(pthread_barrier_t *barrier);
+#ifdef __cplusplus
+}
+#endif
+
#endif