[tuxdroid-svn] r500 - firmware/tuxaudio/branches/audio_cleanup
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-09-07 14:55:40
|
Author: Paul_R Date: 2007-09-07 16:55:34 +0200 (Fri, 07 Sep 2007) New Revision: 500 Added: 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/PC_communication.h Modified: firmware/tuxaudio/branches/audio_cleanup/Makefile firmware/tuxaudio/branches/audio_cleanup/flash.c firmware/tuxaudio/branches/audio_cleanup/flash.h firmware/tuxaudio/branches/audio_cleanup/main.c firmware/tuxaudio/branches/audio_cleanup/spi.c firmware/tuxaudio/branches/audio_cleanup/spi.h Log: * Reorganized the flash memory files : - AT26F004 files contains the functions and definitions specific to the Atmel AT26F flash memory. - spi files contains the functions and definitions specific to access the SPI bus - flash files contains the functions and definitions to read / write in the flash memory for tux usage. * Added PC_communication module which contains the function(s) to manage received/to send frames by the RF module. * Some functions have been optimized in AT26F004.c module. Added: firmware/tuxaudio/branches/audio_cleanup/AT26F004.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.c (rev 0) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.c 2007-09-07 14:55:34 UTC (rev 500) @@ -0,0 +1,160 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id: $ */ + +/* $Id: $ */ + +#include <avr/io.h> +#include "AT26F004.h" +#include "flash.h" +#include "spi.h" + + +uint8_t sector_adress[11][3] = { + {0x00, 0x00, 0x00}, + {0x01, 0x00, 0x00}, + {0x02, 0x00, 0x00}, + {0x03, 0x00, 0x00}, + {0x04, 0x00, 0x00}, + {0x05, 0x00, 0x00}, + {0x06, 0x00, 0x00}, + {0x07, 0x00, 0x00}, + {0x07, 0x80, 0x00}, + {0x07, 0xA0, 0x00}, + {0x07, 0xC0, 0x00} +}; + + +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 */ + return status; +} +/** + * \ingroup flash + + \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 */ + +} +/** + * \ingroup flash + + \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 */ +} + +/** + * \ingroup flash + + \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 */ + +} +/** + * \ingroup flash + \param ad2 high address part + \param ad1 medium adress part + \param ad0 lower adress part + + \brief This function unprotect a sector. + */ +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 + spiSend(ad1); + spiSend(ad0); + FLASH_CS_OFF; // Chip Deselect + +} +/** + * \ingroup flash + + \brief This function erase the entire memory. + */ + +void erase_flash(void) +{ + uint8_t i; + write_status(0x00); // Disable sector protection register + for (i=0; i<=10; i++) + { + 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_CS_ON; // Chip Select + spiSend(CHIP_ERASE); // Send Erase Bulk command + FLASH_CS_OFF; // Chip Deselect +} + +/** + * \ingroup flash + \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 + + write_enable(); + FLASH_CS_ON; // Chip Select + spiSend(BYTE_PROGRAM); // Send Page Byte Command + spiSend(ad2); // Send Address + spiSend(ad1); + spiSend(ad0); + spiSend(data); // Write data in flash + FLASH_CS_OFF; // Chip Deselect +} + + Added: firmware/tuxaudio/branches/audio_cleanup/AT26F004.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/AT26F004.h (rev 0) +++ firmware/tuxaudio/branches/audio_cleanup/AT26F004.h 2007-09-07 14:55:34 UTC (rev 500) @@ -0,0 +1,87 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef AT26F004_H +#define AT26F004_H + +/* Flash (AT26F004) OP CODE */ +#define READ_ARRAY 0x0B +#define READ_ARRAY_LOW_F 0x03 + +#define BLOCK_ERASE_4K 0x20 +#define BLOCK_ERASE_32K 0x52 +#define BLOCK_ERASE_64K 0xD8 +#define CHIP_ERASE 0x60 + +#define BYTE_PROGRAM 0x02 +#define SEQU_PROGRAM 0xAF + +#define WRITE_EN 0x06 +#define WRITE_DIS 0x04 +#define PROTECT_SECTOR 0x36 +#define UNPROTECT_SECTOR 0x39 +#define READ_SECT_PROTECT 0x3C + +#define READ_STATUS_REG 0x05 +#define WRITE_STATUS_REG 0x01 + +#define READ_MANUFACT 0x9F +#define DEEP_POWER_MODE 0xB9 +#define RESUME_DEEP_MODE 0xAB + +#define NOP 0x00 + +/* Flash status register masks */ +#define BUSY 0x01 +#define WEL 0X02 +#define SWP 0x0C +#define WPP 0x10 +#define RES 0x20 +#define SPM 0x40 +#define SPRL 0x80 + +/* Flash sector adresses */ + +extern uint8_t sector_adress[11][3]; +/** + * \name Flash TOP address + * + * 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 +/*! @} */ + + +extern uint8_t read_status(void); +extern void write_enable(void); +extern void write_disable(void); +extern void write_status(uint8_t const status); +extern void erase_flash(void); +extern void unprotect_sector(uint8_t const ad2, uint8_t const ad1, + uint8_t const ad0); +extern void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, + uint8_t const data); + +#endif Modified: firmware/tuxaudio/branches/audio_cleanup/Makefile =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/Makefile 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/Makefile 2007-09-07 14:55:34 UTC (rev 500) @@ -69,7 +69,7 @@ ## Objects that must be built in order to link -OBJECTS = init.o main.o varis.o fifo.o spi.o flash.o communication.o i2c.o config.o +OBJECTS = init.o main.o varis.o fifo.o spi.o AT26F004.o flash.o communication.o PC_communication.o i2c.o config.o ## Objects explicitly added by the user LINKONLYOBJECTS = @@ -94,12 +94,18 @@ spi.o: spi.c $(CC) $(INCLUDES) $(CFLAGS) -c $< +AT26F004.o: AT26F004.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + flash.o: flash.c $(CC) $(INCLUDES) $(CFLAGS) -c $< communication.o: communication.c $(CC) $(INCLUDES) $(CFLAGS) -c $< +communication.o: PC_communication.c + $(CC) $(INCLUDES) $(CFLAGS) -c $< + i2c.o: i2c.c $(CC) $(INCLUDES) $(CFLAGS) -c $< @@ -109,6 +115,9 @@ bootloader.o: bootloader.c $(CC) $(INCLUDES) $(CFLAGS) -c $< + + + ##Link $(TARGET): $(OBJECTS) $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) Added: firmware/tuxaudio/branches/audio_cleanup/PC_communication.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/PC_communication.c (rev 0) +++ firmware/tuxaudio/branches/audio_cleanup/PC_communication.c 2007-09-07 14:55:34 UTC (rev 500) @@ -0,0 +1,178 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id: */ + +#include <avr/io.h> +#include <avr/interrupt.h> + +#include "varis.h" +#include "fifo.h" +#include "communication.h" +#include "spi.h" + +void spiTransaction(void) +{ + if ((spi_start) && (spi_enable)) // Wait start + { + spi_start = 0; // Reset the spi start flag + spi_enable = 0; // Communication in progress + spi_count = 0; // Reset spi counter + spi_slave = HEADERS; // Set state machine + spi_master = HEADERM; + if (programmingFlash) + PORTB &= ~0x01; + // Reset SPI to fix strange bug on the spi + SPCR = 0x50; + SPSR = 0x00; + asm volatile /* Clear the SPI interrupt flag */ + ("in __tmp_reg__, %0" "\n\t" "in __tmp_reg__, %1" "\n\t":: + "I" (_SFR_IO_ADDR(SPSR)), "I"(_SFR_IO_ADDR(SPDR))); + + PORTB &= ~0x04; // Chip select + while (1) + { + if (spi_ready) + { + spi_ready = 0; + if (spi_slave == HEADERS) + { + /* Sound */ + if (fifoLength(&ADCFifo) >= 17) + spi_headerb = 0x02; /* frame will contain sound */ + else + spi_headerb = 0x00; /* no sound in frame */ + + /* Status */ + if ((rf_data_sent_ack == RF_DATA_SENT_NACKED) + || (rf_data_sent_ack == RF_DATA_SENT_DROPPED)) + { + spi_headerb |= 0x08; /* resend the previous status if nacked */ + cli(); + sei(); + } + else if (rf_data_sent_ack != RF_DATA_SENT_BUSY) /* wait the end of transmission */ + if (!popStatus(spi_commandTX)) /* fetch the next status */ + spi_headerb |= 0x08; /* indicate that the frame contains status */ + + SPDR = spi_headerb; // Header byte + spi_slave = GET_SOUND_FIFO; // Next state + } + else if (spi_slave == GET_SOUND_FIFO) + { + if (spi_count == 17) + spi_slave = PUT_COMMAND; // Next state + if (spi_headerb & 0x02) + { + cli(); + SPDR = pullFifo(&ADCFifo); // Get data from FIFO + sei(); + } + else + SPDR = 0x00; // No data to transmit + } + else if (spi_slave == PUT_COMMAND) + { + if (spi_count == 21) + spi_slave = DUMMY; // Next state + if (spi_headerb & 0x08) + { + SPDR = spi_commandTX[spi_count - 18]; // Get command from buffer + } + else + SPDR = 0x00; // No command to transmit + } + else if (spi_slave == DUMMY) + { + SPDR = 0x00; // Dummy byte in case of big frame + } + + while ((SPSR & 0x80) == 0) ; // Wait SPI response + + spi_count++; + if (spi_master == HEADERM) + { + spi_master_config = SPDR; // Save header config byte + if (spi_master_config & 0x08) // Command + commandRX = 1; // Flag to send command on I2C + if (spi_master_config & 0x80) // Double frame + spi_lenght_data = 34; + else + spi_lenght_data = 17; + spi_master = PUT_SOUND_FIFO; // Go to the next state + + if (!programmingFlash) // XXX code must be review it's very strange ..... + { + if (!(spi_master_config & 0x02)) + { + if (!lockAdaptFifo) + { + cli(); + adaptFifo(&PWMFifo); // Adaptative FIFO + sei(); + lockAdaptFifo = 1; + } + else + resetFifo(&PWMFifo); + } + else + { + lockAdaptFifo = 0; + } + } + + } + else if (spi_master == PUT_SOUND_FIFO) + { + if (spi_master_config & 0x02) + { + cli(); + pushFifo(&PWMFifo, SPDR); // Put into the FIFO + sei(); + } + if (spi_count == (spi_lenght_data + 1)) + spi_master = READ_COMMAND; // Go to the next state + } + else if (spi_master == READ_COMMAND) + { + if (spi_master_config & 0x08) + { + if (spi_master_config & 0x80) + spi_commandRX[spi_count - 36] = SPDR; // Put command into the buffer + else + spi_commandRX[spi_count - 19] = SPDR; // Put command into the buffer + } + if (spi_count == spi_lenght_data + 6) + { + /* Check the acknowledge from the rf */ + if (spi_headerb & 0x08) /* if data was sent in the current SPI transaction, mark buffer as full and drop the received status */ + rf_data_sent_ack = RF_DATA_SENT_BUSY; /* status buffer of the rf filled */ + else + rf_data_sent_ack = spi_commandRX[4]; /* get the acknowledge of the previous sent data */ + + PORTB |= 0x04; // Chip deselect + spi_enable = 1; + break; + } + } + } + } + } +} + Added: firmware/tuxaudio/branches/audio_cleanup/PC_communication.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/PC_communication.h (rev 0) +++ firmware/tuxaudio/branches/audio_cleanup/PC_communication.h 2007-09-07 14:55:34 UTC (rev 500) @@ -0,0 +1,27 @@ +/* + * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id: $ */ + +#ifndef PC_COMMUNICATION_H +#define PC_COMMUNICATION_H + +extern void spiTransaction(void); + +#endif Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-07 14:55:34 UTC (rev 500) @@ -24,6 +24,7 @@ #include "spi.h" #include "i2c.h" #include "flash.h" +#include "AT26F004.h" /* Declarations */ /* Theses functions are declared with the static attribute, so they're * accessible only by this module */ @@ -33,15 +34,6 @@ static void initSoundProgramming(void); static void soundProgramming(void); static void endProgramming(void); -static uint8_t read_status(void); -static void write_enable(void); -static void write_disable(void); -static void write_status(uint8_t const status); -static void erase_flash(void); -static void unprotect_sector(uint8_t const ad2, uint8_t const ad1, - uint8_t const ad0); -static void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, - uint8_t const data); uint8_t f_state = 0; @@ -75,7 +67,7 @@ PORTB |= 0x01; if (f_state == ERASE_STATE) { - if (read_status() == 0x10) + if (read_status() & BUSY) f_state ++; } else if (f_state == FIRST_PROG_STATE) @@ -199,9 +191,9 @@ PORTB |= 0x02; // Chip Deselect /* Check adresses */ - if (ad[0] > 0x07) + if (ad[0] > TOP_A2) return; /* don't read outside the flash */ - if (ad[3] > 0x07) + if (ad[3] > TOP_A2) return; /* don't read outside the flash */ if ((ad[0] == 0) && (ad[1] < 0x04)) return; /* minimum index not respected */ @@ -247,142 +239,12 @@ \brief This function read the flash memory status. */ -static 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 */ - return status; -} -/** - * \ingroup flash - \brief This function set the write enable flag of the flash memory. - */ -static void write_enable(void) -{ - FLASH_CS_ON; /* Chip Select */ - spiSend(WRITE_EN); /* Send Write Enable Command */ - FLASH_CS_OFF; /* Chip Deselect */ -} /** * \ingroup flash - - \brief This function clear the write enable flag of the flash memory. - */ - -static void write_disable(void) -{ - FLASH_CS_ON; /* Chip Select */ - spiSend(WRITE_DIS); /* Send Write Disable Command */ - FLASH_CS_OFF; /* Chip Deselect */ -} - -/** - * \ingroup flash - - \brief This function write into the flash memory status register. - */ - -static 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 */ - -} -/** - * \ingroup flash - \param ad2 high address part - \param ad1 medium adress part - \param ad0 lower adress part - - \brief This function unprotect a sector. - */ -static 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 - spiSend(ad1); - spiSend(ad0); - FLASH_CS_OFF; // Chip Deselect - -} -/** - * \ingroup flash - - \brief This function erase the entire memory. - */ - -static void erase_flash(void) -{ - write_status(0x00); // Disable sector protection register - write_enable(); // Enable the writing - unprotect_sector(SECTOR0); - write_enable(); // Enable the writing - unprotect_sector(SECTOR1); - write_enable(); // Enable the writing - unprotect_sector(SECTOR2); - write_enable(); // Enable the writing - unprotect_sector(SECTOR3); - write_enable(); // Enable the writing - unprotect_sector(SECTOR4); - write_enable(); // Enable the writing - unprotect_sector(SECTOR5); - write_enable(); // Enable the writing - unprotect_sector(SECTOR6); - write_enable(); // Enable the writing - unprotect_sector(SECTOR7); - write_enable(); // Enable the writing - unprotect_sector(SECTOR8); - write_enable(); // Enable the writing - unprotect_sector(SECTOR9); - write_enable(); // Enable the writing - unprotect_sector(SECTOR10); - - write_enable(); // Enable the writing - - FLASH_CS_ON; // Chip Select - spiSend(CHIP_ERASE); // Send Erase Bulk command - FLASH_CS_OFF; // Chip Deselect -} - -/** - * \ingroup flash - \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. - */ - -static void program_flash(uint8_t const ad2, uint8_t const ad1, uint8_t const ad0, - uint8_t const data) -{ - write_enable(); - FLASH_CS_ON; // Chip Select - spiSend(BYTE_PROGRAM); // Send Page Byte Command - spiSend(ad2); // Send Address - spiSend(ad1); - spiSend(ad0); - spiSend(data); // Write data in flash - FLASH_CS_OFF; // Chip Deselect - - while (read_status() != 0x10) ; // Wait Page Program Cycle -} - - - - -/** - * \ingroup flash * \brief Write the number of sound to be stored. This function store the first TOC byte (numSound), received with the flash program command, at the first memory adress. @@ -485,7 +347,7 @@ if (ad1 == 0x00) ad2++; } - while (read_status() != 0x52) ; // Wait Page Program Cycle + while (read_status() & BUSY) ; // Wait Page Program Cycle } /* Check for the last sound byte */ Modified: firmware/tuxaudio/branches/audio_cleanup/flash.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-07 14:55:34 UTC (rev 500) @@ -34,47 +34,12 @@ #ifndef FLASH_H #define FLASH_H -/* Flash (AT26F004) OP CODE define */ -#define READ_ARRAY 0x0B -#define READ_ARRAY_LOW_F 0x03 -#define BLOCK_ERASE_4K 0x20 -#define BLOCK_ERASE_32K 0x52 -#define BLOCK_ERASE_64K 0xD8 -#define CHIP_ERASE 0x60 -#define BYTE_PROGRAM 0x02 -#define SEQU_PROGRAM 0xAF -#define WRITE_EN 0x06 -#define WRITE_DIS 0x04 -#define PROTECT_SECTOR 0x36 -#define UNPROTECT_SECTOR 0x39 -#define READ_SECT_PROTECT 0x3C - -#define READ_STATUS_REG 0x05 -#define WRITE_STATUS_REG 0x01 - -#define READ_MANUFACT 0x9F -#define DEEP_POWER_MODE 0xB9 -#define RESUME_DEEP_MODE 0xAB - -#define NOP 0x00 - #define FLASH_CS_ON PORTB &= ~0x02 #define FLASH_CS_OFF PORTB |= 0x02 -#define SECTOR0 0x00, 0x00, 0x00 -#define SECTOR1 0x01, 0x00, 0x00 -#define SECTOR2 0x02, 0x00, 0X00 -#define SECTOR3 0x03, 0x00, 0X00 -#define SECTOR4 0x04, 0x00, 0X00 -#define SECTOR5 0x05, 0x00, 0X00 -#define SECTOR6 0x06, 0x00, 0X00 -#define SECTOR7 0x07, 0x00, 0X00 -#define SECTOR8 0x07, 0x80, 0X00 -#define SECTOR9 0x07, 0xA0, 0X00 -#define SECTOR10 0x07, 0xC0, 0X00 /* Flash programming states */ #define ERASE_STATE 0 Modified: firmware/tuxaudio/branches/audio_cleanup/main.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/main.c 2007-09-07 14:55:34 UTC (rev 500) @@ -34,6 +34,7 @@ #include "flash.h" #include "version.h" #include "config.h" +#include "PC_communication.h" /* * Version number Modified: firmware/tuxaudio/branches/audio_cleanup/spi.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/spi.c 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/spi.c 2007-09-07 14:55:34 UTC (rev 500) @@ -17,164 +17,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: */ +/* $Id: $ */ #include <avr/io.h> -#include <avr/interrupt.h> +#include "spi.h" -#include "varis.h" -#include "fifo.h" -#include "communication.h" -void spiTransaction(void) -{ - if ((spi_start) && (spi_enable)) // Wait start - { - spi_start = 0; // Reset the spi start flag - spi_enable = 0; // Communication in progress - spi_count = 0; // Reset spi counter - spi_slave = HEADERS; // Set state machine - spi_master = HEADERM; - if (programmingFlash) - PORTB &= ~0x01; - // Reset SPI to fix strange bug on the spi - SPCR = 0x50; - SPSR = 0x00; - asm volatile /* Clear the SPI interrupt flag */ - ("in __tmp_reg__, %0" "\n\t" "in __tmp_reg__, %1" "\n\t":: - "I" (_SFR_IO_ADDR(SPSR)), "I"(_SFR_IO_ADDR(SPDR))); - - PORTB &= ~0x04; // Chip select - while (1) - { - if (spi_ready) - { - spi_ready = 0; - if (spi_slave == HEADERS) - { - /* Sound */ - if (fifoLength(&ADCFifo) >= 17) - spi_headerb = 0x02; /* frame will contain sound */ - else - spi_headerb = 0x00; /* no sound in frame */ - - /* Status */ - if ((rf_data_sent_ack == RF_DATA_SENT_NACKED) - || (rf_data_sent_ack == RF_DATA_SENT_DROPPED)) - { - spi_headerb |= 0x08; /* resend the previous status if nacked */ - cli(); - sei(); - } - else if (rf_data_sent_ack != RF_DATA_SENT_BUSY) /* wait the end of transmission */ - if (!popStatus(spi_commandTX)) /* fetch the next status */ - spi_headerb |= 0x08; /* indicate that the frame contains status */ - - SPDR = spi_headerb; // Header byte - spi_slave = GET_SOUND_FIFO; // Next state - } - else if (spi_slave == GET_SOUND_FIFO) - { - if (spi_count == 17) - spi_slave = PUT_COMMAND; // Next state - if (spi_headerb & 0x02) - { - cli(); - SPDR = pullFifo(&ADCFifo); // Get data from FIFO - sei(); - } - else - SPDR = 0x00; // No data to transmit - } - else if (spi_slave == PUT_COMMAND) - { - if (spi_count == 21) - spi_slave = DUMMY; // Next state - if (spi_headerb & 0x08) - { - SPDR = spi_commandTX[spi_count - 18]; // Get command from buffer - } - else - SPDR = 0x00; // No command to transmit - } - else if (spi_slave == DUMMY) - { - SPDR = 0x00; // Dummy byte in case of big frame - } - - while ((SPSR & 0x80) == 0) ; // Wait SPI response - - spi_count++; - if (spi_master == HEADERM) - { - spi_master_config = SPDR; // Save header config byte - if (spi_master_config & 0x08) // Command - commandRX = 1; // Flag to send command on I2C - if (spi_master_config & 0x80) // Double frame - spi_lenght_data = 34; - else - spi_lenght_data = 17; - spi_master = PUT_SOUND_FIFO; // Go to the next state - - if (!programmingFlash) // XXX code must be review it's very strange ..... - { - if (!(spi_master_config & 0x02)) - { - if (!lockAdaptFifo) - { - cli(); - adaptFifo(&PWMFifo); // Adaptative FIFO - sei(); - lockAdaptFifo = 1; - } - else - resetFifo(&PWMFifo); - } - else - { - lockAdaptFifo = 0; - } - } - - } - else if (spi_master == PUT_SOUND_FIFO) - { - if (spi_master_config & 0x02) - { - cli(); - pushFifo(&PWMFifo, SPDR); // Put into the FIFO - sei(); - } - if (spi_count == (spi_lenght_data + 1)) - spi_master = READ_COMMAND; // Go to the next state - } - else if (spi_master == READ_COMMAND) - { - if (spi_master_config & 0x08) - { - if (spi_master_config & 0x80) - spi_commandRX[spi_count - 36] = SPDR; // Put command into the buffer - else - spi_commandRX[spi_count - 19] = SPDR; // Put command into the buffer - } - if (spi_count == spi_lenght_data + 6) - { - /* Check the acknowledge from the rf */ - if (spi_headerb & 0x08) /* if data was sent in the current SPI transaction, mark buffer as full and drop the received status */ - rf_data_sent_ack = RF_DATA_SENT_BUSY; /* status buffer of the rf filled */ - else - rf_data_sent_ack = spi_commandRX[4]; /* get the acknowledge of the previous sent data */ - - PORTB |= 0x04; // Chip deselect - spi_enable = 1; - break; - } - } - } - } - } -} - unsigned char spiSend(unsigned char data) { SPDR = data; // Send Read Page Command Modified: firmware/tuxaudio/branches/audio_cleanup/spi.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/spi.h 2007-09-07 13:55:42 UTC (rev 499) +++ firmware/tuxaudio/branches/audio_cleanup/spi.h 2007-09-07 14:55:34 UTC (rev 500) @@ -17,12 +17,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: */ +/* $Id: $ */ #ifndef SPI_H #define SPI_H -extern void spiTransaction(void); extern unsigned char spiSend(unsigned char data); #endif |