alkopop79

code

Mar 13th, 2017
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 29.10 KB | None | 0 0
  1.     #include <avr/io.h>                         //this file calls up iom128.h which defines things like PORTA & PIN0 etc
  2.     #include <avr/iom128.h>
  3.     #include <avr/pgmspace.h>                       //defines commands for using ROM e.g. 'const char' and '__elpm_inline'
  4.    
  5.     //#define F_CPU 14745600                    //clock freq = 14.7456MHz
  6.     #define Clks_per_cycle  7                   //number of clocks per cycle of while loop in msDelay function
  7.     #define Cycles_per_ms   (F_CPU / (1000 * Clks_per_cycle))   //number of cycles of while loop per mS in msDelay function
  8.    
  9.     #define AN221_EXECUTE_Low       PORTA &=~(1<<PA0)       //drive EXECUTE low    
  10.     #define AN221_ACTIVATE      bit_is_set(PINA, PIN2)      //sense ACTIVATE high
  11.     #define AN221_NO_ERROR      bit_is_set(PINA, PIN3)      //sense ERRb high i.e. no rror
  12.    
  13.     #define AN221_ERRb_Input    DDRA(1<<DDA3)           //make uP drive ERRb
  14.    
  15.     #define AN221_ERRb_Output   DDRA(0<<DDA3)           //make uP sense ERRb
  16.     #define AN221_ERRb_Low      PORTA &=~(1<<PA3)           //drive ERRb low
  17.     #define AN221_ERRb_High     PORTA |=_BV(PA3)            //drive ERRb high
  18.     #define AN221_DIN_Low       PORTA &=~(1<<PA5)       //drive DIN low
  19.     #define AN221_DIN_High      PORTA |=_BV(PA5)            //drive DIN high
  20.     #define AN221_DCLK_Low      PORTA &=~(1<<PA6)           //drive DCLK low
  21.     #define AN221_DCLK_High     PORTA |=_BV(PA6)            //drive DCLK high
  22.     #define AN221_CS2b_Low      PORTA &=~(1<<PA7)           //drive CS2b low   
  23.    
  24.    
  25.     #define Red_LED_ON          PORTB |=_BV(PB0)
  26.     #define Red_LED_OFF         PORTB &=~(1<<PB0)
  27.     #define Yellow_LED_ON       PORTB &=~(1<<PB1)
  28.     #define Yellow_LED_OFF      PORTB |=_BV(PB1)
  29.     #define Green_LED_ON        PORTB &=~(1<<PB2)
  30.     #define Green_LED_OFF       PORTB |=_BV(PB2)
  31.    
  32.     #define Pushbutton_1        bit_is_clear(PINF, PIN0)    //pushbutton shorts PF0 to ground
  33.     #define Pushbutton_2        bit_is_clear(PINF, PIN1)    //pushbutton shorts PF1 to ground
  34.     #define Pushbutton_3        bit_is_clear(PINF, PIN2)    //pushbutton shorts PF2 to ground
  35.     #define Pushbutton_4        bit_is_clear(PINF, PIN3)    //pushbutton shorts PF3 to ground
  36.    
  37.     #define PrimarySize1        155             //155 bytes in primary bit stream for circuit #1
  38.     #define PrimarySize2        155             //155 bytes in primary bit stream for circuit #2
  39.     #define PrimarySize3        155             //155 bytes in primary bit stream for circuit #3
  40.     #define PrimarySize4        155             //155 bytes in primary bit stream for circuit #4
  41.    
  42.     #define UpdateSize1     34              //34 bytes in reconfig bit stream for circuit #1
  43.     #define UpdateSize2     34              //34 bytes in reconfig bit stream for circuit #2
  44.     #define UpdateSize3     34              //34 bytes in reconfig bit stream for circuit #3
  45.     #define UpdateSize4     34              //34 bytes in reconfig bit stream for circuit #4
  46.    
  47.     #define chipID          0x01                //ID of FPAA
  48.    
  49.    
  50.     const char PrimaryBitStream1[PrimarySize1] =    //set up array in ROM for bitstream #1
  51.     {  //circuit #1 - 1kHz sinewave oscillator. User should replace the config bitstream below with his own
  52.        /* The header for the configuration stream */
  53.        0xD5, /* Synch     */
  54.        0xB7, /* JTAG0     */
  55.        0x22, /* JTAG1     */
  56.        0x0 , /* JTAG2     */
  57.        0x80, /* JTAG3     */
  58.        chipID, /* Device ID */
  59.        0x5 , /* Control   */
  60.    
  61.        /* Start of data block */
  62.        0xCC, /* Byte address: 12 */
  63.        0x0 , /* Bank address:  0 */
  64.        0xC , /* Byte count:   12 */
  65.    
  66.        /* Data bytes for block */
  67.        0x20,  0x0 ,  0x20,  0x4 ,  0x0 ,  0x2 ,  0x2 ,  0x61,
  68.        0x0 ,  0x8 ,  0xFF,  0x1 ,
  69.    
  70.        /* Check Byte: Inverse Synch */
  71.        0x2A,
  72.    
  73.        /* Start of data block */
  74.        0xDE, /* Byte address: 30 */
  75.        0x0 , /* Bank address:  0 */
  76.        0x1 , /* Byte count:    1 */
  77.    
  78.        /* Data bytes for block */
  79.        0xF ,
  80.    
  81.        /* Check Byte: Inverse Synch */
  82.        0x2A,
  83.    
  84.        /* Start of data block */
  85.        0xCE, /* Byte address: 14 */
  86.        0x1 , /* Bank address:  1 */
  87.        0x48, /* Byte count:   72 */
  88.    
  89.        /* Data bytes for block */
  90.        0x1 ,  0x48,  0x3F,  0x48,  0x3F,  0x1 ,  0x20,  0x20,
  91.        0xFF,  0x20,  0x4 ,  0xFF,  0x0 ,  0x0 ,  0x48,  0x3F,
  92.        0x48,  0x3F,  0x1 ,  0x1 ,  0x81,  0x2E,  0x1 ,  0x81,
  93.        0xE4,  0x0 ,  0x10,  0xE5,  0x0 ,  0x10,  0x0 ,  0x7 ,
  94.        0x1E,  0x1 ,  0x82,  0x7 ,  0x0 ,  0x0 ,  0x1 ,  0x1 ,
  95.        0x82,  0x95,  0x0 ,  0x20,  0x0 ,  0x95,  0x0 ,  0x20,
  96.        0x0 ,  0x48,  0x0 ,  0x5 ,  0xAD,  0x81,  0xAC,  0x0 ,
  97.        0x0 ,  0x0 ,  0x0 ,  0x8 ,  0x0 ,  0x98,  0x0 ,  0x0 ,
  98.        0x98,  0x8 ,  0x0 ,  0x0 ,  0x41,  0x9D,  0x81,  0xAC,
  99.    
  100.        /* Check Byte: Inverse Synch */
  101.        0x2A,
  102.    
  103.        /* Start of data block */
  104.        0xDB, /* Byte address: 27 */
  105.        0x3 , /* Bank address:  3 */
  106.        0x5 , /* Byte count:    5 */
  107.    
  108.        /* Data bytes for block */
  109.        0x90,  0x0 ,  0x90,  0xA ,  0x80,
  110.    
  111.        /* Check Byte: Inverse Synch */
  112.        0x2A,
  113.    
  114.        /* Start of data block */
  115.        0xCD, /* Byte address: 13 */
  116.        0x4 , /* Bank address:  4 */
  117.        0x5 , /* Byte count:    5 */
  118.    
  119.        /* Data bytes for block */
  120.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  121.    
  122.        /* Check Byte: Inverse Synch */
  123.        0x2A,
  124.    
  125.        /* Start of data block */
  126.        0xDE, /* Byte address: 30 */
  127.        0x5 , /* Bank address:  5 */
  128.        0x1 , /* Byte count:    1 */
  129.    
  130.        /* Data bytes for block */
  131.        0xA ,
  132.    
  133.        /* Check Byte: Inverse Synch */
  134.        0x2A,
  135.    
  136.        /* Start of data block */
  137.        0xCD, /* Byte address: 13 */
  138.        0x6 , /* Bank address:  6 */
  139.        0x5 , /* Byte count:    5 */
  140.    
  141.        /* Data bytes for block */
  142.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  143.    
  144.        /* Check Byte: Inverse Synch */
  145.        0x2A,
  146.    
  147.        /* Start of data block */
  148.        0xDE, /* Byte address: 30 */
  149.        0x7 , /* Bank address:  7 */
  150.        0x1 , /* Byte count:    1 */
  151.    
  152.        /* Data bytes for block */
  153.        0xA ,
  154.    
  155.        /* Check Byte: Inverse Synch */
  156.        0x2A,
  157.    
  158.        /* Start of data block */
  159.        0xCD, /* Byte address: 13 */
  160.        0x8 , /* Bank address:  8 */
  161.        0x5 , /* Byte count:    5 */
  162.    
  163.        /* Data bytes for block */
  164.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  165.    
  166.        /* Check Byte: Inverse Synch */
  167.        0x2A,
  168.    
  169.        /* Start of data block */
  170.        0x9E, /* Byte address: 30 */
  171.        0x9 , /* Bank address:  9 */
  172.        0x1 , /* Byte count:    1 */
  173.    
  174.        /* Data bytes for block */
  175.        0xA ,
  176.    
  177.        /* Check Byte: Inverse Synch */
  178.        0x2A
  179.     };
  180.    
  181.     const char PrimaryBitStream2[PrimarySize2] =    //set up array in ROM for bitstream #2
  182.     {  //circuit #2 - 2kHz sinewave oscillator. User should replace the config bitstream below with his own
  183.        /* The header for the configuration stream */
  184.        0xD5, /* Synch     */
  185.        0xB7, /* JTAG0     */
  186.        0x22, /* JTAG1     */
  187.        0x0 , /* JTAG2     */
  188.        0x80, /* JTAG3     */
  189.        chipID, /* Device ID */
  190.        0x5 , /* Control   */
  191.    
  192.        /* Start of data block */
  193.        0xCC, /* Byte address: 12 */
  194.        0x0 , /* Bank address:  0 */
  195.        0xC , /* Byte count:   12 */
  196.    
  197.        /* Data bytes for block */
  198.        0x20,  0x0 ,  0x20,  0x4 ,  0x0 ,  0x2 ,  0x2 ,  0x61,
  199.        0x0 ,  0x8 ,  0xFF,  0x1 ,
  200.    
  201.        /* Check Byte: Inverse Synch */
  202.        0x2A,
  203.    
  204.        /* Start of data block */
  205.        0xDE, /* Byte address: 30 */
  206.        0x0 , /* Bank address:  0 */
  207.        0x1 , /* Byte count:    1 */
  208.    
  209.        /* Data bytes for block */
  210.        0xF ,
  211.    
  212.        /* Check Byte: Inverse Synch */
  213.        0x2A,
  214.    
  215.        /* Start of data block */
  216.        0xCE, /* Byte address: 14 */
  217.        0x1 , /* Bank address:  1 */
  218.        0x48, /* Byte count:   72 */
  219.    
  220.        /* Data bytes for block */
  221.        0x1 ,  0x48,  0x3F,  0x48,  0x3F,  0x1 ,  0x20,  0x20,
  222.        0xFF,  0x20,  0x4 ,  0xFF,  0x0 ,  0x0 ,  0x48,  0x3F,
  223.        0x48,  0x3F,  0x2 ,  0x1 ,  0x81,  0x5C,  0x1 ,  0x81,
  224.        0xE4,  0x0 ,  0x10,  0xE4,  0x0 ,  0x10,  0x0 ,  0x7 ,
  225.        0x5A,  0x1 ,  0x82,  0x7 ,  0x0 ,  0x0 ,  0x3 ,  0x1 ,
  226.        0x82,  0xDF,  0x0 ,  0x20,  0x0 ,  0xE0,  0x0 ,  0x20,
  227.        0x0 ,  0x48,  0x0 ,  0x5 ,  0xAD,  0x81,  0xAC,  0x0 ,
  228.        0x0 ,  0x0 ,  0x0 ,  0x8 ,  0x0 ,  0x98,  0x0 ,  0x0 ,
  229.        0x98,  0x8 ,  0x0 ,  0x0 ,  0x41,  0x9D,  0x81,  0xAC,
  230.    
  231.        /* Check Byte: Inverse Synch */
  232.        0x2A,
  233.    
  234.        /* Start of data block */
  235.        0xDB, /* Byte address: 27 */
  236.        0x3 , /* Bank address:  3 */
  237.        0x5 , /* Byte count:    5 */
  238.    
  239.        /* Data bytes for block */
  240.        0x90,  0x0 ,  0x90,  0xA ,  0x80,
  241.    
  242.        /* Check Byte: Inverse Synch */
  243.        0x2A,
  244.    
  245.        /* Start of data block */
  246.        0xCD, /* Byte address: 13 */
  247.        0x4 , /* Bank address:  4 */
  248.        0x5 , /* Byte count:    5 */
  249.    
  250.        /* Data bytes for block */
  251.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  252.    
  253.        /* Check Byte: Inverse Synch */
  254.        0x2A,
  255.    
  256.        /* Start of data block */
  257.        0xDE, /* Byte address: 30 */
  258.        0x5 , /* Bank address:  5 */
  259.        0x1 , /* Byte count:    1 */
  260.    
  261.        /* Data bytes for block */
  262.        0xA ,
  263.    
  264.        /* Check Byte: Inverse Synch */
  265.        0x2A,
  266.    
  267.        /* Start of data block */
  268.        0xCD, /* Byte address: 13 */
  269.        0x6 , /* Bank address:  6 */
  270.        0x5 , /* Byte count:    5 */
  271.    
  272.        /* Data bytes for block */
  273.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  274.    
  275.        /* Check Byte: Inverse Synch */
  276.        0x2A,
  277.    
  278.        /* Start of data block */
  279.        0xDE, /* Byte address: 30 */
  280.        0x7 , /* Bank address:  7 */
  281.        0x1 , /* Byte count:    1 */
  282.    
  283.        /* Data bytes for block */
  284.        0xA ,
  285.    
  286.        /* Check Byte: Inverse Synch */
  287.        0x2A,
  288.    
  289.        /* Start of data block */
  290.        0xCD, /* Byte address: 13 */
  291.        0x8 , /* Bank address:  8 */
  292.        0x5 , /* Byte count:    5 */
  293.    
  294.        /* Data bytes for block */
  295.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  296.    
  297.        /* Check Byte: Inverse Synch */
  298.        0x2A,
  299.    
  300.        /* Start of data block */
  301.        0x9E, /* Byte address: 30 */
  302.        0x9 , /* Bank address:  9 */
  303.        0x1 , /* Byte count:    1 */
  304.    
  305.        /* Data bytes for block */
  306.        0xA ,
  307.    
  308.        /* Check Byte: Inverse Synch */
  309.        0x2A
  310.     };
  311.    
  312.     const char PrimaryBitStream3[PrimarySize3] =    //set up array in ROM for bitstream #3
  313.     {  //circuit #3 - 3kHz sinewave oscillator. User should replace the config bitstream below with his own
  314.        /* The header for the configuration stream */
  315.        0xD5, /* Synch     */
  316.        0xB7, /* JTAG0     */
  317.        0x22, /* JTAG1     */
  318.        0x0 , /* JTAG2     */
  319.        0x80, /* JTAG3     */
  320.        chipID, /* Device ID */
  321.        0x5 , /* Control   */
  322.    
  323.        /* Start of data block */
  324.        0xCC, /* Byte address: 12 */
  325.        0x0 , /* Bank address:  0 */
  326.        0xC , /* Byte count:   12 */
  327.    
  328.        /* Data bytes for block */
  329.        0x20,  0x0 ,  0x20,  0x4 ,  0x0 ,  0x2 ,  0x2 ,  0x61,
  330.        0x0 ,  0x8 ,  0xFF,  0x1 ,
  331.    
  332.        /* Check Byte: Inverse Synch */
  333.        0x2A,
  334.    
  335.        /* Start of data block */
  336.        0xDE, /* Byte address: 30 */
  337.        0x0 , /* Bank address:  0 */
  338.        0x1 , /* Byte count:    1 */
  339.    
  340.        /* Data bytes for block */
  341.        0xF ,
  342.    
  343.        /* Check Byte: Inverse Synch */
  344.        0x2A,
  345.    
  346.        /* Start of data block */
  347.        0xCE, /* Byte address: 14 */
  348.        0x1 , /* Bank address:  1 */
  349.        0x48, /* Byte count:   72 */
  350.    
  351.        /* Data bytes for block */
  352.        0x1 ,  0x48,  0x3F,  0x48,  0x3F,  0x1 ,  0x20,  0x20,
  353.        0xFF,  0x20,  0x4 ,  0xFF,  0x0 ,  0x0 ,  0x48,  0x3F,
  354.        0x48,  0x3F,  0x3 ,  0x1 ,  0x81,  0x8A,  0x1 ,  0x81,
  355.        0xE4,  0x0 ,  0x10,  0xE5,  0x0 ,  0x10,  0x0 ,  0x7 ,
  356.        0x78,  0x1 ,  0x82,  0x7 ,  0x0 ,  0x0 ,  0x4 ,  0x1 ,
  357.        0x82,  0xC6,  0x0 ,  0x20,  0x0 ,  0xC7,  0x0 ,  0x20,
  358.        0x0 ,  0x48,  0x0 ,  0x5 ,  0xAD,  0x81,  0xAC,  0x0 ,
  359.        0x0 ,  0x0 ,  0x0 ,  0x8 ,  0x0 ,  0x98,  0x0 ,  0x0 ,
  360.        0x98,  0x8 ,  0x0 ,  0x0 ,  0x41,  0x9D,  0x81,  0xAC,
  361.    
  362.        /* Check Byte: Inverse Synch */
  363.        0x2A,
  364.    
  365.        /* Start of data block */
  366.        0xDB, /* Byte address: 27 */
  367.        0x3 , /* Bank address:  3 */
  368.        0x5 , /* Byte count:    5 */
  369.    
  370.        /* Data bytes for block */
  371.        0x90,  0x0 ,  0x90,  0xA ,  0x80,
  372.    
  373.        /* Check Byte: Inverse Synch */
  374.        0x2A,
  375.    
  376.        /* Start of data block */
  377.        0xCD, /* Byte address: 13 */
  378.        0x4 , /* Bank address:  4 */
  379.        0x5 , /* Byte count:    5 */
  380.    
  381.        /* Data bytes for block */
  382.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  383.    
  384.        /* Check Byte: Inverse Synch */
  385.        0x2A,
  386.    
  387.        /* Start of data block */
  388.        0xDE, /* Byte address: 30 */
  389.        0x5 , /* Bank address:  5 */
  390.        0x1 , /* Byte count:    1 */
  391.    
  392.        /* Data bytes for block */
  393.        0xA ,
  394.    
  395.        /* Check Byte: Inverse Synch */
  396.        0x2A,
  397.    
  398.        /* Start of data block */
  399.        0xCD, /* Byte address: 13 */
  400.        0x6 , /* Bank address:  6 */
  401.        0x5 , /* Byte count:    5 */
  402.    
  403.        /* Data bytes for block */
  404.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  405.    
  406.        /* Check Byte: Inverse Synch */
  407.        0x2A,
  408.    
  409.        /* Start of data block */
  410.        0xDE, /* Byte address: 30 */
  411.        0x7 , /* Bank address:  7 */
  412.        0x1 , /* Byte count:    1 */
  413.    
  414.        /* Data bytes for block */
  415.        0xA ,
  416.    
  417.        /* Check Byte: Inverse Synch */
  418.        0x2A,
  419.    
  420.        /* Start of data block */
  421.        0xCD, /* Byte address: 13 */
  422.        0x8 , /* Bank address:  8 */
  423.        0x5 , /* Byte count:    5 */
  424.    
  425.        /* Data bytes for block */
  426.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  427.    
  428.        /* Check Byte: Inverse Synch */
  429.        0x2A,
  430.    
  431.        /* Start of data block */
  432.        0x9E, /* Byte address: 30 */
  433.        0x9 , /* Bank address:  9 */
  434.        0x1 , /* Byte count:    1 */
  435.    
  436.        /* Data bytes for block */
  437.        0xA ,
  438.    
  439.        /* Check Byte: Inverse Synch */
  440.        0x2A
  441.     };
  442.    
  443.     const char PrimaryBitStream4[PrimarySize4] =    //set up array in ROM for bitstream #4
  444.     {  //circuit #4 - 4kHz sinewave oscillator. User should replace the config bitstream below with his own
  445.        /* The header for the configuration stream */
  446.        0xD5, /* Synch     */
  447.        0xB7, /* JTAG0     */
  448.        0x22, /* JTAG1     */
  449.        0x0 , /* JTAG2     */
  450.        0x80, /* JTAG3     */
  451.        chipID, /* Device ID */
  452.        0x5 , /* Control   */
  453.    
  454.        /* Start of data block */
  455.        0xCC, /* Byte address: 12 */
  456.        0x0 , /* Bank address:  0 */
  457.        0xC , /* Byte count:   12 */
  458.    
  459.        /* Data bytes for block */
  460.        0x20,  0x0 ,  0x20,  0x4 ,  0x0 ,  0x2 ,  0x2 ,  0x61,
  461.        0x0 ,  0x8 ,  0xFF,  0x1 ,
  462.    
  463.        /* Check Byte: Inverse Synch */
  464.        0x2A,
  465.    
  466.        /* Start of data block */
  467.        0xDE, /* Byte address: 30 */
  468.        0x0 , /* Bank address:  0 */
  469.        0x1 , /* Byte count:    1 */
  470.    
  471.        /* Data bytes for block */
  472.        0xF ,
  473.    
  474.        /* Check Byte: Inverse Synch */
  475.        0x2A,
  476.    
  477.        /* Start of data block */
  478.        0xCE, /* Byte address: 14 */
  479.        0x1 , /* Bank address:  1 */
  480.        0x48, /* Byte count:   72 */
  481.    
  482.        /* Data bytes for block */
  483.        0x1 ,  0x48,  0x3F,  0x48,  0x3F,  0x1 ,  0x20,  0x20,
  484.        0xFF,  0x20,  0x4 ,  0xFF,  0x0 ,  0x0 ,  0x48,  0x3F,
  485.        0x48,  0x3F,  0x4 ,  0x1 ,  0x81,  0xB7,  0x1 ,  0x81,
  486.        0xE3,  0x0 ,  0x10,  0xE4,  0x0 ,  0x10,  0x0 ,  0x7 ,
  487.        0xB4,  0x1 ,  0x82,  0x7 ,  0x0 ,  0x0 ,  0x6 ,  0x1 ,
  488.        0x82,  0xDF,  0x0 ,  0x20,  0x0 ,  0xE0,  0x0 ,  0x20,
  489.        0x0 ,  0x48,  0x0 ,  0x5 ,  0xAD,  0x81,  0xAC,  0x0 ,
  490.        0x0 ,  0x0 ,  0x0 ,  0x8 ,  0x0 ,  0x98,  0x0 ,  0x0 ,
  491.        0x98,  0x8 ,  0x0 ,  0x0 ,  0x41,  0x9D,  0x81,  0xAC,
  492.    
  493.        /* Check Byte: Inverse Synch */
  494.        0x2A,
  495.    
  496.        /* Start of data block */
  497.        0xDB, /* Byte address: 27 */
  498.        0x3 , /* Bank address:  3 */
  499.        0x5 , /* Byte count:    5 */
  500.    
  501.        /* Data bytes for block */
  502.        0x90,  0x0 ,  0x90,  0xA ,  0x80,
  503.    
  504.        /* Check Byte: Inverse Synch */
  505.        0x2A,
  506.    
  507.        /* Start of data block */
  508.        0xCD, /* Byte address: 13 */
  509.        0x4 , /* Bank address:  4 */
  510.        0x5 , /* Byte count:    5 */
  511.    
  512.        /* Data bytes for block */
  513.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  514.    
  515.        /* Check Byte: Inverse Synch */
  516.        0x2A,
  517.    
  518.        /* Start of data block */
  519.        0xDE, /* Byte address: 30 */
  520.        0x5 , /* Bank address:  5 */
  521.        0x1 , /* Byte count:    1 */
  522.    
  523.        /* Data bytes for block */
  524.        0xA ,
  525.    
  526.        /* Check Byte: Inverse Synch */
  527.        0x2A,
  528.    
  529.        /* Start of data block */
  530.        0xCD, /* Byte address: 13 */
  531.        0x6 , /* Bank address:  6 */
  532.        0x5 , /* Byte count:    5 */
  533.    
  534.        /* Data bytes for block */
  535.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  536.    
  537.        /* Check Byte: Inverse Synch */
  538.        0x2A,
  539.    
  540.        /* Start of data block */
  541.        0xDE, /* Byte address: 30 */
  542.        0x7 , /* Bank address:  7 */
  543.        0x1 , /* Byte count:    1 */
  544.    
  545.        /* Data bytes for block */
  546.        0xA ,
  547.    
  548.        /* Check Byte: Inverse Synch */
  549.        0x2A,
  550.    
  551.        /* Start of data block */
  552.        0xCD, /* Byte address: 13 */
  553.        0x8 , /* Bank address:  8 */
  554.        0x5 , /* Byte count:    5 */
  555.    
  556.        /* Data bytes for block */
  557.        0x3 ,  0x0 ,  0x0 ,  0x0 ,  0x3 ,
  558.    
  559.        /* Check Byte: Inverse Synch */
  560.        0x2A,
  561.    
  562.        /* Start of data block */
  563.        0x9E, /* Byte address: 30 */
  564.        0x9 , /* Bank address:  9 */
  565.        0x1 , /* Byte count:    1 */
  566.    
  567.        /* Data bytes for block */
  568.        0xA ,
  569.    
  570.        /* Check Byte: Inverse Synch */
  571.        0x2A
  572.     };
  573.    
  574.     const char UpdateBitStream1[UpdateSize1] =      //set up array of circuit #1 update bitstream in ROM
  575.     {  //circuit #1 - 1kHz sinewave oscillator. User should replace the update bitstream below with his own
  576.        /* The header for the configuration stream */
  577.        0xD5, /* Synch     */
  578.        chipID, /* Device ID */
  579.        0x5 , /* Control   */
  580.    
  581.        /* Start of data block */
  582.        0xC0, /* Byte address:  0 */
  583.        0x2 , /* Bank address:  2 */
  584.        0xA , /* Byte count:   10 */
  585.    
  586.        /* Data bytes for block */
  587.        0x1 ,  0x1 ,  0x81,  0x2E,  0x1 ,  0x81,  0xE4,  0x0 ,
  588.        0x10,  0xE5,
  589.    
  590.        /* Check Byte: Inverse Synch */
  591.        0x2A,
  592.    
  593.        /* Start of data block */
  594.        0xCE, /* Byte address: 14 */
  595.        0x2 , /* Bank address:  2 */
  596.        0x1 , /* Byte count:    1 */
  597.    
  598.        /* Data bytes for block */
  599.        0x1E,
  600.    
  601.        /* Check Byte: Inverse Synch */
  602.        0x2A,
  603.    
  604.        /* Start of data block */
  605.        0x94, /* Byte address: 20 */
  606.        0x2 , /* Bank address:  2 */
  607.        0x8 , /* Byte count:    8 */
  608.    
  609.        /* Data bytes for block */
  610.        0x1 ,  0x1 ,  0x82,  0x95,  0x0 ,  0x20,  0x0 ,  0x95,
  611.    
  612.        /* Check Byte: Inverse Synch */
  613.        0x2A
  614.     };
  615.    
  616.     const char UpdateBitStream2[UpdateSize2] =      //set up array of circuit #2 update bitstream in ROM
  617.     {  //circuit #2 - 2kHz sinewave oscillator. User should replace the update bitstream below with his own
  618.       /* The header for the configuration stream */
  619.        0xD5, /* Synch     */
  620.        chipID, /* Device ID */
  621.        0x5 , /* Control   */
  622.    
  623.        /* Start of data block */
  624.        0xC0, /* Byte address:  0 */
  625.        0x2 , /* Bank address:  2 */
  626.        0xA , /* Byte count:   10 */
  627.    
  628.        /* Data bytes for block */
  629.        0x2 ,  0x1 ,  0x81,  0x5C,  0x1 ,  0x81,  0xE4,  0x0 ,
  630.        0x10,  0xE4,
  631.    
  632.        /* Check Byte: Inverse Synch */
  633.        0x2A,
  634.    
  635.        /* Start of data block */
  636.        0xCE, /* Byte address: 14 */
  637.        0x2 , /* Bank address:  2 */
  638.        0x1 , /* Byte count:    1 */
  639.    
  640.        /* Data bytes for block */
  641.        0x5A,
  642.    
  643.        /* Check Byte: Inverse Synch */
  644.        0x2A,
  645.    
  646.        /* Start of data block */
  647.        0x94, /* Byte address: 20 */
  648.        0x2 , /* Bank address:  2 */
  649.        0x8 , /* Byte count:    8 */
  650.    
  651.        /* Data bytes for block */
  652.        0x3 ,  0x1 ,  0x82,  0xDF,  0x0 ,  0x20,  0x0 ,  0xE0,
  653.    
  654.        /* Check Byte: Inverse Synch */
  655.        0x2A
  656.     };
  657.    
  658.     const char UpdateBitStream3[UpdateSize3] =      //set up array of circuit #3 update bitstream in ROM
  659.     {  //circuit #3 - 3kHz sinewave oscillator. User should replace the update bitstream below with his own
  660.        /* The header for the configuration stream */
  661.        0xD5, /* Synch     */
  662.        chipID, /* Device ID */
  663.        0x5 , /* Control   */
  664.    
  665.        /* Start of data block */
  666.        0xC0, /* Byte address:  0 */
  667.        0x2 , /* Bank address:  2 */
  668.        0xA , /* Byte count:   10 */
  669.    
  670.        /* Data bytes for block */
  671.        0x3 ,  0x1 ,  0x81,  0x8A,  0x1 ,  0x81,  0xE4,  0x0 ,
  672.        0x10,  0xE5,
  673.    
  674.        /* Check Byte: Inverse Synch */
  675.        0x2A,
  676.    
  677.        /* Start of data block */
  678.        0xCE, /* Byte address: 14 */
  679.        0x2 , /* Bank address:  2 */
  680.        0x1 , /* Byte count:    1 */
  681.    
  682.        /* Data bytes for block */
  683.        0x78,
  684.    
  685.        /* Check Byte: Inverse Synch */
  686.        0x2A,
  687.    
  688.        /* Start of data block */
  689.        0x94, /* Byte address: 20 */
  690.        0x2 , /* Bank address:  2 */
  691.        0x8 , /* Byte count:    8 */
  692.    
  693.        /* Data bytes for block */
  694.        0x4 ,  0x1 ,  0x82,  0xC6,  0x0 ,  0x20,  0x0 ,  0xC7,
  695.    
  696.        /* Check Byte: Inverse Synch */
  697.        0x2A
  698.     };
  699.    
  700.     const char UpdateBitStream4[UpdateSize4] =      //set up array of circuit #4 update bitstream in ROM
  701.     {  //circuit #4 - 4kHz sinewave oscillator. User should replace the update bitstream below with his own
  702.        /* The header for the configuration stream */
  703.        0xD5, /* Synch     */
  704.        chipID, /* Device ID */
  705.        0x5 , /* Control   */
  706.    
  707.        /* Start of data block */
  708.        0xC0, /* Byte address:  0 */
  709.        0x2 , /* Bank address:  2 */
  710.        0xA , /* Byte count:   10 */
  711.    
  712.        /* Data bytes for block */
  713.        0x4 ,  0x1 ,  0x81,  0xB7,  0x1 ,  0x81,  0xE3,  0x0 ,
  714.        0x10,  0xE4,
  715.    
  716.        /* Check Byte: Inverse Synch */
  717.        0x2A,
  718.    
  719.        /* Start of data block */
  720.        0xCE, /* Byte address: 14 */
  721.        0x2 , /* Bank address:  2 */
  722.        0x1 , /* Byte count:    1 */
  723.    
  724.        /* Data bytes for block */
  725.        0xB4,
  726.    
  727.        /* Check Byte: Inverse Synch */
  728.        0x2A,
  729.    
  730.        /* Start of data block */
  731.        0x94, /* Byte address: 20 */
  732.        0x2 , /* Bank address:  2 */
  733.        0x8 , /* Byte count:    8 */
  734.    
  735.        /* Data bytes for block */
  736.        0x6 ,  0x1 ,  0x82,  0xDF,  0x0 ,  0x20,  0x0 ,  0xE0,
  737.    
  738.        /* Check Byte: Inverse Synch */
  739.        0x2A
  740.     };
  741.    
  742.    
  743.    
  744.     void msDelay(unsigned int delay)
  745.     {
  746.         unsigned int cycles;
  747.    
  748.         while (delay--)
  749.         {
  750.             cycles = Cycles_per_ms;
  751.             while (cycles--);
  752.         }
  753.     }
  754.    
  755.    
  756.    
  757.     void AN221_Clock(void)
  758.     {
  759.         AN221_DCLK_High;
  760.         AN221_DCLK_Low;
  761.     }
  762.    
  763.    
  764.    
  765.     void AN221_Write(unsigned char data)
  766.     {
  767.         unsigned char bit = 8;
  768.    
  769.         while (bit)
  770.         {
  771.             if (data & 0x80)
  772.                 AN221_DIN_High;     //if MSB=1 then set data pin high
  773.             else
  774.                 AN221_DIN_Low;      //if MSB=0 then set data pin low
  775.             AN221_Clock();          //pulse DCLK once
  776.             data <<= 1;         //left shift the data by 1 bit
  777.             bit--;              //dec the value of bit
  778.         }
  779.         AN221_DIN_Low;              //return DIN low
  780.     }
  781.    
  782.    
  783.    
  784.     void AN221_Reset(unsigned char chip)
  785.     {
  786.         unsigned char i;
  787.    
  788.         if (chip == 0xFF)
  789.         {
  790.             AN221_ERRb_Input;           //make uP drive ERRb
  791.             AN221_ERRb_Low;             //drive ERRb low
  792.             for (i = 0; i < 16; i++)
  793.                 AN221_Clock();          //wait 16 clocks
  794.             AN221_ERRb_High;            //drive ERRb high
  795.             AN221_ERRb_Output;          //make uP sense ERRb again
  796.    
  797.             for (i = 0; i < 32; i++)
  798.                 AN221_Clock();          //send 32 clocks
  799.         }
  800.         else
  801.         {
  802.             for (i = 0; i < 5; i++)
  803.                 AN221_Write(0x00);      //send 5 dummy bytes
  804.    
  805.             AN221_Write(0xD5);          //send synch byte
  806.             AN221_Write(chip);          //send chip ID
  807.             AN221_Write(0x48);          //send 0x48 to control byte to do soft reset
  808.    
  809.             for (i = 0; i < 32; i++)
  810.                 AN221_Clock();          //send 32 clocks
  811.    
  812.             msDelay(35);                //and wait 35mS
  813.         }
  814.     }
  815.    
  816.    
  817.    
  818.     void AN221_Reconfig(char update)
  819.     {
  820.         unsigned char i;
  821.    
  822.         Yellow_LED_ON;                          //turn on yellow LED to show configuration is taking place
  823.         Red_LED_OFF;                            //turn off the red LED
  824.         Green_LED_OFF;                          //turn off the green LED
  825.    
  826.         switch (update)
  827.         {
  828.             case '1':
  829.                 for (i = 0 ; i < UpdateSize1 ; i++)
  830.                     AN221_Write(__elpm_inline(&UpdateBitStream1[i]));   //send update bitstream #1 (from ROM)
  831.                 break;
  832.             case '2':
  833.                 for (i = 0 ; i < UpdateSize2 ; i++)
  834.                     AN221_Write(__elpm_inline(&UpdateBitStream2[i]));   //send update bitstream #2 (from ROM)
  835.                 break;
  836.             case '3':
  837.                 for (i = 0 ; i < UpdateSize3 ; i++)
  838.                     AN221_Write(__elpm_inline(&UpdateBitStream3[i]));   //send update bitstream #3 (from ROM)
  839.                 break;
  840.             case '4':
  841.                 for (i = 0 ; i < UpdateSize4 ; i++)
  842.                     AN221_Write(__elpm_inline(&UpdateBitStream4[i]));   //send update bitstream #4 (from ROM)
  843.                 break;
  844.         }
  845.    
  846.         AN221_Write(0x00);                      //send 1 dummy byte (don't need dummy bytes at start of reconfig)
  847.    
  848.         if (AN221_ACTIVATE && AN221_NO_ERROR)               //if ACTIVATE is high & no error then....
  849.         {
  850.             Green_LED_ON;                       //turn on green LED &...
  851.             Red_LED_OFF;                        //turn off red LED
  852.         }
  853.         else                                //else if ACTIVATE not high or ERRb is low then....
  854.         {
  855.             Red_LED_ON;                     //turn on red LED &...
  856.             Green_LED_OFF;                      //turn off green LED
  857.         }
  858.         Yellow_LED_OFF;                         //configuration over so turn off yellow LED
  859.     }
  860.    
  861.    
  862.    
  863.    
  864.     void AN221_PriConfig(char circuit)
  865.     {
  866.         unsigned int i;
  867.    
  868.         Yellow_LED_ON;                          //turn on yellow LED to show configuration is taking place
  869.         Red_LED_OFF;                            //turn off the red LED
  870.         Green_LED_OFF;                          //turn off the green LED
  871.    
  872.         AN221_Reset(chipID);                        //reset the FPAA
  873.    
  874.         for (i = 0 ; i < 5 ; i++)
  875.             AN221_Write(0x00);                  //send 5 dummy bytes
  876.    
  877.         switch (circuit)
  878.         {
  879.             case '1':
  880.                 for (i = 0 ; i < PrimarySize1 ; i++)
  881.                     AN221_Write(__elpm_inline(&PrimaryBitStream1[i]));  //send config bitstream #1 (from ROM)
  882.                 break;
  883.             case '2':
  884.                 for (i = 0 ; i < PrimarySize2 ; i++)
  885.                     AN221_Write(__elpm_inline(&PrimaryBitStream2[i]));  //send config bitstream #2 (from ROM)
  886.                 break;
  887.             case '3':
  888.                 for (i = 0 ; i < PrimarySize3 ; i++)
  889.                     AN221_Write(__elpm_inline(&PrimaryBitStream3[i]));  //send config bitstream #3 (from ROM)
  890.                 break;
  891.             case '4':
  892.                 for (i = 0 ; i < PrimarySize4 ; i++)
  893.                     AN221_Write(__elpm_inline(&PrimaryBitStream4[i]));  //send config bitstream #4 (from ROM)
  894.                 break;
  895.         }
  896.    
  897.         AN221_Write(0x00);                      //send 1 dummy byte
  898.    
  899.         if (AN221_ACTIVATE && AN221_NO_ERROR)               //if ACTIVATE is high & no error then....
  900.         {
  901.             Green_LED_ON;                       //turn on green LED &...
  902.             Red_LED_OFF;                        //turn off red LED
  903.         }
  904.         else                                //else if ACTIVATE not high or ERRb is low then....
  905.         {
  906.             Red_LED_ON;                     //turn on red LED &...
  907.             Green_LED_OFF;                      //turn off green LED
  908.         }
  909.         Yellow_LED_OFF;                         //configuration over so turn off yellow LED
  910.     }
  911.    
  912.    
  913.     void initialize(void)
  914.     {
  915.         DDRA(0<<DDA2)
  916.         DDRA(0<<DDA3);
  917.         DDRA(0<<DDA4);
  918.         DDRB(1<<DDB0)       //set all port B to outputs to drive LEDs
  919.         DDRB(1<<DDB1)
  920.         DDRB(1<<DDB2)
  921.         DDRF(0<<DDRF0);         //set all port F as inputs for pushbuttons
  922.         DDRF(0<<DDRF1);
  923.         DDRF(0<<DDRF2);
  924.         DDRF(0<<DDRF3);
  925.         PORTA = 0x00;           //disable pull-ups on PA2,3,4
  926.         PORTB = 0xFF;           //all LEDs off
  927.         PORTF = 0xFF;           //enable pull-ups on port F
  928.    
  929.         Red_LED_OFF;            //turn off red LED
  930.         Green_LED_OFF;          //turn off green LED
  931.         Yellow_LED_OFF;         //turn off yellow LED
  932.    
  933.         AN221_DCLK_Low;         //set up initial state of FPAA pins
  934.         AN221_DIN_Low;
  935.         AN221_EXECUTE_Low;
  936.         AN221_CS2b_Low;
  937.    
  938.    
  939.         msDelay(20);            //wait a bit
  940.     }
  941.    
  942.    
  943.     int main(void)
  944.     {
  945.         initialize();                  
  946.    
  947.         AN221_PriConfig('1');               //load circuit #1 as default
  948.    
  949.         while (1)
  950.         {
  951.             msDelay(1000);              //wait a second
  952.    
  953.             if (Pushbutton_1)
  954.                 AN221_Reconfig('1');        //load update 1 if pushbutton 1 pressed
  955.             else if (Pushbutton_2)
  956.                 AN221_Reconfig('2');        //load update 2 if pushbutton 2 pressed
  957.             else if (Pushbutton_3)
  958.                 AN221_Reconfig('3');        //load update 3 if pushbutton 3 pressed
  959.             else if (Pushbutton_4)
  960.                 AN221_Reconfig('4');        //load update 4 if pushbutton 4 pressed
  961.         }
  962.         return 1;
  963.     }
Advertisement
Add Comment
Please, Sign In to add comment