Home > other >  [for] a macro definition read port state error
[for] a macro definition read port state error

Time:01-12

In made domestic chip IAR8.40.1 huada HC32F460 when the underlying configuration, the use of a macro definition to read port state, 0, 0 port state for ever, even if register input port status is 1, reads the status also is 0, the code is as follows:
# define M_PORT_GetBit (enPort u16Pin) (((* *) (Uint16 ((Uint32) \
(& amp; M4_PORT - & gt; PIDRA) + 0 x10u * (enPort))) & gt;> (u16Pin)) & amp; 0 x01)
The use of inline function to read, and the result is the same, a macro definition code is as follows:
# pragma inline=forced
Uint16 M_PORT_GetBit_fun (const en_port_t enPort, const uint16_t u16Pin)
{
Return (((* (Uint16 *) ((Uint32) \
(& amp; M4_PORT - & gt; PIDRA) + 0 x10u * enPort)) & gt;> U16Pin) & amp; 0 x01);
}
But using the ordinary function call, can read correctly set port state 0, the code is as follows:
Uint16 M_PORT_GetBit_fun (const en_port_t enPort, const uint16_t u16Pin)
{
Return (((* (Uint16 *) ((Uint32) \
(& amp; M4_PORT - & gt; PIDRA) + 0 x10u * enPort)) & gt;> U16Pin) & amp; 0 x01);
}
Consult a great god, and if encountered similar problems, please answer, thank you very much,
  • Related