Commit d92ea0e0 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

commited missing files

parent 7c818539
../../kernel/at91_softpwm/at91_softpwm.h
\ No newline at end of file
#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
#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 */
#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;
}
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment