[tuxdroid-svn] r287 - svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment va
Status: Beta
Brought to you by:
ks156
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-22 18:14:11
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 287 Modified: firmware/tuxcore/trunk/bootloader.c firmware/tuxcore/trunk/communication.c firmware/tuxcore/trunk/communication.h firmware/tuxcore/trunk/config.c firmware/tuxcore/trunk/fifo.c firmware/tuxcore/trunk/fifo.h firmware/tuxcore/trunk/global.c firmware/tuxcore/trunk/global.h firmware/tuxcore/trunk/i2c.c firmware/tuxcore/trunk/i2c.h firmware/tuxcore/trunk/ir.c firmware/tuxcore/trunk/ir.h firmware/tuxcore/trunk/led.c firmware/tuxcore/trunk/main.c firmware/tuxcore/trunk/motors.c firmware/tuxcore/trunk/motors.h firmware/tuxcore/trunk/parser.c firmware/tuxcore/trunk/parser.h firmware/tuxcore/trunk/standalone.c firmware/tuxcore/trunk/version.h Log: doegox 2007-04-22 20:13:55 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxcore/trunk/bootloader.c =================================================================== --- firmware/tuxcore/trunk/bootloader.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/bootloader.c 2007-04-22 18:13:55 UTC (rev 287) @@ -33,7 +33,7 @@ uint8_t b[2]; } union16_t; -void (*jump_to_application)(void) = (void *)0x0000; +void (*jump_to_application) (void) = (void *)0x0000; void i2cWaitForComplete(void); /** \ingroup minimal_bootloader @@ -45,13 +45,13 @@ union16_t pageAddress, data; uint16_t address; uint8_t i, twStatus, eeprom_flg = 0; - volatile uint16_t _count=0; + volatile uint16_t _count = 0; - for (_count = 0;_count<0xFFFF; _count++); /* wait for the head button to stabilize */ - if (SW_HD_PIN & SW_HD_MK) /* if head is not pushed at startup */ + for (_count = 0; _count < 0xFFFF; _count++) ; /* wait for the head button to stabilize */ + if (SW_HD_PIN & SW_HD_MK) /* if head is not pushed at startup */ jump_to_application(); - LED_DDR |= LED_L_MK; /* light on left led */ + LED_DDR |= LED_L_MK; /* light on left led */ LED_PT |= LED_L_MK; TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ @@ -60,29 +60,35 @@ TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) { - i2cWaitForComplete(); /* wait the I2C address */ - if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) while(1); + i2cWaitForComplete(); /* wait the I2C address */ + if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) + while (1) ; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the high byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the high byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[1] = TWDR; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the low byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the low byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[0] = TWDR; - if (pageAddress.w & 0x003F) while(1); /* incorrect page address */ - if (pageAddress.w >= 0x8000) /* eeprom programming */ + if (pageAddress.w & 0x003F) + while (1) ; /* incorrect page address */ + if (pageAddress.w >= 0x8000) /* eeprom programming */ { - eeprom_flg = 1; /* don't overwrite the bootloader */ - pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ + eeprom_flg = 1; /* don't overwrite the bootloader */ + pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ } - else if (pageAddress.w >= 0x1E00) while(1); /* don't overwrite the bootloader */ - else eeprom_flg = 0; /* flash programming */ + else if (pageAddress.w >= 0x1E00) + while (1) ; /* don't overwrite the bootloader */ + else + eeprom_flg = 0; /* flash programming */ address = pageAddress.w; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - for (i=0; i<SPM_PAGESIZE; i++) /* fill the complete page with the next data */ + for (i = 0; i < SPM_PAGESIZE; i++) /* fill the complete page with the next data */ { - i2cWaitForComplete(); /* wait data */ + i2cWaitForComplete(); /* wait data */ if ((twStatus = TW_STATUS) == TW_SR_DATA_ACK) { if ((i & 0x01) == 0) @@ -94,31 +100,33 @@ data.b[1] = TWDR; if (eeprom_flg) { - eeprom_write_word ((uint16_t *)address, data.w); + eeprom_write_word((uint16_t *) address, data.w); eeprom_busy_wait(); } else - boot_page_fill (address, data.w); + boot_page_fill(address, data.w); address += 2; } TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); } - else while(1); /* error in communication */ + else + while (1) ; /* error in communication */ } i2cWaitForComplete(); - if ((twStatus = TW_STATUS) != TW_SR_STOP) while(1); /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ - TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ + if ((twStatus = TW_STATUS) != TW_SR_STOP) + while (1) ; /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ + TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ if (!eeprom_flg) { - boot_page_erase (pageAddress.w); - boot_spm_busy_wait (); - boot_page_write (pageAddress.w); /* Store buffer in flash page */ - boot_spm_busy_wait (); + boot_page_erase(pageAddress.w); + boot_spm_busy_wait(); + boot_page_write(pageAddress.w); /* Store buffer in flash page */ + boot_spm_busy_wait(); } } } -void i2cWaitForComplete (void) +void i2cWaitForComplete(void) { - while( !(TWCR & _BV(TWINT)) ); /* wait for i2c interface to complete operation */ + while (!(TWCR & _BV(TWINT))) ; /* wait for i2c interface to complete operation */ } Modified: firmware/tuxcore/trunk/communication.c =================================================================== --- firmware/tuxcore/trunk/communication.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/communication.c 2007-04-22 18:13:55 UTC (rev 287) @@ -38,8 +38,8 @@ * Note that because of this filo stack, commands are not processed in the * order they were issued when the stack holds multiple commands. */ -uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ -uint8_t commandBufIdx = 0; /* index indicating the number of data in the buffer */ +uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ +uint8_t commandBufIdx = 0; /* index indicating the number of data in the buffer */ /* * audioIntBuf is a single buffer for audio commands to be sent to the audio @@ -50,16 +50,18 @@ * cleared when the command is sent so it can be used to check whether the * buffer is empty or not. */ -uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for audio commands to be sent to the audio interface */ -uint8_t audioIntBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ +uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for audio commands to be sent to the audio interface */ +uint8_t audioIntBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ /* * statusBuf is a fifo buffer for status commands to be sent by i2c and then * over the RF link */ uint8_t statusFifoBuf[STATUS_BUF_SIZE]; /* statusBuf is a fifo buffer for status commands to be sent over i2c */ -fifo_t statusFifo_s = {statusFifoBuf, sizeof statusFifoBuf-1, 0, 0}, *statusFifo = &statusFifo_s; +fifo_t statusFifo_s = { statusFifoBuf, sizeof statusFifoBuf - 1, 0, 0 } +, *statusFifo = &statusFifo_s; + uint8_t i2cCommandType; volatile uint8_t i2c_pause; @@ -71,10 +73,10 @@ */ void i2cCommunicationInit(void) { - i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission. Should be before i2cInit otherwise interrupts should be disabled */ - i2cInit(); /* start twi interface */ - i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ - i2cDeviceAddrRW = 0x14; /* set tuxaudio CPU device address */ + i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission. Should be before i2cInit otherwise interrupts should be disabled */ + i2cInit(); /* start twi interface */ + i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ + i2cDeviceAddrRW = 0x14; /* set tuxaudio CPU device address */ } /* @@ -84,13 +86,13 @@ * We basically do a transfer of the received data to the * commandBuf here. */ -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData) +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) { - uint8_t i; + uint8_t i; - receiveData += receiveDataLength; - for (i=0; i< receiveDataLength; i++) - commandBuf[commandBufIdx++] = *--receiveData; + receiveData += receiveDataLength; + for (i = 0; i < receiveDataLength; i++) + commandBuf[commandBufIdx++] = *--receiveData; } /* @@ -105,29 +107,30 @@ */ uint8_t sendCommand(void) { - uint16_t wait=0; + uint16_t wait = 0; i2cMasterStart(); cli(); - i2cFlags.m_end = 0; /* reset master transmission end flag */ + i2cFlags.m_end = 0; /* reset master transmission end flag */ i2cFlags.i2c_busy = 1; - sei(); /* TODO change this by a save restore */ - while(1) /* wait until the command is sent successfully or a nack is received */ + sei(); /* TODO change this by a save restore */ + while (1) /* wait until the command is sent successfully or a nack is received */ { if (i2cFlags.i2c_busy == 0) { if (i2cFlags.mt_nack) { cli(); - i2cFlags.mt_nack = 0; /* keep buffer and reset nack status */ + i2cFlags.mt_nack = 0; /* keep buffer and reset nack status */ sei(); i2c_pause = AFTER_NACK_DELAY; - return 1; /* return nack error */ + return 1; /* return nack error */ } - else if (i2cFlags.m_end) return 0; /* return success */ - else + else if (i2cFlags.m_end) + return 0; /* return success */ + else { - i2cMasterStart(); /* previous transmission was cancelled by arbitration lost or any problem so restart */ + i2cMasterStart(); /* previous transmission was cancelled by arbitration lost or any problem so restart */ cli(); i2cFlags.i2c_busy = 1; sei(); @@ -138,12 +141,12 @@ { wait = 0; TWCR = 0; - while(wait++ < 0xFFF0); + while (wait++ < 0xFFF0) ; i2cFlags.i2c_busy = 0; i2cFlags.m_end = 0; i2cFlags.mt_nack = 0; i2cInit(); - return 1; /* return error */ + return 1; /* return error */ } /* end: workaround for the I2C bug */ } @@ -152,27 +155,30 @@ uint8_t fetchCommands(void) { uint8_t i; - if (statusFifoFlag) return 0; /* fifo is being updated outside the interrupt so don't touch it */ - if (audioIntBufIdx) /* one audio command to send */ + + if (statusFifoFlag) + return 0; /* fifo is being updated outside the interrupt so don't touch it */ + if (audioIntBufIdx) /* one audio command to send */ { - for (i=0; i<audioIntBufIdx; i++) i2cSendData[i] = audioIntBuf[i]; + for (i = 0; i < audioIntBufIdx; i++) + i2cSendData[i] = audioIntBuf[i]; i2cSendDataLength = audioIntBufIdx; i2cCommandType = AUDIO_CMD; return 1; } - else if (!isFifoEmpty(statusFifo)) /* if no audio and there's some status to send, get the next value */ + else if (!isFifoEmpty(statusFifo)) /* if no audio and there's some status to send, get the next value */ { - for (i=0; i<4; i++) /* so we loop 4 times here to get all command bytes */ + for (i = 0; i < 4; i++) /* so we loop 4 times here to get all command bytes */ { i2cSendData[i] = 0; - popFifo(statusFifo, &i2cSendData[i]); /* TODO add a test on returned value to detect any corrupted fifo */ + popFifo(statusFifo, &i2cSendData[i]); /* TODO add a test on returned value to detect any corrupted fifo */ // XXX to delete i2cSendData[i] = statusBuf[statusBufIdx-i-1]; [> decrease index then get the value <] } - i2cSendDataLength = 4; /* status commands have always 3 parameters */ + i2cSendDataLength = 4; /* status commands have always 3 parameters */ i2cCommandType = STATUS_CMD; return 1; } - + return 0; } @@ -192,18 +198,19 @@ { uint8_t i; - if (i2cFlags.i2c_busy) return; /* check if i2c hardware not busy */ - if (i2c_pause) return; /* if nacked, wait a moment */ - if (fetchCommands()) /* and commands are ready */ + if (i2cFlags.i2c_busy) + return; /* check if i2c hardware not busy */ + if (i2c_pause) + return; /* if nacked, wait a moment */ + if (fetchCommands()) /* and commands are ready */ { - if (sendCommand()) /* nack error so we have to restore the values */ + if (sendCommand()) /* nack error so we have to restore the values */ { if (i2cCommandType == STATUS_CMD) - for (i=0; i<4; i++) /* so we loop 4 times here to get all command bytes */ - pushFifo(statusFifo, i2cSendData[i]); /* TODO try to find a better way to do this later on */ + for (i = 0; i < 4; i++) /* so we loop 4 times here to get all command bytes */ + pushFifo(statusFifo, i2cSendData[i]); /* TODO try to find a better way to do this later on */ } - else - if (i2cCommandType == AUDIO_CMD) - audioIntBufIdx = 0; /* clear buffer if command sent successfully */ + else if (i2cCommandType == AUDIO_CMD) + audioIntBufIdx = 0; /* clear buffer if command sent successfully */ } } Modified: firmware/tuxcore/trunk/communication.h =================================================================== --- firmware/tuxcore/trunk/communication.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/communication.h 2007-04-22 18:13:55 UTC (rev 287) @@ -20,7 +20,7 @@ /* $Id: */ #ifndef COMMUNICATION_H -#define COMMUNICATION_H +#define COMMUNICATION_H #include "common/commands.h" #include "fifo.h" @@ -30,24 +30,25 @@ #define MAX_COMMAND_SIZE 4 #define AFTER_NACK_DELAY 6 -enum CMD_TYPE {AUDIO_CMD, STATUS_CMD}; +enum CMD_TYPE +{ AUDIO_CMD, STATUS_CMD }; -extern uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ -extern uint8_t commandBufIdx; /* index indicating the number of data in the buffer */ -extern uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -extern uint8_t audioIntBufIdx; /* index indicating the number of valid bytes in the buffer */ +extern uint8_t commandBuf[COMMAND_BUF_SIZE]; /* buffer for commands received by RF and sent over i2c */ +extern uint8_t commandBufIdx; /* index indicating the number of data in the buffer */ +extern uint8_t audioIntBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +extern uint8_t audioIntBufIdx; /* index indicating the number of valid bytes in the buffer */ + // extern uint8_t statusBuf[STATUS_BUF_SIZE]; [> incomingBuf is a filo buffer for commands received over i2c to be sent back over the RF link <] // extern uint8_t statusBufIdx; [> index indicating the number of valid bytes in the buffer <] extern fifo_t *statusFifo; -extern uint8_t errorBuf[2]; /* buffer for command errors, should contain command number and error code */ +extern uint8_t errorBuf[2]; /* buffer for command errors, should contain command number and error code */ -extern void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData); +extern void i2cSlaveReceiveService(uint8_t receiveDataLength, + uint8_t * receiveData); void i2cCommunicationInit(void); void sendCommands(void); uint8_t fetchCommands(void); - - -#endif /* COMMUNICATION_H */ +#endif /* COMMUNICATION_H */ Modified: firmware/tuxcore/trunk/config.c =================================================================== --- firmware/tuxcore/trunk/config.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/config.c 2007-04-22 18:13:55 UTC (rev 287) @@ -64,11 +64,13 @@ /* Initialize the configuration registers */ void config_init(void) { - eeprom_read_block((void*)&tux_config, (const void*)&tux_config_default, sizeof(tuxcore_config_t)); + eeprom_read_block((void *)&tux_config, (const void *)&tux_config_default, + sizeof(tuxcore_config_t)); } /* Save the configuration registers to the eeprom */ void config_write(void) { - eeprom_write_block((const void*)&tux_config, (void*)&tux_config_default, sizeof(tuxcore_config_t)); + eeprom_write_block((const void *)&tux_config, (void *)&tux_config_default, + sizeof(tuxcore_config_t)); } Modified: firmware/tuxcore/trunk/fifo.c =================================================================== --- firmware/tuxcore/trunk/fifo.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/fifo.c 2007-04-22 18:13:55 UTC (rev 287) @@ -67,7 +67,7 @@ * \param p fifo pointer * * Note that the first element in the fifo will be stored in p->buffer[1] and not p->buffer[0] */ -void resetFifo(fifo_t *p) +void resetFifo(fifo_t * p) { p->inIdx = 0; p->outIdx = 0; @@ -77,16 +77,16 @@ * \param p fifo pointer * \return TRUE if fifo buffer is full */ -uint8_t isFifoFull(fifo_t *p) +uint8_t isFifoFull(fifo_t * p) { - return (p->outIdx == (((uint8_t)(p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return (p->outIdx == (((uint8_t) (p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Return TRUE if the fifo buffer is empty (22b). * \param p fifo pointer * \return TRUE if fifo buffer is empty */ -uint8_t isFifoEmpty(fifo_t *p) +uint8_t isFifoEmpty(fifo_t * p) { return (p->outIdx == p->inIdx); } @@ -95,9 +95,9 @@ * \param p fifo pointer * \return number of elements in the buffer */ -uint8_t fifoLength(fifo_t *p) +uint8_t fifoLength(fifo_t * p) { - return ((uint8_t)(p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return ((uint8_t) (p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Add one data byte to the fifo buffer (32b). @@ -106,15 +106,15 @@ * * If the fifo is already full, return immediately without doing anything. */ -void pushFifo(fifo_t *p, uint8_t data) +void pushFifo(fifo_t * p, uint8_t data) { - uint8_t inIdx; /* use of a local variable to reduce code size */ + uint8_t inIdx; /* use of a local variable to reduce code size */ - inIdx = ((uint8_t)(p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ - if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ + inIdx = ((uint8_t) (p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ { - p->inIdx = inIdx; /* ++ index */ - p->buffer[inIdx] = data; /* stora data */ + p->inIdx = inIdx; /* ++ index */ + p->buffer[inIdx] = data; /* stora data */ } } @@ -127,16 +127,17 @@ * fifo is empty, the index is not decreased, '1' is returned and the pointed * data is left unchanged. */ -uint8_t popFifo(fifo_t *p, uint8_t *data) +uint8_t popFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ - *data = p->buffer[p->outIdx]; /* get data */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ + *data = p->buffer[p->outIdx]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Get the oldest byte in the fifo without removing it @@ -147,14 +148,15 @@ * Return '0' if a value has been read out. If the fifo is empty, '1' * is returned and the pointed data is left unchanged. */ -uint8_t getFifo(fifo_t *p, uint8_t *data) +uint8_t getFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - *data = p->buffer[p->outIdx + 1]; /* get data */ + *data = p->buffer[p->outIdx + 1]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Pull the oldest byte from the fifo, always return something even if @@ -165,13 +167,14 @@ * If the fifo is empty, the index is not decreased but the latest value is * returned. */ -uint8_t pullFifo(fifo_t *p) +uint8_t pullFifo(fifo_t * p) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ } - return p->buffer[p->outIdx]; /* get data in all cases */ + return p->buffer[p->outIdx]; /* get data in all cases */ } + /*@}*/ Modified: firmware/tuxcore/trunk/fifo.h =================================================================== --- firmware/tuxcore/trunk/fifo.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/fifo.h 2007-04-22 18:13:55 UTC (rev 287) @@ -75,13 +75,13 @@ /** \brief UD- Rate at which the adaptation is done. * * The adaptation function will only be run each 2^FIFO_ADAPT_RATE sample */ -#define FIFO_ADAPT_RATE 3 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ +#define FIFO_ADAPT_RATE 3 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ /** \brief UD- High level threshold */ -#define FIFO_ADAPT_HIGH (p->size - (p->size>>2)) /* 3/4 of size */ +#define FIFO_ADAPT_HIGH (p->size - (p->size>>2)) /* 3/4 of size */ /** \brief UD- Low level threshold */ -#define FIFO_ADAPT_LOW (p->size>>2) /* 1/4 of size */ +#define FIFO_ADAPT_LOW (p->size>>2) /* 1/4 of size */ /** \brief Fifo structure type which holds the buffer, it's size, input and * output indexes. @@ -89,33 +89,34 @@ Note that the buffer can only hold (size - 1) elements to be able to make the difference between completely full and completely empty states. */ -typedef struct fifo_s { +typedef struct fifo_s +{ /** array that will store the elements */ - uint8_t *buffer; + uint8_t *buffer; /** size of the fifo buffer array minus 1 * The wrap around is made by a 'AND' function so the AND should be made with * the (array size -1) to be able to clear all bits above the array size. * This -1 is not related to the fact that the buffer can only hold (size -1) * elements. */ - uint8_t size; + uint8_t size; /** input index which indexes the last pushed value */ - uint8_t inIdx; + uint8_t inIdx; /** output index which indexes the last popped value */ - uint8_t outIdx; + uint8_t outIdx; } fifo_t; /* * Extern declarations */ -void resetFifo(fifo_t *p); -uint8_t isFifoFull(fifo_t *p); -uint8_t isFifoEmpty(fifo_t *p); -uint8_t fifoLength(fifo_t *p); -void pushFifo(fifo_t *p, uint8_t data); -uint8_t popFifo(fifo_t *p, uint8_t *data); -uint8_t getFifo(fifo_t *p, uint8_t *data); -uint8_t pullFifo(fifo_t *p); -void adaptFifo(fifo_t *p); +void resetFifo(fifo_t * p); +uint8_t isFifoFull(fifo_t * p); +uint8_t isFifoEmpty(fifo_t * p); +uint8_t fifoLength(fifo_t * p); +void pushFifo(fifo_t * p, uint8_t data); +uint8_t popFifo(fifo_t * p, uint8_t * data); +uint8_t getFifo(fifo_t * p, uint8_t * data); +uint8_t pullFifo(fifo_t * p); +void adaptFifo(fifo_t * p); -#endif /* FIFO_H */ +#endif /* FIFO_H */ Modified: firmware/tuxcore/trunk/global.c =================================================================== --- firmware/tuxcore/trunk/global.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/global.c 2007-04-22 18:13:55 UTC (rev 287) @@ -35,21 +35,27 @@ * General global registers */ uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag = 0; -uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen = 0xFF; +uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, + last_tux_seen = 0xFF; uint8_t led_backup; - /* * Condition flags */ -struct condition_table cond_flags = {1}; /* Set startup flag */ +struct condition_table cond_flags = { 1 }; /* Set startup flag */ /* * Version number */ #define CPU_NUMBER TUXCORE_CPU_NUM /* tuxcore CPU */ -const author_t author __attribute__((section("version.3"))) = {AUTHOR_CMD, AUTHOR_ID, 0}; -const revision_t svn_revision __attribute__((section("version.2"))) = {REVISION_CMD, SVN_REV, SVN_STATUS}; -const version_t tag_version __attribute__((section("version.1"))) = {VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; +const author_t author __attribute__ ((section("version.3"))) = +{ +AUTHOR_CMD, AUTHOR_ID, 0}; +const revision_t svn_revision __attribute__ ((section("version.2"))) = +{ +REVISION_CMD, SVN_REV, SVN_STATUS}; +const version_t tag_version __attribute__ ((section("version.1"))) = +{ +VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; Modified: firmware/tuxcore/trunk/global.h =================================================================== --- firmware/tuxcore/trunk/global.h 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/global.h 2007-04-22 18:13:55 UTC (rev 287) @@ -38,31 +38,31 @@ // #define SW_MK (_BV(PB3) | _BV(PB4) | _BV(PB5)) // #define SW_LW_MK _BV(PB3) [> left wing switch <] // #define SW_RW_MK _BV(PB4) [> right wing switch <] -#define SW_HD_PIN PINB /* head switch input port */ -#define SW_HD_PT PORTB /* head switch port */ -#define SW_HD_DDR DDRB /* head switch DDR */ -#define SW_HD_MK _BV(PB5) /* head switch */ +#define SW_HD_PIN PINB /* head switch input port */ +#define SW_HD_PT PORTB /* head switch port */ +#define SW_HD_DDR DDRB /* head switch DDR */ +#define SW_HD_MK _BV(PB5) /* head switch */ /* Position Switches */ -#define PSW_SPIN_MK _BV(PD3) /* spin switch */ +#define PSW_SPIN_MK _BV(PD3) /* spin switch */ #define PSW_SPIN_PT PORTD #define PSW_SPIN_PIN PIND #define PSW_SPIN_DDR DDRD -#define PSW_WINGS_MK _BV(PC1) /* wings switch */ +#define PSW_WINGS_MK _BV(PC1) /* wings switch */ #define PSW_WINGS_PT PORTC #define PSW_WINGS_PIN PINC #define PSW_WINGS_DDR DDRC #define PSW_MOUTH_PT PORTB #define PSW_MOUTH_PIN PINB #define PSW_MOUTH_DDR DDRB -#define PSW_MOUTH_O_MK _BV(PB3) /* mouth switch when opened */ -#define PSW_MOUTH_C_MK _BV(PB4) /* mouth switch when closed */ +#define PSW_MOUTH_O_MK _BV(PB3) /* mouth switch when opened */ +#define PSW_MOUTH_C_MK _BV(PB4) /* mouth switch when closed */ #define PSW_MOUTH_MK (PSW_MOUTH_O_MK | PSW_MOUTH_C_MK) #define PSW_EYES_PT PORTD #define PSW_EYES_PIN PIND #define PSW_EYES_DDR DDRD -#define PSW_EYES_O_MK _BV(PD6) /* eyes switch when opened */ -#define PSW_EYES_C_MK _BV(PD7) /* eyes switch when closed */ +#define PSW_EYES_O_MK _BV(PD6) /* eyes switch when opened */ +#define PSW_EYES_C_MK _BV(PD7) /* eyes switch when closed */ #define PSW_EYES_MK (PSW_EYES_O_MK | PSW_EYES_C_MK) /* @@ -71,10 +71,10 @@ * -------------------------------------------------------- */ -#define IR_LED_PT PORTD /* ir led */ +#define IR_LED_PT PORTD /* ir led */ #define IR_LED_DDR DDRD #define IR_LED_MK _BV(PD5) -#define IR_REC_PT PORTD /* ir receiver */ +#define IR_REC_PT PORTD /* ir receiver */ #define IR_REC_PIN PIND #define IR_REC_DDR DDRD #define IR_REC_MK _BV(PD2) @@ -105,11 +105,11 @@ * -------------------------------------------------------- */ -#define LED_PT PORTC /* blue eye leds */ -#define LED_PIN PINC /* blue eye leds */ +#define LED_PT PORTC /* blue eye leds */ +#define LED_PIN PINC /* blue eye leds */ #define LED_DDR DDRC -#define LED_L_MK _BV(PC2) /* right blue led */ -#define LED_R_MK _BV(PC3) /* left blue led */ +#define LED_L_MK _BV(PC2) /* right blue led */ +#define LED_R_MK _BV(PC3) /* left blue led */ #define LED_MK (LED_R_MK | LED_L_MK) /* @@ -123,7 +123,6 @@ #define EXIO_PIN PINB #define EXIO_MK _BV(PB7) - /* * -------------------------------------------------------- * MOTORS @@ -134,29 +133,29 @@ // #define MOT_PT PORTD [> motors port <] // #define MOT_DDR DDRD // #define MOT_MK (MOT_WINGS_FW | MOT_WINGS_BW | MOT_MOUTH_MK | MOT_EYES_MK | MOT_SPIN_R_MK | MOT_SPIN_L_MK) -#define MOT_WINGS_BW_MK _BV(PD4) /* wing motor forward */ +#define MOT_WINGS_BW_MK _BV(PD4) /* wing motor forward */ #define MOT_WINGS_BW_PT PORTD #define MOT_WINGS_BW_DDR DDRD -#define MOT_WINGS_FW_MK _BV(PB0) /* wing motor backward */ +#define MOT_WINGS_FW_MK _BV(PB0) /* wing motor backward */ #define MOT_WINGS_FW_PT PORTB #define MOT_WINGS_FW_DDR DDRB #define wingsPwmMask pwmMaskB -#define MOT_MOUTH_MK _BV(PD1) /* mouth motor (forward) */ +#define MOT_MOUTH_MK _BV(PD1) /* mouth motor (forward) */ #define MOT_MOUTH_PT PORTD #define MOT_MOUTH_DDR DDRD -#define MOT_IMOUTH_MK _BV(PD0) /* inverted mouth motor (backward) */ +#define MOT_IMOUTH_MK _BV(PD0) /* inverted mouth motor (backward) */ #define MOT_IMOUTH_PT PORTD #define MOT_IMOUTH_DDR DDRD -#define MOT_IEYES_MK _BV(PD1) /* eyes motor (forward) */ +#define MOT_IEYES_MK _BV(PD1) /* eyes motor (forward) */ #define MOT_IEYES_PT PORTD #define MOT_IEYES_DDR DDRD -#define MOT_EYES_MK _BV(PD0) /* inverted eyes motor (backward) */ +#define MOT_EYES_MK _BV(PD0) /* inverted eyes motor (backward) */ #define MOT_EYES_PT PORTD #define MOT_EYES_DDR DDRD -#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ +#define MOT_SPIN_R_MK _BV(PB2) /* spin motor, turn on the right */ #define MOT_SPIN_R_PT PORTB #define MOT_SPIN_R_DDR DDRB -#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ +#define MOT_SPIN_L_MK _BV(PB1) /* spin motor, turn on the left */ #define MOT_SPIN_L_PT PORTB #define MOT_SPIN_L_DDR DDRB #define MOT_SPIN_MK (MOT_SPIN_L_MK | MOT_SPIN_R_MK) @@ -165,12 +164,12 @@ #define spinPwmMask pwmMaskB /* Control */ -#define EYES_OPEN_DLY 4 /* 4ms unit */ -#define EYES_ICLOSE_DLY 4 /* 4ms unit */ -#define MOUTH_OPEN_DLY 2 /* 4ms unit */ -#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ -#define SPIN_INTT_DLY 10 /* 4ms unit */ -#define WINGS_STOP_DLY 4 /* 4ms unit */ +#define EYES_OPEN_DLY 4 /* 4ms unit */ +#define EYES_ICLOSE_DLY 4 /* 4ms unit */ +#define MOUTH_OPEN_DLY 2 /* 4ms unit */ +#define MOUTH_ICLOSE_DLY 8 /* 4ms unit */ +#define SPIN_INTT_DLY 10 /* 4ms unit */ +#define WINGS_STOP_DLY 4 /* 4ms unit */ /* * -------------------------------------------------------- @@ -182,14 +181,14 @@ * gStatus.sw: Switch Status */ -#define GSTATUS_LEFTWINGBTN_MK STATUS_LEFTWINGBTN_MK -#define GSTATUS_RIGHTWINGBTN_MK STATUS_RIGHTWINGBTN_MK -#define GSTATUS_POWERPLUGSW_MK STATUS_POWERPLUGSW_MK -#define GSTATUS_HEADBTN_MK STATUS_HEADBTN_MK -#define GSTATUS_CHARGER_MK STATUS_CHARGER_MK -#define GSTATUS_RF_MK STATUS_RF_MK -#define GSTATUS_VCC_MK STATUS_VCC_MK -#define GSTATUS_MUTE_MK STATUS_MUTE_MK +#define GSTATUS_LEFTWINGBTN_MK STATUS_LEFTWINGBTN_MK +#define GSTATUS_RIGHTWINGBTN_MK STATUS_RIGHTWINGBTN_MK +#define GSTATUS_POWERPLUGSW_MK STATUS_POWERPLUGSW_MK +#define GSTATUS_HEADBTN_MK STATUS_HEADBTN_MK +#define GSTATUS_CHARGER_MK STATUS_CHARGER_MK +#define GSTATUS_RF_MK STATUS_RF_MK +#define GSTATUS_VCC_MK STATUS_VCC_MK +#define GSTATUS_MUTE_MK STATUS_MUTE_MK /* * gStatus.pos: Position Status (Eyes - Wings - Mouth) @@ -223,8 +222,8 @@ * gStatus.bat: Orientation Status */ -#define GSTATUS_ORI_ORI 0x03 /* Orientation mask */ -#define GSTATUS_ORI_CNT 0xFC /* Turn count mask */ +#define GSTATUS_ORI_ORI 0x03 /* Orientation mask */ +#define GSTATUS_ORI_CNT 0xFC /* Turn count mask */ /* * gStatus.mot: Motors Status @@ -257,9 +256,9 @@ */ /* bits 5-0: - VTCCCCCC (C: RC5 6 bits command) */ -#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ -#define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ -#define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ +#define GSTATUS_IR_VALID _BV(7) /* V: set when RC5 data has been received */ +#define GSTATUS_IR_TOGGLE _BV(6) /* T: toggle bit of the RC5 code */ +#define GSTATUS_IR_COMMAND 0x3F /* T: toggle bit of the RC5 code */ /* * -------------------------------------------------------- @@ -272,12 +271,12 @@ * XXX improve display of bits */ -#define COM_EYES_MK 0x01 /* Eyes motor command mask */ -#define COM_MOUTH_MK 0x02 /* Mouth motor command mask */ +#define COM_EYES_MK 0x01 /* Eyes motor command mask */ +#define COM_MOUTH_MK 0x02 /* Mouth motor command mask */ -#define COM_WINGS_MK 0x20 /* Wings motor */ +#define COM_WINGS_MK 0x20 /* Wings motor */ -#define COM_SPIN_STP_MK 0x80 /* Spin motor stop at bat position */ +#define COM_SPIN_STP_MK 0x80 /* Spin motor stop at bat position */ //#define COM_SPIN_R_MK 0x40 [> Spin Right <] //#define COM_SPIN_L_MK 0x80 [> Spin Left <] @@ -289,14 +288,14 @@ typedef struct { - uint8_t sw; /* Switches */ - uint8_t mic; /* Microphone level */ - uint8_t bat; /* Battery level */ - uint8_t lightL; /* Light level low byte */ - uint8_t lightH; /* Light level high byte */ - uint8_t lightM; /* Light mode */ - uint8_t ir; /* IR RC5 code received from tux's remote */ - uint8_t pos; /* Poitionning */ + uint8_t sw; /* Switches */ + uint8_t mic; /* Microphone level */ + uint8_t bat; /* Battery level */ + uint8_t lightL; /* Light level low byte */ + uint8_t lightH; /* Light level high byte */ + uint8_t lightM; /* Light mode */ + uint8_t ir; /* IR RC5 code received from tux's remote */ + uint8_t pos; /* Poitionning */ } GSTATUS; @@ -305,42 +304,42 @@ /* * Software timers */ -extern uint8_t t4ms_tim; /* 4ms main tick timer */ -extern uint8_t t100ms_tim; /* 100ms tick timer */ -extern uint8_t t1s_tim; /* 1s tick timer XXX unused */ +extern uint8_t t4ms_tim; /* 4ms main tick timer */ +extern uint8_t t100ms_tim; /* 100ms tick timer */ +extern uint8_t t1s_tim; /* 1s tick timer XXX unused */ /* * intflags * Flags that are set inside interrupts, and reset outside when processed */ -uint8_t light_f; /* adc interrupt for light measurement */ -uint8_t batt_f; /* adc interrupt for battery measurement */ -uint8_t ir_f; /* ir code received */ +uint8_t light_f; /* adc interrupt for light measurement */ +uint8_t batt_f; /* adc interrupt for battery measurement */ +uint8_t ir_f; /* ir code received */ /* * Standalone behavior */ -extern uint8_t test_mode; /* normal mode */ +extern uint8_t test_mode; /* normal mode */ /* * General global registers */ extern uint8_t updateStatusFlag, commandProcessFlag, pingCnt, statusFifoFlag; -extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, last_tux_seen; +extern uint8_t ir_delay, ir_flg, ir_oldvalue, alt_mode, ir_send_flg, tux_ir_id, + last_tux_seen; extern uint8_t led_backup; - /* * Condition flags */ -#define COND_RESET_NBR 8 /* number of flags that should be reset, change this according to the table below */ +#define COND_RESET_NBR 8 /* number of flags that should be reset, change this according to the table below */ struct condition_table { /* flags reset by the COND_RESET_CMD */ - uint8_t startup; /* set startup condition at initialization */ + uint8_t startup; /* set startup condition at initialization */ uint8_t head; uint8_t left_flip; uint8_t right_flip; @@ -363,6 +362,6 @@ #define mb_test_condition (PINC & _BV(PC2)) #define sigout_set turnLeftLedOn #define sigout_unset turnLeftLedOff -#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ -#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ +#define sigin_ini() {LED_PT &= ~LED_R_MK; LED_DDR &= ~LED_R_MK;} /* used as signal input */ +#define sigin (LED_PIN & LED_R_MK) /* wait for tester to be as pull up */ #endif Modified: firmware/tuxcore/trunk/i2c.c =================================================================== --- firmware/tuxcore/trunk/i2c.c 2007-04-22 18:12:01 UTC (rev 286) +++ firmware/tuxcore/trunk/i2c.c 2007-04-22 18:13:55 UTC (rev 287) @@ -28,14 +28,14 @@ /* * DEBUG and TEST flags */ -#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ -#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ +#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ +#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ /* DEBUG definitions and variables */ #if (__i2c_debug__) -uint8_t i2cStatus[32]; /* debug only */ +uint8_t i2cStatus[32]; /* debug only */ uint8_t i2cStatusIdx = 0; -extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ +extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ extern uint8_t i2cStatusIdx; #endif #if (__i2c_signals__) @@ -57,11 +57,13 @@ /* I2C status and address variables */ uint8_t i2cDeviceAddrRW; -volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ +volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ + /* send/transmit buffer (outgoing data) */ uint8_t i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; uint8_t i2cSendDataIndex; uint8_t i2cSendDataLength; + /* receive buffer (incoming data) */ uint8_t i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; uint8_t i2cReceiveDataIndex; @@ -69,10 +71,12 @@ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for * writing */ -static void (*i2cSlaveReceive)(uint8_t receiveDataLength, uint8_t* recieveData); +static void (*i2cSlaveReceive) (uint8_t receiveDataLength, + uint8_t * recieveData); /* I2cSlaveTransmit is called when this processor is addressed as a slave for * reading */ -static uint8_t (*i2cSlaveTransmit)(uint8_t transmitDataLengthMax, uint8_t* transmitData); +static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, + uint8_t * transmitData); /* functions */ @@ -89,7 +93,7 @@ /* Setting TWBR. There's a note in the datasheet that TWBR can't be lower * than 10 if the TWI is operated in Master mode */ #if ((F_CPU/1000UL)/I2C_SCL_FREQ_KHZ) < 36 - TWBR = 10; /* smallest TWBR value */ + TWBR = 10; /* smallest TWBR value */ #else TWBR = I2C_TWBR; #endif @@ -109,29 +113,34 @@ /* Set pull-up resistors on I2C bus pins */ #ifdef I2C_PULLUP - PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ - PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ + PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ + PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ #endif -#ifdef TWI_SLA_ENABLED /* If Slave mode: */ +#ifdef TWI_SLA_ENABLED /* If Slave mode: */ /* Set local device address (used in slave mode only) */ TWAR = I2C_TWAR; - TWCR = I2C_MODE; /* enable TWI */ -#else + TWCR = I2C_MODE; /* enable TWI */ +#else #ifdef TWI_M_ENABLED - TWCR = I2C_MODE; /* enable TWI */ + TWCR = I2C_MODE; /* enable TWI */ #endif #endif } /* Set the user function which handles receiving (incoming) data as a slave */ -void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +void +i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func) + (uint8_t receiveDataLength, uint8_t * recieveData)) { i2cSlaveReceive = i2cSlaveRx_func; } /* Set the user function which handles transmitting (outgoing) data as a slave */ -void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)) +void +i2cSetSlaveTransmitHandler(uint8_t(*i2cSlaveTx_func) + (uint8_t transmitDataLengthMax, + uint8_t * transmitData)) { i2cSlaveTransmit = i2cSlaveTx_func; } @@ -145,7 +154,7 @@ { volatile uint8_t wait; - for (wait=0; wait<40; wait++); /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ + for (wait = 0; wait < 40; wait++) ; /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ /* note: when a stop is immediately followed by a start, the slave detects * the stop, need to process the received data and exit the ISR. If it * doesn't have enough time to do this before a new start is set, it will @@ -157,8 +166,8 @@ if (i2cFlags.i2c_busy == 0) // if a start is sent when the TWI is receiving, one of the data will be received as 0x78 instead of 0x80 so we get a corruption there i2cSendStart(); #if (__i2c_signals__) - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ - START_PT |= START_MK; /* 'START' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + START_PT |= START_MK; /* 'START' debug signal */ #endif } @@ -168,9 +177,9 @@ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x02; #endif - i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ + i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif // TWCR = I2C_MODE; TWCR |= I2C_MODE; @@ -179,7 +188,7 @@ static inline void i2cSendStart(void) { #if (__i2c_debug__) - cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ + cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x03; sei(); @@ -197,7 +206,7 @@ TWCR = _BV(TWSTO) | I2C_MODE; i2cFlags.i2c_busy = 0; #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif } @@ -235,7 +244,7 @@ #ifdef TWI_INT_ENABLED ISR(SIG_TWI) { - const static void *twiLookupTable[]={ + const static void *twiLookupTable[] = { &&case_TW_BUS_ERROR, &&case_TW_START, &&case_TW_REP_START, @@ -270,168 +279,164 @@ &&case_TW_NO_INFO, }; - i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ + i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ #if (__i2c_debug__) i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = TW_STATUS; #endif #if (__i2c_signals__) - ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ #endif - goto *twiLookupTable[TWSR>>3]; /* switch(TW_STATUS) */ + goto *twiLookupTable[TWSR >> 3]; /* switch(TW_STATUS) */ { - /* * * Master General * * */ -case_TW_START: /* 0x08: start condition sent */ -case_TW_REP_START: /* 0x10: repeated start condition sent */ + /* * * Master General * * */ + case_TW_START: /* 0x08: start condition sent */ + case_TW_REP_START: /* 0x10: repeated start condition sent */ #if (__i2c_debug__) #endif #if (__i2c_signals__) - START_PT &= ~START_MK; /* 'START' debug signal */ + START_PT &= ~START_MK; /* 'START' debug signal */ #endif - i2cSendDataIndex = 0; /* reset the data index */ - i2cSendByte(i2cDeviceAddrRW); /* send device address */ + i2cSendDataIndex = 0; /* reset the data index */ + i2cSendByte(i2cDeviceAddrRW); /* send device address */ goto END_TABLE; + /* * * Master Transmitter & Receiver status codes * * */ - /* * * Master Transmitter & Receiver status codes * * */ - -case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ -case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ - #if (__i2c_debug__) - #endif - if(i2cSendDataIndex < i2cSendDataLength) + case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ + case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ +#if (__i2c_debug__) +#endif + if (i2cSendDataIndex < i2cSendDataLength) { - i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ + i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ } else { // XXX disabled for the I2C tester for now on // if (fetchCommands()) [> if other commands are ready, fetch them <] - // i2cSendStart(); [> send a repeated start and continue <] + // i2cSendStart(); [> send a repeated start and continue <] // else { - i2cSendStop(); /* no more commands */ - i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ + i2cSendStop(); /* no more commands */ + i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ } } goto END_TABLE; -case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ -case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ -case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ -case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ + case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ + case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ + case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ +#if (__i2c_debug__) +#endif i2cFlags.mt_nack = 1; i2cSendStop(); goto END_TABLE; -case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ + case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ //case_TW_MR_ARB_LOST: /* 0x38: bus arbitration lost */ /* same code as above */ - #if (__i2c_debug__) - #endif +#if (__i2c_debug__) +#endif i2cReset(); goto END_TABLE; -case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ +#if (__i2c_debug__) +#endif // store received data byte // i2cReceiveData[i2cReceiveDataIndex++] = TWDR; // fall-through to see if more bytes will be received -case_TW_MR_SLA_ACK: /* 0x40: slave address acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_SLA_ACK: /* 0x40: slave address acknowledged */ +#if (__i2c_debug__) +#endif // if(i2cReceiveDataIndex < (i2cReceiveDataLength-1)) - // i2cAckReceiveByte(); [> receive more bytes <] + // i2cAckReceiveByte(); [> receive more bytes <] // else - // i2cNackReceiveByte(); [> receive the last byte <] + // i2cNackReceiveByte(); [> receive the last byte <] goto END_TABLE; + /* * * Slave Receiver status codes * * */ - /* * * Slave Receiver status codes * * */ - -case_TW_SR_SLA_ACK: /* 0x60: own SLA+W has been received, ACK has been returned */ -case_TW_SR_ARB_LOST_SLA_ACK: /* 0x68: own SLA+W has been received, ACK has been returned */ -case_TW_SR_GCALL_ACK: /* 0x70: GCA+W has been received, ACK has been returned */ -case_TW_SR_ARB_LOST_GCALL_ACK: /* 0x78: GCA+W has been received, ACK has been returned */ - #if (__i2c_debug__) - #endif + case_TW_SR_SLA_ACK: /* 0x60: own SLA+W has been received, ACK has been returned */ + case_TW_SR_ARB_LOST_SLA_ACK: /* 0x68: own SLA+W has been received, ACK has been returned */ + case_TW_SR_GCALL_ACK: /* 0x70: GCA+W has been received, ACK has been returned */ + case_TW_SR_ARB_LOST_GCALL_ACK: /* 0x78: GCA+W has been received, ACK has been returned */ +#if (__i2c_debug__) +#endif /* we are being addressed as slave for writing (data will be received from master) */ i2cReceiveDataIndex = 0; - i2cFlags.s_nack = 0; /* reset nack flag here, not in user app */ + i2cFlags.s_nack = 0; /* reset nack flag here, not in user app */ if (commandBufIdx <= (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) { - i2cAckReceiveByte(); /* accept data */ + i2cAckReceiveByte(); /* accept data */ } else { - i2cNackReceiveByte(); /* refuse data */ + i2cNackReceiveByte(); /* refuse data */ } goto END_TABLE; -case_TW_SR_DATA_ACK: /* 0x80: data byte has been received, ACK has been returned */ -case_TW_SR_GCALL_DATA_ACK: /* 0x90: data byte has been received, ACK has been returned */ - #if (__i2c_debug__) - #endif - i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* get received data byte */ + case_TW_SR_DATA_ACK: /* 0x80: data byte has been received, ACK has been returned */ + case_TW_SR_GCALL_DATA_ACK: /* 0x90: data byte has been received, ACK has been returned */ +#if (__i2c_debug__) +#endif + i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* get received data byte */ /* check receive buffer status */ - if(i2cReceiveDataIndex < I2C_RECEIVE_DATA_BUFFER_SIZE) + if (i2cReceiveDataIndex < I2C_RECEIVE_DATA_BUFFER_SIZE) { - i2cAckReceiveByte(); /* accept more data */ + i2cAckReceiveByte(); /* accept more data */ } else { - i2cNackReceiveByte(); /* refuse more data */ + i2cNackReceiveByte(); /* refuse more data */ } goto END_TABLE; -case_TW_SR_DATA_NACK: /* 0x88: data byte has been received, NACK has been returned */ -case_TW_SR_GCALL_DATA_NACK: /* 0x98: data byte has been received, NACK has been returned */ - #if (__i2c_debug__) - #endif + case_TW_SR_DATA_NACK: /* 0x88: data byte has been received, NACK has been returned */ + case_TW_SR_GCALL_DATA_NACK: /* 0x98: data byte has been received, NACK has been returned */ +#if (__i2c_debug__) +#endif //i2cReceiveData[i2cReceiveDataIndex++] = TWDR; /* receive last byte XXX check if this is right */ //i2cNackReceiveByte(); //XXX bug here? // receive data byte and return NACK //i2cAckReceiveByte(); [> I should clear the interrupt and enable acknoledge for slave mode (disabled during previous nack) <] - i2cFlags.s_nack = 1; /* XXX check if this flag is reset in all possible conditions */ - i2cReset(); /* reset TWI in slave mode */ + i2cFlags.s_nack = 1; /* XXX check if this flag is reset in all possible conditions */ + i2cReset(); /* reset TWI in slave mode */ goto END_TABLE; /* pass along to restart slave mode */ -case_TW_SR_STOP: /* 0xA0: STOP or REPEATED START has been received while addressed as slave */ - #if (__i2c_debug__) - #endif - if (i2cFlags.s_nack == 0) /* if a nack has been replied, we don't save the received bytes XXX may change this to disable i2c instead of replying a nack so the address will be nacked but this is much more difficult to handle because we need to reenable it and any master mode will reenable it anyway */ - if (i2cReceiveDataIndex == 4) /* add a protection here, in case a start has been sent while receiving or such, the data count may be corrupted */ - i2cSlaveReceive(i2cReceiveDataIndex, i2cReceiveData); /* i2c receive is complete, call i2cSlaveReceive */ - i2cReset(); /* reset TWI in slave mode */ + case_TW_SR_STOP: /* 0xA0: STOP or REPEATED START has been received while addressed as slave */ +#if (__i2c_debug__) +#endif + if (i2cFlags.s_nack == 0) /* if a nack has been replied, we don't save the received bytes XXX may change this to disable i2c instead of replying a nack so the address will be nacked but this is much more difficult to handle because we need to reenable it and any master mode will reenable it anyway */ + if (i2cReceiveDataIndex == 4) /* add a protection here, in case a start has been sent while receiving or such, the data count may be corrupted */ + i2cSlaveReceive(i2cReceiveDataIndex, i2cReceiveData); /* i2c receive is complete, call i2cSlaveReceive */ + i2cReset(); /* reset TWI in slave mode */ goto END_TABLE; + /* * * Slave Transmitter * * */ - /* * * Slave Transmitter * * */ - -case_TW_ST_SLA_ACK: /* 0xA8: own SLA+R has been received, ACK has been returned */ -case_TW_ST_ARB_LOST_SLA_ACK: /* 0xB0: GCA+R has been received, ACK has been returned */ -case_TW_ST_DATA_ACK: /* 0xB8: data byte has been transmitted, ACK has been received */ -case_TW_ST_DATA_NACK: /* 0xC0: data byte has been transmitted, NACK has been received */ -case_TW_ST_LAST_DATA: /* 0xC8: last data byte transmitted, ACK received */ - i2cReset(); /* we don't support slave transmitter, just reset if this happens */ + case_TW_ST_SLA_ACK: /* 0xA8: own SLA+R has been received, ACK has been returned */ + case_TW_ST_ARB_LOST_SLA_ACK: /* 0xB0: GCA+R has been received, ACK has been returned */ + case_TW_ST_DATA_ACK: /* 0xB8: data byte has been transmitted, ACK has been received */ + case_TW_ST_DATA_NACK: /* 0xC0: data byte has been transmitted, NACK has been received */ + case_TW_ST_LAST_DATA: /* 0xC8: last data byte transmitted, ACK received */ + i2cReset(); /* we don't support slave transmitter, just reset if this happens */ goto END_TABLE; + /* * * Misc * * */ - /* * * Misc * * */ - -case_TW_NO_INFO: /* 0xF8: no relevant state information */ + case_TW_NO_INFO: /* 0xF8: no relevant state information */ /* do nothing here */ goto END_TABLE; -case_: -case_TW_BUS_ERROR: /* 0x00: bus error due to illegal start or stop condition */ - #if (__i2c_debug__) - #endif - i2cSendStop(); /* reset internal hardware and release bus */ /* XXX need to test if this works or not */ + case_: + case_TW_BUS_ERROR: /* 0x00: bus error due to illegal start or stop condition */ +#if (__i2c_debug__) +#endif + i2cSendStop(); /* reset internal hardware and release bus *//* XXX need to test if this works or not */ goto END_TABLE; } -END_TABLE: + END_TABLE: #if (__i2c_signals__) - ISR_PT &= ~ISR_MK; /* 'I2C ISR' debug signal */ + ISR_PT &= ~ISR_MK; /* 'I2C ISR' debug signal */ #endif return; } Modified: firmware/tuxcore/trunk/i2c.h =========================... [truncated message content] |