iLLD IFXCPU_GLB_ADDR_DSPR macro

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
IvanoBono
Level 3
Level 3
25 sign-ins 10 sign-ins 10 replies posted

Hi all,

some iLLD functions use the "IFXCPU_GLB_ADDR_DSPR" macro which converts an local DSPR address to global DSPR address, for example:  IfxCpu_waitEvent (in IfxCpu.c). why this? 

0 Likes
1 Solution
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi,

Sorry if I confused you.

The Macro is meant for translation from Local address to Global address. It evaluates if the address is local (0xDXXXXXXX, where X - don't care) if yes it converts the address into a Global address otherwise leave as it is.

In this case, the address of a variable passed through a pointer obviously is a global address so it does nothing.

If in case user intentionally uses Local address in the code then this macro converts it into a Global address as you mentioned:

The sync get the value as below if the Local Address 0xD0001234 is used:

IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), 0xD0001234); 
 
0x70001234 when executed by core0
0x60001234 when executed by core1
0x50001234 when executed by core2
 
If I have a code like this:
 
UINT32 myVariable;
IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), &myVariable); 
 
then all Cores read/write from/to the same location.

View solution in original post

0 Likes
6 Replies
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi IvanoBono,

Each Core has a local/private view of its own memory (DSPR & PSPR) and the above Macro is used to convert the local/private address to the global address based on the Core. You may refer to section 5.3.6.1.1 Local and Global Addressing section in the User manual for more details. Hope this answers your question.

Prudhvi

0 Likes

I am aware of the functioning of the memory addressing of the tc377 and I understand what this MACRO is for. What I don't understand, is why it was used in the "IfxCpu_waitEvent" function.
if, in this function, local addressing had been used instead of global addressing, wouldn't it have worked?

0 Likes
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi,

It won't work if the Local addressing is used, because each core writes to its own DSPR based on the offset calculated from 0xd0000000. Then the intended memory/variable is not written by other cores.

For ex: if the address of the variable used in the function IfxCpu_waitEvent is 0x70000000 the local address of that variable for CPU0 is 0xd0000000.

If the same local address is used then CPU0 writes to its own DPSR : 0x70000000, CPU1 writes to its own DSPR : 0x60000000 & CPU2 writes to its won DSPR : 0x50000000 etc. but not all CPUs write to the memory 0x70000000 where the variable in the function IfxCpu_waitEvent is stored. Here the variable we're discussing about is to be updated by all the cores for Synchronization. Hence this macro is used.

Hope this answers your question.

Prudhvi

0 Likes

I can't understand the reasoning.
this is the "IfxCpu_waitEvent" function:

 boolean IfxCpu_waitEvent(IfxCpu_syncEvent *event, uint32 timeoutMilliSec)
{
   volatile uint32 *sync          = (volatile uint32 *)IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), event);

    boolean          errorcnt      = 0U;
   /* Divide with 1000, gives the count value equivalent to milliseconds */
    uint32           stmCount      = (uint32)((IfxScuCcu_getStmFrequency() / 1000) * timeoutMilliSec);
    uint32           stmCountBegin = STM0_TIM0.U;
 
   while ((*sync & IFXCPU_CFG_ALLCORE_DONE) != IFXCPU_CFG_ALLCORE_DONE)
    {
      __nop();

      if ((uint32)(STM0_TIM0.U - stmCountBegin) >= stmCount)
       {
           errorcnt = 1;
           break;
       }
           /* There is no need to check overflow of the STM timer.
           * When counter after overflow subtracted with counter before overflow,
           * the subtraction result will be as expected, as long as both are unsigned 32 bits
           * eg: stmCountBegin= 0xFFFFFFFE (before overflow)
           *     stmCountNow = 0x00000002 (before overflow)
           *     diff= stmCountNow - stmCountBegin = 4 as expected.*/
    }
       return errorcnt;
  }

"__mfcr(CPU_CORE_ID)" returns the id of the current core.

so if I call:

IfxCpu_waitEvent(0xD00001234,timeout);

sync get the value:

IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), 0xD0001234); 
so:
0x70001234 when executed by core0
0x60001234 when executed by core1
0x50001234 when executed by core2
therefore they end up writing on 3 different addresses in the same way as if 0xD0001234 were kept.
0 Likes
Prudhvi_E
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 25 likes received

Hi,

Sorry if I confused you.

The Macro is meant for translation from Local address to Global address. It evaluates if the address is local (0xDXXXXXXX, where X - don't care) if yes it converts the address into a Global address otherwise leave as it is.

In this case, the address of a variable passed through a pointer obviously is a global address so it does nothing.

If in case user intentionally uses Local address in the code then this macro converts it into a Global address as you mentioned:

The sync get the value as below if the Local Address 0xD0001234 is used:

IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), 0xD0001234); 
 
0x70001234 when executed by core0
0x60001234 when executed by core1
0x50001234 when executed by core2
 
If I have a code like this:
 
UINT32 myVariable;
IFXCPU_GLB_ADDR_DSPR(__mfcr(CPU_CORE_ID), &myVariable); 
 
then all Cores read/write from/to the same location.
0 Likes

I can't imagine a situation where someone has to use this function with local address (0xDxxxxxxx). cmq I would say that we can close the question.

0 Likes