Example #1
0
_mqx_uint _name_create_component
   (
      /* [IN] the initial number of names that can be stored  */
      _mqx_uint initial_number,

      /* [IN] the number of names to be added when table full */
      _mqx_uint grow_number,

      /* [IN] the maximum number of names that can be stored  */
      _mqx_uint maximum_number
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR    kernel_data;
   _mqx_uint                 result;
   pointer                   handle;
   NAME_COMPONENT_STRUCT_PTR component_ptr;

   _GET_KERNEL_DATA(kernel_data);

   _KLOGE4(KLOG_name_create_component, initial_number, grow_number, maximum_number);

   component_ptr = (NAME_COMPONENT_STRUCT_PTR)
      kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT];
   if (component_ptr != NULL){
      if (maximum_number > component_ptr->MAX_NUMBER) {
         component_ptr->MAX_NUMBER = maximum_number;
      } /* Endif */
      _KLOGX2(KLOG_name_create_component, MQX_OK);
      return(MQX_OK);
   } /* Endif */

   result = _name_create_handle_internal(&handle,
      initial_number, grow_number, maximum_number, initial_number);

   /* We must exclude all ISRs at this point */
   if (result == MQX_OK) {
      _int_disable();
      if (kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT] != NULL){
         _int_enable();
         _name_destroy_handle_internal(handle);
         component_ptr = (NAME_COMPONENT_STRUCT_PTR)
            kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT];
         if (maximum_number > component_ptr->MAX_NUMBER) {
            component_ptr->MAX_NUMBER = maximum_number;
         } /* Endif */
         _KLOGX2(KLOG_name_create_component, MQX_OK);
         return(MQX_OK);
      } /* Endif */
      kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT] = handle;
      _int_enable();
   } /* Endif */

   _KLOGX2(KLOG_name_create_component, result);
   return(result);

} /* Endbody */
Example #2
0
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 *
 * \brief This function adds a name to the name component along with the 
 * _mqx_max_type number to be associate with the name.
 * 
 * \param[in] name_handle The handle returned by _name_internal_create.
 * \param[in] name        The name to be associated with the number.
 * \param[in] number      The number to be associated with the name.
 * \param[in] index       The index in the name table.
 * 
 * \return MQX_OK
 * \return MQX_OUT_OF_MEMORY (MQX cannot allocate memory for the name component.)
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data is not valid.)
 * \return NAME_TABLE_FULL (Names database is full.)
 * \return NAME_EXISTS (Name is already in the names database.)
 */ 
_mqx_uint _name_add_internal_by_index
(
    void         *name_handle,
    char     *name,
    _mqx_max_type number,
    _mqx_uint     index
)
{ /* Body */
    NAME_COMPONENT_STRUCT_PTR          base_name_manager_ptr;
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_STRUCT_PTR           name_ptr;
    _mqx_uint                          result = MQX_OK;

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */
#if MQX_CHECK_VALIDITY
    if (name_manager_ptr->VALID != NAME_VALID)
    {
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    base_name_manager_ptr = name_manager_ptr;

    /* We are modifying the table, so lets get exclusive access */
    _int_disable();
#if MQX_CHECK_VALIDITY
    if (base_name_manager_ptr->VALID != NAME_VALID)
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */

    _lwsem_wait((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
    _int_enable();

    /* Scan to correct location in table, and if not found, insert it */
    while (index >= name_manager_ptr->NUMBER_IN_BLOCK)
    {
        index -= name_manager_ptr->NUMBER_IN_BLOCK;
        if (name_manager_ptr->NEXT_TABLE == NULL)
        {
            if (name_manager_ptr->GROW_NUMBER && ((name_manager_ptr->TOTAL_NUMBER + name_manager_ptr->GROW_NUMBER)
                            <= name_manager_ptr->MAX_NUMBER))
            {
                result = _name_create_handle_internal((void **) &name_manager_ptr->NEXT_TABLE,
                                name_manager_ptr->GROW_NUMBER, name_manager_ptr->GROW_NUMBER,
                                name_manager_ptr->MAX_NUMBER, (name_manager_ptr->TOTAL_NUMBER
                                                + name_manager_ptr->GROW_NUMBER));
                if (result != MQX_OK)
                {
                    break;
                }/* Endif */
            }
            else
            {
                result = NAME_TABLE_FULL;
                break;
            } /* Endif */
        } /* Endif */
        name_manager_ptr = name_manager_ptr->NEXT_TABLE;
#if MQX_CHECK_VALIDITY
        if (name_manager_ptr->VALID != NAME_VALID)
        {
            result = MQX_INVALID_COMPONENT_BASE;
            break;
        } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    } /* Endwhile */

    if (result == MQX_OK)
    {
        name_ptr = &name_manager_ptr->NAMES[index];
        if (name_ptr->NAME[0] == '\0')
        {
            strncpy(name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1);
            name_ptr->NAME[NAME_MAX_NAME_SIZE - 1] = '\0';
            name_ptr->NUMBER = number;
            base_name_manager_ptr->NUMBER++;
        }
        else
        {
            result = NAME_EXISTS;
        } /* Endif */
    } /* Endif */

    _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));

    return (result);
} /* Endbody */
Example #3
0
/*!
 * \cond DOXYGEN_PRIVATE
 * \private
 * 
 * \brief This function adds a name to the name component along with the 
 * _mqx_max_type number associated with the name.
 * 
 * \param[in] name_handle The handle returned by _name_internal_create.
 * \param[in] name        The name to be associated with the number.
 * \param[in] number      The number to be associated with the name.
 * 
 * \return MQX_OK
 * \return MQX_OUT_OF_MEMORY (MQX cannot allocate memory for the name component.)
 * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.)
 * \return MQX_INVALID_COMPONENT_BASE (Name component data is not valid.)
 * \return NAME_TOO_SHORT (Name is 0 length string.)
 * \return NAME_TOO_LONG (Name is longer than NAME_MAX_NAME_SIZE.)
 * \return NAME_EXISTS (Name is already in the names database.)
 * \return NAME_TABLE_FULL (Names database is full.) 
 */ 
_mqx_uint _name_add_internal
(
    void         *name_handle,
    char     *name,
    _mqx_max_type number
)
{ /* Body */
    NAME_COMPONENT_STRUCT_PTR          base_name_manager_ptr;
    register NAME_COMPONENT_STRUCT_PTR name_manager_ptr;
    register NAME_STRUCT_PTR           name_ptr;
    register NAME_STRUCT_PTR           saved_name_ptr;
    register _mqx_uint                 i;
    _mqx_uint                          result = MQX_OK;

#if MQX_CHECK_ERRORS
    if (*name == '\0')
    {
        /* Cannot add 0 length string name */
        return (NAME_TOO_SHORT);
    } /* Endif */
    if (_strnlen(name, NAME_MAX_NAME_SIZE) >= NAME_MAX_NAME_SIZE)
    {
        return (NAME_TOO_LONG);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */

    name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle;
#if MQX_CHECK_ERRORS
    if (name_manager_ptr == NULL)
    {
        return (MQX_COMPONENT_DOES_NOT_EXIST);
    } /* Endif */
#endif /* MQX_CHECK_ERRORS */
    base_name_manager_ptr = name_manager_ptr;

    /* We are modifying the table, so lets get exclusive access */
    _int_disable();
#if MQX_CHECK_VALIDITY
    if ((name_manager_ptr->VALID != NAME_VALID) || (base_name_manager_ptr->VALID != NAME_VALID))
    {
        _int_enable();
        return (MQX_INVALID_COMPONENT_BASE);
    } /* Endif */
#endif /* MQX_CHECK_VALIDITY */
    _lwsem_wait((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));
    _int_enable();

    /* 
     * Scan to end of table, looking for a duplicate name..
     * simultaneously, remember the first empty slot found
     */
    saved_name_ptr = NULL;
    while (TRUE)
    {
        i = name_manager_ptr->NUMBER_IN_BLOCK + 1;
        name_ptr = &name_manager_ptr->NAMES[0];
        while (--i)
        {
            if (name_ptr->NAME[0] == '\0')
            {
                if (saved_name_ptr == NULL)
                {
                    saved_name_ptr = name_ptr;
                } /* Endif */
            }
            else
            {
                if (strncmp(name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1) == 0)
                { /* MATCH */
                    result = NAME_EXISTS;
                    break;
                } /* Endif */
            } /* Endif */
            name_ptr++;
        } /* Endwhile */
        if ((name_manager_ptr->NEXT_TABLE == NULL) || (result != MQX_OK))
        {
            break;
        } /* Endif */
        name_manager_ptr = name_manager_ptr->NEXT_TABLE;
    } /* Endwhile */

    if (result == MQX_OK)
    {
        /* We have scanned the whole table, and the original name was not found */

        if (saved_name_ptr == NULL)
        {
            /* 
             * An empty slot was not found in the table so we must try to
             * grow the name table
             */
            if (base_name_manager_ptr->GROW_NUMBER && ((name_manager_ptr->TOTAL_NUMBER
                            + base_name_manager_ptr->GROW_NUMBER) <= base_name_manager_ptr->MAX_NUMBER))
            {
                result = _name_create_handle_internal((void **) &name_manager_ptr->NEXT_TABLE,
                                base_name_manager_ptr->GROW_NUMBER, base_name_manager_ptr->GROW_NUMBER,
                                base_name_manager_ptr->MAX_NUMBER, (name_manager_ptr->TOTAL_NUMBER
                                                + base_name_manager_ptr->GROW_NUMBER));
                if (result == MQX_OK)
                {
                    name_manager_ptr = name_manager_ptr->NEXT_TABLE;
                    saved_name_ptr = &name_manager_ptr->NAMES[0];
                } /* Endif */
            }
            else
            {
                result = NAME_TABLE_FULL;
            } /* Endif */
        } /* Endif */

        if (saved_name_ptr != NULL)
        {
            strncpy(saved_name_ptr->NAME, name, (_mqx_uint) NAME_MAX_NAME_SIZE - 1);
            saved_name_ptr->NAME[NAME_MAX_NAME_SIZE - 1] = '\0';
            saved_name_ptr->NUMBER = number;
            base_name_manager_ptr->NUMBER++;
        }/* Endif */
    }/* Endif */

    _lwsem_post((LWSEM_STRUCT_PTR) (&base_name_manager_ptr->SEM));

    return (result);
} /* Endbody */
Example #4
0
_mqx_uint _event_create_component
   (
      /* [IN] the initial number of event */
      _mqx_uint initial_number, 

      /* 
      ** [IN] the number of events to add when
      ** space is no longer available
      */
      _mqx_uint grow_number,

      /* [IN] the maximum number of events allowed */
      _mqx_uint maximum_number 
   )
{ /* Body */
            KERNEL_DATA_STRUCT_PTR     kernel_data;
   register EVENT_COMPONENT_STRUCT_PTR event_component_ptr;
            _mqx_uint                   result;
            
   _GET_KERNEL_DATA(kernel_data);            

   _KLOGE4(KLOG_event_create_component, initial_number, grow_number, maximum_number);

#if MQX_CHECK_ERRORS
   if (kernel_data->IN_ISR) {
      _KLOGX2(KLOG_event_create_component, MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
      return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR);
   } /* Endif */
#endif

   _lwsem_wait((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));

   event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
      kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS];
   if (event_component_ptr != NULL) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _KLOGX2(KLOG_event_create_component, MQX_OK);
      return(MQX_OK);
   } /* Endif */
   
   event_component_ptr = (EVENT_COMPONENT_STRUCT_PTR)
      _mem_alloc_system_zero((_mem_size)sizeof(EVENT_COMPONENT_STRUCT));
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (event_component_ptr == NULL) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _KLOGX2(KLOG_event_create_component, MQX_OUT_OF_MEMORY);
      return(MQX_OUT_OF_MEMORY);
   } /* Endif */
