tux-droid-svn Mailing List for Tux Droid CE (Page 196)
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...> - 2008-05-07 14:39:53
|
Author: jaguarondi Date: 2008-05-07 16:39:47 +0200 (Wed, 07 May 2008) New Revision: 1131 Modified: firmware/tuxdefs/defines.h Log: * Added a protocol section in common files. Modified: firmware/tuxdefs/defines.h =================================================================== --- firmware/tuxdefs/defines.h 2008-05-07 12:42:28 UTC (rev 1130) +++ firmware/tuxdefs/defines.h 2008-05-07 14:39:47 UTC (rev 1131) @@ -83,6 +83,17 @@ /*! @} */ /** + * \name Hardware protocol + * Protocol between the computer program (daemon, driver, etc.) and all MCUs + * (USB, RF, core and audio). + */ +/*! @{ */ +/** Size of a command in the main communication protocol. */ +#define CMD_SIZE 4 + +/*! @} */ + +/** * \name Versioning */ /*! @{ */ |
From: jaguarondi <c2m...@c2...> - 2008-05-07 12:43:19
|
Author: jaguarondi Date: 2008-05-07 14:42:28 +0200 (Wed, 07 May 2008) New Revision: 1130 Modified: firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/misc.c firmware/tuxaudio/trunk/parser.c Log: * Renamed stuff, updated documentation and improved consistency between functions, and final cleanup of the communication module. This finally looks good now. Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/communication.c 2008-05-07 12:42:28 UTC (rev 1130) @@ -23,6 +23,7 @@ #include <avr/interrupt.h> #include "communication.h" +#include "fifo.h" #include "i2c.h" #include "parser.h" #include "hardware.h" @@ -34,19 +35,18 @@ static uint8_t in_buf[CMD_SIZE]; static struct i2c_msg msg_in = {0, 0, in_buf}; -/* - * core_cmdout is a stack for commands to be sent to tuxcore - */ -FIFO_INSTANCE(core_cmdout_buf, COMMAND_BUF_SIZE); +/** Size of the stack buffer to tuxcore */ +#define CORE_OUT_BUF_SIZE 16 +/** Size of the stack buffer to tuxrf */ +#define RF_OUT_BUF_SIZE 32 + +FIFO_INSTANCE(core_cmdout_buf, CORE_OUT_BUF_SIZE); +/** Stack for commands to be sent to tuxcore */ fifo_t *core_cmdout = FifoPointer(core_cmdout_buf); -/* - * statusFifo is a fifo buffer for commands received from the i2c and that - * should be sent over the RF link - * - */ -FIFO_INSTANCE(statusFifo_s, INCOMING_BUF_SIZE); -fifo_t *statusFifo = FifoPointer(statusFifo_s); +FIFO_INSTANCE(rf_cmdout_buf_s, RF_OUT_BUF_SIZE); +/** Stack for commands to be sent to rf */ +fifo_t *rf_cmdout_buf = FifoPointer(rf_cmdout_buf_s); /* @@ -58,13 +58,13 @@ FifoClear(core_cmdout); } -/* - * sendCommands takes one command (from 1 to 4 bytes) out of the command stack - * and send them by i2c. +/** + * \brief Take one command out of the command stack and send it through i2c. * - * Should return 0 if nothing has to be sent. + * \return 0 if nothing has to be sent, -1 if the stack is corrupted, 1 if + * something has been sent. */ -int8_t sendCommands(void) +static int8_t send_core_cmds(void) { uint8_t i; @@ -87,10 +87,14 @@ return 1; } -void get_core_cmd(void) +/** + * \brief Start an I2C read request to fetch one command from tuxcore. + * If the rf stack is full, we return immediately. + */ +static void get_core_cmd(void) { /* First check if the stack is not full */ - if (FifoLength(statusFifo) > INCOMING_BUF_SIZE - CMD_SIZE) + if (FifoLength(rf_cmdout_buf) > RF_OUT_BUF_SIZE - CMD_SIZE) return; if (i2c_get_status() != I2C_BUSY) @@ -100,69 +104,79 @@ } -/* - * Add a command on the stack for tuxcore - * Returns 0 if the stack is full, 1 if the command has been added +/** + * \brief Add a command on the stack for tuxcore + * \return 0 if the stack is full, 1 if the command has been added * successfully. */ -int8_t send_core_cmd(uint8_t *cmd) +int8_t queue_core_cmd(uint8_t *cmd) { uint8_t i; if (FifoLength(core_cmdout) > FifoSize(core_cmdout) - CMD_SIZE) return 0; + uint8_t sreg; + sreg = SREG; cli(); for (i=0; i<CMD_SIZE; i++) FifoPut(core_cmdout, cmd[i]); - sei(); + SREG = sreg; return 1; } -/* - * Add a command on the stack for tuxcore - * Returns 0 if the stack is full, 1 if the command has been added +/** + * \brief Add a command on the stack for tuxcore + * \return 0 if the stack is full, 1 if the command has been added * successfully. */ -int8_t send_core_cmd_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ +int8_t queue_core_cmd_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ uint8_t param3) { uint8_t c[4] = {cmd , param1, param2, param3}; - return send_core_cmd(c); + return queue_core_cmd(c); } -/* Send status to RF. */ -void send_status(uint8_t const *status) +/** + * \brief Add a command on the stack for the rf + * \return 0 if the stack is full, 1 if the command has been added + * successfully. + */ +int8_t queue_rf_cmd(uint8_t const *status) { uint8_t i; - if (FifoLength(statusFifo) <= INCOMING_BUF_SIZE - CMD_SIZE) - { - uint8_t sreg; - sreg = SREG; - cli(); - for (i = 0; i < CMD_SIZE; i++) - FifoPut(statusFifo, status[i]); - SREG = sreg; - } - /* XXX what if stack is full? */ + if (FifoLength(rf_cmdout_buf) > RF_OUT_BUF_SIZE - CMD_SIZE) + return 0; + + uint8_t sreg; + sreg = SREG; + cli(); + for (i = 0; i < CMD_SIZE; i++) + FifoPut(rf_cmdout_buf, status[i]); + SREG = sreg; + return 1; } -/* Send status to RF. */ -void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ +/** + * \brief Add a command on the stack for the rf + * \return 0 if the stack is full, 1 if the command has been added + * successfully. + */ +int8_t queue_rf_cmd_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ uint8_t param3) { uint8_t c[4] = {cmd , param1, param2, param3}; - send_status(c); + return queue_rf_cmd(c); } -/* - * Slave receiver function associated with the i2c ISR - * - * Only do a backup of the buffer so any new i2c data won't overwrite the - * previous ones +/** + * \brief Callback function associated with the i2c ISR and which process the + * received command. + * \param msg I2C message received + * \return 0 if a stop should be sent, 1 for a restart. */ -bool i2cMasterReceiveService(struct i2c_msg *msg) +bool i2c_master_receive_service(struct i2c_msg *msg) { if (msg->len != CMD_SIZE) /* Error here. */ @@ -178,36 +192,33 @@ /* New pointer necessary as parse_cmd modifies the pointer. */ uint8_t *cmd = msg->buf; /* Parse the command */ - /* XXX Should be moved out of the interrupt, no? */ parse_cmd(cmd); /* and forward if it isn't dropped. */ if (cmd) - send_status(cmd); + queue_rf_cmd(cmd); /* As we got something, there's maybe more so if the stack is not full, * continue */ - if (FifoLength(statusFifo) <= INCOMING_BUF_SIZE - CMD_SIZE) + if (FifoLength(rf_cmdout_buf) <= RF_OUT_BUF_SIZE - CMD_SIZE) return 1; } return 0; } /* - * Get a set of status commands from the statusFifo buffer. The command + * Get a set of status commands from the rf_cmdout_buf buffer. The command * length will always be CMD_SIZE. Returns '1' if there's nothing to * get, '0' otherwise. - * - * The command[] parameter format starts with the command and then the parameters */ uint8_t popStatus(uint8_t *command) { uint8_t i; - if (!FifoLength(statusFifo)) + if (!FifoLength(rf_cmdout_buf)) return 1; /* nothing to do */ cli(); /* XXX try to disable I2C interrupts instead */ for (i = 0; i < CMD_SIZE; i++) - if (FifoGet(statusFifo, &command[i])) + if (FifoGet(rf_cmdout_buf, &command[i])) { sei(); return 1; /* fifo corrupted so drop data XXX add some debug @@ -217,13 +228,17 @@ return 0; } +/** + * \brief Service routine that handles the regular communication tasks like sending + * and fetching commands. + */ void communication_task(void) { /* Clear stack when the RF is disconnected. This makes sense but is * necessary otherwise the standalone commands won't be fetched anymore * when the RF is off. */ if (!(RF_ONLINE_PIN & RF_ONLINE_MK)) - FifoClear(statusFifo); + FifoClear(rf_cmdout_buf); /* If busy, pass. */ if (i2c_get_status() == I2C_BUSY) @@ -236,25 +251,22 @@ return; } - if (!sendCommands()) + /* Send otherwise get commands. */ + if (!send_core_cmds()) { get_core_cmd(); } } -/* - * I2C communication initalisation - * - * Start the twi interface in the mode defined in i2c.h, set the receiver function and - * the behaviour CPU address. +/** + * \brief Initialize the I2C communication and the in and out buffers. */ -void i2cCommunicationInit(void) +void communication_init(void) { i2c_init(); msg_out.addr = TUXCORE_ADDR; msg_out.len = CMD_SIZE; - //msg_out.buf = out_buf; msg_in.addr = TUXCORE_ADDR; msg_in.len = CMD_SIZE; - i2c_master_receive_handler(i2cMasterReceiveService); + i2c_master_receive_handler(i2c_master_receive_service); } Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/communication.h 2008-05-07 12:42:28 UTC (rev 1130) @@ -22,45 +22,23 @@ #ifndef COMMUNICATION_H #define COMMUNICATION_H -#include <stdbool.h> - #include "common/commands.h" #include "common/api.h" #include "common/defines.h" -#include "varis.h" -#include "fifo.h" -#define COMMAND_BUF_SIZE 16 -#define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ -#define CMD_SIZE 4 -#define INCOMING_BUF_SIZE 32 -#define INCOMING_FIFO_SIZE (INCOMING_BUF_SIZE - 1) /* due to the fifo construction */ +void communication_init(void); +void communication_task(void); -extern uint8_t audioBuf[CMD_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 */ - -/* /< XXX New clean commands */ -int8_t send_core_cmd(uint8_t *command); -int8_t send_core_cmd_p(uint8_t command, uint8_t param1, uint8_t param2, \ +int8_t queue_core_cmd(uint8_t *command); +int8_t queue_core_cmd_p(uint8_t command, uint8_t param1, uint8_t param2, \ uint8_t param3); -/* XXX /> */ +int8_t queue_rf_cmd(uint8_t const *status); +int8_t queue_rf_cmd_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ + uint8_t param3); -void i2cCommunicationInit(void); +/* XXX to remove */ void initCommunicationBuffers(void); - -/* From RF to i2c */ -int8_t sendCommands(void); - - -/* From i2c to RF */ -void acceptData(void); -void send_status(uint8_t const *status); -void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ - uint8_t param3); +/* XXX change this when reviewing the rf communication. */ uint8_t popStatus(uint8_t * command); -void get_core_cmd(void); -void communication_task(void); #endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/flash.c 2008-05-07 12:42:28 UTC (rev 1130) @@ -27,6 +27,7 @@ #include "i2c.h" #include "flash.h" #include "AT26F004.h" +#include "common/commands.h" #include "common/api.h" /* Declarations */ @@ -149,14 +150,14 @@ if (ad[0] > 0x07) { programming_state = PROG_END; - send_status_p(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); } else programming_state ++; frame_without_sound = 5000; frame_without_sound_timeout = 5000; - send_status_p(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); } else if (programming_state == PROG_INIT) @@ -177,12 +178,12 @@ if (sound_stored) { last_block = (ad[0] << 4) + (ad[1] >> 4); - send_status_p(STATUS_FLASH_PROG_CMD, WAITING_FOR_CONFIRMATION, last_block - first_block, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, WAITING_FOR_CONFIRMATION, last_block - first_block, 0); programming_state ++; } else { - send_status_p(STATUS_FLASH_PROG_CMD, NO_SOUND, 0, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, NO_SOUND, 0, 0); programming_state = PROG_END; } } @@ -195,7 +196,7 @@ } else if (write_toc == 2) { - send_status_p(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0); if (first_block == 0) { eraseFlag = 1; @@ -214,7 +215,7 @@ } else if (programming_state == PROG_TOC) { - send_status_p(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); numSound ++; index = (numSound * 3) + 1; program_flash(0x00, (index>>8), (index & 0xFF), ad[0]); @@ -232,8 +233,8 @@ programming_state = 0; programmingFlash = 0; TIMSK0 = 0x01; - send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); - send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + queue_rf_cmd_p(SOUND_VAR_CMD, numSound, last_block, 0); } } @@ -284,7 +285,7 @@ } else if (!(read_status() & BUSY)) { - //send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + //queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); enter = 1; eraseFlag = 0; program_flash(0x00, 0x00, 0x00, 0xFE); @@ -293,8 +294,8 @@ program_flash(0x00, 0x00, 0x03, 0x00); numSound = 0; last_block = 0; - send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); - send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); + queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + queue_rf_cmd_p(SOUND_VAR_CMD, numSound, last_block, 0); TIMSK0 = 0x01; } } @@ -488,7 +489,7 @@ { soundToPlay = 0; flashPlay = 0; - send_status_p(STATUS_AUDIO_CMD, 0, 0, 0); + queue_rf_cmd_p(STATUS_AUDIO_CMD, 0, 0, 0); PORTB |= 0x01; // Set the HOLD signal PORTB |= 0x02; // Chip Deselect } Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/main.c 2008-05-07 12:42:28 UTC (rev 1130) @@ -90,7 +90,7 @@ PRR = PRR_bak; init_avr(); initCommunicationBuffers(); - i2cCommunicationInit(); + communication_init(); leave_deep_sleep(); } @@ -137,7 +137,7 @@ command[3] = 1; else command[3] = 0; - send_core_cmd(command); /* push the command set on the filo stack */ + queue_core_cmd(command); /* push the command set on the filo stack */ } int main(void) @@ -149,7 +149,7 @@ config_init(); /* load the configuration defaults from EEPROM */ numSound = readFlashNumber(); last_block = readLastBlock(numSound); - i2cCommunicationInit(); /* I2C initialization */ + communication_init(); /* I2C initialization */ frame_without_sound_timeout = TTS_TIMEOUT; sei(); /* Init global interrupt */ @@ -178,7 +178,7 @@ /* XXX there are some empty commands getting through, removed from * here for now. */ if (spi_commandRX && spi_commandRX[0]) - send_core_cmd(spi_commandRX); + queue_core_cmd(spi_commandRX); } if (programmingFlash) // Restora all the context for flash programming @@ -211,7 +211,7 @@ sendSensors(); /* wait for all status to be sent before going to sleep */ /* TODO fix these conditions for the sleep */ - //if (isFifoEmpty(statusFifo)) + //if (isFifoEmpty(rf_cmdout_buf)) /* wait for audio commands to be processed */ //if (!audioBufIdx && !flashPlay) Modified: firmware/tuxaudio/trunk/misc.c =================================================================== --- firmware/tuxaudio/trunk/misc.c 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/misc.c 2008-05-07 12:42:28 UTC (rev 1130) @@ -25,6 +25,7 @@ #include "misc.h" #include "communication.h" #include "version.h" +#include "varis.h" /* * Version number @@ -48,9 +49,9 @@ /* Retrieve version information */ for (i = 0; i < 12; i++) buf[i] = pgm_read_byte(data++); - send_status((uint8_t const *) buf); - send_status((uint8_t const *) buf+4); - send_status((uint8_t const *) buf+8); + queue_rf_cmd((uint8_t const *) buf); + queue_rf_cmd((uint8_t const *) buf+4); + queue_rf_cmd((uint8_t const *) buf+8); /* Send extra information */ - send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); + queue_rf_cmd_p(SOUND_VAR_CMD, numSound, last_block, 0); } Modified: firmware/tuxaudio/trunk/parser.c =================================================================== --- firmware/tuxaudio/trunk/parser.c 2008-05-07 11:12:02 UTC (rev 1129) +++ firmware/tuxaudio/trunk/parser.c 2008-05-07 12:42:28 UTC (rev 1130) @@ -91,7 +91,7 @@ audioLevel = cmd[2]; //playingAudio(cmd[1]); /* start playing the sound */ soundToPlay = cmd[1]; - send_status_p(STATUS_AUDIO_CMD, cmd[1], 0, 0); + queue_rf_cmd_p(STATUS_AUDIO_CMD, cmd[1], 0, 0); flashPlay = 1; flash_state = 1; } |
From: jaguarondi <c2m...@c2...> - 2008-05-07 11:12:00
|
Author: jaguarondi Date: 2008-05-07 13:12:02 +0200 (Wed, 07 May 2008) New Revision: 1129 Modified: firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/hardware.h firmware/tuxaudio/trunk/i2c.c firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/parser.c Log: * Now continuously polling for commands, not only each 33ms. * Clear statusFifo when RF offline otherwise standalone command doesn't get through in this case. * Some commands were still lost because the I2C_BUSY was not set if a restart and the stack could overflow. I now wait for the stack to have some space before fetching new commands. * Some more cleanup. Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/communication.c 2008-05-07 11:12:02 UTC (rev 1129) @@ -25,6 +25,7 @@ #include "communication.h" #include "i2c.h" #include "parser.h" +#include "hardware.h" /* I2C write message (out) */ static uint8_t out_buf[CMD_SIZE]; @@ -33,9 +34,6 @@ static uint8_t in_buf[CMD_SIZE]; static struct i2c_msg msg_in = {0, 0, in_buf}; -/* XXX to delete */ -uint8_t statusFlag; - /* * core_cmdout is a stack for commands to be sent to tuxcore */ @@ -43,18 +41,6 @@ fifo_t *core_cmdout = FifoPointer(core_cmdout_buf); /* - * audioBuf is a single buffer for commands received over i2c to control the - * audio interface - * - * audioBufIdx should be set to the number of valid bytes in the buffer, - * depending on the number of parameters associated with the command. It is - * cleared when the command is processed so it can be used to check whether the - * buffer has been processed or not. - */ -uint8_t audioBuf[CMD_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 * @@ -65,11 +51,11 @@ /* * Initialize (clear) the communication buffers + * XXX can't we delete this? */ void initCommunicationBuffers(void) { FifoClear(core_cmdout); - audioBufIdx = 0; } /* @@ -85,7 +71,6 @@ if (FifoLength(core_cmdout)) /* Send commands received from RF or testers to tuxcore only. */ { - msg_out.len = CMD_SIZE; for (i = 0; i < CMD_SIZE; i++) { if (FifoGet(core_cmdout, &out_buf[i])) @@ -93,7 +78,6 @@ * bytes) XXX add an error feedback on this */ return -1; } - msg_out.addr = TUXCORE_ADDR; i2c_send_bytes(&msg_out); } else @@ -105,10 +89,12 @@ void get_core_cmd(void) { + /* First check if the stack is not full */ + if (FifoLength(statusFifo) > INCOMING_BUF_SIZE - CMD_SIZE) + return; + if (i2c_get_status() != I2C_BUSY) { - msg_in.addr = TUXCORE_ADDR; - msg_in.len = CMD_SIZE; i2c_read_bytes(&msg_in); } } @@ -192,12 +178,15 @@ /* New pointer necessary as parse_cmd modifies the pointer. */ uint8_t *cmd = msg->buf; /* Parse the command */ + /* XXX Should be moved out of the interrupt, no? */ parse_cmd(cmd); /* and forward if it isn't dropped. */ if (cmd) send_status(cmd); - /* As we got something, there's maybe more so continue */ - return 1; + /* As we got something, there's maybe more so if the stack is not full, + * continue */ + if (FifoLength(statusFifo) <= INCOMING_BUF_SIZE - CMD_SIZE) + return 1; } return 0; } @@ -228,8 +217,14 @@ return 0; } -void core_communications(bool tick) +void communication_task(void) { + /* Clear stack when the RF is disconnected. This makes sense but is + * necessary otherwise the standalone commands won't be fetched anymore + * when the RF is off. */ + if (!(RF_ONLINE_PIN & RF_ONLINE_MK)) + FifoClear(statusFifo); + /* If busy, pass. */ if (i2c_get_status() == I2C_BUSY) return; @@ -240,19 +235,10 @@ i2c_send_bytes(&msg_out); return; } - else if (msg_in.state == I2C_NACK) - { - get_core_cmd(); - return; - } if (!sendCommands()) { - if (tick) - { - get_core_cmd(); - statusFlag = 0; - } + get_core_cmd(); } } @@ -266,7 +252,9 @@ { i2c_init(); msg_out.addr = TUXCORE_ADDR; - msg_out.buf = out_buf; + msg_out.len = CMD_SIZE; + //msg_out.buf = out_buf; + msg_in.addr = TUXCORE_ADDR; + msg_in.len = CMD_SIZE; i2c_master_receive_handler(i2cMasterReceiveService); } - Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/communication.h 2008-05-07 11:12:02 UTC (rev 1129) @@ -39,8 +39,6 @@ extern uint8_t audioBuf[CMD_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 statusFlag; - extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ /* /< XXX New clean commands */ @@ -63,6 +61,6 @@ uint8_t param3); uint8_t popStatus(uint8_t * command); void get_core_cmd(void); -void core_communications(bool tick); +void communication_task(void); #endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/hardware.h =================================================================== --- firmware/tuxaudio/trunk/hardware.h 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/hardware.h 2008-05-07 11:12:02 UTC (rev 1129) @@ -42,6 +42,15 @@ /** RF reset DDR. */ #define RF_RESET_DDR DDRB +/** RF online mask. */ +#define RF_ONLINE_MK _BV(PB6) +/** RF online PIN. */ +#define RF_ONLINE_PIN PINB +/** RF online PORT. */ +#define RF_ONLINE_PT PORTB +/** RF online DDR. */ +#define RF_ONLINE_DDR DDRB + /* Flash memory port */ #define FLASH_PORT PORTB #define FLASH_CS_PIN _BV(PB1) Modified: firmware/tuxaudio/trunk/i2c.c =================================================================== --- firmware/tuxaudio/trunk/i2c.c 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/i2c.c 2008-05-07 11:12:02 UTC (rev 1129) @@ -365,6 +365,7 @@ if (i2c_master_receive(m_msg)) { buf_idx = 0; + i2c_state = I2C_BUSY; twi_send_start(); /* restart a read */ } else Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/main.c 2008-05-07 11:12:02 UTC (rev 1129) @@ -129,7 +129,7 @@ command[0] = SEND_AUDIOSENSORS_CMD; command[1] = (PINC & 0x0F) | (PIND & 0xD0); /* get switches, charger status , RF status and mute status */ - if (PINB & 0x40) + if (RF_ONLINE_PIN & RF_ONLINE_MK) command[1] |= 0x20; command[1] ^= 0x9B; /* some bits should be inverted */ command[2] = soundToPlay; @@ -160,7 +160,7 @@ * This delay is critical as the INT0 is quite shaky and any glitches on * INT0 at the boot of the RF CPU immeditely crash this CPU or set it in * the while(1) loop of spi.c */ - while (PINB & 0x40); + while (RF_ONLINE_PIN & RF_ONLINE_MK); /* Activate the interrupts used by the RF module. */ EIFR = (_BV(INT1) | _BV(INT0)); EIMSK = (_BV(INT1) | _BV(INT0)); @@ -191,7 +191,7 @@ erase(); /* Send commands to I2C, otherwise get new status from tuxcore */ - core_communications(statusFlag); + communication_task(); /*else if (sleep_f)*/ /*{*/ /*sleep_f = 0;*/ @@ -215,9 +215,6 @@ /* wait for audio commands to be processed */ //if (!audioBufIdx && !flashPlay) - /* Main tick to retrieve status */ - statusFlag = 1; - /* Delay used to power the IR receiver slowly */ if (power_on_reset_delay) { Modified: firmware/tuxaudio/trunk/parser.c =================================================================== --- firmware/tuxaudio/trunk/parser.c 2008-05-07 10:45:54 UTC (rev 1128) +++ firmware/tuxaudio/trunk/parser.c 2008-05-07 11:12:02 UTC (rev 1129) @@ -52,7 +52,7 @@ pong_received = cmd[1]; pong_missed = 0; } - else if (pong_received > cmd[1]) /* pongs missed */ + else /* pongs */ { pong_missed += pong_received - cmd[1]; pong_received = cmd[1]; /* resync */ |
From: jaguarondi <c2m...@c2...> - 2008-05-07 10:45:54
|
Author: jaguarondi Date: 2008-05-07 12:45:54 +0200 (Wed, 07 May 2008) New Revision: 1128 Modified: firmware/tuxcore/trunk/communication.c firmware/tuxcore/trunk/communication.h firmware/tuxcore/trunk/main.c Log: * Moved the pong function so that they are sent as fast as possible, not one every 100ms anymore. This should point more communication problems in this worst case. Modified: firmware/tuxcore/trunk/communication.c =================================================================== --- firmware/tuxcore/trunk/communication.c 2008-05-07 10:44:53 UTC (rev 1127) +++ firmware/tuxcore/trunk/communication.c 2008-05-07 10:45:54 UTC (rev 1128) @@ -171,6 +171,11 @@ (i2c_get_status() == I2C_BUSY)); } +bool cmds_empty(void) +{ + return !FifoLength(statusFifo); +} + /** * I2C communication initialization * Modified: firmware/tuxcore/trunk/communication.h =================================================================== --- firmware/tuxcore/trunk/communication.h 2008-05-07 10:44:53 UTC (rev 1127) +++ firmware/tuxcore/trunk/communication.h 2008-05-07 10:45:54 UTC (rev 1128) @@ -47,6 +47,7 @@ uint8_t param3); int8_t send_cmd(uint8_t *status); bool cmds_sent(void); +bool cmds_empty(void); uint8_t fetchCommands(void); #endif /* COMMUNICATION_H */ Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2008-05-07 10:44:53 UTC (rev 1127) +++ firmware/tuxcore/trunk/main.c 2008-05-07 10:45:54 UTC (rev 1128) @@ -199,6 +199,12 @@ updateStatus(); } + /* send pending pongs */ + if (pingCnt && cmds_empty()) + { + pingCnt--; + send_cmd_p(PONG_CMD, pingCnt, 0, 0); + } /* Parse and execute received commands. */ parse_received_cmd(); @@ -282,11 +288,6 @@ } if (gerror) send_cmd_p(GERROR_CMD, TUXCORE_CPU_NUM, gerror, 0); - if (pingCnt) /* send pending pongs */ - { - pingCnt--; - send_cmd_p(PONG_CMD, pingCnt, 0, 0); - } sensorsUpdate |= STATUS_SENT; } |
From: jaguarondi <c2m...@c2...> - 2008-05-07 10:44:55
|
Author: jaguarondi Date: 2008-05-07 12:44:53 +0200 (Wed, 07 May 2008) New Revision: 1127 Modified: firmware/tuxcore/trunk/bootloader.c Log: * Updated with the new defines. Modified: firmware/tuxcore/trunk/bootloader.c =================================================================== --- firmware/tuxcore/trunk/bootloader.c 2008-05-07 10:43:08 UTC (rev 1126) +++ firmware/tuxcore/trunk/bootloader.c 2008-05-07 10:44:53 UTC (rev 1127) @@ -56,7 +56,7 @@ LED_PT |= LED_L_MK; TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ - TWAR = TUXCORE_BL_TWAR; + TWAR = (TUXCORE_BL_ADDR << 1); TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) |
From: jaguarondi <c2m...@c2...> - 2008-05-07 10:43:07
|
Author: jaguarondi Date: 2008-05-07 12:43:08 +0200 (Wed, 07 May 2008) New Revision: 1126 Modified: firmware/tuxcore/trunk/parser.c Log: * bug: LED_PULSE_CMD disappeared in the merge. Modified: firmware/tuxcore/trunk/parser.c =================================================================== --- firmware/tuxcore/trunk/parser.c 2008-05-07 10:09:23 UTC (rev 1125) +++ firmware/tuxcore/trunk/parser.c 2008-05-07 10:43:08 UTC (rev 1126) @@ -148,8 +148,11 @@ { motors_run(cmd[1], cmd[2], cmd[3]); } + else if (cmd[0] == LED_PULSE_CMD) + { + led_pulse(cmd[1], cmd[2], cmd[3]); + } - /* Deprecated functions, though they can be kept for the standalone as * they're simpler than the other LED functions. */ else if (cmd[0] == LED_ON_CMD) |
From: jaguarondi <c2m...@c2...> - 2008-05-07 10:09:26
|
Author: jaguarondi Date: 2008-05-07 12:09:23 +0200 (Wed, 07 May 2008) New Revision: 1125 Modified: firmware/tuxaudio/trunk/misc.c Log: * Author and revision were not sent; cleanup. Modified: firmware/tuxaudio/trunk/misc.c =================================================================== --- firmware/tuxaudio/trunk/misc.c 2008-05-06 17:13:30 UTC (rev 1124) +++ firmware/tuxaudio/trunk/misc.c 2008-05-07 10:09:23 UTC (rev 1125) @@ -48,15 +48,9 @@ /* Retrieve version information */ for (i = 0; i < 12; i++) buf[i] = pgm_read_byte(data++); - cli(); send_status((uint8_t const *) buf); - sei(); - - buf[0] = SOUND_VAR_CMD; - buf[1] = numSound; - buf[2] = last_block; - buf[3] = 0; - cli(); - send_status((uint8_t const *) buf); - sei(); + send_status((uint8_t const *) buf+4); + send_status((uint8_t const *) buf+8); + /* Send extra information */ + send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); } |
From: jaguarondi <c2m...@c2...> - 2008-05-06 17:13:54
|
Author: jaguarondi Date: 2008-05-06 19:13:30 +0200 (Tue, 06 May 2008) New Revision: 1124 Modified: firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/i2c.c firmware/tuxaudio/trunk/i2c.h firmware/tuxaudio/trunk/main.c Log: * I now use an I2C restart between 2 read from tuxcore. * When nacked, the new core_comunications() restart the request. I should still get rid of statusFlag. Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-06 15:56:07 UTC (rev 1123) +++ firmware/tuxaudio/trunk/communication.c 2008-05-06 17:13:30 UTC (rev 1124) @@ -73,20 +73,6 @@ } /* - * I2C communication initalisation - * - * Start the twi interface in the mode defined in i2c.h, set the receiver function and - * the behaviour CPU address. - */ -void i2cCommunicationInit(void) -{ - i2c_init(); - msg_out.addr = TUXCORE_ADDR; - msg_out.buf = out_buf; - i2c_master_receive_handler(i2cMasterReceiveService); -} - -/* * sendCommands takes one command (from 1 to 4 bytes) out of the command stack * and send them by i2c. * @@ -95,50 +81,25 @@ int8_t sendCommands(void) { uint8_t i; - static uint8_t nack_cnt = 0; - if (i2c_get_status() == I2C_BUSY) - return 1; - if (msg_out.state == I2C_NACK) + if (FifoLength(core_cmdout)) + /* Send commands received from RF or testers to tuxcore only. */ { - /* If NACK, try a couple more time. */ - if (++nack_cnt == 4) + msg_out.len = CMD_SIZE; + for (i = 0; i < CMD_SIZE; i++) { - nack_cnt = 0; - switch (msg_out.addr) - { - case TUXCORE_ADDR: - /* Return 0 as if there were nothing to do so we can do - something else. Returning here doesn't drop the message. */ - return 0; - } + if (FifoGet(core_cmdout, &out_buf[i])) + /* Drop the data if the fifo is corrupted (not enough + * bytes) XXX add an error feedback on this */ + return -1; } - else - i2c_send_bytes(&msg_out); - return 2; + msg_out.addr = TUXCORE_ADDR; + i2c_send_bytes(&msg_out); } else - /* Send something else. */ - { - nack_cnt = 0; - if (FifoLength(core_cmdout)) - /* Send commands received from RF or testers to tuxcore only. */ - { - msg_out.len = CMD_SIZE; - for (i = 0; i < CMD_SIZE; i++) - { - if (FifoGet(core_cmdout, &out_buf[i])) - /* Drop the data if the fifo is corrupted (not enough - * bytes) XXX add an error feedback on this */ - return -1; - } - msg_out.addr = TUXCORE_ADDR; - i2c_send_bytes(&msg_out); - } - else - /* Nothing to do anymore */ - return 0; - } + /* Nothing to do anymore */ + return 0; + return 1; } @@ -215,28 +176,30 @@ * Only do a backup of the buffer so any new i2c data won't overwrite the * previous ones */ -void i2cMasterReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) +bool i2cMasterReceiveService(struct i2c_msg *msg) { - if (receiveDataLength != CMD_SIZE) + if (msg->len != CMD_SIZE) /* Error here. */ - return; - if (*receiveData == 0) + return 0; + if (*(msg->buf) == 0) { /* Got nothing so stop reading. */ - statusFlag = 0; - return; + return 0; } - if (msg_in.addr == TUXCORE_ADDR) + if (msg->addr == TUXCORE_ADDR) /* From tuxcore */ { + /* New pointer necessary as parse_cmd modifies the pointer. */ + uint8_t *cmd = msg->buf; /* Parse the command */ - parse_cmd(receiveData); + parse_cmd(cmd); /* and forward if it isn't dropped. */ - if (receiveData) - send_status(receiveData); - /* As we got something, there's maybe more so continue. */ - statusFlag = 1; + if (cmd) + send_status(cmd); + /* As we got something, there's maybe more so continue */ + return 1; } + return 0; } /* @@ -267,9 +230,43 @@ void core_communications(bool tick) { + /* If busy, pass. */ + if (i2c_get_status() == I2C_BUSY) + return; + + /* If nacked, restart. */ + if (msg_out.state == I2C_NACK) + { + i2c_send_bytes(&msg_out); + return; + } + else if (msg_in.state == I2C_NACK) + { + get_core_cmd(); + return; + } + if (!sendCommands()) { - if (statusFlag) + if (tick) + { get_core_cmd(); + statusFlag = 0; + } } } + +/* + * I2C communication initalisation + * + * Start the twi interface in the mode defined in i2c.h, set the receiver function and + * the behaviour CPU address. + */ +void i2cCommunicationInit(void) +{ + i2c_init(); + msg_out.addr = TUXCORE_ADDR; + msg_out.buf = out_buf; + i2c_master_receive_handler(i2cMasterReceiveService); +} + Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2008-05-06 15:56:07 UTC (rev 1123) +++ firmware/tuxaudio/trunk/communication.h 2008-05-06 17:13:30 UTC (rev 1124) @@ -58,7 +58,6 @@ /* From i2c to RF */ void acceptData(void); -void i2cMasterReceiveService(uint8_t receiveDataLength, uint8_t * receiveData); void send_status(uint8_t const *status); void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ uint8_t param3); Modified: firmware/tuxaudio/trunk/i2c.c =================================================================== --- firmware/tuxaudio/trunk/i2c.c 2008-05-06 15:56:07 UTC (rev 1123) +++ firmware/tuxaudio/trunk/i2c.c 2008-05-06 17:13:30 UTC (rev 1124) @@ -84,8 +84,7 @@ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for * writing */ -static void (*i2c_master_receive) (uint8_t receiveDataLength, - uint8_t * recieveData); +static bool (*i2c_master_receive) (struct i2c_msg *msg); /* I2cSlaveTransmit is called when this processor is addressed as a slave for * reading */ static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, @@ -100,9 +99,7 @@ //i2c_resume(); /* Set the user function which handles receiving (incoming) data as a slave */ -void -i2c_master_receive_handler(void (*i2cMasterRx_func) - (uint8_t receiveDataLength, uint8_t * recieveData)) +void i2c_master_receive_handler(bool (*i2cMasterRx_func) (struct i2c_msg *msg)) { i2c_master_receive = i2cMasterRx_func; } @@ -364,8 +361,15 @@ i2c_state = I2C_FULL; m_msg->state = i2c_state; if (i2c_master_receive) - i2c_master_receive(m_msg->len, m_msg->buf); - twi_send_stop(); /* end of data stream */ + { + if (i2c_master_receive(m_msg)) + { + buf_idx = 0; + twi_send_start(); /* restart a read */ + } + else + twi_send_stop(); /* end of data stream */ + } break; case TW_MT_SLA_NACK: /* 0x20 */ /* SLA+W has been transmitted; NOT ACK has been received. */ Modified: firmware/tuxaudio/trunk/i2c.h =================================================================== --- firmware/tuxaudio/trunk/i2c.h 2008-05-06 15:56:07 UTC (rev 1123) +++ firmware/tuxaudio/trunk/i2c.h 2008-05-06 17:13:30 UTC (rev 1124) @@ -22,6 +22,7 @@ #ifndef _I2C_H_ #define _I2C_H_ +#include <stdbool.h> #include <util/twi.h> enum i2c_state @@ -79,10 +80,8 @@ /* Functions */ void i2cInit(void); +void i2c_master_receive_handler(bool (*i2cMasterRx_func) (struct i2c_msg *msg)); void -i2c_master_receive_handler(void (*i2cSlaveRx_func) - (uint8_t receiveDataLength, uint8_t * recieveData)); -void i2cSetSlaveTransmitHandler(uint8_t(*i2cSlaveTx_func) (uint8_t transmitDataLengthMax, uint8_t * transmitData)); Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2008-05-06 15:56:07 UTC (rev 1123) +++ firmware/tuxaudio/trunk/main.c 2008-05-06 17:13:30 UTC (rev 1124) @@ -191,7 +191,7 @@ erase(); /* Send commands to I2C, otherwise get new status from tuxcore */ - core_communications(0); + core_communications(statusFlag); /*else if (sleep_f)*/ /*{*/ /*sleep_f = 0;*/ |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:56:05
|
Author: jaguarondi Date: 2008-05-06 17:56:07 +0200 (Tue, 06 May 2008) New Revision: 1123 Modified: daemon/trunk/libs/USBDaemon_command_tux.c Log: * This command doesn't exist anymore as it was for production only. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2008-05-06 15:54:05 UTC (rev 1122) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2008-05-06 15:56:07 UTC (rev 1123) @@ -540,9 +540,6 @@ case TUX_CMD_STRUCT_SUB_ERASE: ACK = send_usb_tux_cmd(ERASE_FLASH_CMD, 0, 0, 0); break; - case TUX_CMD_STRUCT_SUB_TEST: - ACK = send_usb_tux_cmd(TEST_SOUND_CMD, 0, 0, 0); - break; } break; case TUX_CMD_STRUCT_PING: |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:54:17
|
Author: jaguarondi Date: 2008-05-06 17:54:05 +0200 (Tue, 06 May 2008) New Revision: 1122 Modified: firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h Log: * I2C read was dropped if tuxcore nacked the request. Now the flag is only cleared when an empty command has been received. All pong are now received. Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-06 15:43:40 UTC (rev 1121) +++ firmware/tuxaudio/trunk/communication.c 2008-05-06 15:54:05 UTC (rev 1122) @@ -118,9 +118,9 @@ return 2; } else - nack_cnt = 0; /* Send something else. */ { + nack_cnt = 0; if (FifoLength(core_cmdout)) /* Send commands received from RF or testers to tuxcore only. */ { @@ -142,11 +142,10 @@ return 1; } -void getStatus(void) +void get_core_cmd(void) { if (i2c_get_status() != I2C_BUSY) { - statusFlag = 0; msg_in.addr = TUXCORE_ADDR; msg_in.len = CMD_SIZE; i2c_read_bytes(&msg_in); @@ -218,12 +217,15 @@ */ void i2cMasterReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) { - if (*receiveData == 0) - /* Nothing to get. */ - return; if (receiveDataLength != CMD_SIZE) /* Error here. */ return; + if (*receiveData == 0) + { + /* Got nothing so stop reading. */ + statusFlag = 0; + return; + } if (msg_in.addr == TUXCORE_ADDR) /* From tuxcore */ { @@ -268,6 +270,6 @@ if (!sendCommands()) { if (statusFlag) - getStatus(); + get_core_cmd(); } } Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2008-05-06 15:43:40 UTC (rev 1121) +++ firmware/tuxaudio/trunk/communication.h 2008-05-06 15:54:05 UTC (rev 1122) @@ -63,7 +63,7 @@ void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ uint8_t param3); uint8_t popStatus(uint8_t * command); -void getStatus(void); +void get_core_cmd(void); void core_communications(bool tick); #endif /* COMMUNICATION_H */ |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:43:42
|
Author: jaguarondi Date: 2008-05-06 17:43:40 +0200 (Tue, 06 May 2008) New Revision: 1121 Modified: firmware/tuxaudio/trunk/main.c Log: * I don't know yet where they come from, but there are some empty commands getting through. I filter them in main.c for now. Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2008-05-06 15:18:34 UTC (rev 1120) +++ firmware/tuxaudio/trunk/main.c 2008-05-06 15:43:40 UTC (rev 1121) @@ -175,7 +175,9 @@ { commandRX = 0; // Reset flag parse_cmd(spi_commandRX); - if (spi_commandRX) + /* XXX there are some empty commands getting through, removed from + * here for now. */ + if (spi_commandRX && spi_commandRX[0]) send_core_cmd(spi_commandRX); } |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:19:19
|
Author: jaguarondi Date: 2008-05-06 17:18:34 +0200 (Tue, 06 May 2008) New Revision: 1120 Modified: firmware/tuxaudio/trunk/parser.c Log: * Minor cleanup. Modified: firmware/tuxaudio/trunk/parser.c =================================================================== --- firmware/tuxaudio/trunk/parser.c 2008-05-06 15:10:03 UTC (rev 1119) +++ firmware/tuxaudio/trunk/parser.c 2008-05-06 15:18:34 UTC (rev 1120) @@ -35,8 +35,6 @@ */ void parse_cmd(uint8_t *cmd) { - static uint8_t pong_received; /* value of the pong received from the behavior */ - static uint8_t pong_missed; /* counting the pong missed on the I2C */ /* * Commands that should be forwarded @@ -45,6 +43,10 @@ /* Ping */ if (cmd[0] == PONG_CMD) { + /* Index of the pong that is supposed to be received from tuxcore */ + static uint8_t pong_received; + /* Counter of the missed pongs */ + static uint8_t pong_missed; if (pong_received-- < cmd[1]) /* new ping, reset */ { pong_received = cmd[1]; @@ -59,13 +61,12 @@ } else if (cmd[0] == SLEEP_CMD) { + /* XXX sleep commented for now */ /* Forwards the cmd to the rf CPU */ - cmd[0] = SLEEP_ACK_CMD; - cmd[1] = 0; - cmd[2] = 0; - cmd[3] = 0; - send_status(cmd); - /* XXX sleep commented for now */ + /*cmd[0] = SLEEP_ACK_CMD;*/ + /*cmd[1] = 0;*/ + /*cmd[2] = 0;*/ + /*cmd[3] = 0;*/ /*pre_sleep_delay = 30; [> handle sleep in its own function <]*/ /*sleep_f = 1;*/ /*statusFlag = 1;*/ @@ -119,6 +120,7 @@ else write_toc = 2; } - cmd = NULL; + /* Drop the command */ + cmd = NULL; } } |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:10:45
|
Author: jaguarondi Date: 2008-05-06 17:10:03 +0200 (Tue, 06 May 2008) New Revision: 1119 Modified: firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/parser.c Log: * send_status is called within and outside interrupts so we should disable interrupts when accessing the status fifo. Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-06 15:00:57 UTC (rev 1118) +++ firmware/tuxaudio/trunk/communication.c 2008-05-06 15:10:03 UTC (rev 1119) @@ -191,8 +191,14 @@ uint8_t i; if (FifoLength(statusFifo) <= INCOMING_BUF_SIZE - CMD_SIZE) + { + uint8_t sreg; + sreg = SREG; + cli(); for (i = 0; i < CMD_SIZE; i++) FifoPut(statusFifo, status[i]); + SREG = sreg; + } /* XXX what if stack is full? */ } Modified: firmware/tuxaudio/trunk/parser.c =================================================================== --- firmware/tuxaudio/trunk/parser.c 2008-05-06 15:00:57 UTC (rev 1118) +++ firmware/tuxaudio/trunk/parser.c 2008-05-06 15:10:03 UTC (rev 1119) @@ -64,9 +64,7 @@ cmd[1] = 0; cmd[2] = 0; cmd[3] = 0; - cli(); send_status(cmd); - sei(); /* XXX sleep commented for now */ /*pre_sleep_delay = 30; [> handle sleep in its own function <]*/ /*sleep_f = 1;*/ |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:10:41
|
Author: jaguarondi Date: 2008-05-06 17:00:57 +0200 (Tue, 06 May 2008) New Revision: 1118 Added: firmware/tuxaudio/trunk/misc.c firmware/tuxaudio/trunk/misc.h firmware/tuxaudio/trunk/parser.c firmware/tuxaudio/trunk/parser.h Modified: firmware/tuxaudio/trunk/Makefile firmware/tuxaudio/trunk/bootloader.c firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/hardware.h firmware/tuxaudio/trunk/init.h firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/varis.c firmware/tuxaudio/trunk/varis.h Log: * Added 2 modules: parser and misc. The parser functions spread in main.c and communication.c are now merged into one function in parser.c. All commands coming from the RF and tuxcore will be parsed by the same function now. * Moved some functions around and some cleanup. Modified: firmware/tuxaudio/trunk/Makefile =================================================================== --- firmware/tuxaudio/trunk/Makefile 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/Makefile 2008-05-06 15:00:57 UTC (rev 1118) @@ -69,7 +69,7 @@ ## Objects that must be built in order to link -OBJECTS = init.o main.o varis.o fifo.o spi.o AT26F004.o flash.o communication.o PC_communication.o i2c.o config.o +OBJECTS = init.o main.o varis.o fifo.o spi.o AT26F004.o flash.o communication.o parser.o misc.o PC_communication.o i2c.o config.o ## Objects explicitly added by the user LINKONLYOBJECTS = @@ -103,6 +103,12 @@ communication.o: communication.c $(CC) $(INCLUDES) $(CFLAGS) -c $< +parser.o: parser.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +misc.o: misc.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + PC_communication.o: PC_communication.c $(CC) $(INCLUDES) $(CFLAGS) -c $< Modified: firmware/tuxaudio/trunk/bootloader.c =================================================================== --- firmware/tuxaudio/trunk/bootloader.c 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/bootloader.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -54,7 +54,7 @@ jump_to_application(); TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ - TWAR = TUXAUDIO_BL_TWAR; + TWAR = (TUXAUDIO_BL_ADDR << 1); TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/communication.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -24,20 +24,20 @@ #include "communication.h" #include "i2c.h" -#include "hardware.h" -#include "config.h" +#include "parser.h" -#define I2C_TUXCORE_ADDR 0x2A - +/* I2C write message (out) */ static uint8_t out_buf[CMD_SIZE]; static struct i2c_msg msg_out = {0, 0, out_buf}; +/* I2C read message (in) */ static uint8_t in_buf[CMD_SIZE]; static struct i2c_msg msg_in = {0, 0, in_buf}; -volatile uint8_t ret; + +/* XXX to delete */ uint8_t statusFlag; /* - * core_cmdout is a buffer for commands to be sent to tuxcore + * core_cmdout is a stack for commands to be sent to tuxcore */ FIFO_INSTANCE(core_cmdout_buf, COMMAND_BUF_SIZE); fifo_t *core_cmdout = FifoPointer(core_cmdout_buf); @@ -81,7 +81,7 @@ void i2cCommunicationInit(void) { i2c_init(); - msg_out.addr = I2C_TUXCORE_ADDR; + msg_out.addr = TUXCORE_ADDR; msg_out.buf = out_buf; i2c_master_receive_handler(i2cMasterReceiveService); } @@ -107,7 +107,7 @@ nack_cnt = 0; switch (msg_out.addr) { - case I2C_TUXCORE_ADDR: + case TUXCORE_ADDR: /* Return 0 as if there were nothing to do so we can do something else. Returning here doesn't drop the message. */ return 0; @@ -132,8 +132,8 @@ * bytes) XXX add an error feedback on this */ return -1; } - msg_out.addr = I2C_TUXCORE_ADDR; - ret = i2c_send_bytes(&msg_out); + msg_out.addr = TUXCORE_ADDR; + i2c_send_bytes(&msg_out); } else /* Nothing to do anymore */ @@ -147,9 +147,9 @@ if (i2c_get_status() != I2C_BUSY) { statusFlag = 0; - msg_in.addr = I2C_TUXCORE_ADDR; + msg_in.addr = TUXCORE_ADDR; msg_in.len = CMD_SIZE; - ret = i2c_read_bytes(&msg_in); + i2c_read_bytes(&msg_in); } } @@ -204,44 +204,6 @@ send_status(c); } -uint8_t pong_received; /* value of the pong received from the behavior */ -uint8_t pong_missed; /* counting the pong missed on the I2C */ - -void parse_core_cmd(uint8_t *data) -{ - uint8_t i; - - if (*data < 0xC0) - /* Audio command to be executed, can't have 3 parameters */ - { - for (i = 0; i < CMD_SIZE; i++) - audioBuf[i] = data[i]; - audioBufIdx = CMD_SIZE; - /* XXX only fill buffer if it's not full, need to add the check */ - } - else - /* Status, forward to RF and testers */ - { - /* Intercept some of them */ - /* Pong check */ - if (data[0] == PONG_CMD) - { - if (pong_received-- < data[1]) /* new ping, reset */ - { - pong_received = data[1]; - pong_missed = 0; - } - else if (pong_received > data[1]) /* pongs missed */ - { - pong_missed++; - pong_received = data[1]; /* resync */ - } - data[2] = pong_missed; - } - send_status(data); - } -} - /* * Slave receiver function associated with the i2c ISR * @@ -256,12 +218,15 @@ if (receiveDataLength != CMD_SIZE) /* Error here. */ return; - if (msg_in.addr == I2C_TUXCORE_ADDR) + if (msg_in.addr == TUXCORE_ADDR) /* From tuxcore */ { - /* Parse commands */ - parse_core_cmd(receiveData); - /* If we got something, there's maybe more so continue. */ + /* Parse the command */ + parse_cmd(receiveData); + /* and forward if it isn't dropped. */ + if (receiveData) + send_status(receiveData); + /* As we got something, there's maybe more so continue. */ statusFlag = 1; } } @@ -291,3 +256,12 @@ sei(); return 0; } + +void core_communications(bool tick) +{ + if (!sendCommands()) + { + if (statusFlag) + getStatus(); + } +} Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/communication.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -64,5 +64,6 @@ uint8_t param3); uint8_t popStatus(uint8_t * command); void getStatus(void); +void core_communications(bool tick); #endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/flash.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -232,7 +232,6 @@ programming_state = 0; programmingFlash = 0; TIMSK0 = 0x01; - //info_flg = 1; send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); } @@ -296,7 +295,6 @@ last_block = 0; send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); - //info_flg = 1; TIMSK0 = 0x01; } } Modified: firmware/tuxaudio/trunk/hardware.h =================================================================== --- firmware/tuxaudio/trunk/hardware.h 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/hardware.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -52,4 +52,29 @@ #define flash_onhold() (FLASH_PORT &= ~FLASH_HOLD_PIN) #define flash_enable() (FLASH_PORT |= FLASH_HOLD_PIN) +/* Power management */ +#define POWER_DDR DDRD /* VCC power switch */ +#define POWER_MK _BV(PD6) +#define POWER_PT PORTD + +/* Audio mute */ +#define MUTE_DDR DDRD /* amp _SHDN pin */ +#define MUTE_MK _BV(PD7) +#define MUTE_PT PORTD + +#define AUDIO_OUT_DDR DDRD /* PWM output compare pin */ +#define AUDIO_OUT_MK _BV(PD5) +#define AUDIO_OUT_PT PORTD + +static __inline__ void unmute_amp(void) +{ + (MUTE_PT |= MUTE_MK); + (AUDIO_OUT_DDR |= AUDIO_OUT_MK); +} +static __inline__ void mute_amp(void) +{ + (MUTE_PT &= ~MUTE_MK); + (AUDIO_OUT_DDR &= ~AUDIO_OUT_MK); +} + #endif /* _HARDWARE_H_ */ Modified: firmware/tuxaudio/trunk/init.h =================================================================== --- firmware/tuxaudio/trunk/init.h 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/init.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -24,29 +24,5 @@ extern void init_avr(void); -/* Power management */ -#define POWER_DDR DDRD /* VCC power switch */ -#define POWER_MK _BV(PD6) -#define POWER_PT PORTD -/* Audio mute */ -#define MUTE_DDR DDRD /* amp _SHDN pin */ -#define MUTE_MK _BV(PD7) -#define MUTE_PT PORTD - -#define AUDIO_OUT_DDR DDRD /* PWM output compare pin */ -#define AUDIO_OUT_MK _BV(PD5) -#define AUDIO_OUT_PT PORTD - -static __inline__ void unmute_amp(void) -{ - (MUTE_PT |= MUTE_MK); - (AUDIO_OUT_DDR |= AUDIO_OUT_MK); -} -static __inline__ void mute_amp(void) -{ - (MUTE_PT &= ~MUTE_MK); - (AUDIO_OUT_DDR &= ~AUDIO_OUT_MK); -} - #endif Modified: firmware/tuxaudio/trunk/main.c =================================================================== --- firmware/tuxaudio/trunk/main.c 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/main.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -21,7 +21,6 @@ #include <avr/io.h> #include <avr/interrupt.h> -#include <avr/pgmspace.h> #include <util/delay.h> #include <avr/sleep.h> @@ -34,8 +33,8 @@ #include "fifo.h" #include "i2c.h" #include "communication.h" +#include "parser.h" #include "flash.h" -#include "version.h" #include "config.h" #include "PC_communication.h" @@ -44,43 +43,10 @@ */ #include "AT26F004.h" -/* - * Version number - */ -#define CPU_NUMBER TUXAUDIO_CPU_NUM /* audio CPU */ -const author_t author __attribute__ ((section("version.3"))) = -{AUTHOR_CMD, AUTHOR_ID, VARIATION}; -const revision_t svn_revision __attribute__ ((section("version.2"))) = -{REVISION_CMD, SVN_REV, RELEASE_TYPE}; -const version_t tag_version __attribute__ ((section("version.1"))) = -{VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; - /* Set when sleep should be entered */ -static uint8_t pre_sleep_delay = 0, sleep_f = 0; +static uint8_t pre_sleep_delay = 0; -void send_info(void) -{ - uint8_t i, buf[12]; - uint8_t *data = ((uint8_t *) & tag_version); - - /* Retrieve version information */ - for (i = 0; i < 12; i++) - buf[i] = pgm_read_byte(data++); - cli(); - send_status((uint8_t const *) buf); - sei(); - - buf[0] = SOUND_VAR_CMD; - buf[1] = numSound; - buf[2] = last_block; - buf[3] = 0; - cli(); - send_status((uint8_t const *) buf); - sei(); - info_flg = 0; -} - ISR(SIG_PIN_CHANGE1) { /* Nothing to do here, it's just an interrupt set on the head button to @@ -151,88 +117,6 @@ } #endif -/* - * Parse commands received by the twi interface and trigger the associated - * functions or send status bytes to the RF interface - * - * audioBufIdx is reset at the end of this function which means the buffer - * will be overwritten. So it is necessary to process or backup the data in - * this function. - */ -void audioIntParser(void) -{ - if (audioBuf[0] == PLAY_SOUND_CMD) - /* param: audioBuf[1] : sound number */ - /* audioBuf[2] : mic sound intensity */ - { - /* postpone the command if a sound is already playing */ - if (flashPlay || programmingFlash) - return; - audioLevel = audioBuf[2]; - //playingAudio(audioBuf[1]); /* start playing the sound */ - soundToPlay = audioBuf[1]; - send_status_p(STATUS_AUDIO_CMD, audioBuf[1], 0, 0); - flashPlay = 1; - flash_state = 1; - } - else if (audioBuf[0] == MUTE_CMD) - { - if (audioBuf[1]) - mute_amp(); - else - unmute_amp(); - } - else if (audioBuf[0] == SLEEP_CMD) - { - pre_sleep_delay = 30; /* handle sleep in its own function */ - /* Forwards the command to the rf CPU */ - audioBuf[0] = SLEEP_ACK_CMD; - audioBuf[1] = 0; - audioBuf[2] = 0; - audioBuf[3] = 0; - cli(); - send_status(audioBuf); - sei(); - sleep_f = 1; - statusFlag = 1; - } - audioBufIdx = 0; /* clear buffer; this buffer can only hold one command so should be simply reset here */ -} - -/* - * Directly parse some commands received by the RF interface and push the - * others on the commandFifo to be sent through i2c to the behavioural CPU - */ -void commandParser(uint8_t * command) -{ - if (command[0] == STORE_SOUND_CMD) - { - if (flashPlay) - flashPlay = 0; - flash_state = 1; /* Erasing flash flag */ - programmingFlash = 1; /* Set the flag to enter programming sequence */ - } - else if (command[0] == ERASE_FLASH_CMD) - { - eraseFlag = 1; - } - - /* Version */ - else if (command[0] == INFO_TUXAUDIO_CMD) - info_flg = 1; /* info should be sent when the buffer will be free */ - - else if (command[0] == CONFIRM_STORAGE_CMD) - { - if (command[1]) - write_toc = 1; - else - write_toc = 2; - } - - else - send_core_cmd(command); /* push the command set on the filo stack */ -} - /** * \brief Send sensors status * @@ -270,10 +154,6 @@ sei(); /* Init global interrupt */ - /* Send CPU information at startup */ - /* XXX doesn't seem to work anymore */ - spi_commandRX[0] = INFO_TUXAUDIO_CMD; - commandParser(spi_commandRX); /* Activate INTO and INT1 only if the RF board is present, this is for * production tests only. @@ -294,7 +174,9 @@ if (commandRX) // commend RX from radio { commandRX = 0; // Reset flag - commandParser(spi_commandRX); // Analyse command RX + parse_cmd(spi_commandRX); + if (spi_commandRX) + send_core_cmd(spi_commandRX); } if (programmingFlash) // Restora all the context for flash programming @@ -307,16 +189,12 @@ erase(); /* Send commands to I2C, otherwise get new status from tuxcore */ - if (!sendCommands()) - { - if (statusFlag) - getStatus(); - else if (sleep_f) - { - sleep_f = 0; - sleep(); - } - } + core_communications(0); + /*else if (sleep_f)*/ + /*{*/ + /*sleep_f = 0;*/ + /*sleep();*/ + /*}*/ if (sendSensorsFlag) { @@ -335,6 +213,7 @@ /* wait for audio commands to be processed */ //if (!audioBufIdx && !flashPlay) + /* Main tick to retrieve status */ statusFlag = 1; /* Delay used to power the IR receiver slowly */ @@ -354,14 +233,7 @@ DDRD &= ~0x03; } } - if (audioBufIdx) - audioIntParser(); - - /* Send information to the computer. */ - if (info_flg) - send_info(); - /* Sleep mode */ if (pre_sleep_delay == 1) sleep(); Added: firmware/tuxaudio/trunk/misc.c =================================================================== --- firmware/tuxaudio/trunk/misc.c (rev 0) +++ firmware/tuxaudio/trunk/misc.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -0,0 +1,62 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +#include <avr/pgmspace.h> +#include <avr/interrupt.h> + +#include "misc.h" +#include "communication.h" +#include "version.h" + +/* + * Version number + */ +#define CPU_NUMBER TUXAUDIO_CPU_NUM /* audio CPU */ +const author_t author __attribute__ ((section("version.3"))) = +{AUTHOR_CMD, AUTHOR_ID, VARIATION}; +const revision_t svn_revision __attribute__ ((section("version.2"))) = +{REVISION_CMD, SVN_REV, RELEASE_TYPE}; +const version_t tag_version __attribute__ ((section("version.1"))) = +{VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; + +/** + * Send version information. + */ +void send_info(void) +{ + uint8_t i, buf[12]; + uint8_t *data = ((uint8_t *) & tag_version); + + /* Retrieve version information */ + for (i = 0; i < 12; i++) + buf[i] = pgm_read_byte(data++); + cli(); + send_status((uint8_t const *) buf); + sei(); + + buf[0] = SOUND_VAR_CMD; + buf[1] = numSound; + buf[2] = last_block; + buf[3] = 0; + cli(); + send_status((uint8_t const *) buf); + sei(); +} Property changes on: firmware/tuxaudio/trunk/misc.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxaudio/trunk/misc.h =================================================================== --- firmware/tuxaudio/trunk/misc.h (rev 0) +++ firmware/tuxaudio/trunk/misc.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -0,0 +1,27 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +#ifndef MISC_H +#define MISC_H + +void send_info(void); + +#endif /* MISC_H */ Property changes on: firmware/tuxaudio/trunk/misc.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxaudio/trunk/parser.c =================================================================== --- firmware/tuxaudio/trunk/parser.c (rev 0) +++ firmware/tuxaudio/trunk/parser.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -0,0 +1,126 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +#include <stddef.h> +#include <avr/interrupt.h> + +#include "parser.h" +#include "communication.h" +#include "hardware.h" +#include "misc.h" +#include "varis.h" /* XXX remove this one */ +#include "flash.h" /* XXX remove this one */ + +/** + * Parse a cmd received by the computer or by tuxcore and drop it if it + * shouldn't be forwarded. + */ +void parse_cmd(uint8_t *cmd) +{ + static uint8_t pong_received; /* value of the pong received from the behavior */ + static uint8_t pong_missed; /* counting the pong missed on the I2C */ + + /* + * Commands that should be forwarded + */ + + /* Ping */ + if (cmd[0] == PONG_CMD) + { + if (pong_received-- < cmd[1]) /* new ping, reset */ + { + pong_received = cmd[1]; + pong_missed = 0; + } + else if (pong_received > cmd[1]) /* pongs missed */ + { + pong_missed += pong_received - cmd[1]; + pong_received = cmd[1]; /* resync */ + } + cmd[2] = pong_missed; + } + else if (cmd[0] == SLEEP_CMD) + { + /* Forwards the cmd to the rf CPU */ + cmd[0] = SLEEP_ACK_CMD; + cmd[1] = 0; + cmd[2] = 0; + cmd[3] = 0; + cli(); + send_status(cmd); + sei(); + /* XXX sleep commented for now */ + /*pre_sleep_delay = 30; [> handle sleep in its own function <]*/ + /*sleep_f = 1;*/ + /*statusFlag = 1;*/ + } + else + { + /* + * Commands that shouldn't be forwarded. + */ + /* Version */ + if (cmd[0] == INFO_TUXAUDIO_CMD) + { + send_info(); + } + else if (cmd[0] == PLAY_SOUND_CMD) + /* param: cmd[1] : sound number */ + /* cmd[2] : mic sound intensity */ + { + /* postpone the cmd if a sound is already playing */ + if (flashPlay || programmingFlash) + return; + audioLevel = cmd[2]; + //playingAudio(cmd[1]); /* start playing the sound */ + soundToPlay = cmd[1]; + send_status_p(STATUS_AUDIO_CMD, cmd[1], 0, 0); + flashPlay = 1; + flash_state = 1; + } + else if (cmd[0] == MUTE_CMD) + { + if (cmd[1]) + mute_amp(); + else + unmute_amp(); + } + else if (cmd[0] == STORE_SOUND_CMD) + { + if (flashPlay) + flashPlay = 0; + flash_state = 1; /* Erasing flash flag */ + programmingFlash = 1; /* Set the flag to enter programming sequence */ + } + else if (cmd[0] == ERASE_FLASH_CMD) + { + eraseFlag = 1; + } + else if (cmd[0] == CONFIRM_STORAGE_CMD) + { + if (cmd[1]) + write_toc = 1; + else + write_toc = 2; + } + cmd = NULL; + } +} Property changes on: firmware/tuxaudio/trunk/parser.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/tuxaudio/trunk/parser.h =================================================================== --- firmware/tuxaudio/trunk/parser.h (rev 0) +++ firmware/tuxaudio/trunk/parser.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -0,0 +1,29 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +#ifndef PARSER_H +#define PARSER_H + +#include <stdbool.h> + +void parse_cmd(uint8_t *cmd); + +#endif /* PARSER_H */ Property changes on: firmware/tuxaudio/trunk/parser.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: firmware/tuxaudio/trunk/varis.c =================================================================== --- firmware/tuxaudio/trunk/varis.c 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/varis.c 2008-05-06 15:00:57 UTC (rev 1118) @@ -77,5 +77,4 @@ uint8_t last_block = 0; // General flags -uint8_t info_flg = 0; /* indicates if version information should be sent */ uint8_t write_toc = 0; Modified: firmware/tuxaudio/trunk/varis.h =================================================================== --- firmware/tuxaudio/trunk/varis.h 2008-05-06 14:56:11 UTC (rev 1117) +++ firmware/tuxaudio/trunk/varis.h 2008-05-06 15:00:57 UTC (rev 1118) @@ -87,6 +87,5 @@ extern uint8_t last_block; // General flags -extern uint8_t info_flg; extern uint8_t write_toc; #endif |
From: jaguarondi <c2m...@c2...> - 2008-05-06 15:06:16
|
Author: jaguarondi Date: 2008-05-06 16:56:11 +0200 (Tue, 06 May 2008) New Revision: 1117 Modified: firmware/tuxdefs/defines.h Log: * Added the I2C address of tuxcore. Modified: firmware/tuxdefs/defines.h =================================================================== --- firmware/tuxdefs/defines.h 2008-05-06 14:55:18 UTC (rev 1116) +++ firmware/tuxdefs/defines.h 2008-05-06 14:56:11 UTC (rev 1117) @@ -68,7 +68,8 @@ * I2C addresses of all CPUs. * * tuxcore, tuxaudio, tuxrf and fuxrf have different I2C addresses when they're - * running in normal or bootloader mode. + * running in bootloader mode (BL). In normal mode, only tuxcore has an I2C + * address as tuxaudio is master. */ enum I2C_ADDRESSES { @@ -76,11 +77,7 @@ TUXAUDIO_BL_ADDR = 0X31, TUXRF_BL_ADDR = 0X32, FUXRF_BL_ADDR = 0X33, - /* XXX we should remove these TWAR stuff from here */ - TUXCORE_BL_TWAR = (TUXCORE_BL_ADDR << 1), - TUXAUDIO_BL_TWAR = (TUXAUDIO_BL_ADDR << 1), - TUXRF_BL_TWAR = (TUXRF_BL_ADDR << 1), - FUXRF_BL_TWAR = (FUXRF_BL_ADDR << 1), + TUXCORE_ADDR = 0x2A, }; /*! @} */ |
From: jaguarondi <c2m...@c2...> - 2008-05-06 14:55:26
|
Author: jaguarondi Date: 2008-05-06 16:55:18 +0200 (Tue, 06 May 2008) New Revision: 1116 Modified: daemon/trunk/libs/USBDaemon_status_table.c Log: * Added debug of the ping/pong command. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2008-05-06 11:33:40 UTC (rev 1115) +++ daemon/trunk/libs/USBDaemon_status_table.c 2008-05-06 14:55:18 UTC (rev 1116) @@ -755,6 +755,9 @@ case PONG_CMD: pong_received++; pong_event(new_status[1], pong_received); + log_debug("pong %d %d %d %d", new_status[1], new_status[2], + new_status[3], pong_received ); + break; case VERSION_CMD: |
From: Paul_R <c2m...@c2...> - 2008-05-06 11:33:39
|
Author: Paul_R Date: 2008-05-06 13:33:40 +0200 (Tue, 06 May 2008) New Revision: 1115 Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 firmware/fuxusb/branches/usb_cleanup/global.c firmware/fuxusb/branches/usb_cleanup/global.h firmware/fuxusb/branches/usb_cleanup/lib_mcu/uart/tools/c51_bdr.c firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo.c firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.c firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.h firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.c firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.h firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.c firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.h firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.c firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.h firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c firmware/fuxusb/branches/usb_cleanup/spi/spi_task.h firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c firmware/fuxusb/branches/usb_cleanup/usb/usb_enum.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Replaced all unsigned int/char by uint16/8_t Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -57,7 +57,7 @@ i2cSendDataLength = dataLength + 2; #ifdef BOOTLOAD_DEBUG { - unsigned char i; + uint8_t i; printf("I2C: Page 0x%BX%BX:\n", i2cSendData[0], i2cSendData[1]); for (i=2; i<i2cSendDataLength; i++) printf("%BX", i2cSendData[i]); Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 =================================================================== --- firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 11:33:40 UTC (rev 1115) @@ -55,7 +55,7 @@ EnvLib () EnvReg () OrgReg () - TgStat=0 + TgStat=9 OutDir (.\obj\) OutName (fuxusb.aof) GenApp=1 Modified: firmware/fuxusb/branches/usb_cleanup/global.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/global.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/global.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -13,6 +13,7 @@ #include "global.h" #include "version.h" +#include "lib_c/stdint.h" /*_____ M A C R O S ________________________________________________________*/ @@ -29,23 +30,23 @@ //------------------------------------------------------- // USB Controler //------------------------------------------------------- -unsigned int usb_sof_counter; -unsigned char usb_configuration_nb; -bit usb_connected_Flag; +uint16_t usb_sof_counter; +uint8_t usb_configuration_nb; +bit usb_connected_Flag; -bit CMD_OUT_Bank_Nb; // To store the number of the Bank used for the CMD_OUT Endpoint -unsigned char CMD_IN_Bank_Nb; +bit CMD_OUT_Bank_Nb; // To store the number of the Bank used for the CMD_OUT Endpoint +uint8_t CMD_IN_Bank_Nb; -bit USB_ParserProcess_Permit_Flag; -bit USB_StatusProcess_Permit_Flag; -bit USB_Status_NewCmd_Flag; -bit USB_Bootloader_NewCmd_Flag; +bit USB_ParserProcess_Permit_Flag; +bit USB_StatusProcess_Permit_Flag; +bit USB_Status_NewCmd_Flag; +bit USB_Bootloader_NewCmd_Flag; //------------------------------------------------------- // I2C Controler //------------------------------------------------------- -unsigned char i2c_wait_counter = 0; -bit i2c_task_on_Flag; +uint8_t i2c_wait_counter = 0; +bit i2c_task_on_Flag; //------------------------------------------------------- // RF Controler @@ -59,11 +60,11 @@ //------------------------------------------------------- -bit RF_OFFLine_Back; -unsigned char RF_Status; -unsigned char RF_Status_Temp; +bit RF_OFFLine_Back; +uint8_t RF_Status; +uint8_t RF_Status_Temp; -unsigned int spi_watchdog_ctr; +uint16_t spi_watchdog_ctr; //------------------------------------------------------- // Tux Command and Status @@ -71,11 +72,11 @@ // From USB //------------------------------------------------------- -unsigned char USBCommand_ForDongle[65]; // For Dongle -unsigned char USBCommand_ForRF[65]; // For RF -unsigned char USBCommand_Ctr; // Store the number of byte sent by the LIBUSB -bit USBCommand_NewRequest_Flag; -unsigned char USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C +uint8_t USBCommand_ForDongle[65]; // For Dongle +uint8_t USBCommand_ForRF[65]; // For RF +uint8_t USBCommand_Ctr; // Store the number of byte sent by the LIBUSB +bit USBCommand_NewRequest_Flag; +uint8_t USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C #define LIBUSB_TUX_CMD_HDR 0 #define LIBUSB_DONGLE_CMD_HDR 1 Modified: firmware/fuxusb/branches/usb_cleanup/global.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/global.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/global.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -14,12 +14,14 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ - +#include "lib_c/stdint.h" #include "common\api.h" #include "common\defines.h" #include "common\commands.h" /*_____ M A C R O S ________________________________________________________*/ +//#define uin8_t unsigned char +//#define uint16_t unsigned int /*_____ D E F I N I T I O N ________________________________________________*/ @@ -30,25 +32,25 @@ /*_____ D E C L A R A T I O N ______________________________________________*/ -extern unsigned int Sleep_Ctr; +extern uint16_t Sleep_Ctr; //------------------------------------------------------- // SPI Controler //------------------------------------------------------- extern bit spi_task_on_Flag; // = 1; // to turn ON the RF Task // = 0; // to turn OFF the RF Task -extern unsigned int spi_watchdog_ctr; +extern uint16_t spi_watchdog_ctr; #define SPI_WATCHDOG_MAX (6000) //------------------------------------------------------- // USB Controler //------------------------------------------------------- -extern unsigned int usb_sof_counter; -extern unsigned char usb_configuration_nb; +extern uint16_t usb_sof_counter; +extern uint8_t usb_configuration_nb; extern bit usb_connected_Flag; extern bit CMD_OUT_Bank_Nb;// To store the number of the Bank used for the CMD_OUT Endpoint -extern unsigned char CMD_IN_Bank_Nb; +extern uint8_t CMD_IN_Bank_Nb; extern bit USB_ParserProcess_Permit_Flag; extern bit USB_StatusProcess_Permit_Flag; @@ -59,7 +61,7 @@ // I2C Controler //------------------------------------------------------- -extern unsigned char i2c_wait_counter; +extern uint8_t i2c_wait_counter; extern bit i2c_task_on_Flag; //------------------------------------------------------- @@ -75,8 +77,8 @@ //------------------------------------------------------- extern bit RF_OFFLine_Back; -extern unsigned char RF_Status; -extern unsigned char RF_Status_Temp; +extern uint8_t RF_Status; +extern uint8_t RF_Status_Temp; //------------------------------------------------------- // Tux Command and Status @@ -86,12 +88,12 @@ // From USB //------------------------------------------------------- -extern unsigned char USBCommand_ForRF[]; // Store the USB Command -extern unsigned char USBCommand_ForDongle[]; // For Dongle -extern unsigned char USBCommand_Ctr; // Store the number of byte sent by the LIBUSB +extern uint8_t USBCommand_ForRF[]; // Store the USB Command +extern uint8_t USBCommand_ForDongle[]; // For Dongle +extern uint8_t USBCommand_Ctr; // Store the number of byte sent by the LIBUSB extern bit USBCommand_NewRequest_Flag; -extern unsigned char USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C +extern uint8_t USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C #define LIBUSB_TUX_CMD_HDR 0 Modified: firmware/fuxusb/branches/usb_cleanup/lib_mcu/uart/tools/c51_bdr.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/lib_mcu/uart/tools/c51_bdr.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/lib_mcu/uart/tools/c51_bdr.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -57,7 +57,7 @@ 1843200, 0 }; -unsigned int fosc; +uint16_t fosc; int bdr (int prescaler, int max, int val) { Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -152,7 +152,7 @@ */ void adaptFifo(fifo_t *p) { - unsigned char fifoSize, index; + uint8_t fifoSize, index; /* check if outIdx equals FIFO_ADAPT_RATE or any of its mutliples */ index = p->outIdx & (FIFO_ADAPT_RATE*2 - 1); /* clear all bits above FIFO_ADAPT_RATE */ Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -25,12 +25,12 @@ #define FIFO_MIC_READY_VALUE 128 -unsigned char FifoTbl_MIC[FIFOTBL_MIC_MAX]; +uint8_t FifoTbl_MIC[FIFOTBL_MIC_MAX]; -unsigned char FifoIn_MIC_Idx; -unsigned char FifoOut_MIC_Idx; +uint8_t FifoIn_MIC_Idx; +uint8_t FifoOut_MIC_Idx; -unsigned char FifoOut_MIC_cmpt; +uint8_t FifoOut_MIC_cmpt; bit Fifoready_MIC = 0; @@ -54,7 +54,7 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -void FIFO_MIC_put (unsigned char Data) +void FIFO_MIC_put (uint8_t Data) { FifoOut_MIC_cmpt++; @@ -82,9 +82,9 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -unsigned char FIFO_MIC_get (void) +uint8_t FIFO_MIC_get (void) { - unsigned char Data; + uint8_t Data; if (FifoOut_MIC_cmpt == 0) Fifoready_MIC = 0; // FIFO empty Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_mic.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -15,7 +15,7 @@ extern void FIFO_MIC_init (void); -extern void FIFO_MIC_put (unsigned char Data); -extern unsigned char FIFO_MIC_get (void); +extern void FIFO_MIC_put (uint8_t Data); +extern uint8_t FIFO_MIC_get (void); #endif /*_FIFO_MIC_H_*/ Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -16,15 +16,15 @@ #include "usb\usb_drv.h" -unsigned char FifoTbl_SPK[FIFOTBL_SPK_MAX]; +uint8_t FifoTbl_SPK[FIFOTBL_SPK_MAX]; -unsigned char FifoIn_SPK_Idx; -unsigned char FifoOut_SPK_Idx; +uint8_t FifoIn_SPK_Idx; +uint8_t FifoOut_SPK_Idx; -unsigned char FifoOut_SPK_cmpt; +uint8_t FifoOut_SPK_cmpt; bit Fifoready_SPK = 0; -unsigned char FIFO_i; +uint8_t FIFO_i; //------------------------------------------------------------------------ // Fifo Manager @@ -86,7 +86,7 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -void FIFO_SPK_put (unsigned char Data) +void FIFO_SPK_put (uint8_t Data) { Uchar FilterByte; FifoOut_SPK_cmpt++; @@ -117,9 +117,9 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -unsigned char FIFO_SPK_get (void) +uint8_t FIFO_SPK_get (void) { - unsigned char Data; + uint8_t Data; if (FifoOut_SPK_cmpt < FIFO_SPK_READY_VALUE_MIN) Fifoready_SPK = 0; // FIFO empty Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo/fifo_spk.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -21,20 +21,20 @@ #define FIFO_SPK_READY_VALUE_MAX 32 #define FIFO_SPK_READY_VALUE_MIN 16 -extern unsigned char FifoTbl_SPK[FIFOTBL_SPK_MAX]; +extern uint8_t FifoTbl_SPK[FIFOTBL_SPK_MAX]; -extern unsigned char FifoIn_SPK_Idx; -extern unsigned char FifoOut_SPK_Idx; +extern uint8_t FifoIn_SPK_Idx; +extern uint8_t FifoOut_SPK_Idx; -extern unsigned char FifoOut_SPK_cmpt; +extern uint8_t FifoOut_SPK_cmpt; extern bit Fifoready_SPK; -extern unsigned char FIFO_i; +extern uint8_t FIFO_i; extern void FIFO_SPK_init (void); -extern void FIFO_SPK_put (unsigned char Data); +extern void FIFO_SPK_put (uint8_t Data); extern void FIFO_SPK_put8 (void); -extern unsigned char FIFO_SPK_get (void); +extern uint8_t FIFO_SPK_get (void); #endif /* _FIFO_SPK_H_*/ Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -16,12 +16,12 @@ #include "usb\usb_drv.h" -unsigned char FifoTbl_Stt[FIFOTBL_STT_MAX]; +uint8_t FifoTbl_Stt[FIFOTBL_STT_MAX]; -unsigned char FifoIn_STT_Idx; -unsigned char FifoOut_STT_Idx; +uint8_t FifoIn_STT_Idx; +uint8_t FifoOut_STT_Idx; -unsigned char FifoOut_STT_cmpt; +uint8_t FifoOut_STT_cmpt; bit FifoOverLoad_STT = 0; @@ -30,7 +30,7 @@ // Fifo_isFull // //------------------------------------------------------------------------ -unsigned char FIFO_isFull() +uint8_t FIFO_isFull() { return (FifoOverLoad_STT); @@ -67,7 +67,7 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -void FIFO_STT_put (unsigned char Data) +void FIFO_STT_put (uint8_t Data) { if(FifoOverLoad_STT) { @@ -89,9 +89,9 @@ // //------------------------------------------------------------------------ //#pragma ot(4, SPEED) -unsigned char FIFO_STT_get (void) +uint8_t FIFO_STT_get (void) { - unsigned char Data; + uint8_t Data; Data = FifoTbl_STT[FifoOut_STT_Idx]; FifoOut_STT_Idx++; Modified: firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/modules/fifo_stt/fifo_stt.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -19,19 +19,19 @@ -extern unsigned char FifoTbl_STT[FIFOTBL_STT_MAX]; +extern uint8_t FifoTbl_STT[FIFOTBL_STT_MAX]; -extern unsigned char FifoIn_STT_Idx; -extern unsigned char FifoOut_STT_Idx; +extern uint8_t FifoIn_STT_Idx; +extern uint8_t FifoOut_STT_Idx; -extern unsigned char FifoOut_STT_cmpt; +extern uint8_t FifoOut_STT_cmpt; extern bit FifoOverLoad_STT; -extern unsigned char FIFO_isFull(void); +extern uint8_t FIFO_isFull(void); extern void FIFO_STT_flush (void); extern void FIFO_STT_init (void); -extern void FIFO_STT_put (unsigned char Data); -extern unsigned char FIFO_STT_get (void); +extern void FIFO_STT_put (uint8_t Data); +extern uint8_t FIFO_STT_get (void); #endif /*_FIFO_STT_H_*/ Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -44,7 +44,7 @@ *****************************************************************************/ -unsigned char spi_SendByte(Uchar Data) +uint8_t spi_SendByte(Uchar Data) { SPDAT = Data; while(!(SPSTA&0x80)); Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/spi/spi_lib.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -26,6 +26,6 @@ /*_____ P R O T O T Y P E S ____________________________________________________________*/ extern void spi_init(void); -extern unsigned char spi_SendByte(Uchar Data); +extern uint8_t spi_SendByte(Uchar Data); #endif Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -31,16 +31,16 @@ data STM_SPI_MASTER_SLAVE_TYPE spi_slave; data STM_SPI_SLAVE_MASTER_TYPE spi_master; -data unsigned char spi_slave_config; -data unsigned char spi_master_config; -data unsigned char spi_count; -data unsigned char spi_lenght_data; +data uint8_t spi_slave_config; +data uint8_t spi_master_config; +data uint8_t spi_count; +data uint8_t spi_lenght_data; bit spi_enable = 1; bit spi_ready = 0; bit spi_Start_Flag = 0; -unsigned char spi_TestCtr ; // Debug +uint8_t spi_TestCtr ; // Debug /*F************************************************************************** @@ -151,10 +151,10 @@ void spi_task(void) { - data unsigned char Spi_Overflow_Ctr; + data uint8_t Spi_Overflow_Ctr; uint8_t i; - data unsigned char received_status[4]; - data unsigned char received_data[34]; + data uint8_t received_status[4]; + data uint8_t received_data[34]; Cpu_reset=1; if(spi_task_on_Flag) { Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/spi/spi_task.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/spi/spi_task.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -31,16 +31,16 @@ extern data STM_SPI_MASTER_SLAVE_TYPE spi_slave; typedef enum {HEADERM, PUT_SOUND_FIFO, READ_COMMAND} STM_SPI_SLAVE_MASTER_TYPE; extern data STM_SPI_SLAVE_MASTER_TYPE spi_master; -extern data unsigned char spi_slave_config; -extern data unsigned char spi_master_config; -extern data unsigned char spi_count; -extern data unsigned char spi_lenght_data; +extern data uint8_t spi_slave_config; +extern data uint8_t spi_master_config; +extern data uint8_t spi_count; +extern data uint8_t spi_lenght_data; extern bit spi_enable ; extern bit spi_ready ; extern bit spi_Start_Flag ; -extern unsigned char spi_TestCtr ; // Debug +extern uint8_t spi_TestCtr ; // Debug /*_____ D E C L A R A T I O N ______________________________________________*/ void spi_task_init (void); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -18,7 +18,7 @@ static void ep_spk(void); static void ep_tts(void); static void ep_mic(void); -static void tux_command_parser (unsigned char* commands, unsigned char data_length); +static void tux_command_parser (uint8_t * commands, uint8_t data_length); static void usb_command_parser(void); void endpoints_ctr(void) @@ -233,9 +233,9 @@ /** * Parse generic tux commands and process those addressed to the dongle. */ -static void tux_command_parser (unsigned char* commands, unsigned char data_length) +static void tux_command_parser (uint8_t * commands, uint8_t data_length) { - unsigned char i = 0; + uint8_t i = 0; while (data_length > i) { Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_enum.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_enum.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_enum.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -1059,11 +1059,11 @@ *****************************************************************************/ void usb_set_interface (void) { - unsigned char LAlternateSetting; - unsigned char HAlternateSetting; + uint8_t LAlternateSetting; + uint8_t HAlternateSetting; - unsigned char Linterface_number; - unsigned char Hinterface_number; + uint8_t Linterface_number; + uint8_t Hinterface_number; LAlternateSetting = Usb_read_byte(); /* read the conf. num. in wValue */ HAlternateSetting = Usb_read_byte(); /* read the conf. num. in wValue */ @@ -1378,11 +1378,11 @@ *****************************************************************************/ void usb_get_current (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_rx_setup(); Usb_set_DIR(); @@ -1418,11 +1418,11 @@ void usb_get_min (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_rx_setup(); Usb_set_DIR(); @@ -1444,11 +1444,11 @@ void usb_get_max (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_rx_setup(); Usb_set_DIR(); @@ -1470,11 +1470,11 @@ void usb_get_res (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_rx_setup(); Usb_set_DIR(); @@ -1513,11 +1513,11 @@ *****************************************************************************/ void usb_set_current (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); @@ -1548,11 +1548,11 @@ void usb_set_min (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); @@ -1570,11 +1570,11 @@ void usb_set_max (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); @@ -1592,11 +1592,11 @@ void usb_set_res (void) { - unsigned char LwValue = Usb_read_byte(); - unsigned char HwValue = Usb_read_byte(); + uint8_t LwValue = Usb_read_byte(); + uint8_t HwValue = Usb_read_byte(); - unsigned char LwIndex = Usb_read_byte(); - unsigned char HwIndex = Usb_read_byte(); + uint8_t LwIndex = Usb_read_byte(); + uint8_t HwIndex = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 11:33:40 UTC (rev 1115) @@ -34,8 +34,8 @@ void data_to_send(void); /*_____ D E C L A R A T I O N ______________________________________________*/ #if (PONG_CHECK) -unsigned char pong_received; /* value of the pong received from the sound cpu */ -unsigned char pong_missed; /* counting the pong missed on the SPI */ +uint8_t pong_received; /* value of the pong received from the sound cpu */ +uint8_t pong_missed; /* counting the pong missed on the SPI */ #endif bit EP_AUDIOIN_Loaded = 0; @@ -48,10 +48,10 @@ fifo_t statusBuf; fifo_t *statusFifo = &statusBuf; -data unsigned char received_status[4]; -data unsigned char received_data[34]; -data unsigned char Sample8; -data unsigned char Spi_Overflow_Ctr; +data uint8_t received_status[4]; +data uint8_t received_data[34]; +data uint8_t Sample8; +data uint8_t Spi_Overflow_Ctr; /*F************************************************************************** * NAME: usb_task_init Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 10:08:37 UTC (rev 1114) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 11:33:40 UTC (rev 1115) @@ -11,6 +11,7 @@ #ifndef _USB_TASK_H_ #define _USB_TASK_H_ #include "config.h" +#include "lib_c/stdint.h" /*_____ I N C L U D E S ____________________________________________________*/ |
From: Paul_R <c2m...@c2...> - 2008-05-06 10:08:33
|
Author: Paul_R Date: 2008-05-06 12:08:37 +0200 (Tue, 06 May 2008) New Revision: 1114 Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h firmware/fuxusb/branches/usb_cleanup/main.c firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Moved the calls of spi_task() and i2c_task() from usb_task.c to main.c * Moved some stuff from usb_task to usb_misc Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 10:08:37 UTC (rev 1114) @@ -22,6 +22,8 @@ uint8_t packet_idx; uint16_t address_tracking; +bit i2c_bootloading_Flag = 0; /* bootloader mode */ + blHeader_t blHeader; /* header for bootloading */ /* Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.h 2008-05-06 10:08:37 UTC (rev 1114) @@ -35,6 +35,7 @@ } blHeader_t; extern blHeader_t blHeader; +extern bit i2c_bootloading_Flag; /* * Extern declarations Modified: firmware/fuxusb/branches/usb_cleanup/main.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 10:08:37 UTC (rev 1114) @@ -16,6 +16,10 @@ #include "lib_c/stdint.h" #include "global.h" #include "usb\usb_task.h" +#include "rf.h" +#include "spi/spi_task.h" +#include "bootloader/i2c.h" +#include "bootloader/bootloading.h" #ifdef MAIN_DEBUG #include "lib_mcu\uart\uart_lib.h" @@ -67,17 +71,29 @@ #ifdef MAIN_DEBUG uart_init(); - printf("\n\n= TUX started ==\n"); + printf("\n== Tux started ==\n"); #endif + while(1) { usb_task(); - /* XXX - if (BOOT_MODE) - bootloader_task(); - else - spi_task(); - */ + if(usb_connected_Flag) + { + if (i2c_bootloading_Flag) /* I2C bootloading */ + { + i2c_task(); + } + else if(!RF_OFFLINE) + { + spi_task(); + } + else // if RF_OFFLINE + { + if (Cpu_reset) + rf_reset(); + Cpu_reset = 0; + } + } } } Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c 2008-05-06 10:08:37 UTC (rev 1114) @@ -4,6 +4,8 @@ #include "usb/usb_drv.h" #include "usb/usb_enum.h" #include "spi/spi_task.h" +#include "spi/spi_lib.h" +#include "bootloader/bootloading.h" #include "modules/fifo/fifo.h" #include "modules/fifo/fifo_spk.h" #include "modules/fifo/fifo_mic.h" @@ -97,3 +99,38 @@ } } +void tick_1ms(void) +{ +Usb_clear_sof(); + usb_sof_counter ++; // == 0xFF == 250ms + + if(spi_watchdog_ctr) + { + spi_watchdog_ctr--; // Decrement Watchdog + } + //--------------------------------------------------------- + // Reset SPI Transfer + //--------------------------------------------------------- + else if (!i2c_bootloading_Flag) + { + //Led_1_on(); + spi_slave = HEADERS; // Set state machine + spi_master = HEADERM; + spi_enable = 1; // Communication Authorized + SPI_CSn = 1; // Chip select + spi_Start_Flag = 0; + spi_ready = 0; + } + + //-------------------------------------------------------------------------- + // I2C pause timer + //-------------------------------------------------------------------------- + if (i2c_wait_counter) i2c_wait_counter--; + + //-------------------------------------------------------------------------- + // Led Behavior + //-------------------------------------------------------------------------- + if(usb_connected_Flag && usb_configuration_nb) + led_behavior(); +} + Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h 2008-05-06 10:08:37 UTC (rev 1114) @@ -1,4 +1,5 @@ void resume(void); void reset(void); void suspend(void); +void tick_1ms(void); void led_behavior(void); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 10:08:37 UTC (rev 1114) @@ -13,16 +13,11 @@ #include "config.h" #include "global.h" #include "rf.h" -#include "spi\spi_lib.h" #include "usb\usb_drv.h" #include "usb/usb_misc.h" #include "usb/usb_endpoints.h" - #include "usb\usb_task.h" -#include "spi\spi_task.h" #include "usb\usb_enum.h" -#include "modules\timer_soft\timer_soft.h" -#include "modules\fifo\fifo_spk.h" #include "modules\fifo\fifo_mic.h" #include "modules\fifo\fifo.h" #include "modules\fifo_stt\fifo_stt.h" @@ -43,9 +38,9 @@ unsigned char pong_missed; /* counting the pong missed on the SPI */ #endif bit EP_AUDIOIN_Loaded = 0; -bit i2c_bootloading_Flag = 0; /* bootloader mode */ + bit ReadStatus_USBRequest_Flag = 0; bit Cpu_reset = 0; bit Speaker_TTS_Select_Flag = 0; @@ -114,8 +109,6 @@ USB_Bootloader_NewCmd_Flag = FALSE; } - - /*F************************************************************************** * NAME: usb_command_parser *---------------------------------------------------------------------------- @@ -179,8 +172,6 @@ } } - - void data_to_send(void) { if (CMD_IN_Bank_Nb) @@ -191,10 +182,6 @@ } } - - - - /*F************************************************************************** * NAME: usb_task *---------------------------------------------------------------------------- @@ -220,40 +207,8 @@ reset(); if (Usb_sof()) - { - Usb_clear_sof(); - usb_sof_counter ++; // == 0xFF == 250ms + tick_1ms(); - if(spi_watchdog_ctr) - { - spi_watchdog_ctr--; // Decrement Watchdog - } - //--------------------------------------------------------- - // Reset SPI Transfer - //--------------------------------------------------------- - else if (!i2c_bootloading_Flag) - { - //Led_1_on(); - spi_slave = HEADERS; // Set state machine - spi_master = HEADERM; - spi_enable = 1; // Communication Authorized - SPI_CSn = 1; // Chip select - spi_Start_Flag = 0; - spi_ready = 0; - } - - //-------------------------------------------------------------------------- - // I2C pause timer - //-------------------------------------------------------------------------- - if (i2c_wait_counter) i2c_wait_counter--; - - //-------------------------------------------------------------------------- - // Led Behavior - //-------------------------------------------------------------------------- - if(usb_connected_Flag && usb_configuration_nb) - led_behavior(); - } - //-------------------------------------------------------------------------- // // Process to load Status Data in the USB FIFO @@ -274,14 +229,12 @@ if(Fifoready_MIC) { Usb_select_ep(EP_AUDIO_IN); - //DEBUG_1 = 1; i=8; do { Usb_write_byte(FIFO_MIC_get()); // No data to transmit i--; } while(i); - //DEBUG_1 = 0; Usb_set_tx_ready(); EP_AUDIOIN_Loaded = 1; } @@ -291,29 +244,7 @@ // USB Events // //-------------------------------------------------------------------------- - if(Usb_endpoint_interrupt()) - { + if(Usb_endpoint_interrupt()) endpoints_ctr(); - } } - - - if(!usb_connected_Flag) - return; - - - if (i2c_bootloading_Flag) /* I2C bootloading */ - { - i2c_task(); - } - else if(!RF_OFFLINE) - { - spi_task(); - } - else // if RF_OFFLINE - { - if (Cpu_reset) - rf_reset(); - Cpu_reset = 0; - } } Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 10:00:17 UTC (rev 1113) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 10:08:37 UTC (rev 1114) @@ -25,7 +25,7 @@ /*_____ D E C L A R A T I O N ______________________________________________*/ extern bit Cpu_reset; -extern bit i2c_bootloading_Flag; + extern bit Speaker_TTS_Select_Flag; extern bit EP_AUDIOIN_Loaded; |
From: Paul_R <c2m...@c2...> - 2008-05-06 10:00:20
|
Author: Paul_R Date: 2008-05-06 12:00:17 +0200 (Tue, 06 May 2008) New Revision: 1113 Removed: firmware/fuxusb/branches/usb_cleanup/modules/timer_soft/ Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 Log: * Removed unused module Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 =================================================================== --- firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 09:54:21 UTC (rev 1112) +++ firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 10:00:17 UTC (rev 1113) @@ -23,7 +23,6 @@ File 3,1,<.\spi\spi_lib.c><spi_lib.c> 0x0 File 4,1,<.\bootloader\bootloading.c><bootloading.c> 0x0 File 4,1,<.\bootloader\i2c.c><i2c.c> 0x0 -File 5,1,<.\modules\timer_soft\timer_soft.c><timer_soft.c> 0x0 File 5,1,<.\modules\fifo\fifo.c><fifo.c> 0x0 File 5,1,<.\modules\fifo\fifo_spk.c><fifo_spk.c> 0x0 File 5,1,<.\modules\fifo\fifo_mic.c><fifo_mic.c> 0x0 |
From: jaguarondi <c2m...@c2...> - 2008-05-06 09:54:17
|
Author: jaguarondi Date: 2008-05-06 11:54:21 +0200 (Tue, 06 May 2008) New Revision: 1112 Modified: firmware/tuxaudio/trunk/AT26F004.c firmware/tuxaudio/trunk/AT26F004.h firmware/tuxaudio/trunk/PC_communication.c firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/i2c.h firmware/tuxcore/trunk/adc.c firmware/tuxcore/trunk/debug.h firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/hardware.h firmware/tuxcore/trunk/i2c.h firmware/tuxcore/trunk/ir.c firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/sensors.c Log: * Cleanup of spaces and tabs. Modified: firmware/tuxaudio/trunk/AT26F004.c =================================================================== --- firmware/tuxaudio/trunk/AT26F004.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxaudio/trunk/AT26F004.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -27,7 +27,7 @@ static void unprotect_sectors(void); /** * \ingroup at26f004 - * \brief initialize a table with the sector adresses values + * \brief initialize a table with the sector adresses values */ static uint8_t sector_adress[11][3] = { {SECTOR0}, @@ -44,10 +44,10 @@ }; /** - * \ingroup at26f004 + * \ingroup at26f004 \brief This function set the write enable flag of the flash memory. - */ + */ uint8_t read_status(void) { uint8_t status; @@ -59,10 +59,10 @@ return status; } /** - * \ingroup at26f004 + * \ingroup at26f004 \brief This function set the write enable flag of the flash memory. - */ + */ void write_enable(void) { flash_select(); @@ -70,10 +70,10 @@ flash_unselect(); } /** - * \ingroup at26f004 + * \ingroup at26f004 \brief This function clear the write enable flag of the flash memory. - */ + */ void write_disable(void) { flash_select(); @@ -82,10 +82,10 @@ } /** - * \ingroup at26f004 + * \ingroup at26f004 \brief This function write into the flash memory status register. - */ + */ void write_status(uint8_t const status) { flash_select(); @@ -94,13 +94,13 @@ flash_unselect(); } /** - * \ingroup at26f004 - \param ad2 high address part - \param ad1 medium adress part + * \ingroup at26f004 + \param ad2 high address part + \param ad1 medium adress part \param ad0 lower adress part \brief This function unprotect a sector. - */ + */ void unprotect_sector(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) { flash_select(); @@ -112,10 +112,10 @@ flash_unselect(); } /** - * \ingroup at26f004 + * \ingroup at26f004 \brief This function erase the entire memory. - */ + */ void erase_flash(void) { @@ -138,13 +138,13 @@ } } /** - * \ingroup at26f004 - \param ad2 high address part - \param ad1 medium adress part + * \ingroup at26f004 + \param ad2 high address part + \param ad1 medium adress part \param ad0 lower adress part \brief This function write a byte in the flash memory. - */ + */ void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, uint8_t const data) { @@ -162,13 +162,13 @@ } /** - * \ingroup at26f004 - \param ad2 high address part - \param ad1 medium adress part + * \ingroup at26f004 + \param ad2 high address part + \param ad1 medium adress part \param ad0 lower adress part \return Data read \brief This function read a single byte in the flash memory. - */ + */ uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) { uint8_t data1; @@ -186,11 +186,11 @@ } /** - * \ingroup at26f004 - \param first_block The first block to erase + * \ingroup at26f004 + \param first_block The first block to erase \param last_block The last block to erase - \brief This function erase a specified area in the memory. The memory will be erased by 4kB's blocks. - */ + \brief This function erase a specified area in the memory. The memory will be erased by 4kB's blocks. + */ void blockErase(uint8_t first_block, uint8_t last_block) { uint8_t diff, ad0, ad1; Modified: firmware/tuxaudio/trunk/AT26F004.h =================================================================== --- firmware/tuxaudio/trunk/AT26F004.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxaudio/trunk/AT26F004.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -44,43 +44,43 @@ /** * \name Read opcodes @{ */ -#define READ_ARRAY 0x0B +#define READ_ARRAY 0x0B #define READ_ARRAY_LOW_F 0x03 /* @} */ /** \name Erase opcodes *@{ */ -#define BLOCK_ERASE_4K 0x20 -#define BLOCK_ERASE_32K 0x52 -#define BLOCK_ERASE_64K 0xD8 -#define CHIP_ERASE 0x60 +#define BLOCK_ERASE_4K 0x20 +#define BLOCK_ERASE_32K 0x52 +#define BLOCK_ERASE_64K 0xD8 +#define CHIP_ERASE 0x60 /* @} */ /** \name Program opcodes * @{ */ -#define BYTE_PROGRAM 0x02 -#define SEQU_PROGRAM 0xAF +#define BYTE_PROGRAM 0x02 +#define SEQU_PROGRAM 0xAF /* @} */ /** \name Sectors managment opcodes * @{ */ -#define WRITE_EN 0x06 -#define WRITE_DIS 0x04 -#define PROTECT_SECTOR 0x36 +#define WRITE_EN 0x06 +#define WRITE_DIS 0x04 +#define PROTECT_SECTOR 0x36 #define UNPROTECT_SECTOR 0x39 #define READ_SECT_PROTECT 0x3C /* @} */ /** \name Status command * @{ */ -#define READ_STATUS_REG 0x05 +#define READ_STATUS_REG 0x05 #define WRITE_STATUS_REG 0x01 /* @} */ /** \name Misc. opcodes * @{ */ -#define READ_MANUFACT 0x9F -#define DEEP_POWER_MODE 0xB9 +#define READ_MANUFACT 0x9F +#define DEEP_POWER_MODE 0xB9 #define RESUME_DEEP_MODE 0xAB -#define NOP 0x00 +#define NOP 0x00 /* @} */ /** Modified: firmware/tuxaudio/trunk/PC_communication.c =================================================================== --- firmware/tuxaudio/trunk/PC_communication.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxaudio/trunk/PC_communication.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -118,7 +118,7 @@ { if (frame_without_sound) frame_without_sound --; - + else sound_played = 0; } Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxaudio/trunk/flash.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -45,12 +45,12 @@ /** - * \ingroup flash + * \ingroup flash \brief Read the number of sound in the flash memory. This function scan the sound's indexes, and return the number of sound stored in the flash memory. - */ + */ uint8_t readFlashNumber(void) { @@ -87,10 +87,10 @@ ad[1] = read_data(0x00, (index>>8), (index & 0xFF)); index ++; ad[2] = read_data(0x00, (index>>8), (index & 0xFF)); - return (ad[0] << 4) + (ad[1] >> 4); + return (ad[0] << 4) + (ad[1] >> 4); } /** - * \ingroup flash + * \ingroup flash \brief Store a sound in the memory. This function contain 5 states : @@ -108,7 +108,7 @@ \note Each sound starts at the first byte of a 4kB block. To do this, the lower address byte is reset, and the medium address byte is incremented. -*/ +*/ void programming(void) { @@ -150,12 +150,12 @@ { programming_state = PROG_END; send_status_p(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); - } + } else programming_state ++; frame_without_sound = 5000; - frame_without_sound_timeout = 5000; + frame_without_sound_timeout = 5000; send_status_p(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); } @@ -170,7 +170,7 @@ { if (flash_state) programming_sound(); - + else { write_disable(); @@ -186,7 +186,7 @@ programming_state = PROG_END; } } - } + } else if (programming_state == WAITING_STATE) { if (write_toc == 1) @@ -212,7 +212,7 @@ } write_toc = 0; } - else if (programming_state == PROG_TOC) + else if (programming_state == PROG_TOC) { send_status_p(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); numSound ++; @@ -268,19 +268,19 @@ } /** - * \ingroup flash + * \ingroup flash \brief Erase the flash memory. - + The first step is to send the command to erase the flash. After, the status is polled while the erase process isn't finished. When the BUSY flag is null, the erase sequence is stopped. -*/ +*/ void erase(void) { uint8_t static enter = 1; if (enter) { - erase_flash(); + erase_flash(); enter = 0; } else if (!(read_status() & BUSY)) @@ -302,14 +302,14 @@ } /** - * \ingroup flash + * \ingroup flash \brief This function is used to play a sound from the flash memory. The first step (playInit) is to initialize the flash memory with the selected sound to play. Many tests are made to ensure that the sound to play exist, the indexes are correct, etc. The second step (playingSound) is to fill the fifo with the sound's bytes, and to verify the addresses. - */ + */ void playSound(void) @@ -322,7 +322,7 @@ /* Static functions */ /** - * \ingroup flash + * \ingroup flash \brief This function is used to init the memory to play a sound. \param nsound Track number to be played. @@ -333,7 +333,7 @@ If these conditions are respected, the memory is initialised with the first sound's byte address. The next index is stored to identify the end of the sound track. -*/ +*/ static void playInit(uint8_t const nsound) { @@ -407,7 +407,7 @@ } /* minimum index not respected */ if (ad[3] < ad[0]) { - flashPlay = 0; + flashPlay = 0; return; } /* check that the stop index is greater than the start index */ else if (ad[3] == ad[0]) @@ -440,12 +440,12 @@ /* Static functions */ /** - * \ingroup flash + * \ingroup flash \brief Read the flash memory and fill the fifo. This function reads bytes into the flash memory and fill the fifo. When the last byte is read, the sound play's sequence is stopped. - */ + */ static void playingSound(void) { @@ -482,10 +482,10 @@ /* Static functions */ /** - * \ingroup flash + * \ingroup flash \brief Stop the play sequence. - - */ + + */ static void stopPlaying(void) { soundToPlay = 0; @@ -496,14 +496,14 @@ } /** - * \ingroup flash - \brief Init the programming sequence - + * \ingroup flash + \brief Init the programming sequence + To perform a sequential programming, the first step is to send the correct OP code, and the three address bytes where the first data byte must be stored. - The second step is to send the OP code and a data to write. - - This function perform the first step. + The second step is to send the OP code and a data to write. + + This function perform the first step. */ static void init_programming(uint8_t adi0, uint8_t adi1, uint8_t adi2) { @@ -518,14 +518,14 @@ spiSend(data); else spiSend(0x80); - + flash_unselect(); // Chip Deselect } /** - * \ingroup flash - \brief Program the sound's data into the flash memory + * \ingroup flash + \brief Program the sound's data into the flash memory This function is executed while the SPI start command is not present. Each cycle, one byte is popped from the PWM fifo and stored in the sound flash. @@ -542,20 +542,20 @@ The sound_stored flag is set when at least one byte is stored in the memory. Else, this variable is null. - */ + */ static void programming_sound(void) { while (!spi_start) { - if (FifoLength(PWMFifo)) + if (FifoLength(PWMFifo)) { uint8_t data; sound_stored = 1; frame_without_sound = STOP_FRAME_NUMBER; frame_without_sound_timeout = STOP_FRAME_NUMBER; - flash_select(); + flash_select(); spiSend(SEQU_PROGRAM); FifoGet(PWMFifo, &data); spiSend(data); Modified: firmware/tuxaudio/trunk/i2c.h =================================================================== --- firmware/tuxaudio/trunk/i2c.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxaudio/trunk/i2c.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -41,8 +41,8 @@ struct i2c_msg { uint8_t addr; /**> Slave address, the AVR only supports 7-bit address space. */ - uint8_t len; /**> Message length. */ - uint8_t *buf; /**> Pointer to msg data. */ + uint8_t len; /**> Message length. */ + uint8_t *buf; /**> Pointer to msg data. */ enum i2c_state state; }; Modified: firmware/tuxcore/trunk/adc.c =================================================================== --- firmware/tuxcore/trunk/adc.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/adc.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -82,7 +82,7 @@ \brief Start a conversion on the selected channel. \param ad_mux (ADMUX) Reference, format and channel selection. \ingroup adc - + ADC Multiplexer Selection Register - ADMUX Bit 7:6 - REFS1:0: Reference Selection Bits 0 0 AREF, Internal Vref turned off @@ -117,7 +117,7 @@ */ uint16_t ADC_read() { - union16_t adc_value; + union16_t adc_value; /* ADCH should be read after ADCL otherwise ADCL stays wite protected * (c.f. datasheet). */ adc_value.b[0] = ADCL; Modified: firmware/tuxcore/trunk/debug.h =================================================================== --- firmware/tuxcore/trunk/debug.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/debug.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id:$ */ +/* $Id$ */ /** * \defgroup debug Debugging aid Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/global.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -104,7 +104,7 @@ */ /* gStatus.mot:[0] Spin motor - * xxxxxxx0 === Spin off + * xxxxxxx0 === Spin off * xxxxxxx1 === Spin on */ #define GSTATUS_MOT_SPIN 0x01 /* gStatus.mot:[1] Eyes/Mouth motor Modified: firmware/tuxcore/trunk/hardware.h =================================================================== --- firmware/tuxcore/trunk/hardware.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/hardware.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -36,7 +36,7 @@ /** \ingroup hardware */ /*! @{ */ -/** +/** * \name Head button * The head button switch shortcuts to ground when pressed. * @{ */ @@ -50,7 +50,7 @@ #define SW_HD_MK _BV(PB5) /*! @} */ -/** +/** * \name Position switches * All position switches shortcuts to ground when pressed. * @@ -60,7 +60,7 @@ * position of the flippers. * - The eyes and mouth both have 2 switches to detect when they are open or * closed. The corresponding switch is pressed when a plain position is - * reached. In between, both switches are released. + * reached. In between, both switches are released. * @{ */ /** Spin switch mask. */ #define PSW_SPIN_MK _BV(PD3) @@ -104,7 +104,7 @@ #define PSW_EYES_MK (PSW_EYES_O_MK | PSW_EYES_C_MK) /*! @} */ -/** +/** * \name IR * - The IR led is controlled through a power driver. Setting the output pin * will turn the led on. @@ -127,7 +127,7 @@ #define IR_REC_MK _BV(PD2) /*! @} */ -/** +/** * \name Phototransistor * The Phototransistor is connected as an LDR to a 1MOhms resistor. A second * pull-up of 10kOhms can be added in parallel to change the load. The extra @@ -145,7 +145,7 @@ #define LIGHT_ADMUX 0x06 /*! @} */ -/** +/** * \name Charger inhibit * This pin inhibits the charge when set high. It shouldn't be left in high-z * otherwise the charge won't be stable. Keep it low. @@ -161,7 +161,7 @@ #define CHARGER_INH_MK _BV(PB6) /*! @} */ -/** +/** * \name LED * The leds are directly connected to the output pins through a 100 Ohms * resistor. @@ -180,7 +180,7 @@ #define LED_MK (LED_R_MK | LED_L_MK) /*! @} */ -/** +/** * \name External I/O * The external I/O is routed to the external connector which is accessible in * the battery compartment of tux. There's a 330 Ohms resistor in series to @@ -196,7 +196,7 @@ #define EXIO_MK _BV(PB7) /*! @} */ -/** +/** * \name Motors * The motor drivers use 2 pins to move forward or backward. Setting the first * pin to high will move forward, setting the other will turn backward. You @@ -260,7 +260,7 @@ #define MOT_SPIN_MK (MOT_SPIN_L_MK | MOT_SPIN_R_MK) /*! @} */ -/** +/** * \name Battery * The battery voltage can be measured on the pin ADC7 through a resistive * divider. Modified: firmware/tuxcore/trunk/i2c.h =================================================================== --- firmware/tuxcore/trunk/i2c.h 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/i2c.h 2008-05-06 09:54:21 UTC (rev 1112) @@ -43,8 +43,8 @@ struct i2c_msg { uint8_t addr; /**> Slave address, the AVR only supports 7-bit address space. */ - uint8_t len; /**> Message length. */ - uint8_t *buf; /**> Pointer to msg data. */ + uint8_t len; /**> Message length. */ + uint8_t *buf; /**> Pointer to msg data. */ }; extern void i2c_init(void); Modified: firmware/tuxcore/trunk/ir.c =================================================================== --- firmware/tuxcore/trunk/ir.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/ir.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -168,7 +168,7 @@ gStatus.ir = ((uint8_t)irReceivedCode & 0x3F); /* Check if the code comes from our remote control. */ if ((irReceivedCode & 0x07C0) == 0x0740) - gStatus.ir |= GSTATUS_IR_VALID; /* set valid bit */ + gStatus.ir |= GSTATUS_IR_VALID; /* set valid bit */ if (irReceivedCode & 0x0800) gStatus.ir |= GSTATUS_IR_TOGGLE; /* set toggle bit */ else Modified: firmware/tuxcore/trunk/main.c =================================================================== --- firmware/tuxcore/trunk/main.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/main.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -57,7 +57,7 @@ */ DBG_STACK_INIT -/** +/** * \name Software timers * The main tick has a period of 4ms and is driven by a hardware timer * interrupt. Counters are used to get 100ms and 1s ticks. Modified: firmware/tuxcore/trunk/motors.c =================================================================== --- firmware/tuxcore/trunk/motors.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/motors.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -31,7 +31,7 @@ #include "motors.h" #include "common/defines.h" /** - * \name Motors PWM + * \name Motors PWM * @{ */ uint8_t flippers_params_pwm = 5; uint8_t spin_params_pwm = 5; @@ -170,7 +170,7 @@ /*! @} */ /** - * \name Motors command parser + * \name Motors command parser * These functions parse the received command, and call the specific motor * function. * @{ */ @@ -184,7 +184,7 @@ void motors_run(uint8_t motor, uint8_t const value, uint8_t const param) { uint8_t cnt; - + if (motor == MOT_EYES) { if (param & 0x01) @@ -238,7 +238,7 @@ \brief Parse the MOTORS_SET_CMD to command a motor with a specific number of movements. \param motor The motor to command \param pwm The PWM value - + The PWM can be used only for the spinning and the flippers. */ void motors_config(uint8_t const motor, uint8_t const pwm) @@ -515,9 +515,9 @@ \brief Open the mouth. \ingroup mouth - This function open the mouth if it's not already open. + This function open the mouth if it's not already open. The command is sent only if the mouth is not open or if the motor is - running. + running. We don't know the absolute mouth position. So, a command is sent with 2 movements, and a flag is set to specify the final position. When the final position is reached, the mouth_move_counter is reinitialized, and the @@ -536,9 +536,9 @@ \brief Close the mouth. \ingroup mouth - This function close the mouth if it's not already closed. + This function close the mouth if it's not already closed. The command is sent only if the mouth is not closed or if the motor is - running. + running. We don't know the absolute mouth position. So, a command is sent with 2 movements, and a flag is set to specify the final position. When the final position is reached, the mouth_move_counter is reinitialized, and the @@ -705,7 +705,7 @@ if (gStatus.pos == 0) wave_flippers(1,5); else - flippers_move_counter = 2; + flippers_move_counter = 2; } /** @@ -723,7 +723,7 @@ if (gStatus.pos == 1) wave_flippers(1,5); else - flippers_move_counter = 2; + flippers_move_counter = 2; } /** Modified: firmware/tuxcore/trunk/sensors.c =================================================================== --- firmware/tuxcore/trunk/sensors.c 2008-05-06 09:53:54 UTC (rev 1111) +++ firmware/tuxcore/trunk/sensors.c 2008-05-06 09:54:21 UTC (rev 1112) @@ -50,7 +50,7 @@ To execute this function, the STATUS_SENT flag OR the ADC_READY flag must be set. The STATUS_SEND flag is set when the status are send to the PC. The ADC_READY flag is set when an interrupt on the ADC module occurs. - When the state machine is in the last state, it will be resetted and wait while the status are sent. If status are sent before the last state, the cycle continue. + When the state machine is in the last state, it will be resetted and wait while the status are sent. If status are sent before the last state, the cycle continue. */ void sensors_control(void) { @@ -67,7 +67,7 @@ light_control(ADC_read()); if (gStatus.mot) motorsStatus = 1; - + ADC_start(BATTERY_ADMUX); // XXX arg : ADMUX sensorsControlState ++; } @@ -75,7 +75,7 @@ { if (gStatus.mot) motorsStatus = 1; - battery_control(ADC_read()); + battery_control(ADC_read()); sensorsControlState = 0; } } |
From: jaguarondi <c2m...@c2...> - 2008-05-06 09:53:51
|
Author: jaguarondi Date: 2008-05-06 11:53:54 +0200 (Tue, 06 May 2008) New Revision: 1111 Modified: firmware/tuxdefs/api.h firmware/tuxdefs/commands.h Log: * Cleanup of spaces at EOL. Modified: firmware/tuxdefs/api.h =================================================================== --- firmware/tuxdefs/api.h 2008-05-06 09:38:42 UTC (rev 1110) +++ firmware/tuxdefs/api.h 2008-05-06 09:53:54 UTC (rev 1111) @@ -259,7 +259,7 @@ * usually represent tux's status. * @{ */ -/** +/** * LEDs status, both intensities and whether any effect is ongoing. * * Parameters: @@ -287,9 +287,9 @@ * Parameters: * - 1 : The motor to command * - 2 : The count or/ timeout value - * - 3 : + * - 3 : * .0..1 : The final state - * .2 : 0 for count, 1 for timeout + * .2 : 0 for count, 1 for timeout */ #define MOTORS_SET_CMD 0xD4 Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2008-05-06 09:38:42 UTC (rev 1110) +++ firmware/tuxdefs/commands.h 2008-05-06 09:53:54 UTC (rev 1111) @@ -99,7 +99,7 @@ #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 +#define STORE_SOUND_CMD 0x52 #define CONFIRM_STORAGE_CMD 0x53 /* 1st parameter: 1 to write the sound |
From: jaguarondi <c2m...@c2...> - 2008-05-06 09:38:41
|
Author: jaguarondi Date: 2008-05-06 11:38:42 +0200 (Tue, 06 May 2008) New Revision: 1110 Modified: firmware/tuxaudio/trunk/PC_communication.c firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/fifo.c firmware/tuxaudio/trunk/fifo.h firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/flash.h firmware/tuxaudio/trunk/hardware.h firmware/tuxaudio/trunk/i2c.c firmware/tuxaudio/trunk/i2c.h firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/varis.c firmware/tuxaudio/trunk/varis.h firmware/tuxcore/trunk/communication.c firmware/tuxcore/trunk/communication.h firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/i2c.c firmware/tuxcore/trunk/i2c.h firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/parser.h firmware/tuxcore/trunk/standalone.c Log: * Ported the refactored I2C developped for the production firmare to the public firmware. This is a major change in the internal communication between the 2 main MCUs. Earlier, the communication protocol on top of I2C was mutli-master, each MCU sending data as master to the other whenever necessary. Now, tuxaudio is a single master and regularly polls tuxcore for new status. The functionalities shouldn't have changed. This is a simple port, it seems to work but I didn't test it much. There are still many simplifications I want to do on the communication protocol. * Updated the fifo module and all calls. * Sleep functions added in the flash module. * Some cleanup. Modified: firmware/tuxaudio/trunk/PC_communication.c =================================================================== --- firmware/tuxaudio/trunk/PC_communication.c 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/PC_communication.c 2008-05-06 09:38:42 UTC (rev 1110) @@ -31,10 +31,9 @@ void spiTransaction(void) { - if ((spi_start) && (spi_enable)) // Wait start + if (spi_start) // Wait start { spi_start = 0; // Reset the spi start flag - spi_enable = 0; // Communication in progress spi_count = 0; // Reset spi counter spi_slave = HEADERS; // Set state machine spi_master = HEADERM; @@ -54,7 +53,7 @@ if (spi_slave == HEADERS) { /* Sound */ - if (fifoLength(&ADCFifo) >= 17) + if (FifoLength(ADCFifo) >= 17) spi_headerb = 0x02; /* frame will contain sound */ else spi_headerb = 0x00; /* no sound in frame */ @@ -78,8 +77,10 @@ spi_slave = PUT_COMMAND; // Next state if (spi_headerb & 0x02) { + uint8_t data; cli(); - SPDR = pullFifo(&ADCFifo); // Get data from FIFO + FifoGet(ADCFifo, &data); + SPDR = data; // Get data from FIFO sei(); } else @@ -135,11 +136,83 @@ { if (!lockAdaptFifo) { - adaptFifo(&PWMFifo); // Adaptative FIFO + //adaptFifo(PWMFifo); // Adaptative FIFO +#if 0 +/** \brief 3 levels adaptative function. + * \param p fifo pointer + * + * High and low thresholds are used to differentiate 3 levels of the buffer. In + * each level, a custom code or a function call can be provided to do the + * adaptation. + */ +void adaptFifo(fifo_t * p) +{ + unsigned char fifoLevel; + + fifoLevel = fifoLength(p); + if (!p->adpt_cycle) + { + if (p->matched == 8) + { + if (OCR0A < 254) + p->pwm_max = OCR0A + 2; + else + p->pwm_max = 255; + if (OCR0A > 231) + p->pwm_min = OCR0A - 2; + else + p->pwm_min = 230; + p->matched = 9; + } + + if (fifoLevel >= FIFO_ADAPT_HIGH) + { + if (OCR0A > p->pwm_min) + { + OCR0A--; + p->pwm_adpt_sens = 1; + } + } + else if (fifoLevel < FIFO_ADAPT_LOW) + { + if (OCR0A < p->pwm_max) + { + OCR0A++; + p->pwm_adpt_sens = 2; + } + } + else + { + if (p->pwm_adpt_sens) + { + if ((p->pwm_adpt_sens) == 1) + { + if (OCR0A < p->pwm_max) + OCR0A++; + } + else + { + if (OCR0A > p->pwm_min) + OCR0A--; + } + p->pwm_adpt_sens = 0; + p->matched = 0; + } + else + { + if (p->matched != 9) + p->matched++; + } + } + } + p->adpt_cycle++; + p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1; +} +#endif lockAdaptFifo = 1; } else - resetFifo(&PWMFifo); + FifoClear(PWMFifo); } else { @@ -153,7 +226,7 @@ if (spi_master_config & 0x02) { if (!flashPlay) - pushFifo(&PWMFifo, SPDR); // Put into the FIFO + FifoPut(PWMFifo, SPDR); // Put into the FIFO } if (spi_count == (spi_lenght_data + 1)) spi_master = READ_COMMAND; // Go to the next state @@ -177,7 +250,6 @@ rf_data_sent_ack = spi_commandRX[4]; /* get the acknowledge of the previous sent data */ PORTB |= 0x04; // Chip deselect - spi_enable = 1; break; } } Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/communication.c 2008-05-06 09:38:42 UTC (rev 1110) @@ -24,39 +24,24 @@ #include "communication.h" #include "i2c.h" +#include "hardware.h" +#include "config.h" -/* Debug mode, uncomment for debug */ -//#define __com_debug__ +#define I2C_TUXCORE_ADDR 0x2A -/* XXX i2c bug of the AVR */ -#define I2C_IDLE_RESET 250; -uint8_t i2c_idle_time = I2C_IDLE_RESET; +static uint8_t out_buf[CMD_SIZE]; +static struct i2c_msg msg_out = {0, 0, out_buf}; +static uint8_t in_buf[CMD_SIZE]; +static struct i2c_msg msg_in = {0, 0, in_buf}; +volatile uint8_t ret; +uint8_t statusFlag; -#ifdef __com_debug__ -uint8_t errorNbr = 0; -void comError(void) -{ - errorNbr = 1; -} -#endif - /* - * commandBuf is a filo buffer for commands received by RF and sent over i2c - * - * Check the following conditions when you fill it. - * - i2cFlags.i2c_idx == 0 : commandBuf is processed by the I2C sendCommands() - * function when i2c_idx = 1 so you should not change it at that time - * - this stack is a filo, you should push the latest byte first (latest - * parameter) so a command is always at the top of the stack. - * - * Note that because of this filo stack, commands are not processed in the - * order they were issued when the stack holds multiple commands. + * core_cmdout is a buffer for commands to be sent to tuxcore */ -uint8_t commandBuf[COMMAND_BUF_SIZE]; -fifo_t _commandFifo = { (uint8_t *) commandBuf, sizeof commandBuf - 1, 0, 0 } +FIFO_INSTANCE(core_cmdout_buf, COMMAND_BUF_SIZE); +fifo_t *core_cmdout = FifoPointer(core_cmdout_buf); -, *commandFifo = &_commandFifo; - /* * audioBuf is a single buffer for commands received over i2c to control the * audio interface @@ -66,7 +51,7 @@ * 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 audioBuf[CMD_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 */ /* @@ -74,31 +59,16 @@ * 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 } +FIFO_INSTANCE(statusFifo_s, INCOMING_BUF_SIZE); +fifo_t *statusFifo = FifoPointer(statusFifo_s); -, *statusFifo = &_statusBuf; - -void send_status(uint8_t status ,uint8_t byte1 ,uint8_t byte2 ,uint8_t byte3) -{ - uint8_t buf[4]; - buf[0] = status; - buf[1] = byte1; - buf[2] = byte2; - buf[3] = byte3; - cli(); - i2cSlaveReceiveService(4, buf); - sei(); -} - - /* - * Initializes (clear) the communication buffers + * Initialize (clear) the communication buffers */ void initCommunicationBuffers(void) { - resetFifo(commandFifo); + FifoClear(core_cmdout); audioBufIdx = 0; } @@ -110,183 +80,213 @@ */ 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 */ + i2c_init(); + msg_out.addr = I2C_TUXCORE_ADDR; + msg_out.buf = out_buf; + i2c_master_receive_handler(i2cMasterReceiveService); } /* * sendCommands takes one command (from 1 to 4 bytes) out of the command stack * and send them by i2c. * - * In order to protect this buffer of being corrupted by any modification in - * interrupts, a flag (i2cFlags.i2c_idx) is set during manipulations. - * - * The i2c busy flag (i2cFlags.i2c_busy) is checked here to know if we can send - * the next command. + * Should return 0 if nothing has to be sent. */ -void sendCommands(void) +int8_t sendCommands(void) { uint8_t i; + static uint8_t nack_cnt = 0; - if (!(i2cFlags.i2c_busy)) /* i2c hardware not busy */ + if (i2c_get_status() == I2C_BUSY) + return 1; + if (msg_out.state == I2C_NACK) { - i2c_idle_time = I2C_IDLE_RESET; - if (i2cFlags.mt_nack) /* if nack error, resend previous command */ + /* If NACK, try a couple more time. */ + if (++nack_cnt == 4) { - i2cMasterStart(); - cli(); - i2cFlags.mt_nack = 0; - i2cFlags.i2c_busy = 1; - sei(); + nack_cnt = 0; + switch (msg_out.addr) + { + case I2C_TUXCORE_ADDR: + /* Return 0 as if there were nothing to do so we can do + something else. Returning here doesn't drop the message. */ + return 0; + } } - else if (i2cFlags.m_end == 0) /* previous transmission was cancelled by arbitration lost or any problem so restart */ + else + i2c_send_bytes(&msg_out); + return 2; + } + else + nack_cnt = 0; + /* Send something else. */ + { + if (FifoLength(core_cmdout)) + /* Send commands received from RF or testers to tuxcore only. */ { - 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 */ - { - cli(); - 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++) + msg_out.len = CMD_SIZE; + for (i = 0; i < CMD_SIZE; i++) { - if (popFifo(commandFifo, &i2cSendData[i])) - i2cSendDataLength = 0; /* drop the data if the fifo seems corrupted XXX add an error feedback on this */ + if (FifoGet(core_cmdout, &out_buf[i])) + /* Drop the data if the fifo is corrupted (not enough + * bytes) XXX add an error feedback on this */ + return -1; } - i2cMasterStart(); - cli(); - i2cFlags.i2c_idx = 0; /* release commandFifo protection */ - i2cFlags.i2c_busy = 1; - sei(); + msg_out.addr = I2C_TUXCORE_ADDR; + ret = i2c_send_bytes(&msg_out); } + else + /* Nothing to do anymore */ + return 0; } - /* XXX patch for the I2C bug of the AVR */ - else if (!i2c_idle_time--) + return 1; +} + +void getStatus(void) +{ + if (i2c_get_status() != I2C_BUSY) { - uint16_t wait = 0; - - TWCR = 0; - while (wait++ < 0xFFF0) ; - i2cFlags.i2c_busy = 0; - i2cFlags.m_end = 0; - i2cFlags.mt_nack = 0; - i2cInit(); + statusFlag = 0; + msg_in.addr = I2C_TUXCORE_ADDR; + msg_in.len = CMD_SIZE; + ret = i2c_read_bytes(&msg_in); } } + /* - * Insert a set of commands to the commandBuf filo stack. Returns '0' if the - * commands are stored, '1' if the stack is full and an error has been - * generated. - * - * i2cFlags.i2c_idx is not checked here so if you call this function from an - * interrupt you should check it yourself. - * - * The command[] parameter format starts with the command and then the parameters + * Add a command on the stack for tuxcore + * Returns 0 if the stack is full, 1 if the command has been added + * successfully. */ -uint8_t pushCommands(uint8_t * command) +int8_t send_core_cmd(uint8_t *cmd) { uint8_t i; - if (*command) - { - 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++) - pushFifo(commandFifo, *command++); + if (FifoLength(core_cmdout) > FifoSize(core_cmdout) - CMD_SIZE) return 0; - } + + cli(); + for (i=0; i<CMD_SIZE; i++) + FifoPut(core_cmdout, cmd[i]); + sei(); return 1; } /* - * acceptData is a checking function associated with the i2c ISR to ack or nack - * the incoming command depending on the various stack status + * Add a command on the stack for tuxcore + * Returns 0 if the stack is full, 1 if the command has been added + * successfully. */ -void acceptData(void) +int8_t send_core_cmd_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ + uint8_t param3) { - if (TWDR < 0xC0) /* command to be executed, cannot have 3 parameters */ - { - 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 */ + uint8_t c[4] = {cmd , param1, param2, param3}; + return send_core_cmd(c); } -/* - * Slave receiver function associated with the i2c ISR - * - * 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 */ +/* Send status to RF. */ +void send_status(uint8_t const *status) +{ + uint8_t i; -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) + if (FifoLength(statusFifo) <= INCOMING_BUF_SIZE - CMD_SIZE) + for (i = 0; i < CMD_SIZE; i++) + FifoPut(statusFifo, status[i]); + /* XXX what if stack is full? */ +} + +/* Send status to RF. */ +void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ + uint8_t param3) { + uint8_t c[4] = {cmd , param1, param2, param3}; + send_status(c); +} + +uint8_t pong_received; /* value of the pong received from the behavior */ +uint8_t pong_missed; /* counting the pong missed on the I2C */ + +void parse_core_cmd(uint8_t *data) +{ uint8_t i; - if (*receiveData < 0xC0) /* (audio) command to be executed, can't have 3 parameters */ + if (*data < 0xC0) + /* Audio command to be executed, can't have 3 parameters */ { - for (i = 0; i < receiveDataLength; i++) - audioBuf[i] = receiveData[i]; - audioBufIdx = receiveDataLength; + for (i = 0; i < CMD_SIZE; i++) + audioBuf[i] = data[i]; + audioBufIdx = CMD_SIZE; /* XXX only fill buffer if it's not full, need to add the check */ } - else /* fill in the statusFifo buffer */ + else + /* Status, forward to RF and testers */ { + /* Intercept some of them */ /* Pong check */ - if (receiveData[0] == PONG_CMD) + if (data[0] == PONG_CMD) { - if (pong_received-- < receiveData[1]) /* new ping, reset */ + if (pong_received-- < data[1]) /* new ping, reset */ { - pong_received = receiveData[1]; + pong_received = data[1]; pong_missed = 0; } - else if (pong_received > receiveData[1]) /* pongs missed */ + else if (pong_received > data[1]) /* pongs missed */ { pong_missed++; - pong_received = receiveData[1]; /* resync */ + pong_received = data[1]; /* resync */ } - receiveData[2] = pong_missed; + data[2] = pong_missed; } + send_status(data); + } +} - /* Store data on the fifo buffer */ - if (fifoLength(statusFifo) < INCOMING_FIFO_SIZE - MAX_COMMAND_SIZE) - for (i = 0; i < MAX_COMMAND_SIZE; i++) - pushFifo(statusFifo, receiveData[i]); - /* XXX add a return in case data was not added */ +/* + * Slave receiver function associated with the i2c ISR + * + * Only do a backup of the buffer so any new i2c data won't overwrite the + * previous ones + */ +void i2cMasterReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) +{ + if (*receiveData == 0) + /* Nothing to get. */ + return; + if (receiveDataLength != CMD_SIZE) + /* Error here. */ + return; + if (msg_in.addr == I2C_TUXCORE_ADDR) + /* From tuxcore */ + { + /* Parse commands */ + parse_core_cmd(receiveData); + /* If we got something, there's maybe more so continue. */ + statusFlag = 1; } } /* * Get a set of status commands from the statusFifo buffer. The command - * length will always be MAX_COMMAND_SIZE. Returns '1' if there's nothing to + * length will always be CMD_SIZE. Returns '1' if there's nothing to * get, '0' otherwise. * * 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)) + if (!FifoLength(statusFifo)) 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])) + for (i = 0; i < CMD_SIZE; i++) + if (FifoGet(statusFifo, &command[i])) { sei(); - return 1; /* fifo corrupted so drop data XXX add some debug feedback on this instead of dropping data */ + 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 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/communication.h 2008-05-06 09:38:42 UTC (rev 1110) @@ -22,34 +22,47 @@ #ifndef COMMUNICATION_H #define COMMUNICATION_H +#include <stdbool.h> + #include "common/commands.h" +#include "common/api.h" +#include "common/defines.h" +#include "varis.h" #include "fifo.h" #define COMMAND_BUF_SIZE 16 #define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ -#define MAX_COMMAND_SIZE 4 +#define CMD_SIZE 4 #define INCOMING_BUF_SIZE 32 #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 audioBuf[CMD_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 statusFlag; + extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ +/* /< XXX New clean commands */ +int8_t send_core_cmd(uint8_t *command); +int8_t send_core_cmd_p(uint8_t command, uint8_t param1, uint8_t param2, \ + uint8_t param3); +/* XXX /> */ + void i2cCommunicationInit(void); void initCommunicationBuffers(void); /* From RF to i2c */ -void sendCommands(void); -uint8_t pushCommands(uint8_t * command); +int8_t sendCommands(void); + /* From i2c to RF */ void acceptData(void); -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData); -void send_status(uint8_t status ,uint8_t byte1 ,uint8_t byte2 ,uint8_t byte3); +void i2cMasterReceiveService(uint8_t receiveDataLength, uint8_t * receiveData); +void send_status(uint8_t const *status); +void send_status_p(uint8_t cmd, uint8_t param1, uint8_t param2, \ + uint8_t param3); uint8_t popStatus(uint8_t * command); +void getStatus(void); -/* XXX move to a global definition file */ -#define AUDIO_STATE 0xE0 /* state of the audio interface */ - #endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/fifo.c =================================================================== --- firmware/tuxaudio/trunk/fifo.c 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/fifo.c 2008-05-06 09:38:42 UTC (rev 1110) @@ -19,228 +19,63 @@ /* $Id$ */ -#include <avr/io.h> -#include <inttypes.h> -#include "fifo.h" - /** \file fifo.c - \ingroup single_size_fifo - \brief Standard pointer fifo - - \section modulo Typecasts and modulo - - \note All wrap around now use '&' instead of '\%' because the size is a - variable and not a constant and the compiler can't optimize it itself - anymore. I still leave this notice for reference and in case someone wants - to change back to modulo. - - All functions that use modulo usually use typecasts - i.e. the following statement - - \code length = (p->inIdx - p->outIdx) % p->size; \endcode - - has a problem when (p->inIdx - p->outIdx) is <0. Then the - modulus is not done, the return value is 0xF9 for example. This is due to - the implicit promotion of the intermediate value to an int. - - "%" is a signed modulus, so -1 % 8 == -1. - - We need to trim down the intermediate result to a uint8_t result - immediately so the modulus applies to a uint8_t otherwise the implicit - promotion of a uint8_t argument to an int expression makes the expression - signed and brake the code for the above reason. The correct expression is - - \code length = ((uint8_t)(p->inIdx - p->outIdx) % p->size); \endcode - - So forgetting the typecast not only makes the code much bigger, it also - brake it when the intermediate result is negative. - + \brief Circular buffer (FIFO) */ -/** \name Accessors +#include <inttypes.h> +#include "fifo.h" - Functions to initialise, manipulate and get the status of the fifo buffer. */ +/** \weakgroup circular_buffer */ +/*! @{ */ -/* @{ */ -/** \ingroup single_size_fifo */ - -/** \brief Resets the indexes to an empty state (8b). - * \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) +/** \brief Empty the buffer by clearing the indexes. + * \param p Fifo pointer. + */ +void FifoClear(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; } -/** \brief Return TRUE if the fifo buffer is full (28b). - * \param p fifo pointer - * \return TRUE if fifo buffer is full +/** \brief Return TRUE if the buffer is full. + * \param p Fifo pointer. + * \return TRUE if the buffer is full, FALSE otherwise. */ -uint8_t isFifoFull(fifo_t * p) +uint8_t FifoFull(fifo_t const *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 (FifoLength(p) == p->size); } -/** \brief Return TRUE if the fifo buffer is empty (22b). - * \param p fifo pointer - * \return TRUE if fifo buffer is empty +/** \brief Add one data byte to the fifo buffer. + * \param p Fifo pointer. + * \param data Data byte to add to the queue. + * \return Return FIFO_OK if the data has been added, FIFO_FULL if the buffer + * was full and the data couldn't be added. */ -uint8_t isFifoEmpty(fifo_t * p) +int8_t FifoPut(fifo_t *p, uint8_t const data) { - return (p->outIdx == p->inIdx); -} + if (FifoLength(p) == p->size) + return FIFO_FULL; -/** \brief Return the number of elements in the fifo buffer (16b). - * \param p fifo pointer - * \return number of elements in the buffer - */ -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 */ + p->buffer[p->inIdx++ & (p->size-1)] = data; /* store data */ + return FIFO_OK; } -/** \brief Add one data byte to the fifo buffer (32b). - * \param p fifo pointer - * \param data data byte to add to the queue - * - * If the fifo is already full, return immediately without doing anything. +/** \brief Pop the oldest byte from the buffer. + * \param p Fifo pointer. + * \param data pointer for storing the data read from the queue + * \return FIFO_OK if a value has been popped out at the pointer address. If + * the fifo is empty, FIFO_EMPTY is returned and the pointed data is left + * unchanged. */ -void pushFifo(fifo_t * p, uint8_t data) +int8_t FifoGet(fifo_t *p, uint8_t *data) { - uint8_t inIdx; /* use of a local variable to reduce code size */ + if (p->outIdx == p->inIdx) + return FIFO_EMPTY; - 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 */ - } + *data = p->buffer[p->outIdx++ & (p->size-1)]; + return FIFO_OK; } -/** \brief Pop the oldest byte in the fifo (48b). - * \param p fifo pointer - * \param data pointer to store the data read from the queue - * \return success status - * - * Return '0' if a value has been popped out at the pointer address. If the - * 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) -{ - 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 */ - return 0; - } - else - return 1; -} - -/** \brief Pull the oldest byte from the fifo, always return something even if - * the fifo is empty (36b). - * \param p fifo pointer - * \return data read from the queue - * - * If the fifo is empty, the index is not decreased but the latest value is - * returned. - */ -uint8_t pullFifo(fifo_t * p) -{ - if (p->outIdx != p->inIdx) /* if fifo is not empty */ - { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ - } - return p->buffer[p->outIdx]; /* get data in all cases */ -} - -/*@}*/ - -/** - \name Adaptative functions - @{ -*/ -/** \ingroup single_size_fifo */ - -/** \brief 3 levels adaptative function. - * \param p fifo pointer - * - * High and low thresholds are used to differentiate 3 levels of the buffer. In - * each level, a custom code or a function call can be provided to do the - * adaptation. - */ -void adaptFifo(fifo_t * p) -{ - unsigned char fifoLevel; - - fifoLevel = fifoLength(p); - if (!p->adpt_cycle) - { - if (p->matched == 8) - { - if (OCR0A < 254) - p->pwm_max = OCR0A + 2; - else - p->pwm_max = 255; - if (OCR0A > 231) - p->pwm_min = OCR0A - 2; - else - p->pwm_min = 230; - p->matched = 9; - } - - if (fifoLevel >= FIFO_ADAPT_HIGH) - { - if (OCR0A > p->pwm_min) - { - OCR0A--; - p->pwm_adpt_sens = 1; - } - } - else if (fifoLevel < FIFO_ADAPT_LOW) - { - if (OCR0A < p->pwm_max) - { - OCR0A++; - p->pwm_adpt_sens = 2; - } - } - else - { - if (p->pwm_adpt_sens) - { - if ((p->pwm_adpt_sens) == 1) - { - if (OCR0A < p->pwm_max) - OCR0A++; - } - else - { - if (OCR0A > p->pwm_min) - OCR0A--; - } - p->pwm_adpt_sens = 0; - p->matched = 0; - } - else - { - if (p->matched != 9) - p->matched++; - } - } - } - p->adpt_cycle++; - p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1; -} - -/*@}*/ +/*! @} */ Modified: firmware/tuxaudio/trunk/fifo.h =================================================================== --- firmware/tuxaudio/trunk/fifo.h 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/fifo.h 2008-05-06 09:38:42 UTC (rev 1110) @@ -19,137 +19,144 @@ /* $Id$ */ -#ifndef FIFO_H -#define FIFO_H +/** \file fifo.h + \ingroup circular_buffer + \brief Circular buffer (FIFO) -/** \defgroup single_size_fifo Single size Fifo - \ingroup fifo + \section Internals - "fifo" is a general use fifo wich has been optimized for size. The fifo is - a structure of a data array pointer, it's size and input and output - indexes. The fifo buffer is never accessed directly by the application. - Therefore it has a couple of accessors to push/pop data or access - properties like status or length. + These routines are inspired from an article in Jack Ganssle's Embedded + Muse: http://www.ganssle.com/tem/tem110.pdf - All fifo sizes should have a value to the power of 2 so the wrap-around - (modulo), necessary when the index is at the end of the buffer array, - simplifies to a single AND operation. This greatly reduces the code size. - Maximum fifo size is 256. It is not possible to use any value for the fifo - size although this could be done by changing all '&' operations by '%' in - fifo.c but the code size will increase a lot. It would be more efficient to - change the wrap around to an 'if (inIdx == outIdx)' method. + The buffer size must be a power of 2 and is limited to 128. This simplyfies + the wrap-around to a single AND operation which is only applied when + accessing the buffer but not applied on the in and out indexes. The indexes + increase from 0 to 255 then wrap to 0. With this method, the buffer is + empty when the indexes are equal and is full when the difference is equal + to the buffer size. Thus we can't use a buffer of 256 as it wouldn't be + possible to differentiate the buffer when it's empty or full. +*/ - Note that the buffer can only hold the given size minus 1 (fifo->size - - 1) elements to be able to make the difference between completely full and - completely empty states. So if your fifo has a size of 128, it'll only hold - a maximum of 127 elements. +#ifndef _FIFO_H_ +#define _FIFO_H_ - Interrupts should be disabled before a call to an accessor if fifo's are - also manupilated in interrupts. It's up to the application to take care of - this. As all accessors are very short, it makes no sense to have the sei - and cli inside them, they would be at the beginning and end of the function - anyway. +/** \defgroup circular_buffer Circular buffer (FIFO) + This circular buffer module implements a minimal general use fifo. + + The fifo is a structure of a data array pointer, it's size, input and + output indexes. The fifo buffer itself is hidden from the + application. There are a couple of functions to put/get data or + access its properties. + + The buffer size must be a power of 2 and is limited to 128 (2, 4, + 8, 16, 32, 64, or 128). + + Interrupts should be disabled if you access a fifo from both interrupt + routines and the main code. + Usage: - use the following include: \code #include "fifo.h" \endcode - - create a buffer, a fifo structure and a pointer to it. The structure - should be initialized with a pointer to the buffer, the (size - 1) of the - buffer (see the structure definition for details) and input and output - indexes which should be reset. Replace FIFO_SIZE by a value or define it. - \code uint8_t testFifo_buf[FIFO_SIZE]; - fifo_t testFifo = {testFifo_buf, sizeof testFifo_buf-1, 0, 0}, *myFifo = &testFifo; + - instanciate a fifo with a given name and size. The size must be a power + of 2 and is limited to 128 (2, 4, 8, 16, 32, 64, or 128). + \code + FIFO_INSTANCE(fifo_name, FIFO_SIZE); \endcode + - declare a pointer to a fifo type and initialize it with the address of + the fifo you just created + \code + fifo_t *myFifo = FifoPointer(fifo_name); + \endcode - If you want multiple fifo's, just repeat the last step with other names for - the buffer, fifo and pointer. + You can instanciate multiple fifo with FIFO_INSTANCE and get the pointer to + them with FifoPointer(). +*/ - Test code: test_fifo.c +/* + * Hidden from the interface + */ - \section Internals +/** \brief Fifo structure type which holds the buffer, it's size, input and + * output indexes. + * + * This structure is hidden from the application and should not be accessed + * directly. + */ +typedef struct fifo_t fifo_t; +struct fifo_t { + /** buffer array */ + uint8_t *buffer; + /** size of the buffer */ + uint8_t const size; + /** input index, points to the next empty cell */ + uint8_t inIdx; + /** output index, points to the next value to get */ + uint8_t outIdx; +}; - fifo_s structure holds the stack buffer, it's size and 2 indexes. The input index - points to the last pushed value and the output index points to the last - popped value. +/** \addtogroup circular_buffer */ +/*! @{ */ - The fifo is empty when both indexes are equal which means that the last - pushed value has been popped. The fifo is full when the output index is - the input index +1. There's still one free space in the fifo when it's full - but we can't use it while keeping the fifo handling simple. +/** \brief Status which is returned by some functions. */ +enum FIFO_STATUS {FIFO_OK = 0, FIFO_FULL, FIFO_EMPTY}; - Here's a diagram that shows how indexes change while the fiffo is filled - and emptied. The fifo is 8 bytes long and indexes are intialized at 0. +/** \name Initialization */ +/*! @{ */ - \image html fifo_fifostates.png "Fifo states" +/* + * Initialization + */ -*/ +/** \brief This macro instanciates a fifo given its name and its size. The fifo + * can then be accessed with FifoPointer(). + * + * The macro declares the fifo buffer and a the fifo structure which holds the + * buffer, the size and the indexes. Using this macro somehow hides the + * structure from the application. + * + * The real buffer is named with the fifo name appended with _buf and the fifo + * structure is named with the fifo name appended with _struct. + */ +#define FIFO_INSTANCE(fifo_name, fifo_size) \ + uint8_t fifo_name##_buf[fifo_size]; \ + fifo_t fifo_name##_struct = {fifo_name##_buf, sizeof fifo_name##_buf, 0, 0} -/** \file fifo.h - \ingroup single_size_fifo - \brief Single size fifo +/** \brief Return the address of the fifo + * \param fifo_name Name of the fifo you defined with FIFO_INSTANCE. + * \return pointer to the fifo + * + * As the structure should be hidden from the application, this macro should + * be used to return the address of a given fifo. + */ +#define FifoPointer(fifo_name) (&fifo_name##_struct) -*/ +/*! @} */ +/** \name Interface */ +/*! @{ */ /* - * Adaptive parameters + * Interface */ -/** \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 */ -/** \brief UD- High level threshold */ -#define FIFO_ADAPT_HIGH 64 // (p->size - (p->size>>2)) /* 3/4 of size */ +/** \brief Return the number size of the fifo buffer. + * \param p Fifo pointer. + * \return Size of the buffer. + */ +#define FifoSize(p) (p->size) -/** \brief UD- Low level threshold */ -#define FIFO_ADAPT_LOW 17 // (p->size>>2) /* 1/4 of size */ +void FifoClear(fifo_t *p); +uint8_t FifoFull(fifo_t const *p); -#define FIFO_MATCHED_THRESHOLD 8 - -/** \brief Fifo structure type which holds the buffer, it's size, input and - * output indexes. - - 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 -{ - /** array that will store the elements */ - 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; - /** input index which indexes the last pushed value */ - uint8_t inIdx; - /** output index which indexes the last popped value */ - uint8_t outIdx; - /** current sens : increment or decrement pwm value */ - uint8_t pwm_adpt_sens; - /** cycle counter of adaptative function */ - uint8_t adpt_cycle; - /** counter of good pwm value */ - uint8_t matched; - /** min value of pwm range */ - uint8_t pwm_min; - /** max value of pwm range */ - uint8_t pwm_max; - -} fifo_t; - -/* - * Extern declarations +/** \brief Return the number of elements in the fifo buffer. + * \param p Fifo pointer. + * \return Number of elements in the buffer. */ +#define FifoLength(p) (uint8_t)(p->inIdx - p->outIdx) -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); +int8_t FifoPut(fifo_t *p, uint8_t const data); +int8_t FifoGet(fifo_t *p, uint8_t *data); -#endif /* FIFO_H */ +/*! @} */ +/*! @} */ +#endif /* _FIFO_H_ */ Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/flash.c 2008-05-06 09:38:42 UTC (rev 1110) @@ -144,19 +144,19 @@ ad[2] = 0; first_block = (ad[0] << 4) + (ad[1] >> 4); } - resetFifo(&PWMFifo); + FifoClear(PWMFifo); if (ad[0] > 0x07) { programming_state = PROG_END; - send_status(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); + send_status_p(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); } else programming_state ++; frame_without_sound = 5000; frame_without_sound_timeout = 5000; - send_status(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); + send_status_p(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); } else if (programming_state == PROG_INIT) @@ -177,12 +177,12 @@ if (sound_stored) { last_block = (ad[0] << 4) + (ad[1] >> 4); - send_status(STATUS_FLASH_PROG_CMD, WAITING_FOR_CONFIRMATION, last_block - first_block, 0); + send_status_p(STATUS_FLASH_PROG_CMD, WAITING_FOR_CONFIRMATION, last_block - first_block, 0); programming_state ++; } else { - send_status(STATUS_FLASH_PROG_CMD, NO_SOUND, 0, 0); + send_status_p(STATUS_FLASH_PROG_CMD, NO_SOUND, 0, 0); programming_state = PROG_END; } } @@ -195,7 +195,7 @@ } else if (write_toc == 2) { - send_status(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0); + send_status_p(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0); if (first_block == 0) { eraseFlag = 1; @@ -214,7 +214,7 @@ } else if (programming_state == PROG_TOC) { - send_status(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); + send_status_p(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); numSound ++; index = (numSound * 3) + 1; program_flash(0x00, (index>>8), (index & 0xFF), ad[0]); @@ -233,12 +233,41 @@ programmingFlash = 0; TIMSK0 = 0x01; //info_flg = 1; - send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); - send_status(SOUND_VAR_CMD, numSound, last_block, 0); + send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); } } /** + * \ingroup flash + * \brief Active the deep power-down mode + * + * This mode active the deep-power mode. The consumption will pass to 8mA from + * 20uA. + */ +void enter_deep_sleep(void) +{ + flash_enable(); + flash_select(); + spiSend(DEEP_POWER_MODE); + flash_unselect(); +} + +/** + * \ingroup flash + * \brief Leave the deep power_down mode + * + * This function will resume the flash memory from the deep power-down mode. + */ +void leave_deep_sleep(void) +{ + flash_enable(); + flash_select(); + spiSend(RESUME_DEEP_MODE); + flash_unselect(); +} + +/** * \ingroup flash \brief Erase the flash memory. @@ -256,7 +285,7 @@ } else if (!(read_status() & BUSY)) { - //send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + //send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); enter = 1; eraseFlag = 0; program_flash(0x00, 0x00, 0x00, 0xFE); @@ -265,8 +294,8 @@ program_flash(0x00, 0x00, 0x03, 0x00); numSound = 0; last_block = 0; - send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); - send_status(SOUND_VAR_CMD, numSound, last_block, 0); + send_status_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + send_status_p(SOUND_VAR_CMD, numSound, last_block, 0); //info_flg = 1; TIMSK0 = 0x01; } @@ -397,7 +426,7 @@ } } } - resetFifo(&PWMFifo); + FifoClear(PWMFifo); flash_select(); // Chip Select spiSend(0x03); // Send Read Page Command @@ -421,11 +450,11 @@ static void playingSound(void) { uint8_t sound; - while (!spi_start && !isFifoFull(&PWMFifo)) + while (!spi_start && !FifoFull(PWMFifo)) { sound = spiSend(0x00); // Wait response sound = sound >> audioLevel; - pushFifo(&PWMFifo, sound); + FifoPut(PWMFifo, sound); ad[2]++; // Increment address for next play if (ad[2] == 0) @@ -461,7 +490,7 @@ { soundToPlay = 0; flashPlay = 0; - send_status(STATUS_AUDIO_CMD, 0, 0, 0); + send_status_p(STATUS_AUDIO_CMD, 0, 0, 0); PORTB |= 0x01; // Set the HOLD signal PORTB |= 0x02; // Chip Deselect } @@ -475,17 +504,18 @@ The second step is to send the OP code and a data to write. This function perform the first step. - */ + */ static void init_programming(uint8_t adi0, uint8_t adi1, uint8_t adi2) { + uint8_t data; write_enable(); - flash_select(); - spiSend(SEQU_PROGRAM); - spiSend(adi0); + flash_select(); + spiSend(SEQU_PROGRAM); + spiSend(adi0); spiSend(adi1); spiSend(adi2); - if (!isFifoEmpty(&PWMFifo)) - spiSend(pullFifo(&PWMFifo)); + if (FifoGet(PWMFifo, &data) == FIFO_OK) + spiSend(data); else spiSend(0x80); @@ -518,15 +548,17 @@ { while (!spi_start) { - if (!isFifoEmpty(&PWMFifo)) + if (FifoLength(PWMFifo)) { + uint8_t data; sound_stored = 1; frame_without_sound = STOP_FRAME_NUMBER; frame_without_sound_timeout = STOP_FRAME_NUMBER; flash_select(); spiSend(SEQU_PROGRAM); - spiSend(pullFifo(&PWMFifo)); + FifoGet(PWMFifo, &data); + spiSend(data); flash_unselect(); ad[2] ++; Modified: firmware/tuxaudio/trunk/flash.h =================================================================== --- firmware/tuxaudio/trunk/flash.h 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/flash.h 2008-05-06 09:38:42 UTC (rev 1110) @@ -73,6 +73,8 @@ extern void erase(void); extern uint8_t readFlashNumber(void); extern uint8_t readLastBlock(uint8_t num); +extern void enter_deep_sleep(void); +extern void leave_deep_sleep(void); /** start / end flash states flag */ extern uint8_t flash_state; Modified: firmware/tuxaudio/trunk/hardware.h =================================================================== --- firmware/tuxaudio/trunk/hardware.h 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/hardware.h 2008-05-06 09:38:42 UTC (rev 1110) @@ -24,6 +24,24 @@ #ifndef _HARDWARE_H_ #define _HARDWARE_H_ +/** VCC mask. */ +#define VCC_MK _BV(PD6) +/** VCC PIN. */ +#define VCC_PIN PIND +/** VCC PORT. */ +#define VCC_PT PORTD +/** VCC DDR. */ +#define VCC_DDR DDRD + +/** RF reset mask. */ +#define RF_RESET_MK _BV(PB7) +/** RF reset PIN. */ +#define RF_RESET_PIN PINB +/** RF reset PORT. */ +#define RF_RESET_PT PORTB +/** RF reset DDR. */ +#define RF_RESET_DDR DDRB + /* Flash memory port */ #define FLASH_PORT PORTB #define FLASH_CS_PIN _BV(PB1) Modified: firmware/tuxaudio/trunk/i2c.c =================================================================== --- firmware/tuxaudio/trunk/i2c.c 2008-05-06 09:27:01 UTC (rev 1109) +++ firmware/tuxaudio/trunk/i2c.c 2008-05-06 09:38:42 UTC (rev 1110) @@ -19,122 +19,92 @@ /* $Id$ */ +/*@{*/ #include <avr/io.h> #include <avr/interrupt.h> #include "i2c.h" -#include "communication.h" +#define TWI_TWCR (_BV(TWINT) | _BV(TWIE) | _BV(TWEN)) + /* + * I2C constants. + */ +/** Value of the R/W bit when sending the slave address in read mode. */ +#define I2C_R_BIT 1 +/** Value of the R/W bit when sending the slave address in write mode. */ +#define I2C_W_BIT 0 + +/* * 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 */ +/* If set, store in a ring buffer all I2C status that occur. */ +#define __i2c_debug__ 0 +/* If set, some signals will be output on 3 pins, see below. */ +#define __i2c_signals__ 0 /* DEBUG definitions and variables */ #if (__i2c_debug__) -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 i2cStatusIdx; +#define I2C_DBG_STACK_SIZE 16 +/* Debug stack, it's a ring buffer that hold all TWI status codes. */ +uint8_t twi_debug_stack[I2C_DBG_STACK_SIZE]; +uint8_t twi_debug_stack_idx = 0; #endif #if (__i2c_signals__) -/* The START signal is set when a start is requested and reset when the TWI interrupt happens. Either the start is issued and the signal is reset when the interrupt occurs, or the TWI bus was already busy and the signal is only reset when the SLA+W interrupt will happen and no start will be issued this time */ -#define START_PT PORTD -#define START_MK 0x01 +/* The START signal is set when a start is requested and reset when the TWI + * interrupt happens. Either the start is issued and the signal is reset when + * the interrupt occurs, or the TWI bus was already busy and the signal is only + * reset when the SLA+W interrupt will happen and no start will be issued this + * time */ +#define START_PT PORTC +#define START_MK 0x04 #define START_DDR DDRD /* The ISR signal is set at the beginning of the TWI ISR and reset at the end of the interrupt */ -#define ISR_PT PORTD -#define ISR_MK 0x02 +#define ISR_PT PORTC +#define ISR_MK 0x08 #define ISR_DDR DDRD -/* The BUSY signal is the same as i2cFlags.i2c_busy and is set when a start is issued or an TWI slave address is recognized. It is reset at the end of communication when a stop is sent or received */ +/* The BUSY signal is the same as I2C_BUSY and is set when a start is issued or an TWI slave address is recognized. It is reset at the end of communication when a stop is sent or received */ #define BUSY_PT PORTD #define BUSY_MK 0x80 #define BUSY_DDR DDRD -#endif +#endif /* __i2c_signals__ */ /* 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 */ +/** High level status of the I2C module. */ +static enum i2c_state i2c_state; +/** Pointer to the currently processed I2C message. */ +static struct i2c_msg *m_msg; +/** SLA+R/W value. */ +static uint8_t sla_rw; +/** Index for the message buffer. */ +static volatile uint8_t buf_idx; -/* 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; -uint8_t i2cReceiveDataLength; - /* 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, +static void (*i2c_master_receive) (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); -/* functions */ -/* - * Set the TWI transaction bitrate - */ -void i2cSetBitrate(void) -{ - /* For processors with additional bitrate division, we set the prescaler */ -#ifdef TWPS0 - TWSR = I2C_TWSR; -#endif +//i2c_exit(); +//i2c_master_send(); +//i2c_master_recv(); +//static int xfer_read(struct i2c_adapter *adap, unsigned char *buf, int length); + //i2c_suspend(); + //i2c_resume(); - /* 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 */ -#else - TWBR = I2C_TWBR; -#endif -} - -/* - * This function initializes the TWI interface for i2c communication. You - * should use the definitions in i2c.h to select the mode you want. - * - * Note that you should set the i2cSlaveReceive and i2cSlaveTransmit handlers - * after this initialization otherwise they'll be cleared. - */ -void i2cInit(void) -{ - /* Set bitrate */ - i2cSetBitrate(); - - /* 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 */ -#endif - -#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 -#ifdef TWI_M_ENABLED - TWCR = I2C_MODE; /* enable TWI */ -#endif -#endif -} - /* Set the user function which handles receiving (incoming) data as a slave */ void -i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func) +i2c_master_receive_handler(void (*i2cMasterRx_func) (uint8_t receiveDataLength, uint8_t * recieveData)) { - i2cSlaveReceive = i2cSlaveRx_func; + i2c_master_receive = i2cMasterRx_func; } /* Set the user function which handles transmitting (outgoing) data as a slave */ @@ -146,288 +116,320 @@ i2cSlaveTransmit = i2cSlaveTx_func; } -static inline void i2cSendStart(void); - -/* - * Start a Master transmission - */ -void i2cMasterStart(void) +static inline void twi_reset(void) { - 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 */ - /* 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 - * still be in ISR when the start occurs and won't detect it because the - * TWI hardware is said to be partly disabled when TWINT is set. - * Two things to do here, exit the ISR as soon as possible in the slave, - * and add some delay between a stop and a start in the master. Use a - * repeated start condition in such a case. */ - 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 */ -#endif -} - -static inline void i2cReset(void) -{ #if (__i2c_debug__) - i2cStatusIdx %= 32; - i2cStatus[i2cStatusIdx++] = 0x02; + twi_debug_stack_idx %= I2C_DBG_STACK_SIZE; + twi_debug_stack[twi_debug_stack_idx++] = 0x02; #endif - 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 */ #endif - // TWCR = I2C_MODE; - TWCR |= I2C_MODE; + /* In case we lost arbitration, we still want to send the start later on so + * we should 'OR' here and not simply assign. */ + TWCR |= TWI_TWCR; } -static inline void i2cSendStart(void) +/** Send a START or repeated START condition on the bus. + * If a STOP condition just occurred on the bus, a START will be sent. + * Otherwise a repeated START will be sent. */ +static inline void twi_send_start(void) { #if (__i2c_debug__) - cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ - i2cStatusIdx %= 32; - i2cStatus[i2cStatusIdx++] = 0x03; + cli(); /* we need to protect this from an i2c interrupt that will corrupt + those values otherwise */ + twi_debug_stack_idx %= I2C_DBG_STACK_SIZE; + twi_debug_stack[twi_debug_stack_idx++] = 0x03; sei(); #endif - // TWCR = (TWCR & TWCR_CMD_MASK) | _BV(TWSTA); - TWCR = _BV(TWSTA) | I2C_MODE; + TWCR = _BV(TWSTA) | TWI_TWCR; } -static inline void i2cSendStop(void) +static inline void twi_send_stop(void) { #if (__i2c_debug__) - i2cStatusIdx %= 32; - i2cStatus[i2cStatusIdx++] = 0x04; + twi_debug_stack_idx %= I2C_DBG_STACK_SIZE; + twi_debug_stack[twi_debug_stack_idx++] = 0x04; #endif - TWCR = _BV(TWSTO) | I2C_MODE; - i2cFlags.i2c_busy = 0; + TWCR = _BV(TWSTO) | TWI_TWCR; #if (__i2c_signals__) BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif } -static inline void i2cSendByte(uint8_t data) +static inline void twi_send_data(uint8_t data) { #if (__i2c_debug__) - i2cStatusIdx %= 32; - i2cStatus[i2cStatusIdx++] = 0x05; + twi_debug_stack_idx %= I2C_DBG_STACK_SIZE; + twi_debug_stack[twi_debug_stack_idx++] = 0x05; #endif TWDR = data; - TWCR = I2C_MODE; + /* Just clear the interrupt flag. */ + TWCR = TWI_TWCR; } -static inline void i2cAckReceiveByte(void) +static inline uint8_t twi_get_data(void) { - TWCR |= _BV(TWEA); + return TWDR; } -static inline void i2cNackReceiveByte(void) +static inline void twi_return_ack(void) { - TWCR &= ~_BV(TWEA); + TWCR = TWI_TWCR | _BV(TWEA); } -static inline uint8_t i2cGetReceivedByte(void) +static inline void twi_return_nack(void) { - return TWDR; + TWCR = TWI_TWCR & ~_BV(TWEA); } -static inline uint8_t i2cGetStatus(void) +static inline uint8_t twi_get_status(void) { return TWSR; } -/* TWI interrupt service routine */ -#ifdef TWI_INT_ENABLED -ISR(SIG_TWI) +static inline uint8_t twi_poll_status(void) { - const static void *twiLookupTable[] = { - &&case_TW_BUS_ERROR, - &&case_TW_START, - &&case_TW_REP_START, - &&case_TW_MT_SLA_ACK, - &&case_TW_MT_SLA_NACK, - &&case_TW_MT_DATA_ACK, - &&case_TW_MT_DATA_NACK, - &&case_TW_MT_ARB_LOST, - &&case_TW_MR_SLA_ACK, - &&case_TW_MR_SLA_NACK, - &&case_TW_MR_DATA_ACK, - &&case_TW_MR_DATA_NACK, - &&case_TW_SR_SLA_ACK, - &&case_TW_SR_ARB_LOST_SLA_ACK, - &&case_TW_SR_GCALL_ACK, - &&case_TW_SR_ARB_LOST_GCALL_ACK, - &&case_TW_SR_DATA_ACK, - &&case_TW_SR_DATA_NACK, - &&case_TW_SR_GCALL_DATA_ACK, - &&case_TW_SR_GCALL_DATA_NACK, - &&case_TW_SR_STOP, - &&case_TW_ST_SLA_ACK, - &&case_TW_ST_ARB_LOST_SLA_ACK, - &&case_TW_ST_DATA_ACK, - &&case_TW_ST_DATA_NACK, - &&case_TW_ST_LAST_DATA, - &&case_, - &&case_, - &&case_, - &&case_, - &&case_, - &&case_TW_NO_INFO, - }; + while (!(TWCR & _BV(TWINT))); ... [truncated message content] |
From: Paul_R <c2m...@c2...> - 2008-05-06 09:27:01
|
Author: Paul_R Date: 2008-05-06 11:27:01 +0200 (Tue, 06 May 2008) New Revision: 1109 Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 firmware/fuxusb/branches/usb_cleanup/main.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Added new modules (usb_misc and usb_endpoints). Many parts of usb_task have been moved into these new modules. * Reindent. i2c.c Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -306,29 +306,29 @@ void i2c_task(void) { - if (i2c_wait_counter) - /* Wait */ - ; - else if (i2c_task_on_Flag) + if (i2c_wait_counter) + /* Wait */ + ; + else if (i2c_task_on_Flag) + { + /* Send data through I2C */ + bl_senddata(blHeader, 64); +#ifdef BOOTLOAD_DEBUG + printf ("I2C: Send data"); + while (i2cFlags.i2c_busy) { - /* Send data through I2C */ - bl_senddata(blHeader, 64); -#ifdef BOOTLOAD_DEBUG - printf ("I2C: Send data"); - while (i2cFlags.i2c_busy) - { - uint8_t i; - for (i=0; i<0xFF; i++); - printf ("."); - } - printf (" [OK]\n"); + uint8_t i; + for (i=0; i<0xFF; i++); + printf ("."); + } + printf (" [OK]\n"); #else - while (i2cFlags.i2c_busy); + while (i2cFlags.i2c_busy); #endif - /* Wait 20ms before next I2C */ - i2c_wait_counter = 20; - /* ACK or NACK and exit I2C task */ - usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); - i2c_task_on_Flag = 0; - } + /* Wait 20ms before next I2C */ + i2c_wait_counter = 20; + /* ACK or NACK and exit I2C task */ + usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); + i2c_task_on_Flag = 0; + } } Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 =================================================================== --- firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 09:27:01 UTC (rev 1109) @@ -17,6 +17,8 @@ File 2,1,<.\usb\usb_task.c><usb_task.c> 0x0 File 2,1,<.\usb\usb_enum.c><usb_enum.c> 0x0 File 2,1,<.\usb\usb_drv.c><usb_drv.c> 0x0 +File 2,1,<.\usb\usb_misc.c><usb_misc.c> 0x0 +File 2,1,<.\usb\usb_endpoints.c><usb_endpoints.c> 0x0 File 3,1,<.\spi\spi_task.c><spi_task.c> 0x0 File 3,1,<.\spi\spi_lib.c><spi_lib.c> 0x0 File 4,1,<.\bootloader\bootloading.c><bootloading.c> 0x0 @@ -54,7 +56,7 @@ EnvLib () EnvReg () OrgReg () - TgStat=11 + TgStat=0 OutDir (.\obj\) OutName (fuxusb.aof) GenApp=1 Modified: firmware/fuxusb/branches/usb_cleanup/main.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -70,5 +70,14 @@ printf("\n\n= TUX started ==\n"); #endif while(1) + { usb_task(); + + /* XXX + if (BOOT_MODE) + bootloader_task(); + else + spi_task(); + */ + } } Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,364 @@ +#include "global.h" +#include "config.h" +#include "usb/usb_endpoints.h" +#include "usb/usb_drv.h" +#include "usb/usb_task.h" +#include "usb/usb_enum.h" +#include "spi/spi_task.h" +#include "bootloader/bootloading.h" +#include "modules/fifo/fifo.h" +#include "modules/fifo/fifo_spk.h" +#include "modules/fifo/fifo_mic.h" +#include "modules/fifo_stt/fifo_stt.h" +#include "lib_mcu\fa-usb\flash_api.h" + +static void ep_enum(void); +static void ep_cmd_in(void); +static void ep_cmd_out(void); +static void ep_spk(void); +static void ep_tts(void); +static void ep_mic(void); +static void tux_command_parser (unsigned char* commands, unsigned char data_length); +static void usb_command_parser(void); + +void endpoints_ctr(void) +{ + if (Usb_test_it_ep(EP_CMD_IN)) + { + ep_cmd_in(); + } + + if (Usb_test_it_ep(0)) + { + ep_enum(); + } + + if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) + { + ep_tts(); + } + + if(Usb_test_it_ep(EP_AUDIO_OUT)) + { + ep_spk(); + } + + if(Usb_test_it_ep(EP_AUDIO_IN)) + { + ep_mic(); + } + + if(USB_ParserProcess_Permit_Flag) + { + if(Usb_test_it_ep(EP_CMD_OUT)) + { + ep_cmd_out(); + } + } +} + + +static void ep_enum(void) +{ + Usb_select_ep(EP_CONTROL); + if (Usb_setup_received()) + { +#ifdef USB_TASK_DEBUG + printf("Go to Enum process\n"); +#endif + usb_enumeration_process(); + } +} + + +static void ep_cmd_in(void) +{ + Usb_select_ep(EP_CMD_IN); + if(Usb_tx_complete()) + { + Usb_clear_tx_complete(); + CMD_IN_Bank_Nb--; + if (CMD_IN_Bank_Nb<0) + CMD_IN_Bank_Nb = 0; + if (CMD_IN_Bank_Nb != 0) + Usb_set_tx_ready(); + } +} + +static void ep_tts(void) +{ + uint8_t i; + Usb_select_ep(EP_AUDIO_OUT_TTS); + + if(usb_get_nb_byte()) + if(Speaker_TTS_Select_Flag) + { + i=8; + do + { + // Use Only one Call to Get 8 Bytes + FIFO_SPK_put(Usb_read_byte()); + i--; + }while(i); + } + Usb_clear_rx(); +} + +static void ep_spk(void) +{ + uint8_t i; + //DEBUG_1 = 1; + Usb_select_ep(EP_AUDIO_OUT); + + if(usb_get_nb_byte()) + if(Speaker_TTS_Select_Flag==0) + { + i=8; + do + { + // Use Only one Call to Get 8 Bytes + FIFO_SPK_put(Usb_read_byte()); + i--; + }while(i); + } + Usb_clear_rx(); + //DEBUG_1 = 0; + +} + +static void ep_mic(void) +{ + Usb_select_ep(EP_AUDIO_IN); + if(Usb_tx_complete()) + { + Usb_clear_tx_complete(); + // -> Enable a new Loading of the FIFO + EP_AUDIOIN_Loaded = 0; + } +} + +static void ep_cmd_out(void) +{ + uint8_t i; +#ifdef FIFO_DEBUG + printf("CMD OUT\n"); +#endif + if(!USBCommand_NewRequest_Flag) + { + //DEBUG_2 = 1; + Usb_select_ep(EP_CMD_OUT); + //DEBUG_2 = 0; + if(Usb_rx_complete()) + { + // Capture the number of Byte in USB FIFO + USBCommand_Ctr = usb_get_nb_byte(); + // Read the Header + USBCommand_Header = Usb_read_byte(); + //-------------------------------------------------------------------------- + // + // TUX CMD HEADER received + // -> Store Data in USBCommand_ForRF[] + // -> USBCommand_NewRequest_Flag = 1 + // to inform SPI_task that a new command is arrived + // + //-------------------------------------------------------------------------- + if(USBCommand_Header == LIBUSB_TUX_CMD_HDR) + { + if (!RF_OFFLINE) + USBCommand_NewRequest_Flag = 1; + for(i=0;i<(USBCommand_Ctr-1);i++) + USBCommand_ForRF[i] = Usb_read_byte(); + tux_command_parser(USBCommand_ForRF, \ + USBCommand_Ctr); + } + + /* + * DONGLE CMD HEADER received + */ + else if(USBCommand_Header == LIBUSB_DONGLE_CMD_HDR) + { + for(i=0;i<(USBCommand_Ctr-1);i++) + USBCommand_ForDongle[i] = Usb_read_byte(); +#ifdef FIFO_DEBUG + printf("usb command parser\n"); +#endif + usb_command_parser(); + /* Request processed */ + USBCommand_NewRequest_Flag = 0; + } + + /* + * BOOTLOADER HEADER received + */ + else if(USBCommand_Header == + LIBUSB_BOOTLOADER_CMD_HDR) + { + bootloader_task(); + } + + + /* Clear the bank */ + Usb_select_ep(EP_CMD_OUT); + if (CMD_OUT_Bank_Nb == 0 && Usb_rx_bank0_complete()) + { +#ifdef USB_TASK_DEBUG + printf ("USB: clear bank 0\n"); +#endif + Usb_clear_rx_bank0(); + CMD_OUT_Bank_Nb = 1; + } + else if(CMD_OUT_Bank_Nb == 1 && \ + Usb_rx_bank1_complete()) + { +#ifdef USB_TASK_DEBUG + printf ("USB: clear bank 1\n"); +#endif + Usb_clear_rx_bank1(); + CMD_OUT_Bank_Nb = 0; + } +#ifdef USB_TASK_DEBUG + else + { + printf ("USB: ERROR bank synchronisation\n"); + if (Usb_rx_bank1_complete()) + Usb_clear_rx_bank1(); + else + Usb_clear_rx_bank0(); + } +#endif + } + } +} + +/** + * Parse generic tux commands and process those addressed to the dongle. + */ +static void tux_command_parser (unsigned char* commands, unsigned char data_length) +{ + unsigned char i = 0; + + while (data_length > i) + { + + if (commands[i] == INFO_FUXUSB_CMD) + { + // VERSION_CMD + //------------------------------------- + FIFO_STT_put(info_version.version_cmd); + FIFO_STT_put(info_version.cpu_ver_maj); + FIFO_STT_put(info_version.ver_minor); + FIFO_STT_put(info_version.ver_update); + + // REVISION_CMD + //------------------------------------- + FIFO_STT_put(info_revision.revision_cmd); + FIFO_STT_put((info_revision.revision&0xFF00)>>8); + FIFO_STT_put((info_revision.revision&0x00FF)); + FIFO_STT_put(info_revision.release_type); + + // AUTHOR_CMD + //------------------------------------- + FIFO_STT_put(info_author.author_cmd); + FIFO_STT_put((info_author.author_id&0xFF00)>>8); + FIFO_STT_put((info_author.author_id&0x00FF)); + FIFO_STT_put(info_author.variation); + } + i+=4; + + } +} + +/*F************************************************************************** + * NAME: usb_command_parser + *---------------------------------------------------------------------------- + * PARAMS: + * delay: none + * return: none + *---------------------------------------------------------------------------- + * PURPOSE: + * This function initializes the USB controller and the associated variables. + *---------------------------------------------------------------------------- + * EXAMPLE: + *---------------------------------------------------------------------------- + * NOTE: + *---------------------------------------------------------------------------- + * REQUIREMENTS: + *****************************************************************************/ +static void usb_command_parser(void) +{ + + long tc; // R modif + + //-------------------------------------------------------------------------- + // Read Status from RF + //-------------------------------------------------------------------------- + if (USBCommand_ForDongle[0] == 0x01) + { + if (USBCommand_ForDongle[1] == 0x00) + { + if(USBCommand_ForDongle[2] == 0x00) + { + + // Read Status from RF + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0x00) + { + //DEBUG_2 = 1; + USB_Status_NewCmd_Flag = TRUE; + //DEBUG_2 = 0; + } + // Complete reset + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0xfe) + { + IEN0 = 0; + IEN1 = 0; + SPCON = 0x14; + tc=10000; + Usb_detach(); + while(tc) tc --; //tempo(TIMER_5_MS); + Usb_attach(); + WDTRST = 0x1E; + WDTRST = 0xE1; + while(1); + } + // Jump in ISP Mode + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0xff) + { + //--------------------------- + IEN0 = 0; + IEN1 = 0; + SPCON = 0x14; + __api_clr_BLJB(); + __api_wr_SBV (0xF4); + tc=10000; + + Usb_detach(); + while(tc) tc --; //tempo(TIMER_5_MS); + Usb_attach(); + __api_start_bootloader(); + WDTRST = 0x1E; + WDTRST = 0xE1; + while(1); + } + } + } + } + //------------------------------------------------------------------------- + // Text To Speech + // + // USBCommand_ForDongle[1] == 0x01 Text To Speech Selected + // USBCommand_ForDongle[1] == 0x00 Text To Speech UnSelected + //------------------------------------------------------------------------- + if (USBCommand_ForDongle[0] == 0x02) + { + if (USBCommand_ForDongle[1] == 0x01) + Speaker_TTS_Select_Flag = 1; + + else if (USBCommand_ForDongle[1] == 0x00) + Speaker_TTS_Select_Flag = 0; + } +} + + Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1 @@ +void endpoints_ctr(void); Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,99 @@ +#include "global.h" +#include "config.h" +#include "usb/usb_misc.h" +#include "usb/usb_drv.h" +#include "usb/usb_enum.h" +#include "spi/spi_task.h" +#include "modules/fifo/fifo.h" +#include "modules/fifo/fifo_spk.h" +#include "modules/fifo/fifo_mic.h" +#include "modules/fifo_stt/fifo_stt.h" + +/** + * This function is used to resume the usb communication. + */ +void resume(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_resume \n"); +#endif + Usb_clear_suspend_clock(); + usb_connected_Flag = TRUE; + Usb_clear_suspend(); + Usb_clear_resume(); + Usb_clear_sof(); +} + +/** + * Suspend the usb bus. + */ +void suspend(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_suspend \n"); +#endif + usb_connected_Flag = FALSE; + Led_0_off(); + rf_reset_signal = 0; + Usb_clear_suspend(); + Usb_set_suspend_clock(); +} + +/** + * Reset the communication + */ +void reset(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_reset \n"); +#endif + Usb_clear_reset(); + usb_var_init(); + usb_connected_Flag = TRUE; + spi_task_init(); + FIFO_SPK_init(); + FIFO_MIC_init(); + FIFO_STT_init(); + Led_0_off(); + rf_reset_signal = 0; +} + + +void led_behavior(void) +{ + if(RF_OFFLINE) + { + if(RF_OFFLine_Back == 0) + { + Configure_led(0,LED_PORT_2MA); + usb_sof_counter = 0; + RF_OFFLine_Back = 1; + } + if (usb_sof_counter == 0x00) + Led_0_off(); + if (usb_sof_counter == 0x2FF) + Led_0_on(); + if (usb_sof_counter == 0x3FF) //==> Time Base = 1sec + usb_sof_counter = 0xFFFE; + + + } + else // RF ON Line + { + if(RF_OFFLine_Back == 1) + { + Configure_led(0,LED_PORT_10MA); + usb_sof_counter = 0; + RF_OFFLine_Back = 0; + } + { + if (usb_sof_counter == 0x00) + Led_0_off(); + if (usb_sof_counter == 0x10) + Led_0_on(); + if (usb_sof_counter == 0x20) //Time Base = 1sec + usb_sof_counter = 0xFFFE; + } + } +} + Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,4 @@ +void resume(void); +void reset(void); +void suspend(void); +void led_behavior(void); Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -15,7 +15,9 @@ #include "rf.h" #include "spi\spi_lib.h" #include "usb\usb_drv.h" -#include "lib_mcu\fa-usb\flash_api.h" +#include "usb/usb_misc.h" +#include "usb/usb_endpoints.h" + #include "usb\usb_task.h" #include "spi\spi_task.h" #include "usb\usb_enum.h" @@ -191,160 +193,12 @@ -/*F************************************************************************** - * NAME: usb_command_parser - *---------------------------------------------------------------------------- - * PARAMS: - * delay: none - * return: none - *---------------------------------------------------------------------------- - * PURPOSE: - * This function initializes the USB controller and the associated variables. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -void usb_command_parser(void) -{ - long tc; // R modif - //-------------------------------------------------------------------------- - // Read Status from RF - //-------------------------------------------------------------------------- - if (USBCommand_ForDongle[0] == 0x01) - { - if (USBCommand_ForDongle[1] == 0x00) - { - if(USBCommand_ForDongle[2] == 0x00) - { - - // Read Status from RF - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0x00) - { - //DEBUG_2 = 1; - USB_Status_NewCmd_Flag = TRUE; - //DEBUG_2 = 0; - } - // Complete reset - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0xfe) - { - IEN0 = 0; - IEN1 = 0; - SPCON = 0x14; - tc=10000; - Usb_detach(); - while(tc) tc --; //tempo(TIMER_5_MS); - Usb_attach(); - WDTRST = 0x1E; - WDTRST = 0xE1; - while(1); - } - // Jump in ISP Mode - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0xff) - { - //--------------------------- - IEN0 = 0; - IEN1 = 0; - SPCON = 0x14; - __api_clr_BLJB(); - __api_wr_SBV (0xF4); - tc=10000; - - Usb_detach(); - while(tc) tc --; //tempo(TIMER_5_MS); - Usb_attach(); - __api_start_bootloader(); - WDTRST = 0x1E; - WDTRST = 0xE1; - while(1); - } - } - } - } - //------------------------------------------------------------------------- - // Text To Speech - // - // USBCommand_ForDongle[1] == 0x01 Text To Speech Selected - // USBCommand_ForDongle[1] == 0x00 Text To Speech UnSelected - //------------------------------------------------------------------------- - if (USBCommand_ForDongle[0] == 0x02) - { - if (USBCommand_ForDongle[1] == 0x01) - Speaker_TTS_Select_Flag = 1; - - else if (USBCommand_ForDongle[1] == 0x00) - Speaker_TTS_Select_Flag = 0; - } -} - -/** - * Parse generic tux commands and process those addressed to the dongle. - */ -void tux_command_parser (unsigned char* commands, unsigned char data_length) -{ - unsigned char i = 0; - - while (data_length > i) - { - - if (commands[i] == INFO_FUXUSB_CMD) - { - // VERSION_CMD - //------------------------------------- - FIFO_STT_put(info_version.version_cmd); - FIFO_STT_put(info_version.cpu_ver_maj); - FIFO_STT_put(info_version.ver_minor); - FIFO_STT_put(info_version.ver_update); - - // REVISION_CMD - //------------------------------------- - FIFO_STT_put(info_revision.revision_cmd); - FIFO_STT_put((info_revision.revision&0xFF00)>>8); - FIFO_STT_put((info_revision.revision&0x00FF)); - FIFO_STT_put(info_revision.release_type); - - // AUTHOR_CMD - //------------------------------------- - FIFO_STT_put(info_author.author_cmd); - FIFO_STT_put((info_author.author_id&0xFF00)>>8); - FIFO_STT_put((info_author.author_id&0x00FF)); - FIFO_STT_put(info_author.variation); - } - i+=4; - - } -} - /*F************************************************************************** * NAME: usb_task *---------------------------------------------------------------------------- - * PARAMS: - * delay: none - * return: none - *---------------------------------------------------------------------------- * PURPOSE: - * This function manages the USB communication - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ - - - -/*F************************************************************************** - * NAME: usb_task - *---------------------------------------------------------------------------- - * PURPOSE: * This part manages the USB communication *---------------------------------------------------------------------------- * NOTE: @@ -355,70 +209,16 @@ if (!usb_connected_Flag) { if (Usb_resume()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_resume \n"); -#endif - Usb_clear_suspend_clock(); - usb_connected_Flag = TRUE; - Usb_clear_suspend(); - Usb_clear_resume(); - Usb_clear_sof(); - //FIFO_SPK_init(); - //FIFO_MIC_init(); - //spi_task_init(); - } + resume(); } else { -//-------------------------------------------------------------------------- -// -// USB Suspend and Reset -// -//-------------------------------------------------------------------------- - if(USB_suspend_resume_reset()) - { -//-------------------------------------------------------------------------- -// -// USB Suspend -// -//-------------------------------------------------------------------------- - if (Usb_suspend()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_suspend \n"); -#endif - usb_connected_Flag = FALSE; - Led_0_off(); - rf_reset_signal = 0; - Usb_clear_suspend(); - Usb_set_suspend_clock(); - } + if (Usb_suspend()) + suspend(); -//-------------------------------------------------------------------------- -// USB Reset -//-------------------------------------------------------------------------- - if (Usb_reset()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_reset \n"); -#endif - Usb_clear_reset(); - usb_var_init(); - usb_connected_Flag = TRUE; - spi_task_init(); - FIFO_SPK_init(); - FIFO_MIC_init(); - FIFO_STT_init(); - Led_0_off(); - rf_reset_signal = 0; - } -} -//-------------------------------------------------------------------------- -// -// SOF Start of Frame (each ms) -// -//-------------------------------------------------------------------------- + if (Usb_reset()) + reset(); + if (Usb_sof()) { Usb_clear_sof(); @@ -428,9 +228,9 @@ { spi_watchdog_ctr--; // Decrement Watchdog } -//--------------------------------------------------------- -// Reset SPI Transfer -//--------------------------------------------------------- + //--------------------------------------------------------- + // Reset SPI Transfer + //--------------------------------------------------------- else if (!i2c_bootloading_Flag) { //Led_1_on(); @@ -442,68 +242,33 @@ spi_ready = 0; } -//-------------------------------------------------------------------------- -// I2C pause timer -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // I2C pause timer + //-------------------------------------------------------------------------- if (i2c_wait_counter) i2c_wait_counter--; -//-------------------------------------------------------------------------- -// Led Behavior -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // Led Behavior + //-------------------------------------------------------------------------- if(usb_connected_Flag && usb_configuration_nb) - { - if(RF_OFFLINE) - { - if(RF_OFFLine_Back == 0) - { - Configure_led(0,LED_PORT_2MA); - usb_sof_counter = 0; - RF_OFFLine_Back = 1; - } - if (usb_sof_counter == 0x00) - Led_0_off(); - if (usb_sof_counter == 0x2FF) - Led_0_on(); - if (usb_sof_counter == 0x3FF) //==> Time Base = 1sec - usb_sof_counter = 0xFFFE; - - - } - else // RF ON Line - { - if(RF_OFFLine_Back == 1) - { - Configure_led(0,LED_PORT_10MA); - usb_sof_counter = 0; - RF_OFFLine_Back = 0; - } - { - if (usb_sof_counter == 0x00) - Led_0_off(); - if (usb_sof_counter == 0x10) - Led_0_on(); - if (usb_sof_counter == 0x20) //Time Base = 1sec - usb_sof_counter = 0xFFFE; - } - } - } + led_behavior(); } -//-------------------------------------------------------------------------- -// -// Process to load Status Data in the USB FIFO -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // Process to load Status Data in the USB FIFO + // + //-------------------------------------------------------------------------- usb_Satus_command_process_task(); usb_Bootloader_command_process_task(); -//-------------------------------------------------------------------------- -// -// Load the USB AUDIO IN FIFO -// -// Data got from FIFO_MIC -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // Load the USB AUDIO IN FIFO + // + // Data got from FIFO_MIC + // + //-------------------------------------------------------------------------- if(!EP_AUDIOIN_Loaded) if(usb_configuration_nb) if(Fifoready_MIC) @@ -521,223 +286,14 @@ EP_AUDIOIN_Loaded = 1; } -//-------------------------------------------------------------------------- -// -// USB Events -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // USB Events + // + //-------------------------------------------------------------------------- if(Usb_endpoint_interrupt()) - { - if (Usb_test_it_ep(EP_CMD_IN)) - { - Usb_select_ep(EP_CMD_IN); - if(Usb_tx_complete()) - { - Usb_clear_tx_complete(); - CMD_IN_Bank_Nb--; - if (CMD_IN_Bank_Nb<0) - CMD_IN_Bank_Nb = 0; - if (CMD_IN_Bank_Nb != 0) - Usb_set_tx_ready(); - } - } - -//-------------------------------------------------------------------------- -// -// Event on Control EndPoint -// -// -> Enumeration Process -// -//-------------------------------------------------------------------------- - if (Usb_test_it_ep(0)) - { - - Usb_select_ep(EP_CONTROL); - if (Usb_setup_received()) - { -#ifdef USB_TASK_DEBUG - printf("Go to Enum process\n"); -#endif - usb_enumeration_process(); - } - } - - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_OUT TTS EndPoint -// -// Data got from PC , Put it in the Speaker FIFO -// -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) - { - - Usb_select_ep(EP_AUDIO_OUT_TTS); - - if(usb_get_nb_byte()) - if(Speaker_TTS_Select_Flag) - { - i=8; - do - { - // Use Only one Call to Get 8 Bytes - FIFO_SPK_put(Usb_read_byte()); - i--; - }while(i); - } - Usb_clear_rx(); - } - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_OUT EndPoint -// -// Data got from PC , Put it in the Speaker FIFO -// -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_OUT)) - { - //DEBUG_1 = 1; - Usb_select_ep(EP_AUDIO_OUT); - - if(usb_get_nb_byte()) - if(Speaker_TTS_Select_Flag==0) - { - i=8; - do - { - // Use Only one Call to Get 8 Bytes - FIFO_SPK_put(Usb_read_byte()); - i--; - }while(i); - } - Usb_clear_rx(); - //DEBUG_1 = 0; - } - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_IN EndPoint -// -// -> EP_AUDIOIN_Loaded = 0; -// -> Enable a new Loading of the USB FIFO -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_IN)) - { - Usb_select_ep(EP_AUDIO_IN); - if(Usb_tx_complete()) - { - Usb_clear_tx_complete(); - // -> Enable a new Loading of the FIFO - EP_AUDIOIN_Loaded = 0; - } - } - - -//-------------------------------------------------------------------------- -// -// Event on EP_CMD_OUT EndPoint -// -// -//-------------------------------------------------------------------------- - if(USB_ParserProcess_Permit_Flag) - { - if(Usb_test_it_ep(EP_CMD_OUT)) - { -#ifdef FIFO_DEBUG - printf("CMD OUT\n"); -#endif - if(!USBCommand_NewRequest_Flag) - { - //DEBUG_2 = 1; - Usb_select_ep(EP_CMD_OUT); - //DEBUG_2 = 0; - if(Usb_rx_complete()) - { - // Capture the number of Byte in USB FIFO - USBCommand_Ctr = usb_get_nb_byte(); - // Read the Header - USBCommand_Header = Usb_read_byte(); -//-------------------------------------------------------------------------- -// -// TUX CMD HEADER received -// -> Store Data in USBCommand_ForRF[] -// -> USBCommand_NewRequest_Flag = 1 -// to inform SPI_task that a new command is arrived -// -//-------------------------------------------------------------------------- - if(USBCommand_Header == LIBUSB_TUX_CMD_HDR) - { - if (!RF_OFFLINE) - USBCommand_NewRequest_Flag = 1; - for(i=0;i<(USBCommand_Ctr-1);i++) - USBCommand_ForRF[i] = Usb_read_byte(); - tux_command_parser(USBCommand_ForRF, \ - USBCommand_Ctr); - } - - /* - * DONGLE CMD HEADER received - */ - else if(USBCommand_Header == LIBUSB_DONGLE_CMD_HDR) - { - for(i=0;i<(USBCommand_Ctr-1);i++) - USBCommand_ForDongle[i] = Usb_read_byte(); -#ifdef FIFO_DEBUG - printf("usb command parser\n"); -#endif - usb_command_parser(); - /* Request processed */ - USBCommand_NewRequest_Flag = 0; - } - - /* - * BOOTLOADER HEADER received - */ - else if(USBCommand_Header == - LIBUSB_BOOTLOADER_CMD_HDR) - { - bootloader_task(); - } - - - /* Clear the bank */ - Usb_select_ep(EP_CMD_OUT); - if (CMD_OUT_Bank_Nb == 0 && Usb_rx_bank0_complete()) - { -#ifdef USB_TASK_DEBUG - printf ("USB: clear bank 0\n"); -#endif - Usb_clear_rx_bank0(); - CMD_OUT_Bank_Nb = 1; - } - else if(CMD_OUT_Bank_Nb == 1 && \ - Usb_rx_bank1_complete()) - { -#ifdef USB_TASK_DEBUG - printf ("USB: clear bank 1\n"); -#endif - Usb_clear_rx_bank1(); - CMD_OUT_Bank_Nb = 0; - } -#ifdef USB_TASK_DEBUG - else - { - printf ("USB: ERROR bank synchronisation\n"); - if (Usb_rx_bank1_complete()) - Usb_clear_rx_bank1(); - else - Usb_clear_rx_bank0(); - } -#endif - } - } - } - } //if(Usb_endpoint_interrupt()) + { + endpoints_ctr(); } } @@ -745,32 +301,11 @@ if(!usb_connected_Flag) return; -/*F************************************************************************** -* NAME: I2C_task -*---------------------------------------------------------------------------- -* PURPOSE: -* This part manages the I2C communication -*---------------------------------------------------------------------------- -* NOTE: -*****************************************************************************/ if (i2c_bootloading_Flag) /* I2C bootloading */ { i2c_task(); } - - - - -/*F************************************************************************** -* NAME: SPI_task -*---------------------------------------------------------------------------- -* PURPOSE: -* This part manages the SPI communication with THE RF -*---------------------------------------------------------------------------- -* NOTE: -*****************************************************************************/ - else if(!RF_OFFLINE) { spi_task(); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -26,6 +26,8 @@ extern bit Cpu_reset; extern bit i2c_bootloading_Flag; +extern bit Speaker_TTS_Select_Flag; +extern bit EP_AUDIOIN_Loaded; void data_to_send(void); void usb_task_init (void); |
From: jaguarondi <c2m...@c2...> - 2008-05-06 09:17:58
|
Author: jaguarondi Date: 2008-05-06 11:18:01 +0200 (Tue, 06 May 2008) New Revision: 1108 Modified: firmware/tuxdefs/commands.h Log: * Added a global error command that will be used to report firmware errors to the computer. This will be used in the "assert" way, for conditions that shouldn't normally happen. * Wrong bit for the STATUS_VCC_MK mask. * Comment update. Modified: firmware/tuxdefs/commands.h =================================================================== --- firmware/tuxdefs/commands.h 2008-05-06 06:58:50 UTC (rev 1107) +++ firmware/tuxdefs/commands.h 2008-05-06 09:18:01 UTC (rev 1108) @@ -83,11 +83,11 @@ #define LED_ON_CMD 0x1A /* Turn all LEDs on */ #define LED_OFF_CMD 0x1B /* Turn all LEDs off */ -#define LED_TOGGLE_CMD 0x9A /* 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_TOGGLE_CMD 0x9A /* Toggle LEDs */ /* 1st parameter: number of LED toggles */ /* 2nd parameter: delay between each LED toggle, in multiple of 4ms */ @@ -105,19 +105,12 @@ /* 1st parameter: 1 to write the sound * 0 to not write the sound*/ -#define ERASE_FLASH_CMD 0x54 /* get indexes of the flash sound bank [1] */ +#define ERASE_FLASH_CMD 0x54 /* get indexes of the flash sound bank */ -#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 */ -/* note [1]: those commands are not propagated to the core CPU but - * directly executed from the audio CPU when received from RF, so we can use a - * command with 3 parameters here. These commands can't be combined with other - * commands in the buffer sent by the computer on the USB port otherwise the - * other commands will be lost. */ - /* * Sleep commands */ @@ -187,7 +180,7 @@ #define STATUS_HEADBTN_MK 0x08 #define STATUS_CHARGER_MK 0x10 #define STATUS_RF_MK 0x20 -#define STATUS_VCC_MK 0x20 +#define STATUS_VCC_MK 0x40 #define STATUS_MUTE_MK 0x80 /* 2nd parameter: sound played from the flash * 3rd parameter: audio activity @@ -214,7 +207,7 @@ /* send position counters which is related to the motor status */ #define STATUS_POSITION2_CMD 0xC4 /* 1st parameter: spin position counter */ -/* 2nd parameter: */ +/* 2nd parameter: flippers position */ /* 3rd parameter: */ #define STATUS_IR_CMD 0xC5 @@ -246,11 +239,21 @@ /* * Special commands */ -#define ERROR_CMD 0xF9 +/** Global error command */ +#define GERROR_CMD 0xF9 /* 1st parameter: CPU number */ -/* 2nd parameter: error number */ -/* 3rd parameter: depends on the error number */ -#define ERROR_BUF_FULL 0x01 +/* 2nd parameter: error type */ +/* 3rd parameter: optional parameter */ +enum gerrors +{ + GERROR_NONE = 0, + GERROR_CMDINBUF_OVF, + GERROR_CMDINBUF_EMPTY, + GERROR_CMDOUTBUF_FULL, + GERROR_INV_RECEIVE_LENGTH, + CMDGERROR_OUTBUF_OVF, +}; + #define FEEDBACK_CMD 0xF8 /* 3 paramters sent back depending on the last command sent to tux which is * supposed to send feedback */ |
From: Paul_R <c2m...@c2...> - 2008-05-06 06:58:47
|
Author: Paul_R Date: 2008-05-06 08:58:50 +0200 (Tue, 06 May 2008) New Revision: 1107 Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.h firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c Log: * Moved the i2c task into the i2c module Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 06:44:57 UTC (rev 1106) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/bootloading.c 2008-05-06 06:58:50 UTC (rev 1107) @@ -122,6 +122,9 @@ } + + + void bootloader_task(void) { uint8_t i; Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 06:44:57 UTC (rev 1106) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 06:58:50 UTC (rev 1107) @@ -1,4 +1,7 @@ +#include "global.h" +#include "bootloader/bootloading.h" #include "bootloader\i2c.h" +#include "usb/usb_task.h" #define I2C_DEBUG 0 @@ -299,3 +302,33 @@ TWI_CLEAR_SI(); } #endif + + +void i2c_task(void) +{ + if (i2c_wait_counter) + /* Wait */ + ; + else if (i2c_task_on_Flag) + { + /* Send data through I2C */ + bl_senddata(blHeader, 64); +#ifdef BOOTLOAD_DEBUG + printf ("I2C: Send data"); + while (i2cFlags.i2c_busy) + { + uint8_t i; + for (i=0; i<0xFF; i++); + printf ("."); + } + printf (" [OK]\n"); +#else + while (i2cFlags.i2c_busy); +#endif + /* Wait 20ms before next I2C */ + i2c_wait_counter = 20; + /* ACK or NACK and exit I2C task */ + usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); + i2c_task_on_Flag = 0; + } +} Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.h 2008-05-06 06:44:57 UTC (rev 1106) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.h 2008-05-06 06:58:50 UTC (rev 1107) @@ -2,7 +2,7 @@ * Copyright (c) 2006, C2ME S.A. * All rights reserved. * - * $Id:$ + * $Id$ */ #ifndef _I2C_H_ @@ -113,6 +113,7 @@ void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)); void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)); void i2cMasterStart(void); +void i2c_task(void); #endif Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 06:44:57 UTC (rev 1106) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 06:58:50 UTC (rev 1107) @@ -756,31 +756,7 @@ if (i2c_bootloading_Flag) /* I2C bootloading */ { - if (i2c_wait_counter) - /* Wait */ - ; - else if (i2c_task_on_Flag) - { - /* Send data through I2C */ - bl_senddata(blHeader, 64); -#ifdef BOOTLOAD_DEBUG - printf ("I2C: Send data"); - while (i2cFlags.i2c_busy) - { - uint8_t i; - for (i=0; i<0xFF; i++); - printf ("."); - } - printf (" [OK]\n"); -#else - while (i2cFlags.i2c_busy); -#endif - /* Wait 20ms before next I2C */ - i2c_wait_counter = 20; - /* ACK or NACK and exit I2C task */ - usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); - i2c_task_on_Flag = 0; - } + i2c_task(); } |