Beispiel #1
0
/*********************************************************************//**
 * @brief 		Initial for ADC
 * 					+ Set bit PCADC
 * 					+ Set clock for ADC
 * 					+ Set Clock Frequency
 * @param[in]	ADCx pointer to LPC_ADCn_Type, should be: LPC_ADC
 * @param[in]	rate ADC conversion rate, should be <=200KHz
 * @param[in]	bits_accuracy number of bits accuracy, should be <=10 bits and >=3bits
 * @return 		None
 **********************************************************************/
void ADC_Init(LPC_ADCn_Type *ADCx, uint32_t rate, uint8_t bits_accuracy)
{
	uint32_t temp, tmpreg, ADCbitrate;

	CHECK_PARAM(PARAM_ADCx(ADCx));
	CHECK_PARAM(PARAM_ADC_RATE(rate));

	// Turn on power and clock
	//CGU_ConfigPPWR (CGU_PCONP_PCAD, ENABLE);

	ADCx->CR = 0;

	//Enable PDN bit
	tmpreg = ADC_CR_PDN;
	// Set clock frequency
	if(ADCx == LPC_ADC0)
		temp = CGU_GetPCLKFrequency(CGU_PERIPHERAL_ADC0);
	else if(ADCx == LPC_ADC1)
		temp = CGU_GetPCLKFrequency(CGU_PERIPHERAL_ADC1);
	/* The APB clock (PCLK_ADC0) is divided by (CLKDIV+1) to produce the clock for
	 * A/D converter, which should be less than or equal to 13MHz.
	 * A fully conversion requires (bits_accuracy+1) of these clocks.
	 * ADC clock = PCLK_ADC0 / (CLKDIV + 1);
	 * ADC rate = ADC clock / (bits_accuracy+1);
	 */
	 ADCbitrate = (rate * (bits_accuracy+1));
	temp = ((temp*2 + ADCbitrate) / (ADCbitrate*2)) - 1;//get the round value by fomular: (2*A + B)/(2*B)
	tmpreg |=  ADC_CR_CLKDIV(temp) | ADC_CR_BITACC(10 - bits_accuracy);

	ADCx->CR = tmpreg;
}
Beispiel #2
0
/********************************************************************//**
 * @brief		Initializes the SSPx peripheral according to the specified
 *              parameters in the SSP_ConfigStruct.
 * @param[in]	SSPx SSP peripheral selected, should be:
 * 				 	- LPC_SSP0	:SSP0 peripheral
 * 					- LPC_SSP1	:SSP1 peripheral
 * @param[in]	SSP_ConfigStruct Pointer to a SSP_CFG_Type structure that
 * 				contains the configuration information for the specified
 * 				SSP peripheral.
 * @return 		None
 *********************************************************************/
