-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
Copy pathsam_ba_serial.h
143 lines (117 loc) · 3.62 KB
/
sam_ba_serial.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (c) 2015 Arduino LLC. All right reserved.
Copyright (c) 2015 Atmel Corporation/Thibaut VIARD. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SAM_BA_SERIAL_H_
#define _SAM_BA_SERIAL_H_
#include <stdint.h>
#include <stdbool.h>
/* USART buffer size (must be a power of two) */
#define USART_BUFFER_SIZE (128)
/* Define the default time-out value for USART. */
#define USART_DEFAULT_TIMEOUT (1000)
/* Xmodem related defines */
/* CRC16 polynomial */
#define CRC16POLY (0x1021)
#define SHARP_CHARACTER '#'
/* X/Ymodem protocol: */
#define SOH (0x01)
//#define STX (0x02)
#define EOT (0x04)
#define ACK (0x06)
#define NAK (0x15)
#define CAN (0x18)
#define ESC (0x1b)
#define PKTLEN_128 (128)
/**
* \brief Open the given USART
*/
void serial_open(void);
/**
* \brief Stops the USART
*/
void serial_close(void);
/**
* \brief Puts a byte on usart line
*
* \param value Value to put
*
* \return \c 1 if function was successfully done, otherwise \c 0.
*/
int serial_putc(int value);
/**
* \brief Waits and gets a value on usart line
*
* \return value read on usart line
*/
int serial_getc(void);
/**
* \brief Returns true if the SAM-BA Uart received the sharp char
*
* \return Returns true if the SAM-BA Uart received the sharp char
*/
int serial_sharp_received(void);
/**
* \brief This function checks if a character has been received on the usart line
*
* \return \c 1 if a byte is ready to be read.
*/
bool serial_is_rx_ready(void);
/**
* \brief Gets a value on usart line
*
* \return value read on usart line
*/
int serial_readc(void);
/**
* \brief Send buffer on usart line
*
* \param data pointer
* \param number of data to send
* \return number of data sent
*/
uint32_t serial_putdata(void const* data, uint32_t length); //Send given data (polling)
/**
* \brief Gets data from usart line
*
* \param data pointer
* \param number of data to get
* \return value read on usart line
*/
uint32_t serial_getdata(void* data, uint32_t length); //Get data from comm. device
/**
* \brief Send buffer on usart line using Xmodem protocol
*
* \param data pointer
* \param number of data to send
* \return number of data sent
*/
uint32_t serial_putdata_xmd(void const* data, uint32_t length); //Send given data (polling) using xmodem (if necessary)
/**
* \brief Gets data from usart line using Xmodem protocol
*
* \param data pointer
* \param number of data to get
* \return value read on usart line
*/
uint32_t serial_getdata_xmd(void* data, uint32_t length); //Get data from comm. device using xmodem (if necessary)
/**
* \brief Compute the CRC
*
* \param Char to add to CRC
* \param Previous CRC
* \return The new computed CRC
*/
unsigned short serial_add_crc(char c, unsigned short crc);
#endif // _SAM_BA_SERIAL_H_