1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

PyMite: add a new 'openpilot_sitl' platform which allows for stdio to the console and make it the default platform for win32 SiTL.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2436 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
cwabbott 2011-01-15 17:10:10 +00:00 committed by cwabbott
parent 1f7f9486c3
commit 24a058c8c7
8 changed files with 534 additions and 1 deletions

View File

@ -0,0 +1,67 @@
import os
import glob
TCHAIN = "arm-eabi"
#TCHAIN = "arm-elf"
#TCHAIN = "arm-none-eabi"
Import("vars")
vars.Add("PM_UART_BAUD", "Baud rate of the ipm serial connection.", "19200")
vars.Add("IPM", "Add the interactive library to the standard lib", True)
vars.Add("MCU", "Type of ARM device; the arg to -mcpu.", "cortex-m3")
vars.Add("NM", "", "arm-eabi-nm")
vars.Add("OBJCOPY", "", "%s-objcopy" % TCHAIN)
vars.Add("OBJDUMP", "", "%s-objdump" % TCHAIN)
vars.Add("SIZE", "", "%s-size" % TCHAIN)
#vars.Add("DEBUG","", True)
CFLAGS = " -DUART_BAUD=$PM_UART_BAUD -Dgcc" \
" -DUSE_STDPERIPH_DRIVER -DSTM32F10X_HD" \
" -Wall -Wimplicit" \
" -mcpu=$MCU -mthumb -Os -fomit-frame-pointer -mlittle-endian" \
" -ffunction-sections -fdata-sections -fno-strict-aliasing"
LDFLAGS = "-mcpu=$MCU -mthumb -Wl,-T -Xlinker src/platform/stm32/stm32f10x.ld" \
" -u _start-Wl,-e,Reset_Handler -Wl,-static -Wl,--gc-sections" \
" -nostartfiles -Wl,--allow-multiple-definition"
AFLAGS = "-x assembler-with-cpp $_CPPINCFLAGS -mcpu=$MCU -mthumb -Wall -c"
if "DEBUG" in vars.args.keys():
CFLAGS = "-g -gstabs -D__DEBUG__=1 " + CFLAGS
SOURCES = ["main.c", "plat.c", "stm32f10x_it.c", "syscalls.c"]
SOURCES += glob.glob("FWlib/src/*.c")
SOURCES += glob.glob("FWlib/src/*.s")
PY_SOURCES = ["main.py"]
PM_LIB_ROOT = ["pmvm_%s" % vars.args["PLATFORM"]]
env = Environment(variables = vars,
CPPPATH = ["#src/vm", "#src/platform/stm32", "#src/platform/stm32/FWlib/inc"],
CC = "%s-gcc" % TCHAIN,
AS = "%s-gcc" % TCHAIN,
ASFLAGS = AFLAGS,
CCFLAGS = CFLAGS,
CXX = "%s-g++" % TCHAIN,
AR = "%s-ar" % TCHAIN,
ARFLAGS = "rcs",
RANLIB = "%s-ranlib" % TCHAIN,
LINKFLAGS = LDFLAGS,
ENV = os.environ)
vmlib = SConscript(["../../vm/SConscript"], ["env", "vars"])
pmfeatures = env.Command(["pmfeatures.h"], ["pmfeatures.py"],
"src/tools/pmGenPmFeatures.py $SOURCE > $TARGET")
img_sources = env.Command(["main_img.c", "main_nat.c"], [PY_SOURCES],
"src/tools/pmImgCreator.py -f src/platform/stm32/pmfeatures.py -c -u " \
"-o src/platform/stm32/main_img.c " \
"--native-file=src/platform/stm32/main_nat.c $SOURCES")
elf = env.Program("main.elf", SOURCES + img_sources + vmlib,
LIBS = [PM_LIB_ROOT,"c","gcc","m"], LIBPATH = ["../../vm"])
bin = env.Command("main.bin", "main.elf", "$OBJCOPY -O binary $SOURCE $TARGET")

View File

@ -0,0 +1,307 @@
/**
* @file plat.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief PyMite platform definitions for OpenPilot
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pm.h"
#include "openpilot.h"
PmReturn_t plat_init(void)
{
return PM_RET_OK;
}
PmReturn_t plat_deinit(void)
{
return PM_RET_OK;
}
/*
* Gets a byte from the address in the designated memory space
* Post-increments *paddr.
*/
uint8_t plat_memGetByte(PmMemSpace_t memspace, uint8_t const **paddr)
{
uint8_t b = 0;
switch (memspace)
{
case MEMSPACE_RAM:
case MEMSPACE_PROG:
b = **paddr;
*paddr += 1;
return b;
case MEMSPACE_EEPROM:
case MEMSPACE_SEEPROM:
case MEMSPACE_OTHER0:
case MEMSPACE_OTHER1:
case MEMSPACE_OTHER2:
case MEMSPACE_OTHER3:
default:
return 0;
}
}
PmReturn_t plat_getByte(uint8_t *b)
{
int c;
PmReturn_t retval = PM_RET_OK;
c = getchar();
*b = c & 0xFF;
if (c == EOF)
{
PM_RAISE(retval, PM_RET_EX_IO);
}
return retval;
}
PmReturn_t plat_putByte(uint8_t b)
{
int i;
PmReturn_t retval = PM_RET_OK;
i = putchar(b);
fflush(stdout);
if ((i != b) || (i == EOF))
{
PM_RAISE(retval, PM_RET_EX_IO);
}
return retval;
}
PmReturn_t plat_getMsTicks(uint32_t *r_ticks)
{
*r_ticks = xTaskGetTickCount() * portTICK_RATE_MS;
return PM_RET_OK;
}
void plat_reportError(PmReturn_t result)
{
#ifdef HAVE_DEBUG_INFO
#define LEN_FNLOOKUP 26
#define LEN_EXNLOOKUP 17
uint8_t res;
pPmFrame_t pframe;
pPmObj_t pstr;
PmReturn_t retval;
uint8_t bcindex;
uint16_t bcsum;
uint16_t linesum;
uint16_t len_lnotab;
uint8_t const *plnotab;
uint16_t i;
/* This table should match src/vm/fileid.txt */
char const * const fnlookup[LEN_FNLOOKUP] = {
"<no file>",
"codeobj.c",
"dict.c",
"frame.c",
"func.c",
"global.c",
"heap.c",
"img.c",
"int.c",
"interp.c",
"pmstdlib_nat.c",
"list.c",
"main.c",
"mem.c",
"module.c",
"obj.c",
"seglist.c",
"sli.c",
"strobj.c",
"tuple.c",
"seq.c",
"pm.c",
"thread.c",
"float.c",
"class.c",
"bytearray.c",
};
/* This table should match src/vm/pm.h PmReturn_t */
char const * const exnlookup[LEN_EXNLOOKUP] = {
"Exception",
"SystemExit",
"IoError",
"ZeroDivisionError",
"AssertionError",
"AttributeError",
"ImportError",
"IndexError",
"KeyError",
"MemoryError",
"NameError",
"SyntaxError",
"SystemError",
"TypeError",
"ValueError",
"StopIteration",
"Warning",
};
/* Print traceback */
printf("Traceback (most recent call first):\n");
/* Get the top frame */
pframe = gVmGlobal.pthread->pframe;
/* If it's the native frame, print the native function name */
if (pframe == (pPmFrame_t)&(gVmGlobal.nativeframe))
{
/* The last name in the names tuple of the code obj is the name */
retval = tuple_getItem((pPmObj_t)gVmGlobal.nativeframe.nf_func->
f_co->co_names, -1, &pstr);
if ((retval) != PM_RET_OK)
{
printf(" Unable to get native func name.\n");
return;
}
else
{
printf(" %s() __NATIVE__\n", ((pPmString_t)pstr)->val);
}
/* Get the frame that called the native frame */
pframe = (pPmFrame_t)gVmGlobal.nativeframe.nf_back;
}
/* Print the remaining frame stack */
for (; pframe != C_NULL; pframe = pframe->fo_back)
{
/* The last name in the names tuple of the code obj is the name */
retval = tuple_getItem((pPmObj_t)pframe->fo_func->f_co->co_names,
-1,
&pstr);
if ((retval) != PM_RET_OK) break;
/*
* Get the line number of the current bytecode. Algorithm comes from:
* http://svn.python.org/view/python/trunk/Objects/lnotab_notes.txt?view=markup
*/
bcindex = pframe->fo_ip - pframe->fo_func->f_co->co_codeaddr;
plnotab = pframe->fo_func->f_co->co_lnotab;
len_lnotab = mem_getWord(MEMSPACE_PROG, &plnotab);
bcsum = 0;
linesum = pframe->fo_func->f_co->co_firstlineno;
for (i = 0; i < len_lnotab; i += 2)
{
bcsum += mem_getByte(MEMSPACE_PROG, &plnotab);
if (bcsum > bcindex) break;
linesum += mem_getByte(MEMSPACE_PROG, &plnotab);
}
printf(" File \"%s\", line %d, in %s\n",
((pPmFrame_t)pframe)->fo_func->f_co->co_filename,
linesum,
((pPmString_t)pstr)->val);
}
/* Print error */
res = (uint8_t)result;
if ((res > 0) && ((res - PM_RET_EX) < LEN_EXNLOOKUP))
{
printf("%s", exnlookup[res - PM_RET_EX]);
}
else
{
printf("Error code 0x%02X", result);
}
printf(" detected by ");
if ((gVmGlobal.errFileId > 0) && (gVmGlobal.errFileId < LEN_FNLOOKUP))
{
printf("%s:", fnlookup[gVmGlobal.errFileId]);
}
else
{
printf("FileId 0x%02X line ", gVmGlobal.errFileId);
}
printf("%d\n", gVmGlobal.errLineNum);
#else /* HAVE_DEBUG_INFO */
/* Print error */
printf("Error: 0x%02X\n", result);
printf(" Release: 0x%02X\n", gVmGlobal.errVmRelease);
printf(" FileId: 0x%02X\n", gVmGlobal.errFileId);
printf(" LineNum: %d\n", gVmGlobal.errLineNum);
/* Print traceback */
{
pPmObj_t pframe;
pPmObj_t pstr;
PmReturn_t retval;
printf("Traceback (top first):\n");
/* Get the top frame */
pframe = (pPmObj_t)gVmGlobal.pthread->pframe;
/* If it's the native frame, print the native function name */
if (pframe == (pPmObj_t)&(gVmGlobal.nativeframe))
{
/* The last name in the names tuple of the code obj is the name */
retval = tuple_getItem((pPmObj_t)gVmGlobal.nativeframe.nf_func->
f_co->co_names, -1, &pstr);
if ((retval) != PM_RET_OK)
{
printf(" Unable to get native func name.\n");
return;
}
else
{
printf(" %s() __NATIVE__\n", ((pPmString_t)pstr)->val);
}
/* Get the frame that called the native frame */
pframe = (pPmObj_t)gVmGlobal.nativeframe.nf_back;
}
/* Print the remaining frame stack */
for (;
pframe != C_NULL;
pframe = (pPmObj_t)((pPmFrame_t)pframe)->fo_back)
{
/* The last name in the names tuple of the code obj is the name */
retval = tuple_getItem((pPmObj_t)((pPmFrame_t)pframe)->
fo_func->f_co->co_names, -1, &pstr);
if ((retval) != PM_RET_OK) break;
printf(" %s()\n", ((pPmString_t)pstr)->val);
}
printf(" <module>.\n");
}
#endif /* HAVE_DEBUG_INFO */
/* TODO: Copy error information to UAVObject */
/* gVmGlobal.errVmRelease gVmGlobal.errFileId gVmGlobal.errLineNum */
}

