48 uint8 incr_windowfull_retry_cnt(uint8 s)
50 return ++windowfull_retry_cnt[s];
53 void init_windowfull_retry_cnt(uint8 s)
55 windowfull_retry_cnt[s] = 0;
58 uint8 getSn_TSR(uint8 s)
60 return IINCHIP_READ_SOCKETREG(s, WIZS_TSR);
68 void putISR(uint8 s, uint8 val)
73 uint16 getIINCHIP_RxMAX(uint8 s)
78 uint16 getIINCHIP_TxMAX(uint8 s)
98 void IINCHIP_CSoff(
void)
104 void IINCHIP_CSon(
void)
110 uint8 IINCHIP_SpiSendData(uint8 dat)
118 uint8 g_rx_wr_cntl_bits = (uint8)((3&0x07)<<5) | CB_TAIL_RXBUF_WR;
119 uint8 g_rx_rd_cntl_bits = (uint8)((3%0x07)<<5) | CB_TAIL_RXBUF_RD;
121 void IINCHIP_RXBUF_WRRD(uint16 addr, uint8 data)
124 IINCHIP_ISR_DISABLE();
128 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
129 IINCHIP_SpiSendData(addr & 0x00FF);
130 IINCHIP_SpiSendData(g_rx_wr_cntl_bits);
131 IINCHIP_SpiSendData(data);
135 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
136 IINCHIP_SpiSendData(addr & 0x00FF);
137 IINCHIP_SpiSendData(g_rx_rd_cntl_bits);
138 rdata = IINCHIP_SpiSendData(0x00);
141 IINCHIP_ISR_ENABLE();
145 printf(
"addr:%X, data:%X, rdata:%X, ", addr, data, rdata);
146 IINCHIP_ISR_DISABLE();
148 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
149 IINCHIP_SpiSendData(addr & 0x00FF);
150 IINCHIP_SpiSendData(g_rx_rd_cntl_bits);
151 redata = IINCHIP_SpiSendData(0x00);
153 IINCHIP_ISR_ENABLE();
154 printf(
"redata:%X \r\n", redata);
161 void IINCHIP_WRITE(uint16 addr, uint8 cntl_bits, uint8 data)
163 IINCHIP_ISR_DISABLE();
166 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
167 IINCHIP_SpiSendData(addr & 0x00FF);
168 IINCHIP_SpiSendData(cntl_bits);
169 IINCHIP_SpiSendData(data);
171 IINCHIP_ISR_ENABLE();
176 uint8 IINCHIP_READ(uint16 addr, uint8 cntl_bits)
179 IINCHIP_ISR_DISABLE();
181 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
182 IINCHIP_SpiSendData(addr & 0x00FF);
183 IINCHIP_SpiSendData(cntl_bits);
184 data = IINCHIP_SpiSendData(0x00);
186 IINCHIP_ISR_ENABLE();
190 void IINCHIP_WRITE_SEQ(uint16 addr, uint8 cntl_bits, uint16 len, uint8 * data)
200 printf(
"Unexpected1 length 0\r\n");
204 IINCHIP_ISR_DISABLE();
207 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
208 IINCHIP_SpiSendData(addr & 0x00FF);
209 IINCHIP_SpiSendData(cntl_bits);
210 for(idx = 0; idx < len; idx++)
212 IINCHIP_SpiSendData(data[idx]);
215 IINCHIP_ISR_ENABLE();
218 for(idx=0; idx< len; idx++)
224 printf(
"SEQ read pattern Error");
232 void IINCHIP_READ_SEQ(uint16 addr, uint8 cntl_bits, uint16 len, uint8 * data)
242 printf(
"Unexpected2 length 0\r\n");
246 IINCHIP_ISR_DISABLE();
249 IINCHIP_SpiSendData((addr & 0xFF00) >> 8);
250 IINCHIP_SpiSendData(addr & 0x00FF);
251 IINCHIP_SpiSendData(cntl_bits);
252 for(idx = 0; idx < len; idx++)
254 data[idx] = IINCHIP_SpiSendData(0x00);
257 IINCHIP_ISR_ENABLE();
261 void IINCHIP_WRITE_COMMON( uint16 addr, uint8 data)
264 cntl_bits = CB_TAIL_COMREG_WR;
265 IINCHIP_WRITE(addr, cntl_bits, data);
268 uint8 IINCHIP_READ_COMMON(uint16 addr)
272 cntl_bits = CB_TAIL_COMREG_RD;
273 data = IINCHIP_READ(addr, cntl_bits);
278 void IINCHIP_WRITE_DM( uint16 addr, uint8 data)
281 cntl_bits = CM_MEM_DM;
282 IINCHIP_WRITE(addr, cntl_bits, data);
285 uint8 IINCHIP_READ_DM(uint16 addr)
289 cntl_bits = CM_MEM_DM;
290 data = IINCHIP_READ(addr, cntl_bits);
294 void IINCHIP_READ_COMMON_SEQ(uint16 addr, uint8 len, uint8 * data)
297 cntl_bits = (uint8)CB_TAIL_COMMONREG_RD_SEQ;
298 IINCHIP_READ_SEQ(addr, cntl_bits, len, (uint8 *)data);
301 void IINCHIP_WRITE_COMMON_SEQ(uint16 addr, uint8 len, uint8 * data)
304 cntl_bits = (uint8)CB_TAIL_COMMONREG_WR_SEQ;
305 IINCHIP_WRITE_SEQ(addr, cntl_bits, len, (uint8 *)data);
308 void IINCHIP_WRITE_SOCKETREG(uint8 sock_num, uint16 addr, uint8 data)
311 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_SOCKETREG_WR;
313 IINCHIP_WRITE(addr, cntl_bits, data);
316 uint8 IINCHIP_READ_SOCKETREG(uint8 sock_num, uint16 addr)
320 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_SOCKETREG_RD;
322 data = IINCHIP_READ(addr, cntl_bits);
327 void IINCHIP_READ_SOCKETREG_SEQ(uint8 sock_num, uint16 addr, uint8 len, uint8 * data)
330 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_SOCKETREG_RD_SEQ;
331 IINCHIP_READ_SEQ(addr, cntl_bits, len, (uint8 *)data);
334 void IINCHIP_WRITE_SOCKETREG_SEQ(uint8 sock_num, uint16 addr, uint8 len, uint8 * data)
337 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_SOCKETREG_WR_SEQ;
339 IINCHIP_WRITE_SEQ(addr, cntl_bits, len, (uint8 *)data);
342 void IINCHIP_WRITE_TXBUF(uint8 sock_num, uint16 addr, uint8 data)
345 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_TXBUF_WR;
346 IINCHIP_WRITE(addr, cntl_bits, data);
349 uint8 IINCHIP_READ_TXBUF(uint8 sock_num, uint16 addr)
353 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_TXBUF_RD;
354 data = IINCHIP_READ(addr, cntl_bits);
358 void IINCHIP_WRITE_RXBUF(uint8 sock_num, uint16 addr, uint8 data)
361 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_RXBUF_WR;
362 IINCHIP_WRITE(addr, cntl_bits, data);
365 uint8 IINCHIP_READ_RXBUF(uint8 sock_num, uint16 addr)
369 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_RXBUF_RD;
370 data = IINCHIP_READ(addr, cntl_bits);
374 void IINCHIP_WRITE_TXBUF_SEQ(uint8 sock_num, uint16 addr, uint16 len, uint8 * data)
377 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_TXBUF_WR_SEQ;
378 IINCHIP_WRITE_SEQ(addr, cntl_bits, len, (uint8 *)data);
381 void IINCHIP_READ_TXBUF_SEQ(uint8 sock_num, uint16 addr, uint16 len, uint8 * data)
384 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_TXBUF_RD_SEQ;
385 IINCHIP_READ_SEQ(addr, cntl_bits, len, data);
388 void IINCHIP_WRITE_RXBUF_SEQ(uint8 sock_num, uint16 addr, uint16 len, uint8 * data)
391 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_RXBUF_WR_SEQ;
392 IINCHIP_WRITE_SEQ(addr, cntl_bits, len, data);
395 void IINCHIP_READ_RXBUF_SEQ(uint8 sock_num, uint16 addr, uint16 len, uint8 * data)
398 cntl_bits = (uint8)((sock_num&0x07)<<5) | CB_TAIL_RXBUF_RD_SEQ;
399 IINCHIP_READ_SEQ(addr, cntl_bits, len, data);
413 IINCHIP_WRITE_COMMON( (WIZC_GAR0 + 0), addr[0]);
416 IINCHIP_WRITE_COMMON( (WIZC_GAR0 + 1), addr[1]);
419 IINCHIP_WRITE_COMMON( (WIZC_GAR0 + 2), addr[2]);
422 IINCHIP_WRITE_COMMON( (WIZC_GAR0 + 3), addr[3]);
428 printf(
"COMMON REG\r\n");
431 printf(
"%d -- rd: %X ", j, IINCHIP_READ_COMMON( j ) );
432 IINCHIP_WRITE_COMMON( j, 0x00+j);
433 printf(
"wr:%X, rd:%X \r\n", j, IINCHIP_READ_COMMON( j ) );
451 void setSUBR(uint8 * addr)
453 IINCHIP_WRITE_COMMON( (WIZC_SUBR0 + 0), addr[0]);
454 IINCHIP_WRITE_COMMON( (WIZC_SUBR0 + 1), addr[1]);
455 IINCHIP_WRITE_COMMON( (WIZC_SUBR0 + 2), addr[2]);
456 IINCHIP_WRITE_COMMON( (WIZC_SUBR0 + 3), addr[3]);
466 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 0),addr[0]);
467 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 1),addr[1]);
468 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 2),addr[2]);
469 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 3),addr[3]);
470 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 4),addr[4]);
471 IINCHIP_WRITE_COMMON((WIZC_SHAR0 + 5),addr[5]);
481 IINCHIP_WRITE_COMMON((WIZC_SIPR0 + 0),addr[0]);
482 IINCHIP_WRITE_COMMON((WIZC_SIPR0 + 1),addr[1]);
483 IINCHIP_WRITE_COMMON((WIZC_SIPR0 + 2),addr[2]);
484 IINCHIP_WRITE_COMMON((WIZC_SIPR0 + 3),addr[3]);
490 void getGAR(uint8 * addr)
492 addr[0] = IINCHIP_READ_COMMON(WIZC_GAR0);
493 addr[1] = IINCHIP_READ_COMMON(WIZC_GAR0+1);
494 addr[2] = IINCHIP_READ_COMMON(WIZC_GAR0+2);
495 addr[3] = IINCHIP_READ_COMMON(WIZC_GAR0+3);
497 void getSUBR(uint8 * addr)
499 addr[0] = IINCHIP_READ_COMMON(WIZC_SUBR0);
500 addr[1] = IINCHIP_READ_COMMON(WIZC_SUBR0+1);
501 addr[2] = IINCHIP_READ_COMMON(WIZC_SUBR0+2);
502 addr[3] = IINCHIP_READ_COMMON(WIZC_SUBR0+3);
504 void getSHAR(uint8 * addr)
506 addr[0] = IINCHIP_READ_COMMON(WIZC_SHAR0);
507 addr[1] = IINCHIP_READ_COMMON(WIZC_SHAR0+1);
508 addr[2] = IINCHIP_READ_COMMON(WIZC_SHAR0+2);
509 addr[3] = IINCHIP_READ_COMMON(WIZC_SHAR0+3);
510 addr[4] = IINCHIP_READ_COMMON(WIZC_SHAR0+4);
511 addr[5] = IINCHIP_READ_COMMON(WIZC_SHAR0+5);
513 void getSIPR(uint8 * addr)
515 addr[0] = IINCHIP_READ_COMMON(WIZC_SIPR0);
516 addr[1] = IINCHIP_READ_COMMON(WIZC_SIPR0+1);
517 addr[2] = IINCHIP_READ_COMMON(WIZC_SIPR0+2);
518 addr[3] = IINCHIP_READ_COMMON(WIZC_SIPR0+3);
521 void getDIPR(uint8 s, uint8 *addr)
523 addr[0] = IINCHIP_READ_SOCKETREG(s, WIZS_DIPR0 + 0);
524 addr[1] = IINCHIP_READ_SOCKETREG(s, WIZS_DIPR0 + 1);
525 addr[2] = IINCHIP_READ_SOCKETREG(s, WIZS_DIPR0 + 2);
526 addr[3] = IINCHIP_READ_SOCKETREG(s, WIZS_DIPR0 + 3);
533 void getDPORT(uint8 s, uint16 *port)
535 *port = IINCHIP_READ_SOCKETREG(s, WIZS_DPORT0 + 0) << 8;
536 *port += IINCHIP_READ_SOCKETREG(s, WIZS_DPORT0 + 1);
541 void setMR(uint8 val)
543 IINCHIP_WRITE_COMMON(WIZC_MR, val);
551 return IINCHIP_READ_COMMON(WIZC_IR);
565 void setRTR(uint16 timeout)
567 IINCHIP_WRITE_COMMON(WIZC_RTR0,(uint8)((timeout & 0xff00) >> 8));
568 IINCHIP_WRITE_COMMON((WIZC_RTR0 + 1),(uint8)(timeout & 0x00ff));
577 void setRCR(uint8 retry)
579 IINCHIP_WRITE_COMMON(WIZC_RCR,retry);
588 void setIMR(uint8 mask)
590 IINCHIP_WRITE_COMMON(WIZC_IMR, mask);
599 void clearIR(uint8 mask)
601 IINCHIP_WRITE_COMMON(WIZC_IR, ~mask | getIR() );
607 void setSn_MSS(uint8 s, uint16 Sn_MSSR)
609 IINCHIP_WRITE_SOCKETREG( s, WIZS_MSSR0 ,(uint8)((Sn_MSSR & 0xff00) >> 8));
610 IINCHIP_WRITE_SOCKETREG( s,(WIZS_MSSR0 + 1),(uint8)(Sn_MSSR & 0x00ff));
613 void setSn_TTL(uint8 s, uint8 ttl)
615 IINCHIP_WRITE_SOCKETREG( s, WIZS_TTL , ttl);
623 uint8 getSn_IR(uint8 s)
625 return IINCHIP_READ_SOCKETREG(s, WIZS_IR );
632 uint8 getSn_SR(uint8 s)
634 return IINCHIP_READ_SOCKETREG(s, WIZS_SR );
644 uint16 getSn_TX_FSR(uint8 s)
649 val1 = IINCHIP_READ_SOCKETREG(s, WIZS_TX_FSR0 );
650 val1 = (val1 << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_TX_FSR0 + 1);
653 val = IINCHIP_READ_SOCKETREG(s, WIZS_TX_FSR0 );
654 val = (val << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_TX_FSR0 + 1);
656 }
while (val != val1);
666 uint16 getSn_RX_RSR(uint8 s)
671 val1 = IINCHIP_READ_SOCKETREG( s, WIZS_RX_RSR0 );
672 val1 = (val1 << 8) + IINCHIP_READ_SOCKETREG( s, WIZS_RX_RSR0 + 1);
675 val = IINCHIP_READ_SOCKETREG(s, WIZS_RX_RSR0 );
676 val = (val << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_RX_RSR0 + 1);
678 }
while (val != val1);
689 void send_data_processing(uint8 s, uint8 *data, uint16 len)
693 printf(
"CH: %d Unexpected1 length 0\r\n", s);
698 ptr = IINCHIP_READ_SOCKETREG( s, WIZS_TX_WR0 );
699 ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ_SOCKETREG( s, WIZS_TX_WR0 + 1);
701 IINCHIP_WRITE_TXBUF_SEQ(s, ptr, len, data);
703 IINCHIP_WRITE_SOCKETREG( s,WIZS_TX_WR0 ,(uint8)((ptr & 0xff00) >> 8));
704 IINCHIP_WRITE_SOCKETREG( s,(WIZS_TX_WR0 + 1),(uint8)(ptr & 0x00ff));
715 void recv_data_processing(uint8 s, uint8 *data, uint16 len)
721 printf(
"CH: %d Unexpected2 length 0\r\n", s);
725 ptr = IINCHIP_READ_SOCKETREG( s, WIZS_RX_RD0 );
726 ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ_SOCKETREG( s, WIZS_RX_RD0 + 1);
729 IINCHIP_READ_RXBUF_SEQ(s, ptr, len, data);
733 IINCHIP_WRITE_SOCKETREG( s, WIZS_RX_RD0 ,(uint8)((ptr & 0xff00) >> 8));
734 IINCHIP_WRITE_SOCKETREG( s, WIZS_RX_RD0 + 1,(uint8)(ptr & 0x00ff));
738 void recv_data_ignore(uint8 s, uint16 len)
742 ptr = IINCHIP_READ_SOCKETREG(s, WIZS_RX_RD0 + 0);
743 ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ_SOCKETREG(s, WIZS_RX_RD0 + 1);
745 IINCHIP_WRITE_SOCKETREG(s, WIZS_RX_RD0 + 0, (uint8)((ptr & 0xff00) >> 8));
746 IINCHIP_WRITE_SOCKETREG(s, WIZS_RX_RD0 + 1, (uint8)(ptr & 0x00ff));