Пример #1
0
void dump_touch_reg()
{
	printf_string("\n\n-------------- dump_touch_reg --------------------\n\n");
	
	printf_string("ADCCON = 0x%x\n", ADCCON);
	printf_string("ADCTSC = 0x%x\n", ADCTSC);
	
	printf_string("\n\n-------------------------------------------------------\n\n");
}
Пример #2
0
int DecodeBibleVersion(
        struct RecordVersion*    version,
        FILE* fp)
{
    fread_blob(version->versionName, 16, fp);
    fread_blob(version->versionInfo, 128, fp);
    version->sepChar = fread_u8(fp);
    version->versionAttrib = fread_u8(fp);

    version->wordIndex      = fread_u16(fp);
    version->totalWordRec   = fread_u16(fp);
    version->totalBooks     = fread_u16(fp);

#ifdef PDB_DEBUG
    printf("version.versionName : %s\n", version->versionName);
    printf("version.versionInfo : ");
        printf_string(version->versionInfo, 128);
        printf("\n");
    printf("version.sepChar     : 0x%02x\n", version->sepChar);

    printf("version.versionAttrib : 0x%02x\n", version->versionAttrib);
    printf("version.wordIndex   : 0x%04x\n", version->wordIndex);
    printf("version.totalWordRec: %d\n", version->totalWordRec);
    printf("version.totalBooks  : %d\n", version->totalBooks);

    printf("\n");
#endif

    DecodeBibleBookBriefInfo(version->bookBriefInfo, version->totalBooks, fp);

    return 0;
}
Пример #3
0
/******************************************************
* DISPLAY SCORE
* DESCRIPTION: Shows the player scores on the screen.
******************************************************/
void displayPongScore(unsigned int* inUserScore, unsigned int* inCompScore) //Pass by ref
{
	set_LCD_Cursor(0, 0);
	printf_string("       ");
	set_LCD_Cursor(25, 0);
	printf_int(*inUserScore);
	set_LCD_Cursor(45, 0);
	printf_int(*inCompScore);
}
Пример #4
0
char	*printf_s(char *f, char type, void *s)
{
	if (type == 'p')
		return (printf_hexa(f, type, ft_atoi(s)));
	else if (type == 'S')
		return (printf_wstring(f, (wchar_t *)s));
	else if (type == 's')
		return (printf_string(f, (char *)s, type));
	return (f);
}
Пример #5
0
///////////////////////////////////////////////////////////////////////////////
//Local PDB decode interface define
int DecodePDBHeader(struct PDBHeader* header, FILE* fp)
{
    //Fill pdb header
    fread_blob(header->fileName, 32, fp);

    header->fileAttributes = fread_u16(fp);
    header->versionNumber = fread_u16(fp);

    header->createDate    = fread_u32(fp);
    header->modificationDate = fread_u32(fp);
    header->lastBackupDate = fread_u32(fp);

    header->modificationNumber = fread_u32(fp);

    header->appInfoArea   = fread_u32(fp);
    header->sortInfoArea  = fread_u32(fp);

    fread_blob(header->dataBaseType, 4, fp);
    fread_blob(header->creatorID, 4, fp);
    fread_blob(header->uniqueIDSeed, 4, fp);

    header->nextRecord    = fread_u32(fp);
    header->numRecs       = fread_u16(fp);

#ifdef PDB_DEBUG
    //Debug info
    printf("header->FileName    : %s\n", header->fileName);
    
    printf("header->DatabaseType: ");
        printf_string(header->dataBaseType, 4);
    printf("\n");
    
    printf("header->CreatorID   : ");
        printf_string(header->creatorID, 4);
    printf("\n");

    printf("header->NumRecs     : 0x%02x\n",header->numRecs);
#endif
    return 0;
}
Пример #6
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);
}
Пример #7
0
int main()
{
	extern void enter_string(char str[]);
	extern void delete_string(char str[],char ch);
	extern void printf_string(char str[]);

	char c,str[80];
	enter_string(str);
	scanf("%c",&c);
	delete_string(str,c);
	printf_string(str);

	return 0;
}
Пример #8
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;
				};
		};
}
Пример #9
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);
}
Пример #10
0
 /**
 ****************************************************************************************
 * @brief Battery Level Indication  example function 
  * 
 ****************************************************************************************
*/
void batt_test(void){
	
        printf_string("\n\r\n\r****************");
        printf_string("\n\r* BATTERY TEST *\n\r");
        printf_string("****************\n\r");
	
#if BATT_CR2032    
        printf_string("\n\rBattery type: CR2032");  
        printf_string("\n\rCurrent battery level (max.0xFF%): 0x");            
		printf_byte(battery_get_lvl(BATT_CR2032));  
        printf_string("% left");
#else
        printf_string("\n\rBattery type unknown");  
#endif

} 
Пример #11
0
void	printf_conversion_p(t_printf *t)
{
	const void	*ptr;

	ptr = VA_ARG(t->args, void *);
	if (t->flags.prec == 0 && ptr == NULL)
	{
		t->flags.prec = -1;
		t->flags.pad = ' ';
		printf_string(t, "0x", 2);
		return ;
	}
	t->flags.base = 16;
	t->flags.number.word = (unsigned long int)ptr;
	t->flags.is_negative = false;
	t->flags.alt = true;
	t->flags.spec = 'x';
	printf_number(t);
}
Пример #12
0
void app_sample128_enable(void)
{
	struct sample128_enable_req* req =    KE_MSG_ALLOC(
	                                                    SAMPLE128_ENABLE_REQ,
	                                                    TASK_SAMPLE128, TASK_APP,
	                                                    sample128_enable_req
																									   );
	
	req->conhdl  = app_env.conhdl;
	req->sec_lvl = PERM(SVC, ENABLE);
	//req->sample128_1_val = 0x01; // default value for sample128 characteristic 1
	memcpy(&req->sample128_1_val,&sample128_my_new,sizeof(My_new_t));
	req->sample128_2_val = 0xff; // default value for sample128 characteristic 2
	req->feature         = 0x00; // client CFG notify/indication
  printf_string(" app_sample128_enable \r\n");
	// send the message
	ke_msg_send(req);
	
}
Пример #13
0
void touch_handler()
{
	print_string("touch_handler");
	
	//1. Start X/Y coordinate auto convert
	ADCCON |= (1 << 0);
	ADCTSC |= (1 << 2);
	
	//2. Wait conversion finish
	while((ADCCON & (1 << 15)) == 0);
	
	//3. Get X/Y coordinate
	xdata = ADCDAT0 & 0x03ff;
	ydata = ADCDAT1 & 0x03ff;

	//4. Clear interrupt(Write 1)
	(SUBSRCPND) |= (1 << 9);
	(SRCPND) |= (1 << 31);
	(INTPND) |= (1 << 31);
	
	//5. Enter wait stylus up interrupt
	ADCTSC = 0xd3;
	ADCTSC |= (1 << 8);
	
	while(1)
	{
		if((SUBSRCPND) & (1 << 9))
		{
			break;
		}	
	}
	
	printf_string("\n\nxdata = %d\nydata = %d\n\n", xdata, ydata);

	//6. Clear stylus up interrupt
	(SUBSRCPND) |= (1 << 9);
	(SRCPND) |= (1 << 31);
	(INTPND) |= (1 << 31);
	
	//7. Wait another stylus down
	ADCTSC = 0xd3;
}
Пример #14
0
static void		s_check_action(t_printf *t, char **s)
{
	char	sc[2];

	++(*s);
	while ((printf_flags(t, s) || printf_modifiers(t, s)))
		++(*s);
	if (**s)
	{
		if (printf_function_conversion(t, **s) == false)
		{
			sc[0] = **s;
			sc[1] = '\0';
			t->flags.prec = -1;
			printf_string(t, ft_strdup(sc));
		}
	}
	else
	{
		--(*s);
	}
}
Пример #15
0
static int	printf_type(t_printf *p, const int flag)
{
	if (flag & C_WCHAR)
		return (printf_wchar(p));
	if (flag & C_WSTRING)
		return (printf_wstring(p));
	if (flag & C_STRING)
		return (printf_string(p));
	if (flag & C_CHAR)
		return (printf_char(p));
	if (flag & (C_INT | C_LONG))
		return (printf_long(p, p->arg));
	if (flag & C_UINT)
		return (printf_ulong_base(p, p->arg, 10));
	if (flag & C_ULONG)
		return (printf_ulong_base(p, p->arg, 10));
	if (flag & (C_HEXA | C_MHEXA))
		return (printf_ulong_base(p, p->arg, 16));
	if (flag & (C_LOCTAL | C_OCTAL))
		return (printf_ulong_base(p, p->arg, 8));
	if (flag & C_BIN)
		return (printf_ulong_base(p, p->arg, 2));
	return (1);
}
Пример #16
0
/**
 ****************************************************************************************
 * @brief print menu function
  * 
 ****************************************************************************************
*/
void print_menu(void)
{
		printf_string("\n\r====================================\n\r");
		printf_string("= DA14580 Peripheral Examples Menu =\n\r");
		printf_string("\n\r====================================\n\r");    
		printf_string("u. UART Print String Example\n\r");
#ifdef SPI_ENABLED     
		printf_string("f. SPI Flash Memory Example\n\r");
#else
    	printf_string("f. (disabled in this build) SPI Flash Memory Example\n\r");
#endif //SPI_ENABLED    
#ifdef EEPROM_ENABLED        
		printf_string("e. I2C EEPROM Example\n\r");  
#else
		printf_string("e. (disabled in this build) I2C EEPROM Example\n\r");     
#endif //EEPROM_ENABLED     
#ifdef QUADEC_ENABLED
		printf_string("q. Quadrature Encoder Example\n\r");
#else
  		printf_string("q. (disabled in this build) Quadrature (Rotary Encoder) Example\n\r");  
#endif //QUADEC_ENABLED    
    
#ifdef BUZZER_ENABLED 
		printf_string("t. Timer0 (PWM0, PWM1) Example\n\r");
		printf_string("p. Timer2 (PWM2, PWM3, PWM4) Example\n\r");  
#else
 		printf_string("t. (disabled in this build) Timer0 (PWM0, PWM1) Example\n\r");
		printf_string("p. (disabled in this build) Timer2 (PWM2, PWM3, PWM4) Example\n\r");     
#endif //BUZZER_ENABLED    
    
        printf_string("b. Battery Example\n\r");
		printf_string("x. Exit\n\r\n\r");
		print_input();
}
Пример #17
0
char *flowdrv_create_offline_device(const char *path, int format)
// Create new offline device
// path = tracefile that should be used
// format = tracefile format constant
{
  struct mapiipcbuf qbuf;
  int file;

  char *mapidsocket, *mapidsocketglobal;

  mapidsocket = printf_string(MAPIDSOCKHOME, getenv("HOME"));
  mapidsocketglobal = strdup(MAPIDSOCKGLOBAL);
  mapiipc_set_socket_names(mapidsocket, mapidsocketglobal);

  pthread_once(&mapi_is_initialized, (void*)mapi_init);

  //Check to see if file can be opened
  if (path == NULL){
    printf("ERROR: NULL path in flowdrv_create_offline_device\n");
    return NULL;
  }
  else if ((file = open(path,O_LARGEFILE)) == -1) {
    *local_err = MAPI_ERROR_FILE;
    return NULL;
  }

  while(__sync_lock_test_and_set(mapi_lock,1));
  if (((*get_numflows)() == 0) && ((*get_totalflows)() > 0) && *minit) { // socket has been closed, re-create it
    if (mapiipc_client_init()<0) {
      *mapi_lock = 0;
      *local_err = MCOM_INIT_SOCKET_ERROR;
      return NULL;
    }
  }
  *mapi_lock = 0;

  qbuf.mtype = 1;
  qbuf.cmd = CREATE_OFFLINE_DEVICE;
  qbuf.fd = getpid();
  qbuf.pid = getpid();
  qbuf.fid = format;
  strncpy((char *)qbuf.data, path, DATA_SIZE);
  
  while(__sync_lock_test_and_set(mapi_lock,1));
  if (mapiipc_write((struct mapiipcbuf*)&qbuf) < 0)
  {
    *mapi_lock = 0;	  
    *local_err = MCOM_SOCKET_ERROR;
    return NULL;
  }
  if (mapiipc_read((struct mapiipcbuf*)&qbuf) < 0)
  {
    *mapi_lock = 0;
    *local_err = MCOM_SOCKET_ERROR;
    return NULL;
  }
  
  if(qbuf.cmd == SEND_FD)
  {
    if(mapiipc_send_fd(file) == -1)
    {
      *local_err = MAPI_ERROR_SEND_FD;
      *mapi_lock = 0;
      return NULL;      
    }
  }
  else
  {
    *local_err = MAPI_ERROR_SEND_FD;
    *mapi_lock = 0;
    return NULL;
  }

  if (mapiipc_read((struct mapiipcbuf*)&qbuf) < 0)
  {
    *mapi_lock = 0;
    *local_err = MCOM_SOCKET_ERROR;
    return NULL;
  }
  *mapi_lock = 0;
  
  switch(qbuf.cmd)
  {
    case CREATE_OFFLINE_DEVICE_ACK:
      offline_devices++;
      return strdup((char *)qbuf.data);
    case ERROR_ACK:
      *local_err = qbuf.remote_errorcode;
      return NULL;
    default:
      *local_err = MCOM_UNKNOWN_ERROR;
      return NULL;
  }
}
Пример #18
0
 /**
 ****************************************************************************************
 * @briefend exit test
  * 
 ****************************************************************************************
*/
void exit_test(void)
{
		printf_string("\n\r  End of tests \n\r");
}
Пример #19
0
//Initializes MAPI - called only once by pthread_once()
void mapi_init()
{
  if (!globals_set)
  {
    fprintf(stderr, "\nERROR: driver not initialized!\n");
    return;
  }
  struct mapiipcbuf qbuf;
  char libpath[4096], *str, *s;
  *minit = 1;
  char *mapidsocket, *mapidsocketglobal;

  char errstr[512];

  mapidsocket = printf_string(MAPIDSOCKHOME, getenv("HOME"));
  mapidsocketglobal = strdup(MAPIDSOCKGLOBAL);
  mapiipc_set_socket_names(mapidsocket, mapidsocketglobal);

  if (mapiipc_client_init() == -1)
  {
    *local_err = MCOM_INIT_SOCKET_ERROR;
    *minit=0;
    fprintf(stderr, "\n--------------------------------------------------------\n");
    fprintf(stderr, "WARNING: mapid may not be running at the given interface\n");
    fprintf(stderr,"--------------------------------------------------------\n");
  }

  offline_devices = 0;
  
  //Get libpath from mapid
  qbuf.mtype = 1;
  qbuf.cmd = GET_LIBPATH;
  qbuf.fd = getpid();
  qbuf.pid = getpid();
  
  while(__sync_lock_test_and_set(mapi_lock,1));
  
 if (mapiipc_write((struct mapiipcbuf*)&qbuf))
    *local_err = MCOM_SOCKET_ERROR;
 if (mapiipc_read((struct mapiipcbuf*)&qbuf))
    *local_err = MCOM_SOCKET_ERROR;
  
  if (*local_err)
  {
    mapi_read_error(local_err, errstr);
    fprintf(stderr, "ERROR: %d: %s \n", *local_err, errstr);
  }
  
  *mapi_lock = 0;
  
  switch(qbuf.cmd)
  {
    case GET_LIBPATH_ACK:
      strncpy(libpath, (char *)qbuf.data, 4096);
      break;
    
    default:
      /* MAPI_ERROR_GETTING_LIBPATH */
      return;
  }
  printf("libpath=%s\n", libpath);

  //get libs from mapid
  qbuf.mtype = 1;
  qbuf.cmd = GET_LIBS;
  qbuf.fd = getpid();
  qbuf.pid = getpid();
  
  while(__sync_lock_test_and_set(mapi_lock,1));
  
  if (mapiipc_write((struct mapiipcbuf*)&qbuf))
    *local_err = MCOM_SOCKET_ERROR;
  if (mapiipc_read((struct mapiipcbuf*)&qbuf))
    *local_err = MCOM_SOCKET_ERROR;
    
  if (*local_err)
  {
    mapi_read_error(local_err, errstr);
    fprintf(stderr, "ERROR: %d: %s \n", *local_err, errstr);
  }
  
  *mapi_lock = 0;
  
  switch(qbuf.cmd)
  {
    case GET_LIBS_ACK:
      break;
    
    default:
      /* MAPI_ERROR_GETTING_LIBS */
      return; 
  }

  //Load function libraries
  str = (char *)qbuf.data;
  while((s = strchr(str, ':')) != NULL)
  {
    *s = '\0';
    mapilh_load_library(libpath, str);
    str=s+1;
  }

  mapilh_load_library(libpath, str);
  return;
}
Пример #20
0
void arp_process(u8* arp_buff, int length)
{
	u32 i = 0;
	u8* ptr = NULL;
	ARP_HDR* arp_buff_ptr = (ARP_HDR*)arp_buff;
	u8 dev_mac_addr[6] = {9, 8, 7, 6, 5, 4};

	u8 src_ip_addr[4] = {192, 168, 1, 20};
	ARP_HDR arp_send_buf;
	u8 host_ip_addr[4];
	u8 host_mac_addr[6];
	
	switch(ADJUST_ENDIAN(arp_buff_ptr->opcode))
	{
//		printf_string("arp_buff_ptr->opcode = 0x%x\n", ADJUST_ENDIAN(arp_buff_ptr->opcode));
		case 1:	/* Arp request packet */
			/* 1. Construct arp ack packet */
			memcpy(arp_send_buf.eth_hdr.d_mac, arp_buff_ptr->src_mac, 6);
			memcpy(arp_send_buf.eth_hdr.s_mac,arp_buff_ptr->dst_mac, 6);
			arp_send_buf.eth_hdr.type = ADJUST_ENDIAN(0x0806);

			arp_send_buf.hw_type = ADJUST_ENDIAN(0x01);
			arp_send_buf.protocol = ADJUST_ENDIAN(0x0800);
			arp_send_buf.hw_len = 6;
			arp_send_buf.protocol_len = 4;
			arp_send_buf.opcode = ADJUST_ENDIAN(0x02);
			
			memcpy(arp_send_buf.src_mac, dev_mac_addr, 6);
			memcpy(arp_send_buf.src_ip_addr, src_ip_addr, 4);
			
			memcpy(arp_send_buf.dst_mac, arp_buff_ptr->src_mac, 6);				
			memcpy(arp_send_buf.dst_ip_addr, arp_buff_ptr->src_ip_addr, 4);		
			
			/* 2. Send request packet*/			
			dm9000_send((u8*)&arp_send_buf, (14 + 28));
			
			break;

		case 2: /* Arp ack packet */
			memcpy(host_ip_addr, (*arp_buff_ptr).src_ip_addr, 4);
			memcpy(host_mac_addr, (*arp_buff_ptr).src_mac, 6);
			
			print_string("\nHost ip = ");
			for(i = 0; i < 4; i++)
			{
				printf_string("%d ", host_ip_addr[i]);
			}
			
			print_string("\nHost mac = ");
			for(i = 0; i < 6; i++)
			{
				printf_string("%C ", host_mac_addr[i]);
			}
			print_string("\n");
			
			break;
			
		default:
			break;
	}
}
Пример #21
0
void uart_test(void){
		printf_string("\n\r\n\r*************");
		printf_string("\n\r* UART TEST *\n\r");
		printf_string("*************\n\r");
		printf_string("\n\rHello World! == UART printf_string() ==.\n\r");
}
Пример #22
0
int main(int argc, char *argv[]) {

	const char *homedir;

	parse_arguments(argc, argv);

	flowlist=malloc(sizeof(flist_t));
	flist_init(flowlist);

	clientlist = malloc(sizeof(flist_t));
	flist_init(clientlist);

	gflist = malloc(sizeof(global_function_list_t));

	gflist->fflist=malloc(sizeof(flist_t));
	flist_init(gflist->fflist);
	gflist->lock = 0;

	homedir = getenv("HOME");
	if (homedir == NULL) {
		fputs("Environment variable HOME not set. Giving up.\n", stderr);
		exit( 1);
	}

	mapid_conf = printf_string( CONFDIR"/"CONF_FILE );
	printf("using %s\n", mapid_conf);

	log_level = get_log_level(mapid_conf); // get log level from mapi.conf

	if (log_to_syslog) // logging to syslog is enabled
		open_syslog(log_level, "MAPID");

	log_to_file = set_logging_to_file(mapid_conf, &log_fd_info, &log_fd_debug); // support for logging to file

	if (log_to_syslog == 0 && log_to_file == 0)
		log_level = LOGGING_DISABLED;

	if (log_to_syslog == 0)
		printf("logging to syslog: disabled\n");
	else
		printf("logging to syslog: enabled - LogLevel: %d\n", log_level);

	if (log_to_file) {
		daemon_started(log_fd_info, "MAPID", daemonize, 0);
		daemon_started(log_fd_debug, "MAPID", daemonize, 0);
	}

	if (log_to_syslog)
		log_message(
				"MAPID was started %s%s",
				daemonize ? " ( is running as daemon )" : "");
	drvlist = load_drivers();

	if (drvlist == NULL) {
		DEBUG_CMD(Debug_Message("ERROR: No MAPI drivers found"));
		exit(EXIT_FAILURE);
	}

	// Grab some signals so we can mapid_shutdown gracefully
	signal(SIGTERM, mapid_shutdown);
	signal(SIGQUIT, mapid_shutdown);
	signal(SIGINT, mapid_shutdown);

	if (daemonize)
		continue_as_daemon();

	mapidcom();

	mapid_shutdown(0);
	// wait for shutdown to finish
	// espenb TODO: use pthread_cond_wait (or similar) instead
	while (running_shutdown != 2)
		usleep(10000);
	return 0;
}
Пример #23
0
/**
 ****************************************************************************************
 * @brief print menu function
  * 
 ****************************************************************************************
*/
void print_menu(void)
{
		printf_string("\n\r=====================================\n\r");
		printf_string("= DA14580 Engineering Examples Menu =\n\r");
		printf_string("\n\r=====================================\n\r");    
		printf_string("u. UART Print String Example\n\r");
		printf_string("f. SPI Flash Memory Example\n\r");
        printf_string("i. SPI Flash Memory Image Write\n\r");	
		printf_string("e. I2C EEPROM Example\n\r");
		printf_string("d. I2C EEPROM Image Write/Verify Example\n\r");    
#ifdef QUADEC_ENABLED
		printf_string("q. Quadrature (Rotary Encoder) Example\n\r");
#else
  		printf_string("q. (disabled in this build) Quadrature (Rotary Encoder) Example\n\r");  
#endif //QUADEC_ENABLED     
		printf_string("t. Timer0 (PWM0, PWM1) Example\n\r");
		printf_string("p. Timer2 (PWM2, PWM3, PWM4) Example\n\r");    
        printf_string("b. Battery Example\n\r");
		printf_string("x. Exit Example\n\r\n\r");
		print_input();
}
Пример #24
0
/**
 ****************************************************************************************
 * @brief print input function
  * 
 ****************************************************************************************
*/
void print_input(void)
{
		printf_string("\n\rMake a choice : ");
}
Пример #25
0
static void mapidcom()
//Communicates with clients through IPC
{
	fd_set active_fd_set; // active file descriptor list
	fd_set read_fd_set; // temp file descriptor list for select()
	int fdmax; // maximum file descriptor number
	int yes = 1; // for setsockopt() SO_REUSEADDR, below
	struct sockaddr_un mapidaddr;
	struct sockaddr_un remoteaddr;
	struct mapiipcbuf qbuf;
	socklen_t addrlen;
	int nbytes, len, s;
	struct client *cl= NULL;
	flist_node_t *tmpnode;
	conf_category_entry_t *cat=NULL;
	char *local;
	struct group *mapi_group;
  conf_category_t *conf;

	mapidsocket=strdup(MAPIDSOCKGLOBAL);

	if ((conf = pc_load(mapid_conf)) != NULL) {
		cat = pc_get_category(conf, "");
		local=pc_get_param(cat, "local");
		if (local!=NULL && strcmp(local, "1")==0) {
			free(mapidsocket);
			mapidsocket=printf_string(MAPIDSOCKHOME, getenv("HOME") );
		}
		pc_close(conf);

	}
	//  create the listener socket
	if ((listenerfd = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1) {
		DEBUG_CMD(Debug_Message("ERROR: socket: %s", strerror(errno)));
		exit(EXIT_FAILURE);
	}
	// avoid "address already in use" error message
	if (setsockopt(listenerfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))
			== -1) {
		DEBUG_CMD(Debug_Message("ERROR: setsockopt: %s", strerror(errno)));
		exit(EXIT_FAILURE);
	}
	//  set up the address we will be binding to
	memset(&mapidaddr, 0, sizeof (mapidaddr));
	mapidaddr.sun_family = AF_LOCAL;

	memcpy(mapidaddr.sun_path, mapidsocket, strlen(mapidsocket)+1);
	unlink(mapidsocket);

	len = sizeof mapidaddr.sun_family + strlen(mapidaddr.sun_path);
	if (bind(listenerfd, (struct sockaddr *) &mapidaddr, len)) {
		DEBUG_CMD(Debug_Message("ERROR: bind: %s", strerror(errno)));
		exit(EXIT_FAILURE);
	}

	// allow any member of our own group to connect
	chmod(mapidsocket, S_IRWXU | S_IRWXG);

	// if a mapi user group exists, set group permissions accordingly,
	// otherwise the group ID will be equal to the user ID of the user that
	// invoked mapid
	mapi_group = getgrnam(MAPI_GROUP_NAME);
	if (mapi_group != NULL) {
		chown(mapidsocket, -1, mapi_group->gr_gid);
	}

	if (listen(listenerfd, BACKLOG) == -1) {
		DEBUG_CMD(Debug_Message("ERROR: listen: %s", strerror(errno)));
		exit(EXIT_FAILURE);
	}

	FD_ZERO (&active_fd_set);
	// add the listener to the active set
	FD_SET (listenerfd, &active_fd_set)
;
  // keep track of the biggest file descriptor
  		fdmax = listenerfd; // so far, it's just this one

	// wait for commands from the mapi stub, for ever...
	while (1) {
		read_fd_set = active_fd_set; // copy it
		if (select(fdmax + 1, &read_fd_set, NULL, NULL, NULL) == -1) {
			DEBUG_CMD(Debug_Message("ERROR: select: %s", strerror(errno)));
			break;
		}

		// run through the existing connections
		for (s = 0; s <= fdmax; s++) {
			if (FD_ISSET (s, &read_fd_set)) {

				// connection on the original listener socket
				if (s == listenerfd) {
					addrlen = sizeof (remoteaddr);
					if ((newfd = accept(listenerfd,
							(struct sockaddr *) &remoteaddr, &addrlen)) == -1) {
						DEBUG_CMD(Debug_Message("accept: %s", strerror(errno)));
					} else {
						FD_SET (newfd, &active_fd_set)
;						// add to active set
						if (newfd > fdmax)
						{ // keep track of the maximum
							fdmax = newfd;
						}
					}
				}
				// handle data from an existing client
				else
				{
					if ((nbytes = recv (s, &qbuf, MAX_SEND_SIZE, 0)) <= 0)
					{
						if (nbytes == 0)
						{
							// connection closed - find client's pid
							while(__sync_lock_test_and_set(&clientlist_lock,1));
							tmpnode = (flist_node_t *) flist_head (clientlist);

							cl = NULL;
							while (tmpnode != NULL)
							{
								if (((struct client *) tmpnode->data)->sock == s)
								{
									cl = (struct client *) tmpnode->data;
									break;
								}
								tmpnode = flist_next (tmpnode);
							}
							clientlist_lock = 0;

							if (cl == NULL)
							{/* This is not interesting, as it will occur upon requests from clients without flows etc.
							 WARNING_CMD (printf
							 ("WARNING: Zero bytes from socket %d [%s:%d]\n",
							 s, __FILE__, __LINE__));
							 */
								/* shouldn't really exit here? 
								 * this will cause the program to exit on errors with an empty
								 * client-list which isn't really an error (IMHO)
								 */
								//exit(EXIT_FAILURE);
							}
							else
							{
								while(__sync_lock_test_and_set(&clientlist_lock,1));
								//clean up any remaining flows
								tmpnode = (flist_node_t *) flist_head (cl->flowlist);
								while (tmpnode != NULL)
								{
									cleanup_flow ((struct flow *) tmpnode->data);
									tmpnode = flist_next (tmpnode);
								}
								tmpnode = (flist_node_t *) flist_head (cl->devicelist);
								while (tmpnode != NULL)
								{
									mapidrv_delete_device = get_drv_funct (tmpnode->data, "mapidrv_delete_device");
									mapidrv_delete_device (tmpnode->id);
									tmpnode = flist_next (tmpnode);
								}
								flist_destroy (cl->flowlist);
								flist_destroy (cl->devicelist);
								free(cl->devicelist);
								free (cl->flowlist);
								//remove this client from global client list
								free(flist_remove (clientlist, cl->pid));
								clientlist_lock = 0;
							}
						}
						else
						{
							DEBUG_CMD(Debug_Message("WARNING: recv: %s at", strerror (errno)));
						}
						close (s);
						FD_CLR (s, &active_fd_set); // remove it from active set
					}
					else
					{
						// we got some data from a client: process request
						switch (qbuf.cmd)
						{
							case GET_LIBS:
							cmd_get_libs (qbuf.pid, s);
							break;
							case GET_LIBPATH:
							cmd_get_libpath (qbuf.pid, s);
							break;
							case CREATE_FLOW:
							cmd_create_flow ((char *)qbuf.data, qbuf.pid, qbuf.uid, s);
							break;
							case CLOSE_FLOW:
							cmd_close_flow (qbuf.fd, qbuf.pid, s, 1);
							break;
							case GET_FLOW_INFO:
							cmd_get_flow_info (qbuf.fd, qbuf.pid, s);
							break;
							case GET_FUNCTION_INFO:
							cmd_get_function_info (qbuf.fd, qbuf.fid, qbuf.pid, s);
							break;
							case GET_NEXT_FUNCTION_INFO:
							cmd_get_next_function_info (qbuf.fd, qbuf.fid, qbuf.pid, s);
							break;
							case GET_NEXT_FLOW_INFO:
							cmd_get_next_flow_info (qbuf.fd, qbuf.pid, s);
							break;
							case GET_NEXT_DEVICE_INFO:
							cmd_get_next_device_info (qbuf.fd, qbuf.pid, s);
							break;
							case GET_DEVICE_INFO:
							cmd_get_device_info (qbuf.fd, qbuf.pid, s);
							break;
						case MAPI_STATS:
						  cmd_stats ((char *)qbuf.data, qbuf.pid, qbuf.uid, s);
						  break;
							case APPLY_FUNCTION:
							cmd_apply_function (&qbuf, qbuf.pid, s);
							break;
							case READ_RESULT:
							cmd_read_results (qbuf.fd, qbuf.fid, qbuf.pid, s);
							break;
							case CONNECT:
							cmd_connect (qbuf.fd, qbuf.pid, s);
							break;
							case CREATE_FLOW_ACK:
							case APPLY_FUNCTION_ACK:
							case READ_RESULT_ACK:
							case CONNECT_ACK:
							case CLOSE_FLOW_ACK:
							case SET_AUTHDATA_ACK:
							break;
							case READ_ERROR_ACK:
							break;
							case ERROR_ACK:
							break;
							case CREATE_OFFLINE_DEVICE:
							cmd_create_offline_device ((char *)qbuf.data, qbuf.fid, qbuf.pid, s);
							break;
							case CREATE_OFFLINE_DEVICE_ACK:
							break;
							case START_OFFLINE_DEVICE:
							cmd_start_offline_device ((char *)qbuf.data, qbuf.pid, s);
							break;
							case START_OFFLINE_DEVICE_ACK:
							break;
							case DELETE_OFFLINE_DEVICE:
							cmd_delete_offline_device ((char *)qbuf.data, qbuf.pid, s);
							break;
							case DELETE_OFFLINE_DEVICE_ACK:
							break;
							case CREATE_OFFLINE_FLOW_ACK:
							break;
							case LOAD_LIBRARY:
							cmd_load_library ((char *)qbuf.data, qbuf.pid, s);
							default:
							break;
						}
					}
				}
			}
		} // for
	} // while(1)
}