コード例 #1
0
ファイル: main.c プロジェクト: BlueSkyGjj/SAMV71_softpack
/**
 * \brief Application entry point for PWM with PDC example.
 *
 * Outputs a PWM on LED1.
 * Channel #0 is configured as synchronous channels.
 * The update of the duty cycle values is made automatically by the Peripheral DMA Controller.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
    uint32_t i;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;
    
    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();

    /* Output example information */
    printf("-- PWM with DMA Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* PIO configuration */
    PIO_Configure(pinPwm, PIO_LISTSIZE(pinPwm));
    for (i= 0; i< DUTY_BUFFER_LENGTH; i++) dwDutys[i] = i/2;

    /* Enable PWMC peripheral clock */
    PMC_EnablePeripheral(ID_PWM0);

    /* Configure interrupt for PWM transfer */
    NVIC_DisableIRQ(PWM0_IRQn);
    NVIC_ClearPendingIRQ(PWM0_IRQn);
    NVIC_SetPriority(PWM0_IRQn, 0);

    /* Configure DMA channel for PWM transfer */
    _ConfigureDma();

    /* Set clock A to run at PWM_FREQUENCY * MAX_DUTY_CYCLE (clock B is not used) */
    PWMC_ConfigureClocks(PWM0, PWM_FREQUENCY * MAX_DUTY_CYCLE , 0, BOARD_MCK);

    /* Configure PWMC channel for LED0 (left-aligned, enable dead time generator) */
    PWMC_ConfigureChannel( PWM0,
            0,  /* channel */
            PWM_CMR_CPRE_CLKA,   /* prescaler, CLKA  */
            0,                   /* alignment */
            0                    /* polarity */
            );

    PWMC_ConfigureSyncChannel(PWM0,
            (1 << CHANNEL_PWM_LED0), /* Define the synchronous channels by the bits SYNCx */
            PWM_SCM_UPDM_MODE2,      /* Select the manual write of duty-cycle values and the automatic update by setting the field UPDM to 鈥�1鈥� */
            0,
            0);

    /* Configure channel 0 period */
    PWMC_SetPeriod(PWM0, 0, DUTY_BUFFER_LENGTH);
    /* Configure channel 0 duty cycle */
    PWMC_SetDutyCycle(PWM0, 0, MIN_DUTY_CYCLE);
    /* Define the update period by the field UPR in the PWM_SCUP register*/
    PWMC_SetSyncChannelUpdatePeriod(PWM0, 8);
    /* Enable the synchronous channels by writing CHID0 in the PWM_ENA register */
    PWMC_EnableChannel(PWM0, 0);
    /* Enable PWM interrupt */
    PWMC_EnableIt(PWM0, 0, PWM_IER2_WRDY);
    NVIC_EnableIRQ(PWM0_IRQn);
    _PwmDmaTransfer();
    while(1);
}
コード例 #2
0
ファイル: main.c プロジェクト: gstroe/Arm
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t isUsbConnected = 0;
	/* Disable watchdog */
	WDT_Disable(WDT);


	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* Initialize PIO interrupts */
	PIO_InitializeInterrupts(0);

	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

	/* Configure DMA driver */
	_ConfigureDma();

	/* Configure USART */
	_ConfigureUsart();
	_UsartDmaRxSetup();

	/* Initialize OTG clocks */
	_ConfigureUotghs();

	/* CDC serial driver initialization */
	CDCDSerialDriver_Initialize(&cdcdSerialDriverDescriptors);

	/* Help information */
	_DebugHelp();

	// Start USB stack to authorize VBus monitoring
	USBD_Connect();

	/* Driver loop */
	while (1) {
		/* Device is not configured */
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			if (isUsbConnected) {
				isUsbConnected = 0;
				isCdcSerialON  = 0;
			}
		} else if (isUsbConnected == 0)
			isUsbConnected = 1;

		/* Serial port ON/OFF */
		if (CDCDSerialDriver_GetControlLineState() & CDCControlLineState_DTR) {
			if (!isCdcSerialON) {
				isCdcSerialON = 1;

				/* Start receiving data on the USART */
				_UsartDmaRx();
				USART_EnableIt(BASE_USART, US_CSR_FRAME | US_CSR_OVRE | US_IER_TIMEOUT);
				USART_EnableRecvTimeOut(BASE_USART, USART_TIMEOUT);
				/* Start receiving data on the USB */
				CDCDSerialDriver_Read(usbBuffer,
									  DATAPACKETSIZE,
									  (TransferCallback) _UsbDataReceived,
									  0);
			}
		} else if (isCdcSerialON)
			isCdcSerialON = 0;

		if (DBG_IsRxReady()) {
			uint8_t key = DBG_GetChar();

			/* ESC: CDC Echo ON/OFF */
			if (key == 27) {
				printf("** CDC Echo %s\n\r",
					   isCdcEchoON ? "OFF" : "ON");
				isCdcEchoON = !isCdcEchoON;
			}
			/* 't': Test CDC writing  */
			else if (key == 't')
				_SendText();
			else {
				printf("Alive\n\r");

				while (CDCDSerialDriver_Write((char *)"Alive\n\r", 8, 0, 0)
					   != USBD_STATUS_SUCCESS);

				_DebugHelp();
			}
		}
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 *  \brief Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint8_t ucKey;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Output example information */
	printf("-- USART LON Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s  With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);

	/* Configure pins */
	PIO_Configure(pins, PIO_LISTSIZE(pins));
	/* PB4 function selected */
	MATRIX->MATRIX_WPMR = MATRIX_WPMR_WPKEY_PASSWD;
	MATRIX->CCFG_SYSIO |= CCFG_SYSIO_SYSIO4;

	/* Display menu */
	_DisplayMenu();

	/* Configure DMA with IRQ */
	_ConfigureDma();

	Buffer[0] = sizeof(palette) - 1; /* LON Data Length:  */
	Buffer[1] = US_LONL2HDR_BLI(2);
	memcpy(&Buffer[2], palette, sizeof(palette));

	/* configure USART in LON mode*/
	_ConfigureUsart();

	NVIC_EnableIRQ(XDMAC_IRQn);

	while (1) {
		ucKey = DBG_GetChar();
		switch (ucKey) {
		case 't':
		case 'T':
			printf("-I- LON Transmitting ... \n\r");
			USART->US_CR = US_CR_RSTSTA;    /* Reset Status Bits */
			_DmaUsartTx();
			while (!transDone);
			printf("-I- LON Transmitting completed \n\r");
			transDone = 0;
			break;

		case 'r':
		case 'R':
			printf("-I- LON receiving ... \n\r");
			USART->US_CR = US_CR_RSTSTA;    /* Reset Status Bits */
			recvDone = 0;

			_DmaUsartRx();
			while (!recvDone);
			/* successfully received */
			_DumpInfo(pRecvBufferUSART, BUFFER_SIZE - 1);
			printf("\n\r-I- LON Receiving completed \n\r");
			memset(pRecvBufferUSART, 0, sizeof(pRecvBufferUSART));
			break;

		case 'm':
		case 'M':
			_DisplayMenu();
			break;
		}
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: gstroe/Arm
/**
 *  \brief usb_iad_hid_aud Application entry point.
 *
 *  Starts the driver and waits for an audio input stream to forward to the DAC.
 */
int main(void)
{
	volatile uint8_t usbConn = 0;
	volatile uint8_t audioOn = 0;
	int32_t  numDiff = 0, prevDiff = 0;
	int8_t   clockAdjust = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();


	printf("-- USB HID + Audio Device Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	TimeTick_Configure();
	/* Interrupt priority */
	NVIC_SetPriority(USBHS_IRQn, 2);

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

	/* Initialize all USB power (off) */
	_ConfigureUsbhs();

	/* ----- HID Function Initialize */
#ifdef NO_PUSHBUTTON
	printf("-- : DBG key 1 2 used as buttons\n\r");
	printf("-- : 1st press to push, 2nd press to release\n\r");
#else
	/* Initialize key statuses and configure push buttons */
	PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
#endif
	memset(keyStatus, 1, NUM_KEYS);
	//LED_Configure(LED_NUMLOCK);

	/* Audio STREAM LED */
	LED_Configure(USBD_LEDOTHER);

	/* Configure Audio */
	_ConfigureAudioPlay(AUDDevice_SAMPLERATE, BOARD_MCK);

	/* Configure DMA */
	_ConfigureDma();

	/* USB audio driver initialization */
	HIDAUDDDriver_Initialize(&hidauddDriverDescriptors);

	/* connect if needed */
	USBD_Connect();

	/* Infinite loop */
	while (1) {
		if (USBD_GetState() < USBD_STATE_CONFIGURED) {
			usbConn = 0;
			continue;
		}

		if (audioOn) {
			if (isDacActive == 0) {
				AudioPlayEnable(0);
				printf("audE ");
				isFirstFrame = 1;
				audioOn = 0;
			} else {
				numDiff = numBuffersToSend - DAC_DELAY;

				if (prevDiff != numDiff) {
					prevDiff = numDiff;

					if (numDiff > 1 && clockAdjust != 1) {
						printf("+");
						/* USB too fast or SSC too slow: faster clock */
						clockAdjust = 1;
						_SyncAdjust(1);
					}

					if (numDiff < -1 && clockAdjust != -1) {
						printf("-");
						/* USB too slow or SSC too fast: slower clock */
						clockAdjust = -1;
						_SyncAdjust(-1);
					}

					if (numDiff == 0 && clockAdjust != 0) {
						clockAdjust = 0;
						_SyncAdjust(0);
					}
				}
			}
		} else if (isDacActive) {
			printf("audS ");
			audioOn = 1;
		}

		if (usbConn == 0) {
			usbConn = 1;
			/* Start Reading the incoming audio stream */
			AUDDFunction_Read(buffers[inBufferIndex],
							  AUDDevice_BYTESPERFRAME,
							  (TransferCallback) FrameReceived,
							  0); // No optional argument
		}

		HIDDKeyboardProcessKeys();
	}
}