/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* GPIO clock enable */ rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOC); rcu_periph_clock_enable(RCU_GPIOF); /* delay time initialize */ systick_config(); /* configure the CEC peripheral */ cec_config(); /* configure the EXTI */ gd_eval_keyinit(KEY_TAMPER, KEY_MODE_EXTI); #ifdef GD32F130_150 gd_eval_keyinit(KEY_USER, KEY_MODE_EXTI); #elif defined(GD32F170_190) gd_eval_keyinit(KEY_WAKEUP, KEY_MODE_EXTI); #endif /* GD32F130_150 */ /* LED1 LED2 initialize */ gd_eval_ledinit(LED1); gd_eval_ledinit(LED2); gd_eval_ledoff(LED1); gd_eval_ledoff(LED2); /* main loop */ while(1) { /* wait receive data */ while(rcvstatus==0); if(rcvstatus == 1) { if((rcvdata[1]==0xA5)&&(rcvdata[2]==0x5A)) { gd_eval_ledon(LED1); delay_1ms(10); gd_eval_ledoff(LED1); } if((rcvdata[1]==0x5A)&&(rcvdata[2]==0xA5)) { gd_eval_ledon(LED2); delay_1ms(10); gd_eval_ledoff(LED2); } } /* a reception error occured */ rcvstatus = 0; } }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* system clocks configuration */ irc40k_config(); systick_config(); gd_eval_ledinit(LED2); gd_eval_keyinit(KEY_TAMPER,KEY_MODE_EXTI); delay_1ms(50); /* enable write access to FWDGT_PSC and FWDGT_RLD registers. FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */ fwdgt_config(625,FWDGT_PSC_DIV64); fwdgt_enable(); /* check if the system has resumed from FWDGT reset */ if (RESET != rcu_flag_get(RCU_FLAG_FWDGTRST)){ gd_eval_ledon(LED2); rcu_reset_flag_clear(); while(1); }else{ gd_eval_ledoff(LED2); } while (1); }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { can_parameter_struct can_init_parameter; can_filter_parameter_struct can_filter_parameter; receive_flag = RESET; /* configure Tamper key */ gd_eval_keyinit(KEY_TAMPER, KEY_MODE_GPIO); /* configure GPIO */ gpio_config(); /* configure USART */ gd_eval_COMinit(EVAL_COM2); /* configure NVIC */ nvic_config(); /* configure leds */ led_config(); /* set all leds off */ gd_eval_ledoff(LED1); gd_eval_ledoff(LED2); gd_eval_ledoff(LED3); gd_eval_ledoff(LED4); /* initialize CAN */ can_networking_init(can_init_parameter, can_filter_parameter); /* enable phy */ #ifdef CAN0_USED can_phy_enable(CANX); #endif /* enable CAN receive FIFO0 not empty interrupt */ can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0); /* initialize transmit message */ transmit_message.can_tx_sfid = 0x321; transmit_message.can_tx_efid = 0x01; transmit_message.can_tx_ft = CAN_FT_DATA; transmit_message.can_tx_ff = CAN_FF_STANDARD; transmit_message.can_tx_dlen = 1; printf("please press the Tamper key to transmit data!\r\n"); while(1){ /* waiting for the Tamper key pressed */ while(0 == gd_eval_keygetstate(KEY_TAMPER)){ /* if transmit_number is 0x10, set it to 0x00 */ if(transmit_number == 0x10){ transmit_number = 0x00; }else{ transmit_message.can_tx_data[0] = transmit_number++; printf("transmit data: %x\r\n", transmit_message.can_tx_data[0]); /* transmit message */ can_transmit_message(CANX, &transmit_message); delay(); /* waiting for Tamper key up */ while(0 == gd_eval_keygetstate(KEY_TAMPER)); } } if(SET == receive_flag){ gd_eval_ledtoggle(LED1); receive_flag = RESET; printf("recive data: %x\r\n", receive_message.can_rx_data[0]); } } }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* systick config */ systick_config(); /* led config */ led_config(); /* clock enable */ rcu_periph_clock_enable(RCU_PMU); /* wakeup key config */ gd_eval_keyinit(KEY_WAKEUP,KEY_MODE_GPIO); /* tamper key EXTI config */ gd_eval_keyinit(KEY_TAMPER,KEY_MODE_EXTI); /* press wakeup key to enter deepsleep mode and use tamper key generate a exti interrupt to wakeup mcu */ while(1){ if(RESET == gpio_input_bit_get(WAKEUP_KEY_GPIO_PORT,WAKEUP_KEY_PIN)) pmu_to_deepsleepmode(PMU_LDO_LOWPOWER,WFI_CMD); } }
void LOS_EvbKeyInit(void) { #ifdef GD32F150R8 /* configure User key */ gd_eval_keyinit(KEY_USER, KEY_MODE_GPIO); gd_eval_ledinit(LED1); #endif return; }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { systick_config(); gd_eval_ledinit(LED1); gd_eval_keyinit(KEY_TAMPER,KEY_MODE_GPIO); while(1){ /* check whether the button is pressed */ if(RESET == gd_eval_keygetstate(KEY_TAMPER)){ delay_1ms(100); /* check whether the button is pressed */ if(RESET == gd_eval_keygetstate(KEY_TAMPER)){ gd_eval_ledtoggle(LED1); } } } }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* clock enable */ rcu_periph_clock_enable(RCU_PMU); /* led configuration and turn on all led */ led_config(); gd_eval_ledon(LED1); gd_eval_ledon(LED3); gd_eval_ledon(LED2); gd_eval_ledon(LED4); /* tamper key configuration */ gd_eval_keyinit(KEY_TAMPER,KEY_MODE_GPIO); /* wakeup pin enable */ pmu_wakeup_pin_enable(PMU_WAKEUP_PIN0); /* press tamper key to enter standby mode and use wakeup key to wakeup mcu */ while(1){ if(RESET == gpio_input_bit_get(TAMPER_KEY_GPIO_PORT,TAMPER_KEY_PIN)) pmu_to_stdbymode(WFI_CMD); } }
/***************************************************************************** Function : LOS_EvbUartInit Description : enable the device on the dev baord Input : None Output : None Return : None *****************************************************************************/ void LOS_EvbUartInit(void) { #ifdef GD32F150R8 /* initialize the LEDs */ led_init(); /* configure systick */ //systick_config(); /* flash the LEDs for 1 time */ led_flash(1); /* configure EVAL_COM2 */ gd_eval_COMinit(EVAL_COM1); /* configure TAMPER key */ gd_eval_keyinit(KEY_WAKEUP, KEY_MODE_GPIO); #endif return; }