Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

sys.h File Reference

#include "arch/cc.h"
#include "arch/sys_arch.h"

Include dependency graph for sys.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* sys_timeout_handler )(int signo)

Functions

void sys_init (void)
void sys_timeout (u16_t msecs, sys_timeout_handler h, void *arg)
sys_timeoutssys_arch_timeouts (void)
void sys_untimeout (sys_timeout_handler h, void *arg)
sys_sem_t sys_sem_new (u8_t count)
int sys_sem_signal (sys_sem_t sem)
u16_t sys_arch_sem_wait (sys_sem_t sem, u16_t timeout)
void sys_sem_free (sys_sem_t sem)
void sys_sem_wait (sys_sem_t sem)
int sys_sem_wait_timeout (sys_sem_t sem, u32_t timeout)
sys_mbox_t sys_mbox_new (void)
void sys_mbox_post (sys_mbox_t mbox, void *msg)
u16_t sys_arch_mbox_fetch (sys_mbox_t mbox, void **msg, u16_t timeout)
void sys_mbox_free (sys_mbox_t mbox)
void sys_mbox_fetch (sys_mbox_t mbox, void **msg)
void * sys_thread_new (void(*function)(void *arg), void *arg, unsigned long period)
void sys_arch_close (void)
void * sys_thread_exit (void)
int sys_thread_delete (void *pthread)
void sys_thread_register (void *pthread)
void register_tcpip_thread (void)
void * sys_malloc (size_t size)
void sys_free (void *ptr)
void sys_stop_interrupts (unsigned int *state)
void sys_allow_interrupts (unsigned int *state)
void * rt_realloc (void *p, size_t new_len)


Typedef Documentation

typedef void(* sys_timeout_handler)(int signo)
 

Definition at line 47 of file sys.h.

Referenced by rt_3c905cif_init(), rt_3com905cif_etharp_timer(), rt_rtl8139_ifetharp_timer(), rt_rtl8139if_init(), sys_timeout(), sys_untimeout(), and tcpip_thread().


Function Documentation

void register_tcpip_thread void   ) 
 

void* rt_realloc void *  p,
size_t  new_len
 

void sys_allow_interrupts unsigned int *  state  ) 
 

Definition at line 189 of file sys_arch.c.

Referenced by pbuf_free(), pbuf_pool_alloc(), pbuf_pool_free(), pbuf_ref(), pbuf_ref_chain(), pbuf_refresh(), sys_free(), sys_malloc(), and sys_mbox_post().

00189                                               {
00190     rtl_restore_interrupts((rtl_irqstate_t) *state);
00191 }

void sys_arch_close void   ) 
 

Definition at line 703 of file sys_arch.c.

References AND, free_all_resources(), NULL, sys_free(), and threads.

Referenced by rt_3com905cif_low_level_input(), and rt_rtl8139if_low_level_input().

00704 {
00705   struct sys_thread *st;
00706 
00707   for(st = threads; st != NULL; st = st->next) {
00708     if(AND(st->flags,0x81)== 0x80){ //i.e. It is a standalone thread finished
00709       sys_free(st->stack);
00710     }else if(AND(st->flags,0xff)==0x00){ //i.e A thread still working
00711       pthread_delete_np(st->pthread);
00712       //This line is necessary because the thread could be standalone.
00713       //If it is not, nothing happens
00714       sys_free(st->stack);               
00715     }else if(AND(st->flags,0xff)==0x01){ //i.e A registered thread still working
00716       pthread_cancel(st->pthread);
00717       pthread_join(st->pthread,NULL);
00718     }
00719   }
00720 
00721   free_all_resources();
00722 
00723   return;
00724 }

Here is the call graph for this function:

u16_t sys_arch_mbox_fetch sys_mbox_t  mbox,
void **  msg,
u16_t  timeout
 

Referenced by netconn_delete(), and sys_mbox_fetch().

u16_t sys_arch_sem_wait sys_sem_t  sem,
u16_t  timeout
 

Referenced by sys_arch_mbox_fetch(), sys_sem_wait(), and sys_sem_wait_timeout().

struct sys_timeouts* sys_arch_timeouts void   ) 
 

void sys_free void *  ptr  ) 
 

Definition at line 239 of file sys_arch.c.

References mallocs, NULL, obtain_index_to_free(), rtl_free, sys_allow_interrupts(), and sys_stop_interrupts().

Referenced by sys_arch_close(), sys_current_thread(), sys_mbox_free(), sys_search_thread(), sys_sem_free(), sys_thread_new(), and thread_start().

