Monday, December 18th 2017, 9:56am UTC+1

You are not logged in.

  • Login
  • Register

lowlevel

Beginner

Date of registration: Jan 28th 2011

Posts: 5

1

Wednesday, February 2nd 2011, 2:24pm

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?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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

lowlevel

Beginner

Date of registration: Jan 28th 2011

Posts: 5

2

Thursday, February 3rd 2011, 1:52pm

Hello everybody,

I give up trying to get the driver running. It's easier to use USB_MSD_StorageByName together with the File System.

Similar threads