Changeset 110


Ignore:
Timestamp:
06/25/2007 02:37:22 PM (5 years ago)
Author:
ayb
Message:
 
Location:
nano-RK/projects/network_stack
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nano-RK/projects/network_stack/App.c

    r103 r110  
    88#include <hal.h> 
    99#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  
    1026 
    1127nrk_task_type RX_TASK; 
     
    1632NRK_STK tx_task_stack[NRK_APP_STACKSIZE]; 
    1733void tx_task(void); 
     34 
     35/**************************************************************************************/ 
     36uint8_t tx_buf[PAYLOAD]; 
     37 
     38/**************************************************************************************/ 
    1839 
    1940void initialise() 
     
    2849        // clear all LEDs        
    2950        // 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 
    3055        nrk_led_clr(ORANGE_LED);                 
    3156   nrk_led_clr(BLUE_LED);                       // will toggle whenever a packet is sent 
     
    3661        nrk_time_set(0,0); 
    3762 
    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(); 
    4766                  
    4867        return; 
    4968} 
    5069 
    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 }        
     70void 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                         
     120void 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 
    68159 
    69160void nrk_create_taskset() 
     
    78169  RX_TASK.SchType = PREEMPTIVE; 
    79170   
     171  RX_TASK.cpu_reserve.secs = 4; 
     172  RX_TASK.cpu_reserve.nano_secs = 500*NANOS_PER_MS;   
    80173  RX_TASK.period.secs = 3; 
    81174  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     
    85176  RX_TASK.offset.secs = 0; 
    86177  RX_TASK.offset.nano_secs= 0; 
     
    91182  TX_TASK.Ptos = (void *) &tx_task_stack[NRK_APP_STACKSIZE-1]; 
    92183  TX_TASK.Pbos = (void *) &tx_task_stack[0]; 
    93   TX_TASK.prio = 2; 
     184  TX_TASK.prio = 4; 
    94185  TX_TASK.FirstActivation = TRUE; 
    95186  TX_TASK.Type = BASIC_TASK; 
     
    98189  TX_TASK.cpu_reserve.secs = 3; 
    99190  TX_TASK.cpu_reserve.nano_secs = 0;     
    100   TX_TASK.period.secs = TX_TASK.cpu_reserve.secs + 2; 
     191  TX_TASK.period.secs = 4; 
    101192  TX_TASK.period.nano_secs = 0; 
    102193   
     
    105196  nrk_activate_task (&TX_TASK); 
    106197} 
     198 
     199int main() 
     200{ 
     201        initialise(); 
    107202         
     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  
    44#include "NWErrorCodes.h" 
    55#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  
    616 
    717 
     
    2939                go_into_panic("Error in calculating endianness in init_nw_stack()"); 
    3040                 
     41        if(DEBUG == 2) 
     42                nrk_kprintf(PSTR("Before initialising buffer manager\n")); 
    3143        initialise_buffer_manager(); 
     44         
     45        if(DEBUG == 2) 
     46                nrk_kprintf(PSTR("Before initialising transport layer\n")); 
    3247        initialise_transport_layer_udp(); 
     48         
     49        if(DEBUG == 2) 
     50                nrk_kprintf(PSTR("Before initialising network layer\n")); 
    3351        initialise_network_layer(); 
    3452         
  • nano-RK/projects/network_stack/NWStackConfig.h

    r108 r110  
    55 
    66 
    7 #define MAX_APP_PAYLOAD  32                                     // maximum size of the application payload in bytes  
    8 #define MAX_SERIAL_PAYLOAD 32                                   // maximum size of serial data payload 
    9 #define MAX_RX_QUEUE_SIZE 10                                    // maximum number of receive buffers available in the  
     7#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  
    1010                                                                                                                // system for USER tasks  
    11 #define MAX_TX_QUEUE_SIZE 10                            // maximum size of transmit queue for the system  
     11#define MAX_TX_QUEUE_SIZE 8                             // maximum size of transmit queue for the system  
    1212#define DEFAULT_EXCESS_POLICY OVERWRITE // excess policy default 
    1313 
  • nano-RK/projects/network_stack/makefile

    r103 r110  
    11# Platform name  cc2420DK, firefly, micaZ 
    2 PLATFORM = firefly2 
     2PLATFORM = firefly2_2 
    33 
    44# Target file name (without extension). 
Note: See TracChangeset for help on using the changeset viewer.