Show
Ignore:
Timestamp:
08/04/08 20:51:26 (5 months ago)
Author:
liamstask
Message:

- incorporate changes from freertos lwip 1.3 port - mostly changes to sys_arch.c, adding in more stats info

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • firmware/trunk/core/lwip/contrib/port/FreeRTOS/AT91SAM7X/sys_arch.c

    r688 r778  
    3939#include "lwip/sys.h" 
    4040#include "lwip/mem.h" 
    41  
    42 /* Message queue constants. */ 
    43 #define archMESG_QUEUE_LENGTH ( 6 ) 
    44 #define archPOST_BLOCK_TIME_MS  ( ( unsigned portLONG ) 10000 ) 
     41#include "lwip/stats.h" 
     42#include "lwipopts.h" 
    4543 
    4644struct timeoutlist  
     
    5149 
    5250/* This is the number of threads that can be started with sys_thread_new() */ 
    53 // #define SYS_THREAD_MAX 6 
    54  
    55 #define lwipTCP_STACK_SIZE      200 
    56 #define lwipBASIC_SERVER_STACK_SIZE 150 
     51//#define SYS_THREAD_MAX 4 
    5752 
    5853// static struct timeoutlist timeoutlist[SYS_THREAD_MAX]; 
     
    7671  mbox = xQueueCreate( archMESG_QUEUE_LENGTH, sizeof( void * ) ); 
    7772 
     73#if SYS_STATS 
     74      ++lwip_stats.sys.mbox.used; 
     75      if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) { 
     76         lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used; 
     77    } 
     78#endif /* SYS_STATS */ 
     79 
    7880  return mbox; 
    7981} 
     
    9193  { 
    9294    /* Line for breakpoint.  Should never break here! */ 
    93     __asm volatile ( "NOP" ); 
     95    portNOP(); 
     96#if SYS_STATS 
     97      lwip_stats.sys.mbox.err++; 
     98#endif /* SYS_STATS */ 
    9499  } 
    95100 
    96101  vQueueDelete( mbox );  
     102 
     103#if SYS_STATS 
     104     --lwip_stats.sys.mbox.used; 
     105#endif /* SYS_STATS */ 
    97106} 
    98107 
     
    107116/*-----------------------------------------------------------------------------------*/ 
    108117// MakingThings - added for lwip 1.3.0 
    109 //  Posts the "msg" to the mailbox. This function have to block until 
    110 //  the "msg" is really posted. 
     118//  Posts the "msg" to the mailbox. 
    111119err_t  
    112120sys_mbox_trypost(sys_mbox_t mbox, void *msg) 
    113 {    
    114   portBASE_TYPE result = xQueueSend( mbox, &msg, ( portTickType ) ( archPOST_BLOCK_TIME_MS / portTICK_RATE_MS ) ); 
    115   while( result == errQUEUE_FULL) 
    116   { 
    117     vTaskDelay(1); 
    118     result = xQueueSend( mbox, &msg, ( portTickType ) ( archPOST_BLOCK_TIME_MS / portTICK_RATE_MS ) ); 
    119   } 
    120   return ERR_OK; 
     121{ 
     122err_t result; 
     123 
     124   if ( xQueueSend( mbox, &msg, 0 ) == pdPASS )  
     125   { 
     126      result = ERR_OK; 
     127   } 
     128   else { 
     129      // could not post, queue must be full 
     130      result = ERR_MEM; 
     131#if SYS_STATS 
     132      lwip_stats.sys.mbox.err++; 
     133#endif /* SYS_STATS */ 
     134   } 
     135 
     136   return result; 
    121137} 
    122138 
     
    185201 
    186202/*-----------------------------------------------------------------------------------*/ 
     203/* 
     204  Similar to sys_arch_mbox_fetch, but if message is not ready immediately, we'll 
     205  return with SYS_MBOX_EMPTY.  On success, 0 is returned. 
     206*/ 
     207u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) 
     208{ 
     209void *dummyptr; 
     210 
     211  if ( msg == NULL ) 
     212  { 
     213    msg = &dummyptr; 
     214  } 
     215    
     216   if ( pdTRUE == xQueueReceive( mbox, &(*msg), 0 ) )  
     217   { 
     218      return ERR_OK; 
     219   } 
     220   else  
     221   { 
     222      return SYS_MBOX_EMPTY;    
     223   } 
     224} 
     225 
     226/*-----------------------------------------------------------------------------------*/ 
    187227//  Creates and returns a new semaphore. The "count" argument specifies 
    188228//  the initial state of the semaphore. TBD finish and test 
     
    202242  if( xSemaphore == NULL ) 
    203243  { 
     244#if SYS_STATS 
     245      ++lwip_stats.sys.sem.err; 
     246#endif /* SYS_STATS */ 
    204247    return NULL;  // TBD need assert 
    205248  } 
    206249  else 
    207250  { 
     251#if SYS_STATS 
     252      ++lwip_stats.sys.sem.used; 
     253      if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) { 
     254         lwip_stats.sys.sem.max = lwip_stats.sys.sem.used; 
     255    } 
     256#endif /* SYS_STATS */ 
    208257    return xSemaphore; 
    209258  } 
     
    281330sys_sem_free(sys_sem_t sem) 
    282331{ 
     332#if SYS_STATS 
     333      --lwip_stats.sys.sem.used; 
     334#endif /* SYS_STATS */ 
    283335  vQueueDelete( sem );  
    284336}