コード例 #1
0
ファイル: main.c プロジェクト: cxjlante/at91sam3s
/**
 * Initializes drivers and start the USB CDCHID device.
 */
int main(void)
{
    uint8_t usbConnected = 0, serialON = 0;

    /* Disable watchdog */
    WDT_Disable( WDT );

    printf("-- USB CDCHID Device Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* If they are present, configure Vbus & Wake-up pins */
    PIO_InitializeInterrupts(0);

    /* If there is on board power, switch it off */

    /* Enable UPLL for USB */
    ConfigureUsbClock();

    /* Configure timer 0 */
    ConfigureTc0();

    /* ----- CDC Function Initialize */
    /* Configure USART */
    ConfigureUsart();

    /* ----- HID Function Initialize */
    /* Initialize key statuses and configure push buttons */
    PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
    memset(keyStatus, 1, NUM_KEYS);

    /* Configure LEDs */
    LED_Configure(LED_NUMLOCK);


    /* USB CDCHID driver initialization */
    CDCHIDDDriver_Initialize(&cdchiddDriverDescriptors);

    /* connect if needed */
    VBus_Configure();

    /* Driver loop */
    while (1) {

        /* Device is not configured */
        if (USBD_GetState() < USBD_STATE_CONFIGURED) {

            if (usbConnected) {
                printf("-I- USB Disconnect/Suspend\n\r");
                usbConnected = 0;

                /* Serial port closed */
                isSerialPortON = 0;
            }
        }
        else {

            if (usbConnected == 0) {
                printf("-I- USB Connect\n\r");
                usbConnected = 1;
            }

            if (!serialON && isSerialPortON) {
                printf("-I- SerialPort ON\n\r");
                /* Start receiving data on the USART */
                usartCurrentBuffer = 0;
                USART_ReadBuffer(BASE_USART,
                                 usartBuffers[0], DATABUFFERSIZE);
                USART_ReadBuffer(BASE_USART,
                                 usartBuffers[1], DATABUFFERSIZE);
                BASE_USART->US_IER = US_CSR_ENDRX
                                     | US_CSR_FRAME
                                     | US_CSR_OVRE;

                /* Start receiving data on the USB */
                CDCDSerial_Read(usbSerialBuffer0,
                                DATABUFFERSIZE,
                                (TransferCallback) UsbDataReceived,
                                0);
                serialON = 1;
            }
            else if (serialON && !isSerialPortON) {
                printf("-I- SeriaoPort OFF\n\r");
                serialON = 0;
            }

            HIDDKeyboardProcessKeys();
        }
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 * Initializes drivers and start the USB CDCMSD device.
 */
int main(void)
{
	uint8_t usbConnected = 0, serialON = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	printf("-- USB CDCMSD Device Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* If they are present, configure Vbus & Wake-up pins */
	PIO_InitializeInterrupts(0);

	/* If there is on board power, switch it off */
	_ConfigureUotghs();

	/* ----- MSD Function Initialize */
	/* Configure memories */
	_MemoriesInitialize();

	/* USB CDCMSD driver initialization */
	CDCMSDDriver_Initialize(&cdcmsddDriverDescriptors, luns, MAX_LUNS);

	/* connect if needed */
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (usbConnected) {
				printf("-I- USB Disconnect/Suspend\n\r");
				usbConnected = 0;

				/* Serial port closed */
				isSerialPortON = 0;
			}
		} else {
			if (usbConnected == 0) {
				printf("-I- USB Connect\n\r");
				usbConnected = 1;
			}

			if (!serialON && isSerialPortON) {
				printf("-I- SerialPort ON\n\r");
				/* Start receiving data on the USART */
				/* Start receiving data on the USB */
				CDCDSerial_Read(usbSerialBuffer0, DATAPACKETSIZE, 0, 0);
				serialON = 1;
			} else if (serialON && !isSerialPortON) {
				printf("-I- SeriaoPort OFF\n\r");
				serialON = 0;
			}

			MSDFunction_StateMachine();

			if (msdRefresh) {
				msdRefresh = 0;

				if (msdWriteTotal < 50 * 1000) {
					/* Flush Disk Media */
				}

				msdWriteTotal = 0;
			}
		}
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: cxjlante/at91sam3s
/*----------------------------------------------------------------------------
 * Handles interrupts coming from USART
 *----------------------------------------------------------------------------*/
void USART_Handler(void)
{
    uint32_t status;
    unsigned short serialState;

    status  = BASE_USART->US_CSR;
    status &= BASE_USART->US_IMR;

    /* If USB device is not configured, do nothing */
    if (!isSerialPortON) {

        BASE_USART->US_IDR = 0xFFFFFFFF;
        return;
    }

    /* Buffer has been read successfully */
    if ((status & US_CSR_ENDRX) != 0) {

        /* Disable timer */
        TC_Stop(TC0, 0);

        /* Send buffer through the USB */
        while (CDCDSerial_Write(usartBuffers[usartCurrentBuffer],
                                DATABUFFERSIZE, 0, 0) != USBD_STATUS_SUCCESS);

        /* Restart read on buffer */
        USART_ReadBuffer(BASE_USART,
                         usartBuffers[usartCurrentBuffer],
                         DATABUFFERSIZE);
        usartCurrentBuffer = 1 - usartCurrentBuffer;

        /* Restart timer */
        TC_Start(TC0, 0);
    }

    /* Buffer has been sent */
    if ((status & US_IER_TXBUFE) != 0) {

        /* Restart USB read */
        CDCDSerial_Read(usbSerialBuffer0,
                        DATABUFFERSIZE,
                        (TransferCallback) UsbDataReceived,
                        0);
        BASE_USART->US_IDR = US_IER_TXBUFE;
    }

    /* Errors */
    serialState = CDCDSerial_GetSerialState();

    /* Overrun */
    if ((status & US_CSR_OVRE) != 0) {

        TRACE_WARNING( "USART1_IrqHandler: Overrun\n\r");
        serialState |= CDCSerialState_OVERRUN;
    }

    /* Framing error */
    if ((status & US_CSR_FRAME) != 0) {

        TRACE_WARNING( "USART1_IrqHandler: Framing error\n\r");
        serialState |= CDCSerialState_FRAMING;
    }

    CDCDSerial_SetSerialState(serialState);
}