Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Testing
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Testing
Commits
dd955562
Commit
dd955562
authored
Feb 13, 2013
by
Benoit Rat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shw_tool: update code to be compatible with v3.3 (add LED, IO, Temp, ...)
parent
962f8a25
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
818 additions
and
79 deletions
+818
-79
Makefile
sw/shw_tool/Makefile
+28
-8
shw_tool.c
sw/shw_tool/shw_tool.c
+680
-71
sysmon-regs.h
sw/shw_tool/sysmon-regs.h
+110
-0
No files found.
sw/shw_tool/Makefile
View file @
dd955562
## Makefile
#-------------------------------------------------------------------------------
# Makefile
#
# Copyright (c) 2012
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Public License v2.0
# which accompanies this distribution, and is available at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# Contributors:
# Cesar Prados
# Benoit Rat
#-------------------------------------------------------------------------------
# Parameters
TMP
=
$
(
warning
$(
shell
WRS_BASE_DIR
=
$(WRS_BASE_DIR)
/
printenv
|
grep
WRS_BASE_DIR
)
)
ifeq
($(strip
$(WRS_BASE_DIR)),)
$(error
You
first
need
to
define
WRS_BASE_DIR
variable)
#WRS_BASE_DIR=/home/neub/Work/7S/WR/wr-switch-sw/build
endif
EXEC
=
shw_tool
INCLUDES
=
-I
.
-I
${
WRS_BASE_DIR
}
/../userspace/include
-I
${
WRS_BASE_DIR
}
/../userspace/libswitchhw
LDFLAGS
=
-L
${
WRS_BASE_DIR
}
/../userspace/libswitchhw
-lswitchhw
-lm
-ldl
-llua
...
...
@@ -16,7 +32,10 @@ CC = ${CROSS_COMPILE}gcc
#############
all
:
$(EXEC)
all
:
libswitchhw.a ${WRS_BASE_DIR}/../userspace/libswitchhw/libswitchhw.a $(EXEC)
libswitchhw.a
:
$(MAKE)
-C
${
WRS_BASE_DIR
}
/../userspace/libswitchhw all
%.o
:
%.c %.h $(DEPS)
${
CC
}
${
CFLAGS
}
-c
$<
-o
$@
...
...
@@ -32,9 +51,10 @@ clean:
INSTALLDIR
=
alpha-pts/bin/
install
:
all
cp
${
EXEC
}
../
${
INSTALLDIR
}
$(MAKE)
-C
${
WRS_BASE_DIR
}
/../userspace/libswitchhw
install
cp
$(EXEC)
../
$(INSTALLDIR)
cp
$(EXEC)
$(WR_INSTALL_ROOT)
/bin/
#cp $(EXEC) $(WR_INSTALL_ROOT)/../$(INSTALLDIR)
cp
:
all
cp
${
EXEC
}
../
${
INSTALLDIR
}
cp
${
EXEC
}
/tftpboot/rootfs-test/
${
INSTALLDIR
}
\ No newline at end of file
install2
:
libswitchhw.a clean install
sw/shw_tool/shw_tool.c
View file @
dd955562
/*
*
Libswitchhw-tester
*
shw_tool:
*
* Test the libswitchhw library by calling various of its components.
*
* Created on: Oct 30, 2012
* Authors:
* - Benoit RAT
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License...
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "switch_hw.h"
//#include "pio_pins.h"
#include "pio.h"
#include <sys/ioctl.h>
#include <at91_softpwm.h>
#include "fan.h"
#include <fcntl.h>
#include <util.h>
#include <fan.h>
#include <fpga_io.h>
#include <sfp_lib.h>
#include <i2c_io.h>
#include "sysmon-regs.h"
extern
const
pio_pin_t
PIN_mbl_box_fan_en
[];
static
int
pwm_fd
;
#include <shw_io.h>
static
char
*
pgr_name
;
static
char
*
cmd_name
;
//extern const pio_pin_t* _all_cpu_gpio_pins[];
//extern pio_pin_t* _all_fpga_gpio_pins[];
//--------------------------------------- functions
//---------------------------------------
tools
functions
void
usage_error
(
char
**
argv
)
void
print_args
(
int
argc
,
char
*
argv
[]
)
{
fprintf
(
stderr
,
"usage: %s <command> <values>
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
" --fan <fan_speed> (from 0 to 100)
\n
"
);
fprintf
(
stderr
,
" --led <test_ID>
\n
"
);
exit
(
1
);
printf
(
"argc=%d: "
,
argc
);
while
(
argc
>
0
)
{
printf
(
"%s, "
,
argv
[
0
]);
argc
--
;
argv
++
;
}
printf
(
"
\n
"
);
}
/**
* Copy of the function in fan.c to control the softpwn driver.
*/
static
int
enable_d0
=
0
;
void
pwm_configure_pin2
(
const
pio_pin_t
*
pin
,
int
enable
,
int
rate
)
int
atoideflim
(
char
*
arg
,
int
defval
,
int
min
,
int
max
)
{
int
index
=
pin
->
port
*
32
+
pin
->
pin
;
if
(
enable
&&
!
enable_d0
)
ioctl
(
pwm_fd
,
AT91_SOFTPWM_ENABLE
,
index
);
else
if
(
!
enable
&&
enable_d0
)
ioctl
(
pwm_fd
,
AT91_SOFTPWM_DISABLE
,
index
);
enable_d0
=
enable
;
ioctl
(
pwm_fd
,
AT91_SOFTPWM_SETPOINT
,
rate
);
int
ret
=
atoidef
(
arg
,
defval
);
if
(
min
<=
ret
&&
ret
<=
max
)
return
ret
;
else
return
defval
;
}
void
shw_pio_printf
(
const
pio_pin_t
*
pio
)
{
printf
(
"PIO_%c(%d) mode=%d dir=%s
\t
"
,
...
...
@@ -62,89 +80,680 @@ void shw_pio_printf(const pio_pin_t *pio)
}
void
fan_speed
(
int
speed
)
/**
* Change the fan speed of the PWM.
* Note: It seems that it is not working properly at the moment.
*/
int
fan_tool
(
int
argc
,
char
**
argv
)
{
const
pio_pin_t
*
fan_en
=
(
const
pio_pin_t
*
)
&
PIN_mbl_box_fan_en
;
TRACE
(
TRACE_INFO
,
"Starting Fan Test at %d%"
,
speed
);
char
opt
=
0
;
int
optind
=
1
;
uint8_t
f_help
=
0
;
int
bmask
=
0xFF
,
speed
=
0
,
timeout
=
0
;
print_args
(
argc
,
argv
);
while
((
opt
=
getopt
(
argc
,
argv
,
"m:t:h?"
))
!=
0xFF
)
{
optind
++
;
switch
(
opt
)
{
case
'm'
:
bmask
=
atoideflim
(
optarg
,
bmask
,
0
,
0xFF
);
optind
++
;
break
;
case
't'
:
timeout
=
atoideflim
(
optarg
,
timeout
,
-
1
,
0xFFFFFF
);
optind
++
;
break
;
case
'h'
:
case
'?'
:
f_help
=
1
;
break
;
default:
printf
(
"find: illegal option %c (%x)
\n
"
,
opt
,
opt
);
break
;
}
}
argc
-=
optind
;
argv
+=
optind
;
print_args
(
argc
,
argv
);
speed
=
atoideflim
(
argv
[
0
],
speed
,
0
,
100
);
if
(
f_help
)
{
printf
(
"Usage %s %s [OPTIONS] <speed in %>
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
"OPTIONS:
\n
"
" -m bit mask to select the FAN: 0x07 (1, 2 & 3), 0x2 (only 2) (def=0xFF)
\n
"
" -t timeout value in s for updating pwm (def=0)
\n
"
" -h show this help
\n
"
""
);
return
;
}
TRACE
(
TRACE_INFO
,
"Starting Fan Test at %d%% (m=0x%x,t=%ds)"
,
speed
,
bmask
,
timeout
);
shw_pio_mmap_init
();
shw_pio_configure
(
fan_en
);
shw_fpga_mmap_init
();
shw_io_init
();
shw_io_configure_all
();
shw_init_fans
();
if
(
timeout
>=
0
)
shw_pwm_update_timeout
(
timeout
);
else
shw_pwm_update_timeout
(
SHW_FAN_UPDATETO_DEFAULT
);
shw_pwm_speed
(
bmask
,(
speed
)
/
100
.
0
);
}
pwm_fd
=
open
(
"/dev/at91_softpwm"
,
O_RDWR
);
if
(
pwm_fd
<
0
)
/**
* Check all the LED accesible from the CPU.
*/
void
led_tool
(
int
argc
,
char
**
argv
)
{
char
opt
=
0
;
int
optind
=
1
;
int
i
,
j
;
static
unsigned
char
pattern1
[]
=
{
1
,
0
,
1
,
0
};
static
unsigned
char
pattern2
[]
=
{
0
,
1
,
1
,
0
};
static
char
*
desc
[]
=
{
"green"
,
"orange"
,
"yellow"
,
"none"
};
uint8_t
f_help
=
0
,
f_cpu
=
0
,
f_sfp
=
0
,
f_front
=
0
,
f_all
=
1
;
int
spause
=
3
,
idpattern
=-
1
;
print_args
(
argc
,
argv
);
while
((
opt
=
getopt
(
argc
,
argv
,
"p:i:csfh?"
))
!=
0xFF
)
{
TRACE
(
TRACE_INFO
,
"at91_softpwm driver not installed or device not created (Only on/off mode)."
);
if
(
speed
<=
0
)
shw_pio_set
(
fan_en
,
0
);
else
if
(
speed
>=
100
)
shw_pio_set
(
fan_en
,
1
);
optind
++
;
switch
(
opt
)
{
case
'p'
:
spause
=
atoideflim
(
optarg
,
spause
,
0
,
0xFFFFFF
);
optind
++
;
break
;
case
'i'
:
idpattern
=
atoideflim
(
optarg
,
idpattern
,
-
1
,
sizeof
(
pattern1
));
optind
++
;
break
;
case
'c'
:
f_cpu
=
1
;
f_all
=
0
;
break
;
case
's'
:
f_sfp
=
1
;
f_all
=
0
;
break
;
case
'f'
:
f_front
=
1
;
f_all
=
0
;
break
;
case
'h'
:
case
'?'
:
f_help
=
1
;
break
;
default:
printf
(
"find: illegal option %c (%x)
\n
"
,
opt
,
opt
);
break
;
}
}
else
argc
-=
optind
;
argv
+=
optind
;
print_args
(
argc
,
argv
);
if
(
f_help
)
{
printf
(
"Usage %s %s [OPTIONS]
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
"OPTIONS:
\n
"
" -i id of the selected patter (-1=all)
\n
"
" -p pause during X sec between pattern
\n
"
" -c cpu led (inside box, on SCB)
\n
"
" -s SFP led
\n
"
" -f front led
\n
"
" -h show this help
\n
"
""
);
return
;
}
if
(
f_all
)
{
f_cpu
=
1
;
f_sfp
=
1
;
f_front
=
1
;
}
TRACE
(
TRACE_INFO
,
"Starting led test c=%d,s=%d,f=%d (p= %ds, id=%d)"
,
f_cpu
,
f_sfp
,
f_front
,
spause
,
idpattern
);
//Mapping in userspace
//shw_pio_mmap_init();
//Init and configuration
assert_init
(
shw_io_init
());
assert_init
(
shw_io_configure_all
());
//Initialization of FPGA LEDs.
if
(
f_sfp
)
{
shw_fpga_mmap_init
();
shw_sfp_buses_init
();
shw_sfp_gpio_init
();
}
for
(
i
=
0
;
i
<
sizeof
(
pattern1
);
i
++
)
{
//Check only for desired pattern
if
(
idpattern
>=
0
&&
idpattern
!=
i
)
continue
;
TRACE
(
TRACE_INFO
,
"#%d > %-8s (Link & Sync=%d, WR & Act=%d)"
,
i
,
desc
[
i
],
pattern1
[
i
],
pattern2
[
i
]);
if
(
f_cpu
)
{
shw_io_write
(
shw_io_led_cpu1
,
pattern2
[
i
]);
shw_io_write
(
shw_io_led_cpu2
,
pattern1
[
i
]);
}
if
(
f_sfp
)
{
for
(
j
=
0
;
j
<
18
;
j
++
)
{
//left LED
shw_sfp_set_led_link
(
j
,
pattern1
[
i
]);
shw_sfp_set_led_wrmode
(
j
,
pattern2
[
i
]);
//Right LED
shw_sfp_set_led_synced
(
j
,
pattern1
[
i
]);
//We can not access to the activity LED from the FPGA
}
}
if
(
f_front
)
{
shw_io_write
(
shw_io_led_state_g
,
pattern1
[
i
]);
shw_io_write
(
shw_io_led_state_o
,
pattern2
[
i
]);
}
if
(
idpattern
<
0
)
sleep
(
spause
);
}
}
//#define SCB_32 1
#define TSENSORS_SYSMON 0
#define TSENSORS_I2C 1
#define Sensor_TEMP_FPGA 0x4A //(7bits addr) Below FPGA
#ifdef SCB_32
#define Sensor_TEMP_PLL 0x4C //(7bits addr) PLLs
#define Sensor_TEMP_PSL 0x49 //(7bits addr) Power supply left
#define Sensor_TEMP_PSR 0x4D //(7bits addr) Power supply right
#else
#define Sensor_TEMP_PLL 0x48 //(7bits addr) PLLs
#define Sensor_TEMP_PSR 0x49 //(7bits addr) Power supply
#define Sensor_TEMP_PSL 0x49 //(7bits addr) Power supply
#endif
typedef
struct
{
char
name
[
20
];
uint8_t
type
;
uint32_t
val
;
}
t_sensor
;
t_sensor
sensors
[
7
]
=
{
{
"T_ACT"
,
TSENSORS_SYSMON
,
1
},
{
"T_MAX"
,
TSENSORS_SYSMON
,
2
},
{
"T_MIN"
,
TSENSORS_SYSMON
,
3
},
{
"T_BFPGA"
,
TSENSORS_I2C
,
Sensor_TEMP_FPGA
},
{
"T_PLL"
,
TSENSORS_I2C
,
Sensor_TEMP_PLL
},
{
"T_PSR"
,
TSENSORS_I2C
,
Sensor_TEMP_PSR
},
{
"T_PSL"
,
TSENSORS_I2C
,
Sensor_TEMP_PSL
},
};
/**
* Monotorize basic behaviour of the switch (temperature, volatge)
*/
void
monotorize
(
int
argc
,
char
*
argv
[])
{
char
opt
=
0
;
uint8_t
f_time
=
0
,
f_help
=
0
;
int
optind
=
1
,
maxloop
=-
1
,
iloop
=
0
,
nsecup
=
3
;
int
_isensor
,
isensor
,
start
=
0
,
end
=
sizeof
(
sensors
)
/
sizeof
(
t_sensor
);
float
t_cur
;
print_args
(
argc
,
argv
);
while
((
opt
=
getopt
(
argc
,
argv
,
"l:u:th?"
))
!=
0xFF
)
{
optind
++
;
switch
(
opt
)
{
case
'l'
:
maxloop
=
atoideflim
(
optarg
,
-
1
,
0
,
0x0FFFFFFF
);
optind
++
;
break
;
case
'u'
:
nsecup
=
atoideflim
(
optarg
,
-
1
,
0
,
3600
);
optind
++
;
break
;
case
't'
:
f_time
=
1
;
break
;
case
'h'
:
case
'?'
:
f_help
=
1
;
break
;
default:
printf
(
"find: illegal option %c (%x)
\n
"
,
opt
,
opt
);
break
;
}
}
argc
-=
optind
;
argv
+=
optind
;
print_args
(
argc
,
argv
);
_isensor
=
atoideflim
(
argv
[
0
],
-
1
,
0
,
end
);
if
(
f_help
)
{
printf
(
"Usage %s %s [OPTIONS]
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
"OPTIONS:
\n
"
" -l number of loop (if negative it loop infinitively)
\n
"
" -u update frequency in second (default=3s)
\n
"
" -t show time in seconds
\n
"
""
);
return
;
}
TRACE
(
TRACE_INFO
,
"Starting temp tool (%d,%d,%d)"
,
_isensor
,
maxloop
,
end
);
//Initialization
shw_pio_mmap_init
();
shw_fpga_mmap_init
();
shw_init_i2c_sensors
();
if
(
0
<=
_isensor
&&
_isensor
<
end
)
{
start
=
_isensor
;
end
=
_isensor
+
1
;
}
if
(
f_time
)
printf
(
"%10s"
,
"time (in s)
\t
"
);
//Print sensors columns
for
(
isensor
=
start
;
isensor
<
end
;
isensor
++
)
{
printf
(
"%6s
\t
"
,
sensors
[
isensor
].
name
);
if
(
sensors
[
isensor
].
type
==
TSENSORS_I2C
)
tmp100_write_reg
(
sensors
[
isensor
].
val
,
1
,
0x60
);
// 12-bit resolution
}
printf
(
"
\n
"
);
fflush
(
stdout
);
while
(
iloop
++!=
maxloop
)
{
printf
(
"
\n
"
);
if
(
f_time
)
printf
(
"%10d
\t
"
,
time
(
NULL
));
for
(
isensor
=
start
;
isensor
<
end
;
isensor
++
)
{
if
(
sensors
[
isensor
].
type
==
TSENSORS_I2C
)
{
t_cur
=
tmp100_read_temp
(
sensors
[
isensor
].
val
);
}
else
{
t_cur
=
(
float
)((
_fpga_readl
(
0x57000
)
>>
sensors
[
isensor
].
val
*
8
)
&
0xFF
)
/
2
.
0
;
}
printf
(
"%6.1f
\t
"
,
t_cur
);
}
fflush
(
stdout
);
sleep
(
nsecup
);
}
printf
(
"
\n
"
);
}
/**
* Parse cmd line to display GPIO value.
*/
int
gpio_tool
(
int
argc
,
char
**
argv
)
{
int
value
;
pio_pin_t
gpio
=
{
-
1
,
-
1
,
PIO_MODE_GPIO
,
PIO_OUT
}
;
print_args
(
argc
,
argv
);
gpio
.
port
=
(
int
)
argv
[
1
][
0
]
-
'A'
+
1
;
gpio
.
pin
=
atoideflim
(
argv
[
2
],
-
1
,
0
,
32
);
value
=
atoideflim
(
argv
[
3
],
1
,
0
,
1
);
printf
(
"%d => "
,
value
);
shw_pio_printf
(
&
gpio
);
shw_pio_mmap_init
();
shw_pio_configure
((
const
pio_pin_t
*
)
&
gpio
);
if
(
value
)
shw_pio_set
((
const
pio_pin_t
*
)
&
gpio
,
1
);
else
shw_pio_set
((
const
pio_pin_t
*
)
&
gpio
,
0
);
}
/**
* Parse cmd line to display GPIO value.
*/
int
io_tool
(
int
argc
,
char
**
argv
)
{
int
i
=
0
,
id
=
0
,
value
=-
1
;
char
cmdchr
=
'h'
;
shw_io_t
*
all_io
=
(
shw_io_t
*
)
_all_shw_io
;
argc
--
;
argv
++
;
print_args
(
argc
,
argv
);
if
(
argc
==
1
&&
strcmp
(
argv
[
0
],
"-h"
)
==
0
)
{
if
(
speed
>=
100
)
speed
=
99
;
//TODO: Fix this bug
printf
(
"Usage %s %s [<id>] [<value>]
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
"%s %s : list all available io
\n
"
"%s %s <id> : Read the IO with id
\n
"
"%s %s <id> <val> : Write value in the IO with id
\n
"
"%s %s -h : Show this little help
\n
"
""
,
pgr_name
,
cmd_name
,
pgr_name
,
cmd_name
,
pgr_name
,
cmd_name
,
pgr_name
,
cmd_name
);
return
1
;
}
assert_init
(
shw_pio_mmap_init
());
assert_init
(
shw_io_init
());
assert_init
(
shw_io_configure_all
());
if
(
speed
<=
0
)
id
=
atoideflim
(
argv
[
0
],
id
,
0
,
NUM_SHW_IO_ID
);
value
=
atoidef
(
argv
[
1
],
value
);
//List
if
(
argc
==
0
)
{
TRACE
(
TRACE_INFO
,
"io list (%d)"
,
NUM_SHW_IO_ID
);
for
(
i
=
0
;
i
<
NUM_SHW_IO_ID
;
i
++
)
{
TRACE
(
TRACE_INFO
,
"zero speed"
);
pwm_configure_pin2
((
const
pio_pin_t
*
)
&
PIN_mbl_box_fan_en
,
0
,
1000
);
//If we put to 1000 it almost get 0
shw_pio_set
(
fan_en
,
0
);
if
(
all_io
[
i
].
type
)
printf
(
"%d => %-20s %d
\n
"
,
all_io
[
i
].
ID
,
all_io
[
i
].
name
,
all_io
[
i
].
type
);
}
else
pwm_configure_pin2
((
const
pio_pin_t
*
)
&
PIN_mbl_box_fan_en
,
1
,
(
int
)(
speed
*
10
));
}
else
if
(
argc
==
1
)
{
//Read
printf
(
"#%d %s = %d (0x%X)
\n
"
,
all_io
[
id
].
ID
,
all_io
[
id
].
name
,
shw_io_read
(
id
),
shw_io_read
(
id
));
}
else
if
(
argc
==
2
)
{
//Write
printf
(
"#%d %s writing %d (0x%X)
\n
"
,
all_io
[
id
].
ID
,
all_io
[
id
].
name
,
value
,
value
);
shw_io_write
(
id
,
value
);
}
}
const
pio_pin_t
PIN_mbl_box_led_cpu1
[]
=
{{
PIOA
,
0
,
PIO_MODE_GPIO
,
PIO_OUT
},
{
0
}};
const
pio_pin_t
PIN_mbl_box_led_cpu2
[]
=
{{
PIOA
,
1
,
PIO_MODE_GPIO
,
PIO_OUT
},
{
0
}};
void
led_test
(
int
led_id
)
#define FPGA_WB_SYSMON_ADDRESS 0x57000
#include "i2c_sfp.h"
extern
struct
i2c_bus
i2c_buses
[];
void
i2c_tool
(
int
argc
,
char
*
argv
[])
{
int
i
;
static
unsigned
char
pattern1
[]
=
{
0
,
1
,
0
,
1
};
static
unsigned
char
pattern2
[]
=
{
1
,
0
,
0
,
1
};
//Configuration
TRACE
(
TRACE_INFO
,
"Starting led_test tools"
);
char
opt
=
0
;
int
optind
=
1
;
uint8_t
f_time
=
0
,
f_help
=
0
;
int
i
=
0
,
nbus
=
0
,
addr
=
0
;
char
cmdchr
=
'h'
;
uint8_t
value
,
map
[
32
];
print_args
(
argc
,
argv
);
while
((
opt
=
getopt
(
argc
,
argv
,
"b:a:h?"
))
!=
0xFF
)
{
optind
++
;
switch
(
opt
)
{
case
'b'
:
nbus
=
atoideflim
(
optarg
,
nbus
,
0
,
6
);
optind
++
;
break
;
case
'a'
:
addr
=
atoideflim
(
optarg
,
addr
,
0
,
128
);
optind
++
;
break
;
case
'h'
:
case
'?'
:
f_help
=
1
;
break
;
default:
printf
(
"find: illegal option %c (%x)
\n
"
,
opt
,
opt
);
break
;
}
}
argc
-=
optind
;
argv
+=
optind
;
print_args
(
argc
,
argv
);
cmdchr
=
(
argc
>=
1
)
?
argv
[
0
][
0
]
:
'h'
;
value
=
atoideflim
(
argv
[
1
],
0
,
0
,
0xFF
);
if
(
f_help
||
cmdchr
==
'h'
)
{
printf
(
"Usage %s %s [OPTIONS] <cmd> [<value>]
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
"cmd: r (read), w (write), s (scan), c (config), h (help)
\n
"
"OPTIONS:
\n
"
" -b Bus number
\n
"
" -a Adress in the bus (0x20+addr)
\n
"
""
);
return
;
}
TRACE
(
TRACE_INFO
,
"i2c scanning"
);
//Initialization
shw_pio_mmap_init
();
shw_pio_configure
((
const
pio_pin_t
*
)
&
PIN_mbl_box_led_cpu1
);
shw_pio_configure
((
const
pio_pin_t
*
)
&
PIN_mbl_box_led_cpu2
);
shw_i2c_io_init
();
shw_fpga_mmap_init
();
shw_sfp_buses_init
();
//Scanning
if
(
cmdchr
==
's'
)
{
i
=
0
;
while
(
1
)
{
printf
(
"bus: %i "
,
i
);
fflush
(
stdout
);
if
(
shw_sfp_bus_scan
(
i
,
map
)
<
0
)
break
;
else
i
++
;
}
shw_i2c_io_scan
(
map
);
}
}
/**
* Similar as using as devmem but without using the 0x100XXXXX offset
* It also improve how parsing is done.
*/
void
wb_devmem
(
int
argc
,
char
*
argv
[])
{
char
opt
=
0
;
uint8_t
help
=
0
,
f_u
=
0
,
f_x
=
0
,
f_i
=
0
,
f_s
=
0
,
f_c
=
0
;
uint32_t
addr
,
value
,
optind
=
1
;
print_args
(
argc
,
argv
);
if
(
led_id
<=
2
)
char
*
p_c
;
uint8_t
*
p_u8
;
uint16_t
*
p_u16
;
int16_t
*
p_i16
;
while
((
opt
=
getopt
(
argc
,
argv
,
"uxisc8h?"
))
!=
0xFF
)
{
//Test pattern
for
(
i
=
0
;
i
<
4
;
i
++
)
optind
++
;
switch
(
opt
)
{
if
(
led_id
==
0
||
led_id
==
1
)
shw_pio_set
((
const
pio_pin_t
*
)
&
PIN_mbl_box_led_cpu1
,
pattern1
[
i
]);
if
(
led_id
==
0
||
led_id
==
2
)
shw_pio_set
((
const
pio_pin_t
*
)
&
PIN_mbl_box_led_cpu2
,
pattern2
[
i
]);
sleep
(
1
);
case
'u'
:
f_u
=
1
;
break
;
case
'x'
:
f_x
=
1
;
break
;
case
'i'
:
f_i
=
1
;
break
;
case
's'
:
f_s
=
1
;
break
;
case
'8'
:
case
'c'
:
f_c
=
1
;
break
;
case
'h'
:
case
'?'
:
help
=
1
;
break
;
default:
printf
(
"find: illegal option %c (%x)
\n
"
,
opt
,
opt
);
break
;
}
}
argc
-=
optind
;
argv
+=
optind
;
if
(
help
||
argc
<=
0
)
{
printf
(
"Usage %s %s [OPTIONS] <addr> [<value>]
\n
"
,
pgr_name
,
cmd_name
);
printf
(
""
" addr = Wishbone address (0x30034)
\n
"
" OPTIONS: (for read) unsigned: -u, hexa: -x, int: -i, 2x short: -s, 4x 8 bits: -c
\n
"
);
return
;
}
addr
=
strtol
(
argv
[
0
],
NULL
,
16
);
//Must be in hexadecimal format
print_args
(
argc
,
argv
);
shw_fpga_mmap_init
();
//Just read
if
(
argc
==
1
)
{
printf
(
"R@0x%08x > "
,
addr
);
value
=
_fpga_readl
(
addr
);
if
(
f_x
)
printf
(
"0x%x, "
,
value
);
if
(
f_i
)
{
if
(
f_u
)
printf
(
"%d, "
,
value
);
else
printf
(
"%d, "
,(
int
)
value
);
}
if
(
f_s
)
{
if
(
f_u
)
{
p_u16
=
(
uint16_t
*
)
&
value
;
printf
(
"%d %d, "
,
p_u16
[
0
],
p_u16
[
1
]);
}
else
{
p_i16
=
(
int16_t
*
)
&
value
;
printf
(
"%d %d, "
,
p_i16
[
0
],
p_i16
[
1
]);
}
}
if
(
f_c
)
{
fflush
(
stdout
);
if
(
f_u
)
{
p_u8
=
(
uint8_t
*
)
&
value
;
printf
(
"%d %d %d %d, "
,
p_u8
[
0
],
p_u8
[
1
],
p_u8
[
2
],
p_u8
[
3
]);
}
else
{
p_c
=
(
int8_t
*
)
&
value
;
printf
(
"%c %c %c %c, "
,
p_c
[
0
],
p_c
[
1
],
p_c
[
2
],
p_c
[
3
]);
}
}
printf
(
"
\n
"
);
}
else
{
TRACE
(
TRACE_FATAL
,
"
led_id=%d is not supported"
,
led_id
);
TRACE
(
TRACE_FATAL
,
"
Write Not implemented"
);
}
}
int
test
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
**
argv
)
/* Map CPU's pin into memory space */
assert_init
(
shw_pio_mmap_init
());
shw_io_init
();
// shw_i2c_io_test();
//
TRACE
(
TRACE_INFO
,
"ver=%f %d %s"
,
shw_get_hw_ver
(),
shw_get_fpga_type
(),
get_shw_info
(
'f'
));
// struct i2c_bus* iobus=shw_i2c_io_get_bus();
// i2c_read(iobus,0x0,0x5,1);
}
void
usage_error
()
{
fprintf
(
stderr
,
"usage: %s <command> [args]
\n
"
,
pgr_name
);
fprintf
(
stderr
,
"available commands are:
\n
"
" --fan <fan_speed> (from 0 to 100)
\n
"
" --mon
\n
"
" --wb
\n
"
" --led <test_ID>
\n
"
" --gpio <A,B,C,...> <number> <status>
\n
"
"
\n
"
);
exit
(
1
);
}
if
(
argc
<
2
)
usage_error
(
argv
);
const
char
*
command
=
argv
[
1
];
int
main
(
int
argc
,
char
**
argv
)
{
trace_log_stderr
();
if
(
strcmp
(
command
,
"--fan"
)
==
0
)
{
fan_speed
(
atoi
(
argv
[
2
]));
pgr_name
=*
(
argv
++
);
argc
--
;
if
(
argc
==
0
)
usage_error
();
cmd_name
=
argv
[
0
];
TRACE
(
TRACE_INFO
,
"(%s %s)"
,
__DATE__
,
__TIME__
);
if
(
strcmp
(
cmd_name
,
"--fan"
)
==
0
)
{
fan_tool
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--led"
)
==
0
)
{
led_tool
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--gpio"
)
==
0
)
{
gpio_tool
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--mon"
)
==
0
)
{
monotorize
(
argc
,
argv
);
}
else
if
(
strcmp
(
command
,
"--led"
)
==
0
)
{
led_test
(
atoi
(
argv
[
2
]));
else
if
(
strcmp
(
cmd_name
,
"--io"
)
==
0
)
{
io_tool
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--i2c"
)
==
0
)
{
i2c_tool
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--wb"
)
==
0
)
{
wb_devmem
(
argc
,
argv
);
}
else
if
(
strcmp
(
cmd_name
,
"--test"
)
==
0
)
{
test
(
argc
,
argv
);
}
else
if
(
strcmp
(
c
ommand
,
"--sfp
"
)
==
0
)
{
else
if
(
strcmp
(
c
md_name
,
"--
"
)
==
0
)
{
printf
(
"Not implemented"
);
usage_error
(
argv
);
usage_error
();
}
else
{
printf
(
"Command: '%s' is unknown"
,
c
ommand
);
usage_error
(
argv
);
printf
(
"Command: '%s' is unknown"
,
c
md_name
);
usage_error
();
}
return
0
;
}
...
...
sw/shw_tool/sysmon-regs.h
0 → 100644
View file @
dd955562
/*
Register definitions for slave core: Wishbone monitor port
* File : header.h
* Author : auto-generated by wbgen2 from Sysmon_wbslavev5.wb
* Created : Thu Oct 11 16:51:24 2012
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE Sysmon_wbslavev5.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_SYSMON_WBSLAVEV5_WB
#define __WBGEN2_REGDEFS_SYSMON_WBSLAVEV5_WB
#include <inttypes.h>
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
#else
#error "Unsupported compiler?"
#endif
#ifndef __WBGEN2_MACROS_DEFINED__
#define __WBGEN2_MACROS_DEFINED__
#define WBGEN2_GEN_MASK(offset, size) (((1<<(size))-1) << (offset))
#define WBGEN2_GEN_WRITE(value, offset, size) (((value) & ((1<<(size))-1)) << (offset))
#define WBGEN2_GEN_READ(reg, offset, size) (((reg) >> (offset)) & ((1<<(size))-1))
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
/* definitions for register: Temp register */
/* definitions for field: Reset bit in reg: Temp register */
#define WB2_SYSMON_TEMP_RESET WBGEN2_GEN_MASK(0, 1)
/* definitions for field: Actual Temp in reg: Temp register */
#define WB2_SYSMON_TEMP_ACT_MASK WBGEN2_GEN_MASK(8, 8)
#define WB2_SYSMON_TEMP_ACT_SHIFT 8
#define WB2_SYSMON_TEMP_ACT_W(value) WBGEN2_GEN_WRITE(value, 8, 8)
#define WB2_SYSMON_TEMP_ACT_R(reg) WBGEN2_GEN_READ(reg, 8, 8)
/* definitions for field: Max Temp in reg: Temp register */
#define WB2_SYSMON_TEMP_MAX_MASK WBGEN2_GEN_MASK(16, 8)
#define WB2_SYSMON_TEMP_MAX_SHIFT 16
#define WB2_SYSMON_TEMP_MAX_W(value) WBGEN2_GEN_WRITE(value, 16, 8)
#define WB2_SYSMON_TEMP_MAX_R(reg) WBGEN2_GEN_READ(reg, 16, 8)
/* definitions for field: Min Temp in reg: Temp register */
#define WB2_SYSMON_TEMP_MIN_MASK WBGEN2_GEN_MASK(24, 8)
#define WB2_SYSMON_TEMP_MIN_SHIFT 24
#define WB2_SYSMON_TEMP_MIN_W(value) WBGEN2_GEN_WRITE(value, 24, 8)
#define WB2_SYSMON_TEMP_MIN_R(reg) WBGEN2_GEN_READ(reg, 24, 8)
/* definitions for register: Actual Voltage register */
/* definitions for field: Actual VccIN in reg: Actual Voltage register */
#define WB2_SYSMON_V_ACT_VCCIN_MASK WBGEN2_GEN_MASK(0, 16)
#define WB2_SYSMON_V_ACT_VCCIN_SHIFT 0
#define WB2_SYSMON_V_ACT_VCCIN_W(value) WBGEN2_GEN_WRITE(value, 0, 16)
#define WB2_SYSMON_V_ACT_VCCIN_R(reg) WBGEN2_GEN_READ(reg, 0, 16)
/* definitions for field: Actual VccAux in reg: Actual Voltage register */
#define WB2_SYSMON_V_ACT_VCCAUX_MASK WBGEN2_GEN_MASK(16, 16)
#define WB2_SYSMON_V_ACT_VCCAUX_SHIFT 16
#define WB2_SYSMON_V_ACT_VCCAUX_W(value) WBGEN2_GEN_WRITE(value, 16, 16)
#define WB2_SYSMON_V_ACT_VCCAUX_R(reg) WBGEN2_GEN_READ(reg, 16, 16)
/* definitions for register: Max. Voltage register */
/* definitions for field: Maximum VccIN in reg: Max. Voltage register */
#define WB2_SYSMON_V_MAX_VCCIN_MASK WBGEN2_GEN_MASK(0, 16)
#define WB2_SYSMON_V_MAX_VCCIN_SHIFT 0
#define WB2_SYSMON_V_MAX_VCCIN_W(value) WBGEN2_GEN_WRITE(value, 0, 16)
#define WB2_SYSMON_V_MAX_VCCIN_R(reg) WBGEN2_GEN_READ(reg, 0, 16)
/* definitions for field: Maximum VccAux in reg: Max. Voltage register */
#define WB2_SYSMON_V_MAX_VCCAUX_MASK WBGEN2_GEN_MASK(16, 16)
#define WB2_SYSMON_V_MAX_VCCAUX_SHIFT 16
#define WB2_SYSMON_V_MAX_VCCAUX_W(value) WBGEN2_GEN_WRITE(value, 16, 16)
#define WB2_SYSMON_V_MAX_VCCAUX_R(reg) WBGEN2_GEN_READ(reg, 16, 16)
/* definitions for register: Min. Voltage register */
/* definitions for field: Minimum VccIN in reg: Min. Voltage register */
#define WB2_SYSMON_V_MIN_VCCIN_MASK WBGEN2_GEN_MASK(0, 16)
#define WB2_SYSMON_V_MIN_VCCIN_SHIFT 0
#define WB2_SYSMON_V_MIN_VCCIN_W(value) WBGEN2_GEN_WRITE(value, 0, 16)
#define WB2_SYSMON_V_MIN_VCCIN_R(reg) WBGEN2_GEN_READ(reg, 0, 16)
/* definitions for field: Minimum VccAux in reg: Min. Voltage register */
#define WB2_SYSMON_V_MIN_VCCAUX_MASK WBGEN2_GEN_MASK(16, 16)
#define WB2_SYSMON_V_MIN_VCCAUX_SHIFT 16
#define WB2_SYSMON_V_MIN_VCCAUX_W(value) WBGEN2_GEN_WRITE(value, 16, 16)
#define WB2_SYSMON_V_MIN_VCCAUX_R(reg) WBGEN2_GEN_READ(reg, 16, 16)
PACKED
struct
WB2_SYSMON_WB
{
/* [0x0]: REG Temp register */
uint32_t
TEMP
;
/* [0x4]: REG Actual Voltage register */
uint32_t
V_ACT
;
/* [0x8]: REG Max. Voltage register */
uint32_t
V_MAX
;
/* [0xc]: REG Min. Voltage register */
uint32_t
V_MIN
;
};
#endif
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