- fixed sleep()

- use itoa from lib
- fixed Eth_pkt_recv()


git-svn-id: http://moon:8086/svn/mips@210 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2021-11-24 08:23:20 +00:00
parent 001e7af3e3
commit 888c71bf72
3 changed files with 11 additions and 47 deletions
+4 -11
View File
@@ -6,6 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#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)
+2 -33
View File
@@ -1,42 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#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
+5 -3
View File
@@ -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;
}