Exemplo n.º 1
0
void GoToSleep()
{
	gFlags.light_sleep = !( gFlags.has_x32 || dfStatus.lsloff || gFlags.noclock );

	ScreenOff();
	LEDOff();
	gFlags.firing = 0;
	BatReadTimer = 50;
	RTCSleep();
	DevicesOnOff( 1 );
	CLK_SysTickDelay( 250 );
	CLK_SysTickDelay( 250 );
	CLK_SysTickDelay( 250 );
	if ( dfStatus.off || PE0 || KeyPressTime == 1100 )
	{
		SYS_UnlockReg();
		WDT_Close();
		FlushAndSleep();
		PreheatDelay = 0;
	}
	WDT_Open( WDT_TIMEOUT_2POW14, WDT_RESET_DELAY_18CLK, TRUE, FALSE );
	SYS_LockReg();
	gFlags.refresh_battery = 1;
	DevicesOnOff( 0 );
	RTCWakeUp();
	InitDisplay();
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
    //Initial System
    SYS_Init();

    //Enable Timer0 clock and select Timer0 clock source
    CLK_EnableModuleClock(TMR0_MODULE);
    CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_HXT, 0);

    //Initial Timer0 to periodic mode with 2Hz
    TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 2);
    //Enable Timer0 interrupt
    TIMER_EnableInt(TIMER0);
    NVIC_EnableIRQ(TMR0_IRQn);

    //Initial 7-Segment
    Open_Seven_Segment();

    //Start Timer0
    TIMER_Start(TIMER0);

    while(1)
    {
        Show_Seven_Segment(TimerCounter / 10, 1);
        CLK_SysTickDelay(200);
        Show_Seven_Segment(TimerCounter % 10, 2);
        CLK_SysTickDelay(200);
    }
}
Exemplo n.º 3
0
__myevic__ void Plantouille( int xpsr, int* stack )
{
	int i, k;

	k = 0;

	SYS_UnlockReg();
	WDT_Close();
	SYS_LockReg();

	InitDisplay();

	while ( 1 )
	{
		ClearScreenBuffer();

		DrawImage( 0, 0, 'X'+0x27 );
		DrawHexLong( 16, 0, xpsr, 0 );

		DrawHexDigit( 0, 16, k );

		for ( i = 0; i < 14 ; ++i )
		{
			DrawHexLong( 16, 16+i*8, stack[i+k*14], 0 );
		}

		DisplayRefresh();

		while ( !PE0 || !PD2 || !PD3 )
			CLK_SysTickDelay( 10000 );

		while ( PE0 && PD2 && PD3 )
			CLK_SysTickDelay( 10000 );

		if ( !PE0 )
		{
		  SYS_UnlockReg();
		  SYS_ResetChip();
		  while ( 1 )
			;
		}

		if ( !PD2 ) ++k;
		if ( !PD3 ) --k;

		if ( k < 0 ) k = 0;
		else if ( k > 15 ) k = 15;
	}
}
Exemplo n.º 4
0
void textticker(char *string, uint32_t delayus)
{
    char showstring[7], tmpstring[7];
    int showidx, textidx, storeshowidx, storetextidx;
    int textlen;
    uint32_t i;

    strcpy(&showstring[0], "       ");

    textlen = strlen(string);

    showidx = 6;

    for(textidx=0; textidx<textlen; textidx++) {
        // clear showstring
        for(storetextidx=0; storetextidx<=6; storetextidx++) showstring[storetextidx] = ' ';

        storetextidx = textidx;
        if((6-showidx) > 0) {
            storetextidx -= (6-showidx);
        }
        for(storeshowidx=showidx; storeshowidx<=6; storeshowidx++) {
            showstring[storeshowidx] = string[storetextidx++];
        }
        if(showidx!=0)
            showidx--;
        //printf("%s \r\n", showstring);
        LCDLIB_Printf(0, &showstring[0]);
        CLK_SysTickDelay(delayus);

    }

    for(showidx=0; showidx<=6; showidx++) {
        strcpy(tmpstring, showstring);
        for(storeshowidx=0; storeshowidx<=6; storeshowidx++) {
            for(i = 0; i < 10000; i++);

            if((storeshowidx+1) <= 6)
                showstring[storeshowidx] = tmpstring[storeshowidx+1];
            else
                showstring[storeshowidx] = ' ';
        }

        LCDLIB_Printf(0, &showstring[0]);
        CLK_SysTickDelay(delayus);
    }

}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    uint32_t u32TrimInit;

    uint8_t Str[9];
    
    /* Unlock protected registers */
    SYS_UnlockReg();

    SYS_Init();

    UART0_Init();

    printf("\n");
    printf("+--------------------------------------------------------+\n");
    printf("|         NuMicro USB Micro Printer Sample Code          |\n");
    printf("+--------------------------------------------------------+\n");

    USBD_Open(&gsInfo, PTR_ClassRequest, NULL);

    /* Endpoint configuration */
    PTR_Init();
    USBD_Start();

