MNRS-BM-BSP/include/ehrenberg/devices/flexki_messages.h

57 lines
2.2 KiB
C

#ifndef _FLEXKI_MESSAGES_H
#define _FLEXKI_MESSAGES_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 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 */