33 lines
1.6 KiB
C
33 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "periph28335.h"
|
|
|
|
int main(void)
|
|
{
|
|
uint8_t request[PERIPH28335_REQUEST_SIZE];
|
|
static const uint8_t read_prefix[] = { 0x10U, 0x03U, 0x00U, 0x18U, 0x00U, 0x40U };
|
|
static const uint8_t response_payload[] = { 0x10U, 0x03U, 0x04U, 0x80U, 0x05U, 0x12U, 0x34U };
|
|
uint8_t response[sizeof response_payload + 2U];
|
|
uint16_t words[2];
|
|
|
|
if (periph28335_build_read_registers(16U, 24U, 64U, request, sizeof request)
|
|
!= sizeof request || memcmp(request, read_prefix, sizeof read_prefix) != 0) return 1;
|
|
if (periph28335_build_write_register(16U, 7U, 0x1234U, request, sizeof request)
|
|
!= sizeof request || memcmp(request, "\x10\x06\x00\x07\x12\x34", 6U) != 0) return 2;
|
|
if (periph28335_build_command(16U, 15U, request, sizeof request)
|
|
!= sizeof request || memcmp(request, "\x10\x06\x00\x7F\x80\x00", 6U) != 0) return 3;
|
|
if (periph28335_append_crc(response_payload, sizeof response_payload,
|
|
response, sizeof response) != sizeof response) return 4;
|
|
if (periph28335_decode_read_response(response, sizeof response, 16U, 2U,
|
|
words, 2U) != PERIPH28335_OK || words[0] != 0x8005U || words[1] != 0x1234U) return 5;
|
|
response[0] = 17U;
|
|
if (periph28335_decode_read_response(response, sizeof response, 16U, 2U,
|
|
words, 2U) != PERIPH28335_ERROR_CRC) return 6;
|
|
if (periph28335_project_count() != 9U ||
|
|
strcmp(periph28335_project_name(2U), "23550") != 0 ||
|
|
strcmp(periph28335_command_name(2U, 7U), "Send") != 0) return 7;
|
|
puts("PM35/TMS320F28335 protocol tests passed");
|
|
return 0;
|
|
}
|