From: batt Date: Fri, 7 Nov 2008 22:21:30 +0000 (+0000) Subject: Rename app dir to examples. X-Git-Tag: 2.0.0~21 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=24c21c92d29b76a3f0de0a107f4bafef7bb0f812;p=bertos.git Rename app dir to examples. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1913 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/Makefile b/Makefile index a7c0b12c..1eb5c26e 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,8 @@ default: all include bertos/config.mk #Include subtargets -include app/demo/demo.mk -#include app/at91sam7s/at91sam7s.mk -#include app/triface/triface.mk +include examples/demo/demo.mk +#include examples/at91sam7s/at91sam7s.mk +#include examples/triface/triface.mk include bertos/rules.mk diff --git a/Makefile.test b/Makefile.test index 4ddda36b..5b485c11 100644 --- a/Makefile.test +++ b/Makefile.test @@ -5,6 +5,6 @@ V:= 0 default: all include bertos/config.mk -include ./app/test/avrtest.mk -include ./app/test/armtest.mk +include ./examples/test/avrtest.mk +include ./examples/test/armtest.mk include bertos/rules.mk diff --git a/app/at91sam7s/at91sam7s.c b/app/at91sam7s/at91sam7s.c deleted file mode 100644 index 275af6e5..00000000 --- a/app/at91sam7s/at91sam7s.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \author Francesco Sacchi - * - * \brief AT91SAM7S-EK porting test. - */ - -#include -#include -#include -#include -#include -#include -#include - -Timer leds_timer; -Serial ser_fd; - -static void leds_toggle(void) -{ - uint8_t a = (~PIOA_ODSR & 0x0f); - - if (a) - { - PIOA_SODR = a; - PIOA_CODR = a << 1; - } - else - { - PIOA_SODR = 0x0f; - /* turn first led on */ - PIOA_CODR = 0x00000001; - } - - /* Wait for interval time */ - timer_setDelay(&leds_timer, ms_to_ticks(100)); - timer_add(&leds_timer); -} - - -int main(void) -{ - char msg[]="BeRTOS, be fast be beatiful be realtime"; - kdbg_init(); - timer_init(); - - proc_init(); - ASSERT(!IRQ_ENABLED()); - - /* Open the main communication port */ - ser_init(&ser_fd, 0); - ser_setbaudrate(&ser_fd, 115200); - ser_setparity(&ser_fd, SER_PARITY_NONE); - - - IRQ_ENABLE; - ASSERT(IRQ_ENABLED()); - - /* Disable all pullups */ - PIOA_PUDR = 0xffffffff; - /* Set PA0..3 connected to PIOA */ - PIOA_PER = 0x0000001f; - /* Set PA0..3 as output */ - PIOA_OER = 0x0000001f; - /* Disable multidrive on all pins */ - PIOA_MDDR = 0x0000001f; - - /* Set PA0..3 to 1 to turn off leds */ - PIOA_SODR = 0x0000000f; - /* turn first led on */ - PIOA_CODR = 0x00000001; - - timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0); - timer_setDelay(&leds_timer, ms_to_ticks(100)); - timer_add(&leds_timer); - - ASSERT(proc_testRun() == 0); - // Main loop - for(;;) - { - kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg); - } - return 0; -} diff --git a/app/at91sam7s/at91sam7s.mk b/app/at91sam7s/at91sam7s.mk deleted file mode 100644 index 44017904..00000000 --- a/app/at91sam7s/at91sam7s.mk +++ /dev/null @@ -1,45 +0,0 @@ -# -# $Id: at91sam7s.mk 18234 2007-10-08 13:39:48Z rasky $ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib at91sam7s application. -# -# Author: Bernie Innocenti -# -# - -# Set to 1 for debug builds -at91sam7s_DEBUG = 1 - -# Our target application -TRG += at91sam7s - -at91sam7s_CSRC = \ - app/at91sam7s/at91sam7s.c \ - bertos/drv/timer.c \ - bertos/drv/ser.c \ - bertos/cpu/arm/drv/sysirq_at91.c \ - bertos/cpu/arm/drv/ser_at91.c \ - bertos/mware/event.c \ - bertos/mware/formatwr.c \ - bertos/mware/hex.c \ - bertos/kern/kfile.c \ - bertos/kern/proc.c \ - bertos/kern/coop.c \ - bertos/kern/proc_test.c \ - bertos/kern/monitor.c \ - bertos/kern/signal.c - -at91sam7s_CPPASRC = \ - bertos/cpu/arm/hw/crtat91sam7_rom.S \ - bertos/cpu/arm/hw/switch_arm.S - -at91sam7s_CROSS = arm-none-eabi- - -at91sam7s_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug -at91sam7s_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_AT91SAM7S256__ -g3 -gdwarf-2 -fverbose-asm -Iapp/at91sam7s/hw -Iapp/at91sam7s -Ibertos/cpu/arm -at91sam7s_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_ram.ld -Wl,--no-warn-mismatch - -at91sam7s_CPU = arm7tdmi - diff --git a/app/at91sam7s/cfg/cfg_kern.h b/app/at91sam7s/cfg/cfg_kern.h deleted file mode 100644 index bc4594a4..00000000 --- a/app/at91sam7s/cfg/cfg_kern.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * \file - * - * - * \brief Kernel configuration parameters - * - * \version $Id$ - * \author Bernie Innocenti - */ - -#ifndef CFG_KERN_H -#define CFG_KERN_H - -/** - * Enable the multithreading kernel. - */ -#define CONFIG_KERN 1 - -/** - * \name Optional kernel features - * \{ - */ -#define CONFIG_KERN_SCHED 1 ///< Process schedling -#define CONFIG_KERN_SIGNALS 1 ///< Inter-process signals -#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor -#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation -#define CONFIG_KERN_SEMAPHORES 1 ///< Re-entrant mutual exclusion primitives -#define CONFIG_KERN_MONITOR 1 ///< Process monitor -#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling -#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy -/*\}*/ - -/// [ms] Time sharing quantum (a prime number prevents interference effects) -#define CONFIG_KERN_QUANTUM 47 - -/// Module logging level. -#define KERN_LOG_LEVEL LOG_LVL_ERR - -/// Module logging format. -#define KERN_LOG_FORMAT LOG_FMT_VERBOSE - -#endif /* CFG_KERN_H */ diff --git a/app/at91sam7s/hw/hw_cpu.h b/app/at91sam7s/hw/hw_cpu.h deleted file mode 100644 index 69652610..00000000 --- a/app/at91sam7s/hw/hw_cpu.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * \file - * - * - * \brief Hardware-specific definitions - * - * \version $Id$ - * - * \author Bernie Innocenti - */ - -/*#* - *#* $Log$ - *#* Revision 1.1 2006/05/18 00:41:47 bernie - *#* New triface devlib application. - *#* - *#*/ - -#ifndef AT91SAM7SEK_HW_H -#define AT91SAM7SEK_HW_H - -/// CPU Clock frequency (48.023 MHz) -#define CLOCK_FREQ (48023000UL) - - -/* Timer IRQ strobe */ -//#if CONFIG_TIMER_STROBE -// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) -// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) -// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) -//#endif /* CONFIG_TIMER_STROBE */ - -#endif /* AT91SAM7SEK_HW_H */ diff --git a/app/at91sam7s/hw/hw_ser.h b/app/at91sam7s/hw/hw_ser.h deleted file mode 100644 index 7b98f223..00000000 --- a/app/at91sam7s/hw/hw_ser.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * \file - * - * - * \brief Serial hardware-specific definitions - * - * \version $Id$ - * - * \author Daniele Basile - */ - - diff --git a/app/at91sam7s/verstag.h b/app/at91sam7s/verstag.h deleted file mode 100644 index e6163906..00000000 --- a/app/at91sam7s/verstag.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \author Bernie Innocenti - * - * \brief Declare application version strings - */ -#ifndef DEVLIB_VERSTAG_H -#define DEVLIB_VERSTAG_H - -#ifndef ARCH_CONFIG_H - #include "cfg/arch_config.h" -#endif - -#define APP_NAME "AT91SAM7S-EK porting test" -#define APP_DESCRIPTION "AT91SAM7S-EK porting test" -#define APP_AUTHOR "Develer" -#define APP_COPYRIGHT "Copyright 2007 Develer (http://www.develer.com/)" - -#define VERS_MAJOR 0 -#define VERS_MINOR 1 -#define VERS_REV 0 -#define VERS_LETTER "" - -/** - * If _SNAPSHOT is defined, \c VERS_TAG contains the build date - * date instead of a numeric version string. - */ -//#define _SNAPSHOT - -#ifdef _DEBUG - #define VERS_DBG "D" -#else - #define VERS_DBG "" -#endif - -#define __STRINGIZE(x) #x -#define _STRINGIZE(x) __STRINGIZE(x) - -/** Build application version string (i.e.: "1.7.0") */ -#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG -#ifdef _SNAPSHOT - #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG -#else - #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) -#endif - -/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ -#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) -#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) - -/** The revision string (contains VERS_TAG) */ -extern const char vers_tag[]; - -/** Sequential build number (contains VERS_BUILD) */ -extern const int vers_build_nr; -//extern const char vers_build_str[]; - -/** Hostname of the machine used to build this binary (contains VERS_HOST) */ -extern const char vers_host[]; - -#endif /* DEVLIB_VERSTAG_H */ diff --git a/app/demo/cfg/cfg_kern.h b/app/demo/cfg/cfg_kern.h deleted file mode 100644 index e828bce7..00000000 --- a/app/demo/cfg/cfg_kern.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * \file - * - * - * \brief Kernel configuration parameters - * - * \version $Id$ - * \author Bernie Innocenti - */ - -#ifndef CFG_KERN_H -#define CFG_KERN_H - -/** - * Enable the multithreading kernel. - */ -#define CONFIG_KERN 1 - -/** - * \name Optional kernel features - * \{ - */ -#define CONFIG_KERN_SCHED 1 ///< Process schedling -#define CONFIG_KERN_SIGNALS 1 ///< Inter-process signals -#define CONFIG_KERN_IRQ 1 ///< Interrupt supervisor -#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation -#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives -#define CONFIG_KERN_MONITOR 1 ///< Process monitor -#define CONFIG_KERN_PREEMPT 1 ///< Preemptive process scheduling -#define CONFIG_KERN_PRI 1 ///< Priority-based scheduling policy -/*\}*/ - -/// [ms] Time sharing quantum (a prime number prevents interference effects) -#define CONFIG_KERN_QUANTUM 47 - -/// Module logging level. -#define KERN_LOG_LEVEL LOG_LVL_ERR - -/// Module logging format. -#define KERN_LOG_FORMAT LOG_FMT_VERBOSE - -#endif /* CFG_KERN_H */ diff --git a/app/demo/demo.c b/app/demo/demo.c deleted file mode 100644 index 9c2169cc..00000000 --- a/app/demo/demo.c +++ /dev/null @@ -1,315 +0,0 @@ -/** - * \file - * - * - * \brief Multifunction system test for BeRTOS modules. - * - * \version $Id: demo.c 18242 2007-10-08 17:35:23Z marco $ - * \author Bernie Innocenti - */ - -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -/** - * Draw a pentacle in the provided bitmap. - * - * This is invoked by the keyboard polling routine, as a poor man's surrogate - * of true task switching. - */ -void schedule(void) -{ - lcd_blitBitmap(&lcd_bitmap); - emul_idle(); -} - -/** - * Draw a pentacle in the provided bitmap. - */ -static void magic(struct Bitmap *bitmap, coord_t x, coord_t y) -{ - static const coord_t coords[] = { 120, 34, 90, 90, 30, 90, 0, 34, 60, 0, 90, 90, 0, 34, 120, 34, 30, 90, 60, 0 }; - unsigned int i; - - gfx_moveTo(bitmap, coords[countof(coords)-2]/2 + x, coords[countof(coords)-1]/3 + y); - for (i = 0; i < countof(coords); i += 2) - gfx_lineTo(bitmap, coords[i]/2 + x, coords[i+1]/3 + y); -} - -static void hello_world(Bitmap *bm) -{ - extern const Font font_ncenB18; - const Font *old_font = bm->font; - - gfx_bitmapClear(bm); - - /* Set big font */ - gfx_setFont(bm, &font_ncenB18); - - text_xprintf(bm, 1, 0, STYLEF_BOLD | TEXT_FILL | TEXT_CENTER, - "Hello, world!"); - - lcd_blitBitmap(bm); - timer_delay(1000); - - /* Restore old font */ - gfx_setFont(bm, old_font); -} - -/** - * Show the splash screen - */ -static void bouncing_logo(Bitmap *bm) -{ - const long SPEED_SCALE = 1000; - const long GRAVITY_ACCEL = 10; - const long BOUNCE_ELASTICITY = 2; - long h = (long)(-bertos_logo.height) * SPEED_SCALE; - long speed = 1000; - - /* Repeat until logo stands still on the bottom edge */ - while (!((speed == 0) && (h == 0))) - { - /* Move */ - h += speed; - - /* Gravity acceleration */ - speed += GRAVITY_ACCEL; - - if (h > 0 && speed > 0) - { - /* Bounce */ - speed = - (speed / BOUNCE_ELASTICITY); - - } - - /* Update graphics */ - gfx_bitmapClear(bm); - gfx_blitImage(bm, - (bm->width - bertos_logo.width) / 2, - h / SPEED_SCALE, - &bertos_logo); - lcd_blitBitmap(bm); - - timer_delay(10); - } -} - -void win_demo(Bitmap *bm) -{ - const coord_t small_left = 45, small_top = 30, small_width = 50, small_height = 30; - const coord_t large_left = -10, large_top = 10, large_width = 85, large_height = 41; - - Window root_win, small_win, large_win; - Bitmap small_bm, large_bm; - uint8_t small_raster[RAST_SIZE(small_width, small_height)]; - uint8_t large_raster[RAST_SIZE(large_width, large_height)]; - - win_create(&root_win, bm); - - gfx_bitmapInit(&large_bm, large_raster, large_width, large_height); - win_create(&large_win, &large_bm); - win_open(&large_win, &root_win); - win_move(&large_win, large_left, large_top); - - gfx_bitmapInit(&small_bm, small_raster, small_width, small_height); - win_create(&small_win, &small_bm); - win_open(&small_win, &root_win); - win_move(&small_win, small_left, small_top); - - - coord_t x = 0, y = LCD_WIDTH / 2; - coord_t xdir = +1, ydir = -1; - coord_t xdir_large = +1; - coord_t ydir_small = +1; - int raise_counter = 0; - int i; - - for(;;) - { - /* Background animation */ - bm = root_win.bitmap; - gfx_bitmapClear(bm); -// gfx_setClipRect(bm, 0, 0, bm->width, bm->height); -// gfx_rectDraw(bm, 10, 10, bm->width-10, bm->height-10); -// gfx_setClipRect(bm, 11, 11, bm->width-11, bm->height-11); - magic(bm, x, y); - x += xdir; - y += ydir; - if (x >= bm->width) xdir = -1; - if (x <= -50) xdir = +1; - if (y >= bm->height) ydir = -1; - if (y <= -50) ydir = +1; - - /* Large window animation */ - bm = large_win.bitmap; - gfx_bitmapClear(bm); - for (i = 0; i < bm->height / 2; i += 2) - gfx_rectDraw(bm, 0 + i, 0 + i, bm->width - i, bm->height - i); - - - /* Small window animation */ - bm = small_win.bitmap; - gfx_bitmapClear(bm); - gfx_rectDraw(bm, 0, 0, bm->width, bm->height); - gfx_line(bm, 0, 0, bm->width, bm->height); - gfx_line(bm, bm->width, 0, 0, bm->height); - - /* Move windows around */ - win_move(&large_win, large_win.geom.xmin + xdir_large, large_top); - if (large_win.geom.xmin < -20) xdir_large = +1; - if (large_win.geom.xmin > RECT_WIDTH(&root_win.geom) - 5) xdir_large = -1; - - win_move(&small_win, small_left, small_win.geom.ymin + ydir_small); - if (small_win.geom.ymin < -20) ydir_small = +1; - if (small_win.geom.ymin > RECT_HEIGHT(&root_win.geom) - 5) ydir_small = -1; - - ++raise_counter; - if (raise_counter % 997 == 0) - win_raise(&small_win); - else if (raise_counter % 731 == 0) - win_raise(&large_win); - - win_compose(&root_win); - - /* Also does LCD refresh, etc. */ - if (kbd_peek()) - break; - } -} - -void proc_demo(void) -{ - proc_testRun(); -} - -void timer_demo(void) -{ - timer_testRun(); - timer_testTearDown(); -} - - -/* SETTINGS SUBMENU */ - -static struct MenuItem settings_items[] = -{ - { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Language", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)0, 0, NULL, (iptr_t)0 } -}; -static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; - - -/* MX SUBMENU */ - -static struct MenuItem mx_items[] = -{ - { (const_iptr_t)"Mouse", MIF_CHECKIT | MIF_EXCLUDE_1 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Keyboard", MIF_CHECKED | MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Joystick", MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_1, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Autosave", MIF_CHECKED | MIF_CHECKIT | MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)0, 0, NULL, (iptr_t)0 } -}; - -static struct Menu mx_menu = { mx_items, (const_iptr_t)0, MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; - - -/* DISPLAY SUBMENU */ - -static struct MenuItem display_items[] = -{ - { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)0, 0, NULL, (iptr_t)0 } -}; -static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 }; - - -/* MAIN MENU */ - -static struct MenuItem main_items[] = -{ - { (const_iptr_t)"Win Fly", 0, (MenuHook)win_demo, (iptr_t)&lcd_bitmap }, - { (const_iptr_t)"Bounce!", 0, (MenuHook)bouncing_logo,(iptr_t)&lcd_bitmap }, - { (const_iptr_t)"Hello World", 0, (MenuHook)hello_world, (iptr_t)&lcd_bitmap }, - { (const_iptr_t)"Scheduling", 0, (MenuHook)proc_demo, (iptr_t)&lcd_bitmap }, - { (const_iptr_t)"Timer Test", 0, (MenuHook)timer_demo, (iptr_t)&lcd_bitmap }, - { (const_iptr_t)"Menu MX", 0, (MenuHook)menu_handle, (iptr_t)&mx_menu }, - { (const_iptr_t)"Display", 0, (MenuHook)menu_handle, (iptr_t)&display_menu }, - { (const_iptr_t)"Settings", 0, (MenuHook)menu_handle, (iptr_t)&settings_menu }, - { (const_iptr_t)0, 0, NULL, (iptr_t)0 } -}; -static struct Menu main_menu = { main_items, "Main Menu", MF_STICKY, &lcd_bitmap, 0 }; - - -static cpu_stack_t monitor_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]; - -int main(int argc, char *argv[]) -{ - emul_init(&argc, argv); - irq_init(); - timer_init(); - buz_init(); - kbd_init(); - lcd_init(); - proc_init(); - monitor_start(sizeof(monitor_stack), monitor_stack); - - menu_handle(&main_menu); - - timer_cleanup(); - emul_cleanup(); - return 0; -} diff --git a/app/demo/demo.mk b/app/demo/demo.mk deleted file mode 100644 index 3b318d20..00000000 --- a/app/demo/demo.mk +++ /dev/null @@ -1,87 +0,0 @@ -# -# Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/) -# Copyright 2008 Bernie Innocenti -# -# Makefile fragment for DevLib demo application. -# -# Version: $Id: demo.mk 18234 2007-10-08 13:39:48Z rasky $ -# Author: Bernie Innocenti -# - -include bertos/fonts/fonts.mk -include bertos/emul/emul.mk - -# Set to 1 for debug builds -demo_DEBUG = 1 - -# Our target application -TRG += demo - -# FIXME: we want to use g++ for C source too -CC = g++ -CXX = g++ - -demo_CXXSRC = \ - bertos/emul/emul.cpp \ - bertos/emul/emulwin.cpp \ - bertos/emul/emulkbd.cpp \ - bertos/drv/lcd_gfx_qt.cpp - -demo_CSRC = \ - app/demo/demo.c \ - bertos/os/hptime.c \ - bertos/gfx/bitmap.c \ - bertos/gfx/line.c \ - bertos/gfx/win.c \ - bertos/gfx/text.c \ - bertos/gfx/text_format.c \ - bertos/gui/menu.c \ - bertos/fonts/helvB10.c \ - bertos/fonts/luBS14.c \ - bertos/fonts/ncenB18.c \ - bertos/icons/logo.c \ - bertos/drv/kbd.c \ - bertos/drv/timer.c \ - bertos/drv/timer_test.c \ - bertos/drv/buzzer.c \ - bertos/drv/ser.c \ - bertos/emul/ser_posix.c \ - bertos/mware/formatwr.c \ - bertos/mware/hex.c \ - bertos/mware/event.c \ - bertos/mware/observer.c \ - bertos/mware/resource.c \ - bertos/mware/sprintf.c \ - bertos/kern/idle.c \ - bertos/kern/irq.c \ - bertos/kern/preempt.c \ - bertos/kern/proc.c \ - bertos/kern/proc_test.c \ - bertos/kern/sem.c \ - bertos/kern/signal.c \ - bertos/kern/monitor.c \ - bertos/verstag.c - -demo_CPPASRC = \ - bertos/emul/switch.S - -# FIXME: maybe this junk should go in emul/emul.mk? -$(OBJDIR)/demo/bertos/emul/emulwin.o: bertos/emul/emulwin_moc.cpp -$(OBJDIR)/demo/bertos/drv/lcd_gfx_qt.o: bertos/drv/lcd_gfx_qt_moc.cpp -$(OBJDIR)/demo/bertos/drv/timer.o: bertos/emul/timer_qt_moc.cpp -$(OBJDIR)/demo/bertos/emul/emulkbd.o: bertos/emul/emulkbd_moc.cpp - -#FIXME: isn't there a way to avoid repeating the pattern rule? -bertos/emul/timer_qt_moc.cpp: bertos/emul/timer_qt.c - $(QT_MOC) -o $@ $< - - -demo_CFLAGS = -Iapp/demo $(EMUL_CFLAGS) -demo_CXXFLAGS = -Iapp/demo $(EMUL_CFLAGS) -demo_LDFLAGS = $(EMUL_LDFLAGS) - -# Debug stuff -ifeq ($(demo_DEBUG),0) - demo_CFLAGS += -Os - demo_CXXFLAGS += -Os -endif diff --git a/app/demo/hw/kbd_map.h b/app/demo/hw/kbd_map.h deleted file mode 100644 index deb215ef..00000000 --- a/app/demo/hw/kbd_map.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * \file - * - * - * \brief Keyboard map definitions. - * - * \version $Id$ - * - * \author Francesco Sacchi - * \author Stefano Fedrigo - */ - -#ifndef HW_KBD_MAP_H -#define HW_KBD_MAP_H - -#include - - -/** - * Type for keyboard mask. - */ -typedef uint16_t keymask_t; - -/** - * \name Keycodes. - */ -/*@{*/ -#define K_UP BV(0) -#define K_DOWN BV(1) -#define K_OK BV(2) -#define K_CANCEL BV(3) - -#define K_REPEAT BV(14) /**< This is a repeated keyevent. */ -#define K_TIMEOUT BV(15) /**< Fake key event for timeouts. */ -/*@}*/ - - -#endif /* HW_KBD_MAP_H */ diff --git a/app/demo/verstag.h b/app/demo/verstag.h deleted file mode 100644 index a89a5e52..00000000 --- a/app/demo/verstag.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * \file - * - * - * \version $Id: verstag.h 18242 2007-10-08 17:35:23Z marco $ - * - * \author Bernie Innocenti - * - * \brief Declare application version strings - */ - -#ifndef BERTOS_VERSTAG_H -#define BERTOS_VERSTAG_H - -#ifndef CFG_ARCH_CONFIG_H - #include "cfg/cfg_arch.h" -#endif - -#define APP_NAME "BeRTOS Demo" -#define APP_DESCRIPTION "BeRTOS Multidemo Application" -#define APP_AUTHOR "Develer" -#define APP_COPYRIGHT "Copyright 2006 Develer (http://www.develer.com/)" - -#define VERS_MAJOR 0 -#define VERS_MINOR 1 -#define VERS_REV 0 -#define VERS_LETTER "" - -/** - * If _SNAPSHOT is defined, \c VERS_TAG contains the build date - * date instead of a numeric version string. - */ -#define _SNAPSHOT - -#ifdef _DEBUG - #define VERS_DBG "D" -#else - #define VERS_DBG "" -#endif - -#define __STRINGIZE(x) #x -#define _STRINGIZE(x) __STRINGIZE(x) - -/** Build application version string (i.e.: "1.7.0") */ -#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG -#ifdef _SNAPSHOT - #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG -#else - #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) -#endif - -/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ -#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) -#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) - -/** The revision string (contains VERS_TAG) */ -extern const char vers_tag[]; - -/** Sequential build number (contains VERS_BUILD) */ -extern const int vers_build_nr; -//extern const char vers_build_str[]; - -/** Hostname of the machine used to build this binary (contains VERS_HOST) */ -extern const char vers_host[]; - -#endif /* BERTOS_VERSTAG_H */ diff --git a/app/lm3s1968/hw/hw_cpu.h b/app/lm3s1968/hw/hw_cpu.h deleted file mode 100644 index 52e3d4b8..00000000 --- a/app/lm3s1968/hw/hw_cpu.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * - * - * \brief Hardware-specific definitions - * - * \version $Id$ - * - * \author Bernie Innocenti - */ - -#ifndef HW_CPU_H -#define HW_CPU_H - -#warning TODO:This is an example implementation, you must implement it! - -/// CPU Clock frequency -#define CLOCK_FREQ (48023000L/* Implement me! */) - - -/* Timer IRQ strobe */ -//#if CONFIG_TIMER_STROBE -// #define TIMER_STROBE_ON /* Implement me! */ -// #define TIMER_STROBE_OFF /* Implement me! */ -// #define TIMER_STROBE_INIT /* Implement me! */ -//#endif /* CONFIG_TIMER_STROBE */ - -#endif /* HW_CPU_H */ diff --git a/app/lm3s1968/lm3s1968.c b/app/lm3s1968/lm3s1968.c deleted file mode 100644 index 514f255c..00000000 --- a/app/lm3s1968/lm3s1968.c +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \author Manuele Fanelli - * - * \brief LM3S168 porting test. - */ - -#include "bertos/cpu/detect.h" - -int main (void) -{ - int c; - - for (;;) - c++; - return 0; -} diff --git a/app/lm3s1968/lm3s1968.mk b/app/lm3s1968/lm3s1968.mk deleted file mode 100644 index 8d1b32d9..00000000 --- a/app/lm3s1968/lm3s1968.mk +++ /dev/null @@ -1,31 +0,0 @@ -# -# $Id: lm3s1968.mk 18234 2007-10-08 13:39:48Z rasky $ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib lm3s1968 application. -# -# Author: Manuele Fanelli -# -# - -# Set to 1 for debug builds -lm3s1968_DEBUG = 0 - - -# Our target application -TRG += lm3s1968 - -lm3s1968_CSRC = \ - app/lm3s1968/lm3s1968.c \ - #bertos/cpu/cortex-m3/startup_lm3s.c - - -lm3s1968_CROSS = arm-none-eabi- - -lm3s1968_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug -mthumb -lm3s1968_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_LM3S1968__ -g3 -gdwarf-2 -fverbose-asm -mthumb -Iapp/lm3s1968 -Ibertos/cpu/cortex-m3 -lm3s1968_LDFLAGS = -nostartfiles -T app/lm3s1968/standalone.ld -Wl,--no-warn-mismatch - -lm3s1968_CPU = cortex-m3 - diff --git a/app/randpool/appconfig.h b/app/randpool/appconfig.h deleted file mode 100644 index 75a16bb1..00000000 --- a/app/randpool/appconfig.h +++ /dev/null @@ -1,283 +0,0 @@ -/** - * \file - * - * - * \brief DevLib configuration options - * - * You should copy this header in your project and rename it to - * "config.h" and delete the CONFIG_ macros for the modules - * you're not using. - * - *

