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

Subversion Repositories darkriscv

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

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
    printf("build: darkriscv fw build %s\n",BUILD);
38
 
39
    printf("core0: darkriscv@%d.%dMHz with %s%s%s\n",
40
        io.board_cm,                        // board clock MHz
41
        io.board_ck,                        // board clock kHz
42
        ARCH,                               // architecture
43
        threads>1?"+MT":"",                 //  MT support
44
        mac(1000,16,16)==1256?"+MAC":"");   // MAC support
45
 
46
    threads = 0; // prepare for the next restart
47
 
48
    printf("uart0: 115200 bps (div=%d)\n",io.uart.baud);
49
    printf("timr0: periodic timer=%dHz (io.timer=%d)\n",(io.board_cm*1000000u+io.board_ck*10000u)/(io.timer+1),io.timer);
50
    printf("\n");
51
 
52
    printf("Welcome to DarkRISCV!\n");
53
 
54
    usleep(10);
55
 
56
    // main loop
57
 
58
    while(1)
59
    {
60
        char  buffer[64];
61
 
62
        printf("> ");
63
        memset(buffer,0,sizeof(buffer));
64
        gets(buffer,sizeof(buffer));
65
 
66
        char *argv[8];
67
        int   argc;
68
 
69
        for(argc=0;argc<8 && (argv[argc]=strtok(argc==0?buffer:NULL," "));argc++)
70
            //printf("argv[%d] = [%s]\n",argc,argv[argc]);
71
            ;
72
 
73
        if(argv[0])
74
        {
75
          if(!strcmp(argv[0],"clear"))
76
          {
77
              printf("\33[H\33[2J");
78
          }
79
          else
80
          if(!strcmp(argv[0],"reboot"))
81
          {
82
              int i;
83
 
84
              printf("core0: reboot in 3 seconds");
85
 
86
              for(i=0;i!=3;i++)
87
              {
88
                  usleep(1000000);
89
                  putchar('.');
90
              }
91
 
92
              printf("done.\n");
93
 
94
              return 0;
95
          }
96
          else
97
          if(!strcmp(argv[0],"dump"))
98
          {
99
              char *p=(char *)(kmem+(argv[1]?xtoi(argv[1]):0));
100
 
101
              int i,j;
102
 
103
              for(i=0;i!=16;i++)
104
              {
105
                  printf("%x: ",(unsigned) p);
106
 
107
                  for(j=0;j!=16;j++) printf("%x ",p[j]);
108
                  for(j=0;j!=16;j++) putchar((p[j]>=32&&p[j]<127)?p[j]:'.');
109
 
110
                  putchar('\n');
111
                  p+=16;
112
              }
113
          }
114
          else
115
          if(0) // if(!strncmp(argv[0],"rd",2)||!strncmp(argv[0],"wr",2))
116
          {
117
              int kp = 2,
118
                  i = 1,j,k,w,
119
                  vp = 1;
120
 
121
              if(argv[0][kp]=='m')
122
              {
123
                  i=xtoi(argv[vp++]);
124
                  kp++;
125
              }
126
 
127
              printf("%x: ",k=xtoi(argv[vp++]));
128
 
129
              for(j=0;i--;j++)
130
              {
131
                  if(argv[0][0]=='r')
132
                  {
133
                      if(argv[0][kp]=='b') printf("%x ",j[(char  *)k]);
134
                      if(argv[0][kp]=='w') printf("%x ",j[(short *)k]);
135
                      if(argv[0][kp]=='l') printf("%x ",j[(int   *)k]);
136
                  }
137
                  else
138
                  {
139
                      w = xtoi(argv[vp++]);
140
                      if(argv[0][kp]=='b') printf("%x ",j[(char  *)k]=w);
141
                      if(argv[0][kp]=='w') printf("%x ",j[(short *)k]=w);
142
                      if(argv[0][kp]=='l') printf("%x ",j[(int   *)k]=w);
143
                  }
144
              }
145
              printf("\n");
146
          }
147
          else
148
          if(!strcmp(argv[0],"led"))
149
          {
150
              if(argv[1]) io.led = xtoi(argv[1]);
151
 
152
              printf("led = %x\n",io.led);
153
          }
154
          else
155
          if(!strcmp(argv[0],"timer"))
156
          {
157
              if(argv[1]) io.timer = atoi(argv[1]);
158
 
159
              printf("timer = %d\n",io.timer);
160
          }
161
          else
162
          if(!strcmp(argv[0],"gpio"))
163
          {
164
              if(argv[1]) io.gpio = xtoi(argv[1]);
165
 
166
              printf("gpio = %x\n",io.gpio);
167
          }
168
          else
169
          if(!strcmp(argv[0],"mul"))
170
          {
171
              int x = atoi(argv[1]);
172
              int y = atoi(argv[2]);
173
 
174
              printf("mul = %d\n",x*y);
175
          }
176
          else
177
          if(!strcmp(argv[0],"div"))
178
          {
179
              int x = atoi(argv[1]);
180
              int y = atoi(argv[2]);
181
 
182
              printf("div = %d, mod = %d\n",x/y,x%y);
183
          }
184
          else
185
          if(!strcmp(argv[0],"mac"))
186
          {
187
              int acc = atoi(argv[1]);
188
              int x = atoi(argv[2]);
189
              int y = atoi(argv[3]);
190
 
191
              printf("mac = %d\n",mac(acc,x,y));
192
          }
193
          else
194
          if(!strcmp(argv[0],"srai"))
195
          {
196
              int acc = xtoi(argv[1]);
197
              printf("srai %x >> 1 = %x\n",acc,acc>>1);
198
          }
199
          else
200
          if(argv[0][0])
201
          {
202
              printf("command: [%s] not found.\n"
203
                     "valid commands: clear, dump <hex>, led <hex>, timer <dec>, gpio <hex>\n"
204
                     "                mul <dec> <dec>, div <dec> <dec>, mac <dec> <dec> <dec>\n"
205
                     "                rd[m][bwl] <hex> [<hex> when m], wr[m][bwl] <hex> <hex> [<hex> when m]\n",
206
                     argv[0]);
207
          }
208
       }
209
    }
210
}

powered by: WebSVN 2.1.0

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