summaryrefslogtreecommitdiff
path: root/src/hal/drivers/mesa-hostmot2/hm2_test.c
blob: 903b34b622b7046dded8007962884238a9af8660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

//
//    Copyright (C) 2007-2008 Sebastian Kuzminsky
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
//


//
//  This driver behaves like a HostMot2 "low-level I/O" driver, but
//  provides unchanging, compiled-in, information.  It runs without any
//  special hardware plugged in.  Its job is to provide a test-pattern to
//  verify that the hostmot2 driver functions as it ought.
//


#include <linux/pci.h>

#include "rtapi.h"
#include "rtapi_app.h"
#include "rtapi_string.h"

#include "hal.h"

#include "hostmot2.h"
#include "hostmot2-lowlevel.h"
#include "hm2_test.h"


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sebastian Kuzminsky");
MODULE_DESCRIPTION("Test pattern for the hostmot2 driver, does not talk to any hardware");


static char *config[HM2_TEST_MAX_BOARDS];
static int num_config_strings = HM2_TEST_MAX_BOARDS;
module_param_array(config, charp, &num_config_strings, S_IRUGO);
MODULE_PARM_DESC(config, "config string for the AnyIO boards (see hostmot2(9) manpage)");


int test_pattern = 0;
RTAPI_MP_INT(test_pattern, "The test pattern to show to the hostmot2 driver.");


static int comp_id;

static hm2_test_t board[1];




// 
// these are the "low-level I/O" functions exported up
//


static int hm2_test_read(hm2_lowlevel_io_t *this, u32 addr, void *buffer, int size) {
    hm2_test_t *me = this->private;
    memcpy(buffer, (me->test_pattern + addr), size);
    return 1;  // success
}


static int hm2_test_write(hm2_lowlevel_io_t *this, u32 addr, void *buffer, int size) {
    return 1;  // success
}


static int hm2_test_program_fpga(hm2_lowlevel_io_t *this, const bitfile_t *bitfile) {
    return 0;
}


static int hm2_test_reset(hm2_lowlevel_io_t *this) {
    return 0;
}




