Commit eb1c1b8c authored by Guilherme Sanches's avatar Guilherme Sanches

Many changes to adapt the occan to xky. There are also changes to the

can_example that will be used to test iop_can
parent 6d969e73
......@@ -13,7 +13,6 @@
* @brief SPW Header
*/
typedef struct {
// uint16_t hlen; /**< Header Length */
uint8_t hdr[32]; /**< Header */
......@@ -33,7 +32,6 @@ typedef struct {
* @brief Eth header (UDP Packet complete header)
*/
typedef struct {
/* EthII header */
uint8_t dst_mac[6]; /**< destination ethernet address*/
uint8_t src_mac[6]; /**< source ethernet address*/
......@@ -59,17 +57,24 @@ typedef struct {
} __attribute__((packed)) eth_header_t;
typedef struct {
char extended; /* CANBUS extended id option */
char rtr; /* Remote Transmission request */
char sshot; /* Single shot option*/
// unsigned char len; /* payload length from 1-8 bytes */
unsigned int id; /* Remote device identifier */
} __attribute__((packet)) can_header_t;
/**
* @brief IOP generic header
*
* This header is a union of all supported headers
*/
typedef union {
milstd_header_t milstd_hdr; /**< MILSTD 1553b header */
spw_header_t spw_header; /**< SPW header */
eth_header_t eth_header; /**< UDP packet header */
can_header_t can_header; /**< CAN frame header */
} __attribute__((packed)) iop_header_t;
......
......@@ -9,7 +9,6 @@ extern iop_port_t remote_ports[3];
* @brief Logical devices
*/
extern iop_logical_device_t logical_device_0;
extern iop_logical_device_t logical_device_1;
/**
* @brief Physical devices
......@@ -30,7 +29,6 @@ static iop_physical_device_t *physical_device_list[1] = \
static iop_logical_device_t *logical_device_list[2] = \
{
&logical_device_0,
&logical_device_1,
};
static iop_wrapper_t requests_storage[1024];
......@@ -50,13 +48,13 @@ iop_configuration_t usr_configuration = {
.wrappers = requests_storage,
.iop_buffers = iop_buffers,
.iop_buffers_storage = iop_buffers_storage,
.wrappers_count = 1024,
.wrappers_count = 1024,
.physical_devices = {
.length = 1,
.elements = physical_device_list
},
.logical_devices = {
.logical_devices = {
.length = 2,
.elements = logical_device_list
},
......
......@@ -9,24 +9,21 @@ extern iop_physical_device_t physical_device_0;
/**
* @brief Routes Headers
*/
static iop_header_t route_header[1] = \
static iop_header_t route_header[0] = \
{
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(13000),
.src_port = HTONS(13000)
}
}
.can_header = {
.extended = 0,
.rtr = 0,
.sshot = 0,
.id = 2
}
};
/**
* @brief Routes Scheduling
*/
static uint32_t route_schedule_0[1] = \
{ 1 };
{ 1 };
/**
......@@ -34,17 +31,15 @@ static uint32_t route_schedule_0[1] = \
*/
static iop_logical_route_t logical_routes[1] = \
{
{
.schedule = route_schedule_0,
.header = &route_header[0],
.device = &physical_device_0
}
.schedule = route_schedule_0,
.header = &route_header[0],
.device = &physical_device_0
};
/**
* @brief Logical Device configuration
*/
iop_logical_device_t logical_device_0 = \
iop_logical_device_t logical_device_0= \
{
.routes = {
.length = 1,
......
#include <iop.h>
/**
* @brief Physical devices
*/
extern iop_physical_device_t physical_device_0;
/**
* @brief Routes Headers
*/
static iop_header_t route_header[0] = \
{
};
/**
* @brief Routes Scheduling
*/
/**
* @brief Routes Configuration
*/
static iop_logical_route_t logical_routes[0] = \
{
};
/**
* @brief Logical Device configuration
*/
iop_logical_device_t logical_device_1 = \
{
.routes = {
.length = 0,
.elements = logical_routes
},
};
......@@ -7,8 +7,8 @@
* ============================================================================
*/
#include <iop.h>
#include <iop_greth.h>
#include <eth_support.h>
#include <occan.h>
#include <can_support.h>
/**
* @brief IOP remote ports
......@@ -37,8 +37,12 @@ static iop_buffer_t *rx_iop_buffer[32];
static uint8_t descriptor_table[3072];
/** @brief GRETH control structure*/
static greth_softc_t greth_driver = \
static occan_priv occan_driver = \
{
.speed = 250000, // TODO maybe use a enum in the future
.acode = {0, 0, 0, 0},
.amask = {0, 0, 0, 0},
.iop_buffers = iop_buffers,
.iop_buffers_storage = iop_buffers_storage,
......@@ -51,24 +55,22 @@ static greth_softc_t greth_driver = \
};
/** @brief GRETH driver configuration */
static iop_eth_device_t device_configuration = \
static iop_can_device_t device_configuration = \
{
/* device configuration */
.dev = {
.driver = (void *)&greth_driver,
.init = greth_initialize,
.open = greth_open,
.read = greth_read,
.write = greth_write,
.close = greth_close,
.driver = (void *)&occan_driver,
.init = occan_initialize,
.open = occan_open,
.read = occan_read,
.write = occan_write,
.close = occan_close,
},
/* ethernet configuration */
.ip = { 192, 168, 0, 17 },
.mac = { 0x00, 0x50, 0xC2, 0x75, 0xa0, 0x60 },
.rx_count = 32,
.tx_count = 32
.dev_name ="/dev/occan0",
.count = 0,
.flags = 0,
.bytes_moved = 0,
};
/**
......@@ -80,24 +82,16 @@ static uint32_t reads_per_period[] = \
/**
* @brief Routes Headers
*/
static iop_header_t route_header[2] = \
static iop_header_t route_header[1] = \
{
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(14000),
.src_port = HTONS(14000)
}
},
{
.eth_header = {
.dst_ip = { 192,168,0,3 },
.dst_mac = { 0x00,0x50,0xbf,0x50,0x07,0x0d},
.dst_port = HTONS(14000),
.src_port = HTONS(14000)
}
}
{
.can_header = {
.extended = 0,
.rtre = 0,
.sshot = 0,
.id = 2,
},
}
};
/**
......@@ -105,24 +99,17 @@ static iop_header_t route_header[2] = \
*/
static uint32_t route_schedule_0[1] = \
{ 1 };
static uint32_t route_schedule_1[1] = \
{ 1 };
/**
* @brief Routes Configuration
*/
static iop_physical_route_t physical_routes[2] =\
static iop_physical_route_t physical_routes[1] =\
{
{
.schedule = route_schedule_0,
.header = &route_header[0],
.port = &remote_ports[2]
},
{
.schedule = route_schedule_1,
.header = &route_header[1],
.port = &remote_ports[1]
}
};
/**
......@@ -137,9 +124,9 @@ iop_physical_device_t physical_device_0 =\
},
.reads_per_period = reads_per_period,
.reader_task = eth_reader,
.writer_task = eth_writer,
.header_prebuild = eth_prebuild_header,
.header_compare = eth_compare_header,
.header_copy = eth_copy_header,
.reader_task = can_reader,
.writer_task = can_write,
.header_prebuild = can_prebuild_header,
.header_compare = can_compare_header,
.header_copy = can_copy_header,
};
......@@ -13,7 +13,6 @@
* @brief Logical devices
*/
extern iop_logical_device_t logical_device_0;
extern iop_logical_device_t logical_device_1;
/**
* @brief Queuing ports configurations
......
......@@ -16,6 +16,10 @@ void can_compared_header(){
}
void can_compare_id(){
void can_compare_header(){
}
void can_prebuild_header(){
}
......@@ -45,7 +45,7 @@ void can_write(iop_physical_device_t *pdev)
}
void can_read(iop_physical_device_t *pdev)
void can_reader(iop_physical_device_t *pdev)
{
/* Initialize error control chain (packets to be resent) */
iop_chain_control error;
......
......@@ -7,7 +7,7 @@
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* Author: Daniel Hellström, Gaisler Research AB, www.gaisler.com
* Author: Daniel Hellstr��m, Gaisler Research AB, www.gaisler.com
*/
......@@ -16,10 +16,50 @@
#include <ambapp.h>
#include <can_support.h>
#include <iop.h>
#include <xky.h>
#ifdef __cplusplus
extern "C" {
#endif
/* default to byte regs */
#ifndef OCCAN_WORD_REGS
#define OCCAN_BYTE_REGS
#else
#undef OCCAN_BYTE_REGS
#endif
#ifndef OCCAN_PREFIX
#define OCCAN_PREFIX(name) occan##name
#endif
#if !defined(OCCAN_DEVNAME) || !defined(OCCAN_DEVNAME_NO)
#undef OCCAN_DEVNAME
#undef OCCAN_DEVNAME_NO
#define OCCAN_DEVNAME "/dev/occan0"
#define OCCAN_DEVNAME_NO(devstr,no) ((devstr)[10]='0'+(no))
#endif
#ifndef OCCAN_REG_INT
#define OCCAN_REG_INT(handler,irq,arg) set_vector(handler,irq+0x10)
#undef OCCAN_DEFINE_INTHANDLER
#define OCCAN_DEFINE_INTHANDLER
#endif
/* Default to 40MHz system clock */
/*#ifndef SYS_FREQ_HZ
#define SYS_FREQ_HZ 40000000
#endif*/
#define OCCAN_WORD_REG_OFS 0x80
#define OCCAN_NCORE_OFS 0x100
#define DEFAULT_CLKDIV 0x7
#define DEFAULT_EXTENDED_MODE 1
#define DEFAULT_RX_FIFO_LEN 64
#define DEFAULT_TX_FIFO_LEN 64
/* CAN MESSAGE */
typedef struct {
char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
......@@ -30,34 +70,129 @@ typedef struct {
unsigned int id;
} CANMsg;
/* PELICAN */
#ifdef OCCAN_BYTE_REGS
typedef struct {
/* hardware shortcuts */
pelican_regs *regs;
int irq;
occan_speed_regs timing;
int channel; /* 0=default, 1=second bus */
int single_mode;
/* driver state */
rtems_id devsem;
rtems_id txsem;
rtems_id rxsem;
int open;
int started;
int rxblk;
int txblk;
unsigned int status;
occan_stats stats;
/* rx&tx fifos */
occan_fifo *rxfifo;
occan_fifo *txfifo;
unsigned char
mode,
cmd,
status,
intflags,
inten,
resv0,
bustim0,
bustim1,
unused0[2],
resv1,
arbcode,
errcode,
errwarn,
rx_err_cnt,
tx_err_cnt,
rx_fi_xff; /* this is also acceptance code 0 in reset mode */
union{
struct {
unsigned char id[2];
unsigned char data[8];
unsigned char next_in_fifo[2];
} rx_sff;
struct {
unsigned char id[4];
unsigned char data[8];
} rx_eff;
struct {
unsigned char id[2];
unsigned char data[8];
unsigned char unused[2];
} tx_sff;
struct {
unsigned char id[4];
unsigned char data[8];
} tx_eff;
struct {
unsigned char code[3];
unsigned char mask[4];
} rst_accept;
} msg;
unsigned char rx_msg_cnt;
unsigned char unused1;
unsigned char clkdiv;
} pelican_regs;
#else
typedef struct {
unsigned char
mode, unused0[3],
cmd, unused1[3],
status, unused2[3],
intflags, unused3[3],
inten, unused4[3],
resv0, unused5[3],
bustim0, unused6[3],
bustim1, unused7[3],
unused8[8],
resv1,unused9[3],
arbcode,unused10[3],
errcode,unused11[3],
errwarn,unused12[3],
rx_err_cnt,unused13[3],
tx_err_cnt,unused14[3],
rx_fi_xff, unused15[3]; /* this is also acceptance code 0 in reset mode */
/* make sure to use pointers when writing (byte access) to these registers */
union{
struct {
unsigned int id[2];
unsigned int data[8];
unsigned int next_in_fifo[2];
} rx_sff;
struct {
unsigned int id[4];
unsigned int data[8];
} rx_eff;
struct {
unsigned int id[2];
unsigned int data[8];
} tx_sff;
struct {
unsigned int id[4];
unsigned int data[8];
} tx_eff;
struct {
unsigned int code[3];
unsigned int mask[4];
} rst_accept;
} msg;
unsigned char rx_msg_cnt,unused16[3];
unsigned char unused17[4];
unsigned char clkdiv,unused18[3];
} pelican_regs;
#endif
/* Config */
unsigned int speed; /* speed in HZ */
unsigned char acode[4];
unsigned char amask[4];
} occan_priv;
/* fifo interface */
typedef struct {
int cnt;
int ovcnt; /* overwrite count */
int full; /* 1 = base contain cnt CANMsgs, tail==head */
CANMsg *tail, *head;
CANMsg *base;
char fifoarea[1024];
} occan_fifo;
#define MAX_TSEG2 7
#define MAX_TSEG1 15
#if 0
typedef struct {
unsigned char brp;
unsigned char sjw;
unsigned char tseg1;
unsigned char tseg2;
unsigned char sam;
} occan_speed_regs;
#endif
typedef struct {
unsigned char btr0;
unsigned char btr1;
} occan_speed_regs;
typedef struct {
/* tx/rx stats */
......@@ -109,6 +244,45 @@ typedef struct {
} occan_stats;
typedef struct {
/* hardware shortcuts */
pelican_regs *regs;
int irq;
occan_speed_regs timing;
int channel; /* 0=default, 1=second bus */
int single_mode;
/* driver state */
rtems_id devsem;
rtems_id txsem;
rtems_id rxsem;
int open;
int started;
int rxblk;
int txblk;
unsigned int status;
occan_stats stats;
/* rx&tx fifos */
/* Probably this should be changed
* for the tx and rx _iop_buffer */
occan_fifo *rxfifo;
occan_fifo *txfifo;
/* Config */
unsigned int speed; /* speed in HZ */
unsigned char acode[4];
unsigned char amask[4];
/* IOP standard buffers */
iop_buffer_t *iop_buffers;
uint8_t *iop_duffers_storage;
iop_buffer_t **tx_iop_buffer;
iop_buffer_t **rx_iop_buffer;
} occan_priv;
/* indexes into occan_stats.err_bus_segs[index] */
#define OCCAN_SEG_ID28 0x02 /* ID field bit 28:21 */
#define OCCAN_SEG_ID20 0x06 /* ID field bit 20:18 */
......@@ -159,13 +333,6 @@ typedef struct {
#define OCCAN_IOC_SET_BUFLEN 11
#define OCCAN_IOC_SET_BTRS 12
struct occan_afilter {
unsigned char code[4];
unsigned char mask[4];
int single_mode;
};
#define OCCAN_STATUS_RESET 0x01
#define OCCAN_STATUS_OVERRUN 0x02
#define OCCAN_STATUS_WARN 0x04
......@@ -178,7 +345,7 @@ struct occan_afilter {
int occan_register(amba_confarea_type *bus);
// TODO change this to an enum
#define OCCAN_SPEED_500K 500000
#define OCCAN_SPEED_250K 250000
#define OCCAN_SPEED_125K 125000
......@@ -186,6 +353,35 @@ int occan_register(amba_confarea_type *bus);
#define OCCAN_SPEED_50K 50000
#define OCCAN_SPEED_25K 25000
#define OCCAN_SPEED_10K 10000
/**** Hardware related Interface ****/
static int occan_calc_speedregs(unsigned int clock_hz, unsigned int rate, occan_speed_regs *result);
static int occan_set_speedregs(occan_priv *priv, occan_speed_regs *timing);
static int pelican_speed_auto(occan_priv *priv);
static void pelican_init(occan_priv *priv);
static void pelican_open(occan_priv *priv);
static int pelican_start(occan_priv *priv);
static void pelican_stop(occan_priv *priv);
static int pelican_send(occan_priv *can, CANMsg *msg);
static void pelican_set_accept(occan_priv *priv, unsigned char *acode, unsigned char *amask);
static void occan_interrupt(occan_priv *can);
#ifdef DEBUG_PRINT_REGMAP
static void pelican_regadr_print(pelican_regs *regs);
#endif
/***** Driver related interface *****/
uint32_t occan_ioctl(iop_can_device_t *device, void *arg);
uint32_t occan_write(iop_device_driver_t *iop_dev, void *arg);
uint32_t occan_read(iop_device_driver_t *iop_dev, void *arg);
uint32_t occan_close(iop_device_driver_t *iop_dev, void *arg);
uint32_t occan_open(iop_device_driver_t *iop_dev, void *arg);
uint32_t occan_initialize(iop_device_driver_t *iop_dev, void *arg);
#ifdef OCCAN_DEFINE_INTHANDLER
static void occan_interrupt_handler(rtems_vector_number v);
#endif
static int can_cores;
static amba_confarea_type *amba_bus;
static unsigned int sys_freq_hz;
/**
* @brief Paramameter block for read/write.
......
This diff is collapsed.
......@@ -10,21 +10,32 @@
#include <rtems.h>
#include <iop_support.h>
typedef struct {
uint16_t identifier;
uint8_t RTR;
uint8_t data_len; // Data length in bytes to a maximum of 8
char data[8];
}can_frame;
//typedef struct {
// uint16_t identifier;
// uint8_t RTR;
// uint8_t data_len; // Data length in bytes to a maximum of 8
// char data[8];
//}can_frame;
typedef struct {
/* Generic device configuration */
iop_device_driver_t dev;
uint16_t self_id; // This device's ID
uint16_t rx_count;
uint16_t tx_count;
char *dev_name;
struct occan_afilter *filter;
// uint16_t self_id; // This device's ID
// uint16_t rx_count;
// uint16_t tx_count;
// char *buffer;
uint32_t count;
uint32_t flags;
uint32_t bytes_moved;
} iop_can_device_t;