Ejemplo n.º 1
0
/**
 * Test nvm_eeprom_erase_bytes_in_page() and
 * nvm_eeprom_erase_bytes_in_all_pages()
 *
 * Test procedure:
 * - Write two bytes into page TEST_ERASE_BYTES_PAGE_1 and
 *   TEST_ERASE_BYTES_PAGE_2
 * - Load value to page buffer in the address of the first byte
 * - Erase first byte of TEST_ERASE_BYTES_PAGE_1
 * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_1
 * - Load value to page buffer in the address of the first byte
 * - Erase first byte of all pages
 * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_2
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_erase_bytes(void)
{
	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	buffer[1] = 0xaf;

	/* Write two bytes into first page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 0, buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 1, buffer[1]);

	/* Write two bytes into second page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 0, buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 1, buffer[1]);

	/* Erase first byte of the first page */
	nvm_eeprom_load_byte_to_buffer(0, 0xff);
	nvm_eeprom_erase_bytes_in_page(TEST_ERASE_BYTES_PAGE_1);
	buffer[0] = EEPROM_ERASED;

	if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_1, buffer)) {
		/* Erase first byte of all pages */
		nvm_eeprom_load_byte_to_buffer(0, 0xff);
		nvm_eeprom_erase_bytes_in_all_pages();

		if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_2, buffer)) {
			return STATUS_OK;
		}
	}

	return ERR_BAD_DATA;
}
Ejemplo n.º 2
0
/**
 * \brief Test EEPROM read buffer
 *
 * This test erases test page \ref TEST_READ_BUFFER_PAGE then writes four bytes
 * to the test page and tries to read the entire page using
 * nvm_eeprom_read_buffer.
 * It then compares the read page with what's actually in the EEPROM page.
 *
 * \param test Current test case.
 */
static void run_eeprom_read_buffer_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	uint8_t buffer_read[EEPROM_PAGE_SIZE];
	bool    success;

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0x11;
	buffer[1] = 0xaa;
	buffer[2] = 0xee;
	buffer[3] = 0x22;

	// Erase page
	nvm_eeprom_erase_bytes_in_page(TEST_READ_BUFFER_PAGE);

	// Write 4 bytes into page:
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 0,
			buffer[0]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 1,
			buffer[1]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 2,
			buffer[2]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 3,
			buffer[3]);

	nvm_eeprom_read_buffer(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE,
			&buffer_read, EEPROM_PAGE_SIZE);

	// Check that what we have read is actually what's in EEPROM.
	success = is_eeprom_page_equal_to_buffer(TEST_READ_BUFFER_PAGE,
			buffer_read);

	test_assert_true(test, success, "Read buffer failed");
}
Ejemplo n.º 3
0
/**
 * \brief LCD interrupt callback function
 *
 * This function is called when an interrupt has occurred on LCD.
 */
