void SPIAslave_writeSpi(SPIAslave_Handle handle, const uint16_t data) { SPIAslave_Obj *obj = (SPIAslave_Obj *)handle; // reset the Rx fifo pointer to zero SPI_resetRxFifo(obj->spiHandle); SPI_enableRxFifo(obj->spiHandle); // write the command (time N) SPI_write(obj->spiHandle,data); return; }
void DRV8301_writeSpi(DRV8301_Handle handle, const DRV8301_RegName_e regName,const uint16_t data) { DRV8301_Obj *obj = (DRV8301_Obj *)handle; uint16_t ctrlWord; // build the command ctrlWord = (uint16_t)DRV8301_buildCtrlWord(DRV8301_CtrlMode_Write,regName,data); // reset the Rx fifo pointer to zero SPI_resetRxFifo(obj->spiHandle); SPI_enableRxFifo(obj->spiHandle); // write the command (time N) SPI_write(obj->spiHandle,ctrlWord); return; } // end of DRV8301_writeSpi() function
uint16_t DRV8301_readSpi(DRV8301_Handle handle,const DRV8301_RegName_e regName) { DRV8301_Obj *obj = (DRV8301_Obj *)handle; uint16_t ctrlWord; const uint16_t data = 0; volatile uint16_t readWord; static volatile uint16_t WaitTimeOut = 0; volatile SPI_FifoStatus_e RxFifoCnt = SPI_FifoStatus_Empty; // build the control word ctrlWord = (uint16_t)DRV8301_buildCtrlWord(DRV8301_CtrlMode_Read,regName,data); // reset the Rx fifo pointer to zero SPI_resetRxFifo(obj->spiHandle); SPI_enableRxFifo(obj->spiHandle); // write the command SPI_write(obj->spiHandle,ctrlWord); // dummy write to return the reply from the 8301 SPI_write(obj->spiHandle,0x0000); // wait for two words to populate the RX fifo, or a wait timeout will occur while((RxFifoCnt < SPI_FifoStatus_2_Words) && (WaitTimeOut < 0xffff)) { RxFifoCnt = SPI_getRxFifoStatus(obj->spiHandle); if(++WaitTimeOut > 0xfffe) { obj->RxTimeOut = true; } } // Read two words, the dummy word and the data readWord = SPI_readEmu(obj->spiHandle); readWord = SPI_readEmu(obj->spiHandle); return(readWord & DRV8301_DATA_MASK); } // end of DRV8301_readSpi() function
uint16_t SPIAslave_readSpi(SPIAslave_Handle handle) { SPIAslave_Obj *obj = (SPIAslave_Obj *)handle; uint16_t ctrlWord; const uint16_t data = 0; volatile uint16_t readWord; static volatile uint16_t WaitTimeOut = 0; volatile SPI_FifoStatus_e RxFifoCnt = SPI_FifoStatus_Empty; // reset the Rx fifo pointer to zero SPI_resetRxFifo(obj->spiHandle); SPI_enableRxFifo(obj->spiHandle); /*NEED TO CHANGE IT FROM WRITING FIRST TO WAITING FOR THE MASTER TO COMMAND IT*/ // write the command SPI_write(obj->spiHandle,ctrlWord); // dummy write to return the reply from the 8301 SPI_write(obj->spiHandle,0x0000); // wait for two words to populate the RX fifo, or a wait timeout will occur while((RxFifoCnt < SPI_FifoStatus_2_Words) && (WaitTimeOut < 0xffff)) { RxFifoCnt = SPI_getRxFifoStatus(obj->spiHandle); if(++WaitTimeOut > 0xfffe) { obj->RxTimeOut = true; } } /*NEED TO CHANGE IT FROM WRITING FIRST TO WAITING FOR THE MASTER TO COMMAND IT*/ // Read two words, the dummy word and the data readWord = SPI_readEmu(obj->spiHandle); //not necessarily sure we need this readWord = SPI_readEmu(obj->spiHandle); return(readWord); }