Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uniprot.h
Go to the documentation of this file.
1
45 #ifndef _UNIPROT_H_
46 #define _UNIPROT_H_
47 //==============================| Configuration |==============================
48 /* DEFINE PIPE PARAMETERS HERE. This settings can be also in header file of
49 * driver.
50 * However, PLEASE MAKE SURE that used pipe numbers not collide!
51 * Always count pipes from zero! If you "skip" some pipes program will waste
52 * RAM, which you really do not want!
53 * Structure is UNI_PIPEx_(FRAME_SIZE/FUNC_INIT/FUNC_TASK) where "x" is pipe
54 * number.
55 * Example:
56 *
57 * // Define frame size (number of bytes per one transmission)
58 * #define UNI_PIPE0_FRAME_SIZE 8
59 * // Initialize function which will be called in initialization process
60 * #define UNI_PIPE0_FUNC_INIT USB_Init()
61 * // Driver task
62 * #define UNI_PIPE0_FUNC_TASK USB_Task()
63 *
64 * #define UNI_PIPE1_FRAME_SIZE 3 // Every transmission is 3 bytes long
65 * #define UNI_PIPE1_FUNC_INIT I2C_Init()
66 * #define UNI_PIPE1_FUNC_TASK I2C_Task()
67 *
68 * #define UNI_PIPE1_FRAME_SIZE 1 // Every transmission is 1 byte long
69 * #define UNI_PIPE1_FUNC_INIT UART_Init()
70 * #define UNI_PIPE1_FUNC_TASK UART_Task()
71 */
72
73
74 //================================| Includes |=================================
75 // HERE INCLUDE NECCESSARY LOW LEVEL DRIVERS WHICH USED PIPES USE
76 #include "device_generic_hid.h"
77
78
79
80
81
82
83
84
85
86
87
88
89
90 //=============================| Other includes |==============================
91
92 // Data types - uint8, uint16....
93 #include <inttypes.h>
94
95 // CRC library
96 // Include only if architecture is AVR8 (else define own CRC function)
97 #ifdef __AVR_ARCH__
98 #include <util/crc16.h>
99 #endif
100
101
102 //===============================| Definitions |===============================
103
105 #define UNI_CHAR_HEADER 'H'
106
108 #define UNI_CHAR_DATA 'D'
109
111 #define UNI_CHAR_TAIL 'T'
112
114 #define UNI_CHAR_ACK 'A'
115
117 #define UNI_CHAR_NACK 'N'
118
120 #define UNI_CHAR_RESET 'R'
121
123 #define UNI_CHAR_BUFFER_OVERFLOW 'O'
124
125
126
127
128
129
130 #ifdef UNI_PIPE6_FRAME_SIZE
131 #define UNI_MAX_PIPE 6
132 #else
133 #ifdef UNI_PIPE5_FRAME_SIZE
134 #define UNI_MAX_PIPE 5
135 #else
136 #ifdef UNI_PIPE4_FRAME_SIZE
137 #define UNI_MAX_PIPE 4
138 #else
139 #ifdef UNI_PIPE3_FRAME_SIZE
140 #define UNI_MAX_PIPE 3
141 #else
142 #ifdef UNI_PIPE2_FRAME_SIZE
143 #define UNI_MAX_PIPE 2
144 #else
145 #ifdef UNI_PIPE1_FRAME_SIZE
146 #define UNI_MAX_PIPE 1
147 #else
148 #ifdef UNI_PIPE0_FRAME_SIZE
149 #define UNI_MAX_PIPE 0
150 #else
151 #error "At least one pipe MUST be defined! Please take a look at Configuration\
152 subsection."
153 #endif
154 #endif
155 #endif
156 #endif
157 #endif
158 #endif
159 #endif
160 //===============================| Structures |================================
164 typedef enum{
165 UNI_SUCCESS = 0,
166 UNI_FAIL = 2,
167 UNI_INVALID_PARAMETER = 3,
168 UNI_TX_PACKET_NOT_CONFIGURED = 4
169 } UNI_RES_CODE;
170
180 typedef enum{
181 UNI_STATE_HEADER_H = 7,
182 UNI_STATE_HEADER_NOB_H = 8,
183 UNI_STATE_HEADER_NOB_L = 9,
184 UNI_STATE_DATA_D = 10,
185 UNI_STATE_DATA = 11,
186 UNI_STATE_TAIL_T = 12,
187 UNI_STATE_CRC16_H = 13,
188 UNI_STATE_CRC16_L = 14
189 } UNI_PACKET_STATE_DATA;
190
197 typedef enum{
198 UNI_STATE_CMD_CHAR = 0,
199 UNI_STATE_CMD_CRC16_H = 1,
200 UNI_STATE_CMD_CRC16_L = 2,
201 } UNI_PACKET_STATE_CMD;
202
206 typedef struct{
207 UNI_PACKET_STATE_DATA data :4;
208 UNI_PACKET_STATE_CMD cmd :2;
209 } UNI_PACKET_STATE_t;
210
212 typedef struct{
213 // Maximal number of RX Bytes. Also use as received Byte counter
214 uint16_t i_rx_max_num_of_data_Bytes;
215 // Pointer to buffer (where store data)
216 uint8_t *p_rx_buffer;
217 // Backup for begin address of buffer
218 uint8_t *p_rx_buffer_bakup;
219 // When configuration for RX is done
220 uint8_t i_rx_config_done;
221
222
223 /* Number of TX Bytes to transmit. Should not be changed for NACK case (all
224 * data will be send again)
225 */
226 uint16_t i_tx_num_of_data_Bytes;
227 // Pointer to buffer (where load data)
228 uint8_t *p_tx_buffer;
229 // Backup for begin address of buffer
230 uint8_t *p_tx_buffer_backup;
231 // When configuration for TX is done
232 uint8_t i_tx_config_done;
233
234
235 // Number of bytes transmitted by one transmission (common for RX and TX)
236 uint8_t i_frame_size;
237 } UNI_PACKET_CONFIG_t;
238
239
241 typedef struct{
247 uint16_t TX_EN :1;
255 uint16_t REINIT :1;
261 uint16_t ERROR_CHAR_RX_OVERFLOW :1;
266 uint16_t ERROR_RX_BUFFER_OVERFLOW :1;
270 uint16_t DATA_IN_TX_BUFFER_READY :1;
274 uint16_t ERROR_TX_NOT_CONFIGURED :1;
278 uint16_t ERROR_RX_NOT_CONFIGURED :1;
283 uint16_t ERROR_RX_NACK :1;
288 uint16_t SENDING_ACK :1;
290 uint16_t ERROR_HEADER_RX :1;
292 uint16_t ERROR_CRC_RX :1;
294 uint16_t ERROR_TAIL_RX :1;
299 uint16_t ERROR_GENERAL_RX :1;
304 uint16_t ERROR_GENERAL_TX :1;
306 uint16_t RX_DONE :1;
308 uint16_t TX_DONE :1;
309 } UNI_SR_flags;
310
318 typedef union{
320 UNI_SR_flags flags;
322 uint16_t status_reg;
323 } UNI_SR_t;
324
325 //===========================| Function prototypes |===========================
326
331 void Uniprot_Init(void);
332
336 void Uniprot_Task(void);
337
351 UNI_RES_CODE Uniprot_config_RX_packet( uint8_t i_pipe_ID,
352 uint16_t i_rx_max_num_of_data_Bytes,
353 void *p_rx_buffer);
354
355
367 UNI_RES_CODE Uniprot_config_TX_packet( uint8_t i_pipe_ID,
368 uint16_t i_tx_num_of_data_Bytes,
369 void *p_tx_buffer);
370
377 UNI_RES_CODE Uniprot_Is_RX_pipe_ready(uint8_t i_pipe_ID);
378
385 UNI_RES_CODE Uniprot_Is_TX_pipe_ready(uint8_t i_pipe_ID);
386
387
397 UNI_RES_CODE Uniprot_Is_TX_transmission_enable(uint8_t i_pipe_ID);
398
399
408 void Uniprot_rx_data(uint8_t i_pipe_ID, uint8_t* p_DataArray);
409
416 void Uniprot_tx_data(uint8_t i_pipe_ID, uint8_t* p_DataArray);
417
418
419
430 UNI_RES_CODE Uniprot_Is_reinit_flag_set(uint8_t i_pipe_ID);
431
432
433
434
435
436
437
438
450 UNI_RES_CODE Uniprot_Set_init_reinit_flag(uint8_t i_pipe_ID);
451
452
453 #endif