[tuxdroid-svn] r491 - firmware/tuxaudio/branches/audio_cleanup
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-09-06 12:48:23
|
Author: Paul_R Date: 2007-09-06 14:48:22 +0200 (Thu, 06 Sep 2007) New Revision: 491 Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c firmware/tuxaudio/branches/audio_cleanup/flash.h Log: * Added flash memory defines. Modified: firmware/tuxaudio/branches/audio_cleanup/flash.c =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-06 12:07:50 UTC (rev 490) +++ firmware/tuxaudio/branches/audio_cleanup/flash.c 2007-09-06 12:48:22 UTC (rev 491) @@ -23,6 +23,7 @@ #include "varis.h" #include "spi.h" #include "i2c.h" +#include "flash.h" unsigned char read_status(void); void write_enable(void); @@ -42,57 +43,57 @@ { unsigned char status; - PORTB &= ~0x02; /* Chip Select */ + FLASH_CS_ON; /* Chip Select */ - spiSend(0x05); /* Send Read Status Command */ + spiSend(READ_STATUS_REG); /* Send Read Status Command */ - status = spiSend(0x00); /* Read status on spi */ + status = spiSend(NOP); /* Read status on spi */ - PORTB |= 0x02; /* Chip Deselect */ + FLASH_CS_OFF; /* Chip Deselect */ return status; } void write_enable(void) { - PORTB &= ~0x02; /* Chip Select */ + FLASH_CS_ON; /* Chip Select */ - spiSend(0x06); /* Send Write Enable Command */ + spiSend(WRITE_EN); /* Send Write Enable Command */ - PORTB |= 0x02; /* Chip Deselect */ + FLASH_CS_OFF; /* Chip Deselect */ } void write_disable(void) { - PORTB &= ~0x02; /* Chip Select */ + FLASH_CS_ON; /* Chip Select */ - spiSend(0x04); /* Send Write Disable Command */ + spiSend(WRITE_DIS); /* Send Write Disable Command */ - PORTB |= 0x02; /* Chip Deselect */ + FLASH_CS_OFF; /* Chip Deselect */ } void write_status(unsigned char status) { - PORTB &= ~0x02; /* Chip Select */ + FLASH_CS_ON; /* Chip Select */ - spiSend(0x01); /* Send Write Status Command */ + spiSend(WRITE_STATUS_REG); /* Send Write Status Command */ spiSend(status); /* Send status */ - PORTB |= 0x02; /* Chip Deselect */ + FLASH_CS_OFF; /* Chip Deselect */ } void unprotect_sector(unsigned char ad2, unsigned char ad1, unsigned char ad0) { - PORTB &= ~0x02; // Chip Select + FLASH_CS_ON; // Chip Select - spiSend(0x39); // Send unprotect sector command + spiSend(UNPROTECT_SECTOR); // Send unprotect sector command spiSend(ad2); // Send Address spiSend(ad1); spiSend(ad0); - PORTB |= 0x02; // Chip Deselect + FLASH_CS_OFF; // Chip Deselect } @@ -100,35 +101,35 @@ { write_status(0x00); // Disable sector protection register write_enable(); // Enable the writing - unprotect_sector(0x00, 0x00, 0x00); // Unprotected sector 0 + unprotect_sector(SECTOR0); // Unprotected sector 0 write_enable(); // Enable the writing - unprotect_sector(0x01, 0x00, 0x00); // Unprotected sector 1 + unprotect_sector(SECTOR1); // Unprotected sector 1 write_enable(); // Enable the writing - unprotect_sector(0x02, 0x00, 0x00); // Unprotected sector 2 + unprotect_sector(SECTOR2); // Unprotected sector 2 write_enable(); // Enable the writing - unprotect_sector(0x03, 0x00, 0x00); // Unprotected sector 3 + unprotect_sector(SECTOR3); // Unprotected sector 3 write_enable(); // Enable the writing - unprotect_sector(0x04, 0x00, 0x00); // Unprotected sector 4 + unprotect_sector(SECTOR4); // Unprotected sector 4 write_enable(); // Enable the writing - unprotect_sector(0x05, 0x00, 0x00); // Unprotected sector 5 + unprotect_sector(SECTOR5); // Unprotected sector 5 write_enable(); // Enable the writing - unprotect_sector(0x06, 0x00, 0x00); // Unprotected sector 6 + unprotect_sector(SECTOR6); // Unprotected sector 6 write_enable(); // Enable the writing - unprotect_sector(0x07, 0x00, 0x00); // Unprotected sector 7 + unprotect_sector(SECTOR7); // Unprotected sector 7 write_enable(); // Enable the writing - unprotect_sector(0x07, 0x80, 0x00); // Unprotected sector 8 + unprotect_sector(SECTOR8); // Unprotected sector 8 write_enable(); // Enable the writing - unprotect_sector(0x07, 0xA0, 0x00); // Unprotected sector 9 + unprotect_sector(SECTOR9); // Unprotected sector 9 write_enable(); // Enable the writing - unprotect_sector(0x07, 0xC0, 0x00); // Unprotected sector 10 + unprotect_sector(SECTOR10); // Unprotected sector 10 write_enable(); // Enable the writing - PORTB &= ~0x02; // Chip Select + FLASH_CS_ON; // Chip Select - spiSend(0xC7); // Send Erase Bulk command + spiSend(CHIP_ERASE); // Send Erase Bulk command - PORTB |= 0x02; // Chip Deselect + FLASH_CS_OFF; // Chip Deselect } void program_flash(unsigned char ad2, unsigned char ad1, unsigned char ad0, @@ -136,15 +137,15 @@ { write_enable(); - PORTB &= ~0x02; // Chip Select + FLASH_CS_ON; // Chip Select - spiSend(0x02); // Send Page Byte Command + spiSend(BYTE_PROGRAM); // Send Page Byte Command spiSend(ad2); // Send Address spiSend(ad1); spiSend(ad0); spiSend(data); // Write data in flash - PORTB |= 0x02; // Chip Deselect + FLASH_CS_OFF; // Chip Deselect while (read_status() != 0x10) ; // Wait Page Program Cycle } @@ -153,15 +154,15 @@ { unsigned char data1; - PORTB &= ~0x02; // Chip Select + FLASH_CS_ON; // Chip Select - spiSend(0x03); // Send Read Page Command + spiSend(READ_ARRAY_LOW_F); // Send Read Page Command spiSend(ad2); // Send Address spiSend(ad1); spiSend(ad0); - data1 = spiSend(0x00); // Wait response + data1 = spiSend(NOP); // Wait response - PORTB |= 0x02; // Chip Deselect + FLASH_CS_OFF; // Chip Deselect return data1; } @@ -243,8 +244,8 @@ { flash_state = 0; write_enable(); - PORTB &= ~0x02; // Chip Select - spiSend(0xAF); // Send Sequencial Program Command + FLASH_CS_ON; // Chip Select + spiSend(SEQU_PROGRAM); // Send Sequencial Program Command spiSend(ad2); // Send Address spiSend(ad1); spiSend(ad0); @@ -261,7 +262,7 @@ else flash_state = 0; } - PORTB |= 0x02; // Chip Deselect + FLASH_CS_OFF; // Chip Deselect } void soundProgramming(void) @@ -272,10 +273,10 @@ { if (!isFifoEmpty(&PWMFifo)) // Fifo not empty { - PORTB &= ~0x02; // Chip Select - spiSend(0xAF); // Send Sequencial Program Command + FLASH_CS_ON;// PORTB &= ~0x02; // Chip Select + spiSend(SEQU_PROGRAM); // Send Sequencial Program Command spiSend(pullFifo(&PWMFifo)); // Write data in flash - PORTB |= 0x02; // Chip DeselecT + FLASH_CS_OFF;// PORTB |= 0x02; // Chip DeselecT ad0++; // Increment address byte if (ad0 == 0x00) { Modified: firmware/tuxaudio/branches/audio_cleanup/flash.h =================================================================== --- firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-06 12:07:50 UTC (rev 490) +++ firmware/tuxaudio/branches/audio_cleanup/flash.h 2007-09-06 12:48:22 UTC (rev 491) @@ -31,13 +31,51 @@ /** \file flash.c \ingroup flash */ +#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 -#ifndef FLASH_H -#define FLASH_H +#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 + extern unsigned char read_status(void); extern void write_enable(void); extern void write_disable(void); @@ -45,7 +83,6 @@ 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); |