Changeset 12147 for fact/tools


Ignore:
Timestamp:
09/21/11 17:24:15 (13 years ago)
Author:
neise
Message:
Now ARDUINO_FTDI can work like the former UM245R FIFO
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/hvMCUtest/ARDUINO_FTDI/ARDUINO_FTDI.pde

    r12143 r12147  
    2929*/
    3030//define non transferable variables
    31 #define NUMCHANNELS 416
     31#define MAXBOARDS 13
     32#define EXISTINGBOARDS 10
     33#define CHPERBOARD 32
     34#define NUMCHANNELS EXISTINGBOARDS*CHPERBOARD
    3235#define BLANKBYTE 0x00
    3336#define READSTATEBYTE 0x20
     
    4043
    4144typedef enum {
     45  set_message,
     46  send_message,
     47  get_message,
     48  pc_serial,
     49  parsing
     50} state_contr; //Type to define what microcontroller should do
     51
     52typedef enum {
    4253  channel_status,
    4354  sys_reset,
    4455  global_set,
    4556  channel_set
    46 } function_t;
     57} function_t; //Type to define which function of PLD shell be build
    4758
    4859typedef enum {
    49   set_message,
    50   send_message,
    51   get_message
    52 } state_contr;
     60  transmit_PLD_answer,
     61  get_request,
     62} communication; //Type to define communication with PC
     63
    5364
    5465const unsigned char wr  =  2;
     
    5970volatile unsigned char databus = 0x00; //temp. memory for Reading Databus interrupt
    6071unsigned char message[3];       //field where the 3 Byte message is saved
    61 unsigned char messageindex=0;   //index of field
    62 
     72unsigned char messageindex = 0; //index of field
     73unsigned char incommingByte = 0;  //for incomming serial Data
    6374unsigned int recent_voltages[NUMCHANNELS];  //The actual Voltage of each channel is saved in this variable
    6475unsigned int set_voltage;                   //The Value to which channel shell be set is saved in the variable
     
    6879
    6980function_t function;
    70 state_contr state_controler = set_message;
     81state_contr state_controler;
     82communication pc_com = get_request;
    7183
    7284//unsigned char call_function;                //variable to call a funtion
     
    98110function = channel_set;
    99111set_voltage = 0xaaa;
    100 state_controler = set_message; //just for development
     112state_controler = pc_serial; //just for development
    101113digitalWrite(FREE1, LOW);
    102114
     
    141153    }
    142154    if ( state_controler == send_message){
     155        //Serial.print ("sending message");
    143156            //RisingEdge_RD = false;
    144157    //This is the FIFO Read Cycle, PLD reads from FIFO, ARDUINO writes to FIFO
     
    203216                        message[messageindex] = databus;
    204217                        messageindex = 0;
    205                         state_controler = set_message;
     218                        state_controler = pc_serial;
     219                        pc_com = transmit_PLD_answer;
    206220                        break;
    207221            }
     
    213227
    214228  // delay(1000); //slow down process for test pourpose
     229
     230// Communication with PC via USB
     231    if ( state_controler == pc_serial){
     232
     233    // Outgoing Commands
     234    switch ( pc_com ){
     235        //report PLD response to PC
     236        case transmit_PLD_answer:
     237            Serial.println("PLD answered: ");
     238            for (messageindex = 0; messageindex < 3; messageindex++){
     239            Serial.print(message[messageindex], BIN);
     240            Serial.print( "\t" );
     241            }
     242            Serial.println(" in BIN ");
     243            for (messageindex = 0; messageindex < 3; messageindex++){
     244            Serial.print(message[messageindex], HEX);
     245            Serial.print( "\t" );
     246            }
     247            messageindex = 0;
     248            Serial.println(" in HEX ");
     249            Serial.println( "_______________________ " );
     250            pc_com = get_request;
     251            break;
     252
     253    // Incoming Commands
     254        case get_request:
     255            while (Serial.available() < 3){};
     256            if (Serial.available() > 0){
     257                Serial.print("I received: ");
     258                messageindex = 0;
     259                while (messageindex < 3){
     260                message[messageindex] = Serial.read();
     261                Serial.print( "0x" );
     262                Serial.print(message[messageindex], HEX);
     263                messageindex++;
     264                Serial.print( " " );
     265                }
     266                messageindex = 0;
     267                //Serial.print(incommingByte, BYTE);
     268                Serial.println(",du Nase!");
     269                }
     270                state_controler = send_message;
     271            break;
     272
     273    }
     274
     275    }
     276
    215277}
    216278
Note: See TracChangeset for help on using the changeset viewer.