Example #1
0
void CLOCK_Update(void) {
  static int prevHour=-1, prevMinute=-1, prevSecond=1;
  TIMEREC time;
  uint8_t res;

  res = TmDt1_GetTime(&time);
  if (res==ERR_OK) {
    if (time.Hour!=prevHour || time.Min!=prevMinute || time.Sec!=prevSecond) {
      CLOCK_SetTime(time.Hour, time.Min, time.Sec);
      (void)NEO_TransferPixels();
      prevHour = time.Hour;
      prevMinute = time.Min;
      prevSecond = time.Sec;
    }
  }
}
Example #2
0
static void LogToFile(int16_t x, int16_t y, int16_t z) {
  uint8_t write_buf[48];
  UINT bw;
  TIMEREC time;

  /* open file */
  if (FAT1_open(&fp, "./log.txt", FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) {
    Err();
  }
  /* move to the end of the file */
  if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) {
    Err();
  }
  /* get time */
  if (TmDt1_GetTime(&time)!=ERR_OK) {
    Err();
  }
  /* write data */
  write_buf[0] = '\0';
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Hour);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Min);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Sec);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), x);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), y);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), z);
  UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\r\n");
  if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) {
    (void)FAT1_close(&fp);
    Err();
  }
  /* closing file */
  (void)FAT1_close(&fp);
}
Example #3
0
/*
** ===================================================================
**     Method      :  FAT1_get_fattime (component FAT_FileSystem)
**     Description :
**         Returns the current time
**     Parameters  : None
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
uint32_t FAT1_get_fattime(void)
{
  /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
  /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
  /* Pack date and time into a uint32_t variable */
  TIMEREC time;
  DATEREC date;
  uint8_t res;

  res = TmDt1_GetTime(&time);           /* get time information */
  if (res!=ERR_OK) {
    return 0; /* failed */
  }
  res = TmDt1_GetDate(&date);           /* get date information */
  if (res!=ERR_OK) {
    return 0; /* failed */
  }
  return ((uint32_t)(date.Year - 1980) << 25)
       | ((uint32_t)date.Month << 21)
       | ((uint32_t)date.Day << 16)
       | ((uint32_t)time.Hour << 11)
       | ((uint32_t)time.Min << 5)
       | ((uint32_t)time.Sec);
}
Example #4
0
/*! \brief Simple benchmark function: first we are going to write a file, then we will copy it */
static void benchmark(const CLS1_StdIOType *io) {
  static FIL fp;
  uint16_t i;
  UINT bw;
  uint8_t read_buf[10];
  TIMEREC time, startTime;
  int32_t start_mseconds, mseconds;

  /* write benchmark */
  CLS1_SendStr((const unsigned char*)"Benchmark: open file, write 10k times 10 bytes (100'000 bytes), close file:\r\n", io->stdOut);
  CLS1_SendStr((const unsigned char*)"Deleting any existing files...\r\n", io->stdOut);
  (void)FAT1_DeleteFile((const unsigned char*)"./bench.txt", io);
  (void)FAT1_DeleteFile((const unsigned char*)"./copy.txt", io);

  CLS1_SendStr((const unsigned char*)"Creating benchmark file...\r\n", io->stdOut);
  (void)TmDt1_GetTime(&startTime);
  if (FAT1_open(&fp, "./bench.txt", FA_CREATE_ALWAYS|FA_WRITE)!=FR_OK) {
    CLS1_SendStr((const unsigned char*)"*** Failed opening benchmark file!\r\n", io->stdErr);
    return;
  }
  for(i=0;i<10000;i++) {
    if (FAT1_write(&fp, "benchmark ", sizeof("benchmark ")-1, &bw)!=FR_OK) {
      CLS1_SendStr((const unsigned char*)"*** Failed writing file!\r\n", io->stdErr);
      (void)FAT1_close(&fp);
      return;
    }
  }
  (void)FAT1_close(&fp);
  (void)TmDt1_GetTime(&time);
  start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
  mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
  CLS1_SendNum32s(mseconds, io->stdOut);
  CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut);

  /* read benchmark */
  CLS1_SendStr((const unsigned char*)"Reading benchmark file...\r\n", io->stdOut);
  (void)TmDt1_GetTime(&startTime);
  if (FAT1_open(&fp, "./bench.txt", FA_READ)!=FR_OK) {
    CLS1_SendStr((const unsigned char*)"*** Failed opening benchmark file!\r\n", io->stdErr);
    return;
  }
  for(i=0;i<10000;i++) {
    if (FAT1_read(&fp, &read_buf[0], sizeof(read_buf), &bw)!=FR_OK) {
      CLS1_SendStr((const unsigned char*)"*** Failed reading file!\r\n", io->stdErr);
      (void)FAT1_close(&fp);
      return;
    }
  }
  (void)FAT1_close(&fp);
  (void)TmDt1_GetTime(&time);
  start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
  mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
  CLS1_SendNum32s(mseconds, io->stdOut);
  CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut);

  /* copy benchmark */
  CLS1_SendStr((const unsigned char*)"Benchmark: copy file (100'000 bytes):\r\n", io->stdOut);
  CLS1_SendStr((const unsigned char*)"Going to copy file...\r\n", io->stdOut);
  (void)TmDt1_GetTime(&startTime);
  (void)FAT1_CopyFile((const unsigned char*)"./bench.txt", (const unsigned char*)"./copy.txt", io);
  (void)TmDt1_GetTime(&time);
  start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
  mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
  CLS1_SendNum32s(mseconds, io->stdOut);
  CLS1_SendStr((const unsigned char*)" mseconds needed for command.\r\n", io->stdOut);
  CLS1_SendStr((const unsigned char*)"done!\r\n", io->stdOut);
}
Example #5
0
static byte UFFS_Benchmark(const unsigned char *cmd, const CLS1_ConstStdIOType *io)
{
	uint16_t i, j;
	uint8_t read_buf[10];
	TIMEREC time, startTime;
	int32_t start_mseconds, mseconds;

	int fd, fd2;

	/* write benchmark */
	MSGLN("Benchmark: open file, write 10k times 10 bytes (100'000 bytes), close file:");
	MSGLN("Deleting existing benchmark files...");
	uffs_remove("/bench.txt");
	uffs_remove("/copy.txt");

	MSGLN("Creating benchmark file...");
	(void)TmDt1_GetTime(&startTime);
	fd = uffs_open("/bench.txt", UO_CREATE|UO_WRONLY);
	if (fd  < 0) {
		MSGLN("*** Failed opening benchmark file!");
		return ERR_FAILED;
	}
	for(i=0;i<10000;i++) {
		if (uffs_write(fd, "benchmark ", sizeof("benchmark ")-1) <= 0) {
			MSGLN("*** Failed writing file!");
			uffs_close(fd);
			return ERR_FAILED;
		}
	}
	uffs_close(fd);
	(void)TmDt1_GetTime(&time);
	start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
	mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
	MSGLN("%ld ms needed for creating.",mseconds);

	/* read benchmark */
	MSGLN("Reading benchmark file...");
	(void)TmDt1_GetTime(&startTime);
	fd = uffs_open("/bench.txt", UO_RDONLY);
	if (fd < 0) {
		MSGLN("*** Failed opening benchmark file!");
		return ERR_FAILED;
	}
	for(i=0;i<10000;i++) {
		if (uffs_read(fd, read_buf, sizeof(read_buf)) <= 0) {
			MSGLN("*** Failed reading file!");
			uffs_close(fd);
			return ERR_FAILED;
		}
	}
	uffs_close(fd);
	(void)TmDt1_GetTime(&time);
	start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
	mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
	MSGLN("%ld ms needed for reading.",mseconds);

	/* copy benchmark */
	MSGLN("Copy file (100'000 bytes)...");
	(void)TmDt1_GetTime(&startTime);
	
	fd2 = uffs_open("/copy.txt", UO_CREATE|UO_WRONLY);
	if (fd2  < 0) {
		MSGLN("*** Failed opening copy file!");
		return ERR_FAILED;
	}
	fd = uffs_open("/bench.txt", UO_RDONLY);
	if (fd < 0) {
		MSGLN("*** Failed opening benchmark file!");
		return ERR_FAILED;
	}
	i = 0;
	do
	{
		j = uffs_read(fd, read_buf, sizeof(read_buf));
		i += j;
		if (uffs_write(fd2, read_buf, j) < j) {
			MSGLN("*** Failed writing file!");
			uffs_close(fd);
			uffs_close(fd2);
			return ERR_FAILED;
		}
	} while( j > 0);
	uffs_close(fd);
	uffs_close(fd2);
	
	(void)TmDt1_GetTime(&time);
	start_mseconds = startTime.Hour*60*60*1000 + startTime.Min*60*1000 + startTime.Sec*1000 + startTime.Sec100*10;
	mseconds = time.Hour*60*60*1000 + time.Min*60*1000 + time.Sec*1000 + time.Sec100*10 - start_mseconds;
	MSGLN("%ld ms needed for copy.",mseconds);
	
	return ERR_OK;
}