/* * ======== WiFiCC3100_open ======== */ WiFi_Handle WiFiCC3100_open(WiFi_Handle handle, unsigned int spiIndex, WiFi_evntCallback evntCallback, WiFi_Params *params) { unsigned int key; WiFiCC3100_Object *object = handle->object; WiFiCC3100_HWAttrs const *hwAttrs = handle->hwAttrs; union { #if !defined(MSP430WARE) Hwi_Params hwiParams; #endif Semaphore_Params semParams; } paramsUnion; key = Hwi_disable(); if (object->isOpen) { Hwi_restore(key); Log_warning0("WiFi Hwi already in use."); return (NULL); } object->isOpen = true; Hwi_restore(key); /* Construct semaphores to block read/write transactions. */ Semaphore_Params_init(&(paramsUnion.semParams)); paramsUnion.semParams.mode = Semaphore_Mode_BINARY; paramsUnion.semParams.instance->name = "WiFi.writeSemaphore"; Semaphore_construct(&(object->writeSemaphore), 0, &(paramsUnion.semParams)); paramsUnion.semParams.instance->name = "WiFi.readSemaphore"; Semaphore_construct(&(object->readSemaphore), 0, &(paramsUnion.semParams)); #if !defined(MSP430WARE) Hwi_Params_init(&(paramsUnion.hwiParams)); paramsUnion.hwiParams.arg = (UArg) handle; paramsUnion.hwiParams.enableInt = false; /* Hwi_construct cannot fail, use NULL instead of an Error Block */ Hwi_construct(&(object->wifiHwi), hwAttrs->irqIntNum, WiFiCC3100_hostIntHandler, &(paramsUnion.hwiParams), NULL); #endif #if defined(MSP430WARE) || defined(MSP432WARE) MAP_GPIO_clearInterruptFlag(hwAttrs->irqPort, hwAttrs->irqPin); MAP_GPIO_enableInterrupt(hwAttrs->irqPort, hwAttrs->irqPin); #else GPIOIntClear(hwAttrs->irqPort, hwAttrs->irqPin); GPIOIntEnable(hwAttrs->irqPort, hwAttrs->irqPin); #endif /* Store SPI interface parameters */ object->spiIndex = spiIndex; object->bitRate = params->bitRate; return (handle); }
/* * DataService_RegisterAppCBs - Registers the application callback function. * Only call this function once. * * appCallbacks - pointer to application callbacks. */ bStatus_t DataService_RegisterAppCBs( DataServiceCBs_t *appCallbacks ) { if ( appCallbacks ) { pAppCBs = appCallbacks; Log_info1("Registered callbacks to application. Struct %p", (IArg)appCallbacks); return ( SUCCESS ); } else { Log_warning0("Null pointer given for app callbacks."); return ( FAILURE ); } }
/*! * @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); }