-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_logger.c
More file actions
39 lines (32 loc) · 1.16 KB
/
back_logger.c
File metadata and controls
39 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdint.h>
#include "back_logger.h"
static MmrZcpInstance loggerZcpInstance;
static uint8_t loggerTxBuffer[512];
static uint8_t seq_id = 0;
#define WRITE_BEGIN(id) writeBegin(id)
#define WRITE_ASSERT(x) if (!(x)) { MMR_ZCP_TxTransactionAbort(HZCP); return false; }
#define WRITE_APPEND(x) MMR_ZCP_TxTransactionAppend(HZCP, little_endian(x), sizeof(x))
#define WRITE_END() writeEnd()
#define little_endian(x) ((uint8_t*)(&(x)))
#define HZCP (&loggerZcpInstance)
static bool writeBegin(uint16_t msg_id) {
uint32_t tick = MMR_GetTick();
return MMR_ZCP_TxTransactionBegin(HZCP)
&& MMR_ZCP_TxTransactionAppend(HZCP, little_endian(seq_id), sizeof(seq_id))
&& MMR_ZCP_TxTransactionAppend(HZCP, little_endian(tick), sizeof(tick))
&& MMR_ZCP_TxTransactionAppend(HZCP, little_endian(msg_id), sizeof(msg_id));
}
static bool writeEnd() {
if (MMR_ZCP_TxTransactionCommit(HZCP)) {
++seq_id;
return true;
}
return false;
}
#include "log_gen_defs.h"
void MMR_BACK_LOGGER_Init(MmrZcpBsp zcpBsp) {
MMR_ZCP_Init(&loggerZcpInstance, loggerTxBuffer, sizeof(loggerTxBuffer), zcpBsp);
}
void MMR_BACK_LOGGER_Run() {
MMR_ZCP_Run(&loggerZcpInstance);
}