void SSP_Init(LPC_SSPn_Type *SSPx, SSP_CFG_Type *SSP_ConfigStruct)
{
	uint32_t tmp;
	uint32_t prescale, cr0_div, cmp_clk;
	uint64_t ssp_clk;

	CHECK_PARAM(PARAM_SSPx(SSPx));

	if(SSPx == LPC_SSP0) {
		/* Set up clock and power for SSP0 module */
		//LPC_CGU->BASE_SSP0_CLK = (SRC_PL160M_0<<24) | (1<<11);
		CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SSP0);
	} else if(SSPx == LPC_SSP1) {
		/* Set up clock and power for SSP1 module */
		//LPC_CGU->BASE_SSP1_CLK = (SRC_PL160M_0<<24) | (1<<11);
		CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SSP1);
	} else {
		return;
	}

	/* Configure SSP, interrupt is disable, LoopBack mode is disable,
	 * SSP is disable, Slave output is disable as default
	 */
	tmp = ((SSP_ConfigStruct->CPHA) | (SSP_ConfigStruct->CPOL) \
		| (SSP_ConfigStruct->FrameFormat) | (SSP_ConfigStruct->Databit))
		& SSP_CR0_BITMASK;
	// write back to SSP control register
	SSPx->CR0 = tmp;

	tmp = SSP_ConfigStruct->Mode & SSP_CR1_BITMASK;
	// Write back to CR1
	SSPx->CR1 = tmp;

	// Set clock rate for SSP peripheral
	if(SSPx == LPC_SSP0)
		ssp_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SSP0);
	else
		ssp_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SSP1);
	cr0_div = 0;
	cmp_clk = 0xFFFFFFFF;
	prescale = 2;
	while (cmp_clk > SSP_ConfigStruct->ClockRate)
	{
		cmp_clk = ssp_clk / ((cr0_div + 1) * prescale);
		if (cmp_clk > SSP_ConfigStruct->ClockRate)
		{
			cr0_div++;
			if (cr0_div > 0xFF)
			{
				cr0_div = 0;
				prescale += 2;
			}
		}
	}

    /* Write computed prescaler and divider back to register */
    SSPx->CR0 &= (~SSP_CR0_SCR(0xFF)) & SSP_CR0_BITMASK;
    SSPx->CR0 |= (SSP_CR0_SCR(cr0_div)) & SSP_CR0_BITMASK;
    SSPx->CPSR = prescale & SSP_CPSR_BITMASK;
}
Beispiel #3
0
void board_init(void)
{
  SystemInit();
  CGU_Init();
	SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/CFG_TICKS_PER_SECOND );	/* 1 ms Timer */

	//------------- USB Bus power HOST ONLY-------------//
	scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4);	// P1_7 USB0_PWR_EN, USB0 VBus function Xplorer

	scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4); // P2_6 is configured as GPIO5[6] for USB1_PWR_EN
	GPIO_SetDir   (5, BIT_(6), 1);              // GPIO5[6] is output
	GPIO_SetValue (5, BIT_(6));                 // GPIO5[6] output high

	// Leds Init
	for (uint8_t i=0; i<BOARD_MAX_LEDS; i++)
	{
	  scu_pinmux(leds[i].port, leds[i].pin, MD_PUP|MD_EZI|MD_ZI, FUNC0);
	  GPIO_SetDir(leds[i].port, BIT_(leds[i].pin), 1); // output
	}

#if CFG_UART_ENABLE
	//------------- UART init -------------//
	UART_CFG_Type UARTConfigStruct;

	scu_pinmux(0x6 ,4, MD_PDN|MD_EZI, FUNC2); 	// UART0_TXD
	scu_pinmux(0x6 ,5, MD_PDN|MD_EZI, FUNC2); 	// UART0_RXD

	UART_ConfigStructInit(&UARTConfigStruct);                   // default: baud = 9600, 8 bit data, 1 stop bit, no parity
	UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;             // Re-configure baudrate

	UART_Init((LPC_USARTn_Type*) LPC_USART0, &UARTConfigStruct); // Initialize UART port
	UART_TxCmd((LPC_USARTn_Type*) LPC_USART0, ENABLE);           // Enable UART
#endif

}
Beispiel #4
0
int main(void) {
    setup_systemclock();

    //TODO:TimerInitに切り出し
	// Setup SysTick Timer to interrupt at 10 msec intervals
	SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/100);

	GPIO_SetDir(0,1<<8, 1);	// GPIO0[8](LED)を出力に設定
	GPIO_ClearValue(0,1<<8);// GPIO0[8](LED)出力L

////////////////////wave_gen///////////////////////////////
	gen_dac_cfg_t cfg;
    cfg.amplitude=5000;
    cfg.dcOffset=0;
    cfg.frequency=150;
    cfg.waveform=GEN_DAC_CFG_WAVE_TRIANGLE;
    wave_gen(&cfg, &buf);

////////////////////fft///////////////////////////////
    fft_gen();

////////////////spi///////////////////////////////////
	lcd_init();
	lcd_clear();
////////////////lcd///////////////////////////////////
//		uint16_t lcd_x;
//		uint16_t lcd_y;
//		uint8_t scale_time = 2;//横軸データ数を2倍表示
//		uint8_t scale_fft = 2;//横軸データ数を2倍表示

