Doubts on _mfcr command - reg

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

cross mob
User17059
Level 1
Level 1
Hi,
We are using Infineon TC-297 Development kit. I am going through the sample code . I got stuck with this part of code. What is the use of the function _mfcr(CPU_CORE_ID) ??? ( where core ID value is 0xFE1C)


static __inline__ __attribute__((__always_inline__))
unsigned _mfcr (const unsigned __regaddr)
{
unsigned __res;
__asm__ volatile ("mfcr %0, LO:%1"
: "=d" (__res) : "i" (__regaddr) : "memory");
return __res;
}


What does this part of code means???
0 Likes
1 Reply
User13290
Level 5
Level 5
First like received First solution authored

Hi Naveen,

What does this part of code means?


What this snippet accomplishes is that it returns the core identification number of the currently executing core. You need this in a multi-core environment to decide which core is executing and then follow its dedicated code path. As an example, suppose all cores call main after processing the startup code. Then main becomes responsible for distributing the code:


/* main() called by all cores */
int main(void) {
int n = _mfcr(CPU_CORE_ID);
switch (n) {
case 0: do_tc0(); break; /* handled by tc0 */
case 1: do_tc1(); break; /* handled by tc1 */
case 2: do_tc2(); break; /* handled by tc2 */
} while (1);
return 0;
}


NB: Note that in terms of main I'm using a different approach than the iLLD sample cases. These do not have a regular main(). Instead its startup code does the core ID check and then immediately routes to core_main.

Best regards,


Henk-Piet Glas
Principal Technical Specialist
Embedded Systems

0 Likes