sleeping safely

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a UC3B0256 board where I am trying to drop current consumption.
Thus, I wish to sleep. In particular, I wish to sleep until the uart is almost done transmitting, so i have code like this:

if (tx ready irq is enabled) SLEEP(1);

The uart interrupt will disable itself as soon as the last character is sent. If this happens 'before' or during sleep, everything is good. If it happens between the test being performed and the sleep, it will sleep forever.

On AVR( 8 ) one could get away with this (equivalent):

DisableGlobalInterrupt();
if (tx ready irq is enabled) SLEEP(1);
EnableGlobalInterrupt();

However if I do that on AVR32, it will never get out of sleep. I can stop execution before the sleep instruction, inspect that the status and mask registers indeed do have bit 1 (txrdy) set, and it still sleeps.

What is the right way to NOT sleep if one's wakeup source has already fired and gone away?

I am currently at 3.2mA @ 11MHz xtal /2 =5.5MHz for cpu, pba, pbb clocks. I need to keep the adc and usart running, so I can not stop the oscillator.

/Kasper

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it supposed to sleep just during TX via USART?

What is the wake up event?

The UC3 can send or receive over PDCA ie the USART hardware can send a buffer from memory without CPU intervention but I don't know if that works in sleep modes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll need to let the PBA running to get the uart interrupt working. See the sleep mode description in the datasheet power manager section.

-sma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PBA is kept running in SLEEP(1=frozen). With SLEEP(0=idle) HSB is also kept running.
The USART interrupt does bring it out of sleep mode when sleeping with global interrupt enabled. I have tested this, and it works. Current consumption drops compared to busy-looping, and I see short peaks of increased current consumption at the character rate. So far so good.

If I no longer have a wakeup source, I should not sleep*. But how to avoid the hazard between the test and the sleep?

/Kasper

*In this case I should produce more data to send. This thing is inside a motion control loop, reporting sensor values to the loop controller: If I produce data too far ahead of time, it makes life difficult for the loop controller.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OR the sleep mode with 0x80. That will cause the CPU to atomically enable interrupts and enter sleep.

Not all CPUs may support this, but I think all devices except AP7000 and some ES variants of UC3{A,B}{0,1} do.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@how:
This works. Thank you.

(For those who may stumble upon this thread in the future, the tested part is AT32UC3B0256 jtag id 51EE403F, CPU rev 3)

/Kasper