_clkmode and _clkfreq
David Betz
Posts: 14,516
in Propeller 1
Does anyone remember how one goes about setting the clock mode in PropGCC? I know you can set it at runtime by using a macro in propeller.h but I want to set the initial clock settings in the binary file header. I know there is a way to do it but I haven't been able to find the documentation. Does anyone remember? Should this work?
#include <propeller.h> #define RCFAST 0x00 #define RCSLOW 0x01 #define XINPUT 0x22 #define XTAL1 0x2a #define XTAL2 0x32 #define XTAL3 0x3a #define PLL1X 0x41 #define PLL2X 0x42 #define PLL4X 0x43 #define PLL8X 0x44 #define PLL16X 0x45 unsigned char _clkmode = XTAL1+PLL8X;
Comments
The table is a bit misleading though.
Scroll down to the bottom of this code
macros inside assembler...
Getting strings out of the C macro preprocessor is always a challenge. The C preprocessor is very dumb, and it just literally does string substitution, whereas most of us (even seasoned programmers) think in terms of semantic replacement.
Here's a sample program that shows (I think) how to do it. Try1 is the naive approach, which only does one level of expansion. Try2 does a deeper substitution:
The output is:
Note that the macro replacement, if done, is recursive, e.g. if you replace the #define RCSLOW with: the output is still the same. The trick is just getting past that first level of indirection.
You'll get a string something like "0x08+0x0400" substituted (remember, the preprocessor doesn't understand any syntax, it just blindly replaces strings). I think the assembler will probably be OK with that, it should be able to evaluate the expression.
What happens when there are multiple clock settings, one of them has a typo, or there is nothing?
I think so. The only concern I have is polluting the preprocessor macro space. I can't think of any reason off the top of my head why someone would complain about `stringize_` and `string_`.... but maybe something a little more cryptic to be sure? Maybe `__propgcc_stringize_` and `__propgcc_string_` to be sure?
I've used changes in clock settings in SimpleIDE to reduce battery power and for long wait times. For example with a set up that measures temperature, bar pressure, and humidity every 10 minutes and stores them to an SD card for later evaluation.
I have cog 0 enter a wait state after saving the data, setting pin 0 to 0, which causes two other cogs to sleep (waitpeq), but I can't sleep the SimpleIDE SD and ADC cogs, so I rely on lowering the clock to reduce power. After 10 minutes, cog 0 wakes, sets the clock back to 80 Meg, and sets P0 = 1, waking the waitpeq cogs.
Would your method allow this?
Tom
What David was showing was a way to set the initial clock mode and frequency. To change this at run time, use the clkset(mode, frequency) macro from propeller.h.