コード例 #1
0
ファイル: at45dbx_example.c プロジェクト: AndreyMostovov/asf
/*! \brief Main function.
 */
int main(void)
{
	uint16_t i;

	// Initialize the system - clock and board.
	system_init();
	at45dbx_init();
	if(at45dbx_mem_check()==true)	{
		port_pin_set_output_level(DATA_FLASH_LED_EXAMPLE_0, false);
	} else
	{
		test_ko();
	}

	// Prepare half a data flash sector to 0xAA
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		ram_buf[i]=0xAA;
	}
	// And the remaining half to 0x55
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=0x55;
	}

	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read back this sector and compare to expected values
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		if (ram_buf[i]!=0xAA) {
			test_ko();
		}
	}
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		if (ram_buf[i]!=0x55) {
			test_ko();
		}
	}

	// Write one data flash sector to 0x00, 0x01 ....
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=i;
	}
	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read one data flash sector to ram
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		if ( ram_buf[i]!=(i%0x100) ) {
			test_ko();
		}
	}

	while (1);
}
コード例 #2
0
/**
 * \brief Application entry point for AT25DFx example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint16_t i;

	sysclk_init();
	board_init();

	/* Initialize the SerialFlash */
	at25dfx_initialize();

	/* Set the SerialFlash active */
	at25dfx_set_mem_active(AT25DFX_MEM_ID);

	/* Unprotect the chip */
	if (at25dfx_protect_chip(AT25_TYPE_UNPROTECT) == AT25_SUCCESS) {
		LED_On(DATA_FLASH_LED_EXAMPLE_0);
	} else {
		test_ko();
	}

	/* Check if the SerialFlash is valid */
	if (at25dfx_mem_check() == AT25_SUCCESS) {
		LED_On(DATA_FLASH_LED_EXAMPLE_0);
	} else {
		test_ko();
	}

	/* Prepare half of the SerialFlash sector as 0xAA */
	for (i = 0; i < AT25DFX_TEST_DATA_SIZE / 2; i++) {
		ram_buff[i] = 0xAA;
	}

	/* And the remaining half as 0x55 */
	for (; i < AT25DFX_TEST_DATA_SIZE; i++) {
		ram_buff[i] = 0x55;
	}

	/* Erase the block before write */
	at25dfx_erase_block(AT25DFX_TEST_BLOCK_ADDR);

	/* Write the data to the SerialFlash */
	at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	/* Read back this sector and compare them with the expected values */
	at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	for (i = 0; i < AT25DFX_TEST_DATA_SIZE / 2; i++) {
		if (ram_buff[i] != 0xAA) {
			test_ko();
		}
	}
	for (; i < AT25DFX_TEST_DATA_SIZE; i++) {
		if (ram_buff[i] != 0x55) {
			test_ko();
		}
	}

	/* Write one SerialFlash sector as 0x00, 0x01 .... */
	for (i = 0; i < AT25DFX_TEST_DATA_SIZE; i++) {
		ram_buff[i] = i;
	}

	/* Erase the block before write */
	at25dfx_erase_block(AT25DFX_TEST_BLOCK_ADDR);

	/* Write the data to the SerialFlash */
	at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	/* Read back this sector and compare them with the expected values */
	at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	for (i = 0; i < AT25DFX_TEST_DATA_SIZE; i++) {
		if (ram_buff[i] != (i % 0x100)) {
			test_ko();
		}
	}

	LED_On(DATA_FLASH_LED_EXAMPLE_1);
	while (1);
}
コード例 #3
0
/*! \brief Main function.
 */
int main(void)
{
	uint16_t i;
	sysclk_init();

	// Initialize the board.
	// The board-specific conf_board.h file contains the configuration of the board
	// initialization.
	board_init();
	at45dbx_init();
	if(at45dbx_mem_check()==true)	{
		gpio_set_pin_low(DATA_FLASH_LED_EXAMPLE_0);
	} else
	{
		test_ko();
	}

	// Prepare half a data flash sector to 0xAA
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		ram_buf[i]=0xAA;
	}
	// And the remaining half to 0x55
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=0x55;
	}

	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read back this sector and compare to expected values
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		if (ram_buf[i]!=0xAA) {
			test_ko();
		}
	}
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		if (ram_buf[i]!=0x55) {
			test_ko();
		}
	}

	// Write one data flash sector to 0x00, 0x01 ....
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=i;
	}
	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read one data flash sector to ram
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		if ( ram_buf[i]!=(i%0x100) ) {
			test_ko();
		}
	}

	gpio_set_pin_low(DATA_FLASH_LED_EXAMPLE_1);
	while (1);
}