#endif
   _mem_set_type(event_component_ptr, MEM_TYPE_EVENT_COMPONENT);

   result = _name_create_handle_internal(&event_component_ptr->NAME_TABLE_HANDLE,
      initial_number, grow_number, maximum_number, initial_number);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
      _mem_free(event_component_ptr);
      _KLOGX2(KLOG_event_create_component, result);
      return(result);
   } /* Endif */
#endif
   event_component_ptr->VALID             = EVENT_VALID;
   event_component_ptr->GROW_NUMBER       = grow_number;
   if (maximum_number == 0) {
      event_component_ptr->MAXIMUM_NUMBER = MAX_MQX_UINT;
   } else if (maximum_number < initial_number) {
      event_component_ptr->MAXIMUM_NUMBER = initial_number;
   } else {
      event_component_ptr->MAXIMUM_NUMBER = maximum_number;
   } /* Endif */

   kernel_data->KERNEL_COMPONENTS[KERNEL_EVENTS] = event_component_ptr;

#if MQX_TASK_DESTRUCTION
   kernel_data->COMPONENT_CLEANUP[KERNEL_EVENTS] = _event_cleanup;
#endif

   _lwsem_post((LWSEM_STRUCT_PTR)(&kernel_data->COMPONENT_CREATE_LWSEM));
   
   _KLOGX2(KLOG_event_create_component, MQX_OK);
   return(MQX_OK);

} /* Endbody */