Commit 36a2b6d4 authored by julien.delange's avatar julien.delange
Browse files

* complete implementation of serial drivers



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@601 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent c7ff1e99
......@@ -17,6 +17,7 @@
#include <po_hi_utils.h>
#include <po_hi_messages.h>
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
/* po-hi-c related files */
#include <activity.h>
......@@ -38,18 +39,32 @@ int po_hi_c_driver_serial_fd;
void __po_hi_c_driver_serial_linux_poller (void)
{
int n;
int ts;
int tmp;
unsigned long* swap_pointer;
unsigned long swap_value;
__po_hi_msg_t msg;
__po_hi_request_t request;
int n;
int tmp;
__DEBUGMSG ("Hello, i'm the serial linux poller !\n");
__DEBUGMSG ("[LINUX SERIAL] Hello, i'm the serial poller !\n");
n = read (po_hi_c_driver_serial_fd, &(msg.content), __PO_HI_MESSAGES_MAX_SIZE);
__DEBUGMSG ("[LINUX SERIAL] Message: 0x");
for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
{
__DEBUGMSG ("%x", msg.content[ts]);
}
__DEBUGMSG ("\n");
if (n == -1)
{
__DEBUGMSG("[LINUX SERIAL] Cannot read on socket !\n");
return;
}
......@@ -57,22 +72,26 @@ void __po_hi_c_driver_serial_linux_poller (void)
msg.length = n;
if (n > 0)
for (tmp = 0 ; tmp < n ; tmp += 4)
{
for (tmp = 0 ; tmp < n ; tmp += 4)
{
swap_pointer = (unsigned long*) &msg.content[tmp];
swap_value = *swap_pointer;
*swap_pointer = __po_hi_swap_byte (swap_value);
}
swap_pointer = (unsigned long*) &msg.content[tmp];
swap_value = *swap_pointer;
*swap_pointer = __po_hi_swap_byte (swap_value);
}
printf ("[LINUX SERIAL] Received: %s\n", msg.content);
__DEBUGMSG ("[LINUX SERIAL] Message swapped: 0x");
for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
{
__DEBUGMSG ("%x", msg.content[ts]);
}
__DEBUGMSG ("\n");
__po_hi_unmarshall_request (&request, &msg);
__DEBUGMSG ("[LINUX SERIAL] Received: %s\n", msg.content);
printf ("[LINUX SERIAL] Destination port: %d\n", request.port);
__po_hi_main_deliver (&request);
}
__po_hi_unmarshall_request (&request, &msg);
__DEBUGMSG ("[LINUX SERIAL] Destination port: %d\n", request.port);
__po_hi_main_deliver (&request);
}
......@@ -165,10 +184,52 @@ void __po_hi_c_driver_serial_linux_init (__po_hi_device_id id)
__DEBUGMSG ("[LINUX SERIAL] End of init\n");
}
int __po_hi_c_driver_serial_linux_sender (__po_hi_task_id task, __po_hi_port_t port)
int __po_hi_c_driver_serial_linux_sender (__po_hi_task_id task_id, __po_hi_port_t port)
{
write (po_hi_c_driver_serial_fd, "LINUX\n", 6);
int n;
int tmp;
int ts;
unsigned long* swap_pointer;
unsigned long swap_value;
__po_hi_local_port_t local_port;
__po_hi_request_t* request;
__po_hi_msg_t msg;
__po_hi_port_t destination_port;
local_port = __po_hi_get_local_port_from_global_port (port);
request = __po_hi_gqueue_get_most_recent_value (task_id, local_port);
destination_port = __po_hi_gqueue_get_destination (task_id, local_port, 0);
__po_hi_msg_reallocate (&msg);
request->port = destination_port;
__po_hi_marshall_request (request, &msg);
for (tmp = 0 ; tmp < __PO_HI_MESSAGES_MAX_SIZE ; tmp += 4)
{
swap_pointer = (unsigned long*) &msg.content[tmp];
swap_value = *swap_pointer;
*swap_pointer = __po_hi_swap_byte (swap_value);
}
n = write (po_hi_c_driver_serial_fd, &msg, __PO_HI_MESSAGES_MAX_SIZE);
__DEBUGMSG ("[LINUX SERIAL] write() returns %d\n", n);
__DEBUGMSG ("[LINUX SERIAL] Message sent: 0x");
for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
{
__DEBUGMSG ("%x", msg.content[ts]);
}
__DEBUGMSG ("\n");
return 1;
}
#endif
......
......@@ -11,12 +11,14 @@
#ifdef __PO_HI_NEED_DRIVER_SERIAL_RASTA
#include <activity.h>
#include <marshallers.h>
#include <po_hi_debug.h>
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
#include <po_hi_messages.h>
#include <po_hi_utils.h>
#include <drivers/po_hi_rtems_utils.h>
#include <drivers/po_hi_driver_rasta_serial.h>
......@@ -38,16 +40,37 @@ int po_hi_c_driver_rasta_serial_fd;
void __po_hi_c_driver_serial_rasta_poller (void)
{
char buf[1024];
__po_hi_msg_t msg;
__po_hi_request_t request;
int n;
int ts;
__DEBUGMSG ("[RASTA SERIAL] Hello, i'm the poller !\n");
n = read (po_hi_c_driver_rasta_serial_fd, &buf, 6);
n = read (po_hi_c_driver_rasta_serial_fd, &(msg.content), __PO_HI_MESSAGES_MAX_SIZE);
if (n == -1)
{
__DEBUGMSG("[RASTA SERIAL] Cannot read on socket !\n");
return;
}
__DEBUGMSG ("[RASTA SERIAL] read() returns %d\n", n);
if (n > 0)
__DEBUGMSG ("[RASTA SERIAL] Message received by poller: 0x");
for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
{
buf[n] = '\0';
printf ("[RASTA SERIAL] Received: %s\n", buf);
__DEBUGMSG ("%x", msg.content[ts]);
}
__DEBUGMSG ("\n");
msg.length = n;
__po_hi_unmarshall_request (&request, &msg);
printf ("[RASTA SERIAL] Destination port: %d\n", request.port);
__po_hi_main_deliver (&request);
}
void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
......@@ -80,6 +103,7 @@ void __po_hi_c_driver_serial_rasta_init (__po_hi_device_id id)
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;
......@@ -97,9 +121,16 @@ int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const _
__po_hi_marshall_request (request, &msg);
__DEBUGMSG ("[RASTA SERIAL] Message sent: 0x");
for (ts = 0 ; ts < __PO_HI_MESSAGES_MAX_SIZE ; ts++)
{
__DEBUGMSG ("%x", msg.content[ts]);
}
__DEBUGMSG ("\n");
n = write (po_hi_c_driver_rasta_serial_fd, &msg, __PO_HI_MESSAGES_MAX_SIZE);
__DEBUGMSG ("RASTA write returns %d\n", n);
__DEBUGMSG ("[RASTA SERIAL] write() returns %d\n", n);
return 1;
}
......
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