4141#include "hostmot2-lowlevel.h"
4242#include "hostmot2.h"
4343#include "spi_common_rpspi.h"
44+ #include "eshellf.h"
45+ #include "llio_info.h"
4446
4547#define HM2_LLIO_NAME "hm2_rpspi"
4648
@@ -112,127 +114,6 @@ static uint32_t aux_enables; // Previous state of SPI1 enable
112114static hm2_rpspi_t boards [RPSPI_MAX_BOARDS ]; // Connected boards
113115static int comp_id ; // Upstream assigned component ID
114116
115- static const char * hm2_7c80_pin_names [] = {
116- "TB07-02/TB07-03" , /* Step/Dir/Misc 5V out */
117- "TB07-04/TB07-05" ,
118- "TB08-02/TB08-03" ,
119- "TB08-04/TB08-05" ,
120- "TB09-02/TB09-03" ,
121- "TB09-04/TB09-05" ,
122- "TB10-02/TB10-03" ,
123- "TB10-04/TB10-05" ,
124- "TB11-02/TB11-03" ,
125- "TB11-04/TB11-05" ,
126- "TB12-02/TB12-03" ,
127- "TB12-04/TB12-05" ,
128- "TB03-03/TB04-04" , /* RS-422/RS-485 interface */
129- "TB03-05/TB04-06" ,
130- "TB03-05/TB03-06" ,
131- "TB04-01/TB04-02" , /* Encoder */
132- "TB04-04/TB04-05" ,
133- "TB04-07/TB04-08" ,
134- "TB05-02" , /* Spindle */
135- "TB05-02" ,
136- "TB05-05/TB05-06" ,
137- "TB05-07/TB05-08" ,
138- "Internal InMux0" , /* InMux */
139- "Internal InMux1" ,
140- "Internal InMux2" ,
141- "Internal InMux3" ,
142- "Internal InMux4" ,
143-
144- "Internal InMuxData" ,
145- "TB13-01/TB13-02" , /* SSR */
146- "TB13-03/TB13-04" ,
147- "TB13-05/TB13-06" ,
148- "TB13-07/TB13-08" ,
149- "TB14-01/TB14-02" ,
150- "TB14-03/TB14-04" ,
151- "TB14-05/TB14-06" ,
152- "TB14-07/TB14-08" ,
153- "Internal SSR" ,
154- "P1-01/DB25-01" ,
155- "P1-02/DB25-14" ,
156- "P1-03/DB25-02" ,
157- "P1-04/DB25-15" ,
158- "P1-05/DB25-03" ,
159- "P1-06/DB25-16" ,
160- "P1-07/DB25-04" ,
161- "P1-08/DB25-17" ,
162- "P1-09/DB25-05" ,
163- "P1-11/DB25-06" ,
164- "P1-13/DB25-07" ,
165- "P1-15/DB25-08" ,
166- "P1-17/DB25-09" ,
167- "P1-19/DB25-10" ,
168- "P1-21/DB25-11" ,
169- "P1-23/DB25-12" ,
170- "P1-25/DB25-13" ,
171- };
172-
173- static const char * hm2_7c81_pin_names [] = {
174- "P1-01/DB25-01" ,
175- "P1-02/DB25-14" ,
176- "P1-03/DB25-02" ,
177- "P1-04/DB25-15" ,
178- "P1-05/DB25-03" ,
179- "P1-06/DB25-16" ,
180- "P1-07/DB25-04" ,
181- "P1-08/DB25-17" ,
182- "P1-09/DB25-05" ,
183- "P1-11/DB25-06" ,
184- "P1-13/DB25-07" ,
185- "P1-15/DB25-08" ,
186- "P1-17/DB25-09" ,
187- "P1-19/DB25-10" ,
188- "P1-21/DB25-11" ,
189- "P1-23/DB25-12" ,
190- "P1-25/DB25-13" ,
191- "J5-TX0" ,
192- "J6-TX1" ,
193-
194- "P2-01/DB25-01" ,
195- "P2-02/DB25-14" ,
196- "P2-03/DB25-02" ,
197- "P2-04/DB25-15" ,
198- "P2-05/DB25-03" ,
199- "P2-06/DB25-16" ,
200- "P2-07/DB25-04" ,
201- "P2-08/DB25-17" ,
202- "P2-09/DB25-05" ,
203- "P2-11/DB25-06" ,
204- "P2-13/DB25-07" ,
205- "P2-15/DB25-08" ,
206- "P2-17/DB25-09" ,
207- "P2-19/DB25-10" ,
208- "P2-21/DB25-11" ,
209- "P2-23/DB25-12" ,
210- "P2-25/DB25-13" ,
211- "J5-TXEN0" ,
212- "J6-TXEN1" ,
213-
214- "P7-01/DB25-01" ,
215- "P7-02/DB25-14" ,
216- "P7-03/DB25-02" ,
217- "P7-04/DB25-15" ,
218- "P7-05/DB25-03" ,
219- "P7-06/DB25-16" ,
220- "P7-07/DB25-04" ,
221- "P7-08/DB25-17" ,
222- "P7-09/DB25-05" ,
223- "P7-11/DB25-06" ,
224- "P7-13/DB25-07" ,
225- "P7-15/DB25-08" ,
226- "P7-17/DB25-09" ,
227- "P7-19/DB25-10" ,
228- "P7-21/DB25-11" ,
229- "P7-23/DB25-12" ,
230- "P7-25/DB25-13" ,
231- "P5-RX0" ,
232- "P6-RX1"
233- };
234-
235-
236117/*
237118 * Configuration parameters
238119 */
@@ -929,8 +810,8 @@ static uint32_t read_spiclkbase(void)
929810/*************************************************/
930811static int probe_board (hm2_rpspi_t * board ) {
931812 int32_t ret ;
932- char ident [ 8 + 1 ] ;
933- char * base ;
813+ hm2_idrom_t idrom ;
814+ const char * base ;
934815
935816#if defined(RPSPI_DEBUG_WRITE )
936817 uint32_t buf [8 ] = {0x00010203 , 0x04050607 , 0x08090a0b , 0x0c0d0e0f , 0x10111213 , 0x14151617 , 0x18191a1b , 0x1c1d1e1f };
@@ -942,53 +823,16 @@ static int probe_board(hm2_rpspi_t *board) {
942823
943824 rtapi_print_msg (RPSPI_INFO , "hm2_rpspi: SPI%d/CE%d Valid cookie matched\n" , board -> spidevid , board -> spiceid );
944825
945- // Read the board identification.
946- // The IDROM address offset is returned in the cookie check and the
947- // board_name offset is added (see hm2_idrom_t in hostmot2.h)
948- // FIXME: should we not simply read the entire IDROM here?
949- if (!board -> llio .read (& board -> llio , (uint32_t )ret + 0x000c , ident , 8 )) {
826+ // Read the IDROM from the board. The IDROM address offset was returned in
827+ // the cookie check.
828+ if (board -> llio .read (& board -> llio , (uint32_t )ret , & idrom , sizeof (hm2_idrom_t )) <= 0 ) {
950829 rtapi_print_msg (RPSPI_ERR , "hm2_rpspi: SPI%d/CE%d Board ident read failed\n" , board -> spidevid , board -> spiceid );
951830 return - EIO ; // Cookie could be read, so this is a comms error
952831 }
953- ident [sizeof (ident )- 1 ] = 0 ; // Because it may be used in printf, regardless format limits
954-
955- if (!memcmp (ident , "MESA7I90" , 8 )) {
956- base = "hm2_7i90" ;
957- board -> llio .num_ioport_connectors = 3 ;
958- board -> llio .pins_per_connector = 24 ;
959- board -> llio .ioport_connector_name [0 ] = "P1" ;
960- board -> llio .ioport_connector_name [1 ] = "P2" ;
961- board -> llio .ioport_connector_name [2 ] = "P3" ;
962- board -> llio .num_leds = 2 ;
963- board -> llio .fpga_part_number = "xc6slx9tq144" ;
964- } else if (!memcmp (ident , "MESA7C80" , 8 )){
965- base = "hm2_7c80" ;
966- board -> llio .num_ioport_connectors = 2 ;
967- board -> llio .pins_per_connector = 27 ;
968- board -> llio .ioport_connector_name [0 ] = "Embedded I/O" ;
969- board -> llio .ioport_connector_name [1 ] = "Embedded I/O + P1 expansion" ;
970- board -> llio .io_connector_pin_names = hm2_7c80_pin_names ;
971- board -> llio .num_leds = 4 ;
972- board -> llio .fpga_part_number = "xc6slx9tq144" ;
973- } else if (!memcmp (ident , "MESA7C81" , 8 )){
974- base = "hm2_7c81" ;
975- board -> llio .num_ioport_connectors = 3 ;
976- board -> llio .pins_per_connector = 19 ;
977- board -> llio .ioport_connector_name [0 ] = "P1" ;
978- board -> llio .ioport_connector_name [1 ] = "P2" ;
979- board -> llio .ioport_connector_name [2 ] = "P7" ;
980- board -> llio .io_connector_pin_names = hm2_7c81_pin_names ;
981- board -> llio .num_leds = 4 ;
982- board -> llio .fpga_part_number = "xc6slx9tq144" ;
983- } else {
984- int i ;
985- for (i = 0 ; i < sizeof (ident ) - 1 ; i ++ ) {
986- if (!isprint (ident [i ]))
987- ident [i ] = '?' ;
988- }
989- rtapi_print_msg (RPSPI_ERR , "hm2_rpspi: Unknown board at SPI%d/CE%d: %.8s\n" , board -> spidevid , board -> spiceid , ident );
990- return -1 ;
991- }
832+
833+ // Detect board name and fill in informational values
834+ if (!(base = set_llio_info_spi (& board -> llio , & idrom )))
835+ return - ENOENT ;
992836
993837 rtapi_print_msg (RPSPI_INFO , "hm2_rpspi: SPI%d/CE%d Base: %s.%d\n" , board -> spidevid , board -> spiceid , base , board -> nr );
994838 rtapi_snprintf (board -> llio .name , sizeof (board -> llio .name ), "%s.%d" , base , board -> nr );
@@ -1421,49 +1265,22 @@ static int hm2_rpspi_setup(void)
14211265 return j > 0 ? 0 : - ENODEV ;
14221266}
14231267
1424- static int shell (char * command ) {
1425- char * const argv [] = {"sh" , "-c" , command , NULL };
1426- pid_t pid ;
1427- int res = rtapi_spawn_as_root (& pid , "/bin/sh" , NULL , NULL , argv , environ );
1428- if (res < 0 ) perror ("rtapi_spawn_as_root" );
1429- int status ;
1430- waitpid (pid , & status , 0 );
1431- if (WIFEXITED (status )) return WEXITSTATUS (status );
1432- else if (WIFSTOPPED (status )) return WTERMSIG (status )+ 128 ;
1433- else return status ;
1434- }
1435-
1436- static int eshellf (char * fmt , ...) {
1437- char commandbuf [1024 ];
1438- va_list ap ;
1439- va_start (ap , fmt );
1440- vsnprintf (commandbuf , sizeof (commandbuf ), fmt , ap );
1441- va_end (ap );
1442-
1443- int res = shell (commandbuf );
1444- if (res == EXIT_SUCCESS ) return 0 ;
1445-
1446- LL_PRINT ("ERROR: Failed to execute '%s'\n" , commandbuf );
1447- return - EINVAL ;
1448- }
1449-
1450-
14511268/*************************************************/
14521269static void hm2_rpspi_cleanup (void )
14531270{
14541271 if ((void * )peripheralmem != MAP_FAILED ) {
14551272 peripheral_restore ();
14561273 munmap (peripheralmem , peripheralsize );
14571274 }
1458- eshellf ("/sbin/modprobe spi-bcm2835" );
1275+ eshellf (HM2_LLIO_NAME , "/sbin/modprobe spi-bcm2835" );
14591276}
14601277
14611278/*************************************************/
14621279int rtapi_app_main ()
14631280{
14641281 int ret ;
14651282
1466- eshellf ("/sbin/rmmod spi_bcm2835" );
1283+ eshellf (HM2_LLIO_NAME , "/sbin/rmmod spi_bcm2835" );
14671284
14681285 if ((comp_id = ret = hal_init ("hm2_rpspi" )) < 0 )
14691286 goto fail ;
0 commit comments