示例#1
0
int main() {

    SystemInit();
    SER_Init() ;
#if !defined(NO_FILESYSTEM)
    init_card () ;                                    /* initializing SD card */
#endif

    init_time() ;


#if defined(DEBUG_CYASSL)
    printf("Turning ON Debug message\n") ;
    CyaSSL_Debugging_ON() ;
#endif

#ifdef   HAVE_KEIL_RTX
    os_sys_init (main_task) ;
#else
    main_task() ;
#endif

    return 0 ; /* There should be no return here */

}
示例#2
0
文件: Traffic.c 项目: EnergyMicro/RTX
/*----------------------------------------------------------------------------
  Main Thread 'main'
 *---------------------------------------------------------------------------*/
int main (void) {                         /* program execution starts here   */

  GLCD_Init();                            /* initialize GLCD                 */
  SER_Init ();                            /* initialize serial interface     */
  LED_Init ();                            /* initialize LEDs                 */
  KBD_Init ();                            /* initialize Push Button          */

  mut_GLCD = osMutexCreate(osMutex(mut_GLCD));
                                          /* create and start clock timer    */
  clock1s = osTimerCreate(osTimer(clock1s), osTimerPeriodic, NULL);                                          
  if (clock1s) osTimerStart(clock1s, 1000);                                          
                                          /* start thread lcd                */
  tid_lcd = osThreadCreate(osThread(lcd), NULL);

  osDelay(500);
                                          /* start command thread            */
  tid_command = osThreadCreate(osThread(command), NULL);
                                          /* start lights thread             */
  tid_lights  = osThreadCreate(osThread(lights), NULL);
                                          /* start keyread thread            */
  tid_keyread = osThreadCreate(osThread(keyread), NULL);

  osDelay(osWaitForever);
  while(1);
}
示例#3
0
/*----------------------------------------------------------------------------
  Main Program
 *----------------------------------------------------------------------------*/
int main (void) {
  int32_t idx = -1, dir = 1;
  int32_t ledMax = LED_Num();

  LED_Init();                                   /* LED Initialization            */
  SER_Init();                                   /* UART Initialization           */

  SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
  if (SysTick_Config(SystemCoreClock / 1000))  { /* SysTick 1 msec interrupts  */
    while (1) __NOP();                          /* Capture error              */
  }

  while(1) {                                    /* Loop forever               */
    /* Calculate 'idx': 0,1,...,LED_NUM-1,LED_NUM-1,...,1,0,0,...             */
    idx += dir;
    if        (idx == ledMax) { dir = -1; idx =  ledMax - 1; }
    else if   (idx  <  0    ) { dir =  1; idx =  0;          }

    LED_On (idx);                               /* Turn on LED 'idx'          */
    Delay(50);                                  /* Delay 50ms                 */
    LED_Off(idx);                               /* Turn off LED 'idx'         */
    Delay(150);                                 /* Delay 150ms                */

    printf ("Hello World\n\r");
  }
}
示例#4
0
/**
 * [InitTask description]
 */
__task void InitTask(void)
{
	
	int msg_len = 0;
	int clockRate = Chip_Clock_GetMainClockRate();

	/* Enabled Clock To GPPIO */
	Chip_GPIO_Init(LPC_GPIO);
	// Set the pin direction, set high for an output LED2
	Chip_GPIO_SetPinDIR(LPC_GPIO, 0, 2, 1);
	/* Serial Driver Enable */
	SER_Init();

	msg_len = snprintf(message, sizeof(message), "Main clock is: %d\r\n", clockRate);
	Chip_UART0_SendRB(LPC_USART0, &txring, message, msg_len);
	
	for(;;)
	{
		os_dly_wait(50);

		Chip_UART0_SendRB(LPC_USART0, &txring, "Sveiki\r\n", strlen("Sveiki\r\n"));
		Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 0);

		os_dly_wait(100);
		Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 2, 1);

	}
}
示例#5
0
static void init_io () {

  /* Configure LEDs */
  LED_Init();

  /* Configure buttons */
  KBD_Init();

  /* Configure serial output */
  SER_Init();

}
示例#6
0
/*----------------------------------------------------------------------------
  Main Program
 *----------------------------------------------------------------------------*/
int main (void) {
#ifdef __USE_LCD
  uint32_t i;
#endif
  uint32_t ad_avg = 0;
  uint16_t ad_val = 0, ad_val_ = 0xFFFF;

  LED_Init();                                /* LED Initialization            */
  SER_Init();                                /* UART Initialization           */
  ADC_Init();                                /* ADC Initialization            */

#ifdef __USE_LCD
  lcd_Init  ();
  lcd_WrStr("KEIL");
  for (i = 0; i < 10000000; i++);            /* Wait for initial display      */
#endif

  SysTick_Config(SystemCoreClock / 100);     /* Generate interrupt each 10 ms */

  while (1) {                                /* Loop forever                  */

    /* AD converter input                                                     */
    if (AD_done) {                           /* If conversion has finished    */
      AD_done = 0;

      ad_avg += AD_last << 8;                /* Add AD value to averaging     */
      ad_avg ++;
      if ((ad_avg & 0xFF) == 0x10) {         /* average over 16 values        */
        ad_val = (ad_avg >> 8) >> 4;         /* average devided by 16         */
        ad_avg = 0;
      }
    }

    if (ad_val ^ ad_val_) {                  /* AD value changed              */
      ad_val_ = ad_val;

      AD_DbgVal = ad_val;

      sprintf(text, "%04X", ad_val);       /* format text for print out     */
#ifdef __USE_LCD
      lcd_WrStr(text);                       /* write value to LCD            */
#endif
    }

    /* Print message with AD value every second                               */
    if (clock_1s) {
      clock_1s = 0;

      printf("AD value: 0x%s\r\n", text);
    }
  }
示例#7
0
/*
 * Main Thread
 */
int main (void) {

  SER_Init();  // Initialize Serial Interface

  printf("Example: CppSamp - Operator overloading / friend functions.\r\n"
         "===========================================================\r\n\r\n");

  /* Get main thread ID */
  main_id = osThreadGetId();
  
  /* Create thread X */
  threadX_id = osThreadCreate(osThread(threadX), NULL);

  /* Indicate to thread X completion of do-this */
  osSignalSet(threadX_id, 0x0001);
  
  /* Wait for completion of do-that */
  osSignalWait(0x0001, osWaitForever);

  Complex c1(1,2);
  Complex c2(2);
  Complex c3;

  c1.SetKey(1000);

  printf("Complex number c1: ");
  c1.Print();
  printf("Complex number c2: ");
  c2.Print();

  printf("Calculate c1 + c2: ");
  c3 = c1 + c2;
  c3.Print();

  printf("Calculate c2 - c1: ");
  c3 = c2 - c1;
  c3.Print();

  printf("Negate previous  : ");
  c3 = -c3;
  c3.Print();

  c3.Print(10);
  
  printf("\nEnd of Program.\r\n");

  while (1);
}
示例#8
0
/*----------------------------------------------------------------------------
  Main function
 *----------------------------------------------------------------------------*/
int main (void) {
	
	//SysTick_Config(SystemCoreClock/1000);      /* Generate interrupt each 100 ms  */

	//Initialize the required I/O device libraries
	JOY_Init();
	LED_Init();
	SER_Init();
	KBD_Init();
	SRAM_Init();
	GLCD_Init();     // LCD Initialization
	
	time.min = 0;
	time.hours = 12;
	time.sec = 0;
	
	USART3->CR1 |= (1<<5); //Enable the "data received" interrupt for USART3
	NVIC_EnableIRQ(USART3_IRQn); //Enable interrupts for USART3
	NVIC_SetPriority (USART3_IRQn, (1<<__NVIC_PRIO_BITS) - 1);
	
	resetList();

  //memcpy(&tailMessage->text,"This is a test of some really random text that I'm sending as part of a text message. I hope it works! Let's keep typing just to see if we can fill up 160 chars",160);
	
	//Here we are manually setting the head node to display a "No Messages" message if we are not storing anything else
	memcpy(&headMessage->text,"No Messages",11);
	headMessage->length = 11;
	headMessage->prev = NULL;
	headMessage->next = NULL;
	headMessage->rxTime.hours = 0;
	headMessage->rxTime.min = 0;
	headMessage->rxTime.sec = 0;
	displayedMessage = headMessage;
	
	
	//Initialize the LCD
	
	init_display();
	
	os_sys_init_prio(initTask,0xFE);
  
}
示例#9
0
/*
 * main
 *******/
int main (void) {
	
	int input;
//	//uint8_t num1, num2, res;	
	int num1, num2, res;

  HAL_Init ();   /* Init Hardware Abstraction Layer */
  SystemClock_Config ();           /* Config Clocks */

  SER_Init();
  
  for (;;) {                        /* Loop forever */  
		printf("Enter First Number: ");
	  scanf("%d", &input);
		num1 = (int) input;
		printf("Enter Second Number: ");
	  scanf("%d", &input);
		num2 = (int) input;
  	res = num1 + num2;
		printf("Result = %d \n", res);
  }
}
示例#10
0
void UART0_IRQHandler(void)
{
	static char *line = &cmdbuf[0];
	static uint16_t frequency=1;
	float results[2];
	uint32_t temp;
	uint32_t U0IIR = 0;
	uint32_t baudrate;
	uint32_t result[2];
	
	extern uint8_t CorrectIndexesOverride;
	extern uint8_t CorrectIndexesBrute;
	extern uint8_t EqualIndexes;
	extern uint16_t FirstOverrideIndex;
	extern uint16_t SecondOverrideIndex;
	char *EndFromStrtoul;
	
	U0IIR=UART_GetIntId(LPC_UART0);
	if ((U0IIR & 0xE) == 0x4)
	{
		c = UART_ReceiveByte(LPC_UART0);
    if (c == CR) c = LF;  /* read character                 */
		if (c != LF)
		{
			if (c == BACKSPACE  ||  c == DEL) {     /* process backspace              */
				if (uart_rcv_len_cnt != 0)  {
					uart_rcv_len_cnt--;                              /* decrement count                */
					line--;                             /* and line pointer               */
					putchar (BACKSPACE);                /* echo backspace                 */
					putchar (' ');
					putchar (BACKSPACE);
				}
			}
			else if (c != CNTLQ && c != CNTLS) {    /* ignore Control S/Q             */
				putchar (*line = c);                  /* echo and store character       */
				line++;                               /* increment line pointer         */
				uart_rcv_len_cnt++;                                /* and count                      */
			}
			if (uart_rcv_len_cnt == sizeof(cmdbuf))
			{
				printf("\nError.");
				printf("\nBuffer full.");
			}
		}
		else
		{
			line = &cmdbuf[0];
			UART_pressed_enter = 1;
			if (command == none)
			{
				if ( (strcmp(cmdbuf, "cal") == 0) && uart_rcv_len_cnt == 3)
				{
					command = Calibrate;
					printf("\n Entered into calibrating state. Type calibrating command.\n>");
					UART_pressed_enter = 0;
				}
				else if ( (strcmp(cmdbuf, "m") == 0) && uart_rcv_len_cnt == 1)
				{
					wait(1);
					Measure(results, frequency);
					printf("\n Magnitude of impedance is: ");
					printf("%.1f Ohm.", results[0]);
					printf("\n Phase of impedance is: ");
					printf("%.2f graduses.", results[1]*57.295779513);
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "f ", 2) == 0)
				{
					frequency = atoi(&(cmdbuf[2]));
					AD9833_SetFreq(frequency*1000);
					AD9833_Start();
					printf("\n New DDS frequency is %u kHz. ", frequency);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "fmin ", 5) == 0)
				{
					f_min = atoi(&(cmdbuf[5]));
					printf("\n f_min are %u kHz.", f_min);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "fmax ", 5) == 0)
				{
					f_max = atoi(&(cmdbuf[5]));
					printf("\n f_max are %u kHz.", f_max);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "nf ", 3) == 0)
				{
					n_F = atoi(&(cmdbuf[3]));
					printf("\n n_F are %u.", n_F);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if ((strncmp(cmdbuf, "bg", 2) == 0) && uart_rcv_len_cnt == 2)
				{
					bg_flag = 1;
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "r ", 2) == 0)
				{
					temp = atoi(&(cmdbuf[2]));
					AD7793_SetRate(temp);
					printf("\n AD7793 rate field = are %u.", temp);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if ( uart_rcv_len_cnt == 0)
				{
					StartADC=1;
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "g", 1) == 0)
				{
					ADC_RUN(result);
					printf("\n  Magnitude are %u.", result[0]);
					printf("\n  Phase are %u.", result[1]);
					printf("\n Type next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "d ", 2) == 0)
				{
					debug_mode = atoi(&(cmdbuf[2]));
					if (debug_mode == 0)
					{
						printf("\n Debug mode disabled.");
					}
					else
					{
						printf("\n Debug mode enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "raw ", 4) == 0)
				{
					raw_data_mode = atoi(&(cmdbuf[4]));
					if (raw_data_mode == 0)
					{
						printf("\n Raw data mode disabled.");
					}
					else
					{
						printf("\n Raw data mode enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "UartFifo ", 9) == 0)
				{
					UartWithFifo = atoi(&(cmdbuf[9]));
					if (UartWithFifo == 0)
					{
						printf("\n Software UART FIFO disabled.");
					}
					else
					{
						printf("\n Software UART FIFO enabled.");
					}
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "UART ", 5) == 0)
				{
					baudrate = atoi(&(cmdbuf[5]));
					SER_Init(baudrate);
					printf("\n UART baudrate are %u bps.", baudrate);
					printf("\nType next command.\n>");
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "CIO ", 4) == 0)
				{
					CorrectIndexesOverride = atoi(&(cmdbuf[4]));
					if (CorrectIndexesOverride == 1)
					{
						printf("\nEnter correct override indexes:\n>");
						command = CorrectIndexesPutting;
					}
					else
					{
						printf("\n Index overriding disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "CIB ", 4) == 0)
				{
					CorrectIndexesBrute = atoi(&(cmdbuf[4]));
					if (CorrectIndexesBrute == 1)
					{
						printf("\n Correct calibrating curves brute forcing enabled.");
						printf("\nType next command.\n>");
					}
					else
					{
						printf("\n Correct calibrating curves brute force disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else if (strncmp(cmdbuf, "EI ", 3) == 0)
				{
					EqualIndexes = atoi(&(cmdbuf[3]));
					if (EqualIndexes == 1)
					{
						printf("\n Equal calibrating indexes for mag and phase enabled.");
						printf("\nType next command.\n>");
					}
					else
					{
						printf("\n Equal calibrating indexes for mag and phase disabled.");
						printf("\nType next command.\n>");
					}
					UART_pressed_enter = 0;
				}
				else
				{
					printf("\nWrong command. Please type right command.\n");
					UART_pressed_enter = 0;
				}
				memset(cmdbuf,0,15);
				uart_rcv_len_cnt=0;
			}
			else if (command == CorrectIndexesPutting)
			{
				FirstOverrideIndex = strtoul(cmdbuf, &EndFromStrtoul, 10);
				SecondOverrideIndex = atoi(EndFromStrtoul);
				printf("\n FirstCorrectIndex = %u", FirstOverrideIndex);
				printf("\n SecondCorrectIndex = %u", SecondOverrideIndex);
				printf("\nType next command.\n>");
				UART_pressed_enter = 0;
				command = none;
				memset(cmdbuf,0,15);
				uart_rcv_len_cnt=0;
			}
		}
	}
	else if ((U0IIR & 0xE) == 0x2)
	{
		if (SW_UART_FIFO_STRUCT.count!=0)
		{
			LPC_UART0->THR = SW_UART_pop();
		}
		else
			UART_IntConfig(LPC_UART0,UART_INTCFG_THRE,DISABLE);			//Disable UART0 THRE Interrupt
	}
}
示例#11
0
int main (void) {

  //J: zmienne pomocnicze
  int c;              //znak odebrany przez UART0 lub UART1
  char response[150]; //miejsce na odpowiedŸ modu³u
  int char_c=0;       //liczba znaków w odpowiedzi
  int nl_c=0;         //liczba linii w odpowiedzi

  SER_Init();                     /* UART0 and UART1 Initialization           */
  
  //J: w pêtli bêdziemy przekazywaæ znak po znaku od komputera do modu³u i odwrotnie, chyba ¿e z komputera dotrze do nas znak specjalny
  while (1) {
    //gdy jakiœ znak przyszed³ na UART0 (od modu³u)...
    if ((c = SER0_GetChar()) != 0) 
    {
      //je¿eli odebrano coœ na UART0, to przeœlij to na UART1
      SER1_PutChar(c);
    }

    //gdy jakiœ znak przyszed³ na UART1 (od komputera)...
    if ((c = SER1_GetChar()) != 0) 
    {
      switch (c)
      {
        //znak specjalny '(' powoduje sprawdzenie stanu sieci
        case '(':
          //podobno jesteœmy user-friendly
          SER1_PutStr("Sprawdzam stan zalogowania do sieci: \r\n");
          
          //wysy³amy komendê sprawdzenia stanu sieci
          SER0_PutStr("AT+CREG?\r\n");

          //czyœcimy bufor
          char_c=0;
          nl_c=0;

          //-------------------------------------------------------------------
          //Wydaje mi siê, ¿e odpowiedŸ na AT+CREG? ma 22 znaki (razem ze znakami
          //nowej linii i echem samej komendy), a cyfra oznaczaj¹ca status sieci
          //siedzi w 20 znaku, ale TRZEBA TO SPRAWDZIC NA SPRZÊCIE
		  //
		  //Przyk³ad:
		  //na UART0 leci:
		  //AT+CREG?<CR><LF>
		  //a w odpowiedzi (zgodnie z dokumentacj¹) powinniœmy dostaæ
		  //AT+CREG?<CR><LF>
		  //+CREG: 0,2<CR><LF>
          //-------------------------------------------------------------------

          //zbieramy ¿niwo
          //-------------------------------------------------------------------
          //TODO: sprawdziæ warunek zakoñczenia zapisywania danych do bufora
          //-------------------------------------------------------------------
          while (/*warunek stopu w oparciu o nl_c lub char_c typu: odbierz x linii lub odbierz y znaków*/ char_c < 22)
          {
            //spróbuj odebraæ znak
            c = SER0_GetChar();

            //je¿eli odebrano jakiœ znak to dodaj go do bufora
            if (c != 0)
            {
              response[char_c] = c;
              char_c++;
            }

            //je¿eli odebrany znak to NL (ASCII 10) to zwiêksz licznik linii
            if (c == 10)
              nl_c++;
          }

          //-------------------------------------------------------------------
          //TODO: sprawdziæ w którym znaku kryje siê odpowiedŸ (czy jest to znak na 20 pozycji)
          //-------------------------------------------------------------------
          switch (response[19 /* na takim indeksie jest 22-gi znak*/])
          {
            case '0':
              SER1_PutStr("Terminal nie jest podlaczony do sieci\r\n");
              break;
            case '1':
              SER1_PutStr("Terminal jest podlaczony do sieci\r\n");
              break;
            case '2':
              SER1_PutStr("Terminal szuka stacji bazowej\r\n");
              break;
            case '5':
              SER1_PutStr("Terminal jest w trybie roamingu\r\n");
              break;
            default:
              SER1_PutStr("Nierozpoznany status: ");
              SER1_PutChar(response[19]);
              SER1_PutStr("\r\n");
          }

          //¿eby by³o wiadomo, kiedy koñczy siê dzia³anie komendy i zaczyna przepisywanie odebranych znaków na konsolê
          SER1_PutStr("Koniec\r\n");

          break;

        //znak specjalny ')' powoduje odebranie SMSa
        case ')':
          //podobno jesteœmy user-friendly
          SER1_PutStr("Odbieram sesemesa: \r\n");
          
          //wysy³amy komendê prze³¹czenia siê na tryb tekstowy odbioru SMSa
          SER0_PutStr("AT+CMGF=1\r\n");

          //wysy³amy komendê odbioru SMSa z pozycji 1 w kolejce
          SER0_PutStr("AT+CMGR=1\r\n");

          //-------------------------------------------------------------------
          //Uwaga: w odpowiedzi dostaniemy:
          //-echo komendy AT+CMGF=1
          //-wynik komendy (prawdopodobnie coœ w sytlu "OK")
          //-echo komendy AT+CMGR=1
          //-odpowiedŸ w kilku liniach z dat¹ odebrania SMSa, jego treœci¹ i wynikiem komendy ("OK")
          //razem bêdzie tego chyba z 7 linii
		  //
		  //Przyk³ad:
		  //na UART0 wysy³amy:
		  //AT+CMGF=1<CR><LF>
		  //AT+CMGR=1<CR><LF>
		  //a w odpowiedzi (zgodnie z dokumentacj¹) powinniœmy dostaæ
		  //AT+CMGF=1<CR><LF>
		  //OK<CR><LF>
		  //AT+CMGR=1<CR><LF>
		  //+CMGR:"REC UNREAD","133********",,<CR><LF>
		  //"04/02/25,12 :58 :04+04"<CR><LF>
		  //ABCD<CR><LF>
		  //OK<CR><LF>
          //-------------------------------------------------------------------

          //czyœcimy bufor
          char_c=0;
          nl_c=0;

          //zbieramy ¿niwo
          //-------------------------------------------------------------------
          //TODO: sprawdziæ warunek zakoñczenia zapisywania danych do bufora
          //-------------------------------------------------------------------
          while (/*warunek stopu w oparciu o nl_c lub char_c typu: odbierz x linii lub odbierz y znaków*/ nl_c < 7)
          {
            //spróbuj odebraæ znak
            c = SER0_GetChar();

            //je¿eli odebrano jakiœ znak to dodaj go do bufora
            if (c != 0)
            {
              response[char_c] = c;
              char_c++;
            }

            //-----------------------------------------------------------------
            //TODO: sprawdziæ, czy faktycznie treœæ SMSa znajduje siê w linii 6
            //-----------------------------------------------------------------

            //je¿eli aktualnie odbierasz liniê nr, 6 to przepisz j¹ na konsolê, bo to ona zawiera treœæ SMSa
            if (nl_c == 6)
              SER1_PutChar(c);

            //je¿eli odebrany znak to NL (ASCII 10) to zwiêksz licznik linii
            if (c == 10)
              nl_c++;
          }
          SER1_PutStr("\r\n");

          //¿eby by³o wiadomo, kiedy koñczy siê dzia³anie komendy i zaczyna przepisywanie odebranych znaków na konsolê
          SER1_PutStr("Koniec\r\n");

          break;

        //ka¿dy inny znak przekierowujemy do UART0
        default:
          SER1_PutChar(c);

      } //switch
    } //if
  } //while
} //main()