コード例 #1
0
ファイル: IntQueueTimer.c プロジェクト: AlexShiLucky/freertos
void vInitialiseTimerForIntQueueTest( void )
{
const uint32_t ulDivider = 128UL, ulTCCLKS = 3UL;

	/* Enable the TC clocks. */
	PMC->PMC_PCER0 = 1 << ID_TC0;
	PMC->PMC_PCER0 = 1 << ID_TC1;

	/* Configure TC0 channel 0 for a tmrTIMER_0_FREQUENCY frequency and trigger
	on RC compare. */
	TC_Configure( TC0, tmrTC0_CHANNEL_0, ulTCCLKS | TC_CMR_CPCTRG );
	TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_RC = BOARD_MCK / ( tmrTIMER_0_FREQUENCY * ulDivider );
	TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_IER = TC_IER_CPCS;

	/* Configure TC0 channel 1 for a tmrTIMER_1_FREQUENCY frequency and trigger
	on RC compare. */
	TC_Configure( TC0, tmrTC0_CHANNEL_1, ulTCCLKS | TC_CMR_CPCTRG );
	TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_RC = BOARD_MCK / ( tmrTIMER_1_FREQUENCY * ulDivider );
	TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_IER = TC_IER_CPCS;

	/* Configure TC1 channel 0 tmrTIMER_2_FREQUENCY frequency and trigger on
	RC compare. */
	TC_Configure( TC1, tmrTC1_CHANNEL_0, ulTCCLKS | TC_CMR_CPCTRG );
	TC1->TC_CHANNEL[ tmrTC1_CHANNEL_0 ].TC_RC = BOARD_MCK / ( tmrTIMER_2_FREQUENCY * ulDivider );
	TC1->TC_CHANNEL[ tmrTC1_CHANNEL_0 ].TC_IER = TC_IER_CPCS;

	/* Enable interrupts and start the timers. */
	IRQ_ConfigureIT( ID_TC0, tmrLOWER_PRIORITY, prvTC0_Handler );
	IRQ_ConfigureIT( ID_TC1, tmrHIGHER_PRIORITY, prvTC1_Handler );
	IRQ_EnableIT( ID_TC0 );
	IRQ_EnableIT( ID_TC1 );
	TC_Start( TC0, tmrTC0_CHANNEL_0 );
	TC_Start( TC0, tmrTC0_CHANNEL_1 );
	TC_Start( TC1, tmrTC1_CHANNEL_0 );
}
コード例 #2
0
//------------------------------------------------------------------------------
/// Invoked after the USB driver has been initialized. By default, configures
/// the UDP/UDPHS interrupt.
//------------------------------------------------------------------------------
void USBDCallbacks_Initialized(void)
{
#if defined(BOARD_USB_UDP)
    // Configure and enable the UDP interrupt
    IRQ_ConfigureIT(AT91C_ID_UDP, USB_PRIORITY, USBD_InterruptHandler);
    IRQ_EnableIT(AT91C_ID_UDP);

#elif defined(BOARD_USB_UDPHS)
    // Configure and enable the UDPHS interrupt
    IRQ_ConfigureIT(AT91C_ID_UDPHS, USB_PRIORITY, USBD_InterruptHandler);
    IRQ_EnableIT(AT91C_ID_UDPHS);
#else
    #error Unsupported controller.
#endif
}
コード例 #3
0
ファイル: usb_driver.c プロジェクト: Flyagin/BS-MRZV
void usb_init() {
  // If they are present, configure Vbus & Wake-up pins
  unsigned int priority = 0;
  #ifdef AT91C_ID_PIOD_E
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOD_E;
    AT91C_BASE_PIOD->PIO_ISR;
    AT91C_BASE_PIOD->PIO_IDR = 0xFFFFFFFF;
    AT91C_BASE_PIOE->PIO_ISR;
    AT91C_BASE_PIOE->PIO_IDR = 0xFFFFFFFF;
    IRQ_ConfigureIT(AT91C_ID_PIOD_E, priority, PIO_IT_InterruptHandler);
    IRQ_EnableIT(AT91C_ID_PIOD_E);
  #endif

  // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif
  
  // BOT driver initialization
  CDCDSerialDriver_Initialize();

  // connect if needed
  VBUS_CONFIGURE();

  // Connect pull-up, wait for configuration
  USBD_Connect();
}
コード例 #4
0
/*
 * The application must provide a function that configures a peripheral to
 * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
 * in FreeRTOSConfig.h to call the function.  This file contains a function
 * that is suitable for use on the Atmel SAMA5.
 */
