What's the best way to wait for a lock with a timout in assembly?
Lawson
Posts: 870
I just started hacking together a few programs in assembly. (already liking Propeller assembly FAR better than SX assembly) I'm adding an assembly program to an existing application that uses a shared serial port protected by a lock. I've passed my assembly all the information it needs to work. As stated in the subject, I'm wondering what the best way to wait for a lock to be free or a timeout to occur is in assembly?
My current code is below, I'm concerned that It won't deal with wraparounds of CNT properly.
Thanks,
Marty
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Lunch cures all problems! have you had lunch?
Post Edited (Lawson) : 7/24/2008 10:00:00 PM GMT
My current code is below, I'm concerned that It won't deal with wraparounds of CNT properly.
:loop 'lots of code that we don't care about mov timeout, cnt 'mark the current CNT add timeout, wait_time 'move my mark far into the future :ck_lock cmp timeout, CNT wc 'is CNT greater than "timeout"? if_c jmp #:end_loop 'out of time, go to the end of the loop lockset xtx_lock wc 'check if the TX lock is free and set the lock if it is free if_c jmp #:ck_lock 'keep waiting till the lock is free . . . :end_loop jmp #:loop 'variables etc... xtx_lock long 0-0 wait_time long 11000 timeout res 1
Thanks,
Marty
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Lunch cures all problems! have you had lunch?
Post Edited (Lawson) : 7/24/2008 10:00:00 PM GMT
Comments
Note that this requires that the timeout period be less than 2^32
clock cycles (about 50 seconds at 80MHz).
Yes, a very important basic coding principle. It should be at the start of every beginner's programming book. It applies to a whole world of threshold logic.
This is a good example of the difference between the far too simplistic educational examples and that of a really useful tool.
Evan
Marty
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Lunch cures all problems! have you had lunch?