예제 #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*/
예제 #2
0
파일: main.c 프로젝트: gxliu/MQX_3.8.0
void main_task
   (
      uint_32 initial_data
   )
{
   MUTEX_ATTR_STRUCT mutexattr;
   char*             string1 = "Hello from Print task 1\n";
   char*             string2 = "Print task 2 is alive\n";

   /* Initialize mutex attributes */
   if (_mutatr_init(&mutexattr) != MQX_OK) {
      printf("Initialize mutex attributes failed.\n");
      _task_block();
   }
   
   /* Initialize the mutex */ 
   if (_mutex_init(&print_mutex, &mutexattr) != MQX_OK) {
      printf("Initialize print mutex failed.\n");
      _task_block();
   }
   /* Create the print tasks */
   _task_create(0, PRINT_TASK, (uint_32)string1);
   _task_create(0, PRINT_TASK, (uint_32)string2);

   _task_block();
}   
예제 #3
0
/** Lock the Attribute database mutex.
 *
 * SYSTEM_DatabaseMutexPend()
 *	The BLE stack uses a MUTEX to prevent internal/external multiple access 
 *	to the Attribute protocol database, the BLE stack calls this function to 
 *  acquire the MUTEX. This function SHALL be implemented.
 *  Note that the User application does not call this function directly, but
 *  call the application interface ATT_Server_SecureDatabaseAccess().
 *
 *	It could be implemented using a mutex or perhaps a semaphore
 *
 * @see SYSTEM_DatabaseMutexPost()
 *
 * @return none
 *	
 * @author Alexandre GIMARD
 */
void SYSTEM_DatabaseMutexPend(void){
	// Add here specific code to pend the database Mutex
	//>
	#if 0
        if(_mutatr_init(&database_mutexattr) == MQX_OK)
    {
        if(_mutex_init(&database_mutex, &database_mutexattr) == MQX_OK)
            _mutex_lock(&database_mutex);
    }
	#endif
	_mutex_lock(&database_mutex);
}
예제 #4
0
/** Lock the stack mutex.
 *
 * SYSTEM_StackMutexPend()
 *	The BLE stack uses a MUTEX to prevent internal interface reentrency and 
 *	dead lock, the BLE stack calls this function to acquire the MUTEX
 *	this function SHALL be implemented.
 *	It could be implemented using a mutex or perhaps a semaphore
 *
 * @todo implement this function
 * @todo Mutex or semaphore
 *
 * @see SYSTEM_StackMutexPost()
 *
 * @return none
 *	
 * @author Alexandre GIMARD
 */
