[an error occurred while processing this directive]
|
// GetDeviceDensity.c
// gets the device density and updates the global
// variables pages with the number of pages in the device and page_size
// with the number of bytes in a buffer
#include "xmodem.h"
extern unsigned int pages; // number of pages in device
extern unsigned int page_size; // page size for device
// function prototypes
void WriteByte(unsigned char byte);
void GetDeviceDensity(void) {
unsigned char dataflash_density; // spi status register contents
// bring CS on dataflash low for status register read
PORTB &= ~((1 << DFCS));
// now read the status register ... it contains the compare status
// issue status register read
WriteByte(STATUS_REGISTER);
WriteByte(0xff); // have to write a byte to get it back ... full duplex
dataflash_density = SPDR; // read the status
// bring CS on dataflash high
PORTB |= (1 << DFCS);
dataflash_density = ((dataflash_density >> 3) & 0x07);
// decode pages and page_size from device density
switch (dataflash_density) {
case (1) : pages = 512; // 1M
page_size = 264;
break;
case (2) : pages = 1024; // 2M
page_size = 264;
break;
case (3) : pages = 2048; // 4M
page_size = 264;
break;
case (4) : pages = 4096; // 8M
page_size = 264;
break;
case (5) : pages = 4096; // 16M
page_size = 528;
break;
case (6) : pages = 8192; // 32M
page_size = 528;
break;
}
}
E-mail: info@telesys.ru