Пример #1
0
//*****************************************************************************
//
//! \brief ADCSingleMode
//!
//! \param None  
//!
//! \return None  
//
//*****************************************************************************
void ADCSingleMode(void)
{
    UNLOCKREG();

    GCR->P5_MFP = (GCR->P5_MFP & 0x00FFFCFC) | 0x03;  /* P5.1 -> XTAL2, P5.0 -> XTAL1 */
    CLK->PWRCON_BITS.XTLCLK_EN = 1;

    /* Waiting for 12M Xtal stalble */
    while (DrvSYS_GetChipClockSourceStatus(XTL_CLK) != 1);
    /*                           ADC sample code                                       */

    /* default setting: single end input, single operation mode, all channel disable, ADC clock frequency = 12MHz/(3+1) */
    DrvADC_Open(0, EXTERNAL_CLOCK, 3);
    AdcSingleModeTest();

    DrvADC_Close();
}
Пример #2
0
void setupSystemClock()
{
#ifdef M451
	SYS_UnlockReg();
	/* Enable HIRC clock */
	CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

	/* Waiting for HIRC clock ready */
	CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

	/* Switch HCLK clock source to HIRC */
	CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

	/* Set core clock as PLL_CLOCK from PLL and SysTick source to HCLK/2*/
	CLK_SetCoreClock(SYSTEM_CLOCK);
	CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HCLK_DIV2);
	SYS_LockReg();
#else
	uint32_t u32PllCr;
	uint16_t i;
	UNLOCKREG();	
	DrvSYS_SetOscCtrl(E_SYS_OSC22M, 1);
	while (DrvSYS_GetChipClockSourceStatus(E_SYS_OSC22M) != 1);
	DrvSYS_SelectPLLSource(E_SYS_INTERNAL_22M);
	u32PllCr = DrvSYS_GetPLLContent(E_SYS_INTERNAL_22M, SYSTEM_CLOCK);	
	/*Delay for 12M or 22M stable*/
	for (i=0;i<10000;i++);		

	DrvSYS_SetPLLContent(u32PllCr);
	SYSCLK->PLLCON.OE     = 0;
	SYSCLK->PLLCON.PD 	  = 0;

	/*Delay for PLL stable*/
	for (i=0;i<10000;i++);
	/* Change HCLK clock source to be PLL. */
	DrvSYS_SelectHCLKSource(2);
	LOCKREG();	// Lock the protected registers
#endif
}
Пример #3
0
/*************************************************************************//**
 * @brief   Delay 1 second exactly with timer.
 * @param   None
 * @return  None
*****************************************************************************/
void Delay1Sec(void)
{
    UNLOCKREG();
    SYSCLK->PWRCON.XTL12M_EN = 1;
    /* Waiting for 12M Xtal stable */
    while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);
    
    /*Configure gpio p3.6 as OUTPUT for led*/
    DrvGPIO_Open(E_PORT3, E_PIN6, E_IO_OUTPUT);
    /* Example code */
    DrvTIMER_Init();
    DrvTIMER_Open(E_TMR0, 1000, E_PERIODIC_MODE);                   
    DrvTIMER_EnableInt(E_TMR0);     
    DrvTIMER_Start(E_TMR0);             /* Start counting */

    while (1)
    {
        DrvGPIO_SetBit(E_PORT3, E_PIN6);
        DrvTIMER_Delay(E_TMR0, 1000);       /*Delay 1000/1000 Sec*/
        DrvGPIO_ClrBit(E_PORT3, E_PIN6);
        DrvTIMER_Delay(E_TMR0, 1000);
    }
}
Пример #4
0
//*****************************************************************************
//
//! \brief Example of ACMP.
//!
//! \param None  
//!
//! \return None  
//
//*****************************************************************************
void SmplAcmp(void)
{

    UNLOCKREG();
    
    //
    // P5.1 -> XTAL2, P5.0 -> XTAL1
    //
	GCR->P5_MFP = (GCR->P5_MFP & 0x00FFFCFC) | 0x03;
    CLK->PWRCON_BITS.XTLCLK_EN = 1;
    
    //
    // Waiting for 12M Xtal stable
    //
    while (DrvSYS_GetChipClockSourceStatus(XTL_CLK) != 1);

    DrvGPIO_InitFunction(FUNC_ACMP0);
    DrvGPIO_InitFunction(FUNC_ACMP1);

    //
    // Enable ACMP clock source
    //
    CLK->APBCLK_BITS.ACMP_EN = 1;

    //
    // Configure ACMP0
    //
    ACMP->CR0 = 0x13;

    //
    // Configure ACMP1
    //
    ACMP->CR1 = 0x13;

    NVIC_EnableIRQ(ACMP_IRQn);
}
Пример #5
0
/******************************************************************************//**
 *@brief  A simple FMC example. It Erase the LDROM and Verify ,then Program LDROM
 *        and read out data to compare.
 *@param  None
 *@return None 
**********************************************************************************/
void FMC_LDROM(void)
{
	uint32_t u32Data, i;
	int32_t  i32Err;
//	STR_UART_T sParam;

	/* Unlock the protected registers */
	UNLOCKREG();

	/* Enable the 12MHz oscillator oscillation */
	SYSCLK->PWRCON.XTL12M_EN = 1;

	/* Waiting for 12M Xtal stable */
	while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1);

	/* Set UART Pin */
	DrvGPIO_InitFunction(E_FUNC_UART0);

	/* UART Setting */
