Beispiel #1
0
void MutexA
   (
      uint32_t   parameter
   )
{
   MUTEX_ATTR_STRUCT      mutex_init;

   /* initialize a mutex Mutex1 */
   if (_mutatr_init(&mutex_init) == MQX_EOK) {
      _mutatr_set_wait_protocol(&mutex_init,MUTEX_QUEUEING);
      _mutatr_set_sched_protocol(&mutex_init,MUTEX_NO_PRIO_INHERIT);
      _mutex_init(&Mutex1,&mutex_init);
   }

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      if (_mutex_lock(&Mutex1) != MQX_EOK) { 
         /* an error occurred */
      }

      /* access shared resource */

      _time_delay_ticks(1);
      _mutex_unlock(&Mutex1);
   } /* endwhile */ 
} /*end of task*/
Beispiel #2
0
/*!
 * \brief Allocates and initializes drive context structure.
 *
 * \param drive_ptr_ptr
 *
 * \return _mfs_error
 */
_mfs_error MFS_Create_drive(
    MFS_DRIVE_STRUCT_PTR *drive_ptr_ptr)
{
    MFS_DRIVE_STRUCT_PTR drive_ptr;
    _mfs_error error_code = MFS_NO_ERROR;

    if (drive_ptr_ptr == NULL)
    {
        return MFS_INVALID_POINTER;
    }

    drive_ptr = MFS_mem_alloc_system_zero(sizeof(MFS_DRIVE_STRUCT));
    if (drive_ptr == NULL)
    {
        return MFS_INSUFFICIENT_MEMORY;
    }
    _mem_set_type(drive_ptr, MEM_TYPE_MFS_DRIVE_STRUCT);

#if MFSCFG_USE_MUTEX
    {
        MUTEX_ATTR_STRUCT mutex_attr;

        error_code = _mutatr_init(&mutex_attr);
        if (error_code == MFS_NO_ERROR)
        {
            error_code = _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);
            if (error_code == MFS_NO_ERROR)
            {
                error_code = _mutatr_set_wait_protocol(&mutex_attr, MUTEX_PRIORITY_QUEUEING);
            }

            if (error_code == MFS_NO_ERROR)
            {
                error_code = _mutex_init(&drive_ptr->MUTEX, &mutex_attr);
            }

            _mutatr_destroy(&mutex_attr);
        }
    }
#else
    error_code = _lwsem_create(&drive_ptr->LWSEM, 1);
#endif

    if (error_code)
    {
        MFS_mem_free(drive_ptr);
    }

    *drive_ptr_ptr = drive_ptr;
    return error_code;
}
Beispiel #3
0
_mqx_int _io_pipe_open
   (
      /* [IN] the file handle for the device being opened */
      FILE_DEVICE_STRUCT_PTR fd_ptr,
       
      /* [IN] the remaining portion of the name of the device */
      char             _PTR_ open_name_ptr,

      /* [IN] the flags to be used during operation:
      ** echo, translation, xon/xoff
      */
      char             _PTR_ flags
   )
{ /* Body */
   IO_DEVICE_STRUCT_PTR          io_dev_ptr = fd_ptr->DEV_PTR;
   IO_PIPE_INIT_STRUCT_PTR       io_pipe_init_ptr;
   IO_PIPE_INFO_STRUCT_PTR       io_pipe_info_ptr;
   MUTEX_ATTR_STRUCT             mutex_attr;
   uint_32                       result = MQX_OK;

   /* Allocate a Pipe information structure */
   io_pipe_info_ptr = _mem_alloc_system_zero(
      (uint_32)sizeof(IO_PIPE_INFO_STRUCT));

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_pipe_info_ptr == NULL){
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif 

   fd_ptr->DEV_DATA_PTR = io_pipe_info_ptr;
   io_pipe_init_ptr = (IO_PIPE_INIT_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR;
   
   io_pipe_info_ptr->QUEUE_SIZE = io_pipe_init_ptr->QUEUE_SIZE;

   /* Initialize mutexes */
   result = _mutatr_init(&mutex_attr); 
   
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   _mutatr_set_wait_protocol(&mutex_attr, MUTEX_PRIORITY_QUEUEING);
   _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);

   result = _mutex_init(&io_pipe_info_ptr->READ_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 
   
   result = _mutex_init(&io_pipe_info_ptr->WRITE_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   result = _mutex_init(&io_pipe_info_ptr->ACCESS_MUTEX, &mutex_attr);
#if MQX_CHECK_ERRORS
   if (result != MQX_EOK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   /* Initialize semaphores */

   result = _lwsem_create(&io_pipe_info_ptr->FULL_SEM, 0);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 

   result = _lwsem_create(&io_pipe_info_ptr->EMPTY_SEM, 0);
#if MQX_CHECK_ERRORS
   if (result != MQX_OK) {
      _mem_free(io_pipe_info_ptr);
      return (result);
   } /* Endif */
#endif 
                          
   /* Allocate queue structure for pipe char queue */
   io_pipe_info_ptr->QUEUE = (pointer)_mem_alloc_system(
      sizeof(CHARQ_STRUCT) - (4 * sizeof(char)) + io_pipe_info_ptr->QUEUE_SIZE);

#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if (io_pipe_info_ptr->QUEUE == NULL){
      _mem_free(io_pipe_info_ptr);
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
#endif            

   /* Initialize Pipe queue */
   _CHARQ_INIT(io_pipe_info_ptr->QUEUE, io_pipe_init_ptr->QUEUE_SIZE);
   
   return(result);

} /* Endbody */