tux-droid-svn Mailing List for Tux Droid CE (Page 229)
Status: Beta
Brought to you by:
ks156
You can subscribe to this list here.
2007 |
Jan
|
Feb
(32) |
Mar
(108) |
Apr
(71) |
May
(38) |
Jun
(128) |
Jul
(1) |
Aug
(14) |
Sep
(77) |
Oct
(104) |
Nov
(90) |
Dec
(71) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(81) |
Feb
(18) |
Mar
(40) |
Apr
(102) |
May
(151) |
Jun
(74) |
Jul
(151) |
Aug
(257) |
Sep
(447) |
Oct
(379) |
Nov
(404) |
Dec
(430) |
2009 |
Jan
(173) |
Feb
(236) |
Mar
(519) |
Apr
(300) |
May
(112) |
Jun
(232) |
Jul
(314) |
Aug
(58) |
Sep
(203) |
Oct
(293) |
Nov
(26) |
Dec
(109) |
2010 |
Jan
(19) |
Feb
(25) |
Mar
(33) |
Apr
(1) |
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: jaguarondi <c2m...@c2...> - 2007-05-10 16:37:53
|
Author: jaguarondi Date: 2007-05-10 18:37:21 +0200 (Thu, 10 May 2007) New Revision: 307 Modified: firmware/tuxaudio/trunk/main.c firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxdefs/commands.h Log: - ADD: sleep and sleep acknowledge commands are added, the sleep command goes from the computer to tuxcore, is forwarded to tuxaudio and is then changed into the sleep_ack command, sent to tuxrf which sends it back to the computer. To check this, tuxaudio plays a sound when the command is received. No sleep function implemented yet, only the command goes around. Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxaudio/trunk/main.c 2007-05-10 16:37:21 UTC (rev 307) @@ -49,6 +49,7 @@ { VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; uint8_t info_flg = 0; /* indicates if version information should be sent */ +uint8_t sleep_flg = 0; /* set when sleep should be entered */ void send_info(void) { @@ -72,6 +73,15 @@ info_flg = 0; } +void sleep(void) +{ + if (isFifoEmpty(statusFifo)) /* waits for all status to be sent before going to sleep */ + { + sleep_flg = 0; + playingAudio(1); /* XXX debug */ + } +} + /* * Debug and test flags */ @@ -124,6 +134,16 @@ { test_mode = audioBuf[2]; /* audio test mode is the second parameter */ } + else if (audioBuf[0] == SLEEP_CMD) + { + sleep_flg = 1; /* handle sleep in its own function */ + audioBuf[0] |= SLEEP_ACK_CMD; /* go to sleep mode and acknowledge it */ + audioBuf[2] |= SLEEP_ACK_MK; /* go to sleep mode and acknowledge it */ + /* Forwards the command to the rf CPU */ + cli(); + i2cSlaveReceiveService(4, audioBuf); + sei(); + } audioBufIdx = 0; /* clear buffer; this buffer can only hold one command so should be simply reset here */ } @@ -293,6 +313,7 @@ } } sendCommands(); /* Send commands on I2C */ + if (audioBufIdx) audioIntParser(); @@ -382,6 +403,8 @@ if (info_flg) send_info(); /* send information to the computer */ + if (sleep_flg) + sleep(); /* send information to the computer */ } } Modified: firmware/tuxcore/trunk/global.c =================================================================== --- firmware/tuxcore/trunk/global.c 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxcore/trunk/global.c 2007-05-10 16:37:21 UTC (rev 307) @@ -41,9 +41,11 @@ /* * Condition flags + * + * Initialization */ -struct condition_table cond_flags = { 1 }; /* Set startup flag */ +struct condition_table cond_flags = { .startup=1 }; /* Set startup flag */ /* * Version number Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxcore/trunk/global.h 2007-05-10 16:37:21 UTC (rev 307) @@ -333,9 +333,11 @@ /* * Condition flags + * + * TODO merge flags by categories in bitfields or bytes and masks */ -#define COND_RESET_NBR 8 /* number of flags that should be reset, change this according to the table below */ +#define COND_RESET_NBR 9 /* number of flags that should be reset, change this according to the table below */ struct condition_table { /* flags reset by the COND_RESET_CMD */ @@ -347,6 +349,7 @@ uint8_t unplug; uint8_t tux_recog_cnt; uint8_t tux_recog; + uint8_t sleep; /* flags not reset by the COND_RESET_CMD */ uint8_t eyes_closed; uint8_t rf_conn; Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxcore/trunk/main.c 2007-05-10 16:37:21 UTC (rev 307) @@ -63,7 +63,7 @@ * Stack Overflow detection * * Fill the ram with a value (0x5F) before the first initialization in order to - * detect any stack overflow just by looking to the memory at any breakpoint + * detect any stack overflow just by looking into the memory at any breakpoint */ void init_ram(void) __attribute__ ((naked)) __attribute__ ((section(".init1"))); void init_ram(void) Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxcore/trunk/parser.c 2007-05-10 16:37:21 UTC (rev 307) @@ -156,14 +156,14 @@ /* Sound */ else if (command[0] == PLAY_SOUND_CMD) { - for (i = 0; i < 3; i++) /* forwards the command to the audio CPU too */ + for (i = 0; i < 3; i++) /* forwards the command to the audio CPU */ audioIntBuf[i] = command[i]; audioIntBufIdx = 3; return; } else if (command[0] == MUTE_CMD) { - for (i = 0; i < 3; i++) /* forwards the command to the audio CPU too */ + for (i = 0; i < 3; i++) /* forwards the command to the audio CPU */ audioIntBuf[i] = command[i]; audioIntBufIdx = 3; return; @@ -172,9 +172,11 @@ /* Sleep mode */ else if (command[0] == SLEEP_CMD) { - for (i = 0; i < 3; i++) /* forwards the command to the audio CPU too */ + command[1] |= SLEEP_ACK_MK; /* ack the command */ + for (i = 0; i < 3; i++) /* forward the command to the audio CPU */ audioIntBuf[i] = command[i]; audioIntBufIdx = 3; + cond_flags.sleep = 1; return; } @@ -183,7 +185,7 @@ { if (!audioIntBufIdx) { - for (i = 0; i < 3; i++) /* forwards the command to the audio CPU too */ + for (i = 0; i < 3; i++) /* forwards the command to the audio CPU */ audioIntBuf[i] = command[i]; audioIntBufIdx = 3; } Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2007-05-10 16:23:16 UTC (rev 306) +++ firmware/tuxdefs/commands.h 2007-05-10 16:37:21 UTC (rev 307) @@ -222,15 +222,16 @@ /* * Sleep commands */ -#define SLEEP_CMD 0x93 /* set the CPU in sleep mode */ -/* 1st parameter: XXX undefined yet */ -/* 2nd parameter: XXX undefined yet */ +#define SLEEP_CMD 0xB7 /* set the CPU in sleep mode */ +/* 1st parameter: type of sleep mode */ +/* 2nd parameter: reserved */ +#define SLEEP_ACK_CMD 0xF7 /* acknowledge of the sleep mode command */ +/* 1st parameter: acknowledge of tuxcore */ +/* 2nd parameter: acknowledge of tuxaudio */ +/* 3rd parameter: acknowledge of tuxrf */ +#define SLEEP_ACK_MK 0x01 /* - * I2C commands - */ - -/* * Status commands */ #define STATUS_PORTS_CMD 0xC0 /* send core CPU's ports */ |
From: jaguarondi <c2m...@c2...> - 2007-05-10 16:23:29
|
Author: jaguarondi Date: 2007-05-10 18:23:16 +0200 (Thu, 10 May 2007) New Revision: 306 Modified: firmware/tuxaudio/trunk/Makefile firmware/tuxcore/trunk/Makefile Log: - ADD: programming directives for tuxup, stk500 and jtagice mkii. Modified: firmware/tuxaudio/trunk/Makefile =================================================================== --- firmware/tuxaudio/trunk/Makefile 2007-05-10 12:16:33 UTC (rev 305) +++ firmware/tuxaudio/trunk/Makefile 2007-05-10 16:23:16 UTC (rev 306) @@ -159,3 +159,12 @@ ## Other dependencies -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) +# Programming +prog: $(PROJECT).hex + tuxup $(PROJECT).hex $(PROJECT).eep + +progisp: $(PROJECT).hex + AVRDUDE -p $(MCU) -c jtag2isp -P usb -B 10 -e -U flash:w:$(PROJECT).hex + +progstk: $(PROJECT).hex + AVRDUDE -p $(MCU) -c stk500v2 -e -U flash:w:$(PROJECT).hex Modified: firmware/tuxcore/trunk/Makefile =================================================================== --- firmware/tuxcore/trunk/Makefile 2007-05-10 12:16:33 UTC (rev 305) +++ firmware/tuxcore/trunk/Makefile 2007-05-10 16:23:16 UTC (rev 306) @@ -165,3 +165,12 @@ ## Other dependencies -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) +# Programming +prog: $(PROJECT).hex + tuxup $(PROJECT).hex $(PROJECT).eep + +progisp: $(PROJECT).hex + AVRDUDE -p $(MCU) -c jtag2isp -P usb -B 10 -e -U flash:w:$(PROJECT).hex + +progstk: $(PROJECT).hex + AVRDUDE -p $(MCU) -c stk500v2 -e -U flash:w:$(PROJECT).hex |
From: neimad <c2m...@c2...> - 2007-05-10 12:17:03
|
Author: neimad Date: 2007-05-10 14:16:33 +0200 (Thu, 10 May 2007) New Revision: 305 Modified: daemon/trunk/main.c Log: * Fixed USR handler not being set up when not running as a daemon. Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-05-08 16:39:26 UTC (rev 304) +++ daemon/trunk/main.c 2007-05-10 12:16:33 UTC (rev 305) @@ -321,8 +321,12 @@ daemonize(log_target, log_level); else { + atexit(terminate); + signal(SIGUSR2, toggle_debugging); + log_open(LOG_TARGET_SHELL); log_set_level(log_level); + if (!write_pid()) exit(1); } |
From: jaguarondi <c2m...@c2...> - 2007-05-08 16:40:01
|
Author: jaguarondi Date: 2007-05-08 18:39:26 +0200 (Tue, 08 May 2007) New Revision: 304 Modified: software/alarm_clock/trunk/tdac.py software/email_alert/trunk/tdema.py software/gtdi/trunk/gtdi.py Log: - ADD: patch from Georges Dubus to add support for terminals in kde and xterm - UPD: removed the unnecessary gnome module from email alert and alarm clock Modified: software/alarm_clock/trunk/tdac.py =================================================================== --- software/alarm_clock/trunk/tdac.py 2007-05-03 06:05:56 UTC (rev 303) +++ software/alarm_clock/trunk/tdac.py 2007-05-08 16:39:26 UTC (rev 304) @@ -37,7 +37,6 @@ import os import gtk -import gnome from SimpleGladeApp import SimpleGladeApp from SimpleGladeApp import bindtextdomain @@ -168,7 +167,6 @@ #------------------------------------------------------------------------------ def main(): gtk.gdk.threads_init() - gnome.program_init("tdac", "0.0.1") window1 = Window1() window1.run() Modified: software/email_alert/trunk/tdema.py =================================================================== --- software/email_alert/trunk/tdema.py 2007-05-03 06:05:56 UTC (rev 303) +++ software/email_alert/trunk/tdema.py 2007-05-08 16:39:26 UTC (rev 304) @@ -37,7 +37,6 @@ import os import gtk -import gnome from poplib import * import thread @@ -236,7 +235,6 @@ #------------------------------------------------------------------------------ def main(): gtk.gdk.threads_init() - gnome.program_init("tdema", "0.0.1") window1 = Window1() window1.run() Modified: software/gtdi/trunk/gtdi.py =================================================================== --- software/gtdi/trunk/gtdi.py 2007-05-03 06:05:56 UTC (rev 303) +++ software/gtdi/trunk/gtdi.py 2007-05-08 16:39:26 UTC (rev 304) @@ -56,6 +56,11 @@ status_list_st=[] status_list_changed=False toggled_by_event=False + +for term in ["gnome-terminal","konsole","xterm"]: + if not os.popen('type %s'%term).close(): + terminal_app=term + break #============================================================================== # Main window class #============================================================================== @@ -374,7 +379,7 @@ # On "Tux Droid shell" button clicked #-------------------------------------------------------------------------- def on_tdshell_bt_clicked(self, widget, *args): - tux.sys.shell_free('gnome-terminal -e "tuxsh"') + tux.sys.shell_free(terminal_app + ' -e "tuxsh"') #-------------------------------------------------------------------------- # On "Get light level" button clicked |
From: neimad <c2m...@c2...> - 2007-05-03 06:05:58
|
Author: neimad Date: 2007-05-03 08:05:56 +0200 (Thu, 03 May 2007) New Revision: 303 Modified: daemon/trunk/libs/USBDaemon_status_table.c Log: * Fixed bug (wrong index in right blue led status) introduced in commit r301. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 17:56:14 UTC (rev 302) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-05-03 06:05:56 UTC (rev 303) @@ -415,7 +415,7 @@ { tcp_frame[4] = DATA_STATUS_RIGHT_BLUE_LED; tcp_frame[5] = !portc.bits.PB2; - log_debug("right blue led %s", tcp_frame[0] ? "on" : "off"); + log_debug("right blue led %s", tcp_frame[5] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } |
From: srikantap <c2m...@c2...> - 2007-05-02 17:56:22
|
Author: srikantap Date: 2007-05-02 19:56:14 +0200 (Wed, 02 May 2007) New Revision: 302 Modified: daemon/branches/CPPDaemon/TCP.cpp daemon/branches/CPPDaemon/TuxDeviceManager.cpp Log: Additional comments and TODOs. Modified: daemon/branches/CPPDaemon/TCP.cpp =================================================================== --- daemon/branches/CPPDaemon/TCP.cpp 2007-05-02 16:42:22 UTC (rev 301) +++ daemon/branches/CPPDaemon/TCP.cpp 2007-05-02 17:56:14 UTC (rev 302) @@ -87,24 +87,7 @@ ::memcpy(_msg, newMsg, 16); } -#if 0 -Message::Message(string& newMsg) - //: msg(newMsg.c_str()) -{ - printf("Entered\n"); - const char *c = newMsg.c_str(); - for (int i = 0; i < 16; i++) - { - //printf("%d ", (int) newMsg[i]); - // msg[i] = newMsg[i]; - printf("%d ", (unsigned char) c[i]); - msg[i] = c[i]; - } - printf("\n"); -} -#endif - /***************************************************************/ CommManager::Client::Client() : _name(CLIENT_NAME_SIZE, '\0') @@ -120,63 +103,13 @@ { _name = name; } -#if 0 -void CommManager::Client::setId(int id) -{ - _id = id; -} -#endif -/* -bool CommManager::Client::accept(int sockId) -{ - _id = ::accept(sockId, (struct sockaddr *) NULL, NULL); - - if (_id <= 0) - { - return false; - } - else - { - //fcntl(_id, F_SETFL, O_NONBLOCK); - is_valid = true; - return true; - } -} -*/ - void CommManager::Client::invalidate() { close(); } -#if 0 -void CommManager::Client::valid() -{ - is_valid_ = true; -} -#endif - -#if 0 -int CommManager::Client::recv(Message& msg) -{ - char buf [16]; - memset (buf, 0, 16); - - // int status = ::recv (_id, buf, MAXRECV, 0); - // int status = ::recv(m_sock, buf, 16, 0); - - if (status > 0); - { - msg = buf; - } - - return (status); -} -#endif - - /***************************************************************/ CommManager::CommManager() : clients (new Client[10]) @@ -248,6 +181,7 @@ * if handle is valid: check for any msg * else continue **/ + /* TODO: Use select patch (main-daemon) */ for (int i = 0; i < 10; i++) { // printf("processing %d\n", i); Modified: daemon/branches/CPPDaemon/TuxDeviceManager.cpp =================================================================== --- daemon/branches/CPPDaemon/TuxDeviceManager.cpp 2007-05-02 16:42:22 UTC (rev 301) +++ daemon/branches/CPPDaemon/TuxDeviceManager.cpp 2007-05-02 17:56:14 UTC (rev 302) @@ -9,7 +9,6 @@ { printf("TuxDeviceManager::Send: Writing to tux...\n"); usb_interrupt_write(deviceHandle, TUX_WRITE_EP, (char *) msg, TUX_SEND_LENGTH, 5000); - } bool TuxDeviceManager::initializeDevice() |
From: neimad <c2m...@c2...> - 2007-05-02 16:42:27
|
Author: neimad Date: 2007-05-02 18:42:22 +0200 (Wed, 02 May 2007) New Revision: 301 Modified: daemon/trunk/libs/USBDaemon_status_table.c Log: * Simplified the status change functions a bit. The pattern is the almost always the same and thus this could be further simplified (with shifting instead of bitfields, too). Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 15:44:16 UTC (rev 300) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 16:42:22 UTC (rev 301) @@ -329,16 +329,8 @@ if ((portb.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_BACKWARD; - if (portb.bits.PB0) - { - log_debug("wings motor backward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings motor backward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB0; + log_debug("wings motor backward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -346,16 +338,8 @@ if ((portb.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_BACKWARD; - if (portb.bits.PB1) - { - log_debug("spin motor backward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin motor backward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB1; + log_debug("spin motor backward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -363,16 +347,8 @@ if ((portb.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_FORWARD; - if (portb.bits.PB2) - { - log_debug("spin motor forward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin motor forward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB2; + log_debug("spin motor forward %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -380,18 +356,8 @@ if ((portb.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_MOUTH_OPEN_POSITION; - if (portb.bits.PB3) - { - /* Up */ - log_debug("mouth open position 0"); - tcp_frame[5] = 0; - } - else - { - /* Down */ - log_debug("mouth open position 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB3; + log_debug("mouth open position %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -399,16 +365,8 @@ if ((portb.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_MOUTH_CLOSED_POSITION; - if (portb.bits.PB4) - { - log_debug("mouth close position 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("mouth close position 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB4; + log_debug("mouth close position %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -416,16 +374,8 @@ if ((portb.Byte & 0x40) != (new_value & 0x40)) { tcp_frame[4] = DATA_STATUS_CHARGER_INHIBIT_SIGNAL; - if (portb.bits.PB6) - { - log_debug("charger inhibit signal 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("charger inhibit signal 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portb.bits.PB6; + log_debug("charger inhibit signal %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -454,16 +404,9 @@ if ((portc.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_WINGS_POSITION_SWITCH; - if (portc.bits.PB1) - { - log_debug("wings position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB1; + log_debug("wings position switch %d", tcp_frame[5]); + tcp_frame[5] = 0; tcp_server_send_raw(tcp_frame); } @@ -471,16 +414,8 @@ if ((portc.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_RIGHT_BLUE_LED; - if (portc.bits.PB2) - { - log_debug("right blue led off"); - tcp_frame[5] = 0; - } - else - { - log_debug("right blue led on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB2; + log_debug("right blue led %s", tcp_frame[0] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } @@ -488,16 +423,8 @@ if ((portc.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_LEFT_BLUE_LED; - if (portc.bits.PB3) - { - log_debug("left blue led off"); - tcp_frame[5] = 0; - } - else - { - log_debug("left blue led on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portc.bits.PB3; + log_debug("left blue led %s", tcp_frame[5] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } @@ -526,16 +453,8 @@ if ((portd.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_EYES; - if (portd.bits.PB0) - { - log_debug("head motor for eyes 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("head motor for eyes 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB0; + log_debug("head motor for eyes %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -543,16 +462,8 @@ if ((portd.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_MOUTH; - if (portd.bits.PB1) - { - log_debug("head motor for mouth 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("head motor for mouth 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB1; + log_debug("head motor for mouth %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -560,16 +471,8 @@ if ((portd.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_SPIN_POSITION_SWITCH; - if (portd.bits.PB3) - { - log_debug("spin position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("spin position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB3; + log_debug("spin position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -577,16 +480,9 @@ if ((portd.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_FORWARD; - if (portd.bits.PB4) - { - log_debug("wings motor forward 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("wings motor forward 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB4; + log_debug("wings motor forward %d", tcp_frame[5]); + tcp_frame[5] = 0; tcp_server_send_raw(tcp_frame); } @@ -594,16 +490,8 @@ if ((portd.Byte & 0x20) != (new_value & 0x20)) { tcp_frame[4] = DATA_STATUS_IR_LED; - if (portd.bits.PB5) - { - log_debug("IR led 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("IR led 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB5; + log_debug("IR led %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -611,16 +499,8 @@ if ((portd.Byte & 0x40) != (new_value & 0x40)) { tcp_frame[4] = DATA_STATUS_EYES_OPEN_POSITION_SWITCH; - if (portd.bits.PB6) - { - log_debug("eyes open position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("eyes open position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB6; + log_debug("eyes open position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -628,16 +508,8 @@ if ((portd.Byte & 0x80) != (new_value & 0x80)) { tcp_frame[4] = DATA_STATUS_EYES_CLOSED_POSITION_SWITCH; - if (portd.bits.PB7) - { - log_debug("eyes closed position switch 0"); - tcp_frame[5] = 0; - } - else - { - log_debug("eyes closed position switch 1"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !portd.bits.PB7; + log_debug("eyes closed position switch %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -666,16 +538,8 @@ if ((sensors1.Byte & 0x01) != (new_value & 0x01)) { tcp_frame[4] = DATA_STATUS_LEFT_WING_PUSH; - if (sensors1.bits.PB0) - { - log_debug("Left wing button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Left wing button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB0; + log_debug("Left wing button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -683,16 +547,8 @@ if ((sensors1.Byte & 0x02) != (new_value & 0x02)) { tcp_frame[4] = DATA_STATUS_RIGHT_WING_PUSH; - if (sensors1.bits.PB1) - { - log_debug("Right wing button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Right wing button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB1; + log_debug("Right wing button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -700,16 +556,8 @@ if ((sensors1.Byte & 0x04) != (new_value & 0x04)) { tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; - if (sensors1.bits.PB2) - { - log_debug("power plug insertion switch on"); - tcp_frame[5] = 0; - } - else - { - log_debug("power plug insertion switch off"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB2; + log_debug("power plug insertion switch %s", tcp_frame[5] ? "off" : "on"); tcp_server_send_raw(tcp_frame); } @@ -717,16 +565,8 @@ if ((sensors1.Byte & 0x08) != (new_value & 0x08)) { tcp_frame[4] = DATA_STATUS_HEAD_PUSH_SWITCH; - if (sensors1.bits.PB3) - { - log_debug("Head button Up"); - tcp_frame[5] = 0; - } - else - { - log_debug("Head button Down"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB3; + log_debug("Head button %s", tcp_frame[5] ? "Down" : "Up"); tcp_server_send_raw(tcp_frame); } @@ -734,16 +574,8 @@ if ((sensors1.Byte & 0x10) != (new_value & 0x10)) { tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; - if (sensors1.bits.PB4) - { - log_debug("Charger led 1"); - tcp_frame[5] = 1; - } - else - { - log_debug("Charger led 0"); - tcp_frame[5] = 0; - } + tcp_frame[5] = sensors1.bits.PB4; + log_debug("Charger led %d", tcp_frame[5]); tcp_server_send_raw(tcp_frame); } @@ -751,16 +583,8 @@ if ((sensors1.Byte & 0x80) != (new_value & 0x80)) { tcp_frame[4] = DATA_STATUS_MUTE_STATUS; - if (sensors1.bits.PB7) - { - log_debug("mute status off"); - tcp_frame[5] = 0; - } - else - { - log_debug("mute status on"); - tcp_frame[5] = 1; - } + tcp_frame[5] = !sensors1.bits.PB7; + log_debug("mute status %s", tcp_frame[5] ? "on" : "off"); tcp_server_send_raw(tcp_frame); } |
From: neimad <c2m...@c2...> - 2007-05-02 15:44:19
|
Author: neimad Date: 2007-05-02 17:44:16 +0200 (Wed, 02 May 2007) New Revision: 300 Modified: daemon/trunk/main.c Log: * Check for running daemon *after* options have been processed, so that the user may get help even when the daemon's running. Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-05-02 15:16:36 UTC (rev 299) +++ daemon/trunk/main.c 2007-05-02 15:44:16 UTC (rev 300) @@ -279,12 +279,6 @@ /* On exiting */ signal(SIGINT, on_close_daemon); - /* Only one instance of the daemon is authorized */ - if (check_pid()) - { - printf("Tuxdaemon is already launched !\n"); - exit(0); - } /* Program arguments */ for (i = 1; i < argc; i++) { @@ -316,6 +310,13 @@ } } + /* Only one instance of the daemon is authorized */ + if (check_pid()) + { + printf("Tuxdaemon is already launched !\n"); + exit(0); + } + if (daemonized) daemonize(log_target, log_level); else |
From: neimad <c2m...@c2...> - 2007-05-02 15:19:22
|
Author: neimad Date: 2007-05-02 17:16:36 +0200 (Wed, 02 May 2007) New Revision: 299 Modified: daemon/trunk/main.c Log: * Can't catch SIGKILL. Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-05-02 15:13:43 UTC (rev 298) +++ daemon/trunk/main.c 2007-05-02 15:16:36 UTC (rev 299) @@ -278,7 +278,7 @@ /* On exiting */ signal(SIGINT, on_close_daemon); - signal(SIGKILL, on_close_daemon); + /* Only one instance of the daemon is authorized */ if (check_pid()) { |
From: neimad <c2m...@c2...> - 2007-05-02 15:14:02
|
Author: neimad Date: 2007-05-02 17:13:43 +0200 (Wed, 02 May 2007) New Revision: 298 Modified: daemon/trunk/main.c Log: * English. Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-05-02 15:12:21 UTC (rev 297) +++ daemon/trunk/main.c 2007-05-02 15:13:43 UTC (rev 298) @@ -182,7 +182,8 @@ { case 0: break; - case -1: /*erreur */ + case -1: + /* error */ exit(1); break; default: |
From: neimad <c2m...@c2...> - 2007-05-02 15:13:05
|
Author: neimad Date: 2007-05-02 17:12:21 +0200 (Wed, 02 May 2007) New Revision: 297 Modified: daemon/trunk/libs/USBDaemon_pidfile.c Log: * Use new constant TUX_DAEMON_NAME in the definition of PIDILE. Modified: daemon/trunk/libs/USBDaemon_pidfile.c =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.c 2007-05-02 15:08:18 UTC (rev 296) +++ daemon/trunk/libs/USBDaemon_pidfile.c 2007-05-02 15:12:21 UTC (rev 297) @@ -33,7 +33,7 @@ #include "USBDaemon_globals.h" #include "USBDaemon_log.h" -#define PIDFILE "/var/run/tuxdaemon.pid" +#define PIDFILE "/var/run/" TUX_DAEMON_NAME ".pid" /************************************************************************ */ |
From: neimad <c2m...@c2...> - 2007-05-02 15:09:26
|
Author: neimad Date: 2007-05-02 17:08:18 +0200 (Wed, 02 May 2007) New Revision: 296 Added: daemon/trunk/libs/USBDaemon_log.c daemon/trunk/libs/USBDaemon_log.h Modified: daemon/trunk/Makefile daemon/trunk/TODO daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_globals.h daemon/trunk/libs/USBDaemon_pidfile.c daemon/trunk/libs/USBDaemon_pidfile.h daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_readWrite.c daemon/trunk/main.c Log: Logging facility for Tux daemon. It has 3 logging modes: - syslog mode, which is the default when running as a daemon (option -d), unless option -v ("view in shell") is given. Messages are logged to /var/log/messages. - tux mode, where the daemon logs to its own separate logfile, /var/log/tuxdaemon.log. - shell mode, which is the default when *not* running as a daemon, where messages are printed to std{out,err}. There are 5 logging levels (from lowest to highest priority): debug, info, warning, error, none The logging level can be configured with log_set_level(). A message is logged at level L by calling log_L(), i.e. one of log_debug(), log_info(), log_warning() and log_error() Logging a message at level 'none' has no sense, so there is no corresponding function. All messages are logged prefixed with their logging level, except for 'info' messages. If a message is logged at level L such that L < C, where C is the current logging level, then that message is silently dropped. Most notably, if the logging level is set to 'none', then *no* message will be logged at all. The following changes were made: * Defined TUX_DAEMON_NAME, name of the daemon, for use everywhere in place of hardcoded strings. * Added module libs/USBDaemon_log.[ch], which implements the logging facility. * Moved function terminate() from libs/USBDaemon_pidfile.[ch] to main.c, which makes more sense. It is now registered with atexit() and is hence automatically executed at exit. * All calls to terminate() have been replaced with calls to exit() (see above). * Replaced printf() with log_info() and fprintf(stderr) with log_error(). Some of these calls should probably be replaced with log_warning() or log_debug(). * All status changes (wings motor, leds, etc) are logged at level DEBUG. * Added -l option to set the logging mode: -lsys Log to syslog -ltux Log to /var/log/tuxdaemon.log -lstd Print to std{out,err} Option -v is still there for now (as an alias for -lstd) but is marked deprecated. * Added -debug option to set the logging level to DEBUG at start (default is INFO). * Added ability to activate/deactivate the DEBUG level dynamically by sending USR2 to the daemon. * Removed logging from the TODO list. Modified: daemon/trunk/Makefile =================================================================== --- daemon/trunk/Makefile 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/Makefile 2007-05-02 15:08:18 UTC (rev 296) @@ -43,9 +43,9 @@ $(OBJ_DIR)/USBDaemon_status_table.o \ $(OBJ_DIR)/USBDaemon_pidfile.o \ $(OBJ_DIR)/USBDaemon_command_tux.o \ - $(OBJ_DIR)/USBDaemon_tcp_server.o + $(OBJ_DIR)/USBDaemon_tcp_server.o \ + $(OBJ_DIR)/USBDaemon_log.o - define build_target @echo Linking... @$(CC) -o "$(OUTPUT_DIR)/$(TARGET)" $(SRC_OBJS) $(LIB_DIRS) $(LIBS) $(LDFLAGS) @@ -93,6 +93,9 @@ version.h $(compile_source) +$(OBJ_DIR)/USBDaemon_log.o: libs/USBDaemon_log.c libs/USBDaemon_log.h + $(compile_source) + $(OBJ_DIR)/USBDaemon_usb_enum.o: libs/USBDaemon_usb_enum.c \ libs/USBDaemon_usb_enum.h \ libs/USBDaemon_globals.h \ Modified: daemon/trunk/TODO =================================================================== --- daemon/trunk/TODO 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/TODO 2007-05-02 15:08:18 UTC (rev 296) @@ -1,7 +1,5 @@ $Id$ -- Add a decent logging functionality to the daemon. - - Use the GNU Autotools framework to configure and compile the daemon. - Support multiple dongles. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-05-02 15:08:18 UTC (rev 296) @@ -28,6 +28,7 @@ #include "USBDaemon_command_tux.h" #include "USBDaemon_usb_readWrite.h" #include "USBDaemon_globals.h" +#include "USBDaemon_log.h" #include "../tuxdefs/commands.h" #include "USBDaemon_tcp_server.h" #include "USBDaemon_pidfile.h" @@ -261,10 +262,10 @@ pthread_mutex_unlock(&tcp_mutex); break; case SUB_D_CMD_STRUC_KILL_DAEMON: - printf("WARNING : daemon killed by user\n"); + log_warning("daemon killed by user"); send_daemon_disconnected(); result[0] = ACK_CMD_OK; - terminate(0); + exit(0); break; case SUB_D_CMD_STRUC_DEFINE_CLIENT_NAME: { @@ -273,8 +274,8 @@ for (i = 0; i < 11; i++) tcp_clients_name[id_client][i] = data[i + 1]; result[0] = ACK_CMD_OK; - printf("Name of client %d is %s\n", id_client, - tcp_clients_name[id_client]); + log_debug("Name of client %d is %s", id_client, + tcp_clients_name[id_client]); } break; } Modified: daemon/trunk/libs/USBDaemon_globals.h =================================================================== --- daemon/trunk/libs/USBDaemon_globals.h 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_globals.h 2007-05-02 15:08:18 UTC (rev 296) @@ -29,6 +29,10 @@ #include <pthread.h> /*_____________________ D E F I N E S ______________________________________*/ + +/** Name of the daemon */ +#define TUX_DAEMON_NAME "tuxdaemon" + #define TUX_PID 0xFF07 #define TUX_VID 0x03EB #define TUX_INTERFACE 0x03 Added: daemon/trunk/libs/USBDaemon_log.c =================================================================== --- daemon/trunk/libs/USBDaemon_log.c (rev 0) +++ daemon/trunk/libs/USBDaemon_log.c 2007-05-02 15:08:18 UTC (rev 296) @@ -0,0 +1,210 @@ + +#include "USBDaemon_globals.h" +#include "USBDaemon_log.h" + +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> +#include <syslog.h> + +/** Name of log file for target LOG_TARGET_TUX */ +#define LOG_FILE "/var/log/" TUX_DAEMON_NAME ".log" + +/** All logged messages are prefixed with this text */ +#define LOG_PREFIX TUX_DAEMON_NAME + +/** Current logging level */ +static log_level_t current_level = LOG_LEVEL_INFO; + +/** Logging level names */ +static const char *level_names[] = +{ + [LOG_LEVEL_DEBUG] = "debug", + [LOG_LEVEL_INFO] = "info", + [LOG_LEVEL_WARNING] = "warning", + [LOG_LEVEL_ERROR] = "error", + [LOG_LEVEL_NONE] = "none" +}; + +/** Logging level to syslog priority mapping */ +static int level_prio[] = +{ + [LOG_LEVEL_DEBUG] = LOG_DEBUG, + [LOG_LEVEL_INFO] = LOG_INFO, + [LOG_LEVEL_WARNING] = LOG_WARNING, + [LOG_LEVEL_ERROR] = LOG_ERR, + [LOG_LEVEL_NONE] = 0 +}; + +/** Current logging target */ +static log_target_t log_target = LOG_TARGET_SHELL; + +/** Log file for target LOG_TARGET_TUX */ +static FILE *log_file; + +/** Whether the log has been opened */ +static int log_opened; + +/** + * @brief Open the log. + * + * @param[in] target Logging target + * + * @return 1 if successfull, 0 otherwise + */ +int log_open(log_target_t target) +{ + if (log_opened) + return 1; + + switch (target) + { + case LOG_TARGET_SYSLOG: + openlog(LOG_PREFIX, 0, LOG_DAEMON); + break; + + case LOG_TARGET_TUX: + log_file = fopen(LOG_FILE, "at"); + if (log_file == NULL) + return 0; + break; + + case LOG_TARGET_SHELL: + break; + } + + log_target = target; + log_opened = 1; + + return 1; +} + +/** + * @brief Close the log. + */ +void log_close(void) +{ + if (!log_opened) + return; + + switch (log_target) + { + case LOG_TARGET_SYSLOG: + closelog(); + break; + + case LOG_TARGET_TUX: + fclose(log_file); + log_file = NULL; + break; + + case LOG_TARGET_SHELL: + break; + } + + log_opened = 0; +} + +/** + * @brief Set the logging level. + * + * @param[in] new_level New logging level + */ +void log_set_level(log_level_t new_level) +{ + assert(new_level >= LOG_LEVEL_DEBUG && new_level <= LOG_LEVEL_NONE); + current_level = new_level; +} + +/** + * @brief Get the logging level. + * + * @return current logging level + */ +log_level_t log_get_level(void) +{ + return current_level; +} + +/** + * @brief Log formatted message at the specified level. + * + * @param[in] at_level Level to log the message at + * @param[in] fmt Message format + * @param[in] ... Optional message data + * + * If the priority of the specifed level is lower than the priority + * of the current logging level, the message is silently dropped. + * + * @return 1 if successful, 0 otherwise + */ +int log_text(log_level_t at_level, const char *fmt, ...) +{ + char text[1024], *p = text; + size_t size = sizeof(text); + int prio; + time_t now; + va_list al; + int r; + + /* No need for the log to be 'opened' when logging to std{out,err} */ + if (log_target != LOG_TARGET_SHELL && !log_opened) + return 0; + + /* Logging at level NONE has no sense */ + assert(at_level >= LOG_LEVEL_DEBUG && at_level < LOG_LEVEL_NONE); + + if (at_level < current_level) + return 1; + + /* Add date & time when LOG_TARGET_TUX */ + if (log_target == LOG_TARGET_TUX) + { + now = time(NULL); + r = strftime(p, size, "%F %T ", localtime(&now)); + if (r == 0) + return 0; + + p += r; + size -= r; + } + + /* Only prefix non-INFO level messages */ + if (at_level != LOG_LEVEL_INFO) + { + r = snprintf(p, size, "%s: ", level_names[at_level]); + if (r < 0) + return 0; + + p += r; + size -= r; + } + + va_start(al, fmt); + r = vsnprintf(p, size, fmt, al); + va_end(al); + if (r < 0) + return 0; + + switch (log_target) + { + case LOG_TARGET_SYSLOG: + prio = level_prio[at_level]; + syslog(prio, "%s", text); + break; + + case LOG_TARGET_TUX: + fprintf(log_file, "%s\n", text); + break; + + case LOG_TARGET_SHELL: + if (at_level == LOG_LEVEL_WARNING || at_level == LOG_LEVEL_ERROR) + fprintf(stderr, "%s\n", text); + else + fprintf(stdout, "%s\n", text); + break; + } + + return 1; +} Added: daemon/trunk/libs/USBDaemon_log.h =================================================================== --- daemon/trunk/libs/USBDaemon_log.h (rev 0) +++ daemon/trunk/libs/USBDaemon_log.h 2007-05-02 15:08:18 UTC (rev 296) @@ -0,0 +1,36 @@ +#ifndef __USBDAEMON_LOG_H__ +#define __USBDAEMON_LOG_H__ + +/** Logging target */ +typedef enum log_target +{ + LOG_TARGET_SYSLOG, + LOG_TARGET_TUX, + LOG_TARGET_SHELL +} log_target_t; + +extern int log_open(log_target_t target); +extern void log_close(void); + +/** Logging levels, in increasing priorities */ +typedef enum log_level +{ + LOG_LEVEL_DEBUG, + LOG_LEVEL_INFO, + LOG_LEVEL_WARNING, + LOG_LEVEL_ERROR, + LOG_LEVEL_NONE +} log_level_t; + +extern void log_set_level(log_level_t new_level); +extern log_level_t log_get_level(void); + +extern int log_text(log_level_t at_level, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); + +#define log_debug(fmt, ...) log_text(LOG_LEVEL_DEBUG, (fmt), ## __VA_ARGS__) +#define log_info(fmt, ...) log_text(LOG_LEVEL_INFO, (fmt), ## __VA_ARGS__) +#define log_warning(fmt, ...) log_text(LOG_LEVEL_WARNING, (fmt), ## __VA_ARGS__) +#define log_error(fmt, ...) log_text(LOG_LEVEL_WARNING, (fmt), ## __VA_ARGS__) + +#endif Modified: daemon/trunk/libs/USBDaemon_pidfile.c =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_pidfile.c 2007-05-02 15:08:18 UTC (rev 296) @@ -29,7 +29,9 @@ #include <string.h> #include <errno.h> #include <signal.h> + #include "USBDaemon_globals.h" +#include "USBDaemon_log.h" #define PIDFILE "/var/run/tuxdaemon.pid" @@ -94,7 +96,7 @@ if ((fd = open(PIDFILE, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1 || (f = fdopen(fd, "r+")) == NULL) { - fprintf(stderr, "Can't open or create %s: %m\n", PIDFILE); + log_error("Can't open or create %s: %m", PIDFILE); return 0; } @@ -102,14 +104,14 @@ { fscanf(f, "%d", &pid); fclose(f); - fprintf(stderr, "Can't lock, lock is held by pid %d.\n", pid); + log_error("Can't lock, lock is held by pid %d", pid); return 0; } pid = getpid(); if (!fprintf(f, "%d\n", pid)) { - fprintf(stderr, "Can't write pid: %m.\n"); + log_error("Can't write pid: %m"); close(fd); return 0; } @@ -117,7 +119,7 @@ if (flock(fd, LOCK_UN) == -1) { - fprintf(stderr, "Can't unlock pidfile %s: %m.\n", PIDFILE); + log_error("Can't unlock pidfile %s: %m", PIDFILE); close(fd); return 0; } @@ -137,16 +139,3 @@ { return unlink(PIDFILE); } - -/************************************************************************ */ - -/* Terminate */ - -/************************************************************************ */ -void terminate(int ret) -{ - if (remove_pid()) - fprintf(stderr, "Could not delete PID file\n"); - - exit(ret); -} Modified: daemon/trunk/libs/USBDaemon_pidfile.h =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.h 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_pidfile.h 2007-05-02 15:08:18 UTC (rev 296) @@ -62,10 +62,4 @@ */ extern int remove_pid(void); -/* terminate - * - * Remove the pid file and exit - */ -extern void terminate(int ret); - #endif Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-05-02 15:08:18 UTC (rev 296) @@ -25,6 +25,7 @@ #include <stdio.h> #include "USBDaemon_status_table.h" #include "USBDaemon_globals.h" +#include "USBDaemon_log.h" #include "USBDaemon_tcp_server.h" #include "../tuxdefs/commands.h" @@ -120,8 +121,8 @@ default: if (show_invalid_raw) - printf("%.2x %.2x %.2x %.2x\n", new_status[0], new_status[1], - new_status[2], new_status[3]); + log_debug("%.2x %.2x %.2x %.2x", new_status[0], new_status[1], + new_status[2], new_status[3]); break; } } @@ -266,7 +267,7 @@ if (new_code) { - printf("Remote code : %.2x\n", code); + log_debug("Remote code : %.2x", code); for (i = 0; i < sizeof(tcp_frame); i++) tcp_frame[i] = '\0'; @@ -330,12 +331,12 @@ tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_BACKWARD; if (portb.bits.PB0) { - printf("wings motor backward 0\n"); + log_debug("wings motor backward 0"); tcp_frame[5] = 0; } else { - printf("wings motor backward 1\n"); + log_debug("wings motor backward 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -347,12 +348,12 @@ tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_BACKWARD; if (portb.bits.PB1) { - printf("spin motor backward 0\n"); + log_debug("spin motor backward 0"); tcp_frame[5] = 0; } else { - printf("spin motor backward 1\n"); + log_debug("spin motor backward 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -364,12 +365,12 @@ tcp_frame[4] = DATA_STATUS_SPIN_MOTOR_FORWARD; if (portb.bits.PB2) { - printf("spin motor forward 0\n"); + log_debug("spin motor forward 0"); tcp_frame[5] = 0; } else { - printf("spin motor forward 1\n"); + log_debug("spin motor forward 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -382,13 +383,13 @@ if (portb.bits.PB3) { /* Up */ - printf("mouth open position 0\n"); + log_debug("mouth open position 0"); tcp_frame[5] = 0; } else { /* Down */ - printf("mouth open position 1\n"); + log_debug("mouth open position 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -400,12 +401,12 @@ tcp_frame[4] = DATA_STATUS_MOUTH_CLOSED_POSITION; if (portb.bits.PB4) { - printf("mouth close position 0\n"); + log_debug("mouth close position 0"); tcp_frame[5] = 0; } else { - printf("mouth close position 1\n"); + log_debug("mouth close position 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -417,12 +418,12 @@ tcp_frame[4] = DATA_STATUS_CHARGER_INHIBIT_SIGNAL; if (portb.bits.PB6) { - printf("charger inhibit signal 0\n"); + log_debug("charger inhibit signal 0"); tcp_frame[5] = 0; } else { - printf("charger inhibit signal 1\n"); + log_debug("charger inhibit signal 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -455,12 +456,12 @@ tcp_frame[4] = DATA_STATUS_WINGS_POSITION_SWITCH; if (portc.bits.PB1) { - printf("wings position switch 0\n"); + log_debug("wings position switch 0"); tcp_frame[5] = 0; } else { - printf("wings position switch 1\n"); + log_debug("wings position switch 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -472,12 +473,12 @@ tcp_frame[4] = DATA_STATUS_RIGHT_BLUE_LED; if (portc.bits.PB2) { - printf("right blue led off\n"); + log_debug("right blue led off"); tcp_frame[5] = 0; } else { - printf("right blue led on\n"); + log_debug("right blue led on"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -489,12 +490,12 @@ tcp_frame[4] = DATA_STATUS_LEFT_BLUE_LED; if (portc.bits.PB3) { - printf("left blue led off\n"); + log_debug("left blue led off"); tcp_frame[5] = 0; } else { - printf("left blue led on\n"); + log_debug("left blue led on"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -527,12 +528,12 @@ tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_EYES; if (portd.bits.PB0) { - printf("head motor for eyes 0\n"); + log_debug("head motor for eyes 0"); tcp_frame[5] = 0; } else { - printf("head motor for eyes 1\n"); + log_debug("head motor for eyes 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -544,12 +545,12 @@ tcp_frame[4] = DATA_STATUS_HEAD_MOTOR_FOR_MOUTH; if (portd.bits.PB1) { - printf("head motor for mouth 0\n"); + log_debug("head motor for mouth 0"); tcp_frame[5] = 0; } else { - printf("head motor for mouth 1\n"); + log_debug("head motor for mouth 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -561,12 +562,12 @@ tcp_frame[4] = DATA_STATUS_SPIN_POSITION_SWITCH; if (portd.bits.PB3) { - printf("spin position switch 0\n"); + log_debug("spin position switch 0"); tcp_frame[5] = 0; } else { - printf("spin position switch 1\n"); + log_debug("spin position switch 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -578,12 +579,12 @@ tcp_frame[4] = DATA_STATUS_WINGS_MOTOR_FORWARD; if (portd.bits.PB4) { - printf("wings motor forward 0\n"); + log_debug("wings motor forward 0"); tcp_frame[5] = 0; } else { - printf("wings motor forward 1\n"); + log_debug("wings motor forward 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -595,12 +596,12 @@ tcp_frame[4] = DATA_STATUS_IR_LED; if (portd.bits.PB5) { - printf("IR led 0\n"); + log_debug("IR led 0"); tcp_frame[5] = 0; } else { - printf("IR led 1\n"); + log_debug("IR led 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -612,12 +613,12 @@ tcp_frame[4] = DATA_STATUS_EYES_OPEN_POSITION_SWITCH; if (portd.bits.PB6) { - printf("eyes open position switch 0\n"); + log_debug("eyes open position switch 0"); tcp_frame[5] = 0; } else { - printf("eyes open position switch 1\n"); + log_debug("eyes open position switch 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -629,12 +630,12 @@ tcp_frame[4] = DATA_STATUS_EYES_CLOSED_POSITION_SWITCH; if (portd.bits.PB7) { - printf("eyes closed position switch 0\n"); + log_debug("eyes closed position switch 0"); tcp_frame[5] = 0; } else { - printf("eyes closed position switch 1\n"); + log_debug("eyes closed position switch 1"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -667,12 +668,12 @@ tcp_frame[4] = DATA_STATUS_LEFT_WING_PUSH; if (sensors1.bits.PB0) { - printf("Left wing button Up\n"); + log_debug("Left wing button Up"); tcp_frame[5] = 0; } else { - printf("Left wing button Down\n"); + log_debug("Left wing button Down"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -684,12 +685,12 @@ tcp_frame[4] = DATA_STATUS_RIGHT_WING_PUSH; if (sensors1.bits.PB1) { - printf("Right wing button Up\n"); + log_debug("Right wing button Up"); tcp_frame[5] = 0; } else { - printf("Right wing button Down\n"); + log_debug("Right wing button Down"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -701,12 +702,12 @@ tcp_frame[4] = DATA_STATUS_POWER_PLUG_SWITCH; if (sensors1.bits.PB2) { - printf("power plug insertion switch on\n"); + log_debug("power plug insertion switch on"); tcp_frame[5] = 0; } else { - printf("power plug insertion switch off\n"); + log_debug("power plug insertion switch off"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -718,12 +719,12 @@ tcp_frame[4] = DATA_STATUS_HEAD_PUSH_SWITCH; if (sensors1.bits.PB3) { - printf("Head button Up\n"); + log_debug("Head button Up"); tcp_frame[5] = 0; } else { - printf("Head button Down\n"); + log_debug("Head button Down"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); @@ -735,12 +736,12 @@ tcp_frame[4] = DATA_STATUS_CHARGER_LED_STATUS; if (sensors1.bits.PB4) { - printf("Charger led 1\n"); + log_debug("Charger led 1"); tcp_frame[5] = 1; } else { - printf("Charger led 0\n"); + log_debug("Charger led 0"); tcp_frame[5] = 0; } tcp_server_send_raw(tcp_frame); @@ -752,12 +753,12 @@ tcp_frame[4] = DATA_STATUS_MUTE_STATUS; if (sensors1.bits.PB7) { - printf("mute status off\n"); + log_debug("mute status off"); tcp_frame[5] = 0; } else { - printf("mute status on\n"); + log_debug("mute status on"); tcp_frame[5] = 1; } tcp_server_send_raw(tcp_frame); Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-05-02 15:08:18 UTC (rev 296) @@ -34,6 +34,7 @@ #include "USBDaemon_status_table.h" #include "USBDaemon_tcp_server.h" #include "USBDaemon_pidfile.h" +#include "USBDaemon_log.h" /*_____________________ V A R I A B L E S __________________________________*/ @@ -63,7 +64,7 @@ if ((tcp_server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - printf("TCP socket : server error\n"); + log_error("TCP socket: socket creation failed: %m"); return NULL; } @@ -72,7 +73,7 @@ (tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { /* Don't need to quit on this one. */ - printf("TCP socket : setsockopt error\n"); + log_error("TCP socket: setsockopt failed: %m"); } bzero(&tcp_server_sockaddr, sizeof(tcp_server_sockaddr)); @@ -83,15 +84,16 @@ (tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, sizeof(tcp_server_sockaddr)) < 0) { - printf("TCP socket : binding error\n"); - terminate(2); + log_error("TCP socket: bind failed: %m"); + exit(2); } if (listen(tcp_server_handle, 5) < 0) { - printf("TCP socket : listening error\n"); + log_error("TCP socket: listen failed: %m"); return NULL; } - printf("TCP socket : opened\n"); + + log_info("TCP socket: opened"); tux_tcp_status = TUX_TCP_STATUS_UP; while (tcp_server_handle >= 0) @@ -130,7 +132,7 @@ accept(tcp_server_handle, (struct sockaddr *)NULL, NULL); if (tmp_client < 0) - fprintf(stderr, "accept failed: %m\n"); + log_error("accept failed: %m"); else { int client_added = 0; @@ -145,10 +147,10 @@ } if (client_added) - printf("client %d connected\n", i); + log_info("client %d connected", i); else { - fprintf(stderr, "client rejected: client table full\n"); + log_error("client rejected: client table full"); close(tmp_client); } } Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-05-02 15:08:18 UTC (rev 296) @@ -26,6 +26,7 @@ #include <errno.h> #include "USBDaemon_usb_enum.h" #include "USBDaemon_globals.h" +#include "USBDaemon_log.h" #include "USBDaemon_status_table.h" #include "USBDaemon_usb_readWrite.h" #include "USBDaemon_command_tux.h" @@ -84,7 +85,7 @@ setuid(NEWUID); if (!tux_hdl) { - printf("Can't open device: %s (%d)\n", strerror(errno), errno); + log_error("Can't open device: %s (%d)", strerror(errno), errno); return NULL; } /* Claim device interface */ @@ -95,7 +96,7 @@ error = usb_claim_interface(tux_hdl, TUX_INTERFACE); if (error != 0) { - printf("Can't claim interface: %s (%d)\n", strerror(errno), errno); + log_error("Can't claim interface: %s (%d)", strerror(errno), errno); return NULL; } } @@ -116,7 +117,7 @@ tux_device = usb_find_TuxDroid(); if (tux_device == NULL) { - printf("Tux dongle not found\n"); + log_error("Tux dongle not found"); } sleep(1); } @@ -125,11 +126,11 @@ /* Old firmware should be discarded here */ if (tux_device->descriptor.bcdDevice < 0x100) { - printf("\nERROR: Your dongle firmware is too old.\n" + log_error("Your dongle firmware is too old.\n" "This version is not compatible with this daemon, please update\n" "the firmware to version 1.00 or better.\n" "Check http://www.tuxisalive.com/documentation/how-to/updating-the-firmware\n" - "for details.\n"); + "for details."); return (0); } @@ -137,7 +138,7 @@ tux_handle = usb_open_TuxDroid(tux_device); if (tux_handle == NULL) { - printf("You must load the daemon in root mode\n"); + log_error("You must load the daemon in root mode"); return (0); } return (1); @@ -167,9 +168,9 @@ if (dongle_is_present_counter == 0) if (usb_find_TuxDroid() == NULL) { - printf("Tux dongle is disconnected\n"); + log_error("Tux dongle is disconnected"); send_daemon_disconnected(); - terminate(1); + exit(1); } usb_get_status_TuxDroid(); usleep(50000); Modified: daemon/trunk/libs/USBDaemon_usb_readWrite.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/libs/USBDaemon_usb_readWrite.c 2007-05-02 15:08:18 UTC (rev 296) @@ -25,6 +25,7 @@ #include <stdio.h> #include "USBDaemon_usb_enum.h" #include "USBDaemon_globals.h" +#include "USBDaemon_log.h" #include "USBDaemon_status_table.h" #include "USBDaemon_tcp_server.h" #include "USBDaemon_usb_readWrite.h" @@ -71,7 +72,7 @@ unsigned char cmd_send[5]; unsigned char cmd_dispatch[5]; int idx; - unsigned char i, j; + unsigned char i; for (i = 0; i < 64; i++) data[i] = 0; @@ -115,8 +116,8 @@ update_system_status_table(cmd_dispatch); if (show_frames) - printf("RF_st: %.2x CMD_st: %.2x NB_frames : %d idx : %d\n", RF_status, - CMD_status, NUMBER_frames, idx); + log_debug("RF_st: %.2x CMD_st: %.2x NB_frames : %d idx : %d", + RF_status, CMD_status, NUMBER_frames, idx); if (NUMBER_frames > 0 && NUMBER_frames < 16) { @@ -129,11 +130,9 @@ cmd_dispatch[4] = 0; if (show_raw_status) - { - for (j = 0; j < 5; j++) - printf("%.2x ", cmd_dispatch[j]); - printf("\n"); - } + log_debug("%.2x %.2x %.2x %.2x %.2x", cmd_dispatch[0], + cmd_dispatch[1], cmd_dispatch[2], cmd_dispatch[3], + cmd_dispatch[4]); update_raw_status_table(cmd_dispatch); } Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-04-28 09:26:30 UTC (rev 295) +++ daemon/trunk/main.c 2007-05-02 15:08:18 UTC (rev 296) @@ -36,6 +36,7 @@ #include <signal.h> #include <sys/file.h> #include "libs/USBDaemon_globals.h" +#include "libs/USBDaemon_log.h" #include "libs/USBDaemon_pidfile.h" #include "libs/USBDaemon_usb_enum.h" #include "libs/USBDaemon_tcp_server.h" @@ -99,18 +100,6 @@ /************************************************************************ */ -/* On_close_daemon */ - -/************************************************************************ */ -static void on_close_daemon(int sig) -{ - send_daemon_disconnected(); - printf("Daemon closed\n"); - terminate(0); -} - -/************************************************************************ */ - /* Clean closing of STD IN-OUT FILENO*/ /************************************************************************ */ @@ -134,12 +123,57 @@ return fd2; } +/** + * \brief Called when exiting. Performs cleanup. + */ +static void terminate(void) +{ + send_daemon_disconnected(); + + if (remove_pid()) + log_error("Could not delete PID file"); + + log_info("terminated"); + log_close(); +} + +/** + * \brief Toggle debugging mode on/off. + * + * \param[in] sig Signal (unused) + */ +static void toggle_debugging(int sig) +{ + static int first_call = 1; + static log_level_t saved_level; + int debugging; + + if (first_call) + { + debugging = (log_get_level() == LOG_LEVEL_DEBUG); + first_call = 0; + } + + debugging = !debugging; + if (debugging) + { + saved_level = log_get_level(); + log_set_level(LOG_LEVEL_DEBUG); + log_debug("debugging mode activated"); + } + else + { + log_debug("debugging mode deactivated"); + log_set_level(saved_level); + } +} + /************************************************************************ */ /* Daemonizer */ /************************************************************************ */ -static void daemonize(unsigned char shell_view) +static void daemonize(log_target_t log_target, log_level_t log_level) { pid_t pid, sid; @@ -149,33 +183,44 @@ case 0: break; case -1: /*erreur */ - terminate(1); + exit(1); break; default: exit(0); } + atexit(terminate); + signal(SIGUSR2, toggle_debugging); + + if (!log_open(log_target)) + { + log_error("failed opening log file"); + exit(1); + } + + log_set_level(log_level); + umask(0); sid = setsid(); if (sid < 0) { - perror("sid"); - terminate(1); + log_error("setsid failed: %m"); + exit(1); } if (chdir("/") < 0) { - perror("chdir"); - terminate(1); + log_error("chdir failed: %m"); + exit(1); } daemon_pid = (unsigned short)getpid(); - printf("Tux USB Daemon started : pid = %d\n", (int)getpid()); + log_info("Tux USB Daemon started: pid = %d", (int)getpid()); if (!write_pid()) exit(1); /* No shell */ - if (!shell_view) + if (log_target != LOG_TARGET_SHELL) { fd_nullify(STDIN_FILENO); fd_nullify(STDOUT_FILENO); @@ -185,6 +230,16 @@ /************************************************************************ */ +/* On_close_daemon */ + +/************************************************************************ */ +static void on_close_daemon(int sig) +{ + exit(0); +} + +/************************************************************************ */ + /* Show usages of tux daemon */ /************************************************************************ */ @@ -192,12 +247,16 @@ { printf("usage : tuxdaemon [options]\n"); printf("options:\n"); - printf(" -d start in daemon mode\n"); - printf(" -v view in shell ( for daemon mode )\n"); - printf(" -st show the structure of the usb frames\n"); - printf(" -sr show all raw status\n"); - printf(" -si show only invalid raw status\n"); - printf(" -h show this usage list\n"); + printf(" -d start in daemon mode\n"); + printf(" -lsys log to syslog\n"); + printf(" -ltux log to /var/log/tuxdaemon\n"); + printf(" -lstd log to stdout & stderr\n"); + printf(" -v view in shell (deprecated, use -lstd instead)\n"); + printf(" -debug start in debug mode\n"); + printf(" -st show the structure of the usb frames\n"); + printf(" -sr show all raw status\n"); + printf(" -si show only invalid raw status\n"); + printf(" -h show this usage list\n"); } /************************************************************************ */ @@ -212,7 +271,8 @@ GThread *TcpThread; GError *error = NULL; unsigned char i; - unsigned char shell_view = 0; + log_target_t log_target = LOG_TARGET_SYSLOG; + log_level_t log_level = LOG_LEVEL_INFO; unsigned char daemonized = 0; /* On exiting */ @@ -227,10 +287,16 @@ /* Program arguments */ for (i = 1; i < argc; i++) { - if (!strcmp("-v", argv[i])) - shell_view = 1; - else if (!strcmp("-d", argv[i])) + if (!strcmp("-d", argv[i])) daemonized = 1; + else if (!strcmp("-lsys", argv[i])) + log_target = LOG_TARGET_SYSLOG; + else if (!strcmp("-ltux", argv[i])) + log_target = LOG_TARGET_TUX; + else if (!strcmp("-lstd", argv[i]) || !strcmp("-v", argv[i])) + log_target = LOG_TARGET_SHELL; + else if (!strcmp("-debug", argv[i])) + log_level = LOG_LEVEL_DEBUG; else if (!strcmp("-st", argv[i])) show_frames = 1; else if (!strcmp("-sr", argv[i])) @@ -250,9 +316,14 @@ } if (daemonized) - daemonize(shell_view); - else if (!write_pid()) - exit(1); + daemonize(log_target, log_level); + else + { + log_open(LOG_TARGET_SHELL); + log_set_level(log_level); + if (!write_pid()) + exit(1); + } /* Setup & print daemon information */ setup_daemon_info(); @@ -267,7 +338,7 @@ /* open USB handler and setuid nobody */ if (!usb_init_TuxDroid()) { - terminate(1); + exit(1); } /* Gestion Multithread */ if (!g_thread_supported()) @@ -276,16 +347,16 @@ } else { - printf("g_thread NOT supported\n"); - terminate(1); + log_error("g_thread NOT supported"); + exit(1); } /* Start USB task thread */ UsbThread = g_thread_create((GThreadFunc) usb_start_task, NULL, TRUE, &error); if (UsbThread == NULL) { - printf("Thread creation failed: %s \n", error->message); - terminate(2); + log_error("Thread creation failed: %s", error->message); + exit(2); } /* Start TCP task thread */ @@ -294,13 +365,12 @@ &error); if (TcpThread == NULL) { - printf("Thread creation failed: %s \n", error->message); - terminate(2); + log_error("Thread creation failed: %s", error->message); + exit(2); } loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(loop); - terminate(0); - return (0); + exit(0); } |
From: neimad <c2m...@c2...> - 2007-04-28 09:27:16
|
Author: neimad Date: 2007-04-28 11:26:30 +0200 (Sat, 28 Apr 2007) New Revision: 295 Modified: daemon/trunk/libs/USBDaemon_pidfile.c Log: * Doxygenified comments. Modified: daemon/trunk/libs/USBDaemon_pidfile.c =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.c 2007-04-27 18:58:27 UTC (rev 294) +++ daemon/trunk/libs/USBDaemon_pidfile.c 2007-04-28 09:26:30 UTC (rev 295) @@ -1,4 +1,3 @@ - /* * Tux Droid - USB Daemon * Copyright (C) 2007 C2ME Sa <rem...@c2...> @@ -42,11 +41,10 @@ /************************************************************************ */ -/* read_pid +/** + * @brief Read the pid from the pid file. * - * Reads the specified pidfile and returns the read pid. - * 0 is returned if either there's no pidfile, it's empty - * or no pid can be read. + * @return 0 if either there's no pid file, it's empty or no pid can be read */ int read_pid(void) { @@ -62,11 +60,10 @@ return pid; } -/* check_pid +/** + * @brief Check existence of the process whose pid is in the pid file. * - * Reads the pid using read_pid and looks up the pid in the process - * table (using /proc) to determine if the process already exists. If - * so 1 is returned, otherwise 0. + * @return 1 if the process exists, 0 otherwise */ int check_pid(void) { @@ -76,22 +73,17 @@ if (!pid || pid == getpid()) return 0; - /* - * The 'standard' method of doing this is to try and do a 'fake' kill - * of the process. If an ESRCH error is returned the process cannot - * be found -- GW - */ - /* But... errno is usually changed only on error.. */ + /* Sending signal 0 sets errno to ESRCH if the process doesn't exist */ if (kill(pid, 0) && errno == ESRCH) return 0; return pid; } -/* write_pid +/** + * @brief Write the current process' pid to the pid file. * - * Writes the pid to the specified file. If that fails 0 is - * returned, otherwise the pid. + * @return Pid written if successful, 0 otherwise */ int write_pid(void) { @@ -136,10 +128,10 @@ return pid; } -/* remove_pid +/** + * @brief Delete the pid file. * - * Remove the the specified file. The result from unlink(2) - * is returned + * @return result from unkink(2) */ int remove_pid(void) { |
From: neimad <c2m...@c2...> - 2007-04-27 19:00:25
|
Author: neimad Date: 2007-04-27 20:58:27 +0200 (Fri, 27 Apr 2007) New Revision: 294 Modified: daemon/trunk/libs/USBDaemon_command_tux.h daemon/trunk/libs/USBDaemon_globals.h daemon/trunk/libs/USBDaemon_pidfile.h daemon/trunk/libs/USBDaemon_status_table.h daemon/trunk/libs/USBDaemon_tcp_server.h daemon/trunk/libs/USBDaemon_usb_enum.h daemon/trunk/libs/USBDaemon_usb_readWrite.h Log: * Added preprocessor directive for inclusion of headers. Can't believe I didn't see that before ! Modified: daemon/trunk/libs/USBDaemon_command_tux.h =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_command_tux.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_COMMAND_TUX_H__ +#define __USBDAEMON_COMMAND_TUX_H__ + /*_____________________ I N C L U D E S____________________________________ */ /*_____________________ D E F I N E S ______________________________________*/ @@ -68,3 +71,5 @@ unsigned char middle_add, unsigned char higher_add); extern unsigned char send_test_sound(); + +#endif Modified: daemon/trunk/libs/USBDaemon_globals.h =================================================================== --- daemon/trunk/libs/USBDaemon_globals.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_globals.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_GLOBALS_H__ +#define __USBDAEMON_GLOBALS_H__ + /*_____________________ I N C L U D E S____________________________________ */ #include <usb.h> #include <pthread.h> @@ -61,3 +64,5 @@ int revision; }; extern struct version_s version; + +#endif Modified: daemon/trunk/libs/USBDaemon_pidfile.h =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_pidfile.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id: main.c 242 2007-04-13 08:48:33Z remi $ */ +#ifndef __USBDAEMON_PIDFILE_H__ +#define __USBDAEMON_PIDFILE_H__ + /************************************************************************ */ /* Functions to deal with the pidfile @@ -64,3 +67,5 @@ * Remove the pid file and exit */ extern void terminate(int ret); + +#endif Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_STATUS_TABLE_H__ +#define __USBDAEMON_STATUS_TABLE_H__ + /*_____________________ I N C L U D E S____________________________________ */ #include "../tuxdefs/commands.h" @@ -263,3 +266,5 @@ unsigned char mouth_position, unsigned char wings_position); extern void position2_changed(unsigned char new_value); + +#endif Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-27 18:58:27 UTC (rev 294) @@ -1,4 +1,3 @@ - /* * Tux Droid - USB Daemon * Copyright (C) 2007 C2ME Sa <rem...@c2...> @@ -21,6 +20,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_TCP_SERVER_H__ +#define __USBDAEMON_TCP_SERVER_H__ + /*_____________________ I N C L U D E S____________________________________ */ #include <sys/types.h> #include <sys/socket.h> @@ -60,3 +62,5 @@ const tcp_frame_t data); extern void send_daemon_disconnected(); extern void tcp_remove_client(unsigned char id_client); + +#endif Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_USB_ENUM_H__ +#define __USBDAEMON_USB_ENUM_H__ + /*_____________________ I N C L U D E S____________________________________ */ #include <usb.h> @@ -43,3 +46,5 @@ extern struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *device); extern void *usb_start_task(void *unused); extern int usb_init_TuxDroid(void); + +#endif Modified: daemon/trunk/libs/USBDaemon_usb_readWrite.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_readWrite.h 2007-04-24 20:25:34 UTC (rev 293) +++ daemon/trunk/libs/USBDaemon_usb_readWrite.h 2007-04-27 18:58:27 UTC (rev 294) @@ -21,6 +21,9 @@ /* $Id$ */ +#ifndef __USBDAEMON_USB_READWRITE_H__ +#define __USBDAEMON_USB_READWRITE_H__ + /*_____________________ I N C L U D E S____________________________________ */ #include <usb.h> @@ -32,3 +35,5 @@ extern void usb_read_TuxDroid(void); extern void usb_get_status_TuxDroid(void); extern unsigned char usb_write_TuxDroid(unsigned char datas[]); + +#endif |
From: doegox <c2m...@c2...> - 2007-04-26 11:07:10
|
Author: doegox Date: 2007-04-24 22:25:34 +0200 (Tue, 24 Apr 2007) New Revision: 293 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h daemon/trunk/main.c Log: Open USB handler and setuid before creating threads, this makes things easier especially to get closer to linuxthread compatibility. Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-24 20:25:34 UTC (rev 293) @@ -43,13 +43,10 @@ pthread_mutex_t tcp_mutex; int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = - { [0 ... TUX_MAX_TCP_CLIENTS - 1] = -1 }; + {[(0)...(TUX_MAX_TCP_CLIENTS - 1)] = -1 }; client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; unsigned char tcp_clients_count = 0; -pthread_cond_t dropcond; -pthread_mutex_t dropcond_mutex; - /*_____________________ F U N C T I O N S __________________________________*/ /************************************************************************ */ @@ -63,10 +60,7 @@ int val; pthread_mutex_init(&tcp_mutex, NULL); - pthread_mutex_init(&dropcond_mutex, NULL); - /* Wait for privileges to be dropped */ - pthread_cond_wait(&dropcond, &dropcond_mutex); if ((tcp_server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("TCP socket : server error\n"); @@ -74,8 +68,8 @@ } val = 1; - if (setsockopt(tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, - &val, sizeof(val)) < 0) + if (setsockopt + (tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { /* Don't need to quit on this one. */ printf("TCP socket : setsockopt error\n"); @@ -85,8 +79,9 @@ tcp_server_sockaddr.sin_family = AF_INET; tcp_server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); tcp_server_sockaddr.sin_port = htons(TUX_SERVER_PORT); - if (bind(tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, - sizeof(tcp_server_sockaddr)) < 0) + if (bind + (tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, + sizeof(tcp_server_sockaddr)) < 0) { printf("TCP socket : binding error\n"); terminate(2); Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-24 20:25:34 UTC (rev 293) @@ -52,7 +52,6 @@ extern unsigned char tcp_clients_count; extern client_name_t tcp_clients_name[]; extern pthread_mutex_t tcp_mutex; -extern pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ extern void *tcp_server_start_task(void *unused); Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-24 20:25:34 UTC (rev 293) @@ -104,13 +104,11 @@ /************************************************************************ */ -/* usb_start_task_TuxDroid() */ +/* usb_init_TuxDroid() */ /************************************************************************ */ -void *usb_start_task(void *unused) +int usb_init_TuxDroid(void) { - unsigned char dongle_is_present_counter; - pthread_mutex_init(&usb_mutex, NULL); /* Find Tux */ do @@ -132,7 +130,7 @@ "the firmware to version 1.00 or better.\n" "Check http://www.tuxisalive.com/documentation/how-to/updating-the-firmware\n" "for details.\n"); - terminate(1); + return (0); } /* Get Device handle */ @@ -140,12 +138,20 @@ if (tux_handle == NULL) { printf("You must load the daemon in root mode\n"); - terminate(1); + return (0); } + return (1); +} - /* Signals that root privileges were dropped */ - pthread_cond_signal(&dropcond); +/************************************************************************ */ +/* usb_start_task_TuxDroid() */ + +/************************************************************************ */ +void *usb_start_task(void *unused) +{ + unsigned char dongle_is_present_counter; + usleep(50000); TUX_USB_STATUS = TUX_USB_CONNECTED; /* Reinit audio channel */ Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-24 20:25:34 UTC (rev 293) @@ -42,3 +42,4 @@ extern struct usb_device *usb_find_TuxDroid(); extern struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *device); extern void *usb_start_task(void *unused); +extern int usb_init_TuxDroid(void); Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/main.c 2007-04-24 20:25:34 UTC (rev 293) @@ -264,6 +264,11 @@ usb_init(); #endif + /* open USB handler and setuid nobody */ + if (!usb_init_TuxDroid()) + { + terminate(1); + } /* Gestion Multithread */ if (!g_thread_supported()) { @@ -274,8 +279,6 @@ printf("g_thread NOT supported\n"); terminate(1); } - - pthread_cond_init(&dropcond, 0); /* Start USB task thread */ UsbThread = g_thread_create((GThreadFunc) usb_start_task, NULL, TRUE, &error); |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-24 20:26:38
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 293 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h daemon/trunk/main.c Log: doegox 2007-04-24 22:25:34 +0200 (Tue, 24 Apr 2007) 133 Open USB handler and setuid before creating threads, this makes things easier especially to get closer to linuxthread compatibility. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-24 20:25:34 UTC (rev 293) @@ -43,13 +43,10 @@ pthread_mutex_t tcp_mutex; int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = - { [0 ... TUX_MAX_TCP_CLIENTS - 1] = -1 }; + {[(0)...(TUX_MAX_TCP_CLIENTS - 1)] = -1 }; client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; unsigned char tcp_clients_count = 0; -pthread_cond_t dropcond; -pthread_mutex_t dropcond_mutex; - /*_____________________ F U N C T I O N S __________________________________*/ /************************************************************************ */ @@ -63,10 +60,7 @@ int val; pthread_mutex_init(&tcp_mutex, NULL); - pthread_mutex_init(&dropcond_mutex, NULL); - /* Wait for privileges to be dropped */ - pthread_cond_wait(&dropcond, &dropcond_mutex); if ((tcp_server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("TCP socket : server error\n"); @@ -74,8 +68,8 @@ } val = 1; - if (setsockopt(tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, - &val, sizeof(val)) < 0) + if (setsockopt + (tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { /* Don't need to quit on this one. */ printf("TCP socket : setsockopt error\n"); @@ -85,8 +79,9 @@ tcp_server_sockaddr.sin_family = AF_INET; tcp_server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); tcp_server_sockaddr.sin_port = htons(TUX_SERVER_PORT); - if (bind(tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, - sizeof(tcp_server_sockaddr)) < 0) + if (bind + (tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, + sizeof(tcp_server_sockaddr)) < 0) { printf("TCP socket : binding error\n"); terminate(2); Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-24 20:25:34 UTC (rev 293) @@ -52,7 +52,6 @@ extern unsigned char tcp_clients_count; extern client_name_t tcp_clients_name[]; extern pthread_mutex_t tcp_mutex; -extern pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ extern void *tcp_server_start_task(void *unused); Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-24 20:25:34 UTC (rev 293) @@ -104,13 +104,11 @@ /************************************************************************ */ -/* usb_start_task_TuxDroid() */ +/* usb_init_TuxDroid() */ /************************************************************************ */ -void *usb_start_task(void *unused) +int usb_init_TuxDroid(void) { - unsigned char dongle_is_present_counter; - pthread_mutex_init(&usb_mutex, NULL); /* Find Tux */ do @@ -132,7 +130,7 @@ "the firmware to version 1.00 or better.\n" "Check http://www.tuxisalive.com/documentation/how-to/updating-the-firmware\n" "for details.\n"); - terminate(1); + return (0); } /* Get Device handle */ @@ -140,12 +138,20 @@ if (tux_handle == NULL) { printf("You must load the daemon in root mode\n"); - terminate(1); + return (0); } + return (1); +} - /* Signals that root privileges were dropped */ - pthread_cond_signal(&dropcond); +/************************************************************************ */ +/* usb_start_task_TuxDroid() */ + +/************************************************************************ */ +void *usb_start_task(void *unused) +{ + unsigned char dongle_is_present_counter; + usleep(50000); TUX_USB_STATUS = TUX_USB_CONNECTED; /* Reinit audio channel */ Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-24 20:25:34 UTC (rev 293) @@ -42,3 +42,4 @@ extern struct usb_device *usb_find_TuxDroid(); extern struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *device); extern void *usb_start_task(void *unused); +extern int usb_init_TuxDroid(void); Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-04-23 19:45:50 UTC (rev 292) +++ daemon/trunk/main.c 2007-04-24 20:25:34 UTC (rev 293) @@ -264,6 +264,11 @@ usb_init(); #endif + /* open USB handler and setuid nobody */ + if (!usb_init_TuxDroid()) + { + terminate(1); + } /* Gestion Multithread */ if (!g_thread_supported()) { @@ -274,8 +279,6 @@ printf("g_thread NOT supported\n"); terminate(1); } - - pthread_cond_init(&dropcond, 0); /* Start USB task thread */ UsbThread = g_thread_create((GThreadFunc) usb_start_task, NULL, TRUE, &error); |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-23 19:45:52
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 292 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c Log: neimad 2007-04-23 21:45:50 +0200 (Mon, 23 Apr 2007) 75 * Fixed a few re-indentation oddities, removed unnecessary curly braces. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:40:07 UTC (rev 291) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:45:50 UTC (rev 292) @@ -64,6 +64,7 @@ pthread_mutex_init(&tcp_mutex, NULL); pthread_mutex_init(&dropcond_mutex, NULL); + /* Wait for privileges to be dropped */ pthread_cond_wait(&dropcond, &dropcond_mutex); if ((tcp_server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0) @@ -73,8 +74,8 @@ } val = 1; - if (setsockopt - (tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) + if (setsockopt(tcp_server_handle, SOL_SOCKET, SO_REUSEADDR, + &val, sizeof(val)) < 0) { /* Don't need to quit on this one. */ printf("TCP socket : setsockopt error\n"); @@ -84,9 +85,8 @@ tcp_server_sockaddr.sin_family = AF_INET; tcp_server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); tcp_server_sockaddr.sin_port = htons(TUX_SERVER_PORT); - if (bind - (tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, - sizeof(tcp_server_sockaddr)) < 0) + if (bind(tcp_server_handle, (struct sockaddr *)&tcp_server_sockaddr, + sizeof(tcp_server_sockaddr)) < 0) { printf("TCP socket : binding error\n"); terminate(2); @@ -210,9 +210,7 @@ continue; if (send(tcp_clients_handle[i], data, sizeof(tcp_frame_t), 0) == 0) - { tcp_remove_client(i); - } } pthread_mutex_unlock(&tcp_mutex); @@ -237,9 +235,7 @@ { if (send(tcp_clients_handle[client_index], data, sizeof(tcp_frame_t), 0) == 0) - { tcp_remove_client(client_index); - } } pthread_mutex_unlock(&tcp_mutex); |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-23 19:40:10
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 291 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/libs/USBDaemon_usb_enum.h Log: neimad 2007-04-23 21:40:07 +0200 (Mon, 23 Apr 2007) 119 * Fixed parameters and return type of tcp_server_start_task() and usb_start_task(). They now conform to GThreadFunc. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:29:13 UTC (rev 290) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:40:07 UTC (rev 291) @@ -57,7 +57,7 @@ /* tcp_server_start_task() */ /************************************************************************ */ -void tcp_server_start_task() +void *tcp_server_start_task(void *unused) { tcp_frame_t datas_recv; int val; @@ -69,7 +69,7 @@ if ((tcp_server_handle = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("TCP socket : server error\n"); - return; + return NULL; } val = 1; @@ -94,7 +94,7 @@ if (listen(tcp_server_handle, 5) < 0) { printf("TCP socket : listening error\n"); - return; + return NULL; } printf("TCP socket : opened\n"); tux_tcp_status = TUX_TCP_STATUS_UP; @@ -183,6 +183,8 @@ pthread_mutex_unlock(&tcp_mutex); } + + return NULL; } /************************************************************************ */ Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 19:29:13 UTC (rev 290) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 19:40:07 UTC (rev 291) @@ -55,7 +55,7 @@ extern pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ -extern void tcp_server_start_task(); +extern void *tcp_server_start_task(void *unused); extern void tcp_server_send_raw(const tcp_frame_t data); extern void tcp_server_send_raw_to_client(int client_index, const tcp_frame_t data); Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 19:29:13 UTC (rev 290) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 19:40:07 UTC (rev 291) @@ -107,7 +107,7 @@ /* usb_start_task_TuxDroid() */ /************************************************************************ */ -void usb_start_task() +void *usb_start_task(void *unused) { unsigned char dongle_is_present_counter; @@ -168,4 +168,6 @@ usb_get_status_TuxDroid(); usleep(50000); } + + return NULL; } Modified: daemon/trunk/libs/USBDaemon_usb_enum.h =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-23 19:29:13 UTC (rev 290) +++ daemon/trunk/libs/USBDaemon_usb_enum.h 2007-04-23 19:40:07 UTC (rev 291) @@ -41,4 +41,4 @@ /*_____________________ F U N C T I O N S __________________________________*/ extern struct usb_device *usb_find_TuxDroid(); extern struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *device); -extern void usb_start_task(); +extern void *usb_start_task(void *unused); |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-23 19:29:16
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 290 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c Log: neimad 2007-04-23 21:29:13 +0200 (Mon, 23 Apr 2007) 81 * Regrouped logically linked variables together, spaced variable declarations. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:25:56 UTC (rev 289) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:29:13 UTC (rev 290) @@ -36,15 +36,19 @@ #include "USBDaemon_pidfile.h" /*_____________________ V A R I A B L E S __________________________________*/ + int tcp_server_handle = -1; +struct sockaddr_in tcp_server_sockaddr; +tux_tcp_status_t tux_tcp_status = TUX_TCP_STATUS_DOWN; +pthread_mutex_t tcp_mutex; + int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = { [0 ... TUX_MAX_TCP_CLIENTS - 1] = -1 }; +client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; unsigned char tcp_clients_count = 0; -client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; -struct sockaddr_in tcp_server_sockaddr; -tux_tcp_status_t tux_tcp_status = TUX_TCP_STATUS_DOWN; -pthread_mutex_t tcp_mutex, dropcond_mutex; + pthread_cond_t dropcond; +pthread_mutex_t dropcond_mutex; /*_____________________ F U N C T I O N S __________________________________*/ |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-23 19:26:47
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 289 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h daemon/trunk/libs/USBDaemon_usb_enum.c daemon/trunk/main.c Log: neimad 2007-04-23 21:25:56 +0200 (Mon, 23 Apr 2007) 111 * Moved definition of dropcond from main.c to USBDaemon_tcp_server.c where it belongs (with dropcond_mutex). svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 17:30:51 UTC (rev 288) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 19:25:56 UTC (rev 289) @@ -44,7 +44,7 @@ struct sockaddr_in tcp_server_sockaddr; tux_tcp_status_t tux_tcp_status = TUX_TCP_STATUS_DOWN; pthread_mutex_t tcp_mutex, dropcond_mutex; -extern pthread_cond_t dropcond; +pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 17:30:51 UTC (rev 288) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-23 19:25:56 UTC (rev 289) @@ -52,6 +52,7 @@ extern unsigned char tcp_clients_count; extern client_name_t tcp_clients_name[]; extern pthread_mutex_t tcp_mutex; +extern pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ extern void tcp_server_start_task(); Modified: daemon/trunk/libs/USBDaemon_usb_enum.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 17:30:51 UTC (rev 288) +++ daemon/trunk/libs/USBDaemon_usb_enum.c 2007-04-23 19:25:56 UTC (rev 289) @@ -37,7 +37,6 @@ struct usb_device *tux_device; TUX_USB_CONN_STATUS TUX_USB_STATUS = TUX_USB_DISCONNECTED; pthread_mutex_t usb_mutex; -extern pthread_cond_t dropcond; /*_____________________ F U N C T I O N S __________________________________*/ Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2007-04-23 17:30:51 UTC (rev 288) +++ daemon/trunk/main.c 2007-04-23 19:25:56 UTC (rev 289) @@ -56,7 +56,6 @@ unsigned char show_raw_status = 0; unsigned char show_invalid_raw = 0; unsigned short daemon_pid = 0; -pthread_cond_t dropcond; /************************************************************************ */ |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-23 17:31:43
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 288 Modified: daemon/trunk/libs/USBDaemon_tcp_server.c Log: neimad 2007-04-23 19:30:51 +0200 (Mon, 23 Apr 2007) 59 * Fixed compilation error (introduced by indent, I guess). svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-22 18:13:55 UTC (rev 287) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-23 17:30:51 UTC (rev 288) @@ -37,8 +37,8 @@ /*_____________________ V A R I A B L E S __________________________________*/ int tcp_server_handle = -1; -int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = {[0...TUX_MAX_TCP_CLIENTS - 1] = - -1 }; +int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = + { [0 ... TUX_MAX_TCP_CLIENTS - 1] = -1 }; unsigned char tcp_clients_count = 0; client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; struct sockaddr_in tcp_server_sockaddr; |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-22 18:14:11
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 287 Modified: firmware/tuxcore/trunk/bootloader.c firmware/tuxcore/trunk/communication.c firmware/tuxcore/trunk/communication.h firmware/tuxcore/trunk/config.c firmware/tuxcore/trunk/fifo.c firmware/tuxcore/trunk/fifo.h firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/i2c.c firmware/tuxcore/trunk/i2c.h firmware/tuxcore/trunk/ir.c firmware/tuxcore/trunk/ir.h firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/parser.h firmware/tuxcore/trunk/standalone.c firmware/tuxcore/trunk/version.h Log: doegox 2007-04-22 20:13:55 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxcore/trunk/bootloader.c =================================================================== --- firmware/tuxcore/trunk/bootloader.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/bootloader.c 2007-04-22 18:13:55 UTC (rev 287) @@ -33,7 +33,7 @@ uint8_t b[2]; } union16_t; -void (*jump_to_application)(void) = (void *)0x0000; +void (*jump_to_application) (void) = (void *)0x0000; void i2cWaitForComplete(void); /** \ingroup minimal_bootloader @@ -45,13 +45,13 @@ union16_t pageAddress, data; uint16_t address; uint8_t i, twStatus, eeprom_flg = 0; - volatile uint16_t _count=0; + volatile uint16_t _count = 0; - for (_count = 0;_count<0xFFFF; _count++); /* wait for the head button to stabilize */ - if (SW_HD_PIN & SW_HD_MK) /* if head is not pushed at startup */ + for (_count = 0; _count < 0xFFFF; _count++) ; /* wait for the head button to stabilize */ + if (SW_HD_PIN & SW_HD_MK) /* if head is not pushed at startup */ jump_to_application(); - LED_DDR |= LED_L_MK; /* light on left led */ + LED_DDR |= LED_L_MK; /* light on left led */ LED_PT |= LED_L_MK; TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ @@ -60,29 +60,35 @@ TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) { - i2cWaitForComplete(); /* wait the I2C address */ - if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) while(1); + i2cWaitForComplete(); /* wait the I2C address */ + if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) + while (1) ; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the high byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the high byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[1] = TWDR; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the low byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the low byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[0] = TWDR; - if (pageAddress.w & 0x003F) while(1); /* incorrect page address */ - if (pageAddress.w >= 0x8000) /* eeprom programming */ + if (pageAddress.w & 0x003F) + while (1) ; /* incorrect page address */ + if (pageAddress.w >= 0x8000) /* eeprom programming */ { - eeprom_flg = 1; /* don't overwrite the bootloader */ - pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ + eeprom_flg = 1; /* don't overwrite the bootloader */ + pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ } - else if (pageAddress.w >= 0x1E00) while(1); /* don't overwrite the bootloader */ - else eeprom_flg = 0; /* flash programming */ + else if (pageAddress.w >= 0x1E00) + while (1) ; /* don't overwrite the bootloader */ + else + eeprom_flg = 0; /* flash programming */ address = pageAddress.w; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - for (i=0; i<SPM_PAGESIZE; i++) /* fill the complete page with the next data */ + for (i = 0; i < SPM_PAGESIZE; i++) /* fill the complete page with the next data */ { - i2cWaitForComplete(); /* wait data */ + i2cWaitForComplete(); /* wait data */ if ((twStatus = TW_STATUS) == TW_SR_DATA_ACK) { if ((i & 0x01) == 0) @@ -94,31 +100,33 @@ data.b[1] = TWDR; if (eeprom_flg) { - eeprom_write_word ((uint16_t *)address, data.w); + eeprom_write_word((uint16_t *) address, data.w); eeprom_busy_wait(); } else - boot_page_fill (address, data.w); + boot_page_fill(address, data.w); address += 2; } TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); } - else while(1); /* error in communication */ + else + while (1) ; /* error in communication */ } i2cWaitForComplete(); - if ((twStatus = TW_STATUS) != TW_SR_STOP) while(1); /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ - TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ + if ((twStatus = TW_STATUS) != TW_SR_STOP) + while (1) ; /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ + TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ if (!eeprom_flg) { - boot_page_erase (pageAddress.w); - boot_spm_busy_wait (); - boot_page_write (pageAddress.w); /* Store buffer in flash page */ - boot_spm_busy_wait (); + boot_page_erase(pageAddress.w); + boot_spm_busy_wait(); + boot_page_write(pageAddress.w); /* Store buffer in flash page */ + boot_spm_busy_wait(); } } } -void i2cWaitForComplete (void) +void i2cWaitForComplete(void) { - while( !(TWCR & _BV(TWINT)) ); /* wait for i2c interface to complete operation */ + while (!(TWCR & _BV(TWINT))) ; /* wait for i2c interface to complete operation */ } Modified: firmware/tuxcore/trunk/communication.c =================================================================== --- firmware/tuxcore/trunk/communication.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/communication.c 2007-04-22 18:13:55 UTC (rev 287) @@ -38,8 +38,8 @@ * Note that because of this filo stack, commands are not processed in the * order they were issued when the stack holds multiple commands. */ -uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ -uint8_t commandBufIdx = 0; /* index indicating the number of data in the buffer */ +uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ +uint8_t commandBufIdx = 0; /* index indicating the number of data in the buffer */ /* * audioIntBuf is a single buffer for audio commands to be sent to the audio @@ -50,16 +50,18 @@ * cleared when the command is sent so it can be used to check whether the * buffer is empty or not. */ -uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for audio commands to be sent to the audio interface */ -uint8_t audioIntBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ +uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for audio commands to be sent to the audio interface */ +uint8_t audioIntBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ /* * statusBuf is a fifo buffer for status commands to be sent by i2c and then * over the RF link */ uint8_t statusFifoBuf[STATUS_BUF_SIZE]; /* statusBuf is a fifo buffer for status commands to be sent over i2c */ -fifo_t statusFifo_s = {statusFifoBuf, sizeof statusFifoBuf-1, 0, 0}, *statusFifo = &statusFifo_s; +fifo_t statusFifo_s = { statusFifoBuf, sizeof statusFifoBuf - 1, 0, 0 } +, *statusFifo = &statusFifo_s; + uint8_t i2cCommandType; volatile uint8_t i2c_pause; @@ -71,10 +73,10 @@ */ void i2cCommunicationInit(void) { - i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission. Should be before i2cInit otherwise interrupts should be disabled */ - i2cInit(); /* start twi interface */ - i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ - i2cDeviceAddrRW = 0x14; /* set tuxaudio CPU device address */ + i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission. Should be before i2cInit otherwise interrupts should be disabled */ + i2cInit(); /* start twi interface */ + i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ + i2cDeviceAddrRW = 0x14; /* set tuxaudio CPU device address */ } /* @@ -84,13 +86,13 @@ * We basically do a transfer of the received data to the * commandBuf here. */ -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData) +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) { - uint8_t i; + uint8_t i; - receiveData += receiveDataLength; - for (i=0; i< receiveDataLength; i++) - commandBuf[commandBufIdx++] = *--receiveData; + receiveData += receiveDataLength; + for (i = 0; i < receiveDataLength; i++) + commandBuf[commandBufIdx++] = *--receiveData; } /* @@ -105,29 +107,30 @@ */ uint8_t sendCommand(void) { - uint16_t wait=0; + uint16_t wait = 0; i2cMasterStart(); cli(); - i2cFlags.m_end = 0; /* reset master transmission end flag */ + i2cFlags.m_end = 0; /* reset master transmission end flag */ i2cFlags.i2c_busy = 1; - sei(); /* TODO change this by a save restore */ - while(1) /* wait until the command is sent successfully or a nack is received */ + sei(); /* TODO change this by a save restore */ + while (1) /* wait until the command is sent successfully or a nack is received */ { if (i2cFlags.i2c_busy == 0) { if (i2cFlags.mt_nack) { cli(); - i2cFlags.mt_nack = 0; /* keep buffer and reset nack status */ + i2cFlags.mt_nack = 0; /* keep buffer and reset nack status */ sei(); i2c_pause = AFTER_NACK_DELAY; - return 1; /* return nack error */ + return 1; /* return nack error */ } - else if (i2cFlags.m_end) return 0; /* return success */ - else + else if (i2cFlags.m_end) + return 0; /* return success */ + else { - i2cMasterStart(); /* previous transmission was cancelled by arbitration lost or any problem so restart */ + i2cMasterStart(); /* previous transmission was cancelled by arbitration lost or any problem so restart */ cli(); i2cFlags.i2c_busy = 1; sei(); @@ -138,12 +141,12 @@ { wait = 0; TWCR = 0; - while(wait++ < 0xFFF0); + while (wait++ < 0xFFF0) ; i2cFlags.i2c_busy = 0; i2cFlags.m_end = 0; i2cFlags.mt_nack = 0; i2cInit(); - return 1; /* return error */ + return 1; /* return error */ } /* end: workaround for the I2C bug */ } @@ -152,27 +155,30 @@ uint8_t fetchCommands(void) { uint8_t i; - if (statusFifoFlag) return 0; /* fifo is being updated outside the interrupt so don't touch it */ - if (audioIntBufIdx) /* one audio command to send */ + + if (statusFifoFlag) + return 0; /* fifo is being updated outside the interrupt so don't touch it */ + if (audioIntBufIdx) /* one audio command to send */ { - for (i=0; i<audioIntBufIdx; i++) i2cSendData[i] = audioIntBuf[i]; + for (i = 0; i < audioIntBufIdx; i++) + i2cSendData[i] = audioIntBuf[i]; i2cSendDataLength = audioIntBufIdx; i2cCommandType = AUDIO_CMD; return 1; } - else if (!isFifoEmpty(statusFifo)) /* if no audio and there's some status to send, get the next value */ + else if (!isFifoEmpty(statusFifo)) /* if no audio and there's some status to send, get the next value */ { - for (i=0; i<4; i++) /* so we loop 4 times here to get all command bytes */ + for (i = 0; i < 4; i++) /* so we loop 4 times here to get all command bytes */ { i2cSendData[i] = 0; - popFifo(statusFifo, &i2cSendData[i]); /* TODO add a test on returned value to detect any corrupted fifo */ + popFifo(statusFifo, &i2cSendData[i]); /* TODO add a test on returned value to detect any corrupted fifo */ // XXX to delete i2cSendData[i] = statusBuf[statusBufIdx-i-1]; [> decrease index then get the value <] } - i2cSendDataLength = 4; /* status commands have always 3 parameters */ + i2cSendDataLength = 4; /* status commands have always 3 parameters */ i2cCommandType = STATUS_CMD; return 1; } - + return 0; } @@ -192,18 +198,19 @@ { uint8_t i; - if (i2cFlags.i2c_busy) return; /* check if i2c hardware not busy */ - if (i2c_pause) return; /* if nacked, wait a moment */ - if (fetchCommands()) /* and commands are ready */ + if (i2cFlags.i2c_busy) + return; /* check if i2c hardware not busy */ + if (i2c_pause) + return; /* if nacked, wait a moment */ + if (fetchCommands()) /* and commands are ready */ { - if (sendCommand()) /* nack error so we have to restore the values */ + if (sendCommand()) /* nack error so we have to restore the values */ { if (i2cCommandType == STATUS_CMD) - for (i=0; i<4; i++) /* so we loop 4 times here to get all command bytes */ - pushFifo(statusFifo, i2cSendData[i]); /* TODO try to find a better way to do this later on */ + for (i = 0; i < 4; i++) /* so we loop 4 times here to get all command bytes */ + pushFifo(statusFifo, i2cSendData[i]); /* TODO try to find a better way to do this later on */ } - else - if (i2cCommandType == AUDIO_CMD) - audioIntBufIdx = 0; /* clear buffer if command sent successfully */ + else if (i2cCommandType == AUDIO_CMD) + audioIntBufIdx = 0; /* clear buffer if command sent successfully */ } } Modified: firmware/tuxcore/trunk/communication.h =================================================================== --- firmware/tuxcore/trunk/communication.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/communication.h 2007-04-22 18:13:55 UTC (rev 287) @@ -20,7 +20,7 @@ /* $Id: */ #ifndef COMMUNICATION_H -#define COMMUNICATION_H +#define COMMUNICATION_H #include "common/commands.h" #include "fifo.h" @@ -30,24 +30,25 @@ #define MAX_COMMAND_SIZE 4 #define AFTER_NACK_DELAY 6 -enum CMD_TYPE {AUDIO_CMD, STATUS_CMD}; +enum CMD_TYPE +{ AUDIO_CMD, STATUS_CMD }; -extern uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ -extern uint8_t commandBufIdx; /* index indicating the number of data in the buffer */ -extern uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -extern uint8_t audioIntBufIdx; /* index indicating the number of valid bytes in the buffer */ +extern uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ +extern uint8_t commandBufIdx; /* index indicating the number of data in the buffer */ +extern uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +extern uint8_t audioIntBufIdx; /* index indicating the number of valid bytes in the buffer */ + // extern uint8_t statusBuf[STATUS_BUF_SIZE]; [> incomingBuf is a filo buffer for commands received over i2c to be sent back over the RF link <] // extern uint8_t statusBufIdx; [> index indicating the number of valid bytes in the buffer <] extern fifo_t *statusFifo; -extern uint8_t errorBuf[2]; /* buffer for command errors, should contain command number and error code */ +extern uint8_t errorBuf[2]; /* buffer for command errors, should contain command number and error code */ -extern void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData); +extern void i2cSlaveReceiveService(uint8_t receiveDataLength, + uint8_t * receiveData); void i2cCommunicationInit(void); void sendCommands(void); uint8_t fetchCommands(void); - - -#endif /* COMMUNICATION_H */ +#endif /* COMMUNICATION_H */ Modified: firmware/tuxcore/trunk/config.c =================================================================== --- firmware/tuxcore/trunk/config.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/config.c 2007-04-22 18:13:55 UTC (rev 287) @@ -64,11 +64,13 @@ /* Initialize the configuration registers */ void config_init(void) { - eeprom_read_block((void*)&tux_config, (const void*)&tux_config_default, sizeof(tuxcore_config_t)); + eeprom_read_block((void *)&tux_config, (const void *)&tux_config_default, + sizeof(tuxcore_config_t)); } /* Save the configuration registers to the eeprom */ void config_write(void) { - eeprom_write_block((const void*)&tux_config, (void*)&tux_config_default, sizeof(tuxcore_config_t)); + eeprom_write_block((const void *)&tux_config, (void *)&tux_config_default, + sizeof(tuxcore_config_t)); } Modified: firmware/tuxcore/trunk/fifo.c =================================================================== --- firmware/tuxcore/trunk/fifo.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/fifo.c 2007-04-22 18:13:55 UTC (rev 287) @@ -67,7 +67,7 @@ * \param p fifo pointer * * Note that the first element in the fifo will be stored in p->buffer[1] and not p->buffer[0] */ -void resetFifo(fifo_t *p) +void resetFifo(fifo_t * p) { p->inIdx = 0; p->outIdx = 0; @@ -77,16 +77,16 @@ * \param p fifo pointer * \return TRUE if fifo buffer is full */ -uint8_t isFifoFull(fifo_t *p) +uint8_t isFifoFull(fifo_t * p) { - return (p->outIdx == (((uint8_t)(p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return (p->outIdx == (((uint8_t) (p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Return TRUE if the fifo buffer is empty (22b). * \param p fifo pointer * \return TRUE if fifo buffer is empty */ -uint8_t isFifoEmpty(fifo_t *p) +uint8_t isFifoEmpty(fifo_t * p) { return (p->outIdx == p->inIdx); } @@ -95,9 +95,9 @@ * \param p fifo pointer * \return number of elements in the buffer */ -uint8_t fifoLength(fifo_t *p) +uint8_t fifoLength(fifo_t * p) { - return ((uint8_t)(p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return ((uint8_t) (p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Add one data byte to the fifo buffer (32b). @@ -106,15 +106,15 @@ * * If the fifo is already full, return immediately without doing anything. */ -void pushFifo(fifo_t *p, uint8_t data) +void pushFifo(fifo_t * p, uint8_t data) { - uint8_t inIdx; /* use of a local variable to reduce code size */ + uint8_t inIdx; /* use of a local variable to reduce code size */ - inIdx = ((uint8_t)(p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ - if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ + inIdx = ((uint8_t) (p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ { - p->inIdx = inIdx; /* ++ index */ - p->buffer[inIdx] = data; /* stora data */ + p->inIdx = inIdx; /* ++ index */ + p->buffer[inIdx] = data; /* stora data */ } } @@ -127,16 +127,17 @@ * fifo is empty, the index is not decreased, '1' is returned and the pointed * data is left unchanged. */ -uint8_t popFifo(fifo_t *p, uint8_t *data) +uint8_t popFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ - *data = p->buffer[p->outIdx]; /* get data */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ + *data = p->buffer[p->outIdx]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Get the oldest byte in the fifo without removing it @@ -147,14 +148,15 @@ * Return '0' if a value has been read out. If the fifo is empty, '1' * is returned and the pointed data is left unchanged. */ -uint8_t getFifo(fifo_t *p, uint8_t *data) +uint8_t getFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - *data = p->buffer[p->outIdx + 1]; /* get data */ + *data = p->buffer[p->outIdx + 1]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Pull the oldest byte from the fifo, always return something even if @@ -165,13 +167,14 @@ * If the fifo is empty, the index is not decreased but the latest value is * returned. */ -uint8_t pullFifo(fifo_t *p) +uint8_t pullFifo(fifo_t * p) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ } - return p->buffer[p->outIdx]; /* get data in all cases */ + return p->buffer[p->outIdx]; /* get data in all cases */ } + /*@}*/ Modified: firmware/tuxcore/trunk/fifo.h =================================================================== --- firmware/tuxcore/trunk/fifo.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/fifo.h 2007-04-22 18:13:55 UTC (rev 287) @@ -75,13 +75,13 @@ /** \brief UD- Rate at which the adaptation is done. * * The adaptation function will only be run each 2^FIFO_ADAPT_RATE sample */ -#define FIFO_ADAPT_RATE 3 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ +#define FIFO_ADAPT_RATE 3 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ /** \brief UD- High level threshold */ -#define FIFO_ADAPT_HIGH (p->size - (p->size>>2)) /* 3/4 of size */ +#define FIFO_ADAPT_HIGH (p->size - (p->size>>2)) /* 3/4 of size */ /** \brief UD- Low level threshold */ -#define FIFO_ADAPT_LOW (p->size>>2) /* 1/4 of size */ +#define FIFO_ADAPT_LOW (p->size>>2) /* 1/4 of size */ /** \brief Fifo structure type which holds the buffer, it's size, input and * output indexes. @@ -89,33 +89,34 @@ Note that the buffer can only hold (size - 1) elements to be able to make the difference between completely full and completely empty states. */ -typedef struct fifo_s { +typedef struct fifo_s +{ /** array that will store the elements */ - uint8_t *buffer; + uint8_t *buffer; /** size of the fifo buffer array minus 1 * The wrap around is made by a 'AND' function so the AND should be made with * the (array size -1) to be able to clear all bits above the array size. * This -1 is not related to the fact that the buffer can only hold (size -1) * elements. */ - uint8_t size; + uint8_t size; /** input index which indexes the last pushed value */ - uint8_t inIdx; + uint8_t inIdx; /** output index which indexes the last popped value */ - uint8_t outIdx; + uint8_t outIdx; } fifo_t; /* * Extern declarations */ -void resetFifo(fifo_t *p); -uint8_t isFifoFull(fifo_t *p); -uint8_t isFifoEmpty(fifo_t *p); -uint8_t fifoLength(fifo_t *p); -void pushFifo(fifo_t *p, uint8_t data); -uint8_t popFifo(fifo_t *p, uint8_t *data); -uint8_t getFifo(fifo_t *p, uint8_t *data); -uint8_t pullFifo(fifo_t *p); -void adaptFifo(fifo_t *p); +void resetFifo(fifo_t * p); +uint8_t isFifoFull(fifo_t * p); +uint8_t isFifoEmpty(fifo_t * p); +uint8_t fifoLength(fifo_t * p); +void pushFifo(fifo_t * p, uint8_t data); +uint8_t popFifo(fifo_t * p, uint8_t * data); +uint8_t getFifo(fifo_t * p, uint8_t * data); +uint8_t pullFifo(fifo_t * p); +void adaptFifo(fifo_t * p); -#endif /* FIFO_H */ +#endif /* FIFO_H */ Modified: firmware/tuxcore/trunk/global.c =================================================================== --- firmware/tuxcore/trunk/global.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/global.c 2007-04-22 18:13:55 UTC (rev 287) @@ -35,21 +35,27 @@ * General global registers */ uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag = 0; -uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen = 0xFF; +uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, + last_tux_seen = 0xFF; uint8_t led_backup; - /* * Condition flags */ -struct condition_table cond_flags = {1}; /* Set startup flag */ +struct condition_table cond_flags = { 1 }; /* Set startup flag */ /* * Version number */ #define CPU_NUMBER TUXCORE_CPU_NUM /* tuxcore CPU */ -const author_t author __attribute__((section("version.3"))) = {AUTHOR_CMD, AUTHOR_ID, 0}; -const revision_t svn_revision __attribute__((section("version.2"))) = {REVISION_CMD, SVN_REV, SVN_STATUS}; -const version_t tag_version __attribute__((section("version.1"))) = {VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; +const author_t author __attribute__ ((section("version.3"))) = +{ +AUTHOR_CMD, AUTHOR_ID, 0}; +const revision_t svn_revision __attribute__ ((section("version.2"))) = +{ +REVISION_CMD, SVN_REV, SVN_STATUS}; +const version_t tag_version __attribute__ ((section("version.1"))) = +{ +VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/global.h 2007-04-22 18:13:55 UTC (rev 287) @@ -38,31 +38,31 @@ // #define SW_MK (_BV(PB3) | _BV(PB4) | _BV(PB5)) // #define SW_LW_MK _BV(PB3) [> left wing switch <] // #define SW_RW_MK _BV(PB4) [> right wing switch <] -#define SW_HD_PIN PINB /* head switch input port */ -#define SW_HD_PT PORTB /* head switch port */ -#define SW_HD_DDR DDRB /* head switch DDR */ -#define SW_HD_MK _BV(PB5) /* head switch */ +#define SW_HD_PIN PINB /* head switch input port */ +#define SW_HD_PT PORTB /* head switch port */ +#define SW_HD_DDR DDRB /* head switch DDR */ +#define SW_HD_MK _BV(PB5) /* head switch */ /* Position Switches */ -#define PSW_SPIN_MK _BV(PD3) /* spin switch */ +#define PSW_SPIN_MK _BV(PD3) /* spin switch */ #define PSW_SPIN_PT PORTD #define PSW_SPIN_PIN PIND #define PSW_SPIN_DDR DDRD -#define PSW_WINGS_MK _BV(PC1) /* wings switch */ +#define PSW_WINGS_MK _BV(PC1) /* wings switch */ #define PSW_WINGS_PT PORTC #define PSW_WINGS_PIN PINC #define PSW_WINGS_DDR DDRC #define PSW_MOUTH_PT PORTB #define PSW_MOUTH_PIN PINB #define PSW_MOUTH_DDR DDRB -#define PSW_MOUTH_O_MK _BV(PB3) /* mouth switch when opened */ -#define PSW_MOUTH_C_MK _BV(PB4) /* mouth switch when closed */ +#define PSW_MOUTH_O_MK _BV(PB3) /* mouth switch when opened */ +#define PSW_MOUTH_C_MK _BV(PB4) /* mouth switch when closed */ #define PSW_MOUTH_MK (PSW_MOUTH_O_MK | PSW_MOUTH_C_MK) #define PSW_EYES_PT PORTD #define PSW_EYES_PIN PIND #define PSW_EYES_DDR DDRD -#define PSW_EYES_O_MK _BV(PD6) /* eyes switch when opened */ -#define PSW_EYES_C_MK _BV(PD7) /* eyes switch when closed */ +#define PSW_EYES_O_MK _BV(PD6) /* eyes switch when opened */ +#define PSW_EYES_C_MK _BV(PD7) /* eyes switch when closed */ #define PSW_EYES_MK (PSW_EYES_O_MK | PSW_EYES_C_MK) /* @@ -71,10 +71,10 @@ * -------------------------------------------------------- */ -#define IR_LED_PT PORTD /* ir led */ +#define IR_LED_PT PORTD /* ir led */ #define IR_LED_DDR DDRD #define IR_LED_MK _BV(PD5) -#define IR_REC_PT PORTD /* ir receiver */ +#define IR_REC_PT PORTD /* ir receiver */ #define IR_REC_PIN PIND #define IR_REC_DDR DDRD #define IR_REC_MK _BV(PD2) @@ -105,11 +105,11 @@ * -------------------------------------------------------- */ -#define LED_PT PORTC /* blue eye leds */ -#define LED_PIN PINC /* blue eye leds */ +#define LED_PT PORTC /* blue eye leds */ +#define LED_PIN PINC /* blue eye leds */ #define LED_DDR DDRC -#define LED_L_MK _BV(PC2) /* right blue led */ -#define LED_R_MK _BV(PC3) /* left blue led */ +#define LED_L_MK _BV(PC2) /* right blue led */ +#define LED_R_MK _BV(PC3) /* left blue led */ #define LED_MK (LED_R_MK | LED_L_MK) /* @@ -123,7 +123,6 @@ #define EXIO_PIN PINB #define EXIO_MK _BV(PB7) - /* * -------------------------------------------------------- * MOTORS @@ -134,29 +133,29 @@ // #define MOT_PT PORTD [> motors port <] // #define MOT_DDR DDRD // #define MOT_MK (MOT_WINGS_FW | MOT_WINGS_BW | MOT_MOUTH_MK | MOT_EYES_MK | MOT_SPIN_R_MK | MOT_SPIN_L_MK) -#define MOT_WINGS_BW_MK _BV(PD4) /* wing motor forward */ +#define MOT_WINGS_BW_MK _BV(PD4) /* wing motor forward */ #define MOT_WINGS_BW_PT PORTD #define MOT_WINGS_BW_DDR DDRD -#define MOT_WINGS_FW_MK _BV(PB0) /* wing motor backward */ +#define MOT_WINGS_FW_MK _BV(PB0) /* wing motor backward */ #define MOT_WINGS_FW_PT PORTB #define MOT_WINGS_FW_DDR DDRB #define wingsPwmMask pwmMaskB -#define MOT_MOUTH_MK _BV(PD1) /* mouth motor (forward) */ +#define MOT_MOUTH_MK _BV(PD1) /* mouth motor (forward) */ #define MOT_MOUTH_PT PORTD #define MOT_MOUTH_DDR DDRD -#define MOT_IMOUTH_MK _BV(PD0) /* inverted mouth motor (backward) */ +#define MOT_IMOUTH_MK _BV(PD0) /* inverted mouth motor (backward) */ #define MOT_IMOUTH_PT PORTD #define MOT_IMOUTH_DDR DDRD -#define MOT_IEYES_MK _BV(PD1) /* eyes motor (forward) */ +#define MOT_IEYES_MK _BV(PD1) /* eyes motor (forward) */ #define MOT_IEYES_PT PORTD #define MOT_IEYES_DDR DDRD -#define MOT_EYES_MK _BV(PD0) /* inverted eyes motor (backward) */ +#define MOT_EYES_MK _BV(PD0) /* inverted eyes motor (backward) */ #define MOT_EYES_PT PORTD #define MOT_EYES_DDR DDRD -#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ +#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ #define MOT_SPIN_R_PT PORTB #define MOT_SPIN_R_DDR DDRB -#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ +#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ #define MOT_SPIN_L_PT PORTB #define MOT_SPIN_L_DDR DDRB #define MOT_SPIN_MK (MOT_SPIN_L_MK | MOT_SPIN_R_MK) @@ -165,12 +164,12 @@ #define spinPwmMask pwmMaskB /* Control */ -#define EYES_OPEN_DLY 4 /* 4ms unit */ -#define EYES_ICLOSE_DLY 4 /* 4ms unit */ -#define MOUTH_OPEN_DLY 2 /* 4ms unit */ -#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ -#define SPIN_INTT_DLY 10 /* 4ms unit */ -#define WINGS_STOP_DLY 4 /* 4ms unit */ +#define EYES_OPEN_DLY 4 /* 4ms unit */ +#define EYES_ICLOSE_DLY 4 /* 4ms unit */ +#define MOUTH_OPEN_DLY 2 /* 4ms unit */ +#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ +#define SPIN_INTT_DLY 10 /* 4ms unit */ +#define WINGS_STOP_DLY 4 /* 4ms unit */ /* * -------------------------------------------------------- @@ -182,14 +181,14 @@ * gStatus.sw: Switch Status */ -#define GSTATUS_LEFTWINGBTN_MK STATUS_LEFTWINGBTN_MK -#define GSTATUS_RIGHTWINGBTN_MK STATUS_RIGHTWINGBTN_MK -#define GSTATUS_POWERPLUGSW_MK STATUS_POWERPLUGSW_MK -#define GSTATUS_HEADBTN_MK STATUS_HEADBTN_MK -#define GSTATUS_CHARGER_MK STATUS_CHARGER_MK -#define GSTATUS_RF_MK STATUS_RF_MK -#define GSTATUS_VCC_MK STATUS_VCC_MK -#define GSTATUS_MUTE_MK STATUS_MUTE_MK +#define GSTATUS_LEFTWINGBTN_MK STATUS_LEFTWINGBTN_MK +#define GSTATUS_RIGHTWINGBTN_MK STATUS_RIGHTWINGBTN_MK +#define GSTATUS_POWERPLUGSW_MK STATUS_POWERPLUGSW_MK +#define GSTATUS_HEADBTN_MK STATUS_HEADBTN_MK +#define GSTATUS_CHARGER_MK STATUS_CHARGER_MK +#define GSTATUS_RF_MK STATUS_RF_MK +#define GSTATUS_VCC_MK STATUS_VCC_MK +#define GSTATUS_MUTE_MK STATUS_MUTE_MK /* * gStatus.pos: Position Status (Eyes - Wings - Mouth) @@ -223,8 +222,8 @@ * gStatus.bat: Orientation Status */ -#define GSTATUS_ORI_ORI 0x03 /* Orientation mask */ -#define GSTATUS_ORI_CNT 0xFC /* Turn count mask */ +#define GSTATUS_ORI_ORI 0x03 /* Orientation mask */ +#define GSTATUS_ORI_CNT 0xFC /* Turn count mask */ /* * gStatus.mot: Motors Status @@ -257,9 +256,9 @@ */ /* bits 5-0: - VTCCCCCC (C: RC5 6 bits command) */ -#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ -#define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ -#define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ +#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ +#define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ +#define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ /* * -------------------------------------------------------- @@ -272,12 +271,12 @@ * XXX improve display of bits */ -#define COM_EYES_MK 0x01 /* Eyes motor command mask */ -#define COM_MOUTH_MK 0x02 /* Mouth motor command mask */ +#define COM_EYES_MK 0x01 /* Eyes motor command mask */ +#define COM_MOUTH_MK 0x02 /* Mouth motor command mask */ -#define COM_WINGS_MK 0x20 /* Wings motor */ +#define COM_WINGS_MK 0x20 /* Wings motor */ -#define COM_SPIN_STP_MK 0x80 /* Spin motor stop at bat position */ +#define COM_SPIN_STP_MK 0x80 /* Spin motor stop at bat position */ //#define COM_SPIN_R_MK 0x40 [> Spin Right <] //#define COM_SPIN_L_MK 0x80 [> Spin Left <] @@ -289,14 +288,14 @@ typedef struct { - uint8_t sw; /* Switches */ - uint8_t mic; /* Microphone level */ - uint8_t bat; /* Battery level */ - uint8_t lightL; /* Light level low byte */ - uint8_t lightH; /* Light level high byte */ - uint8_t lightM; /* Light mode */ - uint8_t ir; /* IR RC5 code received from tux's remote */ - uint8_t pos; /* Poitionning */ + uint8_t sw; /* Switches */ + uint8_t mic; /* Microphone level */ + uint8_t bat; /* Battery level */ + uint8_t lightL; /* Light level low byte */ + uint8_t lightH; /* Light level high byte */ + uint8_t lightM; /* Light mode */ + uint8_t ir; /* IR RC5 code received from tux's remote */ + uint8_t pos; /* Poitionning */ } GSTATUS; @@ -305,42 +304,42 @@ /* * Software timers */ -extern uint8_t t4ms_tim; /* 4ms main tick timer */ -extern uint8_t t100ms_tim; /* 100ms tick timer */ -extern uint8_t t1s_tim; /* 1s tick timer XXX unused */ +extern uint8_t t4ms_tim; /* 4ms main tick timer */ +extern uint8_t t100ms_tim; /* 100ms tick timer */ +extern uint8_t t1s_tim; /* 1s tick timer XXX unused */ /* * intflags * Flags that are set inside interrupts, and reset outside when processed */ -uint8_t light_f; /* adc interrupt for light measurement */ -uint8_t batt_f; /* adc interrupt for battery measurement */ -uint8_t ir_f; /* ir code received */ +uint8_t light_f; /* adc interrupt for light measurement */ +uint8_t batt_f; /* adc interrupt for battery measurement */ +uint8_t ir_f; /* ir code received */ /* * Standalone behavior */ -extern uint8_t test_mode; /* normal mode */ +extern uint8_t test_mode; /* normal mode */ /* * General global registers */ extern uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag; -extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen; +extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, + last_tux_seen; extern uint8_t led_backup; - /* * Condition flags */ -#define COND_RESET_NBR 8 /* number of flags that should be reset, change this according to the table below */ +#define COND_RESET_NBR 8 /* number of flags that should be reset, change this according to the table below */ struct condition_table { /* flags reset by the COND_RESET_CMD */ - uint8_t startup; /* set startup condition at initialization */ + uint8_t startup; /* set startup condition at initialization */ uint8_t head; uint8_t left_flip; uint8_t right_flip; @@ -363,6 +362,6 @@ #define mb_test_condition (PINC & _BV(PC2)) #define sigout_set turnLeftLedOn #define sigout_unset turnLeftLedOff -#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ -#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ +#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ +#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ #endif Modified: firmware/tuxcore/trunk/i2c.c =================================================================== --- firmware/tuxcore/trunk/i2c.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/i2c.c 2007-04-22 18:13:55 UTC (rev 287) @@ -28,14 +28,14 @@ /* * DEBUG and TEST flags */ -#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ -#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ +#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ +#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ /* DEBUG definitions and variables */ #if (__i2c_debug__) -uint8_t i2cStatus[32]; /* debug only */ +uint8_t i2cStatus[32]; /* debug only */ uint8_t i2cStatusIdx = 0; -extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ +extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ extern uint8_t i2cStatusIdx; #endif #if (__i2c_signals__) @@ -57,11 +57,13 @@ /* I2C status and address variables */ uint8_t i2cDeviceAddrRW; -volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ +volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ + /* send/transmit buffer (outgoing data) */ uint8_t i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; uint8_t i2cSendDataIndex; uint8_t i2cSendDataLength; + /* receive buffer (incoming data) */ uint8_t i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; uint8_t i2cReceiveDataIndex; @@ -69,10 +71,12 @@ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for * writing */ -static void (*i2cSlaveReceive)(uint8_t receiveDataLength, uint8_t* recieveData); +static void (*i2cSlaveReceive) (uint8_t receiveDataLength, + uint8_t * recieveData); /* I2cSlaveTransmit is called when this processor is addressed as a slave for * reading */ -static uint8_t (*i2cSlaveTransmit)(uint8_t transmitDataLengthMax, uint8_t* transmitData); +static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, + uint8_t * transmitData); /* functions */ @@ -89,7 +93,7 @@ /* Setting TWBR. There's a note in the datasheet that TWBR can't be lower * than 10 if the TWI is operated in Master mode */ #if ((F_CPU/1000UL)/I2C_SCL_FREQ_KHZ) < 36 - TWBR = 10; /* smallest TWBR value */ + TWBR = 10; /* smallest TWBR value */ #else TWBR = I2C_TWBR; #endif @@ -109,29 +113,34 @@ /* Set pull-up resistors on I2C bus pins */ #ifdef I2C_PULLUP - PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ - PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ + PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ + PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ #endif -#ifdef TWI_SLA_ENABLED /* If Slave mode: */ +#ifdef TWI_SLA_ENABLED /* If Slave mode: */ /* Set local device address (used in slave mode only) */ TWAR = I2C_TWAR; - TWCR = I2C_MODE; /* enable TWI */ -#else + TWCR = I2C_MODE; /* enable TWI */ +#else #ifdef TWI_M_ENABLED - TWCR = I2C_MODE; /* enable TWI */ + TWCR = I2C_MODE; /* enable TWI */ #endif #endif } /* Set the user function which handles receiving (incoming) data as a slave */ -void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +void +i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func) + (uint8_t receiveDataLength, uint8_t * recieveData)) { i2cSlaveReceive = i2cSlaveRx_func; } /* Set the user function which handles transmitting (outgoing) data as a slave */ -void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)) +void +i2cSetSlaveTransmitHandler(uint8_t(*i2cSlaveTx_func) + (uint8_t transmitDataLengthMax, + uint8_t * transmitData)) { i2cSlaveTransmit = i2cSlaveTx_func; } @@ -145,7 +154,7 @@ { volatile uint8_t wait; - for (wait=0; wait<40; wait++); /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ + for (wait = 0; wait < 40; wait++) ; /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ /* note: when a stop is immediately followed by a start, the slave detects * the stop, need to process the received data and exit the ISR. If it * doesn't have enough time to do this before a new start is set, it will @@ -157,8 +166,8 @@ if (i2cFlags.i2c_busy == 0) // if a start is sent when the TWI is receiving, one of the data will be received as 0x78 instead of 0x80 so we get a corruption there i2cSendStart(); #if (__i2c_signals__) - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ - START_PT |= START_MK; /* 'START' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + START_PT |= START_MK; /* 'START' debug signal */ #endif } @@ -168,9 +177,9 @@ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x02; #endif - i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ + i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif // TWCR = I2C_MODE; TWCR |= I2C_MODE; @@ -179,7 +188,7 @@ static inline void i2cSendStart(void) { #if (__i2c_debug__) - cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ + cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x03; sei(); @@ -197,7 +206,7 @@ TWCR = _BV(TWSTO) | I2C_MODE; i2cFlags.i2c_busy = 0; #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif } @@ -235,7 +244,7 @@ #ifdef TWI_INT_ENABLED ISR(SIG_TWI) { - const static void *twiLookupTable[]={ + const static void *twiLookupTable[] = { &&case_TW_BUS_ERROR, &&case_TW_START, &&case_TW_REP_START, @@ -270,168 +279,164 @@ &&case_TW_NO_INFO, }; - i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ + i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ #if (__i2c_debug__) i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = TW_STATUS; #endif #if (__i2c_signals__) - ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ #endif - goto *twiLookupTable[TWSR>>3]; /* switch(TW_STATUS) */ + goto *twiLookupTable[TWSR >> 3]; /* switch(TW_STATUS) */ { - /* * * Master General * * */ -case_TW_START: /* 0x08: start condition sent */ -case_TW_REP_START: /* 0x10: repeated start condition sent */ + /* * * Master General * * */ + case_TW_START: /* 0x08: start condition sent */ + case_TW_REP_START: /* 0x10: repeated start condition sent */ #if (__i2c_debug__) #endif #if (__i2c_signals__) - START_PT &= ~START_MK; /* 'START' debug signal */ + START_PT &= ~START_MK; /* 'START' debug signal */ #endif - i2cSendDataIndex = 0; /* reset the data index */ - i2cSendByte(i2cDeviceAddrRW); /* send device address */ + i2cSendDataIndex = 0; /* reset the data index */ + i2cSendByte(i2cDeviceAddrRW); /* send device address */ goto END_TABLE; + /* * * Master Transmitter & Receiver status codes * * */ - /* * * Master Transmitter & Receiver status codes * * */ - -case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ -case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ - #if (__i2c_debug__) - #endif - if(i2cSendDataIndex < i2cSendDataLength) + case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ + case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ +#if (__i2c_debug__) +#endif + if (i2cSendDataIndex < i2cSendDataLength) { - i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ + i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ } else { // XXX disabled for the I2C tester for now on // if (fetchCommands()) [> if other commands are ready, fetch them <] - // i2cSendStart(); [> send a repeated start and continue <] + // i2cSendStart(); [> send a repeated start and continue <] // else { - i2cSendStop(); /* no more commands */ - i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ + i2cSendStop(); /* no more commands */ + i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ } } goto END_TABLE; -case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ -case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ -case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ -case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ + case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ + case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ + case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ +#if (__i2c_debug__) +#endif i2cFlags.mt_nack = 1; i2cSendStop(); goto END_TABLE; -case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ + case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ //case_TW_MR_ARB_LOST: /* 0x38: bus arbitration lost */ /* same code as above */ - #if (__i2c_debug__) - #endif +#if (__i2c_debug__) +#endif i2cReset(); goto END_TABLE; -case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ +#if (__i2c_debug__) +#endif // store received data byte // i2cReceiveData[i2cReceiveDataIndex++] = TWDR; // fall-through to see if more bytes will be received -case_TW_MR_SLA_ACK: /* 0x40: slave address acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_SLA_ACK: /* 0x40: slave address acknowledged */ +#if (__i2c_debug__) +#endif // if(i2cReceiveDataIndex < (i2cReceiveDataLength-1)) - // i2cAckReceiveByte(); [> receive more bytes <] + // i2cAckReceiveByte(); [> receive more bytes <] // else - // i2cNackReceiveByte(); [> receive the last byte <] + // i2cNackReceiveByte(); [> receive the last byte <] goto END_TABLE; + /* * * Slave Receiver status codes * * */ - /* * * Slave Receiver status codes * * */ - -case_TW_SR_SLA_ACK: /* 0x60: own SLA+W has been received, ACK has been returned */ -case_TW_SR_ARB_LOST_SLA_ACK: /* 0x68: own SLA+W has been received, ACK has been returned */ -case_TW_SR_GCALL_ACK: /* 0x70: GCA+W has been received, ACK has been returned */ -case_TW_SR_ARB_LOST_GCALL_ACK: /* 0x78: GCA+W has been received, ACK has been returned */ - #if (__i2c_debug__) - #endif + case_TW_SR_SLA_ACK: /* 0x60: own SLA+W has been received, ACK has been returned */ + case_TW_SR_ARB_LOST_SLA_ACK: /* 0x68: own SLA+W has been received, ACK has been returned */ + case_TW_SR_GCALL_ACK: /* 0x70: GCA+W has been received, ACK has been returned */ + case_TW_SR_ARB_LOST_GCALL_ACK: /* 0x78: GCA+W has been received, ACK has been returned */ +#if (__i2c_debug__) +#endif /* we are being addressed as slave for writing (data will be received from master) */ i2cReceiveDataIndex = 0; - i2cFlags.s_nack = 0; /* reset nack flag here, not in user app */ + i2cFlags.s_nack = 0; /* reset nack flag here, not in user app */ if (commandBufIdx <= (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) { - i2cAckReceiveByte(); /* accept data */ + i2cAckReceiveByte(); /* accept data */ } else { - i2cNackReceiveByte(); /* refuse data */ + i2cNackReceiveByte(); /* refuse data */ } goto END_TABLE; -case_TW_SR_DATA_ACK: /* 0x80: data byte has been received, ACK has been returned */ -case_TW_SR_GCALL_DATA_ACK: /* 0x90: data byte has been received, ACK has been returned */ - #if (__i2c_debug__) - #endif - i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* get received data byte */ + case_TW_SR_DATA_ACK: /* 0x80: data byte has been received, ACK has been returned */ + case_TW_SR_GCALL_DATA_ACK: /* 0x90: data byte has been received, ACK has been returned */ +#if (__i2c_debug__) +#endif + i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* get received data byte */ /* check receive buffer status */ - if(i2cReceiveDataIndex < I2C_RECEIVE_DATA_BUFFER_SIZE) + if (i2cReceiveDataIndex < I2C_RECEIVE_DATA_BUFFER_SIZE) { - i2cAckReceiveByte(); /* accept more data */ + i2cAckReceiveByte(); /* accept more data */ } else { - i2cNackReceiveByte(); /* refuse more data */ + i2cNackReceiveByte(); /* refuse more data */ } goto END_TABLE; -case_TW_SR_DATA_NACK: /* 0x88: data byte has been received, NACK has been returned */ -case_TW_SR_GCALL_DATA_NACK: /* 0x98: data byte has been received, NACK has been returned */ - #if (__i2c_debug__) - #endif + case_TW_SR_DATA_NACK: /* 0x88: data byte has been received, NACK has been returned */ + case_TW_SR_GCALL_DATA_NACK: /* 0x98: data byte has been received, NACK has been returned */ +#if (__i2c_debug__) +#endif //i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* receive last byte XXX check if this is right */ //i2cNackReceiveByte(); //XXX bug here? // receive data byte and return NACK //i2cAckReceiveByte(); [> I should clear the interrupt and enable acknoledge for slave mode (disabled during previous nack) <] - i2cFlags.s_nack = 1; /* XXX check if this flag is reset in all possible conditions */ - i2cReset(); /* reset TWI in slave mode */ + i2cFlags.s_nack = 1; /* XXX check if this flag is reset in all possible conditions */ + i2cReset(); /* reset TWI in slave mode */ goto END_TABLE; /* pass along to restart slave mode */ -case_TW_SR_STOP: /* 0xA0: STOP or REPEATED START has been received while addressed as slave */ - #if (__i2c_debug__) - #endif - if (i2cFlags.s_nack == 0) /* if a nack has been replied, we don't save the received bytes XXX may change this to disable i2c instead of replying a nack so the address will be nacked but this is much more difficult to handle because we need to reenable it and any master mode will reenable it anyway */ - if (i2cReceiveDataIndex == 4) /* add a protection here, in case a start has been sent while receiving or such, the data count may be corrupted */ - i2cSlaveReceive(i2cReceiveDataIndex, i2cReceiveData); /* i2c receive is complete, call i2cSlaveReceive */ - i2cReset(); /* reset TWI in slave mode */ + case_TW_SR_STOP: /* 0xA0: STOP or REPEATED START has been received while addressed as slave */ +#if (__i2c_debug__) +#endif + if (i2cFlags.s_nack == 0) /* if a nack has been replied, we don't save the received bytes XXX may change this to disable i2c instead of replying a nack so the address will be nacked but this is much more difficult to handle because we need to reenable it and any master mode will reenable it anyway */ + if (i2cReceiveDataIndex == 4) /* add a protection here, in case a start has been sent while receiving or such, the data count may be corrupted */ + i2cSlaveReceive(i2cReceiveDataIndex, i2cReceiveData); /* i2c receive is complete, call i2cSlaveReceive */ + i2cReset(); /* reset TWI in slave mode */ goto END_TABLE; + /* * * Slave Transmitter * * */ - /* * * Slave Transmitter * * */ - -case_TW_ST_SLA_ACK: /* 0xA8: own SLA+R has been received, ACK has been returned */ -case_TW_ST_ARB_LOST_SLA_ACK: /* 0xB0: GCA+R has been received, ACK has been returned */ -case_TW_ST_DATA_ACK: /* 0xB8: data byte has been transmitted, ACK has been received */ -case_TW_ST_DATA_NACK: /* 0xC0: data byte has been transmitted, NACK has been received */ -case_TW_ST_LAST_DATA: /* 0xC8: last data byte transmitted, ACK received */ - i2cReset(); /* we don't support slave transmitter, just reset if this happens */ + case_TW_ST_SLA_ACK: /* 0xA8: own SLA+R has been received, ACK has been returned */ + case_TW_ST_ARB_LOST_SLA_ACK: /* 0xB0: GCA+R has been received, ACK has been returned */ + case_TW_ST_DATA_ACK: /* 0xB8: data byte has been transmitted, ACK has been received */ + case_TW_ST_DATA_NACK: /* 0xC0: data byte has been transmitted, NACK has been received */ + case_TW_ST_LAST_DATA: /* 0xC8: last data byte transmitted, ACK received */ + i2cReset(); /* we don't support slave transmitter, just reset if this happens */ goto END_TABLE; + /* * * Misc * * */ - /* * * Misc * * */ - -case_TW_NO_INFO: /* 0xF8: no relevant state information */ + case_TW_NO_INFO: /* 0xF8: no relevant state information */ /* do nothing here */ goto END_TABLE; -case_: -case_TW_BUS_ERROR: /* 0x00: bus error due to illegal start or stop condition */ - #if (__i2c_debug__) - #endif - i2cSendStop(); /* reset internal hardware and release bus */ /* XXX need to test if this works or not */ + case_: + case_TW_BUS_ERROR: /* 0x00: bus error due to illegal start or stop condition */ +#if (__i2c_debug__) +#endif + i2cSendStop(); /* reset internal hardware and release bus *//* XXX need to test if this works or not */ goto END_TABLE; } -END_TABLE: + END_TABLE: #if (__i2c_signals__) - ISR_PT &= ~ISR_MK; /* 'I2C ISR' debug signal */ + ISR_PT &= ~ISR_MK; /* 'I2C ISR' debug signal */ #endif return; } Modified: firmware/tuxcore/trunk/i2c.h =========================... [truncated message content] |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-22 18:12:33
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 286 Modified: firmware/tuxup/trunk/bootloader.c firmware/tuxup/trunk/bootloader.h firmware/tuxup/trunk/main.c firmware/tuxup/trunk/tux-api.h firmware/tuxup/trunk/usb-connection.c firmware/tuxup/trunk/usb-connection.h Log: doegox 2007-04-22 20:12:01 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/bootloader.c 2007-04-22 18:12:01 UTC (rev 286) @@ -58,53 +58,53 @@ const char *hexFile = NULL; -typedef uint32_t FILE_Addr_t; -typedef uint32_t FILE_SegmentLen_t; -typedef unsigned FILE_LineNum_t; -typedef uint8_t FILE_ParsedLen_t; +typedef uint32_t FILE_Addr_t; +typedef uint32_t FILE_SegmentLen_t; +typedef unsigned FILE_LineNum_t; +typedef uint8_t FILE_ParsedLen_t; enum mem_type_t mem_type; typedef struct { - FILE_LineNum_t lineNum; /* Line number of data record in ASCII file.*/ - FILE_Addr_t addr; /* Address that was parsed */ - FILE_ParsedLen_t dataLen; /* Number of bytes of data */ - FILE_ParsedLen_t dataAlloc; /* Number of bytes allocated */ - uint8_t *data; /* Data that was parsed */ + FILE_LineNum_t lineNum; /* Line number of data record in ASCII file. */ + FILE_Addr_t addr; /* Address that was parsed */ + FILE_ParsedLen_t dataLen; /* Number of bytes of data */ + FILE_ParsedLen_t dataAlloc; /* Number of bytes allocated */ + uint8_t *data; /* Data that was parsed */ } FILE_ParsedData_t; typedef struct { - FILE_LineNum_t lineNum; /* Tracks line number we're working on */ - FILE_ParsedData_t parsedData; /* Last hunk of data parsed */ - FILE_Addr_t segAddr; /* Address of the segment in memory */ - FILE_SegmentLen_t segLen; /* Length of the segment in memory */ - int inSeg; /* We've started a segment which hasn't been finished yet */ - FILE_Addr_t currAddr; /* The current address in memory being processed */ - uint8_t *segmentData; /* Complete segment data */ - int segmentDataIdx; /* index used for filling in the segment data */ - usb_dev_handle *dev_handle; /* usb device handle for sending parsed data */ + FILE_LineNum_t lineNum; /* Tracks line number we're working on */ + FILE_ParsedData_t parsedData; /* Last hunk of data parsed */ + FILE_Addr_t segAddr; /* Address of the segment in memory */ + FILE_SegmentLen_t segLen; /* Length of the segment in memory */ + int inSeg; /* We've started a segment which hasn't been finished yet */ + FILE_Addr_t currAddr; /* The current address in memory being processed */ + uint8_t *segmentData; /* Complete segment data */ + int segmentDataIdx; /* index used for filling in the segment data */ + usb_dev_handle *dev_handle; /* usb device handle for sending parsed data */ } Parser_t; /** * Clears any data stored in the parsed data */ -void ClearData(FILE_ParsedData_t *parsedData) +void ClearData(FILE_ParsedData_t * parsedData) { if (parsedData->dataAlloc > 0) { memset(parsedData->data, 0, parsedData->dataAlloc); } -} // ClearData +} // ClearData /** * Releases any allocated data in the parsed data buffer. */ -void FreeData(FILE_ParsedData_t *parsedData) +void FreeData(FILE_ParsedData_t * parsedData) { if (parsedData->dataAlloc > 0) { @@ -113,14 +113,13 @@ parsedData->dataAlloc = 0; } -} // FreeData +} // FreeData - /** * Allocates (or reallocates) the data buffer */ -uint8_t *AllocData(FILE_ParsedData_t *parsedData, FILE_ParsedLen_t reqLen) +uint8_t *AllocData(FILE_ParsedData_t * parsedData, FILE_ParsedLen_t reqLen) { if (reqLen <= parsedData->dataAlloc) { @@ -138,23 +137,19 @@ return parsedData->data; -} // AllocData +} // AllocData - - /** * Parses a single nibble from a string containing ASCII Hex characters. * * @return TRUE, if a nibble was parsed successfully, FALSE otherwise. */ -int GetNibble -( - Parser_t *parser, ///< (mod) Parser object that we're reporting about. - const char **s, ///< (mod) Pointer to string. Will be advanced. - unsigned char *b , ///< (out) nibble that was parsed. - const char *label ///< (in) Error string (used for reporting errors). -) +int GetNibble(Parser_t * parser, ///< (mod) Parser object that we're reporting about. + const char **s, ///< (mod) Pointer to string. Will be advanced. + unsigned char *b, ///< (out) nibble that was parsed. + const char *label ///< (in) Error string (used for reporting errors). + ) { char ch = **s; @@ -162,53 +157,50 @@ if ((ch >= '0') && (ch <= '9')) { - *b = ch - '0'; - return TRUE; + *b = ch - '0'; + return TRUE; } if ((ch >= 'A') && (ch <= 'F')) { - *b = ch - 'A' + 10; - return TRUE; + *b = ch - 'A' + 10; + return TRUE; } if ((ch >= 'a') && (ch <= 'f')) { - *b = ch - 'a' + 10; - return TRUE; + *b = ch - 'a' + 10; + return TRUE; } // Error(parser, "parsing %s, expecting hex digit, found '%c'", label, ch); return FALSE; - -} // GetNibble +} // GetNibble + /** * Parses a single byte from a string containing ASCII Hex characters. * * @return TRUE, if a byte was parsed successfully, FALSE otherwise. */ -int GetByte -( - Parser_t *parser, ///< (mod) Parser object that we're reporting about. - const char **s, ///< (mod) Pointer to string. Will be advanced. - unsigned char *b , ///< (out) nibble that was parsed. - const char *label ///< (in) Error string (used for reporting errors). -) +int GetByte(Parser_t * parser, ///< (mod) Parser object that we're reporting about. + const char **s, ///< (mod) Pointer to string. Will be advanced. + unsigned char *b, ///< (out) nibble that was parsed. + const char *label ///< (in) Error string (used for reporting errors). + ) { - unsigned char b1, b2; + unsigned char b1, b2; - if (GetNibble(parser, s, &b1, label) - && GetNibble(parser, s, &b2, label)) + if (GetNibble(parser, s, &b1, label) && GetNibble(parser, s, &b2, label)) { - *b = b1 << 4 | b2; - return TRUE; + *b = b1 << 4 | b2; + return TRUE; } return FALSE; -} // GetByte +} // GetByte /** * Parses two bytes from a string containing ASCII Hex characters. @@ -216,35 +208,33 @@ * @return TRUE, if a byte was parsed successfully, FALSE otherwise. */ -int GetWord -( - Parser_t *parser, ///< (mod) Parser object that we're reporting about. - const char **s, ///< (mod) Pointer to string. Will be advanced. - unsigned short *b , ///< (out) nibble that was parsed. - const char *label ///< (in) Error string (used for reporting errors). -) +int GetWord(Parser_t * parser, ///< (mod) Parser object that we're reporting about. + const char **s, ///< (mod) Pointer to string. Will be advanced. + unsigned short *b, ///< (out) nibble that was parsed. + const char *label ///< (in) Error string (used for reporting errors). + ) { - unsigned char b1, b2; + unsigned char b1, b2; - if (GetByte(parser, s, &b1, label) - && GetByte(parser, s, &b2, label)) + if (GetByte(parser, s, &b1, label) && GetByte(parser, s, &b2, label)) { - *b = (unsigned short)b1 << 8 | b2; - return TRUE; + *b = (unsigned short)b1 << 8 | b2; + return TRUE; } return FALSE; -} // GetWord +} // GetWord -int startSegment(Parser_t *parser) +int startSegment(Parser_t * parser) { parser->segmentDataIdx = 0; - /* set segment address */ - parser->segmentData[parser->segmentDataIdx++] = (uint8_t)(parser->segAddr >> 8); - parser->segmentData[parser->segmentDataIdx++] = (uint8_t)parser->segAddr; + /* set segment address */ + parser->segmentData[parser->segmentDataIdx++] = + (uint8_t) (parser->segAddr >> 8); + parser->segmentData[parser->segmentDataIdx++] = (uint8_t) parser->segAddr; /* fill with '0xFF' if necessary */ - while(parser->currAddr < parser->parsedData.addr) + while (parser->currAddr < parser->parsedData.addr) { parser->segmentData[parser->segmentDataIdx++] = 0xFF; parser->currAddr++; @@ -255,7 +245,7 @@ /** * Put one byte of data in the segmentData */ -int fillSegment(Parser_t *parser, uint8_t data) +int fillSegment(Parser_t * parser, uint8_t data) { parser->segmentData[parser->segmentDataIdx++] = data; parser->currAddr++; @@ -267,54 +257,60 @@ * * \todo remove the USB commands from here and put them in their own function */ -int finishSegment(Parser_t *parser) +int finishSegment(Parser_t * parser) { int i, idx = 0; uint8_t data_buffer[36]; int ret; - parser->inSeg = FALSE; /* inidicates that we completed a segment */ + parser->inSeg = FALSE; /* inidicates that we completed a segment */ #if (PRINT_DATA) printf("segment data: \n"); /* XXX debug */ - for (i=0; i<parser->segLen+2; i++) printf("%02x", parser->segmentData[i]); + for (i = 0; i < parser->segLen + 2; i++) + printf("%02x", parser->segmentData[i]); printf("\n"); #endif data_buffer[0] = LIBUSB_I2C_HEADER; data_buffer[1] = BOOT_FILLPAGE; - for (i=2; i<36; i++) data_buffer[i] = parser->segmentData[idx++]; /* send first packet */ + for (i = 2; i < 36; i++) + data_buffer[i] = parser->segmentData[idx++]; /* send first packet */ /* EEPROM handling */ if (mem_type == EEPROM) { - usleep(200000); /* try to solve the programming problem with some boards */ + usleep(200000); /* try to solve the programming problem with some boards */ data_buffer[2] |= 0x80; /* set the last bit to 1 to indicate eeprom type to the bootloader */ } ret = usb_send_commands(parser->dev_handle, data_buffer, 36); #if (PRINT_DATA) - printf("Status of the first packet sent: %d\n",ret); + printf("Status of the first packet sent: %d\n", ret); #endif - if (ret != 36) return FALSE; - for (i=2; i<34; i++) data_buffer[i] = parser->segmentData[idx++]; /* send second packet */ + if (ret != 36) + return FALSE; + for (i = 2; i < 34; i++) + data_buffer[i] = parser->segmentData[idx++]; /* send second packet */ keybreak(); ret = usb_send_commands(parser->dev_handle, data_buffer, 34); #if (PRINT_DATA) - printf("Status of the second packet sent: %d\n",ret); + printf("Status of the second packet sent: %d\n", ret); #endif - if (ret != 34) return FALSE; + if (ret != 34) + return FALSE; keybreak(); ret = usb_get_commands(parser->dev_handle, data_buffer, 5); #if (PRINT_DATA) - printf("Status of feedback from bootloader: %x\n",ret); + printf("Status of feedback from bootloader: %x\n", ret); #endif - if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) /* Bootlader status command and result */ + if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) /* Bootlader status command and result */ { printf("."); return TRUE; } else { - fprintf(stderr, "Bootloading failed, program aborted at dongle reply.\n"); + fprintf(stderr, + "Bootloading failed, program aborted at dongle reply.\n"); exit(1); } } @@ -327,9 +323,9 @@ * @return TRUE if parsing should continue, FALSE if it should stop. */ -int ParsedData(Parser_t *parser, int lastSeg) +int ParsedData(Parser_t * parser, int lastSeg) { - FILE_ParsedData_t *parsedData = &parser->parsedData; + FILE_ParsedData_t *parsedData = &parser->parsedData; /* Last segment, fill with '0xFF', send and return */ if (lastSeg) @@ -337,7 +333,7 @@ #if (PRINT_DATA) printf("--last segment --\n"); #endif - while (parser->currAddr < (parser->segAddr + parser->segLen)) /* fill with '0' until the end of segment */ + while (parser->currAddr < (parser->segAddr + parser->segLen)) /* fill with '0' until the end of segment */ { fillSegment(parser, 0xFF); } @@ -346,18 +342,18 @@ } /* resynchronise currAddr and addr */ - while(parser->currAddr != parsedData->addr) + while (parser->currAddr != parsedData->addr) { #if (PRINT_DATA) printf("--synchronisation--\n"); #endif if (!parser->inSeg) { - parser->currAddr = parsedData->addr & ~(parser->segLen - 1); /* set current address at the segment start by zeroing lower bits */ + parser->currAddr = parsedData->addr & ~(parser->segLen - 1); /* set current address at the segment start by zeroing lower bits */ break; } fillSegment(parser, 0xFF); - if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ + if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ { finishSegment(parser); } @@ -365,25 +361,26 @@ /* loop until all data has been processed */ int dataIdx = 0; - while(parser->currAddr < (parsedData->addr + parsedData->dataLen)) + + while (parser->currAddr < (parsedData->addr + parsedData->dataLen)) { #if (PRINT_DATA) printf("--loop--"); #endif - if (!parser->inSeg) /* start a new segment if needed */ + if (!parser->inSeg) /* start a new segment if needed */ { #if (PRINT_DATA) - printf("--new segment--\n"); + printf("--new segment--\n"); #endif parser->inSeg = TRUE; - parser->segAddr = parser->currAddr; /* set address of the segment start */ + parser->segAddr = parser->currAddr; /* set address of the segment start */ startSegment(parser); } - /* store data in segmentData */ + /* store data in segmentData */ fillSegment(parser, parsedData->data[dataIdx]); dataIdx++; - if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ + if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ { #if (PRINT_DATA) printf("--end segment--"); @@ -394,7 +391,7 @@ return TRUE; -} // ParsedData +} // ParsedData /** * Parses a single line from an Intel Hex file. @@ -416,11 +413,11 @@ * See: http://www.xess.com/faq/intelhex.pdf for the complete spec */ -int parseIHexLine(Parser_t *parser, const char *line) +int parseIHexLine(Parser_t * parser, const char *line) { - int i; - FILE_ParsedData_t *parsedData = &parser->parsedData; - uint8_t *data; + int i; + FILE_ParsedData_t *parsedData = &parser->parsedData; + uint8_t *data; ClearData(parsedData); @@ -432,8 +429,8 @@ return TRUE; } - const char *s = &line[ 1 ]; - unsigned char dataLen; + const char *s = &line[1]; + unsigned char dataLen; if (!GetByte(parser, &s, &dataLen, "count")) { @@ -442,27 +439,30 @@ data = AllocData(parsedData, dataLen); - unsigned short addr; + unsigned short addr; + if (!GetWord(parser, &s, &addr, "addr")) { return FALSE; } unsigned char recType; + if (!GetByte(parser, &s, &recType, "recType")) { return FALSE; } - unsigned char checksumCalc = dataLen + ((addr & 0xFF00) >> 8) + (addr & 0x00FF) + recType; + unsigned char checksumCalc = + dataLen + ((addr & 0xFF00) >> 8) + (addr & 0x00FF) + recType; - for (i = 0; i < dataLen; i++) + for (i = 0; i < dataLen; i++) { - if (!GetByte(parser, &s, &data[ i ], "data")) + if (!GetByte(parser, &s, &data[i], "data")) { return FALSE; } - checksumCalc += data[ i ]; + checksumCalc += data[i]; } unsigned char checksumFound; @@ -475,29 +475,29 @@ if ((unsigned char)(checksumCalc + checksumFound) != 0) { // Error(parser, "found checksum 0x%02x, expecting 0x%02x", - // checksumFound, 0 - checksumCalc); + // checksumFound, 0 - checksumCalc); return FALSE; } switch (recType) { - case 0: // Data + case 0: // Data { - parsedData->addr = addr; + parsedData->addr = addr; parsedData->dataLen = dataLen; ParsedData(parser, FALSE); break; } - case 1: // EOF + case 1: // EOF { - ParsedData(parser, TRUE); /* fill the last segment and send it */ + ParsedData(parser, TRUE); /* fill the last segment and send it */ // Flush(parser); /* XXX what to do here? */ break; } - default: + default: { // Error(parser, "Unrecognized record type: %d", recType); return FALSE; @@ -506,23 +506,23 @@ return TRUE; -} // parseIHexLine +} // parseIHexLine /** * Parses an intel hex file, calling the appropriate callbacks along the way */ -int FILE_ParseFile(usb_dev_handle *dev_h, const char *fileName) +int FILE_ParseFile(usb_dev_handle * dev_h, const char *fileName) { - FILE *fs = NULL; - Parser_t parser; - char line[ 100 ]; - int rc = FALSE; + FILE *fs = NULL; + Parser_t parser; + char line[100]; + int rc = FALSE; - memset(&parser, 0, sizeof(parser)); /* clear all parser elements */ + memset(&parser, 0, sizeof(parser)); /* clear all parser elements */ - parser.segLen = 0x40; /* TODO get this value from either the file or the main program. What if we get an ATM168? */ - parser.dev_handle = dev_h; /* XXX this is not a good way to pass the handle up to finsihSegment, any better idea? */ + parser.segLen = 0x40; /* TODO get this value from either the file or the main program. What if we get an ATM168? */ + parser.dev_handle = dev_h; /* XXX this is not a good way to pass the handle up to finsihSegment, any better idea? */ if ((parser.segmentData = malloc(parser.segLen + 2)) == NULL) { fprintf(stderr, "Unable to allocate segmentData space"); @@ -547,7 +547,7 @@ /* Everything went successfully */ rc = TRUE; -cleanup: + cleanup: if (fs != NULL) { @@ -557,19 +557,19 @@ return rc; -} // FILE_ParseFile +} // FILE_ParseFile - /** * Bootloads a CPU with the provided hex file */ -int bootload(usb_dev_handle *dev_h, uint8_t cpu_address, uint8_t mem_t, const char *filename) +int bootload(usb_dev_handle * dev_h, uint8_t cpu_address, uint8_t mem_t, + const char *filename) { - int rc = FALSE; + int rc = FALSE; uint8_t data_buffer[5]; - uint8_t page_size = 64; /* XXX should be adapted depending on the CPU type, how to do this? */ - uint8_t packet_total = 2; /* XXX should be adapted depending on the CPU type, how to do this? */ + uint8_t page_size = 64; /* XXX should be adapted depending on the CPU type, how to do this? */ + uint8_t packet_total = 2; /* XXX should be adapted depending on the CPU type, how to do this? */ int ret; /* Set global variable mem_type to the memory type */ @@ -581,15 +581,17 @@ data_buffer[2] = cpu_address; data_buffer[3] = page_size; data_buffer[4] = packet_total; - + ret = usb_send_commands(dev_h, data_buffer, 5); #if (PRINT_DATA) - printf("Boot init status: %x\n",ret); + printf("Boot init status: %x\n", ret); #endif - if (ret != 5) return FALSE; /* initialization failed */ + if (ret != 5) + return FALSE; /* initialization failed */ /* Bootloader: parse hex file and send data */ - if (FILE_ParseFile(dev_h, filename)) rc = TRUE; + if (FILE_ParseFile(dev_h, filename)) + rc = TRUE; /* Bootloader initialization */ data_buffer[0] = LIBUSB_I2C_HEADER; @@ -597,7 +599,7 @@ data_buffer[2] = 0; data_buffer[3] = 0; data_buffer[4] = 0; - + ret = usb_send_commands(dev_h, data_buffer, 5); return rc; } Modified: firmware/tuxup/trunk/bootloader.h =================================================================== --- firmware/tuxup/trunk/bootloader.h 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/bootloader.h 2007-04-22 18:12:01 UTC (rev 286) @@ -22,6 +22,7 @@ #ifndef bootloader_h #define bootloader_h -int bootload(usb_dev_handle *dev_h, uint8_t cpu_address, uint8_t mem_type, const char *filename); +int bootload(usb_dev_handle * dev_h, uint8_t cpu_address, uint8_t mem_type, + const char *filename); #endif Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/main.c 2007-04-22 18:12:01 UTC (rev 286) @@ -32,32 +32,33 @@ #include "common/commands.h" /* Messages. */ -const char * msg_old_firmware = \ -"\nERROR: Your dongle firmware is too old to support switching to bootloader"\ -"\nmode automatically.\n"\ -"\n To enter bootloading mode manually, you need to unplug the dongle, press"\ -"\n with a small pin on the button located inside the hole on the belly and,"\ -"\n while keeping it pressed, plug the dongle."\ -"\n The eyes should not turn blue at this time, otherwise try again."\ -"\n Now, reprogram the dongle alone with the command:"\ -"\n 'tuxup /opt/tuxdroid/hex/fusxusb.hex'"\ -"\n (You may use another path depending on the hex files"\ -" you want to use).\n"\ -"\nCheck http://www.tuxisalive.com/documentation/how-to/updating-the-firmware"\ -"\nfor more details.\n"; +const char *msg_old_firmware = + "\nERROR: Your dongle firmware is too old to support switching to bootloader" + "\nmode automatically.\n" + "\n To enter bootloading mode manually, you need to unplug the dongle, press" + "\n with a small pin on the button located inside the hole on the belly and," + "\n while keeping it pressed, plug the dongle." + "\n The eyes should not turn blue at this time, otherwise try again." + "\n Now, reprogram the dongle alone with the command:" + "\n 'tuxup /opt/tuxdroid/hex/fusxusb.hex'" + "\n (You may use another path depending on the hex files" + " you want to use).\n" + "\nCheck http://www.tuxisalive.com/documentation/how-to/updating-the-firmware" + "\nfor more details.\n"; -const char* msg_dfu_programmer_not_installed = \ -"\nERROR: dfu-programmer is not installed or is not in your path, tuxup uses"\ -"\nit to reprogram the USB cpu so installing dfu-programmer is mandatory.\n"; +const char *msg_dfu_programmer_not_installed = + "\nERROR: dfu-programmer is not installed or is not in your path, tuxup uses" + "\nit to reprogram the USB cpu so installing dfu-programmer is mandatory.\n"; /* Programming modes. */ -enum program_modes_t {NONE, ALL, MAIN, INPUTFILES}; +enum program_modes_t +{ NONE, ALL, MAIN, INPUTFILES }; /* The name of this program. */ -const char* program_name = "tuxup"; +const char *program_name = "tuxup"; /* The version defined in version.h */ -const char * program_version = VERSION; +const char *program_version = VERSION; /* Pointer o the input hex file */ FILE *hex_file; @@ -69,46 +70,44 @@ int pretend = 0; /* USB handle */ -struct usb_device* device; +struct usb_device *device; struct usb_dev_handle *dev_h; -int usb_connected = 0; /* Flag for usb connection status */ +int usb_connected = 0; /* Flag for usb connection status */ /* * Prints usage information for this program to STREAM (typically * stdout or stderr), and exit the program with EXIT_CODE. Does not return. */ -void usage (FILE* stream, int exit_code) +void usage(FILE * stream, int exit_code) { - fprintf(stream, "%s %s\n",program_name, program_version ); + fprintf(stream, "%s %s\n", program_name, program_version); fprintf(stream, "Usage: %s options [path|file ...]\n", program_name); - fprintf (stream, - " -m --main Reprogram tuxcore and tuxaudio (flash and eeprom) with hex files located in path.\n" - " -a --all Reprogram all cpu's with hex files located in path.\n" - " -p --pretend Don't do the programming, just simulates.\n" - " -h --help Display this usage information.\n" - " -v --verbose Print verbose messages.\n" - " -V --version Print the version number.\n" - "\n" - "Connection: connect the dongle alone, then press on tux's head\n" - " button while switching it on, finally connect the white cable\n" - " between tux and the dongle\n" - "\n" - "Notes: '-a' and -'m' options can't be used simultaneously.\n" - " Inputfiles can be specified only if the -a or -m options are\n" - " not selected.\n" - " Any .hex or .eep files compiled for Tux Droid can be used.\n" - " The eeprom file names should contain 'tuxcore' or 'tuxaudio'\n" - " in order to be identified, the usb hex file should contain\n" - " 'fuxusb'.\n" - ); - exit (exit_code); + fprintf(stream, + " -m --main Reprogram tuxcore and tuxaudio (flash and eeprom) with hex files located in path.\n" + " -a --all Reprogram all cpu's with hex files located in path.\n" + " -p --pretend Don't do the programming, just simulates.\n" + " -h --help Display this usage information.\n" + " -v --verbose Print verbose messages.\n" + " -V --version Print the version number.\n" "\n" + "Connection: connect the dongle alone, then press on tux's head\n" + " button while switching it on, finally connect the white cable\n" + " between tux and the dongle\n" "\n" + "Notes: '-a' and -'m' options can't be used simultaneously.\n" + " Inputfiles can be specified only if the -a or -m options are\n" + " not selected.\n" + " Any .hex or .eep files compiled for Tux Droid can be used.\n" + " The eeprom file names should contain 'tuxcore' or 'tuxaudio'\n" + " in order to be identified, the usb hex file should contain\n" + " 'fuxusb'.\n"); + exit(exit_code); } void fux_connect(void) { int wait = 5; - if (usb_connected) return; + if (usb_connected) + return; /* detect Tux on USB */ for (;;) @@ -116,14 +115,16 @@ device = usb_find_tux(); if (device == NULL) { - if (!wait) { + if (!wait) + { fprintf(stderr, "The dongle was not found, now exiting.\n"); exit(1); } } else { - if (verbose) printf("The dongle was found.\n"); + if (verbose) + printf("The dongle was found.\n"); /* Check if we have the old firmware that requires entering * bootloader mode manually, exits with a message that exlains what * to do in such a case. */ @@ -140,28 +141,34 @@ } /* open USB device */ - if ((dev_h = usb_open_tux(device))==NULL) { + if ((dev_h = usb_open_tux(device)) == NULL) + { fprintf(stderr, "USB DEVICE INIT ERROR \n"); exit(1); } - if (verbose) printf("Interface configured \n\n"); + if (verbose) + printf("Interface configured \n\n"); usb_connected = 1; } void fux_disconnect(void) { - if (!usb_connected) return; - if (verbose) printf("Closing interface ...\n"); + if (!usb_connected) + return; + if (verbose) + printf("Closing interface ...\n"); usb_release_interface(dev_h, USB_COMMAND); usb_close(dev_h); - if (verbose) printf(" ... interface closed \n"); + if (verbose) + printf(" ... interface closed \n"); usb_connected = 0; } int hex_to_i(char *hex_nr) { int nr; - sscanf(hex_nr,"%x",&nr); + + sscanf(hex_nr, "%x", &nr); return nr; } @@ -171,32 +178,33 @@ * from the hex file and returns 0 if the hex file has a cpu and version * numbers, 1 otherwise. */ -int check_hex_file(char *filename, version_bf_t* version) +int check_hex_file(char *filename, version_bf_t * version) { FILE *fs = NULL; char word[80]; char hex_nr[3]; - hex_nr[2]=(char)'\0'; + hex_nr[2] = (char)'\0'; if ((fs = fopen(filename, "r")) == NULL) { fprintf(stderr, "Unable to open file '%s' for reading\n", filename); exit(1); } - while( fscanf( fs, " %s", word)!=EOF) + while (fscanf(fs, " %s", word) != EOF) { /* look for the address 0EF0 or 1EF0 and the C8 version command */ - if (!strncmp(word, ":0C0EF000C8", 11) || !strncmp(word, ":0C1DF000C8", 11)) + if (!strncmp(word, ":0C0EF000C8", 11) + || !strncmp(word, ":0C1DF000C8", 11)) { /* get cpu number and version number */ strncpy(hex_nr, &word[11], 2); - version->cpu_nbr = (hex_to_i(hex_nr) & 0x7); /* 3 lower bits */ - version->ver_major = (hex_to_i(hex_nr) >> 3); /* 5 higher bits */ + version->cpu_nbr = (hex_to_i(hex_nr) & 0x7); /* 3 lower bits */ + version->ver_major = (hex_to_i(hex_nr) >> 3); /* 5 higher bits */ strncpy(hex_nr, &word[13], 2); - version->ver_minor = hex_to_i(hex_nr); /* 5 higher bits */ + version->ver_minor = hex_to_i(hex_nr); /* 5 higher bits */ strncpy(hex_nr, &word[15], 2); - version->ver_update = hex_to_i(hex_nr); /* 5 higher bits */ + version->ver_update = hex_to_i(hex_nr); /* 5 higher bits */ return 0; } } @@ -209,11 +217,14 @@ uint8_t cpu_i2c_addr; /* Connect the dongle. */ - if (!pretend) fux_connect(); + if (!pretend) + fux_connect(); if (check_hex_file(filename, &version)) { - printf("[FAIL] Programming of '%s' failed, this file is not a correct hex file for that CPU\n\n", filename); + printf + ("[FAIL] Programming of '%s' failed, this file is not a correct hex file for that CPU\n\n", + filename); return 1; } printf("Programming %s in the ", filename); @@ -239,12 +250,16 @@ } else { - printf("Unrecognized CPU number, %s doesn't appear to be compiled for a CPU of tuxdroid.\n", filename); + printf + ("Unrecognized CPU number, %s doesn't appear to be compiled for a CPU of tuxdroid.\n", + filename); return 1; } - printf ("Version %d.%d.%d\n", version.ver_major, version.ver_minor, version.ver_update); + printf("Version %d.%d.%d\n", version.ver_major, version.ver_minor, + version.ver_update); - if (pretend) return 0; + if (pretend) + return 0; if (bootload(dev_h, cpu_i2c_addr, FLASH, filename)) { @@ -261,7 +276,8 @@ uint8_t cpu_i2c_addr; /* Connect the dongle. */ - if (!pretend) fux_connect(); + if (!pretend) + fux_connect(); printf("Programming %s in ", filename); if (cpu_nbr == TUXCORE_CPU_NUM) @@ -280,7 +296,8 @@ return 0; } - if (pretend) return 0; + if (pretend) + return 0; if (bootload(dev_h, cpu_i2c_addr, EEPROM, filename)) { @@ -294,35 +311,41 @@ int prog_usb(char *filename) { - uint8_t send_data[5] = {0x01, 0x01, 0x00, 0x00, 0xFF}; /* XXX include those as defines in commands.h */ + uint8_t send_data[5] = { 0x01, 0x01, 0x00, 0x00, 0xFF }; /* XXX include those as defines in commands.h */ char tmp_string[90]; int ret; + printf("Programming %s in the USB CPU\n", filename); - if (pretend) return 0; + if (pretend) + return 0; /* Check if the dongle is already in bootloader mode */ if (verbose) { - fprintf(stdout,"Testing if the dongle is already in bootloader mode.\n"\ + fprintf(stdout, + "Testing if the dongle is already in bootloader mode.\n" "If it is not, 'no device present' will be reported.\n"); ret = system("dfu-programmer at89c5130 get bootloader-version"); } else - ret = system("dfu-programmer at89c5130 get bootloader-version 2> /dev/null"); + ret = + system + ("dfu-programmer at89c5130 get bootloader-version 2> /dev/null"); /* If dfu-programmer didn't detect the dongle, we try to set it in bootloader mode with the specific command */ if (ret) { /* Check if dfu-programmer is installed */ - if (ret == 32512) /* XXX a better way to code that error, a define? */ + if (ret == 32512) /* XXX a better way to code that error, a define? */ { fprintf(stdout, msg_dfu_programmer_not_installed); exit(1); } if (verbose) { - fprintf(stdout,"The dongle was not detected in bootloader mode, "\ + fprintf(stdout, + "The dongle was not detected in bootloader mode, " "now \ntrying to set it with a command.\n"); } fux_connect(); @@ -330,17 +353,17 @@ ret = usb_send_commands(dev_h, send_data, 5); if (ret == 5) { - if (verbose) fprintf(stdout, "Switched to bootloader mode.\n"); + if (verbose) + fprintf(stdout, "Switched to bootloader mode.\n"); sleep(2); } else { - fprintf (stderr, "Switching to bootloader mode failed.\n"); + fprintf(stderr, "Switching to bootloader mode failed.\n"); return 1; } } - ret = system("dfu-programmer at89c5130 erase"); if (ret) { @@ -374,53 +397,56 @@ { int ret = -1; size_t len; - char * extension, filenamepath[90]; + char *extension, filenamepath[90]; if (path) { /* Checking path */ len = strlen(path); - if (path[len-1] != '/') - strcat(path, "/"); /* Append '/' at the end if not specified. */ - strcpy (filenamepath, path); + if (path[len - 1] != '/') + strcat(path, "/"); /* Append '/' at the end if not specified. */ + strcpy(filenamepath, path); strcat(filenamepath, filename); filename = filenamepath; } - if (verbose) printf ("Processing: %s\n", filename); + if (verbose) + printf("Processing: %s\n", filename); extension = strrchr(filename, '.'); - if (extension) /* check that an extension has been given */ + if (extension) /* check that an extension has been given */ { /* Check which program function to start. */ if (!strcmp(extension, ".hex")) { int i, usb = 0; + /* Check for 'fuxusb' hex file. */ len = strlen(filename); - for (i=0; i< len-7; i++) + for (i = 0; i < len - 7; i++) { - if (!strncmp(filename+i, "fuxusb", 6)) + if (!strncmp(filename + i, "fuxusb", 6)) { ret = prog_usb(filename); usb = 1; break; } } - if (!usb) /* AVR hex file. */ + if (!usb) /* AVR hex file. */ ret = prog_flash(filename); } else if (!strcmp(extension, ".eep")) { int i; + len = strlen(filename); - for (i=0; i< len-7; i++) + for (i = 0; i < len - 7; i++) { - if (!strncmp(filename+i, "tuxcore", 7)) + if (!strncmp(filename + i, "tuxcore", 7)) { ret = prog_eeprom(TUXCORE_CPU_NUM, filename); break; } - else if (!strncmp(filename+i, "tuxaudio", 7)) + else if (!strncmp(filename + i, "tuxaudio", 7)) { ret = prog_eeprom(TUXAUDIO_CPU_NUM, filename); break; @@ -428,144 +454,157 @@ } } } - if (ret == -1) fprintf(stderr, "%s is not a valid programming file.\n", filename); - fprintf(stdout,"\n"); + if (ret == -1) + fprintf(stderr, "%s is not a valid programming file.\n", filename); + fprintf(stdout, "\n"); return ret; } /* * Main application */ -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { char path[90]; enum program_modes_t program_mode = NONE; time_t start_time, end_time; int next_option; + /* A string listing valid short options letters. */ - const char* const short_options = "maphvV"; + const char *const short_options = "maphvV"; + /* An array describing valid long options. */ const struct option long_options[] = { - { "main", 0, NULL, 'm' }, - { "all", 0, NULL, 'a' }, - { "pretend", 0, NULL, 'p' }, - { "help", 0, NULL, 'h' }, - { "verbose", 0, NULL, 'v' }, - { "version", 0, NULL, 'V' }, - { NULL, 0, NULL, 0 } /* Required at end of array. */ + {"main", 0, NULL, 'm'}, + {"all", 0, NULL, 'a'}, + {"pretend", 0, NULL, 'p'}, + {"help", 0, NULL, 'h'}, + {"verbose", 0, NULL, 'v'}, + {"version", 0, NULL, 'V'}, + {NULL, 0, NULL, 0} /* Required at end of array. */ }; /* Remember the name of the program, to incorporate in messages. - The name is stored in argv[0]. */ - /*program_name = argv[0];*/ + * The name is stored in argv[0]. */ + /*program_name = argv[0]; */ /* Save the start time to measure the programming time */ - start_time = time((time_t *)0); + start_time = time((time_t *) 0); - do { - next_option = getopt_long (argc, argv, short_options, - long_options, NULL); + do + { + next_option = + getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { - case 'h': /* -h or --help */ - /* User has requested usage information. Print it to standard - output, and exit with exit code zero (normal termination). */ - usage(stdout, 0); - case 'm': /* -m or --main */ - if (program_mode == NONE) - program_mode = MAIN; - else - { - fprintf(stderr, "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); - usage (stderr, 1); - } - break; - case 'a': /* -a or --all */ - if (program_mode == NONE) - program_mode = ALL; - else - { - fprintf(stderr, "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); - usage (stderr, 1); - } - break; - case 'p': /* -a or --all */ - pretend = 1; - break; - case 'v': /* -v or --verbose */ - verbose = 1; - break; - case 'V': /* -V or --version */ - fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n",program_name, program_version ); - exit(0); /* version is already printed, so just exit. */ - break; - case '?': /* The user specified an invalid option. */ - /* Print usage information to standard error, and exit with exit - code one (indicating abnormal termination). */ - usage (stderr, 1); - case -1: /* Done with options. */ - break; - default: /* Something else: unexpected. */ - abort (); + case 'h': /* -h or --help */ + /* User has requested usage information. Print it to standard + * output, and exit with exit code zero (normal termination). */ + usage(stdout, 0); + case 'm': /* -m or --main */ + if (program_mode == NONE) + program_mode = MAIN; + else + { + fprintf(stderr, + "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); + usage(stderr, 1); + } + break; + case 'a': /* -a or --all */ + if (program_mode == NONE) + program_mode = ALL; + else + { + fprintf(stderr, + "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); + usage(stderr, 1); + } + break; + case 'p': /* -a or --all */ + pretend = 1; + break; + case 'v': /* -v or --verbose */ + verbose = 1; + break; + case 'V': /* -V or --version */ + fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n", + program_name, program_version); + exit(0); /* version is already printed, so just exit. */ + break; + case '?': /* The user specified an invalid option. */ + /* Print usage information to standard error, and exit with exit + * code one (indicating abnormal termination). */ + usage(stderr, 1); + case -1: /* Done with options. */ + break; + default: /* Something else: unexpected. */ + abort(); } } while (next_option != -1); /* Done with options. OPTIND points to first nonoption argument. */ /* Print program name and version at program launch */ - if (verbose) fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n",program_name, program_version ); + if (verbose) + fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n", + program_name, program_version); /* If no program mode has been selected, choose INPUTFILES. */ if (program_mode == NONE) program_mode = INPUTFILES; /* Check that if we have inputfiles, the correct program mode is selected */ - if (optind < argc) /* Input files have been given. */ + if (optind < argc) /* Input files have been given. */ { if (program_mode != INPUTFILES) { if (argc == optind + 1) strcpy(path, argv[optind]); else - usage (stderr, 1); + usage(stderr, 1); } } - else /* No arguments given. */ - usage (stderr, 1); + else /* No arguments given. */ + usage(stderr, 1); /* Select which files to program */ switch (program_mode) { int i; - case INPUTFILES: - for (i = optind; i < argc; ++i) - { - program(argv[i], NULL); /* XXX returned values are not used yet */ - } - break; - case MAIN: - program("tuxcore.hex", path); - program("tuxcore.eep", path); - program("tuxaudio.hex", path); - program("tuxaudio.eep", path); - break; - case ALL: - program("fuxusb.hex", path); - program("tuxcore.hex", path); - program("tuxcore.eep", path); - program("tuxaudio.hex", path); - program("tuxaudio.eep", path); - program("tuxrf.hex", path); - program("fuxrf.hex", path); - break; - default: - abort(); + + case INPUTFILES: + for (i = optind; i < argc; ++i) + { + program(argv[i], NULL); /* XXX returned values are not used yet */ + } + break; + case MAIN: + program("tuxcore.hex", path); + program("tuxcore.eep", path); + program("tuxaudio.hex", path); + program("tuxaudio.eep", path); + break; + case ALL: + program("fuxusb.hex", path); + program("tuxcore.hex", path); + program("tuxcore.eep", path); + program("tuxaudio.hex", path); + program("tuxaudio.eep", path); + program("tuxrf.hex", path); + program("fuxrf.hex", path); + break; + default: + abort(); } - if (!pretend) fux_disconnect(); + if (!pretend) + fux_disconnect(); /* Print time elapsed for programming. */ - end_time = time((time_t *)0); - if (!pretend) printf ("Time elapsed: %2.0f seconds.\n",difftime(end_time, start_time)); + end_time = time((time_t *) 0); + if (!pretend) + printf("Time elapsed: %2.0f seconds.\n", + difftime(end_time, start_time)); return 0; } Modified: firmware/tuxup/trunk/tux-api.h =================================================================== --- firmware/tuxup/trunk/tux-api.h 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/tux-api.h 2007-04-22 18:12:01 UTC (rev 286) @@ -20,7 +20,7 @@ /* $Id$ */ #ifndef TUX_API_H -#define TUX_API_H +#define TUX_API_H /** * USB command types @@ -29,6 +29,7 @@ #define LIBUSB_RF_HEADER 0 #define LIBUSB_I2C_HEADER 2 -enum mem_type_t {FLASH, EEPROM, EXTERNAL_FlasH}; +enum mem_type_t +{ FLASH, EEPROM, EXTERNAL_FlasH }; #endif /* TUX_API_H */ Modified: firmware/tuxup/trunk/usb-connection.c =================================================================== --- firmware/tuxup/trunk/usb-connection.c 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/usb-connection.c 2007-04-22 18:12:01 UTC (rev 286) @@ -21,7 +21,7 @@ #include <stdint.h> #include <stdio.h> -#include <usb.h> /* libusb header */ +#include <usb.h> /* libusb header */ #include <syslog.h> #include "usb-connection.h" @@ -43,25 +43,26 @@ * \brief Scan all USB busses to find Tux device * \return USB device of Tux */ -struct usb_device* usb_find_tux() +struct usb_device *usb_find_tux() { struct usb_bus *bus; struct usb_device *device; + usb_init(); usb_find_busses(); usb_find_devices(); - for(bus=usb_busses;bus;bus=bus->next) + for (bus = usb_busses; bus; bus = bus->next) { - for (device = bus->devices;device;device=device->next) + for (device = bus->devices; device; device = device->next) { - if ((device->descriptor.idVendor == TUX_VENDOR_ID) && - (device->descriptor.idProduct ==TUX_PRODUCT_ID)) + if ((device->descriptor.idVendor == TUX_VENDOR_ID) + && (device->descriptor.idProduct == TUX_PRODUCT_ID)) { return device; } } - } + } return NULL; } @@ -70,31 +71,32 @@ * \param dev USB device * \return dev_h USB device handle */ -usb_dev_handle * usb_open_tux(struct usb_device* dev) +usb_dev_handle *usb_open_tux(struct usb_device * dev) { int err; usb_dev_handle *dev_h; - if (!(dev_h=usb_open(dev))) + if (!(dev_h = usb_open(dev))) { - return NULL; + return NULL; } - else - if (verbose) printf("Device opened\n"); + else if (verbose) + printf("Device opened\n"); err = usb_claim_interface(dev_h, USB_COMMAND); if (err != 0) { usb_detach_kernel_driver_np(dev_h, USB_COMMAND); err = usb_claim_interface(dev_h, USB_COMMAND); - if (err !=0) + if (err != 0) { fprintf(stderr, "Claim interface failed: %s\n", usb_strerror()); usb_close(dev_h); return NULL; } } - if (verbose) printf("USB interface claimed successfully \n"); + if (verbose) + printf("USB interface claimed successfully \n"); return dev_h; } @@ -104,10 +106,10 @@ * * Releases and close the interface */ -void usb_close_tux(usb_dev_handle *dev_h) +void usb_close_tux(usb_dev_handle * dev_h) { usb_release_interface(dev_h, USB_COMMAND); - usb_close(dev_h); + usb_close(dev_h); } /** @@ -118,18 +120,25 @@ * \todo Need to define the format of the data array to send and pass it as parameter * \todo Need to add some doc or links about what this status is really */ -int usb_send_commands(usb_dev_handle *dev_h, uint8_t *send_data, int size) +int usb_send_commands(usb_dev_handle * dev_h, uint8_t * send_data, int size) { int status; - if((status = usb_interrupt_write(dev_h, USB_W_ENDPOINT, (char*)send_data, size, USB_W_TIMEOUT)) < 0) + + if ((status = + usb_interrupt_write(dev_h, USB_W_ENDPOINT, (char *)send_data, size, + USB_W_TIMEOUT)) < 0) /* error on usb_interrupt_write() */ - { - fprintf(stderr, "usb_interrupt_write error: status = %d :: %s \n", status, usb_strerror()); + { + fprintf(stderr, "usb_interrupt_write error: status = %d :: %s \n", + status, usb_strerror()); } - else /* success */ + else /* success */ { #if (PRINT_DATA) - printf("usb_interrupt_write: status =%d -> TX Buffer[%d]={%2X, %2X, %2X, %2X, %2X}\n", status, status, send_data[0], send_data[1], send_data[2], send_data[3], send_data[4]); + printf + ("usb_interrupt_write: status =%d -> TX Buffer[%d]={%2X, %2X, %2X, %2X, %2X}\n", + status, status, send_data[0], send_data[1], send_data[2], + send_data[3], send_data[4]); #endif } return status; @@ -143,22 +152,28 @@ * \todo Need to define the format of the data array to send and pass it as parameter * \todo Need to add some doc or links about what this status is really */ -int usb_get_commands(usb_dev_handle *dev_h, uint8_t *receive_data, int size) +int usb_get_commands(usb_dev_handle * dev_h, uint8_t * receive_data, int size) { int status; - if((status = usb_interrupt_read(dev_h, USB_R_ENDPOINT, (char*)receive_data, size, USB_R_TIMEOUT)) < 0) + if ((status = + usb_interrupt_read(dev_h, USB_R_ENDPOINT, (char *)receive_data, size, + USB_R_TIMEOUT)) < 0) { - fprintf(stderr, "usb_interrupt_read error: status = %d :: %s \n", status, usb_strerror()); + fprintf(stderr, "usb_interrupt_read error: status = %d :: %s \n", + status, usb_strerror()); } else { /* XXX this is only to test and display what has been received */ #if (PRINT_DATA) - printf("usb_interrupt_read: status = %d -> TX Buffer[%d]={%hX, %hX, %hX, %hX, %hX}\n", status, status, receive_data[0], receive_data[1], receive_data[2], receive_data[3], receive_data[4]); + printf + ("usb_interrupt_read: status = %d -> TX Buffer[%d]={%hX, %hX, %hX, %hX, %hX}\n", + status, status, receive_data[0], receive_data[1], receive_data[2], + receive_data[3], receive_data[4]); #endif } return status; } -/** @} */ /* end of USB group */ + /** @} *//* end of USB group */ Modified: firmware/tuxup/trunk/usb-connection.h =================================================================== --- firmware/tuxup/trunk/usb-connection.h 2007-04-22 18:09:42 UTC (rev 285) +++ firmware/tuxup/trunk/usb-connection.h 2007-04-22 18:12:01 UTC (rev 286) @@ -62,10 +62,10 @@ // }; /* Prototypes */ -usb_dev_handle * usb_open_tux(struct usb_device* dev); -struct usb_device* usb_find_tux(); -int usb_check_tux_status(usb_dev_handle *dev_h); -int usb_send_commands(usb_dev_handle *dev_h, uint8_t *send_data, int size); -int usb_get_commands(usb_dev_handle *dev_h, uint8_t *receive_data, int size); +usb_dev_handle *usb_open_tux(struct usb_device *dev); +struct usb_device *usb_find_tux(); +int usb_check_tux_status(usb_dev_handle * dev_h); +int usb_send_commands(usb_dev_handle * dev_h, uint8_t * send_data, int size); +int usb_get_commands(usb_dev_handle * dev_h, uint8_t * receive_data, int size); #endif /* USB_CONNECTION_H */ |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-22 18:10:00
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 285 Modified: firmware/tuxaudio/trunk/bootloader.c firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/config.c firmware/tuxaudio/trunk/config.h firmware/tuxaudio/trunk/fifo.c firmware/tuxaudio/trunk/fifo.h firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/flash.h firmware/tuxaudio/trunk/i2c.c firmware/tuxaudio/trunk/i2c.h firmware/tuxaudio/trunk/init.c firmware/tuxaudio/trunk/init.h firmware/tuxaudio/trunk/interrupt.c firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/spi.c firmware/tuxaudio/trunk/spi.h firmware/tuxaudio/trunk/test.c firmware/tuxaudio/trunk/test.h firmware/tuxaudio/trunk/varis.c firmware/tuxaudio/trunk/varis.h firmware/tuxaudio/trunk/version.h Log: doegox 2007-04-22 20:09:42 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxaudio/trunk/bootloader.c =================================================================== --- firmware/tuxaudio/trunk/bootloader.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/bootloader.c 2007-04-22 18:09:42 UTC (rev 285) @@ -32,7 +32,7 @@ uint8_t b[2]; } union16_t; -void (*jump_to_application)(void) = (void *)0x0000; +void (*jump_to_application) (void) = (void *)0x0000; void i2cWaitForComplete(void); /** \ingroup minimal_bootloader @@ -44,13 +44,13 @@ union16_t pageAddress, data; uint16_t address; uint8_t i, twStatus, eeprom_flg = 0; - volatile uint8_t _count=0; + volatile uint8_t _count = 0; - PORTC = 0x08; /* head button on PC3 */ - DDRC=0x08; /* force the head button up for a short period to quickly charge the capacitance */ - for (_count = 0;_count<50; _count++); - DDRC=0x00; /* then set as pull-up */ - if ((PINC & 0x08)) /* and check it */ + PORTC = 0x08; /* head button on PC3 */ + DDRC = 0x08; /* force the head button up for a short period to quickly charge the capacitance */ + for (_count = 0; _count < 50; _count++) ; + DDRC = 0x00; /* then set as pull-up */ + if ((PINC & 0x08)) /* and check it */ jump_to_application(); TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ @@ -59,29 +59,35 @@ TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) { - i2cWaitForComplete(); /* wait the I2C address */ - if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) while(1); + i2cWaitForComplete(); /* wait the I2C address */ + if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) + while (1) ; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the high byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the high byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[1] = TWDR; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the low byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the low byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[0] = TWDR; - if (pageAddress.w & 0x003F) while(1); /* incorrect page address */ - if (pageAddress.w >= 0x8000) /* eeprom programming */ + if (pageAddress.w & 0x003F) + while (1) ; /* incorrect page address */ + if (pageAddress.w >= 0x8000) /* eeprom programming */ { - eeprom_flg = 1; /* don't overwrite the bootloader */ - pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ + eeprom_flg = 1; /* don't overwrite the bootloader */ + pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ } - else if (pageAddress.w >= 0x1E00) while(1); /* don't overwrite the bootloader */ - else eeprom_flg = 0; /* flash programming */ + else if (pageAddress.w >= 0x1E00) + while (1) ; /* don't overwrite the bootloader */ + else + eeprom_flg = 0; /* flash programming */ address = pageAddress.w; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - for (i=0; i<SPM_PAGESIZE; i++) /* fill the complete page with the next data */ + for (i = 0; i < SPM_PAGESIZE; i++) /* fill the complete page with the next data */ { - i2cWaitForComplete(); /* wait data */ + i2cWaitForComplete(); /* wait data */ if ((twStatus = TW_STATUS) == TW_SR_DATA_ACK) { if ((i & 0x01) == 0) @@ -93,31 +99,33 @@ data.b[1] = TWDR; if (eeprom_flg) { - eeprom_write_word ((uint16_t *)address, data.w); + eeprom_write_word((uint16_t *) address, data.w); eeprom_busy_wait(); } else - boot_page_fill (address, data.w); + boot_page_fill(address, data.w); address += 2; } TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); } - else while(1); /* error in communication */ + else + while (1) ; /* error in communication */ } i2cWaitForComplete(); - if ((twStatus = TW_STATUS) != TW_SR_STOP) while(1); /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ - TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ + if ((twStatus = TW_STATUS) != TW_SR_STOP) + while (1) ; /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ + TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ if (!eeprom_flg) { - boot_page_erase (pageAddress.w); - boot_spm_busy_wait (); - boot_page_write (pageAddress.w); /* Store buffer in flash page */ - boot_spm_busy_wait (); + boot_page_erase(pageAddress.w); + boot_spm_busy_wait(); + boot_page_write(pageAddress.w); /* Store buffer in flash page */ + boot_spm_busy_wait(); } } } -void i2cWaitForComplete (void) +void i2cWaitForComplete(void) { - while( !(TWCR & _BV(TWINT)) ); /* wait for i2c interface to complete operation */ + while (!(TWCR & _BV(TWINT))) ; /* wait for i2c interface to complete operation */ } Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/communication.c 2007-04-22 18:09:42 UTC (rev 285) @@ -33,7 +33,7 @@ uint8_t i2c_idle_time = I2C_IDLE_RESET; #ifdef __com_debug__ -uint8_t errorNbr=0; +uint8_t errorNbr = 0; void comError(void) { errorNbr = 1; @@ -53,8 +53,10 @@ * order they were issued when the stack holds multiple commands. */ uint8_t commandBuf[COMMAND_BUF_SIZE]; -fifo_t _commandFifo = {(uint8_t *)commandBuf, sizeof commandBuf-1, 0, 0}, *commandFifo = &_commandFifo; +fifo_t _commandFifo = { (uint8_t *) commandBuf, sizeof commandBuf - 1, 0, 0 } +, *commandFifo = &_commandFifo; + /* * audioBuf is a single buffer for commands received over i2c to control the * audio interface @@ -64,17 +66,19 @@ * cleared when the command is processed so it can be used to check whether the * buffer has been processed or not. */ -uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -uint8_t audioBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ +uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +uint8_t audioBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ /* * statusFifo is a fifo buffer for commands received from the i2c and that * should be sent over the RF link * */ -uint8_t statusBuf[INCOMING_BUF_SIZE]; /* statusBuf is used for commands received from the i2c and should be sent over the RF link */ -fifo_t _statusBuf = {(uint8_t *)statusBuf, sizeof statusBuf-1, 0, 0}, *statusFifo = &_statusBuf; +uint8_t statusBuf[INCOMING_BUF_SIZE]; /* statusBuf is used for commands received from the i2c and should be sent over the RF link */ +fifo_t _statusBuf = { (uint8_t *) statusBuf, sizeof statusBuf - 1, 0, 0 } +, *statusFifo = &_statusBuf; + /* * I2C communication initalisation * @@ -83,10 +87,10 @@ */ void i2cCommunicationInit(void) { - i2cInit(); /* start twi interface */ - i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ - i2cDeviceAddrRW = 0x54; /* set behaviour CPU device address */ - i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission*/ + i2cInit(); /* start twi interface */ + i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ + i2cDeviceAddrRW = 0x54; /* set behaviour CPU device address */ + i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission */ } /* @@ -103,10 +107,10 @@ { uint8_t i; - if (!(i2cFlags.i2c_busy)) /* i2c hardware not busy */ + if (!(i2cFlags.i2c_busy)) /* i2c hardware not busy */ { i2c_idle_time = I2C_IDLE_RESET; - if (i2cFlags.mt_nack) /* if nack error, resend previous command */ + if (i2cFlags.mt_nack) /* if nack error, resend previous command */ { i2cMasterStart(); cli(); @@ -114,28 +118,28 @@ i2cFlags.i2c_busy = 1; sei(); } - else if (i2cFlags.m_end == 0) /* previous transmission was cancelled by arbitration lost or any problem so restart */ + else if (i2cFlags.m_end == 0) /* previous transmission was cancelled by arbitration lost or any problem so restart */ { i2cMasterStart(); cli(); i2cFlags.i2c_busy = 1; sei(); } - else if (!isFifoEmpty(commandFifo)) /* elsif no error and previous transmission is finished and if there's something to send, get the next value */ + else if (!isFifoEmpty(commandFifo)) /* elsif no error and previous transmission is finished and if there's something to send, get the next value */ { cli(); - i2cFlags.i2c_idx = 1; /* protect commandFifo from external changes */ + i2cFlags.i2c_idx = 1; /* protect commandFifo from external changes */ i2cFlags.m_end = 0; /* reset master transmission end flag */ sei(); i2cSendDataLength = MAX_COMMAND_SIZE; - for (i=0; i<=MAX_COMMAND_SIZE; i++) + for (i = 0; i <= MAX_COMMAND_SIZE; i++) { if (popFifo(commandFifo, &i2cSendData[i])) - i2cSendDataLength = 0; /* drop the data if the fifo seems corrupted XXX add an error feedback on this */ + i2cSendDataLength = 0; /* drop the data if the fifo seems corrupted XXX add an error feedback on this */ } i2cMasterStart(); cli(); - i2cFlags.i2c_idx = 0; /* release commandFifo protection */ + i2cFlags.i2c_idx = 0; /* release commandFifo protection */ i2cFlags.i2c_busy = 1; sei(); } @@ -144,8 +148,9 @@ else if (!i2c_idle_time--) { uint16_t wait = 0; + TWCR = 0; - while(wait++ < 0xFFF0); + while (wait++ < 0xFFF0) ; i2cFlags.i2c_busy = 0; i2cFlags.m_end = 0; i2cFlags.mt_nack = 0; @@ -163,15 +168,15 @@ * * The command[] parameter format starts with the command and then the parameters */ -uint8_t pushCommands(uint8_t* command) +uint8_t pushCommands(uint8_t * command) { uint8_t i; if (*command) { - if (fifoLength(commandFifo) > (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) /* Tux stack is full, we send an error back */ + if (fifoLength(commandFifo) > (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) /* Tux stack is full, we send an error back */ return 1; - for (i=0; i<=MAX_COMMAND_SIZE; i++) + for (i = 0; i <= MAX_COMMAND_SIZE; i++) pushFifo(commandFifo, *command++); return 0; } @@ -184,12 +189,13 @@ */ void acceptData(void) { - if (TWDR < 0xC0) /* command to be executed, cannot have 3 parameters */ + if (TWDR < 0xC0) /* command to be executed, cannot have 3 parameters */ { - if (!audioBufIdx) i2cFlags.s_val = 1; /* previous command processed */ + if (!audioBufIdx) + i2cFlags.s_val = 1; /* previous command processed */ } else if (fifoLength(statusFifo) < (INCOMING_FIFO_SIZE - MAX_COMMAND_SIZE)) - i2cFlags.s_val = 1; /* status with 3 parameters */ + i2cFlags.s_val = 1; /* status with 3 parameters */ } /* @@ -198,30 +204,31 @@ * Only do a backup of the buffer so any new i2c data won't overwrite the * previous ones */ -uint8_t pong_received; /* value of the pong received from the behavior */ -uint8_t pong_missed; /* counting the pong missed on the I2C */ +uint8_t pong_received; /* value of the pong received from the behavior */ +uint8_t pong_missed; /* counting the pong missed on the I2C */ -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData) +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) { - uint8_t i; + uint8_t i; - if (*receiveData < 0xC0) /* (audio) command to be executed, can't have 3 parameters */ + if (*receiveData < 0xC0) /* (audio) command to be executed, can't have 3 parameters */ { - for (i=0; i<receiveDataLength; i++) audioBuf[i] = receiveData[i]; + for (i = 0; i < receiveDataLength; i++) + audioBuf[i] = receiveData[i]; audioBufIdx = receiveDataLength; /* XXX only fill buffer if it's not full, need to add the check */ } - else /* fill in the statusFifo buffer */ + else /* fill in the statusFifo buffer */ { /* Pong check */ if (receiveData[0] == PONG_CMD) { - if (pong_received-- < receiveData[1]) /* new ping, reset */ + if (pong_received-- < receiveData[1]) /* new ping, reset */ { pong_received = receiveData[1]; pong_missed = 0; } - else if (pong_received > receiveData[1]) /* pongs missed */ + else if (pong_received > receiveData[1]) /* pongs missed */ { pong_missed++; pong_received = receiveData[1]; /* resync */ @@ -231,7 +238,7 @@ /* Store data on the fifo buffer */ if (fifoLength(statusFifo) < INCOMING_FIFO_SIZE - MAX_COMMAND_SIZE) - for (i=0; i<MAX_COMMAND_SIZE; i++) + for (i = 0; i < MAX_COMMAND_SIZE; i++) pushFifo(statusFifo, receiveData[i]); /* XXX add a return in case data was not added */ } @@ -244,20 +251,20 @@ * * The command[] parameter format starts with the command and then the parameters */ -uint8_t popStatus(uint8_t* command) +uint8_t popStatus(uint8_t * command) { uint8_t i; if (isFifoEmpty(statusFifo)) - return 1; /* nothing to do */ + return 1; /* nothing to do */ - cli(); /* XXX try to disable I2C interrupts instead */ - for (i=0; i<MAX_COMMAND_SIZE; i++) - if (popFifo(statusFifo, &command[i])) - { - sei(); - return 1; /* fifo corrupted so drop data XXX add some debug feedback on this instead of dropping data */ - } + cli(); /* XXX try to disable I2C interrupts instead */ + for (i = 0; i < MAX_COMMAND_SIZE; i++) + if (popFifo(statusFifo, &command[i])) + { + sei(); + return 1; /* fifo corrupted so drop data XXX add some debug feedback on this instead of dropping data */ + } sei(); return 0; } Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/communication.h 2007-04-22 18:09:42 UTC (rev 285) @@ -26,26 +26,28 @@ #include "fifo.h" #define COMMAND_BUF_SIZE 16 -#define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ +#define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ #define MAX_COMMAND_SIZE 4 #define INCOMING_BUF_SIZE 32 -#define INCOMING_FIFO_SIZE (INCOMING_BUF_SIZE - 1) /* due to the fifo construction */ +#define INCOMING_FIFO_SIZE (INCOMING_BUF_SIZE - 1) /* due to the fifo construction */ -extern uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -extern uint8_t audioBufIdx; /* index indicating the number of valid bytes in the buffer */ +extern uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +extern uint8_t audioBufIdx; /* index indicating the number of valid bytes in the buffer */ -extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ +extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ void i2cCommunicationInit(void); + /* From RF to i2c */ void sendCommands(void); -uint8_t pushCommands(uint8_t* command); +uint8_t pushCommands(uint8_t * command); + /* From i2c to RF */ void acceptData(void); -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData); -uint8_t popStatus(uint8_t* command); +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData); +uint8_t popStatus(uint8_t * command); /* XXX move to a global definition file */ -#define AUDIO_STATE 0xE0 /* state of the audio interface */ +#define AUDIO_STATE 0xE0 /* state of the audio interface */ -#endif /* COMMUNICATION_H */ +#endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/config.c =================================================================== --- firmware/tuxaudio/trunk/config.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/config.c 2007-04-22 18:09:42 UTC (rev 285) @@ -31,11 +31,15 @@ /* Initialize the configuration registers */ void config_init(void) { - eeprom_read_block((void*)&tuxaudio_config, (const void*)&tuxaudio_config_default, sizeof(tuxaudio_config_t)); + eeprom_read_block((void *)&tuxaudio_config, + (const void *)&tuxaudio_config_default, + sizeof(tuxaudio_config_t)); } /* Save the configuration registers to the eeprom */ void config_write(void) { - eeprom_write_block((const void*)&tuxaudio_config, (void*)&tuxaudio_config_default, sizeof(tuxaudio_config_t)); + eeprom_write_block((const void *)&tuxaudio_config, + (void *)&tuxaudio_config_default, + sizeof(tuxaudio_config_t)); } Modified: firmware/tuxaudio/trunk/config.h =================================================================== --- firmware/tuxaudio/trunk/config.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/config.h 2007-04-22 18:09:42 UTC (rev 285) @@ -30,4 +30,3 @@ void config_init(void); #endif /* CONFIG_H */ - Modified: firmware/tuxaudio/trunk/fifo.c =================================================================== --- firmware/tuxaudio/trunk/fifo.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/fifo.c 2007-04-22 18:09:42 UTC (rev 285) @@ -68,31 +68,31 @@ * \param p fifo pointer * * Note that the first element in the fifo will be stored in p->buffer[1] and not p->buffer[0] */ -void resetFifo(fifo_t *p) +void resetFifo(fifo_t * p) { p->inIdx = 0; p->outIdx = 0; p->pwm_adpt_sens = 0; - p->adpt_cycle=0; - p->matched=0; - p->pwm_min=230; - p->pwm_max=255; + p->adpt_cycle = 0; + p->matched = 0; + p->pwm_min = 230; + p->pwm_max = 255; } /** \brief Return TRUE if the fifo buffer is full (28b). * \param p fifo pointer * \return TRUE if fifo buffer is full */ -uint8_t isFifoFull(fifo_t *p) +uint8_t isFifoFull(fifo_t * p) { - return (p->outIdx == (((uint8_t)(p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return (p->outIdx == (((uint8_t) (p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Return TRUE if the fifo buffer is empty (22b). * \param p fifo pointer * \return TRUE if fifo buffer is empty */ -uint8_t isFifoEmpty(fifo_t *p) +uint8_t isFifoEmpty(fifo_t * p) { return (p->outIdx == p->inIdx); } @@ -101,9 +101,9 @@ * \param p fifo pointer * \return number of elements in the buffer */ -uint8_t fifoLength(fifo_t *p) +uint8_t fifoLength(fifo_t * p) { - return ((uint8_t)(p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return ((uint8_t) (p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Add one data byte to the fifo buffer (32b). @@ -112,15 +112,15 @@ * * If the fifo is already full, return immediately without doing anything. */ -void pushFifo(fifo_t *p, uint8_t data) +void pushFifo(fifo_t * p, uint8_t data) { - uint8_t inIdx; /* use of a local variable to reduce code size */ + uint8_t inIdx; /* use of a local variable to reduce code size */ - inIdx = ((uint8_t)(p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ - if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ + inIdx = ((uint8_t) (p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ { - p->inIdx = inIdx; /* ++ index */ - p->buffer[inIdx] = data; /* stora data */ + p->inIdx = inIdx; /* ++ index */ + p->buffer[inIdx] = data; /* stora data */ } } @@ -133,16 +133,17 @@ * fifo is empty, the index is not decreased, '1' is returned and the pointed * data is left unchanged. */ -uint8_t popFifo(fifo_t *p, uint8_t *data) +uint8_t popFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ - *data = p->buffer[p->outIdx]; /* get data */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ + *data = p->buffer[p->outIdx]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Pull the oldest byte from the fifo, always return something even if @@ -153,15 +154,16 @@ * If the fifo is empty, the index is not decreased but the latest value is * returned. */ -uint8_t pullFifo(fifo_t *p) +uint8_t pullFifo(fifo_t * p) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ } - return p->buffer[p->outIdx]; /* get data in all cases */ + return p->buffer[p->outIdx]; /* get data in all cases */ } + /*@}*/ /** @@ -177,24 +179,24 @@ * each level, a custom code or a function call can be provided to do the * adaptation. */ -void adaptFifo(fifo_t *p) +void adaptFifo(fifo_t * p) { unsigned char fifoLevel; - fifoLevel=fifoLength(p); - if(!p->adpt_cycle) + fifoLevel = fifoLength(p); + if (!p->adpt_cycle) { - if (p->matched==8) + if (p->matched == 8) { - if (OCR0A<254) - p->pwm_max=OCR0A+2; + if (OCR0A < 254) + p->pwm_max = OCR0A + 2; else - p->pwm_max=255; - if (OCR0A>231) - p->pwm_min=OCR0A-2; + p->pwm_max = 255; + if (OCR0A > 231) + p->pwm_min = OCR0A - 2; else - p->pwm_min=230; - p->matched=9; + p->pwm_min = 230; + p->matched = 9; } if (fifoLevel >= FIFO_ADAPT_HIGH) @@ -202,7 +204,7 @@ if (OCR0A > p->pwm_min) { OCR0A--; - p->pwm_adpt_sens=1; + p->pwm_adpt_sens = 1; } } else if (fifoLevel < FIFO_ADAPT_LOW) @@ -210,13 +212,13 @@ if (OCR0A < p->pwm_max) { OCR0A++; - p->pwm_adpt_sens=2; + p->pwm_adpt_sens = 2; } } else { if (p->pwm_adpt_sens) - { + { if ((p->pwm_adpt_sens) == 1) { if (OCR0A < p->pwm_max) @@ -228,17 +230,17 @@ OCR0A--; } p->pwm_adpt_sens = 0; - p->matched=0; + p->matched = 0; } else { - if (p->matched!=9) + if (p->matched != 9) p->matched++; } } } p->adpt_cycle++; - p->adpt_cycle&=(FIFO_ADAPT_RATE << 1)-1; + p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1; } /*@}*/ Modified: firmware/tuxaudio/trunk/fifo.h =================================================================== --- firmware/tuxaudio/trunk/fifo.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/fifo.h 2007-04-22 18:09:42 UTC (rev 285) @@ -96,13 +96,13 @@ /** \brief UD- Rate at which the adaptation is done. * * The adaptation function will only be run each 2^FIFO_ADAPT_RATE sample */ -#define FIFO_ADAPT_RATE 1 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ +#define FIFO_ADAPT_RATE 1 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ /** \brief UD- High level threshold */ -#define FIFO_ADAPT_HIGH 64// (p->size - (p->size>>2)) /* 3/4 of size */ +#define FIFO_ADAPT_HIGH 64 // (p->size - (p->size>>2)) /* 3/4 of size */ /** \brief UD- Low level threshold */ -#define FIFO_ADAPT_LOW 17// (p->size>>2) /* 1/4 of size */ +#define FIFO_ADAPT_LOW 17 // (p->size>>2) /* 1/4 of size */ #define FIFO_MATCHED_THRESHOLD 8 @@ -112,29 +112,30 @@ Note that the buffer can only hold (size - 1) elements to be able to make the difference between completely full and completely empty states. */ -typedef struct fifo_s { +typedef struct fifo_s +{ /** array that will store the elements */ - uint8_t *buffer; + uint8_t *buffer; /** size of the fifo buffer array minus 1 * The wrap around is made by a 'AND' function so the AND should be made with * the (array size -1) to be able to clear all bits above the array size. * This -1 is not related to the fact that the buffer can only hold (size -1) * elements. */ - uint8_t size; + uint8_t size; /** input index which indexes the last pushed value */ - uint8_t inIdx; + uint8_t inIdx; /** output index which indexes the last popped value */ - uint8_t outIdx; + uint8_t outIdx; /** current sens : increment or decrement pwm value */ - uint8_t pwm_adpt_sens; + uint8_t pwm_adpt_sens; /** cycle counter of adaptative function */ - uint8_t adpt_cycle; + uint8_t adpt_cycle; /** counter of good pwm value */ - uint8_t matched; + uint8_t matched; /** min value of pwm range */ - uint8_t pwm_min; + uint8_t pwm_min; /** max value of pwm range */ - uint8_t pwm_max; + uint8_t pwm_max; } fifo_t; @@ -142,13 +143,13 @@ * Extern declarations */ -void resetFifo(fifo_t *p); -uint8_t isFifoFull(fifo_t *p); -uint8_t isFifoEmpty(fifo_t *p); -uint8_t fifoLength(fifo_t *p); -void pushFifo(fifo_t *p, uint8_t data); -uint8_t popFifo(fifo_t *p, uint8_t *data); -uint8_t pullFifo(fifo_t *p); -void adaptFifo(fifo_t *p); +void resetFifo(fifo_t * p); +uint8_t isFifoFull(fifo_t * p); +uint8_t isFifoEmpty(fifo_t * p); +uint8_t fifoLength(fifo_t * p); +void pushFifo(fifo_t * p, uint8_t data); +uint8_t popFifo(fifo_t * p, uint8_t * data); +uint8_t pullFifo(fifo_t * p); +void adaptFifo(fifo_t * p); #endif /* FIFO_H */ Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/flash.c 2007-04-22 18:09:42 UTC (rev 285) @@ -24,237 +24,229 @@ #include "spi.h" #include "i2c.h" -unsigned char read_status (void); -void write_enable (void); -void write_disable (void); -void write_status (unsigned char status); -void erase_flash (void); -unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0); -void programmingAudio (void); -void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0); -void playingAudio (unsigned char nsound); -void stopPlayingAudio (void); +unsigned char read_status(void); +void write_enable(void); +void write_disable(void); +void write_status(unsigned char status); +void erase_flash(void); +unsigned char read_data(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +void programmingAudio(void); +void unprotect_sector(unsigned char ad2, unsigned char ad1, unsigned char ad0); +void playingAudio(unsigned char nsound); +void stopPlayingAudio(void); - -unsigned char read_status (void) +unsigned char read_status(void) { - unsigned char status; + unsigned char status; + PORTB &= ~0x02; // Chip Select - PORTB &= ~0x02; // Chip Select + spiSend(0x05); // Send Read Status Command + status = spiSend(0x00); // Read status on spi - spiSend (0x05); // Send Read Status Command - status = spiSend (0x00); // Read status on spi + PORTB |= 0x02; // Chip Deselect - PORTB |= 0x02; // Chip Deselect - return status; } - -void write_enable (void) +void write_enable(void) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x06); // Send Write Enable Command + spiSend(0x06); // Send Write Enable Command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void write_disable (void) +void write_disable(void) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x04); // Send Write Disable Command + spiSend(0x04); // Send Write Disable Command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void write_status (unsigned char status) +void write_status(unsigned char status) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x01); // Send Write Status Command - spiSend (status); // Send status + spiSend(0x01); // Send Write Status Command + spiSend(status); // Send status - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0) +void unprotect_sector(unsigned char ad2, unsigned char ad1, unsigned char ad0) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x39); // Send unprotect sector command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); + spiSend(0x39); // Send unprotect sector command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void erase_flash (void) +void erase_flash(void) { - write_status (0x00); // Disable sector protection register - write_enable(); // Enable the writing - unprotect_sector (0x00, 0x00, 0x00); // Unprotected sector 0 - write_enable(); // Enable the writing - unprotect_sector (0x01, 0x00, 0x00); // Unprotected sector 1 - write_enable(); // Enable the writing - unprotect_sector (0x02, 0x00, 0x00); // Unprotected sector 2 - write_enable(); // Enable the writing - unprotect_sector (0x03, 0x00, 0x00); // Unprotected sector 3 - write_enable(); // Enable the writing - unprotect_sector (0x04, 0x00, 0x00); // Unprotected sector 4 - write_enable(); // Enable the writing - unprotect_sector (0x05, 0x00, 0x00); // Unprotected sector 5 - write_enable(); // Enable the writing - unprotect_sector (0x06, 0x00, 0x00); // Unprotected sector 6 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0x00, 0x00); // Unprotected sector 7 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0x80, 0x00); // Unprotected sector 8 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0xA0, 0x00); // Unprotected sector 9 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0xC0, 0x00); // Unprotected sector 10 + write_status(0x00); // Disable sector protection register + write_enable(); // Enable the writing + unprotect_sector(0x00, 0x00, 0x00); // Unprotected sector 0 + write_enable(); // Enable the writing + unprotect_sector(0x01, 0x00, 0x00); // Unprotected sector 1 + write_enable(); // Enable the writing + unprotect_sector(0x02, 0x00, 0x00); // Unprotected sector 2 + write_enable(); // Enable the writing + unprotect_sector(0x03, 0x00, 0x00); // Unprotected sector 3 + write_enable(); // Enable the writing + unprotect_sector(0x04, 0x00, 0x00); // Unprotected sector 4 + write_enable(); // Enable the writing + unprotect_sector(0x05, 0x00, 0x00); // Unprotected sector 5 + write_enable(); // Enable the writing + unprotect_sector(0x06, 0x00, 0x00); // Unprotected sector 6 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0x00, 0x00); // Unprotected sector 7 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0x80, 0x00); // Unprotected sector 8 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0xA0, 0x00); // Unprotected sector 9 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0xC0, 0x00); // Unprotected sector 10 - write_enable(); // Enable the writing + write_enable(); // Enable the writing - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0xC7); // Send Erase Bulk command + spiSend(0xC7); // Send Erase Bulk command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - while (read_status()!= 0x10); // Wait Bulk Erase Cycle + while (read_status() != 0x10) ; // Wait Bulk Erase Cycle } - -void program_flash (unsigned char ad2, unsigned char ad1, unsigned char ad0, unsigned char data) +void program_flash(unsigned char ad2, unsigned char ad1, unsigned char ad0, + unsigned char data) { - write_enable (); + write_enable(); - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x02); // Send Page Byte Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - spiSend (data); // Write data in flash + spiSend(0x02); // Send Page Byte Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + spiSend(data); // Write data in flash - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - while (read_status() != 0x10); // Wait Page Program Cycle + while (read_status() != 0x10) ; // Wait Page Program Cycle } - -unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0) +unsigned char read_data(unsigned char ad2, unsigned char ad1, unsigned char ad0) { - unsigned char data1; + unsigned char data1; - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - data1 = spiSend (0x00); // Wait response + spiSend(0x03); // Send Read Page Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + data1 = spiSend(0x00); // Wait response - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - return data1; + return data1; } - -void programmingAudio (void) +void programmingAudio(void) { unsigned char ad0, ad1, ad2, i, j; - TCCR0A=0x00; // Desactivate PWM - TCCR0B=0x00; - OCR0A=0x00; - TIMSK0=0x00; + TCCR0A = 0x00; // Desactivate PWM + TCCR0B = 0x00; + OCR0A = 0x00; + TIMSK0 = 0x00; TWCR = (TWCR & TWCR_CMD_MASK) & ~_BV(TWIE); // Desactivate I2C // Deactivate all interrupt - resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ + resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ - programmingFlash = 1; // Set the flag to suspend the task + programmingFlash = 1; // Set the flag to suspend the task // First step ERASE FLASH - erase_flash (); // Erase the flash + erase_flash(); // Erase the flash // Second step WRITE FIRST BYTE OF TOC - program_flash (0x00, 0x00, 0x00, numSound); // Write first byte of the TOC + program_flash(0x00, 0x00, 0x00, numSound); // Write first byte of the TOC // Third step WRITE TOC - ad0 = 0x01; // Init TOC address + ad0 = 0x01; // Init TOC address ad1 = 0x00; ad2 = 0x00; - for (i = 0; i <= numSound; i++) // Writing TOC + for (i = 0; i <= numSound; i++) // Writing TOC { - while (!TOCRX); // Wait TOC address incomming - TOCRX = 0; // Reset TOC incomming flag + while (!TOCRX) ; // Wait TOC address incomming + TOCRX = 0; // Reset TOC incomming flag for (j = 0; j < 3; j++) { - program_flash (ad2, ad1, ad0, TOCadress[j]); - ad0++; // Increment new adress + program_flash(ad2, ad1, ad0, TOCadress[j]); + ad0++; // Increment new adress if (ad0 == 0x00) ad1++; } } - ad[0] = TOCadress[2]; // Save final addres + ad[0] = TOCadress[2]; // Save final addres ad[1] = TOCadress[1]; ad[2] = TOCadress[0]; // Fourth step WRITE SOUND - ad2 = 0x00; // Init sound address + ad2 = 0x00; // Init sound address ad1 = 0x04; ad0 = 0x00; - write_enable (); - PORTB &= ~0x02; // Chip Select - spiSend (0xAF); // Send Sequencial Program Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - while (1) // Send first byte into the page flash + write_enable(); + PORTB &= ~0x02; // Chip Select + spiSend(0xAF); // Send Sequencial Program Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + while (1) // Send first byte into the page flash { - if (!isFifoEmpty(&PWMFifo)) // Fifo not empty + if (!isFifoEmpty(&PWMFifo)) // Fifo not empty { - spiSend (pullFifo(&PWMFifo)); // Write data in flash + spiSend(pullFifo(&PWMFifo)); // Write data in flash ad0++; - break; // End of firt command + break; // End of firt command } } - PORTB |= 0x02; // Chip Deselect - while (read_status() != 0x52); // Wait Page Program Cycle + PORTB |= 0x02; // Chip Deselect + while (read_status() != 0x52) ; // Wait Page Program Cycle while (1) { - if (!isFifoEmpty(&PWMFifo)) // Fifo not empty + if (!isFifoEmpty(&PWMFifo)) // Fifo not empty { - PORTB &= ~0x02; // Chip Select - spiSend (0xAF); // Send Sequencial Program Command - spiSend (pullFifo(&PWMFifo)); // Write data in flash - PORTB |= 0x02; // Chip DeselecT - ad0++; // Increment address byte + PORTB &= ~0x02; // Chip Select + spiSend(0xAF); // Send Sequencial Program Command + spiSend(pullFifo(&PWMFifo)); // Write data in flash + PORTB |= 0x02; // Chip DeselecT + ad0++; // Increment address byte if (ad0 == 0x00) { ad1++; if (ad1 == 0x00) ad2++; } - while (read_status() != 0x52); // Wait Page Program Cycle + while (read_status() != 0x52) ; // Wait Page Program Cycle } if (ad2 == ad[2]) { @@ -262,43 +254,41 @@ { if (ad0 == ad[0]) { - break; // Stop programming flash + break; // Stop programming flash } } } } - write_disable (); // Disable wrtie flash + write_disable(); // Disable wrtie flash + TCCR0A = 0x23; // Reactivate PWM + TCCR0B = 0x09; + OCR0A = 249; /* we need TOP=250 to get a 8kHz sampling frequency */ + TIMSK0 = 0x01; - TCCR0A=0x23; // Reactivate PWM - TCCR0B=0x09; - OCR0A=249; /* we need TOP=250 to get a 8kHz sampling frequency */ - TIMSK0=0x01; + TWCR = (TWCR & TWCR_CMD_MASK) | _BV(TWIE); // Reactivate I2C - TWCR = (TWCR & TWCR_CMD_MASK) | _BV(TWIE); // Reactivate I2C - // Reactivate all interrupt - programmingFlash = 0; // Reset the flag to suspend the task + programmingFlash = 0; // Reset the flag to suspend the task } - -void playingAudio (unsigned char nsound) +void playingAudio(unsigned char nsound) { unsigned char count, i; - unsigned char adp1, adp0, sounds_stored; // Address pointer varaible + unsigned char adp1, adp0, sounds_stored; // Address pointer varaible - sounds_stored = read_data (0x00, 0x00, 0x00); - if (sounds_stored == 0xFF) /* if unprogrammed we have 0xFF stored in flash */ + sounds_stored = read_data(0x00, 0x00, 0x00); + if (sounds_stored == 0xFF) /* if unprogrammed we have 0xFF stored in flash */ return; - if (!nsound || (nsound > sounds_stored)) /* check the limits */ + if (!nsound || (nsound > sounds_stored)) /* check the limits */ return; count = 1; adp1 = 0x00; adp0 = 0x01; - while (count != nsound) // Compute address + while (count != nsound) // Compute address { for (i = 0; i < 3; i++) { @@ -309,49 +299,55 @@ count++; } - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (0x00); // Send Address - spiSend (adp1); - spiSend (adp0); + spiSend(0x03); // Send Read Page Command + spiSend(0x00); // Send Address + spiSend(adp1); + spiSend(adp0); for (i = 0; i < 6; i++) { - ad[i] = spiSend(0x00); // Read start and stop sound address + ad[i] = spiSend(0x00); // Read start and stop sound address } - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect /* Check adresses */ - if (ad[0] > 0x07) return; /* don't read outside the flash */ - if (ad[3] > 0x07) return; /* don't read outside the flash */ - if ((ad[0] == 0) && (ad[1] < 0x04)) return; /* minimum index not respected */ - if ((ad[4] == 0) && (ad[5] < 0x04)) return; /* minimum index not respected */ - if (ad[3] < ad[0]) return; /* check that the stop index is greater than the start index */ + if (ad[0] > 0x07) + return; /* don't read outside the flash */ + if (ad[3] > 0x07) + return; /* don't read outside the flash */ + if ((ad[0] == 0) && (ad[1] < 0x04)) + return; /* minimum index not respected */ + if ((ad[4] == 0) && (ad[5] < 0x04)) + return; /* minimum index not respected */ + if (ad[3] < ad[0]) + return; /* check that the stop index is greater than the start index */ else if (ad[3] == ad[0]) { - if (ad[4] < ad[1]) return; + if (ad[4] < ad[1]) + return; else if (ad[4] == ad[1]) - if (ad[5] <= ad[2]) return; + if (ad[5] <= ad[2]) + return; } - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (ad[0]); // Send Address - spiSend (ad[1]); - spiSend (ad[2]); - PORTB &= ~0x01; // Reset the HOLD signal + spiSend(0x03); // Send Read Page Command + spiSend(ad[0]); // Send Address + spiSend(ad[1]); + spiSend(ad[2]); + PORTB &= ~0x01; // Reset the HOLD signal - OCR0A = 250; // Normal operation for PWM if fifo adaptative is on - flashPlay = 1; // Read of sound + OCR0A = 250; // Normal operation for PWM if fifo adaptative is on + flashPlay = 1; // Read of sound } - -void stopPlayingAudio (void) +void stopPlayingAudio(void) { flashPlay = 0; - PORTB |= 0x01; // Set the HOLD signal - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x01; // Set the HOLD signal + PORTB |= 0x02; // Chip Deselect } Modified: firmware/tuxaudio/trunk/flash.h =================================================================== --- firmware/tuxaudio/trunk/flash.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/flash.h 2007-04-22 18:09:42 UTC (rev 285) @@ -22,16 +22,17 @@ #ifndef FLASH_H #define FLASH_H -extern unsigned char read_status (void); -extern void write_enable (void); -extern void write_disable (void); -extern void write_status (unsigned char status); -extern void erase_flash (void); -extern unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0); -extern void programmingAudio (void); -extern void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0); -extern void playingAudio (unsigned char nsound); -extern void stopPlayingAudio (void); +extern unsigned char read_status(void); +extern void write_enable(void); +extern void write_disable(void); +extern void write_status(unsigned char status); +extern void erase_flash(void); +extern unsigned char read_data(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +extern void programmingAudio(void); +extern void unprotect_sector(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +extern void playingAudio(unsigned char nsound); +extern void stopPlayingAudio(void); - #endif Modified: firmware/tuxaudio/trunk/i2c.c =================================================================== --- firmware/tuxaudio/trunk/i2c.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/i2c.c 2007-04-22 18:09:42 UTC (rev 285) @@ -28,14 +28,14 @@ /* * DEBUG and TEST flags */ -#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ -#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ +#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ +#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ /* DEBUG definitions and variables */ #if (__i2c_debug__) -uint8_t i2cStatus[32]; /* debug only */ +uint8_t i2cStatus[32]; /* debug only */ uint8_t i2cStatusIdx = 0; -extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ +extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ extern uint8_t i2cStatusIdx; #endif #if (__i2c_signals__) @@ -57,11 +57,13 @@ /* I2C status and address variables */ uint8_t i2cDeviceAddrRW; -volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ +volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ + /* send/transmit buffer (outgoing data) */ uint8_t i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; uint8_t i2cSendDataIndex; uint8_t i2cSendDataLength; + /* receive buffer (incoming data) */ uint8_t i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; uint8_t i2cReceiveDataIndex; @@ -70,10 +72,12 @@ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for * writing */ -static void (*i2cSlaveReceive)(uint8_t receiveDataLength, uint8_t* recieveData); +static void (*i2cSlaveReceive) (uint8_t receiveDataLength, + uint8_t * recieveData); /* I2cSlaveTransmit is called when this processor is addressed as a slave for * reading */ -static uint8_t (*i2cSlaveTransmit)(uint8_t transmitDataLengthMax, uint8_t* transmitData); +static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, + uint8_t * transmitData); /* functions */ @@ -90,7 +94,7 @@ /* Setting TWBR. There's a note in the datasheet that TWBR can't be lower * than 10 if the TWI is operated in Master mode */ #if ((F_CPU/1000UL)/I2C_SCL_FREQ_KHZ) < 36 - TWBR = 10; /* smallest TWBR value */ + TWBR = 10; /* smallest TWBR value */ #else TWBR = I2C_TWBR; #endif @@ -110,29 +114,34 @@ /* Set pull-up resistors on I2C bus pins */ #ifdef I2C_PULLUP - PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ - PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ + PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ + PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ #endif -#ifdef TWI_SLA_ENABLED /* If Slave mode: */ +#ifdef TWI_SLA_ENABLED /* If Slave mode: */ /* Set local device address (used in slave mode only) */ TWAR = I2C_TWAR; - TWCR = I2C_MODE; /* enable TWI */ -#else + TWCR = I2C_MODE; /* enable TWI */ +#else #ifdef TWI_M_ENABLED - TWCR = I2C_MODE; /* enable TWI */ + TWCR = I2C_MODE; /* enable TWI */ #endif #endif } /* Set the user function which handles receiving (incoming) data as a slave */ -void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +void +i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func) + (uint8_t receiveDataLength, uint8_t * recieveData)) { i2cSlaveReceive = i2cSlaveRx_func; } /* Set the user function which handles transmitting (outgoing) data as a slave */ -void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)) +void +i2cSetSlaveTransmitHandler(uint8_t(*i2cSlaveTx_func) + (uint8_t transmitDataLengthMax, + uint8_t * transmitData)) { i2cSlaveTransmit = i2cSlaveTx_func; } @@ -146,7 +155,7 @@ { volatile uint8_t wait; - for (wait=0; wait<20; wait++); /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ + for (wait = 0; wait < 20; wait++) ; /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ /* note: when a stop is immediately followed by a start, the slave detects * the stop, need to process the received data and exit the ISR. If it * doesn't have enough time to do this before a new start is set, it will @@ -158,8 +167,8 @@ if (i2cFlags.i2c_busy == 0) // if a start is sent when the TWI is receiving, one of the data will be received as 0x78 instead of 0x80 so we get a corruption there i2cSendStart(); #if (__i2c_signals__) - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ - START_PT |= START_MK; /* 'START' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + START_PT |= START_MK; /* 'START' debug signal */ #endif } @@ -169,9 +178,9 @@ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x02; #endif - i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ + i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif // TWCR = I2C_MODE; TWCR |= I2C_MODE; @@ -180,7 +189,7 @@ static inline void i2cSendStart(void) { #if (__i2c_debug__) - cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ + cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x03; sei(); @@ -198,7 +207,7 @@ TWCR = _BV(TWSTO) | I2C_MODE; i2cFlags.i2c_busy = 0; #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif } @@ -236,7 +245,7 @@ #ifdef TWI_INT_ENABLED ISR(SIG_TWI) { - const static void *twiLookupTable[]={ + const static void *twiLookupTable[] = { &&case_TW_BUS_ERROR, &&case_TW_START, &&case_TW_REP_START, @@ -271,156 +280,153 @@ &&case_TW_NO_INFO, }; - i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ + i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ #if (__i2c_debug__) i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = TW_STATUS; #endif #if (__i2c_signals__) - ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ #endif - goto *twiLookupTable[TWSR>>3]; /* switch(TW_STATUS) */ + goto *twiLookupTable[TWSR >> 3]; /* switch(TW_STATUS) */ { - /* * * Master General * * */ -case_TW_START: /* 0x08: start condition sent */ -case_TW_REP_START: /* 0x10: repeated start condition sent */ + /* * * Master General * * */ + case_TW_START: /* 0x08: start condition sent */ + case_TW_REP_START: /* 0x10: repeated start condition sent */ #if (__i2c_debug__) #endif #if (__i2c_signals__) - START_PT &= ~START_MK; /* 'START' debug signal */ + START_PT &= ~START_MK; /* 'START' debug signal */ #endif - i2cSendDataIndex = 0; /* reset the data index */ - i2cSendByte(i2cDeviceAddrRW); /* send device address */ + i2cSendDataIndex = 0; /* reset the data index */ + i2cSendByte(i2cDeviceAddrRW); /* send device address */ goto END_TABLE; + /* * * Master Transmitter & Receiver status codes * * */ - /* * * Master Transmitter & Receiver status codes * * */ - -case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ -case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ - #if (__i2c_debug__) - #endif - if(i2cSendDataIndex < i2cSendDataLength) + case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ + case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ +#if (__i2c_debug__) +#endif + if (i2cSendDataIndex < i2cSendDataLength) { - i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ + i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ } else { - i2cSendStop(); /* end of data stream */ + i2cSendStop(); /* end of data stream */ i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ } goto END_TABLE; -case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ -case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ -case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ -case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ + case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ + case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ + case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ +#if (__i2c_debug__) +#endif i2cFlags.mt_nack = 1; i2cSendStop(); goto END_TABLE; -case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ + case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ //case_TW_MR_ARB_LOST: /* 0x38: bus arbitration lost */ /* same code as above */ - #if (__i2c_debug__) - #endif +#if (__i2c_debug__) +#endif i2cReset(); goto END_TABLE; -case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ +#if (__i2c_debug__) +#endif // store received data byte i2... [truncated message content] |
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-22 18:00:26
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 284 Modified: firmware/tuxdefs/commands.h firmware/tuxdefs/config.h firmware/tuxdefs/remote.h Log: doegox 2007-04-22 20:00:21 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2007-04-22 17:47:57 UTC (rev 283) +++ firmware/tuxdefs/commands.h 2007-04-22 18:00:21 UTC (rev 284) @@ -99,8 +99,8 @@ typedef struct { uint8_t version_cmd; - uint8_t cpu_nbr :3; /* 3 lower bits are the CPU number */ - uint8_t ver_major :5; /* 5 higher bits are the major version number */ + uint8_t cpu_nbr:3; /* 3 lower bits are the CPU number */ + uint8_t ver_major:5; /* 5 higher bits are the major version number */ uint8_t ver_minor; uint8_t ver_update; } version_bf_t; @@ -113,28 +113,29 @@ typedef struct { uint8_t version_cmd; - uint8_t cpu_ver_maj; /* 3 lower bits are the CPU number, 5 higher bits are the major version number */ + uint8_t cpu_ver_maj; /* 3 lower bits are the CPU number, 5 higher bits are the major version number */ uint8_t ver_minor; uint8_t ver_update; } version_t; + #define CPU_VER_JOIN(cpu_nbr, ver_major) ((cpu_nbr & 0x7) + (ver_major << 3)) -#define CPU_VER_CPU(cpu_ver_maj) (cpu_ver_maj & 0x07) /* cpu_nbr: 3 lower bits */ -#define CPU_VER_MAJ(cpu_ver_maj) ((cpu_ver_maj & 0xF8) >> 3) /* ver_major: 5 higher bits */ +#define CPU_VER_CPU(cpu_ver_maj) (cpu_ver_maj & 0x07) /* cpu_nbr: 3 lower bits */ +#define CPU_VER_MAJ(cpu_ver_maj) ((cpu_ver_maj & 0xF8) >> 3) /* ver_major: 5 higher bits */ #define REVISION_CMD 0xC9 typedef struct { uint8_t revision_cmd; uint16_t revision; - uint8_t _undefined_; /* XXX reserved, maybe a branch ID? */ + uint8_t _undefined_; /* XXX reserved, maybe a branch ID? */ } revision_t; #define AUTHOR_CMD 0xCA typedef struct { uint8_t author_cmd; - uint16_t author_id; /* official releases have id=0, other authors can have their own id's */ - uint8_t _undefined_; /* XXX reserved */ + uint16_t author_id; /* official releases have id=0, other authors can have their own id's */ + uint8_t _undefined_; /* XXX reserved */ } author_t; /* @@ -147,35 +148,35 @@ * Move commands */ -#define BLINK_EYES_CMD 0x40 /* blink the eyes */ +#define BLINK_EYES_CMD 0x40 /* blink the eyes */ /* 1st parameter: number of movements before the eyes will stop */ -#define STOP_EYES_CMD 0x32 /* stop the eyes motor */ -#define OPEN_EYES_CMD 0x33 /* open the eyes if they are closed */ -#define MOVE_MOUTH_CMD 0x41 /* move the mouth */ +#define STOP_EYES_CMD 0x32 /* stop the eyes motor */ +#define OPEN_EYES_CMD 0x33 /* open the eyes if they are closed */ +#define MOVE_MOUTH_CMD 0x41 /* move the mouth */ /* 1st parameter: number of movements before the mouth will stop */ -#define OPEN_MOUTH_CMD 0x34 /* open the mouth if it is closed */ -#define CLOSE_MOUTH_CMD 0x35 /* close the mouth if it is open */ -#define STOP_MOUTH_CMD 0x36 /* stop the mouth motor */ -#define WAVE_WINGS_CMD 0x80 /* move the wings up and down */ +#define OPEN_MOUTH_CMD 0x34 /* open the mouth if it is closed */ +#define CLOSE_MOUTH_CMD 0x35 /* close the mouth if it is open */ +#define STOP_MOUTH_CMD 0x36 /* stop the mouth motor */ +#define WAVE_WINGS_CMD 0x80 /* move the wings up and down */ /* 1st parameter: number of movements before the wings will stop */ /* 2nd parameter: pwm value between 1 (slow) and 5 (fast) */ -#define STOP_WINGS_CMD 0x30 /* stop the wings motor */ -#define RESET_WINGS_CMD 0x31 /* reset the wings in the low position */ -#define SPIN_LEFT_CMD 0x82 /* spin left of a given angle */ +#define STOP_WINGS_CMD 0x30 /* stop the wings motor */ +#define RESET_WINGS_CMD 0x31 /* reset the wings in the low position */ +#define SPIN_LEFT_CMD 0x82 /* spin left of a given angle */ /* 1st parameter: angle to turn, the unit is approximately 1/8th of a turn */ /* 2nd parameter: pwm value between 1 (slow) and 5 (fast) */ -#define SPIN_RIGHT_CMD 0x83 /* spin right of a given angle */ +#define SPIN_RIGHT_CMD 0x83 /* spin right of a given angle */ /* 1st parameter: angle to turn, the unit is approximately 1/8th of a turn */ /* 2nd parameter: pwm value between 1 (slow) and 5 (fast) */ -#define STOP_SPIN_CMD 0x37 /* stop the spinning motor */ +#define STOP_SPIN_CMD 0x37 /* stop the spinning motor */ /* * IR commands */ -#define TURN_IR_ON_CMD 0x17 /* turn IR led on */ -#define TURN_IR_OFF_CMD 0x18 /* turn IR led off */ -#define IR_SEND_RC5_CMD 0x91 /* send RC5 ir code */ +#define TURN_IR_ON_CMD 0x17 /* turn IR led on */ +#define TURN_IR_OFF_CMD 0x18 /* turn IR led off */ +#define IR_SEND_RC5_CMD 0x91 /* send RC5 ir code */ /* 1st parameter: address - xxTAAAAA (T: toggle bit, A: RC5 5 bits address) */ /* 2nd parameter: command - xxCCCCCC (C: RC5 6 bits command) */ @@ -183,13 +184,13 @@ * LED commands */ -#define LED_ON_CMD 0x1A /* Turn all leds on */ -#define LED_OFF_CMD 0x1B /* Turn all leds off */ -#define LED_L_ON_CMD 0x1C /* Turn left led on */ -#define LED_L_OFF_CMD 0x1D /* Turn left led off */ -#define LED_R_ON_CMD 0x1E /* Turn right led on */ -#define LED_R_OFF_CMD 0x1F /* Turn right led off */ -#define LED_BLINK_CMD 0x9A /* Blink both leds multiple time */ +#define LED_ON_CMD 0x1A /* Turn all leds on */ +#define LED_OFF_CMD 0x1B /* Turn all leds off */ +#define LED_L_ON_CMD 0x1C /* Turn left led on */ +#define LED_L_OFF_CMD 0x1D /* Turn left led off */ +#define LED_R_ON_CMD 0x1E /* Turn right led on */ +#define LED_R_OFF_CMD 0x1F /* Turn right led off */ +#define LED_BLINK_CMD 0x9A /* Blink both leds multiple time */ /* 1st parameter: number of led toggles */ /* 2nd parameter: delay between each led toggle, in multiple of 4ms */ @@ -198,17 +199,17 @@ * * Audio commands can't have 3 parameters, see the above note for details */ -#define PLAY_SOUND_CMD 0x90 /* play a sound from the flash sound bank */ +#define PLAY_SOUND_CMD 0x90 /* play a sound from the flash sound bank */ /* 1st parameter: sound number */ /* 2nd parameter: sound volume */ -#define STORE_SOUND_CMD 0x52 /* start flash sound bank storage [1] */ +#define STORE_SOUND_CMD 0x52 /* start flash sound bank storage [1] */ /* 1st parameter: number of sounds to store */ -#define STORE_INDEX_CMD 0xD0 /* get indexes of the flash sound bank [1] */ +#define STORE_INDEX_CMD 0xD0 /* get indexes of the flash sound bank [1] */ /* 1st parameter: lower address byte */ /* 2nd parameter: middle address byte */ /* 3rd parameter: higher address byte */ -#define TEST_SOUND_CMD 0x10 /* test the audio input and output [1] */ -#define MUTE_CMD 0x92 /* mute/unmute the audio amplifier */ +#define TEST_SOUND_CMD 0x10 /* test the audio input and output [1] */ +#define MUTE_CMD 0x92 /* mute/unmute the audio amplifier */ /* 1st parameter: mute state 0:unmute 1:mute */ /* 2nd parameter: reserved */ @@ -221,7 +222,7 @@ /* * Sleep commands */ -#define SLEEP_CMD 0x93 /* set the CPU in sleep mode */ +#define SLEEP_CMD 0x93 /* set the CPU in sleep mode */ /* 1st parameter: XXX undefined yet */ /* 2nd parameter: XXX undefined yet */ @@ -232,7 +233,7 @@ /* * Status commands */ -#define STATUS_PORTS_CMD 0xC0 /* send core CPU's ports */ +#define STATUS_PORTS_CMD 0xC0 /* send core CPU's ports */ /* 1st parameter: PORTB * PB0: wings motor backward * PB1: spin motor forward @@ -263,8 +264,8 @@ * PD7: eyes closed position switch */ -#define SEND_AUDIOSENSORS_CMD 0xF0 /* send sensors status of the audio CPU to the core CPU */ -#define STATUS_SENSORS1_CMD 0xC1 /* send sensors status of the audio CPU to the computer */ +#define SEND_AUDIOSENSORS_CMD 0xF0 /* send sensors status of the audio CPU to the core CPU */ +#define STATUS_SENSORS1_CMD 0xC1 /* send sensors status of the audio CPU to the computer */ /* 1st parameter: switches and status from the audio CPU * .0: left wing push button * .1: right wing push button @@ -291,12 +292,12 @@ /* 2nd parameter: light level low byte */ /* 3rd parameter: light mode: 0: low light, 1:strong light */ -#define STATUS_POSITION1_CMD 0xC3 /* send position counters which is related to the motor status */ +#define STATUS_POSITION1_CMD 0xC3 /* send position counters which is related to the motor status */ /* 1st parameter: eyes position counter */ /* 2nd parameter: mouth position counter */ /* 3rd parameter: wings position counter */ -#define STATUS_POSITION2_CMD 0xC4 /* send position counters which is related to the motor status */ +#define STATUS_POSITION2_CMD 0xC4 /* send position counters which is related to the motor status */ /* 1st parameter: spin position counter */ /* 2nd parameter: */ /* 3rd parameter: */ @@ -326,13 +327,14 @@ /* 1st parameter: number of pongs pending */ /* 2nd parameter: number of pongs lost by the I2C */ /* 3rd parameter: number of pongs lost by the RF link */ -#define COND_RESET_CMD 0x3E /* reset conditional flags that are resettable */ +#define COND_RESET_CMD 0x3E /* reset conditional flags that are resettable */ /* * Error numbers */ -enum error_numbers_t { +enum error_numbers_t +{ E_STACK_CORRUPTION, /* 3rd parameter: see source code, depends on the function that report the error */ E_STATUS_INVALID, @@ -352,24 +354,27 @@ #define TEST_MODE_CMD 0xB8 /* 1st parameter: core CPU test mode */ -enum test_mode_b_t { - BT_NO_TEST, /* run in normal mode, no tests activated */ - BT_TEST_ALL, /* production tests, enable spinning while plugged, continuous light measurement */ - BT_REMOTE, /* use the remote control to control movements and sounds of tux */ - BT_MBTEST, /* test of the MB naked */ +enum test_mode_b_t +{ + BT_NO_TEST, /* run in normal mode, no tests activated */ + BT_TEST_ALL, /* production tests, enable spinning while plugged, continuous light measurement */ + BT_REMOTE, /* use the remote control to control movements and sounds of tux */ + BT_MBTEST, /* test of the MB naked */ BT_MBTEST0, BT_MBTEST1, BT_MBTEST2, BT_MBTEST3, }; + /* 2nd parameter: TUXAUDIO CPU test mode */ -enum test_mode_a_t { - AT_NO_TEST, /* run in normal mode, no tests activated */ - AT_NOSTATUSUP, /* flush the status buffer all the time so the I2C bus is running freely even without any RF connected */ - AT_MBTEST, /* test the flash,sends an acknowledge and enters audio link mode */ +enum test_mode_a_t +{ + AT_NO_TEST, /* run in normal mode, no tests activated */ + AT_NOSTATUSUP, /* flush the status buffer all the time so the I2C bus is running freely even without any RF connected */ + AT_MBTEST, /* test the flash,sends an acknowledge and enters audio link mode */ AT_MBTEST1, AT_MBTEST2, - AT_AUDIOLINK, /* link the microphone output to the speaker */ + AT_AUDIOLINK, /* link the microphone output to the speaker */ }; -#endif /* _COMMAND_H_ */ +#endif /* _COMMAND_H_ */ Modified: firmware/tuxdefs/config.h =================================================================== --- firmware/tuxdefs/config.h 2007-04-22 17:47:57 UTC (rev 283) +++ firmware/tuxdefs/config.h 2007-04-22 18:00:21 UTC (rev 284) @@ -1,3 +1,4 @@ + /* KySoH iTux agent * * Config options for tux @@ -19,7 +20,7 @@ #define SHORT_EVENT 16 #define LONG_EVENT 31 -#define END_OF_ACTIONS 0xFF /* action time that indicates the end of commands */ +#define END_OF_ACTIONS 0xFF /* action time that indicates the end of commands */ /* Startup event */ #define STARTUP_E_SEQ {\ @@ -104,15 +105,15 @@ */ typedef struct { - uint8_t ir_feedback; /* flashes the leds when an ir code is received */ - uint8_t led_off_when_closed_eyes; /* turns off the leds when the eyes are closed */ - uint8_t tux_greeting; /* greeting when another tux is seen */ + uint8_t ir_feedback; /* flashes the leds when an ir code is received */ + uint8_t led_off_when_closed_eyes; /* turns off the leds when the eyes are closed */ + uint8_t tux_greeting; /* greeting when another tux is seen */ } tuxcore_config_t; typedef struct { - uint8_t automute; /* mutes the speaker when no sounds are played and unmute it when sound arrives, you can't use the line in in this mode as the insertion of a plug is not detected so the speaker won't be unmuted */ + uint8_t automute; /* mutes the speaker when no sounds are played and unmute it when sound arrives, you can't use the line in in this mode as the insertion of a plug is not detected so the speaker won't be unmuted */ } tuxaudio_config_t; @@ -120,5 +121,4 @@ #define TUXCORE_CONFIG {1, 1, 0} #define TUXAUDIO_CONFIG {0} - #endif /* _CONFIG_H_ */ Modified: firmware/tuxdefs/remote.h =================================================================== --- firmware/tuxdefs/remote.h 2007-04-22 17:47:57 UTC (rev 283) +++ firmware/tuxdefs/remote.h 2007-04-22 18:00:21 UTC (rev 284) @@ -1,3 +1,4 @@ + /* KySoH iTux agent * * General command listing |