-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer0.asm
229 lines (179 loc) · 5.93 KB
/
timer0.asm
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
NAME TIMER0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; TIMER0 ;
; Timer0 Functions ;
; EE/CS 51 ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This file contains the functions to initialize and install the timer and event
; handler for the RoboTrike’s motors/laser
; Timer0EventHandler: Handles the timer interrupt and calls PWMHandler to
; change the values sent to port B of the target board
; which controls the motors/laser
; InitTimer0: initializes 80188 timer 0
; InstallTimer0EventHandler: Install event handler for timer interrupts
;
; Revision History:
; 11/7/2015 Anshul Ramachandran initial rev, func specs./pseudocodes
$INCLUDE(timer0.inc)
CGROUP GROUP CODE
CODE SEGMENT PUBLIC 'CODE'
ASSUME CS:CGROUP
; external function declarations
EXTRN PWMHandler:NEAR
; Timer0EventHandler
;
;
; Description: This procedure is the event handler for the timer 2 interrupt. It
; calls PWMHandler to handle sending the correct bits to port B
; of the target board, which controls the motors and laser of the
; RoboTrike
;
; Operation: Calls PWMHandler to handle sending the correct bits to port B
; of the target board, which controls the motors and laser of the
; RoboTrike and then sends out EOIs to signify end of the interrupt
; handler execution.
;
; Arguments: None.
;
; Return Values: None.
;
; Local Variables: None.
; Shared Variables: None.
; Global Variables: None.
;
; Input: None.
; Output: None.
;
; Error Handling: None.
;
; Registers Used: None.
;
; Algorithms: None.
; Data Structures: None.
;
; Known Bugs: None.
; Limitations: None.
;
; Revision History:
; 11/7/2015 Anshul Ramachandran func. spec. and pseudocode
Timer0EventHandler PROC NEAR
PUBLIC Timer0EventHandler
PUSH DX
PUSH AX
CALL PWMHandler ; Call PWM handling function, which sends
; the current motor/laser bit patterns to
; port B of the target board
MOV DX, INTCtrlrEOI ; Send timer EOI
MOV AX, TimerEOI
OUT DX, AL
POP AX
POP DX
IRET ; IRET must be used in interrupt handler
Timer0EventHandler ENDP
; InitTimer0
;
;
; Description: Initialize the 80188 timer #0. The interrupt controller
; is also initialized to allow the timer 0 interrupts.
;
; Operation: The appropriate values are written to the timer 0 control
; register in the PCB. Also, the timer 0 count registers
; are reset to zero. Finally, the interrupt controller is
; setup to accept timer interrupts and any pending
; interrupts are cleared by sending a TimerEOI to the
; interrupt controller.
;
; Arguments: None.
;
; Return Values: None.
;
; Local Variables: None.
; Shared Variables: None.
; Global Variables: None.
;
; Input: None.
; Output: None.
;
; Error Handling: None.
;
; Registers Used: AX, DX
;
; Algorithms: None.
; Data Structures: None.
;
; Known Bugs: None.
; Limitations: None.
;
; Revision History:
; 11/7/2015 Anshul Ramachandran func. spec. and pseudocode
InitTimer0 PROC NEAR
PUBLIC InitTimer0
PUSH DX
PUSH AX
MOV DX, Tmr0Count ;initialize the count register to 0
XOR AX, AX
OUT DX, AL
MOV DX, Tmr0MaxCnt ;setup max count for 1ms counts
MOV AX, CNT_32_MS
OUT DX, AL
MOV DX, Tmr0Ctrl ;setup the control register
MOV AX, Tmr0CtrlVal
OUT DX, AL
MOV DX, INTCtrlrCtrl;setup the interrupt control register
MOV AX, INTCtrlrCVal
OUT DX, AL
MOV DX, INTCtrlrEOI ;send an EOI to turn off any pending interrupts
MOV AX, TimerEOI
OUT DX, AL
POP AX
POP DX
RET ;done so return
InitTimer0 ENDP
; InstallTimer0EventHandler
;
;
; Description: Install event handler for the timer interrupt
;
; Operation: Write address of the timer event handler to the appropriate
; interrupt vector
;
; Arguments: None.
;
; Return Values: None.
;
; Local Variables: None.
; Shared Variables: None.
; Global Variables: None.
;
; Input: None.
; Output: None.
;
; Error Handling: None.
;
; Registers Used: flags, AX, ES
;
; Algorithms: None.
; Data Structures: None.
;
; Known Bugs: None.
; Limitations: None.
;
; Revision History:
; 11/7/2015 Anshul Ramachandran func. spec. and pseudocode
InstallTimer0EventHandler PROC NEAR
PUBLIC InstallTimer0EventHandler
PUSH AX
PUSH ES
XOR AX, AX ;clear ES (interrupt vectors are in segment 0)
MOV ES, AX
;store the vector
MOV ES: WORD PTR (4 * Tmr0Vec), OFFSET(Timer0EventHandler)
MOV ES: WORD PTR (4 * Tmr0Vec + 2), SEG(Timer0EventHandler)
POP ES
POP AX
RET ;all done, return
InstallTimer0EventHandler ENDP
CODE ENDS
END