QuRT and POSIX changes

Partial commit of the changes for QuRT and related changes for POSIX

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-04-24 00:52:44 -07:00
parent a4c33f5173
commit 3336fce1f4
25 changed files with 919 additions and 2435 deletions
+43
View File
@@ -0,0 +1,43 @@
/****************************************************************************
* include/nuttx/i2c.h
*
* Copyright(C) 2009-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
struct i2c_msg_s
{
uint16_t addr; /* Slave address */
uint16_t flags; /* See I2C_M_* definitions */
uint8_t *buffer;
int length;
};
+37
View File
@@ -1,3 +1,40 @@
/****************************************************************************
* include/poll.h
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
typedef unsigned int nfds_t;
#define POLLIN (0x01)
+3
View File
@@ -0,0 +1,3 @@
#pragma once
#define _IO(x,y) (x+y)
+26 -21
View File
@@ -49,25 +49,29 @@
//typedef int (*px4_main_t)(int argc, char *argv[]);
#include "apps.h"
//#include "px4_middleware.h"
#include "px4_middleware.h"
static const char *commands = "hello start\n";
static const char *commands = "hello start\n"
"list_tasks";
static void run_cmd(const vector<string> &appargs) {
// command is appargs[0]
string command = appargs[0];
printf("Looking for %s\n", command.c_str());
if (apps.find(command) != apps.end()) {
const char *arg[appargs.size()+2];
const char *arg[2+1];
unsigned int i = 0;
while (i < appargs.size() && appargs[i] != "") {
printf("size = %d\n", appargs.size());
while (i < appargs.size() && appargs[i].c_str()[0] != '\0') {
arg[i] = (char *)appargs[i].c_str();
printf(" arg = '%s'\n", arg[i]);
++i;
}
arg[i] = (char *)0;
//printf("BEFORE argc = %d %s %s %p\n", i, arg[0], arg[1], arg[2]);
apps[command](i,(char **)arg);
//printf("AFTER argc = %d %s %s %p\n", i, arg[0], arg[1], arg[2]);
}
else
{
@@ -76,35 +80,39 @@ static void run_cmd(const vector<string> &appargs) {
}
}
void eat_whitespace(const char *&b, int &i)
{
// Eat whitespace
while (b[i] == ' ' || b[i] == '\t') { ++i; }
b = &b[i];
i=0;
}
static void process_commands(const char *cmds)
{
vector<string> appargs(5);
vector<string> appargs;
int i=0;
int j=0;
const char *b = cmds;
bool found_first_char = false;
char arg[20];
// Eat leading whitespace
while (b[i] == ' ') { ++i; };
b = &b[i];
eat_whitespace(b, i);
for(;;) {
// End of command line
if (b[i] == '\n' || b[i] == '\0') {
strncpy(arg, b, i);
arg[i] = '\0';
appargs[j] = arg;
appargs.push_back(arg);
// If we have a command to run
if (i > 0 || j > 0)
if (appargs.size() > 0) {
run_cmd(appargs);
j=0;
}
appargs.clear();
if (b[i] == '\n') {
// Eat whitespace
while (b[++i] == ' ');
b = &b[i];
i=0;
eat_whitespace(b, ++i);
continue;
}
else {
@@ -115,12 +123,8 @@ static void process_commands(const char *cmds)
else if (b[i] == ' ') {
strncpy(arg, b, i);
arg[i] = '\0';
appargs[j] = arg;
j++;
// Eat whitespace
while (b[++i] == ' ');
b = &b[i];
i=0;
appargs.push_back(arg);
eat_whitespace(b, ++i);
continue;
}
++i;
@@ -129,6 +133,7 @@ static void process_commands(const char *cmds)
int main(int argc, char **argv)
{
px4::init(argc, argv, "mainapp");
process_commands(commands);
for (;;) {}
}
+24 -13
View File
@@ -79,14 +79,17 @@ typedef struct
static void entry_adapter ( void *ptr )
{
pthdata_t *data;
data = (pthdata_t *) ptr;
pthdata_t *data = (pthdata_t *) ptr;
data->entry(data->argc, data->argv);
free(ptr);
printf("TEST3\n");
#if 0
//data->entry(data->argc, data->argv);
printf("TEST4\n");
printf("Before px4_task_exit\n");
px4_task_exit(0);
//free(ptr);
printf("After px4_task_exit\n");
#endif
}
void
@@ -95,7 +98,7 @@ px4_systemreset(bool to_bootloader)
printf("Called px4_system_reset\n");
}
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const argv[])
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const *argv)
{
int rv;
int argc = 0;
@@ -105,14 +108,18 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
unsigned long structsize;
char * p;
//printf("arg %d %s %s %p\n", argc, argv[0], argv[1], argv[2]);
printf("arg %d %p\n", argc, argv);
// Calculate argc
for(;;) {
p = argv[argc];
printf("arg %d %s\n", argc, argv[argc]);
if (p == (char *)0)
break;
++argc;
len += strlen(p)+1;
if (argv) {
for(;;) {
p = argv[argc];
if (p == (char *)0)
break;
printf("arg %d %s\n", argc, argv[argc]);
++argc;
len += strlen(p)+1;
}
}
structsize = sizeof(pthdata_t)+(argc+1)*sizeof(char *);
pthdata_t *taskdata;
@@ -125,6 +132,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
taskdata->argc = argc;
for (i=0; i<argc; i++) {
printf("TEST\n");
printf("arg %d %s\n", i, argv[i]);
taskdata->argv[i] = (char *)offset;
strcpy((char *)offset, argv[i]);
@@ -138,10 +146,11 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
taskmap[i].pid = i+1;
taskmap[i].name = name;
taskmap[i].isused = true;
taskmap[i].sp = malloc(stack_size);;
taskmap[i].sp = malloc(stack_size);
break;
}
}
printf("TEST2\n");
thread_create(entry_adapter, taskmap[i].sp, i+1, (void *) taskdata);
return i+1;
@@ -156,6 +165,8 @@ int px4_task_delete(px4_task_t id)
void px4_task_exit(int ret)
{
thread_stop();
// Free stack
}
void px4_killall(void)
@@ -56,7 +56,7 @@ static void usage()
}
int hello_main(int argc, char *argv[])
{
printf("argc = %d %s %s\n", argc, argv[0], argv[1]);
printf("argc = %d %s %s %p\n", argc, argv[0], argv[1], argv[2]);
if (argc < 2) {
usage();
return 1;