status_code_t nvm_read(mem_type_t mem, uint32_t address, void *buffer, uint32_t len) { switch (mem) { case INT_FLASH: case INT_USERPAGE: memcpy(buffer, (const void *)address, len); break; #if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX) case AT45DBX: { uint32_t sector = address / AT45DBX_SECTOR_SIZE; if (!at45dbx_read_sector_open(sector)) { return ERR_BAD_ADDRESS; } at45dbx_read_sector_to_ram(buffer); at45dbx_read_close(); } break; #endif default: return ERR_INVALID_ARG; } return STATUS_OK; }
Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram) { if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)){ return CTRL_FAIL; } at45dbx_read_sector_open(addr); at45dbx_read_sector_to_ram(ram); at45dbx_read_close(); return CTRL_GOOD; }
/** * \brief Test the read and write multiple sector operations on the DataFlash * * This function will test the read and write functionalities of the DataFlash * using multiple sector access. It will first fill the 10 first DataFlash * sectors with a known pattern and read it back to test each value.\n * * \param test Current test case. */ static void run_multiple_sector_access_test(const struct test_case *test) { bool status; uint32_t i; uint8_t value, cur_sector; uint8_t expected; /* Write the ram sector to the DataFlash */ status = at45dbx_write_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for write access"); cur_sector = 0; while (cur_sector++ < 10) { /* Fills a ram sector with a known pattern */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { value = BYTE_PATTERN3(cur_sector * AT45DBX_SECTOR_SIZE + i); ((uint8_t *) sector_buf)[i] = value; } /* Write sector on DataFlash */ status = at45dbx_write_sector_from_ram(sector_buf); test_assert_true(test, status == true, "Error while writing sector # %i", cur_sector); } at45dbx_write_close(); /* Read back the sector of the DataFlash */ status = at45dbx_read_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for read access"); cur_sector = 0; while (cur_sector++ < 10) { // Read the next sector. status = at45dbx_read_sector_to_ram(sector_buf); test_assert_true(test, status == true, "Error while reading sector # %i", cur_sector); /* Test each values of the current sector */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { expected = BYTE_PATTERN3(cur_sector * AT45DBX_SECTOR_SIZE + i); test_assert_true(test, ((uint8_t *) sector_buf)[i] == expected, "Value not expected @ 0x%08x in sector # %i" " (read: 0x%02x, expected: 0x%02x)", i, cur_sector, ((uint8_t *) sector_buf)[i], expected); } } at45dbx_read_close(); }
Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector) { if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)){ return CTRL_FAIL; } at45dbx_read_sector_open(addr); while (nb_sector--) { // Read the next sector. at45dbx_read_sector_to_ram(sector_buf); udi_msc_trans_block( true, sector_buf, AT45DBX_SECTOR_SIZE, NULL); } at45dbx_read_close(); return CTRL_GOOD; }
status_code_t nvm_read(mem_type_t mem, uint32_t address, void *buffer, uint32_t len) { switch (mem) { case INT_FLASH: memcpy(buffer, (const void *)address, len); break; #if SAM4S case INT_USERPAGE: { /*! This function creates a buffer of IFLASH_PAGE_SIZE to * read the data from starting of user signature */ uint32_t temp_buff[IFLASH_PAGE_SIZE], *buff = buffer; /* Read from the starting of user signature */ if (flash_read_user_signature(temp_buff, len)) { return ERR_INVALID_ARG; } /* Calculate offset and copy required number of bytes */ for (uint16_t i = 0; i < len; i++) { *buff = temp_buff[address - IFLASH_ADDR + i]; buff++; } break; } #endif #if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX) case AT45DBX: { uint32_t sector = address / AT45DBX_SECTOR_SIZE; if (!at45dbx_read_sector_open(sector)) { return ERR_BAD_ADDRESS; } at45dbx_read_sector_to_ram(buffer); at45dbx_read_close(); } break; #endif default: return ERR_INVALID_ARG; } return STATUS_OK; }
/** * \brief Test the read and write sector operations on the DataFlash * * This function will test the read and write functionalities of the DataFlash * using sector access. It will first fill a sector with a known pattern and * read it back by testing each value read.\n * * \param test Current test case. */ static void run_sector_access_test(const struct test_case *test) { uint32_t i; bool status; /* Fills a ram sector with a known pattern */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { sector_buf[i] = BYTE_PATTERN2(i); } /* Write the ram sector to the DataFlash */ status = at45dbx_write_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for write access"); status = at45dbx_write_sector_from_ram(sector_buf); test_assert_true(test, status == true, "Write sector operation error"); at45dbx_write_close(); /* Clear the ram sector buffer */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { sector_buf[i] = 0; } /* Read back the sector of the DataFlash */ status = at45dbx_read_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for read access"); status = at45dbx_read_sector_to_ram(sector_buf); test_assert_true(test, status == true, "Read sector operation error"); at45dbx_read_close(); /* Compare the values read from the DataFlash with the expected values */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { test_assert_true(test, sector_buf[i] == BYTE_PATTERN2(i), "Value not expected @ 0x%08x (read: 0x%02x," " expected: 0x%02x)", i, sector_buf[i], BYTE_PATTERN2(i)); } }
void network_application() { draw_background(); gfx_draw_filled_rect(5, 26, 310, 182, GFX_COLOR(20, 20, 20)); if(!wifi_ready && wifi_error) { gfx_draw_string_aligned(SYMFONT_WIFI, gfx_get_width() / 2, 120, &symbol_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER); gfx_draw_string_aligned("Not Connected", gfx_get_width() / 2, 155, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER); } else { gfx_draw_string_aligned(SYMFONT_WIFI, gfx_get_width() / 2, 120, &symbol_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_GREEN, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER); gfx_draw_string_aligned("Connected", gfx_get_width() / 2, 155, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_GREEN, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER); } uint8_t ram_buf[AT45DBX_SECTOR_SIZE]; at45dbx_read_sector_open(0x0007); at45dbx_read_sector_to_ram(ram_buf); at45dbx_read_close(); char mac_string[128]; snprintf(mac_string, sizeof(mac_string), "MAC: %s", ram_buf); gfx_draw_string_aligned(mac_string, 11, 27, &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); if (wifi_error) { gfx_draw_string_aligned(esp_error, 11, 47, &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); } struct keyboard_event input; while(mma8451_orientation() != 6) { esp8266_check_buffer(); keyboard_get_key_state(&input); if (input.type == KEYBOARD_RELEASE) { if (input.keycode == KEYBOARD_B) { break; } } if(mma8451_clear_interrupt() && is_low_power()) { exit_low_power(); } } }
status_code_t nvm_read(mem_type_t mem, uint32_t address, void *buffer, uint32_t len) { switch (mem) { case INT_FLASH: nvm_flash_read_buffer((flash_addr_t)address, buffer, (uint16_t)len); break; case INT_USERPAGE: nvm_user_sig_read_buffer((flash_addr_t)address, buffer, (uint16_t)len); break; case INT_EEPROM: nvm_eeprom_read_buffer((eeprom_addr_t)address, buffer, (uint16_t)len); break; #if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX) case AT45DBX: { uint32_t sector = address / AT45DBX_SECTOR_SIZE; if (!at45dbx_read_sector_open(sector)) { return ERR_BAD_ADDRESS; } at45dbx_read_sector_to_ram(buffer); at45dbx_read_close(); } break; #endif default: return ERR_INVALID_ARG; } return STATUS_OK; }
/*! \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); }
void draw_event() { draw_background(); draw_time(); gfx_draw_filled_rect(5, 26, 310, 182, GFX_COLOR(8, 8, 8)); draw_button_hints(); switch(event_track) { case 0: gfx_draw_string_aligned("Schedule - KEYNOTES", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; case 1: gfx_draw_string_aligned("Schedule - TRACK 1", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; case 2: gfx_draw_string_aligned("Schedule - TRACK 2", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; case 3: gfx_draw_string_aligned("Schedule - TRACK 3", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; case 4: gfx_draw_string_aligned("Schedule - TRACK 4", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; case 5: gfx_draw_string_aligned("Schedule - TRACK 5", 11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); break; } uint16_t keynote = 0x0100; uint16_t track1 = 0x0200; uint16_t track2 = 0x0300; uint16_t track3 = 0x0400; uint16_t track4 = 0x0500; uint16_t track5 = 0x0600; uint16_t addresses[] = {keynote, track1, track2, track3, track4, track5}; //uint16_t max_event[] = {5, 22, 22, 15, 23}; uint8_t ram_buf[AT45DBX_SECTOR_SIZE]; at45dbx_read_sector_open(addresses[event_track] + event_index); at45dbx_read_sector_to_ram(ram_buf); at45dbx_read_close(); char *array[6]; uint8_t i = 0; array[i] = strtok(ram_buf,";"); while(array[i] != NULL) { array[++i] = strtok(NULL, ";"); } char *title[256]; uint8_t a = word_wrap(&title, array[0], 30); gfx_draw_string_aligned(title, 11, 27, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); char event_time[36]; snprintf(event_time, sizeof(event_time),"%s - %s", array[1], array[2]); char *names[256]; uint8_t n = word_wrap(&names, array[3], 33); gfx_draw_string_aligned(names, 11, 60+(a*20), &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); gfx_draw_string_aligned(array[4], 11, 85+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); gfx_draw_string_aligned(event_time, 11, 100+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT); // } }
/*! \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); }