reading data into memory problem

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

guys, have a look at the code below! when I read the contents into the cache it is off by a few characters when I test if.  Can someone please tell me why.  It was working but I have no idea what has changed in the interim.

	unsigned char * cache = (unsigned char *)cache_alloc(cluster_size(file));

	// perform DMA read of directory location to ensure the data is up-to-date
	dma_hardware_read(1, file->cluster_addr, sectors_per_cluster(file), cache, 0);

	struct directory_entry     * directory = (struct directory_entry * )cache;

	unsigned char * test = (unsigned char *)directory;

	for(int i = 0; i < 64; i++, test++){

		if((i % 32) == 0)
			c_printf("\n\r");

		c_printf("%x ", * test);
	}

 

This topic has a solution.
Last Edited: Mon. Sep 6, 2021 - 08:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alignment?

 

Caches often rely on data alignment.

 

Does the cache_alloc() guarantee to deliver an aligned pointer? If not, when using it perhaps round up to the next boundary?

 

I also notice "dma" in there. Again DMA transfers are often aligned to granular boundaries. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

was thinking that clawson.  I'll have a go tonight at it and report back.

Thanks mate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just another quick question.  How do I align the allocation???

	unsigned char * cache = (unsigned char *)cache_alloc(cluster_size(file));

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Will this do the trick?

	unsigned char * cache = (unsigned char *)cache_alloc(cluster_size(file) + 4);

	cache = (((int)cache + 4) &~ 0x0F);

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be a pretty crap alloc function that didn't return an aligned pointer. However I would expect some sort of hardware exception if you performed a misaligned read/write operation.

 

dma_hardware_read(...)

One thought - Is that a synchronous function or asynch ?

In other words when it returns, has the operation definitely completed ?

Should you also check it's return value ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys. It lives!  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which model of Xmega is this?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.