Initial commit for stepper controller
[radiotelescope.git] / stepper_controller / arduino / stepper / serial_io.h
1 //
2 // Product: Serial I/O library for QPnano and Arduino
3 // Version: 0.1
4 // Date:    25 November 2010
5 //
6 //                      +-----------------------+
7 //                      |   d e c i s i o n s   |
8 //                      +-----------------------|
9 //                      | a n d   d e s i g n s |
10 //                      +-----------------------+
11 //
12 // Copyright (C) 2010 Decisions and Designs Pty Ltd. All rights reserved.
13 //
14 // This software may be distributed and modified under the terms of the GNU
15 // General Public License version 2 (GPL) as published by the Free Software
16 // Foundation and appearing in the file GPL.TXT included in the packaging of
17 // this file. Please note that GPL Section 2[b] requires that all works based
18 // on this software must also be made publicly available under the terms of
19 // the GPL ("Copyleft").
20 //
21 // Contact information:
22 // Decisions and Designs Web site: http://www.decisions-and-designs.com.au
23 // e-mail:                         [email protected]
24 //
25
26 #ifndef serial_io_h
27 #define serial_io_h
28
29 #define SERIAL_SUCCESS              0
30 #define SERIAL_TRANSMIT_BUSY        1
31 #define SERIAL_PORT_INVALID         2
32
33 #define SERIAL_STATUS_OVERRUN 0
34 #define SERIAL_STATUS_FRAME   1
35 #define SERIAL_STATUS_PARITY  2
36
37 enum {
38     USART = 0
39     #if defined (__AVR_ATmega1280__)
40    ,USART1,
41     USART2,
42     USART3
43     #endif
44 }; 
45
46 typedef struct serial_msg {
47     uint8_t port;           // USART0 to USART3
48     uint8_t ch;             // received character, undefined for TX signals
49     uint8_t status;         // generic status bits SERIAL_STATUS_...
50 } SerialMsg;
51
52 typedef union {
53     QParam param;
54     SerialMsg msg;
55 } SerialParam;
56
57 /* Initialise hardware and attach the receiver and/or transmitter to a HSM.
58    If rx or tx are NULL then an assignment will not be made for that part.
59    This allows two different HSMs to use the tx and rx part but the baud
60    rate will be set by the last caller */
61 void initSerial(uint32_t baud, QActive *rx, QActive *tx);
62 #if defined(__AVR_ATmega1280__)
63 void initSerial1(uint32_t baud, QActive *rx, QActive *tx);
64 void initSerial2(uint32_t baud, QActive *rx, QActive *tx);
65 void initSerial3(uint32_t baud, QActive *rx, QActive *tx);
66 #endif /* __AVR_ATmega1280__ */
67
68 // Attempt to transmit a character. Report if SERIAL_TRANSMIT_BUSY.
69 uint8_t serialTransmit(uint8_t ch);
70 #if defined(__AVR_ATmega1280__)
71 uint8_t serial1Transmit(uint8_t ch);
72 uint8_t serial2Transmit(uint8_t ch);
73 uint8_t serial3Transmit(uint8_t ch);
74 #endif /* __AVR_ATmega1280__ */
75
76 // Send a SERIAL_TX_COMPLETE signal when the last char has been transmitted
77 void serialTransmitComplete(void);
78 #if defined(__AVR_ATmega1280__)
79 void serial1TransmitComplete(void);
80 void serial2TransmitComplete(void);
81 void serial3TransmitComplete(void);
82 #endif /* __AVR_ATmega1280__ */
83
84 #endif                                                       /* serial_io_h */

UCC git Repository :: git.ucc.asn.au