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