??????????????????????????ι?????????????????mempool?????????block??С??pool????????pool??С???????????????????????

??????1???ж??????????????????

??????2????????????n??????n??????????С??

??????3??????block???????????????????block???NULL???

??????4????pool?????????raw_block_pool_available_list???????????

RAW_U16 raw_block_allocate(MEM_POOL *pool_ptr?? RAW_VOID **block_ptr?? RAW_U32 wait_option)
  {
  
   RAW_U16    status;       
 
   RAW_U8  *work_ptr;      
 
   RAW_SR_ALLOC();
 
   #if (RAW_BLOCK_FUNCTION_CHECK > 0)
  
   if (pool_ptr == 0) {
    return RAW_NULL_OBJECT;
   }
  
   if (block_ptr == 0) {
   
    return RAW_NULL_POINTER;
   }
 
   if (raw_int_nesting) {
 
    if (wait_option != RAW_NO_WAIT) {
    
     return RAW_NOT_CALLED_BY_ISR;
    }
   
   }
  
   #endif
 
   RAW_CRITICAL_ENTER();
 
   /* Determine if there is an available block.  */
   if (pool_ptr ->raw_block_pool_available) {
 
    /* Yes?? a block is available.  Decrement the available count.  */
    pool_ptr ->raw_block_pool_available--;
 
    /* Pickup the current block pointer.  */
    work_ptr =  pool_ptr ->raw_block_pool_available_list;
 
    /* Return the first available block to the caller.  */
    *((RAW_U8 **)block_ptr) =  work_ptr;
 
    /* Modify the available list to point at the next block in the pool. */
    pool_ptr ->raw_block_pool_available_list = *((RAW_U8 **)work_ptr);
 
    /* Set status to success.  */
    status =  RAW_SUCCESS;
   }
 
   /*if no block memory is available then do it depend wait_option*/
   else {
   
    if (wait_option == RAW_NO_WAIT) {
     *((RAW_U8 **)block_ptr)     = 0;
     RAW_CRITICAL_EXIT();
     return RAW_NO_PEND_WAIT;
    }
 
    /*system is locked so task can not be blocked just return immediately*/
    if (raw_sched_lock) {
     *((RAW_U8 **)block_ptr)     = 0;
     RAW_CRITICAL_EXIT();
     return RAW_SCHED_DISABLE;  
    }
  
    raw_pend_object(&pool_ptr->common_block_obj?? raw_task_active?? wait_option);
 
    RAW_CRITICAL_EXIT();
 
    raw_sched();                                           
 
    RAW_CRITICAL_ENTER();
 
    *((RAW_U8 **)block_ptr)     = 0;
    status = block_state_post_process(raw_task_active?? block_ptr);
   
    RAW_CRITICAL_EXIT();
 
   }
 
 
   return status;
 
  }