Changeset 110
- Timestamp:
- 06/25/2007 02:37:22 PM (5 years ago)
- Location:
- nano-RK/projects/network_stack
- Files:
-
- 4 edited
-
App.c (modified) (8 diffs)
-
NWStackConfig.c (modified) (2 diffs)
-
NWStackConfig.h (modified) (1 diff)
-
makefile (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
nano-RK/projects/network_stack/App.c
r103 r110 8 8 #include <hal.h> 9 9 #include <nrk_error.h> 10 #include <stdint.h> 11 12 #include "NWStackConfig.h" 13 #include "TransportLayerUDP.h" 14 #include "NetworkLayer.h" 15 #include "Pack.h" 16 #include "Serial.h" 17 #include "BufferManager.h" 18 19 #define SERVER1_PORT 1 20 #define SERVER2_PORT 2 21 #define SERVER1_RQS 4 22 #define SERVER2_RQS 4 23 24 #define PAYLOAD 64 25 #define DEBUG_APP 2 10 26 11 27 nrk_task_type RX_TASK; … … 16 32 NRK_STK tx_task_stack[NRK_APP_STACKSIZE]; 17 33 void tx_task(void); 34 35 /**************************************************************************************/ 36 uint8_t tx_buf[PAYLOAD]; 37 38 /**************************************************************************************/ 18 39 19 40 void initialise() … … 28 49 // clear all LEDs 29 50 // this will toggle when information about an already received neighbor is received again 51 52 if(DEBUG_APP == 2) 53 nrk_kprintf(PSTR("Before clearing LEDs\n")); 54 30 55 nrk_led_clr(ORANGE_LED); 31 56 nrk_led_clr(BLUE_LED); // will toggle whenever a packet is sent … … 36 61 nrk_time_set(0,0); 37 62 38 // configure the bmac task 39 bmac_task_config(); 40 41 // initialise the transport and network layer 42 initialise_transport_layer_udp(); 43 // initialise_network_layer(); 44 45 // initialise the buffer manager 46 initialise_buffer_manager(); 63 printf("Before initialising network stack"); 64 // initialise the network stack 65 nrk_init_nw_stack(); 47 66 48 67 return; 49 68 } 50 69 51 void tx_task() 52 { 53 } 54 55 void rx_task() 56 { 57 } 58 59 int main() 60 { 61 initialise(); 62 63 nrk_create_taskset(); // create the set of tasks 64 nrk_start(); // start this node 65 66 return 0; 67 } 70 void rx_task () 71 { 72 int8_t sock; 73 int8_t ret; 74 uint8_t *rx_buf; 75 int8_t len; 76 int16_t srcAddr; 77 int8_t srcPort; 78 int8_t rssi; 79 int8_t i; 80 81 82 printf ("rx_task PID=%d\r\n", nrk_get_pid ()); 83 sock = create_socket(SOCK_DGRAM); 84 if(sock == NRK_ERROR) 85 nrk_kprintf(PSTR("Error creating socket in rx_task")); 86 87 if(NODE_ADDR == 1) 88 ret = bind(sock, SERVER1_PORT); 89 else 90 ret = bind(sock, SERVER2_PORT); 91 92 if(ret == NRK_ERROR) 93 printf("Error in binding to socket %d\n", nrk_errno_get()); 94 95 if(NODE_ADDR == 1) 96 ret = set_rx_queue_size(sock, SERVER1_RQS); 97 else 98 ret = set_rx_queue_size(sock, SERVER2_RQS); 99 100 if(ret == NRK_ERROR) 101 printf("Error in setting rx queue size %d\n", nrk_errno_get()); 102 103 while(1) 104 { 105 rx_buf = receive(sock, &len, &srcAddr, &srcPort, &rssi); 106 107 printf("Received a pkt from %d,%d with RSSI = %d\n", srcAddr, srcPort, rssi); 108 nrk_led_set(GREEN_LED); 109 110 for(i = 0; i < len; i++) 111 printf("%c ", rx_buf[i]); 112 113 nrk_led_clr(GREEN_LED); 114 release_buffer(sock, rx_buf); 115 } 116 117 return; 118 } 119 120 void tx_task () 121 { 122 int8_t ret, len, cnt; 123 int8_t sock; 124 125 printf ("tx_task PID=%d\r\n", nrk_get_pid ()); 126 127 sock = create_socket(SOCK_DGRAM); 128 if(sock == NRK_ERROR) 129 printf("Error in creating socket %d\n", nrk_errno_get()); 130 cnt = 0; 131 132 while (1) 133 { 134 // Build a TX packet 135 sprintf (tx_buf, "This is a test %d", cnt); 136 cnt++; 137 nrk_led_set (BLUE_LED); 138 139 if(NODE_ADDR == 1) 140 send(sock, tx_buf, strlen(tx_buf), 2, SERVER2_PORT, NORMAL_PRIORITY); 141 else 142 send(sock, tx_buf, strlen(tx_buf), 1, SERVER1_PORT, NORMAL_PRIORITY); 143 144 nrk_kprintf (PSTR ("Tx packet enqueued\r\n")); 145 146 ret = wait_until_send_done(sock); 147 if(ret == NRK_ERROR) 148 printf("Error in waiting for send done signal %d\n", nrk_errno_get()); 149 150 // Task gets control again after TX complete 151 nrk_kprintf (PSTR ("Tx task sent data!\r\n")); 152 nrk_led_clr (BLUE_LED); 153 nrk_wait_until_next_period (); 154 } 155 156 return; 157 } 158 68 159 69 160 void nrk_create_taskset() … … 78 169 RX_TASK.SchType = PREEMPTIVE; 79 170 171 RX_TASK.cpu_reserve.secs = 4; 172 RX_TASK.cpu_reserve.nano_secs = 500*NANOS_PER_MS; 80 173 RX_TASK.period.secs = 3; 81 174 RX_TASK.period.nano_secs = 0; 82 RX_TASK.cpu_reserve.secs = 4; 83 RX_TASK.cpu_reserve.nano_secs = 500*NANOS_PER_MS; 84 175 85 176 RX_TASK.offset.secs = 0; 86 177 RX_TASK.offset.nano_secs= 0; … … 91 182 TX_TASK.Ptos = (void *) &tx_task_stack[NRK_APP_STACKSIZE-1]; 92 183 TX_TASK.Pbos = (void *) &tx_task_stack[0]; 93 TX_TASK.prio = 2;184 TX_TASK.prio = 4; 94 185 TX_TASK.FirstActivation = TRUE; 95 186 TX_TASK.Type = BASIC_TASK; … … 98 189 TX_TASK.cpu_reserve.secs = 3; 99 190 TX_TASK.cpu_reserve.nano_secs = 0; 100 TX_TASK.period.secs = TX_TASK.cpu_reserve.secs + 2;191 TX_TASK.period.secs = 4; 101 192 TX_TASK.period.nano_secs = 0; 102 193 … … 105 196 nrk_activate_task (&TX_TASK); 106 197 } 198 199 int main() 200 { 201 initialise(); 107 202 203 nrk_create_taskset(); // create the set of tasks 204 nrk_start(); // start this node 205 206 return 0; 207 } -
nano-RK/projects/network_stack/NWStackConfig.c
r103 r110 4 4 #include "NWErrorCodes.h" 5 5 #include <stdint.h> 6 #include <nrk.h> 7 #include <include.h> 8 #include <ulib.h> 9 #include <stdio.h> 10 #include <avr/sleep.h> 11 #include <hal.h> 12 #include <nrk_error.h> 13 #include <stdint.h> 14 15 #define DEBUG 2 6 16 7 17 … … 29 39 go_into_panic("Error in calculating endianness in init_nw_stack()"); 30 40 41 if(DEBUG == 2) 42 nrk_kprintf(PSTR("Before initialising buffer manager\n")); 31 43 initialise_buffer_manager(); 44 45 if(DEBUG == 2) 46 nrk_kprintf(PSTR("Before initialising transport layer\n")); 32 47 initialise_transport_layer_udp(); 48 49 if(DEBUG == 2) 50 nrk_kprintf(PSTR("Before initialising network layer\n")); 33 51 initialise_network_layer(); 34 52 -
nano-RK/projects/network_stack/NWStackConfig.h
r108 r110 5 5 6 6 7 #define MAX_APP_PAYLOAD 32// maximum size of the application payload in bytes8 #define MAX_SERIAL_PAYLOAD 32// maximum size of serial data payload9 #define MAX_RX_QUEUE_SIZE 10// maximum number of receive buffers available in the7 #define MAX_APP_PAYLOAD 16 // maximum size of the application payload in bytes 8 #define MAX_SERIAL_PAYLOAD 16 // maximum size of serial data payload 9 #define MAX_RX_QUEUE_SIZE 8 // maximum number of receive buffers available in the 10 10 // system for USER tasks 11 #define MAX_TX_QUEUE_SIZE 10// maximum size of transmit queue for the system11 #define MAX_TX_QUEUE_SIZE 8 // maximum size of transmit queue for the system 12 12 #define DEFAULT_EXCESS_POLICY OVERWRITE // excess policy default 13 13 -
nano-RK/projects/network_stack/makefile
r103 r110 1 1 # Platform name cc2420DK, firefly, micaZ 2 PLATFORM = firefly2 2 PLATFORM = firefly2_2 3 3 4 4 # Target file name (without extension).
Note: See TracChangeset
for help on using the changeset viewer.
