Example #1
0
void APP_Run(void) {
  int value;
  char buffer[64];

#if 0
  for(;;) {
    printf("Hello world!\r\n");
    LEDR_On();
    WAIT1_Waitms(500);
    LEDR_Off();

    LEDG_On();
    WAIT1_Waitms(500);
    LEDG_Off();
  }
#endif

  for(;;) {
    printf("Hello world!\r\n");
    printf("Please enter a name:\n\r");
    scanf("%s", buffer);
    printf("  I have received: '%s'\r\n", buffer);

    printf("Please enter a number:\r\n");
    scanf("%i", &value);
    printf("  I have received: '%i'\r\n", value);
  }
}
Example #2
0
static void CheckStatus(void) {
  switch (FsMSD1_GetDeviceStatus()) {
     case USB_DEVICE_IDLE:
       break;
     case USB_DEVICE_ATTACHED:
       LEDR_Off();
       LEDG_On();
       print((unsigned char*)"Mass Storage Device Attached\n" );
       break;
     case USB_DEVICE_SET_INTERFACE_STARTED:
       break;
     case USB_DEVICE_INTERFACED:
       break;
     case USB_DEVICE_DETACHED:
       LEDR_On();
       LEDG_Off();
       print((unsigned char*)"\nMass Storage Device Detached\n" );
       break;
     case USB_DEVICE_OTHER:
       break;
     default:
       print((unsigned char*)"Unknown Mass Storage Device State\n");
       break;
  } /* switch */
}
Example #3
0
static void CheckButton(void) {
  uint32_t timeTicks; /* time in ticks */
  #define BUTTON_CNT_MS  100  /* iteration count for button */
  bool autoCalibrate = FALSE;

  if (SW1_GetVal()==0) { /* button pressed */
    /* short press (1 beep): start or stop line following if calibrated 
     * 1 s press   (2 beep): calibrate manually
     * 2 s press   (3 beep): calibrate with auto-move
     * 3 s press   (4 beep or more): clear path
     * */
    FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* simple debounce */
    if (SW1_GetVal()==0) { /* still pressed */
      LEDG_On();
      timeTicks = 0;
      while(SW1_GetVal()==0 && timeTicks<=6000/BUTTON_CNT_MS) { 
        FRTOS1_vTaskDelay(BUTTON_CNT_MS/portTICK_RATE_MS);
        if ((timeTicks%(1000/BUTTON_CNT_MS))==0) {
#if PL_HAS_BUZZER
          BUZ_Beep(300, 200);
#endif
        }
        timeTicks++;
      } /* wait until released */
      autoCalibrate = FALSE;
      if (timeTicks<1000/BUTTON_CNT_MS) { /* less than 1 second */
        CLS1_SendStr((unsigned char*)"button press.\r\n", CLS1_GetStdio()->stdOut);
        StateMachine(TRUE); /* <1 s, short button press, according to state machine */
      } else if (timeTicks>=(1000/BUTTON_CNT_MS) && timeTicks<(2000/BUTTON_CNT_MS)) {
        CLS1_SendStr((unsigned char*)"calibrate.\r\n", CLS1_GetStdio()->stdOut);
        APP_StateStartCalibrate(); /* 1-2 s: start calibration by hand */
      } else if (timeTicks>=(2000/BUTTON_CNT_MS) && timeTicks<(3000/BUTTON_CNT_MS)) {
        CLS1_SendStr((unsigned char*)"auto calibrate.\r\n", CLS1_GetStdio()->stdOut);
        APP_StateStartCalibrate(); /* 2-3 s: start auto calibration */
        autoCalibrate = TRUE;
      } else if (timeTicks>=(3000/BUTTON_CNT_MS)) {
        CLS1_SendStr((unsigned char*)"delete solution.\r\n", CLS1_GetStdio()->stdOut);
        MAZE_ClearSolution();
      } 
      while (SW1_GetVal()==0) { /* wait until button is released */
        FRTOS1_vTaskDelay(BUTTON_CNT_MS/portTICK_RATE_MS);
      }
      if (autoCalibrate) {
        CLS1_SendStr((unsigned char*)"start auto-calibration...\r\n", CLS1_GetStdio()->stdOut);
        /* perform automatic calibration */
        WAIT1_WaitOSms(1500); /* wait some time */
        TURN_Turn(TURN_LEFT90);
        TURN_Turn(TURN_RIGHT90);
        TURN_Turn(TURN_RIGHT90);
        TURN_Turn(TURN_LEFT90);
        TURN_Turn(TURN_STOP);
        APP_StateStopCalibrate();
        CLS1_SendStr((unsigned char*)"auto-calibration finished.\r\n", CLS1_GetStdio()->stdOut);
      }
    }
  } /* if */
}
Example #4
0
static portTASK_FUNCTION(Task2, pvParameters) {
	(void) pvParameters;  //parameter not used 
	for (;;) {
		LEDB_Off();
		LEDR_Off();
		LEDG_On();
		//FRTOS1_vTaskDelay(500/portTICK_RATE_MS);
	}
}
Example #5
0
/*
** ===================================================================
**     Method      :  LEDG_SetRatio16 (component LED)
**     Description :
**         Method to specify the duty cycle. If using a PWM pin, this
**         means the duty cycle is set. For On/off pins, values smaller
**         0x7FFF means off, while values greater means on.
**     Parameters  :
**         NAME            - DESCRIPTION
**         ratio           - Ratio value, where 0 means 'off' and
**                           0xffff means 'on'
**     Returns     : Nothing
** ===================================================================
*/
void LEDG_SetRatio16(word ratio)
{
  /* on/off LED: binary on or off */
  if (ratio<(0xffff/2)) {
    LEDG_Off();
  } else {
    LEDG_On();
  }
}
Example #6
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  for(;;) {
    LEDR_On();
    WAIT1_Waitms(500);
    LEDR_Off();
    WAIT1_Waitms(500);

    LEDG_On();
    WAIT1_Waitms(500);
    LEDG_Off();

    LEDB_On();
    WAIT1_Waitms(500);
    LEDB_Off();

    LEDR_SetRatio16(0xc000);
    WAIT1_Waitms(500);
    LEDR_SetRatio16(0x8000);
    WAIT1_Waitms(500);
    LEDR_SetRatio16(0x4000);
    WAIT1_Waitms(500);
    LEDR_SetRatio16(0x1000);
    WAIT1_Waitms(500);
    LEDR_SetRatio16(0x500);
    WAIT1_Waitms(500);
    LEDR_SetRatio16(0x100);
    WAIT1_Waitms(500);
 }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Example #7
0
static void Test(void) {
  UINT bw; /* number of bytes written */

  if (FAT1_isDiskPresent()) { /* if no hardware CardDetect pin is assigned, it will always return TRUE */
    LEDR_On(); /* turn red RGB LED on */
    FAT1_mount(0, &fs); /* mount file system */
    if (!FAT1_isWriteProtected()) { /* if no hardware WritePtotect pin is assigned, it will always return FALSE */
      LEDG_On(); /* turn green RGB LED on */
      if (FAT1_open(&fp, "./test.txt", FA_CREATE_ALWAYS|FA_WRITE)!=FR_OK) { /* open file, will always create it if not already on disk */
        for(;;){} /* error! */
      }
      if (FAT1_write(&fp, "Hello World!", sizeof("Hello World!")-1, &bw)!=FR_OK) { /* write string to file */
        for(;;){} /* error! */
      }
    }
    (void)FAT1_close(&fp); /* close file */
    FAT1_mount(0, NULL); /* unmount file system */
  }
}
Example #8
0
static void StateMachine(bool buttonPress) {
  static uint8_t cnt;
  
  switch (appState) {
    case APP_STATE_INIT:
      LEDG_Off();
      LEDR_On();
      if (buttonPress) {
        APP_StateStartCalibrate(); 
      }
      break;
    case APP_STATE_CALIBRATE:
      cnt++;
      if (cnt>50) {
        cnt = 0;
        LEDR_Neg();
      }
      if (buttonPress) {
        APP_StateStopCalibrate(); 
      }
      break;
    case APP_STATE_IDLE:
      LEDR_Off();
      LEDG_On();
      if (buttonPress) {
        LF_StartFollowing();
        appState = APP_STATE_FOLLOW;
      }
      break;
    case APP_STATE_FOLLOW:
      LEDR_Off();
      LEDG_Off();
      if (!LF_IsFollowing()) {
        appState = APP_STATE_IDLE;
      }
      if (buttonPress) {
        LF_StopFollowing(); 
        appState = APP_STATE_IDLE;
      }
      break;
  } /* switch */
}
Example #9
0
static void StateMachine(bool buttonPress) {
#if PL_APP_FOLLOW_OBSTACLE || PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE
  static uint8_t cnt;
#endif
  
  switch (appState) {
    case APP_STATE_INIT:
      LEDG_Off();
      LEDR_On();
#if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE
      if (buttonPress) {
        APP_StateStartCalibrate(); 
      }
#elif PL_APP_FOLLOW_OBSTACLE
      appState = APP_STATE_IDLE;
#endif
      break;
#if PL_APP_FOLLOW_OBSTACLE
    case APP_STATE_FOLLOW_OBSTACLE:
      cnt++;
      if (cnt>50) {
        cnt = 0;
        LEDR_Neg();
      }
      if (buttonPress) {
        followObstacle = FALSE;
        appState = APP_STATE_IDLE;
      }
      break;
#endif
#if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE
    case APP_STATE_CALIBRATE:
      cnt++;
      if (cnt>50) {
        cnt = 0;
        LEDR_Neg();
      }
      if (buttonPress) {
        APP_StateStopCalibrate(); 
      }
      break;
#endif
    case APP_STATE_IDLE:
      LEDR_Off();
      LEDG_On();
      if (buttonPress) {
#if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE
        LF_StartFollowing();
        appState = APP_STATE_FOLLOW_LINE;
#elif PL_APP_FOLLOW_OBSTACLE
        followObstacle = TRUE;
        appState = APP_STATE_FOLLOW_OBSTACLE;
#endif
      }
      break;
#if PL_APP_LINE_FOLLOWING || PL_APP_LINE_MAZE
    case APP_STATE_FOLLOW_LINE:
      LEDR_Off();
      LEDG_Off();
      if (!LF_IsFollowing()) {
        appState = APP_STATE_IDLE;
      }
      if (buttonPress) {
        LF_StopFollowing(); 
        appState = APP_STATE_IDLE;
      }
      break;
#endif
  } /* switch */
}
Example #10
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 */
    }
  }
}