예제 #1
0
파일: wc_port.c 프로젝트: jakobsa/wolfssl
        int InitMutex(wolfSSL_Mutex* m)
        {
           Semaphore_Params params;
           Error_Block eb;
           Error_init(&eb);
           Semaphore_Params_init(&params);
           params.mode = Semaphore_Mode_BINARY;

           *m = Semaphore_create(1, &params, &eb);
           if( Error_check( &eb )  )
           {
               Error_raise( &eb, Error_E_generic, "Failed to Create the semaphore.",NULL);
           } else return 0;
        }
예제 #2
0
/*
 *  ======== SemProcessSupport_Instance_init ========
 */
Void SemProcessSupport_Instance_init(SemProcessSupport_Handle sem, 
    Int count, Int key, const SemProcessSupport_Params* params)
{
    Semaphore_Handle bios6sem;
    Semaphore_Params semParams;
    
    Semaphore_Params_init(&semParams);
    semParams.mode = (Semaphore_Mode)params->mode;

    bios6sem = SemProcessSupport_Instance_State_sem(sem);

    Semaphore_construct(
            Semaphore_struct(bios6sem), count, &semParams);
}
/* ========================================================================== */
TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreCreate(TIMM_OSAL_PTR *pSemaphore,
        TIMM_OSAL_U32  uInitCount)
{
    TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
    TIMM_OSAL_SEMAPHORE *pHandle = TIMM_OSAL_NULL;
    Semaphore_Params params;
    IArg keyOSALgate;

    *pSemaphore = TIMM_OSAL_NULL;
    pHandle = (TIMM_OSAL_SEMAPHORE *) TIMM_OSAL_Malloc(sizeof(TIMM_OSAL_SEMAPHORE),
              TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_EXT);

    if(TIMM_OSAL_NULL == pHandle)
    {
        bReturnStatus = TIMM_OSAL_ERR_ALLOC;
        goto EXIT;
    }

    /* Generate name of the semaphore */
    keyOSALgate = GateMutexPri_enter(gOSALgate);
    sprintf(pHandle->name, "SEM%lu", gUniqueSemNameCnt++);
    /*To prevent array overflow*/
    if(gUniqueSemNameCnt == 9999)
        gUniqueSemNameCnt = 0;
    GateMutexPri_leave(gOSALgate, keyOSALgate);

    /*Initialize with default values*/
    Semaphore_Params_init(&params);
    params.instance->name = (xdc_String)(pHandle->name);
    params.mode = Semaphore_Mode_COUNTING;

    pHandle->sem = Semaphore_create(uInitCount,&params,NULL);

    if(pHandle->sem == NULL)
    {
        TIMM_OSAL_Free(pHandle);
        bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
    }

    /* Update sem counter */
    gSemCnt++;

    *pSemaphore = (TIMM_OSAL_PTR)pHandle;

EXIT:
    return bReturnStatus;
}
bool_t osCreateMutex(OsMutex *mutex)
{
   Semaphore_Params semaphoreParams;

   //Set parameters
   Semaphore_Params_init(&semaphoreParams);
   semaphoreParams.mode = Semaphore_Mode_BINARY_PRIORITY;

   //Create a mutex
   mutex->handle = Semaphore_create(1, &semaphoreParams, NULL);

   //Check whether the returned handle is valid
   if(mutex->handle != NULL)
      return TRUE;
   else
      return FALSE;
}
bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count)
{
   Semaphore_Params semaphoreParams;

   //Set parameters
   Semaphore_Params_init(&semaphoreParams);
   semaphoreParams.mode = Semaphore_Mode_COUNTING;

   //Create a semaphore
   semaphore->handle = Semaphore_create(count, &semaphoreParams, NULL);

   //Check whether the returned handle is valid
   if(semaphore->handle != NULL)
      return TRUE;
   else
      return FALSE;
}
예제 #6
0
/*
 *  ======== main ========
 */
Int main()
{       
    Clock_Params     clkParams;
    Task_Params      tskParams;
    Mailbox_Params   mbxParams;
    Semaphore_Params semParams;
    
    /* Create a one-shot Clock Instance with timeout = 5 system time units */
    Clock_Params_init(&clkParams);
    clkParams.startFlag = TRUE;
    clk1 = Clock_create(clk0Fxn, 5, &clkParams, NULL);
    
    /* Create an one-shot Clock Instance with timeout = 10 system time units */
    Clock_Params_init(&clkParams);
    clkParams.startFlag = TRUE;
    clk2 = Clock_create(clk1Fxn, 10, &clkParams, NULL);

    /* create an Event Instance */
    evt = Event_create(NULL, NULL);
    
    /* create a Semaphore Instance */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    semParams.event = evt;
    semParams.eventId = Event_Id_01;
    sem = Semaphore_create(0, &semParams, NULL);

    /* create a Mailbox Instance */
    Mailbox_Params_init(&mbxParams);
    mbxParams.readerEvent = evt;
    mbxParams.readerEventId = Event_Id_02;
    mbx = Mailbox_create(sizeof(MsgObj), 2, &mbxParams, NULL);

    /* create a writer task */
    Task_Params_init(&tskParams);
    tskParams.priority = 1;
    tskParams.arg0 = (UArg) mbx;
    Task_create(writer, &tskParams, NULL);

    /* create a reader task */
    Task_create(reader, &tskParams, NULL);

    BIOS_start();    /* does not return */
    return(0);
}
예제 #7
0
/*
 *  ======== SemProcessSupport_Instance_init ========
 */
Void SemProcessSupport_Instance_init(SemProcessSupport_Handle sem, 
    Int count, Int key, const SemProcessSupport_Params* params)
{
    Semaphore_Handle bios6sem;
    Semaphore_Params semParams;
    
    Semaphore_Params_init(&semParams);
    if (params->mode == ISemaphore_Mode_COUNTING) {
        semParams.mode = Semaphore_Mode_COUNTING;
    }
    else {
        semParams.mode = Semaphore_Mode_BINARY;
    }

    bios6sem = SemProcessSupport_Instance_State_sem(sem);

    Semaphore_construct(
            Semaphore_struct(bios6sem), count, &semParams);
}
예제 #8
0
/*
 *  ======== SyncSem_Instance_init ========
 */
