Changeset 1067
- Timestamp:
- 02/25/2010 05:04:54 PM (7 months ago)
- Location:
- nano-RK
- Files:
-
- 7 modified
-
projects/tests/test_bmac/main.c (modified) (9 diffs)
-
projects/tests/test_tdma/main.c (modified) (3 diffs)
-
src/net/tdma_asap/tdma_asap.c (modified) (15 diffs)
-
src/net/tdma_asap/tdma_asap.h (modified) (1 diff)
-
src/net/tdma_asap/tdma_asap_stats.c (modified) (4 diffs)
-
src/net/tdma_asap/tdma_asap_stats.h (modified) (1 diff)
-
src/net/tdma_asap/tdma_asap_tree.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
nano-RK/projects/tests/test_bmac/main.c
r1062 r1067 39 39 #define BMAC_SINK 2 40 40 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 41 52 // for compatibility 42 53 #define BMAC_DATA_START 0 43 54 #define STATS_STACK 512 44 55 45 #define NODE_MODE BMAC_S OURCE46 47 #define EVENT_PERIOD_SECS 048 #define EVENT_PERIOD_NANOS 50000000056 #define NODE_MODE BMAC_SINK 57 58 #define EVENT_PERIOD_SECS 1 59 #define EVENT_PERIOD_NANOS 0 49 60 #define EVENT_PERIOD_MULT 1 50 61 … … 100 111 uint8_t have_data_to_send; 101 112 uint16_t pkt_num; 113 114 uint16_t pkt_nbr_expect; 115 uint16_t errs; 102 116 103 117 … … 291 305 int8_t rte_event(uint8_t * ev_buf) 292 306 { 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 293 318 ev_queue[end].sender = ev_buf[BMAC_DATA_START+4]; 294 319 ev_queue[end].seq = ev_buf[BMAC_DATA_START+5]<<8; … … 320 345 pkt_nbr <<= 8; 321 346 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 322 355 323 356 printf("PKTGET %d %d %d\r\n", … … 693 726 while (!bmac_started()) 694 727 nrk_wait(delay_time); 728 695 729 printf("bmac init done\r\n"); 696 730 … … 766 800 { 767 801 802 uint8_t retries; 803 768 804 printf("txTask %d\r\n", nrk_get_pid()); 769 805 have_data_to_send = 0; … … 807 843 808 844 //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 810 854 811 855 nrk_led_clr(RED_LED); … … 819 863 //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); 820 864 //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 821 873 printf("PKTSEND %u %u %u %u\r\n", my_addr8, pkt_num-1, my_level, my_parent); 874 #endif 822 875 823 876 } … … 886 939 } 887 940 } 941 else 942 nrk_kprintf(PSTR("wrong CTL\r\n")); 888 943 } 889 944 else -
nano-RK/projects/tests/test_tdma/main.c
r1062 r1067 42 42 // Only require MAC address for address decode 43 43 #define MAC_ADDR 0x0001 44 #define EVENT_PERIOD_SECS 045 #define EVENT_PERIOD_NANOS 50000000046 #define EVENT_PERIOD_MULT 144 #define EVENT_PERIOD_SECS 1 45 #define EVENT_PERIOD_NANOS 0 46 #define EVENT_PERIOD_MULT 5 47 47 48 48 #define TDMA_MODE TDMA_SLAVE … … 165 165 int8_t rte_event(uint8_t * ev_buf) 166 166 { 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 167 178 ev_queue[end].sender = ev_buf[TDMA_DATA_START+4]; 168 179 ev_queue[end].seq = ev_buf[TDMA_DATA_START+5]<<8; … … 723 734 } 724 735 } 736 725 737 local_rx_buf[TDMA_DATA_START] = 1; 726 738 tdma_rx_pkt_release(); -
nano-RK/src/net/tdma_asap/tdma_asap.c
r1062 r1067 130 130 #endif 131 131 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 132 140 uint8_t tdma_init_done = 0; 133 141 uint8_t tdma_running=0; … … 137 145 138 146 uint16_t minipkt_id = 0; 139 140 // for autoack141 static uint8_t pkt_got_ack = 0;142 143 147 144 148 uint8_t tdma_channel = TDMA_DEFAULT_CHANNEL; … … 482 486 } 483 487 488 // make sure sleeping til end of slot is disabled 489 #ifdef TDMA_SLEEP_OPT 490 tdma_sleep_opt_slot = 0xFFFF; 491 #endif 492 484 493 tdma_init_done = 1; 485 494 return NRK_OK; … … 793 802 #ifdef TDMA_TEXT_DEBUG_ALL 794 803 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; 795 812 #endif 796 813 … … 1063 1080 // if it's newer, sync to it. 1064 1081 // 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 ))) 1067 1084 { 1068 1085 … … 1157 1174 else 1158 1175 { 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 1159 1181 // If it is an explicit time sync packet, then release it 1160 1182 // so it doesn't block a buffer... … … 1213 1235 1214 1236 // This clears the explicit sync bit 1215 tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= -1;1237 tdma_rfTxInfo.pPayload[TDMA_TIME_TOKEN]= tdma_time_token; 1216 1238 explicit_tsync=0; 1217 1239 1218 1240 // 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) 1220 1244 { 1221 1245 explicit_tsync=1; … … 1654 1678 1655 1679 // 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; 1657 1682 1658 1683 … … 1676 1701 #endif 1677 1702 rf_rx_off(); 1678 1679 //if (!pkt_got_ack)1680 // printf("af %u\r\n", tdma_rfTxInfo.destAddr);1681 1682 // restore dest addr at end1683 //if (explicit_tsync)1684 // tdma_rfTxInfo.destAddr = dest_tmp;1685 1703 1686 1704 #ifdef TDMA_STATS_COLLECT … … 2013 2031 if (sync_slot < 0 || sync_slot > TDMA_SLOTS_PER_CYCLE) 2014 2032 { 2015 printf("BAD SYNC % d\r\n", sync_slot);2033 printf("BAD SYNC %u\r\n", sync_slot); 2016 2034 continue; 2017 2035 } … … 2020 2038 tmp_token = 0x7F & tdma_rfRxInfo.pPayload[TDMA_TIME_TOKEN]; 2021 2039 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 )) 2024 2042 { 2025 2043 printf("bad token %d %d\r\n", tdma_time_token, tmp_token); … … 2123 2141 // sync time has expired. Go into re-sync mode 2124 2142 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 2126 2151 continue; 2127 2152 } … … 2186 2211 } 2187 2212 2213 2214 2188 2215 #ifdef GPIO_NEWTMR_SLT_DEBUG 2189 2216 PORTA &= ~BM(GPIO_NEWTMR_SLT_DEBUG); … … 2243 2270 _tdma_rx(next_schedule_entry.slot); 2244 2271 2272 #ifdef TDMA_STATS_COLLECT 2273 if (next_schedule_entry.priority == 1) 2274 sync_slot_cnt++; 2275 #endif 2245 2276 /* 2246 2277 if (tdma_rx_pkt_check() == 0) … … 2389 2420 2390 2421 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 2391 2442 } 2392 2443 } -
nano-RK/src/net/tdma_asap/tdma_asap.h
r1061 r1067 108 108 109 109 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 110 115 111 116 -
nano-RK/src/net/tdma_asap/tdma_asap_stats.c
r1028 r1067 100 100 dbl_pkt_cnt = 0; 101 101 mpkt_log_curbuf=0; 102 sync_rx_cnt = 0; 103 sync_slot_cnt = 0; 102 104 //recording_awk_reg = 0; 103 105 //recording_awk_steal =0; … … 203 205 // number of slot steals 204 206 // number of backoffs 207 // number of rx syncs 208 // number of sync slots 205 209 206 210 #ifdef NRK_STATS_TRACKER … … 211 215 #endif 212 216 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", 214 218 tdma_mac_get(), 215 219 tdma_cpu_time.secs, … … 217 221 ticks_rdo, 218 222 steal_cnt, 219 backoff_cnt); 223 backoff_cnt, 224 sync_rx_cnt, 225 sync_slot_cnt); 220 226 221 227 } -
nano-RK/src/net/tdma_asap/tdma_asap_stats.h
r1028 r1067 49 49 uint32_t backoff_cnt; 50 50 uint32_t dbl_pkt_cnt; 51 // # sync packets rcvd (100% if equal to sync_slot_cnt) 52 uint16_t sync_rx_cnt; 53 // # of sync slots 54 uint16_t sync_slot_cnt; 51 55 52 56 /* -
nano-RK/src/net/tdma_asap/tdma_asap_tree.h
r1061 r1067 25 25 26 26 // use a static schedule as computed by a slot spreading algorithm 27 //#define TDMA_SLOT_SPREADING27 #define TDMA_SLOT_SPREADING 28 28 29 29 // # of nodes max using TDMA
