add scale parameter to sserial

This commit is contained in:
Rene Hopf
2017-12-06 18:38:55 +01:00
parent cdebad1738
commit a6343d00de
4 changed files with 277 additions and 230 deletions

View File

@@ -290,7 +290,7 @@ f3_boot:
deploy: boot f3_boot f3 build
format:
find src/ f3dfu/ bootloader/ stm32f103/ stm32f303/ shared/ inc/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
find src/ f3dfu/ bootloader/ stm32f103/ stm32f303/ shared/ inc/ tools/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
# Display compiler version information
#

View File

@@ -40,3 +40,4 @@ io0.out2 = sserial0.out2
fault0.brake_release = sserial0.out3
term0.wave2 = linrev0.cmd_d_out
sserial0.current = hv0.q_fb
linrev0.scale = sserial0.scale

View File

@@ -43,6 +43,7 @@ HAL_PIN(pos_cmd_d);
HAL_PIN(pos_fb);
HAL_PIN(vel_fb);
HAL_PIN(current);
HAL_PIN(scale);
HAL_PIN(in0);
HAL_PIN(in1);
@@ -77,65 +78,71 @@ int available;
unit_no_t unit;
uint32_t max_waste_ticks;
uint32_t block_bytes;
int printdebug;
uint8_t printbuf[16];
#pragma pack(1)
//*****************************************************************************
uint8_t sserial_slave[] = {
0x0B, 0x09, 0x7F, 0x01, 0x99, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xA0, 0x20, 0x10, 0x80,
0x00, 0x00, 0x80, 0xFF, 0x00, 0x00, 0x80, 0x7F,
0x08, 0x00, 0x72, 0x61, 0x64, 0x00, 0x70, 0x6F,
0x73, 0x5F, 0x63, 0x6D, 0x64, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xA0, 0x20, 0x10, 0x80,
0x00, 0x00, 0x80, 0xFF, 0x00, 0x00, 0x80, 0x7F,
0x26, 0x00, 0x72, 0x61, 0x64, 0x00, 0x76, 0x65,
0x6C, 0x5F, 0x63, 0x6D, 0x64, 0x00, 0x00, 0x00,
0xA0, 0x04, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x3F, 0x46, 0x00, 0x6E, 0x6F,
0x6E, 0x65, 0x00, 0x6F, 0x75, 0x74, 0x70, 0x75,
0x74, 0x5F, 0x70, 0x69, 0x6E, 0x73, 0x00, 0x00,
0xA0, 0x01, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x3F, 0x67, 0x00, 0x6E, 0x6F,
0x6E, 0x65, 0x00, 0x65, 0x6E, 0x61, 0x62, 0x6C,
0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA0, 0x20, 0x10, 0x00, 0x00, 0x00, 0x80, 0xFF,
0x00, 0x00, 0x80, 0x7F, 0x82, 0x00, 0x72, 0x61,
0x64, 0x00, 0x70, 0x6F, 0x73, 0x5F, 0x66, 0x62,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA0, 0x20, 0x10, 0x00, 0x00, 0x00, 0x80, 0xFF,
0x00, 0x00, 0x80, 0x7F, 0xA1, 0x00, 0x72, 0x61,
0x64, 0x00, 0x76, 0x65, 0x6C, 0x5F, 0x66, 0x62,
0x00, 0x00, 0x00, 0x00, 0xA0, 0x08, 0x03, 0x00,
0x00, 0x00, 0xF0, 0xC1, 0x00, 0x00, 0xF0, 0x41,
0xC1, 0x00, 0x41, 0x00, 0x63, 0x75, 0x72, 0x72,
0x65, 0x6E, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA0, 0x04, 0x01, 0x00, 0x00, 0x00, 0xC8, 0xC2,
0x00, 0x00, 0xC8, 0x42, 0xDC, 0x00, 0x6E, 0x6F,
0x6E, 0x65, 0x00, 0x69, 0x6E, 0x70, 0x75, 0x74,
0x5F, 0x70, 0x69, 0x6E, 0x73, 0x00, 0x00, 0x00,
0xA0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x3F, 0xFE, 0x00, 0x6E, 0x6F,
0x6E, 0x65, 0x00, 0x66, 0x61, 0x75, 0x6C, 0x74,
0x00, 0x00, 0x00, 0x00, 0xA0, 0x01, 0x07, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F,
0x19, 0x01, 0x6E, 0x6F, 0x6E, 0x65, 0x00, 0x69,
0x6E, 0x64, 0x65, 0x78, 0x5F, 0x65, 0x6E, 0x61,
0x62, 0x6C, 0x65, 0x00, 0xB0, 0x00, 0x01, 0x00,
0x50, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E,
0x20, 0x6D, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00,
0xA0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x4E, 0x01, 0x00, 0x70,
0x61, 0x64, 0x64, 0x69, 0x6E, 0x67, 0x00, 0x00,
0xA0, 0x02, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x67, 0x01, 0x00, 0x70,
0x61, 0x64, 0x64, 0x69, 0x6E, 0x67, 0x00, 0x0C,
0x00, 0x2C, 0x00, 0x48, 0x00, 0x68, 0x00, 0x88,
0x00, 0xA8, 0x00, 0xC4, 0x00, 0xE0, 0x00, 0x00,
0x01, 0x1C, 0x01, 0x50, 0x01, 0x68, 0x01, 0x00,
0x00, 0x3C, 0x01, 0x00, 0x00,
0x0B, 0x09, 0x9B, 0x01, 0xB5, 0x01, 0x00, 0x00, // 0..7
0x00, 0x00, 0x00, 0x00, 0xA0, 0x20, 0x10, 0x80, // 8..15
0x00, 0x00, 0x80, 0xFF, 0x00, 0x00, 0x80, 0x7F, // 16..23
0x08, 0x00, 0x72, 0x61, 0x64, 0x00, 0x70, 0x6F, // 24..31
0x73, 0x5F, 0x63, 0x6D, 0x64, 0x00, 0x00, 0x00, // 32..39
0x00, 0x00, 0x00, 0x00, 0xA0, 0x20, 0x10, 0x80, // 40..47
0x00, 0x00, 0x80, 0xFF, 0x00, 0x00, 0x80, 0x7F, // 48..55
0x26, 0x00, 0x72, 0x61, 0x64, 0x00, 0x76, 0x65, // 56..63
0x6C, 0x5F, 0x63, 0x6D, 0x64, 0x00, 0x00, 0x00, // 64..71
0xA0, 0x04, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, // 72..79
0x00, 0x00, 0x80, 0x3F, 0x46, 0x00, 0x6E, 0x6F, // 80..87
0x6E, 0x65, 0x00, 0x6F, 0x75, 0x74, 0x70, 0x75, // 88..95
0x74, 0x5F, 0x70, 0x69, 0x6E, 0x73, 0x00, 0x00, // 96..103
0xA0, 0x01, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, // 104..111
0x00, 0x00, 0x80, 0x3F, 0x67, 0x00, 0x6E, 0x6F, // 112..119
0x6E, 0x65, 0x00, 0x65, 0x6E, 0x61, 0x62, 0x6C, // 120..127
0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 128..135
0xA0, 0x20, 0x10, 0x00, 0x00, 0x00, 0x80, 0xFF, // 136..143
0x00, 0x00, 0x80, 0x7F, 0x82, 0x00, 0x72, 0x61, // 144..151
0x64, 0x00, 0x70, 0x6F, 0x73, 0x5F, 0x66, 0x62, // 152..159
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 160..167
0xA0, 0x20, 0x10, 0x00, 0x00, 0x00, 0x80, 0xFF, // 168..175
0x00, 0x00, 0x80, 0x7F, 0xA1, 0x00, 0x72, 0x61, // 176..183
0x64, 0x00, 0x76, 0x65, 0x6C, 0x5F, 0x66, 0x62, // 184..191
0x00, 0x00, 0x00, 0x00, 0xA0, 0x08, 0x03, 0x00, // 192..199
0x00, 0x00, 0xF0, 0xC1, 0x00, 0x00, 0xF0, 0x41, // 200..207
0xC1, 0x00, 0x41, 0x00, 0x63, 0x75, 0x72, 0x72, // 208..215
0x65, 0x6E, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, // 216..223
0xA0, 0x04, 0x01, 0x00, 0x00, 0x00, 0xC8, 0xC2, // 224..231
0x00, 0x00, 0xC8, 0x42, 0xDC, 0x00, 0x6E, 0x6F, // 232..239
0x6E, 0x65, 0x00, 0x69, 0x6E, 0x70, 0x75, 0x74, // 240..247
0x5F, 0x70, 0x69, 0x6E, 0x73, 0x00, 0x00, 0x00, // 248..255
0xA0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, // 256..263
0x00, 0x00, 0x80, 0x3F, 0xFE, 0x00, 0x6E, 0x6F, // 264..271
0x6E, 0x65, 0x00, 0x66, 0x61, 0x75, 0x6C, 0x74, // 272..279
0x00, 0x00, 0x00, 0x00, 0xA0, 0x01, 0x07, 0x40, // 280..287
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, // 288..295
0x19, 0x01, 0x6E, 0x6F, 0x6E, 0x65, 0x00, 0x69, // 296..303
0x6E, 0x64, 0x65, 0x78, 0x5F, 0x65, 0x6E, 0x61, // 304..311
0x62, 0x6C, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, // 312..319
0xA0, 0x20, 0x10, 0x80, 0x00, 0x00, 0x80, 0xFF, // 320..327
0x00, 0x00, 0x80, 0x7F, 0x3C, 0x01, 0x6E, 0x6F, // 328..335
0x6E, 0x65, 0x00, 0x73, 0x63, 0x61, 0x6C, 0x65, // 336..343
0x00, 0xB0, 0x00, 0x01, 0x00, 0x50, 0x6F, 0x73, // 344..351
0x69, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x6D, 0x6F, // 352..359
0x64, 0x65, 0x00, 0x00, 0xA0, 0x02, 0x00, 0x00, // 360..367
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 368..375
0x6B, 0x01, 0x00, 0x70, 0x61, 0x64, 0x64, 0x69, // 376..383
0x6E, 0x67, 0x00, 0x00, 0xA0, 0x02, 0x00, 0x80, // 384..391
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 392..399
0x83, 0x01, 0x00, 0x70, 0x61, 0x64, 0x64, 0x69, // 400..407
0x6E, 0x67, 0x00, 0x0C, 0x00, 0x2C, 0x00, 0x48, // 408..415
0x00, 0x68, 0x00, 0x88, 0x00, 0xA8, 0x00, 0xC4, // 416..423
0x00, 0xE0, 0x00, 0x00, 0x01, 0x1C, 0x01, 0x6C, // 424..431
0x01, 0x84, 0x01, 0x00, 0x00, 0x40, 0x01, 0x59, // 432..439
0x01, 0x00, 0x00,
};
uint16_t sserial_ptocp = 0x017F;
uint16_t sserial_gtocp = 0x0199;
uint16_t sserial_ptocp = 0x019B;
uint16_t sserial_gtocp = 0x01B5;
typedef struct {
float pos_cmd;
@@ -163,6 +170,8 @@ typedef struct {
uint32_t padding : 2;
} sserial_in_process_data_t; //size:10 bytes
_Static_assert(sizeof(sserial_in_process_data_t) == 10, "sserial_in_process_data_t size error!");
//global name:scale addr:0x13c size:32 dir:0x80
#define scale_address 316
//******************************************************************************
sserial_out_process_data_t data_out;
sserial_in_process_data_t data_in;
@@ -472,23 +481,54 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst
} else {
continue;
}
} else if(lbp.ct == CT_RW && lbp.wr == 0) { //read TODO: implement write.
timeout = 0;
if(available >= 2) {
if(lbp.as == 1) { //address included in command = cmd+addr+addr+crc
if(available >= 4) {
address = rxbuf[(rxpos + 1) % sizeof(rxbuf)] + (rxbuf[(rxpos + 2) % sizeof(rxbuf)] << 8);
rxpos += 4;
} else {
continue;
}
} else if(lbp.ct == CT_RW && lbp.wr == 0) { //read
//size = 1 + 2*lbp.as + 1
int size = 2 * lbp.as + 2;
timeout = 0;
if(available >= size) {
if(lbp.as) { //address included in command = cmd+addr+addr+crc
address = rxbuf[(rxpos + 1) % sizeof(rxbuf)] + (rxbuf[(rxpos + 2) % sizeof(rxbuf)] << 8);
rxpos += 4;
} else { //address not included in command = cmd+crc
rxpos += 2;
}
//TODO: check if address is valid
memcpy((void *)txbuf, &sserial_slave[address], (1 << lbp.ds));
send((1 << lbp.ds), 1);
if(lbp.ai == 1) { //auto increment address by datasize
if(address + (1 << lbp.ds) < sizeof(sserial_slave)) { //check if address is valid
memcpy((void *)txbuf, &sserial_slave[address], (1 << lbp.ds));
send((1 << lbp.ds), 1);
}
if(lbp.ai) { //auto increment address by datasize
address += (1 << lbp.ds);
}
} else {
continue;
}
} else if(lbp.ct == CT_RW && lbp.wr == 1) { // lbp (addr1 addr2) data0, data1,...
//size = 1 + 2*ai +ds +crc
int size = 2 * lbp.as + (1 << lbp.ds) + 2;
timeout = 0;
if(available >= size) {
// for(int i = 0; i < size; i++) {
// printbuf[i] = rxbuf[(rxpos + i) % sizeof(rxbuf)];
// }
// printdebug = size;
if(lbp.as) { //address included in command = cmd+addr+addr+crc
address = rxbuf[(rxpos + 1) % sizeof(rxbuf)] + (rxbuf[(rxpos + 2) % sizeof(rxbuf)] << 8);
rxpos += 3;
} else { //address not included in command = cmd+crc
rxpos += 1;
}
//TODO: check size
if(address + (1 << lbp.ds) < sizeof(sserial_slave)) { //check if address is valid
for(int i = 0; i < (1 << lbp.ds); i++) {
sserial_slave[address + i] = rxbuf[(rxpos + i) % sizeof(rxbuf)];
}
}
rxpos += (1 << lbp.ds) + 1;
//update globals
float tmp;
memcpy(&tmp, &sserial_slave[scale_address], 4);
PIN(scale) = tmp;
if(lbp.ai) { //auto increment address by datasize
address += (1 << lbp.ds);
}
} else {
@@ -519,9 +559,30 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst
timeout++;
}
// static void nrt_func(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
// struct sserial_ctx_t *ctx = (struct sserial_ctx_t *)ctx_ptr;
// struct sserial_pin_ctx_t *pins = (struct sserial_pin_ctx_t *)pin_ptr;
// if(printdebug) {
// printf("write: ");
// for(int i = 0; i < printdebug; i++) {
// printf("0x%x ", printbuf[i]);
// }
// printf("\n");
// printf("sserial_slave @316: ");
// for(int i = 0; i < 4; i++) {
// printf("0x%x ", sserial_slave[i + 316]);
// }
// printf("\n");
// float foo;
// memcpy(&foo, &sserial_slave[316], 4);
// printf("value: %f\n", foo);
// printdebug = 0;
// }
// }
const hal_comp_t sserial_comp_struct = {
.name = "sserial",
.nrt = 0,
.nrt = 0, //nrt_func,
.rt = 0,
.frt = frt_func,
.nrt_init = 0,

View File

@@ -77,195 +77,180 @@ void metadata(pd_metadata_t *pdm, process_data_descriptor_t *ptr) {
pdm->bitmax = (1 << ptr->data_size) - 1;
}
void print_pd(process_data_descriptor_t* pd){
int strl = strlen(&pd->names);
char* unit = &pd->names;
char* name = &pd->names+strl+1;
switch(pd->data_type){
case DATA_TYPE_PAD:
printf("uint32_t padding : %u;\n",pd->data_size);
void print_pd(process_data_descriptor_t *pd) {
int strl = strlen(&pd->names);
char *unit = &pd->names;
char *name = &pd->names + strl + 1;
switch(pd->data_type) {
case DATA_TYPE_PAD:
printf("uint32_t padding : %u;\n", pd->data_size);
break;
case DATA_TYPE_BITS:
for(int i = 0;i<pd->data_size;i++){
printf("uint32_t %s_%i : 1;\n",name,i);
case DATA_TYPE_BITS:
for(int i = 0; i < pd->data_size; i++) {
printf("uint32_t %s_%i : 1;\n", name, i);
}
break;
case DATA_TYPE_UNSIGNED:
if(pd->data_size == 8){
printf("uint8_t %s;\n",name);
}else{
case DATA_TYPE_UNSIGNED:
if(pd->data_size == 8) {
printf("uint8_t %s;\n", name);
} else {
printf("warning: unsupported int size!\n");
}
break;
case DATA_TYPE_SIGNED:
if(pd->data_size == 8){
printf("int8_t %s;\n",name);
}else{
case DATA_TYPE_SIGNED:
if(pd->data_size == 8) {
printf("int8_t %s;\n", name);
} else {
printf("warning: unsupported int size!\n");
}
break;
case DATA_TYPE_FLOAT:
case DATA_TYPE_FLOAT:
//TODO: check size
if(pd->data_size != 32){
printf("warning: unsupported float size!");
if(pd->data_size != 32) {
printf("warning: unsupported float size!");
}
printf("float %s;\n",name);
printf("float %s;\n", name);
break;
case DATA_TYPE_BOOLEAN:
printf("uint32_t %s : %u;\n",name,pd->data_size);
break;
case DATA_TYPE_NONVOL_UNSIGNED:
case DATA_TYPE_NONVOL_SIGNED:
case DATA_TYPE_STREAM:
case DATA_TYPE_ENCODER:
case DATA_TYPE_ENCODER_H:
case DATA_TYPE_ENCODER_L:
default:
printf("unsupported data type: 0x%02X\n",pd->data_type);
}
case DATA_TYPE_BOOLEAN:
printf("uint32_t %s : %u;\n", name, pd->data_size);
break;
case DATA_TYPE_NONVOL_UNSIGNED:
case DATA_TYPE_NONVOL_SIGNED:
case DATA_TYPE_STREAM:
case DATA_TYPE_ENCODER:
case DATA_TYPE_ENCODER_H:
case DATA_TYPE_ENCODER_L:
default:
printf("unsupported data type: 0x%02X\n", pd->data_type);
}
}
int main(){
int main() {
heap_ptr = memory.heap;
uint16_t input_bits = 8; // this starts at 8 bits = 1 byte for the fault byte
uint16_t output_bits = 0;
// these are temp toc arrays that the macros will write pointers into. the tocs get copied to main memory after everything else is written in
uint16_t ptoc[32];
uint16_t gtoc[32];
heap_ptr = memory.heap;
uint16_t *ptocp = ptoc;
uint16_t *gtocp = gtoc;
process_data_descriptor_t *last_pd;
uint16_t input_bits = 8; // this starts at 8 bits = 1 byte for the fault byte
uint16_t output_bits = 0;
ADD_PROCESS_VAR(("pos_cmd", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
metadata(&(pd_table.pos_cmd), last_pd);
ADD_PROCESS_VAR(("vel_cmd", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
metadata(&(pd_table.vel_cmd), last_pd);
ADD_PROCESS_VAR(("output_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_OUTPUT, 0, 1));
metadata(&(pd_table.output_pins), last_pd);
ADD_PROCESS_VAR(("enable", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_OUTPUT, 0, 1));
metadata(&(pd_table.enable), last_pd);
// these are temp toc arrays that the macros will write pointers into. the tocs get copied to main memory after everything else is written in
uint16_t ptoc[32];
uint16_t gtoc[32];
ADD_PROCESS_VAR(("pos_fb", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_INPUT, -INFINITY, INFINITY));
metadata(&(pd_table.pos_fb), last_pd);
ADD_PROCESS_VAR(("vel_fb", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_INPUT, -INFINITY, INFINITY));
metadata(&(pd_table.vel_fb), last_pd);
ADD_PROCESS_VAR(("current", "A", 8, DATA_TYPE_SIGNED, DATA_DIRECTION_INPUT, -30, 30));
metadata(&(pd_table.current), last_pd);
ADD_PROCESS_VAR(("input_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_INPUT, -100, 100));
metadata(&(pd_table.input_pins), last_pd);
ADD_PROCESS_VAR(("fault", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_INPUT, 0, 1));
metadata(&(pd_table.fault), last_pd);
ADD_PROCESS_VAR(("index_enable", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_BI_DIRECTIONAL, 0, 1));
metadata(&(pd_table.index_enable), last_pd);
uint16_t *ptocp = ptoc;
uint16_t *gtocp = gtoc;
process_data_descriptor_t *last_pd;
ADD_GLOBAL_VAR(("scale", "none", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
ADD_PROCESS_VAR(("pos_cmd", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
metadata(&(pd_table.pos_cmd), last_pd);
ADD_PROCESS_VAR(("vel_cmd", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
metadata(&(pd_table.vel_cmd), last_pd);
ADD_PROCESS_VAR(("output_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_OUTPUT, 0, 1));
metadata(&(pd_table.output_pins), last_pd);
ADD_PROCESS_VAR(("enable", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_OUTPUT, 0, 1));
metadata(&(pd_table.enable), last_pd);
ADD_MODE(("Position mode", 0, 1));
ADD_PROCESS_VAR(("pos_fb", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_INPUT, -INFINITY, INFINITY));
metadata(&(pd_table.pos_fb), last_pd);
ADD_PROCESS_VAR(("vel_fb", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_INPUT, -INFINITY, INFINITY));
metadata(&(pd_table.vel_fb), last_pd);
ADD_PROCESS_VAR(("current", "A", 8, DATA_TYPE_SIGNED, DATA_DIRECTION_INPUT, -30, 30));
metadata(&(pd_table.current), last_pd);
ADD_PROCESS_VAR(("input_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_INPUT, -100, 100));
metadata(&(pd_table.input_pins), last_pd);
ADD_PROCESS_VAR(("fault", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_INPUT, 0, 1));
metadata(&(pd_table.fault), last_pd);
ADD_PROCESS_VAR(("index_enable", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_BI_DIRECTIONAL, 0, 1));
metadata(&(pd_table.index_enable), last_pd);
// automatically create padding pds based on the mod remainder of input/output bits
if(input_bits % 8)
ADD_PROCESS_VAR(("padding", "", 8 - (input_bits % 8), DATA_TYPE_PAD, DATA_DIRECTION_INPUT, 0, 0));
if(output_bits % 8)
ADD_PROCESS_VAR(("padding", "", 8 - (output_bits % 8), DATA_TYPE_PAD, DATA_DIRECTION_OUTPUT, 0, 0));
// now that all the toc entries have been added, write out the tocs to memory and set up the toc pointers
//ADD_PROCESS_VAR(("pos_cmd", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_OUTPUT, -INFINITY, INFINITY));
//metadata(&(pd_table.pos_cmd), last_pd);
//calculate bytes from bits
memory.discovery.input = input_bits >> 3;
memory.discovery.output = output_bits >> 3;
// ADD_PROCESS_VAR(("output_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_OUTPUT, 0, 1));
// metadata(&(pd_table.output_pins), last_pd);
// ADD_PROCESS_VAR(("enable", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_OUTPUT, 0, 1));
// metadata(&(pd_table.enable), last_pd);
memory.discovery.ptocp = MEMPTR(*heap_ptr);
for(uint8_t i = 0; i < ptocp - ptoc; i++) {
*heap_ptr++ = ptoc[i] & 0x00FF;
*heap_ptr++ = (ptoc[i] & 0xFF00) >> 8;
}
// this is the ptoc end marker
*heap_ptr++ = 0x00;
*heap_ptr++ = 0x00;
memory.discovery.gtocp = MEMPTR(*heap_ptr);
//ADD_PROCESS_VAR(("pos_fb", "rad", 32, DATA_TYPE_FLOAT, DATA_DIRECTION_INPUT, -INFINITY, INFINITY));
//metadata(&(pd_table.pos_fb), last_pd);
for(uint8_t i = 0; i < gtocp - gtoc; i++) {
*heap_ptr++ = gtoc[i] & 0x00FF;
*heap_ptr++ = (gtoc[i] & 0xFF00) >> 8;
}
// this is the gtoc end marker
*heap_ptr++ = 0x00;
*heap_ptr++ = 0x00;
// ADD_PROCESS_VAR(("input_pins", "none", 4, DATA_TYPE_BITS, DATA_DIRECTION_INPUT, -100, 100));
// metadata(&(pd_table.input_pins), last_pd);
// ADD_PROCESS_VAR(("fault", "none", 1, DATA_TYPE_BOOLEAN, DATA_DIRECTION_INPUT, 0, 1));
// metadata(&(pd_table.fault), last_pd);
//globals and modes are not working. https://github.com/LinuxCNC/linuxcnc/blob/2957cc5ad0a463c39fb35c10a0c14909c09a5fb7/src/hal/drivers/mesa-hostmot2/sserial.c#L1516
// - globals need write support
// - linuxcnc only supports globals of type DATA_TYPE_NONVOL_UNSIGNED or DATA_TYPE_NONVOL_SIGNED
//ADD_GLOBAL_VAR(("swr", "non", 8, DATA_TYPE_NONVOL_UNSIGNED, DATA_DIRECTION_OUTPUT, 0, 0));
//ADD_MODE(("foo", 0, 0));
ADD_MODE(("Position mode", 0, 1));
// automatically create padding pds based on the mod remainder of input/output bits
if(input_bits % 8)
ADD_PROCESS_VAR(("padding", "", 8 - (input_bits % 8), DATA_TYPE_PAD, DATA_DIRECTION_INPUT, 0, 0));
if(output_bits % 8)
ADD_PROCESS_VAR(("padding", "", 8 - (output_bits % 8), DATA_TYPE_PAD, DATA_DIRECTION_OUTPUT, 0, 0));
// now that all the toc entries have been added, write out the tocs to memory and set up the toc pointers
//calculate bytes from bits
memory.discovery.input = input_bits >> 3;
memory.discovery.output = output_bits >> 3;
memory.discovery.ptocp = MEMPTR(*heap_ptr);
for(uint8_t i = 0; i < ptocp - ptoc; i++) {
*heap_ptr++ = ptoc[i] & 0x00FF;
*heap_ptr++ = (ptoc[i] & 0xFF00) >> 8;
}
// this is the ptoc end marker
*heap_ptr++ = 0x00;
*heap_ptr++ = 0x00;
memory.discovery.gtocp = MEMPTR(*heap_ptr);
for(uint8_t i = 0; i < gtocp - gtoc; i++) {
*heap_ptr++ = gtoc[i] & 0x00FF;
*heap_ptr++ = (gtoc[i] & 0xFF00) >> 8;
}
// this is the gtoc end marker
*heap_ptr++ = 0x00;
*heap_ptr++ = 0x00;
// printf("gtoc:%u\n",memory.discovery.gtocp);
// printf("ptoc:%u\n",memory.discovery.ptocp);
// printf("%i\n",sizeof(memory_t));
//printf("%u\n",MEMPTR(*heap_ptr));
int nl = 0;
printf("uint8_t sserial_slave[] = {\n");
for(int i = 0;i < MEMPTR(*heap_ptr);i++){
//printf("%u %c\n",memory.bytes[i],memory.bytes[i]);
printf("0x%02X,",memory.bytes[i]);
nl++;
if(nl > 7){
nl = 0;
printf("\n");
}
}
printf("\n};\n");
printf("uint16_t sserial_ptocp = 0x%04X;\n",memory.discovery.ptocp);
printf("uint16_t sserial_gtocp = 0x%04X;\n",memory.discovery.gtocp);
printf("\n");
printf("typedef struct {\n");
ptocp = (uint16_t *)(memory.bytes + memory.discovery.ptocp);
while(*ptocp != 0x0000) {
process_data_descriptor_t *pd = (process_data_descriptor_t *)(memory.bytes + *ptocp++);
//printf("0x%02X\n",pd->data_direction);
if((pd->data_direction == DATA_DIRECTION_OUTPUT || pd->data_direction == DATA_DIRECTION_BI_DIRECTIONAL) && pd->record_type == RECORD_TYPE_PROCESS_DATA_RECORD){
print_pd(pd);
}
// printf("pd has data at %x with value %x\n", pd->data_addr, MEMU16(pd->data_addr));
// printf("gtoc:%u\n",memory.discovery.gtocp);
// printf("ptoc:%u\n",memory.discovery.ptocp);
// printf("%i\n",sizeof(memory_t));
//printf("%u\n",MEMPTR(*heap_ptr));
int nl = 0;
printf("uint8_t sserial_slave[] = {\n");
for(int i = 0; i < MEMPTR(*heap_ptr); i++) {
//printf("%u %c\n",memory.bytes[i],memory.bytes[i]);
printf("0x%02X,", memory.bytes[i]);
nl++;
if(nl > 7) {
nl = 0;
printf("// %i..%i\n", i - 7, i);
}
printf("} sserial_out_process_data_t; //size:%u bytes\n",memory.discovery.output);
printf("_Static_assert(sizeof(sserial_out_process_data_t) == %u, \"sserial_out_process_data_t size error!\");\n",memory.discovery.output);
printf("\n");
printf("typedef struct {\n");
ptocp = (uint16_t *)(memory.bytes + memory.discovery.ptocp);
while(*ptocp != 0x0000) {
process_data_descriptor_t *pd = (process_data_descriptor_t *)(memory.bytes + *ptocp++);
//printf("0x%02X\n",pd->data_direction);
if((pd->data_direction == DATA_DIRECTION_INPUT || pd->data_direction == DATA_DIRECTION_BI_DIRECTIONAL) && pd->record_type == RECORD_TYPE_PROCESS_DATA_RECORD){
print_pd(pd);
}
// printf("pd has data at %x with value %x\n", pd->data_addr, MEMU16(pd->data_addr));
}
printf("\n};\n");
printf("uint16_t sserial_ptocp = 0x%04X;\n", memory.discovery.ptocp);
printf("uint16_t sserial_gtocp = 0x%04X;\n", memory.discovery.gtocp);
printf("\n");
printf("typedef struct {\n");
ptocp = (uint16_t *)(memory.bytes + memory.discovery.ptocp);
gtocp = (uint16_t *)(memory.bytes + memory.discovery.gtocp);
while(*ptocp != 0x0000) {
process_data_descriptor_t *pd = (process_data_descriptor_t *)(memory.bytes + *ptocp++);
//printf("0x%02X\n",pd->data_direction);
if((pd->data_direction == DATA_DIRECTION_OUTPUT || pd->data_direction == DATA_DIRECTION_BI_DIRECTIONAL) && pd->record_type == RECORD_TYPE_PROCESS_DATA_RECORD) {
print_pd(pd);
}
printf("} sserial_in_process_data_t; //size:%u bytes\n",memory.discovery.input-1);
printf("_Static_assert(sizeof(sserial_in_process_data_t) == %u, \"sserial_in_process_data_t size error!\");\n",memory.discovery.input-1);
// printf("pd has data at %x with value %x\n", pd->data_addr, MEMU16(pd->data_addr));
}
printf("} sserial_out_process_data_t; //size:%u bytes\n", memory.discovery.output);
printf("_Static_assert(sizeof(sserial_out_process_data_t) == %u, \"sserial_out_process_data_t size error!\");\n", memory.discovery.output);
printf("\n");
printf("typedef struct {\n");
ptocp = (uint16_t *)(memory.bytes + memory.discovery.ptocp);
while(*ptocp != 0x0000) {
process_data_descriptor_t *pd = (process_data_descriptor_t *)(memory.bytes + *ptocp++);
//printf("0x%02X\n",pd->data_direction);
if((pd->data_direction == DATA_DIRECTION_INPUT || pd->data_direction == DATA_DIRECTION_BI_DIRECTIONAL) && pd->record_type == RECORD_TYPE_PROCESS_DATA_RECORD) {
print_pd(pd);
}
// printf("pd has data at %x with value %x\n", pd->data_addr, MEMU16(pd->data_addr));
}
printf("} sserial_in_process_data_t; //size:%u bytes\n", memory.discovery.input - 1);
printf("_Static_assert(sizeof(sserial_in_process_data_t) == %u, \"sserial_in_process_data_t size error!\");\n", memory.discovery.input - 1);
gtocp = (uint16_t *)(memory.bytes + memory.discovery.gtocp);
while(*gtocp != 0x0000) {
process_data_descriptor_t *pd = (process_data_descriptor_t *)(memory.bytes + *gtocp++);
if(pd->record_type == RECORD_TYPE_PROCESS_DATA_RECORD) {
int strl = strlen(&pd->names);
char *unit = &pd->names;
char *name = &pd->names + strl + 1;
printf("//global name:%s addr:0x%x size:%i dir:0x%x\n", name, pd->data_addr, pd->data_size, pd->data_direction);
printf("#define %s_address %i\n", name, pd->data_addr);
}
}
}