X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=beginners%2Fseason_junior.asm;h=703b29fbe203ed2bcd020c27a2e256022968822b;hb=db9964b83523d6892548d2e55cbfede35c33d473;hp=94ba21c6ccf34330ea351fc4b7e798329e8d8213;hpb=448a02069232f473cbdde6b2aa698d062bd3876a;p=my-code%2Fatmel.git diff --git a/beginners/season_junior.asm b/beginners/season_junior.asm index 94ba21c..703b29f 100644 --- a/beginners/season_junior.asm +++ b/beginners/season_junior.asm @@ -6,37 +6,108 @@ ; at90s2313 ; setup: -; vcc card --- vcc cam -; rst card --- rst cam --- atmel t0 (pd4) -; clk card --- clk cam --- atmel t1 (pd5) +; vcc card --- atmel vcc +; vcc cam --- +; rst cam --- atmel int0 (pd2) +; rst card --- atmel (pd4) +; clk card -\ +; - atmel t1 (pd5) +; clk cam -/ ; gnd card --- gnd cam --- atmel gnd -; i/o card --- atmel int0 (pd2) +; i/o card --- atmel icp (pd6) ; i/o cam --- atmel int1 (pd3) -include "../include/2313def.inc" - +.include "../include/2313def.inc" +; functions by now: ; -; interrupt vectors: +; stupid mode only by now. just see what cam/card do and redirect +; this to card/cam. +; +; next implementation: +; +; try to read one byte of card/cam communication and output via uart. +; output time information in some way. ; +; future: +; +; buffer/parse whole strings and decide whether to send to card or not. + +; ####### +; defines +; ####### + +; baudrate = clock freq / etu +; std smartcard etu: 372 +; other smartcards: 625 +.define clock 8000000 +.define clk_h 4000000 +.define etu 625 +.define etu_h 312 +.define baudrate 5 ; UBRR value for 76800 bits/s (8mhz clock) + +; names for registers +.define tmp r16 +.define bitcount r17 +.define tmp1 r18 +.define tmp2 r19 +.define byte r20 +.define overflow_counter r21 +.define counter_l r22 +.define counter_h r23 +.define state r24 +.define state_m r25 +.define mode r26 +.define counter_l_tmp r27 +.define counter_h_tmp r28 +.define one r1 +.define zero r0 + +; state +.define LOW (1<<0) +.define LOW_F 1 +.define HIGH (1<<1) +.define HIGH_F 2 +; mode +.define STUPID (1<<0) ; forward cam <-> card communication +.define STUPID_F 1 +.define COOL (1<<1) ; send time (clocks) & state via uart +.define COOL_F 2 +.define ELITE (1<<2) ; create bytes, maybe even whole command arrays +.define ELITE_F 3 +.define GODLIKE (1<<3) ; filter and mask for commands to card - send rejected via uart only +.define GODLIKE_F 4 +.define INCREDIBLE_HACK (1<<4) ; destroy all your hardware +.define INCREDIBLE_HACK_F 5 + +; but there is only stupid and cool mode right now %) + + +; ############# +; programm code +; ############# + +; ------------------ +; interrupt vectors: +; ------------------ ; reset rjmp INIT ; int0 -rjmp REC_CARD +rjmp RST_CAM ; int1 rjmp REC_CAM ; timer/counter capt 1 -reti +rjmp REC_CARD ; timer/counter compare reti ; timer/counter overflow 1 -rjmp T1_OVERFLOW +rjmp CLK_OVERFLOW ; timer/counter overflow 0 reti @@ -45,7 +116,7 @@ reti reti ; uart data register empty -reti +rjmp UART_OUT ; uart tx complete reti @@ -53,41 +124,216 @@ reti ; analog comparator reti -; +; ------------ ; init routine -; +; ------------ INIT: ; set stackpointer -ldi r16,low(RAMEND) -out SPL,r16 +ldi tmp,low(RAMEND) +out SPL,tmp ; enable interrupts int0,int1 -ldi r16,((1< calc delta, store to counter_l_tmp, counter_h_tmp + +; send time and state via uart +sbrc mode,COOL_F +rcall SEND_TO_UART ; -> prepare date & enable uart dre interrupt (sbi UCR,UDRIE) + +; return +reti + +; ------------------------ +; toggle_icp_sense routine +; ------------------------ + +TOGGLE_ICP_SENSE: + +; toggle according to state +cbi TCCR1B,ICES1 +sbrs state,HIGH +sbi TCCR1B,ICES1 + +; return +ret + +; ------------------ +; fwd_to_cam routine +; ------------------ + +; output state on port to cam +mov tmp,state +andi tmp,HIGH +lsl tmp ; as we have to set pd3 (dirty, shorter way?) +sbi DDRD,DDD3 +out PORTD,tmp ; <- hunz: low or high if pd3 bit is set ? + +; return +ret + + +; zzZZzZzZZZ .... hier gehts weiter !!! + +; +; rec_cam routines +; + +REC_CAM: + +; decide what to do +sbic PORTD,PD3 +rjmp REC_CAM_HIGH +rjmp REC_CAM_LOW + +REC_CAM_HIGH: + +; output high on port to card +sbi PORTD,PD6 + +; toggle int1 sense +in r16,MCUCR +cbr r16,ISC10 +out MCUCR,r16 + +reti + +REC_CAM_LOW: + +; output low on port to card +cbi PORTD,PD6 + +; toggle int 1 sense +in r16,MCUCR +sbr r16,ISC10 +out MCUCR,r16 + +reti + +; +; t1_overflow routine +; + +T1_OVERFLOW: + +add r22,r1 ; inc counter overflow register + +reti + +; +; rst_cam routine +; + +RST_CAM: + +; decide what to do +sbic PORTD,PD2 +rjmp RST_CAM_HIGH +rjmp RST_CAM_LOW + +RST_CAM_HIGH: + +; output high on rst port to card +sbi PORTD,PD4 + +; toggle int0 sense +in r16,MCUCR +cbr r16,ISC00 +out MCUCR,r16 + +reti + +RST_CAM_LOW: + +; output low on rst port to cam +cbi PORTD,PD4 + +; toggle int0 sense +in r16,MCUCR +sbr r16,ISC00 +out MCUCR,r16 + +reti + +; +; uart_out routines +; + +UART_OUT: + +; +; hier weiter ... +;