From 676de7015522237793874ac6eb17a0264f06e86c Mon Sep 17 00:00:00 2001 From: asterix Date: Mon, 27 Apr 2009 09:43:02 +0000 Subject: [PATCH] Add at91sam7x bertos example. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2670 38d2e660-2303-0410-9eaa-f027e97ec537 --- examples/at91sam7x/at91sam7s.mk | 48 ++++++++ examples/at91sam7x/at91sam7x.c | 157 +++++++++++++++++++++++++++ examples/at91sam7x/at91sam7x.mk | 48 ++++++++ examples/at91sam7x/cfg/cfg_monitor.h | 48 ++++++++ examples/at91sam7x/cfg/cfg_proc.h | 100 +++++++++++++++++ examples/at91sam7x/cfg/cfg_sem.h | 48 ++++++++ examples/at91sam7x/cfg/cfg_ser.h | 107 ++++++++++++++++++ examples/at91sam7x/cfg/cfg_signal.h | 48 ++++++++ examples/at91sam7x/cfg/cfg_timer.h | 55 ++++++++++ examples/at91sam7x/hw/hw_ser.h | 40 +++++++ examples/at91sam7x/verstag.h | 94 ++++++++++++++++ 11 files changed, 793 insertions(+) create mode 100644 examples/at91sam7x/at91sam7s.mk create mode 100644 examples/at91sam7x/at91sam7x.c create mode 100644 examples/at91sam7x/at91sam7x.mk create mode 100644 examples/at91sam7x/cfg/cfg_monitor.h create mode 100644 examples/at91sam7x/cfg/cfg_proc.h create mode 100644 examples/at91sam7x/cfg/cfg_sem.h create mode 100644 examples/at91sam7x/cfg/cfg_ser.h create mode 100644 examples/at91sam7x/cfg/cfg_signal.h create mode 100644 examples/at91sam7x/cfg/cfg_timer.h create mode 100644 examples/at91sam7x/hw/hw_ser.h create mode 100644 examples/at91sam7x/verstag.h diff --git a/examples/at91sam7x/at91sam7s.mk b/examples/at91sam7x/at91sam7s.mk new file mode 100644 index 00000000..2a3bcfc8 --- /dev/null +++ b/examples/at91sam7x/at91sam7s.mk @@ -0,0 +1,48 @@ +# +# $Id: at91sam7x.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 at91sam7x application. +# +# Author: Bernie Innocenti +# +# + +# Set to 1 for debug builds +at91sam7x_DEBUG = 1 + +# Our target application +TRG += at91sam7x + +at91sam7x_CSRC = \ + examples/at91sam7x/at91sam7x.c \ + bertos/drv/timer.c \ + bertos/drv/ser.c \ + bertos/cpu/arm/drv/sysirq_at91.c \ + bertos/cpu/arm/drv/ser_at91.c \ + bertos/cpu/arm/drv/timer_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 \ + # + +at91sam7x_CPPASRC = \ + bertos/cpu/arm/hw/crtat91sam7_rom.S \ + bertos/cpu/arm/hw/switch_ctx_arm.S \ + # + +at91sam7x_PREFIX = arm-none-eabi- + +at91sam7x_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug +at91sam7x_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_AT91SAM7X256__ -D'CPU_FREQ=(48023000UL)' -D'WIZ_AUTOGEN' -g3 -gdwarf-2 -fverbose-asm -Iexamples/at91sam7x -Ibertos/cpu/arm +at91sam7x_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_rom.ld -Wl,--no-warn-mismatch + +at91sam7x_CPU = arm7tdmi + diff --git a/examples/at91sam7x/at91sam7x.c b/examples/at91sam7x/at91sam7x.c new file mode 100644 index 00000000..aaec740d --- /dev/null +++ b/examples/at91sam7x/at91sam7x.c @@ -0,0 +1,157 @@ +/** + * \file + * + * + * \version $Id: at91sam7s.c 2663 2009-04-24 16:30:11Z asterix $ + * + * \author Francesco Sacchi + * \author Daniele Basile + * + * \brief Simple BeRTOS test on AT91SAM7X-EK evaluation board. + * + * This short program shows you a simple demo of some BeRTOS feature: + * + * - Debug system + * - Timer interrupt + * - Serial + * - Cooperative BeRTOS Kernel + * + */ + +#include "cfg/cfg_ser.h" +#include + +#include + +#include +#include +#include + +#include + +Timer leds_timer; +Serial ser_fd; +int roll = 0; + +/* + * Supercar leds effect.. + */ +static void leds_toggle(void) +{ + uint32_t a = (~PIOB_ODSR & 0x780000); + + // Turn on led in forward direction + if (roll == 1) + { + if(a == 0x200000) + roll = 2; + + PIOB_SODR = a; + PIOB_CODR = a << 1; + } + // Turn on led in backward direction + else if (roll == 2) + { + if(a == 0x100000) + roll = 1; + + PIOB_SODR = a; + PIOB_CODR = a >> 1; + } + // Start to turn on first led + else + { + PIOB_SODR = 0x780000; + /* turn first led on */ + PIOB_CODR = 0x80000; + roll = 1; + } + + /* 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 */ + PIOB_PUDR = 0xffffffff; + /* Set PB0..3 connected to PIOA */ + PIOB_PER = 0x780000; + /* Set PB0..3 as output */ + PIOB_OER = 0x780000; + /* Disable multidrive on all pins */ + PIOB_MDDR = 0xffffffff; + + /* Set PA0..3 to 1 to turn off leds */ + PIOB_SODR = 0x780000; + + /* turn first led on */ + PIOB_CODR = 0x80000; + + /* + * Register timer and arm timer interupt. + */ + timer_setSoftint(&leds_timer, (Hook)leds_toggle, 0); + timer_setDelay(&leds_timer, ms_to_ticks(100)); + timer_add(&leds_timer); + + /* + * Run process test. + */ + if(!proc_testRun()) + kfile_printf(&ser_fd.fd, "ProcTest..ok!\n"); + else + kfile_printf(&ser_fd.fd, "ProcTest..FAIL!\n"); + + // Main loop + for(;;) + { + kfile_printf(&ser_fd.fd, "From serial 0: %s\r\n", msg); + } + return 0; +} diff --git a/examples/at91sam7x/at91sam7x.mk b/examples/at91sam7x/at91sam7x.mk new file mode 100644 index 00000000..2a3bcfc8 --- /dev/null +++ b/examples/at91sam7x/at91sam7x.mk @@ -0,0 +1,48 @@ +# +# $Id: at91sam7x.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 at91sam7x application. +# +# Author: Bernie Innocenti +# +# + +# Set to 1 for debug builds +at91sam7x_DEBUG = 1 + +# Our target application +TRG += at91sam7x + +at91sam7x_CSRC = \ + examples/at91sam7x/at91sam7x.c \ + bertos/drv/timer.c \ + bertos/drv/ser.c \ + bertos/cpu/arm/drv/sysirq_at91.c \ + bertos/cpu/arm/drv/ser_at91.c \ + bertos/cpu/arm/drv/timer_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 \ + # + +at91sam7x_CPPASRC = \ + bertos/cpu/arm/hw/crtat91sam7_rom.S \ + bertos/cpu/arm/hw/switch_ctx_arm.S \ + # + +at91sam7x_PREFIX = arm-none-eabi- + +at91sam7x_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug +at91sam7x_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_AT91SAM7X256__ -D'CPU_FREQ=(48023000UL)' -D'WIZ_AUTOGEN' -g3 -gdwarf-2 -fverbose-asm -Iexamples/at91sam7x -Ibertos/cpu/arm +at91sam7x_LDFLAGS = -nostartfiles -T bertos/cpu/arm/scripts/at91sam7_256_rom.ld -Wl,--no-warn-mismatch + +at91sam7x_CPU = arm7tdmi + diff --git a/examples/at91sam7x/cfg/cfg_monitor.h b/examples/at91sam7x/cfg/cfg_monitor.h new file mode 100644 index 00000000..5e97031e --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_monitor.h @@ -0,0 +1,48 @@ +/** + * \file + * + * + * \brief Kernel monitor configuration parameters + * + * \version $Id: cfg_monitor.h 2429 2009-03-25 16:30:24Z batt $ + * \author Bernie Innocenti + */ + +#ifndef CFG_MONITOR_H +#define CFG_MONITOR_H + +/** + * Process monitor. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_MONITOR 1 + +#endif /* CFG_MONITOR_H */ diff --git a/examples/at91sam7x/cfg/cfg_proc.h b/examples/at91sam7x/cfg/cfg_proc.h new file mode 100644 index 00000000..7f818f49 --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_proc.h @@ -0,0 +1,100 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \version $Id: cfg_proc.h 2659 2009-04-24 09:28:30Z batt $ + * \author Bernie Innocenti + */ + +#ifndef CFG_PROC_H +#define CFG_PROC_H + +/** + * Enable the multithreading kernel. + * + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN 1 + +/** + * Kernel interrupt supervisor. + * $WIZ$ type = "boolean" + */ +#define CONFIG_KERN_IRQ 0 + +/** + * Dynamic memory allocation for processes. + * + * $WIZ$ type = "boolean" + * $WIZ$ supports = "False" + */ +#define CONFIG_KERN_HEAP 0 + +/** + * Preemptive process scheduling. WARNING: Experimental, still incomplete! + * + * $WIZ$ type = "boolean" + */ +#define CONFIG_KERN_PREEMPT 0 + +/** + * Priority-based scheduling policy. + * $WIZ$ type = "boolean" + */ +#define CONFIG_KERN_PRI 0 + +/** + * Time sharing quantum (a prime number prevents interference effects) [ms]. + * + * $WIZ$ type = "int" + * $WIZ$ min = "0" + */ +#define CONFIG_KERN_QUANTUM 47 + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/** + * Module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_PROC_H */ diff --git a/examples/at91sam7x/cfg/cfg_sem.h b/examples/at91sam7x/cfg/cfg_sem.h new file mode 100644 index 00000000..6e3cfab7 --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_sem.h @@ -0,0 +1,48 @@ +/** + * \file + * + * + * \brief Kernel semaphores configuration parameters. + * + * \version $Id: cfg_sem.h 2429 2009-03-25 16:30:24Z batt $ + * \author Bernie Innocenti + */ + +#ifndef CFG_SEM_H +#define CFG_SEM_H + +/** + * Re-entrant mutual exclusion primitives. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_SEMAPHORES 1 + +#endif /* CFG_SEM_H */ diff --git a/examples/at91sam7x/cfg/cfg_ser.h b/examples/at91sam7x/cfg/cfg_ser.h new file mode 100644 index 00000000..a00ab85d --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_ser.h @@ -0,0 +1,107 @@ +/** + * \file + * + * + * \brief Configuration file for serial module. + * + * \version $Id: cfg_ser.h 2571 2009-04-20 10:37:07Z batt $ + * + * \author Daniele Basile + */ + +#ifndef CFG_SER_H +#define CFG_SER_H + +/** + * Example of setting for serial port and + * spi port. + * Edit these define for your project. + */ + +/// [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 32 + +/// [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 32 + + +/// [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 -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 + +/// For serial debug. +#define CONFIG_SER_STROBE 0 + +#endif /* CFG_SER_H */ diff --git a/examples/at91sam7x/cfg/cfg_signal.h b/examples/at91sam7x/cfg/cfg_signal.h new file mode 100644 index 00000000..86feb726 --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_signal.h @@ -0,0 +1,48 @@ +/** + * \file + * + * + * \brief Kernel signals configuration parameters + * + * \version $Id: cfg_signal.h 2429 2009-03-25 16:30:24Z batt $ + * \author Bernie Innocenti + */ + +#ifndef CFG_SIGNAL_H +#define CFG_SIGNAL_H + +/** + * Inter-process signals. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_SIGNALS 1 + +#endif /* CFG_SIGNAL_H */ diff --git a/examples/at91sam7x/cfg/cfg_timer.h b/examples/at91sam7x/cfg/cfg_timer.h new file mode 100644 index 00000000..ac66befa --- /dev/null +++ b/examples/at91sam7x/cfg/cfg_timer.h @@ -0,0 +1,55 @@ +/** + * \file + * + * + * \brief Configuration file for timer module. + * + * \version $Id: cfg_timer.h 1969 2008-12-03 16:23:56Z asterix $ + * + * \author Daniele Basile + */ + +#ifndef CFG_TIMER_H +#define CFG_TIMER_H + +/// Hardware timer selection for drv/timer.c +#define CONFIG_TIMER TIMER_DEFAULT + +/// Debug timer interrupt using a strobe pin. +#define CONFIG_TIMER_STROBE 0 + +/// Enable asynchronous timers +#define CONFIG_TIMER_EVENTS 1 + +/// Support hi-res timer_usleep() +#define CONFIG_TIMER_UDELAY 1 + +#endif /* CFG_TIMER_H */ diff --git a/examples/at91sam7x/hw/hw_ser.h b/examples/at91sam7x/hw/hw_ser.h new file mode 100644 index 00000000..0a87ec12 --- /dev/null +++ b/examples/at91sam7x/hw/hw_ser.h @@ -0,0 +1,40 @@ +/** + * \file + * + * + * \brief Serial hardware-specific definitions + * + * \version $Id: hw_ser.h 982 2007-11-07 16:32:20Z batt $ + * + * \author Daniele Basile + */ + + diff --git a/examples/at91sam7x/verstag.h b/examples/at91sam7x/verstag.h new file mode 100644 index 00000000..bf43c463 --- /dev/null +++ b/examples/at91sam7x/verstag.h @@ -0,0 +1,94 @@ +/** + * \file + * + * + * \version $Id: verstag.h 1532 2008-08-04 07:21:26Z bernie $ + * + * \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 "AT91SAM7X-EK porting test" +#define APP_DESCRIPTION "AT91SAM7X-EK porting test" +#define APP_AUTHOR "Develer" +#define APP_COPYRIGHT "Copyright 2009 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 */ -- 2.25.1