Пример #1
0
int main(void)
{
    debug_init(SOFTWARE_NAME);

    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    char_display_init();
    LED_Configure(0);
    LED_Configure(1);

    if (! BCAN_Init(1000, 0, NULL)) {
        printf("INIT FAIL");
        LED_Set(1);
        return 1;
    }

    printf("INIT OK\n\r");
    LED_Set(0);

    BCAN_InitMailboxRegisters( 0, 2, AT91C_CAN_MIDvA, (0x5AC << 18), AT91C_CAN_MOT_RX, 0x0);

    char_display_number(6);
    while(1) {
        CAN_Packet packet = BCAN_ReadAndClear(0,2);
        if (packet.valid) {
            char_display_number(packet.data_low);
        }
        char_display_tick();
        for (unsigned volatile int i = 0xFF; i > 0; i--) ;
    }

    return 0;
}
Пример #2
0
Файл: ui.c Проект: gstroe/Arm
/**
 * \name Main user interface functions
 * @{
 */
void ui_init(void)
{
	/* Initialize LEDs */
	LED_Configure(LED_YELLOW0);
#if 2 == LED_NUM
	LED_Configure(LED_YELLOW1);
#endif
}
//------------------------------------------------------------------------------
/// Invoked when the USB device leaves the Suspended state. By default,
/// configures the LEDs.
//------------------------------------------------------------------------------
void USBDCallbacks_Resumed(void)
{
    // Initialize LEDs
    LED_Configure(USBD_LEDPOWER);
    LED_SET_POWER;//LED_Set(USBD_LEDPOWER);
    LED_Configure(USBD_LEDUDATA);
    LED_CLEAR_DATA;//LED_Clear(USBD_LEDUDATA);

}
Пример #4
0
//------------------------------------------------------------------------------
//         Callbacks re-implementation
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Invoked when the USB device leaves the Suspended state. By default,
/// configures the LEDs.
//------------------------------------------------------------------------------
void USBDCallbacks_Resumed(void)
{
    // Initialize LEDs
    LED_Configure(USBD_LEDPOWER);
    LED_Set(USBD_LEDPOWER);
    LED_Configure(USBD_LEDUSB);
    LED_Clear(USBD_LEDUSB);
    USBState = STATE_RESUME;
}
Пример #5
0
int main(void)
{
    unsigned int switchPressed;

    debug_init(SOFTWARE_NAME);

    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    switches_init();
    char_display_init();
    LED_Configure(0);
    LED_Configure(1);

    if (! BCAN_Init(1000, 0, NULL)) {
        printf("INIT FAIL");
        LED_Set(1);
        return 1;
    }

    printf("INIT OK\n\r");
    LED_Set(0);

    BCAN_InitMailboxRegisters( 0, 1, 0x0, (0x5AC << 18), AT91C_CAN_MOT_TX, 0x0);

    while(1) {
        DisplayMenu();

        switchPressed = -1;
        while (switchPressed == -1) {
            if (switches_pressed(0)) {
                TRACE_INFO("Switch 0 is pressed\n\r");
                switchPressed = 0;
            } else if (switches_pressed(1)) {
                TRACE_INFO("Switch 1 is pressed\n\r");
                switchPressed = 1;
            } else if (switches_pressed(2)) {
                TRACE_INFO("Switch 2 is pressed\n\r");
                switchPressed = 2;
            } else if (switches_pressed(3)) {
                TRACE_INFO("Switch 3 is pressed\n\r");
                switchPressed = 3;
            } else {
                //TRACE_INFO("No Switch is pressed\n\r");
            }
            char_display_tick();
            for (volatile unsigned int i = 0xFF; i > 0; i--) ;
        }

        unsigned int result = -1;
        while (result != CAN_STATUS_SUCCESS) {
            result = BCAN_Write(0, 1, 0, switchPressed, 0x1);
        }
        char_display_number(switchPressed);
    }

    return 0;
}
Пример #6
0
static void prvSetupHardware( void )
{
	/* Disable watchdog. */
	WDT_Disable( WDT );
	WDT_Disable( ( Wdt * ) RSWDT );

	SCB_EnableICache();
	SCB_EnableDCache();

    LED_Configure( 0 );
    LED_Configure( 1 );
}
Пример #7
0
void vParTestInitialise( void )
{	
unsigned long ul;

	for( ul = 0; ul < partstNUM_LEDS; ul++ )
	{
		LED_Configure( ul );
	}
}
Пример #8
0
//-----------------------------------------------------------------------------
/// Initializes an USB audio speaker function driver
//-----------------------------------------------------------------------------
void AUDDFunctionDriver_Initialize()
{
    auddSpeakerChannels[0].muted = 0;
    auddSpeakerChannels[0].number = AUDD_MASTERCHANNEL;
    auddSpeakerChannels[1].muted = 0;
    auddSpeakerChannels[1].number = AUDD_LEFTCHANNEL;
    auddSpeakerChannels[2].muted = 0;
    auddSpeakerChannels[2].number = AUDD_RIGHTCHANNEL;

    // Initialize the third LED to indicate when the audio interface is active
    LED_Configure(USBD_LEDOTHER);
}
Пример #9
0
/* Hardware Initialisation */
static void prvSetupHardware( void )
{
    portDISABLE_INTERRUPTS();

    /* When using the JTAG debugger the hardware is not always initialised to
    the correct default state.  This line just ensures that this does not
    cause all interrupts to be masked at the start. */
    AT91C_BASE_AIC->AIC_EOICR = 0;

    /* Most setup is performed by the low level init function called from the
    startup asm file. */

    /* Enable the peripheral clock. */
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;

    /* Initialise the LED outputs for use by the demo application tasks. */
    LED_Configure(0);
}
Пример #10
0
//------------------------------------------------------------------------------
/// Initializes an USB audio speaker device driver, as well as the underlying
/// USB controller.
//------------------------------------------------------------------------------
void AUDDSpeakerDriver_Initialize()
{
    // Initialize speaker channels
    AUDDSpeakerChannel_Initialize(&(auddSpeakerDriver.channels[0]),
                                  AUDDSpeakerDriver_MASTERCHANNEL,
                                  0);
    AUDDSpeakerChannel_Initialize(&(auddSpeakerDriver.channels[1]),
                                  AUDDSpeakerDriver_LEFTCHANNEL,
                                  0);
    AUDDSpeakerChannel_Initialize(&(auddSpeakerDriver.channels[2]),
                                  AUDDSpeakerDriver_RIGHTCHANNEL,
                                  0);
    
    // Initialize the USB driver
    USBDDriver_Initialize(&(auddSpeakerDriver.usbdDriver),
                          &auddSpeakerDriverDescriptors,
                          auddSpeakerDriverInterfaces);
    USBD_Init();

    // Initialize the third LED to indicate when the audio interface is active
    LED_Configure(USBD_LEDOTHER);
}
Пример #11
0
Файл: main.c Проект: gstroe/Arm
/**
 *  \brief getting-started Application entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main(void)
{
	uint32_t id_offset = 0;
	uint32_t fifo_entries;
	uint32_t button_state = BUTTON_PUSHED;
	uint32_t button_state2 = BUTTON_NOT_PUSHED;
	uint32_t can_mode = CAN_STANDARD;

	/* Disable watchdog */
	WDT_Disable(WDT);

	/* Output example information */
	printf("\n\r-- Controller Area Network (CAN) Example %s --\n\r",
			SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__);
	printf("-- LED0 toggles on CAN message reception\n\r");
	printf("-- LED1 toggles on CAN message transmission\n\r");
	printf("-- CAN message transmission stopped while SW0 is pushed\n\r");
	printf("-- SW1 pushes alternate between standard CAN and CAN-FD\n\r");

	SCB_EnableICache();
	SCB_EnableDCache();

	/* Configure systick for 1 ms. */
	TimeTick_Configure();

	/* Configure Board LED's */
	LED_Configure(0);
#if 2 == LED_NUM
	LED_Configure(1);
#endif

	/* Configure Timer/Counter for 250msec Tick */
	_ConfigureTc();

	/* Configure Board Push-buttons */
	// SW1 is a ERASE system function, switch it to port function
	MATRIX->CCFG_SYSIO |= (1u << 12);
	/* have to disable the pull down on PB12 for SW1 before the pull up can be
		enabled */
	PIOB->PIO_PPDDR = 1 << 12;
	PIO_Configure(pushbutton, PIO_LISTSIZE(pushbutton));
	/* Adjust pio denounce filter parameters, uses 10 Hz filter. */
	PIO_SetDebounceFilter(&pushbutton[0], 10);
#if 2 == BUTTON_NUM
	PIO_SetDebounceFilter(&pushbutton[1], 10000);
#endif

	SystemCoreClockUpdate();

	MCAN_Init(&mcan1Config);

	MCAN_InitFdBitRateSwitchEnable(&mcan1Config);
	MCAN_InitTxQueue(&mcan1Config);
	MCAN_InitLoopback(&mcan1Config);  // remove to disable loop back mode
	MCAN_Enable(&mcan1Config);

	MCAN_IEnableMessageStoredToRxDedBuffer(&mcan1Config, CAN_INTR_LINE_1);

	txMailbox0 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_0,
			MSG_ID_0, CAN_STD_ID, CAN_DLC_1);
	txMailbox1 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_1,
			MSG_ID_1, CAN_EXT_ID, CAN_DLC_8);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_0, FILTER_0, MSG_ID_0,
			CAN_STD_ID);
	MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_1, FILTER_0, MSG_ID_1,
			CAN_EXT_ID);
	MCAN_ConfigRxClassicFilter(&mcan1Config, CAN_FIFO_0, FILTER_1, MSG_ID_2,
			CAN_STD_ID, MSG_ID_2_MASK);

	while (1) {
		 if (tick) {
			tick = 0;
			if (PIO_Get(&pushbutton[0]) == BUTTON_NOT_PUSHED) {
				if (button_state2 == BUTTON_NOT_PUSHED) {
					/* periodically transmit messages while SW0 is not pushed */
					// send standard ID from a dedicated buffer
					*txMailbox0 = MSG_ID_0_DATA1;  // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_0);  // send data
					txdCntr++;
					// send extended ID from a dedicated buffer
					*txMailbox1 = MSG_ID_1_DATA1_4;  // write data into CAN mailbox
					*(txMailbox1 + 1) = MSG_ID_1_DATA5_8; // write data into CAN mailbox
					MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_1); // send the data
					txdCntr++;
					// send from Tx Queue
					MCAN_AddToTxFifoQ(&mcan1Config, MSG_ID_2 + id_offset, CAN_STD_ID,
							CAN_DLC_1, &txData[0]);
					txdCntr++;
					// increment the offset so we send different ID's within the
					// range defined by the mask
					id_offset = (id_offset + 1) & (uint32_t) ~MSG_ID_2_MASK;
					// update data being sent for next time
					txData[0]++;
					button_state2 = BUTTON_NOT_PUSHED;
				}
			} else {
				if (button_state2 == BUTTON_NOT_PUSHED)
					button_state2 = BUTTON_PUSHED;
				else
					button_state2 = BUTTON_NOT_PUSHED;
			}
		}
		/* poll for TX'd message complete */
		 if (MCAN_IsTxComplete(&mcan1Config)) {
			MCAN_ClearTxComplete(&mcan1Config);
			if (MCAN_IsBufferTxd(&mcan1Config, TX_BUFFER_0)) {
		#if 2 == LED_NUM
				LED_Toggle(1);
		#endif
			}
		}
		/* Poll for new CAN messages in RX FIFO */
		do {
			fifo_entries = MCAN_GetRxFifoBuffer(&mcan1Config, CAN_FIFO_0,
					(Mailbox64Type *) &rxMailbox2);
			if (fifo_entries > 0) rxdCntr++;
		} while (fifo_entries > 1);

		/* SW1 used to alternate between standard CAN and CAN-FD operation */
