Skip to content

Commit

Permalink
Merge pull request #2288 from LinuxCNC/hm2-bspi-fixes
Browse files Browse the repository at this point in the history
Hm2 bspi fixes
  • Loading branch information
jepler committed Jan 18, 2023
2 parents 8f0e6c6 + 640a6c9 commit 24b1e58
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/hal/drivers/mesa-hostmot2/bspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,20 @@ int hm2_tram_add_bspi_frame(char *name, int chan, rtapi_u32 **wbuff, rtapi_u32 *
} else {
HM2_ERR("SPI frame must have a write entry for channel (%i) on %s.\n", chan, name);
return -1;
}
}
bool will_echo = !(hm2->bspi.instance[i].cd[chan] & 0x80000000);
bool has_rbuff = rbuff != NULL;
if (will_echo != has_rbuff) {
HM2_ERR("SPI frame must have a read entry for channel (%i) on %s.\n", chan, name);
return -1;
}
if (rbuff != NULL){
// Don't add a read entry for a no-echo channel
if(!(hm2->bspi.instance[i].cd[chan] & 0x80000000)) {
r = hm2_register_tram_read_region(hm2,hm2->bspi.instance[i].addr[0], sizeof(rtapi_u32),rbuff);
if (r < 0) {
HM2_ERR( "Failed to add TRAM read entry for %s\n", name);
return -1;
}
// Reading from addr[0] instead of addr[chan] is intentional
// here - all the channels share one receive FIFO.
r = hm2_register_tram_read_region(hm2,hm2->bspi.instance[i].addr[0], sizeof(rtapi_u32),rbuff);
if (r < 0) {
HM2_ERR( "Failed to add TRAM read entry for %s\n", name);
return -1;
}
}

Expand All @@ -174,6 +179,26 @@ int hm2_allocate_bspi_tram(char* name)
return 0;
}

EXPORT_SYMBOL_GPL(hm2_bspi_clear_fifo);
int hm2_bspi_clear_fifo(char * name)
{
hostmot2_t * hm2;
int i, r;

i = hm2_get_bspi(&hm2, name);
if (i < 0){
HM2_ERR_NO_LL("Can not find BSPI instance %s.\n", name);
return -1;
}
rtapi_u32 zero = 0;
r = hm2->llio->write(hm2->llio, hm2->bspi.instance[i].count_addr, &zero, sizeof(rtapi_u32));
if (r < 0) {
HM2_ERR("BSPI: hm2->llio->write failure %s\n", name);
}

return r;
}

EXPORT_SYMBOL_GPL(hm2_bspi_write_chan);
int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val)
{
Expand Down
1 change: 1 addition & 0 deletions src/hal/drivers/mesa-hostmot2/hostmot2-serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int hm2_bspi_set_write_function(char *name, int (*func)(void *subdata), void *su
int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val);
int hm2_allocate_bspi_tram(char* name);
int hm2_tram_add_bspi_frame(char *name, int chan, rtapi_u32 **wbuff, rtapi_u32 **rbuff);
int hm2_bspi_clear_fifo(char * name);

RTAPI_END_DECLS

Expand Down
1 change: 1 addition & 0 deletions src/hal/drivers/mesa-hostmot2/hostmot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,7 @@ int hm2_sserial_read_configs(hostmot2_t *hm2, hm2_sserial_remote_t *chan);
int hm2_bspi_parse_md(hostmot2_t *hm2, int md_index);
void hm2_bspi_print_module(hostmot2_t *hm2);
void hm2_bspi_cleanup(hostmot2_t *hm2);
int hm2_bspi_clear_fifo(char * name);
void hm2_bspi_write(hostmot2_t *hm2);
void hm2_bspi_force_write(hostmot2_t *hm2);
void hm2_bspi_prepare_tram_write(hostmot2_t *hm2, long period);
Expand Down
12 changes: 12 additions & 0 deletions src/hal/drivers/mesa_7i65.comp
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,27 @@ EXTRA_SETUP(){
"quitting\n", -r);
return -EINVAL;
}

// Clear BSPI Rx & Tx FIFOs.
// This discards the received data from the ADC setup writes above,
// and any other old stale data.
r = hm2_bspi_clear_fifo(name);
if (r < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "failed to clear BSPI fifos on %s\n", name);
}

// Add BSPI Frames
// digital inputs and outputs
r += hm2_tram_add_bspi_frame(name, 4, &CPLD_write,
&CPLD_read);

// analog inputs
for(i = 0; i < 8; i++) {
r += hm2_tram_add_bspi_frame(name, 3, &AD7329_write[i],
&AD7329_read[i]);
}

// analog outputs
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1A,0);
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1B,0);
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1C,0);
Expand Down

0 comments on commit 24b1e58

Please sign in to comment.