Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
29
Issues
29
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
de90af81
Commit
de90af81
authored
Jun 04, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shell: moved environment functions to separate file
parent
07c2ccca
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
102 deletions
+126
-102
Makefile
Makefile
+3
-2
environ.c
shell/environ.c
+106
-0
shell.c
shell/shell.c
+5
-100
shell.h
shell/shell.h
+10
-0
shell.mk
shell/shell.mk
+2
-0
No files found.
Makefile
View file @
de90af81
PLATFORM
=
lm32
OBJS_WRC
=
wrc_main.o wrc_ptp.o dev/uart.o dev/endpoint.o dev/minic.o dev/pps_gen.o dev/syscon.o dev/softpll_ng.o
lib/mprintf.o
dev/ep_pfilter.o dev/dna.o dev/i2c.o monitor/monitor.o dev/onewire.o dev/eeprom.o
OBJS_WRC
=
wrc_main.o wrc_ptp.o dev/uart.o dev/endpoint.o dev/minic.o dev/pps_gen.o dev/syscon.o dev/softpll_ng.o dev/ep_pfilter.o dev/dna.o dev/i2c.o monitor/monitor.o dev/onewire.o dev/eeprom.o
D
=
ptp-noposix
PTPD_CFLAGS
=
-ffreestanding
-DPTPD_FREESTANDING
-DWRPC_EXTRA_SLIM
-DPTPD_MSBF
-DPTPD_DBG
...
...
@@ -34,6 +34,7 @@ OBJS_PLATFORM+=target/lm32/debug.o
include
shell/shell.mk
include
tests/tests.mk
include
lib/lib.mk
CC
=
$(CROSS_COMPILE)
gcc
OBJCOPY
=
$(CROSS_COMPILE)
objcopy
...
...
@@ -41,7 +42,7 @@ OBJDUMP=$(CROSS_COMPILE)objdump
CFLAGS
=
$(CFLAGS_PLATFORM)
-ffunction-sections
-fdata-sections
-Os
-Iinclude
-include
include/trace.h
$(PTPD_CFLAGS)
-Iptp-noposix
/PTPWRd
-I
.
LDFLAGS
=
$(LDFLAGS_PLATFORM)
-ffunction-sections
-fdata-sections
-Os
-Iinclude
SIZE
=
$(CROSS_COMPILE)
size
OBJS
=
$(OBJS_PLATFORM)
$(OBJS_WRC)
$(OBJS_PTPD)
$(OBJS_PTPD_FREE)
$(OBJS_SHELL)
$(OBJS_TESTS)
OBJS
=
$(OBJS_PLATFORM)
$(OBJS_WRC)
$(OBJS_PTPD)
$(OBJS_PTPD_FREE)
$(OBJS_SHELL)
$(OBJS_TESTS)
$(OBJS_LIB)
OUTPUT
=
wrc
REVISION
=
$(
shell
git rev-parse HEAD
)
...
...
shell/environ.c
0 → 100644
View file @
de90af81
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "shell.h"
#define SH_ENVIRON_SIZE 256
/* Environment-related functions */
static
unsigned
char
env_buf
[
SH_ENVIRON_SIZE
];
void
env_init
()
{
env_buf
[
0
]
=
0xff
;
}
static
char
*
_env_get
(
const
char
*
var
)
{
int
i
=
0
;
while
(
i
<
SH_ENVIRON_SIZE
&&
env_buf
[
i
]
!=
0xff
)
{
if
(
env_buf
[
i
]
==
0xaa
&&
!
strcasecmp
((
char
*
)
env_buf
+
i
+
1
,
var
))
return
(
char
*
)
env_buf
+
i
;
i
++
;
}
return
NULL
;
}
char
*
env_get
(
const
char
*
var
)
{
char
*
p
=
_env_get
(
var
);
if
(
!
p
)
return
NULL
;
return
p
+
2
+
strlen
(
p
+
1
);
}
static
int
_env_end
()
{
int
i
;
for
(
i
=
0
;
i
<
SH_ENVIRON_SIZE
;
i
++
)
if
(
env_buf
[
i
]
==
0xff
)
return
i
;
}
int
env_set
(
const
char
*
var
,
const
char
*
value
)
{
unsigned
char
*
vstart
=
_env_get
(
var
),
*
p
;
int
end
;
if
(
vstart
)
/* entry already present? remove current and append at the end of environment */
{
p
=
vstart
+
1
;
while
(
*
p
!=
0xaa
&&
*
p
!=
0xff
)
p
++
;
memmove
(
vstart
,
p
,
SH_ENVIRON_SIZE
-
(
p
-
env_buf
));
}
end
=
_env_end
();
if
((
end
+
strlen
(
var
)
+
strlen
(
value
)
+
3
)
>=
SH_ENVIRON_SIZE
)
return
-
ENOMEM
;
p
=
&
env_buf
[
end
];
*
p
++
=
0xaa
;
memcpy
(
p
,
var
,
strlen
(
var
)
+
1
);
p
+=
strlen
(
var
)
+
1
;
memcpy
(
p
,
value
,
strlen
(
value
)
+
1
);
p
+=
strlen
(
value
)
+
1
;
*
p
++
=
0xff
;
p
=
env_buf
;
return
0
;
}
int
cmd_env
(
const
char
*
args
[])
{
unsigned
char
*
p
=
env_buf
;
while
(
*
p
!=
0xff
)
{
if
(
*
p
==
0xaa
)
mprintf
(
"%s=%s
\n
"
,
p
+
1
,
p
+
strlen
(
p
+
1
)
+
2
);
p
++
;
}
return
0
;
}
int
cmd_saveenv
(
const
char
*
args
[])
{
return
-
ENOTSUP
;
}
int
cmd_set
(
const
char
*
args
[])
{
if
(
!
args
[
1
])
return
-
EINVAL
;
return
env_set
(
args
[
0
],
args
[
1
]);
}
shell/shell.c
View file @
de90af81
...
...
@@ -2,6 +2,8 @@
#include <string.h>
#include <errno.h>
#include "util.h"
#include "uart.h"
#include "shell.h"
#define SH_MAX_LINE_LEN 80
...
...
@@ -29,11 +31,6 @@ struct shell_cmd {
int
(
*
exec
)(
const
char
*
args
[]);
};
extern
int
uart_read_byte
();
static
int
cmd_env
(
const
char
*
args
[]);
static
int
cmd_saveenv
(
const
char
*
args
[]);
static
int
cmd_set
(
const
char
*
args
[]);
static
const
struct
shell_cmd
cmds_list
[]
=
{
{
"pll"
,
cmd_pll
},
...
...
@@ -46,7 +43,8 @@ static const struct shell_cmd cmds_list[] = {
{
"set"
,
cmd_set
},
{
"env"
,
cmd_env
},
{
"saveenv"
,
cmd_saveenv
},
{
"time"
,
cmd_time
},
{
NULL
,
NULL
}
};
...
...
@@ -55,99 +53,6 @@ static int cmd_pos = 0, cmd_len = 0;
static
int
state
=
SH_PROMPT
;
static
int
current_key
=
0
;
/* Environment-related functions */
static
unsigned
char
env_buf
[
SH_ENVIRON_SIZE
];
static
char
*
_env_get
(
const
char
*
var
)
{
int
i
=
0
;
while
(
i
<
SH_ENVIRON_SIZE
&&
env_buf
[
i
]
!=
0xff
)
{
if
(
env_buf
[
i
]
==
0xaa
&&
!
strcasecmp
(
env_buf
+
i
+
1
,
var
))
return
env_buf
+
i
;
i
++
;
}
return
NULL
;
}
static
char
*
env_get
(
const
char
*
var
)
{
char
*
p
=
_env_get
(
var
);
if
(
!
p
)
return
NULL
;
return
p
+
2
+
strlen
(
p
+
1
);
}
static
int
_env_end
()
{
int
i
;
for
(
i
=
0
;
i
<
SH_ENVIRON_SIZE
;
i
++
)
if
(
env_buf
[
i
]
==
0xff
)
return
i
;
}
static
int
env_set
(
const
char
*
var
,
const
char
*
value
)
{
unsigned
char
*
vstart
=
_env_get
(
var
),
*
p
;
int
end
;
if
(
vstart
)
/* entry already present? remove current and append at the end of environment */
{
p
=
vstart
+
1
;
while
(
*
p
!=
0xaa
&&
*
p
!=
0xff
)
p
++
;
memmove
(
vstart
,
p
,
SH_ENVIRON_SIZE
-
(
p
-
env_buf
));
}
end
=
_env_end
();
if
((
end
+
strlen
(
var
)
+
strlen
(
value
)
+
3
)
>=
SH_ENVIRON_SIZE
)
return
-
ENOMEM
;
p
=
&
env_buf
[
end
];
*
p
++
=
0xaa
;
memcpy
(
p
,
var
,
strlen
(
var
)
+
1
);
p
+=
strlen
(
var
)
+
1
;
memcpy
(
p
,
value
,
strlen
(
value
)
+
1
);
p
+=
strlen
(
value
)
+
1
;
*
p
++
=
0xff
;
p
=
env_buf
;
return
0
;
}
static
int
cmd_env
(
const
char
*
args
[])
{
unsigned
char
*
p
=
env_buf
;
while
(
*
p
!=
0xff
)
{
if
(
*
p
==
0xaa
)
mprintf
(
"%s=%s
\n
"
,
p
+
1
,
p
+
strlen
(
p
+
1
)
+
2
);
p
++
;
}
return
0
;
}
static
int
cmd_saveenv
(
const
char
*
args
[])
{
return
-
ENOTSUP
;
}
static
int
cmd_set
(
const
char
*
args
[])
{
if
(
!
args
[
1
])
return
-
EINVAL
;
return
env_set
(
args
[
0
],
args
[
1
]);
}
static
int
insert
(
char
c
)
{
if
(
cmd_len
>=
SH_MAX_LINE_LEN
)
...
...
@@ -226,7 +131,7 @@ int shell_exec(const char *cmd)
void
shell_init
()
{
env_
buf
[
0
]
=
0xff
;
env_
init
()
;
cmd_len
=
cmd_pos
=
0
;
state
=
SH_PROMPT
;
mprintf
(
"
\033
[2J
\033
[1;1H"
);
...
...
shell/shell.h
View file @
de90af81
...
...
@@ -9,8 +9,18 @@ int cmd_ptp(const char *args[]);
int
cmd_sfp
(
const
char
*
args
[]);
int
cmd_mode
(
const
char
*
args
[]);
int
cmd_measure_t24p
(
const
char
*
args
[]);
int
cmd_time
(
const
char
*
args
[]);
int
cmd_env
(
const
char
*
args
[]);
int
cmd_saveenv
(
const
char
*
args
[]);
int
cmd_set
(
const
char
*
args
[]);
char
*
env_get
(
const
char
*
var
);
int
env_set
(
const
char
*
var
,
const
char
*
value
);
void
env_init
();
int
shell_exec
(
const
char
*
buf
);
void
shell_interactive
();
#endif
shell/shell.mk
View file @
de90af81
OBJS_SHELL = shell/shell.o \
shell/environ.o \
shell/cmd_version.o \
shell/cmd_pll.o \
shell/cmd_stat.o \
shell/cmd_ptp.o \
shell/cmd_mode.o \
shell/cmd_measure_t24p.o \
shell/cmd_time.o \
shell/cmd_gui.o
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment