Skip to content

Commit c147f05

Browse files
committed
hostmot2 bspi: add hm2_bspi_clear_fifo()
The BSPI module has a receive fifo and a transmit fifo per instance (shared among all the channels of that instance). Writing anything to the fifo count register clears both fifos, discarding any old read data and any pending write data.
1 parent 46ac11c commit c147f05

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ int hm2_allocate_bspi_tram(char* name)
179179
return 0;
180180
}
181181

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+
182202
EXPORT_SYMBOL_GPL(hm2_bspi_write_chan);
183203
int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val)
184204
{

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);

0 commit comments

Comments
 (0)