//////////////////////////////////////////////////////
//	uint16_t i;
//	int j;

	ADC_DMA_Init();
    NVIC_SetPriority(DMA_IRQn,   ((0x01<<3)|0x01));

    // Enter an infinite loop
    while(1) {
//wav_genタイムドメイン表示
//    	for (i = 0; i < 240; i++) {
//    		for (j = 0; j < 25; j++) {
//    			lcd_data[i][j]=0x0000;
//    		}
//    	}
//    	for (i = 0; i < 400*scale_time; i++ ){
//    	    lcd_x = ((int16_t)(i/scale_time) -200) * -1 + 200;//左右逆転(LCD都合
//    		lcd_y = (buf.LUT_BUFFER[i]-2048)/17 + 120;//0~240に正規化
//    		lcd_data[lcd_y][lcd_x/16] = lcd_data[lcd_y][lcd_x/16] | 0x01<<(lcd_x%16);
//    	}
//    	lcd_write(lcd_data);
    	systick_delay(50);
    }
	ADC_DMA_Exit();
    return 0 ;
}
//====================================================================================
void main()
{
	volatile uint32_t i;
	uint32_t timer_mark;
	//while(1);
	
	SystemInit();
	CGU_Init();

	scu_pinmux(0xE ,7 , MD_PDN, FUNC4); 	// P8.1 : USB0_IND1 LED

	GPIO_SetDir(LED1_PORT,(1<<LED1_BIT), 1);

	GPIO_ClearValue(LED1_PORT,(1<<LED1_BIT));

	// M3Frequency is automatically set when SetClock(BASE_M3_CLK... was called.
	SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/1000);  				// Generate interrupt @ 1000 Hz
	
	/*for(;;)
	{
		GPIO_ClearValue(LED1_PORT,(1<<LED1_BIT));
		for(i = 0; i < 200000; i++);
		GPIO_SetValue(LED1_PORT,(1<<LED1_BIT));
		for(i = 0; i < 200000; i++);
	}

	while (1)
	{                           					// Loop forever
		timer_mark = msTicks;					// Take timer snapshot 
		while(msTicks < (timer_mark + 100));	// Wait until 100ms has passed
		GPIO_ClearValue(LED1_PORT,(1<<LED1_BIT));				// Turn the LED off
	
		timer_mark = msTicks;					// Take timer snapshot 
		while(msTicks < (timer_mark + 100));	// Wait until 100ms has passed
		GPIO_SetValue(LED1_PORT,(1<<LED1_BIT));				// Turn the LED on
	}*/

	
	
	// Init on-board LED as output
	//GPIO1->FIODIR |= 1 << 18;
	
	// Init SysTick
	//SysTick_Config(SystemFrequency / 1000);		// Generate interrupt every 1 ms
	
	while (1)
	{                           					// Loop forever
		msec = 100;
		while(msec);
		GPIO_ClearValue(LED1_PORT,(1<<LED1_BIT));
		msec = 100;
		while(msec);
		GPIO_SetValue(LED1_PORT,(1<<LED1_BIT));

	}
}
static uint32_t getPClock (uint32_t timernum)
{
	uint32_t clkdlycnt;
	switch (timernum)
	{
	case 0:
		clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER0)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER0);
		break;

	case 1:
		clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER1)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER1);
		break;

	case 2:
		clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER2)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER2);
		break;

	case 3:
		clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER3)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER3);
		break;
	}
	return clkdlycnt;
}
Beispiel #7
0
void bsp_init(void)
{
    uint32_t Core_Clock;
    /* Set up core clock */
    CGU_Init();

    /*Init Timer*/
    Core_Clock = CGU_GetPCLKFrequency(CORE_CLOCK_ID);
    SysTick_Config(Core_Clock/100);	/* 10ms Timer */

    /* Initialize the external memory controller */
    vEMC_InitSRDRAM(SDRAM_BASE_ADDR, SDRAM_WIDTH, SDRAM_SIZE_MBITS, SDRAM_DATA_BUS_BITS, SDRAM_COL_ADDR_BITS);

    scu_pinmux(0x9, 5, MD_PUP | MD_EZI, FUNC2);				// P9_5 USB1_PWR_EN, USB1 VBus function
    scu_pinmux(0x2, 5, MD_PLN | MD_EZI | MD_ZI, FUNC2);		// P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION

    scu_pinmux(0x6, 3, MD_PUP | MD_EZI, FUNC1);     		// P6_3 USB0_PWR_EN, USB0 VBus function
}
Beispiel #8
0
/********************************************************************//**
 * @brief		Initializes the I2Cx peripheral with specified parameter.
 * @param[in]	I2Cx	I2C peripheral selected, should be
 * 					- LPC_I2C0	:I2C0 peripheral
 * 					- LPC_I2C1	:I2C1 peripheral
 * @param[in]	clockrate Target clock rate value to initialized I2C
 * 				peripheral (Hz)
 * @return 		None
 *********************************************************************/
void I2C_Init(LPC_I2Cn_Type *I2Cx, uint32_t clockrate)
{
	uint32_t tem;

	CHECK_PARAM(PARAM_I2Cx(I2Cx));

	if (I2Cx==LPC_I2C0)
	{
		/* Set up clock for I2C0 module */
		//LPC_CGU->BASE_VPB1_CLK = (SRC_PL160M_0<<24) | (1<<11);
		CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_APB1);
		/* Select weather standard, fast, fast plus mode*/
		if(clockrate>=1000000)// Fast mode plus: 1MHz, high speed 3.4MHz
			LPC_SCU->SFSI2C0 = SFSI2C0_CONFIGURE_FASTPLUS_HIGHSPEED_MODE;
		else				  // standard 100KHz, fast 400KHz
			LPC_SCU->SFSI2C0 = SFSI2C0_CONFIGURE_STANDARD_FAST_MODE;
	}
	else if (I2Cx==LPC_I2C1)
	{
		/* Set up clock for I2C1 module */
		//LPC_CGU->BASE_VPB3_CLK = (SRC_PL160M_0<<24) | (1<<11);
		CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_APB3);
		/* Configure pin function for I2C1*/
		LPC_SCU->SFSP2_3 = SFSP2_3_CONFIGURE_I2C1_SDA;			/* SDA */
		LPC_SCU->SFSP2_4 = SFSP2_4_CONFIGURE_I2C1_SCL;			/* SCL */
		/* Check if I2C1 run fast mode*/
  		if(clockrate != 400000)
  			return;
	}
	else {
		// Up-Support this device
		return;
	}

    /* Set clock rate */
	if(clockrate<1000)	//make sure SCLH,SCLL not exceed its 16bit value
		return;
	tem = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE) / clockrate;
	I2Cx->SCLH = (uint32_t)(tem / 2);
	I2Cx->SCLL = (uint32_t)(tem - I2Cx->SCLH);
    /* Set I2C operation to default */
    I2Cx->CONCLR = (I2C_I2CONCLR_AAC |I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_I2ENC);
}
/*********************************************************************//**
 * @brief		Calculates the actual velocity in RPM passed via velocity
 * 				capture value and Pulse Per Round (of the encoder) value
 * 				parameter input.
 * @param[in]	qeiId The Id of the expected QEI component, should be: 0
 * @param[in]	ulVelCapValue	Velocity capture input value that can be
 * 				got from QEI_GetVelocityCap() function
 * @param[in]	ulPPR	Pulse per round of encoder
 * @return		The actual value of velocity in RPM (Round per minute)
 **********************************************************************/
uint32_t QEI_CalculateRPM(uint8_t qeiId, uint32_t ulVelCapValue, uint32_t ulPPR)
{
	LPC_QEI_Type* pQei = QEI_GetPointer(qeiId);

	uint64_t rpm, clock, Load, edges;

	// Get current Clock rate for timer input
	clock = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE);

	// Get Timer load value (velocity capture period)
	Load  = (uint64_t)(pQei->LOAD + 1);

	// Get Edge
	edges = (uint64_t)((pQei->CONF & QEI_CONF_CAPMODE) ? 4 : 2);

	// Calculate RPM
	rpm = ((clock * ulVelCapValue * 60) / (Load * ulPPR * edges));

	return (uint32_t)(rpm);
}
Beispiel #10
0
int main(void)
{
    SystemInit();
    CGU_Init();

    // Configure external flash
    MemoryPinInit();
    EMCSRDRAMInit();
    EMCFlashInit();

    // Init SysTick to 1ms
    SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / 1000);

    // Copy image to SDRAM
    memcpy((void *)SDRAM_BASE_ADDR, (void *)IMAGE_FLASH_ADDR, 2UL*1024*768);

    // Initialize TFP410
    TFP410_Init((void *)SDRAM_BASE_ADDR);

    while (1)
    {
    }
}
/*********************************************************************//**
 * @brief		Set timer reload value for QEI peripheral. When the velocity timer is
 * 				over-flow, the value that set for Timer Reload register will be loaded
 * 				into the velocity timer for next period. The calculated velocity in RPM
 * 				therefore will be affect by this value.
 * @param[in]	qeiId The Id of the expected QEI component, should be: 0
 * @param[in]	QEIReloadStruct	QEI reload structure
 * @return		None
 **********************************************************************/
void QEI_SetTimerReload(uint8_t qeiId, QEI_RELOADCFG_Type *QEIReloadStruct)
{
	LPC_QEI_Type* pQei = QEI_GetPointer(qeiId);
	uint64_t pclk;

	if (QEIReloadStruct->ReloadOption == QEI_TIMERRELOAD_TICKVAL)
	{
		pQei->LOAD = QEIReloadStruct->ReloadValue - 1;
	}
	else
	{
#if 1
		pclk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE);

		pclk = (pclk /(1000000/QEIReloadStruct->ReloadValue)) - 1;

		pQei->LOAD = (uint32_t)pclk;
#else
		ld = M3Frequency;

		if (ld/1000000 > 0)
		{
		 	ld /= 1000000;
			ld *= QEIReloadStruct->ReloadValue;
			ld -= 1;
		}
		else
		{
			ld *= QEIReloadStruct->ReloadValue;
			ld /= 1000000;
			ld -= 1;
		}

		pQei->LOAD = ld;
#endif
	}
}
Beispiel #12
0
int main(void)
{
    uint8_t i;

    SystemInit();
    CGU_Init();

    // Configure buttons
    scu_pinmux(S1_SCU_PORT, S1_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
    scu_pinmux(S2_SCU_PORT, S2_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
    scu_pinmux(S3_SCU_PORT, S3_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
    scu_pinmux(S4_SCU_PORT, S4_SCU_PIN, MD_BUK | MD_EZI, FUNC4);
    for (i = 0; i < 4; i++)
    {
        GPIO_SetDir(buttons[i].port, buttons[i].mask, 0);   // input
    }

    // Configure LED D2
    scu_pinmux(D2_SCU_PORT, D2_SCU_PIN, MD_BUK, FUNC0);
    GPIO_SetDir(D2_GPIO_PORT, D2_GPIO_MASK, 1);             // output
    GPIO_ClearValue(D2_GPIO_PORT, D2_GPIO_MASK);            // low

    // Start M0
    m0started = 0;
    InitM0aProcessor();
    NVIC_ClearPendingIRQ(M0CORE_IRQn);
    NVIC_EnableIRQ(M0CORE_IRQn);
    StartM0aProcessor();
    while (!m0started);

    // Init SysTick to 1ms
    SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / 1000);

    while (1)
    {
    }
}
Beispiel #13
0
void bsp_init(void)
{
	uint32_t Core_Clock;
	/* Set up core clock */
	CGU_Init();

	/*Init Timer*/
	Core_Clock = CGU_GetPCLKFrequency(CORE_CLOCK_ID);
	SysTick_Config(Core_Clock/100);	/* 10ms Timer */

	/* Initialize the external memory controller */
	vEMC_InitSRDRAM(SDRAM_BASE_ADDR, SDRAM_WIDTH, SDRAM_SIZE_MBITS, SDRAM_DATA_BUS_BITS, SDRAM_COL_ADDR_BITS);

	/* Turn on 5V USB VBUS TODO Should be Host-only */
	scu_pinmux(0x2, 6, MD_PUP | MD_EZI, FUNC4);				// P2_6 USB1_PWR_EN, USB1 VBus function
	scu_pinmux(0x2, 5, MD_PLN | MD_EZI | MD_ZI, FUNC2);		// P2_5 USB1_VBUS, MUST CONFIGURE THIS SIGNAL FOR USB1 NORMAL OPERATION

	/* Turn on 5V USB VBUS TODO Should be Host-only */
#if (BOARD == BOARD_XPLORER)
	scu_pinmux(0x1, 7, MD_PUP | MD_EZI, FUNC4);				// P1_7 USB0_PWR_EN, USB0 VBus function Xplorer
#else
	scu_pinmux(0x2, 3, MD_PUP | MD_EZI, FUNC7);     		// P2_3 USB0_PWR_EN, USB0 VBus function Farnell
#endif
}
Beispiel #14
0
void clockInit(void)
{
	//uint32_t EMCClk;

	__disable_irq();
 	/* Set the XTAL oscillator frequency to 12MHz*/
	CGU_SetXTALOSC(__CRYSTAL);
	CGU_EnableEntity(CGU_CLKSRC_XTAL_OSC, ENABLE);
	CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_BASE_M3);
	
	/* Set PL160M 12*1 = 12 MHz */
	CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_CLKSRC_PLL1);
//	CGU_EntityConnect(CGU_CLKSRC_IRC, CGU_CLKSRC_PLL1);
	CGU_SetPLL1(1);
	CGU_EnableEntity(CGU_CLKSRC_PLL1, ENABLE);

	// setup CLKOUT
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_CLKSRC_IDIVB);
	CGU_EnableEntity(CGU_CLKSRC_IDIVB, ENABLE);
	CGU_SetDIV(CGU_CLKSRC_IDIVB, 12);  // 12 -> 6 pclks per cpu clk, 10 -> 5 pclks
	// set input for CLKOUT to IDIVB
	LPC_CGU->BASE_OUT_CLK &= ~0x0f000000;
	LPC_CGU->BASE_OUT_CLK |= 0x0d000000;

	/* Run SPIFI from PL160M, /2 */
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_CLKSRC_IDIVA);
	CGU_EnableEntity(CGU_CLKSRC_IDIVA, ENABLE);
	CGU_SetDIV(CGU_CLKSRC_IDIVA, 2);
	CGU_EntityConnect(CGU_CLKSRC_IDIVA, CGU_BASE_SPIFI);
	CGU_UpdateClock();

	LPC_CCU1->CLK_M4_EMCDIV_CFG |=    (1<<0) |  (1<<5);		// Turn on clock / 2
	LPC_CREG->CREG6 |= (1<<16);	// EMC divided by 2
    LPC_CCU1->CLK_M4_EMC_CFG |= (1<<0);		// Turn on clock

	/* Set PL160M @ 12*9=108 MHz */
	CGU_SetPLL1(9);

	/* Run base M3 clock from PL160M, no division */
	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_M3);

	waitMS(10);

	/* Change the clock to 204 MHz */
	/* Set PL160M @ 12*15=180 MHz */
	CGU_SetPLL1(17);

	waitMS(10);

	CGU_UpdateClock();

	//EMCFlashInit();

	//vEMC_InitSRDRAM(SDRAM_BASE_ADDR, SDRAM_WIDTH, SDRAM_SIZE_MBITS, SDRAM_DATA_BUS_BITS, SDRAM_COL_ADDR_BITS);
	LPC_SCU->SFSP3_3 = 0xF3; /* high drive for SCLK */
	/* IO pins */
	LPC_SCU->SFSP3_4=LPC_SCU->SFSP3_5=LPC_SCU->SFSP3_6=LPC_SCU->SFSP3_7 = 0xD3;
	LPC_SCU->SFSP3_8 = 0x13; /* CS doesn't need feedback */

