Example #1
0
 int InitMutex(wolfSSL_Mutex* m)
 {
     if (_mutex_init(m, NULL) == MQX_EOK)
         return 0;
     else
         return BAD_MUTEX_E;
 }
Example #2
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*/
Example #3
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();
}   
Example #4
0
void 
gc_jd_queue_init(gc_jd_queue_t *q)
{
  _mutex_init(ptr_to_ea(&q->mutex));
  q->head = 0;
  q->tail = 0;
  smp_wmb();
}
Example #5
0
/**
  * @brief: UART2 must be init before call this function
  *
  */
void trace_init(void)
{
    _mqx_uint err;

    err = _mutex_init(&g_trace_mutex, NULL);
    ASSERT_PARAM(err == MQX_EOK);

   // init_uart0(uart0_irq_handler);
	init_uart1(uart1_irq_handler);
}
Example #6
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);
}
Example #7
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);

} 
Example #8
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;
}
Example #9
0
os_mutex_handle OS_Mutex_create()
{
    MUTEX_STRUCT_PTR mutex = NULL;
    mutex = _mem_alloc_system_zero(sizeof(MUTEX_STRUCT));
    if (mutex == NULL)
    {
        return NULL;
    }
    if (_mutex_init(mutex, NULL) != MQX_OK)
    {
        _mem_free(mutex);
        return NULL;
    }
    return (os_mutex_handle)mutex;
}
Example #10
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 */
Example #11
0
//=============================================================================
//                Public Function Definition
//=============================================================================
int
msgq_create_handle(
    msgq_handle_t       **ppHMsgq,
    msgq_init_info_t    *pInit_info)
{
    int             result = ERRCODE_OK;
    msgq_dev_t      *pDev = 0;

    do{
        if( !ppHMsgq || !pInit_info )
        {
            result = ERRCODE_NULL_POINTER;
            err_msg("err, NULL pointer !!\n");
            break;
        }

        if( *ppHMsgq != 0 )
        {
            result = ERRCODE_INVALID_PARAM;
            err_msg("err, Exist msgq handle !!\n");
            break;
        }

        if( !pInit_info->max_msg_num )
        {
            result = ERRCODE_INVALID_PARAM;
            err_msg("err, invalid parameter !!\n");
            break;
        }

        // -------------------------------
        // create device
        if( !(pDev = malloc(sizeof(msgq_dev_t))) )
        {
            result = ERRCODE_MALLOC_FAIL;
            err_msg("err, malloc fail !\n");
            break;
        }
        memset(pDev, 0x0, sizeof(msgq_dev_t));

        // create node list
        if( !(pDev->ppNode_list = malloc(pInit_info->max_msg_num*sizeof(msg_node_t*))) )
        {
            result = ERRCODE_MALLOC_FAIL;
            err_msg("err, malloc fail !\n");
            break;
        }
        memset(pDev->ppNode_list, 0x0, pInit_info->max_msg_num*sizeof(msg_node_t*));

        //---------------------------------
        // init parameter
        pDev->hMsgq.max_msg_cnt = pInit_info->max_msg_num;
        pDev->node_max_num      = pInit_info->max_msg_num;
        pDev->node_idx_r        = 0;//-1;

        _mutex_init(pDev->mutex);

        //----------------------
        (*ppHMsgq) = &pDev->hMsgq;

    }while(0);

    if( result )
    {
        msgq_handle_t   *pHMsgq = &pDev->hMsgq;
        msgq_destroy_handle(&pHMsgq);

        err_msg("err %d !\n", result);
    }

    return result;
}
Example #12
0
void _cklock_init(cklock_t *lock, const char *file, const char *func, const int line)
{
	_mutex_init(&lock->mutex, file, func, line);
	_rwlock_init(&lock->rwlock, file, func, line);
}
Example #13
0
_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 */