Files
templates/c/set-protocol/tests/test_tms2812.c

36 lines
1.2 KiB
C

#include <stdio.h>
#include <string.h>
#include "tms2812.h"
int main(void)
{
uint8_t request[TMS2812_UPLOAD_REQUEST_SIZE];
static const uint8_t prefix[] = {
0x05U, 0x34U, 0x78U, 0x56U, 0x34U, 0x12U,
0x00U, 0x10U, 0x00U, 0x00U
};
uint8_t reply[4U + TMS2812_UPLOAD_RESPONSE_OVERHEAD];
uint8_t decoded[4];
uint16_t crc;
if (tms2812_build_upload_request(5U, 0x12345678UL, 0x1000U,
request, sizeof request) != sizeof request ||
memcmp(request, prefix, sizeof prefix) != 0) return 1;
reply[0] = 5U;
reply[1] = TMS2812_CMD_UPLOAD;
reply[2] = 0x10U; reply[3] = 0x20U; reply[4] = 0x30U; reply[5] = 0x40U;
crc = tms2812_crc16(reply, 6U);
reply[6] = (uint8_t)crc;
reply[7] = (uint8_t)(crc >> 8);
memset(&reply[8], 0, 4U);
if (tms2812_decode_upload_response(reply, sizeof reply, 5U, 4U,
decoded, sizeof decoded) != TMS2812_OK ||
memcmp(decoded, &reply[2], sizeof decoded) != 0) return 2;
reply[6] ^= 1U;
if (tms2812_validate_upload_response(reply, sizeof reply, 5U, 4U)
!= TMS2812_ERROR_CRC) return 3;
puts("PM67/TMS320F2812 upload protocol tests passed");
return 0;
}