Working with multiple applications

- * - * If your project is made of multiple DevLib-based applications, - * create a custom "config.h" file in each application subdirectory - * and play with the compiler include path to get the desired result. - * You can share common options by creationg a "config_common.h" header - * and including it from all your "config.h" copies. - * - *

Configuration style

- * - * For improved compile-time checking of configuration options, - * the preferred way to use a \c CONFIG_ symbol is keeping it - * always defined with a value of either 0 or 1. This lets - * you write tests like this: - * - * \code - * #if CONFIG_FOO - * void foo(void) - * { - * if (CONFIG_BAR) - * bar(); - * } - * #endif // CONFIG_FOO - * \endcode - * - * In most cases, we rely on the optimizer to discard checks - * on constant values and performing dead-code elimination. - * - * \version $Id$ - * \author Bernie Innocenti - * \author Stefano Fedrigo - */ - -/*#* - *#* $Log$ - *#* Revision 1.1 2007/02/15 18:17:51 asterix - *#* Add randpool test program. - *#* - *#* Revision 1.16 2007/02/12 15:29:41 asterix - *#* Add CONFIG_RANDPOOL_TIMER macro to swich on or off timer support in randpool. - *#* - *#* Revision 1.15 2007/02/08 14:20:35 asterix - *#* Add CONFIG_SIZE_ENTROPY_POOL. - *#* - *#* Revision 1.14 2007/02/06 11:37:26 asterix - *#* Add CONFIG_MD2_STD_PERM for use standard permutation in MD2. - *#* - *#* Revision 1.13 2007/01/31 13:49:40 asterix - *#* Add config size block for MD2 - *#* - *#* Revision 1.3 2006/09/13 18:29:22 bernie - *#* Add a few missing CONFIG_ definitions. - *#* - *#* Revision 1.2 2006/07/19 12:56:24 bernie - *#* Convert to new Doxygen style. - *#* - *#* Revision 1.1 2006/05/18 00:40:43 bernie - *#* Rename appconfig.h to appconfig_common.h. - *#* - *#* Revision 1.11 2006/04/11 00:08:53 bernie - *#* Add smooth scrolling for menus. - *#* - *#* Revision 1.10 2006/03/22 09:48:51 bernie - *#* Add a few more config options. - *#* - *#* Revision 1.9 2006/02/24 00:27:35 bernie - *#* Enable kernel and fix Doxygen markup. - *#* - *#* Revision 1.8 2006/02/21 16:06:05 bernie - *#* Update copyright info. - *#* - *#* Revision 1.7 2006/02/17 22:28:19 bernie - *#* Add missing UART definitions. - *#* - *#* Revision 1.6 2006/02/15 09:12:56 bernie - *#* Switch to BITMAP_FMT_PLANAR_V_LSB. - *#* - *#* Revision 1.5 2006/02/10 12:34:33 bernie - *#* Add missing config options for gfx and kbd. - *#* - *#* Revision 1.4 2006/01/23 23:12:27 bernie - *#* Enable CONFIG_GFX_VCOORDS. - *#* - *#* Revision 1.3 2006/01/17 02:30:06 bernie - *#* Add new config vars. - *#* - *#* Revision 1.2 2005/11/27 03:04:57 bernie - *#* CONFIG_WATCHDOG: New config option. - *#* - *#* Revision 1.1 2005/11/04 17:42:12 bernie - *#* Move cfg/config.h to appconfig.h. - *#*/ - -#ifndef APPCONFIG_H -#define APPCONFIG_H - -/** Baud-rate for the kdebug console */ -#define CONFIG_KDEBUG_BAUDRATE 19200 - -/** - * printf()-style formatter configuration. - * - * \sa PRINTF_DISABLED - * \sa PRINTF_NOMODIFIERS - * \sa PRINTF_REDUCED - * \sa PRINTF_NOFLOAT - * \sa PRINTF_FULL - */ -#define CONFIG_PRINTF PRINTF_FULL - -/** - * Multithreading kernel. - * - * \sa config_kern.h - */ -#define CONFIG_KERN 0 - -/** - * \name Serial driver parameters - * \{ - */ - /** [bytes] Size of the outbound FIFO buffer for port 0. */ - #define CONFIG_UART0_TXBUFSIZE 32 - - /** [bytes] Size of the inbound FIFO buffer for port 0. */ - #define CONFIG_UART0_RXBUFSIZE 64 - - /** [bytes] Size of the outbound FIFO buffer for port 1. */ - #define CONFIG_UART1_TXBUFSIZE 32 - - /** [bytes] Size of the inbound FIFO buffer for port 1. */ - #define CONFIG_UART1_RXBUFSIZE 64 - - /** [bytes] Size of the outbound FIFO buffer for SPI port (AVR only). */ - #define CONFIG_SPI_TXBUFSIZE 16 - - /** [bytes] Size of the inbound FIFO buffer for SPI port (AVR only). */ - #define CONFIG_SPI_RXBUFSIZE 32 - - /** SPI data order (AVR only). */ - #define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST - - /** SPI clock division factor (AVR only). */ - #define CONFIG_SPI_CLOCK_DIV 16 - - /** SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). */ - #define CONFIG_SPI_CLOCK_POL 0 - - /** SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). */ - #define CONFIG_SPI_CLOCK_PHASE 0 - - /** Default transmit timeout (ms). Set to -1 to disable timeout support */ - #define CONFIG_SER_TXTIMEOUT -1 - - /** Default receive timeout (ms). Set to -1 to disable timeout support */ - #define CONFIG_SER_RXTIMEOUT -1 - - /** Use RTS/CTS handshake */ - #define CONFIG_SER_HWHANDSHAKE 0 - - /** Default baud rate (set to 0 to disable) */ - #define CONFIG_SER_DEFBAUDRATE 0 - - /** Enable ser_gets() and ser_gets_echo() */ - #define CONFIG_SER_GETS 0 - - /** Enable second serial port in emulator. */ - #define CONFIG_EMUL_UART1 0 - - /** - * Transmit always something on serial port 0 TX - * to avoid interference when sending burst of data, - * using AVR multiprocessor serial mode - */ - #define CONFIG_SER_TXFILL 0 - - #define CONFIG_SER_STROBE 0 -/*\}*/ - -/// Hardware timer selection for drv/timer.c -#define CONFIG_TIMER TIMER_ON_OUTPUT_COMPARE2 - -/// Debug timer interrupt using a strobe pin. -#define CONFIG_TIMER_STROBE 0 - -/// Enable ADS strobe. -#define CONFIG_ADC_STROBE 0 - -/// Enable watchdog timer. -#define CONFIG_WATCHDOG 0 - -/// EEPROM type for drv/eeprom.c -#define CONFIG_EEPROM_TYPE EEPROM_24XX256 - -/// Select bitmap pixel format. -#define CONFIG_BITMAP_FMT BITMAP_FMT_PLANAR_V_LSB - -/// Enable line clipping algorithm. -#define CONFIG_GFX_CLIPPING 1 - -/// Enable text rendering in bitmaps. -#define CONFIG_GFX_TEXT 1 - -/// Enable virtual coordinate system. -#define CONFIG_GFX_VCOORDS 1 - -/// Keyboard polling method -#define CONFIG_KBD_POLL KBD_POLL_SOFTINT - -/// Enable keyboard event delivery to observers -#define CONFIG_KBD_OBSERVER 0 - -/// Enable key beeps -#define CONFIG_KBD_BEEP 1 - -/// Enable long pression handler for keys -#define CONFIG_KBD_LONGPRESS 1 - -/** - * \name Type for the chart dataset - * \{ - */ -#define CONFIG_CHART_TYPE_X uint8_t -#define CONFIG_CHART_TYPE_Y uint8_t -/*\}*/ - -/// Enable button bar behind menus -#define CONFIG_MENU_MENUBAR 0 - -/// Enable smooth scrolling in menus -#define CONFIG_MENU_SMOOTH 1 - -/// Size of block for MD2 algorithm. -#define CONFIG_MD2_BLOCK_LEN 16 - -/// Use standard permutation in MD2 algorithm. -#define CONFIG_MD2_STD_PERM 0 - -/// Define a size, in byte, of entropy pool. -#define CONFIG_SIZE_ENTROPY_POOL 256 - -/// Turn on or off timer support in Randpool. -#define CONFIG_RANDPOOL_TIMER 1 - -#endif /* APPCONFIG_H */ diff --git a/app/randpool/randpool_demo.c b/app/randpool/randpool_demo.c deleted file mode 100644 index 3010cd10..00000000 --- a/app/randpool/randpool_demo.c +++ /dev/null @@ -1,251 +0,0 @@ -/** - * \file - * - * - * \brief Test function for randpool API. - * - * This program return a rand number generate from randpool function. - * For use randpool function you need a souce of entropy. In this - * program you can choose from: - * - /dev/random - * - /dev/urandom - * - /dev/input/mouse0 - * - * There are 3 mode of output: - * - binmode: program generate a sequenze of random byte. - * - Matrix of random number for octave program. - * - Vector of random number for octave program. - * - * \version $Id$ - * \author Daniele Basile - */ - -/*#* - *#* $Log$ - *#* Revision 1.1 2007/02/15 18:17:51 asterix - *#* Add randpool test program. - *#* - *#*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define LEN 256 //Size of buffer containing a random number. -#define SAMPLE 1000 //Defoult number of byte that put in entropy pool. - -int main (int argc, char *argv[]) -{ - EntropyPool pool; - uint8_t ch; - uint8_t buff[LEN]; - FILE *pdev; - int opt = getopt (argc, argv, "murh"); - int samp = SAMPLE; - int round = 10; - int mode = 0; - int pass = 0; - - timer_init(); - - randpool_init(&pool, NULL, 0); //Init a entropy pool. - - /* - * Chose a source of entropy. - */ - switch(opt) - { - case 'm': - { - pdev = fopen("/dev/input/mouse0", "r"); - break; - } - case 'u': - { - pdev = fopen("/dev/urandom", "r"); - break; - } - case 'r': - { - pdev = fopen("/dev/random", "r"); - break; - } - case 'h': - { - } - default: - { - printf("\n"); - printf("\n"); - printf("randpool_demo [OPTION] [SAMPLE] [ROUND] [MODE]\n"); - printf("\n"); - printf("OPTION:\n"); - printf(" -r /dev/random\n"); - printf(" -u /dev/urandom\n"); - printf(" -m /dev/input/mouse0\n"); - printf("\n"); - printf("SAMPLE:\n"); - printf(" num number of entropy byte to put in etropy pool.\n"); - printf("\n"); - printf("ROUND:\n"); - printf(" num number call of randpool_get function.\n"); - printf("\n"); - printf("MODE:\n"); - printf(" 0 binmode\n"); - printf(" 1 vector mode\n"); - printf(" 2 matrix mode\n"); - printf("\n"); - printf("Test program of randpool API.\n"); - printf("This program create an entropy pool of 256byte, and fill it\n"); - printf("with entropy from a exsternal source. This source can be:\n"); - printf(" - /dev/random (option: -r)\n"); - printf(" - /dev/urandom (option: -u)\n"); - printf(" - /dev/input/mouse0 (option: -m)\n"); - printf("\n"); - printf("Once the pool is full, program call a randpool_get ROUND time,\n"); - printf("printing on STDOUT random value, in accord with a select mode.\n"); - printf("The mode are:\n"); - printf(" - binmode: program print on STDOUT random byte. (option: 0 (defaul mode)\n"); - printf(" - vector mode: program print on STDOUT a ROUND vector of random value.\n"); - printf(" The output is format for octave program. (option: 1)\n"); - printf(" - matrix mode: program print on STDOUT a matrix of random value.\n"); - printf(" The output is format for octave program. (option: 2)\n"); - printf("\n"); - exit(1); - } - - } - - /* - * - */ - if(argc > 2) - { - if(argv[2]) - samp = atoi(argv[2]); //Number of byte take from entropy source - if(argv[3]) - round = atoi(argv[3]); //Number of time we call randpool_get. - if(argv[4]) - { - switch(atoi(argv[4])) - { - case 1: - { - mode = 1; - printf("# Created by Asterix.\n"); - printf("# name: __nargin__\n"); - printf("# type: scalar\n"); - printf("0\n"); - break; - } - case 2: - { - mode = 2; - printf("# Created by Asterix.\n"); - printf("# name: __nargin__\n"); - printf("# type: scalar\n"); - printf("0\n"); - break; - } - default: - { - break; - } - - } - - } - - } - - /* - * Add byte to entropy pool from a source of entropy. - */ - for(int i = 0; i < samp; i++) - { - - ch = fgetc(pdev); - randpool_add(&pool, &ch, sizeof(ch)); - - } - - fclose(pdev); - - - for(int k = 0; k < round; k++) - { - switch(mode) - { - case 1: - { - printf("\n"); - printf("\n# name: vet%d",k); - printf("\n# type: matrix"); - printf("\n# rows: 1"); - printf("\n# columns: %d\n", LEN); - pass = 1; - break; - } - case 2: - { - printf("\n"); - printf("\n# name: randMatrix"); - printf("\n# type: matrix"); - printf("\n# rows: %d",round); - printf("\n# columns: %d\n", LEN); - pass = 1; - mode = 0; - break; - } - } - - randpool_get(&pool, buff, LEN); - - if(pass) - { - for(int j = 0; j < LEN; j++) - { - printf("%d ", buff[j]); - } - printf("\n"); - } - else - fwrite(buff, sizeof(uint8_t), LEN, stdout); - } - - -} - diff --git a/app/randpool/randpool_demo.mk b/app/randpool/randpool_demo.mk deleted file mode 100644 index 11d947e6..00000000 --- a/app/randpool/randpool_demo.mk +++ /dev/null @@ -1,37 +0,0 @@ -# -# $Id$ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib randpool_demo application. -# -# Author: Daniele Basile -# -# $Log$ -# Revision 1.1 2007/02/15 18:17:51 asterix -# Add randpool test program. -# -# - - -# Set to 1 for debug builds -randpool_demo_DEBUG = 0 - -# Our target application -TRG += randpool_demo - -randpool_demo_CSRC = \ - app/randpool/randpool_demo.c \ - algos/randpool.c \ - algos/md2.c \ - drv/timer.c \ - os/hptime.c - -randpool_demo_CFLAGS = -O0 -D'ARCH=0' -Iapp/randpool/ -Iapp/randpool/hw - -# Debug stuff -ifeq ($(randpool_demo_DEBUG),1) - randpool_demo_CFLAGS += -D_DEBUG - randpool_demo_PCSRC += drv/kdebug.c -endif - diff --git a/app/test/armtest.mk b/app/test/armtest.mk deleted file mode 100644 index 4a36082b..00000000 --- a/app/test/armtest.mk +++ /dev/null @@ -1,32 +0,0 @@ -# -# $Id: armtest.mk 18234 2007-10-08 13:39:48Z rasky $ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib armtest application. -# -# Author: Bernie Innocenti -# -# - -# Set to 1 for debug builds -armtest_DEBUG = 1 - -# Our target application -TRG += armtest - -#include arm c and asm sources -include ./app/test/arm_src.mk - -armtest_CSRC = $(arm_CSRC) app/test/empty_main.c - -armtest_CPPASRC = $(arm_ASRC) - -armtest_CROSS = arm-elf- - -armtest_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug -armtest_CPPFLAGS = -O0 -D'ARCH=ARCH_NIGHTTEST' -D__ARM_AT91SAM7S256__ -g3 -gdwarf-2 -fverbose-asm -Iapp/test -Ibertos/cpu/arm -armtest_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_rom.ld -Wl,--no-warn-mismatch - -armtest_CPU = arm7tdmi - diff --git a/app/test/avrtest.mk b/app/test/avrtest.mk deleted file mode 100644 index a6ff97ff..00000000 --- a/app/test/avrtest.mk +++ /dev/null @@ -1,32 +0,0 @@ -# -# $Id: avrtest.mk,v 1.3 2006/06/12 21:37:02 marco Exp $ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib avrtest application. -# -# Author: Bernie Innocenti -# - - - -# Set to 1 for debug builds -avrtest_DEBUG = 1 - -# Our target application -TRG += avrtest - -avrtest_MCU = atmega64 - -#include avr c and asm sources -include app/test/avr_src.mk - -avrtest_CSRC = $(avr_CSRC) app/test/empty_main.c - -avrtest_CPPASRC = $(avr_ASRC) - -avrtest_PCSRC += bertos/mware/formatwr.c - -avrtest_CROSS = avr- -avrtest_CPPFLAGS = -D'ARCH=ARCH_NIGHTTEST' -Iapp/test -Ibertos/cpu/avr -avrtest_CFLAGS = -Os -mcall-prologues -fno-strict-aliasing diff --git a/app/test/empty_main.c b/app/test/empty_main.c deleted file mode 100644 index 66a8e4ad..00000000 --- a/app/test/empty_main.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * \file - * - * - * \brief Hardware-specific definitions - * - * \version $Id$ - * - * \author Daniele Basile - */ - -int main(void) -{ - for(;;) - { - } - - return 0; -} diff --git a/app/triface/boot/boot.ld b/app/triface/boot/boot.ld deleted file mode 100644 index 733f1e99..00000000 --- a/app/triface/boot/boot.ld +++ /dev/null @@ -1,170 +0,0 @@ -/* Linker script for boot loader */ - -OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") -OUTPUT_ARCH(avr:5) -MEMORY -{ - text (rx) : ORIGIN = 0xE000, LENGTH = 8K - data (rw!x) : ORIGIN = 0x800060, LENGTH = 4000 - eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 2K -} -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : - { - *(.rel.text) - *(.rel.text.*) - *(.rel.gnu.linkonce.t*) - } - .rela.text : - { - *(.rela.text) - *(.rela.text.*) - *(.rela.gnu.linkonce.t*) - } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : - { - *(.rel.rodata) - *(.rel.rodata.*) - *(.rel.gnu.linkonce.r*) - } - .rela.rodata : - { - *(.rela.rodata) - *(.rela.rodata.*) - *(.rela.gnu.linkonce.r*) - } - .rel.data : - { - *(.rel.data) - *(.rel.data.*) - *(.rel.gnu.linkonce.d*) - } - .rela.data : - { - *(.rela.data) - *(.rela.data.*) - *(.rela.gnu.linkonce.d*) - } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - /* Internal text space or external memory */ - .text : - { - KEEP(*(.vectors)) - __ctors_start = . ; - *(.ctors) - __ctors_end = . ; - __dtors_start = . ; - *(.dtors) - __dtors_end = . ; - *(.progmem.gcc*) - *(.progmem*) - . = ALIGN(2); - KEEP(*(.init0)) /* Start here after reset. */ - KEEP(*(.init1)) - KEEP(*(.init2)) /* Clear __zero_reg__, set up stack pointer. */ - KEEP(*(.init3)) - KEEP(*(.init4)) /* Initialize data and BSS. */ - KEEP(*(.init5)) - KEEP(*(.init6)) /* C++ constructors. */ - KEEP(*(.init7)) - KEEP(*(.init8)) - KEEP(*(.init9)) /* Call main(). */ - *(.text) - . = ALIGN(2); - *(.text.*) - . = ALIGN(2); - *(.fini9) /* _exit() starts here. */ - *(.fini8) - *(.fini7) - *(.fini6) /* C++ destructors. */ - *(.fini5) - *(.fini4) - *(.fini3) - *(.fini2) - *(.fini1) - *(.fini0) /* Infinite loop after program termination. */ - _etext = . ; - } > text - .data : AT (ADDR (.text) + SIZEOF (.text)) - { - PROVIDE (__data_start = .) ; - *(.data .data.* .rodata .rodata.*) - *(.gnu.linkonce.d*) - . = ALIGN(2); - _edata = . ; - PROVIDE (__data_end = .) ; - } > data - .bss SIZEOF(.data) + ADDR(.data) : - { - PROVIDE (__bss_start = .) ; - *(.bss .bss.*) - *(COMMON) - PROVIDE (__bss_end = .) ; - } > data - __data_load_start = LOADADDR(.data); - __data_load_end = __data_load_start + SIZEOF(.data); - /* Global data not cleared after reset. */ - .noinit SIZEOF(.bss) + ADDR(.bss) : - { - PROVIDE (__noinit_start = .) ; - *(.noinit*) - PROVIDE (__noinit_end = .) ; - _end = . ; - PROVIDE (__heap_start = .) ; - } > data - .eeprom : - AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.data)) - { - *(.eeprom*) - __eeprom_end = . ; - } > eeprom - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } -} diff --git a/app/triface/boot/cfg/cfg_arch.h b/app/triface/boot/cfg/cfg_arch.h deleted file mode 100644 index 0956196a..00000000 --- a/app/triface/boot/cfg/cfg_arch.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * - * - * \brief Set system configuration - * - * \version $Id$ - * - * \author Bernie Innocenti - * - */ - - -#ifndef CFG_ARCH_CONFIG_H -#define CFG_ARCH_CONFIG_H - -#include - -/** - * \name Architectures - * \{ - */ -#define ARCH_TRIFACE BV(0) -#define ARCH_BOOT BV(1) -#define ARCH_EMUL BV(2) -/*\}*/ - -#endif /* CFG_ARCH_CONFIG_H */ diff --git a/app/triface/boot/cfg/cfg_boot.h b/app/triface/boot/cfg/cfg_boot.h deleted file mode 100644 index 72deb0c7..00000000 --- a/app/triface/boot/cfg/cfg_boot.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for boot module. - * - * \version $Id$ - * - * \author Manuele Fanelli - */ - -#ifndef CFG_BOOT_H -#define CFG_BOOT_H - -#define CONFIG_SER_HOSTPORT 1 ///< Triface comunication host port - -#define CONFIG_SER_HOSTPORTBAUDRATE 115200 ///< Serial host port baudrate - -#endif /* CFG_BOOT_H */ diff --git a/app/triface/boot/cfg/cfg_formatwr.h b/app/triface/boot/cfg/cfg_formatwr.h deleted file mode 100644 index 91c992ab..00000000 --- a/app/triface/boot/cfg/cfg_formatwr.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for formatted write module. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef CFG_FORMTWR_H -#define CFG_FORMTWR_H - -/** - * printf()-style formatter configuration. - * - * \sa PRINTF_DISABLED - * \sa PRINTF_NOMODIFIERS - * \sa PRINTF_REDUCED - * \sa PRINTF_NOFLOAT - * \sa PRINTF_FULL - */ -#define CONFIG_PRINTF PRINTF_REDUCED - - -#endif /* CFG_FORMTWR_H */ - diff --git a/app/triface/boot/cfg/cfg_kern.h b/app/triface/boot/cfg/cfg_kern.h deleted file mode 100644 index 78031e3e..00000000 --- a/app/triface/boot/cfg/cfg_kern.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * \file - * - * - * \brief Kernel configuration parameters - * - * \version $Id$ - * \author Bernie Innocenti - */ - -#ifndef CFG_KERN_H -#define CFG_KERN_H - -/** - * Enable the multithreading kernel. - */ -#define CONFIG_KERN 0 - -/** - * \name Optional kernel features - * \{ - */ -#define CONFIG_KERN_SCHED 0 ///< Process schedling -#define CONFIG_KERN_SIGNALS 0 ///< Inter-process signals -#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor -#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation -#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives -#define CONFIG_KERN_MONITOR 0 ///< Process monitor -#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling -#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy -/*\}*/ - -/// [ms] Time sharing quantum (a prime number prevents interference effects) -#define CONFIG_KERN_QUANTUM 47 - -/// Module logging level. -#define KERN_LOG_LEVEL LOG_LVL_ERR - -/// Module logging format. -#define KERN_LOG_FORMAT LOG_FMT_VERBOSE - -#endif /* CFG_KERN_H */ diff --git a/app/triface/boot/cfg/cfg_kfile.h b/app/triface/boot/cfg/cfg_kfile.h deleted file mode 100644 index e4f13b25..00000000 --- a/app/triface/boot/cfg/cfg_kfile.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for KFile interface module. - * - * \version $Id$ - * \author Daniele Basile - */ - -#ifndef CFG_KFILE_H -#define CFG_KFILE_H - -/// Module logging level definition. -#define KFILE_LOG_LEVEL LOG_LVL_INFO - -/// Module logging verbosity. -#define KFILE_LOG_FORMAT LOG_FMT_TERSE - -/// Enable the gets function with echo. -#define CONFIG_KFILE_GETS 1 - -#endif /* CFG_KFILE_H */ diff --git a/app/triface/boot/cfg/cfg_ser.h b/app/triface/boot/cfg/cfg_ser.h deleted file mode 100644 index eb11a4cb..00000000 --- a/app/triface/boot/cfg/cfg_ser.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for serial module. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef CFG_SER_H -#define CFG_SER_H - - -/// Kdebug console on debug unit -#define CONFIG_TRIFACE_PORT 0 - -/// Baud-rate for the kdebug console -#define CONFIG_TRIFACE_BAUDRATE 115200 - -/// [bytes] Size of the outbound FIFO buffer for port 0. -#define CONFIG_UART0_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for port 0. -#define CONFIG_UART0_RXBUFSIZE 64 - -/// [bytes] Size of the outbound FIFO buffer for port 1. -#define CONFIG_UART1_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for port 1. -#define CONFIG_UART1_RXBUFSIZE 64 - - -/// [bytes] Size of the outbound FIFO buffer for SPI port (AVR only) -#define CONFIG_SPI_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port (AVR only) -#define CONFIG_SPI_RXBUFSIZE 32 - -/// [bytes] Size of the outbound FIFO buffer for SPI port 0. -#define CONFIG_SPI0_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port 0. -#define CONFIG_SPI0_RXBUFSIZE 32 - -/// [bytes] Size of the outbound FIFO buffer for SPI port 1. -#define CONFIG_SPI1_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port 1. -#define CONFIG_SPI1_RXBUFSIZE 32 - -/// SPI data order (AVR only). -#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST - -/// SPI clock division factor (AVR only). -#define CONFIG_SPI_CLOCK_DIV 16 - -/// SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). -#define CONFIG_SPI_CLOCK_POL 0 - -/// SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). -#define CONFIG_SPI_CLOCK_PHASE 0 - -/// Default transmit timeout (ms). Set to -1 to disable timeout support. -#define CONFIG_SER_TXTIMEOUT 100 - -/// Default receive timeout (ms). Set to -1 to disable timeout support. -#define CONFIG_SER_RXTIMEOUT 100 - -/// Use RTS/CTS handshake -#define CONFIG_SER_HWHANDSHAKE 0 - -/// Default baud rate (set to 0 to disable). -#define CONFIG_SER_DEFBAUDRATE 0 - -/// Enable second serial port in emulator. -#define CONFIG_EMUL_UART1 0 - -/** - * Transmit always something on serial port 0 TX - * to avoid interference when sending burst of data, - * using AVR multiprocessor serial mode - */ -#define CONFIG_SER_TXFILL 0 - -/// For serial debug. -#define CONFIG_SER_STROBE 0 - -#endif /* CFG_SER_H */ diff --git a/app/triface/boot/hw/hw_boot.h b/app/triface/boot/hw/hw_boot.h deleted file mode 100644 index fa9bff4a..00000000 --- a/app/triface/boot/hw/hw_boot.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * \file - * - * - * \brief Macro for boot loader. - * - * - * \version $Id$ - * - * \author Daniele Basile - * \author Francesco Sacchi - */ - -#ifndef HW_BOOT_H -#define HW_BOOT_H - -#include - -/* Set up function pointer to RESET vector */ -void (*rom_start)(void) NORETURN = 0x0000; - -#define START_APP() rom_start() - -#define BOOT_INIT do \ -{ \ - /* Enable change of Interrupt Vectors */ \ - MCUCR = BV(IVCE); \ - /* Move interrupts to boot Flash section */ \ - MCUCR = BV(IVSEL); \ -} while(0) - -#define BOOT_END do \ -{ \ - /* Enable change of Interrupt Vectors */ \ - MCUCR = BV(IVCE); \ - /* Move interrupts to boot Flash section */ \ - MCUCR = 0; \ -} while(0) - -#endif // HW_BOOT_H - diff --git a/app/triface/boot/hw/hw_cpu.h b/app/triface/boot/hw/hw_cpu.h deleted file mode 100644 index 840c82c3..00000000 --- a/app/triface/boot/hw/hw_cpu.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * Rights Reserved. - * - * \brief Hardware-specific definitions - * - * \version $Id$ - * - * \author Bernie Innocenti - */ - -#ifndef TRIFACE_HW_H -#define TRIFACE_HW_H - -/// CPU Clock frequency (14.7456 MHz) -#define CLOCK_FREQ (14745600UL) - - -/* Timer IRQ strobe */ -//#if CONFIG_TIMER_STROBE -// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) -// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) -// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) -//#endif /* CONFIG_TIMER_STROBE */ - -#endif /* TRIFACE_HW_H */ - diff --git a/app/triface/boot/hw/hw_ser.h b/app/triface/boot/hw/hw_ser.h deleted file mode 100644 index 21451b6c..00000000 --- a/app/triface/boot/hw/hw_ser.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * \file - * - * - * \brief Serial hardware-specific definitions - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef HW_SER_H -#define HW_SER_H - - - -#endif /* HW_SER_H */ diff --git a/app/triface/boot/main.c b/app/triface/boot/main.c deleted file mode 100644 index dc105baf..00000000 --- a/app/triface/boot/main.c +++ /dev/null @@ -1,97 +0,0 @@ -/** - * \file - * - * - * \brief Flash boot loader main. - * This is a simple generic bootloader app. - * It requires only a serial port to work. - * Try to receive a file through XMODEM protocol - * and flash it on program memory. - * BOOT_INIT, BOOT_END are macros used to perform special operations - * respectively at boot start and boot end and are CPU dependant. - * The macro START_APP() jumps to main application start. - * - * \version $Id$ - * \author Stefano Fedrigo - * \author Francesco Sacchi - * \author Daniele Basile - */ - -#include -#include -#include -#include /* BV() */ - -#include -#include -#include -#include - -#include "hw/hw_boot.h" -#include "cfg/cfg_boot.h" - -#include - -int main(void) -{ - FlashAvr flash; - Serial ser; - - - // Set up flash programming functions. - flash_avr_init(&flash); - - IRQ_ENABLE; - - BOOT_INIT; - - kdbg_init(); - timer_init(); - - - /* Open the main communication port */ - - ser_init(&ser, CONFIG_SER_HOSTPORT); - ser_setbaudrate(&ser, CONFIG_SER_HOSTPORTBAUDRATE); - - xmodem_recv(&ser, &flash.fd); - kfile_close(&flash.fd); - kfile_close(&ser.fd); - - IRQ_DISABLE; - - BOOT_END; - - START_APP(); - -} - diff --git a/app/triface/cfg/cfg_arch.h b/app/triface/cfg/cfg_arch.h deleted file mode 100644 index 0956196a..00000000 --- a/app/triface/cfg/cfg_arch.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * - * - * \brief Set system configuration - * - * \version $Id$ - * - * \author Bernie Innocenti - * - */ - - -#ifndef CFG_ARCH_CONFIG_H -#define CFG_ARCH_CONFIG_H - -#include - -/** - * \name Architectures - * \{ - */ -#define ARCH_TRIFACE BV(0) -#define ARCH_BOOT BV(1) -#define ARCH_EMUL BV(2) -/*\}*/ - -#endif /* CFG_ARCH_CONFIG_H */ diff --git a/app/triface/cfg/cfg_debug.h b/app/triface/cfg/cfg_debug.h deleted file mode 100644 index a7c548a9..00000000 --- a/app/triface/cfg/cfg_debug.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for Debug module. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef CFG_DEBUG_H -#define CFG_DEBUG_H - -/// kdebug console. -#define CONFIG_KDEBUG_PORT 1 - -/// Baud-rate for the kdebug console. -#define CONFIG_KDEBUG_BAUDRATE 115200 - -#endif /* CFG_DEBUG_H */ diff --git a/app/triface/cfg/cfg_kern.h b/app/triface/cfg/cfg_kern.h deleted file mode 100644 index 78031e3e..00000000 --- a/app/triface/cfg/cfg_kern.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * \file - * - * - * \brief Kernel configuration parameters - * - * \version $Id$ - * \author Bernie Innocenti - */ - -#ifndef CFG_KERN_H -#define CFG_KERN_H - -/** - * Enable the multithreading kernel. - */ -#define CONFIG_KERN 0 - -/** - * \name Optional kernel features - * \{ - */ -#define CONFIG_KERN_SCHED 0 ///< Process schedling -#define CONFIG_KERN_SIGNALS 0 ///< Inter-process signals -#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor -#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation -#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives -#define CONFIG_KERN_MONITOR 0 ///< Process monitor -#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling -#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy -/*\}*/ - -/// [ms] Time sharing quantum (a prime number prevents interference effects) -#define CONFIG_KERN_QUANTUM 47 - -/// Module logging level. -#define KERN_LOG_LEVEL LOG_LVL_ERR - -/// Module logging format. -#define KERN_LOG_FORMAT LOG_FMT_VERBOSE - -#endif /* CFG_KERN_H */ diff --git a/app/triface/cfg/cfg_kfile.h b/app/triface/cfg/cfg_kfile.h deleted file mode 100644 index 10bb72db..00000000 --- a/app/triface/cfg/cfg_kfile.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for KFile interface module. - * - * \version $Id$ - * \author Daniele Basile - */ - -#ifndef CFG_KFILE_H -#define CFG_KFILE_H - -/// Module logging level definition. -#define KFILE_LOG_LEVEL LOG_LVL_INFO - -/// Module logging format. -#define KFILE_LOG_FORMAT LOG_FMT_TERSE - -/// Enable the gets function with echo. -#define CONFIG_KFILE_GETS 1 - -#endif /* CFG_KFILE_H */ diff --git a/app/triface/cfg/cfg_ser.h b/app/triface/cfg/cfg_ser.h deleted file mode 100644 index c474c890..00000000 --- a/app/triface/cfg/cfg_ser.h +++ /dev/null @@ -1,122 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for serial module. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef CFG_SER_H -#define CFG_SER_H - - -/// Kdebug console on debug unit -#define CONFIG_TRIFACE_PORT 1 - -/// Baud-rate for the kdebug console -#define CONFIG_TRIFACE_BAUDRATE 115200 -/// Triface serial tag port -#define TAG_SER_PORT 0 -///Baud-rate for triface serial tag port -#define TAG_SER_BAUDRATE 9600 - -/// [bytes] Size of the outbound FIFO buffer for port 0. -#define CONFIG_UART0_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for port 0. -#define CONFIG_UART0_RXBUFSIZE 64 - -/// [bytes] Size of the outbound FIFO buffer for port 1. -#define CONFIG_UART1_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for port 1. -#define CONFIG_UART1_RXBUFSIZE 64 - - -/// [bytes] Size of the outbound FIFO buffer for SPI port (AVR only) -#define CONFIG_SPI_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port (AVR only) -#define CONFIG_SPI_RXBUFSIZE 32 - -/// [bytes] Size of the outbound FIFO buffer for SPI port 0. -#define CONFIG_SPI0_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port 0. -#define CONFIG_SPI0_RXBUFSIZE 32 - -/// [bytes] Size of the outbound FIFO buffer for SPI port 1. -#define CONFIG_SPI1_TXBUFSIZE 32 - -/// [bytes] Size of the inbound FIFO buffer for SPI port 1. -#define CONFIG_SPI1_RXBUFSIZE 32 - -/// SPI data order (AVR only). -#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST - -/// SPI clock division factor (AVR only). -#define CONFIG_SPI_CLOCK_DIV 16 - -/// SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). -#define CONFIG_SPI_CLOCK_POL 0 - -/// SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). -#define CONFIG_SPI_CLOCK_PHASE 0 - -/// Default transmit timeout (ms). Set to -1 for infinite timeout, 0 for null timeout -#define CONFIG_SER_TXTIMEOUT 0 - -/// Default receive timeout (ms). Set to -1 for infinite timeout, 0 for null timeout -#define CONFIG_SER_RXTIMEOUT 0 - -/// Use RTS/CTS handshake -#define CONFIG_SER_HWHANDSHAKE 0 - -/// Default baud rate (set to 0 to disable). -#define CONFIG_SER_DEFBAUDRATE 0 - -/// Enable second serial port in emulator. -#define CONFIG_EMUL_UART1 0 - -/** - * Transmit always something on serial port 0 TX - * to avoid interference when sending burst of data, - * using AVR multiprocessor serial mode - */ -#define CONFIG_SER_TXFILL 0 - -/// For serial debug. -#define CONFIG_SER_STROBE 0 - -#endif /* CFG_SER_H */ diff --git a/app/triface/cfg/cfg_wdt.h b/app/triface/cfg/cfg_wdt.h deleted file mode 100644 index 8404dbd2..00000000 --- a/app/triface/cfg/cfg_wdt.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * \file - * - * - * \brief Configuration file for watchdog module. - * - * \version $Id$ - * - * \author Daniele Basile - */ - -#ifndef CFG_WDT_H -#define CFG_WDT_H - -/// Enable watchdog timer. -#define CONFIG_WATCHDOG 1 - -#endif /* CFG_WDT_H */ - - diff --git a/app/triface/cmd_ctor.h b/app/triface/cmd_ctor.h deleted file mode 100644 index bf073f1e..00000000 --- a/app/triface/cmd_ctor.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * - * - * \brief Macro for defining command for protocol. - * - * - * \version $Id$ - * - * \author Marco Benelli - */ - -#ifndef CMD_CTOR_H -#define CMD_CTOR_H - -#include - -#define REGISTER_FUNCTION parser_register_cmd - -#define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) - -#define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \ -const struct CmdTemplate cmd_ ## NAME ## _template = \ -{ \ - #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \ -}; - -#define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \ -static ResultCode cmd_ ## NAME (parms *args) \ -{ \ - return (ResultCode)BODY; \ -} \ -MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) - -#endif // CMD_CTOR_H diff --git a/app/triface/doc/PROTOCOL b/app/triface/doc/PROTOCOL deleted file mode 100644 index defc38d5..00000000 --- a/app/triface/doc/PROTOCOL +++ /dev/null @@ -1,84 +0,0 @@ - -Command format: - - ... - -Where: - command - alphanumeric command name - argN - numeric argument (unsigned base 10, 0-65535) - -Positive response format: - - 0... - -Where: - argN - numeric value (unsigned base 10, 0-65535) - -Negative response format: - - -N"" - -Where: - -N - numeric error code (negative number) - desc - verbose error description - -# Write digital outputs (masked) -> dout 120 240 -< 0 - -# Read digital inputs -> din -< 0 125 - -# Read analog inputs -> ain -< 0 32 121 35 31 - -# Wait specified amount of milliseconds -> sleep 300 -< 0 - -# Return firmware major version, minor version and revision -> vers -< 0 1 42 0 - -# Reset board -< reset -> 0 - -# Ping/nop -< ping -> 0 - -# NOP (empty command) -> -< (ignored) - -# Comments -> # foo bar foobar -< (ignored) - -# Unknown command -> sing -< -1 "Unknown command" - -# Missing parameter -> dout -< -2 "Required parameter missing" - -# Too many parameters -> din 42 666 -< -3 "Too many parameters" - -# Malformed command -> dout %'I! -< -4 "Invalid parameter" - -# Attention -> or -< 1 "Uh?" - - -To recover from a possibly unknown board status, -a client should begin the conversation by issuing -an attention sequence, eventually followed by a reset. diff --git a/app/triface/doc/schematics/TRIFACE.DSN b/app/triface/doc/schematics/TRIFACE.DSN deleted file mode 100644 index d18fa84b..00000000 Binary files a/app/triface/doc/schematics/TRIFACE.DSN and /dev/null differ diff --git a/app/triface/doc/schematics/triface.opj b/app/triface/doc/schematics/triface.opj deleted file mode 100644 index 79f75bb3..00000000 --- a/app/triface/doc/schematics/triface.opj +++ /dev/null @@ -1,36 +0,0 @@ -(ExpressProject "triface" - (ProjectVersion "19981106") - (ProjectType "PCB") - (Folder "Design Resources" - (Folder "Library") - (NoModify) - (File ".\triface.dsn" - (Type "Schematic Design")) - (BuildFileAddedOrDeleted "x") - (CompileFileAddedOrDeleted "x") - (ANNOTATE_Scope "0") - (ANNOTATE_Mode "1") - (ANNOTATE_Action "0") - (Annotate_Page_Order "0") - (ANNOTATE_Reset_References_to_1 "FALSE") - (ANNOTATE_No_Page_Number_Change "FALSE") - (ANNOTATE_Property_Combine "{Value}{Source Package}{POWER_GROUP}") - (ANNOTATE_IncludeNonPrimitive "FALSE")) - (Folder "Outputs") - (Folder "Referenced Projects") - (PartMRUSelector) - (GlobalState - (FileView - (Path "Design Resources") - (Path "Design Resources" - "c:\documents and settings\administrator\desktop\new triface\triface.dsn") - (Path "Design Resources" - "c:\documents and settings\administrator\desktop\new triface\triface.dsn" - "TRIFACE BOARD")) - (HierarchyView) - (Doc - (Type "COrCapturePMDoc") - (Frame - (Placement "44 2 3 -1 -1 -4 -23 214 743 2 443")) - (Tab 0))) - (MPSSessionName "Administrator")) diff --git a/app/triface/hw/hw_adc.c b/app/triface/hw/hw_adc.c deleted file mode 100644 index 8c603eb8..00000000 --- a/app/triface/hw/hw_adc.c +++ /dev/null @@ -1,109 +0,0 @@ -/** - * \file - * - * - * \brief ADC: Analogic to Digital Converter - * - * - * \version $Id$ - * - * \author Andrea Grandi - */ - -#include "hw/hw_adc.h" - - -#include - -#include - -#include - -/** Set the active AI channel */ -void adc_set_active_ain(int ai) -{ - /* If number of channels is <= 4 we use the first two MUX bits */ - STATIC_ASSERT(ADC_CHANNEL_NUM <= 4); - - ai &= BV(0) | BV(1); - ADMUX &= ~BV(MUX0); - ADMUX &= ~BV(MUX1); - ADMUX |= ai; -} - -/** Initialize the ADC */ -void adc_init(void) -{ - /* Set analog IN as input */ - DDRF &= ~(BV(PF0) | BV(PF1) | BV(PF2) | BV(PF3)); - - /* Disable pull-up */ - PORTF &= ~(BV(PF0) | BV(PF1) | BV(PF2) | BV(PF3)); - - ENABLE_ADC; - adc_set_vref_avcc(); - SET_AI_ADLAR; - - /* Set the Division Factor to 128 */ - ADCSRA |= (BV(ADPS0) | BV(ADPS1) | BV(ADPS2)); -} - -/** Set the initial reference */ -void adc_set_vref_avcc(void) -{ - ADMUX &= ~BV(REFS1); - ADMUX |= BV(REFS0); -} - -/** Read the specified AI channel */ -int adc_read_ai_channel(int channel) -{ - adc_set_active_ain(channel); - timer_udelay(STABILIZING_AI_CHANNEL_TIME); - START_CONVERTION; - - while(ADCSRA & BV(ADSC)) - { - /* - * Intentionally empty loop. - * It waits the convertion to be completed by ADC - */ - } - - ADCSRA |= BV(ADIF); - - uint16_t val; - val = ADCL; - val |= (uint16_t)ADCH << 8; - - return val; -} diff --git a/app/triface/hw/hw_adc.h b/app/triface/hw/hw_adc.h deleted file mode 100644 index 817b190c..00000000 --- a/app/triface/hw/hw_adc.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * \file - * ght 2006 Develer S.r.l. (http://www.develer.com/) - * - * \brief Macro for HW_AIN_H - * - * - * \version $Id$ - * - * \author Andrea Grandi - */ - -#ifndef HW_ADC_H -#define HW_ADC_H - -#include - -#define START_CONVERTION (ADCSRA |= BV(ADSC)) -#define ENABLE_ADC (ADCSRA |= BV(ADEN)) -#define SET_AI_ADLAR (ADMUX &= ~BV(ADLAR)) - -/** Microseconds to wait before starting conversion after changing a channel */ -#define STABILIZING_AI_CHANNEL_TIME 125 - -/** Number of AIN channels */ -#define ADC_CHANNEL_NUM 4 - -void adc_set_active_ain(int ai); -void adc_init(void); -void adc_set_vref_avcc(void); -int adc_read_ai_channel(int channel); - -#endif // HW_ADC_H - diff --git a/app/triface/hw/hw_buzzer.h b/app/triface/hw/hw_buzzer.h deleted file mode 100644 index c3cc6d36..00000000 --- a/app/triface/hw/hw_buzzer.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * - * - * \brief Buzzer hardware-specific definitions - * - * \version $Id$ - * - * \author Francesco Sacchi - * Andrea Grandi - */ - -#ifndef HW_BUZZER_H -#define HW_BUZZER_H - -#include -#include - -#define BUZZER_BIT BV(PE3) -#define IS_BUZZER_ON (PORTE & BUZZER_BIT) -#define BUZZER_HW_INIT do { DDRE |= BV(DDE3); } while (0) -#define BUZZER_ON do { PORTE |= BUZZER_BIT; } while (0) -#define BUZZER_OFF do { PORTE &= ~BUZZER_BIT; } while (0) - -#endif /* HW_BUZZER_H */ - diff --git a/app/triface/hw/hw_cpu.h b/app/triface/hw/hw_cpu.h deleted file mode 100644 index 840c82c3..00000000 --- a/app/triface/hw/hw_cpu.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * \file - * Rights Reserved. - * - * \brief Hardware-specific definitions - * - * \version $Id$ - * - * \author Bernie Innocenti - */ - -#ifndef TRIFACE_HW_H -#define TRIFACE_HW_H - -/// CPU Clock frequency (14.7456 MHz) -#define CLOCK_FREQ (14745600UL) - - -/* Timer IRQ strobe */ -//#if CONFIG_TIMER_STROBE -// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) -// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) -// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) -//#endif /* CONFIG_TIMER_STROBE */ - -#endif /* TRIFACE_HW_H */ - diff --git a/app/triface/hw/hw_input.h b/app/triface/hw/hw_input.h deleted file mode 100644 index e3dcf1c4..00000000 --- a/app/triface/hw/hw_input.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \file - * - * - * \brief Macro for HW_INPUT_H - * - * - * \version $Id$ - * - * \author Andrea Grandi - */ - -#ifndef HW_INPUT_H -#define HW_INPUT_H - -#include - -/* Set pins as input and enable pull-up */ -#define INPUT_INIT_D do \ -{ \ - (DDRD &= ~(BV(PD4) | BV(PD5) | BV(PD6) | BV(PD7))); \ - (PORTD |= (BV(PD4) | BV(PD5) | BV(PD6) | BV(PD7))); \ -} while(0) - -#define INPUT_INIT_E do \ -{ \ - (DDRE &= ~(BV(PE4) | BV(PE5) | BV(PE6) | BV(PE7))); \ - ATOMIC((PORTE |= (BV(PE4) | BV(PE5) | BV(PE6) | BV(PE7)))); \ -} while(0) - -#define INPUT_INIT do { INPUT_INIT_D; INPUT_INIT_E;} while(0) - -INLINE uint8_t INPUT_GET(void) -{ - uint8_t out_d, out_e; - out_d = PIND; - out_e = PINE; - - out_d >>= 4; - out_e = out_e & 0xF0; - - return out_e | out_d; -} - -#endif // HW_INPUT_H diff --git a/app/triface/hw/hw_ser.h b/app/triface/hw/hw_ser.h deleted file mode 100644 index e51824d5..00000000 --- a/app/triface/hw/hw_ser.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * \file - * - * - * \brief Macro for STROBE signal - * - * \version $Id$ - * - * \author Manuele Fanelli - */ - -#ifndef HW_SER_H -#define HW_SER_H - -#include "cfg/cfg_ser.h" - -#if CONFIG_SER_STROBE - - #define SER_STROBE_ON do {PORTC |= BV(0);} while(0) - #define SER_STROBE_OFF do {PORTC &= ~BV(0);} while(0) - #define SER_STROBE_INIT do {DDRC |= BV(0); } while(0) -#endif - -#endif //HW_SER_H diff --git a/app/triface/hw/hw_sipo.h b/app/triface/hw/hw_sipo.h deleted file mode 100644 index f41e35f9..00000000 --- a/app/triface/hw/hw_sipo.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \file - * - * - * \brief Macro for HW_SIPO_H - * - * - * \version $Id$ - * - * \author Andrea Grandi - */ -#ifndef HW_SIPO_H -#define HW_SIPO_H - -#define LOAD_HIGH (PORTB |= BV(PB3)) -#define LOAD_LOW (PORTB &= ~BV(PB3)) -#define LOAD_INIT (DDRB |= BV(PB3)) -#define SET_SCK_OUT (DDRB |= BV(PB1)) -#define SET_SOUT_OUT (DDRB |= BV(PB2)) -#define CLOCK_HIGH (PORTB |= BV(PB1)) -#define CLOCK_LOW (PORTB &= ~BV(PB1)) -#define SET_SOUT_HIGH (PORTB |= BV(PB2)) -#define SET_SOUT_LOW (PORTB &= ~BV(PB2)) -#define CLOCK_PULSE do { CLOCK_HIGH; CLOCK_LOW; } while(0) - -#define OE_OUT (DDRG |= BV(PG3)) -#define OE_LOW (PORTG &= BV(PG3)) - - -#endif // HW_SIPO_H diff --git a/app/triface/protocol.c b/app/triface/protocol.c deleted file mode 100644 index fa4c0bad..00000000 --- a/app/triface/protocol.c +++ /dev/null @@ -1,374 +0,0 @@ -/** - * \file - * - * - * \brief Implementation of the command protocol between the board and the host - * - * - * \version $Id$ - * - * \author Giovanni Bajo - * \author Marco Benelli - * \author Bernie Innocenti - * \author Daniele Basile - */ - -#include "protocol.h" -#include "cmd_ctor.h" // MAKE_CMD, REGISTER_CMD -#include "verstag.h" -#include "hw/hw_adc.h" -#include "hw/hw_input.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#include -#include - -// Define the format string for ADC -#define ADC_FORMAT_STR "dddd" - -// DEBUG: set to 1 to force interactive mode -#define FORCE_INTERACTIVE 1 - -/** - * True if we are in interactive mode, false if we are in protocol mode. - * In interactive mode, commands are read through readline() (prompt, - * completion, history) without IDs, and replies/errors are sent to the serial - * output. - * In protocol mode, we implement the default protocol - */ -static bool interactive; - -/// Readline context, used for interactive mode. -static struct RLContext rl_ctx; - -uint8_t reg_status_dout; -/** - * Send a NAK asking the host to send the current message again. - * - * \a fd kfile handler for serial. - * \a err human-readable description of the error for debug purposes. - */ -INLINE void NAK(KFile *fd, const char *err) -{ -#ifdef _DEBUG - kfile_printf(fd, "NAK \"%s\"\r\n", err); -#else - kfile_printf(fd, "NAK\r\n"); -#endif -} - -static void protocol_prompt(KFile *fd) -{ - kfile_print(fd, ">> "); -} - -/* - * Print args on s, with format specified in t->result_fmt. - * Return number of valid arguments or -1 in case of error. - */ -static bool protocol_reply(KFile *fd, const struct CmdTemplate *t, - const parms *args) -{ - unsigned short offset = strlen(t->arg_fmt) + 1; - unsigned short nres = strlen(t->result_fmt); - - for (unsigned short i = 0; i < nres; ++i) - { - if (t->result_fmt[i] == 'd') - { - kfile_printf(fd, " %ld", args[offset+i].l); - } - else if (t->result_fmt[i] == 's') - { - kfile_printf(fd, " %s", args[offset+i].s); - } - - else - { - abort(); - } - } - kfile_printf(fd, "\r\n"); - return true; -} - -static void protocol_parse(KFile *fd, const char *buf) -{ - const struct CmdTemplate *templ; - - /* Command check. */ - templ = parser_get_cmd_template(buf); - if (!templ) - { - kfile_print(fd, "-1 Invalid command.\r\n"); - protocol_prompt(fd); - return; - } - - parms args[PARSER_MAX_ARGS]; - - /* Args Check. TODO: Handle different case. see doc/PROTOCOL . */ - if (!parser_get_cmd_arguments(buf, templ, args)) - { - kfile_print(fd, "-2 Invalid arguments.\r\n"); - protocol_prompt(fd); - return; - } - - /* Execute. */ - if(!parser_execute_cmd(templ, args)) - { - NAK(fd, "Error in executing command."); - } - if (!protocol_reply(fd, templ, args)) - { - NAK(fd, "Invalid return format."); - } - - protocol_prompt(fd); - return; -} - -void protocol_run(KFile *fd) -{ - /** - * \todo to be removed, we could probably access the serial FIFO - * directly - */ - static char linebuf[80]; - - if (!interactive) - { - kfile_gets(fd, linebuf, sizeof(linebuf)); - - // reset serial port error anyway - kfile_clearerr(fd); - - // check message minimum length - if (linebuf[0]) - { - /* If we enter lines beginning with sharp(#) - they are stripped out from commands */ - if(linebuf[0] != '#') - { - if (linebuf[0] == 0x1B && linebuf[1] == 0x1B) // ESC - { - interactive = true; - kfile_printf(fd, "Entering interactive mode\r\n"); - } - else - { - protocol_parse(fd, linebuf); - } - } - } - } - else - { - const char *buf; - - /* - * Read a line from serial. We use a temporary buffer - * because otherwise we would have to extract a message - * from the port immediately: there might not be any - * available, and one might get free while we read - * the line. We also add a fake ID at the start to - * fool the parser. - */ - buf = rl_readline(&rl_ctx); - - /* If we enter lines beginning with sharp(#) - they are stripped out from commands */ - if(buf && buf[0] != '#') - { - if (buf[0] != '\0') - { - // exit special case to immediately change serial input - if (!strcmp(buf, "exit") || !strcmp(buf, "quit")) - { - rl_clear_history(&rl_ctx); - kfile_printf(fd, "Leaving interactive mode...\r\n"); - interactive = FORCE_INTERACTIVE; - } - else - { - //TODO: remove sequence numbers - linebuf[0] = '0'; - linebuf[1] = ' '; - - strncpy(linebuf + 2, buf, sizeof(linebuf) - 3); - linebuf[sizeof(linebuf) - 1] = '\0'; - protocol_parse(fd, linebuf); - } - } - } - } -} - -/* - * Commands. - * TODO: Command declarations and definitions should be in another file(s). - * Maybe we should use CMD_HUNK_TEMPLATE. - * - */ - -MAKE_CMD(ver, "", "ddd", -({ - args[1].l = VERS_MAJOR; - args[2].l = VERS_MINOR; - args[3].l = VERS_REV; - 0; -}), 0); - -/* Sleep. Example of declaring function body directly in macro call. */ -MAKE_CMD(sleep, "d", "", -({ - timer_delay((mtime_t)args[1].l); - 0; -}), 0) - -/* Ping. */ -MAKE_CMD(ping, "", "", -({ - //Silence "args not used" warning. - (void)args; - 0; -}), 0) - -/* Dout */ -MAKE_CMD(dout, "d", "", -({ - sipo_putchar((uint8_t)args[1].l); - - //Store status of dout ports. - reg_status_dout = (uint8_t)args[1].l; - 0; -}), 0) - -/* rdout read the status of out ports.*/ -MAKE_CMD(rdout, "", "d", -({ - args[1].l = reg_status_dout; - 0; -}), 0) - - -/* Reset */ -MAKE_CMD(reset, "", "", -({ - //Silence "args not used" warning. - (void)args; - wdt_init(7); - wdt_start(); - - /*We want to have an infinite loop that lock access on watchdog timer. - This piece of code it's equivalent to a while(true), but we have done this because - gcc generate a warning message that suggest to use "noreturn" parameter in function reset.*/ - ASSERT(args); - while(args); - 0; - -}), 0) - -/* Din */ -MAKE_CMD(din, "", "d", -({ - args[1].l = INPUT_GET(); - 0; -}), 0) - - - -/* Ain */ -MAKE_CMD(ain, "", ADC_FORMAT_STR, -({ - STATIC_ASSERT((sizeof(ADC_FORMAT_STR) - 1) == ADC_CHANNEL_NUM); - for(int i = 0; i < ADC_CHANNEL_NUM; i++) - args[i+1].l = adc_read_ai_channel(i); - - 0; -}), 0) - -/* Beep */ -MAKE_CMD(beep, "d", "", -({ - buz_beep(args[1].l); - 0; -}), 0) - -/* Register commands. */ -static void protocol_registerCmds(void) -{ - REGISTER_CMD(ver); - REGISTER_CMD(sleep); - REGISTER_CMD(ping); - REGISTER_CMD(dout); - //Set off all dout ports. - reg_status_dout = 0; - REGISTER_CMD(rdout); - REGISTER_CMD(reset); - REGISTER_CMD(din); - REGISTER_CMD(ain); - REGISTER_CMD(beep); -} - -/* Initialization: readline context, parser and register commands. */ -void protocol_init(KFile *fd) -{ - interactive = FORCE_INTERACTIVE; - - rl_init_ctx(&rl_ctx); - //rl_setprompt(&rl_ctx, ">> "); - rl_sethook_get(&rl_ctx, (getc_hook)kfile_getc, fd); - rl_sethook_put(&rl_ctx, (putc_hook)kfile_putc, fd); - rl_sethook_match(&rl_ctx, parser_rl_match, NULL); - rl_sethook_clear(&rl_ctx, (clear_hook)kfile_clearerr,fd); - - parser_init(); - - protocol_registerCmds(); - - protocol_prompt(fd); -} diff --git a/app/triface/protocol.h b/app/triface/protocol.h deleted file mode 100644 index 26113482..00000000 --- a/app/triface/protocol.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * \file - * - * - * \brief Implementation of the command protocol between the board and the host - * - * \version $Id$ - * - * \author Marco Benelli - */ - - -#ifndef PROTOCOL_H -#define PROTOCOL_H - -#include - -void protocol_init(KFile *fd); -void protocol_run(KFile *fd); - -#endif // PROTOOCOL_H diff --git a/app/triface/triface.c b/app/triface/triface.c deleted file mode 100644 index 86f21b2d..00000000 --- a/app/triface/triface.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \author Marco Benelli - * \author Bernie Innocenti - * \author Daniele Basile - * - * \brief Windowing system test. - */ - - -#include "protocol.h" -#include "hw/hw_input.h" -#include "hw/hw_adc.h" -#include "cfg/cfg_ser.h" - -#include - -#include -#include -#include -#include - -#include -#include - - - -static Serial fd_ser; -static Serial tag_ser; - -int main(void) -{ - /* SPI Port Initialization */ - sipo_init(); - - kdbg_init(); - timer_init(); - adc_init(); - buz_init(); - - IRQ_ENABLE; - INPUT_INIT; - - /* Initialize Tag serial port and data structure */ - TagPacket pkt; - - /* Open the main communication port */ - ser_init(&fd_ser, CONFIG_TRIFACE_PORT); - ser_setbaudrate(&fd_ser, CONFIG_TRIFACE_BAUDRATE); - - ser_init(&tag_ser, TAG_SER_PORT); - ser_setbaudrate(&tag_ser, TAG_SER_BAUDRATE); - - keytag_init(&pkt, &fd_ser.fd, &tag_ser.fd); - - protocol_init(&fd_ser.fd); - - // Main loop - for(;;) - { - protocol_run(&fd_ser.fd); - keytag_poll(&pkt); - } - - return 0; -} - - diff --git a/app/triface/triface.mk b/app/triface/triface.mk deleted file mode 100644 index f208dfa3..00000000 --- a/app/triface/triface.mk +++ /dev/null @@ -1,72 +0,0 @@ -# -# $Id$ -# Copyright 2006 Develer S.r.l. (http://www.develer.com/) -# All rights reserved. -# -# Makefile fragment for DevLib triface application. -# -# Author: Bernie Innocenti -# -# - -# Set to 1 for debug builds -triface_DEBUG = 1 - -# Our target application -TRG += triface - -triface_hfuse = 0x88 -triface_lfuse = 0xff -triface_efuse = 0xff -triface_lock = 0x2f -triface_CSRC = \ - app/triface/triface.c \ - app/triface/protocol.c \ - app/triface/hw/hw_adc.c \ - bertos/drv/timer.c \ - bertos/drv/ser.c \ - bertos/drv/buzzer.c \ - bertos/cpu/avr/drv/ser_avr.c \ - bertos/cpu/avr/drv/sipo.c \ - bertos/mware/formatwr.c \ - bertos/mware/hex.c \ - bertos/struct/hashtable.c \ - bertos/mware/readline.c \ - bertos/mware/parser.c \ - bertos/mware/event.c \ - bertos/kern/kfile.c \ - bertos/net/keytag.c \ - # - -triface_PCSRC += bertos/mware/formatwr.c - - -triface_CFLAGS = -O2 -D'ARCH=(ARCH_TRIFACE)' -fno-strict-aliasing -Iapp/triface -Ibertos/cpu/avr -triface_LDFLAGS = -Wl - -triface_MCU = atmega64 -triface_CROSS = avr- - -# Set to 1 for debug builds -boot_DEBUG = 0 - -# Our target application -TRG += boot - -boot_MCU = atmega64 -boot_CSRC = \ - app/triface/boot/main.c \ - bertos/net/xmodem.c \ - bertos/drv/ser.c \ - bertos/cpu/avr/drv/ser_avr.c \ - bertos/cpu/avr/drv/flash_avr.c \ - bertos/drv/timer.c \ - bertos/algo/crc.c \ - bertos/mware/hex.c \ - bertos/kern/kfile.c \ - # -boot_CROSS = avr- -boot_CPPFLAGS = -D'ARCH=(ARCH_TRIFACE|ARCH_BOOT)' -Iapp/triface/boot -Ibertos/cpu/avr -boot_CFLAGS = -Os -mcall-prologues -boot_LDSCRIPT = app/triface/boot/boot.ld -boot_LDFLAGS = -Wl,--relax diff --git a/app/triface/verstag.h b/app/triface/verstag.h deleted file mode 100644 index cbe71278..00000000 --- a/app/triface/verstag.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * \file - * - * - * \version $Id$ - * - * \author Bernie Innocenti - * - * \brief Declare application version strings - */ - -#ifndef BERTOS_VERSTAG_H -#define BERTOS_VERSTAG_H - -#ifndef CFG_ARCH_CONFIG_H - #include "cfg/cfg_arch.h" -#endif - -#define APP_NAME "Triface" -#define APP_DESCRIPTION "Trinity Interface Board" -#define APP_AUTHOR "Develer" -#define APP_COPYRIGHT "Copyright 2006, 2007, 2008, Develer (http://www.develer.com/)" - -#define VERS_MAJOR 2 -#define VERS_MINOR 1 -#define VERS_REV 0 -#define VERS_LETTER "" - -/** - * If _SNAPSHOT is defined, \c VERS_TAG contains the build date - * date instead of a numeric version string. - */ -//#define _SNAPSHOT - -#ifdef _DEBUG - #define VERS_DBG "D" -#else - #define VERS_DBG "" -#endif - -#define __STRINGIZE(x) #x -#define _STRINGIZE(x) __STRINGIZE(x) - -/** Build application version string (i.e.: "1.7.0") */ -#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG -#ifdef _SNAPSHOT - #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG -#else - #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) -#endif - -/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ -#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) -#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) - -/** The revision string (contains VERS_TAG) */ -extern const char vers_tag[]; - -/** Sequential build number (contains VERS_BUILD) */ -extern const int vers_build_nr; -//extern const char vers_build_str[]; - -/** Hostname of the machine used to build this binary (contains VERS_HOST) */ -extern const char vers_host[]; - -#endif /* BERTOS_VERSTAG_H */ diff --git a/examples/at91sam7s/at91sam7s.c b/examples/at91sam7s/at91sam7s.c new file mode 100644 index 00000000..275af6e5 --- /dev/null +++ b/examples/at91sam7s/at91sam7s.c @@ -0,0 +1,116 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Francesco Sacchi + * + * \brief AT91SAM7S-EK porting test. + */ + +#include +#include +#include +#include +#include +#include +#include + +Timer leds_timer; +Serial ser_fd; + +static void leds_toggle(void) +{ + uint8_t a = (~PIOA_ODSR & 0x0f); + + if (a) + { + PIOA_SODR = a; + PIOA_CODR = a << 1; + } + else + { + PIOA_SODR = 0x0f; + /* turn first led on */ + PIOA_CODR = 0x00000001; + } + + /* Wait for interval time */ + timer_setDelay(&leds_timer, ms_to_ticks(100)); + timer_add(&leds_timer); +} + + +int main(void) +{ + char msg[]="BeRTOS, be fast be beatiful be realtime"; + kdbg_init(); + timer_init(); + + proc_init(); + ASSERT(!IRQ_ENABLED()); + + /* Open the main communication port */ + ser_init(&ser_fd, 0); + ser_setbaudrate(&ser_fd, 115200); + ser_setparity(&ser_fd, SER_PARITY_NONE); + + + IRQ_ENABLE; + ASSERT(IRQ_ENABLED()); + + /* Disable all pullups */ + PIOA_PUDR = 0xffffffff; + /* Set PA0..3 connected to PIOA */ + PIOA_PER = 0x0000001f; + /* Set PA0..3 as output */ + PIOA_OER = 0x0000001f; + /* Disable multidrive on all pins */ + PIOA_MDDR = 0x0000001f; + + /* Set PA0..3 to 1 to turn off leds */ + PIOA_SODR = 0x0000000f; + /* turn first led on */ + PIOA_CODR = 0x00000001; + + timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0); + timer_setDelay(&leds_timer, ms_to_ticks(100)); + timer_add(&leds_timer); + + ASSERT(proc_testRun() == 0); + // Main loop + for(;;) + { + kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg); + } + return 0; +} diff --git a/examples/at91sam7s/at91sam7s.mk b/examples/at91sam7s/at91sam7s.mk new file mode 100644 index 00000000..f7d2a9d9 --- /dev/null +++ b/examples/at91sam7s/at91sam7s.mk @@ -0,0 +1,45 @@ +# +# $Id: at91sam7s.mk 18234 2007-10-08 13:39:48Z rasky $ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib at91sam7s application. +# +# Author: Bernie Innocenti +# +# + +# Set to 1 for debug builds +at91sam7s_DEBUG = 1 + +# Our target application +TRG += at91sam7s + +at91sam7s_CSRC = \ + examples/at91sam7s/at91sam7s.c \ + bertos/drv/timer.c \ + bertos/drv/ser.c \ + bertos/cpu/arm/drv/sysirq_at91.c \ + bertos/cpu/arm/drv/ser_at91.c \ + bertos/mware/event.c \ + bertos/mware/formatwr.c \ + bertos/mware/hex.c \ + bertos/kern/kfile.c \ + bertos/kern/proc.c \ + bertos/kern/coop.c \ + bertos/kern/proc_test.c \ + bertos/kern/monitor.c \ + bertos/kern/signal.c + +at91sam7s_CPPASRC = \ + bertos/cpu/arm/hw/crtat91sam7_rom.S \ + bertos/cpu/arm/hw/switch_arm.S + +at91sam7s_CROSS = arm-none-eabi- + +at91sam7s_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug +at91sam7s_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_AT91SAM7S256__ -g3 -gdwarf-2 -fverbose-asm -Iexamples/at91sam7s/hw -Iexamples/at91sam7s -Ibertos/cpu/arm +at91sam7s_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_ram.ld -Wl,--no-warn-mismatch + +at91sam7s_CPU = arm7tdmi + diff --git a/examples/at91sam7s/cfg/cfg_kern.h b/examples/at91sam7s/cfg/cfg_kern.h new file mode 100644 index 00000000..bc4594a4 --- /dev/null +++ b/examples/at91sam7s/cfg/cfg_kern.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \version $Id$ + * \author Bernie Innocenti + */ + +#ifndef CFG_KERN_H +#define CFG_KERN_H + +/** + * Enable the multithreading kernel. + */ +#define CONFIG_KERN 1 + +/** + * \name Optional kernel features + * \{ + */ +#define CONFIG_KERN_SCHED 1 ///< Process schedling +#define CONFIG_KERN_SIGNALS 1 ///< Inter-process signals +#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor +#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation +#define CONFIG_KERN_SEMAPHORES 1 ///< Re-entrant mutual exclusion primitives +#define CONFIG_KERN_MONITOR 1 ///< Process monitor +#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling +#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy +/*\}*/ + +/// [ms] Time sharing quantum (a prime number prevents interference effects) +#define CONFIG_KERN_QUANTUM 47 + +/// Module logging level. +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/// Module logging format. +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_KERN_H */ diff --git a/examples/at91sam7s/hw/hw_cpu.h b/examples/at91sam7s/hw/hw_cpu.h new file mode 100644 index 00000000..69652610 --- /dev/null +++ b/examples/at91sam7s/hw/hw_cpu.h @@ -0,0 +1,61 @@ +/** + * \file + * + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Bernie Innocenti + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2006/05/18 00:41:47 bernie + *#* New triface devlib application. + *#* + *#*/ + +#ifndef AT91SAM7SEK_HW_H +#define AT91SAM7SEK_HW_H + +/// CPU Clock frequency (48.023 MHz) +#define CLOCK_FREQ (48023000UL) + + +/* Timer IRQ strobe */ +//#if CONFIG_TIMER_STROBE +// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) +// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) +// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) +//#endif /* CONFIG_TIMER_STROBE */ + +#endif /* AT91SAM7SEK_HW_H */ diff --git a/examples/at91sam7s/hw/hw_ser.h b/examples/at91sam7s/hw/hw_ser.h new file mode 100644 index 00000000..7b98f223 --- /dev/null +++ b/examples/at91sam7s/hw/hw_ser.h @@ -0,0 +1,40 @@ +/** + * \file + * + * + * \brief Serial hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + + diff --git a/examples/at91sam7s/verstag.h b/examples/at91sam7s/verstag.h new file mode 100644 index 00000000..e6163906 --- /dev/null +++ b/examples/at91sam7s/verstag.h @@ -0,0 +1,94 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernie Innocenti + * + * \brief Declare application version strings + */ +#ifndef DEVLIB_VERSTAG_H +#define DEVLIB_VERSTAG_H + +#ifndef ARCH_CONFIG_H + #include "cfg/arch_config.h" +#endif + +#define APP_NAME "AT91SAM7S-EK porting test" +#define APP_DESCRIPTION "AT91SAM7S-EK porting test" +#define APP_AUTHOR "Develer" +#define APP_COPYRIGHT "Copyright 2007 Develer (http://www.develer.com/)" + +#define VERS_MAJOR 0 +#define VERS_MINOR 1 +#define VERS_REV 0 +#define VERS_LETTER "" + +/** + * If _SNAPSHOT is defined, \c VERS_TAG contains the build date + * date instead of a numeric version string. + */ +//#define _SNAPSHOT + +#ifdef _DEBUG + #define VERS_DBG "D" +#else + #define VERS_DBG "" +#endif + +#define __STRINGIZE(x) #x +#define _STRINGIZE(x) __STRINGIZE(x) + +/** Build application version string (i.e.: "1.7.0") */ +#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG +#ifdef _SNAPSHOT + #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG +#else + #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) +#endif + +/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ +#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) +#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) + +/** The revision string (contains VERS_TAG) */ +extern const char vers_tag[]; + +/** Sequential build number (contains VERS_BUILD) */ +extern const int vers_build_nr; +//extern const char vers_build_str[]; + +/** Hostname of the machine used to build this binary (contains VERS_HOST) */ +extern const char vers_host[]; + +#endif /* DEVLIB_VERSTAG_H */ diff --git a/examples/demo/cfg/cfg_kern.h b/examples/demo/cfg/cfg_kern.h new file mode 100644 index 00000000..e828bce7 --- /dev/null +++ b/examples/demo/cfg/cfg_kern.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \version $Id$ + * \author Bernie Innocenti + */ + +#ifndef CFG_KERN_H +#define CFG_KERN_H + +/** + * Enable the multithreading kernel. + */ +#define CONFIG_KERN 1 + +/** + * \name Optional kernel features + * \{ + */ +#define CONFIG_KERN_SCHED 1 ///< Process schedling +#define CONFIG_KERN_SIGNALS 1 ///< Inter-process signals +#define CONFIG_KERN_IRQ 1 ///< Interrupt supervisor +#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation +#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives +#define CONFIG_KERN_MONITOR 1 ///< Process monitor +#define CONFIG_KERN_PREEMPT 1 ///< Preemptive process scheduling +#define CONFIG_KERN_PRI 1 ///< Priority-based scheduling policy +/*\}*/ + +/// [ms] Time sharing quantum (a prime number prevents interference effects) +#define CONFIG_KERN_QUANTUM 47 + +/// Module logging level. +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/// Module logging format. +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_KERN_H */ diff --git a/examples/demo/demo.c b/examples/demo/demo.c new file mode 100644 index 00000000..9c2169cc --- /dev/null +++ b/examples/demo/demo.c @@ -0,0 +1,315 @@ +/** + * \file + * + * + * \brief Multifunction system test for BeRTOS modules. + * + * \version $Id: demo.c 18242 2007-10-08 17:35:23Z marco $ + * \author Bernie Innocenti + */ + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/** + * Draw a pentacle in the provided bitmap. + * + * This is invoked by the keyboard polling routine, as a poor man's surrogate + * of true task switching. + */ +void schedule(void) +{ + lcd_blitBitmap(&lcd_bitmap); + emul_idle(); +} + +/** + * Draw a pentacle in the provided bitmap. + */ +static void magic(struct Bitmap *bitmap, coord_t x, coord_t y) +{ + static const coord_t coords[] = { 120, 34, 90, 90, 30, 90, 0, 34, 60, 0, 90, 90, 0, 34, 120, 34, 30, 90, 60, 0 }; + unsigned int i; + + gfx_moveTo(bitmap, coords[countof(coords)-2]/2 + x, coords[countof(coords)-1]/3 + y); + for (i = 0; i < countof(coords); i += 2) + gfx_lineTo(bitmap, coords[i]/2 + x, coords[i+1]/3 + y); +} + +static void hello_world(Bitmap *bm) +{ + extern const Font font_ncenB18; + const Font *old_font = bm->font; + + gfx_bitmapClear(bm); + + /* Set big font */ + gfx_setFont(bm, &font_ncenB18); + + text_xprintf(bm, 1, 0, STYLEF_BOLD | TEXT_FILL | TEXT_CENTER, + "Hello, world!"); + + lcd_blitBitmap(bm); + timer_delay(1000); + + /* Restore old font */ + gfx_setFont(bm, old_font); +} + +/** + * Show the splash screen + */ +static void bouncing_logo(Bitmap *bm) +{ + const long SPEED_SCALE = 1000; + const long GRAVITY_ACCEL = 10; + const long BOUNCE_ELASTICITY = 2; + long h = (long)(-bertos_logo.height) * SPEED_SCALE; + long speed = 1000; + + /* Repeat until logo stands still on the bottom edge */ + while (!((speed == 0) && (h == 0))) + { + /* Move */ + h += speed; + + /* Gravity acceleration */ + speed += GRAVITY_ACCEL; + + if (h > 0 && speed > 0) + { + /* Bounce */ + speed = - (speed / BOUNCE_ELASTICITY); + + } + + /* Update graphics */ + gfx_bitmapClear(bm); + gfx_blitImage(bm, + (bm->width - bertos_logo.width) / 2, + h / SPEED_SCALE, + &bertos_logo); + lcd_blitBitmap(bm); + + timer_delay(10); + } +} + +void win_demo(Bitmap *bm) +{ + const coord_t small_left = 45, small_top = 30, small_width = 50, small_height = 30; + const coord_t large_left = -10, large_top = 10, large_width = 85, large_height = 41; + + Window root_win, small_win, large_win; + Bitmap small_bm, large_bm; + uint8_t small_raster[RAST_SIZE(small_width, small_height)]; + uint8_t large_raster[RAST_SIZE(large_width, large_height)]; + + win_create(&root_win, bm); + + gfx_bitmapInit(&large_bm, large_raster, large_width, large_height); + win_create(&large_win, &large_bm); + win_open(&large_win, &root_win); + win_move(&large_win, large_left, large_top); + + gfx_bitmapInit(&small_bm, small_raster, small_width, small_height); + win_create(&small_win, &small_bm); + win_open(&small_win, &root_win); + win_move(&small_win, small_left, small_top); + + + coord_t x = 0, y = LCD_WIDTH / 2; + coord_t xdir = +1, ydir = -1; + coord_t xdir_large = +1; + coord_t ydir_small = +1; + int raise_counter = 0; + int i; + + for(;;) + { + /* Background animation */ + bm = root_win.bitmap; + gfx_bitmapClear(bm); +// gfx_setClipRect(bm, 0, 0, bm->width, bm->height); +// gfx_rectDraw(bm, 10, 10, bm->width-10, bm->height-10); +// gfx_setClipRect(bm, 11, 11, bm->width-11, bm->height-11); + magic(bm, x, y); + x += xdir; + y += ydir; + if (x >= bm->width) xdir = -1; + if (x <= -50) xdir = +1; + if (y >= bm->height) ydir = -1; + if (y <= -50) ydir = +1; + + /* Large window animation */ + bm = large_win.bitmap; + gfx_bitmapClear(bm); + for (i = 0; i < bm->height / 2; i += 2) + gfx_rectDraw(bm, 0 + i, 0 + i, bm->width - i, bm->height - i); + + + /* Small window animation */ + bm = small_win.bitmap; + gfx_bitmapClear(bm); + gfx_rectDraw(bm, 0, 0, bm->width, bm->height); + gfx_line(bm, 0, 0, bm->width, bm->height); + gfx_line(bm, bm->width, 0, 0, bm->height); + + /* Move windows around */ + win_move(&large_win, large_win.geom.xmin + xdir_large, large_top); + if (large_win.geom.xmin < -20) xdir_large = +1; + if (large_win.geom.xmin > RECT_WIDTH(&root_win.geom) - 5) xdir_large = -1; + + win_move(&small_win, small_left, small_win.geom.ymin + ydir_small); + if (small_win.geom.ymin < -20) ydir_small = +1; + if (small_win.geom.ymin > RECT_HEIGHT(&root_win.geom) - 5) ydir_small = -1; + + ++raise_counter; + if (raise_counter % 997 == 0) + win_raise(&small_win); + else if (raise_counter % 731 == 0) + win_raise(&large_win); + + win_compose(&root_win); + + /* Also does LCD refresh, etc. */ + if (kbd_peek()) + break; + } +} + +void proc_demo(void) +{ + proc_testRun(); +} + +void timer_demo(void) +{ + timer_testRun(); + timer_testTearDown(); +} + + +/* SETTINGS SUBMENU */ + +static struct MenuItem settings_items[] = +{ + { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Language", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)0, 0, NULL, (iptr_t)0 } +}; +static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; + + +/* MX SUBMENU */ + +static struct MenuItem mx_items[] = +{ + { (const_iptr_t)"Mouse", MIF_CHECKIT | MIF_EXCLUDE_1 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Keyboard", MIF_CHECKED | MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_2, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Joystick", MIF_CHECKIT | MIF_EXCLUDE_0 | MIF_EXCLUDE_1, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Autosave", MIF_CHECKED | MIF_CHECKIT | MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)0, 0, NULL, (iptr_t)0 } +}; + +static struct Menu mx_menu = { mx_items, (const_iptr_t)0, MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; + + +/* DISPLAY SUBMENU */ + +static struct MenuItem display_items[] = +{ + { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)0, 0, NULL, (iptr_t)0 } +}; +static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 }; + + +/* MAIN MENU */ + +static struct MenuItem main_items[] = +{ + { (const_iptr_t)"Win Fly", 0, (MenuHook)win_demo, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Bounce!", 0, (MenuHook)bouncing_logo,(iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Hello World", 0, (MenuHook)hello_world, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Scheduling", 0, (MenuHook)proc_demo, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Timer Test", 0, (MenuHook)timer_demo, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Menu MX", 0, (MenuHook)menu_handle, (iptr_t)&mx_menu }, + { (const_iptr_t)"Display", 0, (MenuHook)menu_handle, (iptr_t)&display_menu }, + { (const_iptr_t)"Settings", 0, (MenuHook)menu_handle, (iptr_t)&settings_menu }, + { (const_iptr_t)0, 0, NULL, (iptr_t)0 } +}; +static struct Menu main_menu = { main_items, "Main Menu", MF_STICKY, &lcd_bitmap, 0 }; + + +static cpu_stack_t monitor_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]; + +int main(int argc, char *argv[]) +{ + emul_init(&argc, argv); + irq_init(); + timer_init(); + buz_init(); + kbd_init(); + lcd_init(); + proc_init(); + monitor_start(sizeof(monitor_stack), monitor_stack); + + menu_handle(&main_menu); + + timer_cleanup(); + emul_cleanup(); + return 0; +} diff --git a/examples/demo/demo.mk b/examples/demo/demo.mk new file mode 100644 index 00000000..504d80fa --- /dev/null +++ b/examples/demo/demo.mk @@ -0,0 +1,87 @@ +# +# Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/) +# Copyright 2008 Bernie Innocenti +# +# Makefile fragment for DevLib demo application. +# +# Version: $Id: demo.mk 18234 2007-10-08 13:39:48Z rasky $ +# Author: Bernie Innocenti +# + +include bertos/fonts/fonts.mk +include bertos/emul/emul.mk + +# Set to 1 for debug builds +demo_DEBUG = 1 + +# Our target application +TRG += demo + +# FIXME: we want to use g++ for C source too +CC = g++ +CXX = g++ + +demo_CXXSRC = \ + bertos/emul/emul.cpp \ + bertos/emul/emulwin.cpp \ + bertos/emul/emulkbd.cpp \ + bertos/drv/lcd_gfx_qt.cpp + +demo_CSRC = \ + examples/demo/demo.c \ + bertos/os/hptime.c \ + bertos/gfx/bitmap.c \ + bertos/gfx/line.c \ + bertos/gfx/win.c \ + bertos/gfx/text.c \ + bertos/gfx/text_format.c \ + bertos/gui/menu.c \ + bertos/fonts/helvB10.c \ + bertos/fonts/luBS14.c \ + bertos/fonts/ncenB18.c \ + bertos/icons/logo.c \ + bertos/drv/kbd.c \ + bertos/drv/timer.c \ + bertos/drv/timer_test.c \ + bertos/drv/buzzer.c \ + bertos/drv/ser.c \ + bertos/emul/ser_posix.c \ + bertos/mware/formatwr.c \ + bertos/mware/hex.c \ + bertos/mware/event.c \ + bertos/mware/observer.c \ + bertos/mware/resource.c \ + bertos/mware/sprintf.c \ + bertos/kern/idle.c \ + bertos/kern/irq.c \ + bertos/kern/preempt.c \ + bertos/kern/proc.c \ + bertos/kern/proc_test.c \ + bertos/kern/sem.c \ + bertos/kern/signal.c \ + bertos/kern/monitor.c \ + bertos/verstag.c + +demo_CPPASRC = \ + bertos/emul/switch.S + +# FIXME: maybe this junk should go in emul/emul.mk? +$(OBJDIR)/demo/bertos/emul/emulwin.o: bertos/emul/emulwin_moc.cpp +$(OBJDIR)/demo/bertos/drv/lcd_gfx_qt.o: bertos/drv/lcd_gfx_qt_moc.cpp +$(OBJDIR)/demo/bertos/drv/timer.o: bertos/emul/timer_qt_moc.cpp +$(OBJDIR)/demo/bertos/emul/emulkbd.o: bertos/emul/emulkbd_moc.cpp + +#FIXME: isn't there a way to avoid repeating the pattern rule? +bertos/emul/timer_qt_moc.cpp: bertos/emul/timer_qt.c + $(QT_MOC) -o $@ $< + + +demo_CFLAGS = -Iexamples/demo $(EMUL_CFLAGS) +demo_CXXFLAGS = -Iexamples/demo $(EMUL_CFLAGS) +demo_LDFLAGS = $(EMUL_LDFLAGS) + +# Debug stuff +ifeq ($(demo_DEBUG),0) + demo_CFLAGS += -Os + demo_CXXFLAGS += -Os +endif diff --git a/examples/demo/hw/kbd_map.h b/examples/demo/hw/kbd_map.h new file mode 100644 index 00000000..deb215ef --- /dev/null +++ b/examples/demo/hw/kbd_map.h @@ -0,0 +1,67 @@ +/** + * \file + * + * + * \brief Keyboard map definitions. + * + * \version $Id$ + * + * \author Francesco Sacchi + * \author Stefano Fedrigo + */ + +#ifndef HW_KBD_MAP_H +#define HW_KBD_MAP_H + +#include + + +/** + * Type for keyboard mask. + */ +typedef uint16_t keymask_t; + +/** + * \name Keycodes. + */ +/*@{*/ +#define K_UP BV(0) +#define K_DOWN BV(1) +#define K_OK BV(2) +#define K_CANCEL BV(3) + +#define K_REPEAT BV(14) /**< This is a repeated keyevent. */ +#define K_TIMEOUT BV(15) /**< Fake key event for timeouts. */ +/*@}*/ + + +#endif /* HW_KBD_MAP_H */ diff --git a/examples/demo/verstag.h b/examples/demo/verstag.h new file mode 100644 index 00000000..a89a5e52 --- /dev/null +++ b/examples/demo/verstag.h @@ -0,0 +1,95 @@ +/** + * \file + * + * + * \version $Id: verstag.h 18242 2007-10-08 17:35:23Z marco $ + * + * \author Bernie Innocenti + * + * \brief Declare application version strings + */ + +#ifndef BERTOS_VERSTAG_H +#define BERTOS_VERSTAG_H + +#ifndef CFG_ARCH_CONFIG_H + #include "cfg/cfg_arch.h" +#endif + +#define APP_NAME "BeRTOS Demo" +#define APP_DESCRIPTION "BeRTOS Multidemo Application" +#define APP_AUTHOR "Develer" +#define APP_COPYRIGHT "Copyright 2006 Develer (http://www.develer.com/)" + +#define VERS_MAJOR 0 +#define VERS_MINOR 1 +#define VERS_REV 0 +#define VERS_LETTER "" + +/** + * If _SNAPSHOT is defined, \c VERS_TAG contains the build date + * date instead of a numeric version string. + */ +#define _SNAPSHOT + +#ifdef _DEBUG + #define VERS_DBG "D" +#else + #define VERS_DBG "" +#endif + +#define __STRINGIZE(x) #x +#define _STRINGIZE(x) __STRINGIZE(x) + +/** Build application version string (i.e.: "1.7.0") */ +#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG +#ifdef _SNAPSHOT + #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG +#else + #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) +#endif + +/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ +#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) +#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) + +/** The revision string (contains VERS_TAG) */ +extern const char vers_tag[]; + +/** Sequential build number (contains VERS_BUILD) */ +extern const int vers_build_nr; +//extern const char vers_build_str[]; + +/** Hostname of the machine used to build this binary (contains VERS_HOST) */ +extern const char vers_host[]; + +#endif /* BERTOS_VERSTAG_H */ diff --git a/examples/lm3s1968/hw/hw_cpu.h b/examples/lm3s1968/hw/hw_cpu.h new file mode 100644 index 00000000..52e3d4b8 --- /dev/null +++ b/examples/lm3s1968/hw/hw_cpu.h @@ -0,0 +1,56 @@ +/** + * \file + * + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Bernie Innocenti + */ + +#ifndef HW_CPU_H +#define HW_CPU_H + +#warning TODO:This is an example implementation, you must implement it! + +/// CPU Clock frequency +#define CLOCK_FREQ (48023000L/* Implement me! */) + + +/* Timer IRQ strobe */ +//#if CONFIG_TIMER_STROBE +// #define TIMER_STROBE_ON /* Implement me! */ +// #define TIMER_STROBE_OFF /* Implement me! */ +// #define TIMER_STROBE_INIT /* Implement me! */ +//#endif /* CONFIG_TIMER_STROBE */ + +#endif /* HW_CPU_H */ diff --git a/examples/lm3s1968/lm3s1968.c b/examples/lm3s1968/lm3s1968.c new file mode 100644 index 00000000..514f255c --- /dev/null +++ b/examples/lm3s1968/lm3s1968.c @@ -0,0 +1,49 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Manuele Fanelli + * + * \brief LM3S168 porting test. + */ + +#include "bertos/cpu/detect.h" + +int main (void) +{ + int c; + + for (;;) + c++; + return 0; +} diff --git a/examples/lm3s1968/lm3s1968.mk b/examples/lm3s1968/lm3s1968.mk new file mode 100644 index 00000000..bf516125 --- /dev/null +++ b/examples/lm3s1968/lm3s1968.mk @@ -0,0 +1,31 @@ +# +# $Id: lm3s1968.mk 18234 2007-10-08 13:39:48Z rasky $ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib lm3s1968 application. +# +# Author: Manuele Fanelli +# +# + +# Set to 1 for debug builds +lm3s1968_DEBUG = 0 + + +# Our target application +TRG += lm3s1968 + +lm3s1968_CSRC = \ + examples/lm3s1968/lm3s1968.c \ + #bertos/cpu/cortex-m3/startup_lm3s.c + + +lm3s1968_CROSS = arm-none-eabi- + +lm3s1968_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug -mthumb +lm3s1968_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_LM3S1968__ -g3 -gdwarf-2 -fverbose-asm -mthumb -Iexamples/lm3s1968 -Ibertos/cpu/cortex-m3 +lm3s1968_LDFLAGS = -nostartfiles -T examples/lm3s1968/standalone.ld -Wl,--no-warn-mismatch + +lm3s1968_CPU = cortex-m3 + diff --git a/examples/randpool/appconfig.h b/examples/randpool/appconfig.h new file mode 100644 index 00000000..75a16bb1 --- /dev/null +++ b/examples/randpool/appconfig.h @@ -0,0 +1,283 @@ +/** + * \file + * + * + * \brief DevLib configuration options + * + * You should copy this header in your project and rename it to + * "config.h" and delete the CONFIG_ macros for the modules + * you're not using. + * + *

