Beispiel #1
0
/**
 * @brief Main function
 * @return None
 */
int main(void) {

  COMM_Init(COMM_BAUD_RATE); // initialize communication with PC
  println("***********************************************");
  println("Starting program"); // Print a string to terminal

  TIMER_Init(SYSTICK_FREQ); // Initialize timer

  // Add a soft timer with callback running every 1000ms
  int8_t timerID = TIMER_AddSoftTimer(1000, softTimerCallback);
  TIMER_StartSoftTimer(timerID); // start the timer

  LED_Init(LED0); // Add an LED
  LED_Init(LED1); // Add an LED
  LED_Init(LED2); // Add an LED
  LED_Init(LED3); // Add an LED
  LED_Init(LED5); // Add nonexising LED for test
  LED_ChangeState(LED5, LED_ON);

  KEYS_Init(); // Initialize matrix keyboard

  uint8_t buf[255]; // buffer for receiving commands from PC
  uint8_t len;      // length of command

  // test another way of measuring time delays
  uint32_t softTimer = TIMER_GetTime(); // get start time for delay
  SD_Init();
//  FAT_Init(SD_Init, SD_ReadSectors, SD_WriteSectors);

  // Initialize USB device stack
  USBD_Init(&USB_OTG_dev,
            USB_OTG_FS_CORE_ID,
            &USR_desc,
            &USBD_MSC_cb,
            &USR_cb);

  while (1) {

    // test delay method
    if (TIMER_DelayTimer(1000, softTimer)) {
      LED_Toggle(LED3);
      softTimer = TIMER_GetTime(); // get start time for delay
    }

    // check for new frames from PC
    if (!COMM_GetFrame(buf, &len)) {
      println("Got frame of length %d: %s", (int)len, (char*)buf);

      // control LED0 from terminal
      if (!strcmp((char*)buf, ":LED0 ON")) {
        LED_ChangeState(LED0, LED_ON);
      }
      if (!strcmp((char*)buf, ":LED0 OFF")) {
        LED_ChangeState(LED0, LED_OFF);
      }
    }

    TIMER_SoftTimersUpdate(); // run timers
    key = KEYS_Update(); // run keyboard

  }
}
Beispiel #2
0
int main(void)
{
	
	UART2_Init(); // Initialize USART2 (for printf)
	TIMER_Init(SYSTICK_FREQ); // Initialize timer

	int8_t timerID = TIMER_AddSoftTimer(1000,softTimerCallback);
	TIMER_StartSoftTimer(timerID);

	LED_TypeDef led;
	led.nr    = LED0;
	led.gpio  = GPIOD;
	led.pin   = 12;
	led.clk   = RCC_AHB1Periph_GPIOD;

	LED_Add(&led); // Add an LED

	printf("Starting program\r\n"); // Print a string to UART2

//	SD_Init();
//
//	uint8_t buf[1024];
//
//	SD_ReadSectors(buf, 0, 1);
//
//	TIMER_Delay(1000);
//	hexdump(buf, 512);
//
//	printf("After hexdump\r\n");

	FAT_Init(SD_Init, SD_ReadSectors, SD_WriteSectors);

//	FATFS FatFs;
//	FIL file;
//	FRESULT result;
//
//	char buf[256];
//
//	printf("Mounting volume\r\n");
//	result = f_mount(&FatFs, "", 1); // Mount SD card
//
//	if (result) {
//		printf("Error mounting volume!\r\n");
//		while(1);
//	}
//
//	printf("Opening file: \"hello.txt\"\r\n");
//	result = f_open(&file, "hello.txt", FA_READ);
//
//	if (result) {
//		printf("Error opening file!\r\n");
//		while(1);
//	}
//
//	f_gets((char*)buf, 256, &file);
//
//	printf("The file contains the following text:\r\n\"%s\"\r\n", buf);
//
//	f_close(&file); // Close file
//	f_mount(NULL, "", 1); // Unmount SD Card
	
	while (1){  
		TIMER_SoftTimersUpdate();
	}
}