source: rtems/c/src/lib/libbsp/powerpc/qoriq/console/uart-bridge-master.c @ 3bb9f198

4.115
Last change on this file since 3bb9f198 was 964c734b, checked in by Jennifer Averett <Jennifer.Averett@…>, on 10/18/11 at 18:32:23

2011-10-18 Jennifer Averett <Jennifer.Averett@…>

PR 1917/bsps

  • Makefile.am, console/console-config.c, console/uart-bridge-master.c, console/uart-bridge-slave.c, startup/bspstart.c: Modifications to add dynamic tables for libchip serial drivers.
  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup QorIQUartBridge
5 *
6 * @brief UART bridge master implementation.
7 */
8
9/*
10 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 *
22 * $Id$
23 */
24
25#include <sys/stat.h>
26#include <assert.h>
27#include <fcntl.h>
28#include <unistd.h>
29#include <termios.h>
30
31#include <libchip/sersupp.h>
32
33#include <bspopts.h>
34#include <bsp/uart-bridge.h>
35
36#define TRANSMIT_EVENT RTEMS_EVENT_13
37
38static void serial_settings(int fd)
39{
40  struct termios term;
41  int rv = tcgetattr(fd, &term);
42  assert(rv == 0);
43
44  term.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
45  term.c_oflag &= ~OPOST;
46  term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
47  term.c_cflag &= ~(CSIZE | PARENB);
48  term.c_cflag |= CS8;
49
50  term.c_cc [VMIN] = 1;
51  term.c_cc [VTIME] = 1;
52
53  rv = tcsetattr(fd, TCSANOW, &term);
54  assert(rv == 0);
55}
56
57static void uart_bridge_master_service(intercom_packet *packet, void *arg)
58{
59  rtems_status_code sc = RTEMS_SUCCESSFUL;
60  uart_bridge_master_control *control = arg;
61
62  sc = rtems_chain_append_with_notification(
63    &control->transmit_fifo,
64    &packet->glue.node,
65    control->transmit_task,
66    TRANSMIT_EVENT
67  );
68  assert(sc == RTEMS_SUCCESSFUL);
69}
70
71static void receive_task(rtems_task_argument arg)
72{
73  uart_bridge_master_control *control = (uart_bridge_master_control *) arg;
74  intercom_type type = control->type;
75
76  int fd = open(control->device_path, O_RDONLY);
77  assert(fd >= 0);
78
79  serial_settings(fd);
80
81  while (true) {
82    intercom_packet *packet = qoriq_intercom_allocate_packet(
83      type,
84      INTERCOM_SIZE_64
85    );
86    ssize_t in = read(fd, packet->data, packet->size - 1);
87    if (in > 0) {
88      packet->size = (size_t) in;
89      qoriq_intercom_send_packet(QORIQ_UART_BRIDGE_SLAVE_CORE, packet);
90    } else {
91      qoriq_intercom_free_packet(packet);
92    }
93  }
94}
95
96static void transmit_task(rtems_task_argument arg)
97{
98  rtems_status_code sc = RTEMS_SUCCESSFUL;
99  uart_bridge_master_control *control = (uart_bridge_master_control *) arg;
100  rtems_chain_control *fifo = &control->transmit_fifo;
101
102  int fd = open(control->device_path, O_WRONLY);
103  assert(fd >= 0);
104
105  serial_settings(fd);
106
107  while (true) {
108    intercom_packet *packet = NULL;
109    sc = rtems_chain_get_with_wait(
110      fifo,
111      TRANSMIT_EVENT,
112      RTEMS_NO_TIMEOUT,
113      (rtems_chain_node **) &packet
114    );
115    assert(sc == RTEMS_SUCCESSFUL);
116    write(fd, packet->data, packet->size);
117    qoriq_intercom_free_packet(packet);
118  }
119}
120
121static rtems_id create_task(
122  char name,
123  rtems_task_entry entry,
124  uart_bridge_master_control *control
125)
126{
127  rtems_status_code sc = RTEMS_SUCCESSFUL;
128  rtems_id task = RTEMS_ID_NONE;
129  char index = (char) ('0' + control->type - INTERCOM_TYPE_UART_0);
130
131  sc = rtems_task_create(
132    rtems_build_name('U', 'B', name, index),
133    QORIQ_UART_BRIDGE_TASK_PRIORITY,
134    0,
135    RTEMS_DEFAULT_MODES,
136    RTEMS_DEFAULT_ATTRIBUTES,
137    &task
138  );
139  assert(sc == RTEMS_SUCCESSFUL);
140
141  sc = rtems_task_start(
142    task,
143    entry,
144    (rtems_task_argument) control
145  );
146  assert(sc == RTEMS_SUCCESSFUL);
147
148  return task;
149}
150
151static void initialize(int minor)
152{
153  console_tbl *ct = Console_Port_Tbl [minor];
154  uart_bridge_master_control *control = ct->pDeviceParams;
155  intercom_type type = control->type;
156
157  qoriq_intercom_service_install(type, uart_bridge_master_service, control);
158  create_task('R', receive_task, control);
159  control->transmit_task = create_task('T', transmit_task, control);
160}
161
162static int first_open(int major, int minor, void *arg)
163{
164  return -1;
165}
166
167static int last_close(int major, int minor, void *arg)
168{
169  return -1;
170}
171
172static int read_polled(int minor)
173{
174  return -1;
175}
176
177static void write_polled(int minor, char c)
178{
179  /* Do nothing */
180}
181
182static int set_attributes(int minor, const struct termios *term)
183{
184  return -1;
185}
186
187console_fns qoriq_uart_bridge_master = {
188  .deviceProbe = libchip_serial_default_probe,
189  .deviceFirstOpen = first_open,
190  .deviceLastClose = last_close,
191  .deviceRead = read_polled,
192  .deviceWrite = NULL,
193  .deviceInitialize = initialize,
194  .deviceWritePolled = write_polled,
195  .deviceSetAttributes = set_attributes,
196  .deviceOutputUsesInterrupts = false
197};
Note: See TracBrowser for help on using the repository browser.