Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
84
Issues
84
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
White Rabbit Switch - Software
Commits
d92ea0e0
Commit
d92ea0e0
authored
May 30, 2022
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commited missing files
parent
7c818539
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
241 additions
and
0 deletions
+241
-0
at91_softpwm.h
userspace/include/at91_softpwm.h
+1
-0
wrs-hw.h
userspace/include/wrs-hw.h
+25
-0
config.h
userspace/libwr/config.h
+0
-0
gpio.h
userspace/libwr/include/libwr/gpio.h
+64
-0
pca9554_gpio.c
userspace/libwr/pca9554_gpio.c
+92
-0
test_i2c.c
userspace/tools/test_i2c.c
+59
-0
No files found.
userspace/include/at91_softpwm.h
0 → 120000
View file @
d92ea0e0
..
/
..
/
kernel
/
at91_softpwm
/
at91_softpwm
.
h
\ No newline at end of file
userspace/include/wrs-hw.h
0 → 100644
View file @
d92ea0e0
#ifndef __WRS_HW_H
#define __WRS_HW_H
#ifdef WRS_PLATFORM_WRS_10G_AFCZ
#define WRS_FPGA_BASE 0x400000000ULL
#define WRS_FPGA_SIZE 0x100000ULL
#define WRS_FPGA_BASE_RT_SUBSYSTEM 0x0000ULL
#define WRS_FPGA_BASE_RTS_VUART 0x10000ULL
#define WRS_FPGA_BASE_RTS_GPIO 0x10300ULL
#define AFCZ_I2C_MUX_CHANNEL_SI570 2
#define AFCZ_I2C_MUX_CHANNEL_RTM 7
#else
#error Unsupported hardware platform
#endif
#endif
\ No newline at end of file
userspace/libwr/config.h
0 → 100644
View file @
d92ea0e0
userspace/libwr/include/libwr/gpio.h
0 → 100644
View file @
d92ea0e0
#ifndef __LIBWR_GPIO_H
#define __LIBWR_GPIO_H
#include <stdint.h>
#define GPIO_OUT 1
#define GPIO_IN 0
struct
gpio_pin
;
typedef
int
(
*
gpio_configure_func_t
)(
const
struct
gpio_pin
*
);
typedef
void
(
*
gpio_set_dir_func_t
)(
const
struct
gpio_pin
*
,
int
);
typedef
void
(
*
gpio_set_out_func_t
)(
const
struct
gpio_pin
*
,
int
);
typedef
int
(
*
gpio_read_pin_func_t
)(
const
struct
gpio_pin
*
);
struct
gpio_device
{
void
*
priv
;
gpio_set_dir_func_t
set_dir
;
gpio_set_out_func_t
set_out
;
gpio_read_pin_func_t
read_pin
;
gpio_read_pin_func_t
configure
;
}
gpio_device_t
;
typedef
struct
gpio_pin
{
const
struct
gpio_device
*
dev
;
int
pin
;
void
*
priv
;
}
gpio_pin_t
;
int
shw_gpio_configure
(
const
struct
gpio_pin
*
pin
)
{
return
pin
->
dev
->
configure
(
pin
);
}
static
inline
void
shw_gpio_set
(
struct
gpio_pin
*
pin
,
int
state
)
{
pin
->
dev
->
set_out
(
pin
,
state
);
}
static
inline
void
shw_gpio_set1
(
struct
gpio_pin
*
pin
)
{
pin
->
dev
->
set_out
(
pin
,
1
);
}
static
inline
void
shw_gpio_set0
(
struct
gpio_pin
*
pin
)
{
pin
->
dev
->
set_out
(
pin
,
0
);
}
static
inline
int
shw_gpio_get
(
struct
gpio_pin
*
pin
)
{
return
pin
->
dev
->
read_pin
(
pin
);
}
static
inline
void
shw_gpio_set_dir
(
struct
gpio_pin
*
pin
,
int
dir
)
{
pin
->
dev
->
set_dir
(
pin
,
dir
);
}
#endif
/* __LIBWR_GPIO_H */
userspace/libwr/pca9554_gpio.c
0 → 100644
View file @
d92ea0e0
#define PCA9554_REG_IN 0
#define PCA9554_REG_OUT 1
#define PCA9554_REG_INVERT 2
#define PCA9554_REG_CONFIG 3
#include <libwr/gpio.h>
#include <libwr/i2c.h>
static
uint8_t
pca9554_read_reg
(
struct
pca9554_gpio_device
*
dev
,
uint8_t
reg
)
{
uint8_t
rv
;
int
err
;
bb_i2c_start
(
dev
->
bus
);
err
|=
bb_i2c_put_byte
(
dev
->
bus
,
dev
->
i2c_addr
<<
1
);
bb_i2c_put_byte
(
dev
->
bus
,
reg
);
bb_i2c_repeat_start
(
dev
->
bus
);
err
|=
bb_i2c_put_byte
(
dev
->
bus
,
(
dev
->
i2c_addr
<<
1
)
|
1
);
bb_i2c_get_byte
(
dev
->
bus
,
&
rv
,
1
);
bb_i2c_stop
(
dev
->
bus
);
if
(
err
)
{
board_dbg
(
"pca9554 ERROR [addr = 0x%x]!
\n
"
,
dev
->
i2c_addr
);
}
return
rv
;
}
static
void
pca9554_write_reg
(
struct
pca9554_gpio_device
*
dev
,
uint8_t
reg
,
uint8_t
value
)
{
bb_i2c_start
(
dev
->
bus
);
bb_i2c_put_byte
(
dev
->
bus
,
dev
->
i2c_addr
<<
1
);
bb_i2c_put_byte
(
dev
->
bus
,
reg
);
bb_i2c_put_byte
(
dev
->
bus
,
value
);
bb_i2c_stop
(
dev
->
bus
);
}
static
void
pca9554_gpio_out
(
const
struct
gpio_pin
*
pin
,
int
value
)
{
struct
pca9554_gpio_device
*
dev
=
(
struct
pca9554_gpio_device
*
)
pin
->
device
->
priv
;
uint8_t
oreg
=
pca9554_read_reg
(
dev
,
PCA9554_REG_OUT
);
if
(
value
)
oreg
|=
(
1
<<
pin
->
pin
);
else
oreg
&=
~
(
1
<<
pin
->
pin
);
pca9554_write_reg
(
dev
,
PCA9554_REG_OUT
,
oreg
);
}
static
void
pca9554_gpio_set_dir
(
const
struct
gpio_pin
*
pin
,
int
dir
)
{
struct
pca9554_gpio_device
*
dev
=
(
struct
pca9554_gpio_device
*
)
pin
->
device
->
priv
;
uint8_t
dreg
=
pca9554_read_reg
(
dev
,
PCA9554_REG_CONFIG
);
if
(
!
dir
)
dreg
|=
(
1
<<
pin
->
pin
);
else
dreg
&=
~
(
1
<<
pin
->
pin
);
pca9554_write_reg
(
dev
,
PCA9554_REG_CONFIG
,
dreg
);
}
static
int
pca9554_gpio_in
(
const
struct
gpio_pin
*
pin
)
{
struct
pca9554_gpio_device
*
dev
=
(
struct
pca9554_gpio_device
*
)
pin
->
device
->
priv
;
// fixme: implement
return
0
;
}
void
pca9554_gpio_init
(
struct
pca9554_gpio_device
*
dev
,
struct
i2c_bus
*
bus
,
uint8_t
i2c_addr
)
{
dev
->
bus
=
bus
;
dev
->
i2c_addr
=
i2c_addr
;
dev
->
gpio
.
priv
=
(
void
*
)
dev
;
dev
->
gpio
.
read_pin
=
pca9554_gpio_in
;
dev
->
gpio
.
set_dir
=
pca9554_gpio_set_dir
;
dev
->
gpio
.
set_out
=
pca9554_gpio_out
;
}
userspace/tools/test_i2c.c
0 → 100644
View file @
d92ea0e0
#include <stdio.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/select.h>
#include <wrs-hw.h>
#include <libwr/switch_hw.h>
#include <fpga_io.h>
#include "libwr/i2c.h"
#include "libwr/i2c_fpga_reg.h"
i2c_fpga_reg_t
fpga_bus0_reg
=
{
.
base_address
=
FPGA_I2C_ADDRESS
,
.
if_num
=
FPGA_I2C0_IFNUM
,
.
prescaler
=
500
,
};
struct
i2c_bus
i2c_bus_fpga
=
{
.
name
=
"fpga_bus0"
,
.
type
=
I2C_BUS_TYPE_FPGA_REG
,
.
type_specific
=
&
fpga_bus0_reg
};
#define GPIO_COR 0x0 // fixme. alessandro, I hate you!
#define GPIO_SOR 0x4
#define RT_PERIPH_RESET_PIN_N 3
int
test_i2c
()
{
printf
(
"Unreset periph...
\n
"
);
_fpga_writel
(
WRS_FPGA_BASE_RTS_GPIO
+
GPIO_SOR
,
1
<<
RT_PERIPH_RESET_PIN_N
);
// un-reset the peripherals
uint8_t
devs
[
256
];
i2c_bus_init
(
&
i2c_bus_fpga
);
memset
(
devs
,
0
,
sizeof
(
devs
));
i2c_bus_scan
(
&
i2c_bus_fpga
,
devs
);
int
i
;
printf
(
"Found devs: "
);
for
(
i
=
0
;
i
<
128
;
i
++
)
if
(
devs
[
i
/
8
]
&
(
1
<<
(
i
&
0x7
)))
printf
(
"%02x "
,
i
);
printf
(
"
\n
"
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
wrs_msg_init
(
argc
,
argv
,
0
);
shw_fpga_mmap_init
();
test_i2c
();
return
0
;
}
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