Int  SyncSem_Instance_init(SyncSem_Object *obj, const SyncSem_Params *params,
                           Error_Block *eb)
{
    Semaphore_Params semPrms;

    if (params->sem == NULL) {
        Semaphore_Params_init(&semPrms);
        semPrms.mode = Semaphore_Mode_BINARY;
        obj->sem = Semaphore_create(0, &semPrms, eb);
        if (obj->sem == NULL) {
            return (1);
        }
        obj->userSem = FALSE;
    }
    else {
        obj->userSem = TRUE;
        obj->sem = params->sem;
        Assert_isTrue(!Semaphore_getCount(obj->sem), NULL);
    }

    return (0);
}
/*******************************************************************************
 * @fn          devpkLcdOpen
 *
 * @brief       Initialize the LCD
 *
 * @descr       Initializes the pins used by the LCD, creates resource access
 *              protection semaphore, turns on the LCD device, initializes the
 *              frame buffer, initializes to white background/dark foreground,
 *              and finally clears the display.
 *
 * @return      true if success
 */
bool devpkLcdOpen(void)
{
  hLcdPin = PIN_open(&pinState, BoardDevpackLCDPinTable);

  if (hLcdPin != 0)
  {
    display.bg = ClrBlack;
    display.fg = ClrWhite;

    // Open the SPI driver
    bspSpiOpen();

    // Exclusive access
    Semaphore_Params_init(&semParamsLCD);
    semParamsLCD.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&semLCD, 1, &semParamsLCD);
    hSemLCD = Semaphore_handle(&semLCD);

    // Turn on the display
    PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,1);

    // Graphics library init
    GrContextInit(&g_sContext, &g_sharp96x96LCD);

    // Graphics properties
    GrContextForegroundSet(&g_sContext, display.fg);
    GrContextBackgroundSet(&g_sContext, display.bg);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);

    // Clear display
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);
  }

  return hLcdPin != 0;
}
예제 #10
0
int main(void) {

  //Initialize pins, turn on GPIO module
  PIN_init(BoardGpioInitTable);

  //Initialize task
  Task_Params params;
  Task_Params_init(&params);
  params.priority = TASK_PRI;
  params.stackSize = TASK_STACK_SIZE;
  params.stack = taskStack;

  Task_construct(&taskStruct, taskFxn, &params, NULL);

  // Construct semaphore used for pending in task
  Semaphore_Params sParams;
  Semaphore_Params_init(&sParams);
  sParams.mode = Semaphore_Mode_BINARY;

  Semaphore_construct(&sem, 0, &sParams);
  hSem = Semaphore_handle(&sem);

  BIOS_start();
}
/*
 *  ======== ECCROMCC26XX_init ========
 */
void ECCROMCC26XX_init(void)
{
  static uint8_t isInit = 0;
  unsigned int key;
  
  // Enter critical section.
  key = Hwi_disable();
  
  if (!isInit)
  {
    Semaphore_Params semParams;
    
    // Only initialize once.
    isInit = 1;

    // Setup semaphore for sequencing accesses to ECC
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    ECC_semaphore = Semaphore_create(1, &semParams, NULL);
  }
  
  // Exit critical section.
  Hwi_restore(key);
}
예제 #12
0
// External mode startup function
void rtExtModeC6000Startup( RTWExtModeInfo *ei,
                            int_T          numSampTimes,
                            boolean_T      *stopReqPtr)
{
    Task_Params attr;
    Task_Params_init(&attr);
    Semaphore_Params sem_params; 
    Semaphore_Params_init(&sem_params);

    sem_params.mode = ti_sysbios_knl_Semaphore_Mode_BINARY; 
  
    sExtStepArgs.ei = ei;
    sExtStepArgs.numSampTimes = numSampTimes;
    sExtStepArgs.stopReqPtr = stopReqPtr;
    attr.arg1 = (UArg) &sExtStepArgs;

    // Set external mode state to 
    extmodeSimStatus = EXTMODE_STARTUP;

	// Initialize semaphores used for external mode
	// communication
    uploadSem = Semaphore_create(1, &sem_params, NULL);
    extStartStopSem = Semaphore_create(1, NULL, NULL);

    // Pause until Ethernet network initialization completes
    //waitNetworkStartup();
    extmodeSimStatus = EXTMODE_NET_INITIALIZED;

    // Initialize user data structure
    rtExtModeInitUD();
    rt_ExtModeInit();

    // Create external mode task
    attr.priority = 1;
    attr.stack = (Ptr) &stack_pkt_tid[0];
    attr.stackSize = EXT_MODE_TSK_STACK_SIZE;
    extern_pkt_tid = Task_create( (Task_FuncPtr) rtExtModeOneStep,
        &attr, NULL );
    if (extern_pkt_tid == NULL) 
    {
        printf("handle taskpawn error");
    }

 
    /*
     * Pause until receive model start packet - if external mode.
     * Make sure the external mode tasks are running so that 
     * we are listening for commands from the host.
     */
    extmodeSimStatus = EXTMODE_WAITING_START_PACKET;
    modelStatus      = TARGET_STATUS_WAITING_TO_START;
    if (ExtWaitForStartPkt()) 
    {
        printf("\nWaiting for start packet from host.\n");
        // rt_PktServerWork() function posts a semaphore when
        // it receives start packet from host
        // this function in turn runs as part of rt_PktServer task
        //Semaphore_pend(extStartStopSem, BIOS_WAIT_FOREVER);
        while (rt_PktServerWork(ei, numSampTimes, stopReqPtr) != EXT_MODEL_START)
        {
        };
    }
    modelStatus      = TARGET_STATUS_RUNNING;
    extmodeSimStatus = EXTMODE_RUNNING;
}
예제 #13
0
/*
 *  ======== main ========
 */
Void main()
{
  PIN_init(BoardGpioInitTable);


  //enable iCache prefetching
   VIMSConfigure(VIMS_BASE, TRUE, TRUE);
   
   // Enable cache
   VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);

#ifndef POWER_SAVING
    /* Set constraints for Standby, powerdown and idle mode */
    Power_setConstraint(Power_SB_DISALLOW);
    Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif // POWER_SAVING
    

    //Initialize task
    Task_Params params;
    Task_Params_init(&params);
    params.priority = TASK_PRI;
    params.stackSize = TASK_STACK_SIZE;
    params.stack = taskStack;

    //semaphore init
    Semaphore_Params sParams;
    Semaphore_Params_init(&sParams);
    sParams.mode = Semaphore_Mode_BINARY;


    /* Initialize ICall module */
    ICall_init();

    /* Start tasks of external images - Priority 5 */
    ICall_createRemoteTasks();
    
    /* Kick off profile - Priority 3 */
    GAPRole_createTask();
    
    SimpleBLEPeripheral_createTask();

    //Contruct task
    Task_construct(&taskStruct, taskFxn, &params, NULL);

    // Construct semaphore used for pending in task ADC
    Semaphore_construct(&sem, 0, &sParams);
    hSem = Semaphore_handle(&sem);

#ifdef FEATURE_OAD_BIM
    {
      uint8_t counter;
      uint32_t *vectorTable =  (uint32_t*) 0x20000000;
      uint32_t *flashVectors = &__vector_table;
      
      // Write image specific interrupt vectors into RAM vector table.
      for(counter = 0; counter < 15; ++counter)
      {
        *vectorTable++ = *flashVectors++;
      }
    }
#endif //FEATURE_OAD_BIM
    
    /* enable interrupts and start SYS/BIOS */
    BIOS_start();
}
예제 #14
0
/*!
 *  @brief  Function to initialize the CC26XX SPI peripheral specified by the
 *          particular handle. The parameter specifies which mode the SPI
 *          will operate.
 *
 *  The function will set a dependency on it power domain, i.e. power up the
 *  module and enable the clock. The IOs are allocated. Neither the SPI nor UDMA module
 *  will be enabled.
 *
 *  @pre    SPI controller has been initialized.
 *          Calling context: Task
 *
 *  @param  handle        A SPI_Handle
 *
 *  @param  params        Pointer to a parameter block, if NULL it will use
 *                        default values
 *
 *  @return A SPI_Handle on success or a NULL on an error or if it has been
 *          already opened
 *
 *  @sa     SPICC26XXDMA_close()
 */
SPI_Handle SPICC26XXDMA_open(SPI_Handle handle, SPI_Params *params)
{
    /* Use union to save on stack allocation */
    union {
        Semaphore_Params semParams;
        Hwi_Params hwiParams;
    } paramsUnion;
    SPI_Params               defaultParams;
    SPICC26XX_Object         *object;
    SPICC26XX_HWAttrs const  *hwAttrs;
    unsigned int             key;

    /* Get the pointer to the object and hwAttrs */
    object = handle->object;
    hwAttrs = handle->hwAttrs;

    /* Disable preemption while checking if the SPI is open. */
    key = Hwi_disable();

    /* Check if the SPI is open already with the base addr. */
    if (object->isOpen == true) {
        Hwi_restore(key);

        Log_warning1("SPI:(%p) already in use.", hwAttrs->baseAddr);

        return (NULL);
    }

    /* Mark the handle as being used */
    object->isOpen = true;
    Hwi_restore(key);

    /* If params are NULL use defaults */
    if (params == NULL) {
        /* No params passed in, so use the defaults */
        SPI_Params_init(&defaultParams);
        params = &defaultParams;
    }

    Assert_isTrue((params->dataSize >= 4) &&
                  (params->dataSize <= 16), NULL);

    /* Initialize the SPI object */
    object->currentTransaction = NULL;
    object->bitRate            = params->bitRate;
    object->dataSize           = params->dataSize;
    object->frameFormat        = params->frameFormat;
    object->mode               = params->mode;
    object->transferMode       = params->transferMode;
    object->transferTimeout    = params->transferTimeout;
    object->returnPartial      = false;
#ifdef SPICC26XXDMA_WAKEUP_ENABLED
    object->wakeupCallbackFxn  = NULL;
#endif

    /* Determine if we need to use an 8-bit or 16-bit framesize for the DMA */
    object->frameSize = (params->dataSize < 9) ? SPICC26XXDMA_8bit : SPICC26XXDMA_16bit;

    Log_print2(Diags_USER2,"SPI:(%p) DMA buffer incrementation size: %s",
                            hwAttrs->baseAddr,
                           (object->frameSize) ? (UArg)"16-bit" : (UArg)"8-bit");

    /* Register power dependency - i.e. power up and enable clock for SPI. */
    Power_setDependency(hwAttrs->powerMngrId);

    /* Configure the hardware module */
    SPICC26XXDMA_initHw(handle);

    /* CSN is initialized using hwAttrs initially, but can be re-configured later */
    object->csnPin = hwAttrs->csnPin;

    /* Configure IOs after hardware has been initialized so that IOs aren't */
    /* toggled unnecessary and make sure it was successful */
    if (!SPICC26XXDMA_initIO(handle)) {
        /* Trying to use SPI driver when some other driver or application
        *  has already allocated these pins, error! */
        Log_warning0("Could not allocate SPI pins, already in use.");

        /* Release power dependency - i.e. potentially power down serial domain. */
        Power_releaseDependency(hwAttrs->powerMngrId);

        /* Mark the module as available */
        key = Hwi_disable();
        object->isOpen = false;
        Hwi_restore(key);

        /* Signal back to application that SPI driver was not succesfully opened */
        return (NULL);
    }

    /* Create the Hwi for this SPI peripheral. */
    Hwi_Params_init(&paramsUnion.hwiParams);
    paramsUnion.hwiParams.arg = (UArg) handle;
    Hwi_construct(&(object->hwi), (int) hwAttrs->intNum, SPICC26XXDMA_hwiFxn, &paramsUnion.hwiParams, NULL);

    /* Check the transfer mode */
    if (object->transferMode == SPI_MODE_BLOCKING) {
        Log_print1(Diags_USER2, "SPI DMA:(%p) in SPI_MODE_BLOCKING mode",
                                 hwAttrs->baseAddr);

        /* Create a semaphore to block task execution for the duration of the
         * SPI transfer */
        Semaphore_Params_init(&paramsUnion.semParams);
        paramsUnion.semParams.mode = Semaphore_Mode_BINARY;
        Semaphore_construct(&(object->transferComplete), 0, &paramsUnion.semParams);

        /* Store internal callback function */
        object->transferCallbackFxn = SPICC26XXDMA_transferCallback;
    }
    else {
        Log_print1(Diags_USER2, "SPI DMA:(%p) in SPI_MODE_CALLBACK mode", hwAttrs->baseAddr);

        /* Check to see if a callback function was defined for async mode */
        Assert_isTrue(params->transferCallbackFxn != NULL, NULL);

        /* Save the callback function pointer */
        object->transferCallbackFxn = params->transferCallbackFxn;
    }

    /* Declare the dependency on the UDMA driver */
    object->udmaHandle = UDMACC26XX_open();

    /* Configure PIN driver for CSN callback in optional RETURN_PARTIAL slave mode */
    /* and/or optional wake up on CSN assert slave mode */
    if (object->mode == SPI_SLAVE) {
        PIN_registerIntCb(object->pinHandle, SPICC26XXDMA_csnCallback);
        PIN_setUserArg(object->pinHandle, (UArg) handle);
    }

    Log_print1(Diags_USER1, "SPI:(%p) opened", hwAttrs->baseAddr);

    /* Register notification functions */
#ifdef SPICC26XXDMA_WAKEUP_ENABLED
    Power_registerNotify(&object->spiPreObj, Power_ENTERING_STANDBY, (Fxn)spiPreNotify, (UInt32)handle, NULL );
#endif
    Power_registerNotify(&object->spiPostObj, Power_AWAKE_STANDBY, (Fxn)spiPostNotify, (UInt32)handle, NULL );

    return (handle);
}
예제 #15
0
Int32 DupLink_drvCreate(DupLink_Obj * pObj, DupLink_CreateParams * pPrm)
{
    UInt32 outId, frameId;
    Int32 status;
    FVID2_Frame *pFrame;
    System_FrameInfo *pFrameInfo;
    Semaphore_Params semParams;

    memcpy(&pObj->createArgs, pPrm, sizeof(pObj->createArgs));
    UTILS_assert(pObj->createArgs.numOutQue <= DUP_LINK_MAX_OUT_QUE);

    pObj->putFrameCount = 0;
    pObj->getFrameCount = 0;

    memset(pObj->frames, 0, sizeof(pObj->frames));
    memset(pObj->frameInfo, 0, sizeof(pObj->frameInfo));

    status = System_linkGetInfo(pPrm->inQueParams.prevLinkId, &pObj->inTskInfo);
    UTILS_assert(status == FVID2_SOK);
    UTILS_assert(pPrm->inQueParams.prevLinkQueId < pObj->inTskInfo.numQue);

    pObj->info.numQue = pObj->createArgs.numOutQue;

    memcpy(&pObj->info.queInfo[0],
           &pObj->inTskInfo.queInfo[pPrm->inQueParams.prevLinkQueId],
           sizeof(pObj->inTskInfo.queInfo[0]));

    for (outId = 1; outId < pObj->info.numQue; outId++)
    {
        memcpy(&pObj->info.queInfo[outId],
               &pObj->info.queInfo[0], sizeof(pObj->info.queInfo[0]));
    }

    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;

    pObj->lock = Semaphore_create(1u, &semParams, NULL);

    for (outId = 0; outId < DUP_LINK_MAX_OUT_QUE; outId++)
    {
        status = Utils_bufCreate(&pObj->outFrameQue[outId], FALSE, FALSE);
        UTILS_assert(status == FVID2_SOK);

        for (frameId = 0; frameId < DUP_LINK_MAX_FRAMES_PER_OUT_QUE; frameId++)
        {
            pFrame =
                &pObj->frames[DUP_LINK_MAX_FRAMES_PER_OUT_QUE * outId +
                              frameId];
            pFrameInfo =
                &pObj->frameInfo[DUP_LINK_MAX_FRAMES_PER_OUT_QUE * outId +
                                 frameId];

            pFrame->appData = pFrameInfo;

            status = Utils_bufPutEmptyFrame(&pObj->outFrameQue[outId], pFrame);
            UTILS_assert(status == FVID2_SOK);
        }
    }

#ifdef SYSTEM_DEBUG_DUP
    Vps_printf(" %d: DUP   : Create Done !!!\n", Utils_getCurTimeInMsec());
#endif

    return FVID2_SOK;
}
예제 #16
0
/*
 *  ======== Server_setup ========
 *
 *  1. create semaphore object
 *  2. register notify callback
 *  3. wait until remote core has also registered notify callback
 *  4. create local & shared resources
 *  5. send resource ready event
 *  6. wait for remote resource ready event
 *  7. open remote resources
 *  8. handshake the ready event
 */
