トランジスタ技術2011年9月号「mbed30分クッキング」のプログラムです。
Dependencies: mbed TextLCD SDFileSystem
mylib/lenval.h@0:42e9eb506e88, 2011-08-08 (annotated)
- Committer:
- shintamainjp
- Date:
- Mon Aug 08 10:33:50 2011 +0000
- Revision:
- 0:42e9eb506e88
Initial version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:42e9eb506e88 | 1 | /*******************************************************/ |
shintamainjp | 0:42e9eb506e88 | 2 | /* file: lenval.h */ |
shintamainjp | 0:42e9eb506e88 | 3 | /* abstract: This file contains a description of the */ |
shintamainjp | 0:42e9eb506e88 | 4 | /* data structure "lenval". */ |
shintamainjp | 0:42e9eb506e88 | 5 | /*******************************************************/ |
shintamainjp | 0:42e9eb506e88 | 6 | |
shintamainjp | 0:42e9eb506e88 | 7 | #ifndef lenval_dot_h |
shintamainjp | 0:42e9eb506e88 | 8 | #define lenval_dot_h |
shintamainjp | 0:42e9eb506e88 | 9 | |
shintamainjp | 0:42e9eb506e88 | 10 | /* the lenVal structure is a byte oriented type used to store an */ |
shintamainjp | 0:42e9eb506e88 | 11 | /* arbitrary length binary value. As an example, the hex value */ |
shintamainjp | 0:42e9eb506e88 | 12 | /* 0x0e3d is represented as a lenVal with len=2 (since 2 bytes */ |
shintamainjp | 0:42e9eb506e88 | 13 | /* and val[0]=0e and val[1]=3d. val[2-MAX_LEN] are undefined */ |
shintamainjp | 0:42e9eb506e88 | 14 | |
shintamainjp | 0:42e9eb506e88 | 15 | /* maximum length (in bytes) of value to read in */ |
shintamainjp | 0:42e9eb506e88 | 16 | /* this needs to be at least 4, and longer than the */ |
shintamainjp | 0:42e9eb506e88 | 17 | /* length of the longest SDR instruction. If there is, */ |
shintamainjp | 0:42e9eb506e88 | 18 | /* only 1 device in the chain, MAX_LEN must be at least */ |
shintamainjp | 0:42e9eb506e88 | 19 | /* ceil(27/8) == 4. For 6 devices in a chain, MAX_LEN */ |
shintamainjp | 0:42e9eb506e88 | 20 | /* must be 5, for 14 devices MAX_LEN must be 6, for 20 */ |
shintamainjp | 0:42e9eb506e88 | 21 | /* devices MAX_LEN must be 7, etc.. */ |
shintamainjp | 0:42e9eb506e88 | 22 | /* You can safely set MAX_LEN to a smaller number if you*/ |
shintamainjp | 0:42e9eb506e88 | 23 | /* know how many devices will be in your chain. */ |
shintamainjp | 0:42e9eb506e88 | 24 | /* #define MAX_LEN (Actual #define is below this comment block) |
shintamainjp | 0:42e9eb506e88 | 25 | This #define defines the maximum length (in bytes) of predefined |
shintamainjp | 0:42e9eb506e88 | 26 | buffers in which the XSVF player stores the current shift data. |
shintamainjp | 0:42e9eb506e88 | 27 | This length must be greater than the longest shift length (in bytes) |
shintamainjp | 0:42e9eb506e88 | 28 | in the XSVF files that will be processed. 7000 is a very conservative |
shintamainjp | 0:42e9eb506e88 | 29 | number. The buffers are stored on the stack and if you have limited |
shintamainjp | 0:42e9eb506e88 | 30 | stack space, you may decrease the MAX_LEN value. |
shintamainjp | 0:42e9eb506e88 | 31 | |
shintamainjp | 0:42e9eb506e88 | 32 | How to find the "shift length" in bits? |
shintamainjp | 0:42e9eb506e88 | 33 | Look at the ASCII version of the XSVF (generated with the -a option |
shintamainjp | 0:42e9eb506e88 | 34 | for the SVF2XSVF translator) and search for the XSDRSIZE command |
shintamainjp | 0:42e9eb506e88 | 35 | with the biggest parameter. XSDRSIZE is equivalent to the SVF's |
shintamainjp | 0:42e9eb506e88 | 36 | SDR length plus the lengths of applicable HDR and TDR commands. |
shintamainjp | 0:42e9eb506e88 | 37 | Remember that the MAX_LEN is defined in bytes. Therefore, the |
shintamainjp | 0:42e9eb506e88 | 38 | minimum MAX_LEN = ceil( max( XSDRSIZE ) / 8 ); |
shintamainjp | 0:42e9eb506e88 | 39 | |
shintamainjp | 0:42e9eb506e88 | 40 | The following MAX_LEN values have been tested and provide relatively |
shintamainjp | 0:42e9eb506e88 | 41 | good margin for the corresponding devices: |
shintamainjp | 0:42e9eb506e88 | 42 | |
shintamainjp | 0:42e9eb506e88 | 43 | DEVICE MAX_LEN Resulting Shift Length Max (in bits) |
shintamainjp | 0:42e9eb506e88 | 44 | --------- ------- ---------------------------------------------- |
shintamainjp | 0:42e9eb506e88 | 45 | XC9500/XL/XV 32 256 |
shintamainjp | 0:42e9eb506e88 | 46 | |
shintamainjp | 0:42e9eb506e88 | 47 | CoolRunner/II 256 2048 - actual max 1 device = 1035 bits |
shintamainjp | 0:42e9eb506e88 | 48 | |
shintamainjp | 0:42e9eb506e88 | 49 | FPGA 128 1024 - svf2xsvf -rlen 1024 |
shintamainjp | 0:42e9eb506e88 | 50 | |
shintamainjp | 0:42e9eb506e88 | 51 | XC18V00/XCF00 |
shintamainjp | 0:42e9eb506e88 | 52 | 1100 8800 - no blank check performed (default) |
shintamainjp | 0:42e9eb506e88 | 53 | - actual max 1 device = 8192 bits verify |
shintamainjp | 0:42e9eb506e88 | 54 | - max 1 device = 4096 bits program-only |
shintamainjp | 0:42e9eb506e88 | 55 | |
shintamainjp | 0:42e9eb506e88 | 56 | XC18V00/XCF00 when using the optional Blank Check operation |
shintamainjp | 0:42e9eb506e88 | 57 | 2500 20000 - required for blank check |
shintamainjp | 0:42e9eb506e88 | 58 | - blank check max 1 device = 16384 bits |
shintamainjp | 0:42e9eb506e88 | 59 | */ |
shintamainjp | 0:42e9eb506e88 | 60 | // #define MAX_LEN 7000 /* This is the default value. But it's huge for mbed. */ |
shintamainjp | 0:42e9eb506e88 | 61 | #define MAX_LEN 2048 /* Modified for mbed. */ |
shintamainjp | 0:42e9eb506e88 | 62 | |
shintamainjp | 0:42e9eb506e88 | 63 | |
shintamainjp | 0:42e9eb506e88 | 64 | typedef struct var_len_byte |
shintamainjp | 0:42e9eb506e88 | 65 | { |
shintamainjp | 0:42e9eb506e88 | 66 | short len; /* number of chars in this value */ |
shintamainjp | 0:42e9eb506e88 | 67 | unsigned char val[MAX_LEN+1]; /* bytes of data */ |
shintamainjp | 0:42e9eb506e88 | 68 | } lenVal; |
shintamainjp | 0:42e9eb506e88 | 69 | |
shintamainjp | 0:42e9eb506e88 | 70 | |
shintamainjp | 0:42e9eb506e88 | 71 | /* return the long representation of a lenVal */ |
shintamainjp | 0:42e9eb506e88 | 72 | extern long value(lenVal *x); |
shintamainjp | 0:42e9eb506e88 | 73 | |
shintamainjp | 0:42e9eb506e88 | 74 | /* set lenVal equal to value */ |
shintamainjp | 0:42e9eb506e88 | 75 | extern void initLenVal(lenVal *x, long value); |
shintamainjp | 0:42e9eb506e88 | 76 | |
shintamainjp | 0:42e9eb506e88 | 77 | /* check if expected equals actual (taking the mask into account) */ |
shintamainjp | 0:42e9eb506e88 | 78 | extern short EqualLenVal(lenVal *expected, lenVal *actual, lenVal *mask); |
shintamainjp | 0:42e9eb506e88 | 79 | |
shintamainjp | 0:42e9eb506e88 | 80 | /* add val1+val2 and put the result in resVal */ |
shintamainjp | 0:42e9eb506e88 | 81 | extern void addVal(lenVal *resVal, lenVal *val1, lenVal *val2); |
shintamainjp | 0:42e9eb506e88 | 82 | |
shintamainjp | 0:42e9eb506e88 | 83 | /* return the (byte, bit) of lv (reading from left to right) */ |
shintamainjp | 0:42e9eb506e88 | 84 | extern short RetBit(lenVal *lv, int byte, int bit); |
shintamainjp | 0:42e9eb506e88 | 85 | |
shintamainjp | 0:42e9eb506e88 | 86 | /* set the (byte, bit) of lv equal to val (e.g. SetBit("00000000",byte, 1) |
shintamainjp | 0:42e9eb506e88 | 87 | equals "01000000" */ |
shintamainjp | 0:42e9eb506e88 | 88 | extern void SetBit(lenVal *lv, int byte, int bit, short val); |
shintamainjp | 0:42e9eb506e88 | 89 | |
shintamainjp | 0:42e9eb506e88 | 90 | /* read from XSVF numBytes bytes of data into x */ |
shintamainjp | 0:42e9eb506e88 | 91 | extern void readVal(lenVal *x, short numBytes); |
shintamainjp | 0:42e9eb506e88 | 92 | |
shintamainjp | 0:42e9eb506e88 | 93 | #endif |
shintamainjp | 0:42e9eb506e88 | 94 |