コード例 #1
0
ファイル: ultrasound.c プロジェクト: ModelCar/Autonomous-Car
/****************************************************************************
  Function:
    unsigned int ultrasound_read(long Address, unsigned char settings)

  Description:
   // This function receives one Byte via the corresponding UART from the Address

  Precondition:
    Call ultrasound_init(long Address) prior to use this function

  Parameters:
    long Address 			- Address of the UART (and therefore of the Ultrasound)
	unsigned char settings 	- defines maximum distance to measure (1: 11m; 0: 5m)

  Returns:
    unsigned int - distance in mm

  Remarks:
    Distance in meter
  ***************************************************************************/
unsigned int ultrasound_read(long Address, unsigned char settings) 
{
	unsigned int i;
	unsigned char res_l, res_h;
	uart_send_byte(Address, 0xe8);
	for (i = 0; i < 300; i++);
	uart_send_byte(Address, 0x02);
	for (i = 0; i < 300; i++);
	if (settings)
		uart_send_byte(Address, 0xb8); 
	else
		uart_send_byte(Address, 0xb0); 
	for (i = 0; i < 300; i++);
	res_h = uart_receive_byte(Address);
	for (i = 0; i < 300; i++);
	res_l = uart_receive_byte(Address);
	return (((unsigned int) res_h) << 8) + res_l; 
}
コード例 #2
0
/**
 ****************************************************************************************
 * @briefend of test option 
  * 
 ****************************************************************************************
*/
void endtest_bridge(short int *idx)
{
		short int index2 = 0;
		char bchoice;
		printf_string("\n\r\n\rPress m for Engineering Examples Menu or x to exit : ");
		while(1){	
				if (index2 == 1) break;
				bchoice = uart_receive_byte();
				switch (bchoice){
						case 'm' : print_menu(); index2 = 1; break;
						case 'x' : (*idx)=1; index2 = 1; break;
						default : ; break;
				};
		};
}
コード例 #3
0
 /**
 ****************************************************************************************
 * @brief  Main routineof the DA14580 Peripheral Examples Functions
 * DA14580 Peripherals Udage Examples
 *        - UART
 *        - SPI Flash
 *        - Boot From SPI flash
 *        - EEPROM
 *        - Timers
 *        - Battery Level Indication - ADC
 *        - Quadrature
 *        - Buzzer
 * Due to HW Development Kit limitations, user must select one of the follwoing configuartion for UART, SPI, I2C.
 * Addicional Hardware (SPI, EEPROM boadrs) or Hardware modification may needed for some tof the tests. 
 * More information in the file periph_setup.h, Application Notes, and User Guide for DA14580
 *        - UART only  ( No HW modifications on rev C2 motherboard, No additional hardware)
 *        - SPI Flash with UART (HW modifications & additional Hardware needed , SPI_DI_PIN on the additional SPI / EEPROM daughterboard )
 *        - Boot From SPI Flash with UART  (HW modifications & additional Hardware needed, (UART TX) )
 *        - Boot From SPI Flash without UART (Additional Hardware needed)
 *        - Boot From EEPROM with UART (Additional Hardware needed)
 * 
 ****************************************************************************************
*/
int main (void)
{
	  short int index = 0;
	  char mchoice;
 
	  periph_init();
	  printf_string("\n\rDA14580 Peripheral Examples\n\r");
  	  printf_string(    "---------------------------\n\r");  
    printf_string("Before running the tests:\n\r");
    printf_string("  1) Make sure you have connected the appropriate peripheral(s).\n\r");
    printf_string("  2) Select the associated hardware configuration in 'periph_setup.h'.\n\r");
    printf_string("  3) Build.\n\r");
	printf_string("Please, refer to DA14580 Peripheral Examples User Manual\n\r");
    printf_string("for detailed instructions.\n\r");
    
	  print_menu();
	 	 
		while(1){
			if (index==1) break;
			mchoice = uart_receive_byte();
			switch (mchoice){
					case 'u': uart_test(); endtest_bridge(&index); break;
#ifdef SPI_ENABLED                 
					case 'f': spi_test(); endtest_bridge(&index); break;               
#endif //SPI_ENABLED
#ifdef EEPROM_ENABLED                
					case 'e': i2c_test(); endtest_bridge(&index); break;                
#endif //EEPROM_ENABLED                                
#ifdef QUADEC_ENABLED
					case 'q': quad_decoder_test(); endtest_bridge(&index); break;
#endif //QUADEC_ENABLED      

#ifdef BUZZER_ENABLED                
					case 't': timer0_test(); endtest_bridge(&index); break;
                    case 'p': timer2_test(); endtest_bridge(&index); break;        
#endif //BUZZER_ENABLED              
				  case 'b': batt_test(); endtest_bridge(&index); break;
				  case 'x': index=1;break;		
					default: print_input(); continue;
			};
		};
	
		printf_string("\n\r End of tests\n\r");
		while(1);
}
コード例 #4
0
 /**
 ****************************************************************************************
 * @brief  Main routineof the DA14580 Engineering Examples Functions
 * DA14580 Peripherals Udage Examples
 *        - UART
 *        - SPI Flash
 *        - Boot From SPI flash
 *        - EEPROM
 *        - Timers
 *        - Battery Level Indication - ADC
 *        - Quadrature
 *        - Buzzer
 * Due to HW Development Kit limitations, user must select one of the follwoing configuartion for UART, SPI, I2C.
 * Addicional Hardware (SPI, EEPROM boadrs) or Hardware modification may needed for some tof the tests. 
 * More information in the file periph_setup.h, Application Notes, and User Guide for DA14580
 *        - UART only  ( No HW modifications on rev C2 motherboard, No additional hardware)
 *        - SPI Flash with UART (HW modifications & additional Hardware needed , SPI_DI_PIN on the additional SPI / EEPROM daughterboard )
 *        - Boot From SPI Flash with UART  (HW modifications & additional Hardware needed, (UART TX) )
 *        - Boot From SPI Flash without UART (Additional Hardware needed)
 *        - Boot From EEPROM with UART (Additional Hardware needed)
 * 
 ****************************************************************************************
*/
int main (void)
{
	  short int index = 0;
	  char mchoice;
 
	  periph_init();
	  printf_string("DA14580 Engineering Examples\n\r");
 	  printf_string("Connect the appropriate peripheral before choosing each test\n\r\n\r");
	  printf_string("Refer to Engineering Examples User Guide\n\r\n\r");
    
	  print_menu();
	 	 
		while(1){
			if (index==1) break;
			mchoice = uart_receive_byte();
			switch (mchoice){
					case 'u': uart_test(); endtest_bridge(&index); break;
					case 'f': spi_test(); endtest_bridge(&index); break;
                    case 'i': spi_image(); endtest_bridge(&index); break;
					case 'e': i2c_test(); endtest_bridge(&index); break;
					case 'd': i2c_image(); endtest_bridge(&index); break;                
//					case 't': swt_test(); endtest_bridge(&index); break;
#ifdef QUADEC_ENABLED
					case 'q': quad_decoder_test(); endtest_bridge(&index); break;
#endif //QUADEC_ENABLED                
					case 't': timer0_test(); endtest_bridge(&index); break;
                    case 'p': timer2_test(); endtest_bridge(&index); break;        
				    case 'b': batt_test(); endtest_bridge(&index); break;
				    case 'x': index=1;break;		
					default: print_input(); continue;
			};
		};
	
		printf_string("\n\r End of tests\n\r");
		while(1);
}