Changeset 1067

Show
Ignore:
Timestamp:
02/25/2010 05:04:54 PM (7 months ago)
Author:
jcy
Message:

Test updates.
Implementation of sleep-opt in tdma-asap.
Fixed bug in tdma-asap where sync packets were reported to application.

Location:
nano-RK
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • nano-RK/projects/tests/test_bmac/main.c

    r1062 r1067  
    3939#define BMAC_SINK 2 
    4040 
     41 
     42#define DBG_PKT_ORDER 
     43 
     44// max number of retries before giving up packet send 
     45#define BMAC_UNLIMITED_RETRY 
     46 
     47#ifndef BMAC_UNLIMITED_RETRY 
     48    #define MAX_RETRIES 5 
     49#endif 
     50 
     51 
    4152// for compatibility 
    4253#define BMAC_DATA_START 0 
    4354#define STATS_STACK 512 
    4455 
    45 #define NODE_MODE BMAC_SOURCE 
    46  
    47 #define EVENT_PERIOD_SECS 0 
    48 #define EVENT_PERIOD_NANOS 500000000 
     56#define NODE_MODE BMAC_SINK 
     57 
     58#define EVENT_PERIOD_SECS 1 
     59#define EVENT_PERIOD_NANOS 0 
    4960#define EVENT_PERIOD_MULT 1 
    5061 
     
    100111uint8_t have_data_to_send; 
    101112uint16_t pkt_num; 
     113 
     114uint16_t pkt_nbr_expect; 
     115uint16_t errs; 
    102116 
    103117 
     
    291305int8_t rte_event(uint8_t * ev_buf) 
    292306{ 
     307    uint16_t pkt_nbr; 
     308 
     309    pkt_nbr = ev_buf[BMAC_DATA_START+2]; 
     310    pkt_nbr <<= 8; 
     311    pkt_nbr |= ev_buf[BMAC_DATA_START+3]; 
     312 
     313    printf("PKTGET %d %d %d\r\n",  
     314        ev_buf[BMAC_DATA_START+1], 
     315        pkt_nbr, 
     316        my_addr8); 
     317 
    293318    ev_queue[end].sender = ev_buf[BMAC_DATA_START+4]; 
    294319    ev_queue[end].seq  =   ev_buf[BMAC_DATA_START+5]<<8; 
     
    320345    pkt_nbr <<= 8; 
    321346    pkt_nbr |= ev_buf[BMAC_DATA_START+3]; 
     347 
     348#ifdef DBG_PKT_ORDER 
     349    // XXX REMEMBER TO TAKE THIS OUT 
     350    if (pkt_nbr > pkt_nbr_expect) 
     351        printf("WRONGPKT %d\r\n", errs++); 
     352         
     353    pkt_nbr_expect = pkt_nbr+1; 
     354#endif 
    322355 
    323356    printf("PKTGET %d %d %d\r\n",  
     
    693726    while (!bmac_started()) 
    694727        nrk_wait(delay_time); 
     728 
    695729    printf("bmac init done\r\n"); 
    696730 
     
    766800{  
    767801 
     802    uint8_t retries; 
     803 
    768804    printf("txTask %d\r\n", nrk_get_pid()); 
    769805    have_data_to_send = 0; 
     
    807843 
    808844            //while (bmac_tx_pkt(test_tx_buf[(current_buf+1)%2], test_tx_offset[(current_buf+1)%2])==NRK_ERROR); 
    809             while (bmac_tx_pkt(pkt_tx_buf, EVPKT_SIZE)==NRK_ERROR); 
     845 
     846            retries = 0; 
     847 
     848            #ifdef BMAC_UNLIMITED_RETRY 
     849                while (bmac_tx_pkt(pkt_tx_buf, EVPKT_SIZE)==NRK_ERROR); 
     850            #else 
     851                while (bmac_tx_pkt(pkt_tx_buf, EVPKT_SIZE)==NRK_ERROR && retries++ < MAX_RETRIES); 
     852            #endif 
     853 
    810854         
    811855        nrk_led_clr(RED_LED); 
     
    819863        //printf("PKTSEND %u %u %u %u %20"PRIu32" %20"PRIu32"\r\n", my_addr8, pkt_num-1, my_level, tdma_tree_parent_get(), current_time.secs, current_time.nano_secs); 
    820864        //printf("PKTSEND %u %u %u %u %20"PRIu32" %20"PRIu32"\r\n", my_addr8, pkt_num-1, my_level, my_parent, current_time.secs, current_time.nano_secs); 
     865         
     866#ifndef BMAC_UNLIMITED_RETRY 
     867        if (retries < MAX_RETRIES) 
     868            printf("PKTSEND %u %u %u %u\r\n", my_addr8, pkt_num-1, my_level, my_parent); 
     869        else 
     870            printf("GU %u %u\r\n", my_addr8, pkt_num-1); 
     871#else 
     872        // always sent 
    821873        printf("PKTSEND %u %u %u %u\r\n", my_addr8, pkt_num-1, my_level, my_parent); 
     874#endif 
    822875 
    823876    } 
     
    886939                } 
    887940            } 
     941            else 
     942                nrk_kprintf(PSTR("wrong CTL\r\n")); 
    888943        } 
    889944        else 
  • nano-RK/projects/tests/test_tdma/main.c

    r1062 r1067  
    4242// Only require MAC address for address decode  
    4343#define MAC_ADDR    0x0001 
    44 #define EVENT_PERIOD_SECS 0 
    45 #define EVENT_PERIOD_NANOS 500000000 
    46 #define EVENT_PERIOD_MULT 1 
     44#define EVENT_PERIOD_SECS 1 
     45#define EVENT_PERIOD_NANOS 0 
     46#define EVENT_PERIOD_MULT 5 
    4747 
    4848#define TDMA_MODE TDMA_SLAVE 
     
    165165int8_t rte_event(uint8_t * ev_buf) 
    166166{ 
     167    uint16_t pkt_nbr; 
     168 
     169    pkt_nbr = ev_buf[TDMA_DATA_START+2]; 
     170    pkt_nbr <<= 8; 
     171    pkt_nbr |= ev_buf[TDMA_DATA_START+3]; 
     172 
     173    printf("PKTGET %d %d %d\r\n",  
     174        ev_buf[TDMA_DATA_START+1], 
     175        pkt_nbr, 
     176        my_addr8); 
     177 
    167178    ev_queue[end].sender = ev_buf[TDMA_DATA_START+4]; 
    168179    ev_queue[end].seq  =   ev_buf[TDMA_DATA_START+5]<<8; 
     
    723734                } 
    724735            } 
     736 
    725737            local_rx_buf[TDMA_DATA_START] = 1; 
    726738            tdma_rx_pkt_release(); 
  • nano-RK/src/net/tdma_asap/tdma_asap.c

    r1062 r1067  
    130130#endif  
    131131 
     132#ifdef TDMA_SLEEP_OPT 
     133    // acts as both a control value and a slot value 
     134    // if 0xFFFF, then sleep opt is not active 
     135    // otherwise will hold the slot that the feature was 
     136    // activated for this cycle 
     137    uint16_t tdma_sleep_opt_slot; 
     138#endif 
     139 
    132140uint8_t tdma_init_done = 0; 
    133141uint8_t tdma_running=0; 
     
    137145 
    138146uint16_t minipkt_id = 0; 
    139  
    140 // for autoack 
    141 static uint8_t pkt_got_ack = 0; 
    142  
    143147 
    144148uint8_t tdma_channel   = TDMA_DEFAULT_CHANNEL; 
     
    482486    } 
    483487 
     488    // make sure sleeping til end of slot is disabled 
     489    #ifdef TDMA_SLEEP_OPT 
     490    tdma_sleep_opt_slot = 0xFFFF; 
     491    #endif 
     492 
    484493    tdma_init_done = 1; 
    485494    return NRK_OK; 
     
    793802            #ifdef TDMA_TEXT_DEBUG_ALL 
    794803                nrk_kprintf(PSTR("No sender heard\r\n")); 
     804            #endif 
     805 
     806            // If we're using the sleep opt feature, record this slot as 
     807            // the one in the cycle we didn't receive anything from children 
     808            // and thus we'll sleep for the rest of the RX from child slots 
     809            // in this cycle 
     810            #ifdef TDMA_SLEEP_OPT 
     811                tdma_sleep_opt_slot = next_schedule_entry.slot; 
    795812            #endif 
    796813 
     
    10631080        // if it's newer, sync to it. 
    10641081        // token loops around, so allow some slack 
    1065         if (tdma_node_mode != TDMA_MASTER && (tmp_token > tdma_time_token ||  
    1066                     (tdma_time_token > 110 && tmp_token < 10 ))) 
     1082        if (tdma_node_mode != TDMA_MASTER && ((tmp_token > tdma_time_token) ||  
     1083                    (tdma_time_token > 110 && tmp_token < 40 ))) 
    10671084        {    
    10681085             
     
    11571174        else 
    11581175        {  
     1176#ifdef TDMA_STATS_COLLECT 
     1177            // If I was supposed to get a sync packet on this slot, and did, record it 
     1178            if (next_schedule_entry.priority == 1) 
     1179                sync_rx_cnt++; 
     1180#endif 
    11591181            // If it is an explicit time sync packet, then release it 
    11601182            // so it doesn't block a buffer... 
     
    12131235 
    12141236    // This clears the explicit sync bit 
    1215     tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= -1;  
     1237    tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= tdma_time_token;  
    12161238    explicit_tsync=0; 
    12171239 
    12181240    // If it is an empty packet set explicit sync bit 
    1219     if(tdma_rfTxInfo.length==TDMA_DATA_START ) 
     1241    //if(tdma_rfTxInfo.length==TDMA_DATA_START ) 
     1242     
     1243    if (next_schedule_entry.type == TDMA_TX_CHILD) 
    12201244    { 
    12211245        explicit_tsync=1; 
     
    16541678 
    16551679    // This clears the explicit sync bit 
    1656     tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= tdma_time_token;  
     1680    // don't uncomment this.  It will mess up the sync packet stuff. 
     1681    //tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= tdma_time_token;  
    16571682 
    16581683 
     
    16761701#endif 
    16771702    rf_rx_off(); 
    1678  
    1679     //if (!pkt_got_ack) 
    1680     //    printf("af %u\r\n", tdma_rfTxInfo.destAddr); 
    1681  
    1682     // restore dest addr at end 
    1683     //if (explicit_tsync) 
    1684     //    tdma_rfTxInfo.destAddr = dest_tmp; 
    16851703 
    16861704#ifdef TDMA_STATS_COLLECT 
     
    20132031                if (sync_slot < 0 || sync_slot > TDMA_SLOTS_PER_CYCLE) 
    20142032                { 
    2015                     printf("BAD SYNC %d\r\n", sync_slot); 
     2033                    printf("BAD SYNC %u\r\n", sync_slot); 
    20162034                    continue; 
    20172035                } 
     
    20202038                tmp_token = 0x7F & tdma_rfRxInfo.pPayload[TDMA_TIME_TOKEN]; 
    20212039 
    2022                 if ((tmp_token <= tdma_time_token) &&  
    2023                     !(tdma_time_token > 110 && tmp_token < 10 )) 
     2040                if ((tmp_token <= tdma_time_token) && 
     2041                    !(tdma_time_token > 110 && tmp_token < 40 )) 
    20242042                {    
    20252043                    printf("bad token %d %d\r\n", tdma_time_token, tmp_token); 
     
    21232141                // sync time has expired.  Go into re-sync mode 
    21242142                in_sync = 0; 
    2125                 //tdma_time_token = 0; 
     2143 
     2144                // to prevent infinite syncing between 2 nodes that are not parent, 
     2145                // increment the token count by 1 
     2146                //tdma_time_token++; 
     2147 
     2148                //if (tdma_time_token > 126) 
     2149                //    tdma_time_token = 0; 
     2150 
    21262151                continue; 
    21272152            } 
     
    21862211        } 
    21872212 
     2213         
     2214 
    21882215#ifdef GPIO_NEWTMR_SLT_DEBUG 
    21892216        PORTA &= ~BM(GPIO_NEWTMR_SLT_DEBUG); 
     
    22432270            _tdma_rx(next_schedule_entry.slot); 
    22442271 
     2272#ifdef TDMA_STATS_COLLECT 
     2273            if (next_schedule_entry.priority == 1) 
     2274                sync_slot_cnt++; 
     2275#endif 
    22452276/* 
    22462277            if (tdma_rx_pkt_check() == 0) 
     
    23892420 
    23902421        next_schedule_entry = tdma_schedule_get_next(next_schedule_entry.slot); 
     2422 
     2423        #ifdef TDMA_SLEEP_OPT 
     2424            // if tdma_sleep_opt is enabled for this cycle, I have to search the schedule until 
     2425            // a slot that is not a RX from child is found. 
     2426            if (tdma_sleep_opt_slot != 0xFFFF) 
     2427            { 
     2428                // while an rx slot from child 
     2429                while(next_schedule_entry.type == TDMA_RX 
     2430                      && next_schedule_entry.priority != 1 
     2431                      // and the slot is further along in the cycle 
     2432                      && next_schedule_entry.slot > tdma_sleep_opt_slot) 
     2433                { 
     2434                    next_schedule_entry = tdma_schedule_get_next(next_schedule_entry.slot); 
     2435                } 
     2436             
     2437                if (next_schedule_entry.slot <= tdma_sleep_opt_slot) 
     2438                    tdma_sleep_opt_slot = 0xFFFF; 
     2439            } 
     2440        #endif 
     2441 
    23912442    } 
    23922443} 
  • nano-RK/src/net/tdma_asap/tdma_asap.h

    r1061 r1067  
    108108 
    109109 
     110    // optimization added feb 15: if none of my children 
     111    // have to TX I will sleep for the rest of my RX slots from children in the cycle 
     112    // NOTE: this is implemented as still waking up but sleeping immediately again if 
     113    // I don't need to be awake 
     114//#define TDMA_SLEEP_OPT 
    110115 
    111116 
  • nano-RK/src/net/tdma_asap/tdma_asap_stats.c

    r1028 r1067  
    100100    dbl_pkt_cnt = 0; 
    101101    mpkt_log_curbuf=0; 
     102    sync_rx_cnt = 0; 
     103    sync_slot_cnt = 0; 
    102104    //recording_awk_reg = 0; 
    103105    //recording_awk_steal =0; 
     
    203205  // number of slot steals 
    204206  // number of backoffs 
     207  // number of rx syncs 
     208  // number of sync slots 
    205209 
    206210#ifdef NRK_STATS_TRACKER 
     
    211215#endif 
    212216 
    213   printf("SD %d %20"PRIu32" %20"PRIu32" %20"PRIu32" %20"PRIu32" %20"PRIu32"\r\n", 
     217  printf("SD %d %lu %lu %lu %lu %lu %u %u\r\n", 
    214218    tdma_mac_get(), 
    215219    tdma_cpu_time.secs, 
     
    217221    ticks_rdo, 
    218222    steal_cnt, 
    219     backoff_cnt); 
     223    backoff_cnt, 
     224    sync_rx_cnt, 
     225    sync_slot_cnt); 
    220226 
    221227} 
  • nano-RK/src/net/tdma_asap/tdma_asap_stats.h

    r1028 r1067  
    4949uint32_t backoff_cnt; 
    5050uint32_t dbl_pkt_cnt; 
     51// # sync packets rcvd (100% if equal to sync_slot_cnt) 
     52uint16_t sync_rx_cnt; 
     53// # of sync slots 
     54uint16_t sync_slot_cnt; 
    5155 
    5256/* 
  • nano-RK/src/net/tdma_asap/tdma_asap_tree.h

    r1061 r1067  
    2525 
    2626// use a static schedule as computed by a slot spreading algorithm 
    27 //#define TDMA_SLOT_SPREADING 
     27#define TDMA_SLOT_SPREADING 
    2828 
    2929// # of nodes max using TDMA