View File

@ -0,0 +1,31 @@
/**
* @file plat.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief PyMite platform definitions for OpenPilot
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _PLAT_H_
#define _PLAT_H_
#define PM_HEAP_SIZE 0x2000
#define PM_FLOAT_LITTLE_ENDIAN
#endif /* _PLAT_H_ */

View File

@ -0,0 +1,29 @@
# This file is Copyright 2010 Dean Hall.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
#
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.
PM_FEATURES = {
"HAVE_PRINT": True,
"HAVE_GC": True,
"HAVE_FLOAT": True,
"HAVE_DEL": True,
"HAVE_IMPORTS": True,
"HAVE_DEFAULTARGS": True,
"HAVE_REPLICATION": True,
"HAVE_CLASSES": True,
"HAVE_ASSERT": True,
"HAVE_GENERATORS": True,
"HAVE_BACKTICK": False,
"HAVE_STRING_FORMAT": False,
"HAVE_CLOSURES": False,
"HAVE_BYTEARRAY": False,
"HAVE_DEBUG_INFO": False,
}

View File

@ -0,0 +1,47 @@
/**
* PyMite library image file.
*
* Automatically created from:
* main.py
* img-list-terminator
* by pmImgCreator.py on
* Tue Jan 11 21:25:50 2011.
*
* Byte count: 127
*
* Selected memspace type: RAM
*
* DO NOT EDIT THIS FILE.
* ANY CHANGES WILL BE LOST.
*/
/* Place the image into RAM */
#ifdef __cplusplus
extern
#endif
unsigned char const
usrlib_img[] =
{
/* main.py */
0x0A, 0x7E, 0x00, 0x00, 0x40, 0x03, 0x00, 0x00,
0x0C, 0x00, 0x04, 0x03, 0x03, 0x03, 0x00, 0x69,
0x70, 0x6D, 0x03, 0x07, 0x00, 0x67, 0x6C, 0x6F,
0x62, 0x61, 0x6C, 0x73, 0x03, 0x04, 0x00, 0x6D,
0x61, 0x69, 0x6E, 0x03, 0x06, 0x00, 0x05, 0x02,
0x0C, 0x01, 0x10, 0x02, 0x03, 0x08, 0x00, 0x6D,
0x61, 0x69, 0x6E, 0x2E, 0x70, 0x79, 0x00, 0x04,
0x04, 0x03, 0x05, 0x00, 0x48, 0x65, 0x6C, 0x6C,
0x6F, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03,
0x08, 0x00, 0x47, 0x6F, 0x6F, 0x64, 0x2D, 0x62,
0x79, 0x65, 0x04, 0x00, 0x64, 0x00, 0x00, 0x47,
0x48, 0x64, 0x01, 0x00, 0x64, 0x02, 0x00, 0x6B,
0x00, 0x00, 0x5A, 0x00, 0x00, 0x65, 0x00, 0x00,
0x69, 0x00, 0x00, 0x65, 0x01, 0x00, 0x83, 0x00,
0x00, 0x83, 0x01, 0x00, 0x01, 0x64, 0x03, 0x00,
0x47, 0x48, 0x64, 0x02, 0x00, 0x53,
/* img-list-terminator */
0xFF,
};

