3 ; author: hackbard@hackdaworld.dyndns.org
10 ; vcc card --- atmel vcc
12 ; rst cam --- atmel int0 (pd2)
13 ; rst card --- atmel (pd4)
17 ; gnd card --- gnd cam --- atmel gnd
18 ; i/o card --- atmel icp (pd6)
19 ; i/o cam --- atmel int1 (pd3)
21 .include "../include/2313def.inc"
28 ; baudrate = clock freq / etu
29 ; std smartcard etu: 372
30 ; other smartcards: 625
33 .equ baudrate = 8 ; UBRR value for 57600 bits/s (8mhz clock)
36 .equ uart_data_len = 4
44 .def overflow_counter = r21
50 .def counter_l_tmp = r27
51 .def counter_h_tmp = r28
61 .equ STUPID = (1<<0) ; forward cam <-> card communication
63 .equ COOL = (1<<1) ; send time (clocks) & state via uart
65 .equ ELITE = (1<<2) ; create bytes, maybe even whole command arrays
67 .equ GODLIKE = (1<<3) ; filter and mask for commands to card - send rejected via uart only
69 .equ INCREDIBLE_HACK = (1<<4) ; destroy all your hardware
70 .equ INCREDIBLE_HACK_F = 5
74 .equ LED_FWD_TO_CAM = PB2
75 .equ LED_FWD_TO_CARD = PB3
76 .equ LED_OVERFLOW = PB4
78 ; but there is only stupid and cool mode right now %)
98 ; timer/counter capt 1
101 ; timer/counter compare
104 ; timer/counter overflow 1
107 ; timer/counter overflow 0
113 ; uart data register empty
128 ; output low on rst to card while init
136 ; enable interrupts int0,int1,sleep
137 ldi tmp,((1<<INT0)|(1<<INT1))
140 ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10)|(1<<SE))
143 ; enable t/c overflow interrupt and icp
144 ldi tmp,((1<<TOIE1)|(1<<TICIE))
147 ldi tmp,((1<<CS12)|(1<<CS11)|(1<<CS10)|(1<<ICNC1)|(0<<ICES1))
150 ; configure uart - interrupt enabled when i/o
160 ; enable pullups on int0, int1, clk, icp io ports
161 ldi tmp,((1<<PD2)|(1<<PD3)|(1<<PD5)|(1<<PD6))
164 ldi tmp,((1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4))
171 ldi overflow_counter,0
174 ldi state,HIGH ; .. as waiting for falling edge of start bit
176 ldi mode,(STUPID|COOL)
183 ; enable interrupts (global)
186 ; output high on rst to card
204 ; sleep/wait for next interrupt
233 rcall TOGGLE_ICP_SENSE
235 ; fwd to cam if in stupid mode
239 ; calculate delta clocks if in cool mode
241 rcall CALC_DELTA_CLOCK
243 ; send time and state via uart
250 ; ------------------------
251 ; calc_delta_clock routine
252 ; ------------------------
262 mov counter_l_tmp,counter_l
263 mov counter_h_tmp,counter_h
269 ; delta calc on host software by now
274 ; ------------------------
275 ; toggle_icp_sense routine
276 ; ------------------------
285 ; toggle according to state
288 sbrs state,HIGH ; maybe toggle according to TCCR1B?
307 sbi PORTB,LED_FWD_TO_CARD
308 cbi PORTB,LED_FWD_TO_CAM
310 ; disable external interrupt 1 while toggling edge
315 ; output state on port to cam
321 ; configure as output and push-pull low/high
325 ; reenable external interrupt 1
332 ; --------------------
333 ; prepare_uart routine
334 ; --------------------
343 ; write transfer data to sram
347 st Z+,overflow_counter
350 ; enable uart data register empty interrupt
368 ; first thing - pullup on
380 rcall TOGGLE_INT_SENSE
382 ; fwd to card if in stupid mode
386 ; calculate delta clocks if in cool mode
388 rcall CALC_DELTA_CLOCK
393 ; ------------------------
394 ; toggle_int_sense routine
395 ; ------------------------
413 ; -------------------
414 ; fwd_to_card routine
415 ; -------------------
425 sbi PORTB,LED_FWD_TO_CAM
426 cbi PORTB,LED_FWD_TO_CARD
428 ; disable icp interrupt while toggling edge
433 ; output state on port to card
439 ; configure as output and push-pull low/high
443 ; reenable icp interrupt
450 ; -------------------
451 ; t1_overflow routine
452 ; -------------------
461 ; increment counter overflow
462 add overflow_counter,one
465 mov tmp,overflow_counter
467 sbi PORTB,LED_OVERFLOW
469 cbi PORTB,LED_OVERFLOW
485 ; by now just jump to init
494 ; disable uart data register empty interrupt
512 ; read next byte from memmory and transfer via uart
516 ; return if everything was sent
517 cpi tmp,uart_data_len
528 ; wie macht man load mit autoinc richtig?
531 ; read byte from memory and write via uart
535 ; increment counter (maybe needed later)