예제 #1
0
void main() 
{
    int num = 1234;
    GLCD_Init();

    while (1) 
    {
        GLCD_Clear();
        GLCD_DisplayLogo(LogoBitMap);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_Printf("Dec:%d \nHex:%x \nBin:%b \nFloat:%f", num, num, num, 4567.89);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_HorizontalGraph(0, 45);
        GLCD_HorizontalGraph(1, 50);
        GLCD_HorizontalGraph(2, 82);
        GLCD_HorizontalGraph(3, 74);
        DELAY_ms(DELAY_TIME);

        GLCD_Clear();
        GLCD_VerticalGraph(0, 45);
        GLCD_VerticalGraph(1, 50);
        GLCD_VerticalGraph(2, 82);
        GLCD_VerticalGraph(3, 74);
        DELAY_ms(DELAY_TIME);
    }
}
예제 #2
0
파일: lcdtest.c 프로젝트: m3y54m/32bitmicro
/*********************************************************************//**
 * @brief		c_entry: Main LCD program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry(void)
{
//	/* Initialize debug via UART0
//	 * – 115200bps
//	 * – 8 data bit
//	 * – No parity
//	 * – 1 stop bit
//	 * – No flow control
//	 */
//	debug_frmwrk_init();
//
//	// print welcome screen
//	print_menu();

	/* LCD block section -------------------------------------------- */
	GLCD_Init();
	GLCD_Clear(White);

	/* Update LCD Module display text. */
	GLCD_DisplayString(0,0, lcd_text[0] );
	GLCD_DisplayString(1,2, lcd_text[1] );

    /* Loop forever */
    while(1);
    return 1;
}
예제 #3
0
파일: main.c 프로젝트: Madswinther/31370
void init(){
  GLCD_Ctrl (FALSE);
  // Init GPIO
  GpioInit();
#ifndef SDRAM_DEBUG
  // MAM init
  MAMCR_bit.MODECTRL = 0;
  MAMTIM_bit.CYCLES  = 3;   // FCLK > 40 MHz
  MAMCR_bit.MODECTRL = 2;   // MAM functions fully enabled
  // Init clock
  InitClock();
  // SDRAM Init
  SDRAM_Init();
#endif // SDRAM_DEBUG
  // Init VIC
  VIC_Init();
  // GLCD init
  GLCD_Init (NULL, NULL);
  // Disable Hardware cursor
  GLCD_Cursor_Dis(0);
  
  // Touched indication LED
  USB_H_LINK_LED_SEL = 0; // GPIO
  USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
  USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK;
  
  __enable_interrupt();
  
  // Enable GLCD
  GLCD_Ctrl (TRUE);
}
예제 #4
0
파일: main.c 프로젝트: dennisso/ece455
int main(void)
{
	SystemInit();
	GLCD_Init();
	clock_init();

#ifndef BUSY_WAIT
	timer0_init();
#endif /* ifndef BUSY_WAIT */
	
	while(1)
	{
		GLCD_Clear(White);
		GLCD_DisplayString(0, 0, 1, (unsigned char*) clock.text);
		
		// Delay by 1000 milliseconds
#ifdef BUSY_WAIT
		delay_busy_wait(1000);
		clock_increment();
		clock_print();
#else
		// incrementing clock done within interrupt handlers
		clock_print();
#endif /* ifdef BUSY_WAIT */		
	}
}
예제 #5
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);
}
예제 #6
0
void init_system()
{
	// Initialize system and GLCD
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);
}
예제 #7
0
/*----------------------------------------------------------------------------
 *        Initialize On Board LCD Module
 *---------------------------------------------------------------------------*/
static void init_display (void) {
  /* LCD Module init */

  GLCD_Init ();
  GLCD_Clear (White);
  GLCD_SetTextColor (Blue);
  GLCD_DisplayString (1, 2, "     RL-ARM");
  GLCD_DisplayString (2, 2, "SD_File example");
}
예제 #8
0
파일: main.c 프로젝트: mwerezak/ECE455
int main(void)
{
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);

	runHardwareTimer();

	return 0;
}
예제 #9
0
파일: Blinky.c 프로젝트: nganthony/ECE254
/*----------------------------------------------------------------------------
 *        Main: Initialize and start RTX Kernel
 *---------------------------------------------------------------------------*/
int main (void) {

  SystemInit();                             /* Initialize the MCU clocks     */

  LED_init ();                              /* Initialize the LEDs           */
 
  GLCD_Init();                              /* Initialize the GLCD           */
  GLCD_Clear(White);                        /* Clear the GLCD                */

  os_sys_init(init);                        /* Initialize RTX and start init */
}
/*********************************************************************
*
*       _InitController
*
* Function description:
*   Initializes the LCD controller and touch screen
*
*/
static void _InitController(unsigned LayerIndex) {
  //
  // Set display size and video-RAM address
  //
  LCD_SetSizeEx (XSIZE_PHYS, YSIZE_PHYS, LayerIndex);
  LCD_SetVSizeEx(VXSIZE_PHYS, VYSIZE_PHYS, LayerIndex);
  LCD_SetVRAMAddrEx(LayerIndex, (void*)LCD_VRAM_BASE_ADDR);
  //
  // Init LCD
  //
  GLCD_Init();

#if GUI_SUPPORT_TOUCH  // Used when touch screen support is enabled
  {
    U32 TouchOrientation;
    U32 pclk;

    //
    // Initialize touch screen
    //
    LPC_SC->PCONP |= (1 << 12);  // Enable clock for ADC
    LPC_ADC->CR    = 0
                     | (1          <<  1)  // Sel AD0[1]
                     | (ADC_CLKDIV <<  8)
                     | (1          << 21)  // Enable ADC
                     ;
    //
    // Calibrate touch
    //
    TouchOrientation = (GUI_MIRROR_X * LCD_GetMirrorXEx(0)) |
                       (GUI_MIRROR_Y * LCD_GetMirrorYEx(0)) |
                       (GUI_SWAP_XY  * LCD_GetSwapXYEx (0)) ;
    GUI_TOUCH_SetOrientation(TouchOrientation);
    if (LCD_GetSwapXYEx(0)) {
      GUI_TOUCH_Calibrate(GUI_COORD_X, 0, XSIZE_PHYS, TOUCH_AD_LEFT, TOUCH_AD_RIGHT);   // x axis swapped
      GUI_TOUCH_Calibrate(GUI_COORD_Y, 0, YSIZE_PHYS, TOUCH_AD_TOP , TOUCH_AD_BOTTOM);  // y axis swapped
    } else {
      GUI_TOUCH_Calibrate(GUI_COORD_X, 0, XSIZE_PHYS, TOUCH_AD_LEFT, TOUCH_AD_RIGHT);   // x axis
      GUI_TOUCH_Calibrate(GUI_COORD_Y, 0, YSIZE_PHYS, TOUCH_AD_TOP , TOUCH_AD_BOTTOM);  // y axis
    }
    //
    // Start touch timer
    //
    LPC_SC->PCONP |= (0x1<<2);
    pclk = SystemCoreClock/4;
    LPC_TIM1->PR  = pclk/1000000; /* Set prescaler to get 1 M counts/sec */
    LPC_TIM1->MR0 = 1000 * TOUCH_TIMER_INTERVAL;
    LPC_TIM1->MCR = (0x3<<0);	    /* Interrupt and Reset on MR0 */
    NVIC_EnableIRQ(TIMER1_IRQn);
    LPC_TIM1->TCR = 1;            /* Enable timer 1 */
  }
#endif
}
예제 #11
0
int main(void) {
    SystemInit();
    GLCD_Init();
    GLCD_Clear(White);
    GLCD_DisplayString(0, 0, 1, "LAB 2");

    init_morse_code_fsm();
    init_debounced_button();

    while(1) {}

    return 0;
}
예제 #12
0
void init_scroll( void ) {
	GLCD_Init(); 

	GLCD_Clear(BGC);
	GLCD_SetBackColor(BGC);
	GLCD_SetTextColor(TXC);

	cache_start = 0;
	cache_size = 0;
	last_col_cahche = 0;
	window_start = 0;
	window_size = 0;

}
예제 #13
0
파일: main_rev.c 프로젝트: mihai93/MTE-241
int main( void ) {
	/*** Declare all variables ***/
// 	unsigned short circle[N][N] = {BG};
// 	unsigned short circleBitmap[N];
	/*** Declare all variables ***/
	
	SystemInit();
	GLCD_Init();
	GLCD_Clear(BG); 
	
	createCircle(160, 120);

  while(1);
}	
예제 #14
0
/* RT-Thread Device Interface */
static rt_err_t rt_lcd_init (rt_device_t dev)
{
    PINSEL_ConfigPin(5, 4, 0);
	LPC_GPIO5->DIR |= 1<<4;
	LPC_GPIO5->CLR  = 1<<4;
	LPC_GPIO5->SET  = 1<<4;

	/*Disable LCD controller*/
	GLCD_Ctrl (FALSE);
	/*Init LCD and copy picture in video RAM*/
	GLCD_Init (_lcd_info.framebuffer);
	/*Enable LCD*/
	GLCD_Ctrl (TRUE);

	return RT_EOK;
}
예제 #15
0
int main(void) {
    SystemInit();
    GLCD_Init();
    GLCD_Clear(Black);
		GLCD_SetTextColor(Red);
		GLCD_SetBackColor(Black);
		__enable_irq();
	
		GLCD_DisplayString(1, 1, 1, "Status: ");
		GLCD_DisplayString(1, 9, 1, "START");
		GLCD_DisplayString(4, 5, 1, "TIMER");
		BoardInit();
	
		hwInterrupt(min_to_run * ms_in_min);
		GLCD_DisplayString(1, 9, 1, "END  ");
    return 0;
}
예제 #16
0
파일: main.c 프로젝트: mwerezak/ECE455
int main()
{
	SystemInit();
	GLCD_Init();
	GLCD_Clear(White);

	LED_Init();
	Pushbutton_Init();
	Timer_Init(LPC_TIM0);

	FSM_Init();
	CreateMorseFSM();

	MorseReader_Init();
	MorseReader_FSMRun();

	return 0;
}
예제 #17
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);
  
}
void show_bitmap()
{
	
	
	int ax_Phys[2],ay_Phys[2],i;
	unsigned char *images[] = { gImage_terminator_large,
					gImage_britney
					};
	//clear_buttons_and_frames();
	
	GUIDEMO_ShowIntro("Photographic Bitmap",
                    "Showing"
                    "\nTerminator Sarah Connor Chronicles"
                    "\nBy Siddharth Kaul");
	GLCD_Init ();
  	GLCD_Clear (White);
	i = 0;
	do
	{
		GUI_PID_STATE State;
		GUI_TOUCH_GetState(&State);
		if (State.Pressed) 
		{
			GLCD_Clear(White);
		    GLCD_Bitmap(0, 0, 320, 240, images[i]);
			i++;
			if(i > 1)
			{
				i = 0;	
			}
			
			//break;
		}
	}while(1);//end of do while	
	//delete pointer to free up memory
	free(images);
	/*
	GUI_SetFont(&GUI_Font24B_1);
	GUI_SetColor(GUI_YELLOW);
	GUI_DispStringAt("Terminator", 0,0);*/
}
예제 #19
0
/*********************************************************************//**
 * @brief	Initial System Init using Port and Peripheral
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void System_Init(void)
{
	LPC_WDT->WDMOD &= ~WDT_WDMOD_WDEN;  // Disable Watchdog
	SystemInit();						// Initialize system and update core clock
	Port_Init();                        // Port Initialization
	SYSTICK_Config();                   // Systick Initialization
	led_delay = 1000;                   // Heart Beat rate of 1Sec toggle
	NVIC_SetPriority(SysTick_IRQn, 0);  // Set SysTick as Highest Priority

	UART_Config(LPC_UART0, 115200);       // Uart0 Initialize at 9600 Baud Rate
	SSP_Config (LPC_SSP1);              // Initialize SPI
	I2C_Config (LPC_I2C0);              // Initialize I2C0
	GLCD_Init();                        // Initialize GLCD

	GPIO_IntCmd(2,_BIT(7),1);          // Enable GPIO Interrupt at P0.19 Falling Edge
	NVIC_EnableIRQ(EINT3_IRQn);         // NVIC Interrupt EINT3_IRQn for GPIO
	NVIC_SetPriority(EINT3_IRQn, 4);    // Set any lower Priority than SysTick

	TSC2004_Cal_Init(&cmatrix);

}
예제 #20
0
/*----------------------------------------------------------------------------
  Main Thread 'main'
 *---------------------------------------------------------------------------*/
int main (void) {

  LED_Init ();                              /* Initialize the LEDs           */
  GLCD_Init();                              /* Initialize the GLCD           */

  GLCD_Clear(White);                        /* Clear the GLCD                */

  mut_GLCD = osMutexCreate(osMutex(mut_GLCD));

  tid_phaseA = osThreadCreate(osThread(phaseA), NULL);
  tid_phaseB = osThreadCreate(osThread(phaseB), NULL);
  tid_phaseC = osThreadCreate(osThread(phaseC), NULL);
  tid_phaseD = osThreadCreate(osThread(phaseD), NULL);
  tid_clock  = osThreadCreate(osThread(clock),  NULL);
  tid_lcd    = osThreadCreate(osThread(lcd),    NULL);

  osSignalSet(tid_phaseA, 0x0001);          /* set signal to phaseA thread   */

  osDelay(osWaitForever);
  while(1);
}
예제 #21
0
/*********************************************************************//**
 * @brief	Main 4-bit LCD porting with GPIO program body
 **********************************************************************/
int c_entry(void)
{
	// DeInit NVIC and SCBNVIC
	NVIC_DeInit();
	NVIC_SCBDeInit();

	/* Configure the NVIC Preemption Priority Bits:
	 * two (2) bits of preemption priority, six (6) bits of sub-priority.
	 * Since the Number of Bits used for Priority Levels is five (5), so the
	 * actual bit number of sub-priority is three (3)
	 */
	NVIC_SetPriorityGrouping(0x05);

	//  Set Vector table offset value
#if (__RAM_MODE__==1)
	NVIC_SetVTOR(0x10000000);
#else
	NVIC_SetVTOR(0x00000000);
#endif

	/* Initialize debug
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	/* LCD block section -------------------------------------------- */
	GLCD_Init();
//	LCD_cur_off();
	GLCD_Clear(White);

	/* Update LCD Module display text. */
	GLCD_DisplayString(0,0, lcd_text[0] );
	GLCD_DisplayString(1,2, lcd_text[1] );

    /* Loop forever */
    while(1);
    return 1;
}
예제 #22
0
파일: main.c 프로젝트: hyper123/CycloneTCP
int_t main(void)
{
   error_t error;
   NetInterface *interface;
   OsTask *task;

   static DhcpClientSettings dhcpClientSettings;
   static DhcpClientCtx dhcpClientContext;

   //Update system core clock
   SystemCoreClockUpdate();
   //Configure debug UART
   debugInit(115200);

   //Start-up message
   TRACE_INFO("\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("Copyright: 2010-2013 Oryx Embedded\r\n");
   TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
   TRACE_INFO("Target: SAM4E\r\n");
   TRACE_INFO("\r\n");

   //IO configuration
   ioInit();

   //Initialize LCD display
   GLCD_Init();
   GLCD_SetBackColor(Blue);
   GLCD_SetTextColor(White);
   GLCD_Clear(Blue);

   //Welcome message
   lcdSetCursor(0, 0);
   printf("FTP Client Demo\r\n");

   //TCP/IP stack initialization
   error = tcpIpStackInit();

   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
   }

   //Configure the first Ethernet interface
   interface = &netInterface[0];
   //Select the relevant network adapter
   interface->nicDriver = &sam4eEthDriver;
   interface->phyDriver = &ksz8051PhyDriver;
   //Interface name
   strcpy(interface->name, "eth0");
   //Set host MAC address
   macStringToAddr("00-AB-CD-EF-04-16", &interface->macAddr);

#if (IPV6_SUPPORT == ENABLED)
   //Set link-local IPv6 address
   ipv6StringToAddr("fe80::00ab:cdef:0416", &interface->ipv6Config.linkLocalAddr);
#endif

   //Initialize network interface
   error = tcpIpStackConfigInterface(interface);

   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name);
   }

#if 1
   //Set the network interface to be configured by DHCP
   dhcpClientSettings.interface = &netInterface[0];
   //Disable rapid commit option
   dhcpClientSettings.rapidCommit = FALSE;
   //Start DHCP client
   error = dhcpClientStart(&dhcpClientContext, &dhcpClientSettings);

   //Failed to start DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start DHCP client!\r\n");
   }
#else
   //Manual configuration
   interface = &netInterface[0];

   //IPv4 address
   ipv4StringToAddr("192.168.0.20", &interface->ipv4Config.addr);
   //Subnet mask
   ipv4StringToAddr("255.255.255.0", &interface->ipv4Config.subnetMask);
   //Default gateway
   ipv4StringToAddr("192.168.0.254", &interface->ipv4Config.defaultGateway);

   //Primary and secondary DNS servers
   interface->ipv4Config.dnsServerCount = 2;
   ipv4StringToAddr("212.27.40.240", &interface->ipv4Config.dnsServer[0]);
   ipv4StringToAddr ("212.27.40.241", &interface->ipv4Config.dnsServer[1]);