void vConfigureTickInterrupt( void )
{
	/* NOTE:  The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()
	macro in FreeRTOSConfig.h. */

	/* Enable the PIT clock. */
	PMC->PMC_PCER0 = 1 << ID_PIT;

	/* Initialize the PIT to the desired frequency - specified in uS. */
	PIT_Init( 1000000UL / configTICK_RATE_HZ, BOARD_MCK / 1000000 );

	/* Configure interrupt on PIT.  Note this is on the system interrupt, which
	is shared with other system peripherals, so System_Handler() must be
	installed in place of FreeRTOS_Tick_Handler() if other system handlers are
	required.  The tick must be given the lowest priority (0 in the SAMA5 AIC) */
	IRQ_ConfigureIT( ID_PIT, AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE, FreeRTOS_Tick_Handler );
	/* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */
	IRQ_EnableIT( ID_PIT );
	PIT_EnableIT();

	/* Enable the pit. */
	PIT_Enable();

	/* Prevent compiler warnings in the case where System_Handler() is not used
	as the handler.  See the comments above the System_Handler() function
	prototype at the top of this file. */
	( void ) System_Handler;
}
コード例 #5
0
ファイル: potentiometer.c プロジェクト: morriemajor/mariokart
void pot_init(void) {

    //sets up interrupts to trigger on every sucessful conversion
    IRQ_ConfigureIT(AT91C_ID_ADC, 0, ISR_ADC);

    //initilize ADC
    ADC_Initialize(AT91C_BASE_ADC,
            AT91C_ID_ADC,
            AT91C_ADC_TRGEN_DIS,
            0,
            AT91C_ADC_SLEEP_NORMAL_MODE,
            AT91C_ADC_LOWRES_10_BIT,
            BOARD_MCK,
            BOARD_ADC_FREQ,
            10,
            1200);

    ADC_EnableDataReadyIt(AT91C_BASE_ADC);

    ADC_EnableChannel(AT91C_BASE_ADC, POT_CHANNEL);

    IRQ_EnableIT(AT91C_ID_ADC);

    ADC_EnableIt(AT91C_BASE_ADC, POT_CHANNEL);

    //Starts the adc
    ADC_StartConversion(AT91C_BASE_ADC);
}
コード例 #6
0
ファイル: dmad.c プロジェクト: craiglink/at91lib
//------------------------------------------------------------------------------
/// Initializes the DMA controller.
/// \param channel Particular channel number
/// \param defaultHandler Using the default dmad interrupt handler.
//------------------------------------------------------------------------------
void DMAD_Initialize(unsigned char channel, unsigned char defaultHandler)
{
    unsigned int status;
    unsigned int flag;
     
    // Enable peripheral clock
#if !defined(at91sam9rl64)    
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_HDMA;    
#endif    
    
    // Read the channel handler status to ensure the channel is a free channel.
    status = DMA_GetChannelStatus();
    TRACE_INFO ("DMAD_Initialize channel %x  \n\r", channel);
    SANITY_CHECK(!(status & (1 << channel)));
    // Clear any pending interrupts on the channel.
    DMA_GetStatus();
    // Disble the channel.
    DMA_DisableChannel(channel);
    // Disable the interrupt
    flag = 0xffffff;
    DMA_DisableIt(flag);
    // Enable DMA.
    DMA_Enable();
    if(defaultHandler) 
    {
        IRQ_ConfigureIT(AT91C_ID_HDMA, 0, DMAD_Handler);
        IRQ_EnableIT(AT91C_ID_HDMA);
    }
    // Initialize transfer instance.
    dmad.transfers[channel].transferSize = 0;
}
コード例 #7
0
ファイル: samadc.c プロジェクト: armsvb/4pi-firmware
void initadc(int autos)
{
   // printf("-- Basic ADC Project %s --\n\r", SOFTPACK_VERSION);
  //  printf("-- %s\n\r", BOARD_NAME);
  //  printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
  if(autos)
    autosample=1;
#ifdef PINS_ADC
    PIO_Configure(pinsADC, PIO_LISTSIZE(pinsADC));
#endif

    ADC12_Initialize( AT91C_BASE_ADC,
                    AT91C_ID_ADC,
                    AT91C_ADC_TRGEN_DIS,
                    0,
                    AT91C_ADC_SLEEP_NORMAL_MODE,
                    AT91C_ADC_LOWRES_12_BIT,
                    BOARD_MCK,
                    BOARD_ADC_FREQ,
                    10,
                    1200);
	
	//int i;

/*	for(i=0;i<7;i++)
		if ((1<<chns[i]) & enchan)
	        	    ADC12_EnableChannel(AT91C_BASE_ADC, chns[i]);
*/
	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_1);
	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_2);
	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_3);
//	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_4);
    ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_5);
//	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_6);
//	ADC12_EnableChannel(AT91C_BASE_ADC, ADC_NUM_7);
	
	IRQ_ConfigureIT(AT91C_ID_ADC, ADCC0_IRQ_PRIORITY, ADCC0_IrqHandler);
	IRQ_EnableIT(AT91C_ID_ADC);
	
	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_1);
	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_2);
	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_3);
//	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_4);
    ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_5);
//	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_6);
//	ADC12_EnableIt(AT91C_BASE_ADC, 1<<ADC_NUM_7);
	
/*
	for(i=0;i<7;i++)
		if ((1<<chns[i]) & enchan)
	        	ADC12_EnableIt(AT91C_BASE_ADC, 1<<chns[i]);
*/
	    conversionDone=0;
	    ADC12_StartConversion(AT91C_BASE_ADC);
	//printf("adc init done\n");
    
}
コード例 #8
0
ファイル: CDCCommandConsole.c プロジェクト: HclX/freertos
void USBDCallbacks_Initialized( void )
{
	/* CDC specific re-implementation of weak callback function.  Invoked after
	the USB driver has been initialised. By default, configures the UDP/UDPHS
	interrupt.  The interrupt priority is set to the highest to ensure the
	interrupt nesting tests interfer as little as possible with the USB. */
	IRQ_ConfigureIT( ID_UDPHS, 7, USBD_IrqHandler );
	IRQ_EnableIT( ID_UDPHS );
}
コード例 #9
0
//------------------------------------------------------------------------------
/// Invoked after the USB driver has been initialized. By default, configures
/// the UDP/UDPHS interrupt.
//------------------------------------------------------------------------------
void USBDCallbacks_Initialized(void)
{
#if defined(CHIP_USB_UDP)
    // Configure and enable the UDP interrupt
    IRQ_ConfigureIT(AT91C_ID_UDP, 0, USBD_IrqHandler);
    IRQ_EnableIT(AT91C_ID_UDP);

#elif defined(CHIP_USB_UDPHS)
    // Configure and enable the UDPHS interrupt
    IRQ_ConfigureIT(AT91C_ID_UDPHS, 0, USBD_IrqHandler);
    IRQ_EnableIT(AT91C_ID_UDPHS);

#elif defined(CHIP_USB_OTGHS)
    IRQ_ConfigureIT(AT91C_ID_OTGHS, 1, (void*) 0);
    IRQ_EnableIT(AT91C_ID_OTGHS);

#else
    #error Unsupported controller.
#endif
}
コード例 #10
0
ファイル: BootEeprom.c プロジェクト: Bruce511/AcmeBoot
//------------------------------------------------------------------------------
/// Initialize EEPROM device. 
//------------------------------------------------------------------------------
static void EepromInit()
{
    TRACE_INFO("Init TWI EEPROM %s\n\r", NAME_REF);

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

    // Configure TWI
    AT91C_BASE_PMC->PMC_PCER = 1 << BOARD_ID_TWI;
    TWI_ConfigureMaster(BOARD_BASE_TWI, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, BOARD_BASE_TWI);
    IRQ_ConfigureIT(BOARD_ID_TWI, 0, ISR_Twi);
    IRQ_EnableIT(BOARD_ID_TWI);

}
コード例 #11
0
ファイル: serial.c プロジェクト: RitikaGupta1207/freertos
/*
 * See the serial2.h header file.
 */
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
    xComPortHandle xReturn = serHANDLE;
    extern void ( vUART_ISR )( void );
    const Pin xUSART_Pins[] = { BOARD_PIN_USART_RXD, BOARD_PIN_USART_TXD };


    /* Create the queues used to hold Rx and Tx characters. */
    xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
    xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

    /* If the queues were created correctly then setup the serial port
    hardware. */
    if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
    {
        portENTER_CRITICAL();
        {
            /* Enable the peripheral clock in the PMC. */
            PMC_EnablePeripheral( BOARD_ID_USART );

            /* Configure the USART. */
            USART_Configure( BOARD_USART_BASE, AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT, ulWantedBaud, configCPU_CLOCK_HZ );

            /* Configure the interrupt.  Note the pre-emption priority is set
            in bits [8:15] of the priority value passed as the parameter. */
            IRQ_ConfigureIT( BOARD_ID_USART, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 8 ), vSerialISR );
            IRQ_EnableIT( BOARD_ID_USART );

            /* Enable receiver & transmitter. */
            USART_SetTransmitterEnabled( BOARD_USART_BASE, pdTRUE );
            USART_SetReceiverEnabled( BOARD_USART_BASE, pdTRUE );

            /* Configure IO for USART use. */
            PIO_Configure( xUSART_Pins, PIO_LISTSIZE( xUSART_Pins ) );
        }
        portEXIT_CRITICAL();
    }
    else
    {
        xReturn = ( xComPortHandle ) 0;
    }

    /* This demo file only supports a single port but we have to return
    something to comply with the standard demo header file. */
    return xReturn;
}
コード例 #12
0
BOOL CPU_INTC_InterruptEnable(UINT32 Irq_Index)
{
	BOOL WasEnabled;

	if (Irq_Index >= ID_PERIPH_COUNT)
		return FALSE;

	GLOBAL_LOCK(irq);

	AIC->AIC_SSR = Irq_Index;

	WasEnabled = ((AIC->AIC_IMR & AIC_IMR_INTM) != 0) ? TRUE : FALSE;

	IRQ_EnableIT(Irq_Index);

	return WasEnabled;
}
コード例 #13
0
ファイル: main.c プロジェクト: aisandovalm/tcs-tests
//------------------------------------------------------------------------------
/// Configures the PIT to generate 1ms ticks.
//------------------------------------------------------------------------------
static void ConfigurePit(void)
{
    // Initialize and enable the PIT
    PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);

    // Disable the interrupt on the interrupt controller
    IRQ_DisableIT(AT91C_ID_SYS);

    // Configure the AIC for PIT interrupts
    IRQ_ConfigureIT(AT91C_ID_SYS, 0, ISR_Pit);

    // Enable the interrupt on the interrupt controller
    IRQ_EnableIT(AT91C_ID_SYS);

    // Enable the interrupt on the pit
    PIT_EnableIT();

    // Enable the pit
    PIT_Enable();
}
コード例 #14
0
ファイル: heaters.c プロジェクト: CNCBASHER/4pi-firmware
//--------------------------------------------------
// Init Timer 1 for Soft PWM (Hotend 1 & 2)
//--------------------------------------------------
void ConfigureTc_1(void)
{

	// Enable peripheral clock
	AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC1;
	unsigned int freq=10000; 
	// Configure TC for a 10 kHz frequency and trigger on RC compare
	//TC_FindMckDivisor(freq, BOARD_MCK, &div, &tcclks);
	TC_Configure(AT91C_BASE_TC1, 3 | AT91C_TC_CPCTRG);
	AT91C_BASE_TC1->TC_RB = 3;
	AT91C_BASE_TC1->TC_RC = (BOARD_MCK / 128) / freq; // timerFreq / desiredFreq

	// Configure and enable interrupt on RC compare
	//IRQ_ConfigureIT(AT91C_ID_TC1, 2, TC1_IrqHandler);
	AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS | AT91C_TC_CPBS;
	IRQ_EnableIT(AT91C_ID_TC1);

	// Start the counter if LED is enabled.
	TC_Start(AT91C_BASE_TC1);

}
コード例 #15
0
BOOL CPU_INTC_ActivateInterrupt(UINT32 Irq_Index, HAL_CALLBACK_FPN ISR, void* ISR_Param)
{
	// figure out the interrupt
	IRQ_VECTORING* IsrVector = IRQToIRQVector(Irq_Index);

	if (!IsrVector)
		return FALSE;

	GLOBAL_LOCK(irq);

	IRQ_DisableIT(Irq_Index);

	IRQ_ClearIT(Irq_Index);

	// set the vector
	IsrVector->Handler.Initialize(ISR, ISR_Param);

	IRQ_EnableIT(Irq_Index);

	return TRUE;
}
コード例 #16
0
ファイル: MEDSdcard.c プロジェクト: Lodran/4pi-firmware
//------------------------------------------------------------------------------
/// Initializes a Media instance and the associated physical interface
/// \param  media Pointer to the Media instance to initialize
/// \return 1 if success.
//------------------------------------------------------------------------------
unsigned char MEDSdusb_Initialize(Media *media, unsigned char mciID)
{
    TRACE_INFO("MEDSdusb init\n\r");
    
    // Initialize SDcard
    //--------------------------------------------------------------------------
    
    if (!CardIsConnected(mciID)) return 0;
    
    // Configure SDcard pins
    ConfigurePIO(mciID);
    
#if defined(MCI2_INTERFACE)
    DMAD_Initialize(BOARD_MCI_DMA_CHANNEL, DMAD_NO_DEFAULT_IT);
#endif
    // Initialize the MCI driver
    if(mciID == 0) {
        IRQ_ConfigureIT(BOARD_SD_MCI_ID,  MCI0_IRQ_PRIORITY, MCI0_IrqHandler);
        MCI_Init(mciDrv, BOARD_SD_MCI_BASE, BOARD_SD_MCI_ID, BOARD_SD_SLOT, MCI_INTERRUPT_MODE);
        IRQ_EnableIT(BOARD_SD_MCI_ID);
    } else {
#ifdef BOARD_SD_MCI1_ID
        IRQ_ConfigureIT(BOARD_SD_MCI1_ID,  MCI0_IRQ_PRIORITY, MCI0_IrqHandler);
        MCI_Init(mciDrv, BOARD_SD_MCI1_BASE, BOARD_SD_MCI1_ID, BOARD_SD_SLOT, MCI_INTERRUPT_MODE);
        IRQ_EnableIT(BOARD_SD_MCI1_ID);
#else
        TRACE_ERROR("SD/MMC card initialization failed (MCI1 not supported)\n\r");
#endif
    }
#if MCI_BUSY_CHECK_FIX && defined(BOARD_SD_DAT0)
    MCI_SetBusyFix(mciDrv, &pinSdDAT0);
#endif
    
    // Initialize the SD card driver
    if (SD_Init(sdDrv, (SdDriver *)mciDrv)) {
        
        TRACE_ERROR("SD/MMC card initialization failed\n\r");
        return 0;
    }
    else {
        
        TRACE_INFO("SD/MMC card initialization successful\n\r");
        TRACE_INFO("Card size: %d MB\n\r", (int)(MMC_GetTotalSizeKB(sdDrv)/1024));
    }
    MCI_SetSpeed(mciDrv, sdDrv->transSpeed, sdDrv->transSpeed, BOARD_MCK);
    
    // Initialize media fields
    //--------------------------------------------------------------------------
    media->interface = sdDrv;
    media->write = MEDSdusb_Write;
    media->read = MEDSdusb_Read;
    media->lock = 0;
    media->unlock = 0;
    media->handler = 0;
    media->flush = 0;
    
    media->blockSize = SD_BLOCK_SIZE;
    media->baseAddress = 0;
    media->size = SD_TOTAL_BLOCK(sdDrv);
    
    media->mappedRD  = 0;
    media->mappedWR  = 0;
    media->writeProtected = CardIsProtected(mciID);
    media->removable = 1;
    
    media->state = MED_STATE_READY;
    
    media->transfer.data = 0;
    media->transfer.address = 0;
    media->transfer.length = 0;
    media->transfer.callback = 0;
    media->transfer.argument = 0;
    
    return 1;
}