X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fsmartcard%2Fsmartcard.c;h=566081bb5eb173ad617bf19415de9b32c0132be6;hp=e984f24ae201fae6aef6397407dd516c0efc26e4;hb=69539bb167246135b1bde3c55dca7d19bc3c7aee;hpb=577c3ba46d80db877c08a4ce0be89890e294a868 diff --git a/firmware/apps/smartcard/smartcard.c b/firmware/apps/smartcard/smartcard.c index e984f24..566081b 100644 --- a/firmware/apps/smartcard/smartcard.c +++ b/firmware/apps/smartcard/smartcard.c @@ -8,17 +8,91 @@ #include "platform.h" #include "command.h" #include "jtag.h" +#include "smartcard.h" //! Handles a monitor command. -int smartcardhandle(unsigned char app, - unsigned char verb, - unsigned int len){ +void smartcard_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len); + +// define the smartcard app's app_t +app_t const smartcard_app = { + + /* app number */ + SMARTCARD, + + /* handle fn */ + smartcard_handle_fn, + + /* name */ + "SMARTCARD", + + /* desc */ + "\tThe SMARTCARD app allows for communication with smart\n" + "\tcards and SIM cards.\n" +}; + + +//TDO/P5.2 is Data + +//Read a bit. +#define SCIN (P5IN&BIT2) +//Set I/O direction. +#define SCINPUT (P5DIR&=~BIT2) +#define SCOUTPUT (P5DIR|=BIT2) +//Set data value. +#define SCH (P5OUT|=BIT2) +#define SCL (P5OUT&=~BIT2) + +//Clock. +#define SCTICK (P5OUT|=BIT3) +#define SCTOCK (P5OUT&=~BIT3) + + +//! Setup the smart card mode. +void smartcardsetup(){ + P5DIR|=BIT3; + P2DIR|=RST; + msdelay(100); +} + +u16 sctime=0, foo=0; + +//! Handles a monitor command. +void smartcard_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len) +{ switch(verb){ case SETUP: - debugstr("Unable to setup smart card."); + smartcardsetup(); break; case START: - debugstr("Unable to start smart card."); + smartcardsetup(); + debugstr("Reseting card"); + SCINPUT; + + CLRRST; + SCTICK; + SCTOCK; + SCTICK; + SCTOCK; + delay(500); + SETRST; + + while(1){ + sctime++; + SCTICK; + delay(5); + SCTOCK; + + led_toggle(); + if(SCIN!=foo){ + foo=SCIN; + } + if(sctime%0x1000==0) + debughex(foo); + } break; case STOP: default: