Esempio n. 1
0
//*****************************************************************************
//  ADD CODE: Main Function
//*****************************************************************************
int 
main(void)
{
	char buffer[50];
	
	project_init();
	
	sprintf(buffer, "\r\nFinished Initializing the project\r\n");
	uartTxPoll(UART0_BASE, buffer);
	
  if (LedTaskInit() == 1) {
		
	}
	
	sprintf(buffer, "Finished Initializing the LED Task\r\n");
	uartTxPoll(UART0_BASE, buffer);

	vTaskStartScheduler();

  while(1)
  {
		// This should eventually be in a different task
		// Write to the GPIOF pin some data out
		// GPIOF->DATA = 0x00;
     // Infinite Loop
  }
}
Esempio n. 2
0
bool detectMaster(void)
{
 char myChar = 0;
 
 while(1)
 {
	 // Send discovery packets to U5
	 uart5Tx(UART_CMD_DISCOVERY);
	 
	 // Check for a discovery packert on U2
	 myChar = uart2Rx(false);
	 
	 // If we recieved a discovery packet on U2, send a SLAVE_FOUND command
	 // back on U2 and return false.  
	 if( myChar == UART_CMD_DISCOVERY )
	 {
		 uartTxPoll(UART0,"SLAVE: TX UART_CMD_SLAVE_FOUND\n\r");
//		 i = 10000;
//		 while(i > 0) i--;
		 uart2Tx(UART_CMD_SLAVE_FOUND);
		 return false; //This device is the slave
	 }
	 
	 // Check for a SLAVE_FOUND command on U5.  If you receive the SLAVE_FOUND
	 // command, return true, else check everything again
	 myChar = uart5Rx(false);
	 if(myChar == UART_CMD_SLAVE_FOUND)
	 {
		 uartTxPoll(UART0,"MASTER: RX UART_CMD_SLAVE_FOUND\n\r");
		 return true; // This device is the master
	 }
	
		// If no messages are received on either of the UARTs,
		// wait 1 second before sending another discovery message
		uartTxPoll(UART0,"Discovery: Waiting 1 Second\n\r");     
		while(OneSecond == false){};
		uartTxPoll(UART0,"Discovery: Waiting Done\n\r");
		OneSecond=false;
		secondCount++;
		if (secondCount == 3) 
		{
			uartTxPoll(UART0,"MASTER: RX UART_CMD_SLAVE_FOUND\n\r");
			return true;
		}
	}
}
Esempio n. 3
0
//*****************************************************************************
//*****************************************************************************
int 
main(void)
{
	char data[80];
	//uint32_t adctest;
	bool masterDevice = false;
	
	//CONFIGURE BOARD
  PLL_Init(); //given to us
	initBoard();
	
	sprintf(data, "About to detect master.. \n\r");
	uartTxPoll(UART0, data);
	
	masterDevice = detectMaster();

	sprintf(data, "Detected master.. \n\r");
	uartTxPoll(UART0, data);
	
	if (masterDevice)
	{
			masterApp();
	}
	else
	{
			slaveApp();
	}
	
	//MAIN LOOP
  while(1)
  {
//		if (check)
//		{
//			adctest = GetADCval(1);
//			sprintf(data, "ADCVAL: %d \n\r", adctest);
//			uartTxPoll(UART0, data);
//			check = false;
//		}
//		examineButtons();
		
  };

  
}
Esempio n. 4
0
void slaveApp(void)
{
	char myChar;
	char message[80];
	
	uartTxPoll(UART0, "Hello this the slave talking..\n\r");
	while(1) 
	{
		myChar = uart5Rx(false);
		if (myChar != -1)
		{
			sprintf(message, "Received %d.. \n\r", (int)myChar);
			uartTxPoll(UART0, message);
			count = 77; //(int) myChar;
		}
		updateCount();
//		while(OneSecond == false){};
//		OneSecond = false;
//		uartTxPoll(UART0, "Sent clear..\n\r");
//		uart2Tx(UART_CMD_WDT_CLEAR);
	}
}
Esempio n. 5
0
void masterApp(void)
{
	//char myChar;
	
	uartTxPoll(UART0, "Hi! This is your master talking!\n\r");
	while(1) 
	{
//		myChar = uart5Rx(true);
//		if (myChar == UART_CMD_WDT_CLEAR)
//		{
//			uartTxPoll(UART0, "CLEAR!\n\r");
//		}
		examineButtons();
  	updateDisplay();
		updateGenerationRate();
		updateArray();
		uart2Tx(5);
		//uartTxPoll(UART0, "Sent a message!\n\r");
	}
}
Esempio n. 6
0
int 
main(void)
{
  //Local Variables
  bool displayMode = true;//True if display mode, false if in data entry mode
	//Push buttons
	bool upPB = false;
	bool rightPB = false;
	bool downPB = false;
	bool leftPB = false;
	bool modePB = false; 
	//Push buttons shift registers
	uint16_t shiftRegSW2 = 0xFFFF;
	uint16_t shiftRegSW3 = 0xFFFF;
	uint16_t shiftRegSW4 = 0xFFFF;
	uint16_t shiftRegSW5 = 0xFFFF;
	uint16_t shiftRegSW6 = 0xFFFF;
	//Initial display message
  uint8_t displayArray [SAVED_MSG_LEN_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  uint8_t inputArray [17] =
		{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  //Mark the indexcies of the array
	uint8_t endIndex = 19;
	uint8_t currIndex = 0;
	uint8_t inputIndex = 0;
	uint8_t tempIndex = 0;
	//Flag for overflwoing max char array length
	bool overflow = false;
	//Init color
  uint8_t color;
  //ADCval1
  uint32_t ADCval1 = 0;
  uint32_t ADCval2 = 0;
  //Current string
  char myString[21] = "hello world";
  char myChar;
  int8_t stringIndex=-1;

  // Initialize the PLLs so the the main CPU frequency is 80MHz
  PLL_Init();
  
  //Configure Port C
  initPortC();
  //Configure the SYSTICK timer 12.5uS ticks
  SYSTICKConfig(1000, true);
  //Configure Timer0 1mS ticks
  TIMER0Config(80000);
  //Configure watchdog with 1s reset
  WatchdogTIMERConfig();
  

  // Initialize the GPIO Ports
  initializeGPIOPort(PORTA, &portA_config);
  initializeGPIOPort(PORTB, &portB_config);
  initializeGPIOPort(PORTC, &portC_config);
  initializeGPIOPort(PORTD, &portD_config);
  initializeGPIOPort(PORTE, &portE_config);
  initializeGPIOPort(PORTF, &portF_config);
  
  // Initialize SPI0 interface
  initializeSPI(SSI0, PHASE, POLARITY);
  //Init ADC
  ADCInit();
  initializeDisplay();
  // Set up the UARTS for 115200 8N1
  InitializeUART(UART0);
  InitializeUART(UART2);
  InitializeUART(UART5);
  
  // Since PD7 is shared with the NMI, we need to clear the lock register and 
  // set the commit register so that all the pins alternate functions can
  // be used.
  GPIO_PORTD_LOCK_R = 0x4C4F434B;
  GPIO_PORTD_CR_R = 0xFF;
  initializeGPIOPort(PORTD, &portD_config);
  EnableInterrupts(); 
  //Get initial ADC values
  pwm = GetADCval(POT_RIGHT) / 40;
  ADCval2 = GetADCval(POT_LEFT) / 575;
  
  
  // Print out the current string
  uartTxPoll(UART0,"Hello World\n\r");

  while(1)
  {
	if(checkADC){
	 pwm = GetADCval(POT_RIGHT) / 40;
	 ADCval2 = GetADCval(POT_LEFT) / 600;
	 checkADC = false;
	}

    //On systick interrupt display the current character and poll the buttons
    if (refreshLED){
		if (displayMode){
			displayLEDChar(displayArray[currIndex], ADCval2);
		}
		else{
			displayLEDChar(inputArray[inputIndex], ADCval2);
		}
		refreshLED = false;
	}
	if (buttonPoll){
		//Check if any buttons have been pushed
		//If so debounce them 
		buttonPoll = false;
		//SW2
		shiftRegSW2 = debounce(PORTA, SW2, shiftRegSW2);
		upPB = checkPB(shiftRegSW2);
		//SW3	
		shiftRegSW3 = debounce(PORTA, SW3, shiftRegSW3);
		rightPB = checkPB(shiftRegSW3);			
		//SW4
		shiftRegSW4 = debounce(PORTD, SW4, shiftRegSW4);
		downPB = checkPB(shiftRegSW4);
		//SW5
		shiftRegSW5 = debounce(PORTD, SW5, shiftRegSW5);	
		leftPB = checkPB(shiftRegSW5);
		//SW6
		shiftRegSW6 = debounce(PORTF, SW6, shiftRegSW6);
		modePB = checkPB(shiftRegSW6);

	}//End polling
		
		//Display Mode
		if (displayMode){
		  //Check if right button is pressed
				if(rightPB){
					//Clear the button press
					rightPB = false;
					//Display the next character in order in green
					color = GREEN_EN;
					if(currIndex == endIndex)
						currIndex = 0;
					else
						currIndex++;
				}
				//Check if left button is pressed
				else if(leftPB){
					//Clear the button press
					leftPB = false;
					//Display the next character in reverse order in red
					color = RED_EN;
					if(currIndex == 0)
						currIndex = endIndex;
					else
						currIndex--;
				}
				//Check if mode button is pushed
				if(modePB){
					//Clear the button press
					modePB = false;
					//change mode and reset parameters
					displayMode = false;
					inputIndex = 0;
					currIndex = 0;
					endIndex = 0;
					overflow = false;
					tempIndex = 0;
					displayArray[0] = 0;
				}
		}
		
		//Input Mode
		else{
			//Check if right button is pressed
				if(rightPB || leftPB){
					//Clear the button press
					rightPB = false;
					leftPB = false;
					//Save the current input character in the display array if
					//there is enough space
					if (tempIndex >= SAVED_MSG_LEN_MAX){
						tempIndex= 0;
						overflow = true;
					}	
					displayArray[tempIndex] = inputArray[inputIndex];
					tempIndex++;					
					
				}
				//Check if up button is pressed
				else if(upPB){
					//Clear the button press
					upPB = false;
					//Display the next character in order in input array
					if(inputIndex == 15)
						inputIndex = 0;
					else
						inputIndex++;
				}
				//Check if down button is pressed
				else if(downPB){
					//Clear the button press
					downPB = false;
					//Display the next character in reverse order input array
					if(inputIndex == 0)
						inputIndex = 15;
					else
						inputIndex--;
				}
				if(modePB){
					//Clear the button press
					modePB = false;
					//change mode to display and reset parameters
					displayMode = true;
					color = GREEN_EN;
					if(overflow){
						endIndex = SAVED_MSG_LEN_MAX - 1;
					}
					else if (tempIndex != 0)
						endIndex = tempIndex - 1;
				}
		}
  }
}