Пример #1
0
char* modem_send(Modem modem, char* cmd) {
  /* trying fsync, who knows if we actually need it, or if
   * it works, cuz its for kernel flush to disk, and we are
   * talking to a modem. */
  fsync(modem->file);
  write(modem->file, cmd, strlen(cmd));
  modem->timeout = 0.1; /* why is this here?!?! */
  return serial_read_line(modem->file, modem->timeout);
}
Пример #2
0
void modem_send(Modem modem, char* cmd, char *input) {
  /* trying fsync, who knows if we actually need it, or if
   * it works, cuz its for kernel flush to disk, and we are
   * talking to a modem. */
  char *message;
  message = (char*)malloc(sizeof(char)*(strlen(input)+1));
  fsync(modem->file);
  write(modem->file, cmd, strlen(cmd));
  sprintf(message, "%s%c", input, 26);
  modem->timeout = 0.1; /* why is this here?!?! */
  if (serial_read_line(modem->file, modem->timeout)) {
    usleep(50);
    write(modem->file, message, strlen(message));
  }
}
Пример #3
0
int main(void)
{
	uint16_t i;
	char temp_char;
	uint8_t num_chars_ret;

	// For CS4272 (uC i2s interface in slave mode) not sure about
	// initialization sequence (i2s interface first, or setup cs4272 first)
	// For now, start with codec (get interface clocks started first)


	// Initialize USB
    usb_init();
	delay(100);

	// Initialize I2C subsystem
	i2c_init();
    delay(100);



	for(i = 0; i < 64; i++)
	{
		buffer[i] = 0;
	}
	
	// Wait to setup codec to make sure user has turned on audio board power
	while((buffer[0] != 'y') && (buffer[0] != 'Y'))
	{
		serial_write_string("Init codec? (y/n)\r\n>");
		
		// Wait for response
		num_chars_ret = serial_read_line(buffer,64);

		if(num_chars_ret < 1)
		{
			serial_write_string("Error reading line. Please try again.\r\n");
		}
	}

	for(i = 0; i < 64; i++)
	{
		buffer[i] = 0;
	}

	// Initialize CS4272
	codec_init();
	delay(100);



	// Initialize I2S subsystem 
	i2s_init();
	delay(10);

	serial_write_string("Codec Initialized\r\n");
	delay(10);


	// Test to see if i2c is working
	uint8_t reg_result;
	uint8_t ii;
	for(ii = 1; ii < 9; ii++)
	{
		itoa(ii,buffer,10);
		serial_write_string("Address ");
		serial_write_string(buffer);
		serial_write_string(": ");


		reg_result = codec_read(ii);
		itoa(reg_result,buffer,10);
		serial_write_string(buffer);
		serial_write_string("\r\n");
		delay(100);
	}

	for(i = 0; i < 64; i++)
	{
		buffer[i] = 0;
	}

	serial_write_string("Waiting 10 seconds for ADC high pass filter to stabilize\r\n");
	delay(10000);
	
	while(1)
	{
		
		// Initialize indices, etc
		tx_buf_idx = 0;
		rx_buf_idx = 0;
		curr_run = 0;

		for(i = 0; i < NUM_SAMP; i++)
		{
			//recv_data_real[i] = 0;
			//recv_data_imag[i] = 0;
			recv_data_right[i] = 0;
			//recv_data_left[i] = 0;
		}



		for(i = 0; i < 64; i++)
		{
			buffer[i] = 0;
		}


		while((buffer[0] != 'y') && (buffer[0] != 'Y'))
		{
			serial_write_string("Start test? (y/n)\r\n>");
			
			// Wait for response
			num_chars_ret = serial_read_line(buffer,64);

			if(num_chars_ret < 1)
			{
				serial_write_string("Error reading line. Please try again.\r\n");
			}
		}

		// Start test
		serial_write_string("Starting test.\r\n");
		//output_real_part = 1;
		test_running = 1;
		i2s_start();

		// Wait for real part to finish
		while(test_running)
		{
			//serial_write_string("Running real part.  Please wait .....\r\n");
			delay(1000);
		}

		// Test is now finished
//		serial_write_string("Real part is finished.  Starting imaginary part.\r\n");
//		
//		delay(1000);
//
//		// Start imaginary part
//		output_real_part = 0;
//		test_running = 1;
//		i2s_start();
//
//		// Wait for real part to finish
//		while(test_running)
//		{
//			//serial_write_string("Running imaginary part.  Please wait .....\r\n");
//			delay(1000);
//		}
//
//		// Test is now finished
//		serial_write_string("Imaginary part is finished.  Printing Data.\r\n");

		// Print data
		for(i = 0; i < NUM_SAMP; i++)
		{
			itoa(recv_data_right[i],buffer,10);
			serial_write_string(buffer);
			serial_write_string(",");
			itoa(recv_data_left[i],buffer,10);
			serial_write_string(buffer);
			serial_write_string("\r\n");
			delay(50);
		}

		serial_write_string("End of data.\r\n");
		
	}

	return 0;
}
Пример #4
0
/*
 *	Receive IPMI response from the device
 *	Len: buffer size
 *	Returns: -1 or response lenth on success
 */
static int
recv_response(struct ipmi_intf * intf, unsigned char *data, int len)
{
	char hex_rs[IPMI_SERIAL_MAX_RESPONSE * 3];
	int i, j, resp_len = 0;
	long rv;
	char *p, *pp;
	char ch, str_hex[3];

	p = hex_rs;
	while (1) {
		if ((rv = serial_read_line(intf, p, sizeof(hex_rs) - resp_len)) < 0) {
			/* error */
			return -1;
		}
		p += rv;
		resp_len += rv;
		if (*(p - 2) == ']' && (*(p - 1) == '\n' || *(p - 1) == '\r')) {
			*p = 0;
			break;
		}
	}

	p = strrchr(hex_rs, '[');
	if (!p) {
		lprintf(LOG_ERR, "Serial response is invalid");
		return -1;
	}

	p++;
	pp = strchr(p, ']');
	if (!pp) {
		lprintf(LOG_ERR, "Serial response is invalid");
		return -1;
	}
	*pp = 0;

	/* was it an error? */
	if (strncmp(p, "ERR ", 4) == 0) {
		serial_write_line(intf, "\r\r\r\r");
		sleep(1);
		serial_flush(intf);
		errno = 0;
		rv = strtoul(p + 4, &p, 16);
		if ((rv && rv < 0x100 && *p == '\0')
				|| (rv == 0 && !errno)) {
			/* The message didn't get it through. The upper
			   level will have to re-send */
			return 0;
		} else {
			lprintf(LOG_ERR, "Serial response is invalid");
			return -1;
		}
	}

	/* this is needed for correct string to long conversion */
	str_hex[2] = 0;

	/* parse the response */
	i = 0;
	j = 0;
	while (*p) {
		if (i >= len) {
			lprintf(LOG_ERR, "Serial response is too long(%d, %d)", i, len);
			return -1;
		}
		ch = *(p++);
		if (isxdigit(ch)) {
			str_hex[j++] = ch;
		} else {
			if (j == 1 || !isspace(ch)) {
				lprintf(LOG_ERR, "Serial response is invalid");
				return -1;
			}
		}
		if (j == 2) {
			unsigned long tmp;
			errno = 0;
			/* parse the hex number */
			tmp = strtoul(str_hex, NULL, 16);
			if ( tmp > 0xFF || ( !tmp && errno ) ) {
				lprintf(LOG_ERR, "Serial response is invalid");
				return -1;
			}
			data[i++] = tmp;
			j = 0;
		}
	}

	return i;
}
Пример #5
0
int main()
{
    init_platform();

    XIOModule_Initialize(&iomod_inst, 0);

    wait_ms(&iomod_inst,1000);

    codec_init(&iomod_inst);

    wait_ms(&iomod_inst,1000);
    print("Codec Initialized\r\n");
    print("Reading back registers\r\n");

    int i;
    uint8_t regData;
    for(i = 1; i < 9; i++)
    {
    	regData = codec_read(&iomod_inst,i);
    	print("Address ");
    	print_u32_hex((u32)i);
    	print(" ");
    	print_u32_hex((u32)regData);
    	print("\r\n");
    }

    print("Waiting 5 seconds for codec HPF to stabilize...\r\n");

    wait_ms(&iomod_inst,5000);

    u8 numCharsRet;

    clearInpBuffer();

    while(1)
    {
    	print("Please select the channel (L/R)\r\n> ");
    	numCharsRet = serial_read_line(serialInputBuffer,SERIAL_INPUT_BUFFER_LEN);

    	if(numCharsRet > 0)
    	{
    		if((serialInputBuffer[0] == 'l') || (serialInputBuffer[0] == 'L'))
    		{
    			selectedChannel = Left;
    			break;
    		}
    		else if((serialInputBuffer[0] == 'r') || (serialInputBuffer[0] == 'R'))
    		{
    			selectedChannel = Right;
    			break;
    		}
    	}

    	print("Invalid channel selection.\r\n");
    }
    clearInpBuffer();

    RunSineTest();


    for(i = 0; i < MAX_INPUT_LEN; i++)
    {
    	xil_printf("%d\r\n",input_buffer[i]);
    }

    print("End of samples\r\n");


    return 0;
}