[tuxdroid-svn] r285 - 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:10:00
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 285 Modified: firmware/tuxaudio/trunk/bootloader.c firmware/tuxaudio/trunk/communication.c firmware/tuxaudio/trunk/communication.h firmware/tuxaudio/trunk/config.c firmware/tuxaudio/trunk/config.h firmware/tuxaudio/trunk/fifo.c firmware/tuxaudio/trunk/fifo.h firmware/tuxaudio/trunk/flash.c firmware/tuxaudio/trunk/flash.h firmware/tuxaudio/trunk/i2c.c firmware/tuxaudio/trunk/i2c.h firmware/tuxaudio/trunk/init.c firmware/tuxaudio/trunk/init.h firmware/tuxaudio/trunk/interrupt.c firmware/tuxaudio/trunk/main.c firmware/tuxaudio/trunk/spi.c firmware/tuxaudio/trunk/spi.h firmware/tuxaudio/trunk/test.c firmware/tuxaudio/trunk/test.h firmware/tuxaudio/trunk/varis.c firmware/tuxaudio/trunk/varis.h firmware/tuxaudio/trunk/version.h Log: doegox 2007-04-22 20:09:42 +0200 (Sun, 22 Apr 2007) 147 Reindent with: indent -nut -i4 -bad -bap -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: firmware/tuxaudio/trunk/bootloader.c =================================================================== --- firmware/tuxaudio/trunk/bootloader.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/bootloader.c 2007-04-22 18:09:42 UTC (rev 285) @@ -32,7 +32,7 @@ uint8_t b[2]; } union16_t; -void (*jump_to_application)(void) = (void *)0x0000; +void (*jump_to_application) (void) = (void *)0x0000; void i2cWaitForComplete(void); /** \ingroup minimal_bootloader @@ -44,13 +44,13 @@ union16_t pageAddress, data; uint16_t address; uint8_t i, twStatus, eeprom_flg = 0; - volatile uint8_t _count=0; + volatile uint8_t _count = 0; - PORTC = 0x08; /* head button on PC3 */ - DDRC=0x08; /* force the head button up for a short period to quickly charge the capacitance */ - for (_count = 0;_count<50; _count++); - DDRC=0x00; /* then set as pull-up */ - if ((PINC & 0x08)) /* and check it */ + PORTC = 0x08; /* head button on PC3 */ + DDRC = 0x08; /* force the head button up for a short period to quickly charge the capacitance */ + for (_count = 0; _count < 50; _count++) ; + DDRC = 0x00; /* then set as pull-up */ + if ((PINC & 0x08)) /* and check it */ jump_to_application(); TWBR = (F_CPU / 100000UL - 16) / 2; /* twi intialisation */ @@ -59,29 +59,35 @@ TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); for (;;) { - i2cWaitForComplete(); /* wait the I2C address */ - if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) while(1); + i2cWaitForComplete(); /* wait the I2C address */ + if ((twStatus = TW_STATUS) != TW_SR_SLA_ACK) + while (1) ; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the high byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the high byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[1] = TWDR; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - i2cWaitForComplete(); /* wait the low byte of the page address */ - if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) while(1); + i2cWaitForComplete(); /* wait the low byte of the page address */ + if ((twStatus = TW_STATUS) != TW_SR_DATA_ACK) + while (1) ; pageAddress.b[0] = TWDR; - if (pageAddress.w & 0x003F) while(1); /* incorrect page address */ - if (pageAddress.w >= 0x8000) /* eeprom programming */ + if (pageAddress.w & 0x003F) + while (1) ; /* incorrect page address */ + if (pageAddress.w >= 0x8000) /* eeprom programming */ { - eeprom_flg = 1; /* don't overwrite the bootloader */ - pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ + eeprom_flg = 1; /* don't overwrite the bootloader */ + pageAddress.b[1] &= 0x7F; /* remove the eeprom indication bit */ } - else if (pageAddress.w >= 0x1E00) while(1); /* don't overwrite the bootloader */ - else eeprom_flg = 0; /* flash programming */ + else if (pageAddress.w >= 0x1E00) + while (1) ; /* don't overwrite the bootloader */ + else + eeprom_flg = 0; /* flash programming */ address = pageAddress.w; TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); - for (i=0; i<SPM_PAGESIZE; i++) /* fill the complete page with the next data */ + for (i = 0; i < SPM_PAGESIZE; i++) /* fill the complete page with the next data */ { - i2cWaitForComplete(); /* wait data */ + i2cWaitForComplete(); /* wait data */ if ((twStatus = TW_STATUS) == TW_SR_DATA_ACK) { if ((i & 0x01) == 0) @@ -93,31 +99,33 @@ data.b[1] = TWDR; if (eeprom_flg) { - eeprom_write_word ((uint16_t *)address, data.w); + eeprom_write_word((uint16_t *) address, data.w); eeprom_busy_wait(); } else - boot_page_fill (address, data.w); + boot_page_fill(address, data.w); address += 2; } TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); } - else while(1); /* error in communication */ + else + while (1) ; /* error in communication */ } i2cWaitForComplete(); - if ((twStatus = TW_STATUS) != TW_SR_STOP) while(1); /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ - TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ + if ((twStatus = TW_STATUS) != TW_SR_STOP) + while (1) ; /* if no stop at this exact position, there's something wrong with the number of bytes sent, we cancel */ + TWCR = _BV(TWEA) | _BV(TWEN) | _BV(TWINT); /* clear the interrupt immediately so not to miss the next frame */ if (!eeprom_flg) { - boot_page_erase (pageAddress.w); - boot_spm_busy_wait (); - boot_page_write (pageAddress.w); /* Store buffer in flash page */ - boot_spm_busy_wait (); + boot_page_erase(pageAddress.w); + boot_spm_busy_wait(); + boot_page_write(pageAddress.w); /* Store buffer in flash page */ + boot_spm_busy_wait(); } } } -void i2cWaitForComplete (void) +void i2cWaitForComplete(void) { - while( !(TWCR & _BV(TWINT)) ); /* wait for i2c interface to complete operation */ + while (!(TWCR & _BV(TWINT))) ; /* wait for i2c interface to complete operation */ } Modified: firmware/tuxaudio/trunk/communication.c =================================================================== --- firmware/tuxaudio/trunk/communication.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/communication.c 2007-04-22 18:09:42 UTC (rev 285) @@ -33,7 +33,7 @@ uint8_t i2c_idle_time = I2C_IDLE_RESET; #ifdef __com_debug__ -uint8_t errorNbr=0; +uint8_t errorNbr = 0; void comError(void) { errorNbr = 1; @@ -53,8 +53,10 @@ * order they were issued when the stack holds multiple commands. */ uint8_t commandBuf[COMMAND_BUF_SIZE]; -fifo_t _commandFifo = {(uint8_t *)commandBuf, sizeof commandBuf-1, 0, 0}, *commandFifo = &_commandFifo; +fifo_t _commandFifo = { (uint8_t *) commandBuf, sizeof commandBuf - 1, 0, 0 } +, *commandFifo = &_commandFifo; + /* * audioBuf is a single buffer for commands received over i2c to control the * audio interface @@ -64,17 +66,19 @@ * cleared when the command is processed so it can be used to check whether the * buffer has been processed or not. */ -uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -uint8_t audioBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ +uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +uint8_t audioBufIdx = 0; /* index indicating the number of valid bytes in the buffer */ /* * statusFifo is a fifo buffer for commands received from the i2c and that * should be sent over the RF link * */ -uint8_t statusBuf[INCOMING_BUF_SIZE]; /* statusBuf is used for commands received from the i2c and should be sent over the RF link */ -fifo_t _statusBuf = {(uint8_t *)statusBuf, sizeof statusBuf-1, 0, 0}, *statusFifo = &_statusBuf; +uint8_t statusBuf[INCOMING_BUF_SIZE]; /* statusBuf is used for commands received from the i2c and should be sent over the RF link */ +fifo_t _statusBuf = { (uint8_t *) statusBuf, sizeof statusBuf - 1, 0, 0 } +, *statusFifo = &_statusBuf; + /* * I2C communication initalisation * @@ -83,10 +87,10 @@ */ void i2cCommunicationInit(void) { - i2cInit(); /* start twi interface */ - i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ - i2cDeviceAddrRW = 0x54; /* set behaviour CPU device address */ - i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission*/ + i2cInit(); /* start twi interface */ + i2cSetSlaveReceiveHandler(i2cSlaveReceiveService); /* set receive function */ + i2cDeviceAddrRW = 0x54; /* set behaviour CPU device address */ + i2cFlags.m_end = 1; /* set master transmission end flag to enable the first transmission */ } /* @@ -103,10 +107,10 @@ { uint8_t i; - if (!(i2cFlags.i2c_busy)) /* i2c hardware not busy */ + if (!(i2cFlags.i2c_busy)) /* i2c hardware not busy */ { i2c_idle_time = I2C_IDLE_RESET; - if (i2cFlags.mt_nack) /* if nack error, resend previous command */ + if (i2cFlags.mt_nack) /* if nack error, resend previous command */ { i2cMasterStart(); cli(); @@ -114,28 +118,28 @@ i2cFlags.i2c_busy = 1; sei(); } - else if (i2cFlags.m_end == 0) /* previous transmission was cancelled by arbitration lost or any problem so restart */ + else if (i2cFlags.m_end == 0) /* previous transmission was cancelled by arbitration lost or any problem so restart */ { i2cMasterStart(); cli(); i2cFlags.i2c_busy = 1; sei(); } - else if (!isFifoEmpty(commandFifo)) /* elsif no error and previous transmission is finished and if there's something to send, get the next value */ + else if (!isFifoEmpty(commandFifo)) /* elsif no error and previous transmission is finished and if there's something to send, get the next value */ { cli(); - i2cFlags.i2c_idx = 1; /* protect commandFifo from external changes */ + i2cFlags.i2c_idx = 1; /* protect commandFifo from external changes */ i2cFlags.m_end = 0; /* reset master transmission end flag */ sei(); i2cSendDataLength = MAX_COMMAND_SIZE; - for (i=0; i<=MAX_COMMAND_SIZE; i++) + for (i = 0; i <= MAX_COMMAND_SIZE; i++) { if (popFifo(commandFifo, &i2cSendData[i])) - i2cSendDataLength = 0; /* drop the data if the fifo seems corrupted XXX add an error feedback on this */ + i2cSendDataLength = 0; /* drop the data if the fifo seems corrupted XXX add an error feedback on this */ } i2cMasterStart(); cli(); - i2cFlags.i2c_idx = 0; /* release commandFifo protection */ + i2cFlags.i2c_idx = 0; /* release commandFifo protection */ i2cFlags.i2c_busy = 1; sei(); } @@ -144,8 +148,9 @@ else if (!i2c_idle_time--) { uint16_t wait = 0; + TWCR = 0; - while(wait++ < 0xFFF0); + while (wait++ < 0xFFF0) ; i2cFlags.i2c_busy = 0; i2cFlags.m_end = 0; i2cFlags.mt_nack = 0; @@ -163,15 +168,15 @@ * * The command[] parameter format starts with the command and then the parameters */ -uint8_t pushCommands(uint8_t* command) +uint8_t pushCommands(uint8_t * command) { uint8_t i; if (*command) { - if (fifoLength(commandFifo) > (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) /* Tux stack is full, we send an error back */ + if (fifoLength(commandFifo) > (COMMAND_BUF_SIZE - MAX_COMMAND_SIZE)) /* Tux stack is full, we send an error back */ return 1; - for (i=0; i<=MAX_COMMAND_SIZE; i++) + for (i = 0; i <= MAX_COMMAND_SIZE; i++) pushFifo(commandFifo, *command++); return 0; } @@ -184,12 +189,13 @@ */ void acceptData(void) { - if (TWDR < 0xC0) /* command to be executed, cannot have 3 parameters */ + if (TWDR < 0xC0) /* command to be executed, cannot have 3 parameters */ { - if (!audioBufIdx) i2cFlags.s_val = 1; /* previous command processed */ + if (!audioBufIdx) + i2cFlags.s_val = 1; /* previous command processed */ } else if (fifoLength(statusFifo) < (INCOMING_FIFO_SIZE - MAX_COMMAND_SIZE)) - i2cFlags.s_val = 1; /* status with 3 parameters */ + i2cFlags.s_val = 1; /* status with 3 parameters */ } /* @@ -198,30 +204,31 @@ * Only do a backup of the buffer so any new i2c data won't overwrite the * previous ones */ -uint8_t pong_received; /* value of the pong received from the behavior */ -uint8_t pong_missed; /* counting the pong missed on the I2C */ +uint8_t pong_received; /* value of the pong received from the behavior */ +uint8_t pong_missed; /* counting the pong missed on the I2C */ -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData) +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData) { - uint8_t i; + uint8_t i; - if (*receiveData < 0xC0) /* (audio) command to be executed, can't have 3 parameters */ + if (*receiveData < 0xC0) /* (audio) command to be executed, can't have 3 parameters */ { - for (i=0; i<receiveDataLength; i++) audioBuf[i] = receiveData[i]; + for (i = 0; i < receiveDataLength; i++) + audioBuf[i] = receiveData[i]; audioBufIdx = receiveDataLength; /* XXX only fill buffer if it's not full, need to add the check */ } - else /* fill in the statusFifo buffer */ + else /* fill in the statusFifo buffer */ { /* Pong check */ if (receiveData[0] == PONG_CMD) { - if (pong_received-- < receiveData[1]) /* new ping, reset */ + if (pong_received-- < receiveData[1]) /* new ping, reset */ { pong_received = receiveData[1]; pong_missed = 0; } - else if (pong_received > receiveData[1]) /* pongs missed */ + else if (pong_received > receiveData[1]) /* pongs missed */ { pong_missed++; pong_received = receiveData[1]; /* resync */ @@ -231,7 +238,7 @@ /* Store data on the fifo buffer */ if (fifoLength(statusFifo) < INCOMING_FIFO_SIZE - MAX_COMMAND_SIZE) - for (i=0; i<MAX_COMMAND_SIZE; i++) + for (i = 0; i < MAX_COMMAND_SIZE; i++) pushFifo(statusFifo, receiveData[i]); /* XXX add a return in case data was not added */ } @@ -244,20 +251,20 @@ * * The command[] parameter format starts with the command and then the parameters */ -uint8_t popStatus(uint8_t* command) +uint8_t popStatus(uint8_t * command) { uint8_t i; if (isFifoEmpty(statusFifo)) - return 1; /* nothing to do */ + return 1; /* nothing to do */ - cli(); /* XXX try to disable I2C interrupts instead */ - for (i=0; i<MAX_COMMAND_SIZE; i++) - if (popFifo(statusFifo, &command[i])) - { - sei(); - return 1; /* fifo corrupted so drop data XXX add some debug feedback on this instead of dropping data */ - } + cli(); /* XXX try to disable I2C interrupts instead */ + for (i = 0; i < MAX_COMMAND_SIZE; i++) + if (popFifo(statusFifo, &command[i])) + { + sei(); + return 1; /* fifo corrupted so drop data XXX add some debug feedback on this instead of dropping data */ + } sei(); return 0; } Modified: firmware/tuxaudio/trunk/communication.h =================================================================== --- firmware/tuxaudio/trunk/communication.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/communication.h 2007-04-22 18:09:42 UTC (rev 285) @@ -26,26 +26,28 @@ #include "fifo.h" #define COMMAND_BUF_SIZE 16 -#define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ +#define COMMAND_FIFO_SIZE (COMMAND_BUF_SIZE - 1) /* due to the fifo construction */ #define MAX_COMMAND_SIZE 4 #define INCOMING_BUF_SIZE 32 -#define INCOMING_FIFO_SIZE (INCOMING_BUF_SIZE - 1) /* due to the fifo construction */ +#define INCOMING_FIFO_SIZE (INCOMING_BUF_SIZE - 1) /* due to the fifo construction */ -extern uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ -extern uint8_t audioBufIdx; /* index indicating the number of valid bytes in the buffer */ +extern uint8_t audioBuf[MAX_COMMAND_SIZE]; /* single buffer for commands received over i2c to control the audio interface */ +extern uint8_t audioBufIdx; /* index indicating the number of valid bytes in the buffer */ -extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ +extern fifo_t *statusFifo; /* incomingBuf is used for commands received from the i2c and should be sent over the RF link */ void i2cCommunicationInit(void); + /* From RF to i2c */ void sendCommands(void); -uint8_t pushCommands(uint8_t* command); +uint8_t pushCommands(uint8_t * command); + /* From i2c to RF */ void acceptData(void); -void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t* receiveData); -uint8_t popStatus(uint8_t* command); +void i2cSlaveReceiveService(uint8_t receiveDataLength, uint8_t * receiveData); +uint8_t popStatus(uint8_t * command); /* XXX move to a global definition file */ -#define AUDIO_STATE 0xE0 /* state of the audio interface */ +#define AUDIO_STATE 0xE0 /* state of the audio interface */ -#endif /* COMMUNICATION_H */ +#endif /* COMMUNICATION_H */ Modified: firmware/tuxaudio/trunk/config.c =================================================================== --- firmware/tuxaudio/trunk/config.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/config.c 2007-04-22 18:09:42 UTC (rev 285) @@ -31,11 +31,15 @@ /* Initialize the configuration registers */ void config_init(void) { - eeprom_read_block((void*)&tuxaudio_config, (const void*)&tuxaudio_config_default, sizeof(tuxaudio_config_t)); + eeprom_read_block((void *)&tuxaudio_config, + (const void *)&tuxaudio_config_default, + sizeof(tuxaudio_config_t)); } /* Save the configuration registers to the eeprom */ void config_write(void) { - eeprom_write_block((const void*)&tuxaudio_config, (void*)&tuxaudio_config_default, sizeof(tuxaudio_config_t)); + eeprom_write_block((const void *)&tuxaudio_config, + (void *)&tuxaudio_config_default, + sizeof(tuxaudio_config_t)); } Modified: firmware/tuxaudio/trunk/config.h =================================================================== --- firmware/tuxaudio/trunk/config.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/config.h 2007-04-22 18:09:42 UTC (rev 285) @@ -30,4 +30,3 @@ void config_init(void); #endif /* CONFIG_H */ - Modified: firmware/tuxaudio/trunk/fifo.c =================================================================== --- firmware/tuxaudio/trunk/fifo.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/fifo.c 2007-04-22 18:09:42 UTC (rev 285) @@ -68,31 +68,31 @@ * \param p fifo pointer * * Note that the first element in the fifo will be stored in p->buffer[1] and not p->buffer[0] */ -void resetFifo(fifo_t *p) +void resetFifo(fifo_t * p) { p->inIdx = 0; p->outIdx = 0; p->pwm_adpt_sens = 0; - p->adpt_cycle=0; - p->matched=0; - p->pwm_min=230; - p->pwm_max=255; + p->adpt_cycle = 0; + p->matched = 0; + p->pwm_min = 230; + p->pwm_max = 255; } /** \brief Return TRUE if the fifo buffer is full (28b). * \param p fifo pointer * \return TRUE if fifo buffer is full */ -uint8_t isFifoFull(fifo_t *p) +uint8_t isFifoFull(fifo_t * p) { - return (p->outIdx == (((uint8_t)(p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return (p->outIdx == (((uint8_t) (p->inIdx + 1)) & p->size)); /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Return TRUE if the fifo buffer is empty (22b). * \param p fifo pointer * \return TRUE if fifo buffer is empty */ -uint8_t isFifoEmpty(fifo_t *p) +uint8_t isFifoEmpty(fifo_t * p) { return (p->outIdx == p->inIdx); } @@ -101,9 +101,9 @@ * \param p fifo pointer * \return number of elements in the buffer */ -uint8_t fifoLength(fifo_t *p) +uint8_t fifoLength(fifo_t * p) { - return ((uint8_t)(p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + return ((uint8_t) (p->inIdx - p->outIdx)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ } /** \brief Add one data byte to the fifo buffer (32b). @@ -112,15 +112,15 @@ * * If the fifo is already full, return immediately without doing anything. */ -void pushFifo(fifo_t *p, uint8_t data) +void pushFifo(fifo_t * p, uint8_t data) { - uint8_t inIdx; /* use of a local variable to reduce code size */ + uint8_t inIdx; /* use of a local variable to reduce code size */ - inIdx = ((uint8_t)(p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ - if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ + inIdx = ((uint8_t) (p->inIdx + 1)) & p->size; /* typecast necessary because the sum is promoted to an int and without the type cast we can have negative values which after the modulo are still negative values. See modulo section above */ + if (p->outIdx != inIdx) /* full if p->outIdx == p->inIdx + 1 % wrap-around, if not full: */ { - p->inIdx = inIdx; /* ++ index */ - p->buffer[inIdx] = data; /* stora data */ + p->inIdx = inIdx; /* ++ index */ + p->buffer[inIdx] = data; /* stora data */ } } @@ -133,16 +133,17 @@ * fifo is empty, the index is not decreased, '1' is returned and the pointed * data is left unchanged. */ -uint8_t popFifo(fifo_t *p, uint8_t *data) +uint8_t popFifo(fifo_t * p, uint8_t * data) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ - *data = p->buffer[p->outIdx]; /* get data */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ + *data = p->buffer[p->outIdx]; /* get data */ return 0; } - else return 1; + else + return 1; } /** \brief Pull the oldest byte from the fifo, always return something even if @@ -153,15 +154,16 @@ * If the fifo is empty, the index is not decreased but the latest value is * returned. */ -uint8_t pullFifo(fifo_t *p) +uint8_t pullFifo(fifo_t * p) { - if (p->outIdx != p->inIdx) /* if fifo is not empty */ + if (p->outIdx != p->inIdx) /* if fifo is not empty */ { - p->outIdx++; /* ++ index */ - p->outIdx = p->outIdx & p->size; /* wrap-around */ + p->outIdx++; /* ++ index */ + p->outIdx = p->outIdx & p->size; /* wrap-around */ } - return p->buffer[p->outIdx]; /* get data in all cases */ + return p->buffer[p->outIdx]; /* get data in all cases */ } + /*@}*/ /** @@ -177,24 +179,24 @@ * each level, a custom code or a function call can be provided to do the * adaptation. */ -void adaptFifo(fifo_t *p) +void adaptFifo(fifo_t * p) { unsigned char fifoLevel; - fifoLevel=fifoLength(p); - if(!p->adpt_cycle) + fifoLevel = fifoLength(p); + if (!p->adpt_cycle) { - if (p->matched==8) + if (p->matched == 8) { - if (OCR0A<254) - p->pwm_max=OCR0A+2; + if (OCR0A < 254) + p->pwm_max = OCR0A + 2; else - p->pwm_max=255; - if (OCR0A>231) - p->pwm_min=OCR0A-2; + p->pwm_max = 255; + if (OCR0A > 231) + p->pwm_min = OCR0A - 2; else - p->pwm_min=230; - p->matched=9; + p->pwm_min = 230; + p->matched = 9; } if (fifoLevel >= FIFO_ADAPT_HIGH) @@ -202,7 +204,7 @@ if (OCR0A > p->pwm_min) { OCR0A--; - p->pwm_adpt_sens=1; + p->pwm_adpt_sens = 1; } } else if (fifoLevel < FIFO_ADAPT_LOW) @@ -210,13 +212,13 @@ if (OCR0A < p->pwm_max) { OCR0A++; - p->pwm_adpt_sens=2; + p->pwm_adpt_sens = 2; } } else { if (p->pwm_adpt_sens) - { + { if ((p->pwm_adpt_sens) == 1) { if (OCR0A < p->pwm_max) @@ -228,17 +230,17 @@ OCR0A--; } p->pwm_adpt_sens = 0; - p->matched=0; + p->matched = 0; } else { - if (p->matched!=9) + if (p->matched != 9) p->matched++; } } } p->adpt_cycle++; - p->adpt_cycle&=(FIFO_ADAPT_RATE << 1)-1; + p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1; } /*@}*/ Modified: firmware/tuxaudio/trunk/fifo.h =================================================================== --- firmware/tuxaudio/trunk/fifo.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/fifo.h 2007-04-22 18:09:42 UTC (rev 285) @@ -96,13 +96,13 @@ /** \brief UD- Rate at which the adaptation is done. * * The adaptation function will only be run each 2^FIFO_ADAPT_RATE sample */ -#define FIFO_ADAPT_RATE 1 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ +#define FIFO_ADAPT_RATE 1 /* adaptation is done each 2^FIFO_ADAPT_RATE sample */ /** \brief UD- High level threshold */ -#define FIFO_ADAPT_HIGH 64// (p->size - (p->size>>2)) /* 3/4 of size */ +#define FIFO_ADAPT_HIGH 64 // (p->size - (p->size>>2)) /* 3/4 of size */ /** \brief UD- Low level threshold */ -#define FIFO_ADAPT_LOW 17// (p->size>>2) /* 1/4 of size */ +#define FIFO_ADAPT_LOW 17 // (p->size>>2) /* 1/4 of size */ #define FIFO_MATCHED_THRESHOLD 8 @@ -112,29 +112,30 @@ Note that the buffer can only hold (size - 1) elements to be able to make the difference between completely full and completely empty states. */ -typedef struct fifo_s { +typedef struct fifo_s +{ /** array that will store the elements */ - uint8_t *buffer; + uint8_t *buffer; /** size of the fifo buffer array minus 1 * The wrap around is made by a 'AND' function so the AND should be made with * the (array size -1) to be able to clear all bits above the array size. * This -1 is not related to the fact that the buffer can only hold (size -1) * elements. */ - uint8_t size; + uint8_t size; /** input index which indexes the last pushed value */ - uint8_t inIdx; + uint8_t inIdx; /** output index which indexes the last popped value */ - uint8_t outIdx; + uint8_t outIdx; /** current sens : increment or decrement pwm value */ - uint8_t pwm_adpt_sens; + uint8_t pwm_adpt_sens; /** cycle counter of adaptative function */ - uint8_t adpt_cycle; + uint8_t adpt_cycle; /** counter of good pwm value */ - uint8_t matched; + uint8_t matched; /** min value of pwm range */ - uint8_t pwm_min; + uint8_t pwm_min; /** max value of pwm range */ - uint8_t pwm_max; + uint8_t pwm_max; } fifo_t; @@ -142,13 +143,13 @@ * Extern declarations */ -void resetFifo(fifo_t *p); -uint8_t isFifoFull(fifo_t *p); -uint8_t isFifoEmpty(fifo_t *p); -uint8_t fifoLength(fifo_t *p); -void pushFifo(fifo_t *p, uint8_t data); -uint8_t popFifo(fifo_t *p, uint8_t *data); -uint8_t pullFifo(fifo_t *p); -void adaptFifo(fifo_t *p); +void resetFifo(fifo_t * p); +uint8_t isFifoFull(fifo_t * p); +uint8_t isFifoEmpty(fifo_t * p); +uint8_t fifoLength(fifo_t * p); +void pushFifo(fifo_t * p, uint8_t data); +uint8_t popFifo(fifo_t * p, uint8_t * data); +uint8_t pullFifo(fifo_t * p); +void adaptFifo(fifo_t * p); #endif /* FIFO_H */ Modified: firmware/tuxaudio/trunk/flash.c =================================================================== --- firmware/tuxaudio/trunk/flash.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/flash.c 2007-04-22 18:09:42 UTC (rev 285) @@ -24,237 +24,229 @@ #include "spi.h" #include "i2c.h" -unsigned char read_status (void); -void write_enable (void); -void write_disable (void); -void write_status (unsigned char status); -void erase_flash (void); -unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0); -void programmingAudio (void); -void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0); -void playingAudio (unsigned char nsound); -void stopPlayingAudio (void); +unsigned char read_status(void); +void write_enable(void); +void write_disable(void); +void write_status(unsigned char status); +void erase_flash(void); +unsigned char read_data(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +void programmingAudio(void); +void unprotect_sector(unsigned char ad2, unsigned char ad1, unsigned char ad0); +void playingAudio(unsigned char nsound); +void stopPlayingAudio(void); - -unsigned char read_status (void) +unsigned char read_status(void) { - unsigned char status; + unsigned char status; + PORTB &= ~0x02; // Chip Select - PORTB &= ~0x02; // Chip Select + spiSend(0x05); // Send Read Status Command + status = spiSend(0x00); // Read status on spi - spiSend (0x05); // Send Read Status Command - status = spiSend (0x00); // Read status on spi + PORTB |= 0x02; // Chip Deselect - PORTB |= 0x02; // Chip Deselect - return status; } - -void write_enable (void) +void write_enable(void) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x06); // Send Write Enable Command + spiSend(0x06); // Send Write Enable Command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void write_disable (void) +void write_disable(void) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x04); // Send Write Disable Command + spiSend(0x04); // Send Write Disable Command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void write_status (unsigned char status) +void write_status(unsigned char status) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x01); // Send Write Status Command - spiSend (status); // Send status + spiSend(0x01); // Send Write Status Command + spiSend(status); // Send status - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0) +void unprotect_sector(unsigned char ad2, unsigned char ad1, unsigned char ad0) { - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x39); // Send unprotect sector command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); + spiSend(0x39); // Send unprotect sector command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect } - -void erase_flash (void) +void erase_flash(void) { - write_status (0x00); // Disable sector protection register - write_enable(); // Enable the writing - unprotect_sector (0x00, 0x00, 0x00); // Unprotected sector 0 - write_enable(); // Enable the writing - unprotect_sector (0x01, 0x00, 0x00); // Unprotected sector 1 - write_enable(); // Enable the writing - unprotect_sector (0x02, 0x00, 0x00); // Unprotected sector 2 - write_enable(); // Enable the writing - unprotect_sector (0x03, 0x00, 0x00); // Unprotected sector 3 - write_enable(); // Enable the writing - unprotect_sector (0x04, 0x00, 0x00); // Unprotected sector 4 - write_enable(); // Enable the writing - unprotect_sector (0x05, 0x00, 0x00); // Unprotected sector 5 - write_enable(); // Enable the writing - unprotect_sector (0x06, 0x00, 0x00); // Unprotected sector 6 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0x00, 0x00); // Unprotected sector 7 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0x80, 0x00); // Unprotected sector 8 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0xA0, 0x00); // Unprotected sector 9 - write_enable(); // Enable the writing - unprotect_sector (0x07, 0xC0, 0x00); // Unprotected sector 10 + write_status(0x00); // Disable sector protection register + write_enable(); // Enable the writing + unprotect_sector(0x00, 0x00, 0x00); // Unprotected sector 0 + write_enable(); // Enable the writing + unprotect_sector(0x01, 0x00, 0x00); // Unprotected sector 1 + write_enable(); // Enable the writing + unprotect_sector(0x02, 0x00, 0x00); // Unprotected sector 2 + write_enable(); // Enable the writing + unprotect_sector(0x03, 0x00, 0x00); // Unprotected sector 3 + write_enable(); // Enable the writing + unprotect_sector(0x04, 0x00, 0x00); // Unprotected sector 4 + write_enable(); // Enable the writing + unprotect_sector(0x05, 0x00, 0x00); // Unprotected sector 5 + write_enable(); // Enable the writing + unprotect_sector(0x06, 0x00, 0x00); // Unprotected sector 6 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0x00, 0x00); // Unprotected sector 7 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0x80, 0x00); // Unprotected sector 8 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0xA0, 0x00); // Unprotected sector 9 + write_enable(); // Enable the writing + unprotect_sector(0x07, 0xC0, 0x00); // Unprotected sector 10 - write_enable(); // Enable the writing + write_enable(); // Enable the writing - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0xC7); // Send Erase Bulk command + spiSend(0xC7); // Send Erase Bulk command - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - while (read_status()!= 0x10); // Wait Bulk Erase Cycle + while (read_status() != 0x10) ; // Wait Bulk Erase Cycle } - -void program_flash (unsigned char ad2, unsigned char ad1, unsigned char ad0, unsigned char data) +void program_flash(unsigned char ad2, unsigned char ad1, unsigned char ad0, + unsigned char data) { - write_enable (); + write_enable(); - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x02); // Send Page Byte Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - spiSend (data); // Write data in flash + spiSend(0x02); // Send Page Byte Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + spiSend(data); // Write data in flash - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - while (read_status() != 0x10); // Wait Page Program Cycle + while (read_status() != 0x10) ; // Wait Page Program Cycle } - -unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0) +unsigned char read_data(unsigned char ad2, unsigned char ad1, unsigned char ad0) { - unsigned char data1; + unsigned char data1; - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - data1 = spiSend (0x00); // Wait response + spiSend(0x03); // Send Read Page Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + data1 = spiSend(0x00); // Wait response - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect - return data1; + return data1; } - -void programmingAudio (void) +void programmingAudio(void) { unsigned char ad0, ad1, ad2, i, j; - TCCR0A=0x00; // Desactivate PWM - TCCR0B=0x00; - OCR0A=0x00; - TIMSK0=0x00; + TCCR0A = 0x00; // Desactivate PWM + TCCR0B = 0x00; + OCR0A = 0x00; + TIMSK0 = 0x00; TWCR = (TWCR & TWCR_CMD_MASK) & ~_BV(TWIE); // Desactivate I2C // Deactivate all interrupt - resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ + resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ - programmingFlash = 1; // Set the flag to suspend the task + programmingFlash = 1; // Set the flag to suspend the task // First step ERASE FLASH - erase_flash (); // Erase the flash + erase_flash(); // Erase the flash // Second step WRITE FIRST BYTE OF TOC - program_flash (0x00, 0x00, 0x00, numSound); // Write first byte of the TOC + program_flash(0x00, 0x00, 0x00, numSound); // Write first byte of the TOC // Third step WRITE TOC - ad0 = 0x01; // Init TOC address + ad0 = 0x01; // Init TOC address ad1 = 0x00; ad2 = 0x00; - for (i = 0; i <= numSound; i++) // Writing TOC + for (i = 0; i <= numSound; i++) // Writing TOC { - while (!TOCRX); // Wait TOC address incomming - TOCRX = 0; // Reset TOC incomming flag + while (!TOCRX) ; // Wait TOC address incomming + TOCRX = 0; // Reset TOC incomming flag for (j = 0; j < 3; j++) { - program_flash (ad2, ad1, ad0, TOCadress[j]); - ad0++; // Increment new adress + program_flash(ad2, ad1, ad0, TOCadress[j]); + ad0++; // Increment new adress if (ad0 == 0x00) ad1++; } } - ad[0] = TOCadress[2]; // Save final addres + ad[0] = TOCadress[2]; // Save final addres ad[1] = TOCadress[1]; ad[2] = TOCadress[0]; // Fourth step WRITE SOUND - ad2 = 0x00; // Init sound address + ad2 = 0x00; // Init sound address ad1 = 0x04; ad0 = 0x00; - write_enable (); - PORTB &= ~0x02; // Chip Select - spiSend (0xAF); // Send Sequencial Program Command - spiSend (ad2); // Send Address - spiSend (ad1); - spiSend (ad0); - while (1) // Send first byte into the page flash + write_enable(); + PORTB &= ~0x02; // Chip Select + spiSend(0xAF); // Send Sequencial Program Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + while (1) // Send first byte into the page flash { - if (!isFifoEmpty(&PWMFifo)) // Fifo not empty + if (!isFifoEmpty(&PWMFifo)) // Fifo not empty { - spiSend (pullFifo(&PWMFifo)); // Write data in flash + spiSend(pullFifo(&PWMFifo)); // Write data in flash ad0++; - break; // End of firt command + break; // End of firt command } } - PORTB |= 0x02; // Chip Deselect - while (read_status() != 0x52); // Wait Page Program Cycle + PORTB |= 0x02; // Chip Deselect + while (read_status() != 0x52) ; // Wait Page Program Cycle while (1) { - if (!isFifoEmpty(&PWMFifo)) // Fifo not empty + if (!isFifoEmpty(&PWMFifo)) // Fifo not empty { - PORTB &= ~0x02; // Chip Select - spiSend (0xAF); // Send Sequencial Program Command - spiSend (pullFifo(&PWMFifo)); // Write data in flash - PORTB |= 0x02; // Chip DeselecT - ad0++; // Increment address byte + PORTB &= ~0x02; // Chip Select + spiSend(0xAF); // Send Sequencial Program Command + spiSend(pullFifo(&PWMFifo)); // Write data in flash + PORTB |= 0x02; // Chip DeselecT + ad0++; // Increment address byte if (ad0 == 0x00) { ad1++; if (ad1 == 0x00) ad2++; } - while (read_status() != 0x52); // Wait Page Program Cycle + while (read_status() != 0x52) ; // Wait Page Program Cycle } if (ad2 == ad[2]) { @@ -262,43 +254,41 @@ { if (ad0 == ad[0]) { - break; // Stop programming flash + break; // Stop programming flash } } } } - write_disable (); // Disable wrtie flash + write_disable(); // Disable wrtie flash + TCCR0A = 0x23; // Reactivate PWM + TCCR0B = 0x09; + OCR0A = 249; /* we need TOP=250 to get a 8kHz sampling frequency */ + TIMSK0 = 0x01; - TCCR0A=0x23; // Reactivate PWM - TCCR0B=0x09; - OCR0A=249; /* we need TOP=250 to get a 8kHz sampling frequency */ - TIMSK0=0x01; + TWCR = (TWCR & TWCR_CMD_MASK) | _BV(TWIE); // Reactivate I2C - TWCR = (TWCR & TWCR_CMD_MASK) | _BV(TWIE); // Reactivate I2C - // Reactivate all interrupt - programmingFlash = 0; // Reset the flag to suspend the task + programmingFlash = 0; // Reset the flag to suspend the task } - -void playingAudio (unsigned char nsound) +void playingAudio(unsigned char nsound) { unsigned char count, i; - unsigned char adp1, adp0, sounds_stored; // Address pointer varaible + unsigned char adp1, adp0, sounds_stored; // Address pointer varaible - sounds_stored = read_data (0x00, 0x00, 0x00); - if (sounds_stored == 0xFF) /* if unprogrammed we have 0xFF stored in flash */ + sounds_stored = read_data(0x00, 0x00, 0x00); + if (sounds_stored == 0xFF) /* if unprogrammed we have 0xFF stored in flash */ return; - if (!nsound || (nsound > sounds_stored)) /* check the limits */ + if (!nsound || (nsound > sounds_stored)) /* check the limits */ return; count = 1; adp1 = 0x00; adp0 = 0x01; - while (count != nsound) // Compute address + while (count != nsound) // Compute address { for (i = 0; i < 3; i++) { @@ -309,49 +299,55 @@ count++; } - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (0x00); // Send Address - spiSend (adp1); - spiSend (adp0); + spiSend(0x03); // Send Read Page Command + spiSend(0x00); // Send Address + spiSend(adp1); + spiSend(adp0); for (i = 0; i < 6; i++) { - ad[i] = spiSend(0x00); // Read start and stop sound address + ad[i] = spiSend(0x00); // Read start and stop sound address } - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x02; // Chip Deselect /* Check adresses */ - if (ad[0] > 0x07) return; /* don't read outside the flash */ - if (ad[3] > 0x07) return; /* don't read outside the flash */ - if ((ad[0] == 0) && (ad[1] < 0x04)) return; /* minimum index not respected */ - if ((ad[4] == 0) && (ad[5] < 0x04)) return; /* minimum index not respected */ - if (ad[3] < ad[0]) return; /* check that the stop index is greater than the start index */ + if (ad[0] > 0x07) + return; /* don't read outside the flash */ + if (ad[3] > 0x07) + return; /* don't read outside the flash */ + if ((ad[0] == 0) && (ad[1] < 0x04)) + return; /* minimum index not respected */ + if ((ad[4] == 0) && (ad[5] < 0x04)) + return; /* minimum index not respected */ + if (ad[3] < ad[0]) + return; /* check that the stop index is greater than the start index */ else if (ad[3] == ad[0]) { - if (ad[4] < ad[1]) return; + if (ad[4] < ad[1]) + return; else if (ad[4] == ad[1]) - if (ad[5] <= ad[2]) return; + if (ad[5] <= ad[2]) + return; } - PORTB &= ~0x02; // Chip Select + PORTB &= ~0x02; // Chip Select - spiSend (0x03); // Send Read Page Command - spiSend (ad[0]); // Send Address - spiSend (ad[1]); - spiSend (ad[2]); - PORTB &= ~0x01; // Reset the HOLD signal + spiSend(0x03); // Send Read Page Command + spiSend(ad[0]); // Send Address + spiSend(ad[1]); + spiSend(ad[2]); + PORTB &= ~0x01; // Reset the HOLD signal - OCR0A = 250; // Normal operation for PWM if fifo adaptative is on - flashPlay = 1; // Read of sound + OCR0A = 250; // Normal operation for PWM if fifo adaptative is on + flashPlay = 1; // Read of sound } - -void stopPlayingAudio (void) +void stopPlayingAudio(void) { flashPlay = 0; - PORTB |= 0x01; // Set the HOLD signal - PORTB |= 0x02; // Chip Deselect + PORTB |= 0x01; // Set the HOLD signal + PORTB |= 0x02; // Chip Deselect } Modified: firmware/tuxaudio/trunk/flash.h =================================================================== --- firmware/tuxaudio/trunk/flash.h 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/flash.h 2007-04-22 18:09:42 UTC (rev 285) @@ -22,16 +22,17 @@ #ifndef FLASH_H #define FLASH_H -extern unsigned char read_status (void); -extern void write_enable (void); -extern void write_disable (void); -extern void write_status (unsigned char status); -extern void erase_flash (void); -extern unsigned char read_data (unsigned char ad2, unsigned char ad1, unsigned char ad0); -extern void programmingAudio (void); -extern void unprotect_sector (unsigned char ad2, unsigned char ad1, unsigned char ad0); -extern void playingAudio (unsigned char nsound); -extern void stopPlayingAudio (void); +extern unsigned char read_status(void); +extern void write_enable(void); +extern void write_disable(void); +extern void write_status(unsigned char status); +extern void erase_flash(void); +extern unsigned char read_data(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +extern void programmingAudio(void); +extern void unprotect_sector(unsigned char ad2, unsigned char ad1, + unsigned char ad0); +extern void playingAudio(unsigned char nsound); +extern void stopPlayingAudio(void); - #endif Modified: firmware/tuxaudio/trunk/i2c.c =================================================================== --- firmware/tuxaudio/trunk/i2c.c 2007-04-22 18:00:21 UTC (rev 284) +++ firmware/tuxaudio/trunk/i2c.c 2007-04-22 18:09:42 UTC (rev 285) @@ -28,14 +28,14 @@ /* * DEBUG and TEST flags */ -#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ -#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ +#define __i2c_debug__ 0 /* stores in a ring buffer all I2C status that occurs */ +#define __i2c_signals__ 0 /* outputs some signals on pins, see below */ /* DEBUG definitions and variables */ #if (__i2c_debug__) -uint8_t i2cStatus[32]; /* debug only */ +uint8_t i2cStatus[32]; /* debug only */ uint8_t i2cStatusIdx = 0; -extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ +extern uint8_t i2cStatus[]; /* needs to be here for AVRStudio to show it in watch windows */ extern uint8_t i2cStatusIdx; #endif #if (__i2c_signals__) @@ -57,11 +57,13 @@ /* I2C status and address variables */ uint8_t i2cDeviceAddrRW; -volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ +volatile I2C_FLAGS i2cFlags; /* this is a bitfield and it takes more than 1 cycle to set a bit so disable interrupts before changing it outside interrupts */ + /* send/transmit buffer (outgoing data) */ uint8_t i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; uint8_t i2cSendDataIndex; uint8_t i2cSendDataLength; + /* receive buffer (incoming data) */ uint8_t i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; uint8_t i2cReceiveDataIndex; @@ -70,10 +72,12 @@ /* function pointer to i2c receive routine */ /* I2cSlaveReceive is called when this processor is addressed as a slave for * writing */ -static void (*i2cSlaveReceive)(uint8_t receiveDataLength, uint8_t* recieveData); +static void (*i2cSlaveReceive) (uint8_t receiveDataLength, + uint8_t * recieveData); /* I2cSlaveTransmit is called when this processor is addressed as a slave for * reading */ -static uint8_t (*i2cSlaveTransmit)(uint8_t transmitDataLengthMax, uint8_t* transmitData); +static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, + uint8_t * transmitData); /* functions */ @@ -90,7 +94,7 @@ /* Setting TWBR. There's a note in the datasheet that TWBR can't be lower * than 10 if the TWI is operated in Master mode */ #if ((F_CPU/1000UL)/I2C_SCL_FREQ_KHZ) < 36 - TWBR = 10; /* smallest TWBR value */ + TWBR = 10; /* smallest TWBR value */ #else TWBR = I2C_TWBR; #endif @@ -110,29 +114,34 @@ /* Set pull-up resistors on I2C bus pins */ #ifdef I2C_PULLUP - PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ - PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ + PORTC |= _BV(5); /* i2c SCL on ATmega48,88,168 */ + PORTC |= _BV(4); /* i2c SDA on ATmega48,88,168 */ #endif -#ifdef TWI_SLA_ENABLED /* If Slave mode: */ +#ifdef TWI_SLA_ENABLED /* If Slave mode: */ /* Set local device address (used in slave mode only) */ TWAR = I2C_TWAR; - TWCR = I2C_MODE; /* enable TWI */ -#else + TWCR = I2C_MODE; /* enable TWI */ +#else #ifdef TWI_M_ENABLED - TWCR = I2C_MODE; /* enable TWI */ + TWCR = I2C_MODE; /* enable TWI */ #endif #endif } /* Set the user function which handles receiving (incoming) data as a slave */ -void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +void +i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func) + (uint8_t receiveDataLength, uint8_t * recieveData)) { i2cSlaveReceive = i2cSlaveRx_func; } /* Set the user function which handles transmitting (outgoing) data as a slave */ -void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)) +void +i2cSetSlaveTransmitHandler(uint8_t(*i2cSlaveTx_func) + (uint8_t transmitDataLengthMax, + uint8_t * transmitData)) { i2cSlaveTransmit = i2cSlaveTx_func; } @@ -146,7 +155,7 @@ { volatile uint8_t wait; - for (wait=0; wait<20; wait++); /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ + for (wait = 0; wait < 20; wait++) ; /* add a delay for slaves to have time to process data when they receive a stop in case the main loop is too short so that a stop can be immediately followed by a start */ /* note: when a stop is immediately followed by a start, the slave detects * the stop, need to process the received data and exit the ISR. If it * doesn't have enough time to do this before a new start is set, it will @@ -158,8 +167,8 @@ if (i2cFlags.i2c_busy == 0) // if a start is sent when the TWI is receiving, one of the data will be received as 0x78 instead of 0x80 so we get a corruption there i2cSendStart(); #if (__i2c_signals__) - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ - START_PT |= START_MK; /* 'START' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + START_PT |= START_MK; /* 'START' debug signal */ #endif } @@ -169,9 +178,9 @@ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x02; #endif - i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ + i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif // TWCR = I2C_MODE; TWCR |= I2C_MODE; @@ -180,7 +189,7 @@ static inline void i2cSendStart(void) { #if (__i2c_debug__) - cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ + cli(); /* we need to protect this from an i2c interrupt that will corrupt those values otherwise */ i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = 0x03; sei(); @@ -198,7 +207,7 @@ TWCR = _BV(TWSTO) | I2C_MODE; i2cFlags.i2c_busy = 0; #if (__i2c_signals__) - BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ + BUSY_PT &= ~BUSY_MK; /* 'BUSY' debug signal */ #endif } @@ -236,7 +245,7 @@ #ifdef TWI_INT_ENABLED ISR(SIG_TWI) { - const static void *twiLookupTable[]={ + const static void *twiLookupTable[] = { &&case_TW_BUS_ERROR, &&case_TW_START, &&case_TW_REP_START, @@ -271,156 +280,153 @@ &&case_TW_NO_INFO, }; - i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ + i2cFlags.i2c_busy = 1; /* XXX be sure that in any case busy is flagged */ #if (__i2c_debug__) i2cStatusIdx %= 32; i2cStatus[i2cStatusIdx++] = TW_STATUS; #endif #if (__i2c_signals__) - ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ - BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ + ISR_PT |= ISR_MK; /* 'I2C ISR' debug signal */ + BUSY_PT |= BUSY_MK; /* 'BUSY' debug signal */ #endif - goto *twiLookupTable[TWSR>>3]; /* switch(TW_STATUS) */ + goto *twiLookupTable[TWSR >> 3]; /* switch(TW_STATUS) */ { - /* * * Master General * * */ -case_TW_START: /* 0x08: start condition sent */ -case_TW_REP_START: /* 0x10: repeated start condition sent */ + /* * * Master General * * */ + case_TW_START: /* 0x08: start condition sent */ + case_TW_REP_START: /* 0x10: repeated start condition sent */ #if (__i2c_debug__) #endif #if (__i2c_signals__) - START_PT &= ~START_MK; /* 'START' debug signal */ + START_PT &= ~START_MK; /* 'START' debug signal */ #endif - i2cSendDataIndex = 0; /* reset the data index */ - i2cSendByte(i2cDeviceAddrRW); /* send device address */ + i2cSendDataIndex = 0; /* reset the data index */ + i2cSendByte(i2cDeviceAddrRW); /* send device address */ goto END_TABLE; + /* * * Master Transmitter & Receiver status codes * * */ - /* * * Master Transmitter & Receiver status codes * * */ - -case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ -case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ - #if (__i2c_debug__) - #endif - if(i2cSendDataIndex < i2cSendDataLength) + case_TW_MT_SLA_ACK: /* 0x18: slave address acknowledged */ + case_TW_MT_DATA_ACK: /* 0x28: data acknowledged */ +#if (__i2c_debug__) +#endif + if (i2cSendDataIndex < i2cSendDataLength) { - i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ + i2cSendByte(i2cSendData[i2cSendDataIndex++]); /* send data */ } else { - i2cSendStop(); /* end of data stream */ + i2cSendStop(); /* end of data stream */ i2cFlags.m_end = 1; /* transmission ended and OK so set master transmission end flag */ } goto END_TABLE; -case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ -case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ -case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ -case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_NACK: /* 0x58: data received, NACK reply issued */ + case_TW_MR_SLA_NACK: /* 0x48: slave address not acknowledged */ + case_TW_MT_SLA_NACK: /* 0x20: slave address not acknowledged */ + case_TW_MT_DATA_NACK: /* 0x30: data not acknowledged */ +#if (__i2c_debug__) +#endif i2cFlags.mt_nack = 1; i2cSendStop(); goto END_TABLE; -case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ + case_TW_MT_ARB_LOST: /* 0x38: bus arbitration lost */ //case_TW_MR_ARB_LOST: /* 0x38: bus arbitration lost */ /* same code as above */ - #if (__i2c_debug__) - #endif +#if (__i2c_debug__) +#endif i2cReset(); goto END_TABLE; -case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ - #if (__i2c_debug__) - #endif + case_TW_MR_DATA_ACK: /* 0x50: data acknowledged */ +#if (__i2c_debug__) +#endif // store received data byte i2... [truncated message content] |