Телесистемы
 Разработка, производство и продажа радиоэлектронной аппаратуры
На главную   | Карта сайта | Пишите нам | В избранное
Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс.
e-mail:jobsmp@pochta.ru

Телесистемы | Электроника | Конференция «Микроконтроллеры и их применение»

Не помню, где скачал уже (+)

Отправлено DASM 13 мая 2008 г. 16:35
В ответ на: откуда выдрать Си код для работы с флэшой at45db321? отправлено isstar 13 мая 2008 г. 16:24


//*---------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*---------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*---------------------------------------------------------------------------
//* File Name : at45db321.h
//* Object : Data Flash Atmel AT45DB321 Description File
//* Translator : ARM Software Development Toolkit V2.5
//*
//* 1.0 03/06/00 PF : Creation
//*---------------------------------------------------------------------------

#ifndef at45db321_h
#define at45db321_h

/*--------------------*/
/* Command Definition */
/*--------------------*/

#define DB321_PAGE_READ 0x52 /* Main memory page read */
#define DB321_BUF1_READ 0x54 /* Buffer 1 read */
#define DB321_BUF2_READ 0x56 /* Buffer 2 read */
#define DB321_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
#define DB321_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
#define DB321_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
#define DB321_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
#define DB321_BUF1_WRITE 0x84 /* Buffer 1 write */
#define DB321_BUF2_WRITE 0x87 /* Buffer 2 write */
#define DB321_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
#define DB321_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
#define DB321_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */

#define DB321_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
#define DB321_PAGE_ERASE 0x81 /* Page Erase */
#define DB321_BLOCK_ERASE 0x50 /* Block Erase */
#define DB321_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
#define DB321_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
#define DB321_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
#define DB321_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */

#define DB321_STATUS 0x57 /* Status Register */

/*-----------------*/
/* Size Definition */
/*-----------------*/

#define DB321_PAGE_SIZE 528
#define DB321_PAGE_PER_BLOCK 8
#define DB321_BLOCK_SIZE (DB321_PAGE_SIZE*DB321_PAGE_PER_BLOCK) /* 528*8 = 4224 bytes */
#define DB321_BLOCK_PER_SECTOR 64
#define DB321_PAGE_PER_SECTOR (DB321_PAGE_PER_BLOCK*DB321_BLOCK_PER_SECTOR) /* 8*64 = 512 pages */
#define DB321_SECTOR_SIZE (DB321_BLOCK_PER_SECTOR*DB321_BLOCK_SIZE) /* (8*528)*64 = 270336 bytes */
#define DB321_SECTOR_NUMBER 17
#define DB321_SECTOR_0_SIZE (DB321_PAGE_PER_BLOCK*DB321_PAGE_SIZE) /* 8*528 = 4224 bytes */
#define DB321_SECTOR_1_SIZE (DB321_BLOCK_PER_SECTOR*DB321_BLOCK_SIZE) /* 64*4224 = 261888 bytes */
#define DB321_SIZE (DB321_SECTOR_NUMBER*DB321_SECTOR_SIZE)


extern u_int db321_open ( void ) ;
extern void db321_close ( void ) ;
extern void db321_read ( u_char *src, u_char *dest, int size ) ;
extern void db321_write ( u_char *src, u_char *dest, int size ) ;

extern void db321_write_buffer ( u_char *src, u_char *dest, int size ) ;
extern void db321_read_buffer ( u_char *src, u_char *dest, int size ) ;

#endif /* at45db321_h */



//*---------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*---------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*-----------------------------------------------------------------------------
//* File Name : at45db321.c
//* Object : Data Flash Atmel AT45DB321 Driver.
//*
//* 1.0 30/06/00 PF : Creation
//*---------------------------------------------------------------------------

#include "parts/m55800/lib_m55800.h"
#include "drivers/serial_periph_1/serial_periph_1.h"
#include "at45db321.h"

/* Global Variables */
SerialPeriph1DataDesc spi_data ;

/* Data Flash Assembler Interrupt Handler */
extern void data_flash_asm_handler (void) ;

