emUSB USB_MSD_StorageRAM nicht vorhanden

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • emUSB USB_MSD_StorageRAM nicht vorhanden

    Hello everybody,

    I try to use emUSB and want to implement an easy MSD using RAM on an TMPA900CM. I have a lot of problems to get the code to this point because the documentation of the emXXX packages is very imprecise.
    The problem is that I don't find USB_MSD_StorageRAM in the Library. We only purchased the object code variant and not the source code variant of emUSB and I think there USB_MSD_StorageRAM is not included. I tried to implement this very easy RAM API myself but the documentation of USB_MSD_STORAGE_API is not enough for me to understand what the functions have to do. Could anybody help with a detailed description of what the function have to do?

    C Source Code

    1. // USB_MSD_RAM Implementation
    2. #include "USB.h"
    3. #include "USB_MSD.h"
    4. U8 RAMLun;
    5. U8* RAM;
    6. U32 RAMSize;
    7. U32 RAMNumSectors;
    8. U32 RAMSectorSize;
    9. U8* RAMReadBuffer;
    10. U8* RAMWriteBuffer;
    11. U32 RAMSectorIndex;
    12. void _pfInit(U8 Lun, const USB_MSD_INST_DATA_DRIVER * pDriverData)
    13. {
    14. RAMLun = Lun;
    15. RAM = pDriverData->pStart;
    16. RAMSize = pDriverData->NumSectors * pDriverData->SectorSize;
    17. RAMSectorSize = pDriverData->SectorSize;
    18. RAMNumSectors = pDriverData->NumSectors;
    19. return;
    20. }
    21. void _pfGetInfo(U8 Lun, USB_MSD_INFO * pInfo)
    22. {
    23. if(Lun == RAMLun)
    24. {
    25. pInfo->NumSectors = RAMNumSectors;
    26. pInfo->SectorSize = RAMSectorSize;
    27. }
    28. return;
    29. }
    30. U32 _pfGetReadBuffer(U8 Lun, U32 SectorIndex, void ** ppData, U32 NumSectors)
    31. {
    32. if(RAMNumSectors < (SectorIndex+NumSectors))
    33. return 0;
    34. ppData[0] = RAM+(SectorIndex*RAMSectorSize);
    35. return NumSectors;
    36. }
    37. char _pfRead(U8 Lun, U32 SectorIndex, void * pData, U32 NumSector)
    38. {
    39. if(Lun == RAMLun)
    40. {
    41. if(SectorIndex > RAMNumSectors)
    42. return 1;
    43. for(int i=NumSector; i > 0; i--)
    44. {
    45. if((SectorIndex + (NumSector-i)) > RAMNumSectors)
    46. return 1;
    47. else
    48. memset((U8*)(pData)+((SectorIndex + (NumSector - i)) * RAMSectorSize), (U8)(RAM[((SectorIndex + (NumSector - i)) * RAMSectorSize)]), 1);
    49. }
    50. return 0;
    51. }
    52. return 1; // Success
    53. }
    54. U32 _pfGetWriteBuffer(U8 Lun, U32 SectorIndex, void ** ppData, U32 NumSectors)
    55. {
    56. if(RAMNumSectors < NumSectors)
    57. return 0;
    58. ppData[0] = RAM+(SectorIndex*RAMSectorSize);
    59. return NumSectors;
    60. }
    61. char _pfWrite(U8 Lun, U32 SectorIndex, const void * pData, U32 NumSectors)
    62. {
    63. if(Lun == RAMLun)
    64. {
    65. if(SectorIndex > RAMNumSectors)
    66. return 1;
    67. for(int i=NumSectors; i > 0; i--)
    68. {
    69. if((SectorIndex + (NumSectors-i)) > RAMNumSectors)
    70. return 1;
    71. else
    72. memset(RAM+((SectorIndex + (NumSectors-i))*RAMSectorSize), *((U8*)(pData)), 1);
    73. }
    74. return 0;
    75. }
    76. return 1; // Success
    77. }
    78. char _pfMediumIsPresent(U8 Lun)
    79. {
    80. if(Lun == RAMLun)
    81. return 1;
    82. else return 0;
    83. }
    84. void _pfDeInit(U8 Lun)
    85. {
    86. return;
    87. }
    88. const USB_MSD_STORAGE_API USB_MSD_StorageRAM = {
    89. _pfInit,
    90. _pfGetInfo,
    91. _pfGetReadBuffer,
    92. _pfRead,
    93. _pfGetWriteBuffer,
    94. _pfWrite,
    95. _pfMediumIsPresent,
    96. 0
    97. };
    Display All


    P.S: For everybody who has problems in getting the USB Device Driver running. Don't forget to activate clocks on USB. The driver doesn't do it.

    Any help is appreciated.
    lowlevel