DMA priority confusion

Status
Not open for further replies.

WMXZ

Well-known member
I'm stumbling over the following (possible semantic) issue
AFAIK, the different DMA channels have different priorities.
let us assume the priorities are not modified and are the default ones.

My understanding is that
DMA channel 0 (at address 4000_8100) has priority 3 (DMA_DCHPRI3),
DMA channel 1 (at address 4000_8101) has priority 2 (DMA_DCHPRI2), etc.

Now, the DMAChannel class has the following routine (edit: don't doubt word access is more sufficient)
Code:
static uint32_t priority(const DMAChannel &c)
{
	uint32_t n;
	n = *(uint32_t *)((uint32_t)&DMA_DCHPRI3 + (c.channel & 0xFC));
	n = __builtin_bswap32(n);
	return (n >> ((c.channel & 0x03) << 3)) & 0x0F;
}
to retrieve the priority from the selected channel ch

I thought this is rather complicated and wrote a small sketch

Code:
#define DMA_DCHPRI_BASE 0x40008100

uint32_t DMA_priority(int ch) 
{   uint32_t n; 
  n = *(uint32_t *)((uint32_t)&DMA_DCHPRI3 + (ch & 0xFC)); 
  n = __builtin_bswap32(n); 
  return (n >> ((ch & 0x03) << 3)) & 0x3F; // modified from 0x0F to 0x3F to get also GRPPRI
} 

void setup() {
  // put your setup code here, to run once:
  while(!Serial);
  Serial.println("Test");
 uint8_t val;

 for(int ii=0;ii<32;ii++)
 {
 val= *(uint8_t *) (DMA_DCHPRI_BASE + ii);
 Serial.printf ("%d %02x %02x\n",ii,val, DMA_priority(ii));
 }
}

void loop() {
  // put your main code here, to run repeatedly:

}
and obtained the following output for a T3.6
Code:
Test
0 03 00
1 02 01
2 01 02
3 00 03
4 07 04
5 06 05
6 05 06
7 04 07
8 0b 08
9 0a 09
10 09 0a
11 08 0b
12 0f 0c
13 0e 0d
14 0d 0e
15 0c 0f
16 13 10
17 12 11
18 11 12
19 10 13
20 17 14
21 16 15
22 15 16
23 14 17
24 1b 18
25 1a 19
26 19 1a
27 18 1b
28 1f 1c
29 1e 1d
30 1d 1e
31 1c 1f

reading the byte values of the priorities directly (2nd column), I got what I expected, but using the DMAChannel priority function I got the value of the input back
priority == ch
should I not get the value back that is stored in the priority field?
(Note; I intentionally included the priority group in my output)
Any illumination on intended functionality?

Edit: IMO, the byteswap should be removed
 
Last edited:
Status
Not open for further replies.
Back
Top