Hello.
I could not run your code because the call to usbComRequestLineStateChangeNotification is not part of our Wixel SDK and you didn’t specify which third-party Wixel SDK you are using. I think it would be better if you could write your program using the latest commit in our version of the SDK so that there is less chance for problems to be caused by SDK modifications, and we can just focus on the code in one file instead of worrying about all of the code in the SDK.
I also think that your code is still far too complicated for something that is just supposed to demonstrate that WORTIME0 and WORTIME1 cannot be read correctly. You are doing lots of stuff to turn the USB connection on and off, so I think it would be better to just take out all of the USB code and do all communication with a UART. If the bug that you are working around using DMA only has a very small chance of happening, it would be better to remove all the complex DMA code that attempts to work around the bug for the sake of this test. You shouldn’t need to redefine time-keeping functions from the Wixel SDK, or use preprocessor macros like waitDoingServicesInterruptible to generate lots of code. I don’t know why you are sleeping in two different ways depending on the state of your usb_connected flag. I’m not sure why you are reading WORTIME0 and WORTIME1 in the sleep timer ISR instead of reading it in the main loop: there is a chance that the ISR is not even running, or it is running at the wrong time.
A while ago, I posted some code for putting the Wixel into power mode 2, based on section 12.1.3 of the datasheet:
SLEEP = (SLEEP & ~3) | 2; // SLEEP.MODE = 2 : Selects Power Mode 2 (PM2).
__asm nop __endasm; __asm nop __endasm; __asm nop __endasm;
if (SLEEP & 3)
{
PCON |= 1; // PCON.IDLE = 1 : Actually go to sleep.
}
I’d suggest that you write a new, simple program that uses the UART library to listen for a certain command character, and when it gets that character, it sets up the sleep timer, goes to sleep using the code above, wakes up, and then uses printf to send the values of WORTIME0 and WORTIME1 to the UART, and then goes back to listening for commands. You can use one of the LEDs to indicate whether you are sleeping or not, so you can verify that going to sleep and waking up at the right time really worked.
–David
