Rebase changes on upstream master

This brings in many of the changes from the PX4 fork on ATLFLight.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2016-02-19 16:59:41 +01:00
committed by Julian Oes
parent efe9344fc2
commit 9f3bf8e9f4
71 changed files with 2734 additions and 564 deletions
+3 -1
View File
@@ -36,6 +36,8 @@
* Driver for the simulated barometric pressure sensor
*/
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_time.h>
@@ -389,7 +391,7 @@ BAROSIM::devRead(void *buffer, size_t buflen)
int
BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
{
PX4_WARN("baro IOCTL %llu", hrt_absolute_time());
PX4_WARN("baro IOCTL %" PRIu64 , hrt_absolute_time());
switch (cmd) {
@@ -30,6 +30,13 @@
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
if("${CONFIG_SHMEM}" STREQUAL "1")
list(APPEND SHMEM_SRCS
shmem_posix.c
)
endif()
px4_add_module(
MODULE platforms__posix__px4_layer
COMPILE_FLAGS
@@ -41,6 +48,7 @@ px4_add_module(
lib_crc32.c
drv_hrt.c
px4_log.c
${SHMEM_SRCS}
DEPENDS
platforms__common
)
+3
View File
@@ -41,5 +41,8 @@ SRCS = \
lib_crc32.c \
drv_hrt.c \
px4_log.c
ifeq ($(CONFIG_SHMEM), 1)
SRCS += shmem_posix.c
endif
MAXOPTIMIZATION = -Os
@@ -58,6 +58,16 @@ __BEGIN_DECLS
long PX4_TICKS_PER_SEC = sysconf(_SC_CLK_TCK);
#ifdef ENABLE_SHMEM
extern void init_params(void);
#endif
#ifdef ENABLE_SHMEM
extern void init_own_params(void);
extern unsigned int init_other_params(void);
extern unsigned int param_sync_done;
#endif
__END_DECLS
namespace px4
@@ -72,6 +82,12 @@ void init_once(void)
work_queues_init();
hrt_work_queue_init();
hrt_init();
#ifdef ENABLE_SHMEM
PX4_INFO("Starting shared memory param sync\n");
init_own_params();
param_sync_done=init_other_params();
#endif
}
void init(int argc, char *argv[], const char *app_name)
+270
View File
@@ -0,0 +1,270 @@
/****************************************************************************
*
* Copyright (c) 2015 Ramakrishna Kintada. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
#include <px4_defines.h>
#include <px4_posix.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <systemlib/err.h>
#include <errno.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <drivers/drv_hrt.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "systemlib/param/param.h"
#include <shmem.h>
#define SHMEM_DEBUG
int mem_fd;
unsigned char *map_base, *virt_addr;
struct shmem_info* shmem_info_p;
static void* map_memory(off_t target);
int get_shmem_lock(void);
void release_shmem_lock(void);
void init_shared_memory(void);
void copy_params_to_shmem(struct param_info_s *);
void update_to_shmem(param_t param, union param_value_u value);
int update_from_shmem(param_t param, union param_value_u *value);
uint64_t update_from_shmem_prev_time=0, update_from_shmem_current_time=0;
static unsigned char adsp_changed_index[MAX_SHMEM_PARAMS/8+1];
struct param_wbuf_s {
param_t param;
union param_value_u val;
bool unsaved;
};
extern struct param_wbuf_s * param_find_changed(param_t param);
#define MEMDEVICE "/dev/mem"
static void* map_memory(off_t target)
{
if((mem_fd = open(MEMDEVICE, O_RDWR | O_SYNC)) == -1)
{
PX4_ERR("Cannot open %s\n", MEMDEVICE);
exit(1);
}
/* Map one page */
map_base = (unsigned char*) mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, target & ~MAP_MASK);
if(map_base == (void *) -1)
{
PX4_ERR("Cannot mmap /dev/atl_mem\n");
exit(1);
}
return (map_base + (target & MAP_MASK) + LOCK_SIZE);
}
int get_shmem_lock(void)
{
int i=0;
/*ioctl calls cmpxchg*/
while(ioctl(mem_fd, LOCK_MEM)!=0)
{
PX4_INFO("Could not get lock, spinning\n");
usleep(100000); //sleep for 100 msec
i++;
if(i>100) break;
}
if(i>100) return -1;
return 0; //got the lock
}
void release_shmem_lock(void)
{
*(virt_addr-LOCK_SIZE)=1;
}
void init_shared_memory(void)
{
virt_addr = map_memory(MAP_ADDRESS); //16K space
shmem_info_p = (struct shmem_info*)virt_addr;
//PX4_INFO("linux memory mapped\n");
}
void copy_params_to_shmem(struct param_info_s *param_info_base)
{
param_t param;
unsigned int i;
if(get_shmem_lock()!=0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
//PX4_INFO("%d krait params allocated\n", param_count());
for (param = 0; param<param_count(); param++) {
struct param_wbuf_s *s = param_find_changed(param);
if(s==NULL) shmem_info_p->params_val[param] = param_info_base[param].val;
else shmem_info_p->params_val[param] = s->val;
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32){
{PX4_INFO("%d: written %d for param %s to shared mem", param, shmem_info_p->params_val[param].i, param_name(param));}
}
else if(param_type(param)==PARAM_TYPE_FLOAT){
{PX4_INFO("%d: written %f for param %s to shared mem", param, (double)shmem_info_p->params_val[param].f, param_name(param));}
}
#endif
}
//PX4_INFO("written %u params to shmem offset %lu\n", param_count(), (unsigned char*)&shmem_info_p->params_count-(unsigned char*)shmem_info_p);
for(i=0;i<MAX_SHMEM_PARAMS/8+1;i++)
{
shmem_info_p->krait_changed_index[i]=0;
adsp_changed_index[i]=0;
}
release_shmem_lock();
}
/*update value and param's change bit in shared memory*/
void update_to_shmem(param_t param, union param_value_u value)
{
unsigned int byte_changed, bit_changed;
if(get_shmem_lock()!=0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
shmem_info_p->params_val[param] = value;
byte_changed = param/8;
bit_changed = 1 << param%8;
shmem_info_p->krait_changed_index[byte_changed]|=bit_changed;
//PX4_INFO("set %d bit on krait changed index[%d] to %d\n", bit_changed, byte_changed, shmem_info_p->krait_changed_index[byte_changed]);
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32)
{PX4_INFO("Set value %d for param %s to shmem, set krait index %d:%d\n", value.i, param_name(param), byte_changed, bit_changed);}
else if(param_type(param)==PARAM_TYPE_FLOAT)
{PX4_INFO("Set value %f for param %s to shmem, set krait index %d:%d\n", (double)value.f, param_name(param), byte_changed, bit_changed);}
#endif
release_shmem_lock();
}
static void update_index_from_shmem(void)
{
unsigned int i;
if(get_shmem_lock()!=0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
//PX4_INFO("Updating index from shmem\n");
for(i=0;i<MAX_SHMEM_PARAMS/8+1;i++)
adsp_changed_index[i]=shmem_info_p->adsp_changed_index[i];
release_shmem_lock();
}
static void update_value_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
if(get_shmem_lock()!=0) {
fprintf(stderr, "Could not get shmem lock\n");
return;
}
*value = shmem_info_p->params_val[param];
/*also clear the index since we are holding the lock*/
byte_changed = param/8;
bit_changed = 1 << param%8;
shmem_info_p->adsp_changed_index[byte_changed] &= ~bit_changed;
release_shmem_lock();
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32)
{PX4_INFO("Got value %d for param %s from shmem, cleared adsp index %d:%d\n", value->i, param_name(param), byte_changed, bit_changed);}
else if(param_type(param)==PARAM_TYPE_FLOAT)
{PX4_INFO("Got value %f for param %s from shmem, cleared adsp index %d:%d\n", (double)value->f, param_name(param), byte_changed, bit_changed);}
#endif
}
int update_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
unsigned int retval = 0;
update_from_shmem_current_time = hrt_absolute_time();
if((update_from_shmem_current_time - update_from_shmem_prev_time) > 1000000) //update every 1 second
{
update_from_shmem_prev_time = update_from_shmem_current_time;
update_index_from_shmem();
}
byte_changed = param/8;
bit_changed = 1 << param%8;
if(adsp_changed_index[byte_changed] & bit_changed)
{
update_value_from_shmem(param, value);
adsp_changed_index[byte_changed] &= ~bit_changed; //clear the bit
retval = 1;
}
//else {PX4_INFO("no change to param %s\n", param_name(param));}
//PX4_INFO("%s %d bit on adsp index[%d]\n", (retval)?"cleared":"unchanged", bit_changed, byte_changed);
return retval;
}
@@ -43,7 +43,7 @@
#include "muorb_test_example.h"
#include <stdio.h>
#include "uORB/uORBManager.hpp"
#include "uORBKraitFastRpcChannel.hpp"
#include "../../../modules/muorb/krait/uORBKraitFastRpcChannel.hpp"
int PX4_MAIN(int argc, char **argv)
{
@@ -61,10 +61,12 @@ static int writer_main(int argc, char *argv[])
int fd = px4_open(TESTDEV, PX4_F_WRONLY);
int fd = px4_open(TESTDEV, PX4_F_WRONLY);
if (fd < 0) {
PX4_INFO("Writer: Open failed %d %d", fd, px4_errno);
return -px4_errno;
}
src/platforms/posix/tests/vcdev_test/vcdevtest_example.cpp
int ret;
int i = 0;
@@ -92,6 +94,12 @@ static int writer_main(int argc, char *argv[])
class PrivData
{
PrivData() : _read_offset(0) {}
~PrivData() {}
size_t _read_offset;
};
public:
PrivData() : _read_offset(0) {}
~PrivData() {}
@@ -321,12 +329,16 @@ int VCDevExample::main()
(char *const *)NULL);
ret = 0;
PX4_INFO("TEST: BLOCKING POLL ---------------");
if (do_poll(fd, -1, 3, 0)) {
ret = 1;
goto fail2;
PX4_INFO("TEST: ZERO TIMEOUT POLL -----------");
if(do_poll(fd, 0, 3, 0)) {
ret = 1;
goto fail2;
goto fail2;
}
PX4_INFO("TEST: ZERO TIMEOUT POLL -----------");
@@ -348,8 +360,7 @@ int VCDevExample::main()
if (do_poll(fd, 1000, 3, 0)) {
ret = 1;
goto fail2;
}
PX4_INFO("TEST: waiting for writer to stop");
fail2:
g_exit = true;
px4_close(fd);
+10
View File
@@ -77,10 +77,20 @@ typedef sem_t px4_sem_t;
#define px4_sem_init sem_init
#define px4_sem_wait sem_wait
#define px4_sem_post sem_post
#define px4_sem_getvalue sem_getvalue
#define px4_sem_destroy sem_destroy
#if 0
// TODO: Implement this function or remove it from the implementation.
// #define px4_sem_timedwait sem_timedwait
inline int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime)
{
return -1;
}
#endif
#ifdef __PX4_QURT
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
#else
+3 -12
View File
@@ -31,6 +31,8 @@
#
############################################################################
include_directories(${HEXAGON_SDK_ROOT}/lib/common/qurt/ADSPv5MP/include)
set(QURT_LAYER_SRCS
px4_qurt_impl.cpp
px4_qurt_tasks.cpp
@@ -39,6 +41,7 @@ set(QURT_LAYER_SRCS
qurt_stubs.c
main.cpp
params.c
shmem_qurt.c
)
if ("${QURT_ENABLE_STUBS}" STREQUAL "1")
list(APPEND QURT_LAYER_SRCS
@@ -47,18 +50,6 @@ if ("${QURT_ENABLE_STUBS}" STREQUAL "1")
)
endif()
# For Eagle, the commands are specific to the build config label
# e.g. config_qurt_eagle_hil uses commands_hil.c
if ("${BOARD}" STREQUAL "eagle")
# The CI test target can use the hil commands
if ("${LABEL}" STREQUAL "travis")
set(CONFIG_SRC commands_hil.c)
else()
set(CONFIG_SRC commands_${LABEL}.c)
endif()
endif()
px4_add_module(
MODULE platforms__qurt__px4_layer
@@ -1,45 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
/**
* @file commands_hello.c
* Commands to run for the "qurt_hello" config
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
const char *get_commands()
{
static const char *commands = "hello start";
return commands;
}
@@ -1,80 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
/**
* @file commands_muorb_test.c
* Commands to run for the "qurt_muorb_test" config
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
const char *get_commands()
{
static const char *commands =
"uorb start\n"
"muorb_test start\n";
/*
"hil mode_pwm\n"
"mixer load /dev/pwm_output0 /startup/quad_x.main.mix\n";
*/
/*
"param show\n"
"param set CAL_GYRO_ID 2293760\n"
"param set CAL_ACC0_ID 1310720\n"
"param set CAL_ACC1_ID 1376256\n"
"param set CAL_MAG0_ID 196608\n"
"gyrosim start\n"
"accelsim start\n"
"rgbled start\n"
"tone_alarm start\n"
"simulator start -s\n"
"commander start\n"
"sensors start\n"
"ekf_att_pos_estimator start\n"
"mc_pos_control start\n"
"mc_att_control start\n"
"param set MAV_TYPE 2\n"
"param set RC1_MAX 2015\n"
"param set RC1_MIN 996\n"
"param set RC_TRIM 1502\n"
*/
return commands;
/*====================================== Working set
======================================*/
//"muorb_test start\n"
//"gyrosim start\n"
//"adcsim start\n"
}
@@ -1,175 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
/**
* @file commands_muorb_test.c
* Commands to run for the "qurt_muorb_test" config
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
const char *get_commands()
{
static const char *commands =
"uorb start\n"
"param set CAL_GYRO0_ID 2293760\n"
"param set CAL_ACC0_ID 1310720\n"
"param set CAL_ACC1_ID 1376256\n"
"param set CAL_MAG0_ID 196608\n"
"commander start\n"
"param set RC_RECEIVER_TYPE 1\n"
"rc_receiver start -D /dev/tty-1\n"
"attitude_estimator_q start\n"
"position_estimator_inav start\n"
//"ekf_att_pos_estimator start\n"
"mc_pos_control start\n"
"mc_att_control start\n"
"sleep 1\n"
// Channel mapping for Spektrum DX8
"param set RC_MAP_THROTTLE 1\n"
"param set RC_MAP_ROLL 2\n"
"param set RC_MAP_PITCH 3\n"
"param set RC_MAP_YAW 4\n"
"param set RC_MAP_MODE_SW 5\n"
"param set RC_MAP_POSCTL_SW 6\n"
// RC calibration for Spektrum DX8
"param set RC1_MAX 852\n"
"param set RC1_MIN 171\n"
"param set RC1_TRIM 171\n"
"param set RC1_REV 1\n"
"param set RC2_MAX 852\n"
"param set RC2_MIN 171\n"
"param set RC2_TRIM 512\n"
"param set RC2_REV -1\n"
"param set RC3_MAX 852\n"
"param set RC3_MIN 171\n"
"param set RC3_TRIM 512\n"
"param set RC3_REV 1\n"
"param set RC4_MAX 852\n"
"param set RC4_MIN 171\n"
"param set RC4_TRIM 514\n"
"param set RC4_REV -1\n"
"param set RC5_MAX 852\n"
"param set RC5_MIN 171\n"
"param set RC5_TRIM 512\n"
"param set RC5_REV 1\n"
"param set RC6_MAX 852\n"
"param set RC6_MIN 171\n"
"param set RC6_TRIM 171\n"
"param set RC6_REV 1\n"
// // RC calibration for DX6i
// "param set RC1_MAX 2015\n"
// "param set RC1_MIN 996\n"
// "param set RC1_TRIM 1502\n"
// "param set RC1_REV -1\n"
// "param set RC2_MAX 2016 \n"
// "param set RC2_MIN 995\n"
// "param set RC2_TRIM 1500\n"
// "param set RC3_MAX 2003\n"
// "param set RC3_MIN 992\n"
// "param set RC3_TRIM 992\n"
// "param set RC4_MAX 2011\n"
// "param set RC4_MIN 997\n"
// "param set RC4_TRIM 1504\n"
// "param set RC4_REV -1\n"
// "param set RC6_MAX 2016\n"
// "param set RC6_MIN 992\n"
// "param set RC6_TRIM 1504\n"
// "param set RC_CHAN_CNT 8\n"
// "param set RC_MAP_MODE_SW 5\n"
// "param set RC_MAP_POSCTL_SW 7\n"
// "param set RC_MAP_RETURN_SW 8\n"
"sensors start\n"
"param set MC_YAW_P 7.0\n"
"param set MC_YAWRATE_P 0.1125\n"
"param set MC_YAWRATE_I 0.0\n"
"param set MC_YAWRATE_D 0\n"
"param set MC_PITCH_P 6.0\n"
"param set MC_PITCHRATE_P 0.125\n"
"param set MC_PITCHRATE_I 0.0\n"
"param set MC_PITCHRATE_D 0.0\n"
"param set MC_ROLL_P 6.0\n"
"param set MC_ROLLRATE_P 0.1125\n"
"param set MC_ROLLRATE_I 0.0\n"
"param set MC_ROLLRATE_D 0.0\n"
"param set ATT_W_MAG 0.00\n"
"param set PE_MAG_NOISE 1.0f\n" // ekf_att_pos only
"param set SENS_BOARD_ROT 6\n"
"param set CAL_GYRO0_XOFF 0.0\n"
"param set CAL_GYRO0_YOFF 0.0\n"
"param set CAL_GYRO0_ZOFF 0.0\n"
"param set CAL_GYRO0_XSCALE 1.000000\n"
"param set CAL_GYRO0_YSCALE 1.000000\n"
"param set CAL_GYRO0_ZSCALE 1.000000\n"
"param set CAL_ACC0_XOFF 0.0\n"
"param set CAL_ACC0_YOFF 0.0\n"
"param set CAL_ACC0_ZOFF 0.0\n"
"param set CAL_ACC0_XSCALE 1.0\n"
"param set CAL_ACC0_YSCALE 1.0\n"
"param set CAL_ACC0_ZSCALE 1.0\n"
// "param set CAL_ACC0_XOFF 0.064189\n"
// "param set CAL_ACC0_YOFF 0.153990\n"
// "param set CAL_ACC0_ZOFF -0.000567\n"
"param set MPU_GYRO_LPF_ENUM 4\n"
"param set MPU_ACC_LPF_ENUM 4\n"
"param set MPU_SAMPLE_RATE_ENUM 2\n"
"sleep 1\n"
"mpu9x50 start -D /dev/spi-1\n"
"uart_esc start -D /dev/tty-2\n"
"csr_gps start -D /dev/tty-3\n"
"param set MAV_TYPE 2\n"
"list_devices\n"
"list_files\n"
"list_tasks\n"
"list_topics\n"
;
return commands;
}
/*
simulator numbers
"param set MC_YAW_P 1.5\n"
"param set MC_PITCH_P 3.0\n"
"param set MC_ROLL_P 3.0\n"
"param set MC_YAWRATE_P 0.2\n"
"param set MC_PITCHRATE_P 0.03\n"
"param set MC_ROLLRATE_P 0.03\n"
*/
@@ -1,68 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
/**
* @file commands_default.c
* Commands to run for the "qurt_default" config
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
const char *get_commands()
{
static const char *commands =
"hello start\n"
"uorb start\n"
"simulator start -s\n"
"barosim start\n"
"adcsim start\n"
"accelsim start\n"
"gyrosim start\n"
"list_devices\n"
"list_topics\n"
"list_tasks\n"
"param show *\n"
"rgbled start\n"
#if 0
"sensors start\n"
"param set CAL_GYRO0_ID 2293760\n"
"param set CAL_ACC0_ID 1310720\n"
"hil mode_pwm"
"param set CAL_ACC1_ID 1376256\n"
"param set CAL_MAG0_ID 196608\n"
"mavlink start -d /tmp/ttyS0\n"
"commander start\n"
#endif
;
return commands;
}
+48 -7
View File
@@ -46,7 +46,7 @@
#include <string>
#include <map>
#include <stdio.h>
#include <apps.h>
#include <stdlib.h>
#include "get_commands.h"
using namespace std;
@@ -67,24 +67,28 @@ static void run_cmd(map<string, px4_main_t> &apps, const vector<string> &appargs
// command is appargs[0]
string command = appargs[0];
if (apps.find(command) != apps.end()) {
//replaces app.find with iterator code to avoid null pointer exception
for (map<string,px4_main_t>::iterator it=apps.begin(); it!=apps.end(); ++it)
if (it->first == command) {
const char *arg[2 + 1];
unsigned int i = 0;
while (i < appargs.size() && appargs[i].c_str()[0] != '\0') {
arg[i] = (char *)appargs[i].c_str();
PX4_WARN(" arg = '%s'\n", arg[i]);
PX4_WARN(" arg%d = '%s'\n", i, arg[i]);
++i;
}
arg[i] = (char *)0;
//PX4_DEBUG_PRINTF(i);
apps[command](i, (char **)arg);
if(apps[command]==NULL)
PX4_ERR("Null function !!\n");
else {
apps[command](i, (char **)arg);
break;
}
} else {
PX4_WARN("NOT FOUND.");
list_builtins(apps);
}
}
@@ -104,6 +108,7 @@ static void process_commands(map<string, px4_main_t> &apps, const char *cmds)
const char *b = cmds;
char arg[256];
// Eat leading whitespace
eat_whitespace(b, i);
@@ -159,6 +164,42 @@ int dspal_main(int argc, char *argv[]);
__END_DECLS
#define COMMANDS_ADSP_FILE "/dev/fs/px4.config"
const char *get_commands()
{
int fd = open(COMMANDS_ADSP_FILE, O_RDONLY);
if(fd>0)
{
static char *commands;
char buf[4096];
int bytes_read, total_bytes=0;
PX4_INFO("reading commands from %s\n", COMMANDS_ADSP_FILE);
do{
bytes_read = read(fd, (void*)buf, sizeof(buf));
if(bytes_read>0)
{
commands=(char*)realloc(commands, total_bytes+bytes_read);
memcpy(commands+total_bytes, buf, bytes_read);
total_bytes += bytes_read;
}
}while((unsigned int)bytes_read>0);
close(fd);
return (const char*)commands;
}
PX4_ERR("Could not open %s\n", COMMANDS_ADSP_FILE);
static const char *commands =
"uorb start\n"
;
return commands;
}
int dspal_entry(int argc, char *argv[])
{
PX4_INFO("In main\n");
+3 -18
View File
@@ -44,23 +44,8 @@ SRCS = \
px4_qurt_tasks.cpp \
lib_crc32.c \
drv_hrt.c \
qurt_stubs.c \
main.cpp
ifeq ($(CONFIG),qurt_hello)
SRCS += commands_hello.c
endif
ifeq ($(CONFIG),qurt_default)
SRCS += commands_default.c
endif
ifeq ($(CONFIG),qurt_muorb_test)
SRCS += commands_muorb_test.c
endif
ifeq ($(CONFIG),qurt_hil)
SRCS += commands_hil.c
endif
ifeq ($(CONFIG),qurt_adsp)
SRCS += commands_adsp.c
endif
qurt_stubs.c \
main.cpp \
shmem_qurt.c
MAXOPTIMIZATION = -Os
@@ -71,6 +71,9 @@ unsigned int sleep(unsigned int sec)
}
extern void hrt_init(void);
extern void init_own_params();
extern unsigned int init_other_params();
extern unsigned int param_sync_done;
#if 0
void qurt_log(const char *fmt, ...)
@@ -108,6 +111,10 @@ void init_once(void)
hrt_work_queue_init();
hrt_init();
PX4_WARN("after calling hrt_init");
/*Shared memory param sync*/
init_own_params();
param_sync_done=init_other_params();
}
void init(int argc, char *argv[], const char *app_name)
@@ -106,7 +106,7 @@ static void *entry_adapter(void *ptr)
void
px4_systemreset(bool to_bootloader)
{
PX4_WARN("Called px4_system_reset");
PX4_WARN("Called px4_system_reset but NOT yet implemented.");
}
px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry,
+260
View File
@@ -0,0 +1,260 @@
/****************************************************************************
*
* Copyright (c) 2015 Vijay Venkatraman. All rights reserved.
*
* 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 PX4 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.
*
****************************************************************************/
#include <px4_defines.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <atomic_ops.h>
#include "systemlib/param/param.h"
#include <shmem.h>
#include <drivers/drv_hrt.h>
#define SHMEM_DEBUG
int mem_fd;
unsigned char *map_base, *virt_addr;
struct shmem_info* shmem_info_p;
static void* map_memory(off_t target);
int get_shmem_lock(void);
void release_shmem_lock(void);
void init_shared_memory(void);
void copy_params_to_shmem(struct param_info_s *);
void update_to_shmem(param_t param, union param_value_u value);
int update_from_shmem(param_t param, union param_value_u *value);
uint64_t update_from_shmem_prev_time=0, update_from_shmem_current_time=0;
static unsigned char krait_changed_index[MAX_SHMEM_PARAMS/8+1];
struct param_wbuf_s {
param_t param;
union param_value_u val;
bool unsaved;
};
extern struct param_wbuf_s * param_find_changed(param_t param);
static void* map_memory(off_t target)
{
return (void*)(target+LOCK_SIZE);
}
int get_shmem_lock(void)
{
unsigned char *lock = (unsigned char*)(MAP_ADDRESS+LOCK_OFFSET);
unsigned int i=0;
while(!atomic_compare_and_set(lock, 1, 0))
{
PX4_INFO("Could not get lock. spinning\n");
i++;
usleep(1000);
if(i>100) break;
}
if(i>100) return -1;
return 0; //got the lock
}
void release_shmem_lock(void)
{
unsigned char *lock = (unsigned char*)(MAP_ADDRESS+LOCK_OFFSET);
*lock=1;
return;
}
void init_shared_memory(void)
{
//PX4_INFO("Value at lock address is %d\n", *(unsigned int*)0xfbfc000);
virt_addr = map_memory(MAP_ADDRESS);
shmem_info_p = (struct shmem_info*)virt_addr;
//PX4_INFO("adsp memory mapped\n");
}
void copy_params_to_shmem(struct param_info_s *param_info_base)
{
param_t param;
unsigned int i;
if(get_shmem_lock()!=0) {
PX4_INFO("Could not get shmem lock\n");
return;
}
//else PX4_INFO("Got lock\n");
for (param = 0; param<param_count(); param++) {
//{PX4_INFO("writing to offset %d\n", (unsigned char*)(shmem_info_p->adsp_params[param].name)-(unsigned char*)shmem_info_p);}
struct param_wbuf_s *s = param_find_changed(param);
if(s==NULL) shmem_info_p->params_val[param] = param_info_base[param].val;
else shmem_info_p->params_val[param] = s->val;
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32){
PX4_INFO("%d: written %d for param %s to shared mem", param, shmem_info_p->params_val[param].i, param_name(param));}
else if(param_type(param)==PARAM_TYPE_FLOAT){
PX4_INFO("%d: written %f for param %s to shared mem", param, shmem_info_p->params_val[param].f, param_name(param));}
#endif
}
for(i=0;i<MAX_SHMEM_PARAMS/8+1;i++)
{
shmem_info_p->adsp_changed_index[i]=0;
krait_changed_index[i]=0;
}
release_shmem_lock();
//PX4_INFO("Released lock\n");
}
/*update value and param's change bit in shared memory*/
void update_to_shmem(param_t param, union param_value_u value)
{
unsigned int byte_changed, bit_changed;
if(!handle_in_range(param))
return;
if(get_shmem_lock()!=0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
shmem_info_p->params_val[param] = value;
byte_changed = param/8;
bit_changed = 1 << param%8;
shmem_info_p->adsp_changed_index[byte_changed]|=bit_changed;
//PX4_INFO("set %d bit on adsp index[%d] to %d\n", bit_changed, byte_changed, shmem_info_p->adsp_changed_index[byte_changed]);
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32)
{PX4_INFO("Set value %d for param %s to shmem, set adsp index %d:%d\n", value.i, param_name(param), byte_changed, bit_changed);}
else if(param_type(param)==PARAM_TYPE_FLOAT)
{PX4_INFO("Set value %f for param %s to shmem, set adsp index %d:%d\n", value.f, param_name(param), byte_changed, bit_changed);}
#endif
release_shmem_lock();
}
static void update_index_from_shmem(void)
{
unsigned int i;
if(get_shmem_lock()!=0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
//PX4_INFO("Updating index from shmem\n");
for(i=0;i<MAX_SHMEM_PARAMS/8+1;i++)
krait_changed_index[i]=shmem_info_p->krait_changed_index[i];
release_shmem_lock();
}
static void update_value_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
if(get_shmem_lock()!=0) {
PX4_ERR("Could not get shmem lock\n");
return;
}
*value = shmem_info_p->params_val[param];
/*also clear the index since we are holding the lock*/
byte_changed = param/8;
bit_changed = 1 << param%8;
shmem_info_p->krait_changed_index[byte_changed] &= ~bit_changed;
release_shmem_lock();
#ifdef SHMEM_DEBUG
if(param_type(param)==PARAM_TYPE_INT32)
{PX4_INFO("Got value %d for param %s from shmem, cleared krait index %d:%d\n", value->i, param_name(param), byte_changed, bit_changed);}
else if(param_type(param)==PARAM_TYPE_FLOAT)
{PX4_INFO("Got value %f for param %s from shmem, cleared krait index %d:%d\n", value->f, param_name(param), byte_changed, bit_changed);}
#endif
}
int update_from_shmem(param_t param, union param_value_u *value)
{
unsigned int byte_changed, bit_changed;
unsigned int retval = 0;
if(!handle_in_range(param) || value==NULL)
return retval;
update_from_shmem_current_time = hrt_absolute_time();
if((update_from_shmem_current_time - update_from_shmem_prev_time) > 1000000) //update every 1 second
{
update_from_shmem_prev_time = update_from_shmem_current_time;
update_index_from_shmem();
}
byte_changed = param/8;
bit_changed = 1 << param%8;
if(krait_changed_index[byte_changed] & bit_changed)
{
update_value_from_shmem(param, value);
krait_changed_index[byte_changed] &= ~bit_changed;
retval = 1;
}
//else {PX4_INFO("no change to param %s\n", param_name(param));}
//PX4_INFO("%s %d bit on krait changed index[%d]\n", (retval)?"cleared":"unchanged", bit_changed, byte_changed);
return retval;
}
+3
View File
@@ -2,6 +2,8 @@
#include <qurt_log.h>
#include <dspal_platform.h>
#ifdef CONFIG_ARCH_BOARD_EAGLE
void HAP_debug(const char *msg, int level, const char *filename, int line)
{
}
@@ -14,3 +16,4 @@ int dlinit(int a, char **b)
{
return 1;
}
#endif
@@ -88,7 +88,7 @@ int MuorbTestExample::DefaultTest()
int i = 0;
pwm.error_count++;
sc.gyro_errcount++;
sc.gyro_errcount[i]++;
while (!appState.exitRequested() && i < 10) {
@@ -1,6 +1,7 @@
/****************************************************************************
*
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
* Copyright (c) 2015 Ramakrishna Kintada. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,28 +31,30 @@
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file commands_default.c
* Commands to run for the "qurt_eagle_default" config
*
* @author Mark Charlebois <charlebm@gmail.com>
*/
#include "get_commands.h"
#define MAX_SHMEM_PARAMS 3850 //MAP_SIZE - (LOCK_SIZE - sizeof(struct shmem_info))
const char *get_commands()
struct shmem_info
{
union param_value_u params_val[MAX_SHMEM_PARAMS];
unsigned char krait_changed_index[MAX_SHMEM_PARAMS/8+1]; /*bit map of all params changed by krait*/
unsigned char adsp_changed_index[MAX_SHMEM_PARAMS/8+1]; /*bit map of all params changed by adsp*/
static const char *commands =
"uorb start\n"
"param set CAL_GYRO0_ID 2293760\n"
"param set CAL_ACC0_ID 1310720\n"
"param set CAL_ACC1_ID 1376256\n"
"param set CAL_MAG0_ID 196608\n"
"commander start\n"
#ifdef __PX4_NUTTX
};
#else
}__attribute__((packed));
#endif
;
#define MAP_ADDRESS 0xfbfc000
#define MAP_SIZE 16384
#define MAP_MASK (MAP_SIZE - 1)
return commands;
#define LOCK_OFFSET 0
#define LOCK_SIZE 4
#define LOCK_MEM 1
#define UNLOCK_MEM 2
}
#define TYPE_MASK 0x1
extern bool handle_in_range(param_t);