static void DiskTest(void) {
  CLS1_ConstStdIOTypePtr io;

  io = CLS1_GetStdio();
  FAT1_Init();
  CLS1_SendStr((unsigned char*)"Waiting for disk to be inserted...\r\n", io->stdOut);
  while(!FAT1_isDiskPresent()) {
    /* wait until card is present */
  }
  CLS1_SendStr((unsigned char*)"Mounting File system...\r\n", io->stdOut);
  FAT1_mount(0, &fileSystemObject); /* mount file system */
  (void)Test(io);
  CLS1_SendStr((unsigned char*)"Finished test...\r\n", io->stdOut);
  for(;;) {
    LED2_Neg();
    WAIT1_Waitms(100);
  }
}
static void Test(void) {
  UINT bw; /* number of bytes written */

  if (FAT1_isDiskPresent()) { /* if no hardware CardDetect pin is assigned, it will always return TRUE */
    LEDR_On(); /* turn red RGB LED on */
    FAT1_mount(0, &fs); /* mount file system */
    if (!FAT1_isWriteProtected()) { /* if no hardware WritePtotect pin is assigned, it will always return FALSE */
      LEDG_On(); /* turn green RGB LED on */
      if (FAT1_open(&fp, "./test.txt", FA_CREATE_ALWAYS|FA_WRITE)!=FR_OK) { /* open file, will always create it if not already on disk */
        for(;;){} /* error! */
      }
      if (FAT1_write(&fp, "Hello World!", sizeof("Hello World!")-1, &bw)!=FR_OK) { /* write string to file */
        for(;;){} /* error! */
      }
    }
    (void)FAT1_close(&fp); /* close file */
    FAT1_mount(0, NULL); /* unmount file system */
  }
}
Exemple #3
0
static void DiskTest(void) {
  CLS1_ConstStdIOTypePtr io;

  io = CLS1_GetStdio();
  if (FAT1_Init()!=ERR_OK) {
    CLS1_SendStr((unsigned char*)"Failed FatFS initialization!\r\n", io->stdErr);
    return;
  }
  CLS1_SendStr((unsigned char*)"Waiting for disk to be inserted...\r\n", io->stdOut);
  while(!FAT1_isDiskPresent((uint8_t*)"0")) {
    /* wait until card is present */
  }
  CLS1_SendStr((unsigned char*)"Mounting File system...\r\n", io->stdOut);
  if (FAT1_mount(&fileSystemObject, (const TCHAR*)"0", 1) != FR_OK) { /* mount file system */
    CLS1_SendStr((unsigned char*)"Failed FatFS initialization!\r\n", io->stdErr);
    return;
  }
  (void)Test(io);
  CLS1_SendStr((unsigned char*)"Finished test...\r\n", io->stdOut);
}