Beispiel #1
0
void bootloader(void)
{
	FSFILE* file;

	USBInitialize(0);

	if (!FSInit())
	{
		// File system failed - pretty much DISKmount didn't work
		AT45D_FormatFS();
		if (!FSInit())
		{
			error(ERR_FS_INIT);
		}
	}

	while (1)
	{
		USBTasks();
		BlinkBlueLED();

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1))
		{
			// do nothing
		}
		else
		{
			BlinkGreenLED();
			MSDTasks();
		}
		if (_T1IF)
		{
			_T1IF = 0;

			// check for MSD activity...
			if (MDD_AT45D_Write_Activity)
			{
				MDD_AT45D_Write_Activity = 0;
			}
			else
			{
				file = FSfopen("image.hex", "r");
				if (file != NULL)
				{
					file_flash(file);
					FSfclose(file);
					FSremove("image.hex");
					//AT45D_FormatFS();
					return;
				}
			}
		}
	}
}
Beispiel #2
0
void preflight(void)
{
	printf("Initialising USB\r\n");
	USBDeviceInit();        //usb_device.c.  Initializes USB module SFRs and firmware variables to known states.
	#if defined(USB_INTERRUPT)
		USBDeviceAttach();
	#endif
	delay_ms(100);

	printf("Preflight setup\r\n");
	while (U1OTGSTATbits.VBUSVD)
	{
		#if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
		USBDeviceTasks();   // Interrupt or polling method.  If using polling, must call
		                    // this function periodically.  This function will take care
		                    // of processing and responding to SETUP transactions 
		                    // (such as during the enumeration process when you first
		                    // plug in).  USB hosts require that USB devices should accept
		                    // and process SETUP packets in a timely fashion.  Therefore,
		                    // when using polling, this function should be called 
		                    // regularly (such as once every 1.8ms or faster** [see 
		                    // inline code comments in usb_device.c for explanation when
		                    // "or faster" applies])  In most cases, the USBDeviceTasks() 
		                    // function does not take very long to execute (ex: <100 
		                    // instruction cycles) before it returns.
		#endif

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) {
			// do nothing
		} else {
#if (USE_MSD == 1)
			MSDTasks();
#endif
#if (USE_CDC == 1)
			CDCTasks();
#endif
		}
#if (CONSOLE_UART != 0)
		console();
#endif
	}

	led_off(LED_RED);
	led_off(LED_BLUE);
	led_off(LED_GREEN);
	led_off(LED_ORANGE);

	printf("Preflight complete\r\n");
}
Beispiel #3
0
void USBPollingService(void)
{
	if (U1OTGSTATbits.VBUSVD)   // If we detect the USB power has returned, assume an end-of-flight condition
	{
#if (USE_TELELOG != 0)
		log_close();        // Close the datalog file
#endif // USE_TELELOG

		#if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
		USBDeviceTasks();   // Interrupt or polling method.  If using polling, must call
		                    // this function periodically.  This function will take care
		                    // of processing and responding to SETUP transactions 
		                    // (such as during the enumeration process when you first
		                    // plug in).  USB hosts require that USB devices should accept
		                    // and process SETUP packets in a timely fashion.  Therefore,
		                    // when using polling, this function should be called 
		                    // regularly (such as once every 1.8ms or faster** [see 
		                    // inline code comments in usb_device.c for explanation when
		                    // "or faster" applies])  In most cases, the USBDeviceTasks() 
		                    // function does not take very long to execute (ex: <100 
		                    // instruction cycles) before it returns.
		#endif // USB_POLLING

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1))
		{
			// do nothing
		}
		else
		{
#if (USE_MSD == 1)
			MSDTasks();
#endif
#if (USE_CDC == 1)
			CDCTasks();
#endif
		}
	}
}
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) {
        return;
    }

    // Indicate USB is connected.
    xSystemState.bUsbConnected = 1;
    

    // If data was received from the host...
    if(!HIDRxHandleBusy(USBOutHandle)) {
        // Make sure the transmitter is not busy.
        if (!HIDTxHandleBusy(USBInHandle)) {
            // Process the data.
            unsigned char ucTransmitDataLength = ucProcessCommandPacket(ReceivedDataBuffer, ToSendDataBuffer);

            // Send the data if there is any.
            if (ucTransmitDataLength > 0) {
                // Fill the remaining bytes with 0xff if it's not full.
                unsigned char i;
                for (i = ucTransmitDataLength; i < 64; i++) {
                    ToSendDataBuffer[i] = 0xff;
                }

                // Transmit the data.
                USBInHandle = HIDTxPacket(HID_EP, ToSendDataBuffer, 64);
            }

            // Re-arm the OUT endpoint to receive next packet if there is no data to send.
            else {
                USBOutHandle = HIDRxPacket(HID_EP, ReceivedDataBuffer, 64);
            }
        }
    }


    MSDTasks();
}
/*********************************************************************
* Function: void APP_DeviceMSDTasks(void);
*
* Overview: Keeps the Custom HID demo running.
*
* PreCondition: The demo should have been initialized and started via
*   the APP_DeviceMSDInitialize() and APP_DeviceMSDStart() demos
*   respectively.
*
* Input: None
*
* Output: None
*
********************************************************************/
void APP_DeviceMSDTasks()
{
    MSDTasks();
}