-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwa0uwh_Lock_01.spin
149 lines (120 loc) · 3.07 KB
/
wa0uwh_Lock_01.spin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
CON
{{
WA0UWH - Lock Object
FileName: wa0uwh_Lock_01.spin
Author: Eldon R. Brown - WA0UWH
Date: Jun 11, 2011
Rev: 0.01
}}
CON
WMin = 381
CLKSRC = 1 *2 'Comment out the "*2" for 5MHz Cystal, UnComment for 10MHz TCVCXO
_CLKMODE = XTAL1 * CLKSRC * CLKSRC + PLL16X / CLKSRC
_XINFREQ = 5_000_000 * CLKSRC
CON
#16, LCD_RS, LCD_RW, LCD_E, LCD_BL
#12, LCD_DB4, LCD_DB5, LCD_DB6, LCD_DB7
#16, LCD_COLS
#2, LCD_ROWS
CON
#(-1), LNEW, LCLR, LSET, LSTP, LCHK
CON
DAT 'DEMO
{' To Run Demo, Comment this line out with a single quote
OBJ 'DEMO, Needed for DEMO only
'DSP1 : "wa0uwh_DSPL_01" 'Can NOT be used as it would be recursive
DSP1 : "jm_lcd4_ez"
PUB Demo | LocKey, DspKey, i, j, k
DspKey := 0
DspKey := StartLock(locknew+1)
'DspKey := DSP1.StartPAR(locknew+1, 16, 2 )
DspKey := DSP1.Startx(LCD_BL,LCD_E,LCD_RW,LCD_RS,LCD_DB4,LCD_COLS,LCD_ROWS)
DSP1.Cmd(DSP1#CLS)
DSP1.BLon
j := i := -1 'Loop Counters
DSP1.Cmd(DSP1#CLS)
DSP1.Str(string("DEBUG"))
Lock)
DSP1.Cmd(DSP1#CLS)
DSP1.Str(string("Lock Demo:"))
Unlock
if True
pauseSec(1)
'lock
Lock
DSP1.moveto(1,2)
DSP1.Str(string("DK="))
DSP1.Dec(DspKey)
DSP1.Str(string(", "))
DSP1.Str(string("LK="))
'DSP1.Dec(GetLockNum)
DSP1.Dec(LockCheck)
Unlock
'Hang
repeat
waitcnt(cnt)
'}
DAT
'{
PUB LCMD(mode) 'A new Idea for locks
case mode
LNEW: return LockNum := locknew + 1
LCLR: return unLock
LSET: return Lock
LSTP: return Stop
LCHK: return GetLockStat
'}
VAR 'LOCKS
Long LockNum, LockOwner 'Static Variable
PUB StartLock(num) | okay
{{
Initialize LOCKs,
Processor provided Lock 'num' (1 - 8) to be use for sharing resources.
This Lock is used to prevent multiple COGs from mangling resources
Use -1 to request a new lock number.
}}
LockNum := num
if LockNum < 0
LockNum := locknew + 1
if lockNum > 0
LockOwner := True
return LockNum
PUB Stop
if LockNum > 0
if LockOwner
lockret(LockNum - 1)
LockNum := -1
return LockNum
DAT
PUB Lock 'Lock for I2C Bus
if LockNum > 0
repeat while RESULT := lockset(LockNum - 1)
return
PUB UnLock
if LockNum > 0
RESULT := lockclr(LockNum - 1)
return
PUB GetLockStat
{{
THIS MAY NOT WORK AS PLANNED - MORE WORK NEEDED
Returns:
-1 == Lock does not exist
0 == Lock is Clear
1 == Lock is Set
}}
RESULT := -1
if LockNum > 0
if RESULT := ||lockset(LockNum - 1)
Lockclr(LockNum - 1)
return
PUB GetLockNum
return LockNum
VAR 'Simple DEBUG Return Value
PUB DeBug
return LockNum 'Change this to anything of DEBUG interest !
VAR 'PAUSE
Pri PauseSec(sec)
PauseMS(1000 * sec)
Pri PauseMS(ms)
waitcnt(((clkfreq / 1_000 * ms - 3932) #> WMin) + cnt)
VAR 'END