示例#1
0
/**
 * Fills eeprom area with pattern, than read it back and compare
 */
static void __block_api_write(uint8_t pattern, uint32_t len, uint8_t misaligment){
  uint32_t i = 0;
  uint32_t status = 0;
  uint32_t pos = 0;

  /* fill buffer with pattern */
  for (i = 0; i < len; i++)
    referencebuf[i] = pattern;

  /* move to begin of test area */
  chFileStreamSeek(&EfsTest, TestAreaStart + misaligment);
  pos = chFileStreamGetPosition(&EfsTest);
  if (pos != TestAreaStart + misaligment)
    chDbgPanic("file seek error");

  /* write */
  status = chFileStreamWrite(&EfsTest, referencebuf, len);
  if (status < len)
    chDbgPanic("write failed");

  /* check */
  pos = chFileStreamGetPosition(&EfsTest);
  if (pos != len + TestAreaStart + misaligment)
    chDbgPanic("file seek error");
  chFileStreamSeek(&EfsTest, pos - len);
  status = chFileStreamRead(&EfsTest, checkbuf, len);
  if (status < len)
    chDbgPanic("veryfication failed");
  if (memcmp(referencebuf, checkbuf, len) != 0)
    chDbgPanic("veryfication failed");
}
示例#2
0
/**
 * Fills eeprom area with pattern, than read it back and compare
 */
