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?
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
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
- // USB_MSD_RAM Implementation
- #include "USB.h"
- #include "USB_MSD.h"
- U8 RAMLun;
- U8* RAM;
- U32 RAMSize;
- U32 RAMNumSectors;
- U32 RAMSectorSize;
- U8* RAMReadBuffer;
- U8* RAMWriteBuffer;
- U32 RAMSectorIndex;
- void _pfInit(U8 Lun, const USB_MSD_INST_DATA_DRIVER * pDriverData)
- {
- RAMLun = Lun;
- RAM = pDriverData->pStart;
- RAMSize = pDriverData->NumSectors * pDriverData->SectorSize;
- RAMSectorSize = pDriverData->SectorSize;
- RAMNumSectors = pDriverData->NumSectors;
- return;
- }
- void _pfGetInfo(U8 Lun, USB_MSD_INFO * pInfo)
- {
- if(Lun == RAMLun)
- {
- pInfo->NumSectors = RAMNumSectors;
- pInfo->SectorSize = RAMSectorSize;
- }
- return;
- }
- U32 _pfGetReadBuffer(U8 Lun, U32 SectorIndex, void ** ppData, U32 NumSectors)
- {
- if(RAMNumSectors < (SectorIndex+NumSectors))
- return 0;
- ppData[0] = RAM+(SectorIndex*RAMSectorSize);
- return NumSectors;
- }
- char _pfRead(U8 Lun, U32 SectorIndex, void * pData, U32 NumSector)
- {
- if(Lun == RAMLun)
- {
- if(SectorIndex > RAMNumSectors)
- return 1;
- for(int i=NumSector; i > 0; i--)
- {
- if((SectorIndex + (NumSector-i)) > RAMNumSectors)
- return 1;
- else
- memset((U8*)(pData)+((SectorIndex + (NumSector - i)) * RAMSectorSize), (U8)(RAM[((SectorIndex + (NumSector - i)) * RAMSectorSize)]), 1);
- }
- return 0;
- }
- return 1; // Success
- }
- U32 _pfGetWriteBuffer(U8 Lun, U32 SectorIndex, void ** ppData, U32 NumSectors)
- {
- if(RAMNumSectors < NumSectors)
- return 0;
- ppData[0] = RAM+(SectorIndex*RAMSectorSize);
- return NumSectors;
- }
- char _pfWrite(U8 Lun, U32 SectorIndex, const void * pData, U32 NumSectors)
- {
- if(Lun == RAMLun)
- {
- if(SectorIndex > RAMNumSectors)
- return 1;
- for(int i=NumSectors; i > 0; i--)
- {
- if((SectorIndex + (NumSectors-i)) > RAMNumSectors)
- return 1;
- else
- memset(RAM+((SectorIndex + (NumSectors-i))*RAMSectorSize), *((U8*)(pData)), 1);
- }
- return 0;
- }
- return 1; // Success
- }
- char _pfMediumIsPresent(U8 Lun)
- {
- if(Lun == RAMLun)
- return 1;
- else return 0;
- }
- void _pfDeInit(U8 Lun)
- {
- return;
- }
- const USB_MSD_STORAGE_API USB_MSD_StorageRAM = {
- _pfInit,
- _pfGetInfo,
- _pfGetReadBuffer,
- _pfRead,
- _pfGetWriteBuffer,
- _pfWrite,
- _pfMediumIsPresent,
- 0
- };
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