From: asterix Date: Wed, 5 Mar 2008 23:31:15 +0000 (+0000) Subject: Merge from triface project. X-Git-Tag: 1.0.0~89 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=cfd59c8655ed7268c9c48aa58560158d235bc0de;p=bertos.git Merge from triface project. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1163 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/Makefile b/Makefile index fe7c8128..989b43f7 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ default: all include config.mk # Include subtargets -include app/demo/demo.mk -#include app/triface/triface.mk +#include app/demo/demo.mk +include app/triface/triface.mk #include app/at91sam7s/at91sam7s.mk include rules.mk diff --git a/app/triface/appconfig.h b/app/triface/appconfig.h index 2308f234..4c29571b 100644 --- a/app/triface/appconfig.h +++ b/app/triface/appconfig.h @@ -69,33 +69,14 @@ * \author Stefano Fedrigo */ -/*#* - *#* $Log$ - *#* Revision 1.5 2006/09/20 13:54:40 marco - *#* Added new SPI definitions. - *#* - *#* Revision 1.4 2006/07/19 12:56:25 bernie - *#* Convert to new Doxygen style. - *#* - *#* Revision 1.3 2006/06/12 21:37:01 marco - *#* implemented some commands (ver and sleep) - *#* - *#* Revision 1.2 2006/06/01 12:29:21 marco - *#* Add first simple protocol command (version request). - *#* - *#* Revision 1.1 2006/05/18 00:41:47 bernie - *#* New triface devlib application. - *#* - *#*/ - #ifndef APPCONFIG_TRIFACE_H #define APPCONFIG_TRIFACE_H /** Baud-rate for the kdebug console */ -#define CONFIG_KDEBUG_BAUDRATE 38400 +#define CONFIG_KDEBUG_BAUDRATE 115200 /** Serial port number for kdebug console */ -#define CONFIG_KDEBUG_PORT 0 +#define CONFIG_KDEBUG_PORT 1 /** @@ -162,8 +143,14 @@ /** Default baud rate (set to 0 to disable) */ #define CONFIG_SER_DEFBAUDRATE 0 + /** Host Port Baud Rate */ + #define CONFIG_SER_HOSTPORTBAUDRATE 115200 + + /** Host Port */ + #define CONFIG_SER_HOSTPORT 1 + /** Enable ser_gets() and ser_gets_echo() */ - #define CONFIG_SER_GETS 1 + #define CONFIG_SER_GETS 0 /** Enable second serial port in emulator. */ #define CONFIG_EMUL_UART1 0 @@ -179,15 +166,68 @@ /*\}*/ /// Hardware timer selection for drv/timer.c -#define CONFIG_TIMER TIMER_ON_OUTPUT_COMPARE0 +#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 -/// Enable internal parser commands. -#define CONFIG_INTERNAL_COMMANDS 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 64 + +/// Turn on or off timer support in Randpool. +#define CONFIG_RANDPOOL_TIMER 1 #endif /* APPCONFIG_TRIFACE_H */ diff --git a/app/triface/cmd_ctor.h b/app/triface/cmd_ctor.h index 6cd8206e..bf073f1e 100644 --- a/app/triface/cmd_ctor.h +++ b/app/triface/cmd_ctor.h @@ -36,6 +36,7 @@ * * \author Marco Benelli */ + #ifndef CMD_CTOR_H #define CMD_CTOR_H @@ -45,17 +46,17 @@ #define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template) -#define MAKE_TEMPLATE(NAME, ARGS, RES) \ +#define MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) \ const struct CmdTemplate cmd_ ## NAME ## _template = \ { \ - #NAME, ARGS, RES, cmd_ ## NAME, 0 \ + #NAME, ARGS, RES, cmd_ ## NAME, FLAGS \ }; -#define MAKE_CMD(NAME, ARGS, RES, BODY) \ +#define MAKE_CMD(NAME, ARGS, RES, BODY, FLAGS) \ static ResultCode cmd_ ## NAME (parms *args) \ { \ return (ResultCode)BODY; \ } \ -MAKE_TEMPLATE(NAME, ARGS, RES) +MAKE_TEMPLATE(NAME, ARGS, RES, FLAGS) #endif // CMD_CTOR_H diff --git a/app/triface/hw/hw_cpu.h b/app/triface/hw/hw_cpu.h index 4418081f..81339dfb 100644 --- a/app/triface/hw/hw_cpu.h +++ b/app/triface/hw/hw_cpu.h @@ -26,9 +26,10 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2006 Develer S.r.l. (http://www.develer.com/) - * All Rights Reserved. - * --> + * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2000 Bernardo Innocenti + * + * --> Rights Reserved. * * \brief Hardware-specific definitions * @@ -37,13 +38,6 @@ * \author Bernardo Innocenti */ -/*#* - *#* $Log$ - *#* Revision 1.1 2006/05/18 00:41:47 bernie - *#* New triface devlib application. - *#* - *#*/ - #ifndef TRIFACE_HW_H #define TRIFACE_HW_H @@ -61,3 +55,4 @@ //#endif /* CONFIG_TIMER_STROBE */ #endif /* TRIFACE_HW_H */ + diff --git a/app/triface/protocol.c b/app/triface/protocol.c index 08910d04..7dc434e6 100644 --- a/app/triface/protocol.c +++ b/app/triface/protocol.c @@ -26,7 +26,9 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2000 Bernardo Innocenti + * * --> * * \brief Implementation of the command protocol between the board and the host @@ -41,13 +43,16 @@ #include "protocol.h" -#include + #include +#include #include #include #include #include -#include +#include +#include +#include "hw_adc.h" #include #include @@ -55,6 +60,12 @@ //#include #include "cmd_ctor.h" // MAKE_CMD, REGISTER_CMD +#include "hw_input.h" +#include "verstag.h" +#include + +// Define the format string for ADC +#define ADC_FORMAT_STR "dddd" // DEBUG: set to 1 to force interactive mode #define FORCE_INTERACTIVE 1 @@ -71,11 +82,10 @@ 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. * - * \param ser serial port handle to output to. * \param err human-readable description of the error for debug purposes. */ INLINE void NAK(Serial *ser, const char *err) @@ -87,6 +97,11 @@ INLINE void NAK(Serial *ser, const char *err) #endif } +static void protocol_prompt(Serial *ser) +{ + ser_print(ser, ">> "); +} + /* * Print args on s, with format specified in t->result_fmt. * Return number of valid arguments or -1 in case of error. @@ -97,7 +112,6 @@ static bool protocol_reply(Serial *s, const struct CmdTemplate *t, unsigned short offset = strlen(t->arg_fmt) + 1; unsigned short nres = strlen(t->result_fmt); - ser_printf(s, "0"); for (unsigned short i = 0; i < nres; ++i) { if (t->result_fmt[i] == 'd') @@ -108,6 +122,7 @@ static bool protocol_reply(Serial *s, const struct CmdTemplate *t, { ser_printf(s, " %s", args[offset+i].s); } + else { abort(); @@ -125,7 +140,8 @@ static void protocol_parse(Serial *ser, const char *buf) templ = parser_get_cmd_template(buf); if (!templ) { - ser_print(ser, "-1 Invalid command."); + ser_print(ser, "-1 Invalid command.\r\n"); + protocol_prompt(ser); return; } @@ -134,7 +150,8 @@ static void protocol_parse(Serial *ser, const char *buf) /* Args Check. TODO: Handle different case. see doc/PROTOCOL . */ if (!parser_get_cmd_arguments(buf, templ, args)) { - ser_print(ser, "-2 Invalid arguments."); + ser_print(ser, "-2 Invalid arguments.\r\n"); + protocol_prompt(ser); return; } @@ -147,6 +164,8 @@ static void protocol_parse(Serial *ser, const char *buf) { NAK(ser, "Invalid return format."); } + + protocol_prompt(ser); return; } @@ -168,15 +187,20 @@ void protocol_run(Serial *ser) // check message minimum length if (linebuf[0]) { - if (linebuf[0] == 0x1B && linebuf[1] == 0x1B) // ESC + /* If we enter lines beginning with sharp(#) + they are stripped out from commands */ + if(linebuf[0] != '#') { - interactive = true; - ser_printf(ser, - "Entering interactive mode\r\n"); - } - else - { - protocol_parse(ser, linebuf); + if (linebuf[0] == 0x1B && linebuf[1] == 0x1B) // ESC + { + interactive = true; + ser_printf(ser, + "Entering interactive mode\r\n"); + } + else + { + protocol_parse(ser, linebuf); + } } } } @@ -194,25 +218,30 @@ void protocol_run(Serial *ser) */ buf = rl_readline(&rl_ctx); - if (buf && buf[0] != '\0') + /* If we enter lines beginning with sharp(#) + they are stripped out from commands */ + if(buf && buf[0] != '#') { - // exit special case to immediately change serial input - if (!strcmp(buf, "exit") || !strcmp(buf, "quit")) + if (buf[0] != '\0') { - rl_clear_history(&rl_ctx); - ser_printf(ser, - "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(ser, linebuf); + // exit special case to immediately change serial input + if (!strcmp(buf, "exit") || !strcmp(buf, "quit")) + { + rl_clear_history(&rl_ctx); + ser_printf(ser, + "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(ser, linebuf); + } } } } @@ -225,26 +254,91 @@ void protocol_run(Serial *ser) * */ -/* Version. Example of declaring function and passing it to MAKE_CMD. */ -static int ver_fn(const char **str) -{ - *str = VERS_TAG; - return 0; -} -MAKE_CMD(ver, "", "s", ver_fn(&args[1].s)) +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) + +/* Doutx sperimentale....... */ +MAKE_CMD(doutx, "d", "", + ({ + sipo_putchar((uint8_t)args[1].l); + + //Store status of dout ports. + reg_status_dout = (uint8_t)args[1].l; + 0; + }), 0) + +/* Reset */ +MAKE_CMD(reset, "", "", +({ + //Silence "args not used" warning. + (void)args; + wdt_init(7); + wdt_start(); + 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) @@ -252,6 +346,15 @@ 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(doutx); + REGISTER_CMD(reset); + REGISTER_CMD(din); + REGISTER_CMD(ain); + REGISTER_CMD(beep); } /* Initialization: readline context, parser and register commands. */ @@ -260,12 +363,15 @@ void protocol_init(Serial *ser) interactive = FORCE_INTERACTIVE; rl_init_ctx(&rl_ctx); - rl_setprompt(&rl_ctx, ">> "); + //rl_setprompt(&rl_ctx, ">> "); rl_sethook_get(&rl_ctx, (getc_hook)ser_getchar, ser); rl_sethook_put(&rl_ctx, (putc_hook)ser_putchar, ser); rl_sethook_match(&rl_ctx, parser_rl_match, NULL); + rl_sethook_clear(&rl_ctx, (clear_hook)ser_clearstatus,ser); parser_init(); protocol_registerCmds(); + + protocol_prompt(ser); } diff --git a/app/triface/protocol.h b/app/triface/protocol.h index 080d4045..ee758555 100644 --- a/app/triface/protocol.h +++ b/app/triface/protocol.h @@ -26,7 +26,9 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2000 Bernardo Innocenti + * * --> * * \brief Implementation of the command protocol between the board and the host @@ -36,6 +38,7 @@ * \author Marco Benelli */ + #ifndef PROTOCOL_H #define PROTOCOL_H diff --git a/app/triface/triface.c b/app/triface/triface.c index c34b5003..00c1a580 100644 --- a/app/triface/triface.c +++ b/app/triface/triface.c @@ -26,7 +26,8 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2000 Bernardo Innocenti * * --> * @@ -38,24 +39,45 @@ * \brief Windowing system test. */ + #include #include #include #include #include +#include +#include #include "protocol.h" +#include "hw_input.h" +#include "hw_adc.h" int main(void) { + /* SPI Port Initialization */ + sipo_init(); + kdbg_init(); timer_init(); -// buz_init(); + adc_init(); + buz_init(); IRQ_ENABLE; + INPUT_INIT; + + /* Initialize Tag serial port and data structure */ + TagPacket pkt; + + /* Open the main communication port */ + Serial *host_port = ser_open(CONFIG_SER_HOSTPORT); + ser_setbaudrate(host_port, CONFIG_SER_HOSTPORTBAUDRATE); + + pkt.tag_ser = ser_open(TAG_SER_PORT); + ser_setbaudrate(pkt.tag_ser, TAG_SER_BAUDRATE); + pkt.comm_ser = host_port; + keytag_init(&pkt); + - Serial *host_port = ser_open(0); - ser_setbaudrate(host_port, 38400); protocol_init(host_port); @@ -63,6 +85,7 @@ int main(void) for(;;) { protocol_run(host_port); + keytag_poll(&pkt); } return 0; diff --git a/app/triface/triface.mk b/app/triface/triface.mk index be38898e..b7c19cc4 100644 --- a/app/triface/triface.mk +++ b/app/triface/triface.mk @@ -7,6 +7,8 @@ # # Author: Bernardo Innocenti # +# + # Set to 1 for debug builds triface_DEBUG = 1 @@ -14,25 +16,34 @@ 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 \ drv/timer.c \ drv/ser.c \ cpu/avr/drv/ser_avr.c \ + cpu/avr/drv/sipo.c \ mware/formatwr.c \ mware/hex.c \ mware/hashtable.c \ mware/readline.c \ mware/parser.c \ - -# drv/buzzer.c + mware/event.c \ + net/keytag.c \ + hw/hw_adc.c \ + drv/buzzer.c \ triface_PCSRC += mware/formatwr.c -#triface_CFLAGS = -O3 -D'ARCH=0' -Iapp/triface/hw -Iapp/triface -triface_CFLAGS = -O0 -D'ARCH=0' -Iapp/triface/hw -Iapp/triface -Icpu/avr -triface_MCU = atmega128 + +triface_CFLAGS = -O2 -D'ARCH=0' -Iapp/triface/hw -Iapp/triface -Icpu/avr +triface_LDFLAGS = -Wl + +triface_MCU = atmega64 # Debug stuff ifeq ($(triface_DEBUG),1) diff --git a/app/triface/verstag.h b/app/triface/verstag.h index d81a97c3..d3ce13c0 100644 --- a/app/triface/verstag.h +++ b/app/triface/verstag.h @@ -26,8 +26,8 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/) - * Copyright 2001, 2002, 2003 by Bernardo Innocenti + * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/) + * Copyright 2000 Bernardo Innocenti * * --> * @@ -49,7 +49,7 @@ #define APP_AUTHOR "Develer" #define APP_COPYRIGHT "Copyright 2006 Develer (http://www.develer.com/)" -#define VERS_MAJOR 0 +#define VERS_MAJOR 1 #define VERS_MINOR 1 #define VERS_REV 0 #define VERS_LETTER "" diff --git a/config.mk b/config.mk index 5ace0dbd..45280174 100644 --- a/config.mk +++ b/config.mk @@ -30,14 +30,13 @@ DEBUGCFLAGS = -ggdb # # define some variables based on the AVR base path in $(AVR) # -#CROSS = avr- -CC = gcc -CXX = g++ +CROSS = avr- +CC = $(CROSS)gcc +CXX = $(CROSS)g++ AS = $(CC) -x assembler-with-cpp LD = $(CC) -LDXX = $(CXX) -OBJCOPY = objcopy -STRIP = strip +OBJCOPY = $(CROSS)objcopy +STRIP = $(CROSS)strip INSTALL = cp -a RM = rm -f RM_R = rm -rf @@ -84,7 +83,7 @@ endif WARNFLAGS = \ -W -Wformat -Wall -Wundef -Wpointer-arith -Wcast-qual \ -Wcast-align -Wwrite-strings -Wsign-compare \ - -Wmissing-noreturn \ + -Wmissing-prototypes -Wmissing-noreturn \ -Wextra -Wstrict-aliasing=2 \ # -Wunsafe-loop-optimizations