Skip to content

Commit 24b1e58

Browse files
authored
Merge pull request #2288 from LinuxCNC/hm2-bspi-fixes
Hm2 bspi fixes
2 parents 8f0e6c6 + 640a6c9 commit 24b1e58

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

src/hal/drivers/mesa-hostmot2/bspi.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,20 @@ int hm2_tram_add_bspi_frame(char *name, int chan, rtapi_u32 **wbuff, rtapi_u32 *
140140
} else {
141141
HM2_ERR("SPI frame must have a write entry for channel (%i) on %s.\n", chan, name);
142142
return -1;
143-
}
143+
}
144+
bool will_echo = !(hm2->bspi.instance[i].cd[chan] & 0x80000000);
145+
bool has_rbuff = rbuff != NULL;
146+
if (will_echo != has_rbuff) {
147+
HM2_ERR("SPI frame must have a read entry for channel (%i) on %s.\n", chan, name);
148+
return -1;
149+
}
144150
if (rbuff != NULL){
145-
// Don't add a read entry for a no-echo channel
146-
if(!(hm2->bspi.instance[i].cd[chan] & 0x80000000)) {
147-
r = hm2_register_tram_read_region(hm2,hm2->bspi.instance[i].addr[0], sizeof(rtapi_u32),rbuff);
148-
if (r < 0) {
149-
HM2_ERR( "Failed to add TRAM read entry for %s\n", name);
150-
return -1;
151-
}
151+
// Reading from addr[0] instead of addr[chan] is intentional
152+
// here - all the channels share one receive FIFO.
153+
r = hm2_register_tram_read_region(hm2,hm2->bspi.instance[i].addr[0], sizeof(rtapi_u32),rbuff);
154+
if (r < 0) {
155+
HM2_ERR( "Failed to add TRAM read entry for %s\n", name);
156+
return -1;
152157
}
153158
}
154159

@@ -174,6 +179,26 @@ int hm2_allocate_bspi_tram(char* name)
174179
return 0;
175180
}
176181

182+
EXPORT_SYMBOL_GPL(hm2_bspi_clear_fifo);
183+
int hm2_bspi_clear_fifo(char * name)
184+
{
185+
hostmot2_t * hm2;
186+
int i, r;
187+
188+
i = hm2_get_bspi(&hm2, name);
189+
if (i < 0){
190+
HM2_ERR_NO_LL("Can not find BSPI instance %s.\n", name);
191+
return -1;
192+
}
193+
rtapi_u32 zero = 0;
194+
r = hm2->llio->write(hm2->llio, hm2->bspi.instance[i].count_addr, &zero, sizeof(rtapi_u32));
195+
if (r < 0) {
196+
HM2_ERR("BSPI: hm2->llio->write failure %s\n", name);
197+
}
198+
199+
return r;
200+
}
201+
177202
EXPORT_SYMBOL_GPL(hm2_bspi_write_chan);
178203
int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val)
179204
{

src/hal/drivers/mesa-hostmot2/hostmot2-serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int hm2_bspi_set_write_function(char *name, int (*func)(void *subdata), void *su
3939
int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val);
4040
int hm2_allocate_bspi_tram(char* name);
4141
int hm2_tram_add_bspi_frame(char *name, int chan, rtapi_u32 **wbuff, rtapi_u32 **rbuff);
42+
int hm2_bspi_clear_fifo(char * name);
4243

4344
RTAPI_END_DECLS
4445

src/hal/drivers/mesa-hostmot2/hostmot2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ int hm2_sserial_read_configs(hostmot2_t *hm2, hm2_sserial_remote_t *chan);
17191719
int hm2_bspi_parse_md(hostmot2_t *hm2, int md_index);
17201720
void hm2_bspi_print_module(hostmot2_t *hm2);
17211721
void hm2_bspi_cleanup(hostmot2_t *hm2);
1722+
int hm2_bspi_clear_fifo(char * name);
17221723
void hm2_bspi_write(hostmot2_t *hm2);
17231724
void hm2_bspi_force_write(hostmot2_t *hm2);
17241725
void hm2_bspi_prepare_tram_write(hostmot2_t *hm2, long period);

src/hal/drivers/mesa_7i65.comp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,27 @@ EXTRA_SETUP(){
206206
"quitting\n", -r);
207207
return -EINVAL;
208208
}
209+
210+
// Clear BSPI Rx & Tx FIFOs.
211+
// This discards the received data from the ADC setup writes above,
212+
// and any other old stale data.
213+
r = hm2_bspi_clear_fifo(name);
214+
if (r < 0) {
215+
rtapi_print_msg(RTAPI_MSG_ERR, "failed to clear BSPI fifos on %s\n", name);
216+
}
217+
209218
// Add BSPI Frames
219+
// digital inputs and outputs
210220
r += hm2_tram_add_bspi_frame(name, 4, &CPLD_write,
211221
&CPLD_read);
212222

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

229+
// analog outputs
218230
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1A,0);
219231
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1B,0);
220232
r += hm2_tram_add_bspi_frame(name, 1, &AD5754_1C,0);

0 commit comments

Comments
 (0)