Exemplo n.º 1
0
/**
  * Receive Handler for USART1
  * Name: TM_USART1_ReceiveHandler
  *
  * Description: Gives functionality when a character is received over the USART serial communication channel
  *              Stores data received into a buffer for use in other functions 
  *              Control available for use of the backspace key, functions called when enter key pressed (carriage return)
  *              Used to set the RTC time
  *
  * Arguments: uint8_t c - character received
  *
  * Returns: void  
  */  
void TM_USART1_ReceiveHandler(uint8_t c){
  char str[256];
  TM_USART_Putc(USART1, c);
  buffer[i] = c;
  i++;
  /* Backspace */
  if (c == 0x7F){
    i--;
    buffer[i] = 0;
    i--;
    buffer[i] = 0;
  }
  /* Carriage Return */
  if (c == 13){
    if (buffer[0] == 'R' && buffer[1] == 'T' && buffer[2] == 'C'){
    if (isdigit(buffer[4]) && isdigit(buffer[5]) && !isdigit(buffer[6]) && isdigit(buffer[22])){
      strncpy(RTC_time, (char *) buffer + 4, sizeof(buffer) - 4);
	  /* Set RTC time */
      TM_RTC_SetDateTimeString(RTC_time);
    }
  }
  sprintf(str, "\n\rRTC %s\n\r", RTC_time);
  /* Put to USART */
  TM_USART_Puts(USART1, str);
  memset(buffer, 0, sizeof(buffer));
  i = 0;
  }
}
Exemplo n.º 2
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Init USART6, TX: PC6 for debug */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
	
	/* Enable watchdog, 4 seconds before timeout */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
		/* Report to user */
		printf("Reset occured because of Watchdog\n");
	}
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Display to user */
	printf("Program starting..\n");
	
	/* Initialize RTC with internal clock if not already */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* Set default time for RTC */
		
		/* Set date and time if RTC is not initialized already */
		TM_RTC_SetDateTimeString("28.02.15.6;23:35:30");
	};
	
	/* Initialize ethernet peripheral */
	/* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
	/* They are defined in tm_stm32f4_ethernet.h file */
	if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
		/* Successfully initialized */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Unsuccessfull communication */
		TM_DISCO_LedOn(LED_RED);
	}
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();
	
	/* Initialize ethernet server if you want use it, server port 80 */
	TM_ETHERNETSERVER_Enable(80);
	
	/* Set SSI tags, we have 21 SSI tags */
	TM_ETHERNETSERVER_SetSSITags(SSI_Tags, 21);
	
	/* Set CGI tags, we have 1 CGI handler, for leds only */
	TM_ETHERNETSERVER_SetCGIHandlers(CGI_Handlers, 1);
	
	/* Read RTC clock */
	TM_RTC_GetDateTime(&RTC_Data, TM_RTC_Format_BIN);
	
	/* Print current time to USART */
	printf("Current date: %02d:%02d:%02d\n", RTC_Data.hours, RTC_Data.minutes, RTC_Data.seconds);
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();

	while (1) {
		/* Update ethernet, call this as fast as possible */
		TM_ETHERNET_Update();
		
		/* If button pressed, toggle server status */
		if (TM_DISCO_ButtonOnPressed()) {
			/* If server is enabled */
			if (TM_ETHERNETSERVER_Enabled()) {
				/* Disable it */
				TM_ETHERNETSERVER_Disable();
				/* Print to user */
				printf("Server disabled\n");
			} else {
				/* Enable it */
				TM_ETHERNETSERVER_Enable(80);
				/* Print to user */
				printf("Server enabled\n");
			}
		}
		
		/* Reset watchdog */
		TM_WATCHDOG_Reset();
	}
}