这是我读取 MCUCSR 寄存器并从 3 位 PORF、EXTRF、WDRF 发出警报的代码。我希望这是微不足道的,但它不起作用。
任何想法?
static uint8_t mcucsr __attribute__ ((section (".noinit")));
static volatile union
{
struct
{
uint32_t watchdog:1;
uint32_t powerfail:1;
uint32_t reset:1;
uint32_t startup:1;
} b;
uint32_t w;
} __attribute__ ((packed)) alarms;
static void wdinit ()
{
mcucsr = MCUCSR;
MCUCSR &= ~(1 << PORF);
MCUCSR &= ~(1 << EXTRF);
MCUCSR &= ~(1 << WDRF);
} __attribute__((naked)) __attribute__ ((section (".init3")))
int main ()
{
alarms.b.startup = true;
alarms.b.powerfail |= !!(mcucsr & (1 << PORF));
alarms.b.reset |= !!(mcucsr & (1 << EXTRF));
alarms.b.watchdog |= !!(mcucsr & (1 << WDRF));
mcucsr = 0;
...