[tuxdroid-svn] r727 - firmware/tuxaudio/branches/new_flash_programming
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-11-27 08:29:48
|
Author: Paul_R Date: 2007-11-27 09:29:31 +0100 (Tue, 27 Nov 2007) New Revision: 727 Modified: firmware/tuxaudio/branches/new_flash_programming/AT26F004.c firmware/tuxaudio/branches/new_flash_programming/AT26F004.h firmware/tuxaudio/branches/new_flash_programming/PC_communication.c firmware/tuxaudio/branches/new_flash_programming/flash.c firmware/tuxaudio/branches/new_flash_programming/flash.h firmware/tuxaudio/branches/new_flash_programming/main.c firmware/tuxaudio/branches/new_flash_programming/varis.c firmware/tuxaudio/branches/new_flash_programming/varis.h Log: * Changed the way to program the sounds in the memory Modified: firmware/tuxaudio/branches/new_flash_programming/AT26F004.c =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/AT26F004.c 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/AT26F004.c 2007-11-27 08:29:31 UTC (rev 727) @@ -24,6 +24,7 @@ #include "hardware.h" #include "spi.h" +static void unprotect_sectors(void); /** * \ingroup at26f004 * \brief initialize a table with the sector adresses values @@ -117,6 +118,17 @@ */ void erase_flash(void) { + + unprotect_sectors(); + write_enable(); /* Enable the writing */ + + flash_select(); + spiSend(CHIP_ERASE); /* Send Erase Bulk command */ + flash_unselect(); +} + +static void unprotect_sectors(void) +{ uint8_t i; write_status(0x00); /* Disable sector protection register */ for (i=0; i<=10; i++) @@ -124,14 +136,7 @@ write_enable(); /* Enable the writing */ unprotect_sector(sector_adress[i][0], sector_adress[i][1],sector_adress[i][2]); } - - write_enable(); /* Enable the writing */ - - flash_select(); - spiSend(CHIP_ERASE); /* Send Erase Bulk command */ - flash_unselect(); } - /** * \ingroup at26f004 \param ad2 high address part @@ -180,5 +185,37 @@ return data1; } +/** + * \ingroup at26f004 + \param first_block The first block to erase + \param last_block The last block to erase + \brief This function erase a specified area in the memory. The memory will be erased by 4kB's blocks. + */ +void blockErase(uint8_t first_block, uint8_t last_block) +{ + uint8_t diff, ad0, ad1; + // unprotect all sectors + unprotect_sectors(); + // diff is the number of block to erase + diff = last_block - first_block + 1; + while(diff) + { + // Erase a 4kB block + write_enable(); + flash_select(); + ad0 = (last_block >> 4); + ad1 = (last_block << 4); + spiSend(BLOCK_ERASE_4K); /* Send Erase Bulk command */ + spiSend(ad0); + spiSend(ad1); + spiSend(0x00); + flash_unselect(); + + diff --; + last_block --; + while (read_status() & BUSY); + } +} + Modified: firmware/tuxaudio/branches/new_flash_programming/AT26F004.h =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/AT26F004.h 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/AT26F004.h 2007-11-27 08:29:31 UTC (rev 727) @@ -146,6 +146,7 @@ /** \name Misc. functions * @{ */ extern void erase_flash(void); +extern void blockErase(uint8_t first_block, uint8_t last_block); extern void unprotect_sector(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0); /* @} */ Modified: firmware/tuxaudio/branches/new_flash_programming/PC_communication.c =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/PC_communication.c 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/PC_communication.c 2007-11-27 08:29:31 UTC (rev 727) @@ -117,9 +117,15 @@ { if (frame_without_sound) frame_without_sound --; + + else + sound_played = 0; } else + { + sound_played = 1; frame_without_sound = frame_without_sound_timeout; + } spi_master = PUT_SOUND_FIFO; // Go to the next state Modified: firmware/tuxaudio/branches/new_flash_programming/flash.c =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/flash.c 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/flash.c 2007-11-27 08:29:31 UTC (rev 727) @@ -27,6 +27,7 @@ #include "i2c.h" #include "flash.h" #include "AT26F004.h" +#include "common/api.h" /* Declarations */ static void init_programming(uint8_t adi0, uint8_t adi1, uint8_t adi2); @@ -40,6 +41,7 @@ static uint16_t index; static uint8_t sound_stored = 0; static uint8_t count, ad0, ad1; +static uint8_t first_block; /** @@ -59,7 +61,10 @@ while(1) { if (read_data(0x00, ad1, ad0) == 0xFF) - return count - 1; + { + count --; + return count; + } else { for (i = 0; i < 3; i++) @@ -73,6 +78,17 @@ } return 0; } + +uint8_t readLastBlock(uint8_t num) +{ + index = (numSound * 3) + 1; + ad[0] = read_data(0x00, (index>>8), (index & 0xFF)); + index ++; + ad[1] = read_data(0x00, (index>>8), (index & 0xFF)); + index ++; + ad[2] = read_data(0x00, (index>>8), (index & 0xFF)); + return (ad[0] << 4) + (ad[1] >> 4); +} /** * \ingroup flash \brief Store a sound in the memory. @@ -100,13 +116,14 @@ if (programming_state == DETECT_INDEXES) { TIMSK0 = 0x00; - numSound = readFlashNumber(); + //numSound = readFlashNumber(); if (numSound == 0) { /* The flash memory is empty. The first address is 0x000400 */ ad[0] = 0x00; ad[1] = 0x04; ad[2] = 0x00; + first_block = 0; } else { @@ -120,20 +137,26 @@ ad[2] = read_data(0x00, (index>>8), (index & 0xFF)); // Goto the next 4kB block. - ad[1] ++; + ad[1] += 0x10; + ad[1] &= ~0x0F; if (ad[1] == 0) ad[0] ++; ad[2] = 0; + first_block = (ad[0] << 4) + (ad[1] >> 4); } resetFifo(&PWMFifo); if (ad[0] > 0x07) + { programming_state = PROG_END; + send_status(STATUS_FLASH_PROG_CMD, FLASH_FULL, 0, 0); + } else programming_state ++; - frame_without_sound = 255; - frame_without_sound_timeout = 255; + frame_without_sound = 5000; + frame_without_sound_timeout = 5000; + send_status(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]); } else if (programming_state == PROG_INIT) @@ -146,20 +169,52 @@ else if (programming_state == PROGRAMMING) { if (flash_state) - { programming_sound(); - } + else { write_disable(); if (sound_stored) + { + last_block = (ad[0] << 4) + (ad[1] >> 4); + send_status(STATUS_FLASH_PROG_CMD, WAITING_FOR_CONFIRMATION, last_block - first_block, 0); programming_state ++; + } else + { + send_status(STATUS_FLASH_PROG_CMD, NO_SOUND, 0, 0); programming_state = PROG_END; + } } - } + } + else if (programming_state == WAITING_STATE) + { + if (write_toc == 1) + { + programming_state = PROG_TOC; + } + else if (write_toc == 2) + { + send_status(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0); + if (first_block == 0) + { + eraseFlag = 1; + frame_without_sound_timeout = TTS_TIMEOUT; + programming_state = 0; + programmingFlash = 0; + } + else + { + last_block = (ad[0] << 4) + (ad[1] >> 4); + blockErase(first_block, last_block); + programming_state = PROG_END; + } + } + write_toc = 0; + } else if (programming_state == PROG_TOC) { + send_status(STATUS_FLASH_PROG_CMD, WRITE_TOC, 0, 0); numSound ++; index = (numSound * 3) + 1; program_flash(0x00, (index>>8), (index & 0xFF), ad[0]); @@ -167,13 +222,19 @@ program_flash(0x00, (index>>8), (index & 0xFF), ad[1]); index ++; program_flash(0x00, (index>>8), (index & 0xFF), ad[2]); + last_block = (ad[0] << 4) + (ad[1] >> 4); programming_state ++; } else if (programming_state == PROG_END) { + numSound = readFlashNumber(); + frame_without_sound_timeout = TTS_TIMEOUT; programming_state = 0; programmingFlash = 0; TIMSK0 = 0x01; + //info_flg = 1; + send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + send_status(SOUND_VAR_CMD, numSound, last_block, 0); } } @@ -195,13 +256,18 @@ } else if (!(read_status() & BUSY)) { + //send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); enter = 1; eraseFlag = 0; program_flash(0x00, 0x00, 0x00, 0xFE); program_flash(0x00, 0x00, 0x01, 0x00); program_flash(0x00, 0x00, 0x02, 0x04); program_flash(0x00, 0x00, 0x03, 0x00); - numSound = readFlashNumber(); + numSound = 0; + last_block = 0; + send_status(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0); + send_status(SOUND_VAR_CMD, numSound, last_block, 0); + //info_flg = 1; TIMSK0 = 0x01; } } @@ -278,10 +344,14 @@ { ad[i] = spiSend(NOP); // Read start and stop sound address } - ad[1] ++; - if (ad[1] == 0) - ad[0] ++; - ad[2] = 0; + if (nsound > 1) + { + ad[1] += 0x10; + ad[1] &= ~0x0F; + if (ad[1] == 0) + ad[0] ++; + ad[2] = 0; + } flash_unselect(); // Chip Deselect @@ -389,6 +459,7 @@ */ static void stopPlaying(void) { + soundToPlay = 0; flashPlay = 0; send_status(STATUS_AUDIO_CMD, 0, 0, 0); PORTB |= 0x01; // Set the HOLD signal @@ -450,7 +521,8 @@ if (!isFifoEmpty(&PWMFifo)) { sound_stored = 1; - frame_without_sound = frame_without_sound_timeout = STOP_FRAME_NUMBER; + frame_without_sound = STOP_FRAME_NUMBER; + frame_without_sound_timeout = STOP_FRAME_NUMBER; flash_select(); spiSend(SEQU_PROGRAM); Modified: firmware/tuxaudio/branches/new_flash_programming/flash.h =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/flash.h 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/flash.h 2007-11-27 08:29:31 UTC (rev 727) @@ -36,25 +36,41 @@ /** \name Flash programming states @{ */ -#define DETECT_INDEXES 0 -#define PROG_INIT 1 -#define PROGRAMMING 2 -#define PROG_TOC 3 -#define PROG_END 4 +enum { + DETECT_INDEXES = 0, + PROG_INIT, + PROGRAMMING, + WAITING_STATE, + PROG_TOC, + PROG_END, +}; /* @} */ /** \name No sound in frame timeout @{ */ -#define STOP_FRAME_NUMBER 10 +#define STOP_FRAME_NUMBER 10 +#define TTS_TIMEOUT 10 #define START_FRAME_NUMBER 100 /* @} */ +/** \name Flash programming status + @{ */ +enum { + STANDBY = 0, + IN_PROGRESS, + WAITING_FOR_CONFIRMATION, + WRITE_TOC, + ERASING_LAST_SOUND, + FLASH_FULL, + NO_SOUND, +}; +/* @} */ - extern void programming(void); extern void playSound(void); extern void erase(void); extern uint8_t readFlashNumber(void); +extern uint8_t readLastBlock(uint8_t num); /** start / end flash states flag */ extern uint8_t flash_state; Modified: firmware/tuxaudio/branches/new_flash_programming/main.c =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/main.c 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/main.c 2007-11-27 08:29:31 UTC (rev 727) @@ -54,7 +54,7 @@ {REVISION_CMD, SVN_REV, RELEASE_TYPE}; const version_t tag_version __attribute__ ((section("version.1"))) = {VERSION_CMD, CPU_VER_JOIN(CPU_NUMBER, VER_MAJOR), VER_MINOR, VER_UPDATE}; -static uint8_t info_flg = 0; /* indicates if version information should be sent */ + static uint8_t pre_sleep_delay = 0; /* set when sleep should be entered */ void send_info(void) @@ -71,7 +71,7 @@ sei(); buf[0] = SOUND_VAR_CMD; buf[1] = numSound; - buf[2] = 0; + buf[2] = last_block; buf[3] = 0; cli(); i2cSlaveReceiveService(4, buf); @@ -201,21 +201,26 @@ { if (flashPlay) flashPlay = 0; - /* param: command[1] : number of sounds */ flash_state = 1; /* Erasing flash flag */ - send_status(STATUS_AUDIO_CMD, 0, 1, 0); programmingFlash = 1; /* Set the flag to enter programming sequence */ } - else if (command[0] == STORE_INDEX_CMD) + else if (command[0] == ERASE_FLASH_CMD) { eraseFlag = 1; } /* Version */ else if (command[0] == INFO_TUXAUDIO_CMD) + info_flg = 1; /* info should be sent when the buffer will be free */ + + else if (command[0] == CONFIRM_STORAGE_CMD) { - info_flg = 1; /* info should be sent when the buffer will be free */ + if (command[1]) + write_toc = 1; + else + write_toc = 2; } + else pushCommands(command); /* push the command set on the filo stack */ } @@ -235,8 +240,11 @@ if (PINB & 0x40) command[1] |= 0x20; command[1] ^= 0x9B; /* some bits should be inverted */ - command[2] = audio_level; - command[3] = battery_level; + command[2] = soundToPlay; + if (soundToPlay || sound_played) + command[3] = 1; + else + command[3] = 0; pushCommands(command); /* push the command set on the filo stack */ } @@ -248,7 +256,9 @@ resetFifo(&ADCFifo); /* Initialise the ADC fifo */ config_init(); /* load the configuration defaults from EEPROM */ numSound = readFlashNumber(); + last_block = readLastBlock(numSound); i2cCommunicationInit(); /* I2C initialization */ + frame_without_sound_timeout = TTS_TIMEOUT; sei(); /* Init global interrupt */ Modified: firmware/tuxaudio/branches/new_flash_programming/varis.c =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/varis.c 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/varis.c 2007-11-27 08:29:31 UTC (rev 727) @@ -71,5 +71,11 @@ volatile unsigned char Fifoinert = 0; -uint8_t frame_without_sound = 0; -uint8_t frame_without_sound_timeout= 0; +uint16_t frame_without_sound = 0; +uint16_t frame_without_sound_timeout= 0; +uint8_t sound_played = 0; +uint8_t last_block = 0; + +// General flags +uint8_t info_flg = 0; /* indicates if version information should be sent */ +uint8_t write_toc = 0; Modified: firmware/tuxaudio/branches/new_flash_programming/varis.h =================================================================== --- firmware/tuxaudio/branches/new_flash_programming/varis.h 2007-11-26 16:02:39 UTC (rev 726) +++ firmware/tuxaudio/branches/new_flash_programming/varis.h 2007-11-27 08:29:31 UTC (rev 727) @@ -81,6 +81,12 @@ extern volatile unsigned char lockAdaptFifo; extern volatile unsigned char Fifoinert; -extern uint8_t frame_without_sound; -extern uint8_t frame_without_sound_timeout; +extern uint16_t frame_without_sound; +extern uint16_t frame_without_sound_timeout; +extern uint8_t sound_played; +extern uint8_t last_block; + +// General flags +extern uint8_t info_flg; +extern uint8_t write_toc; #endif |