]>
Commit | Line | Data |
---|---|---|
5985ce1c | 1 | ; Timer module |
9c15f366 | 2 | ; |
9c15f366 L |
3 | ; Copyright (C) 2010 Leo C. |
4 | ; | |
5 | ; This file is part of avrcpm. | |
6 | ; | |
7 | ; avrcpm is free software: you can redistribute it and/or modify it | |
8 | ; under the terms of the GNU General Public License as published by | |
9 | ; the Free Software Foundation, either version 3 of the License, or | |
10 | ; (at your option) any later version. | |
11 | ; | |
12 | ; avrcpm is distributed in the hope that it will be useful, | |
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ; GNU General Public License for more details. | |
16 | ; | |
17 | ; You should have received a copy of the GNU General Public License | |
18 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
19 | ; | |
b741422e | 20 | ; $Id$ |
9c15f366 L |
21 | ; |
22 | ||
9c15f366 L |
23 | .dseg |
24 | ||
de15c768 | 25 | timer_var: |
9c15f366 | 26 | delay_timer1: |
de15c768 | 27 | .equ ot_timer1 = delay_timer1-timer_var |
9c15f366 L |
28 | .byte 1 |
29 | delay_timer2: | |
de15c768 | 30 | .equ ot_timer2 = delay_timer2-timer_var |
9c15f366 L |
31 | .byte 1 |
32 | timer_base: | |
33 | timer_ms: | |
de15c768 | 34 | .equ ot_ms = timer_ms-timer_var |
9c15f366 | 35 | .byte 2 |
de15c768 L |
36 | timer_sec: |
37 | .equ ot_sec = timer_sec-timer_var | |
9c15f366 | 38 | .byte 4 |
de15c768 | 39 | |
9c15f366 L |
40 | ; don't change order here, clock put/get depends on it. |
41 | cntms_out: ; register for ms | |
42 | .byte 2 | |
43 | utime_io: ; register for uptime. | |
44 | .byte 4 | |
45 | cnt_1ms: | |
de15c768 | 46 | .equ ot_1ms = cnt_1ms-timer_var |
9c15f366 L |
47 | .byte 2 |
48 | uptime: | |
de15c768 | 49 | .equ ot_uptime = uptime-timer_var |
9c15f366 L |
50 | .byte 4 |
51 | timer_top: | |
52 | .equ timer_size = timer_top - timer_base | |
53 | ||
fb050095 | 54 | .equ utofs = cnt_1ms-cntms_out |
9c15f366 L |
55 | .equ timerofs = cnt_1ms-timer_ms |
56 | ||
fb050095 | 57 | clk_out: |
de15c768 | 58 | .equ oclk_out = clk_out-timer_var |
d8fa6a36 | 59 | .byte 7 ; |
fb050095 | 60 | clock: |
de15c768 | 61 | .equ o_clock = clock-timer_var |
d8fa6a36 | 62 | .byte 7 ;Format (bin): s m h D M YY |
fb050095 L |
63 | .equ clkofs = clock-clk_out |
64 | ||
9c15f366 | 65 | .cseg |
9c15f366 | 66 | |
5985ce1c L |
67 | ; ------------- system timer 1ms --------------- |
68 | ||
69 | ||
4675c141 L |
70 | ; Timer/Counter1 Compare Match B interrupt |
71 | ||
72 | INTERRUPT OC1Baddr | |
de15c768 L |
73 | |
74 | .if TIMER_DEBUG | |
75 | cbi PORTC,5 | |
76 | .endif | |
9c15f366 L |
77 | push zl |
78 | in zl,SREG | |
79 | push zl | |
80 | push zh | |
81 | inm8 zl,OCR1BL | |
82 | inm8 zh,OCR1BH | |
83 | addiw z,F_CPU/1000 | |
84 | outm8 OCR1BH,zh | |
85 | outm8 OCR1BL,zl | |
86 | ||
de15c768 L |
87 | push yl |
88 | push yh | |
89 | ldiw y,timer_var | |
90 | ||
9c15f366 | 91 | #if DRAM_8BIT /* Implies software uart */ |
d8fa6a36 | 92 | lds zl,srx_char_to ;try to decrement character timout |
9c15f366 | 93 | subi zl,1 |
d8fa6a36 L |
94 | brcs syscl0 ;timer was 0 before (not running) |
95 | sts srx_char_to,zl ;timer is running, store new value | |
96 | brne syscl0 | |
9c15f366 L |
97 | rcall srx_to |
98 | syscl0: | |
99 | #endif | |
de15c768 | 100 | ldd zl,y+ot_timer1 |
9c15f366 L |
101 | subi zl,1 |
102 | brcs syscl_t1n | |
de15c768 | 103 | std y+ot_timer1,zl |
9c15f366 | 104 | syscl_t1n: |
de15c768 | 105 | ldd zl,y+ot_timer2 |
9c15f366 L |
106 | subi zl,1 |
107 | brcs syscl_t2n | |
de15c768 | 108 | std y+ot_timer2,zl |
d8fa6a36 L |
109 | syscl_t2n: |
110 | ||
de15c768 L |
111 | ldd zl,y+ot_1ms ;count milli seconds |
112 | ldd zh,y+ot_1ms+1 | |
9c15f366 | 113 | adiw z,1 |
de15c768 L |
114 | std y+ot_1ms,zl |
115 | std y+ot_1ms+1,zh | |
d8fa6a36 L |
116 | cpi zl,low(1000) ;one second ? |
117 | ldi zl,high(1000) ;doesn't change flags | |
9c15f366 | 118 | cpc zh,zl |
de15c768 L |
119 | brlt syscl_end |
120 | ; brge syscl_utime | |
121 | ; rjmp syscl_end | |
fb050095 L |
122 | |
123 | syscl_utime: | |
de15c768 L |
124 | std y+ot_1ms,_0 |
125 | std y+ot_1ms+1,_0 | |
9c15f366 | 126 | |
de15c768 L |
127 | ldd zl,y+ot_uptime+0 |
128 | ldd zh,y+ot_uptime+1 | |
129 | adiw z,1 | |
130 | std y+ot_uptime+0,zl | |
131 | std y+ot_uptime+1,zh | |
fb050095 | 132 | brne syscl_clk |
de15c768 L |
133 | ldd zl,y+ot_uptime+2 |
134 | ldd zh,y+ot_uptime+3 | |
135 | adiw z,1 | |
136 | std y+ot_uptime+2,zl | |
137 | std y+ot_uptime+3,zh | |
fb050095 L |
138 | |
139 | syscl_clk: | |
de15c768 | 140 | ldd zl,y+o_clock+0 ;sec |
fb050095 | 141 | inc zl |
de15c768 | 142 | std y+o_clock+0,zl |
fb050095 | 143 | cpi zl,60 |
de15c768 L |
144 | brlo syscl_end |
145 | std y+o_clock+0,_0 | |
146 | ldd zl,y+o_clock+1 ;min | |
fb050095 | 147 | inc zl |
de15c768 | 148 | std y+o_clock+1,zl |
fb050095 L |
149 | cpi zl,60 |
150 | brlo syscl_end | |
de15c768 L |
151 | std y+o_clock+1,_0 |
152 | ldd zl,y+o_clock+2 ;hour | |
fb050095 | 153 | inc zl |
de15c768 | 154 | std y+o_clock+2,zl |
fb050095 | 155 | cpi zl,24 |
de15c768 | 156 | brlo syscl_end |
d8fa6a36 L |
157 | |
158 | syscl_clk_date: | |
de15c768 | 159 | std y+o_clock+2,_0 |
fb050095 L |
160 | push temp |
161 | ||
162 | ldiw z,dayspm_tab*2 - 1 | |
de15c768 | 163 | ldd temp,y+o_clock+4 ;month |
fb050095 L |
164 | add zl,temp |
165 | adc zh,_0 | |
166 | lpm zh,z ;days this month | |
167 | cpi temp,2 | |
d8fa6a36 | 168 | brne syscl_clknl ;february, may be leap year |
de15c768 | 169 | ldd zl,y+o_clock+5 ;year |
d8fa6a36 | 170 | andi zl,0x03 |
fb050095 L |
171 | brne syscl_clknl |
172 | inc zh ;leap year | |
173 | syscl_clknl: | |
de15c768 | 174 | ldd zl,y+o_clock+3 ;day |
fb050095 | 175 | inc zl |
de15c768 | 176 | std y+o_clock+3,zl |
fb050095 L |
177 | cp zh,zl |
178 | brsh syscl_clke | |
179 | ldi zl,1 | |
de15c768 | 180 | std y+o_clock+3,zl |
fb050095 | 181 | inc temp ;month |
de15c768 | 182 | std y+o_clock+4,temp |
fb050095 L |
183 | cpi temp,13 |
184 | brlo syscl_clke | |
185 | ||
de15c768 L |
186 | std y+o_clock+4,zl |
187 | ldd zl,y+o_clock+5 ;low year | |
188 | ldd zh,y+o_clock+6 ;high year | |
189 | adiw z,1 | |
190 | std y+o_clock+5,zl | |
191 | std y+o_clock+6,zh | |
fb050095 L |
192 | |
193 | syscl_clke: | |
194 | pop temp | |
9c15f366 | 195 | syscl_end: |
de15c768 L |
196 | pop yh |
197 | pop yl | |
9c15f366 L |
198 | pop zh |
199 | pop zl | |
200 | out SREG,zl | |
201 | pop zl | |
de15c768 L |
202 | .if TIMER_DEBUG |
203 | sbi PORTC,5 | |
204 | .endif | |
9c15f366 L |
205 | reti |
206 | ||
fb050095 L |
207 | ; days per month |
208 | ||
209 | dayspm_tab: | |
210 | .db 31,28,31,30,31,30 | |
211 | .db 31,31,30,31,30,31 | |
212 | ||
5985ce1c L |
213 | ; ---------------------------------------------- |
214 | ; delay | |
215 | ; | |
9c15f366 | 216 | ; wait for temp ms |
5985ce1c | 217 | ; |
9c15f366 L |
218 | |
219 | delay_ms: | |
220 | sts delay_timer1,temp | |
221 | dly_loop: | |
222 | lds temp,delay_timer1 | |
223 | cpi temp,0 | |
224 | brne dly_loop | |
225 | ret | |
226 | ||
5985ce1c | 227 | ; ---------------------------------------------- |
9c15f366 | 228 | ; |
9c15f366 | 229 | clockget: |
fb050095 | 230 | ldiw z,clk_out |
d8fa6a36 | 231 | tst temp3 |
9c15f366 | 232 | breq clkget_copy ;lowest byte requestet, latch clock |
9c15f366 | 233 | |
d8fa6a36 | 234 | add zl,temp3 |
fb050095 | 235 | adc zh,_0 |
9c15f366 L |
236 | ld temp,z |
237 | clkget_end: | |
238 | ret | |
239 | ||
d8fa6a36 | 240 | |
9c15f366 | 241 | clkget_copy: |
d8fa6a36 | 242 | ldi temp3,7 |
9c15f366 L |
243 | cli |
244 | clkget_l: | |
245 | ldd temp,z+clkofs | |
246 | st z+,temp | |
d8fa6a36 | 247 | dec temp3 |
9c15f366 L |
248 | brne clkget_l |
249 | sei | |
d8fa6a36 L |
250 | |
251 | ld temp2,-z | |
252 | ld temp, -z | |
253 | rcall binbcd4 | |
254 | std z+0,temp | |
255 | std z+1,temp2 | |
256 | ldi temp3,5 | |
257 | clkget_l2: | |
258 | ld temp,-z | |
259 | rcall binbcd2 | |
260 | st z,temp | |
261 | dec temp3 | |
262 | brne clkget_l2 | |
263 | ||
fb050095 | 264 | lds temp,clk_out |
d8fa6a36 | 265 | ret ;req. byte in temp |
9c15f366 | 266 | |
d8fa6a36 L |
267 | ; ---------------------------------------------- |
268 | ; | |
9c15f366 | 269 | clockput: |
fb050095 | 270 | ldiw z,clk_out |
d8fa6a36 | 271 | add zl,temp3 |
fb050095 L |
272 | adc zh,_0 |
273 | st z,temp | |
d8fa6a36 L |
274 | tst temp3 |
275 | breq clkput_copy ;lowest byte stored, latch clock | |
fb050095 | 276 | clkput_end: |
fb050095 L |
277 | ret |
278 | ||
d8fa6a36 | 279 | |
fb050095 | 280 | clkput_copy: |
d8fa6a36 L |
281 | ldi temp3,5 |
282 | clkput_l2: | |
283 | ld temp,z | |
284 | rcall bcdbin2 | |
285 | st z+,temp | |
286 | dec temp3 | |
287 | brne clkput_l2 | |
288 | ||
289 | ldd temp,z+0 | |
290 | ldd temp2,z+1 | |
291 | rcall bcdbin4 | |
292 | st z+,temp | |
293 | st z+,temp2 | |
294 | ||
295 | ldi temp3,7 | |
fb050095 L |
296 | cli |
297 | clkput_l: | |
d8fa6a36 L |
298 | ld temp,-z |
299 | std z+clkofs,temp | |
300 | dec temp3 | |
fb050095 L |
301 | brne clkput_l |
302 | sei | |
825ecc9d | 303 | #if I2C_SUPPORT |
d8fa6a36 L |
304 | rcall rtc_set ; set hardware clock |
305 | #endif | |
fb050095 L |
306 | ret |
307 | ||
d8fa6a36 L |
308 | |
309 | ; ---------------------------------------------- | |
310 | ||
311 | ; convert binary to bcd | |
312 | ; (only range 0 - 99) | |
313 | ||
314 | binbcd2: | |
315 | push temp2 | |
316 | ldi temp2,10 | |
317 | mov _tmp0,_255 | |
318 | tobcd_l: | |
319 | inc _tmp0 | |
320 | sub temp,temp2 | |
321 | brcc tobcd_l | |
322 | add temp,temp2 | |
323 | swap _tmp0 | |
324 | add temp,_tmp0 | |
325 | pop temp2 | |
326 | ret | |
327 | ||
328 | ||
329 | binbcd4: | |
330 | ldi temp3,16 | |
623dd899 | 331 | movw _tmp0,temp |
d8fa6a36 L |
332 | clr temp |
333 | clr temp2 | |
334 | binbcd4l: | |
335 | lsl _tmp0 | |
336 | rol _tmp1 | |
337 | rol temp | |
338 | rol temp2 | |
339 | dec temp3 | |
340 | breq binbcd4e | |
341 | ||
342 | subi temp2,-0x03 | |
343 | sbrs temp2,3 | |
344 | subi temp2,0x03 | |
345 | subi temp2,-0x30 | |
346 | sbrs temp2,7 | |
347 | subi temp2,0x30 | |
348 | subi temp,-0x03 | |
349 | sbrs temp,3 | |
350 | subi temp,0x03 | |
351 | subi temp,-0x30 | |
352 | sbrs temp,7 | |
353 | subi temp,0x30 | |
354 | rjmp binbcd4l | |
355 | ||
356 | binbcd4e: | |
357 | ret | |
358 | ||
359 | ; convert bcd to binary | |
360 | ||
361 | bcdbin2: | |
362 | push temp2 | |
363 | mov temp2,temp ;temp2 = high digit | |
364 | swap temp2 | |
365 | andi temp2,0x0f | |
366 | andi temp,0x0f ;temp = low digit | |
825ecc9d | 367 | mov r0,temp2 |
d8fa6a36 | 368 | ldi temp2,10 |
825ecc9d L |
369 | mul temp2,r0 ;high digit * 10 |
370 | add temp,r0 ;high digit * 10 + low digit | |
d8fa6a36 L |
371 | pop temp2 |
372 | ret | |
373 | ||
374 | bcdbin4: | |
375 | rcall bcdbin2 | |
376 | push temp | |
377 | mov temp,temp2 | |
378 | rcall bcdbin2 | |
379 | ldi temp2,100 | |
380 | mul temp,temp2 | |
381 | pop temp | |
825ecc9d L |
382 | mov temp2,r1 |
383 | add temp,r0 | |
d8fa6a36 L |
384 | adc temp2,_0 |
385 | ret | |
386 | ||
387 | ||
825ecc9d | 388 | #if I2C_SUPPORT |
d8fa6a36 L |
389 | |
390 | ; ---------------------------------------------- | |
391 | ; Set software clock from hardware clock | |
392 | ||
393 | rtc_get: | |
394 | push _0 ;Placeholder for month/weekday | |
395 | push _0 ;day/year | |
396 | push _0 ;hours | |
397 | push _0 ;minutes | |
398 | ldi temp,0x10 ;register address | |
399 | push temp ;save reg adr/placeholder for sec | |
400 | in zh,sph | |
401 | in zl,spl | |
402 | ldi temp,0xA0 ;PCF8583 slave address | |
403 | push temp | |
404 | ||
405 | ldi temp2,2 | |
406 | rcall i2c_write | |
407 | ldi temp2,3 | |
408 | rcall i2c_read ;get year (stored in RTC-RAM addr. 10h) | |
409 | tst temp | |
79986122 | 410 | brmi rtc_get_e ;i2c error |
d8fa6a36 L |
411 | |
412 | ldd temp3,z+1 ;save year | |
825ecc9d | 413 | ldd xl, z+2 |
d8fa6a36 L |
414 | |
415 | ldi temp2,2 ;register pointer. 2 = secs | |
416 | std z+1,temp2 | |
417 | rcall i2c_write | |
418 | ldi temp2,6 | |
419 | rcall i2c_read | |
420 | tst temp | |
79986122 | 421 | brmi rtc_get_e |
d8fa6a36 | 422 | |
825ecc9d | 423 | mov temp2,xl ;year century |
d8fa6a36 L |
424 | ldd temp,z+4 ;get year |
425 | rol temp | |
426 | rol temp | |
427 | rol temp | |
428 | eor temp,temp3 | |
429 | andi temp,0x03 | |
430 | breq rtc_get_1 | |
825ecc9d L |
431 | subi temp3, low(-1) |
432 | sbci temp2, high(-1) | |
d8fa6a36 L |
433 | rtc_get_1: |
434 | ldiw x,clock | |
435 | cli | |
436 | ||
437 | ldd temp,z+1 ;get seconds | |
438 | rcall bcdbin2 | |
439 | st x+,temp | |
440 | ldd temp,z+2 ;get minutes | |
441 | rcall bcdbin2 | |
442 | st x+,temp | |
443 | ldd temp,z+3 ;get hours | |
444 | rcall bcdbin2 | |
445 | st x+,temp | |
446 | ldd temp,z+4 ;get day | |
447 | andi temp,0x3f | |
448 | rcall bcdbin2 | |
449 | st x+,temp | |
450 | ldd temp,z+5 ;get months | |
451 | andi temp,0x1f | |
452 | rcall bcdbin2 | |
453 | st x+,temp ;store month | |
454 | st x+,temp3 ;store year | |
825ecc9d | 455 | st x+,temp2 ;store year century |
d8fa6a36 L |
456 | sei |
457 | ||
458 | rtc_get_e: | |
459 | pop temp | |
460 | pop temp | |
461 | pop temp | |
462 | pop temp | |
463 | pop temp | |
464 | pop temp | |
465 | ret | |
466 | ||
467 | ;---------------------------------------------- | |
468 | ; Set hardware clock from software clock | |
469 | ; | |
470 | ; Register: temp2: s | |
471 | ; temp3: m | |
825ecc9d | 472 | ; xh: h |
d8fa6a36 L |
473 | ; xl: D |
474 | ; temp: M | |
475 | ; yl: Yl | |
476 | ; yh: Yh | |
477 | ||
478 | rtc_set: | |
479 | ldiw z,clock | |
480 | cli | |
481 | ldd temp2,z+0 ;sec | |
482 | ldd temp3,z+1 ;min | |
825ecc9d | 483 | ldd xh,z+2 ;hours |
d8fa6a36 L |
484 | ldd xl,z+3 ;day |
485 | ldd temp,z+4 ;month | |
486 | ldd yl,z+5 ;yearl | |
487 | ldd yh,z+6 ;yearh | |
488 | sei | |
489 | rcall binbcd2 | |
490 | push temp ;-1 save month | |
491 | mov temp,xl | |
492 | rcall binbcd2 | |
493 | mov xl,yl ; least significant 2 bits of year | |
494 | swap xl | |
495 | lsl xl | |
496 | lsl xl | |
497 | andi xl,0xc0 | |
498 | or temp,xl ; combine with day | |
499 | push temp ;-2 save year/day | |
825ecc9d | 500 | mov temp,xh |
d8fa6a36 L |
501 | rcall binbcd2 |
502 | push temp ;-3 save hours | |
503 | mov temp,temp3 | |
504 | rcall binbcd2 | |
505 | push temp ;-4 save min | |
506 | mov temp,temp2 | |
507 | rcall binbcd2 | |
508 | push temp ;-5 save sec | |
509 | ||
510 | push _0 ;-6 1/10s, 1/100s | |
511 | ldi temp,0x84 ; stop count, alarm enable | |
512 | push temp ;-7 | |
513 | push _0 ;-8 register address | |
514 | in zh,sph | |
515 | in zl,spl | |
516 | ldi temp,0xA0 ; PCF8583 slave address | |
517 | push temp ;(-9) | |
518 | ||
519 | ldi temp2,9 | |
520 | rcall i2c_write | |
521 | ldi temp,0x04 ;enable counting | |
522 | std z+2,temp | |
523 | ldi temp2,3 | |
524 | rcall i2c_write | |
525 | std z+3,yh ;store year in RTC RAM | |
526 | std z+2,yl | |
527 | ldi temp,0x10 | |
528 | std z+1,temp | |
529 | ldi temp2,4 | |
530 | rcall i2c_write | |
531 | ||
532 | addiw z,8 ;remove buffer from stack | |
533 | cli | |
534 | out spl,zl | |
535 | sei | |
536 | out sph,zh | |
537 | ||
538 | ret | |
825ecc9d | 539 | #endif /* I2C_SUPPORT */ |
d8fa6a36 | 540 | |
fb050095 L |
541 | ; ---------------------------------------------- |
542 | ; | |
543 | ||
544 | utimeget: | |
545 | ldi temp,0xFF | |
fb050095 | 546 | ldiw z,cntms_out |
de15c768 L |
547 | subi temp3,1 |
548 | brcs utimget_end ;Rel. port number = 0 ? (controlport) | |
fb050095 | 549 | breq utimget_copy ;lowest byte requestet, latch clock |
fb050095 | 550 | |
de15c768 | 551 | add zl,temp3 |
fb050095 L |
552 | adc zh,_0 |
553 | ld temp,z | |
554 | utimget_end: | |
555 | ret | |
556 | ||
fb050095 L |
557 | utimget_copy: |
558 | ldi temp2,6 | |
559 | cli | |
560 | utimget_l: | |
561 | ldd temp,z+utofs | |
562 | st z+,temp | |
563 | dec temp2 | |
564 | brne utimget_l | |
565 | sei | |
566 | lds temp,cntms_out | |
567 | ;req. byte in temp | |
568 | ret | |
569 | ||
570 | utimeput: | |
de15c768 L |
571 | subi temp3,1 |
572 | brcc utput__1 | |
9c15f366 L |
573 | |
574 | ; clock control | |
575 | ||
576 | cpi temp,starttimercmd | |
de15c768 | 577 | breq timer_start ;timer_ms |
9c15f366 | 578 | cpi temp,quitTimerCmd |
de15c768 | 579 | breq utput_quit ; |
9c15f366 | 580 | cpi temp,printTimerCmd |
de15c768 | 581 | breq timer_print ;timer_ms |
9c15f366 | 582 | cpi temp,uptimeCmd |
fb050095 | 583 | brne utcp_ex |
de15c768 | 584 | rjmp uptime_print ;cnt_1ms |
fb050095 | 585 | utcp_ex: |
9c15f366 L |
586 | ret |
587 | ||
fb050095 | 588 | utput_quit: |
9c15f366 L |
589 | rcall timer_print |
590 | rjmp timer_start | |
591 | ||
fb050095 | 592 | utput__1: |
9c15f366 | 593 | ldiw z,cntms_out |
fb050095 | 594 | breq utput__copy ;lowest byte requestet, latch clock |
9c15f366 | 595 | |
de15c768 L |
596 | add zl,temp3 |
597 | adc zh,_0 | |
9c15f366 | 598 | st z,temp |
9c15f366 L |
599 | ret |
600 | ||
fb050095 | 601 | utput__copy: |
9c15f366 L |
602 | st z,temp |
603 | adiw z,5 | |
604 | ldi temp2,6 | |
605 | cli | |
fb050095 L |
606 | utput__l: |
607 | ldd temp,z+utofs | |
9c15f366 L |
608 | st z+,temp |
609 | dec temp2 | |
fb050095 | 610 | brne utput__l |
9c15f366 L |
611 | sei |
612 | ret | |
613 | ||
614 | ; start/reset timer | |
615 | ; | |
616 | timer_start: | |
617 | ldiw z,timer_ms | |
618 | ldi temp2,6 | |
619 | cli | |
620 | ts_loop: | |
621 | ldd temp,z+timerofs | |
622 | st z+,temp | |
623 | dec temp2 | |
624 | brne ts_loop | |
625 | sei | |
626 | ret | |
627 | ||
628 | ||
629 | ; print timer | |
630 | ; | |
631 | ||
632 | timer_print: | |
825ecc9d L |
633 | push r15 ; |
634 | push r14 ; | |
9c15f366 L |
635 | push yh |
636 | push yl | |
637 | ldiw z,timer_ms | |
638 | ||
639 | ; put ms on stack (16 bit) | |
640 | ||
641 | cli | |
642 | ldd yl,z+timerofs | |
643 | ld temp2,z+ | |
644 | sub yl,temp2 | |
645 | ldd yh,z+timerofs | |
646 | ld temp2,z+ | |
647 | sbc yh,temp2 | |
648 | brsh tp_s | |
649 | ||
650 | addiw y,1000 | |
651 | sec | |
652 | tp_s: | |
653 | push yh | |
654 | push yl | |
655 | ||
656 | ldd temp,z+timerofs | |
657 | ld yl,z+ | |
658 | sbc temp,yl | |
659 | ||
660 | ldd temp2,z+timerofs | |
661 | ld yh,z+ | |
662 | sbc temp2,yh | |
663 | ||
825ecc9d | 664 | ldd r14,z+timerofs |
9c15f366 | 665 | ld yl,z+ |
825ecc9d | 666 | sbc r14,yl |
9c15f366 L |
667 | |
668 | sei | |
825ecc9d | 669 | ldd r15,z+timerofs |
9c15f366 | 670 | ld yh,z+ |
825ecc9d | 671 | sbc r15,yh |
9c15f366 L |
672 | |
673 | printnewline | |
674 | printstring "Timer running. Elapsed: " | |
675 | rcall print_ultoa | |
676 | ||
677 | printstring "." | |
678 | pop temp | |
679 | pop temp2 | |
825ecc9d L |
680 | clr r14 |
681 | clr r15 | |
9c15f366 L |
682 | rcall print_ultoa |
683 | printstring "s." | |
684 | ||
685 | pop yl | |
686 | pop yh | |
825ecc9d L |
687 | pop r14 |
688 | pop r15 | |
9c15f366 L |
689 | ret |
690 | ||
691 | uptime_print: | |
825ecc9d L |
692 | push r15 |
693 | push r14 | |
9c15f366 | 694 | ldiw z,cnt_1ms |
9c15f366 L |
695 | cli |
696 | ld temp,z+ | |
697 | push temp | |
698 | ld temp,z+ | |
699 | push temp | |
700 | ||
701 | ld temp,z+ | |
702 | ld temp2,z+ | |
825ecc9d | 703 | ld r14,z+ |
9c15f366 | 704 | sei |
825ecc9d | 705 | ld r15,z+ |
9c15f366 L |
706 | |
707 | printnewline | |
708 | printstring "Uptime: " | |
709 | ||
710 | rcall print_ultoa | |
711 | printstring "," | |
712 | ||
825ecc9d L |
713 | clr r14 |
714 | clr r15 | |
9c15f366 L |
715 | pop temp2 |
716 | pop temp | |
717 | rcall print_ultoa | |
718 | printstring "s." | |
719 | ||
825ecc9d L |
720 | pop r14 |
721 | pop r15 | |
9c15f366 L |
722 | ret |
723 | ||
5985ce1c | 724 | ; vim:set ts=8 noet nowrap |
9c15f366 | 725 |