Working with multiple applications

+ * + * If your project is made of multiple DevLib-based applications, + * create a custom "config.h" file in each application subdirectory + * and play with the compiler include path to get the desired result. + * You can share common options by creationg a "config_common.h" header + * and including it from all your "config.h" copies. + * + *

Configuration style

+ * + * For improved compile-time checking of configuration options, + * the preferred way to use a \c CONFIG_ symbol is keeping it + * always defined with a value of either 0 or 1. This lets + * you write tests like this: + * + * \code + * #if CONFIG_FOO + * void foo(void) + * { + * if (CONFIG_BAR) + * bar(); + * } + * #endif // CONFIG_FOO + * \endcode + * + * In most cases, we rely on the optimizer to discard checks + * on constant values and performing dead-code elimination. + * + * \version $Id$ + * \author Bernie Innocenti + * \author Stefano Fedrigo + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2007/02/15 18:17:51 asterix + *#* Add randpool test program. + *#* + *#* Revision 1.16 2007/02/12 15:29:41 asterix + *#* Add CONFIG_RANDPOOL_TIMER macro to swich on or off timer support in randpool. + *#* + *#* Revision 1.15 2007/02/08 14:20:35 asterix + *#* Add CONFIG_SIZE_ENTROPY_POOL. + *#* + *#* Revision 1.14 2007/02/06 11:37:26 asterix + *#* Add CONFIG_MD2_STD_PERM for use standard permutation in MD2. + *#* + *#* Revision 1.13 2007/01/31 13:49:40 asterix + *#* Add config size block for MD2 + *#* + *#* Revision 1.3 2006/09/13 18:29:22 bernie + *#* Add a few missing CONFIG_ definitions. + *#* + *#* Revision 1.2 2006/07/19 12:56:24 bernie + *#* Convert to new Doxygen style. + *#* + *#* Revision 1.1 2006/05/18 00:40:43 bernie + *#* Rename appconfig.h to appconfig_common.h. + *#* + *#* Revision 1.11 2006/04/11 00:08:53 bernie + *#* Add smooth scrolling for menus. + *#* + *#* Revision 1.10 2006/03/22 09:48:51 bernie + *#* Add a few more config options. + *#* + *#* Revision 1.9 2006/02/24 00:27:35 bernie + *#* Enable kernel and fix Doxygen markup. + *#* + *#* Revision 1.8 2006/02/21 16:06:05 bernie + *#* Update copyright info. + *#* + *#* Revision 1.7 2006/02/17 22:28:19 bernie + *#* Add missing UART definitions. + *#* + *#* Revision 1.6 2006/02/15 09:12:56 bernie + *#* Switch to BITMAP_FMT_PLANAR_V_LSB. + *#* + *#* Revision 1.5 2006/02/10 12:34:33 bernie + *#* Add missing config options for gfx and kbd. + *#* + *#* Revision 1.4 2006/01/23 23:12:27 bernie + *#* Enable CONFIG_GFX_VCOORDS. + *#* + *#* Revision 1.3 2006/01/17 02:30:06 bernie + *#* Add new config vars. + *#* + *#* Revision 1.2 2005/11/27 03:04:57 bernie + *#* CONFIG_WATCHDOG: New config option. + *#* + *#* Revision 1.1 2005/11/04 17:42:12 bernie + *#* Move cfg/config.h to appconfig.h. + *#*/ + +#ifndef APPCONFIG_H +#define APPCONFIG_H + +/** Baud-rate for the kdebug console */ +#define CONFIG_KDEBUG_BAUDRATE 19200 + +/** + * printf()-style formatter configuration. + * + * \sa PRINTF_DISABLED + * \sa PRINTF_NOMODIFIERS + * \sa PRINTF_REDUCED + * \sa PRINTF_NOFLOAT + * \sa PRINTF_FULL + */ +#define CONFIG_PRINTF PRINTF_FULL + +/** + * Multithreading kernel. + * + * \sa config_kern.h + */ +#define CONFIG_KERN 0 + +/** + * \name Serial driver parameters + * \{ + */ + /** [bytes] Size of the outbound FIFO buffer for port 0. */ + #define CONFIG_UART0_TXBUFSIZE 32 + + /** [bytes] Size of the inbound FIFO buffer for port 0. */ + #define CONFIG_UART0_RXBUFSIZE 64 + + /** [bytes] Size of the outbound FIFO buffer for port 1. */ + #define CONFIG_UART1_TXBUFSIZE 32 + + /** [bytes] Size of the inbound FIFO buffer for port 1. */ + #define CONFIG_UART1_RXBUFSIZE 64 + + /** [bytes] Size of the outbound FIFO buffer for SPI port (AVR only). */ + #define CONFIG_SPI_TXBUFSIZE 16 + + /** [bytes] Size of the inbound FIFO buffer for SPI port (AVR only). */ + #define CONFIG_SPI_RXBUFSIZE 32 + + /** SPI data order (AVR only). */ + #define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST + + /** SPI clock division factor (AVR only). */ + #define CONFIG_SPI_CLOCK_DIV 16 + + /** SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). */ + #define CONFIG_SPI_CLOCK_POL 0 + + /** SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). */ + #define CONFIG_SPI_CLOCK_PHASE 0 + + /** Default transmit timeout (ms). Set to -1 to disable timeout support */ + #define CONFIG_SER_TXTIMEOUT -1 + + /** Default receive timeout (ms). Set to -1 to disable timeout support */ + #define CONFIG_SER_RXTIMEOUT -1 + + /** Use RTS/CTS handshake */ + #define CONFIG_SER_HWHANDSHAKE 0 + + /** Default baud rate (set to 0 to disable) */ + #define CONFIG_SER_DEFBAUDRATE 0 + + /** Enable ser_gets() and ser_gets_echo() */ + #define CONFIG_SER_GETS 0 + + /** Enable second serial port in emulator. */ + #define CONFIG_EMUL_UART1 0 + + /** + * Transmit always something on serial port 0 TX + * to avoid interference when sending burst of data, + * using AVR multiprocessor serial mode + */ + #define CONFIG_SER_TXFILL 0 + + #define CONFIG_SER_STROBE 0 +/*\}*/ + +/// Hardware timer selection for drv/timer.c +#define CONFIG_TIMER TIMER_ON_OUTPUT_COMPARE2 + +/// Debug timer interrupt using a strobe pin. +#define CONFIG_TIMER_STROBE 0 + +/// Enable ADS strobe. +#define CONFIG_ADC_STROBE 0 + +/// Enable watchdog timer. +#define CONFIG_WATCHDOG 0 + +/// EEPROM type for drv/eeprom.c +#define CONFIG_EEPROM_TYPE EEPROM_24XX256 + +/// Select bitmap pixel format. +#define CONFIG_BITMAP_FMT BITMAP_FMT_PLANAR_V_LSB + +/// Enable line clipping algorithm. +#define CONFIG_GFX_CLIPPING 1 + +/// Enable text rendering in bitmaps. +#define CONFIG_GFX_TEXT 1 + +/// Enable virtual coordinate system. +#define CONFIG_GFX_VCOORDS 1 + +/// Keyboard polling method +#define CONFIG_KBD_POLL KBD_POLL_SOFTINT + +/// Enable keyboard event delivery to observers +#define CONFIG_KBD_OBSERVER 0 + +/// Enable key beeps +#define CONFIG_KBD_BEEP 1 + +/// Enable long pression handler for keys +#define CONFIG_KBD_LONGPRESS 1 + +/** + * \name Type for the chart dataset + * \{ + */ +#define CONFIG_CHART_TYPE_X uint8_t +#define CONFIG_CHART_TYPE_Y uint8_t +/*\}*/ + +/// Enable button bar behind menus +#define CONFIG_MENU_MENUBAR 0 + +/// Enable smooth scrolling in menus +#define CONFIG_MENU_SMOOTH 1 + +/// Size of block for MD2 algorithm. +#define CONFIG_MD2_BLOCK_LEN 16 + +/// Use standard permutation in MD2 algorithm. +#define CONFIG_MD2_STD_PERM 0 + +/// Define a size, in byte, of entropy pool. +#define CONFIG_SIZE_ENTROPY_POOL 256 + +/// Turn on or off timer support in Randpool. +#define CONFIG_RANDPOOL_TIMER 1 + +#endif /* APPCONFIG_H */ diff --git a/examples/randpool/randpool_demo.c b/examples/randpool/randpool_demo.c new file mode 100644 index 00000000..3010cd10 --- /dev/null +++ b/examples/randpool/randpool_demo.c @@ -0,0 +1,251 @@ +/** + * \file + * + * + * \brief Test function for randpool API. + * + * This program return a rand number generate from randpool function. + * For use randpool function you need a souce of entropy. In this + * program you can choose from: + * - /dev/random + * - /dev/urandom + * - /dev/input/mouse0 + * + * There are 3 mode of output: + * - binmode: program generate a sequenze of random byte. + * - Matrix of random number for octave program. + * - Vector of random number for octave program. + * + * \version $Id$ + * \author Daniele Basile + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2007/02/15 18:17:51 asterix + *#* Add randpool test program. + *#* + *#*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LEN 256 //Size of buffer containing a random number. +#define SAMPLE 1000 //Defoult number of byte that put in entropy pool. + +int main (int argc, char *argv[]) +{ + EntropyPool pool; + uint8_t ch; + uint8_t buff[LEN]; + FILE *pdev; + int opt = getopt (argc, argv, "murh"); + int samp = SAMPLE; + int round = 10; + int mode = 0; + int pass = 0; + + timer_init(); + + randpool_init(&pool, NULL, 0); //Init a entropy pool. + + /* + * Chose a source of entropy. + */ + switch(opt) + { + case 'm': + { + pdev = fopen("/dev/input/mouse0", "r"); + break; + } + case 'u': + { + pdev = fopen("/dev/urandom", "r"); + break; + } + case 'r': + { + pdev = fopen("/dev/random", "r"); + break; + } + case 'h': + { + } + default: + { + printf("\n"); + printf("\n"); + printf("randpool_demo [OPTION] [SAMPLE] [ROUND] [MODE]\n"); + printf("\n"); + printf("OPTION:\n"); + printf(" -r /dev/random\n"); + printf(" -u /dev/urandom\n"); + printf(" -m /dev/input/mouse0\n"); + printf("\n"); + printf("SAMPLE:\n"); + printf(" num number of entropy byte to put in etropy pool.\n"); + printf("\n"); + printf("ROUND:\n"); + printf(" num number call of randpool_get function.\n"); + printf("\n"); + printf("MODE:\n"); + printf(" 0 binmode\n"); + printf(" 1 vector mode\n"); + printf(" 2 matrix mode\n"); + printf("\n"); + printf("Test program of randpool API.\n"); + printf("This program create an entropy pool of 256byte, and fill it\n"); + printf("with entropy from a exsternal source. This source can be:\n"); + printf(" - /dev/random (option: -r)\n"); + printf(" - /dev/urandom (option: -u)\n"); + printf(" - /dev/input/mouse0 (option: -m)\n"); + printf("\n"); + printf("Once the pool is full, program call a randpool_get ROUND time,\n"); + printf("printing on STDOUT random value, in accord with a select mode.\n"); + printf("The mode are:\n"); + printf(" - binmode: program print on STDOUT random byte. (option: 0 (defaul mode)\n"); + printf(" - vector mode: program print on STDOUT a ROUND vector of random value.\n"); + printf(" The output is format for octave program. (option: 1)\n"); + printf(" - matrix mode: program print on STDOUT a matrix of random value.\n"); + printf(" The output is format for octave program. (option: 2)\n"); + printf("\n"); + exit(1); + } + + } + + /* + * + */ + if(argc > 2) + { + if(argv[2]) + samp = atoi(argv[2]); //Number of byte take from entropy source + if(argv[3]) + round = atoi(argv[3]); //Number of time we call randpool_get. + if(argv[4]) + { + switch(atoi(argv[4])) + { + case 1: + { + mode = 1; + printf("# Created by Asterix.\n"); + printf("# name: __nargin__\n"); + printf("# type: scalar\n"); + printf("0\n"); + break; + } + case 2: + { + mode = 2; + printf("# Created by Asterix.\n"); + printf("# name: __nargin__\n"); + printf("# type: scalar\n"); + printf("0\n"); + break; + } + default: + { + break; + } + + } + + } + + } + + /* + * Add byte to entropy pool from a source of entropy. + */ + for(int i = 0; i < samp; i++) + { + + ch = fgetc(pdev); + randpool_add(&pool, &ch, sizeof(ch)); + + } + + fclose(pdev); + + + for(int k = 0; k < round; k++) + { + switch(mode) + { + case 1: + { + printf("\n"); + printf("\n# name: vet%d",k); + printf("\n# type: matrix"); + printf("\n# rows: 1"); + printf("\n# columns: %d\n", LEN); + pass = 1; + break; + } + case 2: + { + printf("\n"); + printf("\n# name: randMatrix"); + printf("\n# type: matrix"); + printf("\n# rows: %d",round); + printf("\n# columns: %d\n", LEN); + pass = 1; + mode = 0; + break; + } + } + + randpool_get(&pool, buff, LEN); + + if(pass) + { + for(int j = 0; j < LEN; j++) + { + printf("%d ", buff[j]); + } + printf("\n"); + } + else + fwrite(buff, sizeof(uint8_t), LEN, stdout); + } + + +} + diff --git a/examples/randpool/randpool_demo.mk b/examples/randpool/randpool_demo.mk new file mode 100644 index 00000000..680f3cff --- /dev/null +++ b/examples/randpool/randpool_demo.mk @@ -0,0 +1,37 @@ +# +# $Id$ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib randpool_demo application. +# +# Author: Daniele Basile +# +# $Log$ +# Revision 1.1 2007/02/15 18:17:51 asterix +# Add randpool test program. +# +# + + +# Set to 1 for debug builds +randpool_demo_DEBUG = 0 + +# Our target application +TRG += randpool_demo + +randpool_demo_CSRC = \ + examples/randpool/randpool_demo.c \ + algos/randpool.c \ + algos/md2.c \ + drv/timer.c \ + os/hptime.c + +randpool_demo_CFLAGS = -O0 -D'ARCH=0' -Iexamples/randpool/ -Iexamples/randpool/hw + +# Debug stuff +ifeq ($(randpool_demo_DEBUG),1) + randpool_demo_CFLAGS += -D_DEBUG + randpool_demo_PCSRC += drv/kdebug.c +endif + diff --git a/examples/test/armtest.mk b/examples/test/armtest.mk new file mode 100644 index 00000000..c5a8204f --- /dev/null +++ b/examples/test/armtest.mk @@ -0,0 +1,32 @@ +# +# $Id: armtest.mk 18234 2007-10-08 13:39:48Z rasky $ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib armtest application. +# +# Author: Bernie Innocenti +# +# + +# Set to 1 for debug builds +armtest_DEBUG = 1 + +# Our target application +TRG += armtest + +#include arm c and asm sources +include ./examples/test/arm_src.mk + +armtest_CSRC = $(arm_CSRC) examples/test/empty_main.c + +armtest_CPPASRC = $(arm_ASRC) + +armtest_CROSS = arm-elf- + +armtest_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug +armtest_CPPFLAGS = -O0 -D'ARCH=ARCH_NIGHTTEST' -D__ARM_AT91SAM7S256__ -g3 -gdwarf-2 -fverbose-asm -Iexamples/test -Ibertos/cpu/arm +armtest_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_rom.ld -Wl,--no-warn-mismatch + +armtest_CPU = arm7tdmi + diff --git a/examples/test/avrtest.mk b/examples/test/avrtest.mk new file mode 100644 index 00000000..dc72d83e --- /dev/null +++ b/examples/test/avrtest.mk @@ -0,0 +1,32 @@ +# +# $Id: avrtest.mk,v 1.3 2006/06/12 21:37:02 marco Exp $ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib avrtest application. +# +# Author: Bernie Innocenti +# + + + +# Set to 1 for debug builds +avrtest_DEBUG = 1 + +# Our target application +TRG += avrtest + +avrtest_MCU = atmega64 + +#include avr c and asm sources +include examples/test/avr_src.mk + +avrtest_CSRC = $(avr_CSRC) examples/test/empty_main.c + +avrtest_CPPASRC = $(avr_ASRC) + +avrtest_PCSRC += bertos/mware/formatwr.c + +avrtest_CROSS = avr- +avrtest_CPPFLAGS = -D'ARCH=ARCH_NIGHTTEST' -Iexamples/test -Ibertos/cpu/avr +avrtest_CFLAGS = -Os -mcall-prologues -fno-strict-aliasing diff --git a/examples/test/empty_main.c b/examples/test/empty_main.c new file mode 100644 index 00000000..66a8e4ad --- /dev/null +++ b/examples/test/empty_main.c @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + +int main(void) +{ + for(;;) + { + } + + return 0; +} diff --git a/examples/triface/boot/boot.ld b/examples/triface/boot/boot.ld new file mode 100644 index 00000000..733f1e99 --- /dev/null +++ b/examples/triface/boot/boot.ld @@ -0,0 +1,170 @@ +/* Linker script for boot loader */ + +OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr") +OUTPUT_ARCH(avr:5) +MEMORY +{ + text (rx) : ORIGIN = 0xE000, LENGTH = 8K + data (rw!x) : ORIGIN = 0x800060, LENGTH = 4000 + eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 2K +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.text : + { + *(.rel.text) + *(.rel.text.*) + *(.rel.gnu.linkonce.t*) + } + .rela.text : + { + *(.rela.text) + *(.rela.text.*) + *(.rela.gnu.linkonce.t*) + } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.rodata : + { + *(.rel.rodata) + *(.rel.rodata.*) + *(.rel.gnu.linkonce.r*) + } + .rela.rodata : + { + *(.rela.rodata) + *(.rela.rodata.*) + *(.rela.gnu.linkonce.r*) + } + .rel.data : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.gnu.linkonce.d*) + } + .rela.data : + { + *(.rela.data) + *(.rela.data.*) + *(.rela.gnu.linkonce.d*) + } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + /* Internal text space or external memory */ + .text : + { + KEEP(*(.vectors)) + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + *(.progmem.gcc*) + *(.progmem*) + . = ALIGN(2); + KEEP(*(.init0)) /* Start here after reset. */ + KEEP(*(.init1)) + KEEP(*(.init2)) /* Clear __zero_reg__, set up stack pointer. */ + KEEP(*(.init3)) + KEEP(*(.init4)) /* Initialize data and BSS. */ + KEEP(*(.init5)) + KEEP(*(.init6)) /* C++ constructors. */ + KEEP(*(.init7)) + KEEP(*(.init8)) + KEEP(*(.init9)) /* Call main(). */ + *(.text) + . = ALIGN(2); + *(.text.*) + . = ALIGN(2); + *(.fini9) /* _exit() starts here. */ + *(.fini8) + *(.fini7) + *(.fini6) /* C++ destructors. */ + *(.fini5) + *(.fini4) + *(.fini3) + *(.fini2) + *(.fini1) + *(.fini0) /* Infinite loop after program termination. */ + _etext = . ; + } > text + .data : AT (ADDR (.text) + SIZEOF (.text)) + { + PROVIDE (__data_start = .) ; + *(.data .data.* .rodata .rodata.*) + *(.gnu.linkonce.d*) + . = ALIGN(2); + _edata = . ; + PROVIDE (__data_end = .) ; + } > data + .bss SIZEOF(.data) + ADDR(.data) : + { + PROVIDE (__bss_start = .) ; + *(.bss .bss.*) + *(COMMON) + PROVIDE (__bss_end = .) ; + } > data + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + /* Global data not cleared after reset. */ + .noinit SIZEOF(.bss) + ADDR(.bss) : + { + PROVIDE (__noinit_start = .) ; + *(.noinit*) + PROVIDE (__noinit_end = .) ; + _end = . ; + PROVIDE (__heap_start = .) ; + } > data + .eeprom : + AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.data)) + { + *(.eeprom*) + __eeprom_end = . ; + } > eeprom + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/examples/triface/boot/cfg/cfg_arch.h b/examples/triface/boot/cfg/cfg_arch.h new file mode 100644 index 00000000..0956196a --- /dev/null +++ b/examples/triface/boot/cfg/cfg_arch.h @@ -0,0 +1,57 @@ +/** + * \file + * + * + * \brief Set system configuration + * + * \version $Id$ + * + * \author Bernie Innocenti + * + */ + + +#ifndef CFG_ARCH_CONFIG_H +#define CFG_ARCH_CONFIG_H + +#include + +/** + * \name Architectures + * \{ + */ +#define ARCH_TRIFACE BV(0) +#define ARCH_BOOT BV(1) +#define ARCH_EMUL BV(2) +/*\}*/ + +#endif /* CFG_ARCH_CONFIG_H */ diff --git a/examples/triface/boot/cfg/cfg_boot.h b/examples/triface/boot/cfg/cfg_boot.h new file mode 100644 index 00000000..72deb0c7 --- /dev/null +++ b/examples/triface/boot/cfg/cfg_boot.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Configuration file for boot module. + * + * \version $Id$ + * + * \author Manuele Fanelli + */ + +#ifndef CFG_BOOT_H +#define CFG_BOOT_H + +#define CONFIG_SER_HOSTPORT 1 ///< Triface comunication host port + +#define CONFIG_SER_HOSTPORTBAUDRATE 115200 ///< Serial host port baudrate + +#endif /* CFG_BOOT_H */ diff --git a/examples/triface/boot/cfg/cfg_formatwr.h b/examples/triface/boot/cfg/cfg_formatwr.h new file mode 100644 index 00000000..91c992ab --- /dev/null +++ b/examples/triface/boot/cfg/cfg_formatwr.h @@ -0,0 +1,56 @@ +/** + * \file + * + * + * \brief Configuration file for formatted write module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_FORMTWR_H +#define CFG_FORMTWR_H + +/** + * printf()-style formatter configuration. + * + * \sa PRINTF_DISABLED + * \sa PRINTF_NOMODIFIERS + * \sa PRINTF_REDUCED + * \sa PRINTF_NOFLOAT + * \sa PRINTF_FULL + */ +#define CONFIG_PRINTF PRINTF_REDUCED + + +#endif /* CFG_FORMTWR_H */ + diff --git a/examples/triface/boot/cfg/cfg_kern.h b/examples/triface/boot/cfg/cfg_kern.h new file mode 100644 index 00000000..78031e3e --- /dev/null +++ b/examples/triface/boot/cfg/cfg_kern.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \version $Id$ + * \author Bernie Innocenti + */ + +#ifndef CFG_KERN_H +#define CFG_KERN_H + +/** + * Enable the multithreading kernel. + */ +#define CONFIG_KERN 0 + +/** + * \name Optional kernel features + * \{ + */ +#define CONFIG_KERN_SCHED 0 ///< Process schedling +#define CONFIG_KERN_SIGNALS 0 ///< Inter-process signals +#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor +#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation +#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives +#define CONFIG_KERN_MONITOR 0 ///< Process monitor +#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling +#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy +/*\}*/ + +/// [ms] Time sharing quantum (a prime number prevents interference effects) +#define CONFIG_KERN_QUANTUM 47 + +/// Module logging level. +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/// Module logging format. +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_KERN_H */ diff --git a/examples/triface/boot/cfg/cfg_kfile.h b/examples/triface/boot/cfg/cfg_kfile.h new file mode 100644 index 00000000..e4f13b25 --- /dev/null +++ b/examples/triface/boot/cfg/cfg_kfile.h @@ -0,0 +1,51 @@ +/** + * \file + * + * + * \brief Configuration file for KFile interface module. + * + * \version $Id$ + * \author Daniele Basile + */ + +#ifndef CFG_KFILE_H +#define CFG_KFILE_H + +/// Module logging level definition. +#define KFILE_LOG_LEVEL LOG_LVL_INFO + +/// Module logging verbosity. +#define KFILE_LOG_FORMAT LOG_FMT_TERSE + +/// Enable the gets function with echo. +#define CONFIG_KFILE_GETS 1 + +#endif /* CFG_KFILE_H */ diff --git a/examples/triface/boot/cfg/cfg_ser.h b/examples/triface/boot/cfg/cfg_ser.h new file mode 100644 index 00000000..eb11a4cb --- /dev/null +++ b/examples/triface/boot/cfg/cfg_ser.h @@ -0,0 +1,118 @@ +/** + * \file + * + * + * \brief Configuration file for serial module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_SER_H +#define CFG_SER_H + + +/// Kdebug console on debug unit +#define CONFIG_TRIFACE_PORT 0 + +/// Baud-rate for the kdebug console +#define CONFIG_TRIFACE_BAUDRATE 115200 + +/// [bytes] Size of the outbound FIFO buffer for port 0. +#define CONFIG_UART0_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for port 0. +#define CONFIG_UART0_RXBUFSIZE 64 + +/// [bytes] Size of the outbound FIFO buffer for port 1. +#define CONFIG_UART1_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for port 1. +#define CONFIG_UART1_RXBUFSIZE 64 + + +/// [bytes] Size of the outbound FIFO buffer for SPI port (AVR only) +#define CONFIG_SPI_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port (AVR only) +#define CONFIG_SPI_RXBUFSIZE 32 + +/// [bytes] Size of the outbound FIFO buffer for SPI port 0. +#define CONFIG_SPI0_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port 0. +#define CONFIG_SPI0_RXBUFSIZE 32 + +/// [bytes] Size of the outbound FIFO buffer for SPI port 1. +#define CONFIG_SPI1_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port 1. +#define CONFIG_SPI1_RXBUFSIZE 32 + +/// SPI data order (AVR only). +#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST + +/// SPI clock division factor (AVR only). +#define CONFIG_SPI_CLOCK_DIV 16 + +/// SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). +#define CONFIG_SPI_CLOCK_POL 0 + +/// SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). +#define CONFIG_SPI_CLOCK_PHASE 0 + +/// Default transmit timeout (ms). Set to -1 to disable timeout support. +#define CONFIG_SER_TXTIMEOUT 100 + +/// Default receive timeout (ms). Set to -1 to disable timeout support. +#define CONFIG_SER_RXTIMEOUT 100 + +/// Use RTS/CTS handshake +#define CONFIG_SER_HWHANDSHAKE 0 + +/// Default baud rate (set to 0 to disable). +#define CONFIG_SER_DEFBAUDRATE 0 + +/// Enable second serial port in emulator. +#define CONFIG_EMUL_UART1 0 + +/** + * Transmit always something on serial port 0 TX + * to avoid interference when sending burst of data, + * using AVR multiprocessor serial mode + */ +#define CONFIG_SER_TXFILL 0 + +/// For serial debug. +#define CONFIG_SER_STROBE 0 + +#endif /* CFG_SER_H */ diff --git a/examples/triface/boot/hw/hw_boot.h b/examples/triface/boot/hw/hw_boot.h new file mode 100644 index 00000000..fa9bff4a --- /dev/null +++ b/examples/triface/boot/hw/hw_boot.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Macro for boot loader. + * + * + * \version $Id$ + * + * \author Daniele Basile + * \author Francesco Sacchi + */ + +#ifndef HW_BOOT_H +#define HW_BOOT_H + +#include + +/* Set up function pointer to RESET vector */ +void (*rom_start)(void) NORETURN = 0x0000; + +#define START_APP() rom_start() + +#define BOOT_INIT do \ +{ \ + /* Enable change of Interrupt Vectors */ \ + MCUCR = BV(IVCE); \ + /* Move interrupts to boot Flash section */ \ + MCUCR = BV(IVSEL); \ +} while(0) + +#define BOOT_END do \ +{ \ + /* Enable change of Interrupt Vectors */ \ + MCUCR = BV(IVCE); \ + /* Move interrupts to boot Flash section */ \ + MCUCR = 0; \ +} while(0) + +#endif // HW_BOOT_H + diff --git a/examples/triface/boot/hw/hw_cpu.h b/examples/triface/boot/hw/hw_cpu.h new file mode 100644 index 00000000..840c82c3 --- /dev/null +++ b/examples/triface/boot/hw/hw_cpu.h @@ -0,0 +1,56 @@ +/** + * \file + * Rights Reserved. + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Bernie Innocenti + */ + +#ifndef TRIFACE_HW_H +#define TRIFACE_HW_H + +/// CPU Clock frequency (14.7456 MHz) +#define CLOCK_FREQ (14745600UL) + + +/* Timer IRQ strobe */ +//#if CONFIG_TIMER_STROBE +// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) +// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) +// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) +//#endif /* CONFIG_TIMER_STROBE */ + +#endif /* TRIFACE_HW_H */ + diff --git a/examples/triface/boot/hw/hw_ser.h b/examples/triface/boot/hw/hw_ser.h new file mode 100644 index 00000000..21451b6c --- /dev/null +++ b/examples/triface/boot/hw/hw_ser.h @@ -0,0 +1,45 @@ +/** + * \file + * + * + * \brief Serial hardware-specific definitions + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef HW_SER_H +#define HW_SER_H + + + +#endif /* HW_SER_H */ diff --git a/examples/triface/boot/main.c b/examples/triface/boot/main.c new file mode 100644 index 00000000..dc105baf --- /dev/null +++ b/examples/triface/boot/main.c @@ -0,0 +1,97 @@ +/** + * \file + * + * + * \brief Flash boot loader main. + * This is a simple generic bootloader app. + * It requires only a serial port to work. + * Try to receive a file through XMODEM protocol + * and flash it on program memory. + * BOOT_INIT, BOOT_END are macros used to perform special operations + * respectively at boot start and boot end and are CPU dependant. + * The macro START_APP() jumps to main application start. + * + * \version $Id$ + * \author Stefano Fedrigo + * \author Francesco Sacchi + * \author Daniele Basile + */ + +#include +#include +#include +#include /* BV() */ + +#include +#include +#include +#include + +#include "hw/hw_boot.h" +#include "cfg/cfg_boot.h" + +#include + +int main(void) +{ + FlashAvr flash; + Serial ser; + + + // Set up flash programming functions. + flash_avr_init(&flash); + + IRQ_ENABLE; + + BOOT_INIT; + + kdbg_init(); + timer_init(); + + + /* Open the main communication port */ + + ser_init(&ser, CONFIG_SER_HOSTPORT); + ser_setbaudrate(&ser, CONFIG_SER_HOSTPORTBAUDRATE); + + xmodem_recv(&ser, &flash.fd); + kfile_close(&flash.fd); + kfile_close(&ser.fd); + + IRQ_DISABLE; + + BOOT_END; + + START_APP(); + +} + diff --git a/examples/triface/cfg/cfg_arch.h b/examples/triface/cfg/cfg_arch.h new file mode 100644 index 00000000..0956196a --- /dev/null +++ b/examples/triface/cfg/cfg_arch.h @@ -0,0 +1,57 @@ +/** + * \file + * + * + * \brief Set system configuration + * + * \version $Id$ + * + * \author Bernie Innocenti + * + */ + + +#ifndef CFG_ARCH_CONFIG_H +#define CFG_ARCH_CONFIG_H + +#include + +/** + * \name Architectures + * \{ + */ +#define ARCH_TRIFACE BV(0) +#define ARCH_BOOT BV(1) +#define ARCH_EMUL BV(2) +/*\}*/ + +#endif /* CFG_ARCH_CONFIG_H */ diff --git a/examples/triface/cfg/cfg_debug.h b/examples/triface/cfg/cfg_debug.h new file mode 100644 index 00000000..a7c548a9 --- /dev/null +++ b/examples/triface/cfg/cfg_debug.h @@ -0,0 +1,49 @@ +/** + * \file + * + * + * \brief Configuration file for Debug module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_DEBUG_H +#define CFG_DEBUG_H + +/// kdebug console. +#define CONFIG_KDEBUG_PORT 1 + +/// Baud-rate for the kdebug console. +#define CONFIG_KDEBUG_BAUDRATE 115200 + +#endif /* CFG_DEBUG_H */ diff --git a/examples/triface/cfg/cfg_kern.h b/examples/triface/cfg/cfg_kern.h new file mode 100644 index 00000000..78031e3e --- /dev/null +++ b/examples/triface/cfg/cfg_kern.h @@ -0,0 +1,70 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \version $Id$ + * \author Bernie Innocenti + */ + +#ifndef CFG_KERN_H +#define CFG_KERN_H + +/** + * Enable the multithreading kernel. + */ +#define CONFIG_KERN 0 + +/** + * \name Optional kernel features + * \{ + */ +#define CONFIG_KERN_SCHED 0 ///< Process schedling +#define CONFIG_KERN_SIGNALS 0 ///< Inter-process signals +#define CONFIG_KERN_IRQ 0 ///< Interrupt supervisor +#define CONFIG_KERN_HEAP 0 ///< Dynamic memory allocation +#define CONFIG_KERN_SEMAPHORES 0 ///< Re-entrant mutual exclusion primitives +#define CONFIG_KERN_MONITOR 0 ///< Process monitor +#define CONFIG_KERN_PREEMPT 0 ///< Preemptive process scheduling +#define CONFIG_KERN_PRI 0 ///< Priority-based scheduling policy +/*\}*/ + +/// [ms] Time sharing quantum (a prime number prevents interference effects) +#define CONFIG_KERN_QUANTUM 47 + +/// Module logging level. +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/// Module logging format. +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_KERN_H */ diff --git a/examples/triface/cfg/cfg_kfile.h b/examples/triface/cfg/cfg_kfile.h new file mode 100644 index 00000000..10bb72db --- /dev/null +++ b/examples/triface/cfg/cfg_kfile.h @@ -0,0 +1,51 @@ +/** + * \file + * + * + * \brief Configuration file for KFile interface module. + * + * \version $Id$ + * \author Daniele Basile + */ + +#ifndef CFG_KFILE_H +#define CFG_KFILE_H + +/// Module logging level definition. +#define KFILE_LOG_LEVEL LOG_LVL_INFO + +/// Module logging format. +#define KFILE_LOG_FORMAT LOG_FMT_TERSE + +/// Enable the gets function with echo. +#define CONFIG_KFILE_GETS 1 + +#endif /* CFG_KFILE_H */ diff --git a/examples/triface/cfg/cfg_ser.h b/examples/triface/cfg/cfg_ser.h new file mode 100644 index 00000000..c474c890 --- /dev/null +++ b/examples/triface/cfg/cfg_ser.h @@ -0,0 +1,122 @@ +/** + * \file + * + * + * \brief Configuration file for serial module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_SER_H +#define CFG_SER_H + + +/// Kdebug console on debug unit +#define CONFIG_TRIFACE_PORT 1 + +/// Baud-rate for the kdebug console +#define CONFIG_TRIFACE_BAUDRATE 115200 +/// Triface serial tag port +#define TAG_SER_PORT 0 +///Baud-rate for triface serial tag port +#define TAG_SER_BAUDRATE 9600 + +/// [bytes] Size of the outbound FIFO buffer for port 0. +#define CONFIG_UART0_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for port 0. +#define CONFIG_UART0_RXBUFSIZE 64 + +/// [bytes] Size of the outbound FIFO buffer for port 1. +#define CONFIG_UART1_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for port 1. +#define CONFIG_UART1_RXBUFSIZE 64 + + +/// [bytes] Size of the outbound FIFO buffer for SPI port (AVR only) +#define CONFIG_SPI_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port (AVR only) +#define CONFIG_SPI_RXBUFSIZE 32 + +/// [bytes] Size of the outbound FIFO buffer for SPI port 0. +#define CONFIG_SPI0_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port 0. +#define CONFIG_SPI0_RXBUFSIZE 32 + +/// [bytes] Size of the outbound FIFO buffer for SPI port 1. +#define CONFIG_SPI1_TXBUFSIZE 32 + +/// [bytes] Size of the inbound FIFO buffer for SPI port 1. +#define CONFIG_SPI1_RXBUFSIZE 32 + +/// SPI data order (AVR only). +#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST + +/// SPI clock division factor (AVR only). +#define CONFIG_SPI_CLOCK_DIV 16 + +/// SPI clock polarity: 0 = normal low, 1 = normal high (AVR only). +#define CONFIG_SPI_CLOCK_POL 0 + +/// SPI clock phase: 0 = sample on first edge, 1 = sample on second clock edge (AVR only). +#define CONFIG_SPI_CLOCK_PHASE 0 + +/// Default transmit timeout (ms). Set to -1 for infinite timeout, 0 for null timeout +#define CONFIG_SER_TXTIMEOUT 0 + +/// Default receive timeout (ms). Set to -1 for infinite timeout, 0 for null timeout +#define CONFIG_SER_RXTIMEOUT 0 + +/// Use RTS/CTS handshake +#define CONFIG_SER_HWHANDSHAKE 0 + +/// Default baud rate (set to 0 to disable). +#define CONFIG_SER_DEFBAUDRATE 0 + +/// Enable second serial port in emulator. +#define CONFIG_EMUL_UART1 0 + +/** + * Transmit always something on serial port 0 TX + * to avoid interference when sending burst of data, + * using AVR multiprocessor serial mode + */ +#define CONFIG_SER_TXFILL 0 + +/// For serial debug. +#define CONFIG_SER_STROBE 0 + +#endif /* CFG_SER_H */ diff --git a/examples/triface/cfg/cfg_wdt.h b/examples/triface/cfg/cfg_wdt.h new file mode 100644 index 00000000..8404dbd2 --- /dev/null +++ b/examples/triface/cfg/cfg_wdt.h @@ -0,0 +1,48 @@ +/** + * \file + * + * + * \brief Configuration file for watchdog module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_WDT_H +#define CFG_WDT_H + +/// Enable watchdog timer. +#define CONFIG_WATCHDOG 1 + +#endif /* CFG_WDT_H */ + + diff --git a/examples/triface/cmd_ctor.h b/examples/triface/cmd_ctor.h new file mode 100644 index 00000000..bf073f1e --- /dev/null +++ b/examples/triface/cmd_ctor.h @@ -0,0 +1,62 @@ +/** + * \file + * + * + * \brief Macro for defining command for protocol. + * + * + * \version $Id$ + * + * \author Marco Benelli + */ + +#ifndef CMD_CTOR_H +#define CMD_CTOR_H + +#include + +#define REGISTER_FUNCTION parser_register_cmd + +#define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) + +#define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \ +const struct CmdTemplate cmd_ ## NAME ## _template = \ +{ \ + #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \ +}; + +#define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \ +static ResultCode cmd_ ## NAME (parms *args) \ +{ \ + return (ResultCode)BODY; \ +} \ +MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) + +#endif // CMD_CTOR_H diff --git a/examples/triface/doc/PROTOCOL b/examples/triface/doc/PROTOCOL new file mode 100644 index 00000000..defc38d5 --- /dev/null +++ b/examples/triface/doc/PROTOCOL @@ -0,0 +1,84 @@ + +Command format: + + ... + +Where: + command - alphanumeric command name + argN - numeric argument (unsigned base 10, 0-65535) + +Positive response format: + + 0... + +Where: + argN - numeric value (unsigned base 10, 0-65535) + +Negative response format: + + -N"" + +Where: + -N - numeric error code (negative number) + desc - verbose error description + +# Write digital outputs (masked) +> dout 120 240 +< 0 + +# Read digital inputs +> din +< 0 125 + +# Read analog inputs +> ain +< 0 32 121 35 31 + +# Wait specified amount of milliseconds +> sleep 300 +< 0 + +# Return firmware major version, minor version and revision +> vers +< 0 1 42 0 + +# Reset board +< reset +> 0 + +# Ping/nop +< ping +> 0 + +# NOP (empty command) +> +< (ignored) + +# Comments +> # foo bar foobar +< (ignored) + +# Unknown command +> sing +< -1 "Unknown command" + +# Missing parameter +> dout +< -2 "Required parameter missing" + +# Too many parameters +> din 42 666 +< -3 "Too many parameters" + +# Malformed command +> dout %'I! +< -4 "Invalid parameter" + +# Attention +> or +< 1 "Uh?" + + +To recover from a possibly unknown board status, +a client should begin the conversation by issuing +an attention sequence, eventually followed by a reset. diff --git a/examples/triface/doc/schematics/TRIFACE.DSN b/examples/triface/doc/schematics/TRIFACE.DSN new file mode 100644 index 00000000..d18fa84b Binary files /dev/null and b/examples/triface/doc/schematics/TRIFACE.DSN differ diff --git a/examples/triface/doc/schematics/triface.opj b/examples/triface/doc/schematics/triface.opj new file mode 100644 index 00000000..79f75bb3 --- /dev/null +++ b/examples/triface/doc/schematics/triface.opj @@ -0,0 +1,36 @@ +(ExpressProject "triface" + (ProjectVersion "19981106") + (ProjectType "PCB") + (Folder "Design Resources" + (Folder "Library") + (NoModify) + (File ".\triface.dsn" + (Type "Schematic Design")) + (BuildFileAddedOrDeleted "x") + (CompileFileAddedOrDeleted "x") + (ANNOTATE_Scope "0") + (ANNOTATE_Mode "1") + (ANNOTATE_Action "0") + (Annotate_Page_Order "0") + (ANNOTATE_Reset_References_to_1 "FALSE") + (ANNOTATE_No_Page_Number_Change "FALSE") + (ANNOTATE_Property_Combine "{Value}{Source Package}{POWER_GROUP}") + (ANNOTATE_IncludeNonPrimitive "FALSE")) + (Folder "Outputs") + (Folder "Referenced Projects") + (PartMRUSelector) + (GlobalState + (FileView + (Path "Design Resources") + (Path "Design Resources" + "c:\documents and settings\administrator\desktop\new triface\triface.dsn") + (Path "Design Resources" + "c:\documents and settings\administrator\desktop\new triface\triface.dsn" + "TRIFACE BOARD")) + (HierarchyView) + (Doc + (Type "COrCapturePMDoc") + (Frame + (Placement "44 2 3 -1 -1 -4 -23 214 743 2 443")) + (Tab 0))) + (MPSSessionName "Administrator")) diff --git a/examples/triface/hw/hw_adc.c b/examples/triface/hw/hw_adc.c new file mode 100644 index 00000000..8c603eb8 --- /dev/null +++ b/examples/triface/hw/hw_adc.c @@ -0,0 +1,109 @@ +/** + * \file + * + * + * \brief ADC: Analogic to Digital Converter + * + * + * \version $Id$ + * + * \author Andrea Grandi + */ + +#include "hw/hw_adc.h" + + +#include + +#include + +#include + +/** Set the active AI channel */ +void adc_set_active_ain(int ai) +{ + /* If number of channels is <= 4 we use the first two MUX bits */ + STATIC_ASSERT(ADC_CHANNEL_NUM <= 4); + + ai &= BV(0) | BV(1); + ADMUX &= ~BV(MUX0); + ADMUX &= ~BV(MUX1); + ADMUX |= ai; +} + +/** Initialize the ADC */ +void adc_init(void) +{ + /* Set analog IN as input */ + DDRF &= ~(BV(PF0) | BV(PF1) | BV(PF2) | BV(PF3)); + + /* Disable pull-up */ + PORTF &= ~(BV(PF0) | BV(PF1) | BV(PF2) | BV(PF3)); + + ENABLE_ADC; + adc_set_vref_avcc(); + SET_AI_ADLAR; + + /* Set the Division Factor to 128 */ + ADCSRA |= (BV(ADPS0) | BV(ADPS1) | BV(ADPS2)); +} + +/** Set the initial reference */ +void adc_set_vref_avcc(void) +{ + ADMUX &= ~BV(REFS1); + ADMUX |= BV(REFS0); +} + +/** Read the specified AI channel */ +int adc_read_ai_channel(int channel) +{ + adc_set_active_ain(channel); + timer_udelay(STABILIZING_AI_CHANNEL_TIME); + START_CONVERTION; + + while(ADCSRA & BV(ADSC)) + { + /* + * Intentionally empty loop. + * It waits the convertion to be completed by ADC + */ + } + + ADCSRA |= BV(ADIF); + + uint16_t val; + val = ADCL; + val |= (uint16_t)ADCH << 8; + + return val; +} diff --git a/examples/triface/hw/hw_adc.h b/examples/triface/hw/hw_adc.h new file mode 100644 index 00000000..817b190c --- /dev/null +++ b/examples/triface/hw/hw_adc.h @@ -0,0 +1,63 @@ +/** + * \file + * ght 2006 Develer S.r.l. (http://www.develer.com/) + * + * \brief Macro for HW_AIN_H + * + * + * \version $Id$ + * + * \author Andrea Grandi + */ + +#ifndef HW_ADC_H +#define HW_ADC_H + +#include + +#define START_CONVERTION (ADCSRA |= BV(ADSC)) +#define ENABLE_ADC (ADCSRA |= BV(ADEN)) +#define SET_AI_ADLAR (ADMUX &= ~BV(ADLAR)) + +/** Microseconds to wait before starting conversion after changing a channel */ +#define STABILIZING_AI_CHANNEL_TIME 125 + +/** Number of AIN channels */ +#define ADC_CHANNEL_NUM 4 + +void adc_set_active_ain(int ai); +void adc_init(void); +void adc_set_vref_avcc(void); +int adc_read_ai_channel(int channel); + +#endif // HW_ADC_H + diff --git a/examples/triface/hw/hw_buzzer.h b/examples/triface/hw/hw_buzzer.h new file mode 100644 index 00000000..c3cc6d36 --- /dev/null +++ b/examples/triface/hw/hw_buzzer.h @@ -0,0 +1,55 @@ +/** + * \file + * + * + * \brief Buzzer hardware-specific definitions + * + * \version $Id$ + * + * \author Francesco Sacchi + * Andrea Grandi + */ + +#ifndef HW_BUZZER_H +#define HW_BUZZER_H + +#include +#include + +#define BUZZER_BIT BV(PE3) +#define IS_BUZZER_ON (PORTE & BUZZER_BIT) +#define BUZZER_HW_INIT do { DDRE |= BV(DDE3); } while (0) +#define BUZZER_ON do { PORTE |= BUZZER_BIT; } while (0) +#define BUZZER_OFF do { PORTE &= ~BUZZER_BIT; } while (0) + +#endif /* HW_BUZZER_H */ + diff --git a/examples/triface/hw/hw_cpu.h b/examples/triface/hw/hw_cpu.h new file mode 100644 index 00000000..840c82c3 --- /dev/null +++ b/examples/triface/hw/hw_cpu.h @@ -0,0 +1,56 @@ +/** + * \file + * Rights Reserved. + * + * \brief Hardware-specific definitions + * + * \version $Id$ + * + * \author Bernie Innocenti + */ + +#ifndef TRIFACE_HW_H +#define TRIFACE_HW_H + +/// CPU Clock frequency (14.7456 MHz) +#define CLOCK_FREQ (14745600UL) + + +/* Timer IRQ strobe */ +//#if CONFIG_TIMER_STROBE +// #define TIMER_STROBE_ON ATOMIC(PORTD |= BV(PD0)) +// #define TIMER_STROBE_OFF ATOMIC(PORTD &= ~BV(PD0)) +// #define TIMER_STROBE_INIT ATOMIC(PORTD &= ~BV(PD0); DDRD |= BV(PD0)) +//#endif /* CONFIG_TIMER_STROBE */ + +#endif /* TRIFACE_HW_H */ + diff --git a/examples/triface/hw/hw_input.h b/examples/triface/hw/hw_input.h new file mode 100644 index 00000000..e3dcf1c4 --- /dev/null +++ b/examples/triface/hw/hw_input.h @@ -0,0 +1,74 @@ +/** + * \file + * + * + * \brief Macro for HW_INPUT_H + * + * + * \version $Id$ + * + * \author Andrea Grandi + */ + +#ifndef HW_INPUT_H +#define HW_INPUT_H + +#include + +/* Set pins as input and enable pull-up */ +#define INPUT_INIT_D do \ +{ \ + (DDRD &= ~(BV(PD4) | BV(PD5) | BV(PD6) | BV(PD7))); \ + (PORTD |= (BV(PD4) | BV(PD5) | BV(PD6) | BV(PD7))); \ +} while(0) + +#define INPUT_INIT_E do \ +{ \ + (DDRE &= ~(BV(PE4) | BV(PE5) | BV(PE6) | BV(PE7))); \ + ATOMIC((PORTE |= (BV(PE4) | BV(PE5) | BV(PE6) | BV(PE7)))); \ +} while(0) + +#define INPUT_INIT do { INPUT_INIT_D; INPUT_INIT_E;} while(0) + +INLINE uint8_t INPUT_GET(void) +{ + uint8_t out_d, out_e; + out_d = PIND; + out_e = PINE; + + out_d >>= 4; + out_e = out_e & 0xF0; + + return out_e | out_d; +} + +#endif // HW_INPUT_H diff --git a/examples/triface/hw/hw_ser.h b/examples/triface/hw/hw_ser.h new file mode 100644 index 00000000..e51824d5 --- /dev/null +++ b/examples/triface/hw/hw_ser.h @@ -0,0 +1,52 @@ +/** + * \file + * + * + * \brief Macro for STROBE signal + * + * \version $Id$ + * + * \author Manuele Fanelli + */ + +#ifndef HW_SER_H +#define HW_SER_H + +#include "cfg/cfg_ser.h" + +#if CONFIG_SER_STROBE + + #define SER_STROBE_ON do {PORTC |= BV(0);} while(0) + #define SER_STROBE_OFF do {PORTC &= ~BV(0);} while(0) + #define SER_STROBE_INIT do {DDRC |= BV(0); } while(0) +#endif + +#endif //HW_SER_H diff --git a/examples/triface/hw/hw_sipo.h b/examples/triface/hw/hw_sipo.h new file mode 100644 index 00000000..f41e35f9 --- /dev/null +++ b/examples/triface/hw/hw_sipo.h @@ -0,0 +1,59 @@ +/** + * \file + * + * + * \brief Macro for HW_SIPO_H + * + * + * \version $Id$ + * + * \author Andrea Grandi + */ +#ifndef HW_SIPO_H +#define HW_SIPO_H + +#define LOAD_HIGH (PORTB |= BV(PB3)) +#define LOAD_LOW (PORTB &= ~BV(PB3)) +#define LOAD_INIT (DDRB |= BV(PB3)) +#define SET_SCK_OUT (DDRB |= BV(PB1)) +#define SET_SOUT_OUT (DDRB |= BV(PB2)) +#define CLOCK_HIGH (PORTB |= BV(PB1)) +#define CLOCK_LOW (PORTB &= ~BV(PB1)) +#define SET_SOUT_HIGH (PORTB |= BV(PB2)) +#define SET_SOUT_LOW (PORTB &= ~BV(PB2)) +#define CLOCK_PULSE do { CLOCK_HIGH; CLOCK_LOW; } while(0) + +#define OE_OUT (DDRG |= BV(PG3)) +#define OE_LOW (PORTG &= BV(PG3)) + + +#endif // HW_SIPO_H diff --git a/examples/triface/protocol.c b/examples/triface/protocol.c new file mode 100644 index 00000000..fa4c0bad --- /dev/null +++ b/examples/triface/protocol.c @@ -0,0 +1,374 @@ +/** + * \file + * + * + * \brief Implementation of the command protocol between the board and the host + * + * + * \version $Id$ + * + * \author Giovanni Bajo + * \author Marco Benelli + * \author Bernie Innocenti + * \author Daniele Basile + */ + +#include "protocol.h" +#include "cmd_ctor.h" // MAKE_CMD, REGISTER_CMD +#include "verstag.h" +#include "hw/hw_adc.h" +#include "hw/hw_input.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include + +// Define the format string for ADC +#define ADC_FORMAT_STR "dddd" + +// DEBUG: set to 1 to force interactive mode +#define FORCE_INTERACTIVE 1 + +/** + * True if we are in interactive mode, false if we are in protocol mode. + * In interactive mode, commands are read through readline() (prompt, + * completion, history) without IDs, and replies/errors are sent to the serial + * output. + * In protocol mode, we implement the default protocol + */ +static bool interactive; + +/// Readline context, used for interactive mode. +static struct RLContext rl_ctx; + +uint8_t reg_status_dout; +/** + * Send a NAK asking the host to send the current message again. + * + * \a fd kfile handler for serial. + * \a err human-readable description of the error for debug purposes. + */ +INLINE void NAK(KFile *fd, const char *err) +{ +#ifdef _DEBUG + kfile_printf(fd, "NAK \"%s\"\r\n", err); +#else + kfile_printf(fd, "NAK\r\n"); +#endif +} + +static void protocol_prompt(KFile *fd) +{ + kfile_print(fd, ">> "); +} + +/* + * Print args on s, with format specified in t->result_fmt. + * Return number of valid arguments or -1 in case of error. + */ +static bool protocol_reply(KFile *fd, const struct CmdTemplate *t, + const parms *args) +{ + unsigned short offset = strlen(t->arg_fmt) + 1; + unsigned short nres = strlen(t->result_fmt); + + for (unsigned short i = 0; i < nres; ++i) + { + if (t->result_fmt[i] == 'd') + { + kfile_printf(fd, " %ld", args[offset+i].l); + } + else if (t->result_fmt[i] == 's') + { + kfile_printf(fd, " %s", args[offset+i].s); + } + + else + { + abort(); + } + } + kfile_printf(fd, "\r\n"); + return true; +} + +static void protocol_parse(KFile *fd, const char *buf) +{ + const struct CmdTemplate *templ; + + /* Command check. */ + templ = parser_get_cmd_template(buf); + if (!templ) + { + kfile_print(fd, "-1 Invalid command.\r\n"); + protocol_prompt(fd); + return; + } + + parms args[PARSER_MAX_ARGS]; + + /* Args Check. TODO: Handle different case. see doc/PROTOCOL . */ + if (!parser_get_cmd_arguments(buf, templ, args)) + { + kfile_print(fd, "-2 Invalid arguments.\r\n"); + protocol_prompt(fd); + return; + } + + /* Execute. */ + if(!parser_execute_cmd(templ, args)) + { + NAK(fd, "Error in executing command."); + } + if (!protocol_reply(fd, templ, args)) + { + NAK(fd, "Invalid return format."); + } + + protocol_prompt(fd); + return; +} + +void protocol_run(KFile *fd) +{ + /** + * \todo to be removed, we could probably access the serial FIFO + * directly + */ + static char linebuf[80]; + + if (!interactive) + { + kfile_gets(fd, linebuf, sizeof(linebuf)); + + // reset serial port error anyway + kfile_clearerr(fd); + + // check message minimum length + if (linebuf[0]) + { + /* If we enter lines beginning with sharp(#) + they are stripped out from commands */ + if(linebuf[0] != '#') + { + if (linebuf[0] == 0x1B && linebuf[1] == 0x1B) // ESC + { + interactive = true; + kfile_printf(fd, "Entering interactive mode\r\n"); + } + else + { + protocol_parse(fd, linebuf); + } + } + } + } + else + { + const char *buf; + + /* + * Read a line from serial. We use a temporary buffer + * because otherwise we would have to extract a message + * from the port immediately: there might not be any + * available, and one might get free while we read + * the line. We also add a fake ID at the start to + * fool the parser. + */ + buf = rl_readline(&rl_ctx); + + /* If we enter lines beginning with sharp(#) + they are stripped out from commands */ + if(buf && buf[0] != '#') + { + if (buf[0] != '\0') + { + // exit special case to immediately change serial input + if (!strcmp(buf, "exit") || !strcmp(buf, "quit")) + { + rl_clear_history(&rl_ctx); + kfile_printf(fd, "Leaving interactive mode...\r\n"); + interactive = FORCE_INTERACTIVE; + } + else + { + //TODO: remove sequence numbers + linebuf[0] = '0'; + linebuf[1] = ' '; + + strncpy(linebuf + 2, buf, sizeof(linebuf) - 3); + linebuf[sizeof(linebuf) - 1] = '\0'; + protocol_parse(fd, linebuf); + } + } + } + } +} + +/* + * Commands. + * TODO: Command declarations and definitions should be in another file(s). + * Maybe we should use CMD_HUNK_TEMPLATE. + * + */ + +MAKE_CMD(ver, "", "ddd", +({ + args[1].l = VERS_MAJOR; + args[2].l = VERS_MINOR; + args[3].l = VERS_REV; + 0; +}), 0); + +/* Sleep. Example of declaring function body directly in macro call. */ +MAKE_CMD(sleep, "d", "", +({ + timer_delay((mtime_t)args[1].l); + 0; +}), 0) + +/* Ping. */ +MAKE_CMD(ping, "", "", +({ + //Silence "args not used" warning. + (void)args; + 0; +}), 0) + +/* Dout */ +MAKE_CMD(dout, "d", "", +({ + sipo_putchar((uint8_t)args[1].l); + + //Store status of dout ports. + reg_status_dout = (uint8_t)args[1].l; + 0; +}), 0) + +/* rdout read the status of out ports.*/ +MAKE_CMD(rdout, "", "d", +({ + args[1].l = reg_status_dout; + 0; +}), 0) + + +/* Reset */ +MAKE_CMD(reset, "", "", +({ + //Silence "args not used" warning. + (void)args; + wdt_init(7); + wdt_start(); + + /*We want to have an infinite loop that lock access on watchdog timer. + This piece of code it's equivalent to a while(true), but we have done this because + gcc generate a warning message that suggest to use "noreturn" parameter in function reset.*/ + ASSERT(args); + while(args); + 0; + +}), 0) + +/* Din */ +MAKE_CMD(din, "", "d", +({ + args[1].l = INPUT_GET(); + 0; +}), 0) + + + +/* Ain */ +MAKE_CMD(ain, "", ADC_FORMAT_STR, +({ + STATIC_ASSERT((sizeof(ADC_FORMAT_STR) - 1) == ADC_CHANNEL_NUM); + for(int i = 0; i < ADC_CHANNEL_NUM; i++) + args[i+1].l = adc_read_ai_channel(i); + + 0; +}), 0) + +/* Beep */ +MAKE_CMD(beep, "d", "", +({ + buz_beep(args[1].l); + 0; +}), 0) + +/* Register commands. */ +static void protocol_registerCmds(void) +{ + REGISTER_CMD(ver); + REGISTER_CMD(sleep); + REGISTER_CMD(ping); + REGISTER_CMD(dout); + //Set off all dout ports. + reg_status_dout = 0; + REGISTER_CMD(rdout); + REGISTER_CMD(reset); + REGISTER_CMD(din); + REGISTER_CMD(ain); + REGISTER_CMD(beep); +} + +/* Initialization: readline context, parser and register commands. */ +void protocol_init(KFile *fd) +{ + interactive = FORCE_INTERACTIVE; + + rl_init_ctx(&rl_ctx); + //rl_setprompt(&rl_ctx, ">> "); + rl_sethook_get(&rl_ctx, (getc_hook)kfile_getc, fd); + rl_sethook_put(&rl_ctx, (putc_hook)kfile_putc, fd); + rl_sethook_match(&rl_ctx, parser_rl_match, NULL); + rl_sethook_clear(&rl_ctx, (clear_hook)kfile_clearerr,fd); + + parser_init(); + + protocol_registerCmds(); + + protocol_prompt(fd); +} diff --git a/examples/triface/protocol.h b/examples/triface/protocol.h new file mode 100644 index 00000000..26113482 --- /dev/null +++ b/examples/triface/protocol.h @@ -0,0 +1,50 @@ +/** + * \file + * + * + * \brief Implementation of the command protocol between the board and the host + * + * \version $Id$ + * + * \author Marco Benelli + */ + + +#ifndef PROTOCOL_H +#define PROTOCOL_H + +#include + +void protocol_init(KFile *fd); +void protocol_run(KFile *fd); + +#endif // PROTOOCOL_H diff --git a/examples/triface/triface.c b/examples/triface/triface.c new file mode 100644 index 00000000..86f21b2d --- /dev/null +++ b/examples/triface/triface.c @@ -0,0 +1,101 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Marco Benelli + * \author Bernie Innocenti + * \author Daniele Basile + * + * \brief Windowing system test. + */ + + +#include "protocol.h" +#include "hw/hw_input.h" +#include "hw/hw_adc.h" +#include "cfg/cfg_ser.h" + +#include + +#include +#include +#include +#include + +#include +#include + + + +static Serial fd_ser; +static Serial tag_ser; + +int main(void) +{ + /* SPI Port Initialization */ + sipo_init(); + + kdbg_init(); + timer_init(); + adc_init(); + buz_init(); + + IRQ_ENABLE; + INPUT_INIT; + + /* Initialize Tag serial port and data structure */ + TagPacket pkt; + + /* Open the main communication port */ + ser_init(&fd_ser, CONFIG_TRIFACE_PORT); + ser_setbaudrate(&fd_ser, CONFIG_TRIFACE_BAUDRATE); + + ser_init(&tag_ser, TAG_SER_PORT); + ser_setbaudrate(&tag_ser, TAG_SER_BAUDRATE); + + keytag_init(&pkt, &fd_ser.fd, &tag_ser.fd); + + protocol_init(&fd_ser.fd); + + // Main loop + for(;;) + { + protocol_run(&fd_ser.fd); + keytag_poll(&pkt); + } + + return 0; +} + + diff --git a/examples/triface/triface.mk b/examples/triface/triface.mk new file mode 100644 index 00000000..871f02d0 --- /dev/null +++ b/examples/triface/triface.mk @@ -0,0 +1,72 @@ +# +# $Id$ +# Copyright 2006 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Makefile fragment for DevLib triface application. +# +# Author: Bernie Innocenti +# +# + +# Set to 1 for debug builds +triface_DEBUG = 1 + +# Our target application +TRG += triface + +triface_hfuse = 0x88 +triface_lfuse = 0xff +triface_efuse = 0xff +triface_lock = 0x2f +triface_CSRC = \ + examples/triface/triface.c \ + examples/triface/protocol.c \ + examples/triface/hw/hw_adc.c \ + bertos/drv/timer.c \ + bertos/drv/ser.c \ + bertos/drv/buzzer.c \ + bertos/cpu/avr/drv/ser_avr.c \ + bertos/cpu/avr/drv/sipo.c \ + bertos/mware/formatwr.c \ + bertos/mware/hex.c \ + bertos/struct/hashtable.c \ + bertos/mware/readline.c \ + bertos/mware/parser.c \ + bertos/mware/event.c \ + bertos/kern/kfile.c \ + bertos/net/keytag.c \ + # + +triface_PCSRC += bertos/mware/formatwr.c + + +triface_CFLAGS = -O2 -D'ARCH=(ARCH_TRIFACE)' -fno-strict-aliasing -Iexamples/triface -Ibertos/cpu/avr +triface_LDFLAGS = -Wl + +triface_MCU = atmega64 +triface_CROSS = avr- + +# Set to 1 for debug builds +boot_DEBUG = 0 + +# Our target application +TRG += boot + +boot_MCU = atmega64 +boot_CSRC = \ + examples/triface/boot/main.c \ + bertos/net/xmodem.c \ + bertos/drv/ser.c \ + bertos/cpu/avr/drv/ser_avr.c \ + bertos/cpu/avr/drv/flash_avr.c \ + bertos/drv/timer.c \ + bertos/algo/crc.c \ + bertos/mware/hex.c \ + bertos/kern/kfile.c \ + # +boot_CROSS = avr- +boot_CPPFLAGS = -D'ARCH=(ARCH_TRIFACE|ARCH_BOOT)' -Iexamples/triface/boot -Ibertos/cpu/avr +boot_CFLAGS = -Os -mcall-prologues +boot_LDSCRIPT = examples/triface/boot/boot.ld +boot_LDFLAGS = -Wl,--relax diff --git a/examples/triface/verstag.h b/examples/triface/verstag.h new file mode 100644 index 00000000..cbe71278 --- /dev/null +++ b/examples/triface/verstag.h @@ -0,0 +1,95 @@ +/** + * \file + * + * + * \version $Id$ + * + * \author Bernie Innocenti + * + * \brief Declare application version strings + */ + +#ifndef BERTOS_VERSTAG_H +#define BERTOS_VERSTAG_H + +#ifndef CFG_ARCH_CONFIG_H + #include "cfg/cfg_arch.h" +#endif + +#define APP_NAME "Triface" +#define APP_DESCRIPTION "Trinity Interface Board" +#define APP_AUTHOR "Develer" +#define APP_COPYRIGHT "Copyright 2006, 2007, 2008, Develer (http://www.develer.com/)" + +#define VERS_MAJOR 2 +#define VERS_MINOR 1 +#define VERS_REV 0 +#define VERS_LETTER "" + +/** + * If _SNAPSHOT is defined, \c VERS_TAG contains the build date + * date instead of a numeric version string. + */ +//#define _SNAPSHOT + +#ifdef _DEBUG + #define VERS_DBG "D" +#else + #define VERS_DBG "" +#endif + +#define __STRINGIZE(x) #x +#define _STRINGIZE(x) __STRINGIZE(x) + +/** Build application version string (i.e.: "1.7.0") */ +#define MAKE_VERS(maj,min,rev) _STRINGIZE(maj) "." _STRINGIZE(min) "." _STRINGIZE(rev) VERS_LETTER VERS_DBG +#ifdef _SNAPSHOT + #define VERS_TAG "snapshot" " " __DATE__ " " __TIME__ " " VERS_LETTER " " VERS_DBG +#else + #define VERS_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) +#endif + +/** Build application version string suitable for MS windows resource files (i.e.: "1, 7, 0, 1") */ +#define MAKE_RCVERS(maj,min,rev,bld) _STRINGIZE(maj) ", " _STRINGIZE(min) ", " _STRINGIZE(rev) ", " _STRINGIZE(bld) +#define RCVERSION_TAG MAKE_VERS(VERS_MAJOR,VERS_MINOR,VERS_REV) + +/** The revision string (contains VERS_TAG) */ +extern const char vers_tag[]; + +/** Sequential build number (contains VERS_BUILD) */ +extern const int vers_build_nr; +//extern const char vers_build_str[]; + +/** Hostname of the machine used to build this binary (contains VERS_HOST) */ +extern const char vers_host[]; + +#endif /* BERTOS_VERSTAG_H */