Problem with wm_memcpy()


#1

Hiya,

Has anybody else had problems using wm_memcpy() to either (a) copy from a constant array to pointer in RAM; or (b) using wm_memcpy() in a low-level interrupt handler?

Example:

extern const u8 *myData;

#define MYDATALENGTH 17000

s32 pcmAudioStreamHandle;
u8 *PcmStreamBuffer = NULL;
u16 PcmBufferSize = 0;
s32 PcmStartIndex = 0;

s32 pcmLowIrqHandle;
s32 pcmHighIrqHandle;

bool pcmLowIrqHandler (adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel, adl_irqEventData_t *Data)
{
	bool retValue = FALSE;

	// load buffer
	wm_memcpy(PcmStreamBuffer, (myData + PcmStartIndex),
			PcmBufferSize);

	// start playing
       // Set BufferReady flag to TRUE
       *( ( adl_audioStream_t * )Data->SourceData )->BufferReady = TRUE;

	// work out next start position;

	PcmStartIndex += PcmBufferSize;
	if (PcmStartIndex >= MYDATALENGTH)
	{
		retValue = TRUE; // fire HighIrqHandler to stop play
	}

	return retValue;
}

void startPlay( void )
{
	s32 ret;

	pcmAudioStreamHandle = adl_audioSubscribe( ADL_AUDIO_VOICE_CALL_TX,
		voice_pcmAudioEventHandler, ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION );

	TRACE ((2, "PCM audioSubscribe returns [%d]", pcmAudioStreamHandle));

	ret = adl_audioGetOption( pcmAudioStreamHandle,
		ADL_AUDIO_PCM_8K_16B_MONO_BUFFER_SIZE, (s32 *)&PcmBufferSize);
	TRACE ((2, "audioGetOption returns [%d], buffer = [%d]", ret, PcmBufferSize));

	if (PcmStreamBuffer != NULL)
	{
		adl_memRelease( PcmStreamBuffer );
	}
	PcmStreamBuffer = adl_memGet( PcmBufferSize );
	wm_memset(PcmStreamBuffer, 0x00, PcmBufferSize);
	PcmStartIndex = 0;

	// start playing
	ret = adl_audioStreamPlay(pcmAudioStreamHandle, ADL_AUDIO_PCM_MONO_8K_16B,
			pcmLowIrqHandle, pcmHighIrqHandle, PcmStreamBuffer);
	TRACE ((2, "PCM audioStreamPlay returns [%d]", ret));

	return;
}

and myData is defined in another file like this:

const u8 myData[] =
{
	0x30, 0x00, 0x08, 0x00, 0xc7, 0xff, 0xda, 0xff, 0xf6, 0xff, 0x0a, 0x00, 0xf6, 0xff, 0xd9, 0xff, 0xf8, 0xff, 0x10, 0x00,
	0x18, 0x00, 0xd8, 0xff, 0xe0, 0xff, 0x08, 0x00, 0x20, 0x00, 0x30, 0x00, 0x30, 0x00, 0x10, 0x00, 0xf0, 0xff, 0xe8, 0xff,
	0xe8, 0xff, 0xf0, 0xff, 0xef, 0xff, 0xda, 0xff, 0xc6, 0xff, 0xfa, 0xff, 0x17, 0x00, 0x17, 0x00, 0x0a, 0x00, 0xfe, 0xff,
	0x09, 0x00, 0x09, 0x00, 0xf6, 0xff, 0xf3, 0xff, 0xf4, 0xff, 0x0c, 0x00, 0xfc, 0xff, 0x04, 0x00, 0xd5, 0xff, 0xc9, 0xff,
	0xf1, 0xff, 0x16, 0x00, 0x1a, 0x00, 0x06, 0x00, 0x0a, 0x00, 0x06, 0x00, 0x0a, 0x00, 0xf6, 0xff, 0xfa, 0xff, 0xfe, 0xff,
....
.... 
};

The above code starts the PCM stream playing, and calls the low interupt handler (as evidenced by a number of TRACE() outputs in the trace window). All that isn’t happening is that the data from the const u8 array is not being copied into the output buffer, as the audio output is pure noise.

BTW, I know that the Audio playback on my module is OK, because the PCM example compiles and works fine. I also know that the PCM is correct, as I modified the PCM sample to record a sample then dump out the memory buffer so I could use it in this example.

This is driving me nuts - I’ve been figting with it all day…and can’t see what I’ve missed.

Any comments or thoughts are appreciated. It’s probably something obvious!

Dev environment: M2M Studio 1.0.2/Oasis 2.20/Q2686G

Thanks, Dave


#2

Hiya,

Sorted it (well, a mate who is a C guru sorted it for me).

You can’t do the following (as I was):

extern const u8 *myData;

...
...

const u8 myData[] = { ...... };

instead, you have to declare things this way:

extern const u8 myData[];

...
...

const u8 myData[] = {.......};

I knew it would be simple…

ciao, Dave