Commit 421685e5 authored by jdelange's avatar jdelange
Browse files

* po-hi-c/src/drivers/po_hi_driver_rasta_serial.c

   - Update the driver, introduce the ability to use several
     instances of the same device on a single node.
   - Add comments that can be processed by doxygen.



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@2782 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 9d4af098
......@@ -3,7 +3,17 @@
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* Copyright (C) 2010, European Space Agency
* Copyright (C) 2010-2011, European Space Agency
*/
/*! \file po_hi_driver_rasta_serial.c
* \brief Driver that interface PolyORB-HI-C and the serial interface of RASTA boards using the RTEMS 4.8 driver.
*
* This driver works ONLY with the RTEMS 4.8 version that was available on GAISLER website
* on April 2010. This version is available at:
* - http://download.tuxfamily.org/taste/tools/rtems-4.8-gaisler.tgz
* However, please note that it is no longer supported by GAISLER and contains
* other bugs (such as the serial driver for the LEON that does not work).
*/
#include <deployment.h>
......@@ -40,18 +50,28 @@
#include <drivers/configuration/serial.h>
int po_hi_c_driver_rasta_serial_fd_read;
int po_hi_c_driver_rasta_serial_fd_write;
int po_hi_c_driver_rasta_serial_fd_read[__PO_HI_NB_DEVICES];
int po_hi_c_driver_rasta_serial_fd_write[__PO_HI_NB_DEVICES];
__po_hi_msg_t __po_hi_c_driver_rasta_serial_msg;
__po_hi_request_t __po_hi_c_driver_rasta_serial_request;
/*!
* \fn void __po_hi_c_driver_serial_rasta_poller (const __po_hi_device_id dev_id)
* \brief Polling function for the RASTA.
*
* This function is the poller for the serial interface of the RASTA board.
* It is supposed to be called by the underlying AADL code at a given period/rate.
* The argument dev_id is the device_id handled by the device driver. By using
* such an argument, we can use this function on a single node that uses several
* driver instances (several serial interfaces connected to different serial buses).
*/
void __po_hi_c_driver_serial_rasta_poller (const __po_hi_device_id dev_id)
{
(void) dev_id;
int n;
int ts;
uint8_t* ptr;
int n;
int ts;
uint8_t* ptr;
__po_hi_request_t __po_hi_c_driver_rasta_serial_request;
__po_hi_msg_t __po_hi_c_driver_rasta_serial_msg;
ts = __PO_HI_MESSAGES_MAX_SIZE;
ptr = &(__po_hi_c_driver_rasta_serial_msg.content[0]);
......@@ -59,9 +79,9 @@ void __po_hi_c_driver_serial_rasta_poller (const __po_hi_device_id dev_id)
while (ts > 0)
{
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Poller waits for incoming message (%d bytes are required)!\n", ts);
n = read (po_hi_c_driver_rasta_serial_fd_read, ptr, ts);
n = read (po_hi_c_driver_rasta_serial_fd_read[dev_id], ptr, ts);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] read() %d returns %d!\n", po_hi_c_driver_rasta_serial_fd_read, n);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] read() %d returns %d!\n", po_hi_c_driver_rasta_serial_fd_read[dev_id], n);
if (n == -1)
{
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Cannot read on socket !\n");
......@@ -92,6 +112,16 @@ void __po_hi_c_driver_serial_rasta_poller (const __po_hi_device_id dev_id)
extern amba_confarea_type* __po_hi_driver_rasta_common_get_bus ();
void __po_hi_rasta_interrrupt_register(void *handler, int irqno, void *arg);
/*!
* \fn void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
* \brief Initialization function for the RASTA serial driver.
*
* This function is used to initialize the device driver connected to the
* serial interface to a RASTA board. It uses the configuration properties
* from its associated configuration parameters (using the
* __po_hi_get_device_configuration function).
*/
void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
{
__po_hi_c_serial_conf_t* serialconf;
......@@ -112,44 +142,44 @@ void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
__PO_HI_DEBUG_INFO ("[RASTA SERIAL] Initialization starts !\n");
po_hi_c_driver_rasta_serial_fd_write =
po_hi_c_driver_rasta_serial_fd_read = open (serialconf->devname, O_RDWR);
po_hi_c_driver_rasta_serial_fd_write[id] =
po_hi_c_driver_rasta_serial_fd_read[id] = open (serialconf->devname, O_RDWR);
/*
po_hi_c_driver_rasta_serial_fd_write = open (serialconf->devname, O_WRONLY);
*/
if (po_hi_c_driver_rasta_serial_fd_read < 0)
if (po_hi_c_driver_rasta_serial_fd_read[id] < 0)
{
__PO_HI_DEBUG_CRITICAL ("[RASTA SERIAL] Error while opening device %s for reading\n", serialconf->devname);
}
if (po_hi_c_driver_rasta_serial_fd_write < 0)
if (po_hi_c_driver_rasta_serial_fd_write[id] < 0)
{
__PO_HI_DEBUG_CRITICAL ("[RASTA SERIAL] Error while opening device %s for writing\n", serialconf->devname);
}
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Device opened for read (%s), fd=%d\n", serialconf->devname , po_hi_c_driver_rasta_serial_fd_read);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Device opened for write (%s), fd=%d\n", serialconf->devname , po_hi_c_driver_rasta_serial_fd_write);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Device opened for read (%s), fd=%d\n", serialconf->devname , po_hi_c_driver_rasta_serial_fd_read[id]);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Device opened for write (%s), fd=%d\n", serialconf->devname , po_hi_c_driver_rasta_serial_fd_write[id]);
switch (__po_hi_c_driver_serial_common_get_speed (id))
{
case __PO_HI_DRIVER_SERIAL_COMMON_SPEED_19200:
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_BAUDRATE, 19200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write, APBUART_SET_BAUDRATE, 19200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_BAUDRATE, 19200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write[id], APBUART_SET_BAUDRATE, 19200);
break;
case __PO_HI_DRIVER_SERIAL_COMMON_SPEED_38400:
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_BAUDRATE, 38400);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write, APBUART_SET_BAUDRATE, 38400);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_BAUDRATE, 38400);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write[id], APBUART_SET_BAUDRATE, 38400);
break;
case __PO_HI_DRIVER_SERIAL_COMMON_SPEED_57600:
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_BAUDRATE, 57600);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write, APBUART_SET_BAUDRATE, 57600);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_BAUDRATE, 57600);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write[id], APBUART_SET_BAUDRATE, 57600);
break;
case __PO_HI_DRIVER_SERIAL_COMMON_SPEED_115200:
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_BAUDRATE, 115200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write, APBUART_SET_BAUDRATE, 115200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_BAUDRATE, 115200);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_write[id], APBUART_SET_BAUDRATE, 115200);
break;
case __PO_HI_DRIVER_SERIAL_COMMON_SPEED_UNKNWON:
......@@ -161,20 +191,20 @@ void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_SET_BLOCKING, APBUART_BLK_RX | APBUART_BLK_TX | APBUART_BLK_FLUSH);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_SET_BLOCKING, APBUART_BLK_FLUSH | APBUART_BLK_RX);
*/
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_BLOCKING, APBUART_BLK_FLUSH | APBUART_BLK_TX );
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_TXFIFO_LEN, 256); /* Transmitt buffer 64 chars */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_RXFIFO_LEN, 256); /* Receive buffer 256 chars */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_SET_ASCII_MODE, 0); /* Make \n go \n\r or \r\n */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_CLR_STATS, 0);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read, APBUART_START, 0);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_BLOCKING, APBUART_BLK_FLUSH | APBUART_BLK_TX );
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_TXFIFO_LEN, 256); /* Transmitt buffer 64 chars */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_RXFIFO_LEN, 256); /* Receive buffer 256 chars */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_SET_ASCII_MODE, 0); /* Make \n go \n\r or \r\n */
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_CLR_STATS, 0);
__PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd_read[id], APBUART_START, 0);
if (tcflush (po_hi_c_driver_rasta_serial_fd_read, TCIOFLUSH) != 0)
if (tcflush (po_hi_c_driver_rasta_serial_fd_read[id], TCIOFLUSH) != 0)
{
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Error when trying to flush read part\n");
}
if (tcflush (po_hi_c_driver_rasta_serial_fd_write, TCIOFLUSH) != 0)
if (tcflush (po_hi_c_driver_rasta_serial_fd_write[id], TCIOFLUSH) != 0)
{
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Error when trying to flush write part\n");
}
......@@ -182,14 +212,37 @@ void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Initialization complete !\n");
}
/*!
* \fn int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const __po_hi_port_t port)
* \brief Function related to the RASTA serial driver - sender function.
*
* This function implements the sender function to send bytes through the serial line using
* the RASTA device.
* There are the description of the arguments used by the function:
* - task_id: task that actually sends the data (emitter/producer task)
* - port : (global) port that contains the data
* It returns the following possible values :
* - __PO_HI_UNAVAILABLE : the driver does not handle the device connected to argument port.
* - __PO_HI_SUCCESS : either no value was available to be sent or the function
* send the message successfully over the network.
*/
int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const __po_hi_port_t port)
{
int n;
int ts;
__po_hi_local_port_t local_port;
__po_hi_request_t* request;
__po_hi_msg_t msg;
__po_hi_port_t destination_port;
int n;
int ts;
__po_hi_local_port_t local_port;
__po_hi_request_t* request;
__po_hi_msg_t msg;
__po_hi_port_t destination_port;
__po_hi_device_id dev_id;
dev_id = __po_hi_get_device_from_port (port);
if (dev_id == invalid_device_id)
{
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] Invalid device id for sending\n");
return __PO_HI_UNAVAILABLE;
}
local_port = __po_hi_get_local_port_from_global_port (port);
......@@ -218,7 +271,7 @@ int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const _
__PO_HI_DEBUG_DEBUG ("\n");
n = write (po_hi_c_driver_rasta_serial_fd_write, &msg, __PO_HI_MESSAGES_MAX_SIZE);
n = write (po_hi_c_driver_rasta_serial_fd_write[dev_id], &msg, __PO_HI_MESSAGES_MAX_SIZE);
__PO_HI_DEBUG_DEBUG ("[RASTA SERIAL] write() returns %d\n", n);
......
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