static void pattern_fill(EepromFileStream *EfsTest, uint8_t pattern){
  uint32_t i = 0;
  uint32_t status = 0;
  uint32_t pos = 0;
  uint32_t len = chFileStreamGetSize(EfsTest);

  /* fill buffer with pattern */
  for (i = 0; i < len; i++)
    referencebuf[i] = pattern;

  /* move to begin of test area */
  pos = 0;
  chFileStreamSeek(EfsTest, pos);
  if (pos != chFileStreamGetPosition(EfsTest))
    chDbgPanic("file seek error");

  /* write */
  status = chFileStreamWrite(EfsTest, referencebuf, len);
  if (status != len)
    chDbgPanic("write failed");

  /* check */
  pos = chFileStreamGetPosition(EfsTest);
  if (pos != len)
    chDbgPanic("writing error");

  pos = 0;
  chFileStreamSeek(EfsTest, pos);
  status = chFileStreamRead(EfsTest, checkbuf, len);
  if (status != len)
    chDbgPanic("reading back failed");
  if (memcmp(referencebuf, checkbuf, len) != 0)
    chDbgPanic("veryfication failed");
}
示例#3
0
static void test_wtapper_write_byte(uint8_t pattern, uint32_t pos){
  uint8_t u8result;
  uint8_t u8 = pattern;

  chFileStreamSeek(&EfsTest, pos);
  if (EepromWriteByte(&EfsTest, u8) != sizeof(u8))
    chDbgPanic("write failed");
  chFileStreamSeek(&EfsTest, chFileStreamGetPosition(&EfsTest) - sizeof(u8));
  u8result = EepromReadByte(&EfsTest);
  if (u8 != u8result)
    chDbgPanic("veryfication failed");
}
示例#4
0
static void test_wtapper_write_word(uint8_t pattern, uint32_t pos){
  uint32_t u32result;
  uint32_t u32 = 0;
  u32 |= pattern << 24 | pattern << 16 | pattern << 8 | pattern;

  chFileStreamSeek(&EfsTest, pos);
  if (EepromWriteWord(&EfsTest, u32) != sizeof(u32))
    chDbgPanic("write failed");
  chFileStreamSeek(&EfsTest, chFileStreamGetPosition(&EfsTest) - sizeof(u32));
  u32result = EepromReadWord(&EfsTest);
  if (u32 != u32result)
    chDbgPanic("veryfication failed");
}
示例#5
0
static void test_wtapper_write_halfword(uint8_t pattern, uint32_t pos){
  uint16_t u16result;
  uint16_t u16 = 0;
  u16 |= pattern << 8 | pattern;

  chFileStreamSeek(&EfsTest, pos);
  if (EepromWriteHalfword(&EfsTest, u16) != sizeof(u16))
    chDbgPanic("write failed");
  chFileStreamSeek(&EfsTest, chFileStreamGetPosition(&EfsTest) - sizeof(u16));
  u16result = EepromReadHalfword(&EfsTest);
  if (u16 != u16result)
    chDbgPanic("veryfication failed");
}
示例#6
0
void eeprom_testsuit(void){
  int8_t i = 0;
  int8_t j = 0;
  int32_t n = 0;

  /* backup data from test area */
  chFileStreamSeek(&EfsTest, TestAreaStart);
  if (chFileStreamRead(&EfsTest, backupbuf, TEST_AREA_SIZE) < TEST_AREA_SIZE)
    chDbgPanic("backuping failed");

  /* first check the whole test area */
  test_api_all(TEST_AREA_SIZE, 0);

  for (i = -2; i < 3; i++){
    for (j = 0; j < 3; j++){
      /* large block tests */
      n = EEPROM_PAGE_SIZE;
      while (n < (TEST_AREA_SIZE - 3 * EEPROM_PAGE_SIZE)){
        test_api_all(n + i,  j);
        test_api_all(n + i,  EEPROM_PAGE_SIZE - 1 - j);
        n *= EEPROM_PAGE_SIZE;
      }
      /* small block tests */
      for (n = 2; n < 7; n++){
        test_api_all(n + i,     j);
        test_api_all(n + i,     EEPROM_PAGE_SIZE - 1 - j);
        test_api_all(n*10 + i,  j);
        test_api_all(n*10 + i,  EEPROM_PAGE_SIZE - 1 - j);
      }
    }
  }

  /* wrapper fucntions test */
  test_wrapper_write_all_patterns(TestAreaStart);
  test_wrapper_write_all_patterns(TestAreaStart + 1);
  for (i = -4; i < 5; i++)
    test_wrapper_write_all_patterns(TestAreaStart + EEPROM_PAGE_SIZE + i);
  test_wrapper_write_all_patterns(TestAreaFinish - 5);

  /* personally check end of test area */
  test_wtapper_write_byte    (0x55, TestAreaFinish - 1);
  test_wtapper_write_halfword(0xAA, TestAreaFinish - 2);
  test_wtapper_write_word    (0xA5, TestAreaFinish - 4);

  /* roll back data from backup */
  chFileStreamSeek(&EfsTest, TestAreaStart);
  if (chFileStreamWrite(&EfsTest, backupbuf, TEST_AREA_SIZE) < TEST_AREA_SIZE)
    chDbgPanic("rolling back failed");
}
示例#7
0
	static void ImageBaseFileStreamSeek(struct gdispImageIO *pio, size_t pos) {
		if (pio->fd == (void *)-1) return;
		if (pio->pos != pos) {
			chFileStreamSeek(((BaseFileStream *)pio->fd), pos);
			pio->pos = pos;
		}
	}