#endif

   //Create user task
   task = osTaskCreate("User Task", userTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Create a task to blink the LED
   task = osTaskCreate("Blink", blinkTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Start the execution of tasks
   osStart();

   //This function should never return
   return 0;
}
예제 #23
0
// This is the actual task that is run
static portTASK_FUNCTION( vLCDUpdateTask, pvParameters )
{
	#if LCD_EXAMPLE_OP==0
	unsigned short screenColor = 0;
	unsigned short tscr;
	unsigned char curLine;
	unsigned timerCount = 0;
	int xoffset = 0, yoffset = 0;
	unsigned int xmin=0, xmax=0, ymin=0, ymax=0;
	unsigned int x, y;
	int i, j;
	float hue=0, sat=0.2, light=0.2;
	#elif LCD_EXAMPLE_OP==1
	unsigned char picIndex = 0;
	#else
	Bad definition
	#endif
	vtLCDMsg msgBuffer;
	vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters;

	#ifdef INSPECT_STACK
	// This is meant as an example that you can re-use in your own tasks
	// Inspect to the stack remaining to see how much room is remaining
	// 1. I'll check it here before anything really gets started
	// 2. I'll check during the run to see if it drops below 10%
	// 3. You could use break points or logging to check on this, but
	//    you really don't want to print it out because printf() can
	//    result in significant stack usage.
	// 4. Note that this checking is not perfect -- in fact, it will not
	//    be able to tell how much the stack grows on a printf() call and
	//    that growth can be *large* if version 1 of printf() is used.   
	unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL);
	unsigned portBASE_TYPE CurrentStackLeft;
	float remainingStack = InitialStackLeft;
	remainingStack /= lcdSTACK_SIZE;
	if (remainingStack < 0.10) {
		// If the stack is really low, stop everything because we don't want it to run out
		// The 0.10 is just leaving a cushion, in theory, you could use exactly all of it
		VT_HANDLE_FATAL_ERROR(0);
	}
	#endif

	/* Initialize the LCD and set the initial colors */
	GLCD_Init();
	tscr = Red; // may be reset in the LCDMsgTypeTimer code below
	screenColor = White; // may be reset in the LCDMsgTypeTimer code below
	GLCD_SetTextColor(tscr);
	GLCD_SetBackColor(screenColor);
	GLCD_Clear(screenColor);

	// Added by Matthew Ibarra 2/2/2013
	int xPos = 0;

	// Note that srand() & rand() require the use of malloc() and should not be used unless you are using
	//   MALLOC_VERSION==1
	#if MALLOC_VERSION==1
	srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability
	#endif

	curLine = 5;
	// This task should never exit
	for(;;)
	{	
		#ifdef INSPECT_STACK   
		CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL);
		float remainingStack = CurrentStackLeft;
		remainingStack /= lcdSTACK_SIZE;
		if (remainingStack < 0.10) {
			// If the stack is really low, stop everything because we don't want it to run out
			VT_HANDLE_FATAL_ERROR(0);
		}
		#endif

		#if LCD_EXAMPLE_OP==0
		// Wait for a message
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		

		#if EXAMPLE_COLOR_CHANGE==1
		//Log that we are processing a message -- more explanation of logging is given later on
		vtITMu8(vtITMPortLCDMsg,getMsgType(&msgBuffer));
		vtITMu8(vtITMPortLCDMsg,getMsgLength(&msgBuffer));

		// Take a different action depending on the type of the message that we received
		switch(getMsgType(&msgBuffer)) {
		case LCDMsgTypePrint: {
			// This will result in the text printing in the last five lines of the screen
			char   lineBuffer[lcdCHAR_IN_LINE+1];
			copyMsgString(lineBuffer,&msgBuffer,lcdCHAR_IN_LINE);
			// clear the line
			GLCD_ClearLn(curLine,1);
			// show the text
			GLCD_DisplayString(curLine,0,1,(unsigned char *)lineBuffer);
			curLine++;
			if (curLine == lcdNUM_LINES) {
				curLine = 5;
			}
			break;
		}
		case LCDMsgTypeTimer: {
			// Note: if I cared how long the timer update was I would call my routine
			//    unpackTimerMsg() which would unpack the message and get that value
			// Each timer update will cause a circle to be drawn on the top half of the screen
			//   as explained below
			if (timerCount == 0) {
				/* ************************************************** */
				// Find a new color for the screen by randomly (within limits) selecting HSL values
				// This can be ignored unless you care about the color map
				#if MALLOC_VERSION==1
				hue = rand() % 360;
				sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat += 0.5;
				light = (rand() % 1024) / 1023.0;	light = light * 0.8; light += 0.10;
				#else
				hue = (hue + 1); if (hue >= 360) hue = 0;
				sat+=0.01; if (sat > 1.0) sat = 0.20;	
				light+=0.03; if (light > 1.0) light = 0.20;
				#endif
				screenColor = hsl2rgb(hue,sat,light);
				// Now choose a complementary value for the text color
				hue += 180;
				if (hue >= 360) hue -= 360;
				tscr = hsl2rgb(hue,sat,light);
				GLCD_SetTextColor(tscr);
				GLCD_SetBackColor(screenColor);
				// End of playing around with figuring out a random color
				/* ************************************************** */

				// clear the top half of the screen
				GLCD_ClearWindow(0,0,320,120,screenColor); 

				// Now we are going to draw a circle in the upper left corner of the screen
				int	count = 200;
				float radius;
				float inc, val, offset = MAX_RADIUS;
				unsigned short circleColor;
				inc = 2*M_PI/count;
				xmax = 0;
				ymax = 0;
				xmin = 50000;
				ymin = 50000;
				val = 0.0;
				for (i=0;i<count;i++) {
					// Make the circle a little thicker
					// by actually drawing three circles w/ different radii
					float cv = cos(val), sv=sin(val);
					circleColor = (val*0xFFFF)/(2*M_PI);
					GLCD_SetTextColor(circleColor);
					for (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) {
						x = round(cv*radius+offset);
						y = round(sv*radius+offset);
						if (x > xmax) xmax = x;
						if (y > ymax) ymax = y;
						if (x < xmin) xmin = x;
						if (y < ymin) ymin = y;
						GLCD_PutPixel(x,y);	
					}
					val += inc;
				}
				// Now we are going to read the upper left square of the LCD's
				// memory (see its data sheet for details on that) and save
				// that into a buffer for fast re-drawing later
				if (((xmax+1-xmin)*(ymax+1-ymin)) > BUF_LEN) {
					// Make sure we have room for the data
					VT_HANDLE_FATAL_ERROR(0);
				}
				unsigned short int *tbuffer = buffer;
				unsigned int width = (xmax+1-xmin);
				for (j=ymin;j<=ymax;j++) {
					GLCD_GetPixelRow (xmin,j,width,tbuffer);
					tbuffer += width;
				}
				// end of reading in the buffer
				xoffset = xmin;
				yoffset = ymin;
			} else {
				// We are going to write out the data read into the buffer
				//   back onto the screen at a new location
				// This is *very* fast

				// First, clear out where we were
				GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor);
				// Pick the new location
				#if MALLOC_VERSION==1
				xoffset = rand() % (320-(xmax+1-xmin));
				yoffset = rand() % (120-(ymax+1-ymin));
				#else
				xoffset = (xoffset + 10) % (320-(xmax+1-xmin));
				yoffset = (yoffset + 10) % (120-(ymax+1-ymin));
				#endif
				// Draw the bitmap
				GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned char *)buffer);
			}
			timerCount++;
			if (timerCount >= 40) {	  
				// every so often, we reset timer count and start again
				// This isn't for any important reason, it is just to for this example code to do "stuff"
				timerCount = 0;
			}
			break;
		}
		default: {
			// In this configuration, we are only expecting to receive timer messages
			VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
			break;
		}
		} // end of switch()
		#endif
		#if MILESTONE_1==1
		// Added by Matthew Ibarra 2/2/2013
			if(timerCount==0) {
				GLCD_Clear(screenColor);
				
				// Draw the vertical gridlines onto the LCD
				int i;
				for(i = 320/6; i < 315; i = i + 320/6) {
					GLCD_ClearWindow(i, 0, 1, 240, Red);
				}
				
				// Draw the vertical gridlines onto the LCD
				for(i = 240/4; i < 235; i = i + 240/4) {
					GLCD_ClearWindow(0, i, 320, 1, Red);
				}
				
				//Output Scale on LCD
				GLCD_DisplayString(29, 0, 0, (unsigned char*) "V/div=2.5 s/div=3");
				timerCount++;
			}
			int adcValue;
			getMsgValue(&adcValue, &msgBuffer);
			int displayValue;
			displayValue = 120 - (adcValue * 120)/(0x100);
			GLCD_ClearWindow(xPos, displayValue, 2, 2, Black);
			xPos += 2;
			if(xPos > 320) {
				timerCount = 0;
				xPos = 0;
			}
		#endif

		// Here is a way to do debugging output via the built-in hardware -- it requires the ULINK cable and the
		//   debugger in the Keil tools to be connected.  You can view PORT0 output in the "Debug(printf) Viewer"
		//   under "View->Serial Windows".  You have to enable "Trace" and "Port0" in the Debug setup options.  This
		//   should not be used if you are using Port0 for printf()
		// There are 31 other ports and their output (and port 0's) can be seen in the "View->Trace->Records"
		//   windows.  You have to enable the prots in the Debug setup options.  Note that unlike ITM_SendChar()
		//   this "raw" port write is not blocking.  That means it can overrun the capability of the system to record
		//   the trace events if you go too quickly; that won't hurt anything or change the program execution and
		//   you can tell if it happens because the "View->Trace->Records" window will show there was an overrun.
		//vtITMu16(vtITMPortLCD,screenColor);

		#elif 	LCD_EXAMPLE_OP==1
		// In this alternate version, we just keep redrawing a series of bitmaps as
		//   we receive timer messages
		// Wait for a message
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) {
			// In this configuration, we are only expecting to receive timer messages
			VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
		}
  		/* go through a  bitmap that is really a series of bitmaps */
		picIndex = (picIndex + 1) % 9;
		GLCD_Bmp(99,99,120,45,(unsigned char *) &ARM_Ani_16bpp[picIndex*(120*45*2)]);
		#else
		Bad setting
		#endif	
	}
}
예제 #24
0
/*******************************************************************************
* Function Name  : main						    
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
	/* NVIC configuration */
  	NVIC_Configuration();

	initialisation();


	/* Initialisation of SD Card and creation of File */
	SD_Init();
	/* Blinkmuster laden */
	if( SD_Start("muster.txt", FA_OPEN_EXISTING | FA_READ) )
	{
		SD_Read(&muster,1);
	}
	SD_Close();
	
	/* LCD Initialisieren */
  GLCD_Init();
  GLCD_Clear(White);                    
	GLCD_SetTextColor(Red);
  GLCD_DisplayString(1, 1, 1, "Write to SD-Card");
	GLCD_DisplayString(8, 1, 1, "Press User to stop");
	GLCD_DisplayString(4, 1, 1, "Fit Card into Slot");
	
	/* Wait until SD Card is in Slot */
	while(!(SD_Start("time.txt", FA_CREATE_ALWAYS | FA_WRITE)))
	{
		
	}
	
	length=sprintf (buffer, "runtime: %d:%d:%d    ", hour, min, sek);
	GLCD_DisplayString(4, 1, 1, buffer);

	/*****************************
	*	ENDE  INITIALISIERUNG	 *
	******************************/

	
    GPIO_ResetBits(GPIOE,GPIO_Pin_All);				// LED off all pins


  	while(1)
  	{  
//		BFH_GLCD_UDP();
  	 	/* Alle 10ms wird das tickFlag gesetzt */
		if(tickFlag)
		{
	  		tickFlag=0;	// reset tickFlag
			if(write > 1)
			{
				/* Jede Sekunde einen Stamp ins File schreiben */
				if((write%1000) == 0)
				{
					/* Zeit hochzählen */
					sek++;
					if(sek==60)
					{
						sek=0;
						min++;
					}
					if(min==60)
					{
						min=0;
						hour++;
					}
					if(hour==24)
					{
						hour=0;
					}
					/* write time to Diaplay */
					length=sprintf (buffer, "runtime: %d:%d:%d    ", hour, min, sek);
					GLCD_DisplayString(4, 1, 1, buffer);
					/* write time to card */
					length=sprintf (buffer, "runtime: %d:%d:%d\ttext\r\n", hour, min, sek);
					SD_Write(buffer,length);
					/* switch LED */
					GPIOE->ODR ^= muster << 8;
				}
				write += 10;
			}  
			/* Close SD Card */
			else if (write == 1)
			{
				SD_Close();
				write--;
			}
			/* Schreiben beendet -> LED löschen */
			else
			{
				GPIOE->ODR |= muster << 8;
				GLCD_DisplayString(8, 1, 1, "Application stopped");
			}
		}
		/* Wenn Taste gedrückt wird, schreiben beenden */
		if((GPIOB->IDR&0x0080) == 0)
		{
			write = 1;
		}
  	}
}
int main(void)
{
    pInt8U pBuffer;
    Int32U Size,TranSize;
    int i=0,j;
    int k=0;
    int cnt=0;
    int tempcnt=0;
    int concurCnt = 0;
    Flo64 curP, curQ;
    int meanCalc=1,displayIntro=1;
    AlgoPowers_t PowerLines[3];
    AlgoPowers_t prevPLines;
    AlgoPowers_t curPLines;
    int LearnNewMean = 1;
    int learning =1;
    int recognized=0;
    int plugOut = 0;
    Flo64 cInterval = 5000;
    int debug = 0;
    
    // int deviceCnt[3] = {0};
    //AlgoLine_t TestLine;
    // pAlgoLine_t pTestLine=&TestLine;
    AlgoDevice_t tmpDev;
//    AlgoDevice_t devProfiles[3]={0};
    AlgoDevice_t devProfiles[3];
    int devNum=0;
    
    
    bool addDevice = 1;
    
    Int32S devLamps[3];
    
    
    #if CDC_DEVICE_SUPPORT_LINE_CODING > 0
        CDC_LineCoding_t CDC_LineCoding;
    UartLineCoding_t UartLineCoding;
    #endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0
        
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  GUI init  START
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // initialize touch parametres
    Int32U cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2;
    ToushRes_t XY_Touch;
    Boolean Touch = FALSE;
    
    
    GLCD_Ctrl (FALSE);
    
    // Init GPIO
    GpioInit();
    
    #ifndef SDRAM_DEBUG
    // MAM init
    MAMCR_bit.MODECTRL = 0;
    MAMTIM_bit.CYCLES  = 3;   // FCLK > 40 MHz
    MAMCR_bit.MODECTRL = 2;   // MAM functions fully enabled
    // Init clock
    InitClock();
    // SDRAM Init
    SDRAM_Init();
    #endif // SDRAM_DEBUG
        // Init VIC   ---interrupt
    VIC_Init();
    
    
    // GLCD init
    GLCD_Init (NULL, NULL);
    
    GLCD_Cursor_Dis(0);
    
    GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U));
    
    GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32);
    
    GLCD_Move_Cursor(cursor_x, cursor_y);
    
    GLCD_Cursor_En(0);
    
    // Init touch screen
    TouchScrInit();
    
    // Touched indication LED
    USB_H_LINK_LED_SEL = 0; // GPIO
    USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
    USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK;
    
    // Init UART 0
    UartInit(UART_0,0,NORM);
    
    
    __enable_interrupt();
    
    GLCD_Ctrl (TRUE);
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //  GUI init  END
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    
    /* devProfiles[0].dP= 101366.22;   //blow dryer
    devProfiles[0].dQ =51765.90;
    
    devProfiles[1].dP= 35957.14;    //light bulb
    devProfiles[1].dQ = 9045.64;
    */
    
    
    //  GLCD_print("Device char %f %f\r\n",devProfiles[devNum].dP, devProfiles[devNum].dQ );
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    // Update the baud rate
    UartLineCoding.dwDTERate = 115200;
    // Update the stop bits number
    UartLineCoding.bStopBitsFormat = UART_ONE_STOP_BIT;
    // Update the parity type
    UartLineCoding.bParityType = UART_NO_PARITY;
    // Update the word width
    UartLineCoding.bDataBits = (UartWordWidth_t)(3);
    //Description: Init UART Baud rate, Word width, Stop bits, Parity type
    UartSetLineCoding(UART_0,UartLineCoding);
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    //calculate the no load powerlines
    //calcMeanRange(&prevPLines);
    // GLCD_print("P %f %f\n\r",prevPLines.P.CiHigh, prevPLines.P.CiLow);
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    for(i=0; i<3; i++){
      devProfiles[i].dP=0;
      devProfiles[i].dQ=0;
      devLamps[i]=0;
    }
    
    // initialize gui
    //gui_monitoringScreen(devProfiles,devLamps);
    gui_mainScreen();
    
    GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff);
    GLCD_SetWindow(0,0,319,239);
    GLCD_TextSetPos(0,0);
    //calculate the no load powerlines
    calcMeanRange(&prevPLines);
    
    while(1)
    {
        
        ///////////////////////////////////////////////////////////////////////////////
        GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff);
        GLCD_SetWindow(0,0,319,239);
        GLCD_TextSetPos(0,0);
        
        /////////////////////////////////////////////////////////////////////////////////
        
        /////////////////////////////////////////////////////////////////////////////////
        //algo    START
        /////////////////////////////////////////////////////////////////////////////////
        if(dataReady){
            dataReady=0;
            GLCD_print("%s\r\n",dataArray);
            //  GLCD_print("reach reach!!!\r\n");
                        
            //convert the incoming data to floats
            dataConversion(dataArray, dataP, dataQ, dataT, cnt);           
            
            //keep track of devices
            GLCD_print("Device zero:%d   one:%d   two:%d\r",devLamps[0],
            devLamps[1],devLamps[2]);
            
            concurCnt=0;
            //detect a step change.
            if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){
                tempcnt=(int) fmod(cnt+4,45);
                while(cnt != tempcnt){
                    if(dataReady){
                        dataConversion(dataArray, dataP, dataQ, dataT, cnt);
                        if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){
                            concurCnt++;
                        }
                        cnt++;
                        dataReady=0;
                        if(cnt>=45){
                            cnt=0;
                        }
                    }
                }
                
                if(concurCnt>=3){
                    //calculate new powerlines
                    calcMeanRange(&curPLines);
                    
                    tmpDev.dP = curPLines.P.mean - prevPLines.P.mean;
                    tmpDev.dQ = curPLines.Q.mean - prevPLines.Q.mean;
                    GLCD_print("test dev dP is %f\r\n",tmpDev.dP);
                    GLCD_print("test dev dQ is %f\r\n",tmpDev.dQ);
                    
                    
                    //in learning phase
                    if(screen==1){
                        
                        // GLCD_print("we can now add DEVICES!!!\r\n");
                        
                        if(devNum==3){
                            GLCD_print("Can't learn anymore devices\r\n");
                            learning=0;
                        }
                        else{
                            if(tmpDev.dP>0 && tmpDev.dQ>0){
                                
                                GLCD_print("add device or not?\r\n");
                                
                                if(addDevice){
                                    
                                    devProfiles[devNum].dP = tmpDev.dP;
                                    devProfiles[devNum].dQ = tmpDev.dQ;
                                    GLCD_print("new profile %d p:%f q:%f\r\n",devNum,
                                    tmpDev.dP,tmpDev.dQ);
                                    devNum++;
                                }
                                
                            }
                            else{
                                GLCD_print("device is unplugged\r\n");
                                //DO THE CHECK
                                
                                //   determineDevice(devProfiles,tmpDev,&devNum,devLamps);
                                //gui_monitoringScreen(devProfiles,devLamps);
                            }
                        }
                    }
                    //in user phase
                    else if (screen==0){
                        if(devNum==0){
                            GLCD_print("No devices on file. Please enter learning mode");
                        }
                        
                        else{
                            //check aganst known devices
                            for(k=0;k<3;k++){
                                GLCD_print("devProfile %d p:%f  q:%f\r\n",k, devProfiles[k].dP,
                                devProfiles[k].dQ);
                                //if plugging out, the deltas will be negative
                                if(tmpDev.dP<0 && tmpDev.dQ<0){
                                    plugOut=1;
                                    tmpDev.dP = fabs(tmpDev.dP);
                                    tmpDev.dQ = fabs(tmpDev.dQ);
                                }
                                
                                if(withinRange(tmpDev,devProfiles[k],cInterval)){
                                    if(plugOut){
                                        GLCD_print("device %d unplugged!\r\n",k);
                                        plugOut=0;
                                        devLamps[k]=0;
                                    }
                                    else{
                                        GLCD_print("device %d plugged in!\r\n",k);
                                        devLamps[k]=1;
                                    }
                                    gui_monitoringScreen(devProfiles,devLamps);
                                    break;
                                }
                            }
                        } // end of if(devNum>0)
                    }   // end user phase
                    prevPLines = curPLines;
                    GLCD_print("prevPlines %f, %f\r",prevPLines.P,prevPLines.Q);
                }       // end of (concurCnt>=3)
            }           // end of detectStepChange()
            cnt++;
            //dataReady=0;
            if(cnt >= 45){
                cnt=0;
            }
        }               // end of dataReady
        /////////////////////////////////////////////////////////////////////////////////
        //                      End of Algo
        /////////////////////////////////////////////////////////////////////////////////
        
        
        /////////////////////////////////////////////////////////////////////////////////
        //      GUI start
        /////////////////////////////////////////////////////////////////////////////////
        
        if(TouchGet(&XY_Touch))
        {
            cursor_x = XY_Touch.X;
            cursor_y = XY_Touch.Y;
            GLCD_Move_Cursor(cursor_x, cursor_y);
            
            if (FALSE == Touch)
            {
                Touch = TRUE;
                USB_H_LINK_LED_FCLR = USB_H_LINK_LED_MASK;
            }
        }
        
        // check the need to swtich screen
        else if(Touch)
        {
            switch(screen)
            {
                
                case 0: // 0 = Monitoring screen
                
                  // Touch logic
                  if(modeButtonState)
                  {
                      if (cursor_x <= 80 && cursor_y >= 190)
                      {
                          gui_toggleMode(devProfiles,devLamps);
                          break;
                      }
                  }
                  if(settingsButtonState)
                  {
                      if (cursor_x >= 239 && cursor_y >= 190)
                      {
                          gui_settingsScreen();
                          break;
                      }
                  }
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 1: // 1 = Learning screen
                  // Touch logic
                  if(modeButtonState)
                  {
                      if (cursor_x <= 80 && cursor_y >= 190) //  mode
                      {
                          gui_toggleMode(devProfiles,devLamps);
                          break;
                      }
                  }
                  if(addDeviceButtonState)
                  {
                      // add device button placement (80,70,240,120)
                      if (cursor_x >= 80 && cursor_y >= 70 && cursor_x <= 240 && cursor_y <= 120)
                      {
                          addDevice = 1;
                          
                          //gui_addDeviceScreen();
                          break;
                      }
                  }
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 2: // 2 = Devices screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 3: // 3: Webserver screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 4: // 4: Inormation Screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 5: // 5: Settings Screen
                  // Back button
                  if (cursor_x <= 59 && cursor_y <= 59)
                  {
                      gui_mainScreen();
                      break;
                  }
                break;
                case 9: // 9: Main Screen
                  // Monitor Button
                  if (cursor_x >= 59 && cursor_y >= 64 && cursor_x <= 119 && cursor_y <= 124)
                  {    
                      gui_monitoringScreen(devProfiles,devLamps);
                      break;
                  }
                  // Learn Button
                  else if (cursor_x >= 129 && cursor_y >= 64 && cursor_x <= 189 && cursor_y <= 124)
                  {
                      gui_learningScreen();
                      break;
                  }
                  // Devices Button
                  else if (cursor_x >= 199 && cursor_y >= 64 && cursor_x <= 259 && cursor_y <= 124)
                  {
                      gui_devicesScreen();
                      break;
                  }
                  // Server Button
                  else if (cursor_x >= 59 && cursor_y >= 134 && cursor_x <= 119 && cursor_y <= 194)
                  {
                      gui_serverScreen();
                      break;
                  }
                  // Info Button
                  else if (cursor_x >= 129 && cursor_y >= 134 && cursor_x <= 189 && cursor_y <= 194)
                  {
                      gui_infoScreen();
                      break;
                  }
                  // Settings Button
                  else if (cursor_x >= 199 && cursor_y >= 134 && cursor_x <= 259 && cursor_y <= 194)
                  {
                      gui_settingsScreen();
                      break;
                  }
                break;
            }
            USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
            Touch = FALSE;
            
        }
        /////////////////////////////////////////////////////////////////////////////////
        
        /////////////////////////////////////////////////////////////////////////////////
    }
    
}
예제 #26
0
파일: LCDtask.c 프로젝트: benwr/blab
// This is the actual task that is run
static portTASK_FUNCTION(vLCDUpdateTask, pvParameters)
{
#if LCD_EXAMPLE_OP == 0
  unsigned short screenColor = 0;
  unsigned short tscr;
  unsigned char curLine;
  unsigned timerCount = 0;
  int xoffset = 0, yoffset = 0;
  unsigned int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  unsigned int x, y;
  int i;
  float hue = 0, sat = 0.2, light = 0.2;
#else  // if LCD_EXAMPLE_OP==1
  unsigned char picIndex = 0;
#endif
  vtLCDMsg msgBuffer;
  vtLCDStruct *lcdPtr = (vtLCDStruct *)pvParameters;

#ifdef INSPECT_STACK
  // This is meant as an example that you can re-use in your own tasks
  // Inspect to the stack remaining to see how much room is remaining
  // 1. I'll check it here before anything really gets started
  // 2. I'll check during the run to see if it drops below 10%
  // 3. You could use break points or logging to check on this, but
  //    you really don't want to print it out because printf() can
  //    result in significant stack usage.
  // 4. Note that this checking is not perfect -- in fact, it will not
  //    be able to tell how much the stack grows on a printf() call and
  //    that growth can be *large* if version 1 of printf() is used.
  unsigned portBASE_TYPE InitialStackLeft = uxTaskGetStackHighWaterMark(NULL);
  unsigned portBASE_TYPE CurrentStackLeft;
  float remainingStack = InitialStackLeft;
  remainingStack /= lcdSTACK_SIZE;
  if (remainingStack < 0.10) {
    // If the stack is really low, stop everything because we don't want it to
    // run out
    // The 0.10 is just leaving a cushion, in theory, you could use exactly all
    // of it
    VT_HANDLE_FATAL_ERROR(0);
  }
#endif

  // Graph initialization
  const unsigned graphXoff = 30;
  const unsigned graphYoff = 10;
  const unsigned graphWidth = 260;
  const unsigned graphHeight = 160;
  uint8_t graphVals[graphWidth];
  for (i = 0; i < graphWidth; i++) {
    graphVals[i] = 0;
  }
  uint8_t graphStart = 0;

  /* Initialize the LCD and set the initial colors */
  GLCD_Init();
  tscr = White;         // may be reset in the LCDMsgTypeTimer code below
  screenColor = Black;  // may be reset in the LCDMsgTypeTimer code below
  GLCD_SetTextColor(tscr);
  GLCD_SetBackColor(screenColor);
  GLCD_Clear(screenColor);
  GLCD_ClearWindow(graphXoff - 1, graphYoff - 1, 1, graphHeight + 1, Blue);
  GLCD_ClearWindow(
      graphXoff - 1, graphYoff + graphHeight + 1, graphWidth + 1, 1, Blue);
  GLCD_DisplayString(22, 47, 0, (unsigned char *)"0min");
  GLCD_DisplayString(22, 37, 0, (unsigned char *)"-1min");
  GLCD_DisplayString(22, 27, 0, (unsigned char *)"-2min");
  GLCD_DisplayString(22, 17, 0, (unsigned char *)"-3min");
  GLCD_DisplayString(22, 7, 0, (unsigned char *)"-4min");
  GLCD_DisplayString(22, 0, 0, (unsigned char *)"0.0m");
  GLCD_DisplayString(14, 0, 0, (unsigned char *)"0.5m");
  GLCD_DisplayString(8, 0, 0, (unsigned char *)"1.0m");
  GLCD_DisplayString(2, 0, 0, (unsigned char *)"1.5m");

// Note that srand() & rand() require the use of malloc() and should not be used
// unless you are using
//   MALLOC_VERSION==1
#if MALLOC_VERSION == 1
  srand((unsigned)55);  // initialize the random number generator to the same
                        // seed for repeatability
#endif

  curLine = lcdNUM_SMALL_LINES - 1;
  // This task should never exit
  for (;;) {
#ifdef INSPECT_STACK
    CurrentStackLeft = uxTaskGetStackHighWaterMark(NULL);
    float remainingStack = CurrentStackLeft;
    remainingStack /= lcdSTACK_SIZE;
    if (remainingStack < 0.10) {
      // If the stack is really low, stop everything because we don't want it to
      // run out
      VT_HANDLE_FATAL_ERROR(0);
    }
#endif

#if LCD_EXAMPLE_OP == 0
    // Wait for a message
    if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) !=
        pdTRUE) {
      VT_HANDLE_FATAL_ERROR(0);
    }

    // Log that we are processing a message -- more explanation of logging is
    // given later on
    vtITMu8(vtITMPortLCDMsg, getMsgType(&msgBuffer));
    vtITMu8(vtITMPortLCDMsg, getMsgLength(&msgBuffer));

    // Take a different action depending on the type of the message that we
    // received
    switch (getMsgType(&msgBuffer)) {
    case LCDMsgTypePrint: {
      // This will result in the text printing in the last five lines of the
      // screen
      char lineBuffer[lcdCHAR_IN_LINE + 1];
      copyMsgString(lineBuffer, &msgBuffer, lcdCHAR_IN_LINE);
      // clear the line
      GLCD_ClearLn(curLine, 1);
      // show the text
      GLCD_DisplayString(curLine, 0, 0, (unsigned char *)lineBuffer);
      curLine++;
      if (curLine == lcdNUM_SMALL_LINES) {
        curLine = lcdNUM_SMALL_LINES - 1;
      }
      break;
    }
    case LCDMsgTypePoint: {
      graphVals[graphStart] = getMsgPoint(&msgBuffer);
      break;
    }
    case LCDMsgTypeTimer: {
      // Note: if I cared how long the timer update was I would call my
      // routine
      //    unpackTimerMsg() which would unpack the message and get that value
      // Each timer update will cause a circle to be drawn on the top half of
      // the screen
      //   as explained below

      if (timerCount % 2 == 0) {
        /* ************************************************** */
        // Find a new color for the screen by randomly (within limits)
        // selecting
        // HSL values
        // This can be ignored unless you care about the color map
        /*
                        #if MALLOC_VERSION==1
                        hue = rand() % 360;
                        sat = (rand() % 1024) / 1023.0; sat = sat * 0.5; sat
           +=
           0.5;
                        light = (rand() % 1024) / 1023.0;	light = light *
           0.8; light += 0.10;
                        #else
                        hue = (hue + 1); if (hue >= 360) hue = 0;
                        sat+=0.01; if (sat > 1.0) sat = 0.20;
                        light+=0.03; if (light > 1.0) light = 0.20;
                        #endif
                        screenColor = hsl2rgb(hue,sat,light);

                        // Now choose a complementary value for the text color
                        hue += 180;
                        if (hue >= 360) hue -= 360;
                        tscr = hsl2rgb(hue,sat,light);
                        GLCD_SetTextColor(tscr);
                        GLCD_SetBackColor(screenColor);

                        unsigned short int *tbuffer = buffer;
                        //int i;
                        for(i = BUF_LEN; i--;) {
                                tbuffer[i] = screenColor;
                        }
        */
        // End of playing around with figuring out a random color
        /* ************************************************** */

        // clear the top half of the screen
        // GLCD_ClearWindow(0,0,320,120,screenColor);

        /*
                        // Now we are going to draw a circle in the buffer
                        // count is how many pixels are in the circle
                        int	count = 50;
                        float radius;
                        float inc, val, offset = MAX_RADIUS;
                        unsigned short circleColor;
                        inc = 2*M_PI/count;
                        xmax = 0;
                        ymax = 0;
                        xmin = 50000;
                        ymin = 50000;
                        val = 0.0;
                        for (i=0;i<count;i++) {
                                // Make the circle a little thicker
                                // by actually drawing three circles w/
           different radii
                                float cv = cos(val), sv=sin(val);
                                circleColor = (val*0xFFFF)/(2*M_PI);
                                GLCD_SetTextColor(circleColor);
                                for
           (radius=MAX_RADIUS-2.0;radius<=MAX_RADIUS;radius+=1.0) {
                                        x = round(cv*radius+offset);
                                        y = round(sv*radius+offset);
                                        if (x > xmax) xmax = x;
                                        if (y > ymax) ymax = y;
                                        if (x < xmin) xmin = x;
                                        if (y < ymin) ymin = y;
                                        //tbuffer[(y*((MAX_RADIUS*2)+1)) + x]
           =
           circleColor;
                                }
                                val += inc;
                        }
        */
        // GLCD_ClearWindow(graphXoff, graphYoff, graphWidth, graphHeight,
        // screenColor);
        graphStart = (graphStart + 1) % graphWidth;

        DEBUG_OUT(0xf);
        for (i = 0; i < graphWidth; i++) {
          unsigned index = (i + graphStart) % graphWidth;
          unsigned y = graphHeight - graphVals[index] + graphYoff;
          unsigned x = i + graphXoff;
          GLCD_ClearWindow(x, graphYoff, 1, graphHeight, screenColor);
          GLCD_PutPixel(x, y);
        }
        DEBUG_OUT(0x0);

      }  // else {

      // We are going to write out the buffer
      //   back onto the screen at a new location
      // This is *very* fast

      /*
      // First, clear out where we were
      GLCD_ClearWindow(xoffset,yoffset,xmax+1-xmin,ymax+1-ymin,screenColor);
      // Pick the new location
      #if MALLOC_VERSION==1
      xoffset = rand() % (320-(xmax+1-xmin));
      yoffset = rand() % (120-(ymax+1-ymin));
      #else
      xoffset = (xoffset + 10) % (320-(xmax+1-xmin));
      yoffset = (yoffset + 10) % (120-(ymax+1-ymin));
      #endif
      // Draw the bitmap
      GLCD_Bitmap(xoffset,yoffset,xmax+1-xmin,ymax-1-ymin,(unsigned
      char*)buffer);
      */
      //}

      timerCount++;
      if (timerCount >= 100) {
        // every so often, we reset timer count and start again
        // This isn't for any important reason, it is just to for this example
        // code to do "stuff"
        timerCount = 0;
      }
      break;
    }
    default: {
      // In this configuration, we are only expecting to receive timer
      // messages
      VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
      break;
    }
    }  // end of switch()

