/*! * ======== OffloadM3_init ======== * * Initialize the OffloadM3 module, currently supported only on SysM3 */ Void OffloadM3_init() { Task_Params taskParams; Semaphore_Params mutexParams; sysm3ProcId = MultiProc_getId("CORE0"); if (MultiProc_self() != sysm3ProcId) return; Semaphore_Params_init(&mutexParams); mutexParams.mode = Semaphore_Mode_BINARY; module.mutex = Semaphore_create(1, NULL, NULL); module.created = FALSE; module.semaphores[OFFLOAD_CREATE_IDX] = Semaphore_create(0, NULL, NULL); module.semaphores[OFFLOAD_DELETE_IDX] = Semaphore_create(0, NULL, NULL); Task_Params_init(&taskParams); taskParams.instance->name = "OffloadM3_createTask"; taskParams.priority = xdc_runtime_knl_Thread_Priority_NORMAL; taskParams.arg0 = (UArg)module.semaphores[OFFLOAD_CREATE_IDX]; module.tasks[OFFLOAD_CREATE_IDX] = Task_create(OffloadM3_createTask, &taskParams, NULL); Task_Params_init(&taskParams); taskParams.instance->name = "OffloadM3_deleteTask"; taskParams.priority = xdc_runtime_knl_Thread_Priority_HIGHEST; taskParams.arg0 = (UArg)module.semaphores[OFFLOAD_DELETE_IDX]; module.tasks[OFFLOAD_DELETE_IDX] = Task_create(OffloadM3_deleteTask, &taskParams, NULL); }
IsoServer IsoServer_create() { IsoServer self = (IsoServer) GLOBAL_CALLOC(1, sizeof(struct sIsoServer)); self->state = ISO_SVR_STATE_IDLE; self->tcpPort = TCP_PORT; #if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) self->openClientConnections = LinkedList_create(); #else self->openClientConnections = (IsoConnection*) GLOBAL_CALLOC(CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS, sizeof(IsoConnection)); #endif #if (CONFIG_MMS_THREADLESS_STACK != 1) self->connectionCounterMutex = Semaphore_create(1); #if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) self->openClientConnectionsMutex = Semaphore_create(1); #endif #endif /* (CONFIG_MMS_THREADLESS_STACK != 1) */ self->connectionCounter = 0; return self; }
/* * ======== USBKBD_init ======== */ void USBKBD_init(void) { Hwi_Handle hwi; Error_Block eb; Semaphore_Params semParams; Error_init(&eb); /* Install interrupt handler */ hwi = Hwi_create(INT_USB0, USBKBD_hwiHandler, NULL, &eb); if (hwi == NULL) { System_abort("Can't create USB Hwi"); } /* RTOS primitives */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; semKeyboard = Semaphore_create(0, &semParams, &eb); if (semKeyboard == NULL) { System_abort("Can't create keyboard semaphore"); } semUSBConnected = Semaphore_create(0, &semParams, &eb); if (semUSBConnected == NULL) { System_abort("Can't create USB semaphore"); } gateKeyboard = GateMutex_create(NULL, &eb); if (gateKeyboard == NULL) { System_abort("Can't create keyboard gate"); } gateUSBWait = GateMutex_create(NULL, &eb); if (gateUSBWait == NULL) { System_abort("Could not create USB Wait gate"); } /* State specific variables */ state = USBKBD_STATE_UNCONFIGURED; kbLEDs = 0x00; /* Set the USB stack mode to Device mode with VBUS monitoring */ USBStackModeSet(0, eUSBModeForceDevice, 0); /* * Pass our device information to the USB HID device class driver, * initialize the USB controller and connect the device to the bus. */ if (!USBDHIDKeyboardInit(0, &keyboardDevice)) { System_abort("Error initializing the keyboard"); } }
/***************************************************************************** ** Function name: CountingSem_Init ** ** Descriptions: ** Creates a Counting semaphore based Signal. ** parameters: Signal *pThis, Name ** Returned value: TRUE/FALSE ** ** Dependencies/Limitations/Side Effects/Design Notes: *****************************************************************************/ BOOL CountingSem_Init(Signal *pThis, char *name, UINT32 count) { //SEM_Attrs attrs = SEM_ATTRS; Error_Block eb; Semaphore_Params attrs; Error_init(&eb); Semaphore_Params_init( &attrs); attrs.mode= ti_sysbios_knl_Semaphore_Mode_COUNTING ; //Setting of Semaphore name if (name != NULL) { memcpy(pThis->Name, name, SEM_NAME_SIZE); //attrs.name = &pThis->Name[0]; attrs.instance->name = &pThis->Name[0]; } else { // attrs.name = "DUMMY"; attrs.instance->name = "DUMMY"; } //pThis->Handle = SEM_create(0, &attrs); pThis->Handle = Semaphore_create(0, &attrs,&eb); if (pThis->Handle == NULL) { return FALSE; } return TRUE; }
/***************************************************************************** ** Function name: Mutex_Init ** ** Descriptions: ** Creates a Mutex Lock using DSP/BIOS Sem obj. ** parameters: Mutex *pThis, Name, Initial state ** Returned value: TRUE/FALSE ** ** Dependencies/Limitations/Side Effects/Design Notes: ** *****************************************************************************/ BOOL Mutex_Init( Mutex *pThis , char *name, UINT8 InitState) { //SEM_Attrs attrs = SEM_ATTRS; Error_Block eb; Semaphore_Params attrs; Semaphore_Params_init( &attrs); Error_init(&eb); attrs.mode= ti_sysbios_knl_Semaphore_Mode_BINARY ; //Setting of Semaphore name if (name != NULL) { memcpy(pThis->Name, name, SEM_NAME_SIZE); //attrs.name = &pThis->Name[0]; attrs.instance->name = &pThis->Name[0]; } else { //attrs.name = "DUMMY"; attrs.instance->name= "DUMMY"; } //pThis->Handle = SEM_create(InitState, &attrs); pThis->Handle = Semaphore_create(InitState, &attrs,&eb); if (pThis->Handle == NULL) { printf("TASK: Failed create Mutex"); // SYS_abort("Failed create Semaphore"); return FALSE; //Raise an exception. } return TRUE; }
void A110x2500Radio::begin(uint8_t address, channel_t channel, power_t power) { gDataTransmitting = false; gDataReceived = false; Task_Params taskParams; Error_Block eb; Error_init(&eb); GateMutex_construct(&mygate, NULL); sem = Semaphore_create(0, NULL, &eb); // Configure the radio and set the default address, channel, and TX power. A110LR09Init(&gPhyInfo, &gSpi, gGdo); setAddress(address); setChannel(channel); setPower(power); Task_Params_init(&taskParams); taskParams.priority = Task_numPriorities - 1; taskParams.stackSize = 0x800; Task_create(serviceInterrupt, &taskParams, &eb); attachInterrupt(RF_GDO0, gdo0Isr, FALLING); sleep(); }
/* * ======== DSKT2_initLocks ======== * Implements yield function and initializes all the * the lock semaphores, and yield contexts. */ Void DSKT2_initLocks() { Int i; /* * Initialize the yielding context and lock create flags */ for (i = 0; i < DSKT2_NUM_SCRATCH_GROUPS; i++) { _DSKT2_yieldingContext[i] = NULL; /* * Note, an optimization could be to allow this array to be * sparse, and only create enough semaphores for the groups that * will be used. Might require some extra config on the user's part * but it would save on some resources in environments where sems * are heavy. */ _locks[i] = Semaphore_create(1, NULL, NULL); if (_locks[i] == NULL) { /* This is a fatal error */ System_abort("DSKT2_initLocks(): Semaphore creation failed\n"); } } }
int Semaphores_init(Semaphore_Handle *sem, int number) { int i; for(i=0; i<number; i++) { sem[i] = Semaphore_create(0, NULL, NULL); } return 0; }
/* * ======== main ======== */ Void main() { Swi_Params swiParams; Task_Params taskParams; Clock_Params clkParams; Swi_Params_init(&swiParams); swiParams.arg0 = 1; swiParams.arg1 = 0; swiParams.priority = 2; swiParams.trigger = 0; swi0 = Swi_create(swi0Fxn, &swiParams, NULL); swiParams.arg0 = 2; swiParams.arg1 = 0; swiParams.priority = 1; swiParams.trigger = 3; swi1 = Swi_create(swi1Fxn, &swiParams, NULL); Task_Params_init(&taskParams); taskParams.priority = 1; Task_create (tsk0Fxn, &taskParams, NULL); Clock_Params_init(&clkParams); clkParams.startFlag = TRUE; Clock_create(clk0Fxn, 2, &clkParams, NULL); sem0 = Semaphore_create(0, NULL, NULL); BIOS_start(); }
void lcdSetup() { Semaphore_Params mySemParams; Clock_Params myClkParams; /* Use pull up on button inputs to save power */ pinMode(PUSH1, INPUT_PULLUP); pinMode(PUSH2, INPUT_PULLUP); /* Both buttons post the semaphore */ attachInterrupt(PUSH1, button1Interrupt, FALLING); attachInterrupt(PUSH2, button2Interrupt, FALLING); /* set LCD's EXTMODE low (sadly this is the UART Rx pin too) */ digitalWrite(12, 0); /* turn off MPU power */ digitalWrite(22, 0); /* put flash into power down mode */ SPI.begin(); SPI.transfer((uint8_t)32, 0xb9); SPI.end(); /* power down the tmp007 */ Wire.begin(); tmp007.begin(TMP007_CFG_1SAMPLE); tmp007.write16(TMP007_CONFIG, TMP007_CFG_ALERTEN | TMP007_CFG_TRANSC | TMP007_CFG_1SAMPLE); Wire.end(); Semaphore_Params_init(&mySemParams); mySem = Semaphore_create(0, &mySemParams, NULL); Clock_Params_init(&myClkParams); myClkParams.period = 100000; /* one second */ myClkParams.startFlag = true; /* comment out for steady state power testing */ Clock_create(myClkFunc, 0, &myClkParams, NULL); /* set to 1970 plus 45 years */ Seconds_set(secondsOffset); myScreen.begin(); /* also calls SPI.begin() */ myScreen.setFont(1); myScreen.text(10, 10, "Hello!"); myScreen.flush(); SPI.end(); /* to save power */ /* Say Hello for 1 second */ delay(1000); SPI.begin(); myScreen.clear(); SPI.end(); /* to save Power */ }
int main(void) { /* Call board init functions */ uint32_t ui32SysClock; ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120E6); Board_initGeneral(ui32SysClock); Board_initEMAC(); Board_initGPIO(); // Board_initI2C(); // Board_initSDSPI(); // Board_initSPI(); // Board_initUART(); // Board_initUSB(Board_USBDEVICE); // Board_initUSBMSCHFatFs(); // Board_initWatchdog(); // Board_initWiFi(); setup_ledcube(); Mailbox_Params mbox_Params; Error_Block eb; Error_init(&eb); _sem = Semaphore_create(0, NULL, &eb); if (_sem == NULL) { System_abort("Couldn't create semaphore"); } ledEvent = Event_create(NULL,&eb); Mailbox_Params_init(&mbox_Params); mbox_Params.readerEvent=ledEvent; mbox_Params.readerEventId=Event_Id_01; mbox_led = Mailbox_create(sizeof(struct ledMatrix),1, &mbox_Params, &eb); if(mbox_led == NULL){ // Do something with errorblock, in the real world System_abort("woho!"); } create_led_task((UArg) mbox_led); //netOpenHook((UArg) mbox_led); netOpenHook(mbox_led); System_printf("Starting the example\nSystem provider is set to SysMin. " "Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
void SNP_open(void *syncHandle) { #ifdef SNP_LOCAL // Posting this semaphore is the equivalent of posting eventID for // eventHandle. SNP_init((Event_Handle *)syncHandle); // Process any posted events SNP_processEvents(); #else //!SNP_LOCAL // Create Synchronous message semaphore, ready to claim syncReq_sem = Semaphore_create(1, NULL, NULL); // Create waitResponse semaphore, must be signaled before progressing. waitRsp_sem = Semaphore_create(0, NULL, NULL); #endif //SNP_LOCAL }
/* * ======== IpcPower_init ======== */ Void IpcPower_init() { Swi_Params swiParams; Task_Params taskParams; Int i; UArg arg; UInt func; Timer_Handle tHandle = NULL; if (curInit++) { return; } IpcPower_hibLock = 0; for (i = 0; i < Timer_Object_count(); i++) { tHandle = Timer_Object_get(NULL, i); func = (UInt) Timer_getFunc(tHandle, &arg); if (func && ((func == (UInt) ti_sysbios_knl_Clock_doTick__I) || (func == (UInt) Clock_tick) || (func == (UInt) IpcPower_clockFxn))) { tickTimerHandle = tHandle; break; } } if (tickTimerHandle == NULL) { System_abort("IpcPower_init: Cannot find tickTimer Handle. Custom" " clock timer functions currently not supported.\n"); } IpcPower_semSuspend = Semaphore_create(0, NULL, NULL); IpcPower_semExit = Semaphore_create(0, NULL, NULL); Task_Params_init(&taskParams); taskParams.priority = Task_numPriorities - 1; /* Highest priority */ taskParams.instance->name = "ti.pm.IpcPower_tskSuspend"; IpcPower_tskSuspend = Task_create(IpcPower_suspendTaskFxn, &taskParams, NULL); Swi_Params_init(&swiParams); swiParams.priority = Swi_numPriorities - 1; /* Max Priority Swi */ suspendResumeSwi = Swi_create(IpcPower_suspendSwi, &swiParams, NULL); }
int InitMutex(CyaSSL_Mutex* m) { Semaphore_Params params; Semaphore_Params_init(¶ms); params.mode = Semaphore_Mode_BINARY; *m = Semaphore_create(1, ¶ms, NULL); return 0; }
int InitMutex(wolfSSL_Mutex* m) { Semaphore_Params params; Error_Block eb; Error_init(&eb); Semaphore_Params_init(¶ms); params.mode = Semaphore_Mode_BINARY; *m = Semaphore_create(1, ¶ms, &eb); if( Error_check( &eb ) ) { Error_raise( &eb, Error_E_generic, "Failed to Create the semaphore.",NULL); } else return 0; }
/* ========================================================================== */ 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(¶ms); params.instance->name = (xdc_String)(pHandle->name); params.mode = Semaphore_Mode_COUNTING; pHandle->sem = Semaphore_create(uInitCount,¶ms,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 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; }
/** * \brief create semaphore object * * Creates a counting semaphore for inter-thread synchronization. * The initial semaphore count is specified as an input parameter. * * \param[in] p_sem_handle Handle to semaphore control block * \param[in] p_name Name of the semaphore - UNUSED in SYS/BIOS * \param[in] count Initial count of the semaphore * * \return e_SUCCESS on success, e_FAILURE on error * * \sa OS_semaphore_delete, OS_semaphore_put, OS_semaphore_get * \note * * \warning */ e_ret_status OS_semaphore_create(handle p_handle, const void *const p_name, //UNUSED uInt16 count) { Semaphore_Handle sem_handle = NULL; Error_Block eb; Error_init(&eb); sem_handle = Semaphore_create(count, NULL, &eb); if (NULL == sem_handle) { return e_FAILURE; } *(Semaphore_Handle *)p_handle = sem_handle; return e_SUCCESS; }
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; }
IedConnection IedConnection_create() { IedConnection self = (IedConnection) calloc(1, sizeof(struct sIedConnection)); self->enabledReports = LinkedList_create(); self->logicalDevices = NULL; self->clientControls = LinkedList_create(); self->connection = MmsConnection_create(); self->state = IED_STATE_IDLE; self->stateMutex = Semaphore_create(1); return self; }
/* * ======== 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); }
//----------------------------------------------------------------------------- /// Initializes a MSD driver /// \param luns Pointer to a list of LUNs /// \param numLuns Number of LUN in list //----------------------------------------------------------------------------- void MSDDFunctionDriver_Initialize(MSDLun *luns, unsigned char numLuns) { TRACE_INFO("MSD init\n\r"); // Command state initialization msdDriver.commandState.state = 0; msdDriver.commandState.postprocess = 0; msdDriver.commandState.length = 0; //msdDriver.commandState.transfer.semaphore = 0; msdDriver.commandState.transfer.semaphore = Semaphore_create(); //Semaphore_take(msdDriver.commandState.transfer.semaphore, -1); // LUNs msdDriver.luns = luns; msdDriver.maxLun = (unsigned char) (numLuns - 1); // Reset BOT driver MSDD_Reset(); }
static Void OffloadM3_createTask(UArg sem, UArg arg1) { Semaphore_Handle semHandle = (Semaphore_Handle)sem; Task_Params params; Int i; while (1) { Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); Mutex_enter(); if (!module.created) { for (i = OFFLOAD_AC_IDX; i < OFFLOAD_MAX_IDX; i++) { module.semaphores[i] = Semaphore_create(0, NULL, NULL); } Task_Params_init(¶ms); params.instance->name = "workerTaskAC"; params.priority = xdc_runtime_knl_Thread_Priority_NORMAL; params.arg0 = (UArg)module.semaphores[OFFLOAD_AC_IDX]; params.arg1 = (UArg)&interm3PayloadAC; module.tasks[OFFLOAD_AC_IDX] = Task_create(OffloadM3_workerTask, ¶ms, NULL); Task_Params_init(¶ms); params.instance->name = "workerTaskVS"; params.priority = xdc_runtime_knl_Thread_Priority_NORMAL; params.arg0 = (UArg)module.semaphores[OFFLOAD_VS_IDX]; params.arg1 = (UArg)&interm3PayloadVS; module.tasks[OFFLOAD_VS_IDX] = Task_create(OffloadM3_workerTask, ¶ms, NULL); Task_Params_init(¶ms); /* Create a lower priority thread */ params.instance->name = "workerTaskMM"; params.priority = xdc_runtime_knl_Thread_Priority_BELOW_NORMAL; params.arg0 = (UArg)module.semaphores[OFFLOAD_MM_IDX]; params.arg1 = (UArg)&interm3PayloadMM; module.tasks[OFFLOAD_MM_IDX] = Task_create(OffloadM3_workerTask, ¶ms, NULL); module.created = TRUE; } Mutex_leave(); } }
MmsServer MmsServer_create(IsoServer isoServer, MmsDevice* device) { MmsServer self = (MmsServer) malloc(sizeof(struct sMmsServer)); memset(self, 0, sizeof(struct sMmsServer)); self->isoServer = isoServer; self->device = device; self->openConnections = Map_create(); self->valueCaches = createValueCaches(device); self->isLocked = false; #if (CONFIG_MMS_THREADLESS_STACK != 1) self->modelMutex = Semaphore_create(1); IsoServer_setUserLock(isoServer, self->modelMutex); #endif return self; }
/* * ======== 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); }
IsoConnection IsoConnection_create(Socket socket, IsoServer isoServer) { IsoConnection self = (IsoConnection) calloc(1, sizeof(struct sIsoConnection)); self->socket = socket; self->receiveBuffer = (uint8_t*) malloc(RECEIVE_BUF_SIZE); self->sendBuffer = (uint8_t*) malloc(SEND_BUF_SIZE); self->msgRcvdHandler = NULL; self->msgRcvdHandlerParameter = NULL; self->isoServer = isoServer; self->state = ISO_CON_STATE_RUNNING; self->clientAddress = Socket_getPeerAddress(self->socket); self->thread = Thread_create((ThreadExecutionFunction) handleTcpConnection, self, true); self->conMutex = Semaphore_create(1); Thread_start(self->thread); if (DEBUG_ISO_SERVER) printf("ISO_SERVER: new iso connection thread started\n"); return self; }
/* * ======== 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); }
ControlObject* ControlObject_create(IedServer iedServer, MmsDomain* domain, char* lnName, char* name) { ControlObject* self = (ControlObject*) GLOBAL_CALLOC(1, sizeof(ControlObject)); if (self == NULL) goto exit_function; if (DEBUG_IED_SERVER) printf("create control object for LD: %s, LN: %s, name: %s\n", domain->domainName, lnName, name); #if (CONFIG_MMS_THREADLESS_STACK != 1) self->stateLock = Semaphore_create(1); if (self->stateLock == NULL) { ControlObject_destroy(self); self = NULL; goto exit_function; } #endif self->name = copyString(name); if (self->name == NULL) { ControlObject_destroy(self); self = NULL; goto exit_function; } self->lnName = lnName; self->mmsDomain = domain; self->iedServer = iedServer; exit_function: return self; }
Void * _semCreate(Int key, Int count) { Semaphore_Params semParams; Semaphore_Params_init(&semParams); return ((Void *)(Semaphore_create(count, &semParams, NULL))); }
/* * ======== IpcPower_init ======== */ Void IpcPower_init() { Swi_Params swiParams; #ifndef SMP Task_Params taskParams; UInt coreIdx = Core_getId(); #endif Int i; UArg arg; UInt func; Timer_Handle tHandle = NULL; if (curInit++) { return; } #ifndef SMP IpcPower_hibLocks[coreIdx] = 0; sysm3ProcId = MultiProc_getId("CORE0"); appm3ProcId = MultiProc_getId("CORE1"); #else IpcPower_hibLocks = 0; #endif refWakeLockCnt = 0; for (i = 0; i < Timer_Object_count(); i++) { tHandle = Timer_Object_get(NULL, i); func = (UInt) Timer_getFunc(tHandle, &arg); if (func && ((func == (UInt) ti_sysbios_knl_Clock_doTick__I) || (func == (UInt) Clock_tick) || (func == (UInt) IpcPower_clockFxn))) { tickTimerHandle = tHandle; break; } } if (tickTimerHandle == NULL) { System_abort("IpcPower_init: Cannot find tickTimer Handle. Custom" " clock timer functions currently not supported.\n"); } #ifndef SMP IpcPower_semSuspend = Semaphore_create(0, NULL, NULL); IpcPower_semExit = Semaphore_create(0, NULL, NULL); Task_Params_init(&taskParams); taskParams.priority = Task_numPriorities - 1; /* Highest priority */ taskParams.instance->name = "ti.pm.IpcPower_tskSuspend"; IpcPower_tskSuspend = Task_create(IpcPower_suspendTaskFxn, &taskParams, NULL); #endif Swi_Params_init(&swiParams); swiParams.priority = Swi_numPriorities - 1; /* Max Priority Swi */ suspendResumeSwi = Swi_create(IpcPower_suspendSwi, &swiParams, NULL); /*Power settings for saving/restoring context */ PowerSuspArgs.rendezvousResume = TRUE; PowerSuspArgs.dmaChannel = CPU_COPY; PowerSuspArgs.intMask31_0 = 0x0; #ifndef SMP PowerSuspArgs.intMask63_32 = 0x0; #else PowerSuspArgs.intMask63_32 = WUGEN_MAILBOX_BIT << 16; #endif PowerSuspArgs.intMask79_64 = 0x0; IpcPower_sleepMode(IpcPower_SLEEP_MODE_DEEPSLEEP); IpcPower_setWugen(); }