void lcd_interrupt_callback(void)
{
	uint32_t buf_temp;

	// Change text string on LCD when a button is pressed
	if (ui_pusb_button_0()) {
		ui_display_text(lcd_msg_gain_cal, sizeof(lcd_msg_gain_cal));
		c42048a_clear_pixel(ICON_DEGREE_C);
		c42048a_clear_pixel(ICON_MILLI_VOLT);
		test_release_button_gain_cal = true;
	}

	//to limit EEPROM write operations, CAL stored when button released
	if((ui_pusb_button_0() == false)
			&& (test_release_button_gain_cal == true)) {
		buf_temp = (((uint32_t)ext_voltage - ext_offset_cal_val)
				*8000/4095);
		buf_temp = buf_temp * ADC_GAIN_EXT;
		buf_temp = buf_temp / ext_gain_cal_val;

		//store gain value in Flash memory
		if(((buf_temp > EXT_GAIN_MIN_VAL)
				&& (buf_temp < EXT_GAIN_MAX_VAL))){
			ext_gain_cal_val = buf_temp;
			nvm_eeprom_write_byte(ext_gain_cal_addr + 1
				, (uint8_t)(buf_temp>>8));
			nvm_eeprom_write_byte(ext_gain_cal_addr,
				(uint8_t)(buf_temp));
		}
Ejemplo n.º 4
0
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
		nvm_flash_erase_and_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_USERPAGE:
		nvm_user_sig_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_EEPROM:
		nvm_eeprom_write_byte((eeprom_addr_t)address, data);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open(address)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
/**
 * \brief This function will store the calculated calibration value in EEPROM
 *  - Erase all eeprom locations
 *  - Store the calculated calibration value in EEPROM
 */
void rtccalib_store_ppm_val(void)
{
	/* Erase all eeprom locations */
	nvm_eeprom_erase_all();

	/* Store the calculated calibration value in EEPROM at configured
	 * EEPROM address
	 */
	nvm_eeprom_write_byte(RTCCALIB_EEPROM_ADDR_TO_STORE,
			rtccalib_rtc_clk_calib_val);

	/* Store the status of RTC calibration in EEPROM at configured
	 * EEPROM address
	 * Success indicated as 0x01 and failure as 0x02
	 */
	nvm_eeprom_write_byte(RTCCALIB_STAT_EEPROM_ADDR,
			rtccalib_rtc_clk_calib_status);
}
Ejemplo n.º 6
0
/**
 * Test nvm_eeprom_erase_all().
 *
 * Test procedure:
 * - Write one byte to the TEST_ERASE_PAGE page.
 * - Erase all memory locations
 * - Verify that the EEPROM is erased by a spot test on the
 *   TEST_ERASE_PAGE page.
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_erase(void)
{
	nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);
	nvm_eeprom_erase_all();
	set_buffer(buffer, EEPROM_ERASED);

	if (is_eeprom_page_equal_to_buffer(TEST_ERASE_PAGE, buffer)) {
		return STATUS_OK;
	}

	return ERR_BAD_DATA;
}
Ejemplo n.º 7
0
/**
 * \brief Test EEPROM erase
 *
 * This test writes a single byte to test page \ref TEST_ERASE_PAGE, then erases
 * _all_ pages and checks that the test page contains only \ref EEPROM_ERASED.
 *
 * \param test Current test case.
 */
static void run_eeprom_erase_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);
	nvm_eeprom_erase_all();
	set_buffer(buffer, EEPROM_ERASED);

	success = is_eeprom_page_equal_to_buffer(TEST_ERASE_PAGE, buffer);
	test_assert_true(test, success, "Page was not erased");
}
Ejemplo n.º 8
0
/**
 * \brief  Copy a RAM buffer to a eeprom memory section
 *
 * \param dst    Pointer to flash destination.
 * \param src    Pointer to source data.
 * \param nbytes Number of bytes to transfer.
 */
static void mem_eeprom_write(isp_addr_t dst, const void *src, uint16_t nbytes)
{
#if (FLASH_SIZE==0x10000)
	// Optimize CODE space (150B), but decrease the speed
   	// 24s to program 2KB instead of 1s
	while (nbytes--) {
		nvm_eeprom_write_byte(dst++, *(uint8_t*)src);
		src = (uint8_t*)src + 1;
	}
#else
	nvm_eeprom_erase_and_write_buffer(dst, src, nbytes);
#endif
}
Ejemplo n.º 9
0
/**
 * \brief Test EEPROM write
 *
 * This test erases test page \ref TEST_WRITE_PAGE, then writes a single byte to
 * it and verifies that the write succeeded.
 *
 * \param test Current test case.
 */
static void run_eeprom_write_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	nvm_eeprom_erase_page(TEST_WRITE_PAGE);
	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	nvm_eeprom_write_byte(TEST_WRITE_PAGE * EEPROM_PAGE_SIZE, buffer[0]);

	success = is_eeprom_page_equal_to_buffer(TEST_WRITE_PAGE, buffer);
	test_assert_true(test, success, "Byte write failed");
}
Ejemplo n.º 10
0
void menu_main(void) {
    for(int i = 0; i < 4; i++) {
        CMD_buffer[i] = tolower(CMD_buffer[i]);
    }
    if (CMD_buffer[0] == 'v' && CMD_buffer[1] == 'x') {
        switch(CMD_buffer[2]) {
        case 'i': //information
            usb_tx_string_P(PSTR("Vehicle to Everything (V2X) RVI Node 2016\rOpen source hardware and software\rHW Rev1.2 \rSW Rev0.1\r"));
            break;
        case 'j': //Jaguar
            usb_tx_string_P(PSTR("\r\r   ,ggp@@@@mgg,,\r,$Q$(`S@@$;g$$$$$@$@@gg,\r;gP'$@gg)$$@@$@@@$(L$$||$$@g,\r  `g$P`  ``*%@@@P`)Eg|||lLLL||$Bgg,\r    `       ,gg$$@gg,`$..``$Z$$$$$EB$$@g,\r         @P`pgg$$$||`)gggg;,,     |$$$|$$$@g,\r         9w&    '*^^` ``*P#9BB00000$$$@|`$$$g|Sg,\r                                    *$@@L ```T$W~)%g,\r                                      *%@gg,,,,,    5/Sw,     ,\r                                          ```` ` `9g `9g,``*^|'\r                                                    `#g,`)h\r\r   Developed at Jaguar Land Rover OSCT. Portland OR 2016\r"));
            break;
        case 'q':
            menu_status();
            break;
        case 'r':  //reset
            reset_trigger_SYSTEM();
            break;
        case 'a':  //accel
            menu_accel();
            break;
        case 'c':  //CAN interface
            menu_can();
            break;
        case 'm':  //modem
            menu_modem();
            break;
        case 'p':  //power
            menu_power();
            break;
        case 't':  //timer functions
            menu_timer();
            break;
        case 'v': //toggle verbose setting
            verbose = !verbose;
            nvm_eeprom_write_byte(EE_verbose,verbose);
            usb_tx_string_PV(PSTR("Verbose is ON"));
            break;
        case '?':  //timer functions
        default:
            usb_tx_string_P(PSTR("*** Main Menu ***\rI: Device information\rA: Accelerometer menu(ACL)\rC: ELM327 menu(CAN)\rM: SIM Modem menu(GSM)\rP: Power menu\rT: Timer menu\rQ: Query system status\rV: Toggle verbose messages\rR: Reboot\r"));
            break;
        }
    } else {
        usb_tx_string_PV(PSTR("All commands start VX\r"));
    }
    clear_buffer(CMD_buffer);	//clear the buffer for next command
    menu_send_n_st();
}
Ejemplo n.º 11
0
/**
 * Test nvm_eeprom_erase_page() and nvm_eeprom_write_byte().
 *
 * Test procedure:
 * - Erase TEST_WRITE_PAGE
 * - Write one byte
 * - Verify that the byte is written and that all other bytes are erased.
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_write(void)
{
	// Test write
	nvm_eeprom_erase_page(TEST_WRITE_PAGE);

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	nvm_eeprom_write_byte(TEST_WRITE_PAGE*EEPROM_PAGE_SIZE, buffer[0]);

	if (is_eeprom_page_equal_to_buffer(TEST_WRITE_PAGE, buffer)) {
		return STATUS_OK;
	}

	return ERR_BAD_DATA;
}
Ejemplo n.º 12
0
/**
 * \brief Test EEPROM byte erase
 *
 * This test writes two bytes to test pages \ref TEST_ERASE_BYTES_PAGE_1 and
 * \ref TEST_ERASE_BYTES_PAGE_2, then tries to erase one of them in the first
 * page before verifying the erase, then in all pages before verifying that the
 * second page was also erased.
 *
 * \param test Current test case.
 */
static void run_eeprom_erase_byte_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	buffer[1] = 0xaf;

	/* Write two bytes into first page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 0,
			buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 1,
			buffer[1]);

	/* Write two bytes into second page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 0,
			buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 1,
			buffer[1]);

	/* Erase first byte of the first page */
	nvm_eeprom_load_byte_to_buffer(0, 0xff);
	nvm_eeprom_erase_bytes_in_page(TEST_ERASE_BYTES_PAGE_1);
	buffer[0] = EEPROM_ERASED;

	success = is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_1, buffer);
	test_assert_true(test, success, "Byte erase in single page failed");

	/* Erase first byte of all pages */
	nvm_eeprom_load_byte_to_buffer(0, 0xff);
	nvm_eeprom_erase_bytes_in_all_pages();

	success = is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_2, buffer);
	test_assert_true(test, success, "Byte erase in all pages failed");
}
Ejemplo n.º 13
0
/**
 * \brief Write buffer within the eeprom
 *
 * \param address   the address to where to write
 * \param buf       pointer to the data
 * \param len       the number of bytes to write
 */
void nvm_eeprom_erase_and_write_buffer(eeprom_addr_t address, const void *buf, uint16_t len)
{
	while (len) {
		if (((address%EEPROM_PAGE_SIZE)==0) && (len>=EEPROM_PAGE_SIZE)) {
			// A full page can be written
			nvm_eeprom_load_page_to_buffer((uint8_t*)buf);
			nvm_eeprom_atomic_write_page(address/EEPROM_PAGE_SIZE);
			address += EEPROM_PAGE_SIZE;
			buf = (uint8_t*)buf + EEPROM_PAGE_SIZE;
			len -= EEPROM_PAGE_SIZE;
		} else {
			nvm_eeprom_write_byte(address++, *(uint8_t*)buf);
			buf = (uint8_t*)buf + 1;
			len--;
		}
	}
}