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

Subversion Repositories ion

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

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
 @bug   Any attempt to use gets() or puts() triggers a linker error (undefined
6
        reference to '_impure_ptr') in this file, despite the fact that this
7
        file does not reference those symbols; newlib's gets and puts DO, and
8
        the linker is somehow getting confused.
9
        Right now I have no idea how to sort that out.
10
*/
11
 
12
#include <stdint.h>
13
#include <stdio.h>
14
 
15
#include "soc.h"
16
 
17
/* Linker-defined symbols usd to access the data section */
18
extern char data_start [];          /**< Where .data section should be in RAM */
19
extern char data_load_start [];     /**< Where .data section is in ROM */
20
extern char data_size [];           /**< Size of .data section */
21
 
22
 
23
/*-- Non-standard utility functions ------------------------------------------*/
24
 
25
/** Return time elapsed since the last HW reset in clock cycles */
26
unsigned ctime(void){
27
    unsigned cycles;
28
 
29
    cycles = *((volatile unsigned *)0x20000100);
30
    return cycles;
31
}
32
 
33
/** Copies .data sections (initialized data) from ROM to RAM.
34
   Will be called from the startup code IIF the program was linked to run
35
   from FLASH. */
36
void copy_data_sections(void){
37
    uint32_t i;
38
    /* Move data section image from flash to RAM */
39
    if (data_start != data_load_start){
40
        for(i=0;i<(uint32_t)data_size;i++){
41
            data_start[i] = data_load_start[i];
42
        }
43
    }
44
}
45
 
46
 
47
/*-- Libc replacement functions ----------------------------------------------*/
48
 
49
/** Write character to console; replacement for standard puts.
50
    Uses no buffering. */
51
int puts(const char *string){
52
    while(*string){
53
        /* Implicit CR with every NL if requested */
54
        if(IMPLICIT_CR_WITH_NL & (*string == '\n')){
55
            putchar('\r');
56
        }
57
        putchar(*string++);
58
    }
59
    /* A newline character is appended to the output. */
60
    if(IMPLICIT_CR_WITH_NL & (*string == '\n')){
61
        putchar('\r');
62
    }
63
    putchar('\n');
64
 
65
    return 0; /* on success return anything non-negative */
66
}
67
 
68
/** Read character from console, blocking; replacement for standard puts.
69
    Uses no buffering. */
70
char *gets (char *str){
71
    uint32_t i=0;
72
    char c;
73
 
74
    while(1){
75
        c = getchar();
76
 
77
        if(c=='\0'){
78
            break;
79
        }
80
        else if(c=='\n' || c=='\r'){
81
            break;
82
        }
83
        else{
84
            str[i++] = c;
85
        }
86
    }
87
    str[i] = '\0';
88
    return str;
89
}

powered by: WebSVN 2.1.0

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