#if CRYSTAL_LESS
    /* Backup init trim */
    u32TrimInit = M32(TRIM_INIT);

    /* Enable USB crystal-less */
    SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos);
#endif

    NVIC_EnableIRQ(USBD_IRQn);

    PB->PMD = 0x5000;   // PB.6, PB.7 output mode
  
    while(1)
    {
#if CRYSTAL_LESS
        /* Re-start crystal-less when any error found */
        if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk))
        {
            SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk;

            if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253))
                /* Re-enable crystal-less */
                SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos);
            else
                /* Re-enable crystal-less */
                SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos);
            //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL);
        }
#endif

        CLK_SysTickDelay(2000);   // delay
        if(++Str[1] > 0x39)
            Str[1] = 0x30;      // increase 1 to 10 than reset to 0
        PB->DOUT ^= 0x40; // PB.6
    }
}
Exemplo n.º 6
0
/**
 * @brief       Get ID of NOR Flash
 *
 * @param[in]   None
 *
 * @return      Return Manufacture ID and Device ID
 *
 * @details     Return the ID of W39L040P and Manufacture ID should be 0xDA, Device ID should be 0x31.
 */
uint32_t NOR_GetID(void)
{
    uint8_t u8ManuFactureID, u8DeviceID;

    *(g_pu8NorBaseAddr + 0x5555) = 0xAA;
    *(g_pu8NorBaseAddr + 0x2AAA) = 0x55;
    *(g_pu8NorBaseAddr + 0x5555) = 0x90;
    CLK_SysTickDelay(10);

    u8ManuFactureID = *(g_pu8NorBaseAddr + 0x0);
    u8DeviceID      = *(g_pu8NorBaseAddr + 0x1);

    *(g_pu8NorBaseAddr + 0x5555) = 0xAA;
    *(g_pu8NorBaseAddr + 0x2AAA) = 0x55;
    *(g_pu8NorBaseAddr + 0x5555) = 0xF0;
    CLK_SysTickDelay(10);

    return ((u8ManuFactureID << 8) | u8DeviceID);
}
Exemplo n.º 7
0
/**
  * @brief    This function makes USB host to recognize the device
  *
  * @param    None
  *
  * @return   None
  *
  * @details  Enable WAKEUP, FLDET, USB and BUS interrupts. Disable software-disconnect function after 100ms delay with SysTick timer.
  */
