Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 读取大文件会导致看门狗计时器超时_C_File_Fread_Watchdog_Lpc - Fatal编程技术网

C 读取大文件会导致看门狗计时器超时

C 读取大文件会导致看门狗计时器超时,c,file,fread,watchdog,lpc,C,File,Fread,Watchdog,Lpc,我已经为LPC板创建了固件程序。看门狗定时器的超时时间为2秒。我有一个jpg文件,我想使用freed()函数读取该文件并将其存储在缓冲区中。读取过程非常耗时,因此在执行文件读取时板会重置 void func() { int num, NumBytes; static uint8_t acBuffer[0x1000]; FILE *file ; // file contains large data watchdog_reseter(); num = fread(acBuffer,

我已经为LPC板创建了固件程序。看门狗定时器的超时时间为2秒。我有一个jpg文件,我想使用freed()函数读取该文件并将其存储在缓冲区中。读取过程非常耗时,因此在执行文件读取时板会重置

void func() {
 int num, NumBytes;
 static uint8_t acBuffer[0x1000];
 FILE *file ;
 // file contains large data 
 watchdog_reseter();
 num = fread(acBuffer, 1, NumBytes, file); // time-out elapses
 watchdog_reseter();
}
所以我想将文件int拆分为2或3个文件:

void func()
{
  int num, num1, num2, k;
  static uint8_t acBuffer[0x1000], buff[0x1000], buff2[0x1000];
  FILE *file, *file1, *file2 ; 
  /* task 1: file splits to file 1 and file2 */ 
  watchdog_reseter();
  num1 = fread(buff, 1, NumBytes/2, file1); // program resets
  watchdog_reseter();
  num2 = fread(buff2, 1, NumBytes/2, file2); // program resets
  watchdog_reseter(); 
  for(k=0; k<num1+num2, k++)
  {
    if(k<num1)
      acBuffer[k] = buff[k];
    else
      acBuffer[k] = buff2[k-num1];
  } 
}
void func()
{
int num,num1,num2,k;
静态uint8_t acBuffer[0x1000]、buff[0x1000]、buff2[0x1000];
文件*FILE、*file1、*file2;
/*任务1:文件拆分为文件1和文件2*/
看门狗复位器();
num1=fread(buff,1,NumBytes/2,file1);//程序重置
看门狗复位器();
num2=fread(buff2,1,NumBytes/2,file2);//程序重置
看门狗复位器();

对于(k=0;kYou可以将数据以较小的块读取到缓冲区中,直到您拥有所有数据为止,这样您可以更频繁地踢狗。您可以将数据读取到一个缓冲区中,每次读取都会推进缓冲区位置(按读取的字节数)…但是,如果您必须在阻塞函数中等待输入,即使是一个小的数据请求也可能使您失败,更好的策略是在喂狗的同时询问输入,直到有数据可用,然后读取尽可能多的准备好的数据。看门狗通常由另一个程序提供服务。您所在的环境中是否有线程正在为?编写代码?或至少使用中断源,如计时器。@0andriy在中断下为看门狗计时器提供服务是一个非常糟糕的主意。@WeatherVane,这取决于实际情况。如果您有嵌入式单处理器系统,您唯一的选择就是使用其中一个中断来间接(意味着调度)服务看门狗或将您的状态机拆分为保证较小的部分。例如,所有操作系统功能都可以被信号中断(它们都意味着定期检查事件),而计时器中断处理程序只发送(设置位)该信号。您有其他想法吗?