Abstractions to compile systemlib for Linux and Nuttx

Modified uint32_t casts of pointers to unsigned long for portability.
It otherwise breaks on x86_64.

Added _PX4_IOC to handle the conflice between _IOC on Linux and NuttX.

Removed use of px4::ok() because it cannot be used in a thread based
implementation. Changed to use px4::AppMgr which uses ok() on ROS.

Removed up_cxxinitialize.c from Linux build.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-04-20 11:00:16 -07:00
parent 89e1b454af
commit 5084a61f0e
25 changed files with 174 additions and 116 deletions
+3 -3
View File
@@ -42,15 +42,15 @@
* @author Petri Tanskanen <petri.tanskanen@inf.ethz.ch>
*/
#include <px4_config.h>
#include <nuttx/sched.h>
//#include <nuttx/sched.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <arch/arch.h>
//#include <arch/arch.h>
#include <debug.h>
//#include <debug.h>
#include <sys/time.h>
+1
View File
@@ -43,6 +43,7 @@
#include "mcu_version.h"
#include <px4_config.h>
#include <px4_defines.h>
#ifdef CONFIG_ARCH_CHIP_STM32
#include <up_arch.h>
+4 -1
View File
@@ -43,7 +43,6 @@ SRCS = err.c \
conversions.c \
cpuload.c \
getopt_long.c \
up_cxxinitialize.c \
pid/pid.c \
systemlib.c \
airspeed.c \
@@ -57,6 +56,10 @@ SRCS = err.c \
circuit_breaker_params.c \
mcu_version.c
ifeq ($(PX4_TARGET_OS),nuttx)
SRCS += up_cxxinitialize.c
endif
MAXOPTIMIZATION = -Os
EXTRACFLAGS = -Wno-sign-compare
+2 -2
View File
@@ -170,7 +170,7 @@ void F_lock(void)
}
// flash write word.
int F_write_word(uint32_t Address, uint32_t Data)
int F_write_word(unsigned long Address, uint32_t Data)
{
unsigned char octet[4] = {0, 0, 0, 0};
@@ -185,7 +185,7 @@ int F_write_word(uint32_t Address, uint32_t Data)
}
// flash write byte
int F_write_byte(uint32_t Address, uint8_t Data)
int F_write_byte(unsigned long Address, uint8_t Data)
{
volatile int status = F_COMPLETE;
+20 -19
View File
@@ -54,6 +54,7 @@ __BEGIN_DECLS
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
// possible flash statuses
@@ -64,30 +65,30 @@ __BEGIN_DECLS
#define F_COMPLETE 5
typedef struct {
volatile uint32_t accesscontrol; // 0x00
volatile uint32_t key; // 0x04
volatile uint32_t optionkey; // 0x08
volatile uint32_t status; // 0x0C
volatile uint32_t control; // 0x10
volatile uint32_t optioncontrol; //0x14
volatile unsigned long accesscontrol; // 0x00
volatile unsigned long key; // 0x04
volatile unsigned long optionkey; // 0x08
volatile unsigned long status; // 0x0C
volatile unsigned long control; // 0x10
volatile unsigned long optioncontrol; //0x14
} flash_registers;
#define PERIPH_BASE ((uint32_t)0x40000000) //Peripheral base address
#define PERIPH_BASE ((unsigned long)0x40000000) //Peripheral base address
#define AHB1PERIPH_BASE (PERIPH_BASE + 0x00020000)
#define F_R_BASE (AHB1PERIPH_BASE + 0x3C00)
#define FLASH ((flash_registers *) F_R_BASE)
#define F_BSY ((uint32_t)0x00010000) //FLASH Busy flag bit
#define F_OPERR ((uint32_t)0x00000002) //FLASH operation Error flag bit
#define F_WRPERR ((uint32_t)0x00000010) //FLASH Write protected error flag bit
#define CR_PSIZE_MASK ((uint32_t)0xFFFFFCFF)
#define F_PSIZE_WORD ((uint32_t)0x00000200)
#define F_PSIZE_BYTE ((uint32_t)0x00000000)
#define F_CR_PG ((uint32_t)0x00000001) // a bit in the F_CR register
#define F_CR_LOCK ((uint32_t)0x80000000) // also another bit.
#define F_BSY ((unsigned long)0x00010000) //FLASH Busy flag bit
#define F_OPERR ((unsigned long)0x00000002) //FLASH operation Error flag bit
#define F_WRPERR ((unsigned long)0x00000010) //FLASH Write protected error flag bit
#define CR_PSIZE_MASK ((unsigned long)0xFFFFFCFF)
#define F_PSIZE_WORD ((unsigned long)0x00000200)
#define F_PSIZE_BYTE ((unsigned long)0x00000000)
#define F_CR_PG ((unsigned long)0x00000001) // a bit in the F_CR register
#define F_CR_LOCK ((unsigned long)0x80000000) // also another bit.
#define F_KEY1 ((uint32_t)0x45670123)
#define F_KEY2 ((uint32_t)0xCDEF89AB)
#define F_KEY1 ((unsigned long)0x45670123)
#define F_KEY2 ((unsigned long)0xCDEF89AB)
#define IS_F_ADDRESS(ADDRESS) ((((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF)) || (((ADDRESS) >= 0x1FFF7800) && ((ADDRESS) < 0x1FFF7A0F)))
@@ -143,8 +144,8 @@ __EXPORT int write_otp(uint8_t id_type, uint32_t vid, uint32_t pid, char *signat
__EXPORT int lock_otp(void);
__EXPORT int F_write_byte(uint32_t Address, uint8_t Data);
__EXPORT int F_write_word(uint32_t Address, uint32_t Data);
__EXPORT int F_write_byte(unsigned long Address, uint8_t Data);
__EXPORT int F_write_word(unsigned long Address, uint32_t Data);
__END_DECLS
+3 -2
View File
@@ -41,7 +41,8 @@
* and background parameter saving.
*/
#include <debug.h>
//#include <debug.h>
#include <px4_defines.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
@@ -646,7 +647,7 @@ param_save_default(void)
const char *filename = param_get_default_file();
/* write parameters to temp file */
fd = open(filename, O_WRONLY | O_CREAT);
fd = open(filename, O_WRONLY | O_CREAT, 0x777);
if (fd < 0) {
warn("failed to open param file: %s", filename);
+11 -11
View File
@@ -386,7 +386,7 @@ perf_print_counter_fd(int fd, perf_counter_t handle)
case PC_COUNT:
dprintf(fd, "%s: %llu events\n",
handle->name,
((struct perf_ctr_count *)handle)->event_count);
(unsigned long long)((struct perf_ctr_count *)handle)->event_count);
break;
case PC_ELAPSED: {
@@ -395,12 +395,12 @@ perf_print_counter_fd(int fd, perf_counter_t handle)
dprintf(fd, "%s: %llu events, %llu overruns, %lluus elapsed, %lluus avg, min %lluus max %lluus %5.3fus rms\n",
handle->name,
pce->event_count,
pce->event_overruns,
pce->time_total,
pce->time_total / pce->event_count,
pce->time_least,
pce->time_most,
(unsigned long long)pce->event_count,
(unsigned long long)pce->event_overruns,
(unsigned long long)pce->time_total,
(unsigned long long)pce->time_total / pce->event_count,
(unsigned long long)pce->time_least,
(unsigned long long)pce->time_most,
(double)(1e6f * rms));
break;
}
@@ -411,10 +411,10 @@ perf_print_counter_fd(int fd, perf_counter_t handle)
dprintf(fd, "%s: %llu events, %lluus avg, min %lluus max %lluus %5.3fus rms\n",
handle->name,
pci->event_count,
(pci->time_last - pci->time_first) / pci->event_count,
pci->time_least,
pci->time_most,
(unsigned long long)pci->event_count,
(unsigned long long)(pci->time_last - pci->time_first) / pci->event_count,
(unsigned long long)pci->time_least,
(unsigned long long)pci->time_most,
(double)(1e6f * rms));
break;
}
+1
View File
@@ -40,6 +40,7 @@
#include <px4_config.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <systemlib/err.h>
+5 -62
View File
@@ -37,78 +37,21 @@
* Implementation of commonly used low-level system-call like functions.
*/
#include <px4_config.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <float.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stm32_pwr.h>
#include <px4_tasks.h>
#include "systemlib.h"
// Didn't seem right to include up_internal.h, so direct extern instead.
extern void up_systemreset(void) noreturn_function;
void
systemreset(bool to_bootloader)
{
if (to_bootloader) {
stm32_pwr_enablebkp();
/* XXX wow, this is evil - write a magic number into backup register zero */
*(uint32_t *)0x40002850 = 0xb007b007;
}
up_systemreset();
/* lock up here */
while (true);
px4_systemreset(to_bootloader);
}
static void kill_task(FAR struct tcb_s *tcb, FAR void *arg);
void killall()
{
// printf("Sending SIGUSR1 to all processes now\n");
/* iterate through all tasks and send kill signal */
sched_foreach(kill_task, NULL);
px4_killall();
}
static void kill_task(FAR struct tcb_s *tcb, FAR void *arg)
int task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const argv[])
{
kill(tcb->pid, SIGUSR1);
}
int task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, main_t entry, char *const argv[])
{
int pid;
sched_lock();
/* create the task */
pid = task_create(name, priority, stack_size, entry, argv);
if (pid > 0) {
/* configure the scheduler */
struct sched_param param;
param.sched_priority = priority;
sched_setscheduler(pid, scheduler, &param);
/* XXX do any other private task accounting here before the task starts */
}
sched_unlock();
return pid;
return px4_task_spawn_cmd(name, scheduler, priority, stack_size, entry, argv);
}
+5 -3
View File
@@ -39,10 +39,11 @@
************************************************************************************/
#include <px4_config.h>
#include <stdint.h>
#include <debug.h>
//#include <debug.h>
#include <nuttx/arch.h>
//#include <nuttx/arch.h>
//#include <arch/stm32/chip.h>
//#include "chip.h"
@@ -122,7 +123,8 @@ extern uint32_t _etext;
*
***************************************************************************/
__EXPORT void up_cxxinitialize(void)
__EXPORT void up_cxxinitialize(void);
void up_cxxinitialize(void)
{
initializer_t *initp;