00239                         {
00240   int index;
00241   unsigned int state;
00242 
00243   sys_stop_interrupts(&state);
00244 
00245   if(ptr != NULL){
00246     index = obtain_index_to_free(ptr);
00247     if(index != -1){
00248       mallocs[index] = NULL;
00249       rtl_free(ptr);
00250       n_frees++;
00251     }else{
00252       rtl_printf("sys_free: no memory reserved for this pointer\n");
00253     }
00254   }
00255 
00256   sys_allow_interrupts(&state);
00257 }

Here is the call graph for this function:

void sys_init void   ) 
 

Definition at line 728 of file sys_arch.c.

References mallocs, MAX_TIMERS, NULL, signal, sys_timeouts::signal, sys_timeouts::timer_event_spec, and vector_of_timers.

00729 {
00730   int i,retval;
00731 
00732   for(i=0; i<=500; i++)
00733     mallocs[i] = NULL;
00734 
00735   for(i=0; i<MAX_TIMERS; i++){
00736     vector_of_timers[i].signal = RTL_SIGRTMIN + signal++;
00737     vector_of_timers[i].timer_event_spec.sigev_notify = SIGEV_SIGNAL;
00738     vector_of_timers[i].timer_event_spec.sigev_signo = vector_of_timers[i].signal;
00739     vector_of_timers[i].timer_event_spec.sigev_value.sival_int = 13;
00740     
00741     retval = timer_create(CLOCK_REALTIME, &(vector_of_timers[i].timer_event_spec), &(vector_of_timers[i].timer));
00742     
00743     if (retval) {
00744       rtl_printf("timer_create(CLOCK_REALTIME) failed:\n");
00745     }
00746   }
00747 }

void* sys_malloc size_t  size  ) 
 

Definition at line 215 of file sys_arch.c.

References malloc_index, mallocs, MAX_VECTOR_MALLOCS, n_mallocs, NULL, rtl_malloc, sys_allow_interrupts(), and sys_stop_interrupts().

Referenced by sys_mbox_new(), sys_sem_new_(), sys_thread_new(), and sys_thread_register().

00215                              {
00216   void *tmp;
00217   int entry = malloc_index % MAX_VECTOR_MALLOCS;
00218   unsigned int state;
00219 
00220   sys_stop_interrupts(&state);
00221 
00222   while(mallocs[entry] != NULL)
00223     entry = ++malloc_index % MAX_VECTOR_MALLOCS;
00224 
00225   tmp = mallocs[entry] = rtl_malloc(size);
00226 
00227   if(tmp != NULL){
00228     n_mallocs++;
00229     malloc_index++;
00230   }else
00231     rtl_printf("\n\n\n\nERROR: Not enough memory!\n\n\n\n");
00232 
00233   sys_allow_interrupts(&state);
00234 
00235   return tmp;
00236 }

Here is the call graph for this function:

void sys_mbox_fetch sys_mbox_t  mbox,
void **  msg
 

Definition at line 764 of file sys_arch.c.

References sys_arch_mbox_fetch(), and sys_mbox_t.

Referenced by netconn_accept(), netconn_bind(), netconn_close(), netconn_connect(), netconn_delete(), netconn_disconnect(), netconn_listen(), netconn_recv(), netconn_send(), netconn_write(), and tcpip_thread().

00765 {
00766   sys_arch_mbox_fetch(mbox, msg, 0);
00767 }

Here is the call graph for this function:

void sys_mbox_free sys_mbox_t  mbox  ) 
 

Referenced by netconn_delete(), and netconn_recv().

sys_mbox_t sys_mbox_new void   ) 
 

Definition at line 478 of file sys_arch.c.

References NULL, sys_malloc(), and sys_sem_new_().

Referenced by do_listen(), netconn_bind(), netconn_connect(), netconn_listen(), netconn_new(), and tcpip_init().

00479 {
00480   struct sys_mbox *mbox;
00481 
00482   mbox = sys_malloc(sizeof(struct sys_mbox));
00483 
00484   if(mbox != NULL){
00485     
00486     mbox->first = mbox->last = 0;
00487     mbox->mail = sys_sem_new_(0);
00488     mbox->mutex = sys_sem_new_(1);
00489 
00490     return mbox;
00491   }else{
00492     rtl_printf("ERROR: Not enough memory to create mbox\n");
00493     return NULL;
00494   }
00495 }

Here is the call graph for this function:

void sys_mbox_post sys_mbox_t  mbox,
void *  msg
 

Referenced by do_bind(), do_close(), do_connect(), do_delconn(), do_disconnect(), do_listen(), do_recv(), do_send(), do_write(), tcpip_apimsg(), tcpip_callback(), and tcpip_input().

void sys_sem_free sys_sem_t  sem  ) 
 

Referenced by lwip_select(), netconn_delete(), netconn_write(), and sys_mbox_free().

sys_sem_t sys_sem_new u8_t  count  ) 
 

