Esempio n. 1
0
/*!
 * \brief Module entry point for Windows DLL
 *
 * This function is called by Windows OS when an application loads/unloads libMPSSE as a DLL
 *
 * \param[in] hModule			Handle
 * \param[in] reason_for_call	Reason for being called
 * \param[in] lpReserved		Reserved
 * \return none
 * \sa
 * \note
 * \warning
 */
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD reason_for_call,LPVOID lpReserved)
{
	//FT_STATUS status=FT_OK;
	FN_ENTER;

    switch (reason_for_call)
  	{
		case DLL_PROCESS_ATTACH:
			DBG(MSG_DEBUG,"reason_for_call = DLL_PROCESS_ATTACH\n");
			Init_libMPSSE();
		break;
		case DLL_THREAD_ATTACH:
			DBG(MSG_DEBUG,"reason_for_call = DLL_THREAD_ATTACH\n");

      	break;

		case DLL_THREAD_DETACH:
			DBG(MSG_DEBUG,"reason_for_call = DLL_THREAD_DETACH\n");

		break;
		case DLL_PROCESS_DETACH:
			DBG(MSG_DEBUG,"reason_for_call = DLL_PROCESS_DETACH\n");
			Cleanup_libMPSSE();
		break;

		default:
			DBG(MSG_WARN,"DllMain was called with an unknown reason\n");
    }

	FN_EXIT;
    return TRUE;
}
Esempio n. 2
0
/*!
 * \brief Module entry point for Windows Static Library and Linux
 * Dynamic & Static Libraries
 *
 * This function is the entry point for the module when it is loaded as a
 * static library(libMPSSE.lib or libMPSSE.a) in windows, and when it is loaded
 * as either a static library(libMPSSE.a) or a dynamic library(libMPSSE.so) in
 * linux
 *
 * \param[in] none
 * \param[out] none
 * \return none
 * \sa
 * \note
 * \warning
 */
void my_init(void)
{
	//FT_STATUS status=FT_OK;
	FN_ENTER;
	Init_libMPSSE();
	FN_EXIT;
}
Esempio n. 3
0
/*!
 * \brief Main function / Entry point to the sample application
 *
 * This function is the entry point to the sample application. It opens the channel, writes to the
 * EEPROM and reads back.
 *
 * \param[in] none
 * \return Returns 0 for success
 * \sa
 * \note
 * \warning
 */
int main()
{
	FT_STATUS status;
	FT_DEVICE_LIST_INFO_NODE devList;
	uint8 address;
	uint8 data;
	int i,j;

#ifdef _MSC_VER
	Init_libMPSSE();
#endif
	//channelConf.ClockRate = I2C_CLOCK_FAST_MODE;/*i.e. 400000 KHz*/
	//channelConf.ClockRate = I2C_CLOCK_STANDARD_MODE; /*i.e. 100000 KHz*/
	//channelConf.ClockRate = 20000; /*for test only*/
	channelConf.ClockRate = 2000; /*for test only*/
	channelConf.LatencyTimer= 255;
	//channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING;
	channelConf.Options = I2C_ENABLE_DRIVE_ONLY_ZERO;
	//channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING | I2C_ENABLE_DRIVE_ONLY_ZERO;

	status = I2C_GetNumChannels(&channels);
	APP_CHECK_STATUS(status);
	printf("Number of available I2C channels = %d\n",channels);

	if(channels>0)
	{
		for(i=0;i<channels;i++)
		{
			status = I2C_GetChannelInfo(i,&devList);
			APP_CHECK_STATUS(status);
			printf("Information on channel number %d:\n",i);
			/*print the dev info*/
			printf("		Flags=0x%x\n",devList.Flags);
			printf("		Type=0x%x\n",devList.Type);
			printf("		ID=0x%x\n",devList.ID);
			printf("		LocId=0x%x\n",devList.LocId);
			printf("		SerialNumber=%s\n",devList.SerialNumber);
			printf("		Description=%s\n",devList.Description);
			printf("		ftHandle=0x%x\n",devList.ftHandle);/*is 0 unless open*/
		}

		/* Open the first available channel */
		status = I2C_OpenChannel(CHANNEL_TO_OPEN,&ftHandle);
		APP_CHECK_STATUS(status);
		printf("\nhandle=0x%x status=%d\n",ftHandle,status);
		status = I2C_InitChannel(ftHandle,&channelConf);
		APP_CHECK_STATUS(status);

#if 0
		buffer[0]=0x00;
		buffer[1]=0x00;

		status = I2C_DeviceRead(ftHandle, I2C_DEVICE_ADDRESS_EEPROM, 1, buffer, \
		&channels, I2C_TRANSFER_OPTIONS_START_BIT|I2C_TRANSFER_OPTIONS_STOP_BIT|I2C_TRANSFER_OPTIONS_NACK_LAST_BYTE);
		printf("read data = 0x%x\n",buffer[0]);
		APP_CHECK_STATUS(status);

		status = I2C_CloseChannel(ftHandle);
#else

		for(address=START_ADDRESS_EEPROM;address<END_ADDRESS_EEPROM;address++)
		{
			printf("writing address = %d data = %d", address, \
				address+DATA_OFFSET);
			status = write_byte(I2C_DEVICE_ADDRESS_EEPROM, address, \
				address+DATA_OFFSET);
			for(j=0; ((j<RETRY_COUNT_EEPROM) && (FT_OK !=status)); j++)
			{
				printf("---- writing again to address = %d, data =%d\n", \
					address, address+DATA_OFFSET);
				status = write_byte(I2C_DEVICE_ADDRESS_EEPROM, address, \
					address+DATA_OFFSET);
			}
			APP_CHECK_STATUS(status);
		}
		printf("\n");
		for(address=START_ADDRESS_EEPROM; address<END_ADDRESS_EEPROM; address++)
		{
			status = read_byte(I2C_DEVICE_ADDRESS_EEPROM,address, &data);
			for(j=0; ((j<RETRY_COUNT_EEPROM) && (FT_OK !=status)); j++)
			{
				printf("read error... retrying \n");
				status = read_byte(I2C_DEVICE_ADDRESS_EEPROM,address, &data);
			}
			printf("reading address %d data read=%d\n",address,data);
		}
		status = I2C_CloseChannel(ftHandle);
#endif
	}

#ifdef _MSC_VER
	Cleanup_libMPSSE();
#endif

	return 0;
}