Commit 6d969e73 authored by Guilherme Sanches's avatar Guilherme Sanches

Intermidiate commit with work in progress. Starting to write functions

to work with the new occan driver
parent 025b60c7
/*
* can_support.c
*
* Created on: Sep 7, 2017
* Author: gmvs@gmv.com
*/
#include <can_support.h>
void can_copy_header() {
}
void can_compared_header(){
}
void can_compare_id(){
}
/*
* can_tasks.c
*
* Created on: Sep 7, 2017
* Author: gmvs@gmv.com
*
* Read and write functions for CAN
*/
#include <iop.h>
#include <can_support.h>
void can_write(iop_physical_device_t *pdev)
{
/* Initialize error chain (packets to be re-sent) */
iop_chain_control error;
iop_chain_initialize_empty(&error);
/* Get the underlying driver */
iop_can_device_t *can_driver = (iop_can_device_t *) pdev->driver;
iop_debug(" :: can-write running!\n");
while(!iop_chain_is_empty(&pdev->sendqueue)){
iop_wrapper_t *wrapper = obtain_wrapper(&pdev->sendqueue);
uint8_t *message = (uint8_t *) wrapper->buffer->v_addr;
/* Write to the device */
if(can_driver->dev.write((iop_device_driver_t *) can_driver,
wrapper) == RTEMS_SUCCESSFUL){
release_wrapper(wrapper);
} else {
iop_chain_append(&error, &wrapper->node);
iop_raise_error(HW_WRITE_ERROR);
}
}
/* Failed transmissions */
while(!iop_chain_is_empty(&error)) {
iop_wrapper_t *wrapper = obtain_wrapper(&error);
iop_chain_append(&pdev->sendqueue, &wrapper->node);
}
}
void can_read(iop_physical_device_t *pdev)
{
/* Initialize error control chain (packets to be resent) */
iop_chain_control error;
iop_chain_initialize_empty(&error);
/* Get underlaying driver */
iop_can_device_t *driver = (iop_can_device_t *) pdev->driver;
iop_debug(" :: can-read running!\n");
/* Read from the buffer */
}
/*
* Common GRLIB AMBA Core Register definitions
*
* COPYRIGHT (c) 2008.
* Aeroflex Gaisler.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
*/
#ifndef __GRLIB_H__
#define __GRLIB_H__
#ifdef __cplusplus
extern "C" {
#endif
/* ESA MEMORY CONTROLLER */
struct mctrl_regs {
unsigned int mcfg1;
unsigned int mcfg2;
unsigned int mcfg3;
};
/* APB UART */
struct apbuart_regs {
volatile unsigned int data;
volatile unsigned int status;
volatile unsigned int ctrl;
volatile unsigned int scaler;
};
/* IRQMP and IRQAMP interrupt controllers */
struct irqmp_regs {
volatile unsigned int ilevel; /* 0x00 */
volatile unsigned int ipend; /* 0x04 */
volatile unsigned int iforce; /* 0x08 */
volatile unsigned int iclear; /* 0x0c */
volatile unsigned int mpstat; /* 0x10 */
volatile unsigned int bcast; /* 0x14 */
volatile unsigned int notused02; /* 0x18 */
volatile unsigned int notused03; /* 0x1c */
volatile unsigned int ampctrl; /* 0x20 */
volatile unsigned int icsel[2]; /* 0x24,0x28 */
volatile unsigned int notused13; /* 0x2c */
volatile unsigned int notused20; /* 0x30 */
volatile unsigned int notused21; /* 0x34 */
volatile unsigned int notused22; /* 0x38 */
volatile unsigned int notused23; /* 0x3c */
volatile unsigned int mask[16]; /* 0x40 */
volatile unsigned int force[16]; /* 0x80 */
/* Extended IRQ registers */
volatile unsigned int intid[16]; /* 0xc0 */
/* 0x100, align to 4Kb boundary */
volatile unsigned int resv1[(0x1000-0x100)/4];
};
/* GPTIMER Timer instance */
struct gptimer_timer_regs {
volatile unsigned int value;
volatile unsigned int reload;
volatile unsigned int ctrl;
volatile unsigned int notused;
};
/* GPTIMER common registers */
struct gptimer_regs {
volatile unsigned int scaler_value; /* common timer registers */
volatile unsigned int scaler_reload;
volatile unsigned int cfg;
volatile unsigned int notused;
struct gptimer_timer_regs timer[7];
};
/* GRGPIO GPIO */
struct grgpio_regs {
volatile unsigned int data; /* 0x00 I/O port data register */
volatile unsigned int output; /* 0x04 I/O port output register */
volatile unsigned int dir; /* 0x08 I/O port direction register */
volatile unsigned int imask; /* 0x0C Interrupt mask register */
volatile unsigned int ipol; /* 0x10 Interrupt polarity register */
volatile unsigned int iedge; /* 0x14 Interrupt edge register */
volatile unsigned int bypass; /* 0x18 Bypass register */
};
#ifdef __cplusplus
}
#endif
#endif //__GRLIB_H__
......@@ -30,6 +30,35 @@ typedef struct {
unsigned int id;
} CANMsg;
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;
/* Config */
unsigned int speed; /* speed in HZ */
unsigned char acode[4];
unsigned char amask[4];
} occan_priv;
typedef struct {
/* tx/rx stats */
unsigned int rx_msgs;
......
This diff is collapsed.
/**
* @author gmvs@gmv.com
* @brief CAN support structures and functions definitions
*/
#ifndef __CAN_SUPPORT_H__
#define __CAN_SUPPORT_H__
#include <iop.h>
#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 {
iop_device_driver_t dev;
uint16_t self_id; // This device's ID
uint16_t rx_count;
uint16_t tx_count;
} iop_can_device_t;
#endif
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