diff --git a/env/ehrenberg/platform.h b/env/ehrenberg/platform.h index 549e58a..50a19c8 100644 --- a/env/ehrenberg/platform.h +++ b/env/ehrenberg/platform.h @@ -36,7 +36,9 @@ #define i2s PERIPH(i2s_t, APB_BASE + 0x90000) #define camera PERIPH(camera_t, APB_BASE + 0xA0000) #define dma PERIPH(dma_t, APB_BASE + 0xB0000) -#define msgif PERIPH(msgif_t, APB_BASE + 0xC0000) +#define msgif PERIPH(mkcontrolclusterstreamcontroller_t, APB_BASE + 0xC0000) + +#include "ehrenberg/devices/flexki_messages.h" #define XIP_START_LOC 0xE0040000 #define RAM_START_LOC 0x80000000 diff --git a/include/ehrenberg/devices/flexki_messages.h b/include/ehrenberg/devices/flexki_messages.h new file mode 100644 index 0000000..4af6938 --- /dev/null +++ b/include/ehrenberg/devices/flexki_messages.h @@ -0,0 +1,57 @@ +#ifndef _FLEXKI_MESSAGES_H +#define _FLEXKI_MESSAGES_H + +#include + +static void send_msg(uint32_t cluster, uint32_t component, uint32_t msg_len, uint32_t msg_id, uint32_t* words) { + set_mkcontrolclusterstreamcontroller_REG_HEADER_RECIPIENT_COMPONENT(msgif, component); + set_mkcontrolclusterstreamcontroller_REG_HEADER_RECIPIENT_CLUSTER(msgif, cluster); + set_mkcontrolclusterstreamcontroller_REG_HEADER_MESSAGE_LENGTH(msgif, msg_len); + set_mkcontrolclusterstreamcontroller_REG_HEADER_MESSAGE_ID(msgif, msg_id); + for (uint32_t i = 0; i < msg_len; i = i + 1) { + switch (i) { + case 0: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_0(msgif, words[i]); + break; + case 1: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_1(msgif, words[i]); + break; + case 2: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_2(msgif, words[i]); + break; + case 3: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_3(msgif, words[i]); + break; + case 4: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_4(msgif, words[i]); + break; + case 5: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_5(msgif, words[i]); + break; + case 6: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_6(msgif, words[i]); + break; + case 7: + set_mkcontrolclusterstreamcontroller_REG_PAYLOAD_7(msgif, words[i]); + break; + + default: + } + } + set_mkcontrolclusterstreamcontroller_REG_SEND(msgif, 1); +} + +static uint32_t wait_response(uint32_t msg_id) { + while (true) { + if (get_mkcontrolclusterstreamcontroller_REG_ACK_PENDING_RESPONSE(msgif) != 0) { + if (get_mkcontrolclusterstreamcontroller_REG_RECV_ID_RECV_ID(msgif) == msg_id) { + break; + } + } + } + uint32_t response_payload = get_mkcontrolclusterstreamcontroller_REG_RECV_PAYLOAD(msgif); + set_mkcontrolclusterstreamcontroller_REG_ACK_ACK(msgif, 1); + return response_payload; +} + +#endif /* _FLEXKI_MESSAGES_H */ \ No newline at end of file diff --git a/include/ehrenberg/devices/msg_if.h b/include/ehrenberg/devices/msg_if.h index d4727f5..ea8e3ed 100644 --- a/include/ehrenberg/devices/msg_if.h +++ b/include/ehrenberg/devices/msg_if.h @@ -1,6 +1,6 @@ #ifndef _DEVICES_MSG_IF_H #define _DEVICES_MSG_IF_H -#include "gen/msgif.h" +#include "gen/mkcontrolclusterstreamcontroller.h" #endif /* _DEVICES_MSG_IF_H */