Changeset 114


Ignore:
Timestamp:
06/28/2007 01:59:37 AM (5 years ago)
Author:
agr
Message:

First pass at SLIPstream SLIP to UDP interface

Location:
nano-RK
Files:
8 added
15 edited

Legend:

Unmodified
Added
Removed
  • nano-RK/projects/basic_sensors/makefile

    r107 r114  
    11# Platform name  cc2420DK, firefly, micaZ, firefly2, firefly2_2 
    2 PLATFORM = firefly2 
     2PLATFORM = firefly2_2 
    33 
    44 
  • nano-RK/projects/basic_signals/makefile

    r50 r114  
    11# Platform name  cc2420DK, firefly, micaZ, firefly2, firefly2_2 
    2 PLATFORM = firefly2 
     2PLATFORM = firefly2_2 
    33 
    44 
  • nano-RK/projects/basic_slip/main.c

    r47 r114  
    99#include <slip.h> 
    1010 
     11#define MAX_SLIP_BUF 48 
    1112 
    1213NRK_STK Stack1[NRK_APP_STACKSIZE]; 
    1314nrk_task_type TaskOne; 
    14 void Task1(void); 
     15void Task1 (void); 
    1516 
    1617NRK_STK Stack2[NRK_APP_STACKSIZE]; 
     
    2223void Task3 (void); 
    2324 
     25void nrk_create_taskset (); 
    2426 
    25 NRK_STK Stack4[NRK_APP_STACKSIZE]; 
    26 nrk_task_type TaskFour; 
    27 void Task4 (void); 
     27uint8_t slip_buf[MAX_SLIP_BUF]; 
    2828 
    29 void nrk_create_taskset(); 
    30 uint8_t kill_stack(uint8_t val); 
     29int main () 
     30{ 
     31  nrk_setup_ports (); 
     32//  PORTE |= 2; 
     33//  DDRA &= ~(0x10); 
     34  nrk_setup_uart (UART_BAUDRATE_115K2); 
    3135 
    32 int 
    33 main () 
    34 { 
    35   nrk_setup_ports(); 
    36   PORTE |= 2; 
    37   DDRA &= ~(0x10); 
    38   nrk_setup_uart(UART_BAUDRATE_9K6); 
     36  printf ("Starting up...\r\n"); 
    3937 
    40   printf( "Starting up...\r\n" ); 
     38  nrk_init (); 
    4139 
    42   nrk_init(); 
     40  nrk_led_clr (ORANGE_LED); 
     41  nrk_led_clr (BLUE_LED); 
     42  nrk_led_clr (GREEN_LED); 
     43  nrk_led_clr (RED_LED); 
    4344 
    44   nrk_led_clr(ORANGE_LED); 
    45   nrk_led_clr(BLUE_LED); 
    46   nrk_led_clr(GREEN_LED); 
    47   nrk_led_clr(RED_LED); 
     45  nrk_time_set (0, 0); 
     46  nrk_create_taskset (); 
     47  nrk_start (); 
    4848 
    49   nrk_time_set(0,0); 
    50   nrk_create_taskset (); 
    51   nrk_start(); 
    52    
    5349  return 0; 
    5450} 
    5551 
    5652 
    57 void Task1() 
     53void Task1 () 
    5854{ 
    59 uint16_t cnt; 
    60 uint8_t buf[32]; 
    61 printf( "My node's address is %d\r\n",NODE_ADDR ); 
     55  uint16_t cnt; 
     56  uint8_t buf[32], len; 
     57  printf ("My node's address is %d\r\n", NODE_ADDR); 
    6258 
    63   printf( "Task1 PID=%d\r\n",nrk_get_pid()); 
    64   cnt=0; 
    65   slip_init(stdin,stdout,0,0); 
    66   while(1) { 
    67         nrk_led_set(ORANGE_LED); 
    68         buf[0]=66; 
    69         buf[1]=(cnt>>8)&0xFF; 
    70         buf[2]=cnt&0xFF; 
    71         slip_tx(buf,3);  
    72         nrk_wait_until_next_period(); 
    73         nrk_led_clr(ORANGE_LED); 
    74         nrk_wait_until_next_period(); 
    75         cnt++; 
    76         } 
     59  printf ("Task1 PID=%d\r\n", nrk_get_pid ()); 
     60  cnt = 0; 
     61  slip_init (stdin, stdout, 0, 0); 
     62 
     63  while (1) { 
     64    nrk_led_set (ORANGE_LED); 
     65    sprintf (buf, "Hello %d", cnt); 
     66    len = strlen (buf); 
     67    slip_tx (buf, len); 
     68    nrk_wait_until_next_period (); 
     69    nrk_led_clr (ORANGE_LED); 
     70    nrk_wait_until_next_period (); 
     71    cnt++; 
     72  } 
    7773} 
    7874 
    79 void Task2() 
     75void Task2 () 
    8076{ 
    8177  uint8_t cnt; 
    82   printf( "Task2 PID=%d\r\n",nrk_get_pid()); 
    83   cnt=0; 
    84   while(1) { 
    85         nrk_led_set(BLUE_LED); 
    86         printf( "Task2 cnt=%d\r\n",cnt ); 
    87         nrk_wait_until_next_period(); 
    88         nrk_led_clr(BLUE_LED); 
    89         nrk_wait_until_next_period(); 
    90         cnt++; 
    91         } 
     78  printf ("Task2 PID=%d\r\n", nrk_get_pid ()); 
     79  cnt = 0; 
     80  while (1) { 
     81    nrk_led_set (BLUE_LED); 
     82    printf ("Task2 cnt=%d\r\n", cnt); 
     83    nrk_wait_until_next_period (); 
     84    nrk_led_clr (BLUE_LED); 
     85    nrk_wait_until_next_period (); 
     86    cnt++; 
     87  } 
    9288} 
    9389 
    94 void Task3() 
     90void Task3 () 
    9591{ 
    96 uint16_t cnt; 
     92  int8_t v; 
     93  int8_t i; 
     94  printf ("Task3 PID=%d\r\n", nrk_get_pid ()); 
     95  while (slip_started () != 1) 
     96    nrk_wait_until_next_period (); 
    9797 
    98   printf( "Task3 PID=%d\r\n",nrk_get_pid()); 
    99   cnt=0; 
    100   while(1) { 
    101         nrk_led_set(GREEN_LED); 
    102         printf( "Task3 cnt=%d\r\n",cnt ); 
    103         nrk_wait_until_next_period(); 
    104         nrk_led_clr(GREEN_LED); 
    105         nrk_wait_until_next_period(); 
    106         cnt++; 
    107         } 
     98  while (1) { 
     99    nrk_led_toggle (GREEN_LED); 
     100    printf ("Task3\r\n"); 
     101 
     102    v = slip_rx (slip_buf, MAX_SLIP_BUF); 
     103 
     104    if (v > 0) { 
     105      nrk_kprintf (PSTR ("Task3 got data: ")); 
     106      for (i = 0; i < v; i++) 
     107        printf ("%c", slip_buf[i]); 
     108      printf ("\r\n"); 
     109    } 
     110    else 
     111      nrk_kprintf (PSTR ("Task3 data failed\r\n")); 
     112 
     113    nrk_wait_until_next_period (); 
     114  } 
    108115} 
    109116 
    110 void Task4() 
    111 { 
    112 uint16_t cnt; 
    113117 
    114   printf( "Task4 PID=%d\r\n",nrk_get_pid()); 
    115   cnt=0; 
    116   while(1) { 
    117         nrk_led_set(RED_LED); 
    118         printf( "Task4 cnt=%d\r\n",cnt ); 
    119         nrk_wait_until_next_period(); 
    120         nrk_led_clr(RED_LED); 
    121         nrk_wait_until_next_period(); 
    122         cnt++; 
    123         } 
    124 } 
    125118 
    126 void 
    127 nrk_create_taskset() 
     119void nrk_create_taskset () 
    128120{ 
    129121  TaskOne.task = Task1; 
    130   TaskOne.Ptos = (void *) &Stack1[NRK_APP_STACKSIZE]; 
     122  TaskOne.Ptos = (void *) &Stack1[NRK_APP_STACKSIZE - 1]; 
    131123  TaskOne.Pbos = (void *) &Stack1[0]; 
    132124  TaskOne.prio = 1; 
     
    135127  TaskOne.SchType = PREEMPTIVE; 
    136128  TaskOne.period.secs = 1; 
    137   TaskOne.period.nano_secs = 500*NANOS_PER_MS; 
     129  TaskOne.period.nano_secs = 500 * NANOS_PER_MS; 
    138130  TaskOne.cpu_reserve.secs = 0; 
    139   TaskOne.cpu_reserve.nano_secs =  500*NANOS_PER_MS; 
     131  TaskOne.cpu_reserve.nano_secs = 500 * NANOS_PER_MS; 
    140132  TaskOne.offset.secs = 0; 
    141   TaskOne.offset.nano_secs= 0; 
     133  TaskOne.offset.nano_secs = 0; 
    142134  nrk_activate_task (&TaskOne); 
    143135 
    144136  TaskTwo.task = Task2; 
    145   TaskTwo.Ptos = (void *) &Stack2[NRK_APP_STACKSIZE]; 
     137  TaskTwo.Ptos = (void *) &Stack2[NRK_APP_STACKSIZE - 1]; 
    146138  TaskTwo.Pbos = (void *) &Stack2[0]; 
    147139  TaskTwo.prio = 2; 
     
    150142  TaskTwo.SchType = PREEMPTIVE; 
    151143  TaskTwo.period.secs = 0; 
    152   TaskTwo.period.nano_secs = 500*NANOS_PER_MS; 
     144  TaskTwo.period.nano_secs = 250 * NANOS_PER_MS; 
    153145  TaskTwo.cpu_reserve.secs = 0; 
    154   TaskTwo.cpu_reserve.nano_secs = 100*NANOS_PER_MS; 
     146  TaskTwo.cpu_reserve.nano_secs = 100 * NANOS_PER_MS; 
    155147  TaskTwo.offset.secs = 0; 
    156   TaskTwo.offset.nano_secs= 0; 
    157   //nrk_activate_task (&TaskTwo); 
    158  
     148  TaskTwo.offset.nano_secs = 0; 
     149  nrk_activate_task (&TaskTwo); 
    159150 
    160151  TaskThree.task = Task3; 
    161   TaskThree.Ptos = (void *) &Stack3[NRK_APP_STACKSIZE]; 
     152  TaskThree.Ptos = (void *) &Stack3[NRK_APP_STACKSIZE - 1]; 
    162153  TaskThree.Pbos = (void *) &Stack3[0]; 
    163154  TaskThree.prio = 3; 
     
    166157  TaskThree.SchType = PREEMPTIVE; 
    167158  TaskThree.period.secs = 0; 
    168   TaskThree.period.nano_secs = 750*NANOS_PER_MS; 
     159  TaskThree.period.nano_secs = 250 * NANOS_PER_MS; 
    169160  TaskThree.cpu_reserve.secs = 0; 
    170   TaskThree.cpu_reserve.nano_secs = 100*NANOS_PER_MS; 
     161  TaskThree.cpu_reserve.nano_secs = 100 * NANOS_PER_MS; 
    171162  TaskThree.offset.secs = 0; 
    172   TaskThree.offset.nano_secs= 0; 
    173   //nrk_activate_task (&TaskThree); 
     163  TaskThree.offset.nano_secs = 0; 
     164  nrk_activate_task (&TaskThree); 
    174165 
    175166 
    176   TaskFour.task = Task4; 
    177   TaskFour.Ptos = (void *) &Stack4[NRK_APP_STACKSIZE]; 
    178   TaskFour.Pbos = (void *) &Stack4[0]; 
    179   TaskFour.prio = 4; 
    180   TaskFour.FirstActivation = TRUE; 
    181   TaskFour.Type = BASIC_TASK; 
    182   TaskFour.SchType = PREEMPTIVE; 
    183   TaskFour.period.secs = 1; 
    184   TaskFour.period.nano_secs = 0; 
    185   TaskFour.cpu_reserve.secs = 0; 
    186   TaskFour.cpu_reserve.nano_secs = 100*NANOS_PER_MS; 
    187   TaskFour.offset.secs = 0; 
    188   TaskFour.offset.nano_secs= 0; 
    189   //nrk_activate_task (&TaskFour); 
    190167 
    191  
    192   //printf ("Create done\r\n"); 
    193168} 
    194  
    195 uint8_t kill_stack(uint8_t val) 
    196 { 
    197 char bad_memory[10]; 
    198 uint8_t i; 
    199 for(i=0; i<10; i++ ) bad_memory[i]=i; 
    200 for(i=0; i<10; i++ ) printf( "%d ", bad_memory[i]); 
    201    printf( "Die Stack %d\r\n",val ); 
    202 if(val>1) kill_stack(val-1); 
    203 return 0; 
    204 } 
    205  
    206  
  • nano-RK/projects/basic_slip/makefile

    r38 r114  
    11# Platform name  cc2420DK, firefly, micaZ, firefly2, firefly2_2 
    2 PLATFORM = firefly2 
     2PLATFORM = firefly2_2 
    33 
    44 
  • nano-RK/projects/basic_slip/nrk_cfg.h

    r39 r114  
    2222#define NRK_NO_POWER_DOWN 
    2323 
    24 #define NRK_MAX_TASKS                   1    // Max number of tasks in your application 
    25 #define NRK_N_SYS_TASKS                 1    // you need at least the idle task 
    26 #define NRK_N_RES                       1        
    27                             
    28 //#define NRK_DRIVER_FREQ                      250 
    29 //#define NRK_MAX_DRIVER_CNT           1         
     24// This must be greater than or equal to the highest priority task that uses 
     25// the serial port (i.e. print of nrk_kprintf) 
     26#define SLIP_PCP_CEILING                18       
     27 
     28// Enable buffered and signal controlled serial RX 
     29#define NRK_UART_BUF   1 
     30// Set buffer to MAX slip packet size 
     31#define MAX_RX_UART_BUF 128  
     32 
     33 
     34#define NRK_MAX_TASKS                   4    // Max number of tasks in your application 
     35                           
     36// Slip uses a single semaphore to control UART access  
     37#define NRK_MAX_RESOURCE_CNT           2 
    3038 
    3139#define NRK_TASK_IDLE_STK_SIZE         128 // Idle task stack size min=32  
    3240#define NRK_APP_STACKSIZE              128  
    3341#define NRK_KERNEL_STACKSIZE           128  
    34 #define NRK_MAX_RESOURCE_CNT           1 
    3542 
    3643 
    37 #define NRK_MBOX_EN                     0    // Include code for MAILBOXES  
    38 #define NRK_Q_EN                        0    // Include code for QUEUES   
    39 #define NRK_SEM_EN                      0    // Include code for SEMAPHORES  
    40 #define NRK_TASK_CHANGE_PRIO_EN         0    // Include code for OSTaskChangePrio()   
    41  
    42  
    43 #define NRK_STAT_EXT                    0    // Extended Status for OS  
    44  
    4544#endif 
  • nano-RK/src/drivers/platform/firefly2_2/source/adc_driver.c

    r99 r114  
    6060                    if(opt&READ_FLAG) 
    6161                    { 
    62                         RETURN NRK_OK;  
     62                        return NRK_OK;  
    6363                    } 
    6464                    if(opt&WRITE_FLAG) 
    6565                    { 
    66                         RETURN NRK_ERROR;  
     66                        return NRK_ERROR;  
    6767                    } 
    6868                    if(opt&APPEND_FLAG) 
    6969                    { 
    70                         RETURN NRK_ERROR;  
     70                        return NRK_ERROR;  
    7171                    } 
    7272                    if(opt&(READ_FLAG|WRITE_FLAG|APPEND_FLAG)==0) 
     
    8181                              /* Conversion to 8-bit value*/ 
    8282                              uint16_t val=get_adc_val(); 
    83                               buffer[count]=val >>2 & 0xFF; 
     83                              buffer[count]=val >> 2 & 0xFF; 
    8484                      } 
    8585                      return count; 
  • nano-RK/src/drivers/platform/firefly2_2/source/ff_basic_sensor.c

    r99 r114  
    8989                              /* Conversion to 8-bit value*/ 
    9090                              uint16_t val=get_adc_val(); 
    91                               buffer[count]=val >>2 & 0xFF; 
     91                              buffer[count]=val & 0xFF; 
    9292                      count++; 
    9393                      return count; 
  • nano-RK/src/kernel/include/nrk_error.h

    r54 r114  
    5454#define NRK_UNIMPLEMENTED               13       
    5555#define NRK_SIGNAL_CREATE_ERROR         14 
    56 #define NRK_NUM_ERRORS                  15 
     56#define NRK_SEMAPHORE_CREATE_ERROR      15 
     57#define NRK_NUM_ERRORS                  16 
    5758typedef uint8_t NRK_ERRNO; 
    5859 
  • nano-RK/src/kernel/include/nrk_events.h

    r91 r114  
    5959int8_t nrk_sem_post(uint8_t* rsrc); 
    6060int8_t nrk_sem_pend(uint8_t *rsrc ); 
     61int8_t nrk_sem_query(uint8_t *rsrc ); 
    6162 
    6263 
  • nano-RK/src/kernel/source/nrk_error.c

    r97 r114  
    150150      nrk_kprintf (PSTR ("Failed to create Signal")); 
    151151      break; 
     152    case NRK_SEMAPHORE_CREATE_ERROR: 
     153      nrk_kprintf (PSTR ("Failed to create Semaphore")); 
     154      break; 
    152155    default: 
    153156      nrk_kprintf (PSTR ("UNKOWN")); 
  • nano-RK/src/kernel/source/nrk_events.c

    r97 r114  
    208208} 
    209209 
     210int8_t nrk_sem_query(uint8_t *rsrc ) 
     211{ 
     212        int8_t id; 
     213        id=nrk_get_resource_index(rsrc);   
     214        if(id==-1) { _nrk_errno_set(1); return NRK_ERROR;} 
     215        if(id==NRK_MAX_RESOURCE_CNT) { _nrk_errno_set(2); return NRK_ERROR; } 
     216         
     217        return(nrk_resource_value[id]); 
     218} 
     219 
     220 
    210221 
    211222int8_t nrk_sem_pend(uint8_t *rsrc ) 
  • nano-RK/src/net/slip/slip.c

    r39 r114  
    11#include "slip.h" 
     2#include <nrk_events.h> 
     3#include <nrk_error.h> 
     4#include <nrk_cfg.h> 
    25 
    36 
     
    58bool g_echo; 
    69uint8_t g_delay; 
     10int8_t _slip_started = NRK_ERROR; 
     11nrk_sem_t *slip_tx_sem; 
    712 
    8 uint8_t slip_init( FILE *device_in, FILE *device_out, bool echo, uint8_t delay ) 
     13int8_t slip_init (FILE * device_in, FILE * device_out, bool echo, 
     14                  uint8_t delay) 
    915{ 
    10 g_dv_in=device_in; 
    11 g_dv_out=device_out; 
    12 g_echo=echo; 
    13 g_delay=delay; 
     16  g_dv_in = device_in; 
     17  g_dv_out = device_out; 
     18  g_echo = echo; 
     19  g_delay = delay; 
    1420 
    15 return 1; 
     21 
     22#ifndef UART_PCP_CEILING 
     23#define UART_PCP_CEILING       255 
     24#endif 
     25  slip_tx_sem = nrk_sem_create (1, UART_PCP_CEILING); 
     26  if (slip_tx_sem == NRK_ERROR) 
     27    nrk_kernel_error_add (NRK_SEMAPHORE_CREATE_ERROR, nrk_get_pid ()); 
     28 
     29  _slip_started = NRK_OK; 
     30  return NRK_OK; 
    1631} 
    1732 
    18 void put_byte(uint8_t c) 
     33void put_byte (uint8_t c) 
    1934{ 
    20    if(g_delay>0 ) nrk_spin_wait_us(g_delay*1000); 
    21    fputc(c,g_dv_out); 
    22    if(g_echo) 
    23         { 
    24         // Not IMPLEMENTED 
    25         } 
     35  if (g_delay > 0) 
     36    nrk_spin_wait_us (g_delay * 1000); 
     37  fputc (c, g_dv_out); 
     38  if (g_echo) { 
     39    // Not IMPLEMENTED 
     40  } 
    2641} 
    2742 
    28 uint8_t get_byte(void) 
     43uint8_t get_byte (void) 
    2944{ 
    30   return fgetc(g_dv_in); 
     45  return fgetc (g_dv_in); 
    3146} 
    3247 
    33 uint8_t slip_tx(uint8_t *buf, uint8_t size) 
     48int8_t slip_tx (uint8_t * buf, uint8_t size) 
    3449{ 
    35 uint8_t i; 
     50  uint8_t i; 
     51  int8_t v; 
     52  uint8_t checksum; 
     53 
     54// Make sure size is less than 128 so it doesn't act as a control 
     55// message 
     56  if (size > 128) { 
     57    _nrk_errno_set (3); 
     58    return NRK_ERROR; 
     59  } 
     60 
     61  v = nrk_sem_pend (slip_tx_sem); 
     62  if (v == NRK_ERROR) { 
     63    nrk_kprintf (PSTR ("SLIP TX ERROR:  Access to semaphore failed\r\n")); 
     64    _nrk_errno_set (1); 
     65    return NRK_ERROR; 
     66  } 
    3667 
    3768// Send the start byte 
    38 put_byte(END); 
     69  put_byte (START); 
     70  put_byte (size); 
     71 
     72  checksum = 0; 
     73 
    3974// Send payload and stuff bytes as needed 
    40 for(i=0; i<size; i++ ) 
    41    { 
    42         if(buf[i]==END || buf[i]==ESC) put_byte(ESC); 
    43         put_byte(buf[i]); 
    44    } 
    45  // Send the end byte 
    46 put_byte(END); 
     75  for (i = 0; i < size; i++) { 
     76    if (buf[i] == END || buf[i] == ESC) 
     77      put_byte (ESC); 
     78    put_byte (buf[i]); 
     79    checksum += buf[i]; 
     80  } 
    4781 
     82// Make sure checksum is less than 128 so it doesn't act as a control 
     83// message 
     84  checksum &= 0x7F; 
     85  // Send the end byte 
     86  put_byte (checksum); 
     87  put_byte (END); 
     88  v = nrk_sem_post (slip_tx_sem); 
     89  if (v == NRK_ERROR) { 
     90    nrk_kprintf (PSTR ("SLIP TX ERROR:  Release of semaphore failed\r\n")); 
     91    _nrk_errno_set (2); 
     92    return NRK_ERROR; 
     93  } 
     94  return NRK_OK; 
    4895} 
    4996 
    50 uint8_t slip_rx(uint8_t *buf,uint8_t max_len ) 
     97int8_t slip_started () 
    5198{ 
    52 uint8_t c; 
    53 uint8_t index; 
    54 uint8_t received; 
    55 bool start_flag; 
    56  
    57 received=0; 
    58 start_flag=0; 
    59 // Wait until you receive the packet start (END) command 
    60 while(1){ 
    61   c=get_byte(); 
    62   if(start_flag && c==END ) break; 
    63   if(c==ESC) start_flag=1; 
    64   else start_flag=0; 
     99  return _slip_started; 
    65100} 
    66101 
    67            while(1) { 
    68                    // get a character to process 
    69                    c = get_byte(); 
     102int8_t slip_rx (uint8_t * buf, uint8_t max_len) 
     103{ 
     104  uint8_t c; 
     105  uint8_t index, last_c; 
     106  uint8_t received, checksum, size; 
     107  nrk_sig_t uart_rx_signal; 
     108  nrk_sig_mask_t sm; 
    70109 
    71                    // handle bytestuffing if necessary 
    72                    switch(c) { 
     110// Register your task to wakeup on RX Data 
     111  if (uart_rx_signal == NRK_ERROR) 
     112    nrk_kprintf (PSTR ("Get Signal ERROR!\r\n")); 
     113  nrk_signal_register (uart_rx_signal); 
    73114 
    74                    // if it's an END character then we're done with 
    75                    // the packet 
    76                    case END: 
    77                            // a minor optimization: if there is no 
    78                            // data in the packet, ignore it. This is 
    79                            // meant to avoid bothering IP with all 
    80                            // the empty packets generated by the 
    81                            // duplicate END characters which are in 
    82                            // turn sent to try to detect line noise. 
    83                            if(received) 
    84                                    return received; 
    85                            else 
    86                                    break; 
    87115 
    88                    // if it's the same code as an ESC character, wait 
    89                    // and get another character and then figure out 
    90                    // what to store in the packet based on that. 
    91                    case ESC: 
    92                            c = get_byte(); 
    93                            // if "c" is not one of these two, then we 
    94                            // have a protocol violation.  The best bet 
    95                            // seems to be to leave the byte alone and 
    96                            // just stuff it into the packet 
    97                            switch(c) { 
    98                            case END: 
    99                                    c = END; 
    100                                    break; 
    101                            case ESC: 
    102                                    c = ESC; 
    103                                    break; 
    104                                    } 
    105116 
    106                    // here we fall into the default handler and let 
    107                    // it store the character for us 
    108                    default: 
    109                            if(received < max_len) 
    110                                    buf[received++] = c; 
    111                            } 
    112                    } 
     117  received = 0; 
     118 
     119// Wait until you receive the packet start (START) command 
     120  while (1) { 
     121    // Wait for UART signal 
     122    while (nrk_uart_data_ready (NRK_DEFAULT_UART) != 0) { 
     123      // Read Character 
     124      c = getchar (); 
     125      if (c == START) 
     126        break; 
     127      //printf( "%c",c); 
     128    } 
     129    sm = nrk_event_wait (SIG (uart_rx_signal)); 
     130//  c=get_byte(); 
     131    if (c == START) 
     132      break; 
     133  } 
     134 
     135  size = get_byte (); 
     136  checksum = 0; 
     137  while (1) { 
     138    while (nrk_uart_data_ready (NRK_DEFAULT_UART) != 0) { 
     139      last_c = c; 
     140      c = getchar (); 
     141 
     142 
     143      // handle bytestuffing if necessary 
     144      switch (c) { 
     145 
     146        // if it's an END character then we're done with 
     147        // the packet 
     148      case END: 
     149        // a minor optimization: if there is no 
     150        // data in the packet, ignore it. This is 
     151        // meant to avoid bothering IP with all 
     152        // the empty packets generated by the 
     153        // duplicate END characters which are in 
     154        // turn sent to try to detect line noise. 
     155        if (received) { 
     156          checksum &= 0x7f; 
     157          if (last_c == checksum) 
     158            return received; 
     159        } 
     160        return NRK_ERROR; 
     161        break; 
     162 
     163        // if it's the same code as an ESC character, wait 
     164        // and get another character and then figure out 
     165        // what to store in the packet based on that. 
     166      case ESC: 
     167        // FIXME: Need to sleep here 
     168        last_c = c; 
     169        c = get_byte (); 
     170        // if "c" is not one of these two, then we 
     171        // have a protocol violation.  The best bet 
     172        // seems to be to leave the byte alone and 
     173        // just stuff it into the packet 
     174        switch (c) { 
     175        case END: 
     176          c = END; 
     177          break; 
     178        case ESC: 
     179          c = ESC; 
     180          break; 
     181        } 
     182 
     183        // here we fall into the default handler and let 
     184        // it store the character for us 
     185      default: 
     186        if (received < max_len && received < size) { 
     187          buf[received++] = c; 
     188          checksum += c; 
     189        } 
     190      } 
     191    } 
     192    sm = nrk_event_wait (SIG (uart_rx_signal)); 
     193  } 
    113194 
    114195 
    115196} 
    116  
  • nano-RK/src/net/slip/slip.h

    r39 r114  
    99#define ESC     219 
    1010#define END     192      
     11#define START   193      
    1112 
    12  
    13 uint8_t slip_init( FILE *device_in, FILE *device_out, bool echo, uint8_t delay ); 
    14 uint8_t slip_tx(uint8_t *buf, uint8_t size);  
    15 uint8_t slip_rx(uint8_t *buf, uint8_t max_len);  
     13int8_t slip_started(); 
     14int8_t slip_init( FILE *device_in, FILE *device_out, bool echo, uint8_t delay ); 
     15int8_t slip_tx(uint8_t *buf, uint8_t size);  
     16int8_t slip_rx(uint8_t *buf, uint8_t max_len);  
    1617void put_byte(uint8_t c); 
    1718uint8_t get_byte(void); 
  • nano-RK/src/platform/firefly2_2/source/ulib.c

    r94 r114  
    77#include <nrk_pin_define.h> 
    88#include <nrk_error.h> 
     9#include <nrk_events.h> 
    910 
    1011#ifdef NANORK 
     
    1819#define MAX_RX_UART_BUF    16 
    1920#endif 
     21 
    2022 
    2123uint8_t uart_rx_buf_start,uart_rx_buf_end; 
     
    404406} 
    405407 
     408 
     409 
    406410/** 
    407411 * nrk_setup_uart() 
     
    421425  stdout = fdevopen( putc1, getc1); 
    422426  stdin = fdevopen( putc1, getc1); 
     427 
    423428#ifdef NRK_UART_BUF 
    424429   uart_rx_signal=nrk_signal_create(); 
  • nano-RK/src/platform/include/ulib.h

    r83 r114  
    1515void nrk_setup_ports(); 
    1616void nrk_setup_uart(uint16_t baudrate); 
    17  
    1817 
    1918 
Note: See TracChangeset for help on using the changeset viewer.