3 * @brief The function and structure overview for the implemtation of the uart.
5 #ifndef __UARTIMPL_H_INCLUDED__
6 #define __UARTIMPL_H_INCLUDED__
8 #include "utils/lobject.h"
9 #include "utils/lsocket.h"
11 #if defined(ON_MODULE)
12 # include <cyg/kernel/kapi.h> /* All the kernel specific stuff */
13 # include <cyg/io/io.h> /* I/O functions */
14 # include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */
15 # include <cyg/io/serialio.h>
16 # include <cyg/io/config_keys.h>
18 # include <sys/types.h>
20 # include "utils/lthread.h"
21 # include "utils/lsocket.h"
23 #if defined(ON_BUILD_PLATFORM)
27 #define UART_BUFFER_SIZE 255
33 typedef void (*uart_function_t
) (void *ptr
);
35 #define IS_GLOBAL (1<<0)
36 #define IS_XBEE (1<<1)
38 struct simplePackageHdr_t
{
40 } __attribute__ ((__packed__
));
49 * @brief Direct representation of a single uart.
51 * Holds the information for the uart. On the pc, it holds info for
52 * connecting links to the node. For the module, it holds handles and
53 * thread info for uart control.
57 LOBJECT
; /** see lobject for how to use this. */
58 char safeBuffer
[UART_BUFFER_SIZE
];
59 char inBuffer
[UART_BUFFER_SIZE
];
61 //uart_function_t callback_fn;
63 //unsigned callback_size;
64 unsigned curr_buffer_ptr
;
65 unsigned curr_written_buffer_ptr
;
66 struct uart
*other_uart
;
67 uint8_t end
; /** Indicates which connector this
70 lsocket_provider_t
*socket_provider
;
71 lsocket_provider_funcs_t socket_funcs
;
73 struct uart_ids_t
*pIds
;
75 volatile BOOL is_recieving_package
;
76 volatile BOOL is_transmitting_package
;
77 volatile bool_t has_just_sent
;
78 volatile BOOL is_forwarding
;
79 volatile BOOL is_ignored
;
80 volatile BOOL has_data_in_buffer
;
82 lthread_t reader_thread
; /** the thread that performs sleeping
83 wait for a incomming data. */
86 lcondition_t condition
;
88 #if defined (ON_BUILD_PLATFORM)
91 uint8_t _buffer
[UART_BUFFER_SIZE
];
96 #if defined (ON_MODULE)
97 cyg_io_handle_t handle
; /** the actual handle to the serial
99 cyg_serial_info_t inf
; /** is this field actually needed? */
104 /** @brief Constructor for implementation of uart controller. */
105 uart_t
*create_uart (int end
);
106 uart_t
*create_xbee_uart (void);
108 void uart_tie(uart_t
*u1
, uart_t
*u2
);
110 /** @brief Stuffs a piece of data into the out queue. */
111 int uart_send_message (uart_t
*uart
, object_t data
, uint8_t size
);
113 /** @brief copies data from the inbuffer to the location in "buffer". */
114 void uart_recieve_data (uart_t
*uart
, object_t data
, uint8_t size
);
116 void uart_release_connection (uart_t
*uart
);
118 void uart_signal_rcv (uart_t
*uart
);