po_hi_driver_rasta_serial.c 3.28 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
 * Copyright (C) 2010, European Space Agency
 */

9
10
#include <deployment.h>
/* Generated code header */
11

12
#ifdef __PO_HI_NEED_DRIVER_SERIAL_RASTA
13

14
15
#include <marshallers.h>

16
#include <po_hi_debug.h>
17
18
19
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
#include <po_hi_messages.h>
20
21
22
23
24
25
26
#include <drivers/rtems_utils.h>
#include <drivers/po_hi_driver_rasta_serial.h>

#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
27
28
/* POSIX-style files */

29
30
31
32
33
#include <pci.h>
#include <rasta.h>
#include <apbuart_rasta.h>
/* Rasta includes from GAISLER drivers */

34
35
#define __PO_HI_DRIVER_SERIAL_RASTA_DEVICE "/dev/apburasta0"
#define __PO_HI_DRIVER_SERIAL_RASTA_BAUDRATE 19200
36
37
38

int po_hi_c_driver_rasta_serial_fd;

39
40
void __po_hi_c_driver_serial_rasta_poller (void)
{
41
42
   char buf[1024];
   int n;
43
   __DEBUGMSG ("[RASTA SERIAL] Hello, i'm the poller !\n");
44
45
46
   n = read (po_hi_c_driver_rasta_serial_fd, &buf, 6); 
   __DEBUGMSG ("[RASTA SERIAL] read() returns %d\n", n);
   if (n > 0)
47
   {
48
49
      buf[n] = '\0';
      printf ("[RASTA SERIAL] Received: %s\n", buf);
50
   }
51
52
}

53
54
void __po_hi_c_driver_serial_rasta_init (void)
{
55
56
57
58
59
   __DEBUGMSG ("[RASTA SERIAL] Init\n");
   init_pci();
   __DEBUGMSG ("[RASTA SERIAL] Initializing RASTA ...\n");
  if  ( rasta_register() ){
    __DEBUGMSG(" ERROR !\n");
60
    return;
61
62
63
  }
    __DEBUGMSG(" OK !\n");

64
  po_hi_c_driver_rasta_serial_fd = open (__PO_HI_DRIVER_SERIAL_RASTA_DEVICE, O_RDWR);
65
66
67

   if (po_hi_c_driver_rasta_serial_fd < 0)
   {
68
      __DEBUGMSG ("[RASTA SERIAL] Error while opening device %s\n", __PO_HI_DRIVER_SERIAL_RASTA_DEVICE);
69
70
   }

71
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_SET_BAUDRATE, __PO_HI_DRIVER_SERIAL_RASTA_BAUDRATE); /* stream mode */
72
73
74
75
76
77
  __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_TXFIFO_LEN, 64);  /* Transmitt buffer 64 chars */
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_SET_RXFIFO_LEN, 256); /* Receive buffer 256 chars */
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, 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, APBUART_CLR_STATS, 0);
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_START, 0);
78
79
}

80
81
int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const __po_hi_port_t port)
{
82
   int n;
83
   __po_hi_local_port_t local_port;
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
   __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);

   n = write (po_hi_c_driver_rasta_serial_fd, &msg, __PO_HI_MESSAGES_MAX_SIZE);
101

102
   __DEBUGMSG ("RASTA write returns %d\n", n);
103
104
105
   return 1;
}

106
107
#endif