Added MuORB based on virtual CDev implementation

uORB module now compiles and runs for Linux using the
virtual CDev implementation.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-04-20 11:00:18 -07:00
parent 938751993d
commit 7b0783a070
10 changed files with 1415 additions and 43 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ MODULES += drivers/device
#
MODULES += modules/systemlib
MODULES += modules/systemlib/mixer
#MODULES += modules/uORB
MODULES += modules/uORB
#MODULES += modules/dataman
#
-3
View File
@@ -379,9 +379,6 @@ CDev::poll_notify(pollevent_t events)
for (unsigned i = 0; i < _max_pollwaiters; i++)
if (nullptr != _pollset[i])
poll_notify_one(_pollset[i], events);
for (unsigned i = 0; i < _max_pollwaiters; i++)
if (nullptr != _pollset[i])
debug(" CHECK fds=%p %0x %0x",_pollset[i], _pollset[i]->revents, _pollset[i]->events);
unlock();
}
+26 -34
View File
@@ -46,9 +46,6 @@
#include <pthread.h>
#include <unistd.h>
#define DEBUG(...)
//#define DEBUG(...) printf(__VA_ARGS__)
using namespace device;
extern "C" {
@@ -71,7 +68,7 @@ static void *timer_handler(void *data)
usleep(td->ts.tv_nsec/1000);
sem_post(&(td->sem));
printf("Timer expired\n");
PX4_DEBUG("timer_handler: Timer expired\n");
return 0;
}
@@ -80,8 +77,12 @@ static px4_dev_handle_t *filemap[PX4_MAX_FD] = {};
int px4_errno;
int
px4_open(const char *path, int flags)
inline bool valid_fd(int fd)
{
return (fd < PX4_MAX_FD && fd >= 0 && filemap[fd] != NULL);
}
int px4_open(const char *path, int flags)
{
CDev *dev = CDev::getDev(path);
int ret = 0;
@@ -108,17 +109,16 @@ px4_open(const char *path, int flags)
px4_errno = -ret;
return -1;
}
DEBUG("px4_open fd = %d", filemap[i]->fd);
PX4_DEBUG("px4_open fd = %d", filemap[i]->fd);
return filemap[i]->fd;
}
int
px4_close(int fd)
int px4_close(int fd)
{
int ret;
if (fd < PX4_MAX_FD && fd >= 0) {
if (valid_fd(fd)) {
CDev *dev = (CDev *)(filemap[fd]->cdev);
DEBUG("px4_close fd = %d\n", fd);
PX4_DEBUG("px4_close fd = %d\n", fd);
ret = dev->close(filemap[fd]);
filemap[fd] = NULL;
}
@@ -131,13 +131,12 @@ px4_close(int fd)
return ret;
}
ssize_t
px4_read(int fd, void *buffer, size_t buflen)
ssize_t px4_read(int fd, void *buffer, size_t buflen)
{
int ret;
if (fd < PX4_MAX_FD && fd >= 0) {
if (valid_fd(fd)) {
CDev *dev = (CDev *)(filemap[fd]->cdev);
DEBUG("px4_read fd = %d\n", fd);
PX4_DEBUG("px4_read fd = %d\n", fd);
ret = dev->read(filemap[fd], (char *)buffer, buflen);
}
else {
@@ -149,13 +148,12 @@ px4_read(int fd, void *buffer, size_t buflen)
return ret;
}
ssize_t
px4_write(int fd, const void *buffer, size_t buflen)
ssize_t px4_write(int fd, const void *buffer, size_t buflen)
{
int ret = PX4_ERROR;
if (fd < PX4_MAX_FD && fd >= 0) {
if (valid_fd(fd)) {
CDev *dev = (CDev *)(filemap[fd]->cdev);
DEBUG("px4_write fd = %d\n", fd);
PX4_DEBUG("px4_write fd = %d\n", fd);
ret = dev->write(filemap[fd], (const char *)buffer, buflen);
}
else {
@@ -167,13 +165,12 @@ px4_write(int fd, const void *buffer, size_t buflen)
return ret;
}
int
px4_ioctl(int fd, int cmd, unsigned long arg)
int px4_ioctl(int fd, int cmd, unsigned long arg)
{
int ret = PX4_ERROR;
if (fd < PX4_MAX_FD && fd >= 0) {
if (valid_fd(fd)) {
CDev *dev = (CDev *)(filemap[fd]->cdev);
DEBUG("px4_ioctl fd = %d\n", fd);
PX4_DEBUG("px4_ioctl fd = %d\n", fd);
ret = dev->ioctl(filemap[fd], cmd, arg);
}
else {
@@ -188,8 +185,7 @@ px4_ioctl(int fd, int cmd, unsigned long arg)
return ret;
}
int
px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
{
sem_t sem;
int count = 0;
@@ -197,7 +193,7 @@ px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
unsigned int i;
struct timespec ts;
printf("Called px4_poll timeout = %d\n", timeout);
PX4_DEBUG("Called px4_poll timeout = %d\n", timeout);
sem_init(&sem, 0, 0);
// For each fd
@@ -208,15 +204,14 @@ px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
fds[i].priv = NULL;
// If fd is valid
if (fds[i].fd >= 0 && fds[i].fd < PX4_MAX_FD)
if (valid_fd(fds[i].fd))
{
CDev *dev = (CDev *)(filemap[fds[i].fd]->cdev);;
DEBUG("px4_poll: CDev->poll(setup) %d\n", fds[i].fd);
PX4_DEBUG("px4_poll: CDev->poll(setup) %d\n", fds[i].fd);
ret = dev->poll(filemap[fds[i].fd], &fds[i], true);
if (ret < 0)
break;
DEBUG("xxxx fds=%p fds[%d].revents = %d\n", fds, i, fds[i].revents);
}
}
@@ -253,18 +248,15 @@ px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
for (i=0; i<nfds; ++i)
{
// If fd is valid
if (fds[i].fd >= 0 && fds[i].fd < PX4_MAX_FD)
if (valid_fd(fds[i].fd))
{
DEBUG("zzzz fds=%p fds[%d].revents = %d\n",fds, i, fds[i].revents);
CDev *dev = (CDev *)(filemap[fds[i].fd]->cdev);;
DEBUG("px4_poll: CDev->poll(teardown) %d\n", fds[i].fd);
PX4_DEBUG("px4_poll: CDev->poll(teardown) %d\n", fds[i].fd);
ret = dev->poll(filemap[fds[i].fd], &fds[i], false);
if (ret < 0)
break;
DEBUG("yyyy fds=%p fds[%d].revents = %d\n", fds, i, fds[i].revents);
if (fds[i].revents)
count += 1;
}
+2 -1
View File
@@ -40,6 +40,7 @@
* uORB published object driver.
*/
#include <px4_defines.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdint.h>
@@ -61,7 +62,7 @@
#define ORB_MAXNAME 32
#define _ORBIOCBASE (0x2600)
#define _ORBIOC(_n) (_IOC(_ORBIOCBASE, _n))
#define _ORBIOC(_n) (_PX4_IOC(_ORBIOCBASE, _n))
/*
* IOCTLs for the uORB control device
+1 -1
View File
@@ -71,7 +71,7 @@
/**
* Array of static parameter info.
*/
#ifdef _UNIT_TEST
#if defined(_UNIT_TEST) || defined(__PX4_LINUX)
extern struct param_info_s param_array[];
extern struct param_info_s *param_info_base;
extern struct param_info_s *param_info_limit;
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -39,8 +39,12 @@ MODULE_COMMAND = uorb
MODULE_STACKSIZE = 2048
SRCS = uORB.cpp \
objects_common.cpp \
ifeq ($(PX4_TARGET_OS),nuttx)
SRCS = uORB.cpp
else
SRCS = MuORB.cpp
endif
SRCS += objects_common.cpp \
Publication.cpp \
Subscription.cpp
+4 -1
View File
@@ -37,6 +37,9 @@
SRCS = \
px4_linux_impl.cpp \
px4_linux_tasks.c
px4_linux_tasks.c \
lib_crc32.c \
drv_hrt.c \
queue.c
MAXOPTIMIZATION = -Os
@@ -40,12 +40,54 @@
#include <px4_middleware.h>
#include <stdint.h>
#include <stdio.h>
#include "systemlib/param/param.h"
__BEGIN_DECLS
// FIXME - This needs to be properly initialized
struct param_info_s param_array[256];
struct param_info_s *param_info_base;
struct param_info_s *param_info_limit;
__END_DECLS
namespace px4
{
void init(int argc, char *argv[], const char *app_name)
{
struct param_info_s test_1 = {
"TEST_1",
PARAM_TYPE_INT32
};
test_1.val.i = 2;
struct param_info_s test_2 = {
"TEST_2",
PARAM_TYPE_INT32
};
test_2.val.i = 4;
struct param_info_s rc_x = {
"RC_X",
PARAM_TYPE_INT32
};
rc_x.val.i = 8;
struct param_info_s rc2_x = {
"RC2_X",
PARAM_TYPE_INT32
};
rc2_x.val.i = 16;
param_array[0] = test_1;
param_array[1] = test_2;
param_array[2] = rc_x;
param_array[3] = rc2_x;
param_info_base = (struct param_info_s *) &param_array[0];
param_info_limit = (struct param_info_s *) &param_array[4]; // needs to point at the end of the data,
// therefore number of params + 1
printf("App name: %s\n", app_name);
}
+3
View File
@@ -55,6 +55,9 @@
#define PX4_ERROR (-1)
#define PX4_OK 0
//#define PX4_DEBUG(...)
#define PX4_DEBUG(...) printf(__VA_ARGS__)
__BEGIN_DECLS
extern int px4_errno;