po_hi_driver_rasta_serial.c 2.85 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
16
17
18
19
20
21
#include <po_hi_debug.h>
#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>
22
23
/* POSIX-style files */

24
25
26
27
28
29
#include <pci.h>
#include <rasta.h>
#include <apbuart_rasta.h>

/* Rasta includes from GAISLER drivers */

30
31
#define __PO_HI_DRIVER_SERIAL_RASTA_DEVICE "/dev/apburasta0"
#define __PO_HI_DRIVER_SERIAL_RASTA_BAUDRATE 19200
32
33
34

int po_hi_c_driver_rasta_serial_fd;

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

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

60
  po_hi_c_driver_rasta_serial_fd = open (__PO_HI_DRIVER_SERIAL_RASTA_DEVICE, O_RDWR);
61
62
63

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

67
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(po_hi_c_driver_rasta_serial_fd, APBUART_SET_BAUDRATE, __PO_HI_DRIVER_SERIAL_RASTA_BAUDRATE); /* stream mode */
68
69
70
71
72
73
  __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);
74
75
}

76
77
int __po_hi_c_driver_serial_rasta_sender (const __po_hi_task_id task_id, const __po_hi_port_t port)
{
78
   int n;
79
80
81
82
   __po_hi_local_port_t local_port;

   local_port = __po_hi_port_global_to_local[(int)port];
   request = &(__po_hi_gqueues_most_recent_values[id][local_port]);
83
   n = write (po_hi_c_driver_rasta_serial_fd, "blabl\n", 6);
84
   __DEBUGMSG ("RASTA write returns %d\n", n);
85
86
87
   return 1;
}

88
89
#endif