IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2011-01-19 16:24:20 (10 years 3 days ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 999ce5302eacd84742dc11202bbebba848682caa |
Message: | atrf-txrx: added BER test pattern transmit mode - atrf-txrx.c (main): indicate mode of operation in variable "mode" instead of dual-using "cont_tx" - atrf-txrx.c (usage, main): added option -B to enter BER test pattern transit mode - atrf-txrx.c (transmit_pattern): transmit raw frames with a cyclic frame number |
Files: |
tools/atrf-txrx/atrf-txrx.c (9 diffs) |
Change Details
tools/atrf-txrx/atrf-txrx.c | ||
---|---|---|
374 | 374 | } |
375 | 375 | |
376 | 376 | |
377 | static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times) | |
378 | { | |
379 | uint8_t buf[MAX_PSDU]; | |
380 | uint8_t n = 0; | |
381 | int us = fmod(pause_s, 1)*1000000; | |
382 | ||
383 | atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); | |
384 | /* | |
385 | * 180 us, according to AVR2001 section 4.3. We time out after | |
386 | * nominally 200 us. | |
387 | */ | |
388 | wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20); | |
389 | ||
390 | while (run) { | |
391 | memset(buf, n, sizeof(buf)); | |
392 | atrf_buf_write(dsc, buf, sizeof(buf)); | |
393 | ||
394 | atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); | |
395 | ||
396 | /* wait up to 10 ms (nominally) */ | |
397 | wait_for_interrupt(dsc, IRQ_TRX_END, | |
398 | IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000); | |
399 | ||
400 | if (pause_s >= 1) | |
401 | sleep(pause_s); | |
402 | if (us) | |
403 | usleep(us); | |
404 | ||
405 | if (times && !--times) | |
406 | break; | |
407 | n++; | |
408 | } | |
409 | } | |
410 | ||
377 | 411 | |
378 | 412 | static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd) |
379 | 413 | { |
... | ... | |
416 | 450 | { |
417 | 451 | fprintf(stderr, |
418 | 452 | "usage: %s [common_options] [message [repetitions]]\n" |
453 | " %s [common_options] -B pause_s [repetitions]\n" | |
419 | 454 | " %s [common_options] -T offset [command]\n\n" |
420 | 455 | " text message mode:\n" |
421 | 456 | " message message string to send (if absent, receive)\n" |
422 | 457 | " repetitions number of times the message is sent (default 1)\n\n" |
458 | " BER test mode (transmit only):\n" | |
459 | " -B pause_s seconds to pause between frames (floating-point)\n" | |
460 | " repetitions number of messages to send (default: infinite)\n\n" | |
423 | 461 | " constant wave test mode (transmit only):\n" |
424 | 462 | " -T offset test mode. offset is the frequency offset of the constant\n" |
425 | 463 | " wave in MHz: -2, -0.5, or +0.5\n" |
... | ... | |
433 | 471 | " -o file write received data to a file in pcap format\n" |
434 | 472 | " -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n" |
435 | 473 | " -t trim trim capacitor, 0 to 15 (default 0)\n" |
436 | , name, name, DEFAULT_CHANNEL, 2405+5*(DEFAULT_CHANNEL-11), | |
474 | , name, name, name, DEFAULT_CHANNEL, 2405+5*(DEFAULT_CHANNEL-11), | |
437 | 475 | DEFAULT_POWER); |
438 | 476 | exit(1); |
439 | 477 | } |
... | ... | |
441 | 479 | |
442 | 480 | int main(int argc, char *const *argv) |
443 | 481 | { |
482 | enum { | |
483 | mode_msg, | |
484 | mode_ber, | |
485 | mode_cont_tx, | |
486 | } mode = mode_msg; | |
444 | 487 | int channel = DEFAULT_CHANNEL; |
445 | 488 | double power = DEFAULT_POWER; |
446 | 489 | int trim = 0, times = 1; |
447 | 490 | uint8_t cont_tx = 0; |
491 | double pause_s = 0; | |
448 | 492 | char *end; |
449 | 493 | int c, freq; |
450 | 494 | unsigned tmp, clkm = 0; |
... | ... | |
452 | 496 | const char *pcap_file = NULL; |
453 | 497 | struct atrf_dsc *dsc; |
454 | 498 | |
455 | while ((c = getopt(argc, argv, "c:C:f:o:p:t:T:")) != EOF) | |
499 | while ((c = getopt(argc, argv, "B:c:C:f:o:p:t:T:")) != EOF) | |
456 | 500 | switch (c) { |
457 | 501 | case 'c': |
458 | 502 | channel = strtoul(optarg, &end, 0); |
... | ... | |
486 | 530 | if (trim > 15) |
487 | 531 | usage(*argv); |
488 | 532 | break; |
533 | case 'B': | |
534 | mode = mode_ber; | |
535 | pause_s = strtof(optarg, &end); | |
536 | if (*end) | |
537 | usage(*argv); | |
538 | break; | |
489 | 539 | case 'C': |
490 | 540 | tmp = strtol(optarg, &end, 0); |
491 | 541 | if (*end) |
... | ... | |
498 | 548 | usage(*argv); |
499 | 549 | break; |
500 | 550 | case 'T': |
551 | mode = mode_cont_tx; | |
501 | 552 | if (!strcmp(optarg, "-2")) |
502 | 553 | cont_tx = CONT_TX_M2M; |
503 | 554 | else if (!strcmp(optarg, "-0.5")) |
... | ... | |
517 | 568 | case 0: |
518 | 569 | dsc = init_txrx(trim, clkm); |
519 | 570 | set_channel(dsc, channel); |
520 | if (!cont_tx) | |
571 | switch (mode) { | |
572 | case mode_msg: | |
521 | 573 | receive(dsc, pcap_file); |
522 | else { | |
574 | break; | |
575 | case mode_ber: | |
576 | set_power(dsc, power, 0); | |
577 | transmit_pattern(dsc, pause_s, 0); | |
578 | break; | |
579 | case mode_cont_tx: | |
523 | 580 | set_power(dsc, power, 0); |
524 | 581 | status = test_mode(dsc, cont_tx, NULL); |
582 | break; | |
583 | default: | |
584 | abort(); | |
525 | 585 | } |
526 | 586 | break; |
527 | 587 | case 2: |
528 | if (cont_tx) | |
588 | switch (mode) { | |
589 | case mode_msg: | |
590 | break; | |
591 | case mode_ber: | |
592 | /* fall through */ | |
593 | case mode_cont_tx: | |
529 | 594 | usage(*argv); |
595 | default: | |
596 | abort(); | |
597 | } | |
530 | 598 | times = strtoul(argv[optind+1], &end, 0); |
531 | 599 | if (*end) |
532 | 600 | usage(*argv); |
... | ... | |
534 | 602 | case 1: |
535 | 603 | dsc = init_txrx(trim, clkm); |
536 | 604 | set_channel(dsc, channel); |
537 | if (!cont_tx) { | |
605 | switch (mode) { | |
606 | case mode_msg: | |
538 | 607 | set_power(dsc, power, 1); |
539 | 608 | transmit(dsc, argv[optind], times); |
540 | } else { | |
609 | break; | |
610 | case mode_ber: | |
611 | times = strtoul(argv[optind+1], &end, 0); | |
612 | if (*end) | |
613 | usage(*argv); | |
614 | set_power(dsc, power, 0); | |
615 | transmit_pattern(dsc, pause_s, times); | |
616 | break; | |
617 | case mode_cont_tx: | |
541 | 618 | set_power(dsc, power, 0); |
542 | 619 | status = test_mode(dsc, cont_tx, argv[optind]); |
620 | break; | |
621 | default: | |
622 | abort(); | |
623 | ||
543 | 624 | } |
544 | 625 | break; |
545 | 626 | default: |