OpenCores
URL https://opencores.org/ocsvn/darkriscv/darkriscv/trunk

Subversion Repositories darkriscv

[/] [darkriscv/] [trunk/] [src/] [stdio.c] - Diff between revs 2 and 4

Show entire file | Details | Blame | View Log

Rev 2 Rev 4
Line 32... Line 32...
#include <stdio.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdarg.h>
 
 
#ifdef __RISCV__
#ifdef __RISCV__
 
 
 
// idle time, update timer and blink the led! :)
 
 
 
void _idle(void)
 
{
 
    if(io.irq&IRQ_TIMR)
 
    {
 
      if(!utimers--)
 
      {
 
        io.led++;
 
        utimers=999999;
 
      }
 
      io.irq = IRQ_TIMR;
 
    }
 
}
 
 
// putchar and getchar uses the "low-level" io
// putchar and getchar uses the "low-level" io
 
 
int getchar(void)
int getchar(void)
{
{
  while((io.uart.stat&2)==0); // uart empty, wait...
  while((io.uart.stat&2)==0) _idle(); // uart empty, wait...
 
 
  return io.uart.fifo;
  return io.uart.fifo;
}
}
 
 
int putchar(int c)
int putchar(int c)
{
{
  if(c=='\n')
  if(c=='\n')
  {
  {
    while(io.uart.stat&1); // uart busy, wait...
    while(io.uart.stat&1) _idle(); // uart busy, wait...
    io.uart.fifo = '\r';
    io.uart.fifo = '\r';
  }
  }
 
 
  while(io.uart.stat&1); // uart busy, wait...
  while(io.uart.stat&1) _idle(); // uart busy, wait...
  return io.uart.fifo = c;
  return io.uart.fifo = c;
}
}
 
 
#endif
#endif
 
 
// high-level functions uses the getchar/putchar
// high-level functions use the getchar/putchar
 
 
char *gets(char *p,int s)
char *gets(char *p,int s)
{
{
  char *ret = p;
  char *ret = p;
  int c;
  int c;
Line 304... Line 318...
{
{
    unsigned acc,aux;
    unsigned acc,aux;
 
 
    if(!y) return 0;
    if(!y) return 0;
 
 
    for(aux=1,acc=y;acc<x;aux<<=1,acc<<=1,y=acc);
    for(aux=1;y<x&&!(y&(1<<31));aux<<=1,y<<=1);
    for(acc=0;x&&aux;aux>>=1,y>>=1) if(y<=x) x-=y,acc+=aux;
    for(acc=0;x&&aux;aux>>=1,y>>=1) if(y<=x) x-=y,acc+=aux;
 
 
    return opt ? acc : x;
    return opt ? acc : x;
}
}
 
 
Line 347... Line 361...
    return __div_mod_si3(x,y,0);
    return __div_mod_si3(x,y,0);
}
}
 
 
void usleep(int delay)
void usleep(int delay)
{
{
    if(threads>1)
 
    {
 
        while(delay--)
 
        {
 
            int t0 = utimers;
 
 
 
            while(t0==utimers);
 
        }
 
    }
 
    else
 
    {
    {
        while(delay--)
        while(delay--)
        {
        {
            for(io.irq=IRQ_TIMR;!io.irq;);
            for(io.irq=IRQ_TIMR;!io.irq;);
        }
        }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.