// Here is a way to do debugging output via the built-in hardware -- it requires
// the ULINK cable and the debugger in the Keil tools to be connected.  You can
// view PORT0 output in the "Debug(printf) Viewer" under "View->Serial Windows".
// You have to enable "Trace" and "Port0" in the Debug setup options.  This
// should not be used if you are using Port0 for printf(). There are 31 other
// ports and their output (and port 0's) can be seen in the
// "View->Trace->Records" windows.  You have to enable the ports in the Debug
// setup options.  Note that unlike ITM_SendChar() this "raw" port write is not
// blocking.  That means it can overrun the capability of the system to record
// the trace events if you go too quickly; that won't hurt anything or change
// the program execution and you can tell if it happens because the
// "View->Trace->Records" window will show there was an overrun.

// vtITMu16(vtITMPortLCD,screenColor);

#elif LCD_EXAMPLE_OP == 1
    // In this alternate version, we just keep redrawing a series of bitmaps as
    // we receive timer messages

    // Wait for a message
    if (xQueueReceive(lcdPtr->inQ, (void *)&msgBuffer, portMAX_DELAY) !=
        pdTRUE) {
      VT_HANDLE_FATAL_ERROR(0);
    }
    if (getMsgType(&msgBuffer) != LCDMsgTypeTimer) {
      // In this configuration, we are only expecting to receive timer messages
      VT_HANDLE_FATAL_ERROR(getMsgType(&msgBuffer));
    }
    /* go through a  bitmap that is really a series of bitmaps */
    picIndex = (picIndex + 1) % 9;
    GLCD_Bmp(99,
             99,
             120,
             45,
             (unsigned char *)&ARM_Ani_16bpp[picIndex * (120 * 45 * 2)]);