Definition at line 588 of file sys_arch.c.

References sys_sem_new_(), and u8_t.

Referenced by alloc_socket(), event_callback(), lwip_close(), lwip_select(), mem_init(), memp_init(), netconn_write(), and pbuf_init().

00589 {
00590   return sys_sem_new_(count);
00591 }

Here is the call graph for this function:

int sys_sem_signal sys_sem_t  sem  ) 
 

Referenced by alloc_socket(), event_callback(), lwip_accept(), lwip_close(), lwip_select(), mem_free(), mem_malloc(), mem_realloc(), memp_freep(), memp_mallocp(), pbuf_refresh(), sys_arch_mbox_fetch(), and sys_mbox_post().

void sys_sem_wait sys_sem_t  sem  ) 
 

Definition at line 751 of file sys_arch.c.

References sys_arch_sem_wait(), and sys_sem_t.

Referenced by alloc_socket(), event_callback(), lwip_accept(), lwip_close(), lwip_select(), mem_free(), mem_malloc(), mem_realloc(), memp_freep(), memp_mallocp(), netconn_close(), netconn_write(), pbuf_refresh(), sys_mbox_free(), and sys_mbox_post().

00752 {
00753   sys_arch_sem_wait(sem, 0);
00754 }

Here is the call graph for this function:

int sys_sem_wait_timeout sys_sem_t  sem,
u32_t  timeout
 

Definition at line 757 of file sys_arch.c.

References sys_arch_sem_wait(), sys_sem_t, and u32_t.

Referenced by lwip_select().

00758 {
00759   return sys_arch_sem_wait(sem, timeout);
00760 }

Here is the call graph for this function:

void sys_stop_interrupts unsigned int *  state  ) 
 

Definition at line 184 of file sys_arch.c.

Referenced by pbuf_free(), pbuf_pool_alloc(), pbuf_pool_free(), pbuf_ref(), pbuf_ref_chain(), pbuf_refresh(), sys_free(), sys_malloc(), and sys_mbox_post().

00184                                              {
00185   rtl_no_interrupts((rtl_irqstate_t) *state);
00186 }

int sys_thread_delete void *  pthread  ) 
 

Definition at line 360 of file sys_arch.c.

References NULL, SET, and sys_search_thread().

Referenced by cleanup_module().

00361 {
00362   struct sys_thread *thread;
00363   
00364   thread = sys_search_thread(pthread);
00365 
00366   if(thread != NULL){
00367     if(thread->stack != NULL) //i.e. It is a standalone thread
00368       SET(thread->flags, 0x80);
00369     else SET(thread->flags, 0x81);
00370     pthread_cancel(pthread);
00371     pthread_join(pthread,NULL);
00372     return 0;
00373   }
00374 
00375 
00376   return -1;
00377 }

Here is the call graph for this function:

void* sys_thread_exit void   ) 
 

Definition at line 344 of file sys_arch.c.

References NULL, SET, status, and sys_current_thread().

Referenced by dns_client(), serve_echo(), sock_udpclient(), tcp_client(), and udpclient().

00345 {
00346   struct sys_thread *thread;
00347   void *status = NULL;
00348   
00349   thread = sys_current_thread();
00350 
00351   if(thread->stack != NULL) //i.e. It is a standalone thread
00352     SET(thread->flags, 0x80);
00353   else SET(thread->flags, 0x81);
00354 
00355   pthread_exit(status);
00356   return NULL;
00357 }

Here is the call graph for this function:

void* sys_thread_new void(*  function)(void *arg),
void *  arg,
unsigned long  period
 

Definition at line 406 of file sys_arch.c.

References bcopy(), name, NULL, SET, sys_free(), sys_malloc(), thread_start(), and threads.

Referenced by init_module(), rt_3com905cif_low_level_init(), rt_rtl8139if_low_level_init(), slipif_init(), tcpecho_thread(), and tcpip_init().