#if 2 == BUTTON_NUM
		if (PIO_Get(&pushbutton[1]) == BUTTON_NOT_PUSHED) {
#else
		if (1) {
#endif
			 button_state = BUTTON_NOT_PUSHED;
		} else {
			if (button_state == BUTTON_NOT_PUSHED ) {
				// Switch on a NOT PUSHED to PUSHED edge
				button_state = BUTTON_PUSHED;
				if (can_mode == CAN_STANDARD) {
					can_mode = CAN_FD;
					MCAN_RequestFdBitRateSwitch( &mcan1Config );
				} else {
					can_mode = CAN_STANDARD;
					MCAN_RequestIso11898_1( &mcan1Config );
				}
			}
		}
#ifdef POLLKEYBOARD
	/* poll for keyboard entry */
	if (DBG_IsRxReady()) {
		keyboard = DBG_GetChar();
		if (((char) keyboard == 'L' ) || ( (char) keyboard == 'l')) {
			if (loopback == 1) {
				MCAN_LoopbackOff(&mcan1Config);
				loopback = 0;
			} else {
				MCAN_LoopbackOn(&mcan1Config);
				loopback = 1;
			}
		}
	}
#endif
	}
}
Пример #12
0
//------------------------------------------------------------------------------
/// Main function
//------------------------------------------------------------------------------
int main(void)
{
    unsigned char key;
    unsigned char isValid;

    // Configure all pins
    PIO_Configure(pins, PIO_LISTSIZE(pins));

    LED_Configure(0);
    LED_Set(0);
    LED_Configure(1);
    LED_Set(1);

    // Initialize the DBGU
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);

    // Switch to Main clock
    AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // Configure PLL to 98.285MHz
    *AT91C_CKGR_PLLR = ((1 << 29) | (171 << AT91C_CKGR_MUL_SHIFT) \
        | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \
        | (21 << AT91C_CKGR_DIV_SHIFT));
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0);

    // Configure master clock in two operations
    AT91C_BASE_PMC->PMC_MCKR = (( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);
    AT91C_BASE_PMC->PMC_MCKR = ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK);
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // DBGU reconfiguration
    DBGU_Configure(DBGU_STANDARD, 115200, SSC_MCK);

    // Configure and enable the TWI (required for accessing the DAC)
    *AT91C_PMC_PCER = (1<< AT91C_ID_TWI0); 
    TWI_ConfigureMaster(AT91C_BASE_TWI0, TWI_CLOCK, SSC_MCK);
    TWID_Initialize(&twid, AT91C_BASE_TWI0);

    printf("-- OsmoSDR firmware (" BOARD_NAME ") " GIT_REVISION " --\n\r");
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	req_ctx_init();
	PIO_InitializeInterrupts(0);

	cmd_state.out = vprintf;
	uart_cmd_reset(&cmd_state);
	uart_cmds_register(cmds, sizeof(cmds)/sizeof(cmds[0]));

	fastsource_init();
	VBus_Configure();

	power_peripherals(1);

	si570_init(&si570, &twid, SI570_I2C_ADDR);
	set_si570_freq(30000000);

	sam3u_e4k_init(&e4k, &twid, E4K_I2C_ADDR);
	e4k.vco.fosc = 30000000;

	osdr_fpga_init(SSC_MCK);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_ADC_TIMING, (1 << 8) | 255);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_PWM1, (1 << 400) | 800);
	osdr_fpga_set_iq_swap(0);

	ssc_init();
	e4k_init(&e4k);
	e4k_init(&e4k);

    // Enter menu loop
    while (1) {

    	if (DBGU_IsRxReady()) {
        	key = DBGU_GetChar();
        	// Process user input
        	if (uart_cmd_char(&cmd_state, key) == 1) {
        		//ssc_stats();
        	}
    	}
    	ssc_dma_start();
    	fastsource_start();
    }
}
Пример #13
0
/**
 * 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();
        }
    }
}
Пример #14
0
//-----------------------------------------------------------------------------
/// Initializes drivers and start the USB composite device.
//-----------------------------------------------------------------------------
int main()
{
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Composite 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);

    // ----- 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);

    // ----- CDC Function Initialize
    // Configure USART
    PIO_Configure(pinsUsart, PIO_LISTSIZE(pinsUsart));
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US0;
    AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;
    USART_Configure(AT91C_BASE_US0,
                    USART_MODE_ASYNCHRONOUS,
                    115200,
                    MCK);
    USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
    USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
    AIC_ConfigureIT(AT91C_ID_US0, 0, ISR_Usart0);
    AIC_EnableIT(AT91C_ID_US0);

    // Configure timer 0
    AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
    AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
    AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF;
    AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK
                             | AT91C_TC_CPCSTOP
                             | AT91C_TC_CPCDIS
                             | AT91C_TC_WAVESEL_UP_AUTO
                             | AT91C_TC_WAVE;
    AT91C_BASE_TC0->TC_RC = 0x00FF;
    AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
    AIC_ConfigureIT(AT91C_ID_TC0, 0, ISR_Timer0);
    AIC_EnableIT(AT91C_ID_TC0);

    // USB COMPOSITE driver initialization
    COMPOSITEDDriver_Initialize();

    WAKEUP_CONFIGURE();

    // connect if needed
    VBUS_CONFIGURE();

    // Driver loop
    while (1) {

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

            // Connect pull-up, wait for configuration
            USBD_Connect();
            while (USBD_GetState() < USBD_STATE_CONFIGURED);

            // Start receiving data on the USART
            usartCurrentBuffer = 0;
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[0], DATABUFFERSIZE);
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[1], DATABUFFERSIZE);
            AT91C_BASE_US0->US_IER = AT91C_US_ENDRX
                                     | AT91C_US_FRAME
                                     | AT91C_US_OVER;
            AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

            // Start receiving data on the USB
            CDCDSerialDriver_Read(0, usbSerialBuffer0,
                                  DATABUFFERSIZE,
                                  (TransferCallback) UsbDataReceived0,
                                  0);
        }
        else {

            HIDDKeyboardProcessKeys();
        }
        if( USBState == STATE_SUSPEND ) {
            TRACE_DEBUG("suspend  !\n\r");
            LowPowerMode();
            USBState = STATE_IDLE;
        }
        if( USBState == STATE_RESUME ) {
            // Return in normal MODE
            TRACE_DEBUG("resume !\n\r");
            NormalPowerMode();
            USBState = STATE_IDLE;
        }
    }
}
Пример #15
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();
	}
}
Пример #16
0
/**
 *  \brief Configure LEDs
 *
 *  Configures LEDs \#1 and \#2 (cleared by default).
 */
void ConfigureLeds(void)
{
    LED_Configure(0);
    LED_Configure(1);
}
Пример #17
0
void vParTestInitialise( void )
{
    LED_Configure( 0 );
    LED_Configure( 1 );
}
Пример #18
0
Файл: main.c Проект: gstroe/Arm
/**
 *  \brief Application entry point for MPU example.
 *
 *  \return Unused (ANSI-C compatibility).
 */
extern int main( void )
{
	uint8_t ucChoice = 0;

	/* Disable watchdog */
	WDT_Disable(WDT);

	uint32_t *pdw = (uint32_t *)MPU_SRAM_PRIVILEGE_START_ADDRESS;

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

	LED_Configure(LED_YELLOW0);

	/* Set up the default memory regions */
	_SetupMPU();

	/* Set the environment to thread mode */
	__set_CONTROL(USER_MODE);

	while (ucChoice != '9') {
		printf("----------------------------------------\n\r");
		printf("    Choose an option below:\n\r");
		printf("    1. Protect the Yellow LED region\n\r");
		printf("    2. UN-protect the Yellow LED region\n\r");
		printf("    3. Toggle the green LED\n\r");
		printf("    4. Set the RAM region to read only \n\r");
		printf("    5. Set the RAM region to read/write\n\r");
		printf("    6. Read the RAM content at offset 0\n\r");
		printf("    7. Write the RAM context at offset 0\n\r");
		printf("    8. Quit the external program\n\r");
		printf("\n\r");
		printf("  Choice: ");

		ucChoice = DBG_GetChar();
		DBG_PutChar(ucChoice);
		printf("\n\r");

		switch (ucChoice) {
		case '1':
			_UpdateMPU(MPU_PIOC_REGION_REGION,
					MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PIOC_REGION_REGION,
					MPU_AP_UNPRIVILEGED_READONLY |
					MPU_REGION_EXECUTE_NEVER |
					MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS - MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) |
						MPU_REGION_ENABLE);
			break;

		case '2':
			_UpdateMPU(MPU_PIOC_REGION_REGION,
					MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PIOC_REGION_REGION,
					MPU_AP_FULL_ACCESS |
					MPU_REGION_EXECUTE_NEVER |
					MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS -
						MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) |
					MPU_REGION_ENABLE);
			break;

		case '3':
		/* Set back to unprivileged mode*/

			LED_Toggle(LED_YELLOW0);
			__set_CONTROL(USER_MODE);
			break;

		case '4':
			_UpdateMPU(MPU_PRIVILEGE_RAM_REGION,
					MPU_SRAM_PRIVILEGE_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PRIVILEGE_RAM_REGION,
					MPU_AP_UNPRIVILEGED_READONLY |
					MPU_REGION_CACHEABLE |
					MPU_REGION_BUFFERABLE |
					MPU_TEX_B001|
					MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS -
					MPU_SRAM_PRIVILEGE_START_ADDRESS) |
					MPU_REGION_ENABLE);
			break;

		case '5':
			_UpdateMPU(MPU_PRIVILEGE_RAM_REGION,
					MPU_SRAM_PRIVILEGE_START_ADDRESS |
					MPU_REGION_VALID |
					MPU_PRIVILEGE_RAM_REGION,
					MPU_AP_FULL_ACCESS |
					MPU_REGION_CACHEABLE |
					MPU_REGION_BUFFERABLE |
					MPU_TEX_B001|
					MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS -
					MPU_SRAM_PRIVILEGE_START_ADDRESS) |
					MPU_REGION_ENABLE);

			break;

		case '6':
			printf("-I- RAM address has content %x \n\r",(unsigned)(pdw[0]));
			break;

		case '7':
			printf("-I- Write offset 0 of RAM region with content 0x55AA55AA\n\r");
			pdw[0] = 0x55AA55AA;
			break;

		case '8':
			printf("-I- MPU TEST FINISH ...\n\r");
			break;

		default:
			printf("-I- This option is not valid\n\r");
			break;
		}
	}
	/* Setback to privilege mode, before entering the main routine,
	   it is supervisor mode*/
	__ASM volatile(" svc 0x00 ");
	while (!dwRaisePriDone);
	dwRaisePriDone = 0;

	__set_CONTROL(PRIVILEGE_MODE);

	return 0;
}