Beispiel #1
0
uchar	Drv_Uart_init(uchar i)
{
	if(i==0)
		DrvGPIO_InitFunction(E_FUNC_UART0);
	else
		DrvGPIO_InitFunction(E_FUNC_UART0);
	DrvGPIO_Open(E_GPC,2,E_IO_OUTPUT);
	DrvGPIO_Open(E_GPC,3,E_IO_OUTPUT);
	DrvGPIO_Open(E_GPC,1,E_IO_OUTPUT);
}
Beispiel #2
0
int32_t main()
{
	STR_UART_T sParam;

	UNLOCKREG();
  DrvSYS_Open(50000000);
	LOCKREG();
   	
	DrvGPIO_InitFunction(E_FUNC_UART0);	// Set UART pins

	/* UART Setting */
    sParam.u32BaudRate 		  = 9600;
    sParam.u8cDataBits 		  = DRVUART_DATABITS_8;
    sParam.u8cStopBits 		  = DRVUART_STOPBITS_1;
    sParam.u8cParity 		    = DRVUART_PARITY_NONE;
    sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;

	/* Set UART Configuration */
 	if(DrvUART_Open(UART_PORT0,&sParam) != E_SUCCESS);
	DrvUART_EnableInt(UART_PORT0, DRVUART_RDAINT, UART_INT_HANDLE);
	
	init_LCD();                 // initialize LCD panel
	clear_LCD();                 // clear LCD panel							 	
	print_Line(0, "Smpl_UART0_HC05"); // print title
    		   
	while(1)
	{
	}
	//DrvUART_Close(UART_PORT0);
}
Beispiel #3
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvEBI_Open(DRVEBI_CONFIG_T sEBIConfig)
{
	/* EBI clock enable */
	SYSCLK->AHBCLK.EBI_EN = 1;

	/* EBI function enable */
	EBI->EBICON.ExtEN = 1;
	
	if (sEBIConfig.eAddrWidth == E_DRVEBI_ADDR_8BIT)
	{	
		DrvGPIO_InitFunction(E_FUNC_EBI_8B);
	}else
	if (sEBIConfig.eAddrWidth == E_DRVEBI_ADDR_16BIT)
	{
		DrvGPIO_InitFunction(E_FUNC_EBI_16B);
	}else
	{
        return E_DRVEBI_ERR_ARGUMENT;
	}
    EBI->EBICON.ExtBW16 = sEBIConfig.eDataWidth;
    		
    return E_SUCCESS;
}
Beispiel #4
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvEBI_Open(DRVEBI_CONFIG_T sEBIConfig)
{
	/* EBI clock enable */
	SYSCLK->AHBCLK.EBI_EN = 1;

	/* EBI function enable */
	EBI->CON.ExtEN = 1;
	
	if (sEBIConfig.eBusWidth == E_DRVEBI_BUS_8BIT)
	{	
		DrvGPIO_InitFunction(E_FUNC_EBI_8B);
		EBI->CON.ExtBW16 = 0;
	}
	else if (sEBIConfig.eBusWidth == E_DRVEBI_BUS_16BIT)
	{
		DrvGPIO_InitFunction(E_FUNC_EBI_16B);
		EBI->CON.ExtBW16 = 1;
	}else
	{
        return E_DRVEBI_ERR_ARGUMENT;
	}
    		
    return E_SUCCESS;
}
Beispiel #5
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);
}
Beispiel #6
0
void setupUART()
{
#ifdef M451
	setupCommandUART();
#else
	STR_UART_T param;
	DrvGPIO_InitFunction(E_FUNC_UART1);
	DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC,3);
	param.u32BaudRate        = UART_BAUD_RATE;
	param.u8cDataBits        = DRVUART_DATABITS_8;
	param.u8cStopBits        = DRVUART_STOPBITS_1;
	param.u8cParity          = DRVUART_PARITY_NONE;
	param.u8cRxTriggerLevel  = DRVUART_FIFO_1BYTES;
	param.u8TimeOut        	 = 0;
	DrvUART_Open(UART_PORT1, &param);