/*	sParam.u32BaudRate 		= 115200;
	sParam.u8cDataBits 		= DRVUART_DATABITS_8;
	sParam.u8cStopBits 		= DRVUART_STOPBITS_1;
	sParam.u8cParity 		= DRVUART_PARITY_NONE;
	sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
*/
	/* Select UART Clock Source From 12MHz */
	DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0);

	/* Set UART Configuration */
//	DrvUART_Open(UART_PORT0, &sParam);

	/* Enable ISP function */
	DrvFMC_EnableISP();
	/* Enable LDROM update */
	DrvFMC_EnableLDUpdate();

	/* Page Erase LDROM */
	printf("Erase LDROM test...............................");
	for(i=0; i<4096; i+=PAGE_SIZE)
		DrvFMC_Erase(LDROM_BASE + i);
	/* Erase Verify */
	i32Err = 0;
	for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4)
	{
		DrvFMC_Read(i, &u32Data);

		if(u32Data != 0xFFFFFFFF)
		{
			i32Err = 1;
		}
	}
    if (i32Err)
        printf("[FAIL]\n\r");
    else
        printf("[OK]\n\r");

	/* Program LD ROM and read out data to compare */
	printf("Program LDROM test.............................");
	for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4)
	{
		DrvFMC_Write(i, i);
	}
	i32Err = 0;
	for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4)
	{
		DrvFMC_Read(i, &u32Data);
		if(u32Data != i)
		{
			i32Err = 1;
		}
	}
    if (i32Err)
        printf("[FAIL]\n\r");
    else
        printf("[OK]\n\r");

	/* Disable ISP function */
	DrvFMC_DisableISP();

	/* Lock protected registers */
	LOCKREG();

	printf("FMC Sample Code Completed!\n\r");
}
Пример #6
0
//*****************************************************************************
//
//! \brief GPIO test.
//!
//! \param None  
//!
//! \return None  
//
//*****************************************************************************
void GpioTest(void)
{
    int32_t i32Err;

    UNLOCKREG();
    //
    // Enable high external clock and use it as system clock (HCLK)
    //
	  DrvSYS_Open(XTL_CLK);
	  
    //
    // Waiting for 12M Xtal stable
    //
    while (DrvSYS_GetChipClockSourceStatus(XTL_CLK) != 1);

    //
    // Configure Bit0 in Port1 to Output pin and Bit4 in Port3 to Input 
    // pin then close it                  
    //

    DrvGPIO_Open(E_PORT1, E_PIN0, E_IO_OUTPUT);
    DrvGPIO_Open(E_PORT3, E_PIN4, E_IO_INPUT);

    i32Err = 0;

    DrvGPIO_ClrBit(E_PORT1, E_PIN0);
    if (DrvGPIO_GetBit(E_PORT3, E_PIN4) != 0)
    {
        i32Err = 1;
    }

    DrvGPIO_SetBit(E_PORT1, E_PIN0);
    if (DrvGPIO_GetBit(E_PORT3, E_PIN4) != 1)
    {
        i32Err = 1;
    }

    DrvGPIO_Close(E_PORT1, E_PIN0);
    DrvGPIO_Close(E_PORT3, E_PIN4);

    //
    // GPIO Interrupt Test:P15, P22, P32(INT0) and P52(INT1) are used to test 
    // interrupt and control LEDs(P30)
    //

    //
    //Configure P30 for LED control
    //
    DrvGPIO_Open(E_PORT3, E_PIN0, E_IO_OUTPUT);

    //
    //Configure P15 as general GPIO interrupt
    //
    DrvGPIO_Open(E_PORT1, E_PIN5, E_IO_INPUT);
    
    //
    //The Quasi-bidirection mode could be used as input with pull up enable 
    //
    DrvGPIO_Open(E_PORT2, E_PIN2, E_IO_QUASI);

    //
    // Configure general interrupt callback function for P0/P1 and P2/P3/P4
    //
    DrvGPIO_SetIntCallback(P0P1Callback, P2P3P4Callback, P5Callback);

    DrvGPIO_EnableInt(E_PORT1, E_PIN5, E_IO_RISING, E_MODE_EDGE);

    //
    // IO_FALLING means low level trigger if it is in level trigger mode.
    //
    DrvGPIO_EnableInt(E_PORT2, E_PIN2, E_IO_FALLING, E_MODE_LEVEL);

    DrvGPIO_SetDebounceTime(0, E_DBCLKSRC_HCLK);
    DrvGPIO_EnableDebounce(E_PORT1, E_PIN5);
    DrvGPIO_EnableDebounce(E_PORT2, E_PIN2);

    DrvGPIO_EnableDebounce(E_PORT3, E_PIN2);
    DrvGPIO_EnableDebounce(E_PORT5, E_PIN2);
    
    //
    // Configure external interrupt.
    //
    DrvGPIO_InitFunction(FUNC_EXTINT0);
    DrvGPIO_InitFunction(FUNC_EXTINT1);
    DrvGPIO_EnableEINT(E_EINT0_PIN, E_IO_FALLING, E_MODE_EDGE, EINT0Callback);
    DrvGPIO_EnableEINT(E_EINT1_PIN, E_IO_BOTH_EDGE, E_MODE_EDGE, EINT1Callback);
}