📄 udisk.lst
字号:
282 1 rwdisk.write_ptr = reqbuff;
283 1
284 1 if(wait_ack())// 等待应答
285 1 {
286 2 if(rwdisk.cmds==0)
287 2 { handle->fh = reqbuff[0];
288 3 handle->fsize = reqbuff[1]+
289 3 reqbuff[2]*0x100+
290 3 reqbuff[3]*0x10000+
291 3 reqbuff[4]*0x1000000;
292 3 }
293 2 else
294 2 handle = NULL;
295 2 }
296 1 else
297 1 handle = NULL;
298 1
299 1 return handle;
300 1 }
301
302 /*********************************************************************************************************
303 ** 函数名称: FileClose
C51 COMPILER V8.05a UDISK 10/10/2008 20:18:58 PAGE 6
304 ** 功能描述: 关闭指定文件
305 **
306 ** 输 入: Handle:文件句柄
307 **
308 ** 输 出: RETURN_OK:成功
309 ** 其它参考fat.h中关于返回值的说明
310 ********************************************************************************************************/
311 uint8 FileClose(void)
312 {
313 1 uint8 reqbuff[6];
314 1
315 1 reqbuff[0] = 'U'; reqbuff[1]= ':'; reqbuff[2] = 0x12;
316 1 reqbuff[3] = 0; reqbuff[4] = 0; reqbuff[5] = 0;
317 1
318 1 FreeFHandle();
319 1 rwdisk.write_ptr = reqbuff;
320 1 SendResponse(reqbuff,6); // 发送命令请求帧
321 1
322 1 if(wait_ack())// 等待应答
323 1 {
324 2
325 2 return rwdisk.cmds;
326 2 }
327 1 else
328 1 return 0xf0; // 没应答
329 1
330 1 }
331
332 /*********************************************************************************************************
333 ** 函数名称: S_FileWrite
334 ** 功能描述: 写文件
335 **
336 ** 输 入: Buf:要写的数据
337 ** Size:要写的字节数
338 ** Handle:文件句柄
339 ** 输 出: 实际写的字节数
340 ********************************************************************************************************/
341 uint16 S_FileWrite(void *Buf, uint16 Size, FHANDLE *Handle)
342 {
343 1 uint8 reqbuff[10];
344 1 if(Handle==NULL) return 0;
345 1 reqbuff[0] = 'U';reqbuff[1]= ':'; reqbuff[2] = 0x20;
346 1 if(Handle->fh!=0xff) reqbuff[3] = Handle->fh;
347 1 else return 0;
348 1 reqbuff[4] = (uint8)Size;
349 1 reqbuff[5] = (uint8)(Size/0x100);
350 1 rwdisk.write_ptr = &reqbuff[6];
351 1
352 1 SendResponse(reqbuff,6); // 发送命令请求帧
353 1 SendResponse((uint8*)Buf,Size); // 发送命令请求帧
354 1
355 1 /*
356 1 uint8 tempbuf[512+6];
357 1 memcpy(tempbuf,reqbuff,6);
358 1 memcpy(tempbuf+6,Buf,Size);
359 1 SendResponse(tempbuf,6+Size);
360 1 */
361 1
362 1 if(wait_ack())// 等待应答
363 1 { if(rwdisk.cmds!=0)
364 2 return 0;
365 2 }
C51 COMPILER V8.05a UDISK 10/10/2008 20:18:58 PAGE 7
366 1 else
367 1 return 0;
368 1 return (uint16)(reqbuff[6]+reqbuff[7]*0x100); // reqbuff[8],reqbuff[9] 不处理
369 1 }
370
371 /*********************************************************************************************************
372 ** 函数名称: FileWrite
373 ** 功能描述: 写文件
374 **
375 ** 输 入: Buf:要写的数据
376 ** Size:要写的字节数
377 ** Handle:文件句柄
378 ** 输 出: 实际写的字节数
379 ********************************************************************************************************/
380 uint32 FileWrite(uint8 *Buf, uint32 Size, FHANDLE *Handle)
381 {
382 1 uint32 allwrite=0;
383 1 uint16 bewrite;
384 1
385 1 while((Size/MAX_FILE_SIZE)>0)
386 1 {
387 2 Size -= MAX_FILE_SIZE;
388 2 bewrite = S_FileWrite( Buf+allwrite,MAX_FILE_SIZE,Handle);
389 2 if(bewrite == MAX_FILE_SIZE)
390 2 {
391 3 allwrite += bewrite;
392 3 }
393 2 else // 写文件出错
394 2 {
395 3 return allwrite;
396 3 }
397 2 }
398 1
399 1 bewrite = 0;
400 1 if(Size)
401 1 {
402 2 bewrite = S_FileWrite(Buf+allwrite,(uint16) Size,Handle);
403 2 }
404 1
405 1 return allwrite+bewrite;
406 1 }
407
408 /*********************************************************************************************************
409 ** 函数名称: FileRead
410 ** 功能描述: 读取文件
411 **
412 ** 输 入: Buf:保存读回的数据
413 ** Size:要读的字节数
414 ** Handle:文件句柄
415 ** 输 出: 实际读到的字节数
416 ********************************************************************************************************/
417 uint16 S_FileRead(void *Buf, uint16 Size, FHANDLE *Handle)
418 {
419 1 uint8 reqbuff[10];
420 1 if(Handle==NULL) return 0;
421 1 reqbuff[0] = 'U';reqbuff[1]= ':'; reqbuff[2] = 0x30;
422 1 if(Handle->fh!=0xff) reqbuff[3] = Handle->fh;
423 1 else return 0;
424 1 reqbuff[4] = 4;
425 1 reqbuff[5] = 0;
426 1 reqbuff[6] = (uint8)Size;
427 1 reqbuff[7] = (uint8)(Size/0x100);
C51 COMPILER V8.05a UDISK 10/10/2008 20:18:58 PAGE 8
428 1 reqbuff[8] = 0;
429 1 reqbuff[9] = 0;
430 1
431 1 rwdisk.write_ptr = (uint8*)Buf;
432 1 SendResponse(reqbuff,10); // 发送命令请求帧
433 1
434 1
435 1 if(wait_ack())// 等待应答
436 1 { if(rwdisk.cmds!=0)
437 2 return 0;
438 2 }
439 1 else return 0;
440 1 return (uint16)rwdisk.wlen;
441 1 }
442
443 /*********************************************************************************************************
444 ** 函数名称: FileRead
445 ** 功能描述: 读取文件
446 **
447 ** 输 入: Buf:保存读回的数据
448 ** Size:要读的字节数
449 ** Handle:文件句柄
450 ** 输 出: 实际读到的字节数
451 ********************************************************************************************************/
452 uint32 FileRead(uint8 *Buf, uint32 Size, FHANDLE *Handle)
453 {
454 1 uint32 allread=0;
455 1 uint16 beread;
456 1
457 1 while((Size/MAX_FILE_SIZE)>0)
458 1 {
459 2 Size -= MAX_FILE_SIZE;
460 2 beread = S_FileRead( Buf+allread,MAX_FILE_SIZE,Handle);
461 2 if(beread==MAX_FILE_SIZE)
462 2 {
463 3 allread += beread;
464 3 }
465 2 else // 写文件出错
466 2 {
467 3 return allread;
468 3 }
469 2 }
470 1 beread = 0;
471 1 if(Size)
472 1 {
473 2 beread = S_FileRead(Buf+allread,(uint16) Size,Handle);
474 2 }
475 1 return allread+beread;
476 1 }
477
478
479
480 /*********************************************************************************************************
481 ** 函数名称: FileSeek
482 ** 功能描述: 移动文件读\写位置
483 **
484 ** 输 入: Handle:文件句柄
485 ** offset:移动偏移量
486 ** Whence:移动模式SEEK_SET:从文件头计算SEEK_CUR:从当前位置计算SEEK_END:从文件尾计算
487 ** 输 出: 成功返回0
488 ** 出错返回非0值
489 ********************************************************************************************************/
C51 COMPILER V8.05a UDISK 10/10/2008 20:18:58 PAGE 9
490 uint8 FileSeek(FHANDLE *Handle, int32 offset, uint8 Whence)
491 {
492 1 uint8 reqbuff[11];
493 1 if(Handle==NULL) return PARAMETER_ERR;
494 1 reqbuff[0] = 'U'; reqbuff[1]= ':'; reqbuff[2] = 0x40;
495 1 if(Handle->fh!=0xff)
496 1 reqbuff[3] = Handle->fh;
497 1 else
498 1 return PARAMETER_ERR;
499 1 reqbuff[4] = 5;
500 1 reqbuff[5] = 0;
501 1
502 1 reqbuff[6] = offset & 0xff;
503 1 reqbuff[7] = (offset>>8) & 0xff ;
504 1 reqbuff[8] = (offset>>16) & 0xff;
505 1 reqbuff[9] = (offset>>24) & 0xff;
506 1
507 1 reqbuff[10] = Whence;
508 1
509 1 rwdisk.write_ptr = reqbuff;
510 1 SendResponse(reqbuff,11); // 发送命令请求帧
511 1
512 1 if(wait_ack())// 等待应答
513 1 {
514 2 return rwdisk.cmds;
515 2 }
516 1 else
517 1 return 0xff;
518 1 }
519
520 /*********************************************************************************************************
521 ** 函数名称: MakeDir
522 ** 功能描述: 建立目录
523 **
524 ** 输 入: Path:路径名
525 **
526 ** 输 出: 成功返回0
527 ** 出错返回非0值
528 ********************************************************************************************************/
529 uint8 MakeDir(char *Path)
530 {
531 1 uint8 reqbuff[6];
532 1 uint8 namelen;
533 1 uint8 rt;
534 1
535 1 reqbuff[0] = 'U';reqbuff[1]= ':';
536 1 reqbuff[2] = 0x50;reqbuff[3] = 0xff;
537 1 namelen = strlen(Path); // 获取文件夹名字符串长度
538 1 reqbuff[4] = namelen; reqbuff[5] = 0;
539 1
540 1 SendResponse(reqbuff,6); // 发送命令请求帧
541 1 SendResponse((uint8*)Path,namelen); // 发送命令请求帧
542 1
543 1 rwdisk.write_ptr = reqbuff;
544 1
545 1 if(wait_ack()) // 等待应答
546 1 {
547 2 rt = rwdisk.cmds;
548 2 }
549 1 else
550 1 rt = 0xff;
551 1
C51 COMPILER V8.05a UDISK 10/10/2008 20:18:58 PAGE 10
552 1 return rt;
553 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2446 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = 28 151
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -