|
|
@@ -10,6 +10,7 @@ https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
#include "src/peripherals/dac/dac.h"
|
|
|
+#include <inttypes.h>
|
|
|
|
|
|
/*Function to Rx and Tx data from Target to Controller*/
|
|
|
// The code has multiple i2c instances (multiple MCUs connected) from which we
|
|
|
@@ -48,7 +49,7 @@ void mcu_i2c_handle(I2C_Regs *i2c) {
|
|
|
SetChargeDischargeCurrent set_current;
|
|
|
// Read incoming bytes from the Controller:
|
|
|
uint8_t rx_index = 0;
|
|
|
- while (rx_index < sizeof(SetChargeDischargeCurrent)) {
|
|
|
+ while (rx_index < sizeof(SetChargeDischargeCurrent)+1) {
|
|
|
// TODO: Need to have a workaround, currently the code is getting stuck on
|
|
|
// the first trigger and provides result on the second trigger
|
|
|
if (!DL_I2C_isTargetRXFIFOEmpty(i2c)) {
|
|
|
@@ -60,20 +61,21 @@ void mcu_i2c_handle(I2C_Regs *i2c) {
|
|
|
// Byte array received from the Controller will be typecasted to (const
|
|
|
// uint8_t *), treats the rx_buffer as an array of READ ONLY bytes because
|
|
|
// of the const
|
|
|
- if (rx_index != sizeof(SetChargeDischargeCurrent)) {
|
|
|
+ if (rx_index != sizeof(SetChargeDischargeCurrent)+1) {
|
|
|
printf("ERROR: Incomplete I2C Rx: received %d%zu bytes\n", rx_index,
|
|
|
- sizeof(SetChargeDischargeCurrent));
|
|
|
+ sizeof(SetChargeDischargeCurrent)+1);
|
|
|
DL_I2C_flushTargetRXFIFO(i2c);
|
|
|
rx_index = 0;
|
|
|
return;
|
|
|
}
|
|
|
- memcpy(&set_current, (const uint8_t *)rx_buffer,
|
|
|
+ printf("size: %d", sizeof(SetChargeDischargeCurrent));
|
|
|
+ memcpy(&set_current, (const uint8_t *)rx_buffer+1,
|
|
|
sizeof(SetChargeDischargeCurrent));
|
|
|
uint8_t slot = set_current.slot_id;
|
|
|
int16_t current = set_current.current;
|
|
|
- printf("Slot id: %d, Current: %d\n", slot, current);
|
|
|
+ printf("Slot id: %d, Current: %" SCNd16 "\n", slot, current);
|
|
|
if (current >= 0) {
|
|
|
- DAC_SingleWrite(current);
|
|
|
+ DAC_SingleWrite(slot, current);
|
|
|
} else if (current < 0) {
|
|
|
|
|
|
DL_TimerG_startCounter(PWM_0_INST);
|