示例#8
0
void __burn(BaseSequentialStream *chp, uint8_t pattern){
  volatile uint32_t status = 0;
  uint32_t eeprom_cycle;

  eeprom_cycle = BKP->DR1;
  eeprom_cycle = eeprom_cycle << 16;
  eeprom_cycle += BKP->DR2;

  if (BKP->DR3 == 1){
    //chprintf(chp, "EEPROM exhausted at %u try\n", eeprom_cycle);
    return;
  }

  /* fill memory buffer and write it to eeprom */
  memset(databuf, pattern, sizeof(databuf));
  chFileStreamSeek(&EepromFile, 0);
  status = chFileStreamWrite(&EepromFile, databuf, EEPROM_SIZE);
  if (status != sizeof(databuf))
    chDbgPanic("");

  /* read eeprom to test buffer */
  chFileStreamSeek(&EepromFile, 0);
  chFileStreamRead(&EepromFile, testbuf, EEPROM_SIZE);
  if (status != sizeof(databuf))
    chDbgPanic("");

  /* compare 2 buffers. Non zero value denotes bad sector in eeprom */
  status = memcmp(databuf, testbuf, EEPROM_SIZE);
  if (status != 0){
    BKP->DR3 = 1; /* bad sector(s) appeared */
    return;
  }

  /* Print note to console and increment cycle counter */
  //chprintf(chp, "EEPROM burn %u \n", eeprom_cycle);
  eeprom_cycle++;
  BKP->DR2 = eeprom_cycle & 0xFFFF;
  BKP->DR1 = (eeprom_cycle >> 16) & 0xFFFF;

  palTogglePad(IOPORT3, GPIOC_LED);
}
示例#9
0
msg_t EepromTestThread(void *sdp){
  chRegSetThreadName("EepromTst");

  cli_println("basic tests");
  cli_println("--------------------------------------------------------------");
  cli_print("mount aligned file sized to whole test area");
  ocfg.barrier_low  = TEST_AREA_START;
  ocfg.barrier_hi   = TEST_AREA_END;
  EepromFileOpen(&ofile, &ocfg);
  OK();
  printfileinfo(sdp, &ofile);
  cli_print("test fill with 0xFF");
  pattern_fill(&ofile, 0xFF);
  if (chThdShouldTerminate()){goto END;}
  OK();
  cli_print("test fill with 0xAA");
  pattern_fill(&ofile, 0xAA);
  if (chThdShouldTerminate()){goto END;}
  OK();
  cli_print("test fill with 0x55");
  pattern_fill(&ofile, 0x55);
  if (chThdShouldTerminate()){goto END;}
  OK();
  cli_print("test fill with 0x00");
  pattern_fill(&ofile, 0x00);
  if (chThdShouldTerminate()){goto END;}
  OK();
  cli_print("Closing file");
  chFileStreamClose(&ofile);
  OK();


  uint32_t b1, b2, b3, b4, istart, ilen;
  uint8_t pattern = 0x55;
  b1 = TEST_AREA_START;
  b2 = TEST_AREA_START + EEPROM_PAGE_SIZE;
  b3 = TEST_AREA_END - EEPROM_PAGE_SIZE;
  b4 = TEST_AREA_END;
  istart = 0;
  ilen = b3-b2;

  cli_println("    Linear barriers testing.");
  chThdSleepMilliseconds(20);
  overflow_check( b1, b2, b3, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2, b3, b4, istart + 1, ilen - 1, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2, b3, b4, istart + 1, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2, b3, b4, istart + 1, ilen + 23, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b3 + 1, b4, istart, ilen, pattern,  FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 2, b3 + 2, b4, istart + 2, ilen, pattern,  FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b3 + 1, b4, istart + 1, ilen + 23, pattern,  FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 2, b3 + 2, b4, istart + 1, ilen + 23, pattern,  FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 + 2, b3 - 3, b4, istart + 2, ilen, pattern, FALSE,  sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;


  overflow_check( b1, b2, b2 + 1, b4, istart, ilen, pattern,  FALSE,  sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2, b2 + 3, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;


  overflow_check( b1, b2 + 1, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 + 1, b2 + 3, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 + 1, b2 + 4, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;

  overflow_check( b1, b2 - 1, b2,     b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b2 + 1, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b2 + 2, b4, istart, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;

  overflow_check( b1, b2 - 1, b2 + 1, b4, istart + 1, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b2 + 2, b4, istart + 1, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;
  overflow_check( b1, b2 - 1, b2 + 3, b4, istart + 1, ilen, pattern, FALSE, sdp);
  if (chThdShouldTerminate()){goto END;}
  pattern++;

  cli_println("    Basic API testing.");
  chThdSleepMilliseconds(20);

  ocfg.barrier_low  = TEST_AREA_START;
  ocfg.barrier_hi   = TEST_AREA_END;
  EepromFileOpen(&ofile, &ocfg);
  chFileStreamSeek(&ofile, 0);
  EepromWriteByte(&ofile, 0x11);
  EepromWriteHalfword(&ofile, 0x2222);
  EepromWriteWord(&ofile, 0x33333333);
  chFileStreamSeek(&ofile, 0);
  if(EepromReadByte(&ofile) != 0x11)
    chDbgPanic("");
  if(EepromReadHalfword(&ofile) != 0x2222)
    chDbgPanic("");
  if(EepromReadWord(&ofile) != 0x33333333)
    chDbgPanic("");
  chFileStreamClose(&ofile);
  OK();

  cli_println("All tests passed successfully.");
END:
  chThdExit(0);
  return 0;
}
示例#10
0
/**
 * Create overlapped files like this:
 *
 *       |<--------- outer file ------------>|
 *       |                                   |
 * ======b1==b2========================b3===b4======
 * |         |                          |          |
 * |         |<------ inner file ------>|          |
 * |<----------------- EEPROM -------------------->|
 */
static void overflow_check(uint32_t b1, uint32_t b2, uint32_t b3, uint32_t b4,
                          uint32_t istart, uint32_t ilen,
                          uint8_t pattern, bool_t pat_autoinc,
                          BaseSequentialStream *sdp){
  uint32_t status, i, n;

  chDbgCheck(ilen < (b4-b1),"sequences more than length of outer file can not be verified");

  chprintf(sdp, "b1=%u, b2=%u, b3=%u, b4=%u, istart=%u, ilen=%u, ",
            b1, b2, b3, b4, istart, ilen);
  cli_print("autoinc=");
  if (pat_autoinc)    cli_print("TRUE");
  else                cli_print("FALSE");
  chThdSleepMilliseconds(50);

  /* open outer file and clear it */
  ocfg.barrier_low  = b1;
  ocfg.barrier_hi   = b4;
  EepromFileOpen(&ofile, &ocfg);
  pattern_fill(&ofile, 0x00);

  /* open inner file */
  icfg.barrier_low  = b2;
  icfg.barrier_hi   = b3;
  EepromFileOpen(&ifile, &icfg);

  /* reference buffer */
  memset(referencebuf, 0x00, b4-b1);
  n = b2 - b1 + istart;
  if ((ilen + istart) > (b3-b2))
    i = b3 - b2 - istart;
  else
    i = ilen;
  while (i > 0){
    referencebuf[n] = pattern;
    n++;
    i--;
    if (pat_autoinc)
      pattern++;
    }

  /* check buffer */
  n = 0;
  while (n < ilen){
    checkbuf[n] = pattern;
    n++;
    if (pat_autoinc)
      pattern++;
  }

  /* now write check buffer content into inner file */
  chThdSleepMilliseconds(20);
  chFileStreamSeek(&ifile, istart);
  status = chFileStreamWrite(&ifile, checkbuf, ilen);

  if ((istart + ilen) > (b3 - b2)){ /* data must be clamped */
    if (status != (b3 - b2 - istart))
      chDbgPanic("not all data written or overflow ocrred");
  }
  else{/* data fitted in file */
    if (status != ilen)
      chDbgPanic("not all data written or overflow ocrred");
  }

  /* read outer file and compare content with reference buffer */
  memset(checkbuf, 0x00, b4-b1);
  chFileStreamSeek(&ofile, 0);
  status = chFileStreamRead(&ofile, checkbuf, b4-b1);
  if (status != (b4-b1))
    chDbgPanic("reading back failed");
  if (memcmp(referencebuf, checkbuf, b4-b1) != 0)
    chDbgPanic("veryfication failed");

  chFileStreamClose(&ofile);
  chFileStreamClose(&ifile);
  OK();
}