Changeset 1059
- Timestamp:
- 01/27/2010 05:17:05 PM (2 years ago)
- Location:
- nano-RK/projects/tests/test_bmac
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
nano-RK/projects/tests/test_bmac/main.c
r1055 r1059 41 41 // for compatibility 42 42 #define BMAC_DATA_START 0 43 44 //#define NODE_MODE BMAC_SINK 43 #define STATS_STACK 512 44 45 45 #define NODE_MODE BMAC_SOURCE 46 46 47 #define EVENT_PERIOD_SECS 0 48 #define EVENT_PERIOD_NANOS 500000000 49 #define EVENT_PERIOD_MULT 1 50 51 nrk_task_type statsTask; 47 52 nrk_task_type RX_TASK; 48 NRK_STK rx_task_stack[NRK_APP_STACKSIZE]; 53 nrk_task_type evTask; 54 nrk_task_type TX_TASK; 55 56 NRK_STK rx_task_stack[STATS_STACK]; 57 NRK_STK tx_task_stack[STATS_STACK]; 58 NRK_STK ev_task_stack[STATS_STACK]; 59 NRK_STK stats_task_stack[STATS_STACK]; 60 61 62 void stats_task(void); 49 63 void rx_task (void); 50 51 nrk_task_type evTask;52 53 nrk_task_type TX_TASK;54 NRK_STK tx_task_stack[NRK_APP_STACKSIZE];55 NRK_STK ev_task_stack[NRK_APP_STACKSIZE];56 64 void tx_task (void); 57 65 … … 115 123 sensorsInfo[2 ].parent = 1; 116 124 sensorsInfo[3 ].isDead = 0; 117 sensorsInfo[3 ].parent = 1 5;125 sensorsInfo[3 ].parent = 14; 118 126 sensorsInfo[4 ].isDead = 0; 119 127 sensorsInfo[4 ].parent = 1; … … 268 276 269 277 have_data_to_send = 1; 278 nrk_led_set(GREEN_LED); 270 279 271 280 return NRK_OK; … … 399 408 400 409 // init bmac on channel 25 401 bmac_init (1 5);410 bmac_init (18); 402 411 403 412 // Enable AES 128 bit encryption 404 413 // When encryption is active, messages from plaintext 405 414 // source will still be received. 406 bmac_encryption_set_key(aes_key,16);407 bmac_encryption_enable();415 //bmac_encryption_set_key(aes_key,16); 416 //bmac_encryption_enable(); 408 417 // bmac_encryption_disable(); 409 418 … … 419 428 // bmac will try to receive fainter packets. If the value is set 420 429 // too high or too low performance will suffer greatly. 421 // bmac_set_cca_thresh(-45);430 //bmac_set_cca_thresh(-45); 422 431 423 432 … … 546 555 uint16_t cnt; 547 556 uint32_t mac; 557 nrk_time_t offset_time; 548 558 549 559 // does tree-specific things … … 551 561 552 562 printf("evTask %d\r\n", nrk_get_pid()); 563 nrk_led_set(BLUE_LED); 553 564 554 565 r=0; … … 561 572 my_addr8 = (mac & 0xFF); 562 573 563 bmac_init(18); 574 //bmac_init(18); 575 while (!bmac_started()) 576 nrk_wait(delay_time); 564 577 printf("bmac init done\r\n"); 565 //tdma_init(TDMA_CHANNEL); 578 579 // Auto ACK is an energy efficient link layer ACK on packets 580 // If Auto ACK is enabled, then bmac_tx_pkt() will return failure 581 // if no ACK was received. In a broadcast domain, the ACK's will 582 // typically collide. To avoid this, one can use address decoding. 583 // The functions are as follows: 584 bmac_auto_ack_enable(); 585 // bmac_auto_ack_disable(); 586 587 // Address decoding is a way of preventing the radio from receiving 588 // packets that are not address to a particular node. This will 589 // supress ACK packets from nodes that should not automatically ACK. 590 // The functions are as follows: 591 bmac_addr_decode_set_my_mac(my_addr8); 592 //bmac_addr_decode_dest_mac(0xffff); // 0xFFFF is broadcast 593 bmac_addr_decode_dest_mac(my_parent); // 0xFFFF is broadcast 594 bmac_addr_decode_enable(); 595 // bmac_addr_decode_disable(); 596 597 //printf("NODE %d %d %d\r\n", tdma_mac_get(), tdma_tree_level_get(), tdma_tree_parent_get()); 598 599 // seed the number generator off mac address, then wait for 600 // random amount of time, to offset event generation 601 srand(my_addr8); 602 offset_time.secs = 0; 603 offset_time.nano_secs = rand(); 604 nrk_time_compact_nanos(&offset_time); 566 605 567 //tdma_schedule_print(); 568 569 //while (1) 570 // nrk_wait(delay_time); 571 //PORTA |= BM(DEBUG_1); 572 // pretend NOT 573 /* 574 while(1) 575 { 576 PORTA &= ~BM(DEBUG_1); 577 nrk_wait_until_next_period(); 578 PORTA |= BM(DEBUG_1); 579 580 } 581 */ 582 583 //my_addr8 = tdma_mac_get() & 0xFF; 584 //my_level = tdma_tree_level_get(); 585 586 //nrk_kprintf(PSTR("EVTASK Start\r\n")); 587 //printf("NODE %d %d %d\r\n", tdma_mac_get(), tdma_tree_level_get(), tdma_tree_parent_get()); 606 nrk_wait(offset_time); 607 588 608 589 609 while(1) … … 592 612 //r = rand() % 2; 593 613 //r = rand() % 100; 594 r= (r+1) % 10;614 r= (r+1) % (EVENT_PERIOD_MULT) ; 595 615 //printf("r=%d\r\n",r); 596 616 … … 633 653 nrk_wait(delay_time); 634 654 655 tx_done_signal = bmac_get_tx_done_signal(); 656 nrk_signal_register(tx_done_signal); 635 657 //srand(my_addr16); 636 658 … … 640 662 while (!have_data_to_send) 641 663 { 642 nrk_wait(delay_time); 664 //nrk_wait(delay_time); 665 nrk_wait_until_next_period(); 643 666 } 644 667 … … 649 672 //} 650 673 //else 651 { 652 bmac_tx_pkt_nonblocking(test_tx_buf[current_buf], test_tx_offset[current_buf]); 674 nrk_led_set(RED_LED); 675 //while (bmac_tx_pkt(test_tx_buf[current_buf], test_tx_offset[current_buf])==NRK_ERROR) 676 //bmac_tx_pkt_nonblocking(test_tx_buf[current_buf], test_tx_offset[current_buf]); 677 // nrk_kprintf(PSTR("ackfail\r\n")); 653 678 654 679 // switch buffers … … 657 682 test_tx_buf[current_buf][BMAC_DATA_START] = 0; 658 683 have_data_to_send = 0; 684 nrk_led_clr(GREEN_LED); 659 685 660 686 pkt_num++; 661 } 662 663 nrk_event_wait(SIG(tx_done_signal)); 687 688 while (bmac_tx_pkt(test_tx_buf[current_buf], test_tx_offset[current_buf])==NRK_ERROR); 664 689 690 nrk_led_clr(RED_LED); 665 691 666 692 //PORTA |= BM(DEBUG_1); … … 675 701 } 676 702 } 677 678 703 679 704 void rx_task() … … 685 710 uint8_t i; 686 711 uint8_t from_child; 712 nrk_time_t check_period; 713 687 714 688 715 printf("rxTask %d\r\n", nrk_get_pid()); 689 716 717 bmac_init(18); 718 //while(!bmac_started()) 719 // nrk_wait(delay_time); 720 721 bmac_set_cca_thresh(-35); 690 722 bmac_rx_pkt_set_buffer(rx_buf, RF_MAX_PAYLOAD_SIZE); 691 723 692 tx_done_signal = bmac_get_tx_done_signal(); 693 nrk_signal_register(tx_done_signal); 694 695 while(!bmac_started()) 696 nrk_wait(delay_time); 724 check_period.secs = 0; 725 check_period.nano_secs = 100 * NANOS_PER_MS; 726 bmac_set_rx_check_rate(check_period); 727 697 728 698 729 while(1) 699 730 { 731 //printf("wait\r\n"); 700 732 val = bmac_wait_until_rx_pkt(); 733 nrk_led_set(ORANGE_LED); 734 if (val == NRK_ERROR) 735 { 736 printf("Error waiting.\r\n"); 737 //nrk_terminate_task(); 738 } 739 //printf("got\r\n"); 701 740 702 741 local_rx_buf=bmac_rx_pkt_get(&length, &rssi); … … 724 763 } 725 764 } 765 else 766 printf("Not from child %d\r\n", local_rx_buf[BMAC_DATA_START+2]); 726 767 727 768 local_rx_buf[BMAC_DATA_START] = 1; 728 769 bmac_rx_pkt_release(); 729 730 731 /* 732 PORTA |= BM(DEBUG_1); 733 PORTA &= ~BM(DEBUG_1); 734 */ 735 } 770 nrk_led_clr(ORANGE_LED); 771 772 773 //PORTA |= BM(DEBUG_1); 774 //PORTA &= ~BM(DEBUG_1); 775 } 776 } 777 778 void stats_task() 779 { 780 uint8_t r =0; 781 782 printf("statTask %d\r\n", nrk_get_pid()); 783 //uint8_t mode = 0; 784 785 //stats_delay_time.secs = 10; 786 //stats_delay_time.nano_secs = 0; 787 788 while(!bmac_started()) 789 nrk_wait(delay_time); 790 791 while (1) 792 { 793 // print out stats every once in a while 794 nrk_wait_until_next_period(); 795 796 // was mod 50 797 r = (r+1) % 5; 798 799 //nrk_wait_until(stats_delay_time); 800 //stats_delay_time.secs+=10; 801 802 if (r == 0) 803 bmac_stats_dump(); 804 805 } 806 736 807 } 737 808 … … 742 813 743 814 RX_TASK.task = rx_task; 744 nrk_task_set_stk( &RX_TASK, rx_task_stack, NRK_APP_STACKSIZE);815 nrk_task_set_stk( &RX_TASK, rx_task_stack, STATS_STACK); 745 816 RX_TASK.prio = 2; 746 817 RX_TASK.FirstActivation = TRUE; … … 756 827 757 828 TX_TASK.task = tx_task; 758 nrk_task_set_stk( &TX_TASK, tx_task_stack, NRK_APP_STACKSIZE);829 nrk_task_set_stk( &TX_TASK, tx_task_stack, STATS_STACK); 759 830 TX_TASK.prio = 2; 760 831 TX_TASK.FirstActivation = TRUE; 761 832 TX_TASK.Type = BASIC_TASK; 762 833 TX_TASK.SchType = PREEMPTIVE; 763 TX_TASK.period.secs = 1;764 TX_TASK.period.nano_secs = 0;765 TX_TASK.cpu_reserve.secs = 1;766 TX_TASK.cpu_reserve.nano_secs = 500 * NANOS_PER_MS;834 TX_TASK.period.secs = 0; 835 TX_TASK.period.nano_secs = 100000000; 836 TX_TASK.cpu_reserve.secs = 0; 837 TX_TASK.cpu_reserve.nano_secs = 0; 767 838 TX_TASK.offset.secs = 0; 768 839 TX_TASK.offset.nano_secs = 0; … … 771 842 evTask.task = event_task; 772 843 //nrk_task_set_stk( &evTask, tx_task_stack, NRK_APP_STACKSIZE); 773 evTask.Ptos = (void *) &ev_task_stack[ NRK_APP_STACKSIZE-1];844 evTask.Ptos = (void *) &ev_task_stack[STATS_STACK-1]; 774 845 evTask.Pbos = (void *) &ev_task_stack[0]; 775 846 evTask.prio = 2; … … 777 848 evTask.Type = BASIC_TASK; 778 849 evTask.SchType = PREEMPTIVE; 779 evTask.period.secs = 10;780 evTask.period.nano_secs = 5000;850 evTask.period.secs = EVENT_PERIOD_SECS; 851 evTask.period.nano_secs = EVENT_PERIOD_NANOS; 781 852 evTask.cpu_reserve.secs = 0; 782 853 evTask.cpu_reserve.nano_secs = 0; … … 785 856 nrk_activate_task (&evTask); 786 857 858 statsTask.task = stats_task; 859 //nrk_task_set_stk( &statsTask, tx_task_stack, NRK_APP_STACKSIZE); 860 statsTask.Ptos = (void *) &stats_task_stack[STATS_STACK-1]; 861 statsTask.Pbos = (void *) &stats_task_stack[0]; 862 statsTask.prio = 1; 863 statsTask.FirstActivation = TRUE; 864 statsTask.Type = BASIC_TASK; 865 statsTask.SchType = PREEMPTIVE; 866 statsTask.period.secs = 20; 867 statsTask.period.nano_secs = 0; 868 statsTask.cpu_reserve.secs = 0; 869 statsTask.cpu_reserve.nano_secs = 0; 870 statsTask.offset.secs = 0; 871 statsTask.offset.nano_secs = 0; 872 nrk_activate_task (&statsTask); 873 787 874 788 875 printf ("Create done\r\n"); -
nano-RK/projects/tests/test_bmac/makefile
r1055 r1059 25 25 # For example: 26 26 SRC += $(ROOT_DIR)/src/net/bmac/bmac.c 27 SRC += $(ROOT_DIR)/src/net/bmac/bmac_stats.c 27 28 28 29 -
nano-RK/projects/tests/test_bmac/nrk_cfg.h
r1055 r1059 35 35 #define NRK_UART_BUF 1 36 36 37 #define NRK_STATS_TRACKER 38 37 39 38 40 // Max number of tasks in your application … … 40 42 // Making this the correct size will save on BSS memory which 41 43 // is both RAM and ROM... 42 #define NRK_MAX_TASKS 544 #define NRK_MAX_TASKS 6 43 45 #define NRK_N_RES 1 44 46
Note: See TracChangeset
for help on using the changeset viewer.
