📄 hpi.lst
字号:
243 1 bSuccess=1;
244 1 CHRspBlock.len=0;
245 1 //lba=GetSecNumFromPointer();
246 1 //cluster=GetClusterNumFromSectorNum(lba);
247 1 //cluster=ThisFile.StartCluster;
248 1 //lba=FirstSectorofCluster(ThisFile.StartCluster);
249 1 //readLength=SwapINT16(CHCmdBlock.CmdBlock.Cmd_ReadFile.readLength);
250 1 if(readLength>MAX_READ_LENGTH)
251 1 {
252 2 CHRspBlock.errcode=ERC_LENGTHEXCEED;
253 2 return FALSE;
254 2 }
255 1 if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
256 1 {
257 2 CHRspBlock.errcode=ERC_LENGTHEXCEED;
258 2 return FALSE;
259 2 }
260 1 ////////////////////////////////////////////
261 1
262 1 ///////////////////////////////////////////////////
263 1 while(readLength>0)
264 1 {
265 2 if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
266 2 len=DeviceInfo.BPB_BytesPerSec;
267 2 else
268 2 len=readLength+ThisFile.OffsetofSector;
269 2
270 2 //////////////////////////////////////////////////////
271 2 if(ThisFile.OffsetofSector>0)
272 2 {
273 3 if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
274 3 {
275 4 //ThisFile.OffsetofSector=len;
276 4 len=len-ThisFile.OffsetofSector;
277 4 for(i=0;i<len;i++)
278 4 //CHBUF[i]=DBUF[ThisFile.OffsetofSector+i];
279 4 *(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
280 4 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
281 4 }
282 3 else
283 3 {
284 4 CHRspBlock.errcode=ERC_DEVICEERR;
285 4 return FALSE;
286 4 }
287 3 }
288 2 else
289 2 {
290 3 if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+CHRspBlock.len))
291 3 {
292 4 CHRspBlock.errcode=ERC_DEVICEERR;
293 4 return FALSE;
294 4 }
295 3 ThisFile.OffsetofSector=len;
296 3 }
297 2 ////////////////////////////////////////////////////////////
298 2 // if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
299 2 // ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
300 2 readLength-=len;
301 2 CHRspBlock.len+=len;
302 2 // ThisFile.OffsetofSector=;
303 2 /////////////////////////////////////////////////////////
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 6
304 2 if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
305 2 {
306 3 ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
307 3 ThisFile.SectorofCluster+=1;
308 3 if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
309 3 {
310 4 ThisFile.SectorofCluster=0;
311 4 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
312 4 if(ThisFile.ClusterPointer>0xffef)
313 4 {
314 5 //RspBlockReadFile.errcode=ERC_REACHEND;
315 5 //RspBlockReadFile.result=0x0;
316 5 CHRspBlock.errcode=ERC_REACHEND;
317 5 return FALSE;
318 5 }
319 4 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer);
320 4 }
321 3 else
322 3 ThisFile.SectorPointer=ThisFile.SectorPointer+1;
323 3 }
324 2 //////////////////////////////////////////////////////////////////
325 2 }//end while
326 1
327 1
328 1 ThisFile.bFileOpen=1;
329 1 ThisFile.pointer+=CHRspBlock.len;
330 1 //////////////////////////////////////////////
331 1 RspBlockReadFile.readLength=SwapINT16(CHRspBlock.len);
332 1 return TRUE;
333 1 #undef RspBlockReadFile
334 1 }
335
336 unsigned char CreateFile(unsigned char *pBuffer) //创建文件
337 {
338 1 #define RspBlockCreateFile CHRspBlock.RspBlock.Rsp_CreateFile
339 1 //unsigned long sectorNum;
340 1 unsigned int sector,i,j;
341 1 unsigned char bstop;
342 1 PDIR_INFO pDirInfo;
343 1
344 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED) //检测设备是否连入
345 1 {
346 2 CHRspBlock.errcode=ERC_NODEVICE; //否则返回错误
347 2 return FALSE;
348 2 }
349 1 ///////////////////////////////////////////////////////////
350 1 if(OpenFile( pBuffer))RemoveFile(pBuffer);
351 1
352 1 //RspBlockCreateFile.result=0x1;
353 1 //RspBlockCreateFile.errcode=ERC_OK;
354 1 pDirInfo=(PDIR_INFO)pBuffer;
355 1 ///////// Search the file of the same name ///////////
356 1 //CHCmdBlock.CmdBlock.Cmd_CreateFile.filename[j]
357 1 //if(!SPC_TestUnit())
358 1 // return FALSE;
359 1 //////// Search the fat for a free cluster ////////////
360 1 pDirInfo->startCluster=SwapINT16(GetFreeCusterNum());
361 1
362 1 if(pDirInfo->startCluster<0x2)
363 1 {
364 2 CHRspBlock.errcode=ERC_NODEVICE;
365 2 return FALSE;
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 7
366 2 }
367 1 pDirInfo->length=0;
368 1 /////// Search a free space in the root dir space and build the item ///
369 1 ThisFile.bFileOpen=0;
370 1 bstop=0;
371 1 for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
372 1 {
373 2 //////////////////////////////////////////////////
374 2 if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
375 2 {
376 3
377 3 CHRspBlock.errcode=ERC_DEVICEERR;
378 3 return FALSE;
379 3 }
380 2 ///////////////////////////////////////////////////
381 2 for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
382 2 {
383 3 if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
384 3 {
385 4 for(j=0;j<32;j++)
386 4 //DBUF[i+j]=CHCmdBlock.CmdBlock.Cmd_CreateFile.item[j];
387 4 DBUF[i+j]=*(pBuffer+j);
388 4 if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
389 4 {
390 5 CHRspBlock.errcode=ERC_DEVICEERR;
391 5 return FALSE;
392 5 }
393 4 bstop=1;
394 4 break;
395 4 }
396 3 }
397 2 ///////////////////////////////////////////////////////
398 2 if(bstop==1)break;
399 2
400 2 }
401 1 /////////////////////////////////////////////
402 1 //pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
403 1 //ThisFile.FatSectorPointer=ThisFatSecNum(ThisFile.StartCluster);
404 1 ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
405 1 ThisFile.LengthInByte=0;
406 1 ThisFile.ClusterPointer=ThisFile.StartCluster;
407 1 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
408 1 ThisFile.OffsetofSector=0;
409 1 ThisFile.SectorofCluster=0;
410 1 ThisFile.bFileOpen=1;
411 1 ThisFile.pointer=0;
412 1 ThisFile.FatSectorPointer=0;
413 1 //////////////////////////////////////////////
414 1 FreeFat.SectorNum=DeviceInfo.FatStartSector;
415 1 FreeFat.OldSectorNum=DeviceInfo.FatStartSector;
416 1 FreeFat.OffsetofSector=2;
417 1
418 1 return TRUE;
419 1 #undef RspBlockCreateFile
420 1 }
421
422 unsigned char WriteFile(unsigned int writeLength,unsigned char *pBuffer)
423 {
424 1 #define RspBlockWriteFile CHRspBlock.RspBlock.Rsp_WriteFile
425 1 unsigned int len,sector,i;
426 1 PDIR_INFO pDirInfo;
427 1 unsigned char bSuccess,bStop,step;
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 8
428 1
429 1 if(!bXXGFlags.bits.SLAVE_IS_ATTACHED) //U盘是否已经连接
430 1 {
431 2 CHRspBlock.errcode=ERC_NODEVICE;
432 2 return FALSE;
433 2 }
434 1 if(!ThisFile.bFileOpen) //文件是否已经打开
435 1 {
436 2 CHRspBlock.errcode=ERC_FILENOTOPENED;
437 2 return FALSE;
438 2 }
439 1 ///////////////////////////////////////////////////////////
440 1 //if(CHCmdBlock.CmdBlock.Cmd_WriteFile.writeLength>0)
441 1 // {
442 1 // for(i=CHCmdBlock.CmdBlock.Cmd_WriteFile.writeLength;i<MAX_WRITE_LENGTH;i++)
443 1 // CHBUF[i]=0;
444 1 // }
445 1
446 1 ///////////////////////////////////////////////////////////
447 1 ThisFile.bFileOpen=0;
448 1 bSuccess=1;
449 1 bStop=0;
450 1
451 1 CHRspBlock.len=0;
452 1 //if(CHCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)
453 1 while(writeLength>0)
454 1 {
455 2 //////////////////////////////////////////////////////
456 2 if(ThisFile.OffsetofSector>0)
457 2 {
458 3 if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
459 3 len=DeviceInfo.BPB_BytesPerSec;
460 3 else
461 3 len=writeLength+ThisFile.OffsetofSector;
462 3 //////////////////////////////////////////////////
463 3 if(!RBC_Read(ThisFile.SectorPointer,1,DBUF))
464 3 {
465 4 CHRspBlock.errcode=ERC_DEVICEERR;
466 4 return FALSE;
467 4 }
468 3 //ThisFile.OffsetofSector=len;
469 3 len=len-ThisFile.OffsetofSector;
470 3 for(i=0;i<len;i++)
471 3 //DBUF[ThisFile.OffsetofSector+i]=CHBUF[i];
472 3 DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
473 3 if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
474 3 {
475 4 CHRspBlock.errcode=ERC_DEVICEERR;
476 4 return FALSE;
477 4 }
478 3 ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
479 3 }
480 2 else
481 2 {
482 3 if(writeLength>DeviceInfo.BPB_BytesPerSec)
483 3 {
484 4 step=writeLength/DeviceInfo.BPB_BytesPerSec;
485 4 //step=step-ThisFile.SectorofCluster;
486 4 if(step>DeviceInfo.BPB_SecPerClus)
487 4 {
488 5 step=DeviceInfo.BPB_SecPerClus-ThisFile.SectorofCluster;
489 5 len=step*DeviceInfo.BPB_BytesPerSec;
C51 COMPILER V7.06 HPI 11/22/2004 22:08:31 PAGE 9
490 5 }
491 4 else
492 4 {
493 5 step=step-ThisFile.SectorofCluster;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -