/* * ======== WatchdogCC26XX_open ======== */ Watchdog_Handle WatchdogCC26XX_open(Watchdog_Handle handle, Watchdog_Params *params) { unsigned int key; Hwi_Params hwiParams; Watchdog_Params watchdogParams; WatchdogCC26XX_HWAttrs const *hwAttrs; WatchdogCC26XX_Object *object; Types_FreqHz freq; /* get the pointer to the object and hwAttrs */ object = handle->object; hwAttrs = handle->hwAttrs; /* disable preemption while checking if the WatchDog is open. */ key = Hwi_disable(); /* Check if the Watchdog is open already with the HWAttrs */ if (object->isOpen == true) { Hwi_restore(key); Log_warning1("Watchdog: Handle %x already in use.", (UArg)handle); return (NULL); } object->isOpen = true; Hwi_restore(key); /* if params are NULL use defaults. */ if (params == NULL) { Watchdog_Params_init(&watchdogParams); params = &watchdogParams; } /* initialize the Watchdog object */ object->debugStallMode = params->debugStallMode; object->resetMode = params->resetMode; /* 1 second period at default CPU clock frequency */ BIOS_getCpuFreq(&freq); object->reloadValue = freq.lo/2; /* Construct Hwi object for Watchdog */ Hwi_Params_init(&hwiParams); hwiParams.arg = (UArg)handle; /* setup callback function if defined */ if (params->callbackFxn != NULL) { Hwi_construct(&(object->hwi), hwAttrs->intNum, params->callbackFxn, &hwiParams, NULL); } /* initialize the watchdog hardware */ // WatchdogIntClear(); WatchdogCC26XX_initHw(handle); Log_print1(Diags_USER1, "Watchdog: handle %x opened" ,(UArg)handle); /* register notification functions */ Power_registerNotify(&object->watchdogPreObj, PowerCC26XX_ENTERING_STANDBY, (Fxn)watchdogPreNotify, (uint32_t)handle); Power_registerNotify(&object->watchdogPostObj, PowerCC26XX_AWAKE_STANDBY, (Fxn)watchdogPostNotify, (uint32_t)handle); /* return handle of the Watchdog object */ return (handle); }
/*! * @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(¶msUnion.hwiParams); paramsUnion.hwiParams.arg = (UArg) handle; Hwi_construct(&(object->hwi), (int) hwAttrs->intNum, SPICC26XXDMA_hwiFxn, ¶msUnion.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(¶msUnion.semParams); paramsUnion.semParams.mode = Semaphore_Mode_BINARY; Semaphore_construct(&(object->transferComplete), 0, ¶msUnion.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); }