Пример #1
0
int main(void)
{
  time_t then, now;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

  puts("\033[H\033[2JSTR91x A/D Converter Test (" __DATE__ " " __TIME__ ")\n");
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__);

// Turn on peripheral clocks

  SCU_APBPeriphClockConfig(__RTC, ENABLE);
  SCU_APBPeriphClockConfig(__ADC, ENABLE);
  SCU_APBPeriphClockConfig(__GPIO4, ENABLE);

// Configure RTC

  RTC_DeInit();			// Reset RTC

// Configure P4.6 as analog input 6

  GPIO_DeInit(GPIO4);		// Reset GPIO4
  GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);

// Configure A/D converter

  ADC_DeInit();			// Reset A/D converter
  ADC_Cmd(ENABLE);		// Power on A/D converter
  ADC_PrescalerConfig(0x2);	// Conversion clock is 24 MHz

// Sample analog input 6 once a second

  then = 0;

  for (;;)
  {
    now = time(NULL);
    if (now == then) continue;
    then = now;

    printf("The value of A/D input 6 is %04X\n", SampleADC(ADC_Channel_6));
  }
}
Пример #2
0
int main(void)
{
  int status;
  char buf[256];
  uint8_t commandbyte;
  uint8_t responsebyte;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

  printf("\033[H\033[2J%s SPI Master Test (" __DATE__ " " __TIME__ ")\n\n", MCUFAMILYNAME);
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__);

  if ((status = spi_master_init(SPI_PORT, 8, 0, 281250, SPI_MSBFIRST)))
  {
    printf("ERROR: spi_master_init() failed at line %d, %s\n", status, strerror(errno));
    exit(1);
  }

  for (;;)
  {
    printf("Enter a value to send: ");

    gets(buf);
    commandbyte = atoi(buf);

    if ((status = spi_master_transfer(SPI_PORT, &commandbyte, 1, &responsebyte, 1)))
    {
      printf("ERROR: spi_master_transfer() failed at line %d, %s\n", status, strerror(errno));
      exit(1);
    }

    printf("Response was %02X\n\n", responsebyte);
  }
}
Пример #3
0
int main(void)
{
  int i;
  unsigned int myseed;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

  printf("\033[H\033[2J%s Minimal Standard Random Number Generator Test (" __DATE__ " " __TIME__ ")\n\n", MCUFAMILYNAME);
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__);

  myseed = Z1;

  printf("z1 is %d\n", myseed);

  for (i = 0; i < ITERATIONS; i++)
    rand_r(&myseed);

  printf("z%d is %d\n\n", ITERATIONS + 1, myseed);

  if (myseed == Zn)
  {
    puts("SUCCESS!");
  }
  else
  {
    printf("FAILURE! Expected z%d is %d\n", ITERATIONS + 1, Zn);
  }

  exit(0);
}
Пример #4
0
int main(void)
{
  int status;
  char buf[256];
  uint8_t commandbyte;
  uint8_t responsebyte;

  cpu_init(DEFAULT_CPU_FREQ);

  serial_stdio(CONSOLE_PORT);

  puts("\033[H\033[2JSTM32F1 SPI Master Test (" __DATE__ " " __TIME__ ")\n");
  puts(revision);
  printf("\nCPU Freq:%ld Hz  Compiler:%s\n\n", CPUFREQ, __VERSION__);

  if ((status = spimaster_init(SPI_PORT, 0, 281250, TRUE)))
  {
    fprintf(stderr, "ERROR: spimaster_init() failed at line %d, %s\n", status, strerror(errno));
    assert(FALSE);
  }

  for (;;)
  {
    printf("Enter a value to send: ");
    fflush(stdout);
    fflush(stdin);
    gets(buf);
    commandbyte = atoi(buf);

    if ((status = spimaster_transfer(SPI_PORT, &commandbyte, 1, &responsebyte, 1)))
    {
      fprintf(stderr, "ERROR: spimaster_transfer() failed at line %d, %s\n", status, strerror(errno));
      assert(FALSE);
    }

    printf("Response was %02X\n\n", responsebyte);
  }
}
Пример #5
0
int main(void)
{
  xTaskHandle task1;
  xTaskHandle task2;
  xTaskHandle task3;

  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

// Display version information

  printf("\033[H\033[2J%s FreeRTOS Test (" __DATE__ " " __TIME__ ")\n\n", MCUFAMILYNAME);
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s  FreeRTOS:%s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__, tskKERNEL_VERSION_NUMBER);

// Create mutex to arbitrate console output

  console_lock = xSemaphoreCreateMutex();
  if (console_lock == NULL)
  {
    puts("ERROR: xSemaphoreCreateMutex() for console_lock failed!");
    fflush(stdout);
    assert(false);
  }

// Create a couple of tasks

  if (xTaskCreate(putsTaskFunction, (signed char *) "task1", 512, NULL, 1, &task1) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task1 failed!");
    fflush(stdout);
    assert(false);
  }

  if (xTaskCreate(putsTaskFunction, (signed char *) "task2", 512, NULL, 1, &task2) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task2 failed!");
    fflush(stdout);
    assert(false);
  }

  if (xTaskCreate(LEDTaskFunction, (signed char *) "task3", 256, NULL, 1, &task3) != pdPASS)
  {
    puts("ERROR: xTaskCreate() for task3 failed!");
    fflush(stdout);
    assert(false);
  }

  vTaskStartScheduler();
  assert(false);
}
Пример #6
0
int main(void)
{
  cpu_init(DEFAULT_CPU_FREQ);

#ifdef CONSOLE_SERIAL
  serial_stdio(CONSOLE_PORT);
#endif

#ifdef CONSOLE_SEMIHOSTING
  semihosting_stdio(CONSOLE_PORT)
#endif

#ifdef CONSOLE_USB
  usb_serial_stdio(NULL);
  getch();
#endif

  printf("\033[H\033[2J%s C++ Object Test (" __DATE__ " " __TIME__ ")\n\n", MCUFAMILYNAME);
  puts(revision);
  printf("\nCPU Freq:%u Hz  Compiler:%s %s %s\n\n", (unsigned int) SystemCoreClock,
    __COMPILER__, __VERSION__, __ABI__);

// Create some local objects

  testclass1 mytest5 = testclass1(5);

  testclass1 mytest6(6);

  testclass2 mytest7 = testclass2(7);

  testclass2 mytest8(8);

// Test the objects

  if (mytest1.param == 1)
  {
    puts("Object mytest1 was created successfully!");
  }

  if (mytest2.param == 2)
  {
    puts("Object mytest2 was created successfully!");
  }

  if (mytest3.param == 3)
  {
    puts("Object mytest3 was created successfully!");
  }

  if (mytest4.param == 4)
  {
    puts("Object mytest4 was created successfully!");
  }

  if (mytest5.param == 5)
  {
    puts("Object mytest5 was created successfully!");
  }

  if (mytest6.param == 6)
  {
    puts("Object mytest6 was created successfully!");
  }

  if (mytest7.param == 7)
  {
    puts("Object mytest7 was created successfully!");
  }

  if (mytest8.param == 8)
  {
    puts("Object mytest8 was created successfully!");
  }
}