void SYSTEM_StackMutexPend(void){
	// Add here specific code to pend the stack Mutex
	//>
	#if 0
    if(_mutatr_init(&stack_mutexattr) == MQX_OK)
    {
        if(_mutex_init(&stack_mutex, &stack_mutexattr) == MQX_OK)
            _mutex_lock(&stack_mutex);
    }
	#endif
	_mutex_lock(&stack_mutex);

} 
예제 #5
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;
}
예제 #6
0
파일: io_pipe.c 프로젝트: gxliu/MQX_3.8.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 */
예제 #7
0
파일: mu_init.c 프로젝트: gxliu/MQX_3.8.0
_mqx_uint _mutex_init
   (
      /* [IN] - the address where the mutex is to be initialized */
      register MUTEX_STRUCT_PTR      mutex_ptr,

      /* [IN]  - Initialization parameters for the mutex  */
      register MUTEX_ATTR_STRUCT_PTR attr_ptr
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR     kernel_data;
   MUTEX_COMPONENT_STRUCT_PTR mutex_component_ptr;
   MUTEX_ATTR_STRUCT          default_attr;
#if MQX_CHECK_ERRORS
   MUTEX_STRUCT_PTR           mutex_chk_ptr;
#endif
   _mqx_uint                   result;

   _GET_KERNEL_DATA(kernel_data);
   if (attr_ptr == NULL) {
      attr_ptr = &default_attr;
      _mutatr_init(attr_ptr);
      _KLOGE3(KLOG_mutex_init, mutex_ptr, NULL);
   } else {
      _KLOGE3(KLOG_mutex_init, mutex_ptr, attr_ptr);
   } /* Endif */
   
#if MQX_CHECK_ERRORS
   if (mutex_ptr == NULL) {
      _KLOGX2(KLOG_mutex_init, MQX_EINVAL);
      return(MQX_EINVAL);
   } /* Endif */
#endif
#if MQX_CHECK_VALIDITY
   if (attr_ptr->VALID != MUTEX_VALID) {
      _KLOGX2(KLOG_mutex_init, MQX_EINVAL);
      return(MQX_EINVAL);
   } /* Endif */
#endif

   mutex_component_ptr = (MUTEX_COMPONENT_STRUCT_PTR)
      kernel_data->KERNEL_COMPONENTS[KERNEL_MUTEXES];
   if (mutex_component_ptr == NULL) {
      result = _mutex_create_component();
      mutex_component_ptr = (MUTEX_COMPONENT_STRUCT_PTR)
         kernel_data->KERNEL_COMPONENTS[KERNEL_MUTEXES];
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
      if (mutex_component_ptr == NULL){
         _KLOGX2(KLOG_mutex_init, result);
         return(result);
      } /* Endif */
#endif
   } /* Endif */

#if MQX_CHECK_VALIDITY
   if (mutex_component_ptr->VALID != MUTEX_VALID) {
      _KLOGX2(KLOG_mutex_init, MQX_INVALID_COMPONENT_BASE);
      return(MQX_INVALID_COMPONENT_BASE);
   } /* Endif */
#endif

   _int_disable();
#if MQX_CHECK_ERRORS
   /* Check if mutex is already initialized */
   mutex_chk_ptr = (MUTEX_STRUCT_PTR)
      ((pointer)mutex_component_ptr->MUTEXES.NEXT);
   while (mutex_chk_ptr != (MUTEX_STRUCT_PTR)
      ((pointer)&mutex_component_ptr->MUTEXES))
   {
      if (mutex_chk_ptr == mutex_ptr) {
         _int_enable();
         _KLOGX2(KLOG_mutex_init, MQX_EINVAL);
         return(MQX_EINVAL);
      } /* Endif */
      mutex_chk_ptr = (MUTEX_STRUCT_PTR)((pointer)mutex_chk_ptr->LINK.NEXT);
   } /* Endif */
#endif
   
   mutex_ptr->PROTOCOLS        = 
      attr_ptr->SCHED_PROTOCOL | attr_ptr->WAIT_PROTOCOL;
   mutex_ptr->VALID            = MUTEX_VALID;
   mutex_ptr->COUNT            = attr_ptr->COUNT;
   mutex_ptr->PRIORITY_CEILING = attr_ptr->PRIORITY_CEILING;
   mutex_ptr->LOCK             = 0;
   mutex_ptr->BOOSTED          = 0;
   mutex_ptr->OWNER_TD         = NULL;
   _QUEUE_INIT(&mutex_ptr->WAITING_TASKS, 0);

   _QUEUE_ENQUEUE(&mutex_component_ptr->MUTEXES, mutex_ptr);
   _int_enable();

   _KLOGX2(KLOG_mutex_init, MQX_EOK);
   return(MQX_EOK);
   
} /* Endbody */
예제 #8
0
파일: asrc.c 프로젝트: Vinhuit/Freescale
_mqx_uint _io_asrc_install
   (
      /* [IN] A string that identifies the device for fopen */
      char *               identifier,

      /* [IN] The I/O init function */
      _mqx_uint (_CODE_PTR_ init)(void *, void * *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ open)(void *, void *, char *),

      /* The I/O open function */
      _mqx_uint (_CODE_PTR_ close)(void *, void *),

      /* [IN] The I/O de-init function */
      _mqx_uint (_CODE_PTR_ deinit)(void *),

      /* [IN] The I/O ioctl function */
      _mqx_int  (_CODE_PTR_ ioctl)(void *, void *, _mqx_uint, _mqx_uint_ptr),

      /* [IN] The I/O init data pointer */
      void *               init_data_ptr,

      /* [IN] functions for pcm manager*/
      ASRC_PCMM_FUNCS_STRUCT_PTR   pcmm_funcs_ptr

   )

{ /* Body */
   IO_ASRC_DEVICE_STRUCT_PTR asrc_io_dev_ptr;
   MUTEX_ATTR_STRUCT mutex_attr;

   asrc_io_dev_ptr = (IO_ASRC_DEVICE_STRUCT_PTR)_mem_alloc_system_zero(
        (_mem_size)sizeof (IO_ASRC_DEVICE_STRUCT));
   if (asrc_io_dev_ptr == NULL)
   {
      return MQX_OUT_OF_MEMORY;
   }
   _mem_set_type (asrc_io_dev_ptr, MEM_TYPE_IO_ASRC_DEVICE_STRUCT);

   asrc_io_dev_ptr->DEV_INIT          = init;
   asrc_io_dev_ptr->DEV_OPEN          = open;
   asrc_io_dev_ptr->DEV_CLOSE         = close;
   asrc_io_dev_ptr->DEV_DEINIT        = deinit;
   asrc_io_dev_ptr->DEV_IOCTL         = ioctl;
   asrc_io_dev_ptr->DEV_INIT_DATA_PTR = init_data_ptr;
   asrc_io_dev_ptr->DEV_INFO_PTR      = NULL;
   asrc_io_dev_ptr->COUNT             = 0;

   asrc_io_dev_ptr->PCMM_DRV_FUNCS_PTR = pcmm_funcs_ptr;

   _mutatr_init(&mutex_attr);
   _mutatr_set_sched_protocol(&mutex_attr, MUTEX_PRIO_INHERIT);
   _mutex_init(&asrc_io_dev_ptr->DEV_MUTEX, &mutex_attr);

   if (NULL != pcmm_funcs_ptr) {
     /*register to pcm manager*/

     /*set pcm handle to a valid value*/
     asrc_io_dev_ptr->PCMM_DRV_HANDLE = PCMM_HANDLE_ASRC_VALID;

   }

   return (_io_dev_install_ext (identifier,
      _io_asrc_open,  _io_asrc_close,
      NULL,  NULL,
      _io_asrc_ioctl, _io_asrc_uninstall,
      (void *)asrc_io_dev_ptr));

} /* Endbody */