[tuxdroid-svn] r503 - firmware/tuxaudio/branches/audio_cleanup
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-09-10 08:04:48
|
Author: Paul_R Date: 2007-09-10 10:04:14 +0200 (Mon, 10 Sep 2007) New Revision: 503 Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c firmware/tuxaudio/branches/audio_cleanup/AT26F004.h firmware/tuxaudio/branches/audio_cleanup/PC_communication.c firmware/tuxaudio/branches/audio_cleanup/flash.c firmware/tuxaudio/branches/audio_cleanup/flash.h firmware/tuxaudio/branches/audio_cleanup/hardware.h firmware/tuxaudio/branches/audio_cleanup/main.c Log: * Reorganized the programming and flash modules - Some functions and defines have been moved from flash module to AT26F. - Some functions in the flash module have been declared with the 'static' attribute. - Moved the chip select and the hold defines from AT26F. module to hardware.h - Change the programmingFlash's init to not call the erasingFlash function directly from the main loop. Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-10 08:04:14 UTC (rev 503) @@ -19,11 +19,9 @@ /* $Id: $ */ -/* $Id: $ */ - #include <avr/io.h> #include "AT26F004.h" -#include "flash.h" +#include "hardware.h" #include "spi.h" @@ -41,59 +39,58 @@ {0x07, 0xC0, 0x00} }; +/** + * \ingroup at26f004 + \brief This function set the write enable flag of the flash memory. + */ uint8_t read_status(void) { uint8_t status; - FLASH_CS_ON; /* Chip Select */ - spiSend(READ_STATUS_REG); /* Send Read Status Command */ - status = spiSend(NOP); /* Read status on spi */ - FLASH_CS_OFF; /* Chip Deselect */ + FLASH_CS_ON; + spiSend(READ_STATUS_REG); /* Send Read Status Command */ + status = spiSend(NOP); /* Read status on spi */ + FLASH_CS_OFF; return status; } /** - * \ingroup flash + * \ingroup at26f004 \brief This function set the write enable flag of the flash memory. */ - void write_enable(void) { - FLASH_CS_ON; /* Chip Select */ - spiSend(WRITE_EN); /* Send Write Enable Command */ - FLASH_CS_OFF; /* Chip Deselect */ - + FLASH_CS_ON; + spiSend(WRITE_EN); /* Send Write Enable Command */ + FLASH_CS_OFF; } /** - * \ingroup flash + * \ingroup at26f004 \brief This function clear the write enable flag of the flash memory. */ - void write_disable(void) { - FLASH_CS_ON; /* Chip Select */ - spiSend(WRITE_DIS); /* Send Write Disable Command */ - FLASH_CS_OFF; /* Chip Deselect */ + FLASH_CS_ON; + spiSend(WRITE_DIS); /* Send Write Disable Command */ + FLASH_CS_OFF; } /** - * \ingroup flash + * \ingroup at26f004 \brief This function write into the flash memory status register. */ - void write_status(uint8_t const status) { - FLASH_CS_ON; /* Chip Select */ - spiSend(WRITE_STATUS_REG); /* Send Write Status Command */ - spiSend(status); /* Send status */ - FLASH_CS_OFF; /* Chip Deselect */ - + FLASH_CS_ON; + spiSend(WRITE_STATUS_REG); /* Send Write Status Command */ + spiSend(status); /* Send status */ + FLASH_CS_OFF; } /** - * \ingroup flash + * \ingroup at26f004 \param ad2 high address part \param ad1 medium adress part \param ad0 lower adress part @@ -102,59 +99,75 @@ */ void unprotect_sector(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) { - FLASH_CS_ON; // Chip Select - spiSend(UNPROTECT_SECTOR); // Send unprotect sector command - spiSend(ad2); // Send Address + FLASH_CS_ON; + spiSend(UNPROTECT_SECTOR); /* Send unprotect sector command */ + /* Send Adress */ + spiSend(ad2); spiSend(ad1); spiSend(ad0); - FLASH_CS_OFF; // Chip Deselect - + FLASH_CS_OFF; } /** - * \ingroup flash + * \ingroup at26f004 \brief This function erase the entire memory. */ - void erase_flash(void) { uint8_t i; - write_status(0x00); // Disable sector protection register + write_status(0x00); /* Disable sector protection register */ for (i=0; i<=10; i++) { - write_enable(); // Enable the writing + write_enable(); /* Enable the writing */ unprotect_sector(sector_adress[i][0], sector_adress[i][1],sector_adress[i][2]); } - write_enable(); // Enable the writing + write_enable(); /* Enable the writing */ - FLASH_CS_ON; // Chip Select - spiSend(CHIP_ERASE); // Send Erase Bulk command - FLASH_CS_OFF; // Chip Deselect + FLASH_CS_ON; + spiSend(CHIP_ERASE); /* Send Erase Bulk command */ + FLASH_CS_OFF; } /** - * \ingroup flash + * \ingroup at26f004 \param ad2 high address part \param ad1 medium adress part \param ad0 lower adress part \brief This function write a byte in the flash memory. */ - void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, uint8_t const data) { - while (read_status() & BUSY) ; // Wait Page Program Cycle + while (read_status() & BUSY) ; /* Wait Page Program Cycle */ write_enable(); - FLASH_CS_ON; // Chip Select - spiSend(BYTE_PROGRAM); // Send Page Byte Command - spiSend(ad2); // Send Address + FLASH_CS_ON; + spiSend(BYTE_PROGRAM); /* Send Page Byte Command */ + /* Send adress */ + spiSend(ad2); spiSend(ad1); spiSend(ad0); - spiSend(data); // Write data in flash - FLASH_CS_OFF; // Chip Deselect + spiSend(data); /* Write data in flash */ + FLASH_CS_OFF; } +uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) +{ + uint8_t data1; + FLASH_CS_ON; + spiSend(READ_ARRAY_LOW_F); /* Send Read Page Command */ + /* Send address */ + spiSend(ad2); + spiSend(ad1); + spiSend(ad0); + data1 = spiSend(NOP); /* Wait response */ + FLASH_CS_OFF; + + return data1; +} + + + Modified: firmware/tuxaudio/branches/audio_cleanup/AT26F004.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-10 08:04:14 UTC (rev 503) @@ -17,6 +17,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/** \defgroup at26f004 AT26F004 flash memory + \ingroup at26f004 + + This module contains all specific definitions and functions to access the flash memory. + */ +/** \file AT26F004.h + \ingroup at26f004 + \brief AT26F004 flash memory header + + */ + +/** \file AT26F004.c + \ingroup at26f004 + \brief AT26F004 functions + + */ + #ifndef AT26F004_H #define AT26F004_H @@ -63,22 +80,17 @@ extern uint8_t sector_adress[11][3]; /** * \name Flash TOP address - * + * \ingroup at26f004 * The flash memory address range is 0x000000 - [TOP_A2 TOP_A1 TOP_A0] * The AT26F004 has an address range of 0x000000 - 0x7FFFFF - * @{ */ + */ /** High byte of the TOP address. */ #define TOP_A2 0x07 /** Middle byte of the TOP address. */ #define TOP_A1 0xFF /** Low byte of the TOP address. */ #define TOP_A0 0xFF -/*! @} */ -#define FLASH_CS_ON FLASH_PORT &= ~FLASH_CS_PIN -#define FLASH_CS_OFF FLASH_PORT |= FLASH_CS_PIN -#define HOLD_ON FLASH_PORT &= ~FLASH_HOLD_PIN -#define HOLD_OFF FLASH_PORT |= FLASH_HOLD_PIN extern uint8_t read_status(void); extern void write_enable(void); @@ -89,5 +101,6 @@ uint8_t const ad0); extern void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, uint8_t const data); +extern uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0); #endif Modified: firmware/tuxaudio/branches/audio_cleanup/PC_communication.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/PC_communication.c 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/PC_communication.c 2007-09-10 08:04:14 UTC (rev 503) @@ -27,7 +27,7 @@ #include "PC_communication.h" #include "communication.h" #include "spi.h" -#include "AT26F004.h" +#include "hardware.h" void spiTransaction(void) { Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-10 08:04:14 UTC (rev 503) @@ -29,6 +29,7 @@ /* Theses functions are declared with the static attribute, so they're * accessible only by this module */ +static void erasingFlash(void); static void programmingNumSound(void); static void programmingToc(void); static void initSoundProgramming(void); @@ -36,9 +37,9 @@ static void endProgramming(void); -uint8_t f_state = 0; +uint8_t f_state; uint8_t flash_state; - +uint8_t ad0, ad1, ad2, i, j; /* Public functions */ /** @@ -67,7 +68,10 @@ PORTB |= 0x01; if (f_state == ERASE_STATE) { - if (read_status() & BUSY) + if (flash_state) + erasingFlash(); + + else if (read_status() & BUSY) f_state ++; } else if (f_state == FIRST_PROG_STATE) @@ -111,22 +115,23 @@ * flash command is received. */ - -uint8_t ad0, ad1, ad2, i, j; -void erasingFlash(void) +/* XXX This function is directly called by commandParser. It could be changed to + * be called by the flashProgramming function. + */ +static void erasingFlash(void) { - TCCR0A = 0x00; // Desactivate PWM + /* Desactivate the PWM */ + TCCR0A = 0x00; TCCR0B = 0x00; OCR0A = 0x00; TIMSK0 = 0x00; - f_state = 0; - TWCR = (TWCR & TWCR_CMD_MASK) & ~_BV(TWIE); // Desactivate I2C - - resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ - programmingFlash = 1; // Set the flag to suspend the task - erase_flash(); // Erase the flash + + resetFifo(&PWMFifo); /* Reinitialise the PWM fifo */ + erase_flash(); /* Erase the flash */ + flash_state = 0; } + /** * \ingroup flash \param ad2 high address part @@ -136,21 +141,7 @@ \brief This function read a byte in the sound flash memory. */ -uint8_t read_data(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0) -{ - uint8_t data1; - FLASH_CS_ON; // Chip Select - spiSend(READ_ARRAY_LOW_F); // Send Read Page Command - spiSend(ad2); // Send Address - spiSend(ad1); - spiSend(ad0); - data1 = spiSend(NOP); // Wait response - FLASH_CS_OFF; // Chip Deselect - - return data1; -} - void playingAudio(uint8_t nsound) { uint8_t count, i; Modified: firmware/tuxaudio/branches/audio_cleanup/flash.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-10 08:04:14 UTC (rev 503) @@ -47,9 +47,6 @@ extern void flashProgramming(void); -extern void erasingFlash(void); -extern uint8_t read_data(uint8_t const ad2, uint8_t const ad1, - uint8_t const ad0); extern uint8_t flash_state; extern uint8_t f_state; Modified: firmware/tuxaudio/branches/audio_cleanup/hardware.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/hardware.h 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/hardware.h 2007-09-10 08:04:14 UTC (rev 503) @@ -22,10 +22,17 @@ #ifndef HARDWARE_H #define HARDWARE_H +/* Flash memory port */ #define FLASH_PORT PORTB #define FLASH_CS_PIN _BV(PB1) #define FLASH_HOLD_PIN _BV(PB0) +/* Flash memory commands */ +#define FLASH_CS_ON FLASH_PORT &= ~FLASH_CS_PIN +#define FLASH_CS_OFF FLASH_PORT |= FLASH_CS_PIN +#define HOLD_ON FLASH_PORT &= ~FLASH_HOLD_PIN +#define HOLD_OFF FLASH_PORT |= FLASH_HOLD_PIN + #endif Modified: firmware/tuxaudio/branches/audio_cleanup/main.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-07 15:24:24 UTC (rev 502) +++ firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-10 08:04:14 UTC (rev 503) @@ -195,7 +195,9 @@ { /* param: command[1] : number of sounds */ numSound = command[1]; - erasingFlash(); + f_state =0; /* First programming state */ + flash_state = 1; /* Erasing flash flag */ + programmingFlash = 1; /* Set the flag to enter programming sequence */ } else if (command[0] == STORE_INDEX_CMD) { |