#endif
	printf("Version:%d\n", VERSION_CODE);
}
//------------------------------
void bacarfid(){
	uint8_t hasiluart[8];
	STR_UART_T sParam;
				UNLOCKREG();
				DrvSYS_Open(50000000);
				LOCKREG();
				/* Set UART Pin */
					DrvGPIO_InitFunction(E_FUNC_UART0);

					/* UART Setting */
				    sParam.u32BaudRate 		= 9600;
				    sParam.u8cDataBits 		= DRVUART_DATABITS_8;
				    sParam.u8cStopBits 		= DRVUART_STOPBITS_1;
				    sParam.u8cParity 		= DRVUART_PARITY_NONE;
				    sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
			DrvUART_Open(UART_PORT0,&sParam);


}
Beispiel #8
0
void init_SPI3(void)
{
	DrvGPIO_Open(E_GPB, 9, E_IO_OUTPUT);
	DrvGPIO_Open(E_GPB, 7, E_IO_OUTPUT);
	DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT);
	DrvGPIO_Open(E_GPD, 14, E_IO_OUTPUT);
	DrvGPIO_ClrBit(E_GPD, 14);
	DrvGPIO_InitFunction(E_FUNC_SPI3);
	/* Configure SPI3 as a master, Type1 waveform, 8-bit transaction */
	DrvSPI_Open(eDRVSPI_PORT3, eDRVSPI_MASTER, eDRVSPI_TYPE1, 8);
	/* MSB first */
	DrvSPI_SetEndian(eDRVSPI_PORT3, eDRVSPI_MSB_FIRST);
	/* Disable the automatic slave select function of SS0. */
	DrvSPI_DisableAutoSS(eDRVSPI_PORT3);
	/* Set the active level of slave select. */
	DrvSPI_SetSlaveSelectActiveLevel(eDRVSPI_PORT3, eDRVSPI_ACTIVE_LOW_FALLING);
	/* SPI clock rate 20MHz */
	DrvSPI_SetClockFreq(eDRVSPI_PORT3, 25000000, 0);
  SPI_CS_SET; 
}
Beispiel #9
0
/*
*********************************************************************************************************
*                                            LOCAL FUCTION
*********************************************************************************************************
*/
int32_t BSP_INIT_UART0(void)
{
	STR_UART_T param;

	/* SYSCLK =>12Mhz*/
	DrvGPIO_InitFunction(E_FUNC_UART0_RX_TX);

	/* Select UART Clock Source From 12MHz */
	DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC,0); 
	
    param.u32BaudRate        = 115200;
    param.u8cDataBits        = DRVUART_DATABITS_8;
    param.u8cStopBits        = DRVUART_STOPBITS_1;
    param.u8cParity          = DRVUART_PARITY_NONE;
    param.u8cRxTriggerLevel  = DRVUART_FIFO_62BYTES;
    param.u8TimeOut        	 = 250;
    if(DrvUART_Open(UART_PORT0,&param) == 0)
		return TRUE;
	else
		return FALSE;
}
Beispiel #10
0
void motorsInit()
{
#ifdef M451
	CLK_EnableModuleClock(PWM0_MODULE);
	CLK_SetModuleClock(PWM0_MODULE, CLK_CLKSEL2_PWM0SEL_PCLK0, 0);

	SYS->GPC_MFPL = (SYS->GPC_MFPL 
	& (~SYS_GPC_MFPL_PC0MFP_Msk)
	& (~SYS_GPC_MFPL_PC1MFP_Msk)
	& (~SYS_GPC_MFPL_PC2MFP_Msk)
	& (~SYS_GPC_MFPL_PC3MFP_Msk)
#ifdef HEX6X 
	& (~SYS_GPC_MFPL_PC4MFP_Msk)
#endif
	);
#ifdef HEX6X 
	SYS->GPD_MFPL = (SYS->GPD_MFPL 
	& (~SYS_GPD_MFPL_PD7MFP_Msk)
	);
#endif
	SYS->GPC_MFPL |= (SYS_GPC_MFPL_PC0MFP_PWM0_CH0|SYS_GPC_MFPL_PC1MFP_PWM0_CH1|
	SYS_GPC_MFPL_PC2MFP_PWM0_CH2|SYS_GPC_MFPL_PC3MFP_PWM0_CH3
#ifdef HEX6X 
	|SYS_GPC_MFPL_PC4MFP_PWM0_CH4
#endif
	);
#ifdef HEX6X 
	SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD7MFP_PWM0_CH5);
