Date:2011-01-19 16:24:20 (9 years 6 months 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
374374}
375375
376376
377static 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
377411
378412static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd)
379413{
...... 
416450{
417451    fprintf(stderr,
418452"usage: %s [common_options] [message [repetitions]]\n"
453" %s [common_options] -B pause_s [repetitions]\n"
419454" %s [common_options] -T offset [command]\n\n"
420455" text message mode:\n"
421456" message message string to send (if absent, receive)\n"
422457" 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"
423461" constant wave test mode (transmit only):\n"
424462" -T offset test mode. offset is the frequency offset of the constant\n"
425463" wave in MHz: -2, -0.5, or +0.5\n"
...... 
433471" -o file write received data to a file in pcap format\n"
434472" -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n"
435473" -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),
437475        DEFAULT_POWER);
438476    exit(1);
439477}
...... 
441479
442480int main(int argc, char *const *argv)
443481{
482    enum {
483        mode_msg,
484        mode_ber,
485        mode_cont_tx,
486    } mode = mode_msg;
444487    int channel = DEFAULT_CHANNEL;
445488    double power = DEFAULT_POWER;
446489    int trim = 0, times = 1;
447490    uint8_t cont_tx = 0;
491    double pause_s = 0;
448492    char *end;
449493    int c, freq;
450494    unsigned tmp, clkm = 0;
...... 
452496    const char *pcap_file = NULL;
453497    struct atrf_dsc *dsc;
454498
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)
456500        switch (c) {
457501        case 'c':
458502            channel = strtoul(optarg, &end, 0);
...... 
486530            if (trim > 15)
487531                usage(*argv);
488532            break;
533        case 'B':
534            mode = mode_ber;
535            pause_s = strtof(optarg, &end);
536            if (*end)
537                usage(*argv);
538            break;
489539        case 'C':
490540            tmp = strtol(optarg, &end, 0);
491541            if (*end)
...... 
498548                usage(*argv);
499549            break;
500550        case 'T':
551            mode = mode_cont_tx;
501552            if (!strcmp(optarg, "-2"))
502553                cont_tx = CONT_TX_M2M;
503554            else if (!strcmp(optarg, "-0.5"))
...... 
517568    case 0:
518569        dsc = init_txrx(trim, clkm);
519570        set_channel(dsc, channel);
520        if (!cont_tx)
571        switch (mode) {
572        case mode_msg:
521573            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:
523580            set_power(dsc, power, 0);
524581            status = test_mode(dsc, cont_tx, NULL);
582            break;
583        default:
584            abort();
525585        }
526586        break;
527587    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:
529594            usage(*argv);
595        default:
596            abort();
597        }
530598        times = strtoul(argv[optind+1], &end, 0);
531599        if (*end)
532600            usage(*argv);
...... 
534602    case 1:
535603        dsc = init_txrx(trim, clkm);
536604        set_channel(dsc, channel);
537        if (!cont_tx) {
605        switch (mode) {
606        case mode_msg:
538607            set_power(dsc, power, 1);
539608            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:
541618            set_power(dsc, power, 0);
542619            status = test_mode(dsc, cont_tx, argv[optind]);
620            break;
621        default:
622            abort();
623
543624        }
544625        break;
545626    default:

Archive Download the corresponding diff file



interactive