mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 08:15:26 +03:00
[BUS] Lazy allocate device scratchpad memory. Will only allocate it if driver accesses it.
This commit is contained in:
parent
4d3bb32b7f
commit
ddcca7b1a8
2 changed files with 16 additions and 5 deletions
|
@ -27,6 +27,8 @@
|
|||
#include "platform.h"
|
||||
#include "build/debug.h"
|
||||
|
||||
#include "common/memory.h"
|
||||
|
||||
#include "drivers/bus.h"
|
||||
#include "drivers/io.h"
|
||||
|
||||
|
@ -199,16 +201,25 @@ void busSetSpeed(const busDevice_t * dev, busSpeed_e speed)
|
|||
|
||||
uint32_t busDeviceReadScratchpad(const busDevice_t * dev)
|
||||
{
|
||||
return dev->scratchpad[0];
|
||||
uint32_t * mem = busDeviceGetScratchpadMemory(dev);
|
||||
return (mem != NULL) ? mem[0] : 0;
|
||||
}
|
||||
|
||||
void busDeviceWriteScratchpad(busDevice_t * dev, uint32_t value)
|
||||
{
|
||||
dev->scratchpad[0] = value;
|
||||
uint32_t * mem = busDeviceGetScratchpadMemory(dev);
|
||||
|
||||
if (mem != NULL) {
|
||||
mem[0] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void * busDeviceGetScratchpadMemory(const busDevice_t * dev)
|
||||
{
|
||||
if (dev->scratchpad == NULL) {
|
||||
((busDevice_t *)dev)->scratchpad = memAllocate(BUS_SCRATCHPAD_MEMORY_SIZE, OWNER_SYSTEM);
|
||||
}
|
||||
|
||||
return (void *)dev->scratchpad;
|
||||
}
|
||||
|
||||
|
|
|
@ -192,9 +192,9 @@ typedef struct busDevice_s {
|
|||
#endif
|
||||
} busdev;
|
||||
IO_t irqPin; // Device IRQ pin. Bus system will only assign IO_t object to this var. Initialization is up to device driver
|
||||
uint32_t scratchpad[BUS_SCRATCHPAD_MEMORY_SIZE / sizeof(uint32_t)]; // Memory where device driver can store persistent data. Zeroed out when initializing the device
|
||||
// for the first time. Useful when once device is shared between several sensors
|
||||
// (like MPU/ICM acc-gyro sensors)
|
||||
uint32_t * scratchpad; // Memory where device driver can store persistent data. Zeroed out when initializing the device
|
||||
// for the first time. Useful when once device is shared between several sensors
|
||||
// (like MPU/ICM acc-gyro sensors)
|
||||
} busDevice_t;
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue