Esempio n. 1
0
/*
** ===================================================================
**     Method      :  CLS1_KeyPressed (component Shell)
**     Description :
**         Checks if a key has been pressed (a character is present in
**         the input buffer)
**     Parameters  : None
**     Returns     :
**         ---             - Error code
** ===================================================================
*/
bool CLS1_KeyPressed(void)
{
  bool res;

  res = (bool)((AS1_GetCharsInRxBuf()==0U) ? FALSE : TRUE); /* true if there are characters in receive buffer */
  return res;
}
Esempio n. 2
0
File: Events.c Progetto: ducis/HCS
/*
** ===================================================================
**     Event       :  AS1_OnIdle (module Events)
**
**     From bean   :  AS1 [AsynchroSerial]
**     Description :
**         This event is called when an idle condition on the
**         receiver is detected.
**         The event is available only when both <Interrupt
**         service/event> and <Receiver > properties are enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void  AS1_OnIdle(void)
{
  /* Write your code here ... */       
  extern float timecoefficient;
  if(AS1_GetCharsInRxBuf()>0){ 
    unsigned char cmd=255;
    AS1_RecvChar(&cmd);
    if(cmd==0){//handshake
      unsigned char t=0;
      unsigned char rply[2]={0};
      unsigned short x;
      //unsigned char r;
      x=AS1_RecvChar(&t);
      rply[1]=(t+17)&0xff;
      AS1_SendBlock(rply,2,&x);
    }else if(cmd==1){//general query
      word x;
      byte t[4];
      AS1_RecvBlock(t,4,&x);
      AS1_SendBlock((byte*)(t[0]+(t[1]<<8)),t[2]+(t[3]<<8),&x);
    }else if(cmd==2){//inc
      timecoefficient+=0.00001f;
    }else if(cmd==3){//dec
      timecoefficient-=0.00001f;
    }
  }
 /* char cmd=0;
  AS1_RecvChar(&cmd);
  if(cmd==CMD_SETTIMECOEFFICIENT&&AS1_GetCharsInRxBuf()>=sizeof(float)){
    char t=0;
    AS1_RecvBlock((char *)&timecoefficient,sizeof(float),&t);
    if(t!=sizeof(float)){
      //error;
    }
  }else if(cmd==CMD_INC){
    timecoefficient+=0.00001f;
  }else if(cmd==CMD_DEC){
    timecoefficient-=0.00001f;
  }*/
}
Esempio n. 3
0
static uint8_t BL_LoadS19(CLS1_ConstStdIOType *io) {
  unsigned char buf[16];
  uint8_t res = ERR_OK;

  /* first, erase flash */
  if (BL_EraseAppFlash(io)!=ERR_OK) {
    return ERR_FAILED;
  }

  /* load S19 file */
  CLS1_SendStr((unsigned char*)"Waiting for the S19 file...", io->stdOut);
  parserInfo.GetCharIterator = GetChar;
  parserInfo.voidP = (void*)io;
  parserInfo.S19Flash = BL_onS19Flash;
  parserInfo.status = S19_FILE_STATUS_NOT_STARTED;
  parserInfo.currType = 0;
  parserInfo.currAddress = 0;
  parserInfo.codeSize = 0;
  parserInfo.codeBuf = codeBuf;
  parserInfo.codeBufSize = sizeof(codeBuf);
  while (AS1_GetCharsInRxBuf()>0) { /* clear any pending characters in rx buffer */
    AS1_ClearRxBuf();
    WAIT1_Waitms(100);
  }
  do {
    if (S19_ParseLine(&parserInfo)!=ERR_OK) {
      CLS1_SendStr((unsigned char*)"ERROR!\r\nFailed at address 0x", io->stdErr);
      buf[0] = '\0';
      UTIL1_strcatNum32Hex(buf, sizeof(buf), parserInfo.currAddress);
      CLS1_SendStr(buf, io->stdErr);    
      CLS1_SendStr((unsigned char*)"\r\n", io->stdErr);
      res = ERR_FAILED;
      break;
    } else {
      CLS1_SendStr((unsigned char*)"\r\nS", io->stdOut);
      buf[0] = parserInfo.currType;
      buf[1] = '\0';
      CLS1_SendStr(buf, io->stdOut);    
      CLS1_SendStr((unsigned char*)" address 0x", io->stdOut);
      buf[0] = '\0';
      UTIL1_strcatNum32Hex(buf, sizeof(buf), parserInfo.currAddress);
      CLS1_SendStr(buf, io->stdOut);
    }
    if (parserInfo.currType=='7' || parserInfo.currType=='8' || parserInfo.currType=='9') {
      /* end of records */
      break;
    }
  } while (1);
  if (res==ERR_OK) {
    CLS1_SendStr((unsigned char*)"\r\ndone!\r\n", io->stdOut);
  } else {
    while (AS1_GetCharsInRxBuf()>0) {/* clear buffer */
      AS1_ClearRxBuf();
      WAIT1_Waitms(100);
    }
    CLS1_SendStr((unsigned char*)"\r\nfailed!\r\n", io->stdOut);
    /* erase flash again to be sure we do not have illegal application image */
    if (BL_EraseAppFlash(io)!=ERR_OK) {
      res = ERR_FAILED;
    }
  }
  return res;
}
Esempio n. 4
0
 static bool UART_KeyPressed(void) {
   return AS1_GetCharsInRxBuf()!=0;
 }
Esempio n. 5
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 */
    }
  }
}