int rtapi_app_main(void) {
    hm2_test_t *me;
    hm2_lowlevel_io_t *this;
    int r = 0;

    LL_PRINT("loading HostMot2 test driver with test pattern %d\n", test_pattern);

    comp_id = hal_init(HM2_LLIO_NAME);
    if (comp_id < 0) return comp_id;

    me = &board[0];

    this = &me->llio;
    memset(this, 0, sizeof(hm2_lowlevel_io_t));

    me->llio.num_ioport_connectors = 1;
    me->llio.pins_per_connector = 24;
    me->llio.ioport_connector_name[0] = "P99";

    switch (test_pattern) {

        // 
        // this one has nothing
        // 

        case 0: {
            break;
        }


        // 
        // this one has a good IO Cookie, but that's it
        // 

        case 1: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe
            break;
        }


        // 
        // this one has a good IO Cookie and Config Name
        // the idrom offset is 0, and there's nothing there
        // 

        case 2: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's an invalid IDROM type there
        // 

        case 3: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // bad idrom type
            *((u32*)&me->test_pattern[0x400]) = 0x1234;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // but the portwidth is 0
        // 

        case 4: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // but the portwidth is 29 which is bogus
        // 

        case 5: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // bad PortWidth
            *((u32*)&me->test_pattern[0x424]) = 29;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth
        // 

        case 6: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // good PortWidth
            *((u32*)&me->test_pattern[0x424]) = 24;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, but problematic IOPorts and IOWidth
        // 

        case 7: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // good PortWidth = 24, which is stadard
            *((u32*)&me->test_pattern[0x424]) = 24;

            // IOPorts = 1
            *((u32*)&me->test_pattern[0x41c]) = 1;

            // IOWidth = 99 (!= IOPorts * PortWidth)
            *((u32*)&me->test_pattern[0x420]) = 99;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, but IOPorts doesnt match what the llio said
        // 

        case 8: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // good PortWidth = 24, which is stadard
            *((u32*)&me->test_pattern[0x424]) = 24;

            // IOPorts = 2 (!= what the llio said)
            *((u32*)&me->test_pattern[0x41c]) = 2;

            // IOWidth == IOPorts * PortWidth)
            *((u32*)&me->test_pattern[0x420]) = 48;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, IOPorts, and IOWidth
        // but the clocks are bad
        // 

        case 9: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // IOWidth = (IOPorts * PortWidth)
            *((u32*)&me->test_pattern[0x424]) = 24;
            *((u32*)&me->test_pattern[0x41c]) = 1;
            *((u32*)&me->test_pattern[0x420]) = 24;

            // ClockLow = 12345
            *((u32*)&me->test_pattern[0x428]) = 12345;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, IOPorts, and IOWidth
        // but the clocks are bad
        // 

        case 10: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // IOWidth = (IOPorts * PortWidth)
            *((u32*)&me->test_pattern[0x424]) = 24;
            *((u32*)&me->test_pattern[0x41c]) = 1;
            *((u32*)&me->test_pattern[0x420]) = 24;

            // ClockLow = 2e6
            *((u32*)&me->test_pattern[0x428]) = 2e6;

            // ClockHigh = 0
            *((u32*)&me->test_pattern[0x42c]) = 0;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, IOPorts, IOWidth, and clocks
        // 
        // The problem with this register file is that the Pin Descriptor
        // array contains no valid PDs, though the IDROM advertised 144 pins.
        //

        case 11: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // normal offset to Module Descriptors
            *((u32*)&me->test_pattern[0x404]) = 64;

            // unusual offset to PinDescriptors
            *((u32*)&me->test_pattern[0x408]) = 0x1C0;

            // board name (8 bytes, not NULL terminated)
            me->test_pattern[0x40c] = 'T';
            me->test_pattern[0x40d] = 'E';
            me->test_pattern[0x40e] = 'S';
            me->test_pattern[0x40f] = 'T';
            me->test_pattern[0x410] = 'I';
            me->test_pattern[0x411] = 'N';
            me->test_pattern[0x412] = 'G';
            me->test_pattern[0x413] = ' ';

            // IOPorts
            *((u32*)&me->test_pattern[0x41c]) = 6;

            // IOWidth
            *((u32*)&me->test_pattern[0x420]) = 6*24;

            // PortWidth
            *((u32*)&me->test_pattern[0x424]) = 24;

            // ClockLow = 2e6
            *((u32*)&me->test_pattern[0x428]) = 2e6;

            // ClockHigh = 2e7
            *((u32*)&me->test_pattern[0x42c]) = 2e7;

            me->llio.num_ioport_connectors = 6;
            me->llio.ioport_connector_name[0] = "P4";
            me->llio.ioport_connector_name[1] = "P5";
            me->llio.ioport_connector_name[2] = "P6";
            me->llio.ioport_connector_name[3] = "P9";
            me->llio.ioport_connector_name[4] = "P8";
            me->llio.ioport_connector_name[5] = "P7";

            break;
        }



        //
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good PortWidth, IOWidth, and clocks
        // but there are no IOPorts instances according to the MDs
        // (this is the case with a firmware Jeff made for testing an RNG circuit)
        //

        case 12: {
            int num_io_pins = 24;
            int pd_index;

            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // normal offset to Module Descriptors
            *((u32*)&me->test_pattern[0x404]) = 64;

            // normal offset to PinDescriptors
            *((u32*)&me->test_pattern[0x408]) = 0x200;

            // board name (8 bytes, not NULL terminated)
            me->test_pattern[0x40c] = 'T';
            me->test_pattern[0x40d] = 'E';
            me->test_pattern[0x40e] = 'S';
            me->test_pattern[0x40f] = 'T';
            me->test_pattern[0x410] = 'I';
            me->test_pattern[0x411] = 'N';
            me->test_pattern[0x412] = 'G';
            me->test_pattern[0x413] = ' ';

            // IOPorts
            *((u32*)&me->test_pattern[0x41c]) = 1;

            // IOWidth
            *((u32*)&me->test_pattern[0x420]) = num_io_pins;

            // PortWidth
            *((u32*)&me->test_pattern[0x424]) = 24;

            // ClockLow = 2e6
            *((u32*)&me->test_pattern[0x428]) = 2e6;

            // ClockHigh = 2e7
            *((u32*)&me->test_pattern[0x42c]) = 2e7;

            me->llio.num_ioport_connectors = 1;
            me->llio.ioport_connector_name[0] = "P3";

            // make a bunch of valid Pin Descriptors
            for (pd_index = 0; pd_index < num_io_pins; pd_index ++) {
                me->test_pattern[0x600 + (pd_index * 4) + 0] = 0;               // SecPin (byte) = Which pin of secondary function connects here eg: A,B,IDX.  Output pins have bit 7 = '1'
                me->test_pattern[0x600 + (pd_index * 4) + 1] = 0;               // SecTag (byte) = Secondary function type (PWM,QCTR etc).  Same as module GTag
                me->test_pattern[0x600 + (pd_index * 4) + 2] = 0;               // SecUnit (byte) = Which secondary unit or channel connects here
                me->test_pattern[0x600 + (pd_index * 4) + 3] = HM2_GTAG_IOPORT; // PrimaryTag (byte) = Primary function tag (normally I/O port)
            }

            break;
        }


        // this board has a non-standard (ie, non-24) number of pins per connector, but the idrom does not match that
        case 13: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // default PortWidth
            *((u32*)&me->test_pattern[0x424]) = 24;

            // unusual number of pins per connector
            me->llio.pins_per_connector = 5;

            break;
        }


        // 
        // good IO Cookie, Config Name, and IDROM Type
        // the IDROM offset is the usual, 0x400, and there's a good IDROM type there
        // good but unusual (non-24) PortWidth
        // 

        case 14: {
            *((u32*)&me->test_pattern[HM2_ADDR_IOCOOKIE]) = HM2_IOCOOKIE;  // 0x55aacafe

            me->test_pattern[HM2_ADDR_CONFIGNAME+0] = 'H';
            me->test_pattern[HM2_ADDR_CONFIGNAME+1] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+2] = 'S';
            me->test_pattern[HM2_ADDR_CONFIGNAME+3] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+4] = 'M';
            me->test_pattern[HM2_ADDR_CONFIGNAME+5] = 'O';
            me->test_pattern[HM2_ADDR_CONFIGNAME+6] = 'T';
            me->test_pattern[HM2_ADDR_CONFIGNAME+7] = '2';

            // put the IDROM at 0x400, where it usually lives
            *((u32*)&me->test_pattern[HM2_ADDR_IDROM_OFFSET]) = 0x400;

            // standard idrom type
            *((u32*)&me->test_pattern[0x400]) = 2;

            // good but unusual PortWidth
            *((u32*)&me->test_pattern[0x424]) = 37;
            me->llio.pins_per_connector = 37;

            break;
        }


        default: {
            LL_ERR("unknown test pattern %d", test_pattern); 
            return -ENODEV;
        }
    }


    rtapi_snprintf(me->llio.name, sizeof(me->llio.name), "hm2_test.0");

    me->llio.fpga_part_number = "none";

    me->llio.program_fpga = hm2_test_program_fpga;
    me->llio.reset = hm2_test_reset;

    me->llio.comp_id = comp_id;
    me->llio.private = me;

    me->llio.threadsafe = 1;

    me->llio.read = hm2_test_read;
    me->llio.write = hm2_test_write;

    r = hm2_register(&board->llio, config[0]);
    if (r != 0) {
        THIS_ERR("hm2_test fails HM2 registration\n");
        return -EIO;
    }

    THIS_PRINT("initialized hm2 test-pattern %d\n", test_pattern);

    hal_ready(comp_id);
    return 0;
}


void rtapi_app_exit(void) {
    hm2_test_t *me = &board[0];

    hm2_unregister(&me->llio);

    LL_PRINT("driver unloaded\n");
    hal_exit(comp_id);
}