X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fsmartcard%2Fsmartcard.c;h=93beb3a73bdb74a0bd3db68ab6e3564ef1e602c5;hp=8d1e745f0f9de599b111a2ac7d813710e3efea8f;hb=5fb0341d348e101b30794945a6c91546e25e8e7b;hpb=31f45062572380f91438aa566fe6b83ca66c4951 diff --git a/firmware/apps/smartcard/smartcard.c b/firmware/apps/smartcard/smartcard.c index 8d1e745..93beb3a 100644 --- a/firmware/apps/smartcard/smartcard.c +++ b/firmware/apps/smartcard/smartcard.c @@ -8,14 +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: + 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; + + PLEDOUT^=PLEDPIN; + if(SCIN!=foo){ + foo=SCIN; + } + if(sctime%0x1000==0) + debughex(foo); + } break; case STOP: default: