Beispiel #1
0
int main() {
  trace_puts(">>> VfdClock main() init");
  initGpio();
  initRtc();
  initTimer();
  initUart();
  SysTick_Config(72000);  // 1kHz
  trace_puts("<<< VfdClock main() init");

  GPIO_WriteBit(LED_PORT, LED_PIN, RESET);

  // Disable buzzer.
  GPIO_WriteBit(BUZ_PORT, BUZ_PIN, RESET);
  TIM_Cmd(TIM3, DISABLE);

  backupLoad();

  uint8_t digits[6] = {
      DIGIT_BLANK, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_BLANK};
  setDisplay(digits);

  gSeconds = RTC_GetCounter();

  time_t localtime;
  struct tm *t = gmtime(&gSeconds);

  // Logic loop.
  while (1) {
    // Read GPS data, if it exists.
    if (strlen(gGpsLine) > 0) {
      handleGpsLine();
    } else if (gGpsNextPoll < gSeconds) {
      gpsSetPushFreq("ZDA", 2);
    }

    handleDigits(digits, t);
    handleButtonPress();

    if (gSecondFlag) {
      gSecondFlag = 0;
      localtime = gSeconds + gUtcOffset;
      t = gmtime(&localtime);
      handleDigits(digits, t);
      setDisplay(digits);
      // Blink decimal point.
      GPIO_WriteBit(DP_PORT, DP_PIN, SET);
      gDpTick = 500;
    }
  }
}
Beispiel #2
0
int
main(int argc, char* argv[])
{
  // Send a greeting to the trace device (skipped on Release).
  trace_puts("Hello ARM World!");

  // At this stage the system clock should have already been configured
  // at high speed.
  trace_printf("System clock: %u Hz\n", SystemCoreClock);

  timer_start();

  blink_led_init();
  
  uint32_t seconds = 0;

  // Infinite loop
  while (1)
    {
      blink_led_on();
      timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);

      blink_led_off();
      timer_sleep(BLINK_OFF_TICKS);

      ++seconds;

      // Count seconds on the trace device.
      trace_printf("Second %u\n", seconds);
    }
  // Infinite loop, never return.
}
Beispiel #3
0
int main(int argc, char* argv[]) {

	// Send a greeting to the trace device (skipped on Release).
	trace_puts("Hello ARM World!");


	// At this stage the system clock should have already been configured
	// at high speed.
	trace_printf("System clock: %uHz\n", SystemCoreClock);


	/* Configure GPIO's to AN to reduce power consumption */
	GPIO_ConfigAN();

	/* Initialize LED1 */
	BSP_LED_Init(LED1);

	/* Create the queue used by the two threads */
	osMessageQDef(osqueue, QUEUE_LENGTH, uint16_t);
	osQueue = osMessageCreate (osMessageQ(osqueue), NULL);

	/* Note the Tx has a lower priority than the Rx when the threads are
		  spawned. */
	osThreadDef(RxThread, QueueReceiveThread, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
	osThreadCreate(osThread(RxThread), NULL);

	osThreadDef(TxThread, QueueSendThread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE);
	osThreadCreate(osThread(TxThread), NULL);

	/* Start scheduler */
	osKernelStart (NULL, NULL);

	/* We should never get here as control is now taken by the scheduler */
	for(;;);
}
/**
* @brief This function handles CAN2 RX0 interrupts.
*/
void CAN2_RX0_IRQHandler(void)
{
  /* USER CODE BEGIN CAN2_RX0_IRQn 0 */

  /* USER CODE END CAN2_RX0_IRQn 0 */
  trace_puts("Get a message from CAN2!");
  HAL_CAN_IRQHandler(&hcan2);
  /* USER CODE BEGIN CAN2_RX0_IRQn 1 */

  /* USER CODE END CAN2_RX0_IRQn 1 */
}
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{

  trace_puts("Run into USART1_IRQHandler!");
  /* USER CODE BEGIN USART1_IRQn 0 */

  /* USER CODE END USART1_IRQn 0 */
  HAL_UART_IRQHandler(&huart1);
  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}
Beispiel #6
0
_exit(int code __attribute__((unused)))
{
#if !defined(DEBUG)
  __reset_hardware();
#else
  extern void HardFault_Handler(void);
  trace_puts("Debug. Emulate hard fault for debug trace.");
  HardFault_Handler();
#endif

  // TODO: write on trace
  while (1)
    ;
}
Beispiel #7
0
int
main(int argc, char* argv[])
{

  int x;
	// Show the program parameters (passed via semihosting).
  // Output is via the semihosting output channel.
  trace_dump_args(argc, argv);

  // Send a greeting to the trace device (skipped on Release).
  trace_puts("Hello ARM World!");

  // Send a message to the standard output.
  puts("Standard output message.");

  // Send a message to the standard error.
  fprintf(stderr, "Standard error message.\n");

  // At this stage the system clock should have already been configured
  // at high speed.
  trace_printf("System clock: %uHz\n", SystemCoreClock);

  timer_start();

  blink_led_init();
  
  uint32_t seconds = 0;

  printf("input x\r\n");
  scanf("%d",&x);
  printf("%d",x);

  test_read_file_from_host("d:/test.txt");
  // Infinite loop
  while (1)
    {
      blink_led_on();
      timer_sleep(BLINK_ON_TICKS);

      blink_led_off();
      timer_sleep(BLINK_OFF_TICKS);

      ++seconds;

      // Count seconds on the trace device.
      trace_printf("Second %u\n", seconds);
    }
  // Infinite loop, never return.
}
Beispiel #8
0
int
main (void)
{
 trace_puts (PROJNAME);

 initIO();
 initIRQ();
 initDWT();
 initSPI();

 PCD8544_Init (0x38);

 char buf[25];
 struct time_types tm;
 uint8_t x, y;

 PCD8544_GotoXY (0, 0);
 PCD8544_Puts ("SirVolta's", PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
 PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + PCD8544_CHAR5x7_HEIGHT + 1);
 PCD8544_Puts ("Library", PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
 PCD8544_GotoXY (0, PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT * 2) + 1);
 PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) - (PCD8544_CHAR5x7_HEIGHT  / 2));
 PCD8544HorizontalLine(PCD8544_GetX_Y(PCD8544_Pos_Y) + (PCD8544_CHAR5x7_HEIGHT + 3));

 for (uint8_t i = 10; i > 2; i -= 2)
  PCD8544_DrawCircle(65, 10, i, PCD8544_Pixel_Set);
 PCD8544_DrawFilledCircle(65, 10, 2, PCD8544_Pixel_Set);

 PCD8544_Refresh ();

 PCD8544_GetXY(&x, &y);
 while (1)
  {
   GPIO_ToggleBits(LEDPORT, LEDPIN);
   delayMs(1000);

   tm.seconds = (uint32_t)(uptime_ms / 1000);
   secondsToTime(&tm);
   sprintf(buf, "%.2lud%.2luh%.2lum%.2lus\n", tm.days, tm.hours, tm.minutes, tm.seconds);


   //clear line of text, then print it to display
   PCD8544_DrawFilledRectangle(x, y, x + PCD8544_WIDTH, y + PCD8544_CHAR5x7_HEIGHT, PCD8544_Pixel_Clear);
   PCD8544_GotoXY (x, y);
   PCD8544_Puts (buf, PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
   PCD8544_Refresh ();
  }
}
Beispiel #9
0
int8_t submit_system_task(void (*task)(), uint32_t interval, uint8_t is_repeating)
{
	for(uint16_t i=0; i<MAX_SYS_TASKS; i++)
	{
		if (system.task[i].task == NULL)
		{
			system.task[i].task 		= task;
			system.task[i].is_repeating	= is_repeating;
			system.task[i].interval		= interval;
			system.task[i].next_call	= system.sys_ms + (uint64_t) interval;
			return 0;
		}
	}
	trace_puts("\r\nERROR System Queue Overflown.");
	return -1;
}
Beispiel #10
0
/**
 * @brief  Main program
 * @param  None
 * @retval None
 */
int main(void)
{
  /* This sample code shows how to use GPIO HAL API to toggle LED2 IO
   in an infinite loop. */

  /* STM32F103xB HAL library initialization:
   - Configure the Flash prefetch
   - Systick timer is configured by default as source of time base, but user
   can eventually implement his proper time base source (a general purpose
   timer for example or other time source), keeping in mind that Time base
   duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
   handled in milliseconds basis.
   - Set NVIC Group Priority to 4
   - Low Level Initialization
   */
  HAL_Init();

  /* Configure the system clock to 64 MHz */
  SystemClock_Config();

  /* -1- Enable GPIO Clock (to be able to program the configuration registers) */
  LED2_GPIO_CLK_ENABLE()
  ;

  /* -2- Configure IO in output push-pull mode to drive external LEDs */
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Pin = LED2_PIN;
  HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);

  trace_puts("Hello ARM World!");

  int seconds = 0;

  /* -3- Toggle IO in an infinite loop */
  while (1)
  {
    HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
    /* Insert delay 200 ms */
    HAL_Delay(200);

    trace_printf("Second %d\n", ++seconds);
  }
}
Beispiel #11
0
int main(void)
{
  // By customising __initialize_args() it is possible to pass arguments,
  // for example when running tests with semihosting you can pass various
  // options to the test.
  // trace_dump_args(argc, argv);

  // Send a greeting to the trace device (skipped on Release).
  trace_puts("Hello ARM World!");

  // The standard output and the standard error should be forwarded to
  // the trace device. For this to work, a redirection in _write.c is
  // required.
  puts("Standard output message.");
  fprintf(stderr, "Standard error message.\n");

  // At this stage the system clock should have already been configured
  // at high speed.
  //trace_printf("System clock: %uHz\n", SystemCoreClock);

  //timer_start();
  HAL_Init();
  blink_led_init();
  
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  blink_led_off();
  // Infinite loop
  while (1)
    {
      blink_led_on();
      HAL_Delay(1000);
      //timer_sleep(BLINK_ON_TICKS);
      //delay(1000U);
      blink_led_off();
      //timer_sleep(BLINK_OFF_TICKS);
      HAL_Delay(1000);
      // Count seconds on the trace device.
      trace_printf("Second\n");
    }
  // Infinite loop, never return.
}
Beispiel #12
0
int
main(int argc, char* argv[])
{
  // Send a greeting to the trace device (skipped on Release).
  trace_puts("Hello ARM World!");

  // At this stage the system clock should have already been configured
  // at high speed.
  trace_printf("System clock: %uHz\n", SystemCoreClock);

  Timer timer;
  timer.start();

  BlinkLed blinkLed;

  // Perform all necessary initialisations for the LED.
  blinkLed.powerUp();

  uint32_t seconds = 0;

  // Infinite loop
  while (1)
    {
      blinkLed.turnOn();
      timer.sleep(BLINK_ON_TICKS);

      blinkLed.turnOff();
      timer.sleep(BLINK_OFF_TICKS);

      ++seconds;

      // Count seconds on the trace device.
      trace_printf("Second %u\n", seconds);
    }
  // Infinite loop, never return.
}
Beispiel #13
0
abort(void)
{
  trace_puts("abort(), exiting...");

  _exit(1);
}
Beispiel #14
0
/// Handle GPS data containing well synchronized time.
void handleGpsLine() {
  if (memcmp("$GPZDA,", gGpsLine, 7)) {
    trace_puts("Ignoring unknown GPS line:");
    trace_puts(gGpsLine);
    gGpsLine[0] = 0x00;
    return;
  }

  char *chkStart = strstr(gGpsLine, "*") + 1;
  uint8_t theirChk = strtol(chkStart, 0, 16);

  uint8_t chk = 0;
  for (uint8_t i = 1; ; i++) {
    if (gGpsLine[i] == 0x00) break;
    if (gGpsLine[i] == '*') break;
    chk ^= gGpsLine[i];
  }

  if (theirChk != chk) {
    trace_printf("Ignoring checksum mismatch: %02x / %02x\n", theirChk, chk);
    trace_puts(gGpsLine);
    gGpsLine[0] = 0x00;
    return;
  }

  // It just so happens that for the one line (ZDA) we want to handle, just
  // to get the time, it's always fixed length for all fields:
  //
  // 0         1         2         3
  // $GPZDA,,,,,00,00*48
  // $GPZDA,222544.00,24,08,2015,00,00*69
  // $GPZDA,231207.00,24,08,2015,00,00*6B
  //
  // Namely:
  //  - hhmmss.ss time
  //  - dd day
  //  - mm month
  //  - yyyy year
  //  - xx unsupported local hours
  //  - xx unsupported local minutes
  // So we can use very simple parsing techniques, just grab the characters
  // by fixed index!  We only have to prepare by discerning the empty from
  // the full format.

  if (gGpsLine[7] == ',') {
    trace_puts("Ignoring ZDA line with no fix.");
    trace_puts(gGpsLine);
    gGpsLine[0] = 0x00;
    return;
  }

  trace_puts("Setting time from GPS line:");
  trace_puts(gGpsLine);

  struct tm *t = gmtime(&gSeconds);
  uint32_t hms = strtol(gGpsLine + 7, 0, 10);
  t->tm_hour = (hms / 10000);
  t->tm_min = (hms / 100) % 100;
  t->tm_sec = hms % 100;
  t->tm_mday = strtol(gGpsLine + 17, 0, 10);
  t->tm_mon = strtol(gGpsLine + 20, 0, 10);
  t->tm_year = strtol(gGpsLine + 23, 0, 10) - 1900;

  setRtcTime(mktime(t));
  gpsSetPushFreq("ZDA", 0);
  gGpsNextPoll = gSeconds + 3593;
  gGpsAvailable = 1;

  // Empty the string to indicate we've processed it.
  gGpsLine[0] = 0x00;
}
Beispiel #15
0
/// Given gButtonPressed, update state accordingly.
void handleButtonPress() {
  switch (gButtonPressed) {
  case BTN_NONE:
    break;
  case BTN_MAPLE:
    trace_puts("Maple button!");
    gGpsAvailable = !gGpsAvailable;
    break;
  case BTN_SET:
    if (gGpsAvailable) {
      gSettingUtcOffset = !gSettingUtcOffset;
      trace_printf("Set button; setting utc offset=%d\n", gSettingUtcOffset);
      gSecondFlag |= !gSettingUtcOffset;
    } else {
      gBlinkPos += 1;
      if (gBlinkPos > 5) {
        gBlinkPos = 0;
        gSecondFlag = 1;  // Force logic loop to display digits.
      }
      trace_printf("Set button; new pos %d\n", gBlinkPos);
    }
    break;
  case BTN_DIM:
    gGridOc.TIM_Pulse += 10;
    gGridOc.TIM_Pulse %= 80;
    TIM_OC1Init(TIM2, &gGridOc);
    trace_printf("Dim button; pulse now %d of 80.\n", gGridOc.TIM_Pulse);
    backupSave();
    break;
  case BTN_UP:
    trace_puts("Up button!");
    if (gSettingUtcOffset) {
      gUtcOffset += UTC_OFFSET_ADJUST;
      if (gUtcOffset > (14 * 3600)) gUtcOffset = -12 * 3600;
      trace_printf("utc offset now=%d\n", gUtcOffset);
      backupSave();
    } else {
      gSeconds = RTC_GetCounter() + gSettingChange[gBlinkPos];
      setRtcTime(gSeconds);
    }
    gSecondFlag = 1;
    break;
  case BTN_DOWN:
    trace_puts("Down button!");
    if (gSettingUtcOffset) {
      gUtcOffset -= UTC_OFFSET_ADJUST;
      if (gUtcOffset < (-12 * 3600)) gUtcOffset = 14 * 3600;
      trace_printf("utc offset now=%d\n", gUtcOffset);
      backupSave();
    } else {
      gSeconds = RTC_GetCounter() - gSettingChange[gBlinkPos];
      setRtcTime(gSeconds);
    }
    gSecondFlag = 1;
    break;
  default:
    // No button pressed, ignore.
    break;
  }
  gButtonPressed = BTN_NONE;
}
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Timer Init for SysTick */
	timer_start();

	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on FS port.. */
	TM_USBD_CDC_Init(TM_USB_FS);
	
	/* Start USB device mode on FS port.. */
	TM_USBD_Start(TM_USB_FS);
	
	while (1) {
		/* Process USB CDC device, send remaining data if needed */
		/* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
		TM_USBD_CDC_Process(TM_USB_FS);
		
		/* Check if device is ready, if drivers are installed if needed on FS port */
		if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
			TM_DISCO_LedOn(LED_GREEN);
		} else {
			TM_DISCO_LedOff(LED_GREEN);
		}
		
		/* Check if user has changed parameter for COM port */
		TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings);
		
		/* Check if updated */
		if (USB_FS_Settings.Updated) {
			/* Update settings for UART here if needed */
			TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n");
		}
		
		/* Check if anything received on FS port */
		if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) {
			/* One character received */
			
			/* Send it back */
			/* TM_USBD_CDC_Putc(TM_USB_FS, ch); */

			/* Control LEDs based on input (debug) */
			switch(ch){
			case '1':
				TM_DISCO_LedToggle(LED_BLUE);
				break;
			case '2':
				TM_DISCO_LedToggle(LED_ORANGE);
				TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Orange LED\n");
				break;
			case '3':
				TM_DISCO_LedToggle(LED_RED);
				TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Red LED\n");
				break;
			case '4':
				TM_DISCO_LedToggle(LED_GREEN);
				break;
			case '5':
				/* Transfer Sample Audio */
				  trace_puts("Sending Audio Sample");

				/* For now, send entire sample audio data */
				/* TODO get size of sample to be transfered from serial port */

				/* at 115k BAUD 800 bytes is sub 10 msec total transfer time */
				for(int i = 0; i < SAMPLEAUDIO_SIZE;i++)
				{
					/* Need to split 16 bit samples into upper and lower bytes */
					/* Note that these will need to be reconstructed in the
					 * processing script. Updated Buffer size to 1024 from 256 in
					 * USBD_CDC library file for this operation.
					 */
					/* Send MSB first */
					TM_USBD_CDC_Putc(TM_USB_FS, Hi(SampleAudio[i]));
					trace_putchar((int)Hi(SampleAudio[i]));
					/* Then Send LSB */
					TM_USBD_CDC_Putc(TM_USB_FS, Lo(SampleAudio[i]));
					trace_putchar((int)Lo(SampleAudio[i]));
				}
				break;
			default:
				break;
			}
		}
		//Wait for next system tick
		while (g_SysTick_Flag == 0){};
		g_SysTick_Flag = 0;
		TM_DISCO_LedToggle(LED_BLUE);
	}
}