uint32 i2cRead(uint16 targetAddress, uint8 *buf, uint32 bufLength) { if(TCTaskStarted()) return i2cIntRead(targetAddress, buf, bufLength); else return i2cPollRead(targetAddress, buf, bufLength); }
uint32 i2cWrite(uint16 targetAddress, uint8 *buf, uint8 bufLength) { if(TCTaskStarted()) return i2cWriteBuf(targetAddress, buf, bufLength); else return i2cPollWrite(targetAddress, buf, bufLength); }
//This is the interrupt version of SPI, if user wants an blocking version of op, an //user defined semaphore needs to be signalled in the complete_cb. HRESULT spiOpNonBlock(uint32 slaveId, uint32 outData, uint32 *inData) { HRESULT hResult = NO_ERROR; if (!TCTaskStarted ()) { hResult = E_GEN_WRONG_CONTEXT; sysLogError(hResult, __LINE__, moduleName); return hResult; } if((slaveId >= SPI_MAX_SLAVE_COUNT) || !ssTable[slaveId].bValid ) { hResult = E_SPI_INVALID_SLAVEID; sysLogError(hResult, __LINE__, moduleName); } else { if (!_spiBufAdd(slaveId, outData, inData)) { sysLogError(E_SPI_BUF_FULL, __LINE__, moduleName); return E_SPI_BUF_FULL; } } return hResult; }
static HRESULT i2cOp(uint16 target, uint8 type, uint8 *buf, uint8 length) { TCSemaphoreWait(i2cBufSemId); if(tempTran.status != 0) {//busy TCSemaphoreSignal(i2cBufSemId); return E_I2C_TRY_AGAIN; //some error } addI2cTrans(&tempTran, type, target, buf, length); TCSemaphoreSignal(i2cBufSemId); startI2cTran(); if(TCTaskStarted()) TCSemaphoreWait(i2cCompleteSemId); else TCTaskWait(10); //SYS_TRACE3(SYSDEBUG_TRACE_I2C, target, type, length); if(i2cErrorOccur()) { SYS_DEBUG(SYSDEBUG_TRACE_I2C, "error = %d \n", i2cErrorCounter()); return E_FAIL; } else { return NO_ERROR; } }
HRESULT spiOpBlockNoTask(uint32 slaveId, uint32 outData, uint32 *inData) { HRESULT hResult = NO_ERROR; if (TCTaskStarted ()) { hResult = E_GEN_WRONG_CONTEXT; sysLogError(hResult, __LINE__, moduleName); return hResult; } if((slaveId >= SPI_MAX_SLAVE_COUNT) || !ssTable[slaveId].bValid ) { hResult = E_SPI_INVALID_SLAVEID; sysLogError(hResult, __LINE__, moduleName); return hResult; } // this is all based on busy waiting //Wait for previous command done while ((MPTR(SPI_STAT)&0x12) != 0x12); //clear any received data uint32 val = MPTR(SPI_DATA); if(lastSpiSSId != slaveId) { lastSpiSSId = slaveId; if(spiSSRoutine) (*spiSSRoutine)(lastSpiSSId); spiSetSlaveConfig(lastSpiSSId); } //we are ready to send data MPTR(SPI_DATA) = outData; //Wait for this command done while ((MPTR(SPI_STAT)&0x12) != 0x12); //get any received data val = MPTR(SPI_DATA); if (inData) *inData = val; return hResult; }