00408 {
00409   struct sys_thread *thread;
00410   struct thread_start_param *thread_param;
00411   pthread_attr_t attr;
00412 
00413   thread = sys_malloc(sizeof(struct sys_thread));
00414 
00415   if(thread != NULL){
00416 
00417     thread->next = threads;
00418 
00419     SET(thread->flags, 0x00);
00420 
00421     thread->stack = (char *) sys_malloc(sizeof(char)*THREAD_STACK_SIZE);
00422 
00423     thread->timeouts = NULL;
00424 
00425 #ifdef THREAD_DEBUG
00426     thread->name = (char *) sys_malloc(20);
00427     bcopy(name, thread->name, name_len);
00428 #endif
00429 
00430     if(thread->stack == NULL){
00431       sys_free(thread);
00432       rtl_printf("ERROR: Not enough memory to create new thread's stack\n");
00433       return NULL;
00434     }
00435 
00436     threads = thread;
00437 
00438     pthread_attr_init(&attr);
00439 
00440 
00441     /* Because it's a thread which is trying to create another thread, RTLinux
00442        only allows that by passing to the new thread it's stack */    
00443     pthread_attr_setstackaddr(&attr, thread->stack);
00444     pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE);
00445     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
00446     
00447     thread_param = sys_malloc(sizeof(struct thread_start_param));
00448     
00449     if(thread_param == NULL){
00450       sys_free(thread->stack);
00451       sys_free(thread);
00452       rtl_printf("ERROR: Not enough memory to create thread start param\n");
00453       return NULL;
00454     }
00455     
00456     thread_param->function = function;
00457     thread_param->arg = arg;
00458     thread_param->thread = thread;
00459     
00460     if(pthread_create(&(thread->pthread),&attr, thread_start, thread_param)) {
00461       rtl_printf("\nsys_thread_new: pthread_create  0x%x 0x%x\n", pthread_self(),thread->pthread);
00462       rtl_printf("Kernel Panic\n");
00463       return NULL;
00464     }
00465 
00466     if(period != 0)
00467       pthread_make_periodic_np(thread->pthread, gethrtime(), period);
00468 
00469     return (void *) thread->pthread;
00470   }
00471   
00472   rtl_printf("ERROR: Not enough memory to create thread\n"); 
00473   return NULL;
00474 }

Here is the call graph for this function:

void sys_thread_register void *  pthread  ) 
 

Definition at line 380 of file sys_arch.c.

References NULL, sys_thread::pthread, SET, sys_malloc(), and threads.

Referenced by tcp_client().

00381 {
00382   struct sys_thread *thread;
00383 
00384   thread = sys_malloc(sizeof(struct sys_thread));
00385 
00386 
00387   thread->next = threads;
00388   thread->pthread = (pthread_t) pthread;
00389   thread->stack = NULL;
00390   thread->timeouts = NULL;
00391 
00392   SET(thread->flags, 0x01);
00393   threads = thread;
00394 
00395   pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
00396   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
00397 
00398 }

Here is the call graph for this function:

void sys_timeout u16_t  msecs,
sys_timeout_handler  h,
void *  arg
 

Definition at line 770 of file sys_arch.c.

References NULL, sys_current_thread(), sys_timeout_handler, timer_index, u16_t, and vector_of_timers.

Referenced by ip_reass(), ip_reass_timer(), rt_3c905cif_init(), rt_3com905cif_etharp_timer(), rt_rtl8139_ifetharp_timer(), rt_rtl8139if_init(), and tcpip_thread().

00771 {
00772   struct sys_thread *thread;
00773   int err, sec = 0, nsec = 0;
00774 
00775   thread = sys_current_thread();
00776 
00777   if(thread->timeouts == NULL){
00778     thread->timeouts = &vector_of_timers[timer_index++];
00779   }
00780 
00781   thread->timeouts->sa.sa_handler = h;
00782   thread->timeouts->sa.sa_mask=0;
00783   thread->timeouts->sa.sa_flags=0;
00784   thread->timeouts->sa.sa_focus=0;
00785 
00786   rtl_sigemptyset(&(thread->timeouts->sa.sa_mask));
00787 
00788   if (sigaction(thread->timeouts->signal, &(thread->timeouts->sa), NULL)) {
00789     rtl_printf("sigaction failed");
00790   }  
00791 
00792   if(msecs >= 100){
00793     sec = msecs / 1000;
00794     nsec = (msecs % 1000) * 1000000 ;
00795   }else{
00796     nsec = msecs * 1000000;
00797   }
00798 
00799   thread->timeouts->ospec.it_value.tv_sec = sec;
00800   thread->timeouts->ospec.it_value.tv_nsec = nsec;
00801   thread->timeouts->ospec.it_interval.tv_sec = 0;
00802   thread->timeouts->ospec.it_interval.tv_nsec = 0;
00803 
00804   err = timer_settime(thread->timeouts->timer, 0, &(thread->timeouts->ospec), &(thread->timeouts->old_setting));
00805 
00806   return;  
00807 }

Here is the call graph for this function:

void sys_untimeout sys_timeout_handler  h,
void *  arg
 

Definition at line 810 of file sys_arch.c.

References NULL, sys_current_thread(), and sys_timeout_handler.

Referenced by ip_reass().

00810                                                     {
00811   struct sys_thread *thread;
00812 
00813   thread = sys_current_thread();
00814 
00815   if(thread->timeouts != NULL)
00816     timer_delete(thread->timeouts->timer);
00817 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:59:14 2004 for RTL-lwIP-0.4 by doxygen 1.3.4