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

Subversion Repositories darkriscv

[/] [darkriscv/] [trunk/] [src/] [main.c] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 marcelos
/*
2
 * Copyright (c) 2018, Marcelo Samsoniuk
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * * Neither the name of the copyright holder nor the names of its
16
 *   contributors may be used to endorse or promote products derived from
17
 *   this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
 
31
#include <io.h>
32
#include <stdio.h>
33
 
34
int main(void)
35
{
36
    printf("board: %s (id=%d)\n",board_name(io.board_id),io.board_id);
37 4 marcelos
    printf("build: %s for %s\n",BUILD,ARCH);
38 2 marcelos
 
39 4 marcelos
    for(int i=0;i!=threads;i++)
40
    {
41
      printf("core0/thread%d: darkriscv@%d.%dMHz rv32%s%s%s\n",
42
          i,
43
          io.board_cm,                        // board clock MHz
44
          io.board_ck,                        // board clock kHz
45
          check4rv32i()?"i":"e",              // architecture
46
          threads>1?"+MT":"",                 // MT  support
47
          mac(1000,16,16)==1256?"+MAC":"");   // MAC support
48
    }
49
 
50 2 marcelos
    threads = 0; // prepare for the next restart
51
 
52
    printf("uart0: 115200 bps (div=%d)\n",io.uart.baud);
53 4 marcelos
    printf("timr0: frequency=%dHz (io.timer=%d)\n",(io.board_cm*1000000u+io.board_ck*10000u)/(io.timer+1),io.timer);
54 2 marcelos
    printf("\n");
55
 
56
    printf("Welcome to DarkRISCV!\n");
57
 
58
    // main loop
59
 
60
    while(1)
61
    {
62
        char  buffer[64];
63
 
64
        printf("> ");
65
        memset(buffer,0,sizeof(buffer));
66
        gets(buffer,sizeof(buffer));
67
 
68
        char *argv[8];
69
        int   argc;
70
 
71
        for(argc=0;argc<8 && (argv[argc]=strtok(argc==0?buffer:NULL," "));argc++)
72
            //printf("argv[%d] = [%s]\n",argc,argv[argc]);
73
            ;
74
 
75
        if(argv[0])
76
        {
77
          if(!strcmp(argv[0],"clear"))
78
          {
79
              printf("\33[H\33[2J");
80
          }
81
          else
82
          if(!strcmp(argv[0],"reboot"))
83
          {
84
              int i;
85
 
86
              printf("core0: reboot in 3 seconds");
87
 
88
              for(i=0;i!=3;i++)
89
              {
90
                  usleep(1000000);
91
                  putchar('.');
92
              }
93
 
94
              printf("done.\n");
95
 
96
              return 0;
97
          }
98
          else
99
          if(!strcmp(argv[0],"dump"))
100
          {
101
              char *p=(char *)(kmem+(argv[1]?xtoi(argv[1]):0));
102
 
103
              int i,j;
104
 
105
              for(i=0;i!=16;i++)
106
              {
107
                  printf("%x: ",(unsigned) p);
108
 
109
                  for(j=0;j!=16;j++) printf("%x ",p[j]);
110
                  for(j=0;j!=16;j++) putchar((p[j]>=32&&p[j]<127)?p[j]:'.');
111
 
112
                  putchar('\n');
113
                  p+=16;
114
              }
115
          }
116
          else
117
          if(0) // if(!strncmp(argv[0],"rd",2)||!strncmp(argv[0],"wr",2))
118
          {
119
              int kp = 2,
120
                  i = 1,j,k,w,
121
                  vp = 1;
122
 
123
              if(argv[0][kp]=='m')
124
              {
125
                  i=xtoi(argv[vp++]);
126
                  kp++;
127
              }
128
 
129
              printf("%x: ",k=xtoi(argv[vp++]));
130
 
131
              for(j=0;i--;j++)
132
              {
133
                  if(argv[0][0]=='r')
134
                  {
135
                      if(argv[0][kp]=='b') printf("%x ",j[(char  *)k]);
136
                      if(argv[0][kp]=='w') printf("%x ",j[(short *)k]);
137
                      if(argv[0][kp]=='l') printf("%x ",j[(int   *)k]);
138
                  }
139
                  else
140
                  {
141
                      w = xtoi(argv[vp++]);
142
                      if(argv[0][kp]=='b') printf("%x ",j[(char  *)k]=w);
143
                      if(argv[0][kp]=='w') printf("%x ",j[(short *)k]=w);
144
                      if(argv[0][kp]=='l') printf("%x ",j[(int   *)k]=w);
145
                  }
146
              }
147
              printf("\n");
148
          }
149
          else
150
          if(!strcmp(argv[0],"led"))
151
          {
152
              if(argv[1]) io.led = xtoi(argv[1]);
153
 
154
              printf("led = %x\n",io.led);
155
          }
156
          else
157
          if(!strcmp(argv[0],"timer"))
158
          {
159
              if(argv[1]) io.timer = atoi(argv[1]);
160
 
161
              printf("timer = %d\n",io.timer);
162
          }
163
          else
164
          if(!strcmp(argv[0],"gpio"))
165
          {
166
              if(argv[1]) io.gpio = xtoi(argv[1]);
167
 
168
              printf("gpio = %x\n",io.gpio);
169
          }
170
          else
171
          if(!strcmp(argv[0],"mul"))
172
          {
173
              int x = atoi(argv[1]);
174
              int y = atoi(argv[2]);
175
 
176
              printf("mul = %d\n",x*y);
177
          }
178
          else
179
          if(!strcmp(argv[0],"div"))
180
          {
181
              int x = atoi(argv[1]);
182
              int y = atoi(argv[2]);
183
 
184
              printf("div = %d, mod = %d\n",x/y,x%y);
185
          }
186
          else
187
          if(!strcmp(argv[0],"mac"))
188
          {
189
              int acc = atoi(argv[1]);
190
              int x = atoi(argv[2]);
191
              int y = atoi(argv[3]);
192
 
193
              printf("mac = %d\n",mac(acc,x,y));
194
          }
195
          else
196
          if(!strcmp(argv[0],"srai"))
197
          {
198
              int acc = xtoi(argv[1]);
199
              printf("srai %x >> 1 = %x\n",acc,acc>>1);
200
          }
201
          else
202
          if(argv[0][0])
203
          {
204
              printf("command: [%s] not found.\n"
205
                     "valid commands: clear, dump <hex>, led <hex>, timer <dec>, gpio <hex>\n"
206
                     "                mul <dec> <dec>, div <dec> <dec>, mac <dec> <dec> <dec>\n"
207
                     "                rd[m][bwl] <hex> [<hex> when m], wr[m][bwl] <hex> <hex> [<hex> when m]\n",
208
                     argv[0]);
209
          }
210
       }
211
    }
212
}

powered by: WebSVN 2.1.0

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