]> begriffs open source - cmsis-driver-validation/blob - Source/DV_USART.c
Minor update to USART driver validation
[cmsis-driver-validation] / Source / DV_USART.c
1 /*
2  * Copyright (c) 2015-2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * -----------------------------------------------------------------------------
19  *
20  * Project:     CMSIS-Driver Validation
21  * Title:       Universal Synchronous Asynchronous Receiver/Transmitter (USART) 
22  *              Driver Validation tests
23  *
24  * -----------------------------------------------------------------------------
25  */
26
27 #ifndef __DOXYGEN__                     // Exclude form the documentation
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "cmsis_dv.h"
34 #include "DV_USART_Config.h"
35 #include "DV_Framework.h"
36
37 #include "Driver_USART.h"
38
39 // Fixed settings for communication with USART Server (not available through DV_USART_Config.h)
40 #define  USART_CFG_SRV_BAUDRATE         115200  // Baudrate
41 #define  USART_CFG_SRV_DATA_BITS        8       // 8 data bits
42 #define  USART_CFG_SRV_PARITY           0       // None
43 #define  USART_CFG_SRV_STOP_BITS        0       // 1 stop bit
44 #define  USART_CFG_SRV_FLOW_CONTROL     0       // None
45
46 // Check configuration
47 #if (USART_CFG_TEST_MODE == 1)          // If USART Server is selected
48
49 #if (USART_CFG_DEF_MODE == 1)           // If default mode is Asynchronous
50 #if (USART_CFG_SRV_MODE != 1)           // If USART Server mode is not Asynchronous
51 #warning When USART Server Test Mode is used and Default settings for Tests Mode (USART_CFG_DEF_MODE) is Asynchronous then Mode for USART Server (USART_CFG_SRV_MODE) must also be Asynchronous!
52 #endif
53 #elif (USART_CFG_DEF_MODE == 2)         // If default mode is Synchronous Master
54 #if (USART_CFG_SRV_MODE != 1)           // If USART Server mode is not Asynchronous
55 #warning When USART Server Test Mode is used and Default settings for Tests Mode (USART_CFG_DEF_MODE) is Synchronous Master then Mode for USART Server (USART_CFG_SRV_MODE) must be Asynchronous!
56 #endif
57 #elif (USART_CFG_DEF_MODE == 3)         // If default mode is Synchronous Slave
58 #if (USART_CFG_SRV_MODE != 1)           // If USART Server mode is not Asynchronous
59 #warning When USART Server Test Mode is used and Default settings for Tests Mode (USART_CFG_DEF_MODE) is Synchronous Slave then Mode for USART Server (USART_CFG_SRV_MODE) must be Asynchronous!
60 #endif
61 #elif (USART_CFG_DEF_MODE == 4)         // If default mode is Single-wire
62 #if (USART_CFG_SRV_MODE != 4)           // If USART Server mode is not Single-wire
63 #warning When USART Server Test Mode is used and Default settings for Tests Mode (USART_CFG_DEF_MODE) is Single-wire then Mode for USART Server (USART_CFG_SRV_MODE) must also be Single-wire!
64 #endif
65 #elif (USART_CFG_DEF_MODE == 5)         // If default mode is IrDA
66 #if (USART_CFG_SRV_MODE != 5)           // If USART Server mode is not IrDA
67 #warning When USART Server Test Mode is used and Default settings for Tests Mode (USART_CFG_DEF_MODE) is Single-wire then Mode for USART Server (USART_CFG_SRV_MODE) must also be Single-wire!
68 #endif
69 #else
70 #warning Unknown Default settings for Tests Mode (USART_CFG_DEF_MODE)!
71 #endif
72 #else                                   // If Loopback is selected
73 #if (USART_CFG_DEF_MODE != 1)           // If default mode is not Asynchronous
74 #error For Loopback Test Mode only Default settings for Tests Mode (USART_CFG_DEF_MODE) Asynchronous setting is supported!
75 #endif
76 #endif
77
78 #define CMD_LEN                   32UL  // Length of command to USART Server
79 #define RESP_GET_VER_LEN          16UL  // Length of response from USART Server to GET VER command
80 #define RESP_GET_CAP_LEN          32UL  // Length of response from USART Server to GET CAP command
81 #define RESP_GET_CNT_LEN          16UL  // Length of response from USART Server to GET CNT command
82 #define RESP_GET_BRK_LEN          1UL   // Length of response from USART Server to GET BRK command
83 #define RESP_GET_MDM_LEN          1UL   // Length of response from USART Server to GET MDM command
84
85 #define OP_SEND                   0UL   // Send operation
86 #define OP_RECEIVE                1UL   // Receive operation
87 #define OP_TRANSFER               2UL   // Transfer operation (in synchronous mode only)
88 #define OP_RECEIVE_SEND_LB        3UL   // Loopback testing Receive and Send operation (in asynchronous mode only)
89 #define OP_ABORT_SEND             4UL   // Abort send operation
90 #define OP_ABORT_RECEIVE          5UL   // Abort receive operation
91 #define OP_ABORT_TRANSFER         6UL   // Abort transfer operation
92
93 #define MODE_ASYNCHRONOUS         1UL   // UART (Asynchronous)
94 #define MODE_SYNCHRONOUS_MASTER   2UL   // Synchronous Master (generates clock signal)
95 #define MODE_SYNCHRONOUS_SLAVE    3UL   // Synchronous Slave (external clock signal)
96 #define MODE_SINGLE_WIRE          4UL   // UART Single-wire (half-duplex)
97 #define MODE_IRDA                 5UL   // UART IrDA
98 #define MODE_SMART_CARD           6UL   // UART Smart Card
99 #define PARITY_NONE               0UL   // No parity
100 #define PARITY_EVEN               1UL   // Even Parity
101 #define PARITY_ODD                2UL   // Odd Parity
102 #define STOP_BITS_1               0UL   // 1 Stop bit
103 #define STOP_BITS_2               1UL   // 2 Stop bits
104 #define STOP_BITS_1_5             2UL   // 1.5 Stop bits
105 #define STOP_BITS_0_5             3UL   // 0.5 Stop bits
106 #define FLOW_CONTROL_NONE         0UL   // No flow control signal
107 #define FLOW_CONTROL_RTS          1UL   // RTS flow control signal
108 #define FLOW_CONTROL_CTS          2UL   // CTS flow control signal
109 #define FLOW_CONTROL_RTS_CTS      3UL   // RTS and CTS flow control signal
110 #define CPOL0                     0UL   // Clock Polarity 0
111 #define CPOL1                     1UL   // Clock Polarity 1
112 #define CPHA0                     0UL   // Clock Phase 0
113 #define CPHA1                     1UL   // Clock Phase 1
114 #define RTS_AVAILABLE             1UL   // Mask of RTS line available
115 #define CTS_AVAILABLE             2UL   // Mask of CTS line available
116 #define DTR_AVAILABLE             4UL   // Mask of DTR line available
117 #define DSR_AVAILABLE             8UL   // Mask of DSR line available
118 #define DCD_AVAILABLE             16UL  // Mask of DCD line available
119 #define RI_AVAILABLE              32UL  // Mask of RI  line available
120 #define RTS_ON                    1UL   // Set RTS to active state
121 #define DTR_ON                    2UL   // Set DTR to active state
122 #define TO_DCD_ON                 4UL   // Set line driving DCD on USART Client to active state
123 #define TO_RI_ON                  8UL   // Set line driving RI  on USART Client to active state
124
125
126 #define DRIVER_DATA_BITS(x)       ((x == 9U) ? ARM_USART_DATA_BITS_9 : ((x == 8U) ? ARM_USART_DATA_BITS_8 : (((x) << ARM_USART_DATA_BITS_Pos) & ARM_USART_DATA_BITS_Msk)))
127
128 // Testing Configuration definitions
129 #if    (USART_CFG_TEST_MODE != 0)
130 #define USART_SERVER_USED               1
131 #else
132 #define USART_SERVER_USED               0
133 #endif
134
135 // Prepare values for default setting
136 #define USART_CFG_DEF_MODE_VAL        ((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk)
137 #if    (USART_CFG_DEF_DATA_BITS == 5U)
138 #define USART_CFG_DEF_DATA_BITS_VAL    (ARM_USART_DATA_BITS_5)
139 #elif  (USART_CFG_DEF_DATA_BITS == 6U)
140 #define USART_CFG_DEF_DATA_BITS_VAL    (ARM_USART_DATA_BITS_6)
141 #elif  (USART_CFG_DEF_DATA_BITS == 7U)
142 #define USART_CFG_DEF_DATA_BITS_VAL    (ARM_USART_DATA_BITS_7)
143 #elif  (USART_CFG_DEF_DATA_BITS == 8U)
144 #define USART_CFG_DEF_DATA_BITS_VAL    (ARM_USART_DATA_BITS_8)
145 #elif  (USART_CFG_DEF_DATA_BITS == 9U)
146 #define USART_CFG_DEF_DATA_VAL         (ARM_USART_DATA_BITS_9)
147 #endif
148 #define USART_CFG_DEF_PARITY_VAL      ((USART_CFG_DEF_PARITY    << ARM_USART_PARITY_Pos)    & ARM_USART_PARITY_Msk)
149 #define USART_CFG_DEF_STOP_BITS_VAL   ((USART_CFG_DEF_STOP_BITS << ARM_USART_STOP_BITS_Pos) & ARM_USART_STOP_BITS_Msk)
150 #define USART_CFG_DEF_FLOW_CONTROL_VAL ((USART_CFG_DEF_FLOW_CONTROL << ARM_USART_FLOW_CONTROL_Pos) & ARM_USART_FLOW_CONTROL_Msk)
151 #define USART_CFG_DEF_CPOL_VAL        ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos) & ARM_USART_CPOL_Msk)
152 #define USART_CFG_DEF_CPHA_VAL        ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos) & ARM_USART_CPHA_Msk)
153
154 // Check if timeout setting is valid
155 #if    (USART_CFG_XFER_TIMEOUT <= 2U)
156 #error  Transfer timeout must be longer than 2ms!
157 #endif
158
159 // Check if default number of items setting is valid
160 #if    (USART_CFG_DEF_NUM == 0)
161 #error  Default number of items to test must not be 0!
162 #endif
163
164 // Determine maximum number of items used for testing
165 #define USART_NUM_MAX                   USART_CFG_DEF_NUM
166 #if    (USART_CFG_NUM1 > USART_NUM_MAX)
167 #undef  USART_NUM_MAX
168 #define USART_NUM_MAX                   USART_CFG_NUM1
169 #endif
170 #if    (USART_CFG_NUM2 > USART_NUM_MAX)
171 #undef  USART_NUM_MAX
172 #define USART_NUM_MAX                   USART_CFG_NUM2
173 #endif
174 #if    (USART_CFG_NUM3 > USART_NUM_MAX)
175 #undef  USART_NUM_MAX
176 #define USART_NUM_MAX                   USART_CFG_NUM3
177 #endif
178 #if    (USART_CFG_NUM4 > USART_NUM_MAX)
179 #undef  USART_NUM_MAX
180 #define USART_NUM_MAX                   USART_CFG_NUM4
181 #endif
182 #if    (USART_CFG_NUM5 > USART_NUM_MAX)
183 #undef  USART_NUM_MAX
184 #define USART_NUM_MAX                   USART_CFG_NUM5
185 #endif
186
187 // Calculate maximum required buffer size
188 #if    (USART_CFG_DEF_DATA_BITS > 8)
189 #define USART_BUF_MAX                  (USART_NUM_MAX * 2U)
190 #else
191 #define USART_BUF_MAX                  (USART_NUM_MAX)
192 #endif
193
194 typedef struct {                // USART Server version structure
195   uint8_t  major;               // Version major number
196   uint8_t  minor;               // Version minor number
197   uint16_t patch;               // Version patch (revision) number
198 } USART_SERV_VER_t;
199
200 typedef struct {                // USART Server capabilities structure
201   uint32_t mode_mask;           // Mode mask
202   uint32_t db_mask;             // Data Bits mask
203   uint32_t parity_mask;         // Parity mask
204   uint32_t sb_mask;             // Stop Bits mask
205   uint32_t fc_mask;             // Flow Control mask
206   uint32_t ml_mask;             // Modem lines mask
207   uint32_t br_min;              // Min baudrate
208   uint32_t br_max;              // Max baudrate
209 } USART_SERV_CAP_t;
210
211 // Register Driver_USART#
212 #define _ARM_Driver_USART_(n)         Driver_USART##n
213 #define  ARM_Driver_USART_(n)    _ARM_Driver_USART_(n)
214 extern   ARM_DRIVER_USART         ARM_Driver_USART_(DRV_USART);
215 static   ARM_DRIVER_USART *drv = &ARM_Driver_USART_(DRV_USART);
216
217 // Local variables (used in this module only)
218 static int8_t                   buffers_ok;
219 static int8_t                   driver_ok;
220 static int8_t                   server_ok;
221
222 static USART_SERV_VER_t         usart_serv_ver;
223 static USART_SERV_CAP_t         usart_serv_cap;
224
225 static ARM_USART_CAPABILITIES   drv_cap;
226 static volatile uint32_t        event;
227 static volatile uint32_t        duration;
228 static volatile uint32_t        xfer_count;
229 static volatile uint32_t        tx_count_sample, rx_count_sample;
230 static volatile uint8_t         modem_status;
231 static volatile uint8_t         break_status;
232 static uint32_t                 systick_freq;
233 static uint32_t                 ticks_per_ms;
234
235 static osEventFlagsId_t         event_flags;
236
237 static char                     msg_buf[512];
238
239 // Allocated buffer pointers
240 static void                    *ptr_tx_buf_alloc;
241 static void                    *ptr_rx_buf_alloc;
242 static void                    *ptr_cmp_buf_alloc;
243
244 // Buffer pointers used for data transfers (must be aligned to 4 byte)
245 static uint8_t                 *ptr_tx_buf;
246 static uint8_t                 *ptr_rx_buf;
247 static uint8_t                 *ptr_cmp_buf;
248
249 // String representation of various codes
250 static const char *str_srv_status[] = {
251   "Ok",
252   "Failed"
253 };
254
255 static const char *str_test_mode[] = {
256   "Loopback",
257   "USART Server"
258 };
259
260 static const char *str_oper[] = {
261   "Send    ",
262   "Receive ",
263   "Transfer",
264   "Receive/Send LB",
265   "Abort Send    ",
266   "Abort Receive ",
267   "Abort Transfer"
268 };
269
270 static const char *str_mode[] = {
271   "None",
272   "Asynchronous",
273   "Synchronous Master",
274   "Synchronous Slave",
275   "Single-wire",
276   "IrDA",
277   "Smart Card"
278 };
279
280 static const char *str_parity[] = {
281   "None",
282   "Even",
283   "Odd"
284 };
285
286 static const char *str_stop_bits[] = {
287   "1",
288   "2",
289   "1.5",
290   "0.5"
291 };
292
293 static const char *str_flow_control[] = {
294   "None",
295   "CTS",
296   "RTS",
297   "RTS/CTS",
298 };
299
300 static const char *str_cpol[] = {
301   "CPOL0",
302   "CPOL1"
303 };
304
305 static const char *str_cpha[] = {
306   "CPHA0",
307   "CPHA1"
308 };
309
310 static const char *str_modem_line[] = {
311   "RTS",
312   "CTS",
313   "DTR",
314   "DSR",
315   "DCD",
316   "RI"
317 };
318
319 static const char *str_ret[] = {
320   "ARM_DRIVER_OK",
321   "ARM_DRIVER_ERROR",
322   "ARM_DRIVER_ERROR_BUSY",
323   "ARM_DRIVER_ERROR_TIMEOUT",
324   "ARM_DRIVER_ERROR_UNSUPPORTED",
325   "ARM_DRIVER_ERROR_PARAMETER",
326   "ARM_DRIVER_ERROR_SPECIFIC",
327   "ARM_USART_ERROR_MODE",
328   "ARM_USART_ERROR_BAUDRATE",
329   "ARM_USART_ERROR_DATA_BITS",
330   "ARM_USART_ERROR_PARITY",
331   "ARM_USART_ERROR_STOP_BITS",
332   "ARM_USART_ERROR_FLOW_CONTROL",
333   "ARM_USART_ERROR_CPOL",
334   "ARM_USART_ERROR_CPHA"
335 };
336
337 // Local functions
338 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
339 static int32_t  ComConfigDefault       (void);
340 static int32_t  ComSendCommand         (const void *data_out, uint32_t len);
341 static int32_t  ComReceiveResponse     (      void *data_in,  uint32_t len);
342
343 static int32_t  CmdGetVer              (void);
344 static int32_t  CmdGetCap              (void);
345 static int32_t  CmdSetBufTx            (char pattern);
346 static int32_t  CmdSetBufRx            (char pattern);
347 static int32_t  CmdGetBufRx            (uint32_t len);
348 static int32_t  CmdSetCom              (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate);
349 static int32_t  CmdXfer                (uint32_t dir,  uint32_t num,       uint32_t delay,  uint32_t timeout,   uint32_t num_cts);
350 static int32_t  CmdGetCnt              (void);
351 static int32_t  CmdSetBrk              (uint32_t delay, uint32_t duration);
352 static int32_t  CmdGetBrk              (void);
353 static int32_t  CmdSetMdm              (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration);
354 static int32_t  CmdGetMdm              (void);
355
356 static int32_t  ServerInit             (void);
357 static int32_t  ServerCheck            (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t modem_line, uint32_t baudrate);
358 #endif
359
360 static int32_t  IsNotLoopback          (void);
361 static int32_t  IsNotSync              (void);
362 static int32_t  IsNotAsync             (void);
363 static int32_t  IsNotSingleWire        (void);
364
365 static uint32_t DataBitsToBytes        (uint32_t data_bits);
366 static int32_t  DriverInit             (void);
367 static int32_t  BuffersCheck           (void);
368 static int32_t  DriverCheck            (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask);
369
370 static void USART_DataExchange_Operation (uint32_t operation, uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate, uint32_t num);
371
372 // Helper functions
373
374 /*
375   \fn            void USART_DrvEvent (uint32_t evt)
376   \brief         Store event(s) into a global variable.
377   \detail        This is a callback function called by the driver upon an event(s).
378   \param[in]     evt            USART event
379   \return        none
380 */
381 static void USART_DrvEvent (uint32_t evt) {
382   event |= evt;
383
384   (void)osEventFlagsSet(event_flags, evt);
385 }
386
387 /*
388   \fn            static uint32_t DataBitsToBytes (uint32_t data_bits)
389   \brief         Calculate number of bytes used for an item at required data bits.
390   \return        number of bytes per item
391 */
392 static uint32_t DataBitsToBytes (uint32_t data_bits) {
393   uint32_t ret;
394
395   ret = 1U;
396   if (data_bits > 8U) {
397     ret = 2U;
398   }
399
400   return ret;
401 }
402
403 /*
404   \fn            static int32_t DriverInit (void)
405   \brief         Initialize and power-on the driver.
406   \return        execution status
407                    - EXIT_SUCCESS: Driver initialized and powered-up successfully
408                    - EXIT_FAILURE: Driver initialization or power-up failed
409 */
410 static int32_t DriverInit (void) {
411
412   if (drv->Initialize    (USART_DrvEvent) == ARM_DRIVER_OK) {
413     if (drv->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK) {
414       return EXIT_SUCCESS;
415     }
416   }
417
418   TEST_FAIL_MESSAGE("[FAILED] USART driver initialize or power-up. Check driver Initialize and PowerControl functions! Test aborted!");
419
420   return EXIT_FAILURE;
421 }
422
423 /*
424   \fn            static int32_t IsNotLoopback (void)
425   \brief         Check if loopback is not selected.
426   \detail        This function is used to skip executing a test if it is not supported 
427                  in Loopback mode.
428   \return        execution status
429                    - EXIT_SUCCESS: Loopback is not selected
430                    - EXIT_FAILURE: Loopback is selected
431 */
432 static int32_t IsNotLoopback (void) {
433
434 #if (USART_SERVER_USED == 1)
435   return EXIT_SUCCESS;
436 #else
437   TEST_MESSAGE("[WARNING] Test not supported in Loopback Test Mode! Test not executed!");
438   return EXIT_FAILURE;
439 #endif
440 }
441
442 /*
443   \fn            static int32_t IsNotSync (void)
444   \brief         Check if Synchronous Slave/Master mode is not selected as default mode.
445   \detail        This function is used to skip executing a test if it is not supported 
446                  in Synchronous mode.
447   \return        execution status
448                    - EXIT_SUCCESS: Synchronous mode is not selected
449                    - EXIT_FAILURE: Synchronous mode is selected
450 */
451 static int32_t IsNotSync (void) {
452
453 #if ((USART_CFG_DEF_MODE != MODE_SYNCHRONOUS_MASTER) && (USART_CFG_DEF_MODE != MODE_SYNCHRONOUS_SLAVE))
454   return EXIT_SUCCESS;
455 #else
456   TEST_MESSAGE("[WARNING] Test not supported for Synchronous Mode! Test not executed!");
457   return EXIT_FAILURE;
458 #endif
459 }
460
461 /*
462   \fn            static int32_t IsNotAsync (void)
463   \brief         Check if Asynchronous/Single-wire/IrDA modes are not selected as default mode.
464   \detail        This function is used to skip executing a test if it is not supported 
465                  in Asynchronous/Single-wire/IrDA mode.
466   \return        execution status
467                    - EXIT_SUCCESS: Asynchronous/Single-wire/IrDA mode is not selected
468                    - EXIT_FAILURE: Asynchronous/Single-wire/IrDA mode is selected
469 */
470 static int32_t IsNotAsync (void) {
471
472 #if ((USART_CFG_DEF_MODE != MODE_ASYNCHRONOUS) && (USART_CFG_DEF_MODE != MODE_SINGLE_WIRE) && (USART_CFG_DEF_MODE != MODE_IRDA))
473   return EXIT_SUCCESS;
474 #else
475   TEST_MESSAGE("[WARNING] Test not supported for Asynchronous/Single-wire/IrDA Mode! Test not executed!");
476   return EXIT_FAILURE;
477 #endif
478 }
479
480 /*
481   \fn            static int32_t IsNotSingleWire (void)
482   \brief         Check if Single-wire mode is not selected as default mode.
483   \detail        This function is used to skip executing a test if it is not supported 
484                  in Single-wire mode.
485   \return        execution status
486                    - EXIT_SUCCESS: Single-wire mode is not selected
487                    - EXIT_FAILURE: Single-wire mode is selected
488 */
489 static int32_t IsNotSingleWire (void) {
490
491 #if (USART_CFG_DEF_MODE != MODE_SINGLE_WIRE)
492   return EXIT_SUCCESS;
493 #else
494   TEST_MESSAGE("[WARNING] Test not supported for Single-wire Mode! Test not executed!");
495   return EXIT_FAILURE;
496 #endif
497 }
498
499 /*
500   \fn            static int32_t BuffersCheck (void)
501   \brief         Check if buffers are valid.
502   \return        execution status
503                    - EXIT_SUCCESS: Buffers are valid
504                    - EXIT_FAILURE: Buffers are not valid
505 */
506 static int32_t BuffersCheck (void) {
507
508   if ((ptr_tx_buf  != NULL) &&
509       (ptr_rx_buf  != NULL) && 
510       (ptr_cmp_buf != NULL)) {
511     return EXIT_SUCCESS;
512   }
513
514   TEST_FAIL_MESSAGE("[FAILED] Invalid data buffers! Increase heap memory! Test aborted!");
515
516   return EXIT_FAILURE;
517 }
518
519 /*
520   \fn            static int32_t DriverCheck (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask, uint32_t baudrate)
521   \brief         Check if USART Driver supports desired settings.
522   \param[in]     mode           mode:
523                                   - value 1 = Asynchronous
524                                   - value 2 = Synchronous Master
525                                   - value 3 = Synchronous Slave
526                                   - value 4 = Single Wire
527                                   - value 5 = IrDA
528                                   - value 6 = Smart Card
529   \param[in]     flow_control   flow control:
530                                   - value 0 = None
531                                   - value 1 = CTS
532                                   - value 2 = RTS
533                                   - value 3 = RTS/CTS
534   \param[in]     modem_line_mask  modem line mask:
535                                   - bit 0. = RTS
536                                   - bit 1. = CTS
537                                   - bit 2. = DTR
538                                   - bit 3. = DSR
539                                   - bit 4. = DCD
540                                   - bit 5. = RI
541   \return        execution status
542                    - EXIT_SUCCESS: USART Driver supports desired settings
543                    - EXIT_FAILURE: USART Driver does not support desired settings
544 */
545 static int32_t DriverCheck (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask) {
546   int32_t ret;
547
548   ret = EXIT_SUCCESS;
549
550   switch (mode) {
551     case 1:                             // Asynchronous
552       if (drv_cap.asynchronous == 0U) {
553         ret = EXIT_FAILURE;
554       }
555       break;
556     case 2:                             // Synchronous master
557       if (drv_cap.synchronous_master == 0U) {
558         ret = EXIT_FAILURE;
559       }
560       break;
561     case 3:                             // Synchronous slave
562       if (drv_cap.synchronous_slave == 0U) {
563         ret = EXIT_FAILURE;
564       }
565       break;
566     case 4:                             // Single-wire
567       if (drv_cap.single_wire == 0U) {
568         ret = EXIT_FAILURE;
569       }
570       break;
571     case 5:                             // IrDA
572       if (drv_cap.irda == 0U) {
573         ret = EXIT_FAILURE;
574       }
575       break;
576     case 6:                             // Samrt Card
577       if (drv_cap.irda == 0U) {
578         ret = EXIT_FAILURE;
579       }
580       break;
581     default:
582       ret = EXIT_FAILURE;
583       break;
584   }
585
586   if (ret != EXIT_SUCCESS) {
587     // If USART Driver does not support desired mode
588     if (mode <= 6U) {
589       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support %s mode! Test aborted!", str_mode[mode]);
590     } else {
591       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support unknown mode! Test aborted!");
592     }
593     TEST_MESSAGE(msg_buf);
594     return EXIT_FAILURE;
595   }
596
597   switch (flow_control) {
598     case 0:                             // None
599       break;
600     case 1:                             // CTS
601       if (drv_cap.flow_control_cts == 0U) {
602         ret = EXIT_FAILURE;
603       }
604       break;
605     case 2:                             // RTS
606       if (drv_cap.flow_control_rts == 0U) {
607         ret = EXIT_FAILURE;
608       }
609       break;
610     case 3:                             // RTS/CTS
611       if ((drv_cap.flow_control_cts == 0U) || (drv_cap.flow_control_rts == 0U)) {
612         ret = EXIT_FAILURE;
613       }
614       break;
615     default:
616       ret = EXIT_FAILURE;
617       break;
618   }
619
620   if (ret != EXIT_SUCCESS) {
621     // If USART Driver does not support desired flow control
622     if (mode <= 3U) {
623       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support %s flow control! Test aborted!", str_flow_control[flow_control]);
624     } else {
625       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support unknown flow control! Test aborted!");
626     }
627     TEST_MESSAGE(msg_buf);
628     return EXIT_FAILURE;
629   }
630
631   if ((modem_line_mask & 1U) != 0U) {
632     if (drv_cap.rts == 0U) {
633       TEST_MESSAGE("[FAILED] USART Driver does not support RTS modem line! Test aborted!");
634       return EXIT_FAILURE;
635     }
636   }
637   if ((modem_line_mask & (1U << 1)) != 0U) {
638     if (drv_cap.cts == 0U) {
639       TEST_MESSAGE("[FAILED] USART Driver does not support CTS modem line! Test aborted!");
640       return EXIT_FAILURE;
641     }
642   }
643   if ((modem_line_mask & (1U << 2)) != 0U) {
644     if (drv_cap.dtr == 0U) {
645       TEST_MESSAGE("[FAILED] USART Driver does not support DTR modem line! Test aborted!");
646       return EXIT_FAILURE;
647     }
648   }
649   if ((modem_line_mask & (1U << 3)) != 0U) {
650     if (drv_cap.dsr == 0U) {
651       TEST_MESSAGE("[FAILED] USART Driver does not support DSR modem line! Test aborted!");
652       return EXIT_FAILURE;
653     }
654   }
655   if ((modem_line_mask & (1U << 4)) != 0U) {
656     if (drv_cap.dcd == 0U) {
657       TEST_MESSAGE("[FAILED] USART Driver does not support DCD modem line! Test aborted!");
658       return EXIT_FAILURE;
659     }
660   }
661   if ((modem_line_mask & (1U << 5)) != 0U) {
662     if (drv_cap.ri == 0U) {
663       TEST_MESSAGE("[FAILED] USART Driver does not support RI modem line! Test aborted!");
664       return EXIT_FAILURE;
665     }
666   }
667
668   return ret;
669 }
670
671 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
672
673 /*
674   \fn            static int32_t ComConfigDefault (void)
675   \brief         Configure USART Communication Interface to USART Server default communication configuration.
676   \return        execution status
677                    - EXIT_SUCCESS: Default configuration set successfully
678                    - EXIT_FAILURE: Default configuration failed
679 */
680 static int32_t ComConfigDefault (void) {
681   int32_t ret;
682
683   ret = EXIT_SUCCESS;
684
685   if (drv->Control(((USART_CFG_SRV_MODE         << ARM_USART_CONTROL_Pos)      & ARM_USART_CONTROL_Msk)      |
686                      DRIVER_DATA_BITS(USART_CFG_SRV_DATA_BITS)                                               |
687                    ((USART_CFG_SRV_PARITY       << ARM_USART_PARITY_Pos)       & ARM_USART_PARITY_Msk)       |
688                    ((USART_CFG_SRV_STOP_BITS    << ARM_USART_STOP_BITS_Pos)    & ARM_USART_STOP_BITS_Msk)    |
689                    ((USART_CFG_SRV_FLOW_CONTROL << ARM_USART_FLOW_CONTROL_Pos) & ARM_USART_FLOW_CONTROL_Msk) ,
690                      USART_CFG_SRV_BAUDRATE) != ARM_DRIVER_OK) {
691     ret = EXIT_FAILURE;
692   }
693     if (drv->Control(ARM_USART_CONTROL_TX, 1U) != ARM_DRIVER_OK) {
694       ret = EXIT_FAILURE;
695     }
696
697   if (ret != EXIT_SUCCESS) {
698     TEST_FAIL_MESSAGE("[FAILED] Configure communication interface to USART Server default settings. Check driver Control function! Test aborted!");
699   }
700
701   return ret;
702 }
703
704 /**
705   \fn            static int32_t ComSendCommand (const void *data_out, uint32_t num)
706   \brief         Send command to USART Server.
707   \param[out]    data_out       Pointer to memory containing data to be sent
708   \param[in]     len            Number of bytes to be sent
709   \return        execution status
710                    - EXIT_SUCCESS: Command sent successfully
711                    - EXIT_FAILURE: Command send failed
712 */
713 static int32_t ComSendCommand (const void *data_out, uint32_t len) {
714    int32_t ret;
715   uint32_t flags, num, tout;
716
717   ret = EXIT_SUCCESS;
718   num = (len + DataBitsToBytes(USART_CFG_SRV_DATA_BITS) - 1U) / DataBitsToBytes(USART_CFG_SRV_DATA_BITS);
719
720   ret = ComConfigDefault();
721
722   if (ret == EXIT_SUCCESS) {
723     (void)osEventFlagsClear(event_flags, 0x7FFFFFFFU);  
724     if (drv->Control(ARM_USART_CONTROL_TX, 1U) != ARM_DRIVER_OK) {
725       ret = EXIT_FAILURE;
726     }
727     if (ret == EXIT_SUCCESS) {
728       if (drv->Send(data_out, num) != ARM_DRIVER_OK) {
729         ret = EXIT_FAILURE;
730       }
731       if (ret == EXIT_SUCCESS) {
732         if (drv_cap.event_tx_complete != 0U) {
733           // If ARM_USART_EVENT_TX_COMPLETE is supported, wait for it
734           flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_TX_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
735           if (((flags & 0x80000000U) != 0U) ||
736               ((flags & ARM_USART_EVENT_TX_COMPLETE) == 0U)) {
737             ret = EXIT_FAILURE;
738           }
739         } else {
740           // Otherwise wait for ARM_USART_EVENT_SEND_COMPLETE flag
741           flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_SEND_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
742           if (((flags & 0x80000000U) != 0U) ||
743               ((flags & ARM_USART_EVENT_SEND_COMPLETE) == 0U)) {
744             ret = EXIT_FAILURE;
745           }
746
747           if (ret == EXIT_SUCCESS) {
748             // If completed event was signaled, wait for all data to be sent
749             for (tout = USART_CFG_SRV_CMD_TOUT; tout != 0U; tout--) {
750               if ((drv->GetTxCount() == len) && (drv->GetStatus().tx_busy == 0U)) { 
751                 break;
752               }
753               (void)osDelay(1U);
754             }
755           }
756         }
757       }
758       if (ret == EXIT_FAILURE) {
759         (void)drv->Control(ARM_USART_ABORT_SEND, 0U);
760       }
761     }
762   }
763   (void)drv->Control(ARM_USART_CONTROL_TX, 0U);
764
765   return ret;
766 }
767
768 /**
769   \fn            static int32_t ComReceiveResponse (void *data_in, uint32_t num)
770   \brief         Receive response from USART Server.
771   \param[out]    data_in     Pointer to memory where data will be received
772   \param[in]     len         Number of data bytes to be received
773   \return        execution status
774                    - EXIT_SUCCESS: Command received successfully
775                    - EXIT_FAILURE: Command reception failed
776 */
777 static int32_t ComReceiveResponse (void *data_in, uint32_t len) {
778    int32_t ret;
779   uint32_t flags, num, tout;
780
781   ret = EXIT_SUCCESS;
782   num = (len + DataBitsToBytes(USART_CFG_SRV_DATA_BITS) - 1U) / DataBitsToBytes(USART_CFG_SRV_DATA_BITS);
783
784   ret = ComConfigDefault();
785
786   if (ret == EXIT_SUCCESS) {
787     (void)osEventFlagsClear(event_flags, 0x7FFFFFFFU);  
788     if (drv->Control(ARM_USART_CONTROL_RX, 1U) != ARM_DRIVER_OK) {
789       ret = EXIT_FAILURE;
790     }
791     if (ret == EXIT_SUCCESS) {
792       if (drv->Receive(data_in, num) != ARM_DRIVER_OK) {
793         ret = EXIT_FAILURE;
794       }
795       if (ret == EXIT_SUCCESS) {
796         flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_RECEIVE_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
797         if (((flags & 0x80000000U) != 0U) ||
798             ((flags & ARM_USART_EVENT_RECEIVE_COMPLETE) == 0U)) {
799           ret = EXIT_FAILURE;
800         }
801       }
802       if (ret == EXIT_FAILURE) {
803         drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
804       }
805     }
806   }
807   (void)drv->Control(ARM_USART_CONTROL_RX, 0U);
808
809   return ret;
810 }
811
812 /**
813   \fn            static int32_t CmdGetVer (void)
814   \brief         Get version from USART Server and check that it is valid.
815   \return        execution status
816                    - EXIT_SUCCESS: Version retrieved successfully
817                    - EXIT_FAILURE: Version retreival failed
818 */
819 static int32_t CmdGetVer (void) {
820   int32_t     ret;
821   const char *ptr_str;
822   uint16_t    val16;
823   uint8_t     val8;
824
825   ptr_str = NULL;
826
827   memset(&usart_serv_ver, 0, sizeof(usart_serv_ver));
828
829   // Send "GET VER" command to USART Server
830   memset(ptr_tx_buf, 0, CMD_LEN);
831   memcpy(ptr_tx_buf, "GET VER", 7);
832   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
833
834   if (ret == EXIT_SUCCESS) {
835     // Receive response to "GET VER" command from USART Server
836     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_VER_LEN);
837     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_VER_LEN);
838     (void)osDelay(10U);
839   }
840
841   // Parse version
842   if (ret == EXIT_SUCCESS) {
843     // Parse major
844     ptr_str = (const char *)ptr_rx_buf;
845     if (sscanf(ptr_str, "%hhx", &val8) == 1) {
846       usart_serv_ver.major = val8;
847     } else {
848       ret = EXIT_FAILURE;
849     }
850   }
851   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
852     // Parse minor
853     ptr_str = strstr(ptr_str, ".");     // Find '.'
854     if (ptr_str != NULL) {
855       ptr_str++;                        // Skip '.'
856       if (sscanf(ptr_str, "%hhx", &val8) == 1) {
857         usart_serv_ver.minor = val8;
858       } else {
859         ret = EXIT_FAILURE;
860       }
861     } else {
862       ret = EXIT_FAILURE;
863     }
864   }
865   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
866     // Parse patch (revision)
867     ptr_str = strstr(ptr_str, ".");     // Find next '.'
868     if (ptr_str != NULL) {
869       ptr_str++;                        // Skip '.'
870       if (sscanf(ptr_str, "%hx", &val16) == 1) {
871         usart_serv_ver.patch = val16;
872       } else {
873         ret = EXIT_FAILURE;
874       }
875     } else {
876       ret = EXIT_FAILURE;
877     }
878   }
879
880   return ret;
881 }
882
883 /**
884   \fn            static int32_t CmdGetCap (void)
885   \brief         Get capabilities from USART Server.
886   \return        execution status
887                    - EXIT_SUCCESS: Capabilities retrieved successfully
888                    - EXIT_FAILURE: Capabilities retreival failed
889 */
890 static int32_t CmdGetCap (void) {
891   int32_t     ret;
892   const char *ptr_str;
893   uint32_t    val32;
894   uint8_t     val8;
895
896   ptr_str = NULL;
897
898   memset(&usart_serv_cap, 0, sizeof(usart_serv_cap));
899
900   // Send "GET CAP" command to USART Server
901   memset(ptr_tx_buf, 0, CMD_LEN);
902   memcpy(ptr_tx_buf, "GET CAP", 7);
903   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
904
905   if (ret == EXIT_SUCCESS) {
906     (void)osDelay(20U);                 // Give USART Server 20 ms to auto-detect capabilities
907
908     // Receive response to "GET CAP" command from USART Server
909     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_CAP_LEN);
910     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_CAP_LEN);
911     (void)osDelay(10U);
912   }
913
914   // Parse capabilities
915   if (ret == EXIT_SUCCESS) {
916     // Parse mode mask
917     ptr_str = (const char *)ptr_rx_buf;
918     if (sscanf(ptr_str, "%hhx", &val8) == 1) {
919       usart_serv_cap.mode_mask = val8;
920     } else {
921       ret = EXIT_FAILURE;
922     }
923   }
924   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
925     // Parse data bit mask
926     ptr_str = strstr(ptr_str, ",");     // Find ','
927     if (ptr_str != NULL) {
928       ptr_str++;                        // Skip ','
929       if (sscanf(ptr_str, "%x", &val32) == 1) {
930         usart_serv_cap.db_mask = val32;
931       } else {
932         ret = EXIT_FAILURE;
933       }
934     } else {
935       ret = EXIT_FAILURE;
936     }
937   }
938   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
939     // Parse parity mask
940     ptr_str = strstr(ptr_str, ",");     // Find next ','
941     if (ptr_str != NULL) {
942       ptr_str++;                        // Skip ','
943       if (sscanf(ptr_str, "%x", &val32) == 1) {
944         usart_serv_cap.parity_mask = val32;
945       } else {
946         ret = EXIT_FAILURE;
947       }
948     } else {
949       ret = EXIT_FAILURE;
950     }
951   }
952   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
953     // Parse stop bit mask
954     ptr_str = strstr(ptr_str, ",");     // Find next ','
955     if (ptr_str != NULL) {
956       ptr_str++;                        // Skip ','
957       if (sscanf(ptr_str, "%x", &val32) == 1) {
958         usart_serv_cap.sb_mask = val32;
959       } else {
960         ret = EXIT_FAILURE;
961       }
962     } else {
963       ret = EXIT_FAILURE;
964     }
965   }
966   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
967     // Parse flow control mask
968     ptr_str = strstr(ptr_str, ",");     // Find next ','
969     if (ptr_str != NULL) {
970       ptr_str++;                        // Skip ','
971       if (sscanf(ptr_str, "%x", &val32) == 1) {
972         usart_serv_cap.fc_mask = val32;
973       } else {
974         ret = EXIT_FAILURE;
975       }
976     } else {
977       ret = EXIT_FAILURE;
978     }
979   }
980   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
981     // Parse modem lines mask
982     ptr_str = strstr(ptr_str, ",");     // Find next ','
983     if (ptr_str != NULL) {
984       ptr_str++;                        // Skip ','
985       if (sscanf(ptr_str, "%x", &val32) == 1) {
986         usart_serv_cap.ml_mask = val32;
987       } else {
988         ret = EXIT_FAILURE;
989       }
990     } else {
991       ret = EXIT_FAILURE;
992     }
993   }
994   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
995     // Parse minimum baudrate
996     ptr_str = strstr(ptr_str, ",");     // Find next ','
997     if (ptr_str != NULL) {
998       ptr_str++;                        // Skip ','
999       if (sscanf(ptr_str, "%u", &val32) == 1) {
1000         usart_serv_cap.br_min = val32;
1001       } else {
1002         ret = EXIT_FAILURE;
1003       }
1004     } else {
1005       ret = EXIT_FAILURE;
1006     }
1007   }
1008   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
1009     // Parse maximum baudrate
1010     ptr_str = strstr(ptr_str, ",");     // Find next ','
1011     if (ptr_str != NULL) {
1012       ptr_str++;                        // Skip ','
1013       if (sscanf(ptr_str, "%u", &val32) == 1) {
1014         usart_serv_cap.br_max = val32;
1015       } else {
1016         ret = EXIT_FAILURE;
1017       }
1018     } else {
1019       ret = EXIT_FAILURE;
1020     }
1021   }
1022
1023   return ret;
1024 }
1025
1026 /**
1027   \fn            static int32_t CmdSetBufTx (char pattern)
1028   \brief         Set Tx buffer of USART Server to pattern.
1029   \param[in]     pattern        Pattern to fill the buffer with
1030   \return        execution status
1031                    - EXIT_SUCCESS: Command sent successfully
1032                    - EXIT_FAILURE: Command send failed
1033 */
1034 static int32_t CmdSetBufTx (char pattern) {
1035   int32_t ret;
1036
1037   // Send "SET BUF TX" command to USART Server
1038   memset(ptr_tx_buf, 0, CMD_LEN);
1039   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BUF TX,0,%02X", (int32_t)pattern);
1040   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1041   (void)osDelay(10U);
1042
1043   if (ret != EXIT_SUCCESS) {
1044     TEST_FAIL_MESSAGE("[FAILED] Set Tx buffer on USART Server. Check USART Server! Test aborted!");
1045   }
1046
1047   return ret;
1048 }
1049
1050 /**
1051   \fn            static int32_t CmdSetBufRx (char pattern)
1052   \brief         Set Rx buffer of USART Server to pattern.
1053   \param[in]     pattern        Pattern to fill the buffer with
1054   \return        execution status
1055                    - EXIT_SUCCESS: Command sent successfully
1056                    - EXIT_FAILURE: Command send failed
1057 */
1058 static int32_t CmdSetBufRx (char pattern) {
1059   int32_t ret;
1060
1061   // Send "SET BUF RX" command to USART Server
1062   memset(ptr_tx_buf, 0, CMD_LEN);
1063   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BUF RX,0,%02X", (int32_t)pattern);
1064   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1065   (void)osDelay(10U);
1066
1067   if (ret != EXIT_SUCCESS) {
1068     TEST_FAIL_MESSAGE("[FAILED] Set Rx buffer on USART Server. Check USART Server! Test aborted!");
1069   }
1070
1071   return ret;
1072 }
1073
1074 /**
1075   \fn            static int32_t CmdGetBufRx (void)
1076   \brief         Get Rx buffer from USART Server (into global array pointed to by ptr_rx_buf).
1077   \param[in]     len            Number of bytes to read from Rx buffer
1078   \return        execution status
1079                    - EXIT_SUCCESS: Command sent and response received successfully
1080                    - EXIT_FAILURE: Command send or response reception failed
1081 */
1082 static int32_t CmdGetBufRx (uint32_t len) {
1083   int32_t ret;
1084
1085   // Send "GET BUF RX" command to USART Server
1086   memset(ptr_tx_buf, 0, CMD_LEN);
1087   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "GET BUF RX,%i", len);
1088   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1089
1090   if (ret == EXIT_SUCCESS) {
1091     // Receive response to "GET BUF RX" command from USART Server
1092     memset(ptr_rx_buf, (int32_t)'?', len);
1093     ret = ComReceiveResponse(ptr_rx_buf, len);
1094     (void)osDelay(10U);
1095   }
1096
1097   if (ret != EXIT_SUCCESS) {
1098     TEST_FAIL_MESSAGE("[FAILED] Get Rx buffer from USART Server. Check USART Server! Test aborted!");
1099   }
1100
1101   return ret;
1102 }
1103
1104 /**
1105   \fn            static int32_t CmdSetCom (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate)
1106   \brief         Set communication parameters on USART Server for next XFER command.
1107   \param[in]     mode           mode:
1108                                   - value 0 = Asynchronous
1109                                   - value 1 = Synchronous Master
1110                                   - value 2 = Synchronous Slave
1111                                   - value 3 = Single Wire
1112                                   - value 4 = IrDA
1113                                   - value 5 = Smart Card
1114   \param[in]     data_bits      data bits:
1115                                   - values 5 to 9
1116   \param[in]     parity         parity:
1117                                   - value 0 = None
1118                                   - value 1 = Even
1119                                   - value 2 = Odd
1120   \param[in]     stop_bits      stop bits:
1121                                   - value 0 = 1 Stop Bit
1122                                   - value 1 = 2 Stop Bits
1123                                   - value 2 = 1.5 Stop Bits
1124                                   - value 3 = 0.5 Stop Bits
1125   \param[in]     flow_control   flow control:
1126                                   - value 0 = None
1127                                   - value 1 = CTS
1128                                   - value 2 = RTS
1129                                   - value 3 = RTS/CTS
1130   \param[in]     cpol           clock polarity:
1131                                   - value 0 = Data are captured on rising edge
1132                                   - value 1 = Data are captured on falling edge
1133   \param[in]     cpha           clock phase:
1134                                   - value 0 = Sample on first (leading) edge
1135                                   - value 1 = Sample on second (trailing) edge
1136   \param[in]     baudrate       baudrate in bauds
1137   \return        execution status
1138                    - EXIT_SUCCESS: Command sent successfully
1139                    - EXIT_FAILURE: Command send failed
1140 */
1141 static int32_t CmdSetCom (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate) {
1142   int32_t ret, stat;
1143
1144   // Send "SET COM" command to USART Server
1145   memset(ptr_tx_buf, 0, CMD_LEN);
1146   stat = snprintf((char *)ptr_tx_buf, CMD_LEN, "SET COM %i,%i,%i,%i,%i,%i,%i,%i", mode, data_bits, parity, stop_bits, flow_control, cpol, cpha, baudrate);
1147   if ((stat > 0) && (stat < CMD_LEN)) {
1148     ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1149     (void)osDelay(10U);
1150   } else {
1151     ret = EXIT_FAILURE;
1152   }
1153
1154   if (ret != EXIT_SUCCESS) {
1155     TEST_FAIL_MESSAGE("[FAILED] Set communication settings on USART Server. Check USART Server! Test aborted!");
1156   }
1157
1158   return ret;
1159 }
1160
1161 /**
1162   \fn            static int32_t CmdXfer (uint32_t dir, uint32_t num, uint32_t delay, uint32_t timeout, uint32_t num_cts)
1163   \brief         Activate transfer on USART Server.
1164   \param[in]     dir            direction of transfer 
1165                                   - 0 = Send (Tx)
1166                                   - 1 = Receive (Rx)
1167                                   - 2 = Transfer (simultaneous Tx and Rx (in synchronous mode only))
1168   \param[in]     num            number of items (according CMSIS USART driver specification)
1169   \param[in]     delay          initial delay, in milliseconds, before starting requested operation 
1170                                 (0xFFFFFFFF = delay not used)
1171   \param[in]     timeout        timeout in milliseconds, after delay, if delay is specified
1172   \param[in]     num_cts        number of items after which CTS line should be de-activated
1173                                   - 0 = no CTS deactivation
1174   \return        execution status
1175                    - EXIT_SUCCESS: Command sent successfully
1176                    - EXIT_FAILURE: Command send failed
1177 */
1178 static int32_t CmdXfer (uint32_t dir, uint32_t num, uint32_t delay, uint32_t timeout, uint32_t num_cts) {
1179   int32_t ret;
1180
1181   // Send "XFER" command to USART Server
1182   memset(ptr_tx_buf, 0, CMD_LEN);
1183   if (num_cts != 0U) {
1184     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i,%i,%i", dir, num, delay, timeout, num_cts);
1185   } else if ((delay != osWaitForever) && (timeout != 0U)) {
1186     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i,%i",    dir, num, delay, timeout);
1187   } else if (delay != osWaitForever) {
1188     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i",       dir, num, delay);
1189   } else {
1190     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i",          dir, num);
1191   }
1192   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1193
1194   if (ret != EXIT_SUCCESS) {
1195     TEST_FAIL_MESSAGE("[FAILED] Activate transfer on USART Server. Check USART Server! Test aborted!");
1196   }
1197
1198   return ret;
1199 }
1200
1201 /*
1202   \fn            static int32_t CmdGetCnt (void)
1203   \brief         Get XFER command Tx/Rx count from USART Server.
1204   \return        execution status
1205                    - EXIT_SUCCESS: Operation successful
1206                    - EXIT_FAILURE: Operation failed
1207 */
1208 static int32_t CmdGetCnt (void) {
1209   int32_t     ret;
1210   const char *ptr_str;
1211   uint32_t    val32;
1212
1213   xfer_count = 0U;
1214
1215   // Send "GET CNT" command to USART Server
1216   memset(ptr_tx_buf, 0, CMD_LEN);
1217   memcpy(ptr_tx_buf, "GET CNT", 7);
1218   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1219
1220   if (ret == EXIT_SUCCESS) {
1221     // Receive response to "GET CNT" command from USART Server
1222     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_CNT_LEN);
1223     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_CNT_LEN);
1224     (void)osDelay(10U);
1225   }
1226
1227   if (ret == EXIT_SUCCESS) {
1228     // Parse count
1229     ptr_str = (const char *)ptr_rx_buf;
1230     if (sscanf(ptr_str, "%i", &val32) == 1) {
1231       xfer_count = val32;
1232     } else {
1233       ret = EXIT_FAILURE;
1234     }
1235   }
1236
1237   if (ret != EXIT_SUCCESS) {
1238     TEST_FAIL_MESSAGE("[FAILED] Get count from USART Server. Check USART Server! Test aborted!");
1239   }
1240
1241   return ret;
1242 }
1243
1244 /*
1245   \fn            static int32_t CmdSetBrk (uint32_t delay, uint32_t duration)
1246   \brief         Request USART Server to send break signal.
1247   \param[in]     delay:         initial delay, in milliseconds, before start of break signaling
1248   \param[in]     duration:      duration, in milliseconds, of break signaling
1249   \return        execution status
1250                    - EXIT_SUCCESS: Command sent successfully
1251                    - EXIT_FAILURE: Command send failed
1252 */
1253 static int32_t CmdSetBrk (uint32_t delay, uint32_t duration) {
1254   int32_t ret;
1255
1256   // Send "SET BRK" command to USART Server
1257   memset(ptr_tx_buf, 0, CMD_LEN);
1258   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BRK %i,%i", delay, duration);
1259   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1260
1261   if (ret != EXIT_SUCCESS) {
1262     TEST_FAIL_MESSAGE("[FAILED] Set break on USART Server. Check USART Server! Test aborted!");
1263   }
1264
1265   return ret;
1266 }
1267
1268 /**
1269   \fn            static int32_t CmdGetBrk (void)
1270   \brief         Get information on Break state from USART Server.
1271   \return        execution status
1272                    - EXIT_SUCCESS: Command sent and response received successfully
1273                    - EXIT_FAILURE: Command send or response reception failed
1274 */
1275 static int32_t CmdGetBrk (void) {
1276   int32_t ret;
1277
1278   // Send "GET BRK" command to USART Server
1279   memset(ptr_tx_buf, 0, CMD_LEN);
1280   memcpy(ptr_tx_buf, "GET BRK", 7);
1281   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1282
1283   if (ret == EXIT_SUCCESS) {
1284     // Receive response to "GET BRK" command from USART Server
1285     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_BRK_LEN);
1286     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_BRK_LEN);
1287     (void)osDelay(10U);
1288   }
1289
1290   // Store modem status to global variable
1291   if (ret == EXIT_SUCCESS) {
1292     break_status = ptr_rx_buf[0] - '0';
1293   }
1294
1295   if (ret != EXIT_SUCCESS) {
1296     TEST_FAIL_MESSAGE("[FAILED] Get break state from USART Server. Check USART Server! Test aborted!");
1297   }
1298
1299   return ret;
1300 }
1301
1302 /**
1303   \fn            static int32_t CmdSetMdm (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration)
1304   \brief         Set modem lines on USART Server.
1305   \param[in]     mdm_ctrl:      modem control line states:
1306                                   - bit 0.: RTS state
1307                                   - bit 1.: DTS state
1308                                   - bit 2.: Line to USART Client's DCD state
1309                                   - bit 3.: Line to USART Client's RI state
1310   \param[in]     delay:         initial delay, in milliseconds, before start of controlling modem lines
1311   \param[in]     duration:      duration, in milliseconds, of controlling modem lines
1312   \return        execution status
1313                    - EXIT_SUCCESS: Command sent successfully
1314                    - EXIT_FAILURE: Command send failed
1315 */
1316 static int32_t CmdSetMdm (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration) {
1317   int32_t ret;
1318
1319   // Send "SET MDM" command to USART Server
1320   memset(ptr_tx_buf, 0, CMD_LEN);
1321   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET MDM %x,%i,%i", mdm_ctrl, delay, duration);
1322   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1323   (void)osDelay(10U);
1324
1325   if (ret != EXIT_SUCCESS) {
1326     TEST_FAIL_MESSAGE("[FAILED] Set modem control on USART Server. Check USART Server! Test aborted!");
1327   }
1328
1329   return ret;
1330 }
1331
1332 /**
1333   \fn            static int32_t CmdGetMdm (void)
1334   \brief         Get information on modem lines current state from USART Server.
1335   \return        execution status
1336                    - EXIT_SUCCESS: Command sent and response received successfully
1337                    - EXIT_FAILURE: Command send or response reception failed
1338 */
1339 static int32_t CmdGetMdm (void) {
1340   int32_t ret;
1341
1342   // Send "GET MDM" command to USART Server
1343   memset(ptr_tx_buf, 0, CMD_LEN);
1344   memcpy(ptr_tx_buf, "GET MDM", 7);
1345   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1346
1347   if (ret == EXIT_SUCCESS) {
1348     // Receive response to "GET MDM" command from USART Server
1349     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_MDM_LEN);
1350     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_MDM_LEN);
1351     (void)osDelay(10U);
1352   }
1353
1354   // Store modem status to global variable
1355   if (ret == EXIT_SUCCESS) {
1356     modem_status = ptr_rx_buf[0] - '0';
1357   }
1358
1359   if (ret != EXIT_SUCCESS) {
1360     TEST_FAIL_MESSAGE("[FAILED] Get modem lines state from USART Server. Check USART Server! Test aborted!");
1361   }
1362
1363   return ret;
1364 }
1365
1366 /*
1367   \fn            static int32_t ServerInit (void)
1368   \brief         Initialize communication with USART Server, get version and capabilities.
1369   \return        execution status
1370                    - EXIT_SUCCESS: USART Server initialized successfully
1371                    - EXIT_FAILURE: USART Server initialization failed
1372 */
1373 static int32_t ServerInit (void) {
1374
1375   if (server_ok == -1) {                // If -1, means it was not yet checked
1376     server_ok = 1;
1377
1378     if (drv->Control(((USART_CFG_SRV_MODE         << ARM_USART_CONTROL_Pos)      & ARM_USART_CONTROL_Msk)      |
1379                        DRIVER_DATA_BITS(USART_CFG_SRV_DATA_BITS)                                               |
1380                      ((USART_CFG_SRV_PARITY       << ARM_USART_PARITY_Pos)       & ARM_USART_PARITY_Msk)       |
1381                      ((USART_CFG_SRV_STOP_BITS    << ARM_USART_STOP_BITS_Pos)    & ARM_USART_STOP_BITS_Msk)    |
1382                      ((USART_CFG_SRV_FLOW_CONTROL << ARM_USART_FLOW_CONTROL_Pos) & ARM_USART_FLOW_CONTROL_Msk) ,
1383                        USART_CFG_SRV_BAUDRATE) != ARM_DRIVER_OK) {
1384       server_ok = 0;
1385     }
1386     if (server_ok == 0) {
1387       TEST_GROUP_INFO("Failed to configure communication interface to USART Server default settings.\n"\
1388                       "Driver must support basic settings used for communication with USART Server!");
1389     }
1390
1391     if (server_ok == 1) {
1392       (void)osDelay(10U);
1393       if (CmdGetVer() != EXIT_SUCCESS) {
1394         TEST_GROUP_INFO("Failed to Get version from USART Server.\nCheck USART Server!\n");
1395         server_ok = 0;
1396       }
1397     }
1398
1399     if (server_ok == 1) {
1400       if (usart_serv_ver.major == 0U) { 
1401         TEST_GROUP_INFO("USART Server version must be 1.0.0. or higher.\nUpdate USART Server to newer version!\n");
1402         server_ok = 0;
1403       }
1404     }
1405
1406     if (server_ok == 1) {
1407       if (CmdGetCap() != EXIT_SUCCESS) {
1408         TEST_GROUP_INFO("Failed to Get capabilities from USART Server.\nCheck USART Server!\n");
1409         server_ok = 0;
1410       }
1411     }
1412   }
1413
1414   if (server_ok == 1) {
1415     return EXIT_SUCCESS;
1416   }
1417
1418   return EXIT_FAILURE;
1419 }
1420
1421 /*
1422   \fn            static int32_t ServerCheck (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t modem_line, uint32_t baudrate)
1423   \brief         Check if USART Server is functional and if it supports desired settings.
1424   \detail        Parameters describe settings required to test, so server must support complementary sattings.
1425                  For example to test RTS line server must support CTS line.
1426   \param[in]     mode           mode (expected to be tested):
1427                                   - value 1 = Asynchronous
1428                                   - value 2 = Synchronous Master
1429                                   - value 3 = Synchronous Slave
1430                                   - value 4 = Single Wire
1431                                   - value 5 = IrDA
1432                                   - value 6 = Smart Card
1433   \param[in]     data_bits      data bits (5 .. 9)
1434   \param[in]     parity         parity:
1435                                   - value 0 = None
1436                                   - value 1 = Even
1437                                   - value 2 = Odd
1438   \param[in]     stop_bits      stop bits:
1439                                   - value 0 = 1 Stop Bit
1440                                   - value 1 = 2 Stop Bits
1441                                   - value 2 = 1.5 Stop Bits
1442                                   - value 3 = 0.5 Stop Bits
1443   \param[in]     flow_control   flow control:
1444                                   - value 0 = None
1445                                   - value 1 = CTS
1446                                   - value 2 = RTS
1447                                   - value 3 = RTS/CTS
1448   \param[in]     modem_line_mask  modem line mask:
1449                                   - bit 0. = RTS
1450                                   - bit 1. = CTS
1451                                   - bit 2. = DTR
1452                                   - bit 3. = DSR
1453                                   - bit 4. = DCD
1454                                   - bit 5. = RI
1455   \param[in]     baudrate       baudrate in bauds
1456   \return        execution status
1457                    - EXIT_SUCCESS: USART Server supports desired settings
1458                    - EXIT_FAILURE: USART Server does not support desired settings
1459 */
1460 static int32_t ServerCheck (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t modem_line_mask, uint32_t baudrate) {
1461   uint32_t srv_mode, srv_flow_control, srv_modem_line_mask;
1462
1463   if (server_ok == 0) {
1464     TEST_FAIL_MESSAGE("[FAILED] USART Server status. Check USART Server! Test aborted!");
1465     return EXIT_FAILURE;
1466   }
1467
1468 #if   (USART_CFG_SRV_MODE == MODE_ASYNCHRONOUS)
1469     if ((mode == MODE_SINGLE_WIRE) || (mode == MODE_IRDA)) {
1470       TEST_MESSAGE("[FAILED] USART Server mode Asynchronous does not support requested test mode! Test aborted!");
1471       return EXIT_FAILURE;
1472     }
1473 #elif (USART_CFG_SRV_MODE == MODE_SINGLE_WIRE)
1474     if (mode != MODE_SINGLE_WIRE) {
1475       TEST_MESSAGE("[FAILED] USART Server mode Single-wire does not support requested test mode! Test aborted!");
1476       return EXIT_FAILURE;
1477     }
1478 #elif (USART_CFG_SRV_MODE == MODE_SINGLE_IRDA)
1479     if (mode != MODE_SINGLE_IRDA) {
1480       TEST_MESSAGE("[FAILED] USART Server mode IrDA does not support requested test mode! Test aborted!");
1481       return EXIT_FAILURE;
1482     }
1483 #else
1484     TEST_MESSAGE("[FAILED] USART Server mode unknown! Test aborted!");
1485     return EXIT_FAILURE;
1486 #endif
1487
1488   srv_mode = mode;
1489   if (mode == MODE_SYNCHRONOUS_MASTER) {        // If mode to be tested is Synchro Master then server must support Slave
1490     srv_mode = MODE_SYNCHRONOUS_SLAVE;
1491   } else if (mode == MODE_SYNCHRONOUS_SLAVE) {  // If mode to be tested is Synchro Slave  then server must support Master
1492     srv_mode = MODE_SYNCHRONOUS_MASTER;
1493   }
1494
1495   srv_flow_control = flow_control;
1496   if (flow_control == FLOW_CONTROL_RTS) {
1497     srv_flow_control = FLOW_CONTROL_CTS;
1498   }
1499   if (flow_control == FLOW_CONTROL_CTS) {
1500     srv_flow_control = FLOW_CONTROL_RTS;
1501   }
1502
1503   srv_modem_line_mask = 0U;
1504   if ((modem_line_mask & RTS_AVAILABLE   ) != 0U) {
1505     srv_modem_line_mask |= CTS_AVAILABLE;
1506   }
1507   if ((modem_line_mask & CTS_AVAILABLE   ) != 0U) {
1508     srv_modem_line_mask |= RTS_AVAILABLE;
1509   }
1510   if ((modem_line_mask & DTR_AVAILABLE   ) != 0U) {
1511     srv_modem_line_mask |= DSR_AVAILABLE;
1512   }
1513   if ((modem_line_mask & DSR_AVAILABLE   ) != 0U) {
1514     srv_modem_line_mask |= DTR_AVAILABLE;
1515   }
1516   if ((modem_line_mask & DCD_AVAILABLE) != 0U) {
1517     srv_modem_line_mask |= DCD_AVAILABLE;
1518   }
1519   if ((modem_line_mask & RI_AVAILABLE ) != 0U) {
1520     srv_modem_line_mask |= RI_AVAILABLE;
1521   }
1522
1523   if ((usart_serv_cap.mode_mask & (1UL << (srv_mode - 1U))) == 0U) {
1524     // If USART Server does not support desired mode
1525     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s mode! Test aborted!", str_mode[mode]);
1526     TEST_MESSAGE(msg_buf);
1527     return EXIT_FAILURE;
1528   }
1529   if ((usart_serv_cap.db_mask & (1UL << (data_bits - 5U))) == 0U) {
1530     // If USART Server does not support desired data bits
1531     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %i data bits! Test aborted!", data_bits);
1532     TEST_MESSAGE(msg_buf);
1533     return EXIT_FAILURE;
1534   }
1535   if ((usart_serv_cap.parity_mask & (1UL << parity)) == 0U) {
1536     // If USART Server does not support desired parity
1537     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s parity! Test aborted!", str_parity[parity]);
1538     TEST_MESSAGE(msg_buf);
1539     return EXIT_FAILURE;
1540   }
1541   if ((usart_serv_cap.sb_mask & (1UL << stop_bits)) == 0U) {
1542     // If USART Server does not support desired stop bits
1543     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s stop bits! Test aborted!", str_stop_bits[stop_bits]);
1544     TEST_MESSAGE(msg_buf);
1545     return EXIT_FAILURE;
1546   }
1547   if ((usart_serv_cap.fc_mask & (1UL << srv_flow_control)) == 0U) {
1548     // If USART Server does not support desired flow control
1549     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s flow control! Test aborted!", str_flow_control[flow_control]);
1550     TEST_MESSAGE(msg_buf);
1551     return EXIT_FAILURE;
1552   }
1553   if (srv_modem_line_mask != 0U) {
1554     if ((usart_serv_cap.ml_mask & srv_modem_line_mask) == 0U) {
1555       // If USART Server does not support desired modem line
1556       TEST_MESSAGE("[FAILED] USART Server does not support desired modem line! Test aborted!");
1557       return EXIT_FAILURE;
1558     }
1559   }
1560   if ((usart_serv_cap.br_min > baudrate) ||
1561       (usart_serv_cap.br_max < baudrate)) {
1562     // If USART Server does not support desired baudrate
1563     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %i baudrate bus speed! Test aborted!", baudrate);
1564     TEST_MESSAGE(msg_buf);
1565     return EXIT_FAILURE;
1566   }
1567
1568   return EXIT_SUCCESS;
1569 }
1570
1571 #endif                                  // If Test Mode USART Server is selected
1572
1573 /*
1574   \fn            static int32_t SettingsCheck (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t modem_line, uint32_t baudrate)
1575   \brief         Check if Driver and USART Server (if used) is functional and if it supports desired settings.
1576   \detail        Parameters describe settings required to test, so server must support complementary sattings.
1577                  For example to test RTS line server must support CTS line.
1578   \param[in]     mode           mode (expected to be tested):
1579                                   - value 1 = Asynchronous
1580                                   - value 2 = Synchronous Master
1581                                   - value 3 = Synchronous Slave
1582                                   - value 4 = Single Wire
1583                                   - value 5 = IrDA
1584                                   - value 6 = Smart Card
1585   \param[in]     data_bits      data bits (5 .. 9)
1586   \param[in]     parity         parity:
1587                                   - value 0 = None
1588                                   - value 1 = Even
1589                                   - value 2 = Odd
1590   \param[in]     stop_bits      stop bits:
1591                                   - value 0 = 1 Stop Bit
1592                                   - value 1 = 2 Stop Bits
1593                                   - value 2 = 1.5 Stop Bits
1594                                   - value 3 = 0.5 Stop Bits
1595   \param[in]     flow_control   flow control:
1596                                   - value 0 = None
1597                                   - value 1 = CTS
1598                                   - value 2 = RTS
1599                                   - value 3 = RTS/CTS
1600   \param[in]     modem_line_mask  modem line mask:
1601                                   - bit 0. = RTS
1602                                   - bit 1. = CTS
1603                                   - bit 2. = DTR
1604                                   - bit 3. = DSR
1605                                   - bit 4. = DCD
1606                                   - bit 5. = RI
1607   \param[in]     baudrate       baudrate in bauds
1608   \return        execution status
1609                    - EXIT_SUCCESS: Driver and USART Server supports desired settings
1610                    - EXIT_FAILURE: Driver or USART Server does not support desired settings
1611 */
1612 static int32_t SettingsCheck (uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t modem_line_mask, uint32_t baudrate) {
1613
1614   if (BuffersCheck()  != EXIT_SUCCESS) { 
1615     return EXIT_FAILURE;
1616   }
1617
1618   if (DriverCheck (mode, flow_control, modem_line_mask) != EXIT_SUCCESS) { 
1619     return EXIT_FAILURE;
1620   }
1621 #if  (USART_SERVER_USED == 1)
1622   if (ServerCheck (mode, data_bits, parity, stop_bits, flow_control, modem_line_mask, baudrate) != EXIT_SUCCESS) {
1623     return EXIT_FAILURE;
1624   }
1625 #endif
1626
1627   return EXIT_SUCCESS;
1628 }
1629
1630 /*
1631   \fn            void USART_DV_Initialize (void)
1632   \brief         Initialize testing environment for USART testing.
1633   \detail        This function is called by the driver validation framework before USART testing begins.
1634                  It initializes global variables and allocates memory buffers (from heap) used for the USART testing.
1635   \return        none
1636 */
1637 void USART_DV_Initialize (void) {
1638
1639   // Initialize global variables
1640   buffers_ok   = -1;
1641   server_ok    = -1;
1642   driver_ok    = -1;
1643   event        = 0U;
1644   duration     = 0xFFFFFFFFUL;
1645   systick_freq = osKernelGetSysTimerFreq();
1646   if (systick_freq == 0U) {
1647     // systick_freq must not be 0
1648     systick_freq = 1U;
1649   }
1650   ticks_per_ms = systick_freq / 1000U;
1651
1652   memset(&usart_serv_cap, 0, sizeof(usart_serv_cap));
1653   memset(&msg_buf,        0, sizeof(msg_buf));
1654
1655   // Allocate buffers for transmission, reception and comparison
1656   // (maximum size is incremented by 4 bytes to ensure that buffer can be aligned to 4 bytes)
1657
1658   ptr_tx_buf_alloc = malloc(USART_BUF_MAX + 4U);
1659   if (((uint32_t)ptr_tx_buf_alloc & 3U) != 0U) {
1660     // If allocated memory is not 4 byte aligned, use next 4 byte aligned address for ptr_tx_buf
1661     ptr_tx_buf = (uint8_t *)((((uint32_t)ptr_tx_buf_alloc) + 3U) & (~3U));
1662   } else {
1663     // If allocated memory is 4 byte aligned, use it directly
1664     ptr_tx_buf = (uint8_t *)ptr_tx_buf_alloc;
1665   }
1666   ptr_rx_buf_alloc = malloc(USART_BUF_MAX + 4U);
1667   if (((uint32_t)ptr_rx_buf_alloc & 3U) != 0U) {
1668     ptr_rx_buf = (uint8_t *)((((uint32_t)ptr_rx_buf_alloc) + 3U) & (~3U));
1669   } else {
1670     ptr_rx_buf = (uint8_t *)ptr_rx_buf_alloc;
1671   }
1672   ptr_cmp_buf_alloc = malloc(USART_BUF_MAX + 4U);
1673   if (((uint32_t)ptr_cmp_buf_alloc & 3U) != 0U) {
1674     ptr_cmp_buf = (uint8_t *)((((uint32_t)ptr_cmp_buf_alloc) + 3U) & (~3U));
1675   } else {
1676     ptr_cmp_buf = (uint8_t *)ptr_cmp_buf_alloc;
1677   }
1678
1679   event_flags = osEventFlagsNew(NULL);
1680
1681   // Output configuration settings
1682   (void)snprintf(msg_buf, 
1683                  sizeof(msg_buf),
1684                  "Test Mode:          %s\n"\
1685                  "Default settings:\n"\
1686                  " - Mode:            %s\n"\
1687                  " - Data bits:       %i\n"\
1688                  " - Parity:          %s\n"\
1689                  " - Stop bits:       %s\n"\
1690                  " - Flow control:    %s\n"\
1691                  " - Clock polarity:  %s\n"\
1692                  " - Clock phase:     %s\n"\
1693                  " - Bus speed:       %i bauds\n"\
1694                  " - Number of Items: %i",
1695                  str_test_mode   [USART_CFG_TEST_MODE],
1696                  str_mode        [USART_CFG_DEF_MODE],
1697                  USART_CFG_DEF_DATA_BITS,
1698                  str_parity      [USART_CFG_DEF_PARITY],
1699                  str_stop_bits   [USART_CFG_DEF_STOP_BITS],
1700                  str_flow_control[USART_CFG_DEF_FLOW_CONTROL],
1701                  str_cpol        [USART_CFG_DEF_CPOL],
1702                  str_cpha        [USART_CFG_DEF_CPHA],
1703                  USART_CFG_DEF_BAUDRATE,
1704                  USART_CFG_DEF_NUM);
1705   TEST_GROUP_INFO(msg_buf);
1706
1707   drv_cap = drv->GetCapabilities();
1708
1709 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
1710   // Test communication with USART Server
1711   int32_t  server_status;
1712   uint32_t str_len;
1713
1714   // Test communication with USART Server
1715   if (drv->Initialize    (USART_DrvEvent) == ARM_DRIVER_OK) {
1716     if (drv->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK) {
1717       server_status = ServerInit();
1718     }
1719   }
1720   (void)drv->PowerControl(ARM_POWER_OFF);
1721   (void)drv->Uninitialize();
1722
1723 //(void)snprintf(msg_buf, sizeof(msg_buf), "Server status:      %s\n", str_srv_status[server_status]);
1724 //TEST_GROUP_INFO(msg_buf);
1725 #endif
1726 }
1727
1728 /*
1729   \fn            void USART_DV_Uninitialize (void)
1730   \brief         De-initialize testing environment after USART testing.
1731   \detail        This function is called by the driver validation framework after USART testing is finished.
1732                  It frees memory buffers used for the USART testing.
1733   \return        none
1734 */
1735 void USART_DV_Uninitialize (void) {
1736
1737   (void)osEventFlagsDelete(event_flags);
1738
1739   if (ptr_tx_buf_alloc != NULL) {
1740     free(ptr_tx_buf_alloc);
1741     ptr_tx_buf        = NULL;
1742     ptr_tx_buf_alloc  = NULL;
1743   }
1744   if (ptr_rx_buf_alloc != NULL) {
1745     free(ptr_rx_buf_alloc);
1746     ptr_rx_buf        = NULL;
1747     ptr_rx_buf_alloc  = NULL;
1748   }
1749   if (ptr_cmp_buf_alloc != NULL) {
1750     free(ptr_cmp_buf_alloc);
1751     ptr_cmp_buf       = NULL;
1752     ptr_cmp_buf_alloc = NULL;
1753   }
1754 }
1755
1756 #endif                                  // End of exclude form the documentation
1757
1758 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1759 /**
1760 \defgroup dv_usart USART Validation
1761 \brief USART driver validation
1762 \details
1763 The USART validation performs the following tests:
1764 - API interface compliance
1765 - Data exchange with various speeds, transfer sizes and communication settings
1766 - Modem lines operation
1767 - Event signaling
1768
1769 Two Test Modes are available: <b>Loopback</b> and <b>USART Server</b>.
1770
1771 Test Mode : <b>Loopback</b>
1772 ---------------------------
1773
1774 This test mode allows only limited validation of the USART Driver.<br>
1775 It is recommended that this test mode is used only as a proof that driver is 
1776 good enough to be tested with the <b>USART Server</b>.
1777
1778 For this purpose following <b>Default settings</b> should be used:
1779  - Mode: Asynchronous
1780  - Data Bits: 8
1781  - Parity: None
1782  - Stop Bits: 1
1783  - Flow control: No
1784  - Clock Polarity: Clock Polarity 0
1785  - Clock Phase: Clock Phase 0
1786  - Baudrate: 115200
1787  - Number of Items: 32
1788
1789 To enable this mode of testing in the <b>DV_USART_Config.h</b> configuration file select the
1790 <b>Configuration: Test Mode: Loopback</b> setting.
1791
1792 Required pin connection for the <b>Loopback</b> test mode:
1793
1794 \image html usart_loopback_pin_connections.png
1795
1796 \note In this mode following operations / settings cannot be tested:
1797  - synchronous slave or single-wire modes
1798  - operation of the Receive function
1799  - data content sent by the Send function
1800  - parity, stop bits, flow control, clock polarity / phase settings
1801  - data bit settings other then 8
1802  - modem lines operation
1803  - event signaling
1804
1805 \anchor usart_server_con
1806
1807 Test Mode : <b>USART Server</b>
1808 -----------------------------
1809
1810 This test mode allows extensive validation of the USART Driver.<br>
1811 Results of the Driver Validation in this test mode are relevant as a proof of driver compliance 
1812 to the CMSIS-Driver specification.
1813
1814 To perform extensive communication tests, it is required to use an 
1815 \ref usart_server "USART Server" running on a dedicated hardware.
1816
1817 To enable this mode of testing in the <b>DV_USART_Config.h</b> configuration file select the
1818 <b>Configuration: Test Mode: USART Server</b> setting.
1819
1820 Required pin connections for the <b>USART Server</b> test mode with <b>USART Server Mode</b>: <b>Asynchronous</b> or <b>IrDa</b>
1821
1822 \note Only necessary pin connections are Tx, Rx and GND. Flow control (RTS, CTS), modem lines (DSR, DTR, DCD, RI) and 
1823 synchronous clock (CLK) line are optional and depend on pin availability and driver support for flow control, modem lines and 
1824 synchronous mode.
1825 \note For stable idle level on Rx lines, external pull-ups can be added.
1826
1827 \image html usart_server_pin_connections_async.png
1828
1829 Required pin connections for the <b>USART Server</b> test mode with <b>USART Server Mode</b>: <b>Single-wire</b>
1830
1831 \image html usart_server_pin_connections_single_wire.png
1832
1833 \note Asynchronous and IrDa modes use same connection type and Single-wire uses a different connection. 
1834 \note Please ensure that correct connection is used as required by tests otherwise damage to hardware may occur 
1835       (For example using Asynchronous mode selected with hardware connected for Single-wire tests can result in damaged pins).
1836 \note In this mode Tx and Rx pins are internally connected together.
1837 \note Tx pin should use open-drain setting in this mode to prevent damage in case of simultaneous 
1838       driving from both USART Server and USART Client.
1839
1840 \note To ensure proper signal quality:
1841        - keep the connecting wires as short as possible
1842        - if possible keep Tx and Rx wires wires separate from each other
1843        - ensure a good Ground (GND) connection between USART Server and DUT
1844
1845 \defgroup usart_tests Tests
1846 \ingroup dv_usart
1847 */
1848
1849 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1850 /* USART Driver Management tests                                                                                              */
1851 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1852 /**
1853 \defgroup usart_tests_drv_mgmt Driver Management
1854 \ingroup usart_tests
1855 \details
1856 These tests verify API and operation of the USART driver management functions.
1857
1858 The driver management tests verify the following driver functions
1859 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
1860  - \b GetVersion
1861 \code
1862   ARM_DRIVER_VERSION     GetVersion      (void);
1863 \endcode
1864  - \b GetCapabilities
1865 \code
1866   ARM_USART_CAPABILITIES GetCapabilities (void);
1867 \endcode
1868  - \b Initialize
1869 \code
1870   int32_t                Initialize      (ARM_USART_SignalEvent_t cb_event);
1871 \endcode
1872  - \b Uninitialize
1873 \code
1874   int32_t                Uninitialize    (void);
1875 \endcode
1876  - \b PowerControl
1877 \code
1878   int32_t                PowerControl    (ARM_POWER_STATE state);
1879 \endcode
1880
1881 @{
1882 */
1883
1884 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1885 /**
1886 \brief Function: Function USART_GetVersion
1887 \details
1888 The function \b UDSART_GetVersion verifies the \b GetVersion function.
1889 \code
1890   ARM_DRIVER_VERSION GetVersion (void);
1891 \endcode
1892
1893 Testing sequence:
1894   - Driver is uninitialized and peripheral is powered-off:
1895     - Call GetVersion function
1896     - Assert that GetVersion function returned version structure with API and implementation versions higher or equal to 1.0
1897 */
1898 void USART_GetVersion (void) {
1899   ARM_DRIVER_VERSION ver;
1900
1901   ver = drv->GetVersion();
1902
1903   // Assert that GetVersion function returned version structure with API and implementation versions higher or equal to 1.0
1904   TEST_ASSERT((ver.api >= ARM_DRIVER_VERSION_MAJOR_MINOR(1UL,0UL)) && (ver.drv >= ARM_DRIVER_VERSION_MAJOR_MINOR(1UL,0UL)));
1905
1906   (void)snprintf(msg_buf, sizeof(msg_buf), "[INFO] Driver API version %d.%d, Driver version %d.%d", (ver.api >> 8), (ver.api & 0xFFU), (ver.drv >> 8), (ver.drv & 0xFFU));
1907   TEST_MESSAGE(msg_buf);
1908 }
1909
1910 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1911 /**
1912 \brief Function: Function USART_GetCapabilities
1913 \details
1914 The function \b USART_GetCapabilities verifies the \b GetCapabilities function.
1915 \code
1916   ARM_USART_CAPABILITIES GetCapabilities (void);
1917 \endcode
1918
1919 Testing sequence:
1920   - Driver is uninitialized and peripheral is powered-off:
1921     - Call GetCapabilities function
1922     - Assert that GetCapabilities function returned capabilities structure with reserved field 0
1923 */
1924 void USART_GetCapabilities (void) {
1925   ARM_USART_CAPABILITIES cap;
1926
1927   cap = drv->GetCapabilities();
1928
1929   // Assert that GetCapabilities function returned capabilities structure with reserved field 0
1930   TEST_ASSERT_MESSAGE((cap.reserved == 0U), "[FAILED] Capabilities reserved field must be 0");
1931 }
1932
1933 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1934 /**
1935 \brief Function: Function USART_Initialize_Uninitialize
1936 \details
1937 The function \b USART_Initialize_Uninitialize verifies the \b Initialize and \b Uninitialize functions.
1938 \code
1939   int32_t Initialize (ARM_USART_SignalEvent_t cb_event);
1940 \endcode
1941 \code
1942   int32_t Uninitialize (void);
1943 \endcode
1944
1945 Testing sequence:
1946   - Driver is uninitialized and peripheral is powered-off:
1947     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_ERROR status
1948     - Call PowerControl(ARM_POWER_LOW) function and assert that it returned ARM_DRIVER_ERROR status
1949     - Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_ERROR status
1950     - Call Send function and assert that it returned ARM_DRIVER_ERROR status
1951     - Call Receive function and assert that it returned ARM_DRIVER_ERROR status
1952     - Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
1953     - Call GetTxCount function and assert that it returned 0
1954     - Call GetRxCount function and assert that it returned 0
1955     - Call Control function and assert that it returned ARM_DRIVER_ERROR status
1956     - Call GetStatus function
1957     - Assert that GetStatus function returned status structure with tx_busy flag 0
1958     - Assert that GetStatus function returned status structure with rx_busy flag 0
1959     - Assert that GetStatus function returned status structure with tx_underflow flag 0
1960     - Assert that GetStatus function returned status structure with rx_overflow flag 0
1961     - Assert that GetStatus function returned status structure with rx_break flag 0
1962     - Assert that GetStatus function returned status structure with rx_framing_error flag 0
1963     - Assert that GetStatus function returned status structure with rx_parity_error flag 0
1964     - Assert that GetStatus function returned status structure with reserved field 0
1965     - Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
1966   - Driver is initialized and peripheral is powered-off:
1967     - Call Initialize function (without callback specified) again and assert that it returned ARM_DRIVER_OK status
1968     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
1969   - Driver is uninitialized and peripheral is powered-off:
1970     - Call Initialize function (with callback specified) and assert that it returned ARM_DRIVER_OK status
1971   - Driver is initialized and peripheral is powered-off:
1972     - Call Initialize function (with callback specified) again and assert that it returned ARM_DRIVER_OK status
1973     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
1974   - Driver is uninitialized and peripheral is powered-off:
1975     - Call Uninitialize function again and assert that it returned ARM_DRIVER_OK status
1976     - Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
1977   - Driver is initialized and peripheral is powered-off:
1978     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
1979   - Driver is initialized and peripheral is powered-on:
1980     - Call Control function and assert that it returned ARM_DRIVER_OK status
1981     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status<br>
1982       (this must unconditionally terminate active send/receive/transfer, power-off the peripheral and uninitialize the driver)
1983   - Driver is uninitialized and peripheral is powered-off:
1984     - Call GetStatus function
1985     - Assert that GetStatus function returned status structure with tx_busy flag 0
1986     - Assert that GetStatus function returned status structure with rx_busy flag 0
1987 */
1988 void USART_Initialize_Uninitialize (void) {
1989   ARM_USART_STATUS stat;
1990
1991   // Driver is uninitialized and peripheral is powered-off:
1992   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_ERROR status
1993   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_ERROR);
1994
1995   stat = drv->GetStatus();
1996
1997   // Call PowerControl(ARM_POWER_LOW) function and assert that it returned ARM_DRIVER_ERROR status
1998   TEST_ASSERT(drv->PowerControl (ARM_POWER_LOW) == ARM_DRIVER_ERROR);
1999
2000   stat = drv->GetStatus();
2001
2002   // Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_ERROR status
2003   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_ERROR);
2004
2005   stat = drv->GetStatus();
2006
2007   // Call Send function and assert that it returned ARM_DRIVER_ERROR status
2008   TEST_ASSERT(drv->Send (ptr_tx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2009
2010   // Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2011   TEST_ASSERT(drv->Receive (ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2012
2013   // Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2014   TEST_ASSERT(drv->Transfer (ptr_tx_buf, ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2015
2016   // Call GetTxCount function and assert that it returned 0
2017   TEST_ASSERT(drv->GetTxCount () == 0U);
2018
2019   // Call GetRxCount function and assert that it returned 0
2020   TEST_ASSERT(drv->GetRxCount () == 0U);
2021
2022   // Call Control function and assert that it returned ARM_DRIVER_ERROR status
2023   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_ERROR);
2024
2025   // Call GetStatus function
2026   stat = drv->GetStatus();
2027
2028   // Assert that GetStatus function returned status structure with tx_busy flag 0
2029   TEST_ASSERT(stat.tx_busy == 0U);
2030
2031   // Assert that GetStatus function returned status structure with rx_busy flag 0
2032   TEST_ASSERT(stat.rx_busy == 0U);
2033
2034   // Assert that GetStatus function returned status structure with tx_underflow flag 0
2035   TEST_ASSERT(stat.tx_underflow == 0U);
2036
2037   // Assert that GetStatus function returned status structure with rx_overflow flag 0
2038   TEST_ASSERT(stat.rx_overflow == 0U);
2039
2040   // Assert that GetStatus function returned status structure with rx_break flag 0
2041   TEST_ASSERT(stat.rx_break == 0U);
2042
2043   // Assert that GetStatus function returned status structure with rx_framing_error flag 0
2044   TEST_ASSERT(stat.rx_framing_error == 0U);
2045
2046   // Assert that GetStatus function returned status structure with rx_parity_error flag 0
2047   TEST_ASSERT(stat.rx_parity_error == 0U);
2048
2049   // Assert that GetStatus function returned status structure with reserved field 0
2050   TEST_ASSERT(stat.reserved == 0U);
2051
2052   // Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
2053   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2054
2055   // Driver is initialized and peripheral is powered-off:
2056   // Call Initialize function (without callback specified) again and assert that it returned ARM_DRIVER_OK status
2057   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2058
2059   // Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
2060   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2061
2062   // Driver is uninitialized and peripheral is powered-off:
2063   // Call Initialize function (with callback specified) and assert that it returned ARM_DRIVER_OK status
2064   TEST_ASSERT(drv->Initialize (USART_DrvEvent) == ARM_DRIVER_OK);
2065
2066   // Driver is initialized and peripheral is powered-off:
2067   // Call Initialize function (with callback specified) again and assert that it returned ARM_DRIVER_OK status
2068   TEST_ASSERT(drv->Initialize (USART_DrvEvent) == ARM_DRIVER_OK);
2069
2070   // Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
2071   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2072
2073   // Driver is uninitialized and peripheral is powered-off:
2074   // Call Uninitialize function again and assert that it returned ARM_DRIVER_OK status
2075   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2076
2077   // Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
2078   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2079
2080   // Driver is initialized and peripheral is powered-off:
2081   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2082   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2083
2084   // Driver is initialized and peripheral is powered-on:
2085   // Call Control function and assert that it returned ARM_DRIVER_OK status
2086   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2087                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2088                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2089                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_OK);
2090
2091   // Call Uninitialize function assert that it returned ARM_DRIVER_OK status
2092   // (this must unconditionally terminate active send/receive/transfer, power-off the peripheral and uninitialize the driver)
2093   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2094
2095   // Driver is uninitialized and peripheral is powered-off:
2096   // Call GetStatus function
2097   stat = drv->GetStatus();
2098
2099   // Assert that GetStatus function returned status structure with tx_busy flag 0
2100   TEST_ASSERT(stat.tx_busy == 0U);
2101
2102   // Assert that GetStatus function returned status structure with rx_busy flag 0
2103   TEST_ASSERT(stat.rx_busy == 0U);
2104 }
2105
2106 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2107 /**
2108 \brief Function: Function USART_PowerControl
2109 \details
2110 The function \b USART_PowerControl verifies the \b PowerControl function.
2111 \code
2112   int32_t PowerControl (ARM_POWER_STATE state);
2113 \endcode
2114
2115 Testing sequence:
2116   - Driver is initialized and peripheral is powered-off:
2117     - Call Send function and assert that it returned ARM_DRIVER_ERROR status
2118     - Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2119     - Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2120     - Call GetTxCount function and assert that it returned 0
2121     - Call GetRxCount function and assert that it returned 0
2122     - Call Control function and assert that it returned ARM_DRIVER_ERROR status
2123     - Call GetStatus function
2124     - Assert that GetStatus function returned status structure with tx_busy flag 0
2125     - Assert that GetStatus function returned status structure with rx_busy flag 0
2126     - Assert that GetStatus function returned status structure with tx_underflow flag 0
2127     - Assert that GetStatus function returned status structure with rx_overflow flag 0
2128     - Assert that GetStatus function returned status structure with rx_break flag 0
2129     - Assert that GetStatus function returned status structure with rx_framing_error flag 0
2130     - Assert that GetStatus function returned status structure with rx_parity_error flag 0
2131     - Assert that GetStatus function returned status structure with reserved field 0
2132     - Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2133     - Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2134     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2135   - Driver is initialized and peripheral is powered-on:
2136     - Call PowerControl(ARM_POWER_FULL) function again and assert that it returned ARM_DRIVER_OK status
2137     - Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2138   - Driver is initialized and peripheral is powered-off:
2139     - Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2140     - Call PowerControl(ARM_POWER_LOW) function
2141   - Driver is initialized and peripheral is powered-on or in low-power mode:
2142     - Assert that PowerControl(ARM_POWER_LOW) function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED status
2143     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2144   - Driver is initialized and peripheral is powered-on:
2145     - Call Control function and assert that it returned ARM_DRIVER_OK status
2146     - Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_OK status<br>
2147       (this must unconditionally terminate active send/receive/transfer and power-off the peripheral)
2148   - Driver is initialized and peripheral is powered-off:
2149     - Call GetStatus function
2150     - Assert that GetStatus function returned status structure with tx_busy flag 0
2151     - Assert that GetStatus function returned status structure with rx_busy flag 0
2152 */
2153 void USART_PowerControl (void) {
2154   int32_t          ret;
2155   ARM_USART_STATUS stat;
2156
2157   (void)drv->Initialize (NULL);
2158
2159   // Driver is initialized and peripheral is powered-off:
2160   // Call Send function and assert that it returned ARM_DRIVER_ERROR status
2161   TEST_ASSERT(drv->Send (ptr_tx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2162
2163   // Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2164   TEST_ASSERT(drv->Receive (ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2165
2166   // Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2167   TEST_ASSERT(drv->Transfer (ptr_tx_buf, ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2168
2169   // Call GetTxCount function and assert that it returned 0
2170   TEST_ASSERT(drv->GetTxCount () == 0U);
2171
2172   // Call GetRxCount function and assert that it returned 0
2173   TEST_ASSERT(drv->GetRxCount () == 0U);
2174
2175   // Call Control function and assert that it returned ARM_DRIVER_ERROR status
2176   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2177                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2178                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2179                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_ERROR);
2180
2181   // Call GetStatus function
2182   stat = drv->GetStatus();
2183
2184   // Assert that GetStatus function returned status structure with tx_busy flag 0
2185   TEST_ASSERT(stat.tx_busy == 0U);
2186
2187   // Assert that GetStatus function returned status structure with rx_busy flag 0
2188   TEST_ASSERT(stat.rx_busy == 0U);
2189
2190   // Assert that GetStatus function returned status structure with tx_underflow flag 0
2191   TEST_ASSERT(stat.tx_underflow == 0U);
2192
2193   // Assert that GetStatus function returned status structure with rx_overflow flag 0
2194   TEST_ASSERT(stat.rx_overflow == 0U);
2195
2196   // Assert that GetStatus function returned status structure with rx_break flag 0
2197   TEST_ASSERT(stat.rx_break == 0U);
2198
2199   // Assert that GetStatus function returned status structure with rx_framing_error flag 0
2200   TEST_ASSERT(stat.rx_framing_error == 0U);
2201
2202   // Assert that GetStatus function returned status structure with rx_parity_error flag 0
2203   TEST_ASSERT(stat.rx_parity_error == 0U);
2204
2205   // Assert that GetStatus function returned status structure with reserved field 0
2206   TEST_ASSERT(stat.reserved == 0U);
2207
2208   // Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2209   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2210
2211   // Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2212   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2213
2214   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2215   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2216
2217   // Driver is initialized and peripheral is powered-on:
2218   // Call PowerControl(ARM_POWER_FULL) function again and assert that it returned ARM_DRIVER_OK status
2219   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2220
2221   // Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2222   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2223
2224   // Driver is initialized and peripheral is powered-off:
2225   // Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2226   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2227
2228   // Call PowerControl(ARM_POWER_LOW) function
2229   ret = drv->PowerControl (ARM_POWER_LOW);
2230
2231   // Driver is initialized and peripheral is powered-on or in low-power mode:
2232   // Assert that PowerControl(ARM_POWER_LOW) function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED status
2233   TEST_ASSERT((ret == ARM_DRIVER_OK) || (ret == ARM_DRIVER_ERROR_UNSUPPORTED));
2234   if (ret == ARM_DRIVER_ERROR_UNSUPPORTED) {
2235     TEST_MESSAGE("[WARNING] PowerControl (ARM_POWER_LOW) is not supported");
2236   }
2237
2238   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2239   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2240
2241   // Driver is initialized and peripheral is powered-on:
2242   // Call Control function and assert that it returned ARM_DRIVER_OK status
2243   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2244                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2245                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2246                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_OK);
2247
2248   // Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_OK status
2249   // (this must unconditionally terminate active send/receive/transfer and power-off the peripheral)
2250   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2251
2252   // Driver is initialized and peripheral is powered-off:
2253   // Call GetStatus function
2254   stat = drv->GetStatus();
2255
2256   // Assert that GetStatus function returned status structure with tx_busy flag 0
2257   TEST_ASSERT(stat.tx_busy == 0U);
2258
2259   // Assert that GetStatus function returned status structure with rx_busy flag 0
2260   TEST_ASSERT(stat.rx_busy == 0U);
2261
2262   (void)drv->Uninitialize ();
2263 }
2264
2265 /**
2266 @}
2267 */
2268 // End of usart_tests_drv_mgmt
2269
2270 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2271 /* USART Data Exchange tests                                                                                                  */
2272 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2273 /**
2274 \defgroup usart_tests_data_xchg Data Exchange
2275 \ingroup usart_tests
2276 \details
2277 These tests verify API and operation of the USART data exchange functions.
2278
2279 The data exchange tests verify the following driver functions
2280 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
2281  - \b Send
2282 \code
2283   int32_t          Send         (const void *data,                    uint32_t num);
2284 \endcode
2285  - \b Receive
2286 \code
2287   int32_t          Receive      (      void *data,                    uint32_t num);
2288 \endcode
2289  - \b Transfer
2290 \code
2291   int32_t          Transfer     (const void *data_out, void *data_in, uint32_t num);
2292 \endcode
2293  - \b GetTxCount
2294 \code
2295   uint32_t         GetTxCount   (void);
2296 \endcode
2297  - \b GetRxCount
2298 \code
2299   uint32_t         GetRxCount   (void);
2300 \endcode
2301  - \b Control
2302 \code
2303   int32_t          Control      (uint32_t control, uint32_t arg);
2304 \endcode
2305  - \b GetStatus
2306 \code
2307   ARM_USART_STATUS GetStatus    (void);
2308 \endcode
2309  - \b SignalEvent
2310 \code
2311   void (*ARM_USART_SignalEvent_t) (uint32_t event);
2312 \endcode
2313
2314 All of these tests execute a data exchange and check the result of this data exchange.
2315
2316 Data exchange test procedure when Test Mode <b>USART Server</b> is selected:
2317   - send command "SET BUF TX,.." to the USART Server: Set Tx buffer
2318   - send command "SET BUF RX,.." to the USART Server: Set Rx buffer
2319   - send command "SET COM .."    to the USART Server: Set communication settings for the next XFER command
2320   - send command "XFER .."       to the USART Server: Specify transfer
2321   - driver Control: Configure the USART interface
2322   - driver Control: Set the default Tx value (in synchronous mode only)
2323   - driver Send/Receive/Transfer: Start the requested operation
2324   - driver GetStatus/SignalEvent: Wait for the current operation to finish or time-out<br>
2325     (operation is finished when appropriate tx_busy or rx_busy flag is 0 and send/receive/transfer completed event was signaled)
2326   - assert that operation has finished in expected time
2327   - assert that appropriate ARM_USART_EVENT_SEND_COMPLETE, ARM_USART_EVENT_RECEIVE_COMPLETE
2328     or ARM_USART_EVENT_TRANSFER_COMPLETE event was signaled
2329   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2330   - driver GetTxCount: If it was a send or transfer operation assert that number of transmitted items is same as requested
2331   - driver GetRxCount: If it was a receive or transfer operation assert that number of received items is same as requested
2332   - if operation has timed out call driver Control function to Abort operation and wait timeout time<br>
2333     to make sure that the USART Server is ready for the next command
2334   - assert that received content is as expected
2335   - send command "GET BUF RX,.." to the USART Server: Get Rx buffer
2336   - assert that sent content (read from the USART Server's receive buffer) is as expected
2337
2338 Data exchange <b>Abort</b> test procedure when Test Mode <b>USART Server</b> is selected:
2339   - send command "SET BUF TX,.." to the USART Server: Set Tx buffer
2340   - send command "SET BUF RX,.." to the USART Server: Set Rx buffer
2341   - send command "SET COM .."    to the USART Server: Set communication settings for the next XFER command
2342   - send command "XFER .."       to the USART Server: Specify transfer
2343   - driver Control: Configure the USART interface
2344   - driver Control: Set the default Tx value (in synchronous mode only)
2345   - driver Send/Receive/Transfer: Start the requested operation
2346   - wait up to 1 ms
2347   - driver Control: Abort the current operation
2348   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2349   - driver GetTxCount: If it was a send or transfer operation assert that number of transmitted items is less than requested
2350   - driver GetRxCount: If it was a receive or transfer operation assert that number of received items is less than requested
2351
2352 Data exchange test procedure when Test Mode <b>Loopback</b> is selected:
2353   - driver Control: Configure the USART interface
2354   - driver Control: Set the default Tx value (in synchronous mode only)
2355   - driver Send/Receive/Transfer: Start the requested operation
2356   - driver GetStatus/SignalEvent: Wait for the current operation to finish or time-out<br>
2357     (operation is finished when appropriate tx_busy or rx_busy flag is 0 and send/receive/transfer completed event was signaled)
2358   - assert that operation has finished in expected time
2359   - assert that appropriate ARM_USART_EVENT_SEND_COMPLETE and ARM_USART_EVENT_RECEIVE_COMPLETE
2360     or ARM_USART_EVENT_TRANSFER_COMPLETE event was signaled
2361   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2362   - driver GetTxCount: If it was a send and receive or transfer operation assert that number of transmitted items is same as requested
2363   - driver GetRxCount: If it was a send and receive or transfer operation assert that number of received items is same as requested
2364   - if operation has timed out call driver Control function to Abort operation
2365   - assert that sent and received content is same
2366
2367 \note Limitations of Data Exchange tests if Test Mode <b>Loopback</b> is selected:
2368  - in synchronous mode only Master mode transfer can be tested
2369  - only 8 data bit tests are supported
2370  - parity tests are not supported
2371  - stop bits tests are not supported
2372  - flow control tests are not supported
2373  - clock polarity and clock phase tests are not supported
2374 @{
2375 */
2376
2377 #ifndef __DOXYGEN__                     // Exclude form the documentation
2378 /*
2379   \brief         Execute USART data exchange or abort operation.
2380   \param[in]     operation      operation (OP_SEND .. OP_ABORT_TRANSFER)
2381   \param[in]     mode           mode (MODE_ASYNCHRONOUS .. MODE_SMART_CARD)
2382   \param[in]     data_bits      data bits (5 .. 9)
2383   \param[in]     parity         parity (PARITY_NONE, PARITY_EVEN or PARITY_ODD)
2384   \param[in]     stop_bits      stop bits (STOP_BITS_1 .. STOP_BITS_0_5)
2385   \param[in]     flow_control   flow control (FLOW_CONTROL_NONE .. FLOW_CONTROL_RTS_CTS)
2386   \param[in]     cpol           clock polarity (CPOL0 or CPOL1)
2387   \param[in]     cpha           clock phase (CPHA0 or CPHA1)
2388   \param[in]     baudrate       baudrate in bauds
2389   \param[in]     num            number of items to send, receive or transfer
2390   \return        none
2391 */
2392 static void USART_DataExchange_Operation (uint32_t operation, uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate, uint32_t num) {
2393   // volatile specifier is used to prevent compiler from optimizing variables 
2394   // in a way that they cannot be seen with debugger
2395   volatile  int32_t         stat, def_tx_stat;
2396   volatile uint32_t         drv_mode, drv_data_bits, drv_parity, drv_stop_bits, drv_flow_control, drv_cpol, drv_cpha;
2397   volatile uint32_t         srv_mode, srv_dir, srv_flow_control;
2398   volatile ARM_USART_STATUS usart_stat;
2399   volatile uint32_t         tx_count, rx_count;
2400            uint32_t         start_cnt;
2401            uint32_t         val, delay, i;
2402   volatile uint32_t         srv_delay;
2403   volatile uint32_t         drv_delay;
2404            uint8_t          chk_tx_data, chk_rx_data;
2405            uint32_t         timeout, start_tick, curr_tick;
2406
2407   // Prepare parameters for USART Server and Driver configuration
2408   switch (operation & 0x0FU) {
2409     case OP_SEND:
2410     case OP_ABORT_SEND:
2411       srv_dir   = 1U;
2412       drv_delay = 10U;
2413       srv_delay = 0U;
2414       if (mode == MODE_SYNCHRONOUS_MASTER) {
2415         // In Synchronous Master test wait for USART Server to start the trasnsfer
2416         drv_delay = 10U;
2417         srv_delay = 0U;
2418       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2419         // In Synchronous Slave test make USART Server wait for driver to start the send operation
2420         drv_delay = 0U;
2421         srv_delay = 10U;
2422       }
2423       break;
2424     case OP_RECEIVE:
2425     case OP_ABORT_RECEIVE:
2426       srv_dir   = 0U;
2427       drv_delay = 0U;
2428       srv_delay = 10U;
2429       if (mode == MODE_SYNCHRONOUS_MASTER) {
2430         // In Synchronous Master test wait for USART Server to start the trasnsfer
2431         drv_delay = 10U;
2432         srv_delay = 0U;
2433       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2434         // In Synchronous Slave test make USART Server wait for driver to start the receive operation
2435         drv_delay = 0U;
2436         srv_delay = 10U;
2437       }
2438       break;
2439     case OP_TRANSFER:
2440     case OP_ABORT_TRANSFER:
2441       srv_dir   = 2U;
2442       if (mode == MODE_SYNCHRONOUS_MASTER) {
2443         // In Synchronous Master test wait for USART Server to start the trasnsfer
2444         drv_delay = 10U;
2445         srv_delay = 0U;
2446       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2447         // In Synchronous Slave test mode make USART Server wait for driver to start the transfer
2448         drv_delay = 0U;
2449         srv_delay = 10U;
2450       } else {
2451         TEST_FAIL_MESSAGE("[FAILED] Synchronous mode unknown! Data exchange operation aborted!");
2452         return;
2453       }
2454     case OP_RECEIVE_SEND_LB:
2455       drv_delay = 10U;
2456       break;
2457   }
2458
2459   switch (mode) {
2460     case MODE_ASYNCHRONOUS:
2461       drv_mode = ARM_USART_MODE_ASYNCHRONOUS;
2462       srv_mode = MODE_ASYNCHRONOUS;
2463       break;
2464     case MODE_SYNCHRONOUS_MASTER:
2465       drv_mode = ARM_USART_MODE_SYNCHRONOUS_MASTER;
2466       srv_mode = MODE_SYNCHRONOUS_SLAVE;
2467       break;
2468     case MODE_SYNCHRONOUS_SLAVE:
2469       drv_mode = ARM_USART_MODE_SYNCHRONOUS_SLAVE;
2470       srv_mode = MODE_SYNCHRONOUS_MASTER;
2471       break;
2472     case MODE_SINGLE_WIRE:
2473       drv_mode = ARM_USART_MODE_SINGLE_WIRE;
2474       srv_mode = MODE_SINGLE_WIRE;
2475       break;
2476     case MODE_IRDA:
2477       drv_mode = ARM_USART_MODE_IRDA;
2478       srv_mode = MODE_IRDA;
2479       break;
2480     case MODE_SMART_CARD:
2481       TEST_FAIL_MESSAGE("[FAILED] Smart Card mode testing not supported! Data exchange operation aborted!");
2482       return;
2483     default:
2484       TEST_FAIL_MESSAGE("[FAILED] Unknown mode! Data exchange operation aborted!");
2485       return;
2486   }
2487
2488   switch (data_bits) {
2489     case 5U:
2490       drv_data_bits = ARM_USART_DATA_BITS_5;
2491       break;
2492     case 6U:
2493       drv_data_bits = ARM_USART_DATA_BITS_6;
2494       break;
2495     case 7U:
2496       drv_data_bits = ARM_USART_DATA_BITS_7;
2497       break;
2498     case 8U:
2499       drv_data_bits = ARM_USART_DATA_BITS_8;
2500       break;
2501     case 9U:
2502       drv_data_bits = ARM_USART_DATA_BITS_9;
2503       break;
2504     default:
2505       TEST_FAIL_MESSAGE("[FAILED] Data bits not in range 5 to 9! Data exchange operation aborted!");
2506       return;
2507   }
2508
2509   switch (parity) {
2510     case PARITY_NONE:
2511       drv_parity = ARM_USART_PARITY_NONE;
2512       break;
2513     case PARITY_EVEN:
2514       drv_parity = ARM_USART_PARITY_EVEN;
2515       break;
2516     case PARITY_ODD:
2517       drv_parity = ARM_USART_PARITY_ODD;
2518       break;
2519     default:
2520       TEST_FAIL_MESSAGE("[FAILED] Unknown parity! Data exchange operation aborted!");
2521       return;
2522   }
2523
2524   switch (stop_bits) {
2525     case STOP_BITS_1:
2526       drv_stop_bits = ARM_USART_STOP_BITS_1;
2527       break;
2528     case STOP_BITS_2:
2529       drv_stop_bits = ARM_USART_STOP_BITS_2;
2530       break;
2531     case STOP_BITS_1_5:
2532       drv_stop_bits = ARM_USART_STOP_BITS_1_5;
2533       break;
2534     case STOP_BITS_0_5:
2535       drv_stop_bits = ARM_USART_STOP_BITS_0_5;
2536       break;
2537     default:
2538       TEST_FAIL_MESSAGE("[FAILED] Unknown stop bits! Data exchange operation aborted!");
2539       return;
2540   }
2541
2542   switch (flow_control) {
2543     case FLOW_CONTROL_NONE:
2544       drv_flow_control = ARM_USART_FLOW_CONTROL_NONE;
2545       srv_flow_control = FLOW_CONTROL_NONE;
2546       break;
2547     case FLOW_CONTROL_CTS:
2548       drv_flow_control = ARM_USART_FLOW_CONTROL_CTS;
2549       srv_flow_control = FLOW_CONTROL_RTS;
2550       break;
2551     case FLOW_CONTROL_RTS:
2552       drv_flow_control = ARM_USART_FLOW_CONTROL_RTS;
2553       srv_flow_control = FLOW_CONTROL_CTS;
2554       break;
2555     case FLOW_CONTROL_RTS_CTS:
2556       drv_flow_control = ARM_USART_FLOW_CONTROL_RTS_CTS;
2557       srv_flow_control = FLOW_CONTROL_RTS_CTS;
2558       break;
2559     default:
2560       TEST_FAIL_MESSAGE("[FAILED] Unknown flow control! Data exchange operation aborted!");
2561       return;
2562   }
2563
2564   switch (cpol) {
2565     case CPOL0:
2566       drv_cpol = ARM_USART_CPOL0;
2567       break;
2568     case CPOL1:
2569       drv_cpol = ARM_USART_CPOL1;
2570       break;
2571     default:
2572       TEST_FAIL_MESSAGE("[FAILED] Unknown clock polarity! Data exchange operation aborted!");
2573       return;
2574   }
2575
2576   switch (cpha) {
2577     case CPHA0:
2578       drv_cpha = ARM_USART_CPHA0;
2579       break;
2580     case CPHA1:
2581       drv_cpha = ARM_USART_CPHA1;
2582       break;
2583     default:
2584       TEST_FAIL_MESSAGE("[FAILED] Unknown clock phase! Data exchange operation aborted!");
2585       return;
2586   }
2587
2588   // Total transfer timeout (10 ms is overhead before transfer starts)
2589   timeout = USART_CFG_XFER_TIMEOUT + 10U;
2590
2591   // Check that USART status is not busy before starting data exchange test
2592   usart_stat = drv->GetStatus();        // Get USART status
2593   if (usart_stat.tx_busy != 0U) {
2594     // If tx_busy flag is active
2595     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy active before operation! Data exchange operation aborted!");
2596   }
2597   TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
2598   if (usart_stat.rx_busy != 0U) {
2599     // If rx_busy flag is active
2600     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy active before operation! Data exchange operation aborted!");
2601   }
2602   TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
2603   if (usart_stat.tx_busy != 0U) {
2604     return;                             // If tx busy is active abort data exchange operation
2605   }
2606   if (usart_stat.rx_busy != 0U) {
2607     return;                             // If rx busy is active abort data exchange operation
2608   }
2609
2610   do {
2611 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
2612     if (CmdSetBufTx('S')   != EXIT_SUCCESS) { break; }
2613     if (CmdSetBufRx('?')   != EXIT_SUCCESS) { break; }
2614     if (CmdSetCom  (srv_mode, data_bits, parity, stop_bits, srv_flow_control, cpol, cpha, baudrate) != EXIT_SUCCESS) { break; }
2615     if (CmdXfer    (srv_dir, num, srv_delay, USART_CFG_XFER_TIMEOUT, 0U) != EXIT_SUCCESS) { break; }
2616 #else                                   // If Test Mode Loopback is selected
2617     // Remove warnings for unused variables
2618     (void)srv_mode;
2619     (void)srv_dir;
2620     (void)srv_flow_control;
2621     (void)srv_delay;
2622 #endif
2623     start_tick = osKernelGetTickCount();
2624
2625     // Initialize buffers
2626     memset(ptr_tx_buf,  (int32_t)'!' , USART_BUF_MAX);
2627     memset(ptr_tx_buf,  (int32_t)'T' , num * DataBitsToBytes(data_bits));
2628     memset(ptr_rx_buf,  (int32_t)'?' , USART_BUF_MAX);
2629     memset(ptr_cmp_buf, (int32_t)'?' , USART_BUF_MAX);
2630
2631     // Configure required communication settings
2632     (void)osDelay(drv_delay);           // Wait specified time before calling Control function
2633     stat = drv->Control (drv_mode | drv_data_bits | drv_parity | drv_stop_bits | drv_flow_control | drv_cpol | drv_cpha, baudrate);
2634
2635     if (stat != ARM_DRIVER_OK) {
2636       // If configuration has failed
2637       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Control function returned", str_ret[-stat]);
2638     }
2639     // Assert that Control function returned ARM_DRIVER_OK
2640     TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2641
2642     if (stat != ARM_DRIVER_OK) {
2643       // If control function has failed means driver does not support requested settings
2644       // wait for timeout and exit
2645       (void)osDelay(timeout+20U);       // Wait for USART Server to timout XFER and start reception of next command
2646       return;                                   // Here Abort test is finished, exit
2647     }
2648
2649     // Set default 3/16 bit IrDA pulse period (only for IrDA mode)
2650     if (mode == MODE_IRDA) {
2651       stat = drv->Control (ARM_USART_SET_IRDA_PULSE, 0U);
2652       if ((stat != ARM_DRIVER_OK) && (stat != ARM_DRIVER_ERROR_UNSUPPORTED)) {
2653         // If set IrDA pulse has failed
2654         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s", str_oper[operation], "Set IrDA pulse value returned", str_ret[-stat]);
2655       }
2656       // Assert that Control function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED
2657       TEST_ASSERT_MESSAGE((stat == ARM_DRIVER_OK) || (stat == ARM_DRIVER_ERROR_UNSUPPORTED), msg_buf);
2658
2659       if (stat == ARM_DRIVER_ERROR_UNSUPPORTED) {
2660         // If set IrDA pulse value is not supported
2661         (void)snprintf(msg_buf, sizeof(msg_buf), "[WARNING] %s: %s", str_oper[operation], "Set default IrDA pulse value is not supported");
2662         TEST_MESSAGE(msg_buf);
2663       }
2664     }
2665
2666     // Set default Tx value to 'D' byte values (only for synchronous mode)
2667     if ((mode == MODE_SYNCHRONOUS_MASTER) || (mode == MODE_SYNCHRONOUS_SLAVE)) {
2668       val = ((uint32_t)'D' << 24) | ((uint32_t)'D' << 16) | ((uint32_t)'D' << 8) | (uint32_t)'D';
2669       stat = drv->Control (ARM_USART_SET_DEFAULT_TX_VALUE, val);
2670       def_tx_stat = stat;
2671       if ((stat != ARM_DRIVER_OK) && (stat != ARM_DRIVER_ERROR_UNSUPPORTED)) {
2672         // If set default Tx value has failed
2673         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s", str_oper[operation], "Set default Tx value returned", str_ret[-stat]);
2674       }
2675       // Assert that Control function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED
2676       TEST_ASSERT_MESSAGE((stat == ARM_DRIVER_OK) || (stat == ARM_DRIVER_ERROR_UNSUPPORTED), msg_buf);
2677
2678       if (stat == ARM_DRIVER_ERROR_UNSUPPORTED) {
2679         // If set default Tx value is not supported
2680         (void)snprintf(msg_buf, sizeof(msg_buf), "[WARNING] %s: %s", str_oper[operation], "Set default Tx value is not supported");
2681         TEST_MESSAGE(msg_buf);
2682       }
2683     } else {
2684       // For slave mode default Tx is not tested
2685       def_tx_stat = ARM_DRIVER_ERROR_UNSUPPORTED;
2686     }
2687
2688     // Prepare local variables
2689     event             = 0U;
2690     duration          = 0xFFFFFFFFUL;
2691     tx_count          = 0U;
2692     rx_count          = 0U;
2693     tx_count_sample   = 0U;
2694     rx_count_sample   = 0U;
2695     chk_tx_data       = 0U;
2696     chk_rx_data       = 0U;
2697     start_cnt         = osKernelGetSysTimerCount();
2698
2699     // Start the data exchange operation
2700     switch (operation & 0x0FU) {
2701       case OP_SEND:
2702       case OP_ABORT_SEND:
2703         stat = drv->Control(ARM_USART_CONTROL_TX, 1U);
2704         if (stat != ARM_DRIVER_OK) {
2705           // If transmitter enable has failed
2706           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transmitter enable returned", str_ret[-stat]);
2707         }
2708 #if (USART_SERVER_USED == 1)                            // If Test Mode USART Server is selected
2709         chk_tx_data = 1U;                               // Check sent data
2710 #endif
2711         stat = drv->Send(ptr_tx_buf, num);
2712         if (stat != ARM_DRIVER_OK) {
2713           // If Send activation has failed
2714           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Send function returned", str_ret[-stat]);
2715         }
2716         // Assert that Send function returned ARM_DRIVER_OK
2717         TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2718         break;
2719       case OP_RECEIVE:
2720       case OP_ABORT_RECEIVE:
2721         stat = drv->Control(ARM_USART_CONTROL_RX, 1U);
2722         if (stat != ARM_DRIVER_OK) {
2723           // If receiver enable has failed
2724           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receiver enable returned", str_ret[-stat]);
2725         }
2726 #if (USART_SERVER_USED == 1)                            // If Test Mode USART Server is selected
2727         chk_rx_data = 1U;                               // Check received data
2728 #endif
2729         stat = drv->Receive(ptr_rx_buf, num);
2730         if (stat != ARM_DRIVER_OK) {
2731           // If Receive activation has failed
2732           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receive function returned", str_ret[-stat]);
2733         }
2734         // Assert that Receive function returned ARM_DRIVER_OK
2735         TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2736         break;
2737       case OP_TRANSFER:
2738       case OP_ABORT_TRANSFER:
2739         stat = drv->Control(ARM_USART_CONTROL_TX, 1U);
2740         if (stat != ARM_DRIVER_OK) {
2741           // If transmitter enable has failed
2742           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transmitter enable returned", str_ret[-stat]);
2743         }
2744         stat = drv->Control(ARM_USART_CONTROL_RX, 1U);
2745         if (stat != ARM_DRIVER_OK) {
2746           // If receiver enable has failed
2747           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receiver enable returned", str_ret[-stat]);
2748         }
2749         chk_tx_data = 1U;                               // Check sent data
2750         chk_rx_data = 1U;                               // Check received data
2751         stat = drv->Transfer(ptr_tx_buf, ptr_rx_buf, num);
2752         if (stat != ARM_DRIVER_OK) {
2753           // If Transfer activation has failed
2754           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transfer function returned", str_ret[-stat]);
2755         }
2756         // Assert that Transfer function returned ARM_DRIVER_OK
2757         TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2758         break;
2759       case OP_RECEIVE_SEND_LB:
2760         stat = drv->Control(ARM_USART_CONTROL_TX, 1U);
2761         if (stat != ARM_DRIVER_OK) {
2762           // If transmitter enable has failed
2763           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transmitter enable returned", str_ret[-stat]);
2764         }
2765         stat = drv->Control(ARM_USART_CONTROL_RX, 1U);
2766         if (stat != ARM_DRIVER_OK) {
2767           // If receiver enable has failed
2768           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receiver enable returned", str_ret[-stat]);
2769         }
2770         chk_rx_data = 1U;                               // Check received data
2771         stat = drv->Receive(ptr_rx_buf, num);
2772         if (stat != ARM_DRIVER_OK) {
2773           // If Receive activation has failed
2774           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receive function returned", str_ret[-stat]);
2775         }
2776         // Assert that Receive function returned ARM_DRIVER_OK
2777         TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2778         chk_tx_data = 1U;                               // Check sent data
2779         stat = drv->Send(ptr_tx_buf, num);
2780         if (stat != ARM_DRIVER_OK) {
2781           // If Send activation has failed
2782           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Send function returned", str_ret[-stat]);
2783         }
2784         // Assert that Send function returned ARM_DRIVER_OK
2785         TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2786         break;
2787       default:
2788         TEST_FAIL_MESSAGE("[FAILED] Unknown operation! Data exchange operation aborted!");
2789         return;
2790     }
2791
2792     if ((operation == OP_ABORT_SEND)     ||     // This IF block tests only abort functionality
2793         (operation == OP_ABORT_RECEIVE)  ||
2794         (operation == OP_ABORT_TRANSFER)) {
2795       (void)osDelay(1U);                        // Wait short time before doing Abort
2796       switch (operation & 0x0FU) {
2797         case OP_ABORT_SEND:
2798           stat = drv->Control (ARM_USART_ABORT_SEND, 0U);
2799           break;
2800         case OP_ABORT_RECEIVE:
2801           stat = drv->Control (ARM_USART_ABORT_RECEIVE, 0U);
2802           break;
2803         case OP_ABORT_TRANSFER:
2804           stat = drv->Control (ARM_USART_ABORT_TRANSFER, 0U);
2805           break;
2806       }
2807       if (stat != ARM_DRIVER_OK) {
2808         // If Abort has failed
2809         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s", str_oper[operation], "Control function returned", str_ret[-stat]);
2810       }
2811       // Assert that Control function returned ARM_DRIVER_OK
2812       TEST_ASSERT_MESSAGE(stat == ARM_DRIVER_OK, msg_buf);
2813       usart_stat = drv->GetStatus();            // Get USART status
2814       if (usart_stat.tx_busy != 0U) {
2815         // If tx_busy flag is still active
2816         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy still active after Abort");
2817       }
2818       // Assert that tx_busy flag is not active
2819       TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
2820       if (usart_stat.rx_busy != 0U) {
2821         // If rx_busy flag is still active
2822         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy still active after Abort");
2823       }
2824       // Assert that rx_busy flag is not active
2825       TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
2826
2827       if ((operation == OP_ABORT_SEND) || (operation == OP_ABORT_TRANSFER)) {
2828         tx_count = drv->GetTxCount();         // Get Tx count
2829         if (tx_count >= num) {
2830           // If Tx count is more or equal to number of items then Abort has failed
2831           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetTxCount returned", tx_count, "after Abort of", num, "items");
2832         }
2833         // Assert data count is less then number of items requested for send/transfer
2834         TEST_ASSERT_MESSAGE(tx_count < num, msg_buf);
2835       }
2836       if ((operation == OP_ABORT_RECEIVE) || (operation == OP_ABORT_TRANSFER)) {
2837         rx_count = drv->GetRxCount();         // Get Rx count
2838         if (rx_count >= num) {
2839           // If Rx count is more or equal to number of items then Abort has failed
2840           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetRxCount returned", rx_count, "after Abort of", num, "items");
2841         }
2842         // Assert data count is less then number of items requested for receive/transfer
2843         TEST_ASSERT_MESSAGE(rx_count < num, msg_buf);
2844       }
2845
2846       stat = drv->Control(ARM_USART_CONTROL_TX, 0U);
2847       if (stat != ARM_DRIVER_OK) {
2848         // If transmitter disable has failed
2849         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transmitter disable returned", str_ret[-stat]);
2850       }
2851       stat = drv->Control(ARM_USART_CONTROL_RX, 0U);
2852       if (stat != ARM_DRIVER_OK) {
2853         // If receiver disable has failed
2854         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receiver disable returned", str_ret[-stat]);
2855       }
2856
2857 #if (USART_SERVER_USED == 1)                            // If Test Mode USART Server is selected
2858       // Wait until timeout expires
2859       curr_tick = osKernelGetTickCount();
2860       if ((curr_tick - start_tick) < timeout) {
2861         (void)osDelay(timeout - (curr_tick - start_tick));
2862       }
2863       (void)osDelay(20U);                       // Wait for USART Server to start reception of next command
2864 #endif
2865
2866       return;                                   // Here Abort test is finished, exit
2867     }
2868
2869     // Wait for operation to finish
2870     // for send operation wait until status tx_busy is 0 and 
2871     // event ARM_USART_EVENT_SEND_COMPLETE is signaled, or timeout
2872     // for receive operation wait until status rx_busy is 0 and 
2873     // event ARM_USART_EVENT_RECEIVE_COMPLETE is signaled, or timeout
2874     // for transfer operation wait until status tx_busy and rx_busy is 0 and 
2875     // event ARM_USART_EVENT_TRANSFER_COMPLETE is signaled, or timeout
2876     // for receive and send operation wait until status tx_busy and rx_busy is 0 and 
2877     // both events ARM_USART_EVENT_SEND_COMPLETE and ARM_USART_EVENT_RECEIVE_COMPLETE are signaled, or timeout
2878     do {
2879       if (operation == OP_SEND) {
2880         if (tx_count_sample == 0U) {
2881           // Store first Tx count different than 0
2882           tx_count_sample = drv->GetTxCount();  // Get Tx count
2883         }
2884         if ((drv->GetStatus().tx_busy == 0U) && ((event & ARM_USART_EVENT_SEND_COMPLETE) != 0U)) {
2885           duration = osKernelGetSysTimerCount() - start_cnt;
2886           break;
2887         }
2888       }
2889       if (operation == OP_RECEIVE) {
2890         if (rx_count_sample == 0U) {
2891           // Store first Rx count different than 0
2892           rx_count_sample = drv->GetRxCount();  // Get Rx count
2893         }
2894         if ((drv->GetStatus().rx_busy == 0U) && ((event & ARM_USART_EVENT_RECEIVE_COMPLETE) != 0U)) {
2895           duration = osKernelGetSysTimerCount() - start_cnt;
2896           break;
2897         }
2898       }
2899       if (operation == OP_TRANSFER) {
2900         if (tx_count_sample == 0U) {
2901           // Store first Tx count different than 0
2902           tx_count_sample = drv->GetTxCount();  // Get Tx count
2903         }
2904         if (rx_count_sample == 0U) {
2905           // Store first Rx count different than 0
2906           rx_count_sample = drv->GetRxCount();  // Get Rx count
2907         }
2908         if ((drv->GetStatus().tx_busy == 0U) && (drv->GetStatus().rx_busy == 0U) && ((event & ARM_USART_EVENT_TRANSFER_COMPLETE) != 0U)) {
2909           duration = osKernelGetSysTimerCount() - start_cnt;
2910           break;
2911         }
2912       }
2913       if (operation == OP_RECEIVE_SEND_LB) {
2914         if (tx_count_sample == 0U) {
2915           // Store first Tx count different than 0
2916           tx_count_sample = drv->GetTxCount();  // Get Tx count
2917         }
2918         if (rx_count_sample == 0U) {
2919           // Store first Rx count different than 0
2920           rx_count_sample = drv->GetRxCount();  // Get Rx count
2921         }
2922         if ((drv->GetStatus().tx_busy == 0U) && (drv->GetStatus().rx_busy == 0U) && 
2923            ((event & (ARM_USART_EVENT_RECEIVE_COMPLETE | ARM_USART_EVENT_SEND_COMPLETE)) == 
2924                      (ARM_USART_EVENT_RECEIVE_COMPLETE | ARM_USART_EVENT_SEND_COMPLETE))) {
2925           duration = osKernelGetSysTimerCount() - start_cnt;
2926           break;
2927         }
2928       }
2929     } while ((osKernelGetTickCount() - start_tick) < timeout);
2930
2931     if (duration == 0xFFFFFFFFUL) {
2932       // If operation has timed out
2933       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Operation timed out");
2934     }
2935     // Assert that operation has finished in expected time
2936     TEST_ASSERT_MESSAGE(duration != 0xFFFFFFFFUL, msg_buf);
2937
2938     if (duration != 0xFFFFFFFFUL) {
2939       // For Synchronous Slave duration is started by Master srv_delay later so this has to be deducted
2940       if (mode == MODE_SYNCHRONOUS_SLAVE) {
2941         if (srv_delay > 1U) {
2942           srv_delay --;                 // Reduce 1 ms tolerance of delay
2943           if (duration > (srv_delay * (systick_freq / 1000U))) {
2944             duration -= srv_delay * (systick_freq / 1000U);
2945           }
2946         }
2947       }
2948     }
2949
2950     // Check all expected conditions after Send operation
2951     if (operation == OP_SEND) {
2952       if ((event & ARM_USART_EVENT_SEND_COMPLETE) == 0U) {
2953         // If send complete event was not signaled
2954         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_SEND_COMPLETE was not signaled");
2955         chk_tx_data = 0U;                       // Do not check sent content
2956       }
2957       // Assert that ARM_USART_EVENT_SEND_COMPLETE was signaled
2958       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_SEND_COMPLETE) != 0U, msg_buf);
2959
2960       if (drv_cap.event_tx_complete != 0U) {
2961         // If driver supports Tx complete signaling
2962         if ((event & ARM_USART_EVENT_TX_COMPLETE) == 0U) {
2963           // If Tx complete event was not signaled
2964           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TX_COMPLETE was not signaled");
2965           chk_tx_data = 0U;                       // Do not check sent content
2966         }
2967         // Assert that ARM_USART_EVENT_TX_COMPLETE was signaled
2968         TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TX_COMPLETE) != 0U, msg_buf);
2969       }
2970
2971       usart_stat = drv->GetStatus();            // Get USART status
2972       if (usart_stat.tx_busy != 0U) {
2973         // If tx_busy flag is still active
2974         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy still active after operation");
2975         chk_tx_data = 0U;                       // Do not check sent content
2976       }
2977       // Assert that tx_busy flag is not active
2978       TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
2979
2980       tx_count = drv->GetTxCount();             // Get Tx count
2981       if (tx_count != num) {
2982         // If Tx count is different then number of items, then operation has failed
2983         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetTxCount returned", tx_count, "expected was", num, "items");
2984         chk_tx_data = 0U;                       // Do not check sent content
2985       }
2986       // Assert that Tx count is equal to number of items requested for send
2987       TEST_ASSERT_MESSAGE(tx_count == num, msg_buf);
2988
2989       if ((drv->GetStatus().tx_busy != 0U) || ((event & ARM_USART_EVENT_SEND_COMPLETE) == 0U)) {
2990         // If send did not finish in time, abort it
2991         (void)drv->Control(ARM_USART_ABORT_SEND, 0U);
2992       }
2993     }
2994
2995     // Check all expected conditions after Receive operation
2996     if (operation == OP_RECEIVE) {
2997       if ((event & ARM_USART_EVENT_RECEIVE_COMPLETE) == 0U) {
2998         // If receive complete event was not signaled
2999         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_RECEIVE_COMPLETE was not signaled");
3000         chk_rx_data = 0U;                       // Do not check received content
3001       }
3002       // Assert that ARM_USART_EVENT_RECEIVE_COMPLETE was signaled
3003       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RECEIVE_COMPLETE) != 0U, msg_buf);
3004
3005       usart_stat = drv->GetStatus();            // Get USART status
3006       if (usart_stat.rx_busy != 0U) {
3007         // If rx_busy flag is still active
3008         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy still active after operation");
3009         chk_rx_data = 0U;                       // Do not check received content
3010       }
3011       // Assert that rx_busy flag is not active
3012       TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
3013
3014       if ((event & ARM_USART_EVENT_RX_OVERFLOW) != 0U) {
3015         // If Rx overflow was signaled during the transfer
3016         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_RX_OVERFLOW was signaled");
3017         chk_rx_data = 0U;                       // Do not check received content
3018       }
3019       // Assert that ARM_USART_EVENT_RX_OVERFLOW was not signaled
3020       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_OVERFLOW) == 0U, msg_buf);
3021
3022       rx_count = drv->GetRxCount();             // Get Rx count
3023       if (rx_count != num) {
3024         // If Rx count is different then number of items, then operation has failed
3025         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetRxCount returned", rx_count, "expected was", num, "items");
3026         chk_rx_data = 0U;                       // Do not check received content
3027       }
3028       // Assert that Rx count is equal to number of items requested for reception
3029       TEST_ASSERT_MESSAGE(rx_count == num, msg_buf);
3030
3031       if ((drv->GetStatus().rx_busy != 0U) || ((event & ARM_USART_EVENT_RECEIVE_COMPLETE) == 0U)) {
3032         // If reception did not finish in time, abort it
3033         (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
3034       }
3035     }
3036
3037     // Check all expected conditions after Transfer operation
3038     if (operation == OP_TRANSFER) {
3039       if ((event & ARM_USART_EVENT_TRANSFER_COMPLETE) == 0U) {
3040         // If transfer complete event was not signaled
3041         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TRANSFER_COMPLETE was not signaled");
3042         chk_tx_data = 0U;                       // Do not check sent content
3043         chk_rx_data = 0U;                       // Do not check received content
3044       }
3045       // Assert that ARM_USART_EVENT_TRANSFER_COMPLETE was signaled
3046       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TRANSFER_COMPLETE) != 0U, msg_buf);
3047
3048       usart_stat = drv->GetStatus();            // Get USART status
3049       if (usart_stat.tx_busy != 0U) {
3050         // If tx_busy flag is still active
3051         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy still active after operation");
3052         chk_tx_data = 0U;                       // Do not check sent content
3053       }
3054       // Assert that tx_busy flag is not active
3055       TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
3056       if (usart_stat.rx_busy != 0U) {
3057         // If rx_busy flag is still active
3058         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy still active after operation");
3059         chk_rx_data = 0U;                       // Do not check received content
3060       }
3061       // Assert that rx_busy flag is not active
3062       TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
3063
3064       if ((event & ARM_USART_EVENT_TX_UNDERFLOW) != 0U) {
3065         // If Tx underflow was signaled during the transfer
3066         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TX_UNDERFLOW was signaled");
3067         chk_tx_data = 0U;                       // Do not check sent content
3068       }
3069       // Assert that ARM_USART_EVENT_TX_UNDERFLOW was not signaled
3070       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TX_UNDERFLOW) == 0U, msg_buf);
3071
3072       if ((event & ARM_USART_EVENT_RX_OVERFLOW) != 0U) {
3073         // If Rx overflow was signaled during the transfer
3074         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TX_UNDERFLOW was signaled");
3075         chk_rx_data = 0U;                       // Do not check received content
3076       }
3077       // Assert that ARM_USART_EVENT_RX_OVERFLOW was not signaled
3078       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_OVERFLOW) == 0U, msg_buf);
3079
3080       tx_count = drv->GetTxCount();             // Get Tx count
3081       if (tx_count != num) {
3082         // If Tx count is different then number of items, then operation has failed
3083         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetTxCount returned", tx_count, "expected was", num, "items");
3084         chk_tx_data = 0U;                            // Do not check sent content
3085       }
3086       // Assert that Tx count is equal to number of items requested for transfer
3087       TEST_ASSERT_MESSAGE(tx_count == num, msg_buf);
3088
3089       rx_count = drv->GetRxCount();             // Get Rx count
3090       if (rx_count != num) {
3091         // If Rx count is different then number of items, then operation has failed
3092         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetRxCount returned", rx_count, "expected was", num, "items");
3093         chk_rx_data = 0U;                            // Do not check received content
3094       }
3095       // Assert that Rx count is equal to number of items requested for transfer
3096       TEST_ASSERT_MESSAGE(rx_count == num, msg_buf);
3097
3098       if ((drv->GetStatus().tx_busy != 0U) || (drv->GetStatus().rx_busy != 0U) || 
3099          ((event & ARM_USART_EVENT_TRANSFER_COMPLETE) == 0U)) {
3100         // If transfer did not finish in time, abort it
3101         (void)drv->Control(ARM_USART_ABORT_TRANSFER, 0U);
3102       }
3103     }
3104
3105     stat = drv->Control(ARM_USART_CONTROL_TX, 0U);
3106     if (stat != ARM_DRIVER_OK) {
3107       // If transmitter disable has failed
3108       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Transmitter disable returned", str_ret[-stat]);
3109     }
3110     stat = drv->Control(ARM_USART_CONTROL_RX, 0U);
3111     if (stat != ARM_DRIVER_OK) {
3112       // If receiver disable has failed
3113       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %s! Data exchange operation aborted!", str_oper[operation], "Receiver disable returned", str_ret[-stat]);
3114     }
3115
3116 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
3117
3118     // Wait until timeout expires
3119     curr_tick = osKernelGetTickCount();
3120     if ((curr_tick - start_tick) < timeout) {
3121       (void)osDelay(timeout - (curr_tick - start_tick));
3122     }
3123     (void)osDelay(20U);                 // Wait for USART Server to start reception of next command
3124
3125     if (chk_rx_data != 0U) {            // If received content should be checked
3126       // Check received content
3127       memset(ptr_cmp_buf, (int32_t)'S', num * DataBitsToBytes(data_bits));
3128       if (data_bits == 9U) {
3129         // If 9-bit mode is used zero out unused bits in high byte
3130         for (i = 1U; i < num * 2U; i += 2U) {
3131           ptr_cmp_buf[i] &= 0x01U;
3132         }
3133       }
3134       stat = memcmp(ptr_rx_buf, ptr_cmp_buf, num * DataBitsToBytes(data_bits));
3135       if (stat != 0) {
3136         // If data received mismatches
3137         // Find on which byte mismatch starts
3138         for (i = 0U; i < (num * DataBitsToBytes(data_bits)); i++) {
3139           if (ptr_rx_buf[i] != ptr_cmp_buf[i]) {
3140             break;
3141           }
3142         }
3143         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s byte %i, received was 0x%02X, expected was 0x%02X", str_oper[operation], "Received data mismatches on", i, ptr_rx_buf[i], ptr_cmp_buf[i]);
3144       }
3145       // Assert that data received is same as expected
3146       TEST_ASSERT_MESSAGE(stat == 0, msg_buf);
3147     }
3148
3149     if (chk_tx_data != 0U) {            // If sent content should be checked
3150       // Check sent content (by checking USART Server's received buffer content)
3151       if (ComConfigDefault()         != EXIT_SUCCESS) { break; }
3152       if (CmdGetBufRx(USART_BUF_MAX) != EXIT_SUCCESS) { break; }
3153
3154       if ((operation == OP_RECEIVE) && (def_tx_stat == ARM_DRIVER_OK)) {
3155         // Expected data received by USART Server should be default Tx value
3156         memset(ptr_cmp_buf, (int32_t)'D', num * DataBitsToBytes(data_bits));
3157       } else {
3158         // Expected data received by USART Server should be what was sent
3159         memset(ptr_cmp_buf, (int32_t)'T', num * DataBitsToBytes(data_bits));
3160       }
3161       if (data_bits == 9U) {
3162         // If 9-bit mode is used zero out unused bits in high byte
3163         for (i = 1U; i < num * 2U; i += 2U) {
3164           ptr_cmp_buf[i] &= 0x01U;
3165         }
3166       }
3167       stat = memcmp(ptr_rx_buf, ptr_cmp_buf, num * DataBitsToBytes(data_bits));
3168       if (stat != 0) {
3169         // If data sent mismatches
3170         // Find on which byte mismatch starts
3171         for (i = 0U; i < (num * DataBitsToBytes(data_bits)); i++) {
3172           if (ptr_rx_buf[i] != ptr_cmp_buf[i]) {
3173             break;
3174           }
3175         }
3176         if (operation == OP_RECEIVE) {
3177           // If sent was default Tx value, 'D' bytes
3178           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s byte %i, USART Server received 0x%02X, sent was 0x%02X", str_oper[operation], "Default Tx data mismatches on", i, ptr_rx_buf[i], ptr_cmp_buf[i]);
3179         } else {
3180           // If sent was 'T' bytes
3181           (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s byte %i, USART Server received 0x%02X, sent was 0x%02X", str_oper[operation], "Sent data mismatches on", i, ptr_rx_buf[i], ptr_cmp_buf[i]);
3182         }
3183       }
3184       // Assert data sent is same as expected
3185       TEST_ASSERT_MESSAGE(stat == 0, msg_buf);
3186     }
3187
3188 #else                                   // If Test Mode Loopback is selected
3189
3190     // Check all expected conditions after Receive and Send operation (in Loopback Test Mode)
3191     if (operation == OP_RECEIVE_SEND_LB) {
3192       if ((event & ARM_USART_EVENT_SEND_COMPLETE) == 0U) {
3193         // If send complete event was not signaled
3194         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_SEND_COMPLETE was not signaled");
3195         chk_tx_data = 0U;                       // Do not check sent content
3196       }
3197       // Assert that ARM_USART_EVENT_SEND_COMPLETE was signaled
3198       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_SEND_COMPLETE) != 0U, msg_buf);
3199       if ((event & ARM_USART_EVENT_RECEIVE_COMPLETE) == 0U) {
3200         // If receive complete event was not signaled
3201         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_RECEIVE_COMPLETE was not signaled");
3202         chk_rx_data = 0U;                       // Do not check received content
3203       }
3204       // Assert that ARM_USART_EVENT_RECEIVE_COMPLETE was signaled
3205       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RECEIVE_COMPLETE) != 0U, msg_buf);
3206
3207       usart_stat = drv->GetStatus();            // Get USART status
3208       if (usart_stat.tx_busy != 0U) {
3209         // If tx_busy flag is still active
3210         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy still active after operation");
3211         chk_tx_data = 0U;                       // Do not check sent content
3212       }
3213       // Assert that tx_busy flag is not active
3214       TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
3215       if (usart_stat.rx_busy != 0U) {
3216         // If rx_busy flag is still active
3217         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy still active after operation");
3218         chk_rx_data = 0U;                       // Do not check received content
3219       }
3220       // Assert that rx_busy flag is not active
3221       TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
3222
3223       if ((event & ARM_USART_EVENT_TX_UNDERFLOW) != 0U) {
3224         // If Tx underflow was signaled during the transfer
3225         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TX_UNDERFLOW was signaled");
3226         chk_tx_data = 0U;                       // Do not check sent content
3227       }
3228       // Assert that ARM_USART_EVENT_TX_UNDERFLOW was not signaled
3229       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TX_UNDERFLOW) == 0U, msg_buf);
3230
3231       if ((event & ARM_USART_EVENT_RX_OVERFLOW) != 0U) {
3232         // If Rx overflow was signaled during the transfer
3233         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "ARM_USART_EVENT_TX_UNDERFLOW was signaled");
3234         chk_rx_data = 0U;                       // Do not check received content
3235       }
3236       // Assert that ARM_USART_EVENT_RX_OVERFLOW was not signaled
3237       TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_OVERFLOW) == 0U, msg_buf);
3238
3239       tx_count = drv->GetTxCount();             // Get Tx count
3240       if (tx_count != num) {
3241         // If Tx count is different then number of items, then operation has failed
3242         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetTxCount returned", tx_count, "expected was", num, "items");
3243         chk_tx_data = 0U;                            // Do not check sent content
3244       }
3245       // Assert that Tx count is equal to number of items requested for transfer
3246       TEST_ASSERT_MESSAGE(tx_count == num, msg_buf);
3247
3248       rx_count = drv->GetRxCount();             // Get Rx count
3249       if (rx_count != num) {
3250         // If Rx count is different then number of items, then operation has failed
3251         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s %i %s %i %s", str_oper[operation], "GetRxCount returned", rx_count, "expected was", num, "items");
3252         chk_rx_data = 0U;                            // Do not check received content
3253       }
3254       // Assert that Rx count is equal to number of items requested for transfer
3255       TEST_ASSERT_MESSAGE(rx_count == num, msg_buf);
3256
3257       if ((drv->GetStatus().tx_busy == 0U) && (drv->GetStatus().rx_busy == 0U) && 
3258          ((event & (ARM_USART_EVENT_RECEIVE_COMPLETE | ARM_USART_EVENT_SEND_COMPLETE)) == 
3259                    (ARM_USART_EVENT_RECEIVE_COMPLETE | ARM_USART_EVENT_SEND_COMPLETE))) {
3260         // If transfer did not finish in time, abort it
3261         (void)drv->Control(ARM_USART_ABORT_TRANSFER, 0U);
3262       }
3263     }
3264
3265     if ((chk_rx_data != 0U) &&          // If received content should be checked and 
3266         (chk_tx_data != 0U)) {          // if sent content should be checked
3267       stat = memcmp(ptr_rx_buf, ptr_tx_buf, num * DataBitsToBytes(data_bits));
3268       if (stat != 0) {
3269         // If data received mismatches
3270         // Find on which byte mismatch starts
3271         for (i = 0U; i < (num * DataBitsToBytes(data_bits)); i++) {
3272           if (ptr_rx_buf[i] != ptr_cmp_buf[i]) {
3273             break;
3274           }
3275         }
3276         (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s byte %i, received was 0x%02X, sent was 0x%02X", str_oper[operation], "Received data mismatches on", i, ptr_rx_buf[i], ptr_tx_buf[i]);
3277       }
3278       // Assert that data received is same as expected
3279       TEST_ASSERT_MESSAGE(stat == 0, msg_buf);
3280     }
3281 #endif
3282
3283     return;
3284   } while (false);
3285
3286 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
3287   TEST_FAIL_MESSAGE("[FAILED] Problems in communication with USART Server. Test aborted!");
3288 #endif
3289 }
3290
3291 #endif                                  // End of exclude form the documentation
3292
3293 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3294 /**
3295 \brief Function: Function USART_Mode_Asynchronous
3296 \details
3297 The function \b USART_Mode_Asynchronous verifies data exchange:
3298  - in <b>Asynchronous</b> mode
3299  - with default data bits
3300  - with default parity
3301  - with default stop bits
3302  - with default flow control
3303  - at default baudrate
3304  - for default number of data items
3305 */
3306 void USART_Mode_Asynchronous (void) {
3307
3308   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3309   if (SettingsCheck (MODE_ASYNCHRONOUS, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3310
3311 #if (USART_SERVER_USED == 1)
3312   USART_DataExchange_Operation(OP_SEND,            MODE_ASYNCHRONOUS, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3313   USART_DataExchange_Operation(OP_RECEIVE,         MODE_ASYNCHRONOUS, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3314 #else
3315   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, MODE_ASYNCHRONOUS, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3316 #endif
3317 }
3318
3319 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3320 /**
3321 \brief Function: Function USART_Mode_Synchronous_Master
3322 \details
3323 The function \b USART_Mode_Synchronous_Master verifies data exchange:
3324  - in <b>Synchronous Master</b> mode
3325  - with default data bits
3326  - with no parity
3327  - with 1 stop bit
3328  - with no flow control
3329  - with default clock polarity
3330  - with default clock phase
3331  - at default baudrate
3332  - for default number of data items
3333
3334 \note In Test Mode <b>Loopback</b> Receive function is not tested
3335 */
3336 void USART_Mode_Synchronous_Master (void) {
3337
3338   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3339   if (SettingsCheck (MODE_SYNCHRONOUS_MASTER, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3340
3341   USART_DataExchange_Operation(OP_SEND,     MODE_SYNCHRONOUS_MASTER, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3342 #if (USART_SERVER_USED == 1)
3343   USART_DataExchange_Operation(OP_RECEIVE,  MODE_SYNCHRONOUS_MASTER, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3344 #endif
3345   USART_DataExchange_Operation(OP_TRANSFER, MODE_SYNCHRONOUS_MASTER, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3346 }
3347
3348 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3349 /**
3350 \brief Function: Function USART_Mode_Synchronous_Slave
3351 \details
3352 The function \b USART_Mode_Synchronous_Slave verifies data exchange:
3353  - in <b>Synchronous Slave</b> mode
3354  - with default data bits
3355  - with no parity
3356  - with 1 stop bit
3357  - with no flow control
3358  - with default clock polarity
3359  - with default clock phase
3360  - at default baudrate
3361  - for default number of data items
3362
3363 \note In Test Mode <b>Loopback</b> this test is not executed
3364 */
3365 void USART_Mode_Synchronous_Slave (void) {
3366
3367   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3368   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3369   if (SettingsCheck   (MODE_SYNCHRONOUS_SLAVE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3370
3371   USART_DataExchange_Operation(OP_SEND,     MODE_SYNCHRONOUS_SLAVE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3372   USART_DataExchange_Operation(OP_RECEIVE,  MODE_SYNCHRONOUS_SLAVE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3373   USART_DataExchange_Operation(OP_TRANSFER, MODE_SYNCHRONOUS_SLAVE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3374 }
3375
3376 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3377 /**
3378 \brief Function: Function USART_Mode_Single_Wire
3379 \details
3380 The function \b USART_Mode_Single_Wire verifies data exchange:
3381  - in <b>Single-Wire</b> mode
3382  - with default data bits
3383  - with default parity
3384  - with default stop bits
3385  - with no flow control
3386  - at default baudrate
3387  - for default number of data items
3388
3389 \note In Test Mode <b>Loopback</b> this test is not executed
3390 */
3391 void USART_Mode_Single_Wire (void) {
3392
3393   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3394   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3395   if (SettingsCheck   (MODE_SINGLE_WIRE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3396
3397 #if (USART_SERVER_USED == 1)
3398   USART_DataExchange_Operation(OP_SEND,            MODE_SINGLE_WIRE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3399   USART_DataExchange_Operation(OP_RECEIVE,         MODE_SINGLE_WIRE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3400 #else
3401   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, MODE_SINGLE_WIRE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3402 #endif
3403 }
3404
3405 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3406 /**
3407 \brief Function: Function USART_Mode_IrDA
3408 \details
3409 The function \b USART_Mode_IrDA verifies data exchange:
3410  - in <b>Infra-red Data</b> mode
3411  - with default data bits
3412  - with default parity
3413  - with default stop bits
3414  - with default flow control
3415  - at default baudrate
3416  - for default number of data items
3417
3418 \note In Test Mode <b>Loopback</b> this test is not executed
3419 */
3420 void USART_Mode_IrDA (void) {
3421
3422   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3423   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3424   if (SettingsCheck (MODE_IRDA, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3425
3426 #if (USART_SERVER_USED == 1)
3427   USART_DataExchange_Operation(OP_SEND,            MODE_IRDA, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3428   USART_DataExchange_Operation(OP_RECEIVE,         MODE_IRDA, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3429 #else
3430   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, MODE_IRDA, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3431 #endif
3432 }
3433
3434 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3435 /**
3436 \brief Function: Function USART_Data_Bits_5
3437 \details
3438 The function \b USART_Data_Bits_5 verifies data exchange:
3439  - in default mode
3440  - with <b>5 data bits</b>
3441  - with default parity
3442  - with default stop bits
3443  - with default flow control
3444  - with default clock polarity
3445  - with default clock phase
3446  - at default baudrate
3447  - for default number of data items
3448
3449 \note In Test Mode <b>Loopback</b> this test is not executed
3450 */
3451 void USART_Data_Bits_5 (void) {
3452
3453   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3454   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3455   if (SettingsCheck   (USART_CFG_DEF_MODE, 5U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3456
3457   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, 5U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3458   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, 5U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3459 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3460   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, 5U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3461 #endif
3462 }
3463
3464 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3465 /**
3466 \brief Function: Function USART_Data_Bits_6
3467 \details
3468 The function \b USART_Data_Bits_6 verifies data exchange:
3469  - in default mode
3470  - with <b>6 data bits</b>
3471  - with default parity
3472  - with default stop bits
3473  - with default flow control
3474  - with default clock polarity
3475  - with default clock phase
3476  - at default baudrate
3477  - for default number of data items
3478
3479 \note In Test Mode <b>Loopback</b> this test is not executed
3480 */
3481 void USART_Data_Bits_6 (void) {
3482
3483   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3484   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3485   if (SettingsCheck   (USART_CFG_DEF_MODE, 6U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3486
3487   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, 6U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3488   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, 6U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3489 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3490   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, 6U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3491 #endif
3492 }
3493
3494 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3495 /**
3496 \brief Function: Function USART_Data_Bits_7
3497 \details
3498 The function \b USART_Data_Bits_7 verifies data exchange:
3499  - in default mode
3500  - with <b>7 data bits</b>
3501  - with default parity
3502  - with default stop bits
3503  - with default flow control
3504  - with default clock polarity
3505  - with default clock phase
3506  - at default baudrate
3507  - for default number of data items
3508
3509 \note In Test Mode <b>Loopback</b> this test is not executed
3510 */
3511 void USART_Data_Bits_7 (void) {
3512
3513   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3514   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3515   if (SettingsCheck   (USART_CFG_DEF_MODE, 7U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3516
3517   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, 7U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3518   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, 7U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3519 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3520   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, 7U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3521 #endif
3522 }
3523
3524 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3525 /**
3526 \brief Function: Function USART_Data_Bits_8
3527 \details
3528 The function \b USART_Data_Bits_8 verifies data exchange:
3529  - in default mode
3530  - with <b>8 data bits</b>
3531  - with default parity
3532  - with default stop bits
3533  - with default flow control
3534  - with default clock polarity
3535  - with default clock phase
3536  - at default baudrate
3537  - for default number of data items
3538 */
3539 void USART_Data_Bits_8 (void) {
3540
3541   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3542   if (SettingsCheck (USART_CFG_DEF_MODE, 8U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3543
3544 #if (USART_SERVER_USED == 1)
3545   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, 8U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3546   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, 8U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3547 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3548   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, 8U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3549 #endif
3550 #else
3551   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, 8U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3552 #endif
3553 }
3554
3555 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3556 /**
3557 \brief Function: Function USART_Data_Bits_9
3558 \details
3559 The function \b USART_Data_Bits_9 verifies data exchange:
3560  - in default mode
3561  - with <b>9 data bits</b>
3562  - with default parity
3563  - with default stop bits
3564  - with default flow control
3565  - with default clock polarity
3566  - with default clock phase
3567  - at default baudrate
3568  - for default number of data items
3569
3570 \note In Test Mode <b>Loopback</b> this test is not executed
3571 */
3572 void USART_Data_Bits_9 (void) {
3573
3574   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3575   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3576   if (SettingsCheck   (USART_CFG_DEF_MODE, 9U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3577
3578   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, 9U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3579   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, 9U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3580 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3581   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, 9U, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3582 #endif
3583 }
3584
3585 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3586 /**
3587 \brief Function: Function USART_Parity_None
3588 \details
3589 The function \b USART_Parity_None verifies data exchange:
3590  - in default mode
3591  - with default data bits
3592  - with <b>no parity</b>
3593  - with default stop bits
3594  - with default flow control
3595  - with default clock polarity
3596  - with default clock phase
3597  - at default baudrate
3598  - for default number of data items
3599 */
3600 void USART_Parity_None (void) {
3601
3602   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3603   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3604
3605 #if (USART_SERVER_USED == 1)
3606   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3607   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3608 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3609   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3610 #endif
3611 #else
3612   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3613 #endif
3614 }
3615
3616 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3617 /**
3618 \brief Function: Function USART_Parity_Even
3619 \details
3620 The function \b USART_Parity_Even verifies data exchange:
3621  - in default mode
3622  - with default data bits
3623  - with <b>even parity</b>
3624  - with default stop bits
3625  - with default flow control
3626  - at default baudrate
3627  - for default number of data items
3628
3629 \note This test is not executed if any of the following settings are selected:
3630  - Test Mode <b>Loopback</b>
3631  - Tests Default Mode <b>Synchronous Master/Slave</b>
3632 */
3633 void USART_Parity_Even (void) {
3634
3635   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3636   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
3637   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3638   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_EVEN, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3639
3640   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_EVEN, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3641   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_EVEN, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3642 }
3643
3644 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3645 /**
3646 \brief Function: Function USART_Parity_Odd
3647 \details
3648 The function \b USART_Parity_Odd verifies data exchange:
3649  - in default mode
3650  - with default data bits
3651  - with <b>odd parity</b>
3652  - with default stop bits
3653  - with default flow control
3654  - at default baudrate
3655  - for default number of data items
3656
3657 \note This test is not executed if any of the following settings are selected:
3658  - Test Mode <b>Loopback</b>
3659  - Tests Default Mode <b>Synchronous Master/Slave</b>
3660 */
3661 void USART_Parity_Odd (void) {
3662
3663   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3664   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
3665   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3666   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_ODD, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3667
3668   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_ODD, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3669   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_ODD, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3670 }
3671
3672 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3673 /**
3674 \brief Function: Function USART_Stop_Bits_1
3675 \details
3676 The function \b USART_Stop_Bits_1 verifies data exchange:
3677  - in default mode
3678  - with default data bits
3679  - with default parity
3680  - with <b>1 stop bit</b>
3681  - with default flow control
3682  - with default clock polarity
3683  - with default clock phase
3684  - at default baudrate
3685  - for default number of data items
3686 */
3687 void USART_Stop_Bits_1 (void) {
3688
3689   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3690   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3691
3692 #if (USART_SERVER_USED == 1)
3693   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3694   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3695 #if ((USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_MASTER) || (USART_CFG_DEF_MODE == MODE_SYNCHRONOUS_SLAVE))
3696   USART_DataExchange_Operation(OP_TRANSFER,        USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3697 #endif
3698 #else
3699   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3700 #endif
3701 }
3702
3703 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3704 /**
3705 \brief Function: Function USART_Stop_Bits_2
3706 \details
3707 The function \b USART_Stop_Bits_2 verifies data exchange:
3708  - in default mode
3709  - with default data bits
3710  - with default parity
3711  - with <b>2 stop bits</b>
3712  - with default flow control
3713  - at default baudrate
3714  - for default number of data items
3715
3716 \note This test is not executed if any of the following settings are selected:
3717  - Test Mode <b>Loopback</b>
3718  - Tests Default Mode <b>Synchronous Master/Slave</b>
3719 */
3720 void USART_Stop_Bits_2 (void) {
3721
3722   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3723   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
3724   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3725   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_2, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3726
3727   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_2, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3728   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_2, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3729 }
3730
3731 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3732 /**
3733 \brief Function: Function USART_Stop_Bits_1_5
3734 \details
3735 The function \b USART_Stop_Bits_1_5 verifies data exchange:
3736  - in default mode
3737  - with default data bits
3738  - with default parity
3739  - with <b>1.5 stop bits</b>
3740  - with default flow control
3741  - at default baudrate
3742  - for default number of data items
3743
3744 \note This test is not executed if any of the following settings are selected:
3745  - Test Mode <b>Loopback</b>
3746  - Tests Default Mode <b>Synchronous Master/Slave</b>
3747 */
3748 void USART_Stop_Bits_1_5 (void) {
3749
3750   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3751   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
3752   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3753   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1_5, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3754
3755   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1_5, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3756   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_1_5, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3757 }
3758
3759 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3760 /**
3761 \brief Function: Function USART_Stop_Bits_0_5
3762 \details
3763 The function \b USART_Stop_Bits_0_5 verifies data exchange:
3764  - in default mode
3765  - with default data bits
3766  - with default parity
3767  - with <b>0.5 stop bits</b>
3768  - with default flow control
3769  - at default baudrate
3770  - for default number of data items
3771
3772 \note This test is not executed if any of the following settings are selected:
3773  - Test Mode <b>Loopback</b>
3774  - Tests Default Mode <b>Synchronous Master/Slave</b>
3775 */
3776 void USART_Stop_Bits_0_5 (void) {
3777
3778   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3779   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
3780   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
3781   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_0_5, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3782
3783   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_0_5, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3784   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, STOP_BITS_0_5, USART_CFG_DEF_FLOW_CONTROL, 0U, 0U, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3785 }
3786
3787 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3788 /**
3789 \brief Function: Function USART_Flow_Control_None
3790 \details
3791 The function \b USART_Flow_Control_None verifies data exchange:
3792  - in default mode
3793  - with default data bits
3794  - with default parity
3795  - with default stop bits
3796  - with <b>no flow control</b>
3797  - with default clock polarity
3798  - with default clock phase
3799  - at default baudrate
3800  - for default number of data items
3801 */
3802 void USART_Flow_Control_None (void) {
3803
3804   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
3805   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3806
3807 #if (USART_SERVER_USED == 1)
3808   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3809   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3810 #else
3811   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
3812 #endif
3813 }
3814
3815 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3816 /**
3817 \brief Function: Function USART_Flow_Control_RTS
3818 \details
3819 The function \b USART_Flow_Control_RTS verifies functionality of the RTS line flow control by 
3820 trying to receive half of default number of data items, after that, RTS line should 
3821 be deactivated by the USART Client hardware and USART Server should stop sending further data.
3822
3823 The RTS line flow control functionality is tested with following settings:
3824  - in default mode
3825  - with default data bits
3826  - with default parity
3827  - with default stop bits
3828  - with <b>flow control using RTS signal</b>
3829  - at default baudrate
3830
3831 Test procedure consists of the following steps:
3832  - start reception of half of default number of items
3833  - after half of default number of items was received 
3834    the RTS line should go to inactive state
3835  - USART Server after seeing that its CTS line (USART Clients RTS line)
3836    went to inactive state should stop sending further data
3837  - after timeout read from USART Server the number of items it has sent 
3838    and assert that it is less than default number of items
3839
3840 \note This test is not executed if any of the following settings are selected:
3841  - Test Mode <b>Loopback</b>
3842  - Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b>
3843 */
3844 void USART_Flow_Control_RTS (void) {
3845
3846   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
3847 #if  (USART_SERVER_USED == 1)
3848   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
3849   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3850   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
3851   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_RTS, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3852
3853   do {
3854     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
3855     if (CmdSetCom  (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_CTS, 0U, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
3856     if (CmdXfer    (0U, USART_CFG_DEF_NUM, 10U, USART_CFG_XFER_TIMEOUT, 0U) != EXIT_SUCCESS) { break; }
3857
3858     (void)drv->Control(USART_CFG_DEF_MODE_VAL      |
3859                        USART_CFG_DEF_DATA_BITS_VAL | 
3860                        USART_CFG_DEF_PARITY_VAL    | 
3861                        USART_CFG_DEF_STOP_BITS_VAL | 
3862                        ARM_USART_FLOW_CONTROL_RTS  , 
3863                        USART_CFG_DEF_BAUDRATE);
3864
3865     event = 0U;
3866
3867     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
3868
3869     TEST_ASSERT(drv->Receive(ptr_rx_buf, USART_CFG_DEF_NUM / 2U) == ARM_DRIVER_OK);
3870     (void)osDelay(USART_CFG_XFER_TIMEOUT + 20U);        // Wait for USART Server to timeout the XFER command
3871
3872     // Abort and disable reception
3873     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
3874     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
3875
3876     (void)osDelay(10U);
3877
3878     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
3879     if (CmdGetCnt()        != EXIT_SUCCESS) { break; }
3880     TEST_ASSERT_MESSAGE(xfer_count < USART_CFG_DEF_NUM, "[FAILED] All data was received, RTS line is not working!");
3881
3882     if (CmdGetVer()        != EXIT_SUCCESS) { break; }
3883
3884     return;
3885   } while (false);
3886 #endif
3887 }
3888
3889 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3890 /**
3891 \brief Function: Function USART_Flow_Control_CTS
3892 \details
3893 The function \b USART_Flow_Control_CTS verifies functionality of the CTS line flow control by 
3894 trying to send default number of data items, while at half of transmitted number 
3895 of items the USART Server deactivates its RTS line (it is connected to CTS line on the USART Client).
3896
3897 The CTS line flow control functionality is tested with following settings:
3898  - in default mode
3899  - with default data bits
3900  - with default parity
3901  - with default stop bits
3902  - with <b>flow control using CTS signal</b>
3903  - at default baudrate
3904
3905 Test procedure consists of the following steps:
3906  - start send of default number of items
3907  - after USART Server receives half of default number of items it 
3908    will drive its RTS line (USART Clients CTS line) inactive
3909  - before timeout check that tx_busy is active and that number of transmitted items is less than default number of items
3910
3911 \note This test is not executed if any of the following settings are selected:
3912  - Test Mode <b>Loopback</b>
3913  - Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b>
3914 */
3915 void USART_Flow_Control_CTS (void) {
3916
3917   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
3918 #if  (USART_SERVER_USED == 1)
3919   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
3920   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
3921   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
3922   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_CTS, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
3923
3924   do {
3925     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
3926     if (CmdSetCom  (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
3927     if (CmdXfer    (1U, USART_CFG_DEF_NUM, 0U, USART_CFG_XFER_TIMEOUT, USART_CFG_DEF_NUM / 2U) != EXIT_SUCCESS) { break; }
3928
3929     (void)drv->Control(USART_CFG_DEF_MODE_VAL      |
3930                        USART_CFG_DEF_DATA_BITS_VAL | 
3931                        USART_CFG_DEF_PARITY_VAL    | 
3932                        USART_CFG_DEF_STOP_BITS_VAL | 
3933                        ARM_USART_FLOW_CONTROL_CTS  , 
3934                        USART_CFG_DEF_BAUDRATE);
3935
3936     event = 0U;
3937     (void)osDelay(10U);                 // Wait for USART Server to start reception
3938
3939     (void)drv->Control(ARM_USART_CONTROL_TX, 1U);
3940     TEST_ASSERT(drv->Send(ptr_tx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_OK);
3941     (void)osDelay(USART_CFG_XFER_TIMEOUT / 2U); // Wait for half of timeout, after which sending should have stopped
3942
3943     // Assert that tx_busy is still active
3944     TEST_ASSERT_MESSAGE(drv->GetStatus().tx_busy != 0U, "[FAILED] Send has finished, CTS line is not working!");
3945
3946     // Assert that tx count is not 0
3947     TEST_ASSERT_MESSAGE(drv->GetTxCount() != 0U, "[FAILED] No data was sent, CTS line is not working!");
3948
3949     // Assert that tx count is less than default number of items
3950     TEST_ASSERT_MESSAGE(drv->GetTxCount() < USART_CFG_DEF_NUM, "[FAILED] All data was sent, CTS line is not working!");
3951
3952     (void)osDelay(USART_CFG_XFER_TIMEOUT / 2U); // Wait for USART Server to timeout the XFER command
3953
3954     // Abort and disable transmission
3955     (void)drv->Control(ARM_USART_ABORT_SEND, 0U);
3956     (void)drv->Control(ARM_USART_CONTROL_TX, 0U);
3957
3958     (void)osDelay(10U);                         // Wait for USART Server to prepare for reception of new command
3959
3960     // Do a dummy send command to flush any data left-over from previous send
3961     // (When flow control CTS is used the send is started for default number of items.
3962     //  After half of default number of items are sent the CTS line is deasserted, 
3963     //  but data register was already loaded with next item to be sent.
3964     //  To get rid of this loaded data we send a dummy command that USART Server will 
3965     //  ignore, but it will allow us to send next command properly.)
3966     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
3967     (void)ComSendCommand("Dummy", 5U);
3968
3969     (void)osDelay(USART_CFG_SRV_CMD_TOUT+10U);  // Wait for USART Server to timeout the "Dummy" command
3970
3971     return;
3972   } while (false);
3973 #endif
3974 }
3975
3976 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3977 /**
3978 \brief Function: Function USART_Flow_Control_RTS_CTS
3979 \details
3980 The function \b USART_Flow_Control_RTS_CTS verifies functionality of RTS And CTS lines.
3981 It calls function USART_Flow_Control_RTS that checks RTS line functionality, and 
3982 USART_Flow_Control_CTS that checks CTS line functionality.
3983
3984 \note This test is not executed if any of the following settings are selected:
3985  - Test Mode <b>Loopback</b>
3986  - Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b>
3987 */
3988 void USART_Flow_Control_RTS_CTS (void) {
3989
3990   USART_Flow_Control_RTS();
3991   USART_Flow_Control_CTS();
3992 }
3993
3994 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
3995 /**
3996 \brief Function: Function USART_Clock_Pol0_Pha0
3997 \details
3998 The function \b USART_Clock_Pol0_Pha0 verifies data exchange:
3999  - in default mode
4000  - with default data bits
4001  - with no parity
4002  - with 1 stop bit
4003  - with no flow control
4004  - with <b>clock polarity 0</b>
4005  - with <b>clock phase 0</b>
4006  - at default baudrate
4007  - for default number of data items
4008
4009 \note This test is not executed if any of the following settings are selected:
4010  - Test Mode <b>Loopback</b>
4011  - Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b>
4012 */
4013 void USART_Clock_Pol0_Pha0 (void) {
4014
4015   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4016   if (IsNotAsync()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4017   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4018   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4019
4020   USART_DataExchange_Operation(OP_SEND,     USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4021   USART_DataExchange_Operation(OP_RECEIVE,  USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4022   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4023 }
4024
4025 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4026 /**
4027 \brief Function: Function USART_Clock_Pol0_Pha1
4028 \details
4029 The function \b USART_Clock_Pol0_Pha1 verifies data exchange:
4030  - in default mode
4031  - with default data bits
4032  - with no parity
4033  - with 1 stop bit
4034  - with no flow control
4035  - with <b>clock polarity 0</b>
4036  - with <b>clock phase 1</b>
4037  - at default baudrate
4038  - for default number of data items
4039
4040 \note This test is not executed if any of the following settings are selected:
4041  - Test Mode <b>Loopback</b>
4042  - Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b>
4043 */
4044 void USART_Clock_Pol0_Pha1 (void) {
4045
4046   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4047   if (IsNotAsync()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4048   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4049   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4050
4051   USART_DataExchange_Operation(OP_SEND,     USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4052   USART_DataExchange_Operation(OP_RECEIVE,  USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4053   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL0, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4054 }
4055
4056 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4057 /**
4058 \brief Function: Function USART_Clock_Pol1_Pha0
4059 \details
4060 The function \b USART_Clock_Pol1_Pha0 verifies data exchange:
4061  - in default mode
4062  - with default data bits
4063  - with no parity
4064  - with 1 stop bit
4065  - with no flow control
4066  - with <b>clock polarity 1</b>
4067  - with <b>clock phase 0</b>
4068  - at default baudrate
4069  - for default number of data items
4070
4071 \note This test is not executed if any of the following settings are selected:
4072  - Test Mode <b>Loopback</b>
4073  - Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b>
4074 */
4075 void USART_Clock_Pol1_Pha0 (void) {
4076
4077   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4078   if (IsNotAsync()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4079   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4080   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4081
4082   USART_DataExchange_Operation(OP_SEND,     USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4083   USART_DataExchange_Operation(OP_RECEIVE,  USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4084   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA0, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4085 }
4086
4087 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4088 /**
4089 \brief Function: Function USART_Clock_Pol1_Pha1
4090 \details
4091 The function \b USART_Clock_Pol1_Pha1 verifies data exchange:
4092  - in default mode
4093  - with default data bits
4094  - with no parity
4095  - with 1 stop bit
4096  - with no flow control
4097  - with <b>clock polarity 1</b>
4098  - with <b>clock phase 1</b>
4099  - at default baudrate
4100  - for default number of data items
4101
4102 \note This test is not executed if any of the following settings are selected:
4103  - Test Mode <b>Loopback</b>
4104  - Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b>
4105 */
4106 void USART_Clock_Pol1_Pha1 (void) {
4107
4108   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4109   if (IsNotAsync()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4110   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4111   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4112
4113   USART_DataExchange_Operation(OP_SEND,     USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4114   USART_DataExchange_Operation(OP_RECEIVE,  USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4115   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, CPOL1, CPHA1, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4116 }
4117
4118 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4119 /**
4120 \brief Function: Function USART_Baudrate_Min
4121 \details
4122 The function \b USART_Baudrate_Min verifies data exchange:
4123  - in default mode
4124  - with default data bits
4125  - with default parity
4126  - with default stop bits
4127  - with default flow control
4128  - with default clock polarity
4129  - with default clock phase
4130  - at <b>minimum baudrate</b> (define <c>USART_CFG_MIN_BAUDRATE</c> in DV_USART_Config.h)
4131  - for default number of data items
4132
4133 This test function checks the following requirement:
4134  - measured bus speed for Send operation in Test Mode <b>USART Server</b> or Send/Receive operation  in Test Mode <b>Loopback</b> 
4135    is not 25% lower, or higher than requested
4136 */
4137 void USART_Baudrate_Min (void) {
4138   volatile uint64_t br;
4139   volatile  int32_t got_baudrate;
4140
4141   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4142   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4143
4144 #if  (USART_SERVER_USED == 1)
4145   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MIN_BAUDRATE, USART_CFG_DEF_NUM);
4146   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MIN_BAUDRATE, USART_CFG_DEF_NUM);
4147 #else
4148   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MIN_BAUDRATE, USART_CFG_DEF_NUM);
4149 #endif
4150
4151   if (duration != 0xFFFFFFFFU) {        // If Transfer finished before timeout
4152     if (duration != 0U) {               // If duration of transfer was more than 0 SysTick counts
4153       br = ((uint64_t)systick_freq * (1U + USART_CFG_DEF_DATA_BITS + USART_CFG_DEF_STOP_BITS + (uint32_t)(USART_CFG_DEF_PARITY != PARITY_NONE)) * USART_CFG_DEF_NUM) / duration;
4154       if ((br < ((USART_CFG_MIN_BAUDRATE * 3) / 4)) ||
4155           (br >   USART_CFG_MIN_BAUDRATE)) {
4156         // If measured baudrate is 25% lower, or higher than requested
4157         (void)snprintf(msg_buf, sizeof(msg_buf), "[WARNING] At requested baudrate of %i bauds, effective transfer speed is %i bauds", USART_CFG_MIN_BAUDRATE, (uint32_t)br);
4158         TEST_MESSAGE(msg_buf);
4159       }
4160     }
4161   }
4162 }
4163
4164 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4165 /**
4166 \brief Function: Function USART_Baudrate_Max
4167 \details
4168 The function \b USART_Baudrate_Max verifies data exchange:
4169  - in default mode
4170  - with default data bits
4171  - with default parity
4172  - with default stop bits
4173  - with default flow control
4174  - with default clock polarity
4175  - with default clock phase
4176  - at <b>maximum baudrate</b> (define <c>USART_CFG_MAX_BAUDRATE</c> in DV_USART_Config.h)
4177  - for default number of data items
4178
4179 This test function checks the following requirement:
4180  - measured bus speed for Send operation in Test Mode <b>USART Server</b> or Send/Receive operation  in Test Mode <b>Loopback</b> 
4181    is not 25% lower, or higher than requested
4182 */
4183 void USART_Baudrate_Max (void) {
4184   volatile uint64_t br;
4185   volatile  int32_t got_baudrate;
4186
4187   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4188   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4189
4190 #if  (USART_SERVER_USED == 1)
4191   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4192   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4193 #else
4194   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4195 #endif
4196
4197   if (duration != 0xFFFFFFFFU) {        // If Transfer finished before timeout
4198     if (duration != 0U) {               // If duration of transfer was more than 0 SysTick counts
4199       br = ((uint64_t)systick_freq * (1U + USART_CFG_DEF_DATA_BITS + USART_CFG_DEF_STOP_BITS + (uint32_t)(USART_CFG_DEF_PARITY != PARITY_NONE)) * USART_CFG_DEF_NUM) / duration;
4200       if ((br < ((USART_CFG_MAX_BAUDRATE * 3) / 4)) ||
4201           (br >   USART_CFG_MAX_BAUDRATE)) {
4202         // If measured baudrate is 25% lower, or higher than requested
4203         (void)snprintf(msg_buf, sizeof(msg_buf), "[WARNING] At requested baudrate of %i bauds, effective transfer speed is %i bauds", USART_CFG_MAX_BAUDRATE, (uint32_t)br);
4204         TEST_MESSAGE(msg_buf);
4205       }
4206     }
4207   }
4208 }
4209
4210 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4211 /**
4212 \brief Function: Function USART_Number_Of_Items
4213 \details
4214 The function \b USART_Number_Of_Items verifies data exchange:
4215  - in default mode
4216  - with default data bits
4217  - with default parity
4218  - with default stop bits
4219  - with default flow control
4220  - with default clock polarity
4221  - with default clock phase
4222  - at default baudrate
4223  - for <b>different number of items</b> (defines <c>USART_CFG_NUM1 .. USART_CFG_NUM5</c> in DV_USART_Config.h)
4224 */
4225 void USART_Number_Of_Items (void) {
4226
4227   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4228   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4229
4230 #if (USART_CFG_NUM1 != 0U)
4231 #if (USART_SERVER_USED == 1)
4232   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4233   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4234 #else
4235   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4236 #endif
4237 #endif
4238
4239 #if (USART_CFG_NUM2 != 0U)
4240 #if (USART_SERVER_USED == 1)
4241   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4242   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4243 #else
4244   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4245 #endif
4246 #endif
4247
4248 #if (USART_CFG_NUM3 != 0U)
4249 #if (USART_SERVER_USED == 1)
4250   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4251   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4252 #else
4253   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4254 #endif
4255 #endif
4256
4257 #if (USART_CFG_NUM4 != 0U)
4258 #if (USART_SERVER_USED == 1)
4259   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4260   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4261 #else
4262   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4263 #endif
4264 #endif
4265
4266 #if (USART_CFG_NUM5 != 0U)
4267 #if (USART_SERVER_USED == 1)
4268   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4269   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4270 #else
4271   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4272 #endif
4273 #endif
4274 }
4275
4276 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4277 /**
4278 \brief Function: Function USART_GetTxCount
4279 \details
4280 The function \b USART_GetTxCount verifies \b GetTxCount function (count changing) during data exchange (Send):
4281  - in default mode
4282  - with default data bits
4283  - with default parity
4284  - with default stop bits
4285  - with default flow control
4286  - with default clock polarity
4287  - with default clock phase
4288  - at default baudrate
4289 */
4290 void USART_GetTxCount (void) {
4291
4292   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4293   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4294
4295   USART_DataExchange_Operation(OP_SEND, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4296   TEST_ASSERT_MESSAGE((tx_count_sample != 0U) && (tx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetTxCount was not changing during the Send!");
4297 }
4298
4299 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4300 /**
4301 \brief Function: Function USART_GetRxCount
4302 \details
4303 The function \b USART_GetRxCount verifies \b GetRxCount function (count changing) during data exchange (Receive):
4304  - in default mode
4305  - with default data bits
4306  - with default parity
4307  - with default stop bits
4308  - with default flow control
4309  - with default clock polarity
4310  - with default clock phase
4311  - at default baudrate
4312 */
4313 void USART_GetRxCount (void) {
4314
4315   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4316   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4317
4318 #if  (USART_SERVER_USED == 1)
4319   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4320 #else
4321   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4322 #endif
4323 }
4324
4325 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4326 /**
4327 \brief Function: Function USART_GetTxRxCount
4328 \details
4329 The function \b USART_GetTxRxCount verifies \b GetTxCount and \b GetRxCount functions (count changing) during data exchange (Transfer):
4330  - in default mode
4331  - with default data bits
4332  - with no parity
4333  - with 1 stop bits
4334  - with no flow control
4335  - with default clock polarity
4336  - with default clock phase
4337  - at default baudrate
4338
4339 \note If Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b> is selected this test is not executed
4340 */
4341 void USART_GetTxRxCount (void) {
4342
4343   if (IsNotAsync()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4344   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4345   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4346
4347   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4348   TEST_ASSERT_MESSAGE((tx_count_sample != 0U) && (tx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetTxCount was not changing during the Transfer!");
4349   TEST_ASSERT_MESSAGE((rx_count_sample != 0U) && (rx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetRxCount was not changing during the Transfer!");
4350 }
4351
4352 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4353 /**
4354 \brief Function: Function USART_AbortSend
4355 \details
4356 The function \b USART_AbortSend verifies \b Abort function abort of data exchange (Send):
4357  - in default mode
4358  - with default data bits
4359  - with default parity
4360  - with default stop bits
4361  - with default flow control
4362  - at default baudrate
4363 */
4364 void USART_AbortSend (void) {
4365
4366   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4367   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4368
4369   USART_DataExchange_Operation(OP_ABORT_SEND, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4370 }
4371
4372 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4373 /**
4374 \brief Function: Function USART_AbortReceive
4375 \details
4376 The function \b USART_AbortReceive verifies \b Abort function abort of data exchange (Receive):
4377  - in default mode
4378  - with default data bits
4379  - with default parity
4380  - with default stop bits
4381  - with default flow control
4382  - with default clock polarity
4383  - with default clock phase
4384  - at default baudrate
4385 */
4386 void USART_AbortReceive (void) {
4387
4388   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4389   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4390
4391   USART_DataExchange_Operation(OP_ABORT_RECEIVE, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4392 }
4393
4394 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4395 /**
4396 \brief Function: Function USART_AbortTransfer
4397 \details
4398 The function \b USART_AbortTransfer verifies \b Abort function abort of data exchange (Transfer):
4399  - in default mode
4400  - with default data bits
4401  - with no parity
4402  - with 1 stop bit
4403  - with no flow control
4404  - with default clock polarity
4405  - with default clock phase
4406  - at default baudrate
4407
4408 \note If Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b> is selected this test is not executed
4409 */
4410 void USART_AbortTransfer (void) {
4411
4412   if (IsNotAsync()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4413   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4414   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4415
4416   USART_DataExchange_Operation(OP_ABORT_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4417 }
4418
4419 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4420 /**
4421 \brief Function: Function USART_TxBreak
4422 \details
4423 The function \b USART_TxBreak verifies Break signaling:
4424  - in default mode
4425  - with default data bits
4426  - with default parity
4427  - with default stop bits
4428  - with no flow control
4429  - at default baudrate
4430
4431 \note This test is not executed if any of the following settings are selected:
4432  - Test Mode <b>Loopback</b>
4433  - Tests Default Mode <b>Synchronous Master/Slave</b>
4434 */
4435 void USART_TxBreak (void) {
4436
4437   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4438 #if  (USART_SERVER_USED == 1)
4439   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
4440   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4441   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4442
4443   do {
4444     // Dummy read break status to clear it
4445     if (CmdGetBrk()        != EXIT_SUCCESS) { break; }
4446
4447     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4448     if (CmdSetCom  (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
4449
4450     // Instruct USART Server to receive data so it can detect Break
4451     if (CmdXfer    (1U, USART_CFG_DEF_NUM, 0U, USART_CFG_XFER_TIMEOUT, 0U) != EXIT_SUCCESS) { break; }
4452
4453     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4454                        USART_CFG_DEF_DATA_BITS_VAL | 
4455                        USART_CFG_DEF_PARITY_VAL    | 
4456                        USART_CFG_DEF_STOP_BITS_VAL | 
4457                        ARM_USART_FLOW_CONTROL_NONE , 
4458                        USART_CFG_DEF_BAUDRATE);
4459
4460     event = 0U;
4461
4462     (void)osDelay(10U);                 // Wait for USART Server to start reception
4463
4464     (void)drv->Control(ARM_USART_CONTROL_TX, 1U);
4465
4466     (void)osDelay(10U);
4467     TEST_ASSERT(drv->Control(ARM_USART_CONTROL_BREAK, 1U) == ARM_DRIVER_OK);
4468     (void)osDelay(10U);
4469     TEST_ASSERT(drv->Control(ARM_USART_CONTROL_BREAK, 0U) == ARM_DRIVER_OK);
4470     (void)osDelay(10U);
4471
4472     (void)drv->Control(ARM_USART_CONTROL_TX, 0U);
4473
4474     (void)osDelay(USART_CFG_XFER_TIMEOUT + 10U);        // Wait for USART Server to timeout the XFER command
4475
4476     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4477     if (CmdGetBrk()        != EXIT_SUCCESS) { break; }
4478     TEST_ASSERT_MESSAGE(break_status == 1U, "[FAILED] Break was not detected on USART Server!");
4479
4480     (void)osDelay(10U);                 // Wait for USART Server to prepare for reception of new command
4481
4482     return;
4483   } while (false);
4484 #endif
4485 }
4486
4487 /**
4488 @}
4489 */
4490 // End of usart_tests_data_xchg
4491
4492 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4493 /* USART Modem Lines tests                                                                                                  */
4494 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4495 /**
4496 \defgroup usart_tests_modem Modem Lines
4497 \ingroup usart_tests
4498 \details
4499 These tests verify API and operation of the USART modem lines handling functions.
4500
4501 The data exchange tests verify the following driver functions
4502 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
4503  - \b SetModemControl
4504 \code
4505   int32_t                SetModemControl (ARM_USART_MODEM_CONTROL control);
4506 \endcode
4507  - \b GetModemStatus
4508 \code
4509   ARM_USART_MODEM_STATUS GetModemStatus  (void);
4510 \endcode
4511
4512 \note These tests are not executed if any of the following settings are selected:
4513  - Test Mode <b>Loopback</b>
4514  - Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b>
4515 @{
4516 */
4517
4518 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4519 /**
4520 \brief Function: Function USART_Modem_RTS
4521 \details
4522 The function \b USART_Modem_RTS verifies driving of modem line Request To Send (RTS):
4523  - in default mode
4524  - with default data bits
4525  - with default parity
4526  - with default stop bits
4527  - with no flow control
4528  - at default baudrate
4529 */
4530 void USART_Modem_RTS (void) {
4531
4532   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4533 #if  (USART_SERVER_USED == 1)
4534   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4535   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4536   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4537   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, RTS_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4538
4539   do {
4540     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4541
4542     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4543                        USART_CFG_DEF_DATA_BITS_VAL | 
4544                        USART_CFG_DEF_PARITY_VAL    | 
4545                        USART_CFG_DEF_STOP_BITS_VAL | 
4546                        ARM_USART_FLOW_CONTROL_NONE , 
4547                        USART_CFG_DEF_BAUDRATE);
4548
4549     TEST_ASSERT(drv->SetModemControl(ARM_USART_RTS_CLEAR) == ARM_DRIVER_OK);
4550     (void)osDelay(10U);
4551
4552     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4553
4554     TEST_ASSERT_MESSAGE((modem_status & 0x1U) == 0x0U, "[FAILED] CTS line on USART Server is not in inactive state!");
4555
4556     TEST_ASSERT(drv->SetModemControl(ARM_USART_RTS_SET) == ARM_DRIVER_OK);
4557     (void)osDelay(10U);
4558
4559     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4560
4561     TEST_ASSERT_MESSAGE((modem_status & 0x1U) == 0x1U, "[FAILED] CTS line on USART Server is not in active state!");
4562
4563     (void)drv->SetModemControl(ARM_USART_RTS_CLEAR);
4564
4565     // Give USART Server 10 ms to prepare for reception of the next command
4566     (void)osDelay(10U);
4567
4568     return;
4569   } while (false);
4570 #endif
4571 }
4572
4573 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4574 /**
4575 \brief Function: Function USART_Modem_DTR
4576 \details
4577 The function \b USART_Modem_DTR verifies driving of modem line Data Terminal Ready (DTR):
4578  - in default mode
4579  - with default data bits
4580  - with default parity
4581  - with default stop bits
4582  - with no flow control
4583  - at default baudrate
4584 */
4585 void USART_Modem_DTR (void) {
4586
4587   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4588 #if  (USART_SERVER_USED == 1)
4589   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4590   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4591   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4592   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DTR_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4593
4594   do {
4595     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4596
4597     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4598                        USART_CFG_DEF_DATA_BITS_VAL | 
4599                        USART_CFG_DEF_PARITY_VAL    | 
4600                        USART_CFG_DEF_STOP_BITS_VAL | 
4601                        ARM_USART_FLOW_CONTROL_NONE , 
4602                        USART_CFG_DEF_BAUDRATE);
4603
4604     TEST_ASSERT(drv->SetModemControl(ARM_USART_DTR_CLEAR) == ARM_DRIVER_OK);
4605     (void)osDelay(10U);
4606
4607     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4608
4609     TEST_ASSERT_MESSAGE((modem_status & 0x2U) == 0x0U, "[FAILED] DSR line on USART Server is not in inactive state!");
4610
4611     TEST_ASSERT(drv->SetModemControl(ARM_USART_DTR_SET) == ARM_DRIVER_OK);
4612     (void)osDelay(10U);
4613
4614     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4615
4616     TEST_ASSERT_MESSAGE((modem_status & 0x2U) == 0x2U, "[FAILED] DSR line on USART Server is not in active state!");
4617
4618     (void)drv->SetModemControl(ARM_USART_DTR_CLEAR);
4619
4620     // Give USART Server 10 ms to prepare for reception of the next command
4621     (void)osDelay(10U);
4622
4623     return;
4624   } while (false);
4625 #endif
4626 }
4627
4628 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4629 /**
4630 \brief Function: Function USART_Modem_CTS
4631 \details
4632 The function \b USART_Modem_CTS verifies read of modem line Clear To Send (CTS):
4633  - in default mode
4634  - with default data bits
4635  - with default parity
4636  - with default stop bits
4637  - with no flow control
4638  - at default baudrate
4639 */
4640 void USART_Modem_CTS (void) {
4641
4642   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4643 #if  (USART_SERVER_USED == 1)
4644   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4645   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4646   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4647   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, CTS_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4648
4649   do {
4650     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4651
4652     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4653                        USART_CFG_DEF_DATA_BITS_VAL | 
4654                        USART_CFG_DEF_PARITY_VAL    | 
4655                        USART_CFG_DEF_STOP_BITS_VAL | 
4656                        ARM_USART_FLOW_CONTROL_NONE , 
4657                        USART_CFG_DEF_BAUDRATE);
4658
4659     // Instruct USART Server to drive RTS to active state for 20 ms
4660     // RTS line from USART Server should be connected to CTS line on the USART Client (DUT)
4661     if (CmdSetMdm(RTS_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4662
4663     (void)osDelay(20U);
4664
4665     TEST_ASSERT_MESSAGE(drv->GetModemStatus().cts == 1U, "[FAILED] CTS line not active!");
4666
4667     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4668     (void)osDelay(20U);
4669
4670     return;
4671   } while (false);
4672 #endif
4673 }
4674
4675 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4676 /**
4677 \brief Function: Function USART_Modem_DSR
4678 \details
4679 The function \b USART_Modem_DSR verifies read of modem line Data Set Ready (DSR):
4680  - in default mode
4681  - with default data bits
4682  - with default parity
4683  - with default stop bits
4684  - with no flow control
4685  - at default baudrate
4686 */
4687 void USART_Modem_DSR (void) {
4688
4689   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4690 #if  (USART_SERVER_USED == 1)
4691   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4692   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4693   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4694   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DSR_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4695
4696   do {
4697     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4698
4699     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4700                        USART_CFG_DEF_DATA_BITS_VAL | 
4701                        USART_CFG_DEF_PARITY_VAL    | 
4702                        USART_CFG_DEF_STOP_BITS_VAL | 
4703                        ARM_USART_FLOW_CONTROL_NONE , 
4704                        USART_CFG_DEF_BAUDRATE);
4705
4706     // Instruct USART Server to drive DTR to active state for 20 ms
4707     // DTR line from USART Server should be connected to DSR line on the USART Client (DUT)
4708     if (CmdSetMdm(DTR_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4709
4710     (void)osDelay(20U);
4711
4712     TEST_ASSERT_MESSAGE(drv->GetModemStatus().dsr == 1U, "[FAILED] DSR line not active!");
4713
4714     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4715     (void)osDelay(20U);
4716
4717     return;
4718   } while (false);
4719 #endif
4720 }
4721
4722 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4723 /**
4724 \brief Function: Function USART_Modem_DCD
4725 \details
4726 The function \b USART_Modem_DCD verifies read of modem line Data Carrier Detect (DCD):
4727  - in default mode
4728  - with default data bits
4729  - with default parity
4730  - with default stop bits
4731  - with no flow control
4732  - at default baudrate
4733 */
4734 void USART_Modem_DCD (void) {
4735
4736   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4737 #if  (USART_SERVER_USED == 1)
4738   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4739   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4740   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4741   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DCD_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4742
4743   do {
4744     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4745
4746     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4747                        USART_CFG_DEF_DATA_BITS_VAL | 
4748                        USART_CFG_DEF_PARITY_VAL    | 
4749                        USART_CFG_DEF_STOP_BITS_VAL | 
4750                        ARM_USART_FLOW_CONTROL_NONE , 
4751                        USART_CFG_DEF_BAUDRATE);
4752
4753     // Instruct USART Server to drive DTR to active state for 20 ms
4754     if (CmdSetMdm(TO_DCD_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4755     
4756     (void)osDelay(20U);
4757
4758     TEST_ASSERT_MESSAGE(drv->GetModemStatus().dcd == 1U, "[FAILED] DCD line not active!");
4759
4760     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4761     (void)osDelay(20U);
4762
4763     return;
4764   } while (false);
4765 #endif
4766 }
4767
4768 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4769 /**
4770 \brief Function: Function USART_Modem_RI
4771 \details
4772 The function \b USART_Modem_RI verifies read of modem line Ring Indicator (RI):
4773  - in default mode
4774  - with default data bits
4775  - with default parity
4776  - with default stop bits
4777  - with no flow control
4778  - at default baudrate
4779 */
4780 void USART_Modem_RI (void) {
4781
4782   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4783 #if  (USART_SERVER_USED == 1)
4784   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4785   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4786   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4787   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, RI_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4788
4789   do {
4790     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4791
4792     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4793                        USART_CFG_DEF_DATA_BITS_VAL | 
4794                        USART_CFG_DEF_PARITY_VAL    | 
4795                        USART_CFG_DEF_STOP_BITS_VAL | 
4796                        ARM_USART_FLOW_CONTROL_NONE , 
4797                        USART_CFG_DEF_BAUDRATE);
4798
4799     // Instruct USART Server to drive RI to active state for 20 ms
4800     if (CmdSetMdm(TO_RI_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4801
4802     (void)osDelay(20U);
4803
4804     TEST_ASSERT_MESSAGE(drv->GetModemStatus().ri == 1U, "[FAILED] RI line not active!");
4805
4806     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4807     (void)osDelay(20U);
4808
4809     return;
4810   } while (false);
4811 #endif
4812 }
4813
4814 /**
4815 @}
4816 */
4817 // End of usart_tests_modem
4818
4819 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4820 /* USART Event tests                                                                                                        */
4821 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4822 /**
4823 \defgroup usart_tests_evt Event
4824 \ingroup usart_tests
4825 \details
4826 These tests verify API and operation of the USART event signaling, except ARM_USART_EVENT_SEND_COMPLETE, 
4827 ARM_USART_EVENT_RECEIVE_COMPLETE, ARM_USART_EVENT_TRANSFER_COMPLETE and ARM_USART_EVENT_TX_COMPLETE signals 
4828 which is tested in the Data Exchange tests.
4829
4830 The event tests verify the following driver function
4831 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
4832  - \b SignalEvent
4833 \code
4834   void (*ARM_USART_SignalEvent_t) (uint32_t event);
4835 \endcode
4836
4837 \note In Test Mode <b>Loopback</b> these tests are skipped
4838 @{
4839 */
4840
4841 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4842 /**
4843 \brief Function: Function USART_Tx_Underflow
4844 \details
4845 The function \b USART_Tx_Underflow verifies signaling of the <b>ARM_USART_EVENT_TX_UNDERFLOW</b> event:
4846  - in default mode
4847  - with default data bits
4848  - with default parity
4849  - with default stop bits
4850  - with default flow control
4851  - at default baudrate
4852
4853 it also checks that status tx_underflow flag was activated.
4854
4855 \note If Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b> is selected this test is not executed
4856 */
4857 void USART_Tx_Underflow (void) {
4858
4859   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4860 #if  (USART_SERVER_USED == 1)
4861   if (IsNotAsync()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4862   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4863   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4864
4865   do {
4866     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4867     if (CmdSetCom(USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
4868     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
4869
4870     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4871                        USART_CFG_DEF_DATA_BITS_VAL    | 
4872                        USART_CFG_DEF_PARITY_VAL       | 
4873                        USART_CFG_DEF_STOP_BITS_VAL    | 
4874                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4875                        USART_CFG_DEF_CPOL_VAL         | 
4876                        USART_CFG_DEF_CPHA_VAL         , 
4877                        USART_CFG_DEF_BAUDRATE);
4878
4879     event = 0U;
4880
4881     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
4882
4883     (void)osDelay(30U);                 // Wait for USART Server to timeout
4884
4885     // Assert that event ARM_USART_EVENT_TX_UNDERFLOW was signaled
4886     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TX_UNDERFLOW) != 0U, "[FAILED] Event ARM_USART_EVENT_TX_UNDERFLOW was not signaled!");
4887
4888     // Assert that status rx_overflow flag is active
4889     TEST_ASSERT_MESSAGE(drv->GetStatus().tx_underflow != 0U, "[FAILED] Status tx_underflow flag was not activated!");
4890
4891     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
4892
4893     // Give USART Server 10 ms to prepare for reception of the next command
4894     (void)osDelay(10U);
4895
4896     return;
4897   } while (false);
4898 #endif
4899 }
4900
4901 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4902 /**
4903 \brief Function: Function USART_Rx_Overflow
4904 \details
4905 The function \b USART_Rx_Overflow verifies signaling of the <b>ARM_USART_EVENT_RX_OVERFLOW</b> event:
4906  - in default mode
4907  - with default data bits
4908  - with default parity
4909  - with default stop bits
4910  - with default flow control
4911  - at default baudrate
4912
4913 it also checks that status rx_overflow flag was activated.
4914 */
4915 void USART_Rx_Overflow (void) {
4916
4917   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4918 #if  (USART_SERVER_USED == 1)
4919   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4920   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4921
4922   do {
4923     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4924     if (CmdSetCom(USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
4925     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
4926
4927     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4928                        USART_CFG_DEF_DATA_BITS_VAL    | 
4929                        USART_CFG_DEF_PARITY_VAL       | 
4930                        USART_CFG_DEF_STOP_BITS_VAL    | 
4931                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4932                        USART_CFG_DEF_CPOL_VAL         | 
4933                        USART_CFG_DEF_CPHA_VAL         , 
4934                        USART_CFG_DEF_BAUDRATE);
4935
4936     event = 0U;
4937
4938     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
4939
4940     (void)osDelay(30U);                 // Wait for USART Server to timeout
4941
4942     // Assert that event ARM_USART_EVENT_RX_OVERFLOW was signaled
4943     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_OVERFLOW) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_OVERFLOW was not signaled!");
4944
4945     // Assert that status rx_overflow flag is active
4946     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_overflow != 0U, "[FAILED] Status rx_overflow flag was not activated!");
4947
4948     (void)drv->Control(ARM_USART_CONTROL_RX, 0U);
4949
4950     // Give USART Server 10 ms to prepare for reception of the next command
4951     (void)osDelay(10U);
4952
4953     return;
4954   } while (false);
4955 #endif
4956 }
4957
4958 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4959 /**
4960 \brief Function: Function USART_Rx_Timeout
4961 \details
4962 The function \b USART_Rx_Timeout verifies signaling of the <b>ARM_USART_EVENT_RX_TIMEOUT</b> event:
4963  - in default mode
4964  - with default data bits
4965  - with default parity
4966  - with default stop bits
4967  - with default flow control
4968  - at default baudrate
4969
4970 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
4971 */
4972 void USART_Rx_Timeout (void) {
4973
4974   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4975 #if  (USART_SERVER_USED == 1)
4976   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
4977   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4978   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4979
4980   do {
4981     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4982     if (CmdSetCom(USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
4983     if (CmdXfer  (0U, 1U, 10U, 10U, 0U) != EXIT_SUCCESS) { break; }
4984
4985     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4986                        USART_CFG_DEF_DATA_BITS_VAL    | 
4987                        USART_CFG_DEF_PARITY_VAL       | 
4988                        USART_CFG_DEF_STOP_BITS_VAL    | 
4989                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4990                        USART_CFG_DEF_CPOL_VAL         | 
4991                        USART_CFG_DEF_CPHA_VAL         , 
4992                        USART_CFG_DEF_BAUDRATE);
4993
4994     event = 0U;
4995
4996     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
4997     (void)drv->Receive(ptr_rx_buf, 2U);
4998
4999     (void)osDelay(30U);                 // Wait for USART Server to timeout
5000
5001     // Assert that event ARM_USART_EVENT_RX_TIMEOUT was signaled
5002     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_TIMEOUT) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_TIMEOUT was not signaled!");
5003
5004     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5005     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5006
5007     // Give USART Server 10 ms to prepare for reception of the next command
5008     (void)osDelay(10U);
5009
5010     return;
5011   } while (false);
5012 #endif
5013 }
5014
5015 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5016 /**
5017 \brief Function: Function USART_Rx_Break
5018 \details
5019 The function \b USART_Rx_Break verifies signaling of the <b>ARM_USART_EVENT_RX_BREAK</b> event:
5020  - in default mode
5021  - with default data bits
5022  - with default parity
5023  - with default stop bits
5024  - with default flow control
5025  - at default baudrate
5026
5027 it also checks that status rx_break flag was activated.
5028
5029 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5030 */
5031 void USART_Rx_Break (void) {
5032
5033   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5034 #if  (USART_SERVER_USED == 1)
5035   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5036   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5037   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5038
5039   do {
5040     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5041
5042     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
5043                        USART_CFG_DEF_DATA_BITS_VAL    | 
5044                        USART_CFG_DEF_PARITY_VAL       | 
5045                        USART_CFG_DEF_STOP_BITS_VAL    | 
5046                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
5047                        USART_CFG_DEF_CPOL_VAL         | 
5048                        USART_CFG_DEF_CPHA_VAL         , 
5049                        USART_CFG_DEF_BAUDRATE);
5050
5051     // Instruct USART Server to signal Break for 20 ms
5052     if (CmdSetBrk(10U, 20U) != EXIT_SUCCESS) { break; }
5053
5054     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5055     (void)drv->Receive(ptr_rx_buf, 1U);
5056
5057     // This test allows break detection for continuous mode as well 
5058     // as LIN variant (return to inactive after 10/11 bits)
5059     (void)osDelay(40U);
5060
5061     // Assert that event ARM_USART_EVENT_RX_BREAK was signaled
5062     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_BREAK) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_BREAK was not signaled!");
5063
5064     // Assert that status rx_break flag is active
5065     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_break != 0U, "[FAILED] Status rx_break flag was not activated!");
5066
5067     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5068     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5069
5070     // Give USART Server 10 ms to prepare for reception of the next command
5071     (void)osDelay(10U);
5072
5073     return;
5074   } while (false);
5075 #endif
5076 }
5077
5078 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5079 /**
5080 \brief Function: Function USART_Rx_Framing_Error
5081 \details
5082 The function \b USART_Rx_Framing_Error verifies signaling of the <b>ARM_USART_EVENT_RX_FRAMING_ERROR</b> event:
5083  - in default mode
5084  - with default data bits
5085  - with default parity
5086  - with default stop bits
5087  - with default flow control
5088  - at default baudrate
5089
5090 it also checks that status rx_framing_error flag was activated.
5091
5092 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5093 */
5094 void USART_Rx_Framing_Error (void) {
5095
5096   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5097 #if  (USART_SERVER_USED == 1)
5098   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5099   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5100   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5101
5102   do {
5103     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5104
5105     // We test framing error by adding parity bit if it is not set as default setting, 
5106     // or removing parity bit if it is set as default setting
5107     if (USART_CFG_DEF_PARITY == PARITY_NONE) {
5108       if (CmdSetCom(USART_CFG_SRV_MODE, USART_CFG_DEF_DATA_BITS, PARITY_EVEN, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
5109     } else {
5110       if (CmdSetCom(USART_CFG_SRV_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
5111     }
5112     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
5113
5114     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
5115                        USART_CFG_DEF_DATA_BITS_VAL    | 
5116                        USART_CFG_DEF_PARITY_VAL       | 
5117                        USART_CFG_DEF_STOP_BITS_VAL    | 
5118                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
5119                        USART_CFG_DEF_CPOL_VAL         | 
5120                        USART_CFG_DEF_CPHA_VAL         , 
5121                        USART_CFG_DEF_BAUDRATE);
5122
5123     event = 0U;
5124
5125     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5126     (void)drv->Receive(ptr_rx_buf, 1U);
5127
5128     (void)osDelay(30U);                 // Wait for USART Server to timeout
5129
5130     // Assert that event ARM_USART_EVENT_RX_FRAMING_ERROR was signaled
5131     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_FRAMING_ERROR) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_FRAMING_ERROR was not signaled!");
5132
5133     // Assert that status rx_framing_error flag is active
5134     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_framing_error != 0U, "[FAILED] Status rx_framing_error flag was not activated!");
5135
5136     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5137     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5138
5139     // Give USART Server 10 ms to prepare for reception of the next command
5140     (void)osDelay(10U);
5141
5142     return;
5143   } while (false);
5144 #endif
5145 }
5146
5147 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5148 /**
5149 \brief Function: Function USART_Rx_Parity_Error
5150 \details
5151 The function \b USART_Rx_Parity_Error verifies signaling of the <b>ARM_USART_EVENT_RX_PARITY_ERROR</b> event:
5152  - in default mode
5153  - with default data bits
5154  - with default parity
5155  - with default stop bits
5156  - with default flow control
5157  - at default baudrate
5158
5159 it also checks that status rx_parity_error flag was activated.
5160
5161 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5162 */
5163 void USART_Rx_Parity_Error (void) {
5164
5165   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5166 #if  (USART_SERVER_USED == 1)
5167   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5168   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5169   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5170
5171   do {
5172     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5173
5174     // We test parity error by requesting USART Server to send an item at ODD parity  
5175     // and configure USART Client to receive with EVEN parity
5176     if (CmdSetCom(USART_CFG_SRV_MODE, USART_CFG_DEF_DATA_BITS, PARITY_ODD, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
5177
5178     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
5179
5180     (void)drv->Control(USART_CFG_DEF_MODE_VAL                                       | 
5181                        USART_CFG_DEF_DATA_BITS_VAL                                  | 
5182                      ((PARITY_EVEN << ARM_USART_PARITY_Pos) & ARM_USART_PARITY_Msk) | 
5183                        USART_CFG_DEF_STOP_BITS_VAL                                  | 
5184                        USART_CFG_DEF_FLOW_CONTROL_VAL                               | 
5185                        USART_CFG_DEF_CPOL_VAL                                       | 
5186                        USART_CFG_DEF_CPHA_VAL                                       , 
5187                        USART_CFG_DEF_BAUDRATE);
5188
5189     event = 0U;
5190
5191     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5192     (void)drv->Receive(ptr_rx_buf, 1U);
5193
5194     (void)osDelay(30U);                 // Wait for USART Server to timeout
5195
5196     // Assert that event ARM_USART_EVENT_RX_PARITY_ERROR was signaled
5197     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_PARITY_ERROR) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_PARITY_ERROR was not signaled!");
5198
5199     // Assert that status rx_parity_error flag is active
5200     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_parity_error != 0U, "[FAILED] Status rx_parity_error flag was not activated!");
5201
5202     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5203     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5204
5205     // Give USART Server 10 ms to prepare for reception of the next command
5206     (void)osDelay(10U);
5207
5208     return;
5209   } while (false);
5210 #endif
5211 }
5212
5213 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5214 /**
5215 \brief Function: Function USART_Event_CTS
5216 \details
5217 The function \b USART_Event_CTS verifies signaling of the <b>ARM_USART_EVENT_CTS</b> event:
5218  - in default mode
5219  - with default data bits
5220  - with default parity
5221  - with default stop bits
5222  - with no flow control
5223  - at default baudrate
5224
5225 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5226 */
5227 void USART_Event_CTS (void) {
5228
5229   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5230 #if  (USART_SERVER_USED == 1)
5231   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5232   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5233   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5234   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, CTS_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5235
5236   do {
5237     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5238
5239     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5240                        USART_CFG_DEF_DATA_BITS_VAL | 
5241                        USART_CFG_DEF_PARITY_VAL    | 
5242                        USART_CFG_DEF_STOP_BITS_VAL | 
5243                        ARM_USART_FLOW_CONTROL_NONE , 
5244                        USART_CFG_DEF_BAUDRATE);
5245
5246     event = 0;
5247
5248     // Instruct USART Server to drive RTS to active state for 20 ms
5249     // RTS line from USART Server should be connected to CTS line on the USART Client (DUT)
5250     if (CmdSetMdm(RTS_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5251
5252     (void)osDelay(20U);
5253
5254     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_CTS) == ARM_USART_EVENT_CTS, "[FAILED] CTS line did not register change!");
5255
5256     (void)osDelay(20U);
5257
5258     return;
5259   } while (false);
5260 #endif
5261 }
5262
5263 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5264 /**
5265 \brief Function: Function USART_Event_DSR
5266 \details
5267 The function \b USART_Event_DSR verifies signaling of the <b>ARM_USART_EVENT_DSR</b> event:
5268  - in default mode
5269  - with default data bits
5270  - with default parity
5271  - with default stop bits
5272  - with no flow control
5273  - at default baudrate
5274
5275 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5276 */
5277 void USART_Event_DSR (void) {
5278
5279   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5280 #if  (USART_SERVER_USED == 1)
5281   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5282   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5283   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5284   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DSR_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5285
5286   do {
5287     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5288
5289     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5290                        USART_CFG_DEF_DATA_BITS_VAL | 
5291                        USART_CFG_DEF_PARITY_VAL    | 
5292                        USART_CFG_DEF_STOP_BITS_VAL | 
5293                        ARM_USART_FLOW_CONTROL_NONE , 
5294                        USART_CFG_DEF_BAUDRATE);
5295
5296     event = 0;
5297
5298     // Instruct USART Server to drive DTR to active state for 20 ms
5299     // DTR line from USART Server should be connected to DSR line on the USART Client (DUT)
5300     if (CmdSetMdm(DTR_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5301
5302     (void)osDelay(20U);
5303
5304     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_DSR) == ARM_USART_EVENT_DSR, "[FAILED] DSR line did not register change!");
5305
5306     (void)osDelay(20U);
5307
5308     return;
5309   } while (false);
5310 #endif
5311 }
5312
5313 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5314 /**
5315 \brief Function: Function USART_Event_DCD
5316 \details
5317 The function \b USART_Event_DCD verifies signaling of the <b>ARM_USART_EVENT_DCD</b> event:
5318  - in default mode
5319  - with default data bits
5320  - with default parity
5321  - with default stop bits
5322  - with no flow control
5323  - at default baudrate
5324
5325 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5326 */
5327 void USART_Event_DCD (void) {
5328
5329   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5330 #if  (USART_SERVER_USED == 1)
5331   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5332   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5333   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5334   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DCD_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5335
5336   do {
5337     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5338
5339     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5340                        USART_CFG_DEF_DATA_BITS_VAL | 
5341                        USART_CFG_DEF_PARITY_VAL    | 
5342                        USART_CFG_DEF_STOP_BITS_VAL | 
5343                        ARM_USART_FLOW_CONTROL_NONE , 
5344                        USART_CFG_DEF_BAUDRATE);
5345
5346     event = 0;
5347
5348     // Instruct USART Server to drive RTS to active state for 20 ms
5349     if (CmdSetMdm(TO_DCD_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5350
5351     (void)osDelay(20U);
5352
5353     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_DCD) == ARM_USART_EVENT_DCD, "[FAILED] DCD line did not register change!");
5354
5355     (void)osDelay(20U);
5356
5357     return;
5358   } while (false);
5359 #endif
5360 }
5361
5362 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5363 /**
5364 \brief Function: Function USART_Event_RI
5365 \details
5366 The function \b USART_Event_RI verifies signaling of the <b>ARM_USART_EVENT_RI</b> event:
5367  - in default mode
5368  - with default data bits
5369  - with default parity
5370  - with default stop bits
5371  - with no flow control
5372  - at default baudrate
5373
5374 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5375 */
5376 void USART_Event_RI (void) {
5377
5378   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5379 #if  (USART_SERVER_USED == 1)
5380   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5381   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5382   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5383   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, RI_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
5384
5385   do {
5386     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5387
5388     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5389                        USART_CFG_DEF_DATA_BITS_VAL | 
5390                        USART_CFG_DEF_PARITY_VAL    | 
5391                        USART_CFG_DEF_STOP_BITS_VAL | 
5392                        ARM_USART_FLOW_CONTROL_NONE , 
5393                        USART_CFG_DEF_BAUDRATE);
5394
5395     event = 0;
5396
5397     // Instruct USART Server to drive RI to active state for 20 ms
5398     if (CmdSetMdm(TO_RI_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5399
5400     (void)osDelay(40U);
5401
5402     // RI event should be active after RI returns to inactive state (Trailing Edge RI)
5403     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RI) == ARM_USART_EVENT_RI, "[FAILED] RI line did not register change!");
5404
5405     return;
5406   } while (false);
5407 #endif
5408 }
5409
5410 /**
5411 @}
5412 */
5413 // End of usart_tests_evt