void USBD_Start(void)
{
    CLK_SysTickDelay(100000);
    /* Disable software-disconnect function */
    USBD_CLR_SE0();

    /* Clear USB-related interrupts before enable interrupt */
    USBD_CLR_INT_FLAG(USBD_INT_BUS | USBD_INT_USB | USBD_INT_FLDET | USBD_INT_WAKEUP);

    /* Enable USB-related interrupts. */
    USBD_ENABLE_INT(USBD_INT_BUS | USBD_INT_USB | USBD_INT_FLDET | USBD_INT_WAKEUP);
}
Exemplo n.º 8
0
//=========================================================================
//----- (00003564) --------------------------------------------------------
__myevic__ void ReadAtoCurrent()
{
	unsigned int adcShunt1, adcShunt2;
	unsigned int adcAtoVolts;
	unsigned int arez;
	unsigned int current1, current2;
	int s;

	if ( gFlags.firing || gFlags.probing_ato )
	{
		if ( ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
		{
			CLK_SysTickDelay( 10 );
			adcShunt2 = ADC_Read( 15 );
			if ( gFlags.firing && BuckDuty <= 25 && adcShunt2 > 200 )
				adcShunt2 = 0;
			CLK_SysTickDelay( 10 );
		}
		else
		{
			adcShunt2 = 0;
		}

		adcShunt1 = ADC_Read( 2 );
		CLK_SysTickDelay( 10 );
		adcAtoVolts = ADC_Read( 1 );

		if ( ISCUBO200 || ISRX200S || ISRX23 || ISRX300 )
		{
			current1 = ( ( 10 * 2560 * adcShunt2 ) >> 12 ) / AtoShuntRez;
			if ( gFlags.firing )
			{
				current2 = ( ( 10 * 2560 * adcShunt1 ) >> 12 ) / AtoShuntRez;
				AtoCurrent = current1 + current2;
			}
			else
			{
Exemplo n.º 9
0
int32_t main (void)
{
    uint8_t Tx_Data[6];
    uint8_t Rx_Data[6];

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();

    printf("+-------------------------------------------------------+\n");
    printf("|    Software I2C sample code                           |\n");
    printf("|    SW Master                                          |\n");
    printf("|    HW Slave                                           |\n");
    printf("+-------------------------------------------------------+\n");

    printf("Initiate I2C for slave\n");
    InitI2C_HW();

    printf("Initiate software I2C for Master\n");
    I2C_SW_Open(100000);

    printf("Please connect:\n");
    printf("SW SDA - P1.4 (PIN47)  <->   HW SDA - P3.4 (PIN9) \n");
    printf("SW SCL - P1.5 (PIN2)   <->   HW SCL - P3.5 (PIN10) \n");

    Tx_Data[0]=0;
    Tx_Data[1]=0;
    Tx_Data[2]=0xA5;
    Tx_Data[3]=0xcc;
    Tx_Data[4]=0xbb;
    Tx_Data[5]=0xdd;

    printf("Access I2C slave:\n");

    I2C_SW_Send(0x15,Tx_Data,6);
    CLK_SysTickDelay(5000);
    I2C_SW_Get(0x15,Rx_Data,4);

    if((Rx_Data[0] != 0xaa) || (Rx_Data[1] != 0x22) || (Rx_Data[2] != 0x33) || (Rx_Data[3] != 0x44))
        printf("Data Error!!\n");
    else
        printf("Pass!!\n");

    return 0;
}
Exemplo n.º 10
0
int32_t main (void)
{
    uint8_t Tx_Data[6];
    
    /* Init System, IP clock and multi-function I/O */
    SYS_Init();

    /* Init UART for printf */
    UART_Init();
    
    printf("+-------------------------------------------------------+\n");
    printf("|    Software I2C sample code                           |\n");
    printf("|    SW Master -> I2C EEPROM                            |\n");
    printf("+-------------------------------------------------------+\n");

    I2C_SW_I_Open(50000);
    Tx_Data[0]=0;
    Tx_Data[1]=0;
    Tx_Data[2]=0xAA;
    Tx_Data[3]=0xBB;
    Tx_Data[4]=0x55;
    Tx_Data[5]=0xCC;

    printf("Write data into EEPROM\n");
    printf("Data:0x%x,0x%x,0x%x,0x%x\n",Tx_Data[2],Tx_Data[3],Tx_Data[4],Tx_Data[5] );
    I2C_SW_I_Send(0x50,Tx_Data,6);
    while(I2C_SW_I_IsBZ());
    if(I2C_SW_I_Count()!=6)
        while(1);
    CLK_SysTickDelay(5000);

    printf("Write address into EEPROM\n");
    I2C_SW_I_Send(0x50,Tx_Data,2);
    while(I2C_SW_I_IsBZ());
    if(I2C_SW_I_Count()!=2)
        while(1);
        
    printf("Read data form EEPROM\n");        
    I2C_SW_I_Get(0x50,Tx_Data,4);
    while(I2C_SW_I_IsBZ());
    printf("Data:0x%x,0x%x,0x%x,0x%x\n",Tx_Data[0],Tx_Data[1],Tx_Data[2],Tx_Data[3] );
    if(I2C_SW_I_Count()!=4)
        while(1);
    while(1);
}
Exemplo n.º 11
0
/**
 * @brief       NOR Flash Chip Erase
 *
 * @param[in]   None
 *
 * @retval      FALSE       Erase command fail
 * @retval      TRUE        Erase command pass
 *
 * @details     W39L040P whole chip erase.
 */
uint8_t NOR_Erase(void)
{
    uint8_t u8Status;

    *(g_pu8NorBaseAddr + 0x5555) = 0xAA;
    *(g_pu8NorBaseAddr + 0x2AAA) = 0x55;
    *(g_pu8NorBaseAddr + 0x5555) = 0x80;
    *(g_pu8NorBaseAddr + 0x5555) = 0xAA;
    *(g_pu8NorBaseAddr + 0x2AAA) = 0x55;
    *(g_pu8NorBaseAddr + 0x5555) = 0x10;

    u8Status = NOR_CheckCMDComplete(0x0, 0x0);
    if(u8Status == FALSE)
        return FALSE;

    CLK_SysTickDelay(200000);

    return TRUE;
}
Exemplo n.º 12
0
void SYS_Init(void)
{
    /* Unlock protected registers */
    SYS_UnlockReg();  

    /* Enable Internal RC clock */
    CLK->PWRCON |= CLK_PWRCON_XTL12M | CLK_PWRCON_OSC10K_EN_Msk | CLK_PWRCON_IRC22M_EN_Msk;    

    CLK_SysTickDelay(1200);

    /* Waiting for IRC22M clock ready */
    CLK_WaitClockReady(CLK_CLKSTATUS_XTL_STB_Msk | CLK_CLKSTATUS_IRC22M_STB_Msk);  

    /* IP clock divider */
    CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLK_S_XTAL);

    /* Switch HCLK clock source to XTL */
    CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_XTAL,CLK_CLKDIV_HCLK(1));

    /* Enable IP clock */        
    CLK_EnableModuleClock(UART_MODULE);
    CLK_EnableModuleClock(TMR1_MODULE);
  
    /* IP clock source */
    CLK->CLKSEL1 = ( CLK->CLKSEL1 & (~CLK_CLKSEL1_UART_S_Msk) ) |  CLK_CLKSEL1_UART_S_XTAL | CLK_CLKSEL1_TMR1_S_HCLK;
  
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function                                                                                 */
/*---------------------------------------------------------------------------------------------------------*/
    /* Set P0 multi-function pins for UART RXD and TXD */
    SYS->P0_MFP &= ~(SYS_MFP_P01_Msk | SYS_MFP_P00_Msk);
    SYS->P0_MFP |= (SYS_MFP_P01_RXD | SYS_MFP_P00_TXD);  

    /* To update the variable SystemCoreClock */
    SystemCoreClockUpdate();
    
    /* Lock protected registers */
    SYS_LockReg();  
}
Exemplo n.º 13
0
/**
 * @brief       Check Command Complete
 *
 * @param[in]   u32Addr     The address to read out data to check if command complete
 * @param[in]   u8Data      The data to be compared with the read out data
 *
 * @retval      FALSE       Command fail
 * @retval      TRUE        Command complete
 *
 * @details     Check if the specified command is complete or not.
 */
uint8_t NOR_CheckCMDComplete(uint32_t u32Addr, uint8_t u8Data)
{
    /* Using Data Polling Algorithm to check if command is complete or not */
    uint8_t u8CurData;
    volatile uint32_t u32TimeOutCnts = 0;

    /* Command timeout period is 200 ms */
    u8Data = u8Data & (1 << 7); // read D7
    while(u32TimeOutCnts < 200000)
    {
        u8CurData = NOR_ReadData(u32Addr);
        u8CurData = u8CurData & (1 << 7); // read DQ7
        if(u8Data == u8CurData)
        {
            return TRUE;
        }
        CLK_SysTickDelay(1);
        u32TimeOutCnts++;
    }

    return FALSE;
}
Exemplo n.º 14
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main(void)
{
    unsigned int u32ByteCount;
    unsigned int u32PageNumber;
    unsigned int u32ProgramFlashAddress = 0;
    unsigned int u32VerifyFlashAddress = 0;
    unsigned int MidDid;

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, peripheral clock and multi-function I/O */
    SYS_Init();

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();

    printf("Hello World.\n");
    printf("PLL Clock = %d Hz\n", CLK_GetPLLClockFreq());
    printf("Core Clock = %d Hz\n\n", CLK_GetHCLKFreq());
    printf("+-------------------------------------------------------+\n");
    printf("|       M451 Series SPI_Flash Sample Code         |\n");
    printf("+-------------------------------------------------------+\n");

    /* Open 7-Seg */
    Open_Seven_Segment();

    /* Open SPI for Serial Flash */
    Open_SPI_Flash();

    /* Read MID & DID */
    MidDid = SpiFlash_ReadMidDid();
    printf("\nMID and DID = %x", MidDid);

    /* Erase SPI Flash */
    SpiFlash_ChipErase();
    printf("\nFlash Erasing... ");

    /* Wait ready */
    SpiFlash_WaitReady();
    printf("Done!");

    /* Fill the Source Data and clear Destination Data Buffer */
    for(u32ByteCount = 0; u32ByteCount < 256; u32ByteCount++)
    {
        SrcArray[u32ByteCount] = u32ByteCount;
        DestArray[u32ByteCount] = 0;
    }

    u32ProgramFlashAddress = 0;
    u32VerifyFlashAddress = 0;
    for(u32PageNumber = 0; u32PageNumber < TEST_NUMBER; u32PageNumber++)
    {
        printf("\n\nTest Page Number = %d", u32PageNumber);
        Show_Seven_Segment(u32PageNumber, 1);
        CLK_SysTickDelay(200000);

        /*=== Program SPI Flash ===*/
        printf("\n Flash Programming... ");

        /* Page Program */
        SpiFlash_PageProgram(SrcArray, u32ProgramFlashAddress, 256);
        SpiFlash_WaitReady();
        u32ProgramFlashAddress += 0x100;
        printf("Done!");

        /*=== Read Back and Compare Data ===*/
        printf("\n Flash Verifying... ");

        /* Page Read */
        SpiFlash_ReadData(DestArray, u32VerifyFlashAddress, 256);
        u32VerifyFlashAddress += 0x100;

        for(u32ByteCount = 0; u32ByteCount < 256; u32ByteCount++)
        {
            if(DestArray[u32ByteCount] != u32ByteCount)
            {
                /* Error */
                printf("SPI Flash R/W Fail!");
                while(1);
            }
        }

        /* Clear Destination Data Buffer */
        for(u32ByteCount = 0; u32ByteCount < 256; u32ByteCount++)
            DestArray[u32ByteCount] = 0;

        printf("Done!");
    }

    printf("\n\nSPI Flash Test Ok!");
    printf("\n\n");

    while(1);

}
Exemplo n.º 15
0
/**
  * @brief  Main routine.
  * @param  None.
  * @return None.
  */
int32_t main(void)
{
    S_RTC_TIME_DATA_T sCurTime;

    SYS_Init();
    UART0_Init();

    DEBUG_MSG("\nNANO130 NuTiny EVB Demo Program V1.0.0\n");
    DEBUG_MSG("[Power Down Demo]\n");

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Time Setting */
    sCurTime.u32Year       = 2013;
    sCurTime.u32Month      = 10;
    sCurTime.u32Day        = 15;
    sCurTime.u32Hour       = 0;
    sCurTime.u32Minute     = 0;
    sCurTime.u32Second     = 0;
    sCurTime.u32DayOfWeek  = RTC_TUESDAY;
    sCurTime.u32TimeScale  = RTC_CLOCK_24;

    RTC_Open(&sCurTime);
    DEBUG_MSG("RTC Init. complete!\n");

    /* Do LCD Initializaton */
    LCD_Open(LCD_C_TYPE, 4, LCD_BIAS_THIRD, LCD_FREQ_DIV64, LCD_CPVOl_3V);
    LCD_EnableDisplay();

    DEBUG_MSG("LCD Init. complete!\n");

    /* Start displaying on LCD */
    LCDLIB_SetSymbol(2, 27, 1);
    CLK_SysTickDelay(335000);

    textticker("*** NUVOTON NANO130 ***", 335000);
    CLK_SysTickDelay(335000);

    LCDLIB_Printf(0, "NUVOTON");
    LCD_EnableBlink(250);
    CLK_SysTickDelay(335000);
    CLK_SysTickDelay(335000);
    CLK_SysTickDelay(335000);
    CLK_SysTickDelay(335000);
    CLK_SysTickDelay(335000);
    LCD_DisableBlink();

    /* Read curent RTC time */
    RTC_GetDateAndTime(&sCurTime);
    DEBUG_MSG("Current Time:%d/%02d/%02d %02d:%02d:%02d\n",sCurTime.u32Year,sCurTime.u32Month,sCurTime.u32Day,sCurTime.u32Hour,sCurTime.u32Minute,sCurTime.u32Second);

    /* Display RTC time */
    showTime(sCurTime.u32Hour, sCurTime.u32Minute);

    DEBUG_MSG("Start MAIN loop.\n");
    while(1)
    {
        textticker("*** GOING TO POWER DOWN ***", 335000);
        DEBUG_MSG("Going to Power Down...\n");
#ifdef __DEBUG_MSG
        while(!(UART1->FSR & UART_FSR_TE_F)) ;  /* waits for message send out */
#endif
        /* Enter power down mode */
        /* This sample will not wake up*/
        Enter_PowerDown();

        DEBUG_MSG("Program resume...\n");

        if (_Wakeup_Flag == 1)
        {
            _Wakeup_Flag = 0;

            textticker("*** WAKE UP ***", 335000);
            CLK_SysTickDelay(335000);
            CLK_SysTickDelay(335000);
            CLK_SysTickDelay(335000);
        }
    };


}
Exemplo n.º 16
0
/*---------------------------------------------------------------------------------------------------------*/
int main()
{
    unsigned int u32ByteCount;
    unsigned int u32PageNumber;
    unsigned int u32ProgramFlashAddress = 0;
    unsigned int u32VerifyFlashAddress = 0;
    unsigned int MidDid;

    PDMA_T *PDMA_CH1, *PDMA_CH2;

    // PDMA Channel 1/2 control registers
    PDMA_CH1 = (PDMA_T *)((uint32_t) PDMA1_BASE + (0x100 * (CH1-1)));
    PDMA_CH2 = (PDMA_T *)((uint32_t) PDMA1_BASE + (0x100 * (CH2-1)));

    /* Initial system */
    SYS_Init();

    /* Initial UART1 to 115200-8n1 for print message */
    UART1_Init();

    printf("Hello World.\n");
    printf("PLL Clock = %d Hz\n", CLK_GetPLLClockFreq());
    printf("Core Clock = %d Hz\n\n", CLK_GetHCLKFreq());
    printf("+-------------------------------------------------------+\n");
    printf("|    Nano100 Series SPI_Flash Sample Code with PDMA     |\n");
    printf("+-------------------------------------------------------+\n");

    /* Open 7-Seg */
    Open_Seven_Segment();

    /* Open SPI for Serial Flash */
    Open_SPI_Flash();

    /* Initial PDMA Channels */
    Init_PDMA_CH1_for_SPI0_TX((uint32_t)SrcArray);
    Init_PDMA_CH2_for_SPI0_RX((uint32_t)DestArray);

    /* Enable PDMA IRQ */
    NVIC_EnableIRQ(PDMA_IRQn);

    /* Read MID & DID */
    MidDid = SpiFlash_w_PDMA_ReadMidDid();
    printf("\nMID and DID = %x", MidDid);

    /* Erase SPI Flash */
    SpiFlash_w_PDMA_ChipErase();
    printf("\nFlash Erasing... ");

    /* Wait ready */
    SpiFlash_w_PDMA_WaitReady();
    printf("Done!");

    /* Fill the Source Data and clear Destination Data Buffer */
    for(u32ByteCount=0; u32ByteCount<256; u32ByteCount++)
    {
        SrcArray[u32ByteCount] = u32ByteCount;
        DestArray[u32ByteCount] = 0;
    }

    u32ProgramFlashAddress = 0;
    u32VerifyFlashAddress = 0;
    for(u32PageNumber=0; u32PageNumber<TEST_NUMBER; u32PageNumber++)
    {
        printf("\n\nTest Page Number = %d", u32PageNumber);
        Show_Seven_Segment(u32PageNumber,1);
        CLK_SysTickDelay(200000);

        /*=== Program SPI Flash ===*/
        printf("\n Flash Programming... ");

        /* Trigger PDMA specified Channel */
        PDMA_CH1->CSR |= (PDMA_CSR_TRIG_EN_Msk | PDMA_CSR_PDMACEN_Msk);

        /* Page Program */
        SpiFlash_w_PDMA_PageProgram(u32ProgramFlashAddress, 256);
        SpiFlash_w_PDMA_WaitReady();
        u32ProgramFlashAddress += 0x100;
        printf("Done!");

        /*=== Read Back and Compare Data ===*/
        printf("\n Flash Verifying... ");

        /* Trigger PDMA specified Channel */
        PDMA_CH2->CSR |= (PDMA_CSR_TRIG_EN_Msk | PDMA_CSR_PDMACEN_Msk);

        /* Page Read */
        SpiFlash_w_PDMA_ReadData(u32VerifyFlashAddress, 256);
        u32VerifyFlashAddress += 0x100;

        for(u32ByteCount=0; u32ByteCount<256; u32ByteCount++)
        {
            if(DestArray[u32ByteCount]!=u32ByteCount)
            {
                /* Error */
                printf("\n\nSPI Flash R/W Fail!");
                while(1);
            }
        }

        /* Clear Destination Data Buffer */
        for(u32ByteCount=0; u32ByteCount<256; u32ByteCount++)
            DestArray[u32ByteCount] = 0;
        printf("Done!");
    }

    printf("\n\nSPI Flash with PDMA Test Ok!");
    printf("\n\n");

    while(1);

}
Exemplo n.º 17
0
//=========================================================================
// Additional initialisations
//-------------------------------------------------------------------------
__myevic__ void CustomStartup()
{

//-------------------------------------------------------------------------
// EADC test

	if ( 0 )
	{
		uint32_t s1, s2, s3;

		SetADCState( 0, 1 );
		SetADCState( 4, 1 );

		do
		{
			ClearScreenBuffer();

			CLK_SysTickDelay( 10 );
			s3 = ADC_Read( 4 );

			CLK_SysTickDelay( 10 );
			s1 = ADC_Read( 18 );

			CLK_SysTickDelay( 10 );
			s2 = ADC_Read( 0 );

			DrawValue( 8,  0, s1, 0, 0x29, 4 );
			DrawValue( 8, 20, s2, 0, 0x29, 4 );
			DrawValue( 8, 40, s3, 0, 0x29, 4 );

			DisplayRefresh();

			WaitOnTMR2( 1000 );
		}
		while ( PD3 );
	}


//-------------------------------------------------------------------------
// Timer test 1

	if ( 0 )
	{
		TIMER_Stop( TIMER3 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		gPlayfield.ul[1] =
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}


//-------------------------------------------------------------------------
// Timer test 2

	if ( 0 )
	{
		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		MemClear( gPlayfield.uc, 256 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HXT, 0 );
		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_LIRC, 0 );

		CLK_EnableModuleClock( TMR2_MODULE );
		CLK_EnableModuleClock( TMR3_MODULE );

		__set_PRIMASK(1);

		TIMER3->CTL |= TIMER_CTL_RSTCNT_Msk;
		TIMER2->CTL |= TIMER_CTL_RSTCNT_Msk;

		TIMER3->CMP  = 1000;

		TIMER3->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_ONESHOT_MODE;
		TIMER2->CTL  = TIMER_CTL_CNTEN_Msk | TIMER_CONTINUOUS_MODE;
		while(!(TIMER3->INTSTS & TIMER_INTSTS_TIF_Msk));
		TIMER2->CTL = 0;

		gPlayfield.ul[0] = TIMER2->CNT;

		__set_PRIMASK(0);

		TIMER_Close( TIMER2 );
		TIMER_Close( TIMER3 );

		CLK_SetModuleClock( TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HIRC, 0 );
		CLK_EnableModuleClock( TMR2_MODULE );
		TIMER_Open( TIMER2, TIMER_PERIODIC_MODE, 1000 );
		TIMER_EnableInt( TIMER2 );
		TIMER_Start( TIMER2 );

		CLK_SetModuleClock( TMR3_MODULE, CLK_CLKSEL1_TMR3SEL_HXT, 0 );
		CLK_EnableModuleClock( TMR3_MODULE );
		TIMER_Open( TIMER3, TIMER_PERIODIC_MODE, 10 );
		TIMER_EnableInt( TIMER3 );
		TIMER_Start( TIMER3 );
	}

	return;
}
Exemplo n.º 18
0
int32_t main (void)
{
    int tdelay=1000000;
    /* Init System, IP clock and multi-function I/O */
    SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

    /* Init UART0 for printf */
    UART0_Init();
    printf("\n\nCPU @ %dHz\n", SystemCoreClock);

    /*
        This sample code will Output module clock from PC.0 pin.
    */

    printf("+-----------------------------------------+\n");
    printf("| Nano100 Module Clock Output Sample Code |\n");
    printf("+-----------------------------------------+\n");

    /* Enable PLL clock and set PLL clock to 48Mhz */
    CLK_EnablePLL(CLK_PLLCTL_PLL_SRC_HIRC,48000000);

    CLK->MCLKO |= CLK_MCLKO_MCLK_EN_Msk ;
    printf("This sample code will Output module clock from PC.0 pin.\n");
    while(1)
    {
        printf("MCLK output = ISP_CLK\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_ISP_CLK;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = HIRC\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_HIRC;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = HXT\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_HXT;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = LXT\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_LXT;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = LIRC\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_LIRC;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = PLL ouptut\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_PLLO;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = PLL input\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_PLLI;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = sytem tick \n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_SYSTICK;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = HCLK\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_ISP_CLK;
        CLK_SysTickDelay(tdelay);

        printf("MCLK output = PCLK\n");
        CLK->MCLKO = (CLK->MCLKO & ~CLK_MCLKO_MCLK_SEL_Msk) | CLK_MCLKO_MCLK_SEL_PCLK;
        CLK_SysTickDelay(tdelay);
    }
}