/* Mount a Serial Peripheral 1Desc as the as Data Flash */
SerialPeriph1Desc data_flash_desc =
{
&SPI_DESC, /* SPI Mode Register */
&spi_data,
0, /* SPI pin mode */
SP_CPOL|(7<<16)|(50<<8), /* Peripheral Chip Select Register */
SPI_NPCS2_USED, /* Data Flash connected on NPCS1 */
data_flash_asm_handler, /* Assembler Handler */
0
} ;

//*-----------------------------------------------------------------------------
//* Function Name : db321_open
//* Object : Open the Data Flash connection
//* Input Parameters :
//* Output Parameters : The Data Flash status register
//* Functions called :
//*-----------------------------------------------------------------------------
u_int db321_open ( void )
//* Begin
{
u_char cmd[2] = {DB321_STATUS,0} ;
u_int time_out = 1000 ;
u_int i = 0 ;

serial_periph_1_open ( &data_flash_desc ) ;

spi_data.tx_cmd_pt = cmd ;
spi_data.tx_cmd_size = 2 ;
spi_data.rx_cmd_pt = cmd ;
spi_data.rx_cmd_size = 2 ;
spi_data.tx_data_size = 0 ;
serial_periph_1_write ( &data_flash_desc ) ;

while ( (serial_periph_1_get_status( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE) && i < time_out )
i++;

//* If timeout
if ( i < time_out )
{
return ( cmd[1] ) ;
}

else return ( FALSE ) ;
}
//* End

//*-----------------------------------------------------------------------------
//* Function Name : db321_close
//* Object : Close the connection to a Data Flash
//* Input Parameters : None
//* Output Parameters : None
//* Functions called :
//*-----------------------------------------------------------------------------
void db321_close ( void )
//* Begin
{
//* Close the SPI connection
serial_periph_1_close ( &data_flash_desc ) ;
}
//* End

//*-----------------------------------------------------------------------------
//* Function Name : db321_read
//* Object : Read data from the DB321 memory
//* Input Parameters : <*src> = Pointer to Main memory page
//* : <*dest> = data buffer pointer
//* : <size> = data buffer size
//*-----------------------------------------------------------------------------
void db321_read ( u_char *src, u_char *dest, int size )
//* Begin
{
u_char cmd[8] = { DB321_PAGE_READ, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF} ;

spi_data.tx_cmd_pt = cmd ;
spi_data.tx_cmd_size = 8 ;
spi_data.rx_cmd_pt = cmd ;
spi_data.rx_cmd_size = 8 ;

//* If source does not fit a page start address
if (( spi_data.tx_data_size = ((u_int) src % DB321_PAGE_SIZE )) != 0 )
{
//* Send first Read Command
cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.rx_data_size = spi_data.tx_data_size ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;

//* Update size, source and destination pointers
size -= spi_data.tx_data_size ;
dest += spi_data.tx_data_size ;
src += spi_data.tx_data_size ;
}

while (( size-DB321_PAGE_SIZE ) > 0 )
{
//* Send a Read Command with Source Base Address
cmd[0] = DB321_PAGE_READ ;
cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.tx_data_size = DB321_PAGE_SIZE ;
spi_data.rx_data_size = DB321_PAGE_SIZE ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;

//* Update size, source and destination pointers
size -= DB321_PAGE_SIZE ;
dest += DB321_PAGE_SIZE ;
src += DB321_PAGE_SIZE ;
}

//* If still some bytes to read
if (( spi_data.tx_data_size = size ) > 0 )
{
//* Send a Read Command with Source Base Address
cmd[0] = DB321_PAGE_READ ;
cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.rx_data_size = spi_data.tx_data_size ;
serial_periph_1_write ( &data_flash_desc ) ;

serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;
}
}
//* End

//*-----------------------------------------------------------------------------
//* Function Name : db321_write_buffer
//* Object : Write data to the memory
//* Input Parameters : <*src> = Data buffer
//* : <*dest> = Buffer 1 or buffer 2 of the memory
//* : <size> = data buffer size
//*-----------------------------------------------------------------------------
void db321_write_buffer ( u_char *src, u_char *dest, int size )
//* Begin
{
u_char cmd[4] = { DB321_BUF1_WRITE, 0, 0, 0 } ;

spi_data.tx_cmd_pt = cmd ;
spi_data.tx_cmd_size = 4 ;
spi_data.rx_cmd_pt = cmd ;
spi_data.rx_cmd_size = 4 ;

//* Send first Read Command
cmd[1] = (u_char)(((u_int)dest & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)dest & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)dest & 0xFF) ;
spi_data.rx_data_pt = src ;
spi_data.tx_data_pt = src ;
spi_data.rx_data_size = size ;
spi_data.tx_data_size = size ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;
}


