Files
templates/c/set-protocol/ports/tms320f28335/ump_tms28335.c

51 lines
2.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Порт УМП для TMS320F28335. Аппаратное представление данных C28x связывается с общим
* регистровым протоколом; восьмибитные октеты линии нельзя приравнивать к размеру char
* целевого компилятора.
*/
#include "ump_tms28335.h"
extern unsigned int ump_log_read(unsigned int address);
extern int ump_log_write(unsigned int address, unsigned int value);
static uint16_t read_word(void *context, uint16_t address)
{
(void)context;
/* Optional board binding to the common firmware-info static port. Older
* consumers still link without it and return contract=0 (unknown version).
* This hook changes neither PM67 CAN nor the saved parameter layout. */
#ifdef UMP_FIRMWARE_INFO_READ
if (address >= UMP_FIRMWARE_INFO && address < UMP_FIRMWARE_INFO + UMP_FIRMWARE_INFO_WORDS)
return UMP_FIRMWARE_INFO_READ(address - UMP_FIRMWARE_INFO);
#endif
return (uint16_t)ump_log_read(address);
}
static int write_word(void *context, uint16_t address, uint16_t value)
{ (void)context; return ump_log_write(address,value); }
unsigned ump_tms28335_prepare(unsigned fn, uint16_t a, uint16_t n,
uint16_t *reply, unsigned *error)
{
const ump_backend backend = {0,read_word,write_word};
return ump_prepare(&backend,fn,a,n,1,reply,error);
}
size_t ump_tms28335_rtu(unsigned device, unsigned fn, uint16_t a,
uint16_t n, ump_octet *reply, size_t capacity)
{
const ump_backend backend = {0,read_word,write_word};
return ump_rtu_response(&backend,device,fn,a,n,reply,capacity);
}
unsigned ump_tms28335_capture(unsigned fn, uint16_t a, uint16_t n,
uint16_t *words, unsigned *error)
{
const ump_backend backend = {0,read_word,write_word};
return ump_prepare(&backend,fn,a,n,0,words,error);
}
unsigned ump_tms28335_fragment(const uint16_t *words, unsigned count, unsigned index,
unsigned token, unsigned error, uint32_t *mdl, uint32_t *mdh)
{
ump_octet frame[8];
if (!mdl || !mdh || !ump_can_fragment(words,count,index,token,error,frame)) return 0;
*mdl=((uint32_t)frame[0]<<24)|((uint32_t)frame[1]<<16)|(frame[2]<<8)|frame[3];
*mdh=((uint32_t)frame[4]<<24)|((uint32_t)frame[5]<<16)|(frame[6]<<8)|frame[7];
return 8;
}