]> begriffs open source - cmsis-driver-validation/blob - Source/DV_USART.c
Update GitHub Actions runner to ubuntu-22.04 (#18)
[cmsis-driver-validation] / Source / DV_USART.c
1 /*
2  * Copyright (c) 2015-2024 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_ret[] = {
311   "ARM_DRIVER_OK",
312   "ARM_DRIVER_ERROR",
313   "ARM_DRIVER_ERROR_BUSY",
314   "ARM_DRIVER_ERROR_TIMEOUT",
315   "ARM_DRIVER_ERROR_UNSUPPORTED",
316   "ARM_DRIVER_ERROR_PARAMETER",
317   "ARM_DRIVER_ERROR_SPECIFIC",
318   "ARM_USART_ERROR_MODE",
319   "ARM_USART_ERROR_BAUDRATE",
320   "ARM_USART_ERROR_DATA_BITS",
321   "ARM_USART_ERROR_PARITY",
322   "ARM_USART_ERROR_STOP_BITS",
323   "ARM_USART_ERROR_FLOW_CONTROL",
324   "ARM_USART_ERROR_CPOL",
325   "ARM_USART_ERROR_CPHA"
326 };
327
328 // Local functions
329 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
330 static int32_t  ComConfigDefault       (void);
331 static int32_t  ComSendCommand         (const void *data_out, uint32_t len);
332 static int32_t  ComReceiveResponse     (      void *data_in,  uint32_t len);
333
334 static int32_t  CmdGetVer              (void);
335 static int32_t  CmdGetCap              (void);
336 static int32_t  CmdSetBufTx            (char pattern);
337 static int32_t  CmdSetBufRx            (char pattern);
338 static int32_t  CmdGetBufRx            (uint32_t len);
339 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);
340 static int32_t  CmdXfer                (uint32_t dir,  uint32_t num,       uint32_t delay,  uint32_t timeout,   uint32_t num_cts);
341 static int32_t  CmdGetCnt              (void);
342 static int32_t  CmdSetBrk              (uint32_t delay, uint32_t duration);
343 static int32_t  CmdGetBrk              (void);
344 static int32_t  CmdSetMdm              (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration);
345 static int32_t  CmdGetMdm              (void);
346
347 static int32_t  ServerInit             (void);
348 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);
349 #endif
350
351 static int32_t  IsNotLoopback          (void);
352 static int32_t  IsNotSync              (void);
353 static int32_t  IsNotAsync             (void);
354 static int32_t  IsNotSyncMaster        (void);
355 static int32_t  IsNotSingleWire        (void);
356
357 static uint32_t DataBitsToBytes        (uint32_t data_bits);
358 static int32_t  DriverInit             (void);
359 static int32_t  BuffersCheck           (void);
360 static int32_t  DriverCheck            (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask);
361
362 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);
363
364 // Helper functions
365
366 /*
367   \fn            void USART_DrvEvent (uint32_t evt)
368   \brief         Store event(s) into a global variable.
369   \detail        This is a callback function called by the driver upon an event(s).
370   \param[in]     evt            USART event
371   \return        none
372 */
373 static void USART_DrvEvent (uint32_t evt) {
374   event |= evt;
375
376   (void)osEventFlagsSet(event_flags, evt);
377 }
378
379 /*
380   \fn            static uint32_t DataBitsToBytes (uint32_t data_bits)
381   \brief         Calculate number of bytes used for an item at required data bits.
382   \return        number of bytes per item
383 */
384 static uint32_t DataBitsToBytes (uint32_t data_bits) {
385   uint32_t ret;
386
387   ret = 1U;
388   if (data_bits > 8U) {
389     ret = 2U;
390   }
391
392   return ret;
393 }
394
395 /*
396   \fn            static int32_t DriverInit (void)
397   \brief         Initialize and power-on the driver.
398   \return        execution status
399                    - EXIT_SUCCESS: Driver initialized and powered-up successfully
400                    - EXIT_FAILURE: Driver initialization or power-up failed
401 */
402 static int32_t DriverInit (void) {
403
404   if (drv->Initialize    (USART_DrvEvent) == ARM_DRIVER_OK) {
405     if (drv->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK) {
406       return EXIT_SUCCESS;
407     }
408   }
409
410   TEST_FAIL_MESSAGE("[FAILED] USART driver initialize or power-up. Check driver Initialize and PowerControl functions! Test aborted!");
411
412   return EXIT_FAILURE;
413 }
414
415 /*
416   \fn            static int32_t IsNotLoopback (void)
417   \brief         Check if loopback is not selected.
418   \detail        This function is used to skip executing a test if it is not supported 
419                  in Loopback mode.
420   \return        execution status
421                    - EXIT_SUCCESS: Loopback is not selected
422                    - EXIT_FAILURE: Loopback is selected
423 */
424 static int32_t IsNotLoopback (void) {
425
426 #if (USART_SERVER_USED == 1)
427   return EXIT_SUCCESS;
428 #else
429   TEST_MESSAGE("[WARNING] Test not supported in Loopback Test Mode! Test not executed!");
430   return EXIT_FAILURE;
431 #endif
432 }
433
434 /*
435   \fn            static int32_t IsNotSync (void)
436   \brief         Check if Synchronous Slave/Master mode is not selected as default mode.
437   \detail        This function is used to skip executing a test if it is not supported 
438                  in Synchronous mode.
439   \return        execution status
440                    - EXIT_SUCCESS: Synchronous mode is not selected
441                    - EXIT_FAILURE: Synchronous mode is selected
442 */
443 static int32_t IsNotSync (void) {
444
445 #if ((USART_CFG_DEF_MODE != MODE_SYNCHRONOUS_MASTER) && (USART_CFG_DEF_MODE != MODE_SYNCHRONOUS_SLAVE))
446   return EXIT_SUCCESS;
447 #else
448   TEST_MESSAGE("[WARNING] Test not supported for Synchronous Mode! Test not executed!");
449   return EXIT_FAILURE;
450 #endif
451 }
452
453 /*
454   \fn            static int32_t IsNotSyncMaster (void)
455   \brief         Check if Synchronous Master mode is not selected as default mode.
456   \detail        This function is used to skip executing a test if it is not supported 
457                  in Synchronous Master mode.
458   \return        execution status
459                    - EXIT_SUCCESS: Synchronous Master mode is not selected
460                    - EXIT_FAILURE: Synchronous Master mode is selected
461 */
462 static int32_t IsNotSyncMaster (void) {
463
464 #if (USART_CFG_DEF_MODE != MODE_SYNCHRONOUS_MASTER)
465   return EXIT_SUCCESS;
466 #else
467   TEST_MESSAGE("[WARNING] Test not supported for Synchronous Master Mode! Test not executed!");
468   return EXIT_FAILURE;
469 #endif
470 }
471
472 /*
473   \fn            static int32_t IsNotAsync (void)
474   \brief         Check if Asynchronous/Single-wire/IrDA modes are not selected as default mode.
475   \detail        This function is used to skip executing a test if it is not supported 
476                  in Asynchronous/Single-wire/IrDA mode.
477   \return        execution status
478                    - EXIT_SUCCESS: Asynchronous/Single-wire/IrDA mode is not selected
479                    - EXIT_FAILURE: Asynchronous/Single-wire/IrDA mode is selected
480 */
481 static int32_t IsNotAsync (void) {
482
483 #if ((USART_CFG_DEF_MODE != MODE_ASYNCHRONOUS) && (USART_CFG_DEF_MODE != MODE_SINGLE_WIRE) && (USART_CFG_DEF_MODE != MODE_IRDA))
484   return EXIT_SUCCESS;
485 #else
486   TEST_MESSAGE("[WARNING] Test not supported for Asynchronous/Single-wire/IrDA Mode! Test not executed!");
487   return EXIT_FAILURE;
488 #endif
489 }
490
491 /*
492   \fn            static int32_t IsNotSingleWire (void)
493   \brief         Check if Single-wire mode is not selected as default mode.
494   \detail        This function is used to skip executing a test if it is not supported 
495                  in Single-wire mode.
496   \return        execution status
497                    - EXIT_SUCCESS: Single-wire mode is not selected
498                    - EXIT_FAILURE: Single-wire mode is selected
499 */
500 static int32_t IsNotSingleWire (void) {
501
502 #if (USART_CFG_DEF_MODE != MODE_SINGLE_WIRE)
503   return EXIT_SUCCESS;
504 #else
505   TEST_MESSAGE("[WARNING] Test not supported for Single-wire Mode! Test not executed!");
506   return EXIT_FAILURE;
507 #endif
508 }
509
510 /*
511   \fn            static int32_t BuffersCheck (void)
512   \brief         Check if buffers are valid.
513   \return        execution status
514                    - EXIT_SUCCESS: Buffers are valid
515                    - EXIT_FAILURE: Buffers are not valid
516 */
517 static int32_t BuffersCheck (void) {
518
519   if ((ptr_tx_buf  != NULL) &&
520       (ptr_rx_buf  != NULL) && 
521       (ptr_cmp_buf != NULL)) {
522     return EXIT_SUCCESS;
523   }
524
525   TEST_FAIL_MESSAGE("[FAILED] Invalid data buffers! Increase heap memory! Test aborted!");
526
527   return EXIT_FAILURE;
528 }
529
530 /*
531   \fn            static int32_t DriverCheck (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask, uint32_t baudrate)
532   \brief         Check if USART Driver supports desired settings.
533   \param[in]     mode           mode:
534                                   - value 1 = Asynchronous
535                                   - value 2 = Synchronous Master
536                                   - value 3 = Synchronous Slave
537                                   - value 4 = Single Wire
538                                   - value 5 = IrDA
539                                   - value 6 = Smart Card
540   \param[in]     flow_control   flow control:
541                                   - value 0 = None
542                                   - value 1 = CTS
543                                   - value 2 = RTS
544                                   - value 3 = RTS/CTS
545   \param[in]     modem_line_mask  modem line mask:
546                                   - bit 0. = RTS
547                                   - bit 1. = CTS
548                                   - bit 2. = DTR
549                                   - bit 3. = DSR
550                                   - bit 4. = DCD
551                                   - bit 5. = RI
552   \return        execution status
553                    - EXIT_SUCCESS: USART Driver supports desired settings
554                    - EXIT_FAILURE: USART Driver does not support desired settings
555 */
556 static int32_t DriverCheck (uint32_t mode, uint32_t flow_control, uint32_t modem_line_mask) {
557   int32_t ret;
558
559   ret = EXIT_SUCCESS;
560
561   switch (mode) {
562     case 1:                             // Asynchronous
563       if (drv_cap.asynchronous == 0U) {
564         ret = EXIT_FAILURE;
565       }
566       break;
567     case 2:                             // Synchronous master
568       if (drv_cap.synchronous_master == 0U) {
569         ret = EXIT_FAILURE;
570       }
571       break;
572     case 3:                             // Synchronous slave
573       if (drv_cap.synchronous_slave == 0U) {
574         ret = EXIT_FAILURE;
575       }
576       break;
577     case 4:                             // Single-wire
578       if (drv_cap.single_wire == 0U) {
579         ret = EXIT_FAILURE;
580       }
581       break;
582     case 5:                             // IrDA
583       if (drv_cap.irda == 0U) {
584         ret = EXIT_FAILURE;
585       }
586       break;
587     case 6:                             // Samrt Card
588       if (drv_cap.irda == 0U) {
589         ret = EXIT_FAILURE;
590       }
591       break;
592     default:
593       ret = EXIT_FAILURE;
594       break;
595   }
596
597   if (ret != EXIT_SUCCESS) {
598     // If USART Driver does not support desired mode
599     if (mode <= 6U) {
600       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support %s mode! Test aborted!", str_mode[mode]);
601     } else {
602       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support unknown mode! Test aborted!");
603     }
604     TEST_MESSAGE(msg_buf);
605     return EXIT_FAILURE;
606   }
607
608   switch (flow_control) {
609     case 0:                             // None
610       break;
611     case 1:                             // CTS
612       if (drv_cap.flow_control_cts == 0U) {
613         ret = EXIT_FAILURE;
614       }
615       break;
616     case 2:                             // RTS
617       if (drv_cap.flow_control_rts == 0U) {
618         ret = EXIT_FAILURE;
619       }
620       break;
621     case 3:                             // RTS/CTS
622       if ((drv_cap.flow_control_cts == 0U) || (drv_cap.flow_control_rts == 0U)) {
623         ret = EXIT_FAILURE;
624       }
625       break;
626     default:
627       ret = EXIT_FAILURE;
628       break;
629   }
630
631   if (ret != EXIT_SUCCESS) {
632     // If USART Driver does not support desired flow control
633     if (mode <= 3U) {
634       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support %s flow control! Test aborted!", str_flow_control[flow_control]);
635     } else {
636       (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Driver does not support unknown flow control! Test aborted!");
637     }
638     TEST_MESSAGE(msg_buf);
639     return EXIT_FAILURE;
640   }
641
642   if ((modem_line_mask & 1U) != 0U) {
643     if (drv_cap.rts == 0U) {
644       TEST_MESSAGE("[FAILED] USART Driver does not support RTS modem line! Test aborted!");
645       return EXIT_FAILURE;
646     }
647   }
648   if ((modem_line_mask & (1U << 1)) != 0U) {
649     if (drv_cap.cts == 0U) {
650       TEST_MESSAGE("[FAILED] USART Driver does not support CTS modem line! Test aborted!");
651       return EXIT_FAILURE;
652     }
653   }
654   if ((modem_line_mask & (1U << 2)) != 0U) {
655     if (drv_cap.dtr == 0U) {
656       TEST_MESSAGE("[FAILED] USART Driver does not support DTR modem line! Test aborted!");
657       return EXIT_FAILURE;
658     }
659   }
660   if ((modem_line_mask & (1U << 3)) != 0U) {
661     if (drv_cap.dsr == 0U) {
662       TEST_MESSAGE("[FAILED] USART Driver does not support DSR modem line! Test aborted!");
663       return EXIT_FAILURE;
664     }
665   }
666   if ((modem_line_mask & (1U << 4)) != 0U) {
667     if (drv_cap.dcd == 0U) {
668       TEST_MESSAGE("[FAILED] USART Driver does not support DCD modem line! Test aborted!");
669       return EXIT_FAILURE;
670     }
671   }
672   if ((modem_line_mask & (1U << 5)) != 0U) {
673     if (drv_cap.ri == 0U) {
674       TEST_MESSAGE("[FAILED] USART Driver does not support RI modem line! Test aborted!");
675       return EXIT_FAILURE;
676     }
677   }
678
679   return ret;
680 }
681
682 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
683
684 /*
685   \fn            static int32_t ComConfigDefault (void)
686   \brief         Configure USART Communication Interface to USART Server default communication configuration.
687   \return        execution status
688                    - EXIT_SUCCESS: Default configuration set successfully
689                    - EXIT_FAILURE: Default configuration failed
690 */
691 static int32_t ComConfigDefault (void) {
692   int32_t ret;
693
694   ret = EXIT_SUCCESS;
695
696   if (drv->Control(((USART_CFG_SRV_MODE         << ARM_USART_CONTROL_Pos)      & ARM_USART_CONTROL_Msk)      |
697                      DRIVER_DATA_BITS(USART_CFG_SRV_DATA_BITS)                                               |
698                    ((USART_CFG_SRV_PARITY       << ARM_USART_PARITY_Pos)       & ARM_USART_PARITY_Msk)       |
699                    ((USART_CFG_SRV_STOP_BITS    << ARM_USART_STOP_BITS_Pos)    & ARM_USART_STOP_BITS_Msk)    |
700                    ((USART_CFG_SRV_FLOW_CONTROL << ARM_USART_FLOW_CONTROL_Pos) & ARM_USART_FLOW_CONTROL_Msk) ,
701                      USART_CFG_SRV_BAUDRATE) != ARM_DRIVER_OK) {
702     ret = EXIT_FAILURE;
703   }
704     if (drv->Control(ARM_USART_CONTROL_TX, 1U) != ARM_DRIVER_OK) {
705       ret = EXIT_FAILURE;
706     }
707
708   if (ret != EXIT_SUCCESS) {
709     TEST_FAIL_MESSAGE("[FAILED] Configure communication interface to USART Server default settings. Check driver Control function! Test aborted!");
710   }
711
712   return ret;
713 }
714
715 /**
716   \fn            static int32_t ComSendCommand (const void *data_out, uint32_t num)
717   \brief         Send command to USART Server.
718   \param[out]    data_out       Pointer to memory containing data to be sent
719   \param[in]     len            Number of bytes to be sent
720   \return        execution status
721                    - EXIT_SUCCESS: Command sent successfully
722                    - EXIT_FAILURE: Command send failed
723 */
724 static int32_t ComSendCommand (const void *data_out, uint32_t len) {
725    int32_t ret;
726   uint32_t flags, num, tout;
727
728   ret = EXIT_SUCCESS;
729   num = (len + DataBitsToBytes(USART_CFG_SRV_DATA_BITS) - 1U) / DataBitsToBytes(USART_CFG_SRV_DATA_BITS);
730
731   ret = ComConfigDefault();
732
733   if (ret == EXIT_SUCCESS) {
734     (void)osEventFlagsClear(event_flags, 0x7FFFFFFFU);  
735     if (drv->Control(ARM_USART_CONTROL_TX, 1U) != ARM_DRIVER_OK) {
736       ret = EXIT_FAILURE;
737     }
738     if (ret == EXIT_SUCCESS) {
739       if (drv->Send(data_out, num) != ARM_DRIVER_OK) {
740         ret = EXIT_FAILURE;
741       }
742       if (ret == EXIT_SUCCESS) {
743         if (drv_cap.event_tx_complete != 0U) {
744           // If ARM_USART_EVENT_TX_COMPLETE is supported, wait for it
745           flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_TX_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
746           if (((flags & 0x80000000U) != 0U) ||
747               ((flags & ARM_USART_EVENT_TX_COMPLETE) == 0U)) {
748             ret = EXIT_FAILURE;
749           }
750         } else {
751           // Otherwise wait for ARM_USART_EVENT_SEND_COMPLETE flag
752           flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_SEND_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
753           if (((flags & 0x80000000U) != 0U) ||
754               ((flags & ARM_USART_EVENT_SEND_COMPLETE) == 0U)) {
755             ret = EXIT_FAILURE;
756           }
757
758           if (ret == EXIT_SUCCESS) {
759             // If completed event was signaled, wait for all data to be sent
760             for (tout = USART_CFG_SRV_CMD_TOUT; tout != 0U; tout--) {
761               if ((drv->GetTxCount() == len) && (drv->GetStatus().tx_busy == 0U)) { 
762                 break;
763               }
764               (void)osDelay(1U);
765             }
766           }
767         }
768       }
769       if (ret == EXIT_FAILURE) {
770         (void)drv->Control(ARM_USART_ABORT_SEND, 0U);
771       }
772     }
773   }
774   (void)drv->Control(ARM_USART_CONTROL_TX, 0U);
775
776   return ret;
777 }
778
779 /**
780   \fn            static int32_t ComReceiveResponse (void *data_in, uint32_t num)
781   \brief         Receive response from USART Server.
782   \param[out]    data_in     Pointer to memory where data will be received
783   \param[in]     len         Number of data bytes to be received
784   \return        execution status
785                    - EXIT_SUCCESS: Command received successfully
786                    - EXIT_FAILURE: Command reception failed
787 */
788 static int32_t ComReceiveResponse (void *data_in, uint32_t len) {
789    int32_t ret;
790   uint32_t flags, num;
791
792   ret = EXIT_SUCCESS;
793   num = (len + DataBitsToBytes(USART_CFG_SRV_DATA_BITS) - 1U) / DataBitsToBytes(USART_CFG_SRV_DATA_BITS);
794
795   ret = ComConfigDefault();
796
797   if (ret == EXIT_SUCCESS) {
798     (void)osEventFlagsClear(event_flags, 0x7FFFFFFFU);  
799     if (drv->Control(ARM_USART_CONTROL_RX, 1U) != ARM_DRIVER_OK) {
800       ret = EXIT_FAILURE;
801     }
802     if (ret == EXIT_SUCCESS) {
803       if (drv->Receive(data_in, num) != ARM_DRIVER_OK) {
804         ret = EXIT_FAILURE;
805       }
806       if (ret == EXIT_SUCCESS) {
807         flags = osEventFlagsWait(event_flags, ARM_USART_EVENT_RECEIVE_COMPLETE, osFlagsWaitAny, USART_CFG_SRV_CMD_TOUT);
808         if (((flags & 0x80000000U) != 0U) ||
809             ((flags & ARM_USART_EVENT_RECEIVE_COMPLETE) == 0U)) {
810           ret = EXIT_FAILURE;
811         }
812       }
813       if (ret == EXIT_FAILURE) {
814         drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
815       }
816     }
817   }
818   (void)drv->Control(ARM_USART_CONTROL_RX, 0U);
819
820   return ret;
821 }
822
823 /**
824   \fn            static int32_t CmdGetVer (void)
825   \brief         Get version from USART Server and check that it is valid.
826   \return        execution status
827                    - EXIT_SUCCESS: Version retrieved successfully
828                    - EXIT_FAILURE: Version retreival failed
829 */
830 static int32_t CmdGetVer (void) {
831   int32_t     ret;
832   const char *ptr_str;
833   uint16_t    val16;
834   uint8_t     val8;
835
836   ptr_str = NULL;
837
838   memset(&usart_serv_ver, 0, sizeof(usart_serv_ver));
839
840   // Send "GET VER" command to USART Server
841   memset(ptr_tx_buf, 0, CMD_LEN);
842   memcpy(ptr_tx_buf, "GET VER", 7);
843   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
844
845   if (ret == EXIT_SUCCESS) {
846     // Receive response to "GET VER" command from USART Server
847     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_VER_LEN);
848     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_VER_LEN);
849     (void)osDelay(10U);
850   }
851
852   // Parse version
853   if (ret == EXIT_SUCCESS) {
854     // Parse major
855     ptr_str = (const char *)ptr_rx_buf;
856     if (sscanf(ptr_str, "%hhx", &val8) == 1) {
857       usart_serv_ver.major = val8;
858     } else {
859       ret = EXIT_FAILURE;
860     }
861   }
862   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
863     // Parse minor
864     ptr_str = strstr(ptr_str, ".");     // Find '.'
865     if (ptr_str != NULL) {
866       ptr_str++;                        // Skip '.'
867       if (sscanf(ptr_str, "%hhx", &val8) == 1) {
868         usart_serv_ver.minor = val8;
869       } else {
870         ret = EXIT_FAILURE;
871       }
872     } else {
873       ret = EXIT_FAILURE;
874     }
875   }
876   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
877     // Parse patch (revision)
878     ptr_str = strstr(ptr_str, ".");     // Find next '.'
879     if (ptr_str != NULL) {
880       ptr_str++;                        // Skip '.'
881       if (sscanf(ptr_str, "%hx", &val16) == 1) {
882         usart_serv_ver.patch = val16;
883       } else {
884         ret = EXIT_FAILURE;
885       }
886     } else {
887       ret = EXIT_FAILURE;
888     }
889   }
890
891   return ret;
892 }
893
894 /**
895   \fn            static int32_t CmdGetCap (void)
896   \brief         Get capabilities from USART Server.
897   \return        execution status
898                    - EXIT_SUCCESS: Capabilities retrieved successfully
899                    - EXIT_FAILURE: Capabilities retreival failed
900 */
901 static int32_t CmdGetCap (void) {
902   int32_t     ret;
903   const char *ptr_str;
904   uint32_t    val32;
905   uint8_t     val8;
906
907   ptr_str = NULL;
908
909   memset(&usart_serv_cap, 0, sizeof(usart_serv_cap));
910
911   // Send "GET CAP" command to USART Server
912   memset(ptr_tx_buf, 0, CMD_LEN);
913   memcpy(ptr_tx_buf, "GET CAP", 7);
914   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
915
916   if (ret == EXIT_SUCCESS) {
917     (void)osDelay(20U);                 // Give USART Server 20 ms to auto-detect capabilities
918
919     // Receive response to "GET CAP" command from USART Server
920     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_CAP_LEN);
921     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_CAP_LEN);
922     (void)osDelay(10U);
923   }
924
925   // Parse capabilities
926   if (ret == EXIT_SUCCESS) {
927     // Parse mode mask
928     ptr_str = (const char *)ptr_rx_buf;
929     if (sscanf(ptr_str, "%hhx", &val8) == 1) {
930       usart_serv_cap.mode_mask = val8;
931     } else {
932       ret = EXIT_FAILURE;
933     }
934   }
935   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
936     // Parse data bit mask
937     ptr_str = strstr(ptr_str, ",");     // Find ','
938     if (ptr_str != NULL) {
939       ptr_str++;                        // Skip ','
940       if (sscanf(ptr_str, "%x", &val32) == 1) {
941         usart_serv_cap.db_mask = val32;
942       } else {
943         ret = EXIT_FAILURE;
944       }
945     } else {
946       ret = EXIT_FAILURE;
947     }
948   }
949   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
950     // Parse parity mask
951     ptr_str = strstr(ptr_str, ",");     // Find next ','
952     if (ptr_str != NULL) {
953       ptr_str++;                        // Skip ','
954       if (sscanf(ptr_str, "%x", &val32) == 1) {
955         usart_serv_cap.parity_mask = val32;
956       } else {
957         ret = EXIT_FAILURE;
958       }
959     } else {
960       ret = EXIT_FAILURE;
961     }
962   }
963   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
964     // Parse stop bit mask
965     ptr_str = strstr(ptr_str, ",");     // Find next ','
966     if (ptr_str != NULL) {
967       ptr_str++;                        // Skip ','
968       if (sscanf(ptr_str, "%x", &val32) == 1) {
969         usart_serv_cap.sb_mask = val32;
970       } else {
971         ret = EXIT_FAILURE;
972       }
973     } else {
974       ret = EXIT_FAILURE;
975     }
976   }
977   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
978     // Parse flow control mask
979     ptr_str = strstr(ptr_str, ",");     // Find next ','
980     if (ptr_str != NULL) {
981       ptr_str++;                        // Skip ','
982       if (sscanf(ptr_str, "%x", &val32) == 1) {
983         usart_serv_cap.fc_mask = val32;
984       } else {
985         ret = EXIT_FAILURE;
986       }
987     } else {
988       ret = EXIT_FAILURE;
989     }
990   }
991   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
992     // Parse modem lines mask
993     ptr_str = strstr(ptr_str, ",");     // Find next ','
994     if (ptr_str != NULL) {
995       ptr_str++;                        // Skip ','
996       if (sscanf(ptr_str, "%x", &val32) == 1) {
997         usart_serv_cap.ml_mask = val32;
998       } else {
999         ret = EXIT_FAILURE;
1000       }
1001     } else {
1002       ret = EXIT_FAILURE;
1003     }
1004   }
1005   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
1006     // Parse minimum baudrate
1007     ptr_str = strstr(ptr_str, ",");     // Find next ','
1008     if (ptr_str != NULL) {
1009       ptr_str++;                        // Skip ','
1010       if (sscanf(ptr_str, "%u", &val32) == 1) {
1011         usart_serv_cap.br_min = val32;
1012       } else {
1013         ret = EXIT_FAILURE;
1014       }
1015     } else {
1016       ret = EXIT_FAILURE;
1017     }
1018   }
1019   if ((ret == EXIT_SUCCESS) && (ptr_str != NULL)) {
1020     // Parse maximum baudrate
1021     ptr_str = strstr(ptr_str, ",");     // Find next ','
1022     if (ptr_str != NULL) {
1023       ptr_str++;                        // Skip ','
1024       if (sscanf(ptr_str, "%u", &val32) == 1) {
1025         usart_serv_cap.br_max = val32;
1026       } else {
1027         ret = EXIT_FAILURE;
1028       }
1029     } else {
1030       ret = EXIT_FAILURE;
1031     }
1032   }
1033
1034   return ret;
1035 }
1036
1037 /**
1038   \fn            static int32_t CmdSetBufTx (char pattern)
1039   \brief         Set Tx buffer of USART Server to pattern.
1040   \param[in]     pattern        Pattern to fill the buffer with
1041   \return        execution status
1042                    - EXIT_SUCCESS: Command sent successfully
1043                    - EXIT_FAILURE: Command send failed
1044 */
1045 static int32_t CmdSetBufTx (char pattern) {
1046   int32_t ret;
1047
1048   // Send "SET BUF TX" command to USART Server
1049   memset(ptr_tx_buf, 0, CMD_LEN);
1050   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BUF TX,0,%02X", (int32_t)pattern);
1051   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1052   (void)osDelay(10U);
1053
1054   if (ret != EXIT_SUCCESS) {
1055     TEST_FAIL_MESSAGE("[FAILED] Set Tx buffer on USART Server. Check USART Server! Test aborted!");
1056   }
1057
1058   return ret;
1059 }
1060
1061 /**
1062   \fn            static int32_t CmdSetBufRx (char pattern)
1063   \brief         Set Rx buffer of USART Server to pattern.
1064   \param[in]     pattern        Pattern to fill the buffer with
1065   \return        execution status
1066                    - EXIT_SUCCESS: Command sent successfully
1067                    - EXIT_FAILURE: Command send failed
1068 */
1069 static int32_t CmdSetBufRx (char pattern) {
1070   int32_t ret;
1071
1072   // Send "SET BUF RX" command to USART Server
1073   memset(ptr_tx_buf, 0, CMD_LEN);
1074   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BUF RX,0,%02X", (int32_t)pattern);
1075   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1076   (void)osDelay(10U);
1077
1078   if (ret != EXIT_SUCCESS) {
1079     TEST_FAIL_MESSAGE("[FAILED] Set Rx buffer on USART Server. Check USART Server! Test aborted!");
1080   }
1081
1082   return ret;
1083 }
1084
1085 /**
1086   \fn            static int32_t CmdGetBufRx (void)
1087   \brief         Get Rx buffer from USART Server (into global array pointed to by ptr_rx_buf).
1088   \param[in]     len            Number of bytes to read from Rx buffer
1089   \return        execution status
1090                    - EXIT_SUCCESS: Command sent and response received successfully
1091                    - EXIT_FAILURE: Command send or response reception failed
1092 */
1093 static int32_t CmdGetBufRx (uint32_t len) {
1094   int32_t ret;
1095
1096   // Send "GET BUF RX" command to USART Server
1097   memset(ptr_tx_buf, 0, CMD_LEN);
1098   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "GET BUF RX,%i", len);
1099   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1100
1101   if (ret == EXIT_SUCCESS) {
1102     // Receive response to "GET BUF RX" command from USART Server
1103     memset(ptr_rx_buf, (int32_t)'?', len);
1104     ret = ComReceiveResponse(ptr_rx_buf, len);
1105     (void)osDelay(10U);
1106   }
1107
1108   if (ret != EXIT_SUCCESS) {
1109     TEST_FAIL_MESSAGE("[FAILED] Get Rx buffer from USART Server. Check USART Server! Test aborted!");
1110   }
1111
1112   return ret;
1113 }
1114
1115 /**
1116   \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)
1117   \brief         Set communication parameters on USART Server for next XFER command.
1118   \param[in]     mode           mode:
1119                                   - value 0 = Asynchronous
1120                                   - value 1 = Synchronous Master
1121                                   - value 2 = Synchronous Slave
1122                                   - value 3 = Single Wire
1123                                   - value 4 = IrDA
1124                                   - value 5 = Smart Card
1125   \param[in]     data_bits      data bits:
1126                                   - values 5 to 9
1127   \param[in]     parity         parity:
1128                                   - value 0 = None
1129                                   - value 1 = Even
1130                                   - value 2 = Odd
1131   \param[in]     stop_bits      stop bits:
1132                                   - value 0 = 1 Stop Bit
1133                                   - value 1 = 2 Stop Bits
1134                                   - value 2 = 1.5 Stop Bits
1135                                   - value 3 = 0.5 Stop Bits
1136   \param[in]     flow_control   flow control:
1137                                   - value 0 = None
1138                                   - value 1 = CTS
1139                                   - value 2 = RTS
1140                                   - value 3 = RTS/CTS
1141   \param[in]     cpol           clock polarity:
1142                                   - value 0 = Data are captured on rising edge
1143                                   - value 1 = Data are captured on falling edge
1144   \param[in]     cpha           clock phase:
1145                                   - value 0 = Sample on first (leading) edge
1146                                   - value 1 = Sample on second (trailing) edge
1147   \param[in]     baudrate       baudrate in bauds
1148   \return        execution status
1149                    - EXIT_SUCCESS: Command sent successfully
1150                    - EXIT_FAILURE: Command send failed
1151 */
1152 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) {
1153   int32_t ret, stat;
1154
1155   // Send "SET COM" command to USART Server
1156   memset(ptr_tx_buf, 0, CMD_LEN);
1157   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);
1158   if ((stat > 0) && (stat < (int32_t)CMD_LEN)) {
1159     ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1160     (void)osDelay(10U);
1161   } else {
1162     ret = EXIT_FAILURE;
1163   }
1164
1165   if (ret != EXIT_SUCCESS) {
1166     TEST_FAIL_MESSAGE("[FAILED] Set communication settings on USART Server. Check USART Server! Test aborted!");
1167   }
1168
1169   return ret;
1170 }
1171
1172 /**
1173   \fn            static int32_t CmdXfer (uint32_t dir, uint32_t num, uint32_t delay, uint32_t timeout, uint32_t num_cts)
1174   \brief         Activate transfer on USART Server.
1175   \param[in]     dir            direction of transfer 
1176                                   - 0 = Send (Tx)
1177                                   - 1 = Receive (Rx)
1178                                   - 2 = Transfer (simultaneous Tx and Rx (in synchronous mode only))
1179   \param[in]     num            number of items (according CMSIS USART driver specification)
1180   \param[in]     delay          initial delay, in milliseconds, before starting requested operation 
1181                                 (0xFFFFFFFF = delay not used)
1182   \param[in]     timeout        timeout in milliseconds, after delay, if delay is specified
1183   \param[in]     num_cts        number of items after which CTS line should be de-activated
1184                                   - 0 = no CTS deactivation
1185   \return        execution status
1186                    - EXIT_SUCCESS: Command sent successfully
1187                    - EXIT_FAILURE: Command send failed
1188 */
1189 static int32_t CmdXfer (uint32_t dir, uint32_t num, uint32_t delay, uint32_t timeout, uint32_t num_cts) {
1190   int32_t ret;
1191
1192   // Send "XFER" command to USART Server
1193   memset(ptr_tx_buf, 0, CMD_LEN);
1194   if (num_cts != 0U) {
1195     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i,%i,%i", dir, num, delay, timeout, num_cts);
1196   } else if ((delay != osWaitForever) && (timeout != 0U)) {
1197     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i,%i",    dir, num, delay, timeout);
1198   } else if (delay != osWaitForever) {
1199     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i,%i",       dir, num, delay);
1200   } else {
1201     (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "XFER %i,%i",          dir, num);
1202   }
1203   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1204
1205   if (ret != EXIT_SUCCESS) {
1206     TEST_FAIL_MESSAGE("[FAILED] Activate transfer on USART Server. Check USART Server! Test aborted!");
1207   }
1208
1209   return ret;
1210 }
1211
1212 /*
1213   \fn            static int32_t CmdGetCnt (void)
1214   \brief         Get XFER command Tx/Rx count from USART Server.
1215   \return        execution status
1216                    - EXIT_SUCCESS: Operation successful
1217                    - EXIT_FAILURE: Operation failed
1218 */
1219 static int32_t CmdGetCnt (void) {
1220   int32_t     ret;
1221   const char *ptr_str;
1222   uint32_t    val32;
1223
1224   xfer_count = 0U;
1225
1226   // Send "GET CNT" command to USART Server
1227   memset(ptr_tx_buf, 0, CMD_LEN);
1228   memcpy(ptr_tx_buf, "GET CNT", 7);
1229   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1230
1231   if (ret == EXIT_SUCCESS) {
1232     // Receive response to "GET CNT" command from USART Server
1233     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_CNT_LEN);
1234     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_CNT_LEN);
1235     (void)osDelay(10U);
1236   }
1237
1238   if (ret == EXIT_SUCCESS) {
1239     // Parse count
1240     ptr_str = (const char *)ptr_rx_buf;
1241     if (sscanf(ptr_str, "%i", &val32) == 1) {
1242       xfer_count = val32;
1243     } else {
1244       ret = EXIT_FAILURE;
1245     }
1246   }
1247
1248   if (ret != EXIT_SUCCESS) {
1249     TEST_FAIL_MESSAGE("[FAILED] Get count from USART Server. Check USART Server! Test aborted!");
1250   }
1251
1252   return ret;
1253 }
1254
1255 /*
1256   \fn            static int32_t CmdSetBrk (uint32_t delay, uint32_t duration)
1257   \brief         Request USART Server to send break signal.
1258   \param[in]     delay:         initial delay, in milliseconds, before start of break signaling
1259   \param[in]     duration:      duration, in milliseconds, of break signaling
1260   \return        execution status
1261                    - EXIT_SUCCESS: Command sent successfully
1262                    - EXIT_FAILURE: Command send failed
1263 */
1264 static int32_t CmdSetBrk (uint32_t delay, uint32_t duration) {
1265   int32_t ret;
1266
1267   // Send "SET BRK" command to USART Server
1268   memset(ptr_tx_buf, 0, CMD_LEN);
1269   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET BRK %i,%i", delay, duration);
1270   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1271
1272   if (ret != EXIT_SUCCESS) {
1273     TEST_FAIL_MESSAGE("[FAILED] Set break on USART Server. Check USART Server! Test aborted!");
1274   }
1275
1276   return ret;
1277 }
1278
1279 /**
1280   \fn            static int32_t CmdGetBrk (void)
1281   \brief         Get information on Break state from USART Server.
1282   \return        execution status
1283                    - EXIT_SUCCESS: Command sent and response received successfully
1284                    - EXIT_FAILURE: Command send or response reception failed
1285 */
1286 static int32_t CmdGetBrk (void) {
1287   int32_t ret;
1288
1289   // Send "GET BRK" command to USART Server
1290   memset(ptr_tx_buf, 0, CMD_LEN);
1291   memcpy(ptr_tx_buf, "GET BRK", 7);
1292   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1293
1294   if (ret == EXIT_SUCCESS) {
1295     // Receive response to "GET BRK" command from USART Server
1296     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_BRK_LEN);
1297     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_BRK_LEN);
1298     (void)osDelay(10U);
1299   }
1300
1301   // Store modem status to global variable
1302   if (ret == EXIT_SUCCESS) {
1303     break_status = ptr_rx_buf[0] - '0';
1304   }
1305
1306   if (ret != EXIT_SUCCESS) {
1307     TEST_FAIL_MESSAGE("[FAILED] Get break state from USART Server. Check USART Server! Test aborted!");
1308   }
1309
1310   return ret;
1311 }
1312
1313 /**
1314   \fn            static int32_t CmdSetMdm (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration)
1315   \brief         Set modem lines on USART Server.
1316   \param[in]     mdm_ctrl:      modem control line states:
1317                                   - bit 0.: RTS state
1318                                   - bit 1.: DTS state
1319                                   - bit 2.: Line to USART Client's DCD state
1320                                   - bit 3.: Line to USART Client's RI state
1321   \param[in]     delay:         initial delay, in milliseconds, before start of controlling modem lines
1322   \param[in]     duration:      duration, in milliseconds, of controlling modem lines
1323   \return        execution status
1324                    - EXIT_SUCCESS: Command sent successfully
1325                    - EXIT_FAILURE: Command send failed
1326 */
1327 static int32_t CmdSetMdm (uint32_t mdm_ctrl, uint32_t delay, uint32_t duration) {
1328   int32_t ret;
1329
1330   // Send "SET MDM" command to USART Server
1331   memset(ptr_tx_buf, 0, CMD_LEN);
1332   (void)snprintf((char *)ptr_tx_buf, CMD_LEN, "SET MDM %x,%i,%i", mdm_ctrl, delay, duration);
1333   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1334
1335   if (ret != EXIT_SUCCESS) {
1336     TEST_FAIL_MESSAGE("[FAILED] Set modem control on USART Server. Check USART Server! Test aborted!");
1337   }
1338
1339   return ret;
1340 }
1341
1342 /**
1343   \fn            static int32_t CmdGetMdm (void)
1344   \brief         Get information on modem lines current state from USART Server.
1345   \return        execution status
1346                    - EXIT_SUCCESS: Command sent and response received successfully
1347                    - EXIT_FAILURE: Command send or response reception failed
1348 */
1349 static int32_t CmdGetMdm (void) {
1350   int32_t ret;
1351
1352   // Send "GET MDM" command to USART Server
1353   memset(ptr_tx_buf, 0, CMD_LEN);
1354   memcpy(ptr_tx_buf, "GET MDM", 7);
1355   ret = ComSendCommand(ptr_tx_buf, CMD_LEN);
1356
1357   if (ret == EXIT_SUCCESS) {
1358     // Receive response to "GET MDM" command from USART Server
1359     memset(ptr_rx_buf, (int32_t)'?', RESP_GET_MDM_LEN);
1360     ret = ComReceiveResponse(ptr_rx_buf, RESP_GET_MDM_LEN);
1361     (void)osDelay(10U);
1362   }
1363
1364   // Store modem status to global variable
1365   if (ret == EXIT_SUCCESS) {
1366     modem_status = ptr_rx_buf[0] - '0';
1367   }
1368
1369   if (ret != EXIT_SUCCESS) {
1370     TEST_FAIL_MESSAGE("[FAILED] Get modem lines state from USART Server. Check USART Server! Test aborted!");
1371   }
1372
1373   return ret;
1374 }
1375
1376 /*
1377   \fn            static int32_t ServerInit (void)
1378   \brief         Initialize communication with USART Server, get version and capabilities.
1379   \return        execution status
1380                    - EXIT_SUCCESS: USART Server initialized successfully
1381                    - EXIT_FAILURE: USART Server initialization failed
1382 */
1383 static int32_t ServerInit (void) {
1384
1385   if (server_ok == -1) {                // If -1, means it was not yet checked
1386     server_ok = 1;
1387
1388     if (drv->Control(((USART_CFG_SRV_MODE         << ARM_USART_CONTROL_Pos)      & ARM_USART_CONTROL_Msk)      |
1389                        DRIVER_DATA_BITS(USART_CFG_SRV_DATA_BITS)                                               |
1390                      ((USART_CFG_SRV_PARITY       << ARM_USART_PARITY_Pos)       & ARM_USART_PARITY_Msk)       |
1391                      ((USART_CFG_SRV_STOP_BITS    << ARM_USART_STOP_BITS_Pos)    & ARM_USART_STOP_BITS_Msk)    |
1392                      ((USART_CFG_SRV_FLOW_CONTROL << ARM_USART_FLOW_CONTROL_Pos) & ARM_USART_FLOW_CONTROL_Msk) ,
1393                        USART_CFG_SRV_BAUDRATE) != ARM_DRIVER_OK) {
1394       server_ok = 0;
1395     }
1396     if (server_ok == 0) {
1397       TEST_GROUP_INFO("Failed to configure communication interface to USART Server default settings.\n"\
1398                       "Driver must support basic settings used for communication with USART Server!");
1399     }
1400
1401     if (server_ok == 1) {
1402       (void)osDelay(10U);
1403       if (CmdGetVer() != EXIT_SUCCESS) {
1404         TEST_GROUP_INFO("Failed to Get version from USART Server.\nCheck USART Server!\n");
1405         server_ok = 0;
1406       }
1407     }
1408
1409     if (server_ok == 1) {
1410       if (usart_serv_ver.major == 0U) { 
1411         TEST_GROUP_INFO("USART Server version must be 1.0.0. or higher.\nUpdate USART Server to newer version!\n");
1412         server_ok = 0;
1413       }
1414     }
1415
1416     if (server_ok == 1) {
1417       if (CmdGetCap() != EXIT_SUCCESS) {
1418         TEST_GROUP_INFO("Failed to Get capabilities from USART Server.\nCheck USART Server!\n");
1419         server_ok = 0;
1420       }
1421     }
1422   }
1423
1424   if (server_ok == 1) {
1425     return EXIT_SUCCESS;
1426   }
1427
1428   return EXIT_FAILURE;
1429 }
1430
1431 /*
1432   \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)
1433   \brief         Check if USART Server is functional and if it supports desired settings.
1434   \detail        Parameters describe settings required to test, so server must support complementary sattings.
1435                  For example to test RTS line server must support CTS line.
1436   \param[in]     mode           mode (expected to be tested):
1437                                   - value 1 = Asynchronous
1438                                   - value 2 = Synchronous Master
1439                                   - value 3 = Synchronous Slave
1440                                   - value 4 = Single Wire
1441                                   - value 5 = IrDA
1442                                   - value 6 = Smart Card
1443   \param[in]     data_bits      data bits (5 .. 9)
1444   \param[in]     parity         parity:
1445                                   - value 0 = None
1446                                   - value 1 = Even
1447                                   - value 2 = Odd
1448   \param[in]     stop_bits      stop bits:
1449                                   - value 0 = 1 Stop Bit
1450                                   - value 1 = 2 Stop Bits
1451                                   - value 2 = 1.5 Stop Bits
1452                                   - value 3 = 0.5 Stop Bits
1453   \param[in]     flow_control   flow control:
1454                                   - value 0 = None
1455                                   - value 1 = CTS
1456                                   - value 2 = RTS
1457                                   - value 3 = RTS/CTS
1458   \param[in]     modem_line_mask  modem line mask:
1459                                   - bit 0. = RTS
1460                                   - bit 1. = CTS
1461                                   - bit 2. = DTR
1462                                   - bit 3. = DSR
1463                                   - bit 4. = DCD
1464                                   - bit 5. = RI
1465   \param[in]     baudrate       baudrate in bauds
1466   \return        execution status
1467                    - EXIT_SUCCESS: USART Server supports desired settings
1468                    - EXIT_FAILURE: USART Server does not support desired settings
1469 */
1470 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) {
1471   uint32_t srv_mode, srv_flow_control, srv_modem_line_mask;
1472
1473   if (server_ok == 0) {
1474     TEST_FAIL_MESSAGE("[FAILED] USART Server status. Check USART Server! Test aborted!");
1475     return EXIT_FAILURE;
1476   }
1477
1478 #if   (USART_CFG_SRV_MODE == MODE_ASYNCHRONOUS)
1479     if ((mode == MODE_SINGLE_WIRE) || (mode == MODE_IRDA)) {
1480       TEST_MESSAGE("[FAILED] USART Server mode Asynchronous does not support requested test mode! Test aborted!");
1481       return EXIT_FAILURE;
1482     }
1483 #elif (USART_CFG_SRV_MODE == MODE_SINGLE_WIRE)
1484     if (mode != MODE_SINGLE_WIRE) {
1485       TEST_MESSAGE("[FAILED] USART Server mode Single-wire does not support requested test mode! Test aborted!");
1486       return EXIT_FAILURE;
1487     }
1488 #elif (USART_CFG_SRV_MODE == MODE_SINGLE_IRDA)
1489     if (mode != MODE_SINGLE_IRDA) {
1490       TEST_MESSAGE("[FAILED] USART Server mode IrDA does not support requested test mode! Test aborted!");
1491       return EXIT_FAILURE;
1492     }
1493 #else
1494     TEST_MESSAGE("[FAILED] USART Server mode unknown! Test aborted!");
1495     return EXIT_FAILURE;
1496 #endif
1497
1498   srv_mode = mode;
1499   if (mode == MODE_SYNCHRONOUS_MASTER) {        // If mode to be tested is Synchro Master then server must support Slave
1500     srv_mode = MODE_SYNCHRONOUS_SLAVE;
1501   } else if (mode == MODE_SYNCHRONOUS_SLAVE) {  // If mode to be tested is Synchro Slave  then server must support Master
1502     srv_mode = MODE_SYNCHRONOUS_MASTER;
1503   }
1504
1505   srv_flow_control = flow_control;
1506   if (flow_control == FLOW_CONTROL_RTS) {
1507     srv_flow_control = FLOW_CONTROL_CTS;
1508   }
1509   if (flow_control == FLOW_CONTROL_CTS) {
1510     srv_flow_control = FLOW_CONTROL_RTS;
1511   }
1512
1513   srv_modem_line_mask = 0U;
1514   if ((modem_line_mask & RTS_AVAILABLE   ) != 0U) {
1515     srv_modem_line_mask |= CTS_AVAILABLE;
1516   }
1517   if ((modem_line_mask & CTS_AVAILABLE   ) != 0U) {
1518     srv_modem_line_mask |= RTS_AVAILABLE;
1519   }
1520   if ((modem_line_mask & DTR_AVAILABLE   ) != 0U) {
1521     srv_modem_line_mask |= DSR_AVAILABLE;
1522   }
1523   if ((modem_line_mask & DSR_AVAILABLE   ) != 0U) {
1524     srv_modem_line_mask |= DTR_AVAILABLE;
1525   }
1526   if ((modem_line_mask & DCD_AVAILABLE) != 0U) {
1527     srv_modem_line_mask |= DCD_AVAILABLE;
1528   }
1529   if ((modem_line_mask & RI_AVAILABLE ) != 0U) {
1530     srv_modem_line_mask |= RI_AVAILABLE;
1531   }
1532
1533   if ((usart_serv_cap.mode_mask & (1UL << (srv_mode - 1U))) == 0U) {
1534     // If USART Server does not support desired mode
1535     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s mode! Test aborted!", str_mode[mode]);
1536     TEST_MESSAGE(msg_buf);
1537     return EXIT_FAILURE;
1538   }
1539   if ((usart_serv_cap.db_mask & (1UL << (data_bits - 5U))) == 0U) {
1540     // If USART Server does not support desired data bits
1541     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %i data bits! Test aborted!", data_bits);
1542     TEST_MESSAGE(msg_buf);
1543     return EXIT_FAILURE;
1544   }
1545   if ((usart_serv_cap.parity_mask & (1UL << parity)) == 0U) {
1546     // If USART Server does not support desired parity
1547     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s parity! Test aborted!", str_parity[parity]);
1548     TEST_MESSAGE(msg_buf);
1549     return EXIT_FAILURE;
1550   }
1551   if ((usart_serv_cap.sb_mask & (1UL << stop_bits)) == 0U) {
1552     // If USART Server does not support desired stop bits
1553     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s stop bits! Test aborted!", str_stop_bits[stop_bits]);
1554     TEST_MESSAGE(msg_buf);
1555     return EXIT_FAILURE;
1556   }
1557   if ((usart_serv_cap.fc_mask & (1UL << srv_flow_control)) == 0U) {
1558     // If USART Server does not support desired flow control
1559     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %s flow control! Test aborted!", str_flow_control[flow_control]);
1560     TEST_MESSAGE(msg_buf);
1561     return EXIT_FAILURE;
1562   }
1563   if (srv_modem_line_mask != 0U) {
1564     if ((usart_serv_cap.ml_mask & srv_modem_line_mask) == 0U) {
1565       // If USART Server does not support desired modem line
1566       TEST_MESSAGE("[FAILED] USART Server does not support desired modem line! Test aborted!");
1567       return EXIT_FAILURE;
1568     }
1569   }
1570   if ((usart_serv_cap.br_min > baudrate) ||
1571       (usart_serv_cap.br_max < baudrate)) {
1572     // If USART Server does not support desired baudrate
1573     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] USART Server does not support %i baudrate bus speed! Test aborted!", baudrate);
1574     TEST_MESSAGE(msg_buf);
1575     return EXIT_FAILURE;
1576   }
1577
1578   return EXIT_SUCCESS;
1579 }
1580
1581 #endif                                  // If Test Mode USART Server is selected
1582
1583 /*
1584   \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)
1585   \brief         Check if Driver and USART Server (if used) is functional and if it supports desired settings.
1586   \detail        Parameters describe settings required to test, so server must support complementary sattings.
1587                  For example to test RTS line server must support CTS line.
1588   \param[in]     mode           mode (expected to be tested):
1589                                   - value 1 = Asynchronous
1590                                   - value 2 = Synchronous Master
1591                                   - value 3 = Synchronous Slave
1592                                   - value 4 = Single Wire
1593                                   - value 5 = IrDA
1594                                   - value 6 = Smart Card
1595   \param[in]     data_bits      data bits (5 .. 9)
1596   \param[in]     parity         parity:
1597                                   - value 0 = None
1598                                   - value 1 = Even
1599                                   - value 2 = Odd
1600   \param[in]     stop_bits      stop bits:
1601                                   - value 0 = 1 Stop Bit
1602                                   - value 1 = 2 Stop Bits
1603                                   - value 2 = 1.5 Stop Bits
1604                                   - value 3 = 0.5 Stop Bits
1605   \param[in]     flow_control   flow control:
1606                                   - value 0 = None
1607                                   - value 1 = CTS
1608                                   - value 2 = RTS
1609                                   - value 3 = RTS/CTS
1610   \param[in]     modem_line_mask  modem line mask:
1611                                   - bit 0. = RTS
1612                                   - bit 1. = CTS
1613                                   - bit 2. = DTR
1614                                   - bit 3. = DSR
1615                                   - bit 4. = DCD
1616                                   - bit 5. = RI
1617   \param[in]     baudrate       baudrate in bauds
1618   \return        execution status
1619                    - EXIT_SUCCESS: Driver and USART Server supports desired settings
1620                    - EXIT_FAILURE: Driver or USART Server does not support desired settings
1621 */
1622 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) {
1623
1624   if (BuffersCheck()  != EXIT_SUCCESS) { 
1625     return EXIT_FAILURE;
1626   }
1627
1628   if (DriverCheck (mode, flow_control, modem_line_mask) != EXIT_SUCCESS) { 
1629     return EXIT_FAILURE;
1630   }
1631 #if  (USART_SERVER_USED == 1)
1632   if (ServerCheck (mode, data_bits, parity, stop_bits, flow_control, modem_line_mask, baudrate) != EXIT_SUCCESS) {
1633     return EXIT_FAILURE;
1634   }
1635 #else
1636   (void)data_bits;
1637   (void)parity;
1638   (void)stop_bits;
1639   (void)baudrate;
1640 #endif
1641
1642   return EXIT_SUCCESS;
1643 }
1644
1645 /*
1646   \fn            void USART_DV_Initialize (void)
1647   \brief         Initialize testing environment for USART testing.
1648   \detail        This function is called by the driver validation framework before USART testing begins.
1649                  It initializes global variables and allocates memory buffers (from heap) used for the USART testing.
1650   \return        none
1651 */
1652 void USART_DV_Initialize (void) {
1653
1654   // Initialize global variables
1655   buffers_ok   = -1;
1656   server_ok    = -1;
1657   driver_ok    = -1;
1658   event        = 0U;
1659   duration     = 0xFFFFFFFFUL;
1660   systick_freq = osKernelGetSysTimerFreq();
1661   if (systick_freq == 0U) {
1662     // systick_freq must not be 0
1663     systick_freq = 1U;
1664   }
1665   ticks_per_ms = systick_freq / 1000U;
1666
1667   memset(&usart_serv_cap, 0, sizeof(usart_serv_cap));
1668   memset(&msg_buf,        0, sizeof(msg_buf));
1669
1670   // Allocate buffers for transmission, reception and comparison
1671   // (maximum size is incremented by 32 bytes to ensure that buffer can be aligned to 32 bytes)
1672
1673   ptr_tx_buf_alloc = malloc(USART_BUF_MAX + 32U);
1674   if (((uint32_t)ptr_tx_buf_alloc & 31U) != 0U) {
1675     // If allocated memory is not 32 byte aligned, use next 32 byte aligned address for ptr_tx_buf
1676     ptr_tx_buf = (uint8_t *)((((uint32_t)ptr_tx_buf_alloc) + 31U) & (~31U));
1677   } else {
1678     // If allocated memory is 32 byte aligned, use it directly
1679     ptr_tx_buf = (uint8_t *)ptr_tx_buf_alloc;
1680   }
1681   ptr_rx_buf_alloc = malloc(USART_BUF_MAX + 32U);
1682   if (((uint32_t)ptr_rx_buf_alloc & 31U) != 0U) {
1683     ptr_rx_buf = (uint8_t *)((((uint32_t)ptr_rx_buf_alloc) + 31U) & (~31U));
1684   } else {
1685     ptr_rx_buf = (uint8_t *)ptr_rx_buf_alloc;
1686   }
1687   ptr_cmp_buf_alloc = malloc(USART_BUF_MAX + 32U);
1688   if (((uint32_t)ptr_cmp_buf_alloc & 31U) != 0U) {
1689     ptr_cmp_buf = (uint8_t *)((((uint32_t)ptr_cmp_buf_alloc) + 31U) & (~31U));
1690   } else {
1691     ptr_cmp_buf = (uint8_t *)ptr_cmp_buf_alloc;
1692   }
1693
1694   event_flags = osEventFlagsNew(NULL);
1695
1696   // Output configuration settings
1697   (void)snprintf(msg_buf, 
1698                  sizeof(msg_buf),
1699                  "Test Mode:          %s\n"\
1700                  "Default settings:\n"\
1701                  " - Mode:            %s\n"\
1702                  " - Data bits:       %i\n"\
1703                  " - Parity:          %s\n"\
1704                  " - Stop bits:       %s\n"\
1705                  " - Flow control:    %s\n"\
1706                  " - Clock polarity:  %s\n"\
1707                  " - Clock phase:     %s\n"\
1708                  " - Bus speed:       %i bauds\n"\
1709                  " - Number of Items: %i",
1710                  str_test_mode   [USART_CFG_TEST_MODE],
1711                  str_mode        [USART_CFG_DEF_MODE],
1712                  USART_CFG_DEF_DATA_BITS,
1713                  str_parity      [USART_CFG_DEF_PARITY],
1714                  str_stop_bits   [USART_CFG_DEF_STOP_BITS],
1715                  str_flow_control[USART_CFG_DEF_FLOW_CONTROL],
1716                  str_cpol        [USART_CFG_DEF_CPOL],
1717                  str_cpha        [USART_CFG_DEF_CPHA],
1718                  USART_CFG_DEF_BAUDRATE,
1719                  USART_CFG_DEF_NUM);
1720   TEST_GROUP_INFO(msg_buf);
1721
1722   drv_cap = drv->GetCapabilities();
1723
1724 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
1725   // Test communication with USART Server
1726   int32_t server_status;
1727
1728   // Test communication with USART Server
1729   server_status = EXIT_FAILURE;
1730   if (drv->Initialize    (USART_DrvEvent) == ARM_DRIVER_OK) {
1731     if (drv->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK) {
1732       server_status = ServerInit();
1733     }
1734   }
1735   (void)drv->PowerControl(ARM_POWER_OFF);
1736   (void)drv->Uninitialize();
1737
1738   if (server_status != EXIT_SUCCESS) {
1739     (void)snprintf(msg_buf, sizeof(msg_buf), "Server status:      %s\n", str_srv_status[server_status]);
1740     TEST_GROUP_INFO(msg_buf);
1741   }
1742 #endif
1743 }
1744
1745 /*
1746   \fn            void USART_DV_Uninitialize (void)
1747   \brief         De-initialize testing environment after USART testing.
1748   \detail        This function is called by the driver validation framework after USART testing is finished.
1749                  It frees memory buffers used for the USART testing.
1750   \return        none
1751 */
1752 void USART_DV_Uninitialize (void) {
1753
1754   (void)osEventFlagsDelete(event_flags);
1755
1756   if (ptr_tx_buf_alloc != NULL) {
1757     free(ptr_tx_buf_alloc);
1758     ptr_tx_buf        = NULL;
1759     ptr_tx_buf_alloc  = NULL;
1760   }
1761   if (ptr_rx_buf_alloc != NULL) {
1762     free(ptr_rx_buf_alloc);
1763     ptr_rx_buf        = NULL;
1764     ptr_rx_buf_alloc  = NULL;
1765   }
1766   if (ptr_cmp_buf_alloc != NULL) {
1767     free(ptr_cmp_buf_alloc);
1768     ptr_cmp_buf       = NULL;
1769     ptr_cmp_buf_alloc = NULL;
1770   }
1771 }
1772
1773 #endif                                  // End of exclude form the documentation
1774
1775 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1776 /**
1777 \defgroup dv_usart USART Validation
1778 \brief USART driver validation
1779 \details
1780 The USART validation performs the following tests:
1781 - API interface compliance
1782 - Data exchange with various speeds, transfer sizes and communication settings
1783 - Modem lines operation
1784 - Event signaling
1785
1786 Two Test Modes are available: <b>Loopback</b> and <b>USART Server</b>.
1787
1788 Test Mode : <b>Loopback</b>
1789 ---------------------------
1790
1791 This test mode allows only limited validation of the USART Driver.<br>
1792 It is recommended that this test mode is used only as a proof that driver is 
1793 good enough to be tested with the <b>USART Server</b>.
1794
1795 For this purpose following <b>Default settings</b> should be used:
1796  - Mode: Asynchronous
1797  - Data Bits: 8
1798  - Parity: None
1799  - Stop Bits: 1
1800  - Flow control: No
1801  - Clock Polarity: Clock Polarity 0
1802  - Clock Phase: Clock Phase 0
1803  - Baudrate: 115200
1804  - Number of Items: 32
1805
1806 To enable this mode of testing in the <b>DV_USART_Config.h</b> configuration file select the
1807 <b>Configuration: Test Mode: Loopback</b> setting.
1808
1809 Required pin connection for the <b>Loopback</b> test mode:
1810
1811 \image html usart_loopback_pin_connections.png
1812
1813 \note In this mode following operations / settings cannot be tested:
1814  - synchronous slave or single-wire modes
1815  - operation of the Receive function
1816  - data content sent by the Send function
1817  - parity, stop bits, flow control, clock polarity / phase settings
1818  - data bit settings other then 8
1819  - modem lines operation
1820  - event signaling
1821
1822 \anchor usart_server_con
1823
1824 Test Mode : <b>USART Server</b>
1825 -----------------------------
1826
1827 This test mode allows extensive validation of the USART Driver.<br>
1828 Results of the Driver Validation in this test mode are relevant as a proof of driver compliance 
1829 to the CMSIS-Driver specification.
1830
1831 To perform extensive communication tests, it is required to use an 
1832 \ref usart_server "USART Server" running on a dedicated hardware.
1833
1834 To enable this mode of testing in the <b>DV_USART_Config.h</b> configuration file select the
1835 <b>Configuration: Test Mode: USART Server</b> setting.
1836
1837 Required pin connections for the <b>USART Server</b> test mode with <b>USART Server Mode</b>: <b>Asynchronous</b> or <b>IrDa</b>
1838
1839 \note Only necessary pin connections are Tx, Rx and GND. Flow control (RTS, CTS), modem lines (DSR, DTR, DCD, RI) and 
1840 synchronous clock (CLK) line are optional and depend on pin availability and driver support for flow control, modem lines and 
1841 synchronous mode.
1842 \note For stable idle level on Rx lines, external pull-ups can be added.
1843
1844 \image html usart_server_pin_connections_async.png
1845
1846 Required pin connections for the <b>USART Server</b> test mode with <b>USART Server Mode</b>: <b>Single-wire</b>
1847
1848 \image html usart_server_pin_connections_single_wire.png
1849
1850 \note Asynchronous and IrDa modes use same connection type and Single-wire uses a different connection. 
1851 \note Please ensure that correct connection is used as required by tests otherwise damage to hardware may occur 
1852       (For example using Asynchronous mode selected with hardware connected for Single-wire tests can result in damaged pins).
1853 \note In this mode Tx and Rx pins are internally connected together.
1854 \note Tx pin should use open-drain setting in this mode to prevent damage in case of simultaneous 
1855       driving from both USART Server and USART Client.
1856
1857 \note To ensure proper signal quality:
1858        - keep the connecting wires as short as possible
1859        - if possible keep Tx and Rx wires wires separate from each other
1860        - ensure a good Ground (GND) connection between USART Server and DUT
1861
1862 \defgroup usart_tests Tests
1863 \ingroup dv_usart
1864 */
1865
1866 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1867 /* USART Driver Management tests                                                                                              */
1868 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1869 /**
1870 \defgroup usart_tests_drv_mgmt Driver Management
1871 \ingroup usart_tests
1872 \details
1873 These tests verify API and operation of the USART driver management functions.
1874
1875 The driver management tests verify the following driver functions
1876 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
1877  - \b GetVersion
1878 \code
1879   ARM_DRIVER_VERSION     GetVersion      (void);
1880 \endcode
1881  - \b GetCapabilities
1882 \code
1883   ARM_USART_CAPABILITIES GetCapabilities (void);
1884 \endcode
1885  - \b Initialize
1886 \code
1887   int32_t                Initialize      (ARM_USART_SignalEvent_t cb_event);
1888 \endcode
1889  - \b Uninitialize
1890 \code
1891   int32_t                Uninitialize    (void);
1892 \endcode
1893  - \b PowerControl
1894 \code
1895   int32_t                PowerControl    (ARM_POWER_STATE state);
1896 \endcode
1897
1898 @{
1899 */
1900
1901 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1902 /**
1903 \brief Function: Function USART_GetVersion
1904 \details
1905 The function \b UDSART_GetVersion verifies the \b GetVersion function.
1906 \code
1907   ARM_DRIVER_VERSION GetVersion (void);
1908 \endcode
1909
1910 Testing sequence:
1911   - Driver is uninitialized and peripheral is powered-off:
1912     - Call GetVersion function
1913     - Assert that GetVersion function returned version structure with API and implementation versions higher or equal to 1.0
1914 */
1915 void USART_GetVersion (void) {
1916   ARM_DRIVER_VERSION ver;
1917
1918   ver = drv->GetVersion();
1919
1920   // Assert that GetVersion function returned version structure with API and implementation versions higher or equal to 1.0
1921   TEST_ASSERT((ver.api >= ARM_DRIVER_VERSION_MAJOR_MINOR(1UL,0UL)) && (ver.drv >= ARM_DRIVER_VERSION_MAJOR_MINOR(1UL,0UL)));
1922
1923   (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));
1924   TEST_MESSAGE(msg_buf);
1925 }
1926
1927 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1928 /**
1929 \brief Function: Function USART_GetCapabilities
1930 \details
1931 The function \b USART_GetCapabilities verifies the \b GetCapabilities function.
1932 \code
1933   ARM_USART_CAPABILITIES GetCapabilities (void);
1934 \endcode
1935
1936 Testing sequence:
1937   - Driver is uninitialized and peripheral is powered-off:
1938     - Call GetCapabilities function
1939     - Assert that GetCapabilities function returned capabilities structure with reserved field 0
1940 */
1941 void USART_GetCapabilities (void) {
1942   ARM_USART_CAPABILITIES cap;
1943
1944   cap = drv->GetCapabilities();
1945
1946   // Assert that GetCapabilities function returned capabilities structure with reserved field 0
1947   TEST_ASSERT_MESSAGE((cap.reserved == 0U), "[FAILED] Capabilities reserved field must be 0");
1948 }
1949
1950 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
1951 /**
1952 \brief Function: Function USART_Initialize_Uninitialize
1953 \details
1954 The function \b USART_Initialize_Uninitialize verifies the \b Initialize and \b Uninitialize functions.
1955 \code
1956   int32_t Initialize (ARM_USART_SignalEvent_t cb_event);
1957 \endcode
1958 \code
1959   int32_t Uninitialize (void);
1960 \endcode
1961
1962 Testing sequence:
1963   - Driver is uninitialized and peripheral is powered-off:
1964     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_ERROR status
1965     - Call PowerControl(ARM_POWER_LOW) function and assert that it returned ARM_DRIVER_ERROR status
1966     - Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_ERROR status
1967     - Call Send function and assert that it returned ARM_DRIVER_ERROR status
1968     - Call Receive function and assert that it returned ARM_DRIVER_ERROR status
1969     - Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
1970     - Call GetTxCount function and assert that it returned 0
1971     - Call GetRxCount function and assert that it returned 0
1972     - Call Control function and assert that it returned ARM_DRIVER_ERROR status
1973     - Call GetStatus function
1974     - Assert that GetStatus function returned status structure with tx_busy flag 0
1975     - Assert that GetStatus function returned status structure with rx_busy flag 0
1976     - Assert that GetStatus function returned status structure with tx_underflow flag 0
1977     - Assert that GetStatus function returned status structure with rx_overflow flag 0
1978     - Assert that GetStatus function returned status structure with rx_break flag 0
1979     - Assert that GetStatus function returned status structure with rx_framing_error flag 0
1980     - Assert that GetStatus function returned status structure with rx_parity_error flag 0
1981     - Assert that GetStatus function returned status structure with reserved field 0
1982     - Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
1983   - Driver is initialized and peripheral is powered-off:
1984     - Call Initialize function (without callback specified) again and assert that it returned ARM_DRIVER_OK status
1985     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
1986   - Driver is uninitialized and peripheral is powered-off:
1987     - Call Initialize function (with callback specified) and assert that it returned ARM_DRIVER_OK status
1988   - Driver is initialized and peripheral is powered-off:
1989     - Call Initialize function (with callback specified) again and assert that it returned ARM_DRIVER_OK status
1990     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
1991   - Driver is uninitialized and peripheral is powered-off:
1992     - Call Uninitialize function again and assert that it returned ARM_DRIVER_OK status
1993     - Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
1994   - Driver is initialized and peripheral is powered-off:
1995     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
1996   - Driver is initialized and peripheral is powered-on:
1997     - Call Control function and assert that it returned ARM_DRIVER_OK status
1998     - Call Uninitialize function and assert that it returned ARM_DRIVER_OK status<br>
1999       (this must unconditionally terminate active send/receive/transfer, power-off the peripheral and uninitialize the driver)
2000   - Driver is uninitialized and peripheral is powered-off:
2001     - Call GetStatus function
2002     - Assert that GetStatus function returned status structure with tx_busy flag 0
2003     - Assert that GetStatus function returned status structure with rx_busy flag 0
2004 */
2005 void USART_Initialize_Uninitialize (void) {
2006   ARM_USART_STATUS stat;
2007
2008   // Driver is uninitialized and peripheral is powered-off:
2009   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_ERROR status
2010   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_ERROR);
2011
2012   stat = drv->GetStatus();
2013
2014   // Call PowerControl(ARM_POWER_LOW) function and assert that it returned status different then ARM_DRIVER_OK
2015   TEST_ASSERT(drv->PowerControl (ARM_POWER_LOW) != ARM_DRIVER_OK);
2016
2017   stat = drv->GetStatus();
2018
2019   // Call Send function and assert that it returned ARM_DRIVER_ERROR status
2020   TEST_ASSERT(drv->Send (ptr_tx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2021
2022   // Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2023   TEST_ASSERT(drv->Receive (ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2024
2025   // Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2026   TEST_ASSERT(drv->Transfer (ptr_tx_buf, ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2027
2028   // Call Control function and assert that it returned ARM_DRIVER_ERROR status
2029   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);
2030
2031   // Call GetStatus function
2032   stat = drv->GetStatus();
2033
2034   // Assert that GetStatus function returned status structure with tx_busy flag 0
2035   TEST_ASSERT(stat.tx_busy == 0U);
2036
2037   // Assert that GetStatus function returned status structure with rx_busy flag 0
2038   TEST_ASSERT(stat.rx_busy == 0U);
2039
2040   // Assert that GetStatus function returned status structure with tx_underflow flag 0
2041   TEST_ASSERT(stat.tx_underflow == 0U);
2042
2043   // Assert that GetStatus function returned status structure with rx_overflow flag 0
2044   TEST_ASSERT(stat.rx_overflow == 0U);
2045
2046   // Assert that GetStatus function returned status structure with rx_break flag 0
2047   TEST_ASSERT(stat.rx_break == 0U);
2048
2049   // Assert that GetStatus function returned status structure with rx_framing_error flag 0
2050   TEST_ASSERT(stat.rx_framing_error == 0U);
2051
2052   // Assert that GetStatus function returned status structure with rx_parity_error flag 0
2053   TEST_ASSERT(stat.rx_parity_error == 0U);
2054
2055   // Assert that GetStatus function returned status structure with reserved field 0
2056   TEST_ASSERT(stat.reserved == 0U);
2057
2058   // Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
2059   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2060
2061   // Driver is initialized and peripheral is powered-off:
2062   // Call Initialize function (without callback specified) again and assert that it returned ARM_DRIVER_OK status
2063   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2064
2065   // Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
2066   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2067
2068   // Driver is uninitialized and peripheral is powered-off:
2069   // Call Initialize function (with callback specified) and assert that it returned ARM_DRIVER_OK status
2070   TEST_ASSERT(drv->Initialize (USART_DrvEvent) == ARM_DRIVER_OK);
2071
2072   // Driver is initialized and peripheral is powered-off:
2073   // Call Initialize function (with callback specified) again and assert that it returned ARM_DRIVER_OK status
2074   TEST_ASSERT(drv->Initialize (USART_DrvEvent) == ARM_DRIVER_OK);
2075
2076   // Call Uninitialize function and assert that it returned ARM_DRIVER_OK status
2077   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2078
2079   // Driver is uninitialized and peripheral is powered-off:
2080   // Call Uninitialize function again and assert that it returned ARM_DRIVER_OK status
2081   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2082
2083   // Call Initialize function (without callback specified) and assert that it returned ARM_DRIVER_OK status
2084   TEST_ASSERT(drv->Initialize (NULL) == ARM_DRIVER_OK);
2085
2086   // Driver is initialized and peripheral is powered-off:
2087   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2088   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2089
2090   // Driver is initialized and peripheral is powered-on:
2091   // Call Control function and assert that it returned ARM_DRIVER_OK status
2092   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2093                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2094                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2095                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_OK);
2096
2097   // Call Uninitialize function assert that it returned ARM_DRIVER_OK status
2098   // (this must unconditionally terminate active send/receive/transfer, power-off the peripheral and uninitialize the driver)
2099   TEST_ASSERT(drv->Uninitialize () == ARM_DRIVER_OK);
2100
2101   // Driver is uninitialized and peripheral is powered-off:
2102   // Call GetStatus function
2103   stat = drv->GetStatus();
2104
2105   // Assert that GetStatus function returned status structure with tx_busy flag 0
2106   TEST_ASSERT(stat.tx_busy == 0U);
2107
2108   // Assert that GetStatus function returned status structure with rx_busy flag 0
2109   TEST_ASSERT(stat.rx_busy == 0U);
2110 }
2111
2112 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2113 /**
2114 \brief Function: Function USART_PowerControl
2115 \details
2116 The function \b USART_PowerControl verifies the \b PowerControl function.
2117 \code
2118   int32_t PowerControl (ARM_POWER_STATE state);
2119 \endcode
2120
2121 Testing sequence:
2122   - Driver is initialized and peripheral is powered-off:
2123     - Call Send function and assert that it returned ARM_DRIVER_ERROR status
2124     - Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2125     - Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2126     - Call GetTxCount function and assert that it returned 0
2127     - Call GetRxCount function and assert that it returned 0
2128     - Call Control function and assert that it returned ARM_DRIVER_ERROR status
2129     - Call GetStatus function
2130     - Assert that GetStatus function returned status structure with tx_busy flag 0
2131     - Assert that GetStatus function returned status structure with rx_busy flag 0
2132     - Assert that GetStatus function returned status structure with tx_underflow flag 0
2133     - Assert that GetStatus function returned status structure with rx_overflow flag 0
2134     - Assert that GetStatus function returned status structure with rx_break flag 0
2135     - Assert that GetStatus function returned status structure with rx_framing_error flag 0
2136     - Assert that GetStatus function returned status structure with rx_parity_error flag 0
2137     - Assert that GetStatus function returned status structure with reserved field 0
2138     - Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2139     - Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2140     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2141   - Driver is initialized and peripheral is powered-on:
2142     - Call PowerControl(ARM_POWER_FULL) function again and assert that it returned ARM_DRIVER_OK status
2143     - Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2144   - Driver is initialized and peripheral is powered-off:
2145     - Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2146     - Call PowerControl(ARM_POWER_LOW) function
2147   - Driver is initialized and peripheral is powered-on or in low-power mode:
2148     - Assert that PowerControl(ARM_POWER_LOW) function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED status
2149     - Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2150   - Driver is initialized and peripheral is powered-on:
2151     - Call Control function and assert that it returned ARM_DRIVER_OK status
2152     - Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_OK status<br>
2153       (this must unconditionally terminate active send/receive/transfer and power-off the peripheral)
2154   - Driver is initialized and peripheral is powered-off:
2155     - Call GetStatus function
2156     - Assert that GetStatus function returned status structure with tx_busy flag 0
2157     - Assert that GetStatus function returned status structure with rx_busy flag 0
2158 */
2159 void USART_PowerControl (void) {
2160   int32_t          ret;
2161   ARM_USART_STATUS stat;
2162
2163   (void)drv->Initialize (NULL);
2164
2165   // Driver is initialized and peripheral is powered-off:
2166   // Call Send function and assert that it returned ARM_DRIVER_ERROR status
2167   TEST_ASSERT(drv->Send (ptr_tx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2168
2169   // Call Receive function and assert that it returned ARM_DRIVER_ERROR status
2170   TEST_ASSERT(drv->Receive (ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2171
2172   // Call Transfer function and assert that it returned ARM_DRIVER_ERROR status
2173   TEST_ASSERT(drv->Transfer (ptr_tx_buf, ptr_rx_buf, USART_CFG_DEF_NUM) == ARM_DRIVER_ERROR);
2174
2175   // Call Control function and assert that it returned ARM_DRIVER_ERROR status
2176   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2177                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2178                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2179                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_ERROR);
2180
2181   // Call GetStatus function
2182   stat = drv->GetStatus();
2183
2184   // Assert that GetStatus function returned status structure with tx_busy flag 0
2185   TEST_ASSERT(stat.tx_busy == 0U);
2186
2187   // Assert that GetStatus function returned status structure with rx_busy flag 0
2188   TEST_ASSERT(stat.rx_busy == 0U);
2189
2190   // Assert that GetStatus function returned status structure with tx_underflow flag 0
2191   TEST_ASSERT(stat.tx_underflow == 0U);
2192
2193   // Assert that GetStatus function returned status structure with rx_overflow flag 0
2194   TEST_ASSERT(stat.rx_overflow == 0U);
2195
2196   // Assert that GetStatus function returned status structure with rx_break flag 0
2197   TEST_ASSERT(stat.rx_break == 0U);
2198
2199   // Assert that GetStatus function returned status structure with rx_framing_error flag 0
2200   TEST_ASSERT(stat.rx_framing_error == 0U);
2201
2202   // Assert that GetStatus function returned status structure with rx_parity_error flag 0
2203   TEST_ASSERT(stat.rx_parity_error == 0U);
2204
2205   // Assert that GetStatus function returned status structure with reserved field 0
2206   TEST_ASSERT(stat.reserved == 0U);
2207
2208   // Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2209   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2210
2211   // Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2212   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2213
2214   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2215   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2216
2217   // Driver is initialized and peripheral is powered-on:
2218   // Call PowerControl(ARM_POWER_FULL) function again and assert that it returned ARM_DRIVER_OK status
2219   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2220
2221   // Call PowerControl(ARM_POWER_OFF) and assert that it returned ARM_DRIVER_OK status
2222   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2223
2224   // Driver is initialized and peripheral is powered-off:
2225   // Call PowerControl(ARM_POWER_OFF) again and assert that it returned ARM_DRIVER_OK status
2226   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2227
2228   // Call PowerControl(ARM_POWER_LOW) function
2229   ret = drv->PowerControl (ARM_POWER_LOW);
2230
2231   // Driver is initialized and peripheral is powered-on or in low-power mode:
2232   // Assert that PowerControl(ARM_POWER_LOW) function returned ARM_DRIVER_OK or ARM_DRIVER_ERROR_UNSUPPORTED status
2233   TEST_ASSERT((ret == ARM_DRIVER_OK) || (ret == ARM_DRIVER_ERROR_UNSUPPORTED));
2234   if (ret == ARM_DRIVER_ERROR_UNSUPPORTED) {
2235     TEST_MESSAGE("[WARNING] PowerControl (ARM_POWER_LOW) is not supported");
2236   }
2237
2238   // Call PowerControl(ARM_POWER_FULL) function and assert that it returned ARM_DRIVER_OK status
2239   TEST_ASSERT(drv->PowerControl (ARM_POWER_FULL) == ARM_DRIVER_OK);
2240
2241   // Driver is initialized and peripheral is powered-on:
2242   // Call Control function and assert that it returned ARM_DRIVER_OK status
2243   TEST_ASSERT(drv->Control (((USART_CFG_DEF_MODE << ARM_USART_CONTROL_Pos) & ARM_USART_CONTROL_Msk) | 
2244                             ((USART_CFG_DEF_CPOL << ARM_USART_CPOL_Pos)    & ARM_USART_CPOL_Msk)    | 
2245                             ((USART_CFG_DEF_CPHA << ARM_USART_CPHA_Pos)    & ARM_USART_CPHA_Msk)    | 
2246                               ARM_USART_DATA_BITS_8, USART_CFG_DEF_BAUDRATE) == ARM_DRIVER_OK);
2247
2248   // Call PowerControl(ARM_POWER_OFF) function and assert that it returned ARM_DRIVER_OK status
2249   // (this must unconditionally terminate active send/receive/transfer and power-off the peripheral)
2250   TEST_ASSERT(drv->PowerControl (ARM_POWER_OFF) == ARM_DRIVER_OK);
2251
2252   // Driver is initialized and peripheral is powered-off:
2253   // Call GetStatus function
2254   stat = drv->GetStatus();
2255
2256   // Assert that GetStatus function returned status structure with tx_busy flag 0
2257   TEST_ASSERT(stat.tx_busy == 0U);
2258
2259   // Assert that GetStatus function returned status structure with rx_busy flag 0
2260   TEST_ASSERT(stat.rx_busy == 0U);
2261
2262   (void)drv->Uninitialize ();
2263 }
2264
2265 /**
2266 @}
2267 */
2268 // End of usart_tests_drv_mgmt
2269
2270 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2271 /* USART Data Exchange tests                                                                                                  */
2272 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2273 /**
2274 \defgroup usart_tests_data_xchg Data Exchange
2275 \ingroup usart_tests
2276 \details
2277 These tests verify API and operation of the USART data exchange functions.
2278
2279 The data exchange tests verify the following driver functions
2280 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
2281  - \b Send
2282 \code
2283   int32_t          Send         (const void *data,                    uint32_t num);
2284 \endcode
2285  - \b Receive
2286 \code
2287   int32_t          Receive      (      void *data,                    uint32_t num);
2288 \endcode
2289  - \b Transfer
2290 \code
2291   int32_t          Transfer     (const void *data_out, void *data_in, uint32_t num);
2292 \endcode
2293  - \b GetTxCount
2294 \code
2295   uint32_t         GetTxCount   (void);
2296 \endcode
2297  - \b GetRxCount
2298 \code
2299   uint32_t         GetRxCount   (void);
2300 \endcode
2301  - \b Control
2302 \code
2303   int32_t          Control      (uint32_t control, uint32_t arg);
2304 \endcode
2305  - \b GetStatus
2306 \code
2307   ARM_USART_STATUS GetStatus    (void);
2308 \endcode
2309  - \b SignalEvent
2310 \code
2311   void (*ARM_USART_SignalEvent_t) (uint32_t event);
2312 \endcode
2313
2314 All of these tests execute a data exchange and check the result of this data exchange.
2315
2316 Data exchange test procedure when Test Mode <b>USART Server</b> is selected:
2317   - send command "SET BUF TX,.." to the USART Server: Set Tx buffer
2318   - send command "SET BUF RX,.." to the USART Server: Set Rx buffer
2319   - send command "SET COM .."    to the USART Server: Set communication settings for the next XFER command
2320   - send command "XFER .."       to the USART Server: Specify transfer
2321   - driver Control: Configure the USART interface
2322   - driver Control: Set the default Tx value (in synchronous mode only)
2323   - driver Send/Receive/Transfer: Start the requested operation
2324   - driver GetStatus/SignalEvent: Wait for the current operation to finish or time-out<br>
2325     (operation is finished when appropriate tx_busy or rx_busy flag is 0 and send/receive/transfer completed event was signaled)
2326   - assert that operation has finished in expected time
2327   - assert that appropriate ARM_USART_EVENT_SEND_COMPLETE, ARM_USART_EVENT_RECEIVE_COMPLETE
2328     or ARM_USART_EVENT_TRANSFER_COMPLETE event was signaled
2329   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2330   - driver GetTxCount: If it was a send or transfer operation assert that number of transmitted items is same as requested
2331   - driver GetRxCount: If it was a receive or transfer operation assert that number of received items is same as requested
2332   - if operation has timed out call driver Control function to Abort operation and wait timeout time<br>
2333     to make sure that the USART Server is ready for the next command
2334   - assert that received content is as expected
2335   - send command "GET BUF RX,.." to the USART Server: Get Rx buffer
2336   - assert that sent content (read from the USART Server's receive buffer) is as expected
2337
2338 Data exchange <b>Abort</b> test procedure when Test Mode <b>USART Server</b> is selected:
2339   - send command "SET BUF TX,.." to the USART Server: Set Tx buffer
2340   - send command "SET BUF RX,.." to the USART Server: Set Rx buffer
2341   - send command "SET COM .."    to the USART Server: Set communication settings for the next XFER command
2342   - send command "XFER .."       to the USART Server: Specify transfer
2343   - driver Control: Configure the USART interface
2344   - driver Control: Set the default Tx value (in synchronous mode only)
2345   - driver Send/Receive/Transfer: Start the requested operation
2346   - wait up to 1 ms
2347   - driver Control: Abort the current operation
2348   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2349   - driver GetTxCount: If it was a send or transfer operation assert that number of transmitted items is less than requested
2350   - driver GetRxCount: If it was a receive or transfer operation assert that number of received items is less than requested
2351
2352 Data exchange test procedure when Test Mode <b>Loopback</b> is selected:
2353   - driver Control: Configure the USART interface
2354   - driver Control: Set the default Tx value (in synchronous mode only)
2355   - driver Send/Receive/Transfer: Start the requested operation
2356   - driver GetStatus/SignalEvent: Wait for the current operation to finish or time-out<br>
2357     (operation is finished when appropriate tx_busy or rx_busy flag is 0 and send/receive/transfer completed event was signaled)
2358   - assert that operation has finished in expected time
2359   - assert that appropriate ARM_USART_EVENT_SEND_COMPLETE and ARM_USART_EVENT_RECEIVE_COMPLETE
2360     or ARM_USART_EVENT_TRANSFER_COMPLETE event was signaled
2361   - driver GetStatus: Assert that appropriate tx_busy or rx_busy flag is 0
2362   - driver GetTxCount: If it was a send and receive or transfer operation assert that number of transmitted items is same as requested
2363   - driver GetRxCount: If it was a send and receive or transfer operation assert that number of received items is same as requested
2364   - if operation has timed out call driver Control function to Abort operation
2365   - assert that sent and received content is same
2366
2367 \note Limitations of Data Exchange tests if Test Mode <b>Loopback</b> is selected:
2368  - in synchronous mode only Master mode transfer can be tested
2369  - only 8 data bit tests are supported
2370  - parity tests are not supported
2371  - stop bits tests are not supported
2372  - flow control tests are not supported
2373  - clock polarity and clock phase tests are not supported
2374 @{
2375 */
2376
2377 #ifndef __DOXYGEN__                     // Exclude form the documentation
2378 /*
2379   \brief         Execute USART data exchange or abort operation.
2380   \param[in]     operation      operation (OP_SEND .. OP_ABORT_TRANSFER)
2381   \param[in]     mode           mode (MODE_ASYNCHRONOUS .. MODE_SMART_CARD)
2382   \param[in]     data_bits      data bits (5 .. 9)
2383   \param[in]     parity         parity (PARITY_NONE, PARITY_EVEN or PARITY_ODD)
2384   \param[in]     stop_bits      stop bits (STOP_BITS_1 .. STOP_BITS_0_5)
2385   \param[in]     flow_control   flow control (FLOW_CONTROL_NONE .. FLOW_CONTROL_RTS_CTS)
2386   \param[in]     cpol           clock polarity (CPOL0 or CPOL1)
2387   \param[in]     cpha           clock phase (CPHA0 or CPHA1)
2388   \param[in]     baudrate       baudrate in bauds
2389   \param[in]     num            number of items to send, receive or transfer
2390   \return        none
2391 */
2392 static void USART_DataExchange_Operation (uint32_t operation, uint32_t mode, uint32_t data_bits, uint32_t parity, uint32_t stop_bits, uint32_t flow_control, uint32_t cpol, uint32_t cpha, uint32_t baudrate, uint32_t num) {
2393   // volatile specifier is used to prevent compiler from optimizing variables 
2394   // in a way that they cannot be seen with debugger
2395   volatile  int32_t         stat, def_tx_stat;
2396   volatile uint32_t         drv_mode, drv_data_bits, drv_parity, drv_stop_bits, drv_flow_control, drv_cpol, drv_cpha;
2397   volatile uint32_t         srv_mode, srv_dir, srv_flow_control;
2398   volatile ARM_USART_STATUS usart_stat;
2399   volatile uint32_t         tx_count, rx_count;
2400            uint32_t         start_cnt;
2401            uint32_t         val, i;
2402   volatile uint32_t         srv_delay;
2403   volatile uint32_t         drv_delay;
2404            uint8_t          chk_tx_data, chk_rx_data;
2405            uint32_t         timeout, start_tick, curr_tick;
2406
2407   // Prepare parameters for USART Server and Driver configuration
2408   switch (operation & 0x0FU) {
2409     case OP_SEND:
2410     case OP_ABORT_SEND:
2411       srv_dir   = 1U;
2412       drv_delay = 10U;
2413       srv_delay = 0U;
2414       if (mode == MODE_SYNCHRONOUS_MASTER) {
2415         // In Synchronous Master test wait for USART Server to start the trasnsfer
2416         drv_delay = 10U;
2417         srv_delay = 0U;
2418       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2419         // In Synchronous Slave test make USART Server wait for driver to start the send operation
2420         drv_delay = 0U;
2421         srv_delay = 10U;
2422       }
2423       break;
2424     case OP_RECEIVE:
2425     case OP_ABORT_RECEIVE:
2426       srv_dir   = 0U;
2427       drv_delay = 0U;
2428       srv_delay = 10U;
2429       if (mode == MODE_SYNCHRONOUS_MASTER) {
2430         // In Synchronous Master test wait for USART Server to start the trasnsfer
2431         drv_delay = 10U;
2432         srv_delay = 0U;
2433       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2434         // In Synchronous Slave test make USART Server wait for driver to start the receive operation
2435         drv_delay = 0U;
2436         srv_delay = 10U;
2437       }
2438       break;
2439     case OP_TRANSFER:
2440     case OP_ABORT_TRANSFER:
2441       srv_dir   = 2U;
2442       if (mode == MODE_SYNCHRONOUS_MASTER) {
2443         // In Synchronous Master test wait for USART Server to start the trasnsfer
2444         drv_delay = 10U;
2445         srv_delay = 0U;
2446       } else if (mode == MODE_SYNCHRONOUS_SLAVE) {
2447         // In Synchronous Slave test mode make USART Server wait for driver to start the transfer
2448         drv_delay = 0U;
2449         srv_delay = 10U;
2450       } else {
2451         TEST_FAIL_MESSAGE("[FAILED] Synchronous mode unknown! Data exchange operation aborted!");
2452         return;
2453       }
2454     case OP_RECEIVE_SEND_LB:
2455       drv_delay = 10U;
2456       break;
2457   }
2458
2459   switch (mode) {
2460     case MODE_ASYNCHRONOUS:
2461       drv_mode = ARM_USART_MODE_ASYNCHRONOUS;
2462       srv_mode = MODE_ASYNCHRONOUS;
2463       break;
2464     case MODE_SYNCHRONOUS_MASTER:
2465       drv_mode = ARM_USART_MODE_SYNCHRONOUS_MASTER;
2466       srv_mode = MODE_SYNCHRONOUS_SLAVE;
2467       break;
2468     case MODE_SYNCHRONOUS_SLAVE:
2469       drv_mode = ARM_USART_MODE_SYNCHRONOUS_SLAVE;
2470       srv_mode = MODE_SYNCHRONOUS_MASTER;
2471       break;
2472     case MODE_SINGLE_WIRE:
2473       drv_mode = ARM_USART_MODE_SINGLE_WIRE;
2474       srv_mode = MODE_SINGLE_WIRE;
2475       break;
2476     case MODE_IRDA:
2477       drv_mode = ARM_USART_MODE_IRDA;
2478       srv_mode = MODE_IRDA;
2479       break;
2480     case MODE_SMART_CARD:
2481       TEST_FAIL_MESSAGE("[FAILED] Smart Card mode testing not supported! Data exchange operation aborted!");
2482       return;
2483     default:
2484       TEST_FAIL_MESSAGE("[FAILED] Unknown mode! Data exchange operation aborted!");
2485       return;
2486   }
2487
2488   switch (data_bits) {
2489     case 5U:
2490       drv_data_bits = ARM_USART_DATA_BITS_5;
2491       break;
2492     case 6U:
2493       drv_data_bits = ARM_USART_DATA_BITS_6;
2494       break;
2495     case 7U:
2496       drv_data_bits = ARM_USART_DATA_BITS_7;
2497       break;
2498     case 8U:
2499       drv_data_bits = ARM_USART_DATA_BITS_8;
2500       break;
2501     case 9U:
2502       drv_data_bits = ARM_USART_DATA_BITS_9;
2503       break;
2504     default:
2505       TEST_FAIL_MESSAGE("[FAILED] Data bits not in range 5 to 9! Data exchange operation aborted!");
2506       return;
2507   }
2508
2509   switch (parity) {
2510     case PARITY_NONE:
2511       drv_parity = ARM_USART_PARITY_NONE;
2512       break;
2513     case PARITY_EVEN:
2514       drv_parity = ARM_USART_PARITY_EVEN;
2515       break;
2516     case PARITY_ODD:
2517       drv_parity = ARM_USART_PARITY_ODD;
2518       break;
2519     default:
2520       TEST_FAIL_MESSAGE("[FAILED] Unknown parity! Data exchange operation aborted!");
2521       return;
2522   }
2523
2524   switch (stop_bits) {
2525     case STOP_BITS_1:
2526       drv_stop_bits = ARM_USART_STOP_BITS_1;
2527       break;
2528     case STOP_BITS_2:
2529       drv_stop_bits = ARM_USART_STOP_BITS_2;
2530       break;
2531     case STOP_BITS_1_5:
2532       drv_stop_bits = ARM_USART_STOP_BITS_1_5;
2533       break;
2534     case STOP_BITS_0_5:
2535       drv_stop_bits = ARM_USART_STOP_BITS_0_5;
2536       break;
2537     default:
2538       TEST_FAIL_MESSAGE("[FAILED] Unknown stop bits! Data exchange operation aborted!");
2539       return;
2540   }
2541
2542   switch (flow_control) {
2543     case FLOW_CONTROL_NONE:
2544       drv_flow_control = ARM_USART_FLOW_CONTROL_NONE;
2545       srv_flow_control = FLOW_CONTROL_NONE;
2546       break;
2547     case FLOW_CONTROL_CTS:
2548       drv_flow_control = ARM_USART_FLOW_CONTROL_CTS;
2549       srv_flow_control = FLOW_CONTROL_RTS;
2550       break;
2551     case FLOW_CONTROL_RTS:
2552       drv_flow_control = ARM_USART_FLOW_CONTROL_RTS;
2553       srv_flow_control = FLOW_CONTROL_CTS;
2554       break;
2555     case FLOW_CONTROL_RTS_CTS:
2556       drv_flow_control = ARM_USART_FLOW_CONTROL_RTS_CTS;
2557       srv_flow_control = FLOW_CONTROL_RTS_CTS;
2558       break;
2559     default:
2560       TEST_FAIL_MESSAGE("[FAILED] Unknown flow control! Data exchange operation aborted!");
2561       return;
2562   }
2563
2564   switch (cpol) {
2565     case CPOL0:
2566       drv_cpol = ARM_USART_CPOL0;
2567       break;
2568     case CPOL1:
2569       drv_cpol = ARM_USART_CPOL1;
2570       break;
2571     default:
2572       TEST_FAIL_MESSAGE("[FAILED] Unknown clock polarity! Data exchange operation aborted!");
2573       return;
2574   }
2575
2576   switch (cpha) {
2577     case CPHA0:
2578       drv_cpha = ARM_USART_CPHA0;
2579       break;
2580     case CPHA1:
2581       drv_cpha = ARM_USART_CPHA1;
2582       break;
2583     default:
2584       TEST_FAIL_MESSAGE("[FAILED] Unknown clock phase! Data exchange operation aborted!");
2585       return;
2586   }
2587
2588   // Total transfer timeout (10 ms is overhead before transfer starts)
2589   timeout = USART_CFG_XFER_TIMEOUT + 10U;
2590
2591   // Check that USART status is not busy before starting data exchange test
2592   usart_stat = drv->GetStatus();        // Get USART status
2593   if (usart_stat.tx_busy != 0U) {
2594     // If tx_busy flag is active
2595     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Tx busy active before operation! Data exchange operation aborted!");
2596   }
2597   TEST_ASSERT_MESSAGE(usart_stat.tx_busy == 0U, msg_buf);
2598   if (usart_stat.rx_busy != 0U) {
2599     // If rx_busy flag is active
2600     (void)snprintf(msg_buf, sizeof(msg_buf), "[FAILED] %s: %s", str_oper[operation], "Rx busy active before operation! Data exchange operation aborted!");
2601   }
2602   TEST_ASSERT_MESSAGE(usart_stat.rx_busy == 0U, msg_buf);
2603   if (usart_stat.tx_busy != 0U) {
2604     return;                             // If tx busy is active abort data exchange operation
2605   }
2606   if (usart_stat.rx_busy != 0U) {
2607     return;                             // If rx busy is active abort data exchange operation
2608   }
2609
2610   do {
2611 #if (USART_SERVER_USED == 1)            // If Test Mode USART Server is selected
2612     if (CmdSetBufTx('S')   != EXIT_SUCCESS) { break; }
2613     if (CmdSetBufRx('?')   != EXIT_SUCCESS) { break; }
2614     if (CmdSetCom  (srv_mode, data_bits, parity, stop_bits, srv_flow_control, cpol, cpha, baudrate) != EXIT_SUCCESS) { break; }
2615     if (CmdXfer    (srv_dir, num, srv_delay, USART_CFG_XFER_TIMEOUT, 0U) != EXIT_SUCCESS) { break; }
2616 #else                                   // If Test Mode Loopback is selected
2617     // Remove warnings for unused variables
2618     (void)srv_mode;
2619     (void)srv_dir;
2620     (void)srv_flow_control;
2621     (void)srv_delay;
2622     (void)def_tx_stat;
2623     (void)curr_tick;
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
4142   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4143   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; }
4144
4145 #if  (USART_SERVER_USED == 1)
4146   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);
4147   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);
4148 #else
4149   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);
4150 #endif
4151
4152   if (duration != 0xFFFFFFFFU) {        // If Transfer finished before timeout
4153     if (duration != 0U) {               // If duration of transfer was more than 0 SysTick counts
4154       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;
4155       if ((br < ((USART_CFG_MIN_BAUDRATE * 3) / 4)) ||
4156           (br >   USART_CFG_MIN_BAUDRATE)) {
4157         // If measured baudrate is 25% lower, or higher than requested
4158         (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);
4159         TEST_MESSAGE(msg_buf);
4160       }
4161     }
4162   }
4163 }
4164
4165 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4166 /**
4167 \brief Function: Function USART_Baudrate_Max
4168 \details
4169 The function \b USART_Baudrate_Max verifies data exchange:
4170  - in default mode
4171  - with default data bits
4172  - with default parity
4173  - with default stop bits
4174  - with default flow control
4175  - with default clock polarity
4176  - with default clock phase
4177  - at <b>maximum baudrate</b> (define <c>USART_CFG_MAX_BAUDRATE</c> in DV_USART_Config.h)
4178  - for default number of data items
4179
4180 This test function checks the following requirement:
4181  - measured bus speed for Send operation in Test Mode <b>USART Server</b> or Send/Receive operation  in Test Mode <b>Loopback</b> 
4182    is not 25% lower, or higher than requested
4183 */
4184 void USART_Baudrate_Max (void) {
4185   volatile uint64_t br;
4186
4187   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4188   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4189
4190 #if  (USART_SERVER_USED == 1)
4191   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4192   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4193 #else
4194   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_MAX_BAUDRATE, USART_CFG_DEF_NUM);
4195 #endif
4196
4197   if (duration != 0xFFFFFFFFU) {        // If Transfer finished before timeout
4198     if (duration != 0U) {               // If duration of transfer was more than 0 SysTick counts
4199       br = ((uint64_t)systick_freq * (1U + USART_CFG_DEF_DATA_BITS + USART_CFG_DEF_STOP_BITS + (uint32_t)(USART_CFG_DEF_PARITY != PARITY_NONE)) * USART_CFG_DEF_NUM) / duration;
4200       if ((br < ((USART_CFG_MAX_BAUDRATE * 3) / 4)) ||
4201           (br >   USART_CFG_MAX_BAUDRATE)) {
4202         // If measured baudrate is 25% lower, or higher than requested
4203         (void)snprintf(msg_buf, sizeof(msg_buf), "[WARNING] At requested baudrate of %i bauds, effective transfer speed is %i bauds", USART_CFG_MAX_BAUDRATE, (uint32_t)br);
4204         TEST_MESSAGE(msg_buf);
4205       }
4206     }
4207   }
4208 }
4209
4210 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4211 /**
4212 \brief Function: Function USART_Number_Of_Items
4213 \details
4214 The function \b USART_Number_Of_Items verifies data exchange:
4215  - in default mode
4216  - with default data bits
4217  - with default parity
4218  - with default stop bits
4219  - with default flow control
4220  - with default clock polarity
4221  - with default clock phase
4222  - at default baudrate
4223  - for <b>different number of items</b> (defines <c>USART_CFG_NUM1 .. USART_CFG_NUM5</c> in DV_USART_Config.h)
4224 */
4225 void USART_Number_Of_Items (void) {
4226
4227   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4228   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4229
4230 #if (USART_CFG_NUM1 != 0U)
4231 #if (USART_SERVER_USED == 1)
4232   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4233   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4234 #else
4235   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM1);
4236 #endif
4237 #endif
4238
4239 #if (USART_CFG_NUM2 != 0U)
4240 #if (USART_SERVER_USED == 1)
4241   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4242   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4243 #else
4244   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM2);
4245 #endif
4246 #endif
4247
4248 #if (USART_CFG_NUM3 != 0U)
4249 #if (USART_SERVER_USED == 1)
4250   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4251   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4252 #else
4253   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM3);
4254 #endif
4255 #endif
4256
4257 #if (USART_CFG_NUM4 != 0U)
4258 #if (USART_SERVER_USED == 1)
4259   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4260   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4261 #else
4262   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM4);
4263 #endif
4264 #endif
4265
4266 #if (USART_CFG_NUM5 != 0U)
4267 #if (USART_SERVER_USED == 1)
4268   USART_DataExchange_Operation(OP_SEND,            USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4269   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4270 #else
4271   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_NUM5);
4272 #endif
4273 #endif
4274 }
4275
4276 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4277 /**
4278 \brief Function: Function USART_GetTxCount
4279 \details
4280 The function \b USART_GetTxCount verifies \b GetTxCount function (count changing) during data exchange (Send):
4281  - in default mode
4282  - with default data bits
4283  - with default parity
4284  - with default stop bits
4285  - with default flow control
4286  - with default clock polarity
4287  - with default clock phase
4288  - at default baudrate
4289 */
4290 void USART_GetTxCount (void) {
4291
4292   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4293   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4294
4295   USART_DataExchange_Operation(OP_SEND, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4296   TEST_ASSERT_MESSAGE((tx_count_sample != 0U) && (tx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetTxCount was not changing during the Send!");
4297 }
4298
4299 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4300 /**
4301 \brief Function: Function USART_GetRxCount
4302 \details
4303 The function \b USART_GetRxCount verifies \b GetRxCount function (count changing) during data exchange (Receive):
4304  - in default mode
4305  - with default data bits
4306  - with default parity
4307  - with default stop bits
4308  - with default flow control
4309  - with default clock polarity
4310  - with default clock phase
4311  - at default baudrate
4312 */
4313 void USART_GetRxCount (void) {
4314
4315   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4316   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4317
4318 #if  (USART_SERVER_USED == 1)
4319   USART_DataExchange_Operation(OP_RECEIVE,         USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4320 #else
4321   USART_DataExchange_Operation(OP_RECEIVE_SEND_LB, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4322 #endif
4323 }
4324
4325 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4326 /**
4327 \brief Function: Function USART_GetTxRxCount
4328 \details
4329 The function \b USART_GetTxRxCount verifies \b GetTxCount and \b GetRxCount functions (count changing) during data exchange (Transfer):
4330  - in default mode
4331  - with default data bits
4332  - with no parity
4333  - with 1 stop bits
4334  - with no flow control
4335  - with default clock polarity
4336  - with default clock phase
4337  - at default baudrate
4338
4339 \note If Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b> is selected this test is not executed
4340 */
4341 void USART_GetTxRxCount (void) {
4342
4343   if (IsNotAsync()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4344   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4345   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4346
4347   USART_DataExchange_Operation(OP_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4348   TEST_ASSERT_MESSAGE((tx_count_sample != 0U) && (tx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetTxCount was not changing during the Transfer!");
4349   TEST_ASSERT_MESSAGE((rx_count_sample != 0U) && (rx_count_sample != USART_CFG_DEF_NUM), "[FAILED] GetRxCount was not changing during the Transfer!");
4350 }
4351
4352 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4353 /**
4354 \brief Function: Function USART_AbortSend
4355 \details
4356 The function \b USART_AbortSend verifies \b Abort function abort of data exchange (Send):
4357  - in default mode
4358  - with default data bits
4359  - with default parity
4360  - with default stop bits
4361  - with default flow control
4362  - at default baudrate
4363 */
4364 void USART_AbortSend (void) {
4365
4366   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4367   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4368
4369   USART_DataExchange_Operation(OP_ABORT_SEND, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4370 }
4371
4372 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4373 /**
4374 \brief Function: Function USART_AbortReceive
4375 \details
4376 The function \b USART_AbortReceive verifies \b Abort function abort of data exchange (Receive):
4377  - in default mode
4378  - with default data bits
4379  - with default parity
4380  - with default stop bits
4381  - with default flow control
4382  - with default clock polarity
4383  - with default clock phase
4384  - at default baudrate
4385 */
4386 void USART_AbortReceive (void) {
4387
4388   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4389   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4390
4391   USART_DataExchange_Operation(OP_ABORT_RECEIVE, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, USART_CFG_DEF_FLOW_CONTROL, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4392 }
4393
4394 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4395 /**
4396 \brief Function: Function USART_AbortTransfer
4397 \details
4398 The function \b USART_AbortTransfer verifies \b Abort function abort of data exchange (Transfer):
4399  - in default mode
4400  - with default data bits
4401  - with no parity
4402  - with 1 stop bit
4403  - with no flow control
4404  - with default clock polarity
4405  - with default clock phase
4406  - at default baudrate
4407
4408 \note If Tests Default Mode <b>Asynchronous/Single-wire/IrDA</b> is selected this test is not executed
4409 */
4410 void USART_AbortTransfer (void) {
4411
4412   if (IsNotAsync()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4413   if (DriverInit()  != EXIT_SUCCESS) { TEST_FAIL(); return; }
4414   if (SettingsCheck (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4415
4416   USART_DataExchange_Operation(OP_ABORT_TRANSFER, USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, PARITY_NONE, STOP_BITS_1, FLOW_CONTROL_NONE, USART_CFG_DEF_CPOL, USART_CFG_DEF_CPHA, USART_CFG_DEF_BAUDRATE, USART_CFG_DEF_NUM);
4417 }
4418
4419 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4420 /**
4421 \brief Function: Function USART_TxBreak
4422 \details
4423 The function \b USART_TxBreak verifies Break signaling:
4424  - in default mode
4425  - with default data bits
4426  - with default parity
4427  - with default stop bits
4428  - with no flow control
4429  - at default baudrate
4430
4431 \note This test is not executed if any of the following settings are selected:
4432  - Test Mode <b>Loopback</b>
4433  - Tests Default Mode <b>Synchronous Master/Slave</b>
4434 */
4435 void USART_TxBreak (void) {
4436
4437   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4438 #if  (USART_SERVER_USED == 1)
4439   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
4440   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4441   if (SettingsCheck   (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4442
4443   do {
4444     // Dummy read break status to clear it
4445     if (CmdGetBrk()        != EXIT_SUCCESS) { break; }
4446
4447     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4448     if (CmdSetCom  (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, 0U, 0U, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { break; }
4449
4450     // Instruct USART Server to receive data so it can detect Break
4451     if (CmdXfer    (1U, USART_CFG_DEF_NUM, 0U, USART_CFG_XFER_TIMEOUT, 0U) != EXIT_SUCCESS) { break; }
4452
4453     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4454                        USART_CFG_DEF_DATA_BITS_VAL | 
4455                        USART_CFG_DEF_PARITY_VAL    | 
4456                        USART_CFG_DEF_STOP_BITS_VAL | 
4457                        ARM_USART_FLOW_CONTROL_NONE , 
4458                        USART_CFG_DEF_BAUDRATE);
4459
4460     event = 0U;
4461
4462     (void)osDelay(10U);                 // Wait for USART Server to start reception
4463
4464     (void)drv->Control(ARM_USART_CONTROL_TX, 1U);
4465
4466     (void)osDelay(10U);
4467     TEST_ASSERT(drv->Control(ARM_USART_CONTROL_BREAK, 1U) == ARM_DRIVER_OK);
4468     (void)osDelay(10U);
4469     TEST_ASSERT(drv->Control(ARM_USART_CONTROL_BREAK, 0U) == ARM_DRIVER_OK);
4470     (void)osDelay(10U);
4471
4472     (void)drv->Control(ARM_USART_CONTROL_TX, 0U);
4473
4474     (void)osDelay(USART_CFG_XFER_TIMEOUT + 10U);        // Wait for USART Server to timeout the XFER command
4475
4476     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4477     if (CmdGetBrk()        != EXIT_SUCCESS) { break; }
4478     TEST_ASSERT_MESSAGE(break_status == 1U, "[FAILED] Break was not detected on USART Server!");
4479
4480     (void)osDelay(10U);                 // Wait for USART Server to prepare for reception of new command
4481
4482     return;
4483   } while (false);
4484 #endif
4485 }
4486
4487 /**
4488 @}
4489 */
4490 // End of usart_tests_data_xchg
4491
4492 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4493 /* USART Modem Lines tests                                                                                                  */
4494 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4495 /**
4496 \defgroup usart_tests_modem Modem Lines
4497 \ingroup usart_tests
4498 \details
4499 These tests verify API and operation of the USART modem lines handling functions.
4500
4501 The data exchange tests verify the following driver functions
4502 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
4503  - \b SetModemControl
4504 \code
4505   int32_t                SetModemControl (ARM_USART_MODEM_CONTROL control);
4506 \endcode
4507  - \b GetModemStatus
4508 \code
4509   ARM_USART_MODEM_STATUS GetModemStatus  (void);
4510 \endcode
4511
4512 \note These tests are not executed if any of the following settings are selected:
4513  - Test Mode <b>Loopback</b>
4514  - Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b>
4515 @{
4516 */
4517
4518 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4519 /**
4520 \brief Function: Function USART_Modem_RTS
4521 \details
4522 The function \b USART_Modem_RTS verifies driving of modem line Request To Send (RTS):
4523  - in default mode
4524  - with default data bits
4525  - with default parity
4526  - with default stop bits
4527  - with no flow control
4528  - at default baudrate
4529 */
4530 void USART_Modem_RTS (void) {
4531
4532   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4533 #if  (USART_SERVER_USED == 1)
4534   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4535   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4536   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4537   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, RTS_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4538
4539   do {
4540     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4541
4542     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4543                        USART_CFG_DEF_DATA_BITS_VAL | 
4544                        USART_CFG_DEF_PARITY_VAL    | 
4545                        USART_CFG_DEF_STOP_BITS_VAL | 
4546                        ARM_USART_FLOW_CONTROL_NONE , 
4547                        USART_CFG_DEF_BAUDRATE);
4548
4549     TEST_ASSERT(drv->SetModemControl(ARM_USART_RTS_CLEAR) == ARM_DRIVER_OK);
4550     (void)osDelay(10U);
4551
4552     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4553
4554     TEST_ASSERT_MESSAGE((modem_status & 0x1U) == 0x0U, "[FAILED] CTS line on USART Server is not in inactive state!");
4555
4556     TEST_ASSERT(drv->SetModemControl(ARM_USART_RTS_SET) == ARM_DRIVER_OK);
4557     (void)osDelay(10U);
4558
4559     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4560
4561     TEST_ASSERT_MESSAGE((modem_status & 0x1U) == 0x1U, "[FAILED] CTS line on USART Server is not in active state!");
4562
4563     (void)drv->SetModemControl(ARM_USART_RTS_CLEAR);
4564
4565     // Give USART Server 10 ms to prepare for reception of the next command
4566     (void)osDelay(10U);
4567
4568     return;
4569   } while (false);
4570 #endif
4571 }
4572
4573 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4574 /**
4575 \brief Function: Function USART_Modem_DTR
4576 \details
4577 The function \b USART_Modem_DTR verifies driving of modem line Data Terminal Ready (DTR):
4578  - in default mode
4579  - with default data bits
4580  - with default parity
4581  - with default stop bits
4582  - with no flow control
4583  - at default baudrate
4584 */
4585 void USART_Modem_DTR (void) {
4586
4587   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4588 #if  (USART_SERVER_USED == 1)
4589   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4590   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4591   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4592   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DTR_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4593
4594   do {
4595     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4596
4597     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4598                        USART_CFG_DEF_DATA_BITS_VAL | 
4599                        USART_CFG_DEF_PARITY_VAL    | 
4600                        USART_CFG_DEF_STOP_BITS_VAL | 
4601                        ARM_USART_FLOW_CONTROL_NONE , 
4602                        USART_CFG_DEF_BAUDRATE);
4603
4604     TEST_ASSERT(drv->SetModemControl(ARM_USART_DTR_CLEAR) == ARM_DRIVER_OK);
4605     (void)osDelay(10U);
4606
4607     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4608
4609     TEST_ASSERT_MESSAGE((modem_status & 0x2U) == 0x0U, "[FAILED] DSR line on USART Server is not in inactive state!");
4610
4611     TEST_ASSERT(drv->SetModemControl(ARM_USART_DTR_SET) == ARM_DRIVER_OK);
4612     (void)osDelay(10U);
4613
4614     if (CmdGetMdm() != EXIT_SUCCESS) { break; }
4615
4616     TEST_ASSERT_MESSAGE((modem_status & 0x2U) == 0x2U, "[FAILED] DSR line on USART Server is not in active state!");
4617
4618     (void)drv->SetModemControl(ARM_USART_DTR_CLEAR);
4619
4620     // Give USART Server 10 ms to prepare for reception of the next command
4621     (void)osDelay(10U);
4622
4623     return;
4624   } while (false);
4625 #endif
4626 }
4627
4628 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4629 /**
4630 \brief Function: Function USART_Modem_CTS
4631 \details
4632 The function \b USART_Modem_CTS verifies read of modem line Clear To Send (CTS):
4633  - in default mode
4634  - with default data bits
4635  - with default parity
4636  - with default stop bits
4637  - with no flow control
4638  - at default baudrate
4639 */
4640 void USART_Modem_CTS (void) {
4641
4642   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4643 #if  (USART_SERVER_USED == 1)
4644   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4645   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4646   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4647   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, CTS_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4648
4649   do {
4650     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4651
4652     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4653                        USART_CFG_DEF_DATA_BITS_VAL | 
4654                        USART_CFG_DEF_PARITY_VAL    | 
4655                        USART_CFG_DEF_STOP_BITS_VAL | 
4656                        ARM_USART_FLOW_CONTROL_NONE , 
4657                        USART_CFG_DEF_BAUDRATE);
4658
4659     // Instruct USART Server to drive RTS to active state for 20 ms
4660     // RTS line from USART Server should be connected to CTS line on the USART Client (DUT)
4661     if (CmdSetMdm(RTS_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4662
4663     (void)osDelay(20U);
4664
4665     TEST_ASSERT_MESSAGE(drv->GetModemStatus().cts == 1U, "[FAILED] CTS line not active!");
4666
4667     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4668     (void)osDelay(20U);
4669
4670     return;
4671   } while (false);
4672 #endif
4673 }
4674
4675 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4676 /**
4677 \brief Function: Function USART_Modem_DSR
4678 \details
4679 The function \b USART_Modem_DSR verifies read of modem line Data Set Ready (DSR):
4680  - in default mode
4681  - with default data bits
4682  - with default parity
4683  - with default stop bits
4684  - with no flow control
4685  - at default baudrate
4686 */
4687 void USART_Modem_DSR (void) {
4688
4689   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4690 #if  (USART_SERVER_USED == 1)
4691   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4692   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4693   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4694   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DSR_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4695
4696   do {
4697     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4698
4699     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4700                        USART_CFG_DEF_DATA_BITS_VAL | 
4701                        USART_CFG_DEF_PARITY_VAL    | 
4702                        USART_CFG_DEF_STOP_BITS_VAL | 
4703                        ARM_USART_FLOW_CONTROL_NONE , 
4704                        USART_CFG_DEF_BAUDRATE);
4705
4706     // Instruct USART Server to drive DTR to active state for 20 ms
4707     // DTR line from USART Server should be connected to DSR line on the USART Client (DUT)
4708     if (CmdSetMdm(DTR_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4709
4710     (void)osDelay(20U);
4711
4712     TEST_ASSERT_MESSAGE(drv->GetModemStatus().dsr == 1U, "[FAILED] DSR line not active!");
4713
4714     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4715     (void)osDelay(20U);
4716
4717     return;
4718   } while (false);
4719 #endif
4720 }
4721
4722 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4723 /**
4724 \brief Function: Function USART_Modem_DCD
4725 \details
4726 The function \b USART_Modem_DCD verifies read of modem line Data Carrier Detect (DCD):
4727  - in default mode
4728  - with default data bits
4729  - with default parity
4730  - with default stop bits
4731  - with no flow control
4732  - at default baudrate
4733 */
4734 void USART_Modem_DCD (void) {
4735
4736   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4737 #if  (USART_SERVER_USED == 1)
4738   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4739   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4740   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4741   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, DCD_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4742
4743   do {
4744     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4745
4746     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4747                        USART_CFG_DEF_DATA_BITS_VAL | 
4748                        USART_CFG_DEF_PARITY_VAL    | 
4749                        USART_CFG_DEF_STOP_BITS_VAL | 
4750                        ARM_USART_FLOW_CONTROL_NONE , 
4751                        USART_CFG_DEF_BAUDRATE);
4752
4753     // Instruct USART Server to drive DTR to active state for 20 ms
4754     if (CmdSetMdm(TO_DCD_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4755     
4756     (void)osDelay(20U);
4757
4758     TEST_ASSERT_MESSAGE(drv->GetModemStatus().dcd == 1U, "[FAILED] DCD line not active!");
4759
4760     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4761     (void)osDelay(20U);
4762
4763     return;
4764   } while (false);
4765 #endif
4766 }
4767
4768 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4769 /**
4770 \brief Function: Function USART_Modem_RI
4771 \details
4772 The function \b USART_Modem_RI verifies read of modem line Ring Indicator (RI):
4773  - in default mode
4774  - with default data bits
4775  - with default parity
4776  - with default stop bits
4777  - with no flow control
4778  - at default baudrate
4779 */
4780 void USART_Modem_RI (void) {
4781
4782   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4783 #if  (USART_SERVER_USED == 1)
4784   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
4785   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4786   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4787   if (SettingsCheck     (USART_CFG_DEF_MODE, USART_CFG_DEF_DATA_BITS, USART_CFG_DEF_PARITY, USART_CFG_DEF_STOP_BITS, FLOW_CONTROL_NONE, RI_AVAILABLE, USART_CFG_DEF_BAUDRATE) != EXIT_SUCCESS) { TEST_FAIL(); return; }
4788
4789   do {
4790     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4791
4792     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
4793                        USART_CFG_DEF_DATA_BITS_VAL | 
4794                        USART_CFG_DEF_PARITY_VAL    | 
4795                        USART_CFG_DEF_STOP_BITS_VAL | 
4796                        ARM_USART_FLOW_CONTROL_NONE , 
4797                        USART_CFG_DEF_BAUDRATE);
4798
4799     // Instruct USART Server to drive RI to active state for 20 ms
4800     if (CmdSetMdm(TO_RI_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
4801
4802     (void)osDelay(20U);
4803
4804     TEST_ASSERT_MESSAGE(drv->GetModemStatus().ri == 1U, "[FAILED] RI line not active!");
4805
4806     // Give USART Server 20 ms to finish SET MDM command and prepare for reception of the next command
4807     (void)osDelay(20U);
4808
4809     return;
4810   } while (false);
4811 #endif
4812 }
4813
4814 /**
4815 @}
4816 */
4817 // End of usart_tests_modem
4818
4819 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4820 /* USART Event tests                                                                                                        */
4821 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4822 /**
4823 \defgroup usart_tests_evt Event
4824 \ingroup usart_tests
4825 \details
4826 These tests verify API and operation of the USART event signaling, except ARM_USART_EVENT_SEND_COMPLETE, 
4827 ARM_USART_EVENT_RECEIVE_COMPLETE, ARM_USART_EVENT_TRANSFER_COMPLETE and ARM_USART_EVENT_TX_COMPLETE signals 
4828 which is tested in the Data Exchange tests.
4829
4830 The event tests verify the following driver function
4831 (<a href="http://www.keil.com/pack/doc/CMSIS/Driver/html/group__usart__interface__gr.html" target="_blank">USART Driver function documentation</a>):
4832  - \b SignalEvent
4833 \code
4834   void (*ARM_USART_SignalEvent_t) (uint32_t event);
4835 \endcode
4836
4837 \note In Test Mode <b>Loopback</b> these tests are skipped
4838 @{
4839 */
4840
4841 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4842 /**
4843 \brief Function: Function USART_Tx_Underflow
4844 \details
4845 The function \b USART_Tx_Underflow verifies signaling of the <b>ARM_USART_EVENT_TX_UNDERFLOW</b> event:
4846  - in default mode
4847  - with default data bits
4848  - with default parity
4849  - with default stop bits
4850  - with default flow control
4851  - at default baudrate
4852
4853 it also checks that status tx_underflow flag was activated.
4854
4855 \note If Tests Default Mode <b>Asynchronous/Synchronous Master/Single-wire/IrDA</b> is selected this test is not executed
4856 */
4857 void USART_Tx_Underflow (void) {
4858
4859   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4860 #if  (USART_SERVER_USED == 1)
4861   if (IsNotAsync()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4862   if (IsNotSyncMaster() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4863   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4864   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; }
4865
4866   do {
4867     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4868     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; }
4869     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
4870
4871     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4872                        USART_CFG_DEF_DATA_BITS_VAL    | 
4873                        USART_CFG_DEF_PARITY_VAL       | 
4874                        USART_CFG_DEF_STOP_BITS_VAL    | 
4875                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4876                        USART_CFG_DEF_CPOL_VAL         | 
4877                        USART_CFG_DEF_CPHA_VAL         , 
4878                        USART_CFG_DEF_BAUDRATE);
4879
4880     event = 0U;
4881
4882     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
4883
4884     (void)osDelay(30U);                 // Wait for USART Server to timeout
4885
4886     // Assert that event ARM_USART_EVENT_TX_UNDERFLOW was signaled
4887     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_TX_UNDERFLOW) != 0U, "[FAILED] Event ARM_USART_EVENT_TX_UNDERFLOW was not signaled!");
4888
4889     // Assert that status rx_overflow flag is active
4890     TEST_ASSERT_MESSAGE(drv->GetStatus().tx_underflow != 0U, "[FAILED] Status tx_underflow flag was not activated!");
4891
4892     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
4893
4894     // Give USART Server 10 ms to prepare for reception of the next command
4895     (void)osDelay(10U);
4896
4897     return;
4898   } while (false);
4899 #endif
4900 }
4901
4902 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4903 /**
4904 \brief Function: Function USART_Rx_Overflow
4905 \details
4906 The function \b USART_Rx_Overflow verifies signaling of the <b>ARM_USART_EVENT_RX_OVERFLOW</b> event:
4907  - in default mode
4908  - with default data bits
4909  - with default parity
4910  - with default stop bits
4911  - with default flow control
4912  - at default baudrate
4913
4914 it also checks that status rx_overflow flag was activated.
4915
4916 \note If Tests Default Mode <b>Synchronous Master</b> is selected this test is not executed
4917 */
4918 void USART_Rx_Overflow (void) {
4919
4920   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
4921 #if  (USART_SERVER_USED == 1)
4922   if (IsNotSyncMaster() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4923   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
4924   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; }
4925
4926   do {
4927     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4928     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; }
4929     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
4930
4931     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4932                        USART_CFG_DEF_DATA_BITS_VAL    | 
4933                        USART_CFG_DEF_PARITY_VAL       | 
4934                        USART_CFG_DEF_STOP_BITS_VAL    | 
4935                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4936                        USART_CFG_DEF_CPOL_VAL         | 
4937                        USART_CFG_DEF_CPHA_VAL         , 
4938                        USART_CFG_DEF_BAUDRATE);
4939
4940     event = 0U;
4941
4942     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
4943
4944     (void)osDelay(30U);                 // Wait for USART Server to timeout
4945
4946     // Assert that event ARM_USART_EVENT_RX_OVERFLOW was signaled
4947     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_OVERFLOW) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_OVERFLOW was not signaled!");
4948
4949     // Assert that status rx_overflow flag is active
4950     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_overflow != 0U, "[FAILED] Status rx_overflow flag was not activated!");
4951
4952     (void)drv->Control(ARM_USART_CONTROL_RX, 0U);
4953
4954     // Give USART Server 10 ms to prepare for reception of the next command
4955     (void)osDelay(10U);
4956
4957     return;
4958   } while (false);
4959 #endif
4960 }
4961
4962 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4963 /**
4964 \brief Function: Function USART_Rx_Timeout
4965 \details
4966 The function \b USART_Rx_Timeout verifies signaling of the <b>ARM_USART_EVENT_RX_TIMEOUT</b> event:
4967  - in default mode
4968  - with default data bits
4969  - with default parity
4970  - with default stop bits
4971  - with default flow control
4972  - at default baudrate
4973
4974 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
4975 */
4976 void USART_Rx_Timeout (void) {
4977
4978   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
4979 #if  (USART_SERVER_USED == 1)
4980   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
4981   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
4982   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; }
4983
4984   do {
4985     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
4986     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; }
4987     if (CmdXfer  (0U, 1U, 10U, 10U, 0U) != EXIT_SUCCESS) { break; }
4988
4989     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
4990                        USART_CFG_DEF_DATA_BITS_VAL    | 
4991                        USART_CFG_DEF_PARITY_VAL       | 
4992                        USART_CFG_DEF_STOP_BITS_VAL    | 
4993                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
4994                        USART_CFG_DEF_CPOL_VAL         | 
4995                        USART_CFG_DEF_CPHA_VAL         , 
4996                        USART_CFG_DEF_BAUDRATE);
4997
4998     event = 0U;
4999
5000     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5001     (void)drv->Receive(ptr_rx_buf, 2U);
5002
5003     (void)osDelay(30U);                 // Wait for USART Server to timeout
5004
5005     // Assert that event ARM_USART_EVENT_RX_TIMEOUT was signaled
5006     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_TIMEOUT) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_TIMEOUT was not signaled!");
5007
5008     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5009     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5010
5011     // Give USART Server 10 ms to prepare for reception of the next command
5012     (void)osDelay(10U);
5013
5014     return;
5015   } while (false);
5016 #endif
5017 }
5018
5019 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5020 /**
5021 \brief Function: Function USART_Rx_Break
5022 \details
5023 The function \b USART_Rx_Break verifies signaling of the <b>ARM_USART_EVENT_RX_BREAK</b> event:
5024  - in default mode
5025  - with default data bits
5026  - with default parity
5027  - with default stop bits
5028  - with default flow control
5029  - at default baudrate
5030
5031 it also checks that status rx_break flag was activated.
5032
5033 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5034 */
5035 void USART_Rx_Break (void) {
5036
5037   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5038 #if  (USART_SERVER_USED == 1)
5039   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5040   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5041   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; }
5042
5043   do {
5044     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5045
5046     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
5047                        USART_CFG_DEF_DATA_BITS_VAL    | 
5048                        USART_CFG_DEF_PARITY_VAL       | 
5049                        USART_CFG_DEF_STOP_BITS_VAL    | 
5050                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
5051                        USART_CFG_DEF_CPOL_VAL         | 
5052                        USART_CFG_DEF_CPHA_VAL         , 
5053                        USART_CFG_DEF_BAUDRATE);
5054
5055     // Instruct USART Server to signal Break for 20 ms
5056     if (CmdSetBrk(10U, 20U) != EXIT_SUCCESS) { break; }
5057
5058     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5059     (void)drv->Receive(ptr_rx_buf, 1U);
5060
5061     // This test allows break detection for continuous mode as well 
5062     // as LIN variant (return to inactive after 10/11 bits)
5063     (void)osDelay(40U);
5064
5065     // Assert that event ARM_USART_EVENT_RX_BREAK was signaled
5066     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_BREAK) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_BREAK was not signaled!");
5067
5068     // Assert that status rx_break flag is active
5069     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_break != 0U, "[FAILED] Status rx_break flag was not activated!");
5070
5071     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5072     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5073
5074     // Give USART Server 10 ms to prepare for reception of the next command
5075     (void)osDelay(10U);
5076
5077     return;
5078   } while (false);
5079 #endif
5080 }
5081
5082 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5083 /**
5084 \brief Function: Function USART_Rx_Framing_Error
5085 \details
5086 The function \b USART_Rx_Framing_Error verifies signaling of the <b>ARM_USART_EVENT_RX_FRAMING_ERROR</b> event:
5087  - in default mode
5088  - with default data bits
5089  - with default parity
5090  - with default stop bits
5091  - with default flow control
5092  - at default baudrate
5093
5094 it also checks that status rx_framing_error flag was activated.
5095
5096 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5097 */
5098 void USART_Rx_Framing_Error (void) {
5099
5100   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5101 #if  (USART_SERVER_USED == 1)
5102   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5103   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5104   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; }
5105
5106   do {
5107     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5108
5109     // We test framing error by adding parity bit if it is not set as default setting, 
5110     // or removing parity bit if it is set as default setting
5111     if (USART_CFG_DEF_PARITY == PARITY_NONE) {
5112       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; }
5113     } else {
5114       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; }
5115     }
5116     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
5117
5118     (void)drv->Control(USART_CFG_DEF_MODE_VAL         | 
5119                        USART_CFG_DEF_DATA_BITS_VAL    | 
5120                        USART_CFG_DEF_PARITY_VAL       | 
5121                        USART_CFG_DEF_STOP_BITS_VAL    | 
5122                        USART_CFG_DEF_FLOW_CONTROL_VAL | 
5123                        USART_CFG_DEF_CPOL_VAL         | 
5124                        USART_CFG_DEF_CPHA_VAL         , 
5125                        USART_CFG_DEF_BAUDRATE);
5126
5127     event = 0U;
5128
5129     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5130     (void)drv->Receive(ptr_rx_buf, 1U);
5131
5132     (void)osDelay(30U);                 // Wait for USART Server to timeout
5133
5134     // Assert that event ARM_USART_EVENT_RX_FRAMING_ERROR was signaled
5135     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_FRAMING_ERROR) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_FRAMING_ERROR was not signaled!");
5136
5137     // Assert that status rx_framing_error flag is active
5138     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_framing_error != 0U, "[FAILED] Status rx_framing_error flag was not activated!");
5139
5140     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5141     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5142
5143     // Give USART Server 10 ms to prepare for reception of the next command
5144     (void)osDelay(10U);
5145
5146     return;
5147   } while (false);
5148 #endif
5149 }
5150
5151 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5152 /**
5153 \brief Function: Function USART_Rx_Parity_Error
5154 \details
5155 The function \b USART_Rx_Parity_Error verifies signaling of the <b>ARM_USART_EVENT_RX_PARITY_ERROR</b> event:
5156  - in default mode
5157  - with default data bits
5158  - with default parity
5159  - with default stop bits
5160  - with default flow control
5161  - at default baudrate
5162
5163 it also checks that status rx_parity_error flag was activated.
5164
5165 \note If Tests Default Mode <b>Synchronous Master/Slave</b> is selected this test is not executed
5166 */
5167 void USART_Rx_Parity_Error (void) {
5168
5169   if (IsNotLoopback() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5170 #if  (USART_SERVER_USED == 1)
5171   if (IsNotSync()     != EXIT_SUCCESS) { TEST_FAIL(); return; }
5172   if (DriverInit()    != EXIT_SUCCESS) { TEST_FAIL(); return; }
5173   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; }
5174
5175   do {
5176     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5177
5178     // We test parity error by requesting USART Server to send an item at ODD parity  
5179     // and configure USART Client to receive with EVEN parity
5180     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; }
5181
5182     if (CmdXfer  (0U, 1U, 10U, 20U, 0U) != EXIT_SUCCESS) { break; }
5183
5184     (void)drv->Control(USART_CFG_DEF_MODE_VAL                                       | 
5185                        USART_CFG_DEF_DATA_BITS_VAL                                  | 
5186                      ((PARITY_EVEN << ARM_USART_PARITY_Pos) & ARM_USART_PARITY_Msk) | 
5187                        USART_CFG_DEF_STOP_BITS_VAL                                  | 
5188                        USART_CFG_DEF_FLOW_CONTROL_VAL                               | 
5189                        USART_CFG_DEF_CPOL_VAL                                       | 
5190                        USART_CFG_DEF_CPHA_VAL                                       , 
5191                        USART_CFG_DEF_BAUDRATE);
5192
5193     event = 0U;
5194
5195     (void)drv->Control(ARM_USART_CONTROL_RX, 1U);
5196     (void)drv->Receive(ptr_rx_buf, 1U);
5197
5198     (void)osDelay(30U);                 // Wait for USART Server to timeout
5199
5200     // Assert that event ARM_USART_EVENT_RX_PARITY_ERROR was signaled
5201     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RX_PARITY_ERROR) != 0U, "[FAILED] Event ARM_USART_EVENT_RX_PARITY_ERROR was not signaled!");
5202
5203     // Assert that status rx_parity_error flag is active
5204     TEST_ASSERT_MESSAGE(drv->GetStatus().rx_parity_error != 0U, "[FAILED] Status rx_parity_error flag was not activated!");
5205
5206     (void)drv->Control(ARM_USART_ABORT_RECEIVE, 0U);
5207     (void)drv->Control(ARM_USART_CONTROL_RX,    0U);
5208
5209     // Give USART Server 10 ms to prepare for reception of the next command
5210     (void)osDelay(10U);
5211
5212     return;
5213   } while (false);
5214 #endif
5215 }
5216
5217 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5218 /**
5219 \brief Function: Function USART_Event_CTS
5220 \details
5221 The function \b USART_Event_CTS verifies signaling of the <b>ARM_USART_EVENT_CTS</b> event:
5222  - in default mode
5223  - with default data bits
5224  - with default parity
5225  - with default stop bits
5226  - with no flow control
5227  - at default baudrate
5228
5229 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5230 */
5231 void USART_Event_CTS (void) {
5232
5233   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5234 #if  (USART_SERVER_USED == 1)
5235   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5236   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5237   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5238   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; }
5239
5240   do {
5241     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5242
5243     // Instruct USART Server to drive RTS to active state for 20 ms
5244     // RTS line from USART Server should be connected to CTS line on the USART Client (DUT)
5245     if (CmdSetMdm(RTS_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5246
5247     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5248                        USART_CFG_DEF_DATA_BITS_VAL | 
5249                        USART_CFG_DEF_PARITY_VAL    | 
5250                        USART_CFG_DEF_STOP_BITS_VAL | 
5251                        ARM_USART_FLOW_CONTROL_CTS  , 
5252                        USART_CFG_DEF_BAUDRATE);
5253
5254     event = 0;
5255
5256     (void)osDelay(20U);
5257
5258     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_CTS) == ARM_USART_EVENT_CTS, "[FAILED] CTS line did not register change!");
5259
5260     (void)osDelay(20U);
5261
5262     return;
5263   } while (false);
5264 #endif
5265 }
5266
5267 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5268 /**
5269 \brief Function: Function USART_Event_DSR
5270 \details
5271 The function \b USART_Event_DSR verifies signaling of the <b>ARM_USART_EVENT_DSR</b> event:
5272  - in default mode
5273  - with default data bits
5274  - with default parity
5275  - with default stop bits
5276  - with no flow control
5277  - at default baudrate
5278
5279 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5280 */
5281 void USART_Event_DSR (void) {
5282
5283   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5284 #if  (USART_SERVER_USED == 1)
5285   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5286   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5287   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5288   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; }
5289
5290   do {
5291     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5292
5293     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5294                        USART_CFG_DEF_DATA_BITS_VAL | 
5295                        USART_CFG_DEF_PARITY_VAL    | 
5296                        USART_CFG_DEF_STOP_BITS_VAL | 
5297                        ARM_USART_FLOW_CONTROL_NONE , 
5298                        USART_CFG_DEF_BAUDRATE);
5299
5300     event = 0;
5301
5302     // Instruct USART Server to drive DTR to active state for 20 ms
5303     // DTR line from USART Server should be connected to DSR line on the USART Client (DUT)
5304     if (CmdSetMdm(DTR_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5305
5306     (void)osDelay(20U);
5307
5308     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_DSR) == ARM_USART_EVENT_DSR, "[FAILED] DSR line did not register change!");
5309
5310     (void)osDelay(20U);
5311
5312     return;
5313   } while (false);
5314 #endif
5315 }
5316
5317 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5318 /**
5319 \brief Function: Function USART_Event_DCD
5320 \details
5321 The function \b USART_Event_DCD verifies signaling of the <b>ARM_USART_EVENT_DCD</b> event:
5322  - in default mode
5323  - with default data bits
5324  - with default parity
5325  - with default stop bits
5326  - with no flow control
5327  - at default baudrate
5328
5329 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5330 */
5331 void USART_Event_DCD (void) {
5332
5333   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5334 #if  (USART_SERVER_USED == 1)
5335   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5336   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5337   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5338   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; }
5339
5340   do {
5341     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5342
5343     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5344                        USART_CFG_DEF_DATA_BITS_VAL | 
5345                        USART_CFG_DEF_PARITY_VAL    | 
5346                        USART_CFG_DEF_STOP_BITS_VAL | 
5347                        ARM_USART_FLOW_CONTROL_NONE , 
5348                        USART_CFG_DEF_BAUDRATE);
5349
5350     event = 0;
5351
5352     // Instruct USART Server to drive RTS to active state for 20 ms
5353     if (CmdSetMdm(TO_DCD_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5354
5355     (void)osDelay(20U);
5356
5357     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_DCD) == ARM_USART_EVENT_DCD, "[FAILED] DCD line did not register change!");
5358
5359     (void)osDelay(20U);
5360
5361     return;
5362   } while (false);
5363 #endif
5364 }
5365
5366 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
5367 /**
5368 \brief Function: Function USART_Event_RI
5369 \details
5370 The function \b USART_Event_RI verifies signaling of the <b>ARM_USART_EVENT_RI</b> event:
5371  - in default mode
5372  - with default data bits
5373  - with default parity
5374  - with default stop bits
5375  - with no flow control
5376  - at default baudrate
5377
5378 \note If Tests Default Mode <b>Synchronous Master/Slave</b> or <b>Single-wire</b> is selected this test is not executed
5379 */
5380 void USART_Event_RI (void) {
5381
5382   if (IsNotLoopback()   != EXIT_SUCCESS) { TEST_FAIL(); return; }
5383 #if  (USART_SERVER_USED == 1)
5384   if (IsNotSync()       != EXIT_SUCCESS) { TEST_FAIL(); return; }
5385   if (IsNotSingleWire() != EXIT_SUCCESS) { TEST_FAIL(); return; }
5386   if (DriverInit()      != EXIT_SUCCESS) { TEST_FAIL(); return; }
5387   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; }
5388
5389   do {
5390     if (ComConfigDefault() != EXIT_SUCCESS) { break; }
5391
5392     (void)drv->Control(USART_CFG_DEF_MODE_VAL      | 
5393                        USART_CFG_DEF_DATA_BITS_VAL | 
5394                        USART_CFG_DEF_PARITY_VAL    | 
5395                        USART_CFG_DEF_STOP_BITS_VAL | 
5396                        ARM_USART_FLOW_CONTROL_NONE , 
5397                        USART_CFG_DEF_BAUDRATE);
5398
5399     event = 0;
5400
5401     // Instruct USART Server to drive RI to active state for 20 ms
5402     if (CmdSetMdm(TO_RI_ON, 10U, 20U) != EXIT_SUCCESS) { break; }
5403
5404     (void)osDelay(40U);
5405
5406     // RI event should be active after RI returns to inactive state (Trailing Edge RI)
5407     TEST_ASSERT_MESSAGE((event & ARM_USART_EVENT_RI) == ARM_USART_EVENT_RI, "[FAILED] RI line did not register change!");
5408
5409     return;
5410   } while (false);
5411 #endif
5412 }
5413
5414 /**
5415 @}
5416 */
5417 // End of usart_tests_evt