Hi,
as I am not really capable of understanding the ASM-code from the provided application examples that use bankstick patches, maybe someone might check if my concept of storing patches on a bankstick seems correct?
I noticed that my codesize increased rapidly (>50%) due to my implementation of read/save handlers to store patches on a bankstick. This is not critical but it makes me wonder if there’s a more efficient method for this.
Here’s what I’m doing:
Every patch consists of AIN_NUM * 16 bytes. I have a const unsigned int array bankstick_patch_address[MAX_PATCHES] that points to the address of the bankstick.
Then I have two accessor functions, that collect or set the current data
and two functions that read/store the whole patch:
(the code is cutted to the relevant)
#define MAX_PATCHES 16
const unsigned int bankstick_patch_address[MAX_PATCHES] = {
0x000, 0x040, 0x080, 0x0C0, 0x100, 0x140, 0x180, 0x1C0,
0x200, 0x240, 0x280, 0x2C0, 0x300, 0x340, 0x380, 0x3C0
};
void ZS_SENSORIZER_SensorSetting_Write(unsigned int address, unsigned char pin) {
// called by ZS_SENSORIZER_SensorSettings_Write(address)
MIOS_BANKSTICK_Write(address, ZSSENSORIZER_VERSION);
MIOS_BANKSTICK_Write(address + 1, (sensor[pin].enabled) |
(sensor[pin].pedal << 1) |
(sensor[pin].pedalPanic << 2) |
(sensor[pin].invert << 3) |
(sensor[pin].gate << 4) |
(sensor[pin].read << 5) |
(sensor[pin].expand << 6) |
(sensor[pin].scale << 7));
MIOS_BANKSTICK_Write(address + 2, CH[pin]);
MIOS_BANKSTICK_Write(address + 3, CC[pin]);
}
void ZS_SENSORIZER_SensorSetting_Read(unsigned int address, unsigned char pin) {
// called by ZS_SENSORIZER_SensorSettings_Read(address)
// read and set sensor config from Bankstick
if(MIOS_BANKSTICK_Read(address) != ZSSENSORIZER_VERSION) {
return;
}
// read and set sensor pin from buffer
// set sensor settings from buffer
sensor[pin].enabled = 0x0 | (MIOS_BANKSTICK_Read(address + 1));
sensor[pin].pedal = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 1);
sensor[pin].pedalPanic = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 2);
sensor[pin].invert = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 3);
sensor[pin].gate = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 4);
sensor[pin].read = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 5);
sensor[pin].expand = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 6);
sensor[pin].scale = 0x0 | (MIOS_BANKSTICK_Read(address + 1) >> 7);
CH[pin] = (MIOS_BANKSTICK_Read(address + 2));
CC[pin] = (MIOS_BANKSTICK_Read(address + 3));
}
void ZS_SENSORIZER_SensorSettings_Write(unsigned int address) {
// write all sensor configs to Bankstick
// 1 sensor setup needs 16 bytes (c << 4 => c * 16)
unsigned char c;
for(c=0; c<SENSOR_NUM; c++) {
ZS_SENSORIZER_SensorSetting_Write((address + (c << 4)), c);
}
}
void ZS_SENSORIZER_SensorSettings_Read(unsigned int address) {
// read and install all sensor configs from Bankstick
// 1 sensor setup needs 16 bytes (c << 4 => c * 16)
unsigned char c;
for(c=0; c<SENSOR_NUM; c++) {
ZS_SENSORIZER_SensorSetting_Read((address + (c << 4)), c);
}
}
for example, the patch is then loaded by calling this:
// load patch #5
ZS_SENSORIZER_SensorSettings_Read(bankstick_patch_address[5]);
Now I wonder:
-
should I store the address lookup table on the bankstick to save memory?
-
should I rather find a bitshifting formula that increments the address like this: PATCH * 0x40 ?
(I already hammered my brain out, I just can’t figure it out :-[ )
- is this concept okay or is there a better method for this?
Cheers,
Michael