Introduction #
For customers writing PASM2 only programs, the compiler automatically prepends a clock-setter function to the code so that the system clock settings are automatically calculated and configured without the need for user configuration. It just works!
If you don't have an issue with code space, you probably can ignore the rest of this article, and forget all about asmclk!
The compiler handles the heavy lifting and complicated configuration for you!
But if you do come across some example code that includes the
asmclk
instruction at the top of aDAT
block... you might be interested to know what it is for!
How to disable the clock setter #
There might be an occasion where the user wants to avoid the overhead of the start-up clock setter, and instead add the configuration inline with their PASM2 code.
The Propeller 2 asmclk
instruction provides a way to setup the system clock "inline", based on the constant _clkfreq that's set in your code file, rather than by prepending the clock-setter.
To make use of asmclk
, you must define a special constant _AUTOCLK=0
to disable the prepended clock setter; and in which case you MUST use asmclk
(or apply manual clock settings to the appropriate registers).
What impact does the automatic clock-setter have? #
The pre-pended clock-setter uses 16 longs, and executes in milliseconds each boot up time. The total time will vary based on the length of user code. For each long in user code, the boot up sequence of the clock-setter takes 2 clocks (1 read, 1 write). After the clock-setter executes and configures the clock, it then copies the blocks of user code from memory into LUT, then blows them out into the new location. Essentially the user code is shifted up by 64 bytes (16 longs) in memory, to override the space previously taken up by the small clock-setter program.
This behaviour can explain the reason for certain code needing a way to disable this process. One obvious example is where the user code fills the entire memory, and doesn't have space even for the temporary 64 byte requirements of the clock-setter. In this case, the user could use the _AUTOCLK
constant to disable the clock-setter, and instead add the asmclk
command at the top of their PASM2 code.
Code Snippet #
' *** CLOCK SETTER
' *** Sets clock mode, moves application into position, then executes it.
DAT org
'
'
' Set clock mode if externally driven
'
ext1 hubset _clkmode1_ '@000: start external clock, remain in rcfast mode
ext2 waitx tenms '@004: allow 10ms for external clock to stabilize
ext3 hubset _clkmode2_ '@008: switch to external clock mode
'
'
' Move application down to $00000+
'
mov ptra,#@app_start
mov ptrb,#0
rep #4,_appblocks_
setq2 #$200-1
rdlong 0,ptra++
setq2 #$200-1
wrlong 0,ptrb++
'
'
' Set clock mode if RC_SLOW
'
rcslow hubset #1 '@028: start external clock, remain in rcfast mode
'
'
' Relaunch cog 0 from $00000
'
coginit #0,#$00000
'
'
' Data set by the compiler
'
tenms long 20_000_000 / 100 '10ms in rcfast
_clkmode1_ long 0 '@034: clkmode with rcfast
_clkmode2_ long 0 '@038: clkmode with external clock
_appblocks_ long 0 '@03C: application size in blocks of $200 longs
'
'
' Application start
'
app_start 'append application bytes after this label
Resources #
Parallax Propeller 2 - Spin2 Language Documentation