예제 #1
0
static void Run(void) {
  bool doSampling = FALSE;
  bool triggered = FALSE;
  uint32_t heartBeat;
  frequencyDivider freqDivider; // supported from V1.02
  unsigned long data;
  unsigned char cmd;
  int i = 0;

  // prepare SUMP variables
  triggerData[0].mask = 0;
  triggerData[0].values = 0;
  triggerData[0].configuration = 0;
  triggerData[1].mask = 0;
  triggerData[1].values = 0;
  triggerData[1].configuration = 0;
  triggerData[2].mask = 0;
  triggerData[2].values = 0;
  triggerData[2].configuration = 0;
  triggerData[3].mask = 0;
  triggerData[3].values = 0;
  triggerData[3].configuration = 0;
  // and preset Timer
  setSampleFrequency(DEFAULT_CLOCK_DIVIDER);
  heartBeat = DEFAULT_HEARTBEAT_COUNTER;
  for(;;) {
    i++;
    if (i > heartBeat) { /* heartbeat LED (red) if not sampling */
      if (!doSampling) {
        LEDR_Neg();
      }
      i = 0;
    }
    if (finishedSampling) {
      finishedSampling = FALSE;
      doSampling = FALSE;
      triggered = FALSE;
      SendData();
      LEDR_Off();
      LEDG_Off();
    }
    if (AS1_GetCharsInRxBuf()!=0) {
      cmd = GetChar();
      switch (cmd) {
        case SUMP_RESET:
          finishedSampling = FALSE;
          doSampling = FALSE;
          triggered = FALSE;
          LEDR_Off();
          LEDG_Off();
          break;
        case SUMP_RUN:
          bufferSize = BUFFERSIZE;
          finishedSampling = FALSE;
          doSampling = TRUE;
          if (triggerData[0].mask==0) { // no trigger active, simply start sampling
            LEDR_Off();
            //LEDB_On();
            triggered = TRUE;
            TransferDMA();
          } else {
            LEDR_Off();
            LEDG_On();
            while (!triggered) {
              // Use short (fast) loop to detect trigger
              data = (Byte1_GetVal() & 0xFF);
              /* for now, we support only reading from 8 Probes
               data = ( Byte2_GetVal() & 0xFF ) << 8;
               data = ( Byte3_GetVal() & 0xFF ) << 16;
               data = ( Byte4_GetVal() & 0xFF ) << 24;
               */
              /* use this, if single condition mask (AND) needed */
              if (!triggered && triggerData[0].mask != 0) {
                if ((data & triggerData[0].mask) == triggerData[0].values) { /* matching trigger */
                  /* use this, if multiple conditions (OR) are needed
                   for (i = 0; i < DEVICE_NOF_PROBES; i++)
                   { // we can handle all supported 32 Bits
                   if ((triggerData[0].mask & 1 << i) > 0)
                   { // if mask bit is set, check if values bit meets the probe bit
                   if ((triggerData[0].values & 1 << i)
                   == (data & 1 << i))
                   { // yes, we start if any trigger bit meets condition (primitive trigger only)
                   */
                  LEDG_Off();
                  //LEDB_On();
                  triggered = TRUE;
                  // enable DMA AND Trigger first transfer to pick up Trigger
                  // port value from Port
                  // TODO: replace trigger handling by GPIO external trigger
                  //       for Level and Edge
                  TransferDMA();
                  break;
                } /* if */
              } /* if */
              // BUT : do not lockup the analyzer!!!
              if (AS1_GetCharsInRxBuf()!= 0 && GetChar() == SUMP_RESET) {
                finishedSampling = FALSE;
                doSampling = FALSE;
                triggered = FALSE;
                //LEDB_Off();
                LEDG_Off();
                break; // leave the While(!triggered) loop 
              } /* while */
            } /* while */
          } /* if-else */
          break;
        case SUMP_ID:
          PutString("1ALS");
          break;
        case SUMP_GET_METADATA:
          /* device name: */
          PutChar(0x01);
          PutString(DEVICE_NAME);
          PutChar(0x00);
          /* 'Firmware version: */
          PutChar(0x02);
          PutString(DEVICE_FW_VERSION);
          PutChar(0x00);
          /* 'Ancillary' version: */
          PutChar(0x03);
          PutString(DEVICE_ANCILLARY);
          PutChar(0x00);
          /* amount of sample memory available (bytes) */
          SUMP_sendmeta_uint32(0x21, BUFFERSIZE);
          /* maximum sample rate (Hz) */
          SUMP_sendmeta_uint32(0x23, MAX_SAMPLERATE);
          /* number of usable probes (short) */
          SUMP_sendmeta_uint8(0x40, DEVICE_NOF_PROBES);
          /* protocol version (short) */
          SUMP_sendmeta_uint8(0x41, DEVICE_PROTOCOL_VERSION);
          /* end of meta data */
          PutChar(0x00);
          break;
          /* long commands.. consume bytes from UART, NYI */
  
        /* Set Trigger Mask*/
        case 0xC0:
          triggerData[0].mask = GetChar();
          triggerData[0].mask |= GetChar() << 8;
          triggerData[0].mask |= GetChar() << 16;
          triggerData[0].mask |= GetChar() << 24;
          break;
        case 0xC4:
          triggerData[1].mask = GetChar();
          triggerData[1].mask |= GetChar() << 8;
          triggerData[1].mask |= GetChar() << 16;
          triggerData[1].mask |= GetChar() << 24;
          break;
        case 0xC8:
          triggerData[2].mask = GetChar();
          triggerData[2].mask |= GetChar() << 8;
          triggerData[2].mask |= GetChar() << 16;
          triggerData[2].mask |= GetChar() << 24;
          break;
        case 0xCC:
          triggerData[3].mask = GetChar();
          triggerData[3].mask |= GetChar() << 8;
          triggerData[3].mask |= GetChar() << 16;
          triggerData[3].mask |= GetChar() << 24;
          break;
  
        /* Set Trigger Values */
        case 0xC1:
          triggerData[0].values = GetChar();
          triggerData[0].values |= GetChar() << 8;
          triggerData[0].values |= GetChar() << 16;
          triggerData[0].values |= GetChar() << 24;
          break;
        case 0xC5:
          triggerData[1].values = GetChar();
          triggerData[1].values |= GetChar() << 8;
          triggerData[1].values |= GetChar() << 16;
          triggerData[1].values |= GetChar() << 24;
          break;
        case 0xC9:
          triggerData[2].values = GetChar();
          triggerData[2].values |= GetChar() << 8;
          triggerData[2].values |= GetChar() << 16;
          triggerData[2].values |= GetChar() << 24;
          break;
        case 0xCD:
          triggerData[3].values = GetChar();
          triggerData[3].values |= GetChar() << 8;
          triggerData[3].values |= GetChar() << 16;
          triggerData[3].values |= GetChar() << 24;
          break;
          /* Set Trigger Configuration */
        case 0xC2:
          triggerData[0].configuration = GetChar();
          triggerData[0].configuration |= GetChar() << 8;
          triggerData[0].configuration |= GetChar() << 16;
          triggerData[0].configuration |= GetChar() << 24;
          break;
        case 0xC6:
          triggerData[1].configuration = GetChar();
          triggerData[1].configuration |= GetChar() << 8;
          triggerData[1].configuration |= GetChar() << 16;
          triggerData[1].configuration |= GetChar() << 24;
          break;
        case 0xCA:
          triggerData[2].configuration = GetChar();
          triggerData[2].configuration |= GetChar() << 8;
          triggerData[2].configuration |= GetChar() << 16;
          triggerData[2].configuration |= GetChar() << 24;
          break;
        case 0xCE:
          triggerData[3].configuration = GetChar();
          triggerData[3].configuration |= GetChar() << 8;
          triggerData[3].configuration |= GetChar() << 16;
          triggerData[3].configuration |= GetChar() << 24;
          break;
        case SUMP_SET_DIVIDER:
          // preliminary; received divider values seems to need more testing
          freqDivider = GetChar();
          freqDivider |= GetChar() << 8;
          freqDivider |= GetChar() << 16;
          (void)GetChar();
          setSampleFrequency(freqDivider);
          break;
        case SUMP_SET_READ_DELAY_COUNT:
          rdCount = GetChar();
          rdCount |= GetChar() << 8;
          rdCount |= GetChar() << 16;
          rdCount |= GetChar() << 24;
          break;
          /* Set Flag */
        case SUMP_SET_FLAGS:
          flags = GetChar();
          flags |= (GetChar() << 8);
          flags |= (GetChar() << 16);
          flags |= (GetChar() << 24);
          break;
        default:
          break;
      } /* switch */
    }
  }
}
예제 #2
0
JNIEXPORT jint JNICALL Java_com_starlab_component_processor_jni_JNIderivative_nativeSetSampleFrequency
  (JNIEnv *env, jobject obj, jint id, jint sampleFrequency)
{
	return setSampleFrequency(id, sampleFrequency);
}