#endif
	PWM_ConfigOutputChannelf(PWM0, 0, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
	PWM_ConfigOutputChannelf(PWM0, 1, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
	PWM_ConfigOutputChannelf(PWM0, 2, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
	PWM_ConfigOutputChannelf(PWM0, 3, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
#ifdef HEX6X 
	PWM_ConfigOutputChannelf(PWM0, 4, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
	PWM_ConfigOutputChannelf(PWM0, 5, ESC_UPDATE_FREQ, ESC_UPDATE_FREQ/10);
#endif

	motorsSetRatio(MOTOR_M1, 0);
	motorsSetRatio(MOTOR_M2, 0);
	motorsSetRatio(MOTOR_M3, 0);
	motorsSetRatio(MOTOR_M4, 0);
#ifdef HEX6X 
	motorsSetRatio(MOTOR_M5, 0);
	motorsSetRatio(MOTOR_M6, 0);
#endif

	PWM_EnableOutput(PWM0, PWM_CH_0_MASK);
	PWM_EnableOutput(PWM0, PWM_CH_1_MASK);
	PWM_EnableOutput(PWM0, PWM_CH_2_MASK);
	PWM_EnableOutput(PWM0, PWM_CH_3_MASK);
#ifdef HEX6X 
	PWM_EnableOutput(PWM0, PWM_CH_4_MASK);
	PWM_EnableOutput(PWM0, PWM_CH_5_MASK);
#endif
#else
	uint8_t u8Timer;

	DrvPWM_Open();
	DrvGPIO_InitFunction(E_FUNC_PWM01);
	DrvGPIO_InitFunction(E_FUNC_PWM23);

	s_u32Pulse = 0;
	g_u8PWMCount = 1;
	g_u16Frequency = ESC_UPDATE_FREQ;
	sPt.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
	sPt.u32Frequency = g_u16Frequency;
	sPt.u8HighPulseRatio = 1;
	sPt.u8HighPulseBase = 1000000/g_u16Frequency;
	sPt.i32Inverter = 0;

	u8Timer = DRVPWM_TIMER0;
	DrvPWM_SelectClockSource(u8Timer, DRVPWM_HCLK);
	DrvPWM_SetTimerClk(u8Timer, &sPt);
	DrvPWM_SetTimerIO(u8Timer, 1);

	u8Timer = DRVPWM_TIMER1;
	DrvPWM_SelectClockSource(u8Timer, DRVPWM_HCLK);
	DrvPWM_SetTimerClk(u8Timer, &sPt);
	DrvPWM_SetTimerIO(u8Timer, 1);

	u8Timer = DRVPWM_TIMER2;
	DrvPWM_SelectClockSource(u8Timer, DRVPWM_HCLK);
	DrvPWM_SetTimerClk(u8Timer, &sPt);
	DrvPWM_SetTimerIO(u8Timer, 1);

	u8Timer = DRVPWM_TIMER3;
	DrvPWM_SelectClockSource(u8Timer, DRVPWM_HCLK);
	DrvPWM_SetTimerClk(u8Timer, &sPt);
	DrvPWM_SetTimerIO(u8Timer, 1);
#endif
}
Beispiel #11
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");
}
Beispiel #12
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);
}
Beispiel #13
0
char PWM_Single_out(uint32_t Frequency,uint8_t port,uint8_t period)
{
	S_DRVPWM_TIME_DATA_T sPt;
	uint8_t u8Timer;
	if(port<1&&port>4) return 1;
	if(period<1&&port>99) return 1;
	DrvGPIO_InitFunction(E_FUNC_PWM0);
	DrvGPIO_InitFunction(E_FUNC_PWM1);
   	DrvGPIO_InitFunction(E_FUNC_PWM2);
  	DrvGPIO_InitFunction(E_FUNC_PWM3);
  	DrvGPIO_InitFunction(E_FUNC_PWM4);
  	DrvGPIO_InitFunction(E_FUNC_PWM5);
  	DrvGPIO_InitFunction(E_FUNC_PWM6);
  	DrvGPIO_InitFunction(E_FUNC_PWM7);
	sPt.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
    sPt.u32Frequency = Frequency;
    sPt.u8HighPulseRatio = period;   /* High Pulse peroid : Total Pulse peroid = 1 : 100 */ 
    sPt.i32Inverter = 0;
    if(port==1)
	{	
		u8Timer=DRVPWM_TIMER0;          
	}                           
	else if(port==2)
	{
		u8Timer=DRVPWM_TIMER1;	
	}
	else if(port==3)
	{
		u8Timer=DRVPWM_TIMER2;	
	}    
	else if(port==4)
	{
		u8Timer=DRVPWM_TIMER3;	
	}    
	else if(port==5)
	{
		u8Timer=DRVPWM_TIMER4;	
	}    
	else if(port==6)
	{
		u8Timer=DRVPWM_TIMER5;	
	}    
	else if(port==7)
	{
		u8Timer=DRVPWM_TIMER6;	
	}    
	else if(port==8)
	{
		u8Timer=DRVPWM_TIMER7;	
	}        
        /* Select PWM engine clock */
        DrvPWM_SelectClockSource(u8Timer, DRVPWM_HCLK);
                        
        /* Set PWM Timer0 Configuration */
        DrvPWM_SetTimerClk(u8Timer, &sPt);

        /* Enable Output for PWM Timer0 */
        DrvPWM_SetTimerIO(u8Timer, port);

        /* Enable Interrupt Sources of PWM Timer0 and install call back function */
                                                            
        /* Enable the PWM Timer 0 */
        DrvPWM_Enable(u8Timer, port);    
                                                            
        /*--------------------------------------------------------------------------------------*/
        /* Stop PWM Timer0 (Recommended procedure method 2)                                     */
        /* Set PWM Timer counter as 0, When interrupt request happen, disable PWM Timer         */
        /* Set PWM Timer counter as 0 in Call back function                                     */
        /*--------------------------------------------------------------------------------------*/
                                
        /* Disable the PWM Timer 0 */
		return 0;
}
Beispiel #14
0
//*****************************************************************************
//
//! \brief PWM Output.
//!
//! \param None  
//!
//! \return None  
//
//*****************************************************************************
void PWMOutput(void)
{
    S_DRVPWM_TIME_DATA_T sPt;
    int32_t i32Loop = 1;

    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 stalble
    //
    DrvSYS_Delay(5000);
     
    //
    //Enable PWM clock
    //
    DrvPWM_Open();
	  CLK->CLKSEL1_BITS.PWM23_S = 2;
    
    //
    // Set PWM pin
    //
    DrvGPIO_InitFunction(FUNC_PWM3);

    UNLOCKREG();
    DrvSYS_SelectHCLKSource(0);
    LOCKREG();

    while(i32Loop)
    {

        uint8_t u8ItemOK;

        u8ItemOK = 1;
        g_u16Frequency = 256;


        if (u8ItemOK && g_u8PWMCount == 0)
        {
            s_u32Pulse = 0;
            g_u8PWMCount = 1;
            //
            // PWM Timer property
            //
            sPt.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
            sPt.u32Frequency = g_u16Frequency;
            //
            // High Pulse peroid : Total Pulse peroid = 10 : 90
            //
            sPt.u8HighPulseRatio = 90;
            sPt.i32Inverter = 0;
            
            //
            // Set PWM Timer Configuration 
            //
            DrvPWM_SetTimerClk(DRVPWM_TIMER3, &sPt);

            //
            // Enable Output for PWM Timer */
            //
            DrvPWM_SetTimerIO(DRVPWM_TIMER3, 1);
            
            //
            // Enable Interrupt Sources of PWM Timer and install call back function
            //
            DrvPWM_EnableInt(DRVPWM_TIMER3, PWM_INT_PERIOD, PWMA_IRQHandler, 0);
            
            //
            //Enable the PWM Timer
            //
            DrvPWM_Enable(DRVPWM_TIMER3);

            while (g_u8PWMCount);
            DrvPWM_Disable(DRVPWM_TIMER3);
          }
    }
    DrvPWM_Close();
}