Int Server_setup(Void)
{
    Int                 status;
    UInt32              event;
    Semaphore_Params    semParams;
    RcmServer_Params    rcmServerP;


    Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_setup:");

    /*
     *  1. create semaphore object
     */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_COUNTING;
    Semaphore_construct(&Module.semS, 0, &semParams);
    Module.semH = Semaphore_handle(&Module.semS);


    /*
     *  2. register notify callback
     */
    status = Notify_registerEventSingle(Module.hostProcId, Module.lineId,
        Module.eventId, Server_notifyCB, (UArg)&Module);

    if (status < 0) {
        goto leave;
    }


    /*
     *  3. wait until remote core has also registered notify callback
     */
    do {
        status = Notify_sendEvent(Module.hostProcId, Module.lineId,
            Module.eventId, App_CMD_NOP, TRUE);

        if (status == Notify_E_EVTNOTREGISTERED) {
            Task_sleep(200);  /* ticks */
        }
    } while (status == Notify_E_EVTNOTREGISTERED);

    if (status < 0) {
        goto leave;
    }


    /*
     *  4. create local & shared resources (to be opened by remote processor)
     */


    /*
     *  5. send resource ready event
     */
    status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId,
        App_CMD_RESRDY, TRUE);

    if (status < 0) {
        goto leave;
    }


    /*
     *  6. wait for remote resource ready event
     */
    do {
        event = Server_waitForEvent();

        if (event >= App_E_FAILURE) {
            status = -1;
            goto leave;
        }
    } while (event != App_CMD_RESRDY);


    /*
     *  7. open remote resources
     */

    /* open the rcm heap */
    status = HeapBufMP_open(Global_RcmClientHeapName, &Module.heapH);

    if (status < 0) {
        Log_error1("Server_setup: HeapBufMP_open() returned error %d",
            (IArg)status);
        goto leave;
    }

    /* register the rcm heap with MessageQ */
    status = MessageQ_registerHeap((Ptr)(Module.heapH), Global_RcmClientHeapId);

    if (status < 0) {
        Log_error1("Server_setup: MessageQ_restierHeap() returned error %d",
            (IArg)status);
        goto leave;
    }

    /* initialize RcmServer create params */
    RcmServer_Params_init(&rcmServerP);
    rcmServerP.fxns.length = Server_fxnTab.length;
    rcmServerP.fxns.elem = Server_fxnTab.elem;

    /* create the RcmServer instance */
    status = RcmServer_create(Global_RcmServerName, &rcmServerP,
        &Module.rcmServerH);

    if (status < 0) {
        Log_error1("Server_setup: RcmServer_create() returned error %d",
            (IArg)status);
        goto leave;
    }

    /* start the server */
    RcmServer_start(Module.rcmServerH);


    /*
     *  8. handshake the ready event
     */
    status = Notify_sendEvent(Module.hostProcId, Module.lineId, Module.eventId,
        App_CMD_READY, TRUE);

    if (status < 0) {
        goto leave;
    }

    do {
        event = Server_waitForEvent();

        if (event >= App_E_FAILURE) {
            status = -1;
            goto leave;
        }
    } while (event != App_CMD_READY);


leave:
    Log_print1(Diags_EXIT, "<-- Server_setup: %d", (IArg)status);
    return(status);
}
/*!
 *  @brief Function to initialize a given I2C CC26XX peripheral specified by the
 *         particular handle. The parameter specifies which mode the I2C
 *         will operate.
 *
 *  After calling the open function, the I2C is enabled. If there is no active
 *  I2C transactions, the device can enter standby.
 *
 *  @pre    The I2CCC26XX_Config structure must exist and be persistent before this
 *          function can be called. I2CCC26XX has been initialized with I2CCC26XX_init().
 *          Calling context: Task
 *
 *  @param  handle   An I2C_Handle
 *
 *  @param  params   Pointer to a parameter block, if NULL it will use default values.
 *
 *  @return A I2C_Handle on success, or a NULL on an error or if it has been
 *          already opened.
 *
 *  @note  The generic I2C API should be used when accessing the I2CCC26XX.
 *
 *  @sa     I2CCC26XX_close(), I2CCC26XX_init(), I2C_open(), I2C_init()
 */
I2C_Handle I2CCC26XX_open(I2C_Handle handle, I2C_Params *params)
{
    union {
        Hwi_Params              hwiParams;
        Semaphore_Params        semParams;
    } paramsUnion;
    UInt                        key;
    I2C_Params                  i2cParams;
    I2CCC26XX_Object             *object;
    I2CCC26XX_HWAttrs const      *hwAttrs;

    /* Get the pointer to the object and hwAttrs */
    object = handle->object;
    hwAttrs = handle->hwAttrs;

    /* Determine if the device index was already opened */
    key = Hwi_disable();
    if(object->isOpen == true){
        Hwi_restore(key);
        return (NULL);
    }

    /* Mark the handle as being used */
    object->isOpen = true;
    Hwi_restore(key);

    /* Store the I2C parameters */
    if (params == NULL) {
        /* No params passed in, so use the defaults */
        I2C_Params_init(&i2cParams);
        params = &i2cParams;
    }

    /* Configure the IOs early to ensure allocation is allowed (PIN driver and IO config setup only).*/
    if (I2CCC26XX_initIO(handle, params->custom)) {
      /* If initialization and allocation of IOs failed, log error and return NULL pointer */
      Log_print1(Diags_USER1, "I2C: Pin allocation failed, open did not succeed (baseAddr:0x%x)", hwAttrs->baseAddr);
      return (NULL);
    }

    /* Save parameters */
    object->transferMode = params->transferMode;
    object->transferCallbackFxn = params->transferCallbackFxn;
    object->bitRate = params->bitRate;

    /* Create Hwi object for this I2C peripheral */
    Hwi_Params_init(&paramsUnion.hwiParams);
    paramsUnion.hwiParams.arg = (UArg)handle;
    Hwi_construct(&(object->hwi), hwAttrs->intNum, I2CCC26XX_hwiFxn,
                  &paramsUnion.hwiParams, NULL);

    /*
     * Create thread safe handles for this I2C peripheral
     * Semaphore to provide exclusive access to the I2C peripheral
     */
    Semaphore_Params_init(&paramsUnion.semParams);
    paramsUnion.semParams.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&(object->mutex), 1, &paramsUnion.semParams);

    /*
     * Store a callback function that posts the transfer complete
     * semaphore for synchronous mode
     */
    if (object->transferMode == I2C_MODE_BLOCKING) {
        /*
         * Semaphore to cause the waiting task to block for the I2C
         * to finish
         */
        Semaphore_construct(&(object->transferComplete), 0, &paramsUnion.semParams);

        /* Store internal callback function */
        object->transferCallbackFxn = I2CCC26XX_blockingCallback;
    }
    else {
        /* Check to see if a callback function was defined for async mode */
        Assert_isTrue(object->transferCallbackFxn != NULL, NULL);
    }

    /* Specify the idle state for this I2C peripheral */
    object->mode = I2CCC26XX_IDLE_MODE;

    /* Clear the head pointer */
    object->headPtr = NULL;
    object->tailPtr = NULL;

    /* Power on the I2C module */
    Power_setDependency(hwAttrs->powerMngrId);

    /* Initialize the I2C hardware module */
    I2CCC26XX_initHw(handle);

    /* Register notification functions */
    Power_registerNotify(&object->i2cPostObj, Power_AWAKE_STANDBY, (Fxn)i2cPostNotify, (UInt32)handle, NULL );

    Log_print1(Diags_USER1, "I2C: Object created 0x%x", hwAttrs->baseAddr);

    /* Return the address of the handle */
    return (handle);
}
예제 #18
0
Int32 System_init()
{
    Int32 status;

#ifdef SYSTEM_DEBUG
    const Char *versionStr;
#endif
    Vps_PlatformDeviceInitParams initPrms;
    Semaphore_Params semParams;
    Vps_PlatformInitParams platformInitPrms;

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : System VPSS Init in progress !!!\n",
               Utils_getCurTimeInMsec());
#endif
    System_dispCheckStopList();

    Utils_tilerAllocatorInit();

#ifdef SYSTEM_DEBUG_TILER_ALLOC
    Utils_tilerDebugLogEnable(TRUE);
#endif

#ifdef TI_814X_BUILD
    /* Need to set this bit only for ti814x to support tied vencs, pin mux settings */
    /* Need to call this before accessing HD VENC registers in FVID2_init()
        Other wise it may hang in access of HDVENC registers
    */
    (* (UInt32 *)0x481C52C8) = 0x01000000;
#endif

    platformInitPrms.isPinMuxSettingReq = TRUE;
    status = Vps_platformInit(&platformInitPrms);
    UTILS_assert(status == 0);

    Utils_dmTimerInit();
    IpcOutM3Link_init();
    IpcInM3Link_init();
    IpcFramesInLink_init();
    IpcFramesOutLink_init();
#ifdef SYSTEM_DEBUG
    /*
     * Get the version string
     */
    versionStr = FVID2_getVersionString();
    Vps_printf(" %d: SYSTEM : HDVPSS Drivers Version: %s\n",
               Utils_getCurTimeInMsec(), versionStr);
#endif

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : FVID2 Init in progress !!!\n",
               Utils_getCurTimeInMsec());
#endif
    /*
     * FVID2 system init
     */
    status = FVID2_init(NULL);
    UTILS_assert(status == 0);

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : FVID2 Init in progress DONE !!!\n",
               Utils_getCurTimeInMsec());
#endif

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : Device Init in progress !!!\n",
               Utils_getCurTimeInMsec());
#endif
#ifdef TI_814X_BUILD
  #ifdef TI814X_EVM_WITHOUT_VS_CARD
    initPrms.isI2cInitReq = FALSE;
    initPrms.isI2cProbingReq = FALSE;
  #else
    initPrms.isI2cInitReq = TRUE;
    initPrms.isI2cProbingReq = TRUE;
  #endif
#else
    initPrms.isI2cInitReq = TRUE;
    initPrms.isI2cProbingReq = TRUE;
#endif

#ifndef SYSTEM_USE_VIDEO_DECODER
    initPrms.isI2cInitReq = FALSE;
    initPrms.isI2cProbingReq = FALSE;
#endif


    Vps_printf("\ninitPrms.isI2cInitReq = %d\n", initPrms.isI2cInitReq);
    Vps_printf("\ninitPrms.isI2cInitReq = %d\n", initPrms.isI2cProbingReq);
    status = Vps_platformDeviceInit(&initPrms);
    UTILS_assert(status == 0);

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : Device Init in progress DONE !!!\n",
               Utils_getCurTimeInMsec());
#endif

#ifdef TI816X_DVR
    status = Vps_tvp5158Init();
#endif

#ifdef SYSTEM_DEBUG_VIP_RES_ALLOC
   /*
     * enable logs from VIP resource allocator
     */
   Vcore_vipResDebugLogEnable(TRUE);
#endif

   Semaphore_Params_init(&semParams);
   semParams.mode = Semaphore_Mode_BINARY;

   gSystem_objVpss.vipLock[SYSTEM_VIP_0] =
        Semaphore_create(1u, &semParams, NULL);
   UTILS_assert(gSystem_objVpss.vipLock[SYSTEM_VIP_0] != NULL);

   Semaphore_Params_init(&semParams);
   semParams.mode = Semaphore_Mode_BINARY;

   gSystem_objVpss.vipLock[SYSTEM_VIP_1] =
       Semaphore_create(1u, &semParams, NULL);
   UTILS_assert(gSystem_objVpss.vipLock[SYSTEM_VIP_1] != NULL);

   System_clearVipResetFlag(SYSTEM_VIP_0);
   System_clearVipResetFlag(SYSTEM_VIP_1);

   System_allocBlankFrame();

#ifdef SYSTEM_DEBUG
    Vps_printf(" %d: SYSTEM  : System VPSS Init Done !!!\n", Utils_getCurTimeInMsec());
#endif

   Utils_dmaInit();

   System_initLinks();

   return status;
}
Int SystemCfg_create(const SystemCfg_Params *params, SystemCfg_Handle *handleP)
{
    Int                 status, bufSize;
    Error_Block         eb;
    SystemCfg_Object *  obj;
    Semaphore_Params    semParams;


    Log_print0(Diags_ENTRY, "--> "FXNN": ()");

    /* initialize local vars */
    status = 0;
    Error_init(&eb);
    *handleP = (SystemCfg_Handle)NULL;

    /* allocate the object */
    obj = (SystemCfg_Handle)xdc_runtime_Memory_calloc(NULL,
        sizeof(SystemCfg_Object), sizeof(Int), &eb);

    if (obj == NULL) {
        Log_error1(FXNN": out of memory: size=%u", sizeof(SystemCfg_Object));
        status = SystemCfg_E_NOMEMORY;
        goto leave;
    }

    /* object-specific initialization */
    obj->remoteProcName = NULL;
    obj->remoteProcId = MultiProc_INVALIDID;
    obj->semH = NULL;
    obj->rcmHeapH = NULL;
    
    /* initialize structures to zero */
    memset((Void *)&obj->semObj, 0, sizeof(Semaphore_Struct));

    /* store the remote processor name */
    bufSize = strlen(params->remoteProcName) + 1;
    obj->remoteProcName = (String)xdc_runtime_Memory_calloc(NULL,
        bufSize, sizeof(String), &eb);

    if (obj == NULL) {
        Log_error1(FXNN": out of memory: size=%u", bufSize);
        status = SystemCfg_E_NOMEMORY;
        goto leave;
    }

    strcpy(obj->remoteProcName, params->remoteProcName);

    /* lookup the remote processor id */
    obj->remoteProcId = MultiProc_getId(obj->remoteProcName);

    /* create sync object used for synchronizing with remote core */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_COUNTING;
    Semaphore_construct(&obj->semObj, 0, &semParams);
    obj->semH = Semaphore_handle(&obj->semObj);

    /* add object to module list for register hook */
    List_putHead(Mod_objList, &obj->link);

    /* success, return opaque pointer */
    *handleP = (SystemCfg_Handle)obj;

leave:
    Log_print1(Diags_EXIT, "<-- "FXNN": %d", (IArg)status);
    return(status);
}
예제 #20
0
/*
 *  ======== pthread_create ========
 */
int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
        void *(*startroutine)(void *), void *arg)
{
    Semaphore_Params  semParams;
    Task_Params       taskParams;
    pthread_Obj      *thread = NULL;
    Error_Block       eb;
    pthread_attr_t   *pAttr;

    Error_init(&eb);
    Task_Params_init(&taskParams);

    *newthread = NULL;

    thread = (pthread_Obj *)Memory_alloc(Task_Object_heap(),
            sizeof(pthread_Obj), 0, &eb);

    if (thread == NULL) {
        return (ENOMEM);
    }

    pAttr = (attr == NULL) ? &defaultPthreadAttrs : (pthread_attr_t *)attr;

    taskParams.priority = pAttr->priority;
    taskParams.stack = pAttr->stack;
    taskParams.stackSize = pAttr->stacksize + pAttr->guardsize;

    /* Save the function in arg0 for ROV */
    taskParams.arg0 = (UArg)startroutine;
    taskParams.arg1 = (UArg)thread;
    taskParams.env = arg;
    taskParams.priority = -1;

    thread->detached = (pAttr->detachstate == PTHREAD_CREATE_JOINABLE) ? 0 : 1;
    thread->fxn = startroutine;
    thread->joinThread = NULL;
    thread->cancelState = PTHREAD_CANCEL_ENABLE;
    thread->cancelPending = 0;
    thread->priority = pAttr->priority;
    thread->cleanupList = NULL;

#if ti_sysbios_posix_Settings_supportsMutexPriority__D
    thread->blockedMutex = NULL;
    Queue_elemClear((Queue_Elem *)thread);
    Queue_construct(&(thread->mutexList), NULL);
#endif

    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;

    Semaphore_construct(&(thread->joinSem), 0, &semParams);

    thread->task = Task_create((Task_FuncPtr)_pthread_runStub,
            &taskParams, &eb);

    if (thread->task == NULL) {
        Semaphore_destruct(&(thread->joinSem));

#if ti_sysbios_posix_Settings_supportsMutexPriority__D
        Queue_destruct(&(thread->mutexList));
#endif
        Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));

        return (ENOMEM);
    }

    *newthread = (pthread_t)thread;
    Task_setPri(thread->task, pAttr->priority);

    return (0);
}
예제 #21
0
Int32 DisplayLink_drvCreate(DisplayLink_Obj * pObj,
                            DisplayLink_CreateParams * pPrm)
{
    Semaphore_Params semParams;
    Int32 status = FVID2_SOK;

#ifdef SYSTEM_DEBUG_DISPLAY
    Vps_printf(" %d: DISPLAY: Create in progress !!!\n", Utils_getCurTimeInMsec());
#endif

    pObj->cbCount = 0;
    pObj->dequeCount = 0;
    pObj->totalTime = 0;
    pObj->minCbTime = 0xFF;
    pObj->maxCbTime = 0;
    pObj->lastCbTime = 0;
    pObj->maxLatency = 0;
    pObj->minLatency = 0xFF;
    pObj->drvTopFieldLatency = 0;
    pObj->numTopFields = 0;

    pObj->inFrameGetCount = 0;
    pObj->inFramePutCount = 0;

    memcpy(&pObj->createArgs, pPrm, sizeof(*pPrm));

    UTILS_assertError((pPrm->activeQueue < UTILS_ARRAYSIZE(pPrm->inQueParams)),
                      status,
                      -1,
                      pObj->tskId,
                      -1);
    if (status != FVID2_SOK)
    {
        pPrm->activeQueue = 0;
    }
    DisplayLink_drvSetFieldSeparatedInfo(pObj);
    status = System_linkGetInfo(pPrm->inQueParams[pPrm->activeQueue].prevLinkId,
                                &pObj->inTskInfo[pPrm->activeQueue]);
    UTILS_assert(status == FVID2_SOK);
    UTILS_assert(pPrm->inQueParams[pPrm->activeQueue].prevLinkQueId <
                 pObj->inTskInfo[pPrm->activeQueue].numQue);

    memcpy(&pObj->inQueInfo,
           &pObj->inTskInfo[pPrm->activeQueue].queInfo[pPrm->inQueParams[pPrm->activeQueue].prevLinkQueId],
           sizeof(pObj->inQueInfo));
    pObj->curActiveQueue = pPrm->activeQueue;
    pObj->numBufsInDriver = 0;
    pObj->topField = NULL;
    pObj->nextFid  = FVID2_FID_TOP;
    Semaphore_Params_init(&semParams);

    semParams.mode = Semaphore_Mode_BINARY;

    pObj->lock = Semaphore_create(1u, &semParams, NULL);
    UTILS_assert(pObj->lock != NULL);

    Semaphore_Params_init(&semParams);

    semParams.mode = Semaphore_Mode_BINARY;

    pObj->complete = Semaphore_create(0u, &semParams, NULL);
    UTILS_assert(pObj->complete != NULL);

    DisplayLink_drvDisplayCreate(pObj);
    DisplayLink_drvCreateFrameInfo(pObj);
    DisplayLink_drvCreateRtParams(pObj);
    DisplayLink_drvDisplayAllocAndQueBlankFrame(pObj);
    DisplayLink_drvSwitchCh(pObj, 0);
    DisplayLink_drvSetPitchInfo(pObj);


#ifdef SYSTEM_DEBUG_DISPLAY
    Vps_printf(" %d: DISPLAY: Create Done !!!\n", Utils_getCurTimeInMsec());
#endif

    return FVID2_SOK;
}
/*
 *  ======== USBMSCHFatFsTiva_open ========
 */
USBMSCHFatFs_Handle USBMSCHFatFsTiva_open(USBMSCHFatFs_Handle handle,
                                          unsigned char drv,
                                          USBMSCHFatFs_Params *params)
{
    unsigned int                    key;
    DRESULT                         dresult;
    FRESULT                         fresult;
    USBMSCHFatFsTiva_Object        *object = handle->object;
    USBMSCHFatFsTiva_HWAttrs const *hwAttrs = handle->hwAttrs;
    union {
        Task_Params                 taskParams;
        Semaphore_Params            semParams;
        GateMutex_Params            gateParams;
        Hwi_Params                  hwiParams;
    } paramsUnion;

    /* Determine if the device was already opened */
    key = Hwi_disable();
    if (object->driveNumber != DRIVE_NOT_MOUNTED) {
        Hwi_restore(key);
        return (NULL);
    }
    /* Mark as being used */
    object->driveNumber = drv;
    Hwi_restore(key);

    /* Store the USBMSCHFatFs parameters */
    if (params == NULL) {
        /* No params passed in, so use the defaults */
        params = (USBMSCHFatFs_Params *) &USBMSCHFatFs_defaultParams;
    }

    /* Initialize the USB stack for host mode. */
    USBStackModeSet(0, eUSBModeHost, NULL);

    /* Register host class drivers */
    USBHCDRegisterDrivers(0, usbHCDDriverList, numHostClassDrivers);

    /* Open an instance of the MSC host driver */
    object->MSCInstance = USBHMSCDriveOpen(0, USBMSCHFatFsTiva_cbMSCHandler);
    if (!(object->MSCInstance)) {
        Log_print0(Diags_USER1,"USBMSCHFatFs: Error initializing the MSC Host");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Create the Hwi object to service interrupts */
    Hwi_Params_init(&(paramsUnion.hwiParams));
    paramsUnion.hwiParams.priority = hwAttrs->intPriority;

    Hwi_construct(&(object->hwi), hwAttrs->intNum, USBMSCHFatFsTiva_hwiHandler,
                 &(paramsUnion.hwiParams), NULL);

    /* Initialize USB power configuration */
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    /* Enable the USB stack */
    USBHCDInit(0, object->memPoolHCD, HCDMEMORYPOOLSIZE);

    /* RTOS primitives */
    Semaphore_Params_init(&(paramsUnion.semParams));
    paramsUnion.semParams.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&(object->semUSBConnected), 0, &(paramsUnion.semParams));

    GateMutex_Params_init(&(paramsUnion.gateParams));
    paramsUnion.gateParams.instance->name = "USB Library Access";
    GateMutex_construct(&(object->gateUSBLibAccess), &(paramsUnion.gateParams));

    paramsUnion.gateParams.instance->name = "USB Wait";
    GateMutex_construct(&(object->gateUSBWait), &(paramsUnion.gateParams));

    /*
     * Note that serviceUSBHost() should not be run until the USB Stack has been
     * initialized!!
     */
    Task_Params_init(&(paramsUnion.taskParams));

    /*
     * If serviceTaskStackPtr is null, then Task_construct performs a
     * Memory_alloc - requiring a Heap
     */
    paramsUnion.taskParams.stack = params->serviceTaskStackPtr;

    /*
     * If service priority passed in is higher than what is configured by the
     * Task module, then use the highest priority available.
     */
    if (Task_numPriorities - 1 < params->servicePriority) {
        paramsUnion.taskParams.priority = (Task_numPriorities - 1);
    }
    else {
        paramsUnion.taskParams.priority = params->servicePriority;
    }

    /* If no stack size is passed in, then use the default task stack size */
    if (params->serviceTaskStackSize) {
        paramsUnion.taskParams.stackSize = params->serviceTaskStackSize;
    }
    else {
        paramsUnion.taskParams.stackSize = Task_defaultStackSize;
    }

    Task_construct(&(object->taskHCDMain),USBMSCHFatFsTiva_serviceUSBHost,
                   &(paramsUnion.taskParams), NULL);

    /* Register the new disk_*() functions */
    dresult = disk_register(drv,
                            USBMSCHFatFsTiva_diskInitialize,
                            USBMSCHFatFsTiva_diskStatus,
                            USBMSCHFatFsTiva_diskRead,
                            USBMSCHFatFsTiva_diskWrite,
                            USBMSCHFatFsTiva_diskIOctl);

    /* Check for drive errors */
    if (dresult != RES_OK) {
        Log_error0("USBMSCHFatFs: disk functions not registered");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Mount the FatFs (this function does not access the SDCard yet...) */
    fresult = f_mount(drv, &(object->filesystem));
    if (fresult != FR_OK) {
        Log_error1("USBMSCHFatFs: drive %d not mounted", drv);
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    Log_print1(Diags_USER1, "USBMSCHFatFs: drive %d opened", drv);

    return (handle);
}
예제 #23
0
Void * _semCreate(Int key, Int count)
{
    Semaphore_Params semParams;
    Semaphore_Params_init(&semParams);
    return ((Void *)(Semaphore_create(count, &semParams, NULL)));
}
예제 #24
0
/*
 *  ======== USBCDCMOUSE_init ========
 */
void USBCDCMOUSE_init(void)
{
    Error_Block eb;
    Semaphore_Params semParams;
    GateMutex_Params gateParams;

    Error_init(&eb);

    /* RTOS primitives */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    semParams.__iprms.name = "semTxSerial";
    semTxSerial = Semaphore_create(0, &semParams, &eb);
    if (semTxSerial == NULL) {
        System_abort("Can't create TX semaphore");
    }

    semParams.__iprms.name = "semRxSerial";
    semRxSerial = Semaphore_create(0, &semParams, &eb);
    if (semRxSerial == NULL) {
        System_abort("Can't create RX semaphore");
    }

    semParams.__iprms.name = "semMouse";
    semMouse = Semaphore_create(0, &semParams, &eb);
    if (semMouse == NULL) {
        System_abort("Can't create USB semaphore");
    }

    semParams.__iprms.name = "semUSBConnected";
    semUSBConnected = Semaphore_create(0, &semParams, &eb);
    if (semUSBConnected == NULL) {
        System_abort("Can't create USB semaphore");
    }

    GateMutex_Params_init(&gateParams);
    gateParams.__iprms.name = "gateTxSerial";
    gateTxSerial = GateMutex_create(NULL, &eb);
    if (gateTxSerial == NULL) {
        System_abort("Can't create gate");
    }

    gateParams.__iprms.name = "gateRxSerial";
    gateRxSerial = GateMutex_create(NULL, &eb);
    if (gateRxSerial == NULL) {
        System_abort("Can't create gate");
    }

    gateParams.__iprms.name = "gateMouse";
    gateMouse = GateMutex_create(NULL, &eb);
    if (gateMouse == NULL) {
        System_abort("Can't create mouse gate");
    }

    gateParams.__iprms.name = "gateUSBWait";
    gateUSBWait = GateMutex_create(NULL, &eb);
    if (gateUSBWait == NULL) {
        System_abort("Could not create USB Wait gate");
    }

    /* Initialize the USB module, enable events and connect if UBUS is present */
    USB_setup(true, true);
}