wjasper / Linux_Drivers

Open source Linux device drivers
GNU General Public License v3.0
111 stars 64 forks source link

USBCTR zero padding not working #34

Closed MarkRivers closed 5 years ago

MarkRivers commented 5 years ago

I have enhanced my driver to allowing reading the DIO port when scanning. In 16-bit counter mode this works fine. In 32-bit counter mode I add a scan list element with bit 6 set to get a 16-bit 0 word in the stream. This does put a word in the stream but it is not 0, it is the counters in bank0 of counter0.

Have you tested this?

I have also tried it with the Windows UL, and it is also not working, so I suspect it may be a firmware problem. I am running the latest 0.12 firmware and the latest UL library (6.7).

I can work around the problem by setting those bits to 0 in my read poller, but it would be nice if the device did it correctly.

wjasper commented 5 years ago

Yes, I see what you mean. i updated my test-usb-ctr code with the 'i' option to test out this case. Use the 'd' option to set the dio-latch value then the 'i' value to read the scan. The DIO value gets repeated 2 times and the last one is filled with zeros.

MarkRivers commented 5 years ago

The new version of usb-ctr.h contains this:

#define USB_CTR_SCAN_DIO           (0x10)
#define USB_CTR_ZERO_FILL          (0x20)

However, the comments in usbScanConfigR_USB_CTR say this:

    ScanList[33] channel configuration:
      bit(0-2): Counter Nuber (0-7)
      bit(3-4): Counter Bank (0-3)
      bit(5): 1 = DIO,  0 = Counter
      bit(6): 1 = Fill with 16-bits of 0's,  0 = normal (This allows for the creation
      of a 32 or 64-bit element of the DIO when it is mixed with 32 or 64-bit elements of counters)

Bit 5 is actually 0x20 (bit 4 is 0x10) and bit 6 is 0x40, so I think the header file should be:

#define USB_CTR_SCAN_DIO           (0x20)
#define USB_CTR_ZERO_FILL          (0x40)
wjasper commented 5 years ago

Hi Mark, Yes, good call. I changed the name also to USB_CTR_PADZERO. It works correctly now , see the "i" option. Here is the deal. When bit 5 is set (USB_CTR_SCAN_DIO), the device will return the lower byte of the latched value of the DIO. The way to set the latched value is to write to the DIO.
To test this out using my test-usb-ctr program, use the "d" option to write a value to the DIO, then hit "n" when asked to continue. Then run the "i" option, which reads from counters 0-3 and also the DIO plus 6 bytes of padded zeros to make another 96 bits of data. When either bit 5 or 6 is set in the scan list, it ignores the counter number and the counter bank (bits 0-4). If bit 5 is set, it reads from the DIO and returns a 16 bit word with the lower 8 bits from the latched value of the DIO. If bit 6 is set, it returns 0x0 in a 16 bit WORD.

MarkRivers commented 5 years ago

Then run the "i" option, which reads from counters 0-3 and also the DIO plus 6 bytes of padded zeros to make another 96 bits of data. When either bit 5 or 6 is set in the scan list, it ignores the counter number and the counter bank (bits 0-4). If bit 5 is set, it reads from the DIO and returns a 16 bit word with the lower 8 bits from the latched value of the DIO. If bit 6 is set, it returns 0x0 in a 16 bit WORD.

That's the way it is supposed to work, but it does not. It is easy to prove. I just downloaded and ran your "i" test unmodified. Note that I have a 1 MHz pulse train going into counter 0.

This is the output I see


Connect Timer 1 to Counter 1
Scan: 0     0   0   0   0       0x80 0 0 0
Scan: 1     1000   0   0   0       0x80 0x3e8 0x3e8 0x3e8
Scan: 2     2000   0   0   0       0x80 0x7d0 0x7d0 0x7d0
Scan: 3     3000   0   0   0       0x80 0xbb8 0xbb8 0xbb8
Scan: 4     4000   0   0   0       0x80 0xfa0 0xfa0 0xfa0
Scan: 5     5000   0   0   0       0x80 0x1388 0x1388 0x1388
Scan: 6     6000   0   0   0       0x80 0x1770 0x1770 0x1770
Scan: 7     7000   0   0   0       0x80 0x1b58 0x1b58 0x1b58
Scan: 8     8000   0   0   0       0x80 0x1f40 0x1f40 0x1f40
Scan: 9     9000   0   0   0       0x80 0x2328 0x2328 0x2328
Scan: 10     10000   0   0   0       0x80 0x2710 0x2710 0x2710
Scan: 11     11000   0   0   0       0x80 0x2af8 0x2af8 0x2af8
Scan: 12     12000   0   0   0       0x80 0x2ee0 0x2ee0 0x2ee0
Scan: 13     13000   0   0   0       0x80 0x32c8 0x32c8 0x32c8
Scan: 14     14000   0   0   0       0x80 0x36b0 0x36b0 0x36b0
Scan: 15     15000   0   0   0       0x80 0x3a98 0x3a98 0x3a98
Scan: 16     16000   0   0   0       0x80 0x3e80 0x3e80 0x3e80
Scan: 17     17000   0   0   0       0x80 0x4268 0x4268 0x4268
Scan: 18     18000   0   0   0       0x80 0x4650 0x4650 0x4650
Scan: 19     19000   0   0   0       0x80 0x4a38 0x4a38 0x4a38
Scan: 20     20000   0   0   0       0x80 0x4e20 0x4e20 0x4e20
Scan: 21     21000   0   0   0       0x80 0x5208 0x5208 0x5208
Scan: 22     22000   0   0   0       0x80 0x55f0 0x55f0 0x55f0
Scan: 23     23000   0   0   0       0x80 0x59d8 0x59d8 0x59d8
Scan: 24     24000   0   0   0       0x80 0x5dc0 0x5dc0 0x5dc0
Scan: 25     25000   0   0   0       0x80 0x61a8 0x61a8 0x61a8
Scan: 26     26000   0   0   0       0x80 0x6590 0x6590 0x6590
Scan: 27     27000   0   0   0       0x80 0x6978 0x6978 0x6978
Scan: 28     28000   0   0   0       0x80 0x6d60 0x6d60 0x6d60
Scan: 29     29000   0   0   0       0x80 0x7148 0x7148 0x7148
Scan: 30     30000   0   0   0       0x80 0x7530 0x7530 0x7530
Scan: 31     31000   0   0   0       0x80 0x7918 0x7918 0x7918
Scan: 32     32000   0   0   0       0x80 0x7d00 0x7d00 0x7d00
Scan: 33     33000   0   0   0       0x80 0x80e8 0x80e8 0x80e8
Scan: 34     34000   0   0   0       0x80 0x84d0 0x84d0 0x84d0
Scan: 35     35000   0   0   0       0x80 0x88b8 0x88b8 0x88b8
Scan: 36     36000   0   0   0       0x80 0x8ca0 0x8ca0 0x8ca0
Scan: 37     37000   0   0   0       0x80 0x9088 0x9088 0x9088
Scan: 38     38000   0   0   0       0x80 0x9470 0x9470 0x9470
Scan: 39     39000   0   0   0       0x80 0x9858 0x9858 0x9858
Scan: 40     40000   0   0   0       0x80 0x9c40 0x9c40 0x9c40
Scan: 41     41000   0   0   0       0x80 0xa028 0xa028 0xa028
Scan: 42     42000   0   0   0       0x80 0xa410 0xa410 0xa410
Scan: 43     43000   0   0   0       0x80 0xa7f8 0xa7f8 0xa7f8
Scan: 44     44000   0   0   0       0x80 0xabe0 0xabe0 0xabe0
Scan: 45     45000   0   0   0       0x80 0xafc8 0xafc8 0xafc8
Scan: 46     46000   0   0   0       0x80 0xb3b0 0xb3b0 0xb3b0
Scan: 47     47000   0   0   0       0x80 0xb798 0xb798 0xb798
Scan: 48     48000   0   0   0       0x80 0xbb80 0xbb80 0xbb80
Scan: 49     49000   0   0   0       0x80 0xbf68 0xbf68 0xbf68
Scan: 50     50000   0   0   0       0x80 0xc350 0xc350 0xc350
Scan: 51     51000   0   0   0       0x80 0xc738 0xc738 0xc738
Scan: 52     52000   0   0   0       0x80 0xcb20 0xcb20 0xcb20
Scan: 53     53000   0   0   0       0x80 0xcf08 0xcf08 0xcf08
Scan: 54     54000   0   0   0       0x80 0xd2f0 0xd2f0 0xd2f0
Scan: 55     55000   0   0   0       0x80 0xd6d8 0xd6d8 0xd6d8
Scan: 56     56000   0   0   0       0x80 0xdac0 0xdac0 0xdac0
Scan: 57     57000   0   0   0       0x80 0xdea8 0xdea8 0xdea8
Scan: 58     58000   0   0   0       0x80 0xe290 0xe290 0xe290
Scan: 59     59000   0   0   0       0x80 0xe678 0xe678 0xe678
Scan: 60     60000   0   0   0       0x80 0xea60 0xea60 0xea60
Scan: 61     61000   0   0   0       0x80 0xee48 0xee48 0xee48
Scan: 62     62000   0   0   0       0x80 0xf230 0xf230 0xf230
Scan: 63     63000   0   0   0       0x80 0xf618 0xf618 0xf618
Scan: 64     64000   0   0   0       0x80 0xfa00 0xfa00 0xfa00
Scan: 65     65000   0   0   0       0x80 0xfde8 0xfde8 0xfde8
Scan: 66     66000   0   0   0       0x80 0x1d0 0x1d0 0x1d0
Scan: 67     67000   0   0   0       0x80 0x5b8 0x5b8 0x5b8
Scan: 68     68000   0   0   0       0x80 0x9a0 0x9a0 0x9a0
Scan: 69     69000   0   0   0       0x80 0xd88 0xd88 0xd88
Scan: 70     70000   0   0   0       0x80 0x1170 0x1170 0x1170
Scan: 71     71000   0   0   0       0x80 0x1558 0x1558 0x1558
Scan: 72     72000   0   0   0       0x80 0x1940 0x1940 0x1940
Scan: 73     73000   0   0   0       0x80 0x1d28 0x1d28 0x1d28
Scan: 74     74000   0   0   0       0x80 0x2110 0x2110 0x2110
Scan: 75     75000   0   0   0       0x80 0x24f8 0x24f8 0x24f8
Scan: 76     76000   0   0   0       0x80 0x28e0 0x28e0 0x28e0
Scan: 77     77000   0   0   0       0x80 0x2cc8 0x2cc8 0x2cc8
Scan: 78     78000   0   0   0       0x80 0x30b0 0x30b0 0x30b0
Scan: 79     79000   0   0   0       0x80 0x3498 0x3498 0x3498
Scan: 80     80000   0   0   0       0x80 0x3880 0x3880 0x3880
Scan: 81     81000   0   0   0       0x80 0x3c68 0x3c68 0x3c68
Scan: 82     82000   0   0   0       0x80 0x4050 0x4050 0x4050
Scan: 83     83000   0   0   0       0x80 0x4438 0x4438 0x4438
Scan: 84     84000   0   0   0       0x80 0x4820 0x4820 0x4820
Scan: 85     85000   0   0   0       0x80 0x4c08 0x4c08 0x4c08
Scan: 86     86000   0   0   0       0x80 0x4ff0 0x4ff0 0x4ff0
Scan: 87     87000   0   0   0       0x80 0x53d8 0x53d8 0x53d8
Scan: 88     88000   0   0   0       0x80 0x57c0 0x57c0 0x57c0
Scan: 89     89000   0   0   0       0x80 0x5ba8 0x5ba8 0x5ba8
Scan: 90     90000   0   0   0       0x80 0x5f90 0x5f90 0x5f90
Scan: 91     91000   0   0   0       0x80 0x6378 0x6378 0x6378
Scan: 92     92000   0   0   0       0x80 0x6760 0x6760 0x6760
Scan: 93     93000   0   0   0       0x80 0x6b48 0x6b48 0x6b48
Scan: 94     94000   0   0   0       0x80 0x6f30 0x6f30 0x6f30
Scan: 95     95000   0   0   0       0x80 0x7318 0x7318 0x7318
Scan: 96     96000   0   0   0       0x80 0x7700 0x7700 0x7700
Scan: 97     97000   0   0   0       0x80 0x7ae8 0x7ae8 0x7ae8
Scan: 98     98000   0   0   0       0x80 0x7ed0 0x7ed0 0x7ed0
Scan: 99     99000   0   0   0       0x80 0x82b8 0x82b8 0x82b8

Note that the last 4 words are not 0. For Scan 50 all 4 words are 0xc350, which is 50000, which is the value of counter 0 bank 0. So the 3 words at the end that should be 0 are in fact the value of counter 0 bank 0.

My conclusion is that bit 6 is having no effect. If you change this line: scanData.scanList[counter*numBanks+3] = USB_CTR_PADZERO;

to this: scanData.scanList[counter*numBanks+3] = USB_CTR_PADZERO | 1;

then that element will have the counts for counter 1 bank 0.

MCC tech support has acknowledged this problem. They are looking at a solution.

wjasper commented 5 years ago

OK, yes I see now.  I had 0x0 for counter 0 which was why I did not see it.

On 10/1/19 12:49 PM, Mark Rivers wrote:

Then run the "i" option, which reads from counters 0-3 and also
the DIO plus 6 bytes of padded zeros to make another 96 bits of
data. When either bit 5 or 6 is set in the scan list, it ignores
the counter number and the counter bank (bits 0-4). If bit 5 is
set, it reads from the DIO and returns a 16 bit word with the
lower 8 bits from the latched value of the DIO. If bit 6 is set,
it returns 0x0 in a 16 bit WORD.

That's the way it is supposed to work, but it does not. It is easy to prove. I just downloaded and ran your "i" test unmodified. Note that I have a 1 MHz pulse train going into counter 0.