View File

@ -0,0 +1,37 @@
#undef __FILE_ID__
#define __FILE_ID__ 0x0A
/**
* PyMite usr native function file
*
* automatically created by pmImgCreator.py
* on Tue Jan 11 21:25:50 2011
*
* DO NOT EDIT THIS FILE.
* ANY CHANGES WILL BE LOST.
*
* @file main_nat.c
*/
#define __IN_LIBNATIVE_C__
#include "pm.h"
PmReturn_t
nat_placeholder_func(pPmFrame_t *ppframe)
{
/*
* Use placeholder because an index
* value of zero denotes the stdlib.
* This function should not be called.
*/
PmReturn_t retval;
PM_RAISE(retval, PM_RET_EX_SYS);
return retval;
}
/* Native function lookup table */
pPmNativeFxn_t const usr_nat_fxn_table[] =
{
nat_placeholder_func,
};

View File

@ -0,0 +1,15 @@
/* Automatically generated by ../../tools/pmGenPmFeatures.py on Tue Jan 11 21:25:50 2011. DO NOT EDIT. */
#define HAVE_PRINT
#define HAVE_CLASSES
#define HAVE_REPLICATION
#define HAVE_GENERATORS
#define HAVE_STRING_FORMAT
#define HAVE_CLOSURES
#define HAVE_DEBUG_INFO
#define HAVE_ASSERT
#define HAVE_DEFAULTARGS
#define HAVE_DEL
#define HAVE_BACKTICK
#define HAVE_FLOAT
#define HAVE_GC
#define HAVE_IMPORTS

View File

@ -102,7 +102,7 @@ RTOSINCDIR = $(RTOSSRCDIR)/include
DOXYGENDIR = ../Doc/Doxygen
PYMITE = $(FLIGHTLIB)/PyMite
PYMITELIB = $(PYMITE)/lib
PYMITEPLAT = $(PYMITE)/platform/openpilot
PYMITEPLAT = $(PYMITE)/platform/openpilot_sitl
PYMITETOOLS = $(PYMITE)/tools
PYMITEVM = $(PYMITE)/vm
PYMITEINC = $(PYMITEVM)