Exemplo n.º 1
0
// end of file
int pthread_create (pthread_t * __newthread,
			   const pthread_attr_t * __attr,
			   void *(*__start_routine) (void *),
			   void * __arg){
#if defined(OS_FREERTOS)
	(__newthread)->attr = (pthread_attr_t*)__attr;
	(__newthread)->start_routine = __start_routine;
	(__newthread)->arg = __arg;
	  xTaskCreate(
			  (void (*)(void*))(__newthread)->start_routine,/* Function pointer */
			  "",                          				  /* Task name - for debugging only*/
			  (__newthread)->attr ?
					  (__newthread)->attr->stack_size
					  : configMINIMAL_STACK_SIZE,         /* Stack depth in words */
			  (void*) (__newthread)->arg,                   /* Pointer to tasks arguments (parameter) */
			  (__newthread)->prio,           			      /* Task priority*/
			  &(__newthread)->handle         				  /* Task handle */
	  );
#elif defined(OS_UCOS)
		OS_ERR   err;
		LIB_ERR  lib_err;
		(*__newthread) = (pthread_t)Mem_SegAlloc(0, 0, sizeof(struct __pthread_t), &lib_err);
		(*__newthread)->attr = (pthread_attr_t*)__attr;
		(*__newthread)->start_routine = __start_routine;
		(*__newthread)->arg = __arg;
	  // alloc mem
	  (*__newthread)->attr->stack = Mem_SegAlloc(0, 0, (*__newthread)->attr->stack_size * sizeof(CPU_STK), &lib_err);
		OSTaskCreate(&(*__newthread)->handle,                              /* Create the start task                                */
					  "",
					  (OS_TASK_PTR)(*__newthread)->start_routine,
					  (*__newthread)->arg,
					  (*__newthread)->prio,
					  (*__newthread)->attr->stack,
					  (*__newthread)->attr->stack_size/10,
					  (*__newthread)->attr->stack_size,
					  0u,
					  0u,
					  0u,
					 (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
					 &err);
#endif
	  return 0;
}
void  NetICMP_Init (NET_ERR  *p_err)
{
    MEM_SEG  *p_seg;
    LIB_ERR   err_lib;
    KAL_ERR   err_kal;


    NetICMP_ID      = 1u;
    NetICMP_DataPtr = DEF_NULL;

                                                                /* --------------- INITIALIZE ICMP LOCK --------------- */
                                                                /* Create ICMP lock signal ...                          */
                                                                /* ... with ICMP access available (see Note #1d1).      */
    NetICMP_Lock = KAL_LockCreate((const CPU_CHAR *)NET_ICMP_LOCK_NAME,
                                                    DEF_NULL,
                                                   &err_kal);
    switch (err_kal) {
        case KAL_ERR_NONE:
             break;


        case KAL_ERR_MEM_ALLOC:
             *p_err = NET_ERR_FAULT_MEM_ALLOC;
              return;


        case KAL_ERR_ISR:
        case KAL_ERR_INVALID_ARG:
        case KAL_ERR_CREATE:
        default:
            *p_err = NET_ICMP_ERR_LOCK_CREATE;
             return;
    }


    p_seg = DEF_NULL;
    NetICMP_DataPtr = (NET_ICMP_DATA *)Mem_SegAlloc(NET_ICMP_INTERNAL_DATA_SEG_NAME,
                                                    p_seg,
                                                    sizeof(NET_ICMP_DATA),
                                                   &err_lib);
    if (err_lib != LIB_MEM_ERR_NONE) {
       *p_err = NET_ERR_FAULT_MEM_ALLOC;
        return;
    }

    NetICMP_DataPtr->MemSegPtr                 = p_seg;
    NetICMP_DataPtr->EchoReqHandleListStartPtr = DEF_NULL;
    NetICMP_DataPtr->EchoReqHandleListEndPtr   = DEF_NULL;


    Mem_DynPoolCreate(NET_ICMP_ECHO_REQ_POOL_NAME,
                     &NetICMP_DataPtr->EchoReqPool,
                      NetICMP_DataPtr->MemSegPtr,
                      sizeof(NET_ICMP_ECHO_REQ),
                      sizeof(CPU_ALIGN),
                      0u,
                      LIB_MEM_BLK_QTY_UNLIMITED,
                     &err_lib);
    if (err_lib != LIB_MEM_ERR_NONE) {
       *p_err = NET_ERR_FAULT_MEM_ALLOC;
        return;
    }


#ifdef  NET_ICMPv4_MODULE_EN
    NetICMPv4_Init(p_err);
    if (*p_err != NET_ICMPv4_ERR_NONE) {
         return;
    }
#endif

#ifdef  NET_ICMPv6_MODULE_EN
    NetICMPv6_Init();
#endif

   *p_err = NET_ICMP_ERR_NONE;
}