Fixed further issues
This commit is contained in:
@@ -11,8 +11,9 @@
|
||||
#include "task.h"
|
||||
|
||||
|
||||
GobotRPC_CI::GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue) {
|
||||
GobotRPC_CI::GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue, QueueHandle_t ciInstructionReverseQueue) {
|
||||
this->ciInstructionQueue = ciInstructionQueue;
|
||||
this->ciInstructionReverseQueue = ciInstructionReverseQueue;
|
||||
|
||||
this->hardware = hardware;
|
||||
this->hardware->registerCB_RxData(GobotRPC_CI_rxData_cb, this);
|
||||
@@ -49,8 +50,8 @@ void GobotRPC_CI::onRxData(char *data, size_t len) {
|
||||
|
||||
case SET_ADDR_PORT_MAP: {
|
||||
if(this->cb_SetAddressMap != NULL) {
|
||||
uint32_t addr = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
|
||||
uint8_t port = data[5];
|
||||
uint32_t addr = (data[2] << 24) | (data[3] << 16) | (data[4] << 8) | data[5];
|
||||
uint8_t port = data[6];
|
||||
this->cb_SetAddressMap(cb_SetAddressMap_args, addr, port);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -74,4 +74,17 @@ void GobotRPC_CI::send_InfoReset() {
|
||||
resetPacket[1] = 2;
|
||||
|
||||
this->hardware->send(resetPacket, 2);
|
||||
}
|
||||
|
||||
// CI Reverse Instructions (CI -> TI)
|
||||
void GobotRPC_CI::send_rev_SetAddrMap(uint32_t addr, uint8_t port) {
|
||||
CI_Instruction_Transport ciInstruction;
|
||||
ciInstruction.type = CI_INSTRUCTION_REV_SEND_SET_ADDR_MAP;
|
||||
ciInstruction.data[0] = addr & 0xff;
|
||||
ciInstruction.data[1] = (addr >> 8) & 0xff;
|
||||
ciInstruction.data[2] = (addr >> 16) & 0xff;
|
||||
ciInstruction.data[3] = (addr >> 24) & 0xff;
|
||||
ciInstruction.data[4] = port;
|
||||
|
||||
xQueueSend(ciInstructionReverseQueue, &ciInstruction, portMAX_DELAY);
|
||||
}
|
||||
@@ -42,8 +42,9 @@ private:
|
||||
TaskHandle_t txCIInstructionTaskHandle;
|
||||
|
||||
QueueHandle_t ciInstructionQueue;
|
||||
QueueHandle_t ciInstructionReverseQueue;
|
||||
public:
|
||||
GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue);
|
||||
GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue, QueueHandle_t ciInstructionReverseQueue);
|
||||
|
||||
void registerCB_TxPacket(callback_TxPacket cb, void *args);
|
||||
void registerCB_SetAddress(callback_SetAddress cb, void *args);
|
||||
@@ -55,6 +56,7 @@ public:
|
||||
void heartBeartTaskFn();
|
||||
|
||||
// CI Instruction Stuff
|
||||
void send_rev_SetAddrMap(uint32_t addr, uint8_t port);
|
||||
void txCIInstructionTask();
|
||||
void send_ErrorTransmission(bool rx, uint64_t addr);
|
||||
void send_SuccessTransmission(uint64_t addr);
|
||||
|
||||
@@ -45,7 +45,7 @@ private:
|
||||
inputBuffers_t inputBufferPool[NUM_INPUT_BUFFERS];
|
||||
|
||||
TaskHandle_t rxProcessingTaskHandle;
|
||||
|
||||
|
||||
SemaphoreHandle_t rxSignalSemaphore;
|
||||
QueueHandle_t emptyInputBuffersQueue;
|
||||
QueueHandle_t filledInputBuffersQueue;
|
||||
@@ -67,7 +67,6 @@ public:
|
||||
void onRx_ISR();
|
||||
void rxBufferingTaskFn();
|
||||
void rxProcessingTaskFn();
|
||||
|
||||
};
|
||||
|
||||
extern GobotRPC_CI_Hardware_RP2040_UART * g_GobotRPC_CI_Hardware_RP2040_UART;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
enum CI_Instruction_Type {
|
||||
CI_INSTRUCTION_SEND_TRANMISSION_ERROR,
|
||||
CI_INSTRUCTION_SEND_TRANMISSION_SUCCESS,
|
||||
CI_INSTRUCTION_SEND_INFO_RESET
|
||||
CI_INSTRUCTION_SEND_INFO_RESET,
|
||||
CI_INSTRUCTION_REV_SEND_SET_ADDR_MAP,
|
||||
};
|
||||
|
||||
struct CI_Instruction_Transport {
|
||||
|
||||
@@ -9,6 +9,7 @@ struct AppData {
|
||||
QueueHandle_t txQueue;
|
||||
QueueHandle_t rxQueue;
|
||||
QueueHandle_t ciInstructionQueue;
|
||||
QueueHandle_t ciInstructionReverseQueue;
|
||||
};
|
||||
|
||||
void main_core2(void * pvParameters);
|
||||
|
||||
@@ -55,8 +55,14 @@ private:
|
||||
SemaphoreHandle_t i2cMutex;
|
||||
SemaphoreHandle_t i2cRXSemaphore;
|
||||
|
||||
|
||||
TaskHandle_t i2cRxTaskHandle;
|
||||
TaskHandle_t i2cTxTaskHandle;
|
||||
TaskHandle_t i2cIntTaskHandle;
|
||||
TaskHandle_t revCIInstructionTaskHandle;
|
||||
|
||||
QueueHandle_t revCIInstructionQueue;
|
||||
|
||||
UBaseType_t core;
|
||||
|
||||
i2c_inst_t * i2c;
|
||||
@@ -67,7 +73,7 @@ private:
|
||||
bool readI2C(GoRPCPackage_Transport * pkg, uint32_t addr);
|
||||
|
||||
public:
|
||||
GobotRPC_TI_Hardware_RP2040_I2C(UBaseType_t core, i2c_inst_t *i2c);
|
||||
GobotRPC_TI_Hardware_RP2040_I2C(UBaseType_t core, i2c_inst_t *i2c, QueueHandle_t revCIInstructionQueue);
|
||||
|
||||
void registerPullPackageCB(callback_pullPackage cb, void *args);
|
||||
void registerPushPackageCB(callback_pushPackage cb, void *args);
|
||||
@@ -77,12 +83,15 @@ public:
|
||||
|
||||
void i2cRxTask();
|
||||
void i2cTxTask();
|
||||
void manualTriggerIntTask();
|
||||
void intPinISR(BaseType_t * xHigherPriorityTaskWoken);
|
||||
uint32_t readIntPins();
|
||||
|
||||
void raiseTranmissionError(bool rx, uint32_t addr);
|
||||
void raiseTransmissionSuceess(uint32_t addr);
|
||||
void raiseInfoReset();
|
||||
|
||||
void revCIInstructionTask();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -31,4 +31,23 @@ void GobotRPC_TI_Hardware_RP2040_I2C::raiseInfoReset() {
|
||||
ciInstruction.type = CI_INSTRUCTION_SEND_INFO_RESET;
|
||||
|
||||
this->pushCIInstructionCB(&ciInstruction, pushCIInstructionCBArgs);
|
||||
}
|
||||
|
||||
void GobotRPC_TI_Hardware_RP2040_I2C::revCIInstructionTask() {
|
||||
CI_Instruction_Transport ciInstruction;
|
||||
while(1) {
|
||||
xQueueReceive(revCIInstructionQueue, &ciInstruction, portMAX_DELAY);
|
||||
|
||||
switch (ciInstruction.type) {
|
||||
case CI_INSTRUCTION_REV_SEND_SET_ADDR_MAP: {
|
||||
uint32_t addr = ciInstruction.data[0] |\
|
||||
(ciInstruction.data[1] << 8) |\
|
||||
(ciInstruction.data[2] << 16) |\
|
||||
(ciInstruction.data[3] << 24);
|
||||
uint8_t port = ciInstruction.data[4];
|
||||
this->setAddrMap(addr, port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
GobotRPC_TI_Hardware_RP2040_I2C * g_GobotRPC_TI_Hardware_RP2040_I2C;
|
||||
|
||||
GobotRPC_TI_Hardware_RP2040_I2C::GobotRPC_TI_Hardware_RP2040_I2C(UBaseType_t core, i2c_inst_t *i2c) {
|
||||
GobotRPC_TI_Hardware_RP2040_I2C::GobotRPC_TI_Hardware_RP2040_I2C(UBaseType_t core, i2c_inst_t *i2c, QueueHandle_t revCIInstructionQueue) {
|
||||
this->core = core;
|
||||
this->i2c = i2c0;
|
||||
this->revCIInstructionQueue = revCIInstructionQueue;
|
||||
|
||||
g_GobotRPC_TI_Hardware_RP2040_I2C = this;
|
||||
|
||||
@@ -38,6 +39,16 @@ GobotRPC_TI_Hardware_RP2040_I2C::GobotRPC_TI_Hardware_RP2040_I2C(UBaseType_t cor
|
||||
|
||||
}
|
||||
|
||||
static void i2cIntTaskFn(void * pvParameters) {
|
||||
GobotRPC_TI_Hardware_RP2040_I2C * hw = (GobotRPC_TI_Hardware_RP2040_I2C *)pvParameters;
|
||||
hw->manualTriggerIntTask();
|
||||
}
|
||||
|
||||
static void revCIInstructionTaskFn(void * pvParameters) {
|
||||
GobotRPC_TI_Hardware_RP2040_I2C * hw = (GobotRPC_TI_Hardware_RP2040_I2C *)pvParameters;
|
||||
hw->revCIInstructionTask();
|
||||
}
|
||||
|
||||
void GobotRPC_TI_Hardware_RP2040_I2C::initTasks() {
|
||||
i2cMutex = xSemaphoreCreateMutex();
|
||||
i2cRXSemaphore = xSemaphoreCreateBinary();
|
||||
@@ -51,6 +62,8 @@ void GobotRPC_TI_Hardware_RP2040_I2C::initTasks() {
|
||||
|
||||
xTaskCreateAffinitySet(i2cRxTaskFn, "i2c Rx Task", 4096, this, 3, core, &i2cRxTaskHandle);
|
||||
xTaskCreateAffinitySet(i2cTxTaskFn, "i2c Tx Task", 4096, this, 3, core, &i2cTxTaskHandle);
|
||||
xTaskCreateAffinitySet(i2cIntTaskFn, "i2c Int Task", 4096, this, 3, core, &i2cIntTaskHandle);
|
||||
xTaskCreateAffinitySet(revCIInstructionTaskFn, "Rev CI Instruction Task", 4096, this, 3, core, &revCIInstructionTaskHandle);
|
||||
}
|
||||
|
||||
void GobotRPC_TI_Hardware_RP2040_I2C::registerPullPackageCB(callback_pullPackage cb, void *args) {
|
||||
|
||||
@@ -31,4 +31,19 @@ void GobotRPC_TI_Hardware_RP2040_I2C::intPinISR(BaseType_t * xHigherPriorityTask
|
||||
xSemaphoreGiveFromISR(i2cRXSemaphore, xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
void GobotRPC_TI_Hardware_RP2040_I2C::manualTriggerIntTask() {
|
||||
while (1) {
|
||||
uint32_t intPinsStates = readIntPins();
|
||||
|
||||
if(intPinsStates == 0) {
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
continue;
|
||||
}
|
||||
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
||||
xSemaphoreGive(i2cRXSemaphore);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ void GobotRPC_TI_Hardware_RP2040_I2C::i2cRxTask() {
|
||||
xSemaphoreTake(i2cRXSemaphore, portMAX_DELAY);
|
||||
|
||||
uint32_t done_mask = 0xffffffff;
|
||||
|
||||
uint32_t pinStates = readIntPins();
|
||||
|
||||
do {
|
||||
@@ -18,6 +19,7 @@ void GobotRPC_TI_Hardware_RP2040_I2C::i2cRxTask() {
|
||||
if((pinStates & done_mask) & (1 << i)) {
|
||||
done_mask &= ~(1 << i);
|
||||
|
||||
|
||||
uint32_t addr = intAddressMap[i];
|
||||
|
||||
if(addr > 0xff)
|
||||
|
||||
@@ -53,25 +53,31 @@ void onRXFromI2CTask(void * pvParameters) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onSetAddrMap(void * args, uint32_t addr, uint8_t port) {
|
||||
GobotRPC_CI * gobotrpc_ci = (GobotRPC_CI *)args;
|
||||
gobotrpc_ci->send_rev_SetAddrMap(addr, port);
|
||||
}
|
||||
|
||||
int main() {
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, true);
|
||||
|
||||
appData.txQueue = xQueueCreate(5, sizeof(GoRPCPackage_Transport));
|
||||
appData.rxQueue = xQueueCreate(5, sizeof(GoRPCPackage_Transport));
|
||||
appData.ciInstructionQueue = xQueueCreate(5, sizeof(CI_Instruction_Transport));
|
||||
appData.ciInstructionQueue = xQueueCreate(3, sizeof(CI_Instruction_Transport));
|
||||
appData.ciInstructionReverseQueue = xQueueCreate(3, sizeof(CI_Instruction_Transport));
|
||||
|
||||
GobotRPC_CI_Hardware_RP2040_UART gobotrpc_ci_hardware(uart0, 115200, UART_CORE_MASK);
|
||||
|
||||
GobotRPC_CI gobotRPC_ci(&gobotrpc_ci_hardware, UART_CORE_MASK, appData.ciInstructionQueue);
|
||||
|
||||
|
||||
GobotRPC_CI gobotRPC_ci(&gobotrpc_ci_hardware, UART_CORE_MASK, appData.ciInstructionQueue, appData.ciInstructionReverseQueue);
|
||||
gobotRPC_ci.registerCB_SetAddress(onSetAddrMap, &gobotRPC_ci);
|
||||
gobotRPC_ci.registerCB_TxPacket(onTxPacket, &gobotRPC_ci);
|
||||
|
||||
TaskHandle_t taskHandleCore0;
|
||||
TaskHandle_t taskHandleCore1;
|
||||
TaskHandle_t taskRXFromI2CTask;
|
||||
xTaskCreateAffinitySet(vTaskMain, "Main Task Core 0", 2048, &gobotRPC_ci, 1, UART_CORE_MASK, &taskHandleCore0);
|
||||
xTaskCreateAffinitySet(main_core2, "Main Task Core 1", 2048, &gobotRPC_ci, 1, UART_CORE_MASK, &taskHandleCore1);
|
||||
xTaskCreateAffinitySet(main_core2, "Main Task Core 1", 2048, &appData, 1, UART_CORE_MASK, &taskHandleCore1);
|
||||
xTaskCreateAffinitySet(onRXFromI2CTask, "RX From I2C Task", 2048, &gobotRPC_ci, 3, UART_CORE_MASK, &taskRXFromI2CTask);
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
@@ -26,8 +26,9 @@ void pushCIInstruction(CI_Instruction_Transport * src, void *args) {
|
||||
}
|
||||
|
||||
void main_core2(void * pvParameters) {
|
||||
AppData appData = *((AppData *)pvParameters);
|
||||
GobotRPC_TI_Hardware_RP2040_I2C gobotrpc_ti_hardware(UART_CORE_MASK, i2c0);
|
||||
AppData appData1 = *(AppData *)pvParameters;
|
||||
|
||||
GobotRPC_TI_Hardware_RP2040_I2C gobotrpc_ti_hardware(UART_CORE_MASK, i2c0, appData1.ciInstructionReverseQueue);
|
||||
//gobotrpc_ti_hardware.setAddrMap(0x21, 0);
|
||||
|
||||
gobotrpc_ti_hardware.registerPullPackageCB(pullPackageCB, appData.txQueue);
|
||||
|
||||
Reference in New Issue
Block a user