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

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [common/] [libsoc/] [src/] [soc.c] - Blame information for rev 189

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 172 ja_rd
/**
2
 @file  soc.c
3
 @brief Supporting functions that do not warrant their own file.
4
*/
5
 
6
#include <stdint.h>
7
#include "soc.h"
8
 
9 175 ja_rd
/* Prototypes for external functions */
10
extern void putchar(int c);
11
extern int getchar(void);
12 172 ja_rd
 
13
 
14
/*-- Non-standard utility functions ------------------------------------------*/
15
 
16
/** Return time elapsed since the last HW reset in clock cycles */
17
unsigned ctime(void){
18
    unsigned cycles;
19
 
20
    cycles = *((volatile unsigned *)0x20000100);
21
    return cycles;
22
}
23
 
24
 
25
/*-- Libc replacement functions ----------------------------------------------*/
26
 
27 175 ja_rd
/** Write string to console; replacement for standard puts.
28 172 ja_rd
    Uses no buffering. */
29
int puts(const char *string){
30
    while(*string){
31
        /* Implicit CR with every NL if requested */
32
        if(IMPLICIT_CR_WITH_NL & (*string == '\n')){
33
            putchar('\r');
34
        }
35
        putchar(*string++);
36
    }
37
    /* A newline character is appended to the output. */
38
    if(IMPLICIT_CR_WITH_NL & (*string == '\n')){
39
        putchar('\r');
40
    }
41
    putchar('\n');
42
 
43
    return 0; /* on success return anything non-negative */
44
}
45
 
46 175 ja_rd
/** Read string from console, blocking; replacement for standard puts.
47 172 ja_rd
    Uses no buffering. */
48
char *gets (char *str){
49
    uint32_t i=0;
50
    char c;
51
 
52
    while(1){
53
        c = getchar();
54
 
55
        if(c=='\0'){
56
            break;
57
        }
58
        else if(c=='\n' || c=='\r'){
59
            break;
60
        }
61
        else{
62
            str[i++] = c;
63
        }
64
    }
65
    str[i] = '\0';
66
    return str;
67
}

powered by: WebSVN 2.1.0

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