X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/blobdiff_plain/c1d6a43781d91a07fccde6c4f9dbbfc78fce2025..e90caf3962147d853aed69fff4a2f3e6e1c03f05:/pruebas/keil/red_test_anda/etherdev.c diff --git a/pruebas/keil/red_test_anda/etherdev.c b/pruebas/keil/red_test_anda/etherdev.c index aa8f35f..a473629 100644 --- a/pruebas/keil/red_test_anda/etherdev.c +++ b/pruebas/keil/red_test_anda/etherdev.c @@ -17,17 +17,6 @@ unsigned char uip_buf[80] = unsigned int uip_len = 14; -#define ETH_CPU_CLOCK ETH_CPU_XTAL / 12 // 8051 clock rate (X1 mode) - -// Delay routine timing parameters -#define ETH_DELAY_CONST 9.114584e-5 // Delay routine constant -#define ETH_DELAY_MULTPLR (unsigned char)(ETH_DELAY_CONST * ETH_CPU_CLOCK) - -// X1 CPU mode timing parameters -#define ETH_T0_CLOCK ETH_CPU_XTAL / 12 // Timer 0 mode 1 clock rate -#define ETH_T0_INT_RATE 24 // Timer 0 intrupt rate (Hz) -#define ETH_T0_RELOAD 65536 - (ETH_T0_CLOCK / ETH_T0_INT_RATE) - // Packet transmit & receive buffer configuration #define ETH_TX_PAGE_START 0x40 // 0x4000 Tx buffer is 6 * 256 = 1536 bytes #define ETH_RX_PAGE_START 0x46 // 0x4600 Rx buffer is 26 * 256 = 6656 bytes @@ -36,13 +25,11 @@ unsigned int uip_len = 14; #define ETH_ADDR_PORT_MASK 0x1F // 00011111y #define ETH_DATA_PORT_MASK 0xFF // 11111111y -#define ETH_MIN_PACKET_LEN 0x3C +#define ETH_MIN_PACKET_LEN 0x3C // 60 bytes static void etherdev_reg_write(unsigned char reg, unsigned char wr_data); static unsigned char etherdev_reg_read(unsigned char reg); -static void etherdev_delay_ms(unsigned int count); -static unsigned int etherdev_poll(void); // Manipulate PS1 & PS0 in CR to select RTL8019AS register page. #define ETHERDEV_SELECT_REG_PAGE(page) \ @@ -52,8 +39,6 @@ static unsigned int etherdev_poll(void); etherdev_reg_write(CR, etherdev_reg_read(CR) | (page << 6)); \ } while(0) -static unsigned char tick_count = 0; - static void etherdev_reg_write(unsigned char reg, unsigned char wr_data) { @@ -101,27 +86,6 @@ static unsigned char etherdev_reg_read(unsigned char reg) } -/* - - etherdev_timer0_isr() - - This function is invoked each 1/24th of a second and updates a - 1/24th of a second tick counter. - - */ -static void etherdev_timer0_isr(void) interrupt 1 using 1 -{ - // Reload timer/ counter 0 for 24Hz periodic interrupt. - TH0 = ETH_T0_RELOAD >> 8; - TL0 = ETH_T0_RELOAD; - - // Increment 24ths of a second counter. - tick_count++; - - return; -} - - /* etherdev_init() @@ -219,29 +183,6 @@ bit etherdev_init(void) // Receive configuration register to accept broadcast packets. etherdev_reg_write(RCR, AB); - - // Initialize Timer 0 to generate a periodic 24Hz interrupt. - - // Stop timer/ counter 0. - TR0 = 0; - - // Set timer/ counter 0 as mode 1 16 bit timer. - TMOD &= 0xF0; - TMOD |= 0x01; - - // Preload for 24Hz periodic interrupt. - TH0 = ETH_T0_RELOAD >> 8; - TL0 = ETH_T0_RELOAD; - - // Restart timer/ counter 0 running. - TR0 = 1; - - // Enable timer/ counter 0 overflow interrupt. - ET0 = 1; - - // Enable global interrupt. - EA = 1; - return 1; } @@ -313,31 +254,6 @@ void etherdev_send(void) } -/* - - etherdev_read() - - This function will read an entire IP packet into the uip_buf. - If it must wait for more than 0.5 seconds, it will return with - the return value 0. Otherwise, when a full packet has been read - into the uip_buf buffer, the length of the packet is returned. - - */ -unsigned int etherdev_read(void) -{ - unsigned int bytes_read; - - /* tick_count threshold should be 12 for 0.5 sec bail-out - One second (24) worked better for me, but socket recycling - is then slower. I set UIP_TIME_WAIT_TIMEOUT 60 in uipopt.h - to counter this. Retransmission timing etc. is affected also. */ - while ((!(bytes_read = etherdev_poll())) && (tick_count < 12)) continue; - - tick_count = 0; - - return bytes_read; -} - static void etherdev_reset() { bit retransmit = etherdev_reg_read(CR) & TXP; @@ -398,15 +314,9 @@ static void etherdev_reset() } } -/* - - etherdev_poll() - - Poll the RTL8019AS ethernet device for an available packet. - - */ -static unsigned int etherdev_poll(void) -{ + +unsigned int etherdev_read(void) +{ unsigned int len = 0; // Check if the rx buffer has overflowed.