void WizFi250SpiDrv::spi_senddata(uint8_t *send_data, uint32_t send_length, uint8_t *recv_data, uint32_t *recv_length)
{
	uint32_t i = 0;
	uint8_t	 spi_recv_byte;
	uint8_t	 spi_valid_data = 0;
	char	 temp_buff[50];

	(*recv_length) = 0;

	if ( send_length > MAX_SPI_BUFSIZE )
	{
		strcpy_P( temp_buff, (char*)pgm_read_word(&debug_str_table[DBG_START_MSG]) );
		DBG(temp_buff);

		strcpy_P( temp_buff, (char*)pgm_read_word(&debug_str_table[DBG_ERROR_DATA_SIZE_TOO_BIG]) );
		DBG_LN(temp_buff);
		return;
	}

	for ( i=0; i<send_length; i++ )
	{
		spi_recv_byte = wizspi_byte((uint8_t)send_data[i], 1, 1, 1, m_spi_debug_level);
		process_esc_code(&spi_recv_byte, &spi_valid_data);
		if ( spi_valid_data == 1 )
		{
			recv_data[(*recv_length)] = spi_recv_byte;
			(*recv_length)++;
		}
	}

	while(1)
	{
		if ( digitalRead(m_WizFi250_DataReady) == HIGH )
		{
			spi_recv_byte = wizspi_byte((uint8_t)SPI_NULL, 1, 1, 1, m_spi_debug_level);
			process_esc_code(&spi_recv_byte, &spi_valid_data);
			if ( spi_valid_data == 1 )
			{
				recv_data[(*recv_length)] = spi_recv_byte;
				(*recv_length)++;
			}
		}

		else
			break;
	}
}
uint8_t  WizFi250SpiDrv::read(void)
{
	uint8_t	 spi_recv_byte;

	spi_recv_byte = wizspi_byte((uint8_t)SPI_NULL, 1, 1, 1, m_spi_debug_level);

	// 20140123 Test
	//Serial.print((char)spi_recv_byte);

	return spi_recv_byte;
}
uint8_t WizFi250SpiDrv::write(uint8_t ch)
{
	uint8_t retval, spi_valid_data = 0;

//	if(m_spi_free_buf_size == 10)
//	{
//		retval = wizspi_byte((uint8_t)SPI_ESC, 1, 1, 1, m_spi_debug_level);
//		process_esc_code(&retval, &spi_valid_data);
//		storeByteToSPIBuf(retval);
//
//		retval = wizspi_byte((uint8_t)SPI_XOFF, 1, 1, 1, m_spi_debug_level);
//		process_esc_code(&retval, &spi_valid_data);
//		storeByteToSPIBuf(retval);
//	}
//	else if(m_spi_free_buf_size == MAX_SPI_BUFSIZE)
//	{
//		retval = wizspi_byte((uint8_t)SPI_ESC, 1, 1, 1, m_spi_debug_level);
//		process_esc_code(&retval, &spi_valid_data);
//		storeByteToSPIBuf(retval);
//
//		retval = wizspi_byte((uint8_t)SPI_XON, 1, 1, 1, m_spi_debug_level);
//		process_esc_code(&retval, &spi_valid_data);
//		storeByteToSPIBuf(retval);
//	}

	retval = wizspi_byte((uint8_t)ch, 1, 1, 1, m_spi_debug_level);
	process_esc_code(&retval, &spi_valid_data);
	if(spi_valid_data == 1)
	{
		// 20140123 Test
		//Serial.print((char)retval);
		storeByteToSPIBuf(retval);
	}

	return 1;
}
void WizFi250SpiDrv::process_esc_code	(uint8_t *spi_recv, uint8_t *valid_data)
{
	char temp_buff[50];
	static uint8_t esc_mode = 0;
	static uint8_t esc2_mode = 0;
	uint8_t spi2_recv = 0;

	(*valid_data) = 0;

	if( (*spi_recv) == SPI_NULL )		{ return; }
	if( (*spi_recv) == SPI_ESC )		{ esc_mode = 1; return; }

	if( esc_mode == 1 )
	{
		esc_mode = 0;
		switch((*spi_recv))
		{
			case SPI_F0:					// Press 'F0' to upper
				(*valid_data) = 1;
				(*spi_recv) = SPI_NULL;
				break;
			case SPI_F1:					// Press 'F1' to upper
				(*valid_data) = 1;
				(*spi_recv) = SPI_ESC;
				break;
			case SPI_SYNC:					// Handle Sync Signal
				(*spi_recv) = wizspi_byte((uint8_t)SPI_ESC, 1, 1, 1, m_spi_debug_level);
				if ( (*spi_recv) != SPI_NULL )
				{
					strcpy_P( temp_buff, (char*)pgm_read_word(&debug_str_table[DBG_START_MSG]) );
					DBG(temp_buff);

					strcpy_P( temp_buff, (char*)pgm_read_word(&debug_str_table[DBG_NEED_SPI_NULL]) );
					DBG_LN(temp_buff);
				}
				(*spi_recv) = wizspi_byte((uint8_t)SPI_SYNC, 1, 1, 1, m_spi_debug_level);
				break;
			case SPI_XON:					// Handle Oon Signal
				break;
			case SPI_XOFF:					// Handle Xoff Signal
				{
					uint8_t found_xon = 0;
					while(1)
					{
						delay(10);
						spi2_recv = wizspi_byte((uint8_t)SPI_NULL, 1, 1, 1, m_spi_debug_level);
						if ( spi2_recv == SPI_NULL )	{ continue; }
						if ( spi2_recv == SPI_ESC )		{ esc2_mode = 1;	return;	}

						if ( esc2_mode == 1 )
						{
							esc2_mode = 0;
							switch(spi2_recv)
							{
								case SPI_XON:	// Handle Xon Signal
									found_xon = 1;
									break;
								default:
									break;
							}
						}

						if ( found_xon == 1 )		break;
					}
				}
			case SPI_ERR:						// Handle Error Signal
				break;
			case SPI_ESC:						// Lost ESC Data
				esc_mode = 1;					// Just Ignore previous ESC
				break;
			default:
				break;
		}
	}
	else
	{
		(*valid_data) = 1;
	}
}
Ejemplo n.º 5
0
uint8  IINCHIP_SpiSendData(uint8 dat)
{
  //return(SPI1_SendByte(dat));
  //return(SPI2_SendByte(dat));
  return(wizspi_byte(WIZ_SPI2, dat));
}
Ejemplo n.º 6
0
uint8  IINCHIP_SpiSendData(uint8 dat)
{
	return(wizspi_byte(WIZ_SPI1, dat));
}