Skip to content

Commit

Permalink
Move ByteTime field to SPI_DEVICE_CONFIGURATION (#2406)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Aug 5, 2022
1 parent 8ad53cf commit 60d31ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/HAL/Include/nanoHAL_Spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct nanoSPI_BusConfig
int8_t devicesInUse;
SPI_DEVICE_CONFIGURATION deviceConfig[MAX_SPI_DEVICES];
uint32_t deviceHandles[MAX_SPI_DEVICES];
float byteTime[MAX_SPI_DEVICES];
SPI_OP_STATUS spiStatus;
};

Expand Down
3 changes: 3 additions & 0 deletions src/PAL/Include/CPU_SPI_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ struct SPI_DEVICE_CONFIGURATION
bool MD16bits;
// Data order for 16 bit operation
DataBitOrder DataOrder16;
// Rough estimate on the time it takes to send/receive one byte (in milliseconds)
// Used to compute length of time for each IO to see if this is a long running operation
float ByteTime;

// Master Only
uint32_t Clock_RateHz; // Master - SPI bus clock frequency, in hertz (Hz).
Expand Down
12 changes: 6 additions & 6 deletions src/System.Device.Spi/nanoHAL_Spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,16 @@ HRESULT nanoSPI_OpenDeviceEx(
}
}

// Compute rough estimate on the time to tx/rx a byte (in milliseconds)
// Used to compute length of time for each IO to see if this is a long running operation
// Store for each device as each device could use a different bit rate
spiDeviceConfig.ByteTime = (1.0 / spiDeviceConfig.Clock_RateHz) * 1000.0 * 8;

// Add next Device - Copy device config, save handle, increment number devices on bus
nanoSPI_BusConfig *pBusConfig = &spiconfig[spiDeviceConfig.Spi_Bus];
pBusConfig->deviceConfig[spiDeviceConfig.Spi_Bus] = spiDeviceConfig;
pBusConfig->deviceHandles[spiDeviceConfig.Spi_Bus] = deviceHandle;

// Compute rough estimate on the time to tx/rx a byte (in milliseconds)
// Used to compute length of time for each IO to see if this is a long running operation
// Store for each device as each device could use a different bit rate
pBusConfig->byteTime[spiDeviceConfig.Spi_Bus] = (float)(1.0 / spiDeviceConfig.Clock_RateHz) * 1000 * 8;

pBusConfig->devicesInUse++;

// Return unique generated device handle
Expand Down Expand Up @@ -419,7 +419,7 @@ float nanoSPI_GetByteTime(uint32_t handle)

getDevice(handle, spiBus, deviceIndex);

return spiconfig[spiBus].byteTime[deviceIndex];
return spiconfig[spiBus].deviceConfig->ByteTime;
}

void nanoSPI_Wait_Busy(uint32_t handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool System_Device_IsLongRunningOperation(
uint32_t readSize,
bool fullDuplex,
bool bufferIs16bits,
float byteTime,
int32_t byteTime,
uint32_t &estimatedDurationMiliseconds)
{
if (bufferIs16bits)
Expand Down

0 comments on commit 60d31ee

Please sign in to comment.