42 lines
1.8 KiB
C
42 lines
1.8 KiB
C
/* Minimal board-independent composition. This compiles without any MCU headers.
|
|
* Adapt these entry points to the selected board's network/USB/UART/CAN port.
|
|
* Run every call in one task (or protect the entire call with the same lock). */
|
|
#include "set_emu_igbt.h"
|
|
static set_igbt_emu drivers[2];
|
|
static set_reg_region regions[2];
|
|
static set_regmap map;
|
|
unsigned example_service_init(void)
|
|
{
|
|
unsigned i;
|
|
for(i=0;i<2;++i) {
|
|
set_reg_region *r=®ions[i];
|
|
set_igbt_init(&drivers[i]);
|
|
r->base=(uint16_t)(0x300+i*0x100);r->words=SET_IGBT_WORDS;
|
|
r->kind=4;r->version=2;r->instance=(uint16_t)i;r->flags=3;
|
|
r->context=&drivers[i];r->read=set_igbt_read;r->write=set_igbt_write;
|
|
}
|
|
return set_regmap_init(&map,regions,2);
|
|
}
|
|
void example_service_tick(uint8_t inputs0,uint8_t inputs1,uint8_t outputs[2])
|
|
{
|
|
set_igbt_tick(&drivers[0],inputs0);set_igbt_tick(&drivers[1],inputs1);
|
|
outputs[0]=drivers[0].rx;outputs[1]=drivers[1].rx;
|
|
}
|
|
unsigned example_custom_protocol(unsigned function,uint16_t address,uint16_t value,
|
|
uint16_t *words,size_t capacity,size_t *count)
|
|
{
|
|
/* Caller has already decoded/authenticated its own transport envelope. */
|
|
return set_regmap_request(&map,function,address,value,words,capacity,count);
|
|
}
|
|
size_t example_uart_or_usb(const uint8_t *frame,size_t length,uint8_t *reply,size_t capacity)
|
|
{
|
|
return set_regmap_rtu(&map,16,frame,length,reply,capacity);
|
|
}
|
|
size_t example_can(const uint8_t frame[8],uint16_t *snapshot,size_t capacity,
|
|
unsigned *token,unsigned *error)
|
|
{
|
|
/* Select the CAN request ID outside the model; send the returned snapshot
|
|
* using set_regmap_can_fragment and the board's chosen response CAN ID. */
|
|
return set_regmap_can(&map,frame,8,snapshot,capacity,token,error);
|
|
}
|