MNRS-BM-BSP/include/ehrenberg/devices/flexki_messages.h
2025-02-26 17:10:46 +01:00

77 lines
2.7 KiB
C

#ifndef _FLEXKI_MESSAGES_H
#define _FLEXKI_MESSAGES_H
#include "fki_cluster_info.h"
#include <stdbool.h>
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:
break;
}
}
set_mkcontrolclusterstreamcontroller_REG_SEND(msgif, 1);
}
static uint32_t check_response(void) {
while (true) {
if (get_mkcontrolclusterstreamcontroller_REG_ACK_PENDING_RESPONSE(msgif) != 0) {
return get_mkcontrolclusterstreamcontroller_REG_RECV_ID_RECV_ID(msgif);
}
}
}
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;
}
static void fki_dma_transfer(uint32_t cluster, uint32_t msg_id, uint32_t srcAddr, uint32_t destAddr, uint32_t bytes) {
uint32_t values[] = {
0,
srcAddr,
destAddr,
bytes
};
send_msg(cluster, fki_dma(cluster), 4, msg_id, values);
}
#endif /* _FLEXKI_MESSAGES_H */