[tuxdroid-svn] r1129 - firmware/tuxaudio/trunk
Status: Beta
Brought to you by:
ks156
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 */ |