blob: a3f16ee69fc35a19cf21db3265b9b7028134002d [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2012
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * tty_ut.c
40 *
41 * Project:
42 * --------
43 * MOLY
44 *
45 * Description:
46 * ------------
47 * TTY Core unit test file - it needs Host Test Program to run test.
48 *
49 * Author:
50 * -------
51 * -------
52 *
53 * ==========================================================================
54 * $Log$
55 *
56 * 09 23 2019 bo-kai.huang
57 * [MOLY00357061] 97 Code Merge
58 * [TerTer]
59 *
60 * 10 21 2015 mt.tsai
61 * [MOLY00146136] Fix TTY Core ut program for SMP and set gpd's next to NULL
62 * give a UT Task instance on each port to prevent race condition & Set gpd's next as NULL
63 *
64 * 03 11 2015 i-wei.tsai
65 * [MOLY00097392] [UMOLY] [TTY] Timer tick macro modification
66 * .
67 *
68 * 06 26 2013 i-wei.tsai
69 * [MOLY00027496] [TTYCore] Features check-in
70 * 1. add new TTY_CMD_MTU_SIZE support
71 * 2. add plug-in/plug-out indication
72 * 3. fix issue of flushing rx internal gpd
73 *
74 * 05 29 2013 haoren.kao
75 * [MOLY00024108] Support New USB Core
76 * Replace with New USB Core.
77 * We sync with the following codes from HaoRen MOLY CBr w1322:
78 * 1. USB Core
79 * 2. USB Class - acm/rndis/mbim
80 * 3. ipcore
81 * 4. ttycore
82 * 5. ethercore
83 *
84 * 02 21 2013 i-wei.tsai
85 * [MOLY00010632] add TTYCore new features
86 * checkin supporting buffer port features
87 *
88 * 11 08 2012 haoren.kao
89 * [MOLY00005322] TATAKA merge to MOLY
90 *
91 * MOLY Migration from TATAKA
92 ****************************************************************************/
93
94#include <stdio.h>
95#include <stdlib.h>
96#include <math.h>
97#include "kal_debug.h"
98//#include "kal_release.h"
99#include "syscomp_config.h"
100#include "kal_debug.h"
101#include "dcl.h"
102#include "qmu_bm.h"
103#include "qmu_bm_util.h"
104
105#include "devdrv_ls.h"
106#include "drv_msgid.h"
107#include "md_drv_sap.h"
108#include "kal_public_defs.h"
109#include "kal_public_api.h"
110
111/*for dhl trace*/
112#include "dhl_trace.h"
113
114#define TTY_UT_MISC_TEST (0) /* Set 1 to enable owner test and init/deinit test*/
115
116#define USB_TEST
117//#undef USB_TEST
118
119#if defined USB_TEST /* USB COM */
120#define TTY_UT_COM_NUM 3
121#define TTY_UT_COM1 uart_port_usb3
122#define TTY_UT_COM2 uart_port_usb4
123#define TTY_UT_COM3 uart_port_usb5
124
125#else /* UART COM */
126#define TTY_UT_COM_NUM 1
127#define TTY_UT_COM1 uart_port2
128#define TTY_UT_COM2 uart_port2
129#define TTY_UT_COM3 uart_port2
130#endif
131
132#if (TTY_UT_COM_NUM > 3)
133#error "COM number more than three does not support."
134#endif
135
136#define TTY_UT_TASK_1_PRIORITY 1
137#define TTY_UT_TASK_2_PRIORITY 2
138#define TTY_UT_TASK_3_PRIORITY 3
139
140#define IO_REQUEST_PUSH(_ori, _new) \
141{ \
142 tty_io_request_t *tmp_ior = _ori; \
143 while (tmp_ior->next_request != NULL) { \
144 tmp_ior = tmp_ior->next_request; \
145 } \
146 tmp_ior->next_request = _new; \
147}
148
149#define BUSY_WAIT(_loopCnt) do{unsigned int i,j;for(i=0;i<_loopCnt;i++){j=i;j++;}}while(0)
150
151typedef enum _tty_ut_mode {
152 TTY_UT_CONV_TX_ONLY = 0,
153 TTY_UT_NEW_TX_ONLY,
154 TTY_UT_CONV_RX_ONLY,
155 TTY_UT_NEW_RX_ONLY,
156 TTY_UT_CONV_TX_CONV_RX,
157 TTY_UT_CONV_TX_NEW_RX,
158 TTY_UT_NEW_TX_CONV_RX,
159 TTY_UT_NEW_TX_NEW_RX,
160 TTY_UT_NEW_INIT_CONV_TX_CONV_RX,
161 TTY_UT_BYPASS, //This is used to disable test procedure
162} tty_ut_mode_e;
163
164static tty_ut_mode_e tty_ut_mode_1 = TTY_UT_NEW_TX_NEW_RX; //TTY_UT_NEW_TX_NEW_RX;
165static tty_ut_mode_e tty_ut_mode_2 = /*TTY_UT_NEW_TX_NEW_RX;*/ TTY_UT_CONV_TX_CONV_RX;
166static tty_ut_mode_e tty_ut_mode_3 = TTY_UT_NEW_TX_CONV_RX;
167
168// for conventional path
169#define TTY_UT_NEW_BUF_SIZE QBM_TTY_XXX_DATA_LEN
170#define TTY_UT_CONV_BUF_SIZE QBM_TTY_XXX_DATA_LEN*2
171
172#define TTY_UT_LB_CON_TX_TX_BUF_SIZE QBM_TTY_XXX_DATA_LEN*10
173
174#define TTY_UT_CHUNK_SIZE_DEFAULT (QBM_TTY_XXX_DATA_LEN)
175
176typedef struct _ttyut_instance_t {
177 DCL_HANDLE handle;
178 DCL_UINT32 owner;
179 tty_io_request_t *ttyut_rx_ior;
180 kal_mutexid ttyut_mutex;
181
182 kal_uint8 ttyut_rx_buf[TTY_UT_CONV_BUF_SIZE];
183 kal_uint8 ttyut_tx_buf[TTY_UT_CONV_BUF_SIZE];
184 kal_uint32 ttyut_tx_offset;
185 kal_uint32 ttyut_tx_len;
186
187 kal_uint8 conv_tx_rx_buf[TTY_UT_LB_CON_TX_TX_BUF_SIZE];
188 kal_uint32 conv_tx_rx_rd_idx;
189 kal_uint32 conv_tx_rx_wt_idx;
190 kal_uint32 conv_tx_rx_wrap;
191} ttyut_instance_t;
192static ttyut_instance_t ttyut_inst_g[uart_max_port];
193
194#if defined(__MTK_TARGET__)
195extern void dbg_print(char *fmt,...);
196#define ttyut_print dbg_print
197#else
198#define ttyut_print(...) dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_TTY, ##__VA_ARGS__)
199#endif
200
201#define DCL_UART_MAGIC_NUM 0x40000000
202#define DCL_UART_GET_DEV(handle_) ((DCL_DEV)((handle_) & (~DCL_UART_MAGIC_NUM)))
203
204// ==========================================================
205// Private Function
206// ==========================================================
207static kal_bool ttyut_create_instance(DCL_HANDLE handle, DCL_UINT32 owner)
208{
209 char mutex_name_str[64];
210 DCL_DEV uart_port = DCL_UART_GET_DEV(handle);
211
212 if (ttyut_inst_g[uart_port].handle == (DCL_HANDLE) 0x0) {
213
214 sprintf(mutex_name_str, "TTY_UT_%d", (int)handle);
215 ttyut_inst_g[uart_port].handle = handle;
216 ttyut_inst_g[uart_port].owner = owner;
217 ttyut_inst_g[uart_port].ttyut_rx_ior = NULL;
218 ttyut_inst_g[uart_port].ttyut_mutex = kal_create_mutex(mutex_name_str);
219
220 return KAL_TRUE;
221 }
222
223 // Can't create TTY_UT instance, ASSERT.
224 ASSERT(0);
225 return KAL_FALSE;
226}
227
228static ttyut_instance_t* ttyut_get_instance(DCL_HANDLE handle)
229{
230 DCL_DEV uart_port = DCL_UART_GET_DEV(handle);
231
232 if (ttyut_inst_g[uart_port].handle == handle) {
233 return &ttyut_inst_g[uart_port];
234 }
235
236 return NULL;
237}
238
239
240// ==========================================================
241// Private Function
242// ==========================================================
243DCL_STATUS _ttyut_rx_cb(DCL_HANDLE handle, module_type source_id, tty_io_request_t *rx_ior)
244{
245 ttyut_instance_t *ttyut_inst_p;
246
247 ttyut_inst_p = ttyut_get_instance(handle);
248
249 kal_take_mutex(ttyut_inst_p->ttyut_mutex);
250 if (ttyut_inst_p->ttyut_rx_ior) {
251 IO_REQUEST_PUSH(ttyut_inst_p->ttyut_rx_ior, rx_ior);
252 } else {
253 ttyut_inst_p->ttyut_rx_ior = rx_ior;
254 }
255 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
256
257 ttyut_print("=========>_ttyut_rx_cb\r\n");
258 return STATUS_OK;
259}
260
261DCL_STATUS _ttyut_tx_done_cb(DCL_HANDLE handle, module_type source_id, tty_io_request_t *tx_ior)
262{
263 if (tx_ior) {
264 /* free all GPDs of all IOR */
265 do {
266 qbmt_dest_q(tx_ior->first_gpd, tx_ior->last_gpd);
267 } while ((tx_ior = tx_ior->next_request) != NULL);
268 } else {
269 ttyut_print("[TTY UT] [ERROR] =========>_ttyut_tx_done_cb : tx_ior is NULL!!!!!\r\n");
270 }
271
272 ttyut_print("=========>_ttyut_tx_done_cb\r\n");
273 return STATUS_OK;
274}
275
276DCL_STATUS _ttyut_drv_state_cb(DCL_HANDLE handle, tty_drv_state_e state)
277{
278 ttyut_print("=========>_ttyut_drv_state_cb: state - %s\r\n", (state==DRV_ST_ATTACHED)?"attached":"detached");
279 return STATUS_OK;
280}
281
282DCL_STATUS _ttyut_hdr_main(DCL_DEV dev, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
283{
284 return STATUS_OK;
285}
286
287kal_bool _ttyut_upmod_init_deinit_test(kal_uint8 uart_port)
288{
289 #define TEST_ROUND 100
290 #define UART_INVALID_PORT 0xFFFF
291 DCL_STATUS status;
292 DCL_HANDLE handle;
293 int idx;
294 UART_CTRL_OPEN_T ur_ctrl_open;
295 UART_CTRL_CLOSE_T ur_ctrl_close;
296 Seriport_HANDLER_T tty_ut_uart_handler = {DCL_UART_USB_TYPE, _ttyut_hdr_main};
297
298 /*Test 1*/
299 /* Init non-existed port -> should init failed */
300 /* test invalid port 0xFFFF*/
301 handle = DclSerialPort_Open(UART_INVALID_PORT, 0);
302 if(handle != STATUS_INVALID_DEVICE)
303 {
304 ttyut_print("[ERROR][TTY UT] DCL upper module open non-existed port successfully");
305 return KAL_FALSE;
306 }
307 /* test non-exist port by invalid handle with NEW API*/
308 handle = 0xFFFF;
309 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
310 if (status == STATUS_OK) {
311 ttyut_print("[ERROR][TTY UT] DCL upper module init non-existed port with NEW API successfully");
312 return KAL_FALSE;
313 }
314 /* test non-exist port by invalid handle with Conventional API*/
315 handle = 0xFFFF;
316 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
317 if (status == STATUS_OK) {
318 ttyut_print("[ERROR][TTY UT] DCL upper module init non-existed port with Conv API successfully");
319 return KAL_FALSE;
320 }
321
322 /*Test 2 : Driver reg/de-reg API test*/
323 /* First register callback -> should not return failed */
324 handle = DclSerialPort_Open(uart_max_port, 0);
325 for (idx = 0; idx < TEST_ROUND; idx ++)
326 {
327 status = DclSerialPort_DrvRegisterCb(handle, &tty_ut_uart_handler);
328 if (status != STATUS_OK) {
329 ttyut_print("[ERROR][TTY UT] Driver first register callback function failed");
330 return KAL_FALSE;
331 }
332 /* Duplicated register -> should return failed */
333 status = DclSerialPort_DrvRegisterCb(handle, &tty_ut_uart_handler);
334 if (status == STATUS_OK) {
335 ttyut_print("[ERROR][TTY UT] Driver first register callback function twice successfully");
336 return KAL_FALSE;
337 }
338 /* First De-register callback -> should not return failed */
339 status = DclSerialPort_DrvDeRegisterCb(handle);
340 if (status != STATUS_OK) {
341 ttyut_print("[ERROR][TTY UT] Driver first De-register callback function failed");
342 return KAL_FALSE;
343 }
344 /* Duplicated register -> should return failed */
345 status = DclSerialPort_DrvDeRegisterCb(handle);
346 if (status == STATUS_OK) {
347 ttyut_print("[ERROR][TTY UT] Driver De-register callback function twice successfully");
348 return KAL_FALSE;
349 }
350 }
351
352 /*Test 3 : open non-registered port with NEW API*/
353 /* Init non-register port -> should not return failed */
354 handle = DclSerialPort_Open(uart_max_port, 0);
355 for (idx = 0; idx < TEST_ROUND; idx ++)
356 {
357 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
358 if (status != STATUS_OK) {
359 ttyut_print("[ERROR][TTY UT] DCL upper module first init non-registered port failed");
360 return KAL_FALSE;
361 }
362 /* Duplicated init -> should init failed */
363 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
364 if (status == STATUS_OK) {
365 ttyut_print("[ERROR][TTY UT] DCL upper module init twice (non-registered port)successfully!!");
366 return KAL_FALSE;
367 }
368 /* First deinit -> should deinit successfully */
369 status = DclSerialPort_UpModuleDeinit(handle);
370 if (status != STATUS_OK) {
371 ttyut_print("[ERROR][TTY UT] DCL upper module first deinit non-registered port failed");
372 return KAL_FALSE;
373 }
374 /* Duplicated deinit -> should deinit failed */
375 status = DclSerialPort_UpModuleDeinit(handle);
376 if (status == STATUS_OK) {
377 ttyut_print("[ERROR][TTY UT] DCL upper module deinit twice (non-registered port)successfully!!");
378 return KAL_FALSE;
379 }
380 }
381
382 /*Test 4 : open non-registered port with Conv API*/
383 /* Init non-register port -> should not return failed */
384 handle = DclSerialPort_Open(uart_max_port, 0);
385 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
386 ur_ctrl_close.u4OwenrId = MOD_TTY_UT;
387 for (idx = 0; idx < TEST_ROUND; idx ++)
388 {
389 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
390 if (status != STATUS_OK) {
391 ttyut_print("[ERROR][TTY UT] DCL upper module first init non-registered port failed");
392 return KAL_FALSE;
393 }
394 /* Duplicated init -> should init failed */
395 status = DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
396 if (status == STATUS_OK) {
397 ttyut_print("[ERROR][TTY UT] DCL upper module init twice (non-registered port)successfully!!");
398 return KAL_FALSE;
399 }
400 /* First deinit -> should deinit successfully */
401 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
402 if (status != STATUS_OK) {
403 ttyut_print("[ERROR][TTY UT] DCL upper module first deinit non-registered port failed");
404 return KAL_FALSE;
405 }
406 /* Duplicated deinit -> should deinit failed */
407 status = DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
408 if (status == STATUS_OK) {
409 ttyut_print("[ERROR][TTY UT] DCL upper module deinit twice (non-registered port)successfully!!");
410 return KAL_FALSE;
411 }
412 }
413
414 /*Test 5 : open registered port test*/
415 handle = DclSerialPort_Open(uart_port, 0);
416 for (idx = 0; idx < TEST_ROUND; idx ++)
417 {
418 /* First init -> should init successfully */
419 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
420 if (status != STATUS_OK) {
421 ttyut_print("[ERROR][TTY UT] DCL upper module init failed");
422 return KAL_FALSE;
423 }
424 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
425
426 /* Duplicated init -> should init failed */
427 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
428 if (status == STATUS_OK) {
429 ttyut_print("[ERROR][TTY UT] DCL upper module init twice successfully!!");
430 return KAL_FALSE;
431 }
432
433 /* First deinit -> should deinit successfully */
434 status = DclSerialPort_UpModuleDeinit(handle);
435 if (status != STATUS_OK) {
436 ttyut_print("[ERROR][TTY UT] DCL upper module init failed");
437 return KAL_FALSE;
438 }
439
440 /* Duplicated deinit -> should deinit failed */
441 status = DclSerialPort_UpModuleDeinit(handle);
442 if (status == STATUS_OK) {
443 ttyut_print("[ERROR][TTY UT] DCL upper module init failed");
444 return KAL_FALSE;
445 }
446 }
447
448 return KAL_TRUE;
449}
450
451kal_bool _ttyut_upmod_change_owner_test()
452{
453 DCL_STATUS status;
454 DCL_HANDLE handle;
455 UART_CTRL_OPEN_T ur_ctrl_open;
456 UART_CTRL_CLOSE_T ur_ctrl_close;
457 UART_CTRL_OWNER_T ur_ctrl_owner;
458 UART_CTRL_GET_DRV_STATE_T getDrvState;
459 UART_CTRL_GET_CHUNK_SIZE_T getChunkSize;
460
461 handle = DclSerialPort_Open(TTY_UT_COM1, 0);
462
463 kal_sleep_task(KAL_TICKS_3_SEC);
464
465
466 /* Conventional owner change to conventional owner */
467 {
468 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
469 char *test_string1 = "[Change owner test] Conventional Owner A change to ";
470 char *test_string2 = "Conventional owner B\r\n";
471
472 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
473 DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
474
475 /* Send string */
476 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
477 ur_ctrl_putbytes.puBuffaddr = (DCL_UINT8*)test_string1;
478 ur_ctrl_putbytes.u2Length = strlen(test_string1);
479 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
480 kal_sleep_task(KAL_TICKS_10_MSEC/10);
481
482 /* Change owner to MOD_TTY_UT99 */
483 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT99;
484 DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
485
486 kal_set_active_module_id(MOD_TTY_UT99);
487
488 /* Send string */
489 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT99;
490 ur_ctrl_putbytes.puBuffaddr = (DCL_UINT8*)test_string2;
491 ur_ctrl_putbytes.u2Length = strlen(test_string2);
492 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
493 kal_sleep_task(KAL_TICKS_10_MSEC/10);
494
495 /* Close com port */
496 ur_ctrl_close.u4OwenrId = MOD_TTY_UT99;
497 DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
498
499 kal_set_active_module_id(MOD_TTY_UT);
500 }
501
502 BUSY_WAIT(1000);
503
504 /* Conventional owner change to new owner */
505 {
506 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
507 char *test_string1 = "[Change owner test] Conventional Owner A change to ";
508 char *test_string2 = "New owner B\r\n";
509 void *tx_gpd;
510 tty_io_request_t *tx_ior;
511 unsigned char *tx_buf_ptr;
512
513 ur_ctrl_open.u4OwenrId = MOD_TTY_UT;
514 DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &ur_ctrl_open);
515
516 /* Send string */
517 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT;
518 ur_ctrl_putbytes.puBuffaddr = (DCL_UINT8*)test_string1;
519 ur_ctrl_putbytes.u2Length = strlen(test_string1);
520 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
521 kal_sleep_task(KAL_TICKS_10_MSEC/10);
522
523 /* Change owner to MOD_TTY_UT99 */
524 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT99;
525 DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
526 kal_set_active_module_id(MOD_TTY_UT99);
527 DclSerialPort_UpModuleReinit(handle, MOD_TTY_UT99, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
528 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
529
530 // Wait for device ready
531 getDrvState.u4OwnerId = MOD_TTY_UT;
532 do {
533 kal_sleep_task(KAL_TICKS_100_MSEC);
534 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
535 } while (getDrvState.drv_state != DRV_ST_ATTACHED);
536
537 // Get chunk size
538 do {
539 kal_sleep_task(KAL_TICKS_100_MSEC);
540 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
541 } while (status != STATUS_OK);
542
543 /* Send string */
544 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
545 if (tx_gpd) {
546 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
547 tx_ior->next_request = NULL;
548 tx_ior->first_gpd = tx_gpd;
549 tx_ior->last_gpd = tx_gpd;
550
551 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
552 kal_mem_cpy((void*)tx_buf_ptr, test_string2, strlen(test_string2));
553 QBM_DES_SET_DATALEN(tx_gpd, strlen(test_string2)); // Set data length
554
555 QBM_DES_SET_HWO(tx_gpd);
556 qbm_cal_set_checksum(tx_gpd);
557 //QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
558
559 DclSerialPort_UpModuleTransmit(handle, tx_ior);
560 } else {
561 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
562 return KAL_FALSE;
563 }
564 kal_sleep_task(KAL_TICKS_10_MSEC/10);
565
566 /* Close com port */
567 DclSerialPort_UpModuleDeinit(handle);
568
569 kal_set_active_module_id(MOD_TTY_UT);
570 }
571
572 BUSY_WAIT(1000);
573
574 /* New owner change to new owner */
575 {
576 char *test_string1 = "[Change owner test] New Owner A change to ";
577 char *test_string2 = "New owner B\r\n";
578 void *tx_gpd;
579 tty_io_request_t *tx_ior;
580 unsigned char *tx_buf_ptr;
581 UART_CTRL_CLR_BUFFER_T ur_ctrl_clr_buf;
582
583 /* Bind COM port - initialization */
584 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
585 if (status != STATUS_OK) {
586 ttyut_print("[TTY UT] DCL upper module init failed");
587 return KAL_FALSE;
588 } else {
589 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
590 // Wait for device ready
591 getDrvState.u4OwnerId = MOD_TTY_UT;
592 do {
593 kal_sleep_task(KAL_TICKS_100_MSEC);
594 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
595 } while (getDrvState.drv_state != DRV_ST_ATTACHED);
596
597 // Get chunk size
598 do {
599 kal_sleep_task(KAL_TICKS_100_MSEC);
600 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
601 } while (status != STATUS_OK);
602 }
603
604 /* Send string */
605 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
606 if (tx_gpd) {
607 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
608 tx_ior->next_request = NULL;
609 tx_ior->first_gpd = tx_gpd;
610 tx_ior->last_gpd = tx_gpd;
611
612 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
613 kal_mem_cpy((void*)tx_buf_ptr, test_string1, strlen(test_string1));
614 QBM_DES_SET_DATALEN(tx_gpd, strlen(test_string1)); // Set data length
615
616 QBM_DES_SET_HWO(tx_gpd);
617 qbm_cal_set_checksum(tx_gpd);
618 QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
619
620 DclSerialPort_UpModuleTransmit(handle, tx_ior);
621 } else {
622 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
623 return KAL_FALSE;
624 }
625 kal_sleep_task(KAL_TICKS_10_MSEC/10);
626
627 /* Send Clear Tx/Rx buffer commands */
628 ur_ctrl_clr_buf.u4OwenrId = MOD_TTY_UT;
629 DclSerialPort_Control(handle, SIO_CMD_CLR_TX_BUF, (DCL_CTRL_DATA_T*) &ur_ctrl_clr_buf);
630 DclSerialPort_Control(handle, SIO_CMD_CLR_RX_BUF, (DCL_CTRL_DATA_T*) &ur_ctrl_clr_buf);
631
632 /* Change owner to MOD_TTY_UT99 */
633 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT99;
634 DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
635 kal_set_active_module_id(MOD_TTY_UT99);
636 DclSerialPort_UpModuleReinit(handle, MOD_TTY_UT99, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
637 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
638
639 // Wait for device ready
640 getDrvState.u4OwnerId = MOD_TTY_UT;
641 do {
642 kal_sleep_task(KAL_TICKS_100_MSEC);
643 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
644 } while (getDrvState.drv_state != DRV_ST_ATTACHED);
645
646 // Get chunk size
647 do {
648 kal_sleep_task(KAL_TICKS_100_MSEC);
649 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
650 } while (status != STATUS_OK);
651
652 /* Send string */
653 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
654 if (tx_gpd) {
655 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
656 tx_ior->next_request = NULL;
657 tx_ior->first_gpd = tx_gpd;
658 tx_ior->last_gpd = tx_gpd;
659
660 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
661 kal_mem_cpy((void*)tx_buf_ptr, test_string2, strlen(test_string2));
662 QBM_DES_SET_DATALEN(tx_gpd, strlen(test_string2)); // Set data length
663
664 QBM_DES_SET_HWO(tx_gpd);
665 qbm_cal_set_checksum(tx_gpd);
666 //QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
667
668 DclSerialPort_UpModuleTransmit(handle, tx_ior);
669 } else {
670 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
671 return KAL_FALSE;
672 }
673 kal_sleep_task(KAL_TICKS_10_MSEC/10);
674
675 /* Close com port */
676 DclSerialPort_UpModuleDeinit(handle);
677
678 kal_set_active_module_id(MOD_TTY_UT);
679 }
680
681 BUSY_WAIT(1000);
682
683 /* New owner change to conventional owner */
684 {
685 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
686 char *test_string1 = "[Change owner test] New Owner A change to ";
687 char *test_string2 = "Conventional owner B\r\nPASS\r\n";
688 void *tx_gpd;
689 tty_io_request_t *tx_ior;
690 unsigned char *tx_buf_ptr;
691 UART_CTRL_CLR_BUFFER_T ur_ctrl_clr_buf;
692
693 /* Bind COM port - initialization */
694 status = DclSerialPort_UpModuleInit(handle, MOD_TTY_UT, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
695 if (status != STATUS_OK) {
696 ttyut_print("[TTY UT] DCL upper module init failed");
697 return KAL_FALSE;
698 } else {
699 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
700
701 // Wait for device ready
702 getDrvState.u4OwnerId = MOD_TTY_UT;
703
704 do {
705 kal_sleep_task(KAL_TICKS_100_MSEC);
706 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
707 } while (getDrvState.drv_state != DRV_ST_ATTACHED);
708
709 // Get chunk size
710 do {
711 kal_sleep_task(KAL_TICKS_100_MSEC);
712 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
713 } while (status != STATUS_OK);
714 }
715
716 /* Send string */
717 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
718 if (tx_gpd) {
719 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
720 tx_ior->next_request = NULL;
721 tx_ior->first_gpd = tx_gpd;
722 tx_ior->last_gpd = tx_gpd;
723
724 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
725 kal_mem_cpy((void*)tx_buf_ptr, test_string1, strlen(test_string1));
726 QBM_DES_SET_DATALEN(tx_gpd, strlen(test_string1)); // Set data length
727
728 QBM_DES_SET_HWO(tx_gpd);
729 qbm_cal_set_checksum(tx_gpd);
730 //QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
731
732 DclSerialPort_UpModuleTransmit(handle, tx_ior);
733 } else {
734 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
735 return KAL_FALSE;
736 }
737 kal_sleep_task(KAL_TICKS_10_MSEC/10);
738
739 /* Send Clear Tx/Rx buffer commands */
740 ur_ctrl_clr_buf.u4OwenrId = MOD_TTY_UT;
741 DclSerialPort_Control(handle, SIO_CMD_CLR_TX_BUF, (DCL_CTRL_DATA_T*) &ur_ctrl_clr_buf);
742 DclSerialPort_Control(handle, SIO_CMD_CLR_RX_BUF, (DCL_CTRL_DATA_T*) &ur_ctrl_clr_buf);
743
744 /* Change owner to MOD_TTY_UT99 */
745 ur_ctrl_owner.u4OwenrId = MOD_TTY_UT99;
746 DclSerialPort_Control(handle, SIO_CMD_SET_OWNER, (DCL_CTRL_DATA_T*) &ur_ctrl_owner);
747
748 kal_set_active_module_id(MOD_TTY_UT99);
749
750 /* Send string */
751 ur_ctrl_putbytes.u4OwenrId = MOD_TTY_UT99;
752 ur_ctrl_putbytes.puBuffaddr = (DCL_UINT8*)test_string2;
753 ur_ctrl_putbytes.u2Length = strlen(test_string2);
754 DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
755 kal_sleep_task(KAL_TICKS_10_MSEC/10);
756
757 /* Close com port */
758 ur_ctrl_close.u4OwenrId = MOD_TTY_UT99;
759 DclSerialPort_Control(handle, SIO_CMD_CLOSE, (DCL_CTRL_DATA_T*) &ur_ctrl_close);
760
761 kal_set_active_module_id(MOD_TTY_UT);
762 }
763
764 BUSY_WAIT(1000);
765
766 return KAL_TRUE;
767}
768
769static kal_bool ttyut_test_preproc(tty_ut_mode_e test_mode, kal_uint8 uart_port)
770{
771 DCL_STATUS status;
772 DCL_HANDLE handle;
773 DCL_UINT32 owner = MOD_NIL;
774
775 handle = DclSerialPort_Open(uart_port, 0);
776
777 if (TTY_UT_COM1 == uart_port) {
778 owner = MOD_TTY_UT;
779 } else if (TTY_UT_COM2 == uart_port) {
780 owner = MOD_TTY_UT2;
781 } else if (TTY_UT_COM3 == uart_port) {
782 owner = MOD_TTY_UT3;
783 } else {
784 // Unsupported mode, ASSERT.
785 ASSERT(0);
786 }
787 ttyut_create_instance(handle, owner);
788
789 switch (test_mode)
790 {
791 case TTY_UT_BYPASS:
792 {
793 //Do nothing;
794 break;
795 }
796 case TTY_UT_CONV_TX_CONV_RX:
797 case TTY_UT_CONV_TX_ONLY:
798 case TTY_UT_CONV_RX_ONLY:
799 {
800 UART_CTRL_OPEN_T data;
801 data.u4OwenrId = owner;
802 DclSerialPort_Control(handle, SIO_CMD_OPEN, (DCL_CTRL_DATA_T*) &data);
803 }
804 break;
805
806 case TTY_UT_NEW_INIT_CONV_TX_CONV_RX:
807 {
808 status = DclSerialPort_UpModuleInit(handle, owner, 0);
809 if (status != STATUS_OK) {
810 ttyut_print("[TTY UT] DCL upper module init failed");
811 }
812 }
813 break;
814 case TTY_UT_NEW_TX_NEW_RX:
815 case TTY_UT_NEW_TX_ONLY:
816 case TTY_UT_NEW_RX_ONLY:
817 {
818 void *rx_gpd_first, *rx_gpd_last;
819 tty_io_request_t *rx_ior;
820 void *rx_gpd_tmp;
821 int i;
822 UART_CTRL_GET_DRV_STATE_T getDrvState;
823 UART_CTRL_GET_CHUNK_SIZE_T getChunkSize;
824
825 /* Bind COM port - initialization */
826 status = DclSerialPort_UpModuleInit(handle, owner, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
827 if (status != STATUS_OK) {
828 ttyut_print("[TTY UT] DCL upper module init failed");
829 } else {
830 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, _ttyut_tx_done_cb, _ttyut_drv_state_cb);
831
832 // Wait for device ready
833 getDrvState.u4OwnerId = owner;
834 do {
835 kal_sleep_task(KAL_TICKS_100_MSEC);
836 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
837 } while ((getDrvState.drv_state != DRV_ST_ATTACHED) || (status != STATUS_OK));
838
839 // Get chunk size
840 do {
841 kal_sleep_task(KAL_TICKS_100_MSEC);
842 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
843 } while (status != STATUS_OK);
844
845 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_TYPE1, 2, &rx_gpd_first, &rx_gpd_last);
846 rx_gpd_tmp = rx_gpd_first;
847
848 if (!rx_gpd_first || !rx_gpd_last) {
849 ttyut_print("[TTY UT] DCL upper module init failed");
850 return KAL_FALSE;
851 }
852
853 // Set allow length
854 for (i=0; i<2; i++) {
855 if(getChunkSize.chunkSize == 1) //Some HIF doesn't have chunksize restrictions(ex: uart)
856 {
857 QBM_DES_SET_ALLOW_LEN(rx_gpd_tmp, TTY_UT_CHUNK_SIZE_DEFAULT);
858 }
859 else
860 {
861 QBM_DES_SET_ALLOW_LEN(rx_gpd_tmp, (kal_uint16)getChunkSize.chunkSize);
862 }
863 qbm_cal_set_checksum((kal_uint8*)rx_gpd_tmp);
864 QBM_CACHE_FLUSH(rx_gpd_tmp, sizeof(qbm_gpd));
865 rx_gpd_tmp = QBM_DES_GET_NEXT(rx_gpd_tmp);
866 }
867
868 rx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(rx_gpd_first);
869 rx_ior->next_request = NULL;
870 rx_ior->first_gpd = rx_gpd_first;
871 rx_ior->last_gpd = rx_gpd_last;
872
873 DclSerialPort_UpModuleAssignRxIor(handle, rx_ior);
874 }
875 }
876 break;
877
878 case TTY_UT_CONV_TX_NEW_RX:
879 {
880 void *rx_gpd_first, *rx_gpd_last;
881 tty_io_request_t *rx_ior;
882 void *rx_gpd_tmp;
883 int i;
884 UART_CTRL_GET_DRV_STATE_T getDrvState;
885 UART_CTRL_GET_CHUNK_SIZE_T getChunkSize;
886
887 /* Bind COM port - initialization */
888 status = DclSerialPort_UpModuleInit(handle, owner, TTY_FLAG_NEW_RX);
889 if (status != STATUS_OK) {
890 ttyut_print("[TTY UT] DCL upper module init failed");
891 } else {
892 DclSerialPort_UpModuleRegisterCb(handle, _ttyut_rx_cb, NULL, _ttyut_drv_state_cb);
893
894 // Wait for device ready
895 getDrvState.u4OwnerId = owner;
896 do {
897 kal_sleep_task(KAL_TICKS_100_MSEC);
898 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
899 } while ((getDrvState.drv_state != DRV_ST_ATTACHED) || (status != STATUS_OK));
900
901 // Get chunk size
902 do {
903 kal_sleep_task(KAL_TICKS_100_MSEC);
904 status = DclSerialPort_Control(handle, TTY_CMD_GET_CHUNK_SIZE, (DCL_CTRL_DATA_T*) &getChunkSize);
905 } while (status != STATUS_OK);
906
907 qbmt_alloc_q_no_tail(QBM_TYPE_TTY_TYPE1, 2, &rx_gpd_first, &rx_gpd_last);
908 rx_gpd_tmp = rx_gpd_first;
909
910 if (!rx_gpd_first || !rx_gpd_last) {
911 ttyut_print("[TTY UT] DCL upper module init failed");
912 return KAL_FALSE;
913 }
914
915 // Set allow length
916 for (i=0; i<2; i++) {
917 QBM_DES_SET_ALLOW_LEN(rx_gpd_tmp, (kal_uint16)getChunkSize.chunkSize);
918 qbm_cal_set_checksum((kal_uint8*)rx_gpd_tmp);
919 QBM_CACHE_FLUSH(rx_gpd_tmp, sizeof(qbm_gpd));
920 rx_gpd_tmp = QBM_DES_GET_NEXT(rx_gpd_tmp);
921 }
922
923 rx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(rx_gpd_first);
924 rx_ior->next_request = NULL;
925 rx_ior->first_gpd = rx_gpd_first;
926 rx_ior->last_gpd = rx_gpd_last;
927
928 DclSerialPort_UpModuleAssignRxIor(handle, rx_ior);
929 }
930 }
931 break;
932
933 case TTY_UT_NEW_TX_CONV_RX:
934 {
935 UART_CTRL_GET_DRV_STATE_T getDrvState;
936
937 /* Bind COM port - initialization */
938 status = DclSerialPort_UpModuleInit(handle, owner, TTY_FLAG_NEW_TX);
939 if (status != STATUS_OK) {
940 ttyut_print("[TTY UT] DCL upper module init failed");
941 } else {
942 DclSerialPort_UpModuleRegisterCb(handle, NULL, NULL, _ttyut_drv_state_cb);
943
944 // Wait for device ready
945 getDrvState.u4OwnerId = owner;
946 do {
947 kal_sleep_task(KAL_TICKS_100_MSEC);
948 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
949 } while ((getDrvState.drv_state != DRV_ST_ATTACHED) || (status != STATUS_OK));
950 }
951 }
952 break;
953
954 default:
955 break;
956 }
957
958 return KAL_TRUE;
959}
960
961static void _tty_ut_conv_tx_conv_rx_rd_handler(DCL_HANDLE handle)
962{
963 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
964 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
965 ttyut_instance_t *ttyut_inst_p;
966
967 ttyut_inst_p = ttyut_get_instance(handle);
968 ur_ctrl_getbytes.u4OwenrId = ttyut_inst_p->owner;
969 ur_ctrl_getbytes.puBuffaddr = ttyut_inst_p->conv_tx_rx_buf + ttyut_inst_p->conv_tx_rx_rd_idx;
970 ur_ctrl_getbytes.u2Length = ttyut_inst_p->conv_tx_rx_wrap
971 ? (ttyut_inst_p->conv_tx_rx_wt_idx - ttyut_inst_p->conv_tx_rx_rd_idx)
972 : (TTY_UT_LB_CON_TX_TX_BUF_SIZE - ttyut_inst_p->conv_tx_rx_rd_idx);
973 if (ur_ctrl_getbytes.u2Length == 0) {
974 return;
975 }
976
977 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes)
978 && ur_ctrl_getbytes.u2RetSize > 0)
979 {
980 ttyut_inst_p->conv_tx_rx_rd_idx += ur_ctrl_getbytes.u2RetSize;
981
982 if (ttyut_inst_p->conv_tx_rx_rd_idx == TTY_UT_LB_CON_TX_TX_BUF_SIZE ) {
983 /* reach the end of buffer, wrap to head */
984 ASSERT(ttyut_inst_p->conv_tx_rx_wrap == 0);
985 ttyut_inst_p->conv_tx_rx_rd_idx = 0;
986 ttyut_inst_p->conv_tx_rx_wrap = 1;
987 }
988
989 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
990 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->conv_tx_rx_buf + ttyut_inst_p->conv_tx_rx_wt_idx;
991 ur_ctrl_putbytes.u2Length = ttyut_inst_p->conv_tx_rx_wrap
992 ? (TTY_UT_LB_CON_TX_TX_BUF_SIZE - ttyut_inst_p->conv_tx_rx_wt_idx)
993 : (ttyut_inst_p->conv_tx_rx_rd_idx - ttyut_inst_p->conv_tx_rx_wt_idx);
994 ASSERT(ur_ctrl_putbytes.u2Length > 0);
995
996 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes)
997 && ur_ctrl_putbytes.u2RetSize > 0)
998 {
999 ttyut_inst_p->conv_tx_rx_wt_idx += ur_ctrl_putbytes.u2RetSize;
1000
1001 if (ttyut_inst_p->conv_tx_rx_wt_idx == TTY_UT_LB_CON_TX_TX_BUF_SIZE ) {
1002 /* reach the end of buffer, de-wrap to head */
1003 ASSERT(ttyut_inst_p->conv_tx_rx_wrap == 1);
1004 ttyut_inst_p->conv_tx_rx_wt_idx = 0;
1005 ttyut_inst_p->conv_tx_rx_wrap = 0;
1006
1007 if (ttyut_inst_p->conv_tx_rx_rd_idx > 0) {
1008 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1009 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->conv_tx_rx_buf;
1010 ur_ctrl_putbytes.u2Length = ttyut_inst_p->conv_tx_rx_rd_idx - ttyut_inst_p->conv_tx_rx_wt_idx;
1011 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes)
1012 && ur_ctrl_putbytes.u2RetSize > 0)
1013 {
1014 ttyut_inst_p->conv_tx_rx_wt_idx += ur_ctrl_putbytes.u2RetSize;
1015 }
1016 }
1017 }
1018 }
1019 }
1020}
1021
1022static void _ttyut_process_ilm(DCL_HANDLE handle, ilm_struct *ilm_ptr, tty_ut_mode_e test_mode)
1023{
1024 ttyut_instance_t *ttyut_inst_p;
1025
1026 ASSERT(ilm_ptr != NULL);
1027
1028 ttyut_inst_p = ttyut_get_instance(handle);
1029
1030 if (ilm_ptr != NULL)
1031 {
1032 switch (ilm_ptr->msg_id)
1033 {
1034 case MSG_ID_UART_READY_TO_WRITE_IND:
1035 {
1036 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
1037
1038 if (test_mode == TTY_UT_CONV_TX_CONV_RX || test_mode == TTY_UT_NEW_INIT_CONV_TX_CONV_RX)
1039 {
1040 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1041 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->conv_tx_rx_buf + ttyut_inst_p->conv_tx_rx_wt_idx;
1042 ur_ctrl_putbytes.u2Length = ttyut_inst_p->conv_tx_rx_wrap
1043 ? (TTY_UT_LB_CON_TX_TX_BUF_SIZE - ttyut_inst_p->conv_tx_rx_wt_idx)
1044 : (ttyut_inst_p->conv_tx_rx_rd_idx - ttyut_inst_p->conv_tx_rx_wt_idx);
1045
1046 if (ur_ctrl_putbytes.u2Length > 0
1047 && STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes)
1048 && ur_ctrl_putbytes.u2RetSize > 0)
1049 {
1050 ttyut_inst_p->conv_tx_rx_wt_idx += ur_ctrl_putbytes.u2RetSize;
1051
1052 if (ttyut_inst_p->conv_tx_rx_wt_idx == TTY_UT_LB_CON_TX_TX_BUF_SIZE ) {
1053 /* reach the end of buffer, de-wrap to head */
1054 ASSERT(ttyut_inst_p->conv_tx_rx_wrap == 1);
1055 ttyut_inst_p->conv_tx_rx_wt_idx = 0;
1056 ttyut_inst_p->conv_tx_rx_wrap = 0;
1057
1058 if (ttyut_inst_p->conv_tx_rx_rd_idx > 0) {
1059 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1060 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->conv_tx_rx_buf;
1061 ur_ctrl_putbytes.u2Length = ttyut_inst_p->conv_tx_rx_rd_idx - ttyut_inst_p->conv_tx_rx_wt_idx;
1062 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes)
1063 && ur_ctrl_putbytes.u2RetSize > 0)
1064 {
1065 ttyut_inst_p->conv_tx_rx_wt_idx += ur_ctrl_putbytes.u2RetSize;
1066 }
1067 }
1068 }
1069 }
1070 } else if (test_mode == TTY_UT_CONV_TX_ONLY || test_mode == TTY_UT_CONV_TX_NEW_RX) {
1071 if (ttyut_inst_p->ttyut_tx_len > 0)
1072 {
1073 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1074 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->ttyut_tx_buf + ttyut_inst_p->ttyut_tx_offset;
1075 ur_ctrl_putbytes.u2Length = ttyut_inst_p->ttyut_tx_len;
1076 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes))
1077 {
1078 ttyut_print("[TTY UT] send %d bytes data\r\n", ur_ctrl_putbytes.u2RetSize);
1079 ttyut_inst_p->ttyut_tx_len -= ur_ctrl_putbytes.u2RetSize;
1080 ttyut_inst_p->ttyut_tx_offset += ur_ctrl_putbytes.u2RetSize;
1081 }
1082 }
1083 }
1084 }
1085 break;
1086 case MSG_ID_UART_READY_TO_READ_IND:
1087 {
1088 UART_CTRL_GET_BYTES_T ur_ctrl_getbytes;
1089 int idx;
1090
1091 switch (test_mode)
1092 {
1093 case TTY_UT_CONV_TX_CONV_RX:
1094 case TTY_UT_NEW_INIT_CONV_TX_CONV_RX:
1095 {
1096 _tty_ut_conv_tx_conv_rx_rd_handler(handle);
1097 }
1098 break;
1099 case TTY_UT_NEW_TX_CONV_RX:
1100 {
1101 ur_ctrl_getbytes.u4OwenrId = ttyut_inst_p->owner;
1102 ur_ctrl_getbytes.puBuffaddr = ttyut_inst_p->ttyut_rx_buf;
1103 ur_ctrl_getbytes.u2Length = QBM_TTY_XXX_DATA_LEN;
1104
1105 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes)
1106 && ur_ctrl_getbytes.u2RetSize > 0)
1107 {
1108 void *tx_gpd;
1109 tty_io_request_t *tx_ior;
1110 unsigned char *tx_buf_ptr;
1111
1112 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
1113 if (tx_gpd) {
1114 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
1115 tx_ior->next_request = NULL;
1116 tx_ior->first_gpd = tx_gpd;
1117 tx_ior->last_gpd = tx_gpd;
1118
1119 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
1120 kal_mem_cpy((void*)tx_buf_ptr, ur_ctrl_getbytes.puBuffaddr, ur_ctrl_getbytes.u2RetSize);
1121 QBM_DES_SET_DATALEN(tx_gpd, ur_ctrl_getbytes.u2RetSize); // Set data length
1122 QBM_DES_SET_HWO(tx_gpd);
1123 qbm_cal_set_checksum(tx_gpd);
1124 //QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
1125
1126 ttyut_print("[TTY UT] Receive data and re-send to Host, len=%d\r\n", ur_ctrl_getbytes.u2RetSize);
1127 DclSerialPort_UpModuleTransmit(handle, tx_ior);
1128 } else {
1129 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
1130 ASSERT(tx_gpd);
1131 }
1132 }
1133 }
1134 break;
1135 case TTY_UT_CONV_RX_ONLY:
1136 {
1137 ur_ctrl_getbytes.u4OwenrId = ttyut_inst_p->owner;
1138 ur_ctrl_getbytes.puBuffaddr = ttyut_inst_p->ttyut_rx_buf;
1139 ur_ctrl_getbytes.u2Length = TTY_UT_CONV_BUF_SIZE;
1140
1141 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_GET_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_getbytes)
1142 && ur_ctrl_getbytes.u2RetSize > 0)
1143 {
1144 ttyut_print("[TTY UT] Rx Only Test, len=%d, data: ", ur_ctrl_getbytes.u2RetSize);
1145 for (idx = 0; idx < ur_ctrl_getbytes.u2RetSize; idx ++) {
1146 ttyut_print("%c", ur_ctrl_getbytes.puBuffaddr[idx]);
1147 }
1148 ttyut_print("\r\n");
1149 }
1150 }
1151 break;
1152 default:
1153 break;
1154 }
1155 }
1156 break;
1157 default:
1158 break;
1159 }
1160 }
1161}
1162
1163static void ttyut_test(tty_ut_mode_e test_mode, kal_uint8 uart_port)
1164{
1165 ilm_struct current_ilm = {0};
1166 DCL_HANDLE handle;
1167 ttyut_instance_t *ttyut_inst_p;
1168 UART_CTRL_GET_DRV_STATE_T getDrvState;
1169 DCL_UINT32 owner = MOD_NIL;
1170 DCL_STATUS status;
1171
1172 handle = DclSerialPort_Open(uart_port, 0);
1173 ttyut_inst_p = ttyut_get_instance(handle);
1174 ASSERT(ttyut_inst_p);
1175
1176 // Wait for device ready
1177 if (TTY_UT_COM1 == uart_port) {
1178 owner = MOD_TTY_UT;
1179 } else if (TTY_UT_COM2 == uart_port) {
1180 owner = MOD_TTY_UT2;
1181 } else if (TTY_UT_COM3 == uart_port) {
1182 owner = MOD_TTY_UT3;
1183 } else {
1184 // Unsupported mode, ASSERT.
1185 ASSERT(0);
1186 }
1187 getDrvState.u4OwnerId = owner;
1188 do {
1189 kal_sleep_task(KAL_TICKS_100_MSEC);
1190 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
1191 } while ((getDrvState.drv_state != DRV_ST_ATTACHED) || (status != STATUS_OK));
1192
1193
1194 switch (test_mode)
1195 {
1196 case TTY_UT_BYPASS:
1197 {
1198 while(1)
1199 {
1200 //do nothing;
1201 kal_sleep_task(KAL_TICKS_1_MIN);
1202 }
1203 }
1204 case TTY_UT_CONV_TX_CONV_RX:
1205 ttyut_print("[TTY UT] loopback Test of conventional Tx and conventional Rx - in Old init procedure\r\n");
1206 {
1207 while (1)
1208 {
1209 while (msg_get_extq_messages() > 0)
1210 {
1211 if (msg_receive_extq(&current_ilm) == KAL_TRUE)
1212 {
1213 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1214 destroy_ilm(&current_ilm);
1215 }
1216 }
1217
1218 /* Polling Read */
1219 kal_sleep_task(KAL_TICKS_10_MSEC/10);
1220 _tty_ut_conv_tx_conv_rx_rd_handler(handle);
1221 }
1222 }
1223 break;
1224
1225 case TTY_UT_NEW_INIT_CONV_TX_CONV_RX:
1226 ttyut_print("[TTY UT] loopback Test of conventional Tx and conventional Rx - in New init procedure\r\n");
1227 {
1228 while (1)
1229 {
1230 while (msg_get_extq_messages() > 0)
1231 {
1232 if (msg_receive_extq(&current_ilm) == KAL_TRUE)
1233 {
1234 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1235 destroy_ilm(&current_ilm);
1236 }
1237 }
1238
1239 /* Polling Read */
1240 kal_sleep_task(KAL_TICKS_10_MSEC/10);
1241 _tty_ut_conv_tx_conv_rx_rd_handler(handle);
1242 }
1243 }
1244 break;
1245
1246 case TTY_UT_NEW_TX_CONV_RX:
1247 ttyut_print("[TTY UT] loopback Test of new Tx and conventional Rx\r\n");
1248 {
1249 while (1)
1250 {
1251 if (msg_receive_extq(&current_ilm) == KAL_TRUE)
1252 {
1253 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1254 destroy_ilm(&current_ilm);
1255 }
1256 }
1257 }
1258 break;
1259
1260 case TTY_UT_CONV_RX_ONLY:
1261 ttyut_print("[TTY UT] conventional Rx Only Test\r\n");
1262 {
1263 while (1)
1264 {
1265 if (msg_receive_extq(&current_ilm) == KAL_TRUE)
1266 {
1267 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1268 destroy_ilm(&current_ilm);
1269 }
1270 }
1271 }
1272 break;
1273
1274 case TTY_UT_NEW_RX_ONLY:
1275 ttyut_print("[TTY UT] new Rx Only Test\r\n");
1276 {
1277 while (1)
1278 {
1279 tty_io_request_t *rx_ior;
1280 unsigned char *rx_buf_ptr;
1281 int rx_buf_len;
1282 int idx;
1283
1284 kal_take_mutex(ttyut_inst_p->ttyut_mutex);
1285
1286 if (ttyut_inst_p->ttyut_rx_ior) {
1287 rx_ior = ttyut_inst_p->ttyut_rx_ior;
1288 ttyut_inst_p->ttyut_rx_ior = ttyut_inst_p->ttyut_rx_ior->next_request;
1289 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1290 rx_ior->next_request = NULL;
1291
1292 /* Assert if first gpd is not equal to last gpd, unless Clear Rx/Set owner/Close command is requested */
1293 ASSERT(rx_ior->first_gpd == rx_ior->last_gpd);
1294
1295 rx_buf_ptr = QBM_DES_GET_DATAPTR(rx_ior->first_gpd);
1296 rx_buf_len = QBM_DES_GET_DATALEN(rx_ior->first_gpd);
1297 QBM_CACHE_INVALID(rx_buf_ptr, rx_buf_len);
1298
1299 ttyut_print("[TTY UT] Rx Only Test, len=%d, data: ", rx_buf_len);
1300 for (idx = 0; idx < rx_buf_len; idx ++) {
1301 ttyut_print("%c", rx_buf_ptr[idx]);
1302 }
1303 ttyut_print("\r\n");
1304
1305 QBM_DES_SET_HWO(rx_ior->first_gpd);
1306 qbm_cal_set_checksum(rx_ior->first_gpd);
1307 QBM_CACHE_FLUSH(rx_ior->first_gpd, sizeof(qbm_gpd));
1308
1309 /* Re-assign this rx ior to driver for the following receiving */
1310 DclSerialPort_UpModuleAssignRxIor(handle, rx_ior);
1311 } else {
1312 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1313 }
1314
1315 /* TODO: check scheduling/priority issue */
1316 kal_sleep_task(KAL_TICKS_10_MSEC);
1317
1318 /* msg_receive_extq will block, therefore we poll if any message first */
1319 while (msg_get_extq_messages() > 0)
1320 {
1321 if (msg_receive_extq(&current_ilm) != KAL_TRUE)
1322 {
1323 break;
1324 }
1325 destroy_ilm(&current_ilm);
1326 }
1327 }
1328 }
1329 break;
1330 case TTY_UT_CONV_TX_ONLY:
1331 kal_sleep_task(KAL_TICKS_3_SEC);
1332 ttyut_print("[TTY UT] conventional Tx Only Test\r\n");
1333 {
1334 int idx, len;
1335 DCL_STATUS ret_st;
1336
1337 for (idx = 0; idx < TTY_UT_CONV_BUF_SIZE; idx ++) {
1338 ttyut_inst_p->ttyut_tx_buf[idx] = 'a' + idx % ('z'-'a'+1);
1339 }
1340 /* 1st round - 1~2048 bytes in order */
1341 for (len = 1; len <= 2048; len ++) {
1342 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
1343
1344 ttyut_print("[TTY UT] expect send %d bytes data\r\n", len);
1345
1346 ttyut_inst_p->ttyut_tx_offset = 0;
1347 ttyut_inst_p->ttyut_tx_len = len;
1348 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1349 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->ttyut_tx_buf;
1350 ur_ctrl_putbytes.u2Length = len;
1351 ret_st = DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
1352
1353 if (STATUS_OK == ret_st && ur_ctrl_putbytes.u2RetSize > 0) {
1354
1355 ttyut_print("[TTY UT] send %d bytes data\r\n", ur_ctrl_putbytes.u2RetSize);
1356
1357 ttyut_inst_p->ttyut_tx_offset = ur_ctrl_putbytes.u2RetSize;
1358 ttyut_inst_p->ttyut_tx_len -= ur_ctrl_putbytes.u2RetSize;
1359 }
1360
1361 kal_sleep_task(KAL_TICKS_10_MSEC);
1362
1363 /* Polling ttyut_tx_len until all tx buffer are sent */
1364 while (ttyut_inst_p->ttyut_tx_len != 0)
1365 {
1366 kal_sleep_task(KAL_TICKS_10_MSEC/10);
1367
1368 while (msg_get_extq_messages() > 0)
1369 {
1370 if (msg_receive_extq(&current_ilm) != KAL_TRUE) {
1371 break;
1372 } else {
1373 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1374 }
1375 destroy_ilm(&current_ilm);
1376 }
1377 }
1378
1379 }
1380
1381 /* 2nd round - 1~2048 bytes in random size */
1382 while (1)
1383 {
1384 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
1385
1386 len = rand()%TTY_UT_CONV_BUF_SIZE + 1;
1387 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1388 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->ttyut_tx_buf;
1389 ur_ctrl_putbytes.u2Length = len;
1390 ttyut_inst_p->ttyut_tx_offset = 0;
1391 ttyut_inst_p->ttyut_tx_len = len;
1392 ret_st = DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes);
1393
1394 if (STATUS_OK == ret_st && ur_ctrl_putbytes.u2RetSize > 0)
1395 {
1396 ttyut_print("[TTY UT] send %d bytes data\r\n", ur_ctrl_putbytes.u2RetSize);
1397
1398 ttyut_inst_p->ttyut_tx_offset = ur_ctrl_putbytes.u2RetSize;
1399 ttyut_inst_p->ttyut_tx_len -= ur_ctrl_putbytes.u2RetSize;
1400 }
1401
1402 /* Polling ttyut_tx_len until all tx buffer are sent */
1403 while (ttyut_inst_p->ttyut_tx_len != 0)
1404 {
1405 kal_sleep_task(KAL_TICKS_10_MSEC);
1406
1407 while (msg_get_extq_messages() > 0)
1408 {
1409 if (msg_receive_extq(&current_ilm) != KAL_TRUE) {
1410 break;
1411 } else {
1412 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1413 }
1414 destroy_ilm(&current_ilm);
1415 }
1416 }
1417 } /* while */
1418 }
1419
1420 break;
1421 case TTY_UT_NEW_TX_ONLY:
1422 kal_sleep_task(KAL_TICKS_3_SEC);
1423 ttyut_print("[TTY UT] new Tx Only Test\r\n");
1424 {
1425 int idx;
1426 for (idx = 0; idx < TTY_UT_NEW_BUF_SIZE; idx ++) {
1427 ttyut_inst_p->ttyut_tx_buf[idx] = 'a' + idx % ('z'-'a'+1);
1428 }
1429 while (1)
1430 {
1431 void *tx_gpd;
1432 tty_io_request_t *tx_ior;
1433 unsigned char *tx_buf_ptr;
1434
1435 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
1436 if (tx_gpd) {
1437 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
1438 tx_ior->next_request = NULL;
1439 tx_ior->first_gpd = tx_gpd;
1440 tx_ior->last_gpd = tx_gpd;
1441 ttyut_inst_p->ttyut_tx_len = rand()%TTY_UT_NEW_BUF_SIZE + 1;
1442
1443 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
1444 kal_mem_cpy((void*)tx_buf_ptr, ttyut_inst_p->ttyut_tx_buf, ttyut_inst_p->ttyut_tx_len);
1445 QBM_DES_SET_DATALEN(tx_gpd, ttyut_inst_p->ttyut_tx_len); // Set data length
1446 QBM_DES_SET_HWO(tx_gpd);
1447 qbm_cal_set_checksum(tx_gpd);
1448 //QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
1449
1450 ttyut_print("[TTY UT] send %d bytes data\r\n", ttyut_inst_p->ttyut_tx_len);
1451 DclSerialPort_UpModuleTransmit(handle, tx_ior);
1452 } else {
1453 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
1454 }
1455
1456 /* TODO: check scheduling/priority issue */
1457 kal_sleep_task(KAL_TICKS_10_MSEC);
1458
1459 /* msg_receive_extq will block, therefore we poll if any message first */
1460 while (msg_get_extq_messages() > 0)
1461 {
1462 if (msg_receive_extq(&current_ilm) != KAL_TRUE)
1463 {
1464 break;
1465 }
1466 destroy_ilm(&current_ilm);
1467 }
1468 }
1469 }
1470 break;
1471 case TTY_UT_NEW_TX_NEW_RX:
1472 ttyut_print("[TTY UT] loopback Test of new Tx and new Rx\r\n");
1473 {
1474 while (1)
1475 {
1476 void *tx_gpd;
1477 tty_io_request_t *tx_ior;
1478 tty_io_request_t *rx_ior;
1479 unsigned char *tx_buf_ptr;
1480 unsigned char *rx_buf_ptr;
1481 kal_uint16 rx_len;
1482
1483 kal_take_mutex(ttyut_inst_p->ttyut_mutex);
1484
1485 if (ttyut_inst_p->ttyut_rx_ior)
1486 {
1487 rx_ior = ttyut_inst_p->ttyut_rx_ior;
1488 ttyut_inst_p->ttyut_rx_ior = ttyut_inst_p->ttyut_rx_ior->next_request;
1489 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1490 rx_ior->next_request = NULL;
1491
1492 /* Assert if first gpd is not equal to last gpd, unless Clear Rx/Set owner/Close command is requested */
1493 ASSERT(rx_ior->first_gpd == rx_ior->last_gpd);
1494
1495 tx_gpd = QBM_ALLOC_ONE(QBM_TYPE_TTY_TYPE1);
1496 if (tx_gpd) {
1497 tx_ior = (tty_io_request_t*)QBM_DES_GET_SW_CTRL_FIELD(tx_gpd);
1498 tx_ior->next_request = NULL;
1499 tx_ior->first_gpd = tx_gpd;
1500 tx_ior->last_gpd = tx_gpd;
1501
1502 tx_buf_ptr = QBM_DES_GET_DATAPTR(tx_gpd);
1503 rx_buf_ptr = QBM_DES_GET_DATAPTR(rx_ior->first_gpd);
1504 rx_len = QBM_DES_GET_DATALEN(rx_ior->first_gpd);
1505
1506 QBM_CACHE_INVALID(rx_buf_ptr, rx_len);
1507 kal_mem_cpy((void*)tx_buf_ptr, (void*)rx_buf_ptr, rx_len);
1508 QBM_CACHE_FLUSH(tx_buf_ptr, rx_len); // flush tx data
1509
1510 QBM_DES_SET_DATALEN(tx_gpd, rx_len); // Set data length
1511 QBM_DES_SET_HWO(tx_gpd);
1512 qbm_cal_set_checksum(tx_gpd);
1513 QBM_CACHE_FLUSH(tx_gpd, sizeof(qbm_gpd));
1514
1515 ttyut_print("[TTY UT] Receive data and re-send to Host, len=%d\r\n", rx_len);
1516 DclSerialPort_UpModuleTransmitLight(handle, tx_ior);
1517 } else {
1518 ttyut_print("[ERROR] [TTY UT] GPD allocate failed in QBM_TYPE_TTY_TYPE1 type\r\n");
1519 }
1520
1521 QBM_DES_SET_HWO(rx_ior->first_gpd);
1522 qbm_cal_set_checksum(rx_ior->first_gpd);
1523 QBM_CACHE_FLUSH(rx_ior->first_gpd, sizeof(qbm_gpd));
1524
1525 /* Re-assign this rx ior to driver for the following receiving */
1526 DclSerialPort_UpModuleAssignRxIor(handle, rx_ior);
1527 } else {
1528 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1529 }
1530
1531 /* TODO: check scheduling/priority issue */
1532 kal_sleep_task(KAL_TICKS_10_MSEC);
1533
1534 /* msg_receive_extq will block, therefore we poll if any message first */
1535 while (msg_get_extq_messages() > 0)
1536 {
1537 if (msg_receive_extq(&current_ilm) != KAL_TRUE)
1538 {
1539 break;
1540 }
1541 destroy_ilm(&current_ilm);
1542 }
1543 }
1544 }
1545 break;
1546 case TTY_UT_CONV_TX_NEW_RX:
1547 ttyut_print("[TTY UT] loopback Test of conventional Tx and new Rx\r\n");
1548 {
1549 while (1)
1550 {
1551 UART_CTRL_PUT_BYTES_T ur_ctrl_putbytes;
1552 tty_io_request_t *rx_ior;
1553 void *rx_data;
1554 kal_uint16 rx_len;
1555
1556 kal_take_mutex(ttyut_inst_p->ttyut_mutex);
1557
1558 if (ttyut_inst_p->ttyut_rx_ior)
1559 {
1560 rx_ior = ttyut_inst_p->ttyut_rx_ior;
1561 ttyut_inst_p->ttyut_rx_ior = ttyut_inst_p->ttyut_rx_ior->next_request;
1562 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1563 rx_ior->next_request = NULL;
1564
1565 /* Assert if first gpd is not equal to last gpd, unless Clear Rx/Set owner/Close command is requested */
1566 ASSERT(rx_ior->first_gpd == rx_ior->last_gpd);
1567
1568 rx_data = QBM_DES_GET_DATAPTR(rx_ior->first_gpd);
1569 rx_len = QBM_DES_GET_DATALEN(rx_ior->first_gpd);
1570
1571 if (rx_len > 0)
1572 { /* in the test case, only one gpd is used in one ior since we only send 2 gpds to driver and one is for tailing */
1573 QBM_CACHE_INVALID(rx_data, rx_len);
1574 ASSERT(rx_len <= QBM_TTY_XXX_DATA_LEN);
1575 kal_mem_cpy(ttyut_inst_p->ttyut_tx_buf, rx_data, rx_len);
1576 ttyut_inst_p->ttyut_tx_len = rx_len;
1577
1578 ur_ctrl_putbytes.u4OwenrId = ttyut_inst_p->owner;
1579 ur_ctrl_putbytes.puBuffaddr = ttyut_inst_p->ttyut_tx_buf;
1580 ur_ctrl_putbytes.u2Length = ttyut_inst_p->ttyut_tx_len;
1581
1582 if (STATUS_OK == DclSerialPort_Control(handle, SIO_CMD_PUT_BYTES, (DCL_CTRL_DATA_T*) &ur_ctrl_putbytes)
1583 && ur_ctrl_putbytes.u2RetSize < ttyut_inst_p->ttyut_tx_len)
1584 {
1585 ttyut_inst_p->ttyut_tx_offset = ur_ctrl_putbytes.u2RetSize;
1586 ttyut_inst_p->ttyut_tx_len -= ur_ctrl_putbytes.u2RetSize;
1587 }
1588 }
1589
1590 QBM_DES_SET_HWO(rx_ior->first_gpd);
1591 QBM_DES_SET_NEXT(rx_ior->first_gpd, NULL);
1592 qbm_cal_set_checksum(rx_ior->first_gpd);
1593 QBM_CACHE_FLUSH(rx_ior->first_gpd, sizeof(qbm_gpd));
1594
1595 /* Re-assign this rx ior to driver for the following receiving */
1596 DclSerialPort_UpModuleAssignRxIor(handle, rx_ior);
1597 } else {
1598 kal_give_mutex(ttyut_inst_p->ttyut_mutex);
1599 }
1600
1601 /* TODO: check scheduling/priority issue */
1602 kal_sleep_task(KAL_TICKS_10_MSEC);
1603
1604 /* msg_receive_extq will block, therefore we poll if any message first */
1605 while (msg_get_extq_messages() > 0)
1606 {
1607 if (msg_receive_extq(&current_ilm) != KAL_TRUE) {
1608 break;
1609 } else {
1610 _ttyut_process_ilm(handle, &current_ilm, test_mode);
1611 }
1612 destroy_ilm(&current_ilm);
1613 }
1614 }
1615 }
1616 break;
1617 default:
1618 break;
1619 }
1620}
1621
1622
1623// ==========================================================
1624// TTY_UT Task Function
1625// ==========================================================
1626kal_uint32 ttyut_tsk_num=0;
1627kal_spinlockid ttyut_tsk_pri_spl;
1628kal_taskid tty_tsk_pri[TTY_UT_COM_NUM];
1629kal_uint32 ttyut_get_current_task_priority()
1630{
1631 kal_uint32 tty_pri, tty_ist=ttyut_tsk_num;
1632 kal_taskid tskp=kal_get_current_task();
1633 ASSERT(tskp);
1634 kal_take_spinlock(ttyut_tsk_pri_spl, KAL_INFINITE_WAIT);
1635 for(tty_pri=0;tty_pri<ttyut_tsk_num&&tty_tsk_pri[tty_pri]!=tskp;tty_pri++) tty_ist=tty_ist==ttyut_tsk_num&&!tty_tsk_pri[tty_pri]?tty_pri:tty_ist;
1636 if(tty_pri==ttyut_tsk_num&&tty_ist<ttyut_tsk_num) tty_tsk_pri[tty_pri=tty_ist]=tskp;
1637 kal_give_spinlock(ttyut_tsk_pri_spl);
1638 return tty_pri==ttyut_tsk_num?0:tty_pri+1;
1639}
1640
1641kal_bool ttyut_task_init(void)
1642{
1643 if(ttyut_tsk_num==0) ttyut_tsk_pri_spl=kal_create_spinlock("TTYUT_TSK_SPL");
1644 tty_tsk_pri[ttyut_tsk_num++]=NULL;
1645
1646 // Init ttyut instance struct.
1647 kal_mem_set(&ttyut_inst_g, 0, sizeof(ttyut_inst_g));
1648
1649 return KAL_TRUE;
1650}
1651
1652static void ttyut_task_main(task_entry_struct *task_entry_ptr)
1653{
1654 kal_uint32 tsk_pri;
1655 kal_bool ret = KAL_TRUE;
1656
1657 tsk_pri = ttyut_get_current_task_priority();
1658
1659#if TTY_UT_MISC_TEST
1660 DCL_STATUS status;
1661 DCL_HANDLE handle;
1662 UART_CTRL_GET_DRV_STATE_T getDrvState;
1663 /*Init test and change owner test*/
1664 if (TTY_UT_TASK_1_PRIORITY == tsk_pri) {
1665 // Init_deinit test
1666 kal_set_active_module_id(MOD_TTY_UT);
1667
1668 /*Make sure driver is already attached*/
1669 handle = DclSerialPort_Open(TTY_UT_COM1, 0);
1670 getDrvState.u4OwnerId = MOD_TTY_UT;
1671 do {
1672 kal_sleep_task(KAL_TICKS_100_MSEC);
1673 status = DclSerialPort_Control(handle, TTY_CMD_GET_DRV_STATE, (DCL_CTRL_DATA_T*) &getDrvState);
1674 } while ((getDrvState.drv_state != DRV_ST_ATTACHED) || (status != STATUS_OK));
1675
1676 if (_ttyut_upmod_init_deinit_test(TTY_UT_COM1)) {
1677 ttyut_print("[TTY UT] init-deinit test OK\r\n");
1678 } else {
1679 ttyut_print("[TTY UT] init-deinit test failed\r\n");
1680 //return;
1681 ASSERT(0);
1682 }
1683
1684 // Change_owner test
1685 if (_ttyut_upmod_change_owner_test()) {
1686 ttyut_print("[TTY UT] change owner test OK\r\n");
1687 } else {
1688 ttyut_print("[TTY UT] change owner test failed\r\n");
1689 //return;
1690 ASSERT(0);
1691 }
1692 }
1693#endif
1694
1695 /*
1696 * S1.TTYUT_PREPROC.
1697 */
1698 switch (tsk_pri)
1699 {
1700 case TTY_UT_TASK_1_PRIORITY:
1701 kal_set_active_module_id(MOD_TTY_UT);
1702 ret = ttyut_test_preproc(tty_ut_mode_1, TTY_UT_COM1);
1703 break;
1704
1705 case TTY_UT_TASK_2_PRIORITY:
1706 if (TTY_UT_COM_NUM > 1) {
1707 kal_set_active_module_id(MOD_TTY_UT2);
1708 ret = ttyut_test_preproc(tty_ut_mode_2, TTY_UT_COM2);
1709 }
1710 break;
1711
1712 case TTY_UT_TASK_3_PRIORITY:
1713 if (TTY_UT_COM_NUM > 2) {
1714 kal_set_active_module_id(MOD_TTY_UT3);
1715 ret = ttyut_test_preproc(tty_ut_mode_3, TTY_UT_COM3);
1716 }
1717 break;
1718
1719 default:
1720 // Unsupported mode, ASSERT.
1721 ASSERT(0);
1722 break;
1723 }
1724
1725 if (KAL_TRUE == ret) {
1726
1727 } else {
1728 // Failed to ttyut_test_preproc(), ASSERT.
1729 ASSERT(0);
1730 }
1731
1732 /*
1733 * S2. TTYUT_MAIN.
1734 */
1735 switch (tsk_pri)
1736 {
1737 case TTY_UT_TASK_1_PRIORITY:
1738
1739 ttyut_test(tty_ut_mode_1, TTY_UT_COM1);
1740 break;
1741
1742 case TTY_UT_TASK_2_PRIORITY:
1743 if (TTY_UT_COM_NUM > 1) {
1744 ttyut_test(tty_ut_mode_2, TTY_UT_COM2);
1745 }
1746 break;
1747
1748 case TTY_UT_TASK_3_PRIORITY:
1749 if (TTY_UT_COM_NUM > 2) {
1750 ttyut_test(tty_ut_mode_3, TTY_UT_COM3);
1751 }
1752 break;
1753
1754 default:
1755 // Unsupport mode, ASSERT.
1756 ASSERT(0);
1757 break;
1758 }
1759
1760 while (1) {
1761 kal_sleep_task(KAL_TICKS_30_SEC);
1762 }
1763}
1764
1765kal_bool ttyut_create(comptask_handler_struct **handle)
1766{
1767 static const comptask_handler_struct ttyut_handler_info =
1768 {
1769 ttyut_task_main, /* task entry function */
1770 ttyut_task_init, /* task initialization function */
1771 NULL /* task reset handler */
1772 };
1773
1774 ttyut_print("=========>ttyut_create\r\n");
1775
1776 *handle = (comptask_handler_struct *)&ttyut_handler_info;
1777 return KAL_TRUE;
1778}
1779