#if 0
	EMCClk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE)/2;
	if (spifi_init(&sobj, 9, S_RCVCLK | S_FULLCLK, EMCClk)) {
		if (spifi_init(&sobj, 9, S_RCVCLK | S_FULLCLK, EMCClk)) {
			while(1);
		}
	}
#endif
	__enable_irq();
//	SPIFI_Init();
}
Beispiel #15
0
/*********************************************************************//**
 * @brief		Main SDIO program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
void Sdio_init(void)
{

	uint32_t dms, sdio_clk;
	int32_t loops, blk;
	uint8_t buf[50];
	errorc = 1;

	/* Configure the IO's for the LEDs */
		/* Setup muxing for SD interface */
		/*Xplorer*/
	scu_pinmux(0x1 ,11 , SDFASTINOUTPIN, FUNC7);      /* P1.11 SDIO D2 */
	scu_pinmux(0x1 ,10 , SDFASTINOUTPIN, FUNC7);      /* P1.10 SDIO D1 */
	scu_pinmux(0x1 ,9 , SDFASTINOUTPIN, FUNC7);      /* P1.9 SDIO D0 */
	scu_pinmux(0x1 ,6, SDFASTINOUTPIN, FUNC7);      /* P1.6 SDIO command */
	scu_pinmux(0x1 ,12 , SDFASTINOUTPIN, FUNC7);      /* P1.12 SDIO D3 */

	LPC_SCU->SFSCLK_2 = 0x04;						/*	CLK2 Enable*/


	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SDIO);

	/* Generate interrupt @ 100 Hz */

	/* The SDIO driver needs to know the SDIO clock rate */
	sdio_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SDIO);

	/* This init sdio with sdio_clk */
	sdif_init(sdio_clk, sdmmc_irq);

	/* Wait for a card to be inserted (note CD is not on the
	   SDMMC power rail and can be polled without enabling
	   SD slot power */

	/* Allow some time for the power supply to settle and the
	   card to fully seat in the slot */
	dms = u32Milliseconds + 250;
	while (dms > u32Milliseconds);

	/* Enumerate the card once detected. Note this function may
	   block for a little while. */
	if (!sdmmc_acquire(sdmmc_setup_wakeup, sdmmc_irq_driven_wait,
		sdmmc_waitms, &sdcardinfo)) {
		errorc = -1;
		goto error_exit;
	}
	lpc_printf("SD card detected and initialized..!\r\n");
	/* Setup card specific callbacks - use driver functions, but these can
	   be changed to custom functions or unique functions per slot. These
	   aren't used in the drivers, so setup of these is optional, but they
	   are setup here to be complete. */
	sdcardinfo.sdck_det = sdif_card_ndetect;
	sdcardinfo.sdck_wp = sdif_card_wp_on;
	sdcardinfo.sd_setpow = sdif_power_onoff;
	sdcardinfo.sd_setrst = sdif_reset;
	memset(lbuff, 0, sizeof(lbuff));
	if (sdmmc_read_blocks((void *) lbuff, 0, 0) == 0) {
		errorc = -2;
		goto error_exit;
	}
#ifdef ENABLE_WRITE_MODE
	lpc_printf("Writing data to sector 1 of SD card and verifying:\r\n");
	/* Write a single sector of data (512 bytes) */
	if (!sdcardinfo.sdck_wp()) {
		prep_data(0, 1);
		/* Warning: This may corrupt SD card data! */
		if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) {
			errorc = -3;
			goto error_exit;
		}
		/* Wait for write to finish (at the card) */
		wait_for_program_finish();
	}
#endif
	memset(lbuff, 0, sizeof(lbuff));
	/* Read a single sector of data (512 bytes) */
	if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) {
		errorc = -4;
		goto error_exit;
	}
#ifdef ENABLE_WRITE_MODE
	/* Verify data and halt if an error occurs */
	if (!sdcardinfo.sdck_wp()) {
		if (verify_data(1, 0, 1) == 0) {
			errorc = -5;
			goto error_exit;
		}
		lpc_printf("Verified!\r\n");
	}
#endif

#ifdef USE_MULTPLE_TRANSFER
#ifdef ENABLE_WRITE_MODE
 	lpc_printf("Writing data in Multitransfer mode and verifying:\r\n");
	/* Write data using multiple sector write */
	if (!sdcardinfo.sdck_wp()) {
		prep_data(0x10, 3);
		/* Warning: This may corrupt SD card data! */
		if (sdmmc_write_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) {
			errorc = -6;
			goto error_exit;
		}
		wait_for_program_finish();
	}
#endif
	memset(lbuff, 0, sizeof(lbuff));
	/* Read data using multiple sector read */
	if (sdmmc_read_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) {
		errorc = -7;
		goto error_exit;
	}

#ifdef ENABLE_WRITE_MODE
	/* Verify data and halt if an error occurs */
	if (!sdcardinfo.sdck_wp()) {
		if (verify_data(MULT_XFER_MAX_SECTORS, 0x10, 3) == 0) {
			errorc = -8;
			goto error_exit;
		}
		lpc_printf("Verified!\r\n");
	}
