?login_element?

Subversion Repositories NedoOS

Rev

Rev 8 | Blame | Compare with Previous | Last modification | View Log | Download

  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2016        */
  3. /*-----------------------------------------------------------------------*/
  4. /* If a working storage control module is available, it should be        */
  5. /* attached to the FatFs via a glue function rather than modifying it.   */
  6. /* This is an example of glue functions to attach various exsisting      */
  7. /* storage control modules to the FatFs module with a defined API.       */
  8. /*-----------------------------------------------------------------------*/
  9.  
  10. #include "ff.h"                 /* Obtains integer types */
  11. #include "diskio.h"             /* Declarations of disk functions */
  12. #include <stdio.h>
  13. #include <time.h>
  14.  
  15. /* Definitions of physical drive number for each drive */
  16. #define DEV_RAM         0       /* Example: Map Ramdisk to physical drive 0 */
  17. #define DEV_MMC         1       /* Example: Map MMC/SD card to physical drive 1 */
  18. #define DEV_USB         2       /* Example: Map USB MSD to physical drive 2 */
  19.  
  20. extern FILE * img;
  21.  
  22. /*-----------------------------------------------------------------------*/
  23. /* Get Drive Status                                                      */
  24. /*-----------------------------------------------------------------------*/
  25.  
  26. DSTATUS disk_status (
  27.         BYTE pdrv               /* Physical drive nmuber to identify the drive */
  28. )
  29. {
  30.         pdrv;
  31.         if(img==NULL) return RES_ERROR;
  32.         return RES_OK;
  33. }
  34.  
  35.  
  36.  
  37. /*-----------------------------------------------------------------------*/
  38. /* Inidialize a Drive                                                    */
  39. /*-----------------------------------------------------------------------*/
  40.  
  41. DSTATUS disk_initialize (
  42.         BYTE pdrv                               /* Physical drive nmuber to identify the drive */
  43. )
  44. {
  45.         pdrv;
  46.         if(img==NULL) return RES_ERROR;
  47.         return RES_OK;
  48. }
  49.  
  50.  
  51.  
  52. /*-----------------------------------------------------------------------*/
  53. /* Read Sector(s)                                                        */
  54. /*-----------------------------------------------------------------------*/
  55.  
  56. DRESULT disk_read (
  57.         BYTE pdrv,              /* Physical drive nmuber to identify the drive */
  58.         BYTE *buff,             /* Data buffer to store read data */
  59.         DWORD sector,   /* Start sector in LBA */
  60.         UINT count              /* Number of sectors to read */
  61. )
  62. {
  63.         pdrv;
  64.         if(img==NULL) return RES_ERROR;
  65.         fseek(img,sector*512,SEEK_SET);
  66.         fread(buff, 1, count*512, img);
  67.         return RES_OK;
  68. }
  69.  
  70.  
  71.  
  72. /*-----------------------------------------------------------------------*/
  73. /* Write Sector(s)                                                       */
  74. /*-----------------------------------------------------------------------*/
  75.  
  76. #if FF_FS_READONLY == 0
  77.  
  78. DRESULT disk_write (
  79.         BYTE pdrv,                      /* Physical drive nmuber to identify the drive */
  80.         const BYTE *buff,       /* Data to be written */
  81.         DWORD sector,           /* Start sector in LBA */
  82.         UINT count                      /* Number of sectors to write */
  83. )
  84. {
  85.         pdrv;
  86.         if(img==NULL) return RES_ERROR;
  87.         fseek(img,sector*512,SEEK_SET);
  88.         fwrite(buff, 1, count*512, img);
  89.         return RES_OK;
  90. }
  91.  
  92. #endif
  93.  
  94.  
  95. /*-----------------------------------------------------------------------*/
  96. /* Miscellaneous Functions                                               */
  97. /*-----------------------------------------------------------------------*/
  98.  
  99. DRESULT disk_ioctl (
  100.         BYTE pdrv,              /* Physical drive nmuber (0..) */
  101.         BYTE cmd,               /* Control code */
  102.         void *buff              /* Buffer to send/receive control data */
  103. )
  104. {
  105.         DRESULT res=RES_OK;
  106.         int result;
  107.  
  108.         switch (pdrv) {
  109.         case DEV_RAM :
  110.  
  111.                 // Process of the command for the RAM drive
  112.  
  113.                 return res;
  114.  
  115.         case DEV_MMC :
  116.  
  117.                 // Process of the command for the MMC/SD card
  118.  
  119.                 return res;
  120.  
  121.         case DEV_USB :
  122.  
  123.                 // Process of the command the USB drive
  124.  
  125.                 return res;
  126.         }
  127.  
  128.         return RES_PARERR;
  129. }
  130.  
  131. DWORD get_fattime (void){
  132.   struct tm *local;
  133.   time_t t;
  134.   DWORD ft=0;
  135.  
  136.   t = time(NULL);
  137.   local = localtime(&t);
  138.   ft=((local->tm_year-80)&0x7f)<<25;
  139.   ft|=((local->tm_mon+1)&0x0f)<<21;
  140.   ft|=((local->tm_mday)&0x1f)<<16;
  141.   ft|=((local->tm_hour)&0x1f)<<11;
  142.   ft|=((local->tm_min)&0x3f)<<5;
  143.   ft|=((local->tm_sec)&0x3f)>>1;
  144.   //printf("Year: %d\n", ft);
  145.         return ft;
  146. }