示例#1
0
/* CG_ModeSwitch function */
void CG_ModeSwitch(void)
{
    /* Initialize system */
    CG_SetSystem();
    SW_Init();
    LED_Init();
    LED_On(LED0);
    /* set INT0 as interrupt source */
    TSB_PG->FR1 |= 0x08;
    TSB_PG->IE |= 0x08;
    while (1) {

        if (SW_Get(SW0) == 1U) {
            fSysSleep = SLEEP;
            LED_Off(LED0);

            CG_NormalToStop1();

            /* Connect PG3 to VCC to recover from STOP mode */
            LED_On(LED0);
            fSysSleep = WAKE;
            NVIC_DisableIRQ(INT0_IRQn);

        } else {
            LED_On(LED2);
        }
    }

}
示例#2
0
文件: main.c 项目: coocox/Mplib
/**
  * @brief  main function of flash demo
  * @param  None.
  * @retval result to return to system.
  */
int main(void)
{
    #define ERROR_DELAY     1000000U
    #define SUCCESS_DELAY   4000000U
    Result tmp = ERROR;
    uint8_t Flag_1st = 0U;
    
    LED_Init();
    SW_Init();
    while (1U) {
        if(Flag_1st == 0U && SW_Get(SW0)) {   /* if SW0 is turned on 1st time*/ 
            Flag_1st = 1U;
            Copy_Routine(FLASH_API_RAM, FLASH_API_ROM, SIZE_FLASH_API);
            tmp = Flash_Write();
        } else {
        	 /* Do nothing */
        }
        if(tmp== SUCCESS)
        {
            LED_On(LED1);
            delay(SUCCESS_DELAY);
            LED_Off(LED1);
            delay(SUCCESS_DELAY);
        } else {
            LED_On(LED1);
            delay(ERROR_DELAY);
            LED_Off(LED1);
            delay(ERROR_DELAY);
        }
    }
}
示例#3
0
/* main function */
void Example_LED_KEY(void)
{
    LED_Init();
    SW_Init();
    for (;;) {
      if (SW_Get(SW0)||SW_Get(SW4)){
        LED_On(LED0);
       }else{
       	LED_Off(LED0);
       }
      if (SW_Get(SW1)||SW_Get(SW5)){
        LED_On(LED1);
       }else{
       	LED_Off(LED1);
       }
      if (SW_Get(SW2)||SW_Get(SW6)){
        LED_On(LED2);
       }else{
       	LED_Off(LED2);
       }
      if (SW_Get(SW3)||SW_Get(SW7)){
        LED_On(LED3);
       }else{
       	LED_Off(LED3);
       }
}
}
示例#4
0
/**
  * @brief  The main function of TMRB_PPG demo
  * @param  None
  * @retval None
  */
void Example_TMRB_PPG(void)
{

    uint32_t Duty[5] = { 0x1194U, 0xEA6U, 0x9C4U, 0x4E2U, 0x1F4U };     /* duty: 10%, 25%, 50%, 75%, 90% */
    uint8_t keyvalue;

    TMRB_InitTypeDef m_tmrb;
    TMRB_FFOutputTypeDef PPGFFInital;

    /* LCD & switch initialization */
    LCD_Configuration();
    SW_Init();

    /* Set PA5 as TB6OUT for PPG output */
    GPIO_SetOutput(GPIO_PA, GPIO_BIT_5);
    GPIO_EnableFuncReg(GPIO_PA, GPIO_FUNC_REG_2, GPIO_BIT_5);

    m_tmrb.Mode = TMRB_INTERVAL_TIMER;
    m_tmrb.ClkDiv = TMRB_CLK_DIV_8;
    m_tmrb.UpCntCtrl = TMRB_AUTO_CLEAR;
    m_tmrb.Cycle = TMRB6TIME;   /* T = 500us */
    m_tmrb.Duty = Duty[Rate];
    PPGFFInital.FlipflopCtrl = TMRB_FLIPFLOP_CLEAR;
    PPGFFInital.FlipflopReverseTrg = TMRB_FLIPFLOP_MATCH_CYCLE | TMRB_FLIPFLOP_MATCH_DUTY;

    TMRB_Enable(TSB_TB6);
    TMRB_Init(TSB_TB6, &m_tmrb);
    TMRB_SetFlipFlop(TSB_TB6, &PPGFFInital);
    TMRB_SetDoubleBuf(TSB_TB6, ENABLE, TMRB_WRITE_REG_SEPARATE);        /* enable double buffer */
    TMRB_SetRunState(TSB_TB6, TMRB_RUN);

    do {                        /* Handle the condition that start with the SW0 is high*/
        keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0);
        duty_display();
    } while (GPIO_BIT_VALUE_1 == keyvalue);

    delay(0xFFFFU);             /* noise cancel */

    while (1) {       
        do {
            keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0);   /* display when switch is low */
            duty_display();
        } while (GPIO_BIT_VALUE_0 == keyvalue);
        delay(0xFFFFU);         /* noise cancel */
        Rate++;
        if (Rate >= DUTYMAX) {  /* change duty rate */
            Rate = DUTYINIT;
        } else {
            /* Do nothing */
        }
        TMRB_ChangeDuty(TSB_TB6, Duty[Rate]);
        do {
            keyvalue = GPIO_ReadDataBit(KEYPORT, GPIO_BIT_0);   /* display when switch is high */
            duty_display();
        } while (GPIO_BIT_VALUE_1  == keyvalue);
        delay(0xFFFFU);         /* noise cancel */
    }
}
示例#5
0
文件: main.c 项目: coocox/Mplib
int main(void)
{
    LED_Init();
    SW_Init();

    LCD_Configuration();
 
    if (Mode_Judgement() == USER_BOOT_MODE) {   /* if SW0 is turned on, enter user boot mode */

        LED_On(LED3);           /* enter user boot mode */
           
        LCD_Display("User Boot Mode", "");      /* enter user boot mode */
        LCD_Display("RAM transferring", "......");
      
        Copy_Routine(FLASH_API_RAM, FLASH_API_ROM, SIZE_FLASH_API);     /* copy flash API to RAM */
       
        LCD_Display("Flash swapping", "......");
     
        if (FC_SUCCESS == Flash_Swap()) {       /* swap the flash content */
            /* Do nothing */
        } else {
            LED_On(LED1 | LED2 | LED3); /* if have any error, turn on all leds */
              
            LCD_Display("Error", "");   /* if have any error, display error information */
          
        }

    } else {                    /* if SW1 is turned off, enter normal mode */
#if defined ( __CC_ARM   )      /* RealView Compiler */
        ResetSP();              /* reset SP */
#elif defined ( __ICCARM__ )    /* IAR Compiler */
        asm("MOV R0, #0");      /* reset SP */
        asm("LDR SP, [r0]");
#endif
        SCB->VTOR = DEMO_START_ADDR;    /* redirect vector table */
        startup = CODE_START;
        startup();              /* jump to code start address to run */

    }
    

    return 0;
}
示例#6
0
/**
  * @brief  The Flash_Userboot function to run flash userboot mode demo
  * @param  None.
  * @retval result to return to system.
  */
void Flash_Userboot(void)
{


    /* Initialize system */
    SIO_Configuration(UART0);
    SIO_ChInit();

    SW_Init();


    if (Mode_Judgement() == USER_BOOT_MODE) {   /* if SW0 is turned on, enter user boot mode */

        UART0_Print("User Boot Mode\n\r");      /* enter user boot mode */
        UART0_Print("RAM transferring\n\r");
        
        Copy_Routine(FLASH_API_RAM, FLASH_API_ROM, SIZE_FLASH_API);     /* copy flash API to RAM */
        
        UART0_Print("Flash swapping\n\r");
        
        if (FC_SUCCESS == Flash_Swap()) {       /* swap the flash content */
            /* Do nothing */
        } else {
            UART0_Print("Error\n\r");   /* if have any error, display error information */
        }

    } else {                    /* if SW0 is turned off, enter normal mode */

#if defined ( __CC_ARM   )      /* RealView Compiler */
        ResetSP();              /* reset SP */
#elif defined ( __ICCARM__ )    /* IAR Compiler */
        asm("MOV R0, #0");      /* reset SP */
        asm("LDR SP, [r0]");
#endif
        SCB->VTOR = DEMO_START_ADDR;    /* redirect vector table */
        startup = CODE_START;
        startup();              /* jump to code start address to run */
    }
  
}
示例#7
0
void Flash_Userboot(void)
{

    LED_Init();
    SW_Init();

    if (Mode_Judgement() == USER_BOOT_MODE) {   /* if SW0 is turned on, enter user boot mode */

        LED_On(LED2);           /* enter user boot mode */

        Copy_Routine(FLASH_API_RAM, FLASH_API_ROM, SIZE_FLASH_API);     /* copy flash API to RAM */

        if (FC_SUCCESS == Flash_Swap()) {       /* swap the flash content */
            /* Do nothing */
        } else {
            LED_On(LED0 | LED1 | LED3); /* if have any error, turn on all leds */

        }

    } else {                    /* if SW1 is turned off, enter normal mode */
#if defined ( __CC_ARM   )      /* RealView Compiler */
        ResetSP();              /* reset SP */
#elif defined ( __ICCARM__ )    /* IAR Compiler */

        asm("MOV R0, #0");      /* reset SP */
        asm("LDR SP, [r0]");
#endif
        SCB->VTOR = DEMO_START_ADDR;    /* redirect vector table */
        startup = CODE_START;
        startup();              /* jump to code start address to run */

    }



}
示例#8
0
文件: OS.c 项目: c0lin91/EE445M
int OS_AddSWTask(void(*task)(void), unsigned long priority, unsigned long sw){
	SW_Init(task, priority, sw);
	return 1;
}