@@ -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+
177202EXPORT_SYMBOL_GPL (hm2_bspi_write_chan );
178203int hm2_bspi_write_chan (char * name , int chan , rtapi_u32 val )
179204{
0 commit comments