//*-----------------------------------------------------------------------------
//* Function Name : db321_read_buffer
//* Object : Read data from the SPI memory
//* Input Parameters : <*src> = source buffer
//* : <*dest> = destination buffer
//* : <size> = data buffer size
//*-----------------------------------------------------------------------------
void db321_read_buffer ( u_char *src, u_char *dest, int size )
//* Begin
{
u_char cmd[5] = { DB321_BUF1_READ, 0, 0, 0, 0 } ;

spi_data.tx_cmd_pt = cmd ;
spi_data.tx_cmd_size = 5 ;
spi_data.rx_cmd_pt = cmd ;
spi_data.rx_cmd_size = 5 ;

cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.rx_data_size = size ;
spi_data.tx_data_size = size ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;

}

//*-----------------------------------------------------------------------------
//* Function Name : db321_write
//* Object : Write data from the SPI
//* Input Parameters : <*src> = Source buffer
//* : <data> = data buffer pointer
//* : <size> = data buffer size
//*-----------------------------------------------------------------------------
void db321_write ( u_char *src, u_char *dest, int size )
//* Begin
{
u_char cmd[4] = { DB321_BUF1_WRITE, 0, 0, 0 } ;

spi_data.tx_cmd_pt = cmd ;
spi_data.tx_cmd_size = 4 ;
spi_data.rx_cmd_pt = cmd ;
spi_data.rx_cmd_size = 4 ;

//* Send first Read Command
cmd[1] = (u_char)(((u_int)dest & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)dest & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)dest & 0xFF) ;
spi_data.rx_data_pt = src ;
spi_data.tx_data_pt = src ;
spi_data.rx_data_size = 0 ;
spi_data.tx_data_size = size ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;

//* Update size, source and destination pointers
size -= spi_data.tx_data_size ;
dest += spi_data.tx_data_size ;
src += spi_data.tx_data_size ;


#ifdef NEVER
//* If source does not fit a page start address
if (( spi_data.tx_data_size = ((u_int) src % DB321_PAGE_SIZE )) != 0 )
{

while (( size-DB321_PAGE_SIZE ) > 0 )
{
//* Send a Read Command with Source Base Address
cmd[0] = DB321_PAGE_READ ;
cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.tx_data_size = DB321_PAGE_SIZE ;
spi_data.rx_data_size = DB321_PAGE_SIZE ;
serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;

//* Update size, source and destination pointers
size -= DB321_PAGE_SIZE ;
dest += DB321_PAGE_SIZE ;
src += DB321_PAGE_SIZE ;
}

//* If still some bytes to read
if (( spi_data.tx_data_size = size ) > 0 )
{
//* Send a Read Command with Source Base Address
cmd[0] = DB321_PAGE_READ ;
cmd[1] = (u_char)(((u_int)src & 0xFF0000)>>16) ;
cmd[2] = (u_char)(((u_int)src & 0xFF00)>>8) ;
cmd[3] = (u_char)((u_int)src & 0xFF) ;
spi_data.rx_data_pt = dest ;
spi_data.tx_data_pt = dest ;
spi_data.rx_data_size = spi_data.tx_data_size ;
serial_periph_1_write ( &data_flash_desc ) ;

serial_periph_1_write ( &data_flash_desc ) ;

//* Wait for the end of transmission
while ( serial_periph_1_get_status ( &data_flash_desc ) != SERIAL_PERIPH_1_IDLE ) ;
}
#endif
}
//* End


Составить ответ | Вернуться на конференцию

Ответы


Отправка ответа
Имя*: 
Пароль: 
E-mail: 
Тема*:

Сообщение:

Ссылка на URL: 
URL изображения: 

если вы незарегистрированный на форуме пользователь, то
для успешного добавления сообщения заполните поле, как указано ниже:
при вычитании трёх из шести получится:

Перейти к списку ответов | Конференция | Раздел "Электроника" | Главная страница | Карта сайта

Rambler's Top100 Рейтинг@Mail.ru
 
Web telesys.ru