#else
    Bad setting
#endif
  }
}
예제 #27
0
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {                       /* Main Program                       */

//************************************************************************************************************
    /* this is contiki-code */
    watchdog_init();

    /* Initialize hardware. */
    clock_init();

    /* UART4 Initialization */
//	uart4_init(115200);
    USBD_Init(&USB_OTG_dev,	USB_OTG_FS_CORE_ID,	&USR_desc, &USBD_CDC_cb, &USR_cb);

    // Led initialization
    leds_init();
    leds_on(LEDS_BLUE);


    PRINTF("\r\nStarting ");
    PRINTF(CONTIKI_VERSION_STRING);
    PRINTF(" on %s \r\n", PLATFORM_NAME);

#ifdef __USE_LCD
    GLCD_Init();                          /* Initialize graphical LCD display   */

    GLCD_Clear(White);                    /* Clear graphical LCD display        */
    GLCD_SetBackColor(DarkGreen);
    GLCD_SetTextColor(White);
    GLCD_DisplayString(0, 0, __FI, " KUSZ - TU Dortmund ");
    GLCD_DisplayString(1, 0, __FI, "       contiki      ");
    GLCD_DisplayString(2, 0, __FI, " www.tu-dortmund.de ");
    GLCD_SetBackColor(White);
    GLCD_SetTextColor(Blue);

    watchdog_periodic();
#endif // __USE_LCD

    /*
     * Initialize Contiki and our processes.
     */

#ifdef WITH_SERIAL_LINE_INPUT
    //  uart1_set_input(serial_line_input_byte);
    // serial_line_init();
#endif

    /* rtimer and ctimer should be initialized before radio duty cycling layers*/
    rtimer_init();

    process_init();

    process_start(&sensors_process, NULL);

    /* etimers must be started before ctimer_init */
    process_start(&etimer_process, NULL);
    ctimer_init();

    /* Start radio and radio receive process */
    NETSTACK_RADIO.init();

    /* makes use of cpu-specific RNG peripheral - no seed needed */
    random_init(0);

    /* Set addresses BEFORE starting tcpip process */
    addr.u8[0] = 0x02;
    addr.u8[1] = *((uint8_t*)0x1FFF7A10);
    addr.u8[2] = *((uint8_t*)0x1FFF7A10+1);
    addr.u8[3] = 0xFF;
    addr.u8[4] = 0xFE;
    addr.u8[5] = *((uint8_t*)0x1FFF7A10+2);
    addr.u8[6] = *((uint8_t*)0x1FFF7A10+3);
    addr.u8[7] = *((uint8_t*)0x1FFF7A10+4);

    memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t));
    rimeaddr_set_node_addr(&addr);

    rf230_set_pan_addr(0xabcd,0xbabe,(uint8_t *)&addr.u8);
    rf230_set_channel(CHANNEL_802_15_4);
    rf230_set_txpower(0); /* max */
    PRINTF("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

    /* Initialize stack protocols */
    queuebuf_init();

    NETSTACK_RDC.init();
    NETSTACK_MAC.init();
    NETSTACK_NETWORK.init();

#define ANNOUNCE_BOOT 1
#if ANNOUNCE_BOOT
    PRINTF("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
           CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
           rf230_get_txpower());
#if UIP_CONF_IPV6_RPL
    PRINTF("RPL Enabled\n");
#endif
#if UIP_CONF_ROUTER
    PRINTF("Routing Enabled\n");
#endif
#endif /* ANNOUNCE_BOOT */

    process_start(&tcpip_process, NULL);

    /* Autostart other processes */
    autostart_start(autostart_processes);

#if ANNOUNCE_BOOT
    PRINTF("Online\n");
#endif /* ANNOUNCE_BOOT */

    energest_init();
    ENERGEST_ON(ENERGEST_TYPE_CPU);
    watchdog_start();


    while (1) {                           /* Loop forever                       */

        watchdog_periodic();

        process_run();

    }
}
예제 #28
0
파일: main.c 프로젝트: nandojve/embedded
int_t main(void)
{
   error_t error;
   NetInterface *interface;
   OsTask *task;
   MacAddr macAddr;
#if (APP_USE_DHCP == DISABLED)
   Ipv4Addr ipv4Addr;
#endif
#if (APP_USE_SLAAC == DISABLED)
   Ipv6Addr ipv6Addr;
#endif

   //Initialize kernel
   osInitKernel();
   //Configure debug UART
   debugInit(115200);

   //Start-up message
   TRACE_INFO("\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("*** CycloneTCP Web Server Demo ***\r\n");
   TRACE_INFO("**********************************\r\n");
   TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n");
   TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
   TRACE_INFO("Target: SAM3X\r\n");
   TRACE_INFO("\r\n");

   //Configure I/Os
   ioInit();
   //ADC initialization
   adcInit();

   //Initialize LCD display
   GLCD_Init();
   GLCD_SetBackColor(Blue);
   GLCD_SetTextColor(White);
   GLCD_Clear(Blue);

   //Welcome message
   lcdSetCursor(0, 0);
   printf("Web Server Demo\r\n");

   //Generate a random seed

   //PRNG initialization
   error = yarrowInit(&yarrowContext);
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize PRNG!\r\n");
   }

   //Properly seed the PRNG
   error = yarrowSeed(&yarrowContext, seed, sizeof(seed));
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to seed PRNG!\r\n");
   }

   //TCP/IP stack initialization
   error = tcpIpStackInit();
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
   }

   //Configure the first Ethernet interface
   interface = &netInterface[0];

   //Set interface name
   tcpIpStackSetInterfaceName(interface, "eth0");
   //Set host name
   tcpIpStackSetHostname(interface, "WebServerDemo");
   //Select the relevant network adapter
   tcpIpStackSetDriver(interface, &sam3xEthDriver);
   tcpIpStackSetPhyDriver(interface, &dm9161PhyDriver);
   //Set external interrupt line driver
   tcpIpStackSetExtIntDriver(interface, &extIntDriver);
   //Set host MAC address
   macStringToAddr(APP_MAC_ADDR, &macAddr);
   tcpIpStackSetMacAddr(interface, &macAddr);

   //Initialize network interface
   error = tcpIpStackConfigInterface(interface);
   //Any error to report?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name);
   }

#if (IPV4_SUPPORT == ENABLED)
#if (APP_USE_DHCP == ENABLED)
   //Get default settings
   dhcpClientGetDefaultSettings(&dhcpClientSettings);
   //Set the network interface to be configured by DHCP
   dhcpClientSettings.interface = interface;
   //Disable rapid commit option
   dhcpClientSettings.rapidCommit = FALSE;

   //DHCP client initialization
   error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings);
   //Failed to initialize DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize DHCP client!\r\n");
   }

   //Start DHCP client
   error = dhcpClientStart(&dhcpClientContext);
   //Failed to start DHCP client?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start DHCP client!\r\n");
   }
#else
   //Set IPv4 host address
   ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr);
   ipv4SetHostAddr(interface, ipv4Addr);

   //Set subnet mask
   ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr);
   ipv4SetSubnetMask(interface, ipv4Addr);

   //Set default gateway
   ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr);
   ipv4SetDefaultGateway(interface, ipv4Addr);

   //Set primary and secondary DNS servers
   ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 0, ipv4Addr);
   ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr);
   ipv4SetDnsServer(interface, 1, ipv4Addr);
#endif
#endif

#if (IPV6_SUPPORT == ENABLED)
#if (APP_USE_SLAAC == ENABLED)
   //Get default settings
   slaacGetDefaultSettings(&slaacSettings);
   //Set the network interface to be configured
   slaacSettings.interface = interface;

   //SLAAC initialization
   error = slaacInit(&slaacContext, &slaacSettings);
   //Failed to initialize SLAAC?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize SLAAC!\r\n");
   }

   //Start IPv6 address autoconfiguration process
   error = slaacStart(&slaacContext);
   //Failed to start SLAAC process?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start SLAAC!\r\n");
   }
#else
   //Set link-local address
   ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr);
   ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set IPv6 prefix
   ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr);
   ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH);

   //Set global address
   ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr);
   ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID);

   //Set router
   ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr);
   ipv6SetRouter(interface, &ipv6Addr);

   //Set primary and secondary DNS servers
   ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 0, &ipv6Addr);
   ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr);
   ipv6SetDnsServer(interface, 1, &ipv6Addr);
#endif
#endif

   //Get default settings
   httpServerGetDefaultSettings(&httpServerSettings);
   //Bind HTTP server to the desired interface
   httpServerSettings.interface = &netInterface[0];
   //Listen to port 80
   httpServerSettings.port = HTTP_PORT;
   //Specify the server's root directory
   strcpy(httpServerSettings.rootDirectory, "/www/");
   //Set default home page
   strcpy(httpServerSettings.defaultDocument, "index.shtm");
   //Callback functions
   httpServerSettings.authCallback = httpServerAuthCallback;
   httpServerSettings.cgiCallback = httpServerCgiCallback;
   httpServerSettings.uriNotFoundCallback = httpServerUriNotFoundCallback;

   //HTTP server initialization
   error = httpServerInit(&httpServerContext, &httpServerSettings);
   //Failed to initialize HTTP server?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to initialize HTTP server!\r\n");
   }

   //Start HTTP server
   error = httpServerStart(&httpServerContext);
   //Failed to start HTTP server?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start HTTP server!\r\n");
   }

   //Start TCP echo service
   error = tcpEchoStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP echo service!\r\n");
   }

   //Start UDP echo service
   error = udpEchoStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP echo service!\r\n");
   }

   //Start TCP discard service
   error = tcpDiscardStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP discard service!\r\n");
   }

   //Start UDP discard service
   error = udpDiscardStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP discard service!\r\n");
   }

   //Start TCP chargen service
   error = tcpChargenStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start TCP chargen service!\r\n");
   }

   //Start UDP chargen service
   error = udpChargenStart();
   //Failed to TCP echo service?
   if(error)
   {
      //Debug message
      TRACE_ERROR("Failed to start UDP chargen service!\r\n");
   }

   //Create user task
   task = osCreateTask("User Task", userTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Create a task to blink the LED
   task = osCreateTask("Blink", blinkTask, NULL, 500, 1);
   //Failed to create the task?
   if(task == OS_INVALID_HANDLE)
   {
      //Debug message
      TRACE_ERROR("Failed to create task!\r\n");
   }

   //Start the execution of tasks
   osStartKernel();

   //This function should never return
   return 0;
}
예제 #29
0
/*----------------------------------------------------------------------------
  Main Program
 *----------------------------------------------------------------------------*/
int main (void) {
	int i;
	char potOutput[20];
	char answer[10];

	//Following statement sets the timer interrupt frequency
	//The clock rate on this boards MCU is 72 Mhz - this means
	//every second there will be 72 million clocks. So, if use this
	//as the parameter to the function the interrupt rate is going
	//to be every second. If it is reduced to 100 times less then
	//it will do that many clocks in 100 times less time, i.e. 10 msecs.
	//NOTE: We could have chosen to generate a timer interrupt every 1 msec
	//if we wished and that would be quite acceptable in which case we would
	//need to modify the interrupt handler routine in IRQ.c file.
  	SysTick_Config(SystemCoreClock/10000);  /* Generate interrupt each 10 ms      */

   	
	LED_init(); /* LED Initialization                 */

	pin_PA4_For_Speaker(); //Function that initializes the Speaker
		
	ADC_init();  //Function that initializes ADC

	GLCD_Init(); /* Initialize graphical LCD display   */
  		
	joyStick_Init(); // Initialise the joystick

	userButton_Init(); // Initialise User Button

	userButton_IntrEnable(); //initialise the User button as an interrupt source

  //Here we initialise the Joystick switches as interrupt sources
  joyStick_IntrEnable_PG15_13();
	joyStick_IntrEnable_PG7();
	joyStick_IntrEnable_PD3();
	
	AD_done = 0;
	ADC1->CR2 |= (1UL << 22);       		//Start the ADC conversion
	doTone = 0;
	
	WelcomeScreen();

	


// initialiseGetAnswer(answer, 10);
//	if(currentState == ON_DIFFICULTY_SCREEN)
//	{
//			GLCD_Clear(White);
//			if(currDifficulty == 0){
//				currDifficulty = 1;
//			}
//			updateNextDifficulty(nextDifficulty);
//			DisplayInstructions(NULL,currentScore,currDifficulty,1);
//			DrawBarGraph(BAR_X,BAR_Y,currDifficulty * 20,BAR_HEIGHT,BAR_VALUE);
//	}	
	while (TRUE) {
		
		
		// Program pauses whilst Countdown timer ticks - this is necessary because the program does not like interrupts and delay timers
		// i.e. SysTick does not work whilst interrupts being handled
		// Gives the user time to memorise the code
		// Program then advances to accept answer state
		if(currentState == QUESTION_SCREEN) { // Question Screen Delay countdown timer
			RunTimer(5000);
			
			currentState = ANSWER_SCREEN;
			answerScreen();
			
			Vectored_Interrupt(USER_BUTTON); // Simulate user pressing the button
		}
		
		
		
//								
//				//RunTimer(TIMER_LENGTH);
//			GLCD_SetBackColor(Red);
//			DrawBarGraph(100,6*24,barWidth,15,1);
//			delay10th(10000);
//			GLCD_SetBackColor(White);
//			barWidth -= 20;
//			if(barWidth <= 0){
//				barWidth = 100;
//			}
//			GLCD_DisplayString(6,0,__FI,"                   ");
				//Check to see if ADC sampling is completed
//				if (AD_done) {
//					//Yes, so get part of the sample value
//					c = (AD_last >> 8) + 4;
//					if (doTone) {
//						//If enabled, switch the tone on
//							sprintf(potOutput,"Pot = %d",c);
//							displayTestMessage(1,0,potOutput,0);
//				   		generate_Tone_On_Speaker(c * 50, 10);
//					}
//					AD_done = 0;  					//Reset the ADC complete flag waiting for next sample
//					ADC1->CR2 |= (1UL << 22);   	//Start the next ADC conversion
	}
}
예제 #30
0
파일: LCDtask.c 프로젝트: via/ece4534
// This is the actual task that is run
static portTASK_FUNCTION( vLCDUpdateTask, pvParameters )
{
	portTickType xUpdateRate, xLastUpdateTime;
	vtLCDMsg msgBuffer;
	vtLCDStruct *lcdPtr = (vtLCDStruct *) pvParameters;
	//counter for line display
	//uint8_t counter = 0;
	/* Initialize the LCD */
	GLCD_Init();
	GLCD_Clear(White);

	const char line_0[] = "Calc. Position";
	const char line_2[] = "Bearing from #0";
	const char line_4[] = "GPS";
	const char line_6[] = "Bearing from GPS";
	const char line_8[] = "RSSI [0, 1, 2]";
	int initial = 0;

	// Scale the update rate to ensure it really is in ms
	xUpdateRate = lcdWRITE_RATE_BASE / portTICK_RATE_MS;

	/* We need to initialise xLastUpdateTime prior to the first call to 
	vTaskDelayUntil(). */
	xLastUpdateTime = xTaskGetTickCount();
	// Note that srand() & rand() require the use of malloc() and should not be used unless you are using
	//   MALLOC_VERSION==1
	#if MALLOC_VERSION==1
	srand((unsigned) 55); // initialize the random number generator to the same seed for repeatability
	#endif
	// Like all good tasks, this should never exit
	for(;;)
	{	
	if (LCD_STATE == 2){
		/* Ask the RTOS to delay reschduling this task for the specified time */
		vTaskDelayUntil( &xLastUpdateTime, xUpdateRate );
		// wait for a message from another task telling us to send/recv over i2c
		
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}

		//Log that we are processing a message
		vtITMu8(vtITMPortLCDMsg,msgBuffer.length);

		if (msgBuffer.buf[0] == 0xDE && msgBuffer.buf[1] == 0xAD && msgBuffer.buf[2] == 0xBE){
			GLCD_Clear(White);
			LCD_STATE = 3;		
		}
		else {
			char buf[21];
			sprintf(buf, "%4.6f, %4.6f", msgBuffer.tlat, msgBuffer.tlon);
			GLCD_DisplayString(0,0,1,(unsigned char *)msgBuffer.buf);
			GLCD_DisplayString(1,0,1,(unsigned char *) buf);
		}
	}
	else if (LCD_STATE == 3){
		/* Ask the RTOS to delay reschduling this task for the specified time */
		//vTaskDelayUntil( &xLastUpdateTime, xUpdateRate );

		// wait for a message from another task telling us to send/recv over i2c
		if (xQueueReceive(lcdPtr->inQ,(void *) &msgBuffer,portMAX_DELAY) != pdTRUE) {
			VT_HANDLE_FATAL_ERROR(0);
		}
		#if USE_GPIO == 1
		GPIO_SetValue(1, 0x20000000);
		#endif
		//Log that we are processing a message
		vtITMu8(vtITMPortLCDMsg,msgBuffer.length);
		// Decide what color and then clear the line
		GLCD_SetTextColor(Black);
		GLCD_SetBackColor(White);

		if(!initial){
			GLCD_DisplayString(0, 0, 1, (unsigned char *)line_0);
			GLCD_DisplayString(2, 0, 1, (unsigned char *)line_2);
			GLCD_DisplayString(4, 0, 1, (unsigned char *)line_4);
			GLCD_DisplayString(6, 0, 1, (unsigned char *)line_6);
			GLCD_DisplayString(8, 0, 1, (unsigned char *)line_8);
			initial++;
		}
		GLCD_DisplayString(msgBuffer.line_num + 1, 0, 1, (unsigned char *)msgBuffer.buf);
		#if USE_GPIO == 1
		GPIO_ClearValue(1, 0x20000000);
		#endif
	}
else{
	//	Bad setting
	}	
	}
}