#endif
   	lpc_printf("measure continuous read speed...\r\n");
	tstartr = u32Milliseconds;
	loops = 1000;
	blk = 64;
	while (loops-- > 0) {
		if (sdmmc_read_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) {
			errorc = -8;
			goto error_exit;
		}

		blk += MULT_XFER_MAX_SECTORS;
	}
	tstopr = u32Milliseconds;
	memset(buf, 0, sizeof(buf));
	lpc_printf("read speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*1000/(tstopr-tstartr));

#ifdef ENABLE_WRITE_MODE
	lpc_printf("measure continuous write speed...\r\n");

	if (!sdcardinfo.sdck_wp()) {
		tstartw = u32Milliseconds;
		loops = 200;
		blk = 64;
		while (loops-- > 0) {
			if (sdmmc_write_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) {
				errorc = -9;
				goto error_exit;
			}
			blk += MULT_XFER_MAX_SECTORS;
			wait_for_program_finish();
		}
		tstopw = u32Milliseconds;
	}
	memset(buf, 0, sizeof(buf));
	lpc_printf("write speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*200/(tstopw-tstartw));
#endif
#endif
	goto exit;
	error_exit:
	lpc_printf("SD Card read/write operation not succeeded.\r\n");
	Sdio_verification = FALSE;
exit:
	return;
}
Beispiel #16
0
/**********************************************************************
 ** Function name:
 **
 ** Description:
 **
 ** Parameters:
 **
 ** Returned value:
 **********************************************************************/
void Hid_init (void)
{
  USBD_API_INIT_PARAM_T usb_param;
  USB_CORE_DESCS_T desc;
	ErrorCode_t ret;
  USB_INTERFACE_DESCRIPTOR* pIntfDesc;
 volatile uint32_t CoreM4Freq;

//	SystemInit();
//	CGU_Init();
	CoreM4Freq = CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE);
	/* Disable PLL first */
	CGU_EnableEntity(CGU_CLKSRC_PLL0, DISABLE);
	/* the usb core require output clock = 480MHz */
	if(CGU_SetPLL0() != CGU_ERROR_SUCCESS)
		while(1);
	CGU_EntityConnect(CGU_CLKSRC_PLL0, CGU_CLKSRC_PLL0);
	/* Enable PLL after all setting is done */
	CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE);
	/* Re-Update the clock freq */
	CGU_UpdateClock();
	/* Distribute to USB0 base clock */
	CGU_EntityConnect(CGU_CLKSRC_PLL0, CGU_BASE_USB0);

	/* Generate interrupt @ 1000 Hz */
//	SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M3CORE)/1000);

  /* initilize call back structures */
  memset((void*)&usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));

  usb_param.usb_reg_base = LPC_USB0_BASE;
  usb_param.max_num_ep = 6;

  usb_param.mem_base = 0x20004000;
  usb_param.mem_size = 0x2000;
  usb_param.USB_Configure_Event1 = USB_Configure_Event1;

  /* for eagle/raptor the local SRAM is not accesable to USB
  * so copy the descriptors to USB accessable memory
  */
  copy_descriptors(&desc, usb_param.mem_base + usb_param.mem_size);

	/* Turn on the phy */
	LPC_CREG->CREG0 &= ~(1<<5);

  /* USB Initialization */
  ret = USBD_API->hw->Init(&hUsb, &desc, &usb_param);
  if (ret == LPC_OK) {

    pIntfDesc = (USB_INTERFACE_DESCRIPTOR*)((uint32_t)desc.high_speed_desc + USB_CONFIGUARTION_DESC_SIZE);
    ret = usb_hid_init(hUsb, pIntfDesc, &usb_param.mem_base, &usb_param.mem_size);
    if (ret != LPC_OK)
      vCatchError(0); //"usb_hid_init error!!!"


    if (ret == LPC_OK) {
      NVIC_EnableIRQ(USB0_IRQn); //  enable USB0 interrrupts
      /* now connect */
      USBD_API->hw->Connect(hUsb, 1);
    }

  }
  else {
    vCatchError(1); //"\r\nhwUSB_Init error!!!"
  }
#if 0
	while (1)
	{
		u32Milliseconds = 100;

		/* Wait... */
		while(u32Milliseconds);

	}
#endif
}