SPI_Handle ***(SPI_Handle handle, SPI_Params *params)
{
/* Use union to save on stack allocation */
union {
Semaphore_Params semParams;
Hwi_Params hwiParams;
Swi_Params swiParams;
} paramsUnion;
*** *object;
*** 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);
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 ***
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) ? *** : ***;
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 */
***(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 (!***(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);
}
红色判断不通过, 返回NULL 不明白什么鬼
用到了两个SPI接口