Added the repository from the odin svn
[educational.data.git] / fag / speciale / nodes / src / libs / hal / uart.h
blob1dced086364803469d9328ffb6cc9a5790bd3a6c
1 /**
2 * @file uart.h
3 * @brief The function and structure overview for the implemtation of the uart.
4 */
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>
19 # include <dirent.h>
20 # include "utils/lthread.h"
21 # include "utils/lsocket.h"
22 #endif
23 #if defined(ON_BUILD_PLATFORM)
24 # include <stdlib.h>
25 #endif
27 #define UART_BUFFER_SIZE 255
29 BEGIN_CSPEC
31 struct link;
33 typedef void (*uart_function_t) (void *ptr);
35 #define IS_GLOBAL (1<<0)
36 #define IS_XBEE (1<<1)
38 struct simplePackageHdr_t {
39 uint16_t id;
40 } __attribute__ ((__packed__));
42 struct uart_ids_t {
43 uint16_t id[16];
44 uint8_t cp;
45 lmutex_t test_mutex;
48 /**
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.
55 typedef struct uart
57 LOBJECT; /** see lobject for how to use this. */
58 char safeBuffer[UART_BUFFER_SIZE];
59 char inBuffer[UART_BUFFER_SIZE];
60 //void *callback_ptr;
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
68 represents */
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. */
85 lmutex_t mutex;
86 lcondition_t condition;
88 #if defined (ON_BUILD_PLATFORM)
89 struct link *link;
90 void *node;
91 uint8_t _buffer[UART_BUFFER_SIZE];
92 int _buf_size;
93 int _buf_read_ptr;
94 int _buf_write_ptr;
95 #endif
96 #if defined (ON_MODULE)
97 cyg_io_handle_t handle; /** the actual handle to the serial
98 port. */
99 cyg_serial_info_t inf; /** is this field actually needed? */
100 #endif
101 } uart_t;
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);
119 END_CSPEC
120 #endif