This is the output I see

|Connect Timer 1 to Counter 1 Scan: 0 0 0 0 0 0x80 0 0 0 Scan: 1 1000 0 0 0 0x80 0x3e8 0x3e8 0x3e8 Scan: 2 2000 0 0 0 0x80 0x7d0 0x7d0 0x7d0 Scan: 3 3000 0 0 0 0x80 0xbb8 0xbb8 0xbb8 Scan: 4 4000 0 0 0 0x80 0xfa0 0xfa0 0xfa0 Scan: 5 5000 0 0 0 0x80 0x1388 0x1388 0x1388 Scan: 6 6000 0 0 0 0x80 0x1770 0x1770 0x1770 Scan: 7 7000 0 0 0 0x80 0x1b58 0x1b58 0x1b58 Scan: 8 8000 0 0 0 0x80 0x1f40 0x1f40 0x1f40 Scan: 9 9000 0 0 0 0x80 0x2328 0x2328 0x2328 Scan: 10 10000 0 0 0 0x80 0x2710 0x2710 0x2710 Scan: 11 11000 0 0 0 0x80 0x2af8 0x2af8 0x2af8 Scan: 12 12000 0 0 0 0x80 0x2ee0 0x2ee0 0x2ee0 Scan: 13 13000 0 0 0 0x80 0x32c8 0x32c8 0x32c8 Scan: 14 14000 0 0 0 0x80 0x36b0 0x36b0 0x36b0 Scan: 15 15000 0 0 0 0x80 0x3a98 0x3a98 0x3a98 Scan: 16 16000 0 0 0 0x80 0x3e80 0x3e80 0x3e80 Scan: 17 17000 0 0 0 0x80 0x4268 0x4268 0x4268 Scan: 18 18000 0 0 0 0x80 0x4650 0x4650 0x4650 Scan: 19 19000 0 0 0 0x80 0x4a38 0x4a38 0x4a38 Scan: 20 20000 0 0 0 0x80 0x4e20 0x4e20 0x4e20 Scan: 21 21000 0 0 0 0x80 0x5208 0x5208 0x5208 Scan: 22 22000 0 0 0 0x80 0x55f0 0x55f0 0x55f0 Scan: 23 23000 0 0 0 0x80 0x59d8 0x59d8 0x59d8 Scan: 24 24000 0 0 0 0x80 0x5dc0 0x5dc0 0x5dc0 Scan: 25 25000 0 0 0 0x80 0x61a8 0x61a8 0x61a8 Scan: 26 26000 0 0 0 0x80 0x6590 0x6590 0x6590 Scan: 27 27000 0 0 0 0x80 0x6978 0x6978 0x6978 Scan: 28 28000 0 0 0 0x80 0x6d60 0x6d60 0x6d60 Scan: 29 29000 0 0 0 0x80 0x7148 0x7148 0x7148 Scan: 30 30000 0 0 0 0x80 0x7530 0x7530 0x7530 Scan: 31 31000 0 0 0 0x80 0x7918 0x7918 0x7918 Scan: 32 32000 0 0 0 0x80 0x7d00 0x7d00 0x7d00 Scan: 33 33000 0 0 0 0x80 0x80e8 0x80e8 0x80e8 Scan: 34 34000 0 0 0 0x80 0x84d0 0x84d0 0x84d0 Scan: 35 35000 0 0 0 0x80 0x88b8 0x88b8 0x88b8 Scan: 36 36000 0 0 0 0x80 0x8ca0 0x8ca0 0x8ca0 Scan: 37 37000 0 0 0 0x80 0x9088 0x9088 0x9088 Scan: 38 38000 0 0 0 0x80 0x9470 0x9470 0x9470 Scan: 39 39000 0 0 0 0x80 0x9858 0x9858 0x9858 Scan: 40 40000 0 0 0 0x80 0x9c40 0x9c40 0x9c40 Scan: 41 41000 0 0 0 0x80 0xa028 0xa028 0xa028 Scan: 42 42000 0 0 0 0x80 0xa410 0xa410 0xa410 Scan: 43 43000 0 0 0 0x80 0xa7f8 0xa7f8 0xa7f8 Scan: 44 44000 0 0 0 0x80 0xabe0 0xabe0 0xabe0 Scan: 45 45000 0 0 0 0x80 0xafc8 0xafc8 0xafc8 Scan: 46 46000 0 0 0 0x80 0xb3b0 0xb3b0 0xb3b0 Scan: 47 47000 0 0 0 0x80 0xb798 0xb798 0xb798 Scan: 48 48000 0 0 0 0x80 0xbb80 0xbb80 0xbb80 Scan: 49 49000 0 0 0 0x80 0xbf68 0xbf68 0xbf68 Scan: 50 50000 0 0 0 0x80 0xc350 0xc350 0xc350 Scan: 51 51000 0 0 0 0x80 0xc738 0xc738 0xc738 Scan: 52 52000 0 0 0 0x80 0xcb20 0xcb20 0xcb20 Scan: 53 53000 0 0 0 0x80 0xcf08 0xcf08 0xcf08 Scan: 54 54000 0 0 0 0x80 0xd2f0 0xd2f0 0xd2f0 Scan: 55 55000 0 0 0 0x80 0xd6d8 0xd6d8 0xd6d8 Scan: 56 56000 0 0 0 0x80 0xdac0 0xdac0 0xdac0 Scan: 57 57000 0 0 0 0x80 0xdea8 0xdea8 0xdea8 Scan: 58 58000 0 0 0 0x80 0xe290 0xe290 0xe290 Scan: 59 59000 0 0 0 0x80 0xe678 0xe678 0xe678 Scan: 60 60000 0 0 0 0x80 0xea60 0xea60 0xea60 Scan: 61 61000 0 0 0 0x80 0xee48 0xee48 0xee48 Scan: 62 62000 0 0 0 0x80 0xf230 0xf230 0xf230 Scan: 63 63000 0 0 0 0x80 0xf618 0xf618 0xf618 Scan: 64 64000 0 0 0 0x80 0xfa00 0xfa00 0xfa00 Scan: 65 65000 0 0 0 0x80 0xfde8 0xfde8 0xfde8 Scan: 66 66000 0 0 0 0x80 0x1d0 0x1d0 0x1d0 Scan: 67 67000 0 0 0 0x80 0x5b8 0x5b8 0x5b8 Scan: 68 68000 0 0 0 0x80 0x9a0 0x9a0 0x9a0 Scan: 69 69000 0 0 0 0x80 0xd88 0xd88 0xd88 Scan: 70 70000 0 0 0 0x80 0x1170 0x1170 0x1170 Scan: 71 71000 0 0 0 0x80 0x1558 0x1558 0x1558 Scan: 72 72000 0 0 0 0x80 0x1940 0x1940 0x1940 Scan: 73 73000 0 0 0 0x80 0x1d28 0x1d28 0x1d28 Scan: 74 74000 0 0 0 0x80 0x2110 0x2110 0x2110 Scan: 75 75000 0 0 0 0x80 0x24f8 0x24f8 0x24f8 Scan: 76 76000 0 0 0 0x80 0x28e0 0x28e0 0x28e0 Scan: 77 77000 0 0 0 0x80 0x2cc8 0x2cc8 0x2cc8 Scan: 78 78000 0 0 0 0x80 0x30b0 0x30b0 0x30b0 Scan: 79 79000 0 0 0 0x80 0x3498 0x3498 0x3498 Scan: 80 80000 0 0 0 0x80 0x3880 0x3880 0x3880 Scan: 81 81000 0 0 0 0x80 0x3c68 0x3c68 0x3c68 Scan: 82 82000 0 0 0 0x80 0x4050 0x4050 0x4050 Scan: 83 83000 0 0 0 0x80 0x4438 0x4438 0x4438 Scan: 84 84000 0 0 0 0x80 0x4820 0x4820 0x4820 Scan: 85 85000 0 0 0 0x80 0x4c08 0x4c08 0x4c08 Scan: 86 86000 0 0 0 0x80 0x4ff0 0x4ff0 0x4ff0 Scan: 87 87000 0 0 0 0x80 0x53d8 0x53d8 0x53d8 Scan: 88 88000 0 0 0 0x80 0x57c0 0x57c0 0x57c0 Scan: 89 89000 0 0 0 0x80 0x5ba8 0x5ba8 0x5ba8 Scan: 90 90000 0 0 0 0x80 0x5f90 0x5f90 0x5f90 Scan: 91 91000 0 0 0 0x80 0x6378 0x6378 0x6378 Scan: 92 92000 0 0 0 0x80 0x6760 0x6760 0x6760 Scan: 93 93000 0 0 0 0x80 0x6b48 0x6b48 0x6b48 Scan: 94 94000 0 0 0 0x80 0x6f30 0x6f30 0x6f30 Scan: 95 95000 0 0 0 0x80 0x7318 0x7318 0x7318 Scan: 96 96000 0 0 0 0x80 0x7700 0x7700 0x7700 Scan: 97 97000 0 0 0 0x80 0x7ae8 0x7ae8 0x7ae8 Scan: 98 98000 0 0 0 0x80 0x7ed0 0x7ed0 0x7ed0 Scan: 99 99000 0 0 0 0x80 0x82b8 0x82b8 0x82b8 |

Note that the last 4 works are not 0. For Scan 50 all 4 words are 0xc350, which is 50000, which is the value of counter 0 bank 0. So the 3 words at the end that should be 0 are in fact the value of counter 0 bank 0.

My conclusion is that bit 6 is having no effect. If you change this line: scanData.scanList[counter*numBanks+3] = USB_CTR_PADZERO;

to this: scanData.scanList[counter*numBanks+3] = USB_CTR_PADZERO | 1;

then that element will have the counts for counter 1 bank 0.

MCC tech support has acknowledged this problem. They are looking at a solution.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/wjasper/Linux_Drivers/issues/34?email_source=notifications&email_token=AFRLPHPXFIGUYKPO5EQJTVTQMN5R5A5CNFSM4I3L2GY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAB6D6Y#issuecomment-537125371, or mute the thread https://github.com/notifications/unsubscribe-auth/AFRLPHOIQNGSY4YQBTRQN4DQMN5R5ANCNFSM4I3L2GYQ.

--

Warren J. Jasper, PhD, PE Professor and Textile Engineering Program Director North Carolina State University Raleigh, NC 27695 Tel (919) 515-6565 Fax (919) 515-6532