1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
/*
* Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
//#include "console.h"
#include "sdmmc/sys/sys_debug.h"
#include "cmd/cmd_util.h"
#include "cmd/cmd_sd.h"
#include "sdmmc/hal/hal_def.h"
#include "sdmmc/hal_sdhost.h"
#include "sdmmc/sdmmc.h"
//#include "FreeRTOS_CLI.h"
static struct mmc_card *card;
extern int32_t mmc_test(uint32_t host_id, uint32_t cd_mode, uint32_t sdc_degmask, uint32_t card_dbgmask);
extern int32_t mmc_test_init(uint32_t host_id, SDC_InitTypeDef *sdc_param, uint32_t scan);
extern int32_t mmc_test_exit(uint16_t sd_id, uint16_t host_id);
extern struct mmc_card *mmc_scan_init(uint16_t sd_id, uint16_t sdc_id, SDCard_InitTypeDef *card_param);
/* drv sd init [<card_id> <debug_mask>]
* eg:
* 1. drv sd init
* 2. drv sd init 0 0x7f
*/
static enum cmd_status cmd_sd_init_exec(char *cmd)
{
uint32_t cnt;
uint32_t card_id, debug_mask;
SDC_InitTypeDef sdc_param = { 0 };
cnt = cmd_sscanf(cmd, "%u 0x%x", HAL_PR_SZ_P(&card_id), HAL_PR_SZ_P(&debug_mask));
if (cnt != 2) {
mmc_test_init(0, NULL, 0);
} else {
sdc_param.cd_mode = CARD_ALWAYS_PRESENT;
sdc_param.debug_mask = debug_mask;
mmc_test_init(card_id, &sdc_param, 0);
}
return CMD_STATUS_OK;
}
/* drv sd scan [<card_id> <host_id> <card_type> <debug_mask>]
* eg:
* 1. drv sd scan
* 2. drv sd scan 0 0 2 0x7f
*/
static enum cmd_status cmd_sd_scan_exec(char *cmd)
{
uint32_t cnt;
uint32_t card_id, host_id, type, debug_mask;
SDCard_InitTypeDef card_param = { 0 };
cnt = cmd_sscanf(cmd, "%u %u %u 0x%x", HAL_PR_SZ_P(&card_id), HAL_PR_SZ_P(&host_id), HAL_PR_SZ_P(&type), HAL_PR_SZ_P(&debug_mask));
if (cnt != 4) {
card = mmc_scan_init(0, 0, NULL);
} else {
card_param.debug_mask = debug_mask;
card_param.type = type;
card = mmc_scan_init(card_id, host_id, &card_param);
}
if (!card) {
CMD_ERR("scan card failed!\n");
return CMD_STATUS_OK;;
}
return CMD_STATUS_OK;
}
/*
* drv sd read s=<Start_Sector> n=<sector_num>
*/
static enum cmd_status cmd_sd_read_exec(char *cmd)
{
int32_t err;
uint32_t cnt;
uint32_t start_sector, r_secnum;
char *buf;
cnt = cmd_sscanf(cmd, "s=%u n=%u", HAL_PR_SZ_P(&start_sector), HAL_PR_SZ_P(&r_secnum));
if (cnt != 2) {
CMD_ERR("invalid argument %s\n", cmd);
return CMD_STATUS_FAIL;
}
buf = cmd_malloc(r_secnum*512);
if (!buf)
return CMD_STATUS_OK;;
err = mmc_block_read(card, (uint8_t *)buf, start_sector, r_secnum);
if (err) {
CMD_ERR("mmc mult blocks read err!\n");
return CMD_STATUS_FAIL;
}
CMD_DBG("read from %d sector, %d sectors\n", (unsigned int)start_sector, (unsigned int)r_secnum);
print_hex_dump_bytes(buf, r_secnum*512);
return CMD_STATUS_OK;
}
/*
* eg:
* 1. drv sd test
* 2. drv sd test 0 3 0x3c 0x3c
* 3. drv sd test 0 2 0x3c 0x3c
*/
//static enum cmd_status cmd_sd_test_exec(char *cmd)
enum cmd_status cmd_sd_test_exec(char *cmd)
{
uint32_t cnt = 0;
uint32_t host_id = 0, cd_mode = 0, sdc_degmask = 0, card_dbgmask = 0;
// cnt = cmd_sscanf(cmd, "%d %d 0x%x 0x%x", &host_id, &cd_mode, &sdc_degmask, &card_dbgmask);
if (cnt != 4) {
CMD_DBG("use defaule argument %s\n", cmd);
host_id = 0;
cd_mode = CARD_ALWAYS_PRESENT;
/*
sdc_degmask = (ROM_DUMP_MASK | ROM_DBG_MASK | ROM_INF_MASK | \
ROM_WRN_MASK | ROM_ERR_MASK | ROM_ANY_MASK);
card_dbgmask = (ROM_DUMP_MASK | ROM_DBG_MASK | ROM_INF_MASK | \
ROM_WRN_MASK | ROM_ERR_MASK | ROM_ANY_MASK);
*/
sdc_degmask = (ROM_INF_MASK | \
ROM_WRN_MASK | ROM_ERR_MASK | ROM_ANY_MASK);
card_dbgmask = ( ROM_INF_MASK | \
ROM_WRN_MASK | ROM_ERR_MASK | ROM_ANY_MASK);
}
mmc_test(host_id, cd_mode, sdc_degmask, card_dbgmask);
/*
{
sdio_claim_irq(NULL,NULL);
sdio_release_irq(NULL);
sdio_readw(NULL,NULL,NULL);
sdio_readl(NULL,NULL,NULL);
sdio_writel(NULL,NULL,NULL,NULL);
sdio_writew(NULL,NULL,NULL,NULL);
}
*/
return CMD_STATUS_OK;
}
/*
* drv sd deinit [<card_id> <host_id>]
* eg.
* 1. sd deinit
* 2. sd deinit 0 0
*/
static enum cmd_status cmd_sd_deinit_exec(char *cmd)
{
uint32_t cnt;
uint32_t card_id, host_id;
cnt = cmd_sscanf(cmd, "%u %u", HAL_PR_SZ_P(&card_id), HAL_PR_SZ_P(&host_id));
if (cnt != 2) {
card_id = 0;
host_id = 0;
}
mmc_test_exit(card_id, host_id);
return CMD_STATUS_OK;
}
#define CMD_ARG_LEN 64
struct sd_test_param {
uint8_t task_idx;
uint8_t random;
uint8_t task_num;
uint8_t card_dma_use;
uint16_t time_sec;
uint16_t host_debug_mask;
uint16_t card_debug_mask;
uint32_t start_sector;
uint32_t sector_num;
};
static void cmd_sd_bench_task(void *arg)
{
int32_t err;
char *cmd = (char *)arg;
uint32_t start_sector;
uint32_t cnt;
uint32_t throuth_mb, throuth_kb;
OS_Time_t tick_use;
uint32_t bench_sector;
cnt = cmd_sscanf(cmd, "s=%u", HAL_PR_SZ_P(&start_sector));
if (cnt != 1) {
CMD_ERR("invalid argument %s\n", cmd);
goto out;
}
mmc_test_init(0, NULL, 1);
card = mmc_card_open(0);
if (!card) {
CMD_ERR("card open failed!\n");
goto out;
}
bench_sector = start_sector - 1;
for (int i = 0; i < sizeof(unsigned int)*8 - 10; i++) {
unsigned int bench_size = 512 * (1 << i);
uint8_t *buf = cmd_malloc(bench_size);
if (!buf) {
CMD_DBG("%s test end for malloc buff failed!\n", __func__);
goto out;
}
for (int j = 0; j < bench_size/4; j++)
((unsigned int *)buf)[j] = j;
bench_sector += bench_size/512;
tick_use = OS_GetTicks();
err = mmc_block_write(card, buf, bench_sector, bench_size/512);
tick_use = OS_GetTicks() - tick_use;
if (!tick_use)
tick_use = 1;
if (err) {
CMD_ERR("mmc mult blocks write err!\n");
goto next;
} else {
throuth_kb = bench_size*1000/1024/(uint32_t)OS_TicksToMSecs(tick_use);
throuth_mb = throuth_kb/1000;
CMD_DBG("%s mult blocks write ok, ", __func__);
if (bench_size <= 512)
CMD_LOG(CMD_DBG_ON, "0.5");
else
CMD_LOG(CMD_DBG_ON, "%3d", (unsigned int)bench_size/1024);
CMD_LOG(CMD_DBG_ON, " KB use:%3d ms, throughput:%d.%d MB/S\n",
(unsigned int)OS_TicksToMSecs(tick_use),
(unsigned int)throuth_mb,(unsigned int)(throuth_kb - throuth_mb));
}
for (int j = 0; j < bench_size/4; j++)
((unsigned int *)buf)[j] = 0;
tick_use = OS_GetTicks();
err = mmc_block_read(card, buf, bench_sector, bench_size/512);
tick_use = OS_GetTicks() - tick_use;
if (!tick_use)
tick_use = 1;
if (err) {
CMD_ERR("mmc mult blocks read err!\n");
goto next;
} else {
throuth_kb = bench_size*1000/1024/(uint32_t)OS_TicksToMSecs(tick_use);
throuth_mb = throuth_kb/1000;
CMD_DBG("%s mult blocks read ok, ", __func__);
if (bench_size <= 512)
CMD_LOG(CMD_DBG_ON, "0.5");
else
CMD_LOG(CMD_DBG_ON, "%3d", bench_size/1024);
CMD_LOG(CMD_DBG_ON, " KB use:%3d ms, throughput:%d.%d MB/S\n",
(unsigned int)OS_TicksToMSecs(tick_use),
(unsigned int)throuth_mb, (unsigned int)(throuth_kb - throuth_mb));
}
err = 0;
for (int j = 0; j < bench_size/4; j++) {
if (((unsigned int *)buf)[j] != j) {
err = -1;
break;
}
}
if (err) {
CMD_ERR("mmc %d blocks write data err!\n", (unsigned int)bench_size/512);
goto next;
}
next:
cmd_free(buf);
if (err)
break;
}
mmc_card_close(0);
out:
CMD_DBG("%s test end\n", __func__);
mmc_test_exit(card->id, 0);
cmd_free(arg);
OS_ThreadDelete(NULL);
}
#define PRESS_FILE_SIZE (20 * 1024 * 1024) /* 20M */
#define PRESS_READ_SIZE 2048
#define PRESS_WRITE_SIZE 8192
static OS_Semaphore_t sem_wait;
static void cmd_sd_press_read_task(void *arg)
{
int32_t err;
struct sd_test_param *param = (struct sd_test_param *)arg;
OS_Time_t tick_now = 0, tick_print = 0;
OS_Time_t tick_end = OS_GetTicks() + OS_MSecsToTicks(param->time_sec * 1000);
uint32_t random_sleep = param->random;
char *buf;
uint32_t start_sector = param->start_sector;
card = mmc_card_open(0);
if (!card) {
CMD_ERR("card open failed!\n");
goto fail;
}
if (param->task_idx == 0) {
buf = cmd_malloc(4096);
for (int i = 0; i < 512/4; i++) {
((unsigned int *)buf)[i] = i;
}
memcpy(buf+512, buf, 512);
memcpy(buf+1024, buf, 1024);
memcpy(buf+2048, buf, 2048);
CMD_DBG("%s do nothing until sd card prepare ok!\n", __func__);
for (int i = 0; i < (PRESS_FILE_SIZE+4095)/4096; i++) { /* 10M */
int32_t err;
err = mmc_block_write(card, (uint8_t *)buf, start_sector + (i*(4096/512)), 4096/512);
if (err)
goto out;
}
CMD_DBG("%s sd card prepared ok!\n", __func__);
for (int j = 0; j < param->task_num - 1; j++)
OS_SemaphoreRelease(&sem_wait);
cmd_free(buf);
} else {
OS_SemaphoreWait(&sem_wait, OS_WAIT_FOREVER);
}
buf = cmd_malloc(param->sector_num*512);
if (!buf)
goto exit;
if (!random_sleep)
random_sleep = 2;
OS_MSleep(random_sleep);
CMD_DBG("%s id:%d random:%d start_sector:%d\n", __func__, (unsigned int)param->task_idx,
(unsigned int)random_sleep, (unsigned int)start_sector);
while (tick_now < tick_end) {
int j;
err = mmc_block_read(card, (uint8_t *)buf, start_sector, param->sector_num);
if (err) {
CMD_ERR("mmc mult blocks read err!\n");
goto out;
}
err = 0;
for (j = 0; j < param->sector_num*(512/4); j++) {
if (((unsigned int *)buf)[j] != (j & 0x07f)) {
err = -1;
CMD_ERR("%x %x\n", j, ((unsigned int *)buf)[j]);
break;
}
}
if (err) {
CMD_ERR("mmc %d blocks read data err! at sector:%d count:%d\n",
(unsigned int)param->sector_num, (unsigned int)start_sector, j);
goto out;
} else
CMD_DBG("%s mmc blocks read data ok! at sector:%u\n",
__func__, HAL_PR_SZ(start_sector));
start_sector += param->sector_num;
if (start_sector >= param->start_sector + PRESS_FILE_SIZE/512) {
start_sector = param->start_sector;
}
OS_MSleep(random_sleep);
tick_now = OS_GetTicks();
if (tick_now >= tick_print + 5000) {
CMD_DBG("%s id:%d testing... at sector:%d\n", __func__,
(unsigned int)param->task_idx, (unsigned int)start_sector);
tick_print = tick_now;
}
}
out:
CMD_DBG("%s id:%d test end\n", __func__, (unsigned int)param->task_idx);
cmd_free(buf);
exit:
mmc_card_close(0);
fail:
cmd_free(param);
if (param->task_idx == 0)
OS_SemaphoreDelete(&sem_wait);
OS_ThreadDelete(NULL);
}
static void cmd_sd_press_write_task(void *arg)
{
int32_t err;
struct sd_test_param *param = (struct sd_test_param *)arg;
OS_Time_t tick_now = 0, tick_print = 0;
OS_Time_t tick_end = OS_GetTicks() + OS_MSecsToTicks(param->time_sec * 1000);
uint32_t random_sleep = param->random;
char *buf;
uint32_t start_sector = param->start_sector;
uint32_t round = 0;
uint32_t total_num;
card = mmc_card_open(0);
if (!card) {
CMD_ERR("card open failed!\n");
goto fail;
}
buf = cmd_malloc(param->sector_num*512);
if (!buf)
goto out;
for (int i = 0; i < 512/4; i++)
((unsigned int *)buf)[i] = i;
for (int i = 1; i < param->sector_num; i++)
memcpy(buf + i * 512, buf, 512);
if (!random_sleep)
random_sleep = 2;
OS_MSleep(random_sleep);
CMD_DBG("%s id:%d random:%d\n", __func__, (unsigned int)param->task_idx, (unsigned int)random_sleep);
while (tick_now < tick_end) {
err = mmc_block_write(card, (uint8_t *)buf, start_sector, param->sector_num);
if (err) {
CMD_ERR("mmc mult blocks write err!\n");
goto out;
}
start_sector += param->sector_num;
if (start_sector >= param->start_sector + PRESS_FILE_SIZE/512) {
start_sector = param->start_sector;
round = 1;
}
OS_MSleep(random_sleep);
tick_now = OS_GetTicks();
if (tick_now >= tick_print + 5000) {
CMD_DBG("%s id:%d testing... at sector:%d\n", __func__,
(unsigned int)param->task_idx, (unsigned int)start_sector);
tick_print = tick_now;
}
}
CMD_DBG("%s test end. round:%d start_sector:%d end_sector:%d\n", __func__,
(unsigned int)round, (unsigned int)param->start_sector, (unsigned int)start_sector);
if (round) {
total_num = PRESS_FILE_SIZE/512;
} else {
// BUG_ON(start_sector <= param->start_sector);
total_num = start_sector - param->start_sector;
}
total_num /= param->sector_num;
start_sector = param->start_sector;
CMD_DBG("%s test checking... start_sector:%d total_num:%d\n", __func__,
(unsigned int)start_sector, (unsigned int)total_num);
for (int i = 0; i < total_num; i++) {
int j;
memset(buf, 0, param->sector_num*512);
err = mmc_block_read(card, (uint8_t *)buf, start_sector, param->sector_num);
if (err) {
CMD_ERR("mmc mult blocks read err!\n");
goto out;
}
err = 0;
for (j = 0; j < param->sector_num*(512/4); j++) {
if (((unsigned int *)buf)[j] != (j & 0x07f)) {
err = -1;
break;
}
}
if (err) {
CMD_ERR("%x %x\n", ((unsigned int *)buf)[j], (j & 0x07f));
CMD_ERR("mmc %d blocks write data err! at sector:%d count:%d\n",
(unsigned int)param->sector_num, (unsigned int)start_sector, j);
goto out;
} else
CMD_DBG("%s mmc blocks write data ok! at sector:%u\n",
__func__, HAL_PR_SZ(start_sector));
start_sector += param->sector_num;
}
out:
mmc_card_close(0);
CMD_DBG("%s id:%d test end\n", __func__, (unsigned int)param->task_idx);
cmd_free(buf);
fail:
cmd_free(param);
OS_ThreadDelete(NULL);
}
/*
* drv sd bench s=<Start_Sector>
*/
static enum cmd_status cmd_sd_bench_exec(char *cmd)
{
OS_Thread_t thread;
char *param;
uint32_t len;
len = strlen(cmd);
if (len >= CMD_ARG_LEN) {
CMD_ERR("should adjust CMD_ARG_LEN to %d\n", (unsigned int)len);
return CMD_STATUS_FAIL;
}
param = cmd_malloc(CMD_ARG_LEN);
if (!param)
return CMD_STATUS_FAIL;
memcpy(param, cmd, len);
param[len+1] = 0;
OS_ThreadSetInvalid(&thread);
if (OS_ThreadCreate(&thread,
"",
cmd_sd_bench_task,
param,
OS_THREAD_PRIO_APP,
2 * 1024) != OS_OK) {
CMD_ERR("create sd bench test task failed\n");
return CMD_STATUS_FAIL;
}
return CMD_STATUS_OK;
}
/*
* drv sd press r=<threads_num> s=<Start_Sector> n=<sector_num> w=<threads_num>
* s=<Start_Sector> n=<sector_num> t=<secons>
* eg:
* drv sd press r=2 s=200000 n=20 w=2 s=400000 n=20 t=600
*/
static enum cmd_status cmd_sd_press_exec(char *cmd)
{
OS_Thread_t thread;
struct sd_test_param *param;
uint32_t r_threads, w_threads;
uint32_t r_secnum, w_secnum;
uint32_t cnt;
uint32_t time_sec;
uint32_t start_rsector, start_wsector;
cnt = cmd_sscanf(cmd, "r=%u s=%u n=%u w=%u s=%u n=%d t=%u",
HAL_PR_SZ_P(&r_threads), HAL_PR_SZ_P(&start_rsector), HAL_PR_SZ_P(&r_secnum),
HAL_PR_SZ_P(&w_threads), HAL_PR_SZ_P(&start_wsector), HAL_PR_SZ_P(&w_secnum), HAL_PR_SZ_P(&time_sec));
if (cnt != 7) {
CMD_ERR("invalid argument %s\n", cmd);
return CMD_STATUS_FAIL;
}
OS_SemaphoreCreate(&sem_wait, 0, OS_SEMAPHORE_MAX_COUNT);
OS_MSleep(5);
for (uint32_t i = 0; i < r_threads; i++) {
param = cmd_malloc(sizeof(struct sd_test_param));
if (!param)
return CMD_STATUS_FAIL;
param->task_idx = i;
param->task_num = r_threads;
param->start_sector = start_rsector;
param->sector_num = r_secnum;
param->time_sec = time_sec;
param->random = rand() % 8 + i;
if (!r_secnum || time_sec < 2) {
CMD_ERR("%s read n=<sector_num> should not 0 !\n", __func__);
cmd_free(param);
goto out;
}
OS_ThreadSetInvalid(&thread);
if (OS_ThreadCreate(&thread,
"",
cmd_sd_press_read_task,
param,
OS_THREAD_PRIO_APP,
2 * 1024) != OS_OK) {
CMD_ERR("create sd press read task:%d failed\n", (unsigned int)i);
return CMD_STATUS_FAIL;
}
(void)cmd_sd_press_read_task;
OS_MSleep(2);
}
for (uint32_t i = 0; i < w_threads; i++) {
param = cmd_malloc(sizeof(struct sd_test_param));
if (!param)
return CMD_STATUS_FAIL;
param->task_idx = i;
param->task_num = w_threads;
param->start_sector = start_wsector;
param->sector_num = w_secnum;
param->time_sec = time_sec;
param->random = rand() % 20 + i;
if (!w_secnum || time_sec < 2) {
CMD_ERR("%s write n=<sector_num> should not 0 !\n", __func__);
cmd_free(param);
goto out;
}
OS_ThreadSetInvalid(&thread);
if (OS_ThreadCreate(&thread,
"",
cmd_sd_press_write_task,
param,
OS_THREAD_PRIO_APP,
2 * 1024) != OS_OK) {
CMD_ERR("create sd press write task:%d failed\n", (unsigned int)i);
return CMD_STATUS_FAIL;
}
OS_MSleep(2);
}
out:
return CMD_STATUS_OK;
}
static const struct cmd_data g_sd_cmds[] = {
{ "init", cmd_sd_init_exec },
{ "deinit", cmd_sd_deinit_exec },
{ "scan", cmd_sd_scan_exec },
{ "read", cmd_sd_read_exec },
{ "test", cmd_sd_test_exec },
{ "bench", cmd_sd_bench_exec },
{ "press", cmd_sd_press_exec },
};
#if 0
static portBASE_TYPE prvSdmmcTestCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *const pcHeader = "sdmmc test\r\n";
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Generate a table of task stats. */
strcpy( pcWriteBuffer, pcHeader );
vTaskList( pcWriteBuffer + strlen( pcHeader ) );
{
//static enum cmd_status cmd_sd_test_exec(char *cmd);
printf("%s,%d\r\n",__FUNCTION__, __LINE__ );
cmd_sd_test_exec(NULL);
}
/* There is no more data to return after this single string, so return
pdFALSE. */
return pdFALSE;
}
static const CLI_Command_Definition_t xSdmmcTest =
{
"sdmmc-test", /* The command string to type. */
"\r\nsdmmc-test:\r\n test sdmmc drivers\r\n",
prvSdmmcTestCommand, /* The function to run. */
0 /* No parameters are expected. */
};
void xSdmmc_regcmd(void)
{
FreeRTOS_CLIRegisterCommand( &xSdmmcTest );
}
#endif
/*
enum cmd_status cmd_sd_exec(char *cmd)
{
return cmd_exec(cmd, g_sd_cmds, cmd_nitems(g_sd_cmds));
}
*/
int cmd_sdmmc_sample(int argc, char ** argv)
{
int i = 0;
while(argc--)
{
printf("argv[%d] = %s\n", i, argv[i]);
i++;
}
cmd_sd_test_exec(NULL);
return 0;
}
FINSH_FUNCTION_EXPORT_CMD(cmd_sdmmc_sample, sdmmctest, SdmmcTestCommand);
|