From 888c71bf7288c68316785b841fc01fb0c00ecf8f Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 24 Nov 2021 08:23:20 +0000 Subject: [PATCH] - fixed sleep() - use itoa from lib - fixed Eth_pkt_recv() git-svn-id: http://moon:8086/svn/mips@210 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/common/libsys/libsys.c | 15 ++++----------- src/common/libsys/syscalls.c | 35 ++--------------------------------- src/common/network/ethernet.c | 8 +++++--- 3 files changed, 11 insertions(+), 47 deletions(-) diff --git a/src/common/libsys/libsys.c b/src/common/libsys/libsys.c index e9fb48f..6a834c9 100644 --- a/src/common/libsys/libsys.c +++ b/src/common/libsys/libsys.c @@ -6,6 +6,9 @@ #include #include #include "libsys.h" +#include "console.h" +#include "irq.h" + #include "asm/regdef.h" static uint32_t critical_nesting_counter = 0; @@ -40,17 +43,7 @@ void _exit (int exitcode) void sleep(unsigned ms) { - unsigned stop; - struct tms t; - - times(&t); - stop = t.tms_utime + ms; - - do - { - times(&t); - } while (t.tms_utime < stop); - + usleep(1000*ms); } void usleep(unsigned us) diff --git a/src/common/libsys/syscalls.c b/src/common/libsys/syscalls.c index 900c9ae..01ca1c4 100644 --- a/src/common/libsys/syscalls.c +++ b/src/common/libsys/syscalls.c @@ -1,42 +1,11 @@ #include +#include #include "libsys.h" #include "xcpt.h" /* 10 digits + 1 sign + 1 trailing nul */ static char itoa_buf[12]; -char *itoa(int i) -{ - char *pos = itoa_buf + sizeof(itoa_buf) - 1; - unsigned int u; - int negative = 0; - - if (i < 0) - { - negative = 1; - u = ((unsigned int)(-(1+i))) + 1; - } - else - { - u = i; - } - - *pos = 0; - - do - { - *--pos = '0' + (u % 10); - u /= 10; - } while (u); - - if (negative) - { - *--pos = '-'; - } - - return pos; -} - int syscalls_handler(struct xcptcontext * xcp) { int syscall_code; @@ -47,7 +16,7 @@ int syscalls_handler(struct xcptcontext * xcp) switch(syscall_code) { case 1: // print integer - sputs(itoa(xcp->regs[4])); + sputs(itoa(xcp->regs[4], itoa_buf, 10)); break; case 4: // print string diff --git a/src/common/network/ethernet.c b/src/common/network/ethernet.c index f242420..fde6441 100644 --- a/src/common/network/ethernet.c +++ b/src/common/network/ethernet.c @@ -124,7 +124,7 @@ uint32_t Eth_pkt_recv(uint8_t *pData) volatile uint32_t *pEmac_size = (uint32_t*)SYS_EMAC_RX_SIZE; volatile uint32_t *pEmac_data = (uint32_t*)SYS_EMAC_DATA; - uint32_t i, num_words, num_bytes; + uint32_t num_bytes = 0; if(EMAC_RX_is_avail()) { @@ -137,12 +137,14 @@ uint32_t Eth_pkt_recv(uint8_t *pData) // } num_bytes = EMAC_RX_get_size(); - num_words = num_bytes >> 2; + uint32_t num_words = num_bytes >> 2; if (num_bytes & 3) + { num_words++; + } EMAC_RX_request(); - for (i=0; i < num_words; i++) + for (uint32_t i=0; i < num_words; i++) { ((uint32_t*)pData)[i] = *pEmac_data; }