The first question is about the built-in assembly of S32DS library functions. I have checked some information, but I still don't understand it. So I would like to ask you to explain: For example
#define stringify(s) tostring(s)
#define tostring(s) #s
#define mfspr(rn) ({unsigned int rval; __asm__ volatile("mfspr %0," stringify(rn) : "=r" (rval)); rval;})
Let me start with my understanding: Define mfspr (rn) instead of transferring strings to SPR (rn) registers。but how do I get the ID of the core MCU?
The second problem is that in Chapter 4.1.1 of MPC5746C, NOTE has a sentence: "Implemented SIUL2 Multiplexed Single Configuration Register" are from SIUL2_MSCR0 to SIUL2_MSCR263 and SIUL2_IMCR0 to SIUL2_IMCR511. Please note that MSCR 513 in this column corresponds to IMCR 0 and so on. " Is MSCR 513 correct? Have you introduced the corresponding relationship between MSCR registers and IMCR registers?
The following examples are illustrated in the manual:
Example:
If user wants to configure CAN0RX and CAN0TX, then the following configuration can
be used in SIUL2 registers:
SIUL2.MSCR[16].R = 0x03000001; /* PB[0] -> OBE = 1, ODE = 1 and MSCR16_SSS = 1 */
SIUL2.MSCR[17].R = 0x00080000; /* PB[1] -> IBE = 1 */
SIUL2.IMCR[188].R = 0x00080002; /* PB[1] -> MSCR17_SSS = 2, notice that
“IO_Signal_Description_and_Input_multiplexing_tables.xls” shows 700 for the MSCR/IMCR see
note above, thus 188 must be used to properly configure the pin signal connected to it */
How does IMCR [188] relate to MSCR [17]? Please explain, thank you!
Hello,
your first question is pretty tough, and it took me some time to check, how this mechanism works. I hope I will explain it correct and understandably.
In S32DS there is function GetCoreID () which is defined like: #define GetCoreID() ((uint16_t) MFSPR(286)). Number 286 is important, because this is number of SPR register. SPR 286 is Processor ID register.
MFSPR is further define like:
#define MFSPR( rn ) ({unsigned int rval; PPCASM volatile("mfspr %0," stringify(rn) : "=r" (rval)); rval;}) which is simply a function.
Please see, how the function looks like, when you split it into single lines.
#define MFSPR( rn )
(
{
unsigned int rval;
PPCASM volatile("mfspr %0," stringify(rn) : "=r" (rval));
rval;
}
)
rval is local variable, which is used for storing the value from SPR register (SPR is determined by rn parameter, which is given to mfspr instruction). After the mfspr instruction is executed, register r3 is used for returning the value and because it is necessary to access the value using C code, extended assembler is used (("mfspr %0," stringify(rn) : "=r" (rval));) and value is returned using rval variable.
About the MSCR and IMCR register, this is a little bit easier. IMCR register is determined for choosing input functions of the pin.
I will use your example.
SIUL2.MSCR[16].R = 0x03000001; /* PB[0] -> OBE = 1, ODE = 1 and MSCR16_SSS = 1 */
SIUL2.MSCR[17].R = 0x00080000; /* PB[1] -> IBE = 1 */
SIUL2.IMCR[188].R = 0x00080002; /* PB[1] -> MSCR17_SSS = 2, notice that
Pin controller MSCR 16 is used for CAN TX, which means this pin is output. You do not have to care about IMCR register in this case. But pin controlled by MSCR 17 is used for CAN RX, which means this pin is input and when you check pin sheet, you can see following:
For input functions, IMCR pin must be set. From the figure you can see IMCR 700 must be set to 0x0000_0010, but IMCR registers array is defined with size 512, so this means, you must always subtract value 512 from the value in excel sheet.
Result is 700-512 = 188 and this is the value used for IMCR register.
Hope this helps.
Regards,
Martin
Thanks Martin,I'll study it carefully again. If you find something new and reply to me, thank you again!