static void start_sending(void * dummy) { /* set clk to Z and data to 0 */ clk_Z(); data_0(); set_falling_edge(); #ifdef CONFIG_MODULE_MF2_CLIENT_USE_SCHEDULER sched_event = scheduler_add_single_event(watchdog_timeout, NULL, WATCHDOG_TIMEOUT/SCHEDULER_UNIT); #endif }
void recv(void) { uint8_t i; uint16_t c=0; uint16_t d=0; data_Z(); clk_Z(); if (read_data()) printf("burp\r\n"); /* wait_4cyc(WAIT_KBD_CYCLE4); */ /* wait_4cyc(WAIT_KBD_CYCLE4); */ /* wait_4cyc(WAIT_KBD_CYCLE4); */ clk_0(); wait_4cyc(WAIT_KBD_CYCLE4); for (i=0; i<8 ; i++) { if (read_data()) c |= 1 << i; clk_Z(); wait_4cyc(WAIT_KBD_CYCLE4); if (read_data()) d |= 1 << i; clk_0(); wait_4cyc(WAIT_KBD_CYCLE4); } // parite clk_Z(); wait_4cyc(WAIT_KBD_CYCLE4); clk_0(); wait_4cyc(WAIT_KBD_CYCLE4); // ack clk_Z(); data_0(); wait_4cyc(WAIT_KBD_CYCLE4); clk_0(); wait_4cyc(WAIT_KBD_CYCLE4); // stop clk_Z(); data_Z(); wait_4cyc(WAIT_KBD_CYCLE4); clk_0(); wait_4cyc(WAIT_KBD_CYCLE4); clk_Z(); printf("%x\r\n", c); printf("%x\r\n", d); wait_4cyc(2*WAIT_KBD_CYCLE4); while(1); }
void mf2_server_timer_cb(void) { /* static uint16_t i=0; */ static uint16_t t; /* if it is just polling */ if (mf2_state == MF2_SERVER_STATE_READY) { clk_Z(); data_Z(); /* the central server has something to say */ if (read_clk() && !read_data()) { mf2_state = MF2_SERVER_STATE_RECV; mf2_step = 1; timer1A_register_OC_intr_at_tics(mf2_server_timer_cb, timer1_get()+MF2_SERVER_CLK_HALF_PERIOD); // recv(); dump(); return; } /* nothing to do if the central server has nothing to say */ else { /* reload timer */ timer1A_register_OC_intr_at_tics(mf2_server_timer_cb, timer1_get()+MF2_SERVER_READ_POLL_PERIOD); return; } } /* an operation is running */ /* reload timer */ timer1A_register_OC_intr_at_tics(mf2_server_timer_cb, timer1_get()+MF2_SERVER_CLK_HALF_PERIOD); /* XXX we should check if clk is 0 when clk_Z() */ if (mf2_state == MF2_SERVER_STATE_RECV) { switch(mf2_step) { case 1: mf2_data_recv=0; dump(); clk_0(); break; case 2: dump(); clk_Z(); break; case 3: case 5: case 7: case 9: case 11: case 13: case 15: case 17: // t = timer1_get(); dump(); clk_0(); if(read_data()) mf2_data_recv |= (1 << ( (mf2_step-3)/2 ) ); break; case 4: case 6: case 8: case 10: case 12: case 14: case 16: case 18: /* printf("%d\n", timer1_get() - t); */ /* while(1); */ dump(); clk_Z(); break; case 19: /* parity */ dump(); clk_0(); break; case 20: dump(); clk_Z(); data_0(); break; case 21: dump(); clk_0(); break; case 22: dump(); clk_Z(); data_Z(); break; default: if (rx_event) { /* c=check_rx_buf(rx_buf); */ rx_event((char)(mf2_data_recv)); /* rx_event((char)(0xED)); */ } mf2_state = MF2_SERVER_STATE_READY; mf2_step = 0; timer1A_register_OC_intr_at_tics(mf2_server_timer_cb, timer1_get()+MF2_SERVER_READ_POLL_PERIOD); return; } mf2_step++; } else { switch(mf2_step) { case 1: data_0(); break; case 2: clk_0(); break; case 3: case 5: case 7: case 9: case 11: case 13: case 15: case 17: if(mf2_data_send & (1<<((mf2_step-3)/2))) { data_Z(); mf2_parity_cpt ++; } else { data_0(); } clk_Z(); break; case 4: case 6: case 8: case 10: case 12: case 14: case 16: case 18: /* XXX */ if(!(read_clk())) { /* /\* recv(); *\/ */ /* printf("Ceci est un test\n"); */ /* printf("%d\n", mf2_step); */ /* printf("%2.2x\n", mf2_data_send); */ /* while(1); */ mf2_step=0; mf2_state = MF2_SERVER_STATE_RECV; } clk_0(); break; case 19: if(!(mf2_parity_cpt%2)) data_Z(); else data_0(); clk_Z(); break; case 20: clk_0(); break; case 21: clk_Z(); data_Z(); break; case 22: clk_0(); break; case 23: clk_Z(); break; case 24: case 25: break; default: mf2_state = MF2_SERVER_STATE_READY; mf2_step = 0; timer1A_register_OC_intr_at_tics(mf2_server_timer_cb, timer1_get()+MF2_SERVER_READ_POLL_PERIOD); return; } mf2_step++; } }