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

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [boot-loader-ethmac/] [utilities.c] - Blame information for rev 61

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

Line No. Rev Author Line
1 61 csantifort
/*----------------------------------------------------------------
2
//                                                              //
3
//  boot-loader-ethmac.c                                        //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  The main functions for the boot loader application. This    //
10
//  application is embedded in the FPGA's SRAM and is used      //
11
//  to load larger applications into the DDR3 memory on         //
12
//  the development board.                                      //
13
//                                                              //
14
//  Author(s):                                                  //
15
//      - Conor Santifort, csantifort.amber@gmail.com           //
16
//                                                              //
17
//////////////////////////////////////////////////////////////////
18
//                                                              //
19
// Copyright (C) 2011 Authors and OPENCORES.ORG                 //
20
//                                                              //
21
// This source file may be used and distributed without         //
22
// restriction provided that this copyright statement is not    //
23
// removed from the file and that any derivative work contains  //
24
// the original copyright notice and the associated disclaimer. //
25
//                                                              //
26
// This source file is free software; you can redistribute it   //
27
// and/or modify it under the terms of the GNU Lesser General   //
28
// Public License as published by the Free Software Foundation; //
29
// either version 2.1 of the License, or (at your option) any   //
30
// later version.                                               //
31
//                                                              //
32
// This source is distributed in the hope that it will be       //
33
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
34
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
35
// PURPOSE.  See the GNU Lesser General Public License for more //
36
// details.                                                     //
37
//                                                              //
38
// You should have received a copy of the GNU Lesser General    //
39
// Public License along with this source; if not, download it   //
40
// from http://www.opencores.org/lgpl.shtml                     //
41
//                                                              //
42
----------------------------------------------------------------*/
43
 
44
#include "amber_registers.h"
45
#include "utilities.h"
46
 
47
 
48
int next_string(char*buf)
49
{
50
    int pos = 0;
51
    while (*buf != 0) {buf++; pos++;}
52
    return ++pos;
53
}
54
 
55
 
56
int strcmp(char* str1, char*str2)
57
{
58
    int pos = 0;
59
    int equal=1;
60
 
61
    while (*str1!=0 && *str2!=0 && pos<256 && equal) {
62
        equal = *str1==*str2;
63
        str1++;
64
        str2++;
65
        pos++;
66
        }
67
    return equal;
68
}
69
 
70
 
71
/* Return a number recovered from a string of hex digits */
72
int get_hex (char * buf, unsigned int *num)
73
{
74
    int cpos = 0, done = 0;
75
    *num = 0;
76
 
77
    while (!done) {
78
        if ( buf[cpos] >= '0' && buf[cpos] <= '9' ) {
79
           *num = *num<<4;
80
           *num = *num + buf[cpos] - '0';
81
           }
82
        else if ( buf[cpos] >= 'A' && buf[cpos] <= 'F' ) {
83
            *num = *num<<4;
84
            *num = *num + buf[cpos] - 'A' + 10;
85
           }
86
        else if ( buf[cpos] >= 'a' && buf[cpos] <= 'f' ) {
87
            *num = *num<<4;
88
            *num = *num + buf[cpos] - 'a' + 10;
89
           }
90
        else
91
            done = 1;
92
 
93
        // Don't increment cops if the first character is not part of an ascii-hex string
94
        // oo that a 0 is returned to indicate failure.
95
        if (!done)
96
            cpos++;
97
 
98
        if (cpos >= 8)
99
            done = 1;
100
        }
101
 
102
    /* Return length of acsii-hex string */
103
    return cpos;
104
}
105
 
106
 
107
void udelay20(void)
108
{
109
    volatile int i;
110
    for (i=0;i<500;i++) ;
111
}
112
 
113
 
114
void phy_rst(int value)
115
{
116
    *(unsigned int *) ADR_AMBER_TEST_PHY_RST = value;
117
}
118
 
119
 
120
/* turn off all leds */
121
void led_clear()
122
{
123
    *(unsigned int *) ADR_AMBER_TEST_LED = 0;
124
}
125
 
126
 
127
/* led is either 0,1,2 or 3 */
128
void led_flip(int led)
129
{
130
    int current_value;
131
    current_value = *(unsigned int *) ADR_AMBER_TEST_LED;
132
    *(unsigned int *) ADR_AMBER_TEST_LED = current_value ^ (1<<led);
133
}
134
 
135
 
136
 
137
/* led is either 0,1,2 or 3 */
138
void led_on(int led)
139
{
140
    int current_value;
141
    current_value = *(unsigned int *) ADR_AMBER_TEST_LED;
142
    *(unsigned int *) ADR_AMBER_TEST_LED = current_value | (1<<led);
143
}
144
 
145
 
146
 
147
/* led is either 0,1,2 or 3 */
148
void led_off(int led)
149
{
150
    int current_value;
151
    current_value = *(unsigned int *) ADR_AMBER_TEST_LED;
152
    *(unsigned int *) ADR_AMBER_TEST_LED = current_value & ~(1<<led);
153
}
154
 
155
 
156
/* led is either 0,1,2 or 3 */
157
void led_123(int value)
158
{
159
    int current_value;
160
    current_value = *(unsigned int *) ADR_AMBER_TEST_LED;
161
    *(unsigned int *) ADR_AMBER_TEST_LED = (current_value & 1) | value<<1;
162
}

powered by: WebSVN 2.1.0

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