/* Function: void _USB_DEVICE_CDC_GlobalInitialize ( void ) Summary: This function initializes resourses required common to all instances of CDC function driver. Description: This function initializes resourses common to all instances of CDC function driver. This function is called by the USB Device layer during Initalization. Remarks: This is local function and should not be called directly by the application. */ void _USB_DEVICE_CDC_GlobalInitialize (void) { OSAL_RESULT osal_err; /* Create Mutex for CDC IRP objects if not created already */ if (gUSBDeviceCdcCommonDataObj.isMutexCdcIrpInitialized == false) { /* This means that mutexes where not created. Create them. */ osal_err = OSAL_MUTEX_Create(&gUSBDeviceCdcCommonDataObj.mutexCDCIRP); if(osal_err != OSAL_RESULT_TRUE) { /*do not proceed lock was not created, let user know about error*/ return; } /* Set this flag so that global mutexes get allocated only once */ gUSBDeviceCdcCommonDataObj.isMutexCdcIrpInitialized = true; } }
uint32_t WDRV_MutexInit(OSAL_MUTEX_HANDLE_TYPE **mutex_ptr) { *mutex_ptr = malloc(sizeof(OSAL_MUTEX_HANDLE_TYPE)); OSAL_MUTEX_Create(*mutex_ptr) ; return 0; }
SYS_MODULE_OBJ NET_PRES_Initialize( const SYS_MODULE_INDEX index, const SYS_MODULE_INIT * const init ) { if (sNetPresData.initialized || !init) { return SYS_MODULE_OBJ_INVALID; } NET_PRES_INIT_DATA *pInitData = (NET_PRES_INIT_DATA*)init; if (pInitData->numLayers > NET_PRES_NUM_INSTANCE) { return SYS_MODULE_OBJ_INVALID; } memset(&sNetPresData, 0, sizeof(NET_PRES_InternalData)); if (OSAL_MUTEX_Create(&sNetPresData.presMutex) != OSAL_RESULT_TRUE) { return SYS_MODULE_OBJ_INVALID; } memset(&sNetPresSockets, 0, sizeof(NET_PRES_SocketData) * NET_PRES_NUM_SOCKETS); sNetPresData.initialized = true; sNetPresData.numLayers = pInitData->numLayers; uint8_t x; for (x = 0; x < sNetPresData.numLayers; x++) { if (pInitData->pInitData[x].pTransObject_ss) { memcpy(&sNetPresData.transObjectSS[x], pInitData->pInitData[x].pTransObject_ss, sizeof(NET_PRES_TransportObject)); } if (pInitData->pInitData[x].pTransObject_sc) { memcpy(&sNetPresData.transObjectSC[x], pInitData->pInitData[x].pTransObject_sc, sizeof(NET_PRES_TransportObject)); } if (pInitData->pInitData[x].pTransObject_ds) { memcpy(&sNetPresData.transObjectDS[x], pInitData->pInitData[x].pTransObject_ds, sizeof(NET_PRES_TransportObject)); } if (pInitData->pInitData[x].pTransObject_dc) { memcpy(&sNetPresData.transObjectDC[x], pInitData->pInitData[x].pTransObject_dc, sizeof(NET_PRES_TransportObject)); } if (pInitData->pInitData[x].pProvObject_ss) { memcpy(&sNetPresData.encProvObjectSS[x], pInitData->pInitData[x].pProvObject_ss, sizeof(NET_PRES_EncProviderObject)); } if (pInitData->pInitData[x].pProvObject_sc) { memcpy(&sNetPresData.encProvObjectSC[x], pInitData->pInitData[x].pProvObject_sc, sizeof(NET_PRES_EncProviderObject)); } if (pInitData->pInitData[x].pProvObject_ds) { memcpy(&sNetPresData.encProvObjectDS[x], pInitData->pInitData[x].pProvObject_ds, sizeof(NET_PRES_EncProviderObject)); } if (pInitData->pInitData[x].pProvObject_dc) { memcpy(&sNetPresData.encProvObjectDC[x], pInitData->pInitData[x].pProvObject_dc, sizeof(NET_PRES_EncProviderObject)); } } return (SYS_MODULE_OBJ)&sNetPresData; }
SYS_MODULE_OBJ DRV_USART_Initialize ( const SYS_MODULE_INDEX drvIndex, const SYS_MODULE_INIT * const init ) { DRV_USART_OBJ *dObj = (DRV_USART_OBJ*)NULL; DRV_USART_INIT *usartInit = NULL ; /* Check if the specified driver index is in valid range */ if(drvIndex >= DRV_USART_INSTANCES_NUMBER) { SYS_DEBUG(0, "Invalid driver index"); return SYS_MODULE_OBJ_INVALID; } /* Check if this hardware instance was already initialized */ if(gDrvUSARTObj[drvIndex].inUse != false) { SYS_DEBUG(0, "Instance already in use"); return SYS_MODULE_OBJ_INVALID; } /* Assign to the local pointer the init data passed */ usartInit = ( DRV_USART_INIT * ) init ; /* Disable the USART module */ PLIB_USART_Disable (usartInit->usartID) ; /* Allocate the driver object and set the operation flag to be in use */ dObj = &gDrvUSARTObj[drvIndex]; dObj->inUse = true; /* Update the USART PLIB Id and other parameters. */ dObj->nClients = 0; dObj->moduleId = usartInit->usartID; dObj->brgClock = usartInit->brgClock; dObj->isExclusive = false; dObj->queueSizeRead = usartInit->queueSizeReceive; dObj->queueSizeWrite = usartInit->queueSizeTransmit; dObj->dmaChannelRead = usartInit->dmaReceive; dObj->dmaChannelWrite = usartInit->dmaTransmit; dObj->txInterruptSource = usartInit->interruptTransmit; dObj->rxInterruptSource = usartInit->interruptReceive; dObj->errorInterruptSource = usartInit->interruptError; dObj->dmaInterruptTransmit = usartInit->dmaInterruptTransmit; dObj->dmaInterruptReceive = usartInit->dmaInterruptReceive; dObj->interruptNestingCount = 0; dObj->queueSizeCurrentRead = 0; dObj->queueSizeCurrentWrite = 0; /* Setup the Hardware */ _DRV_USART_HardwareSetup(usartInit->usartID, usartInit ) ; /* Clear the interrupts */ SYS_INT_SourceStatusClear(dObj->txInterruptSource); SYS_INT_SourceStatusClear(dObj->rxInterruptSource); SYS_INT_SourceStatusClear(dObj->errorInterruptSource); /* Enable the interrupt source in case of interrupt mode */ _DRV_USART_InterruptSourceEnable(dObj->errorInterruptSource); /* TODO: Enable DMA interrupts if the DMA channel is selected */ /* Create the hardware instance mutex. */ OSAL_ASSERT((OSAL_MUTEX_Create(&(dObj->mutexDriverInstance)) == OSAL_RESULT_TRUE), "Unable to create hardware instance mutex"); /* Check if the global mutexes have been created. If not then create these. */ if(!gDrvUSARTCommonDataObj.membersAreInitialized) { /* This means that mutexes where not created. Create them. */ OSAL_ASSERT((OSAL_MUTEX_Create(&(gDrvUSARTCommonDataObj.mutexClientObjects)) == OSAL_RESULT_TRUE), "Unable to create client instance mutex"); OSAL_ASSERT((OSAL_MUTEX_Create(&(gDrvUSARTCommonDataObj.mutexBufferQueueObjects)) == OSAL_RESULT_TRUE), "Unable to create buffer queue objects mutex"); /* Set this flag so that global mutexes get allocated only once */ gDrvUSARTCommonDataObj.membersAreInitialized = true; } /* Enable the USART module */ PLIB_USART_Enable(usartInit->usartID) ; /* Update the status */ dObj->status = SYS_STATUS_READY; /* Return the object structure */ return ( (SYS_MODULE_OBJ)drvIndex ); }