#include "gd32vf103.h"
#include "systick.h"
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
uint64_t start_mtime, delta_mtime;
// Don't start measuruing until we see an mtime tick
uint64_t tmp = get_timer_value();
do {
start_mtime = get_timer_value();
} while (start_mtime == tmp);
do {
delta_mtime = get_timer_value() - start_mtime;
}while(delta_mtime <(SystemCoreClock/4000.0 *count ));
}
src/main.c
#include "gd32vf103.h"
#include "systick.h"
#include <stdio.h>
/* BUILTIN LED OF LONGAN BOARDS IS PIN PC13 */
#define LED_PIN GPIO_PIN_8
#define LED_GPIO_PORT GPIOA
#define LED_GPIO_CLK RCU_GPIOA
void longan_led_init()
{
/* enable the led clock */
rcu_periph_clock_enable(LED_GPIO_CLK);
/* configure led GPIO port */
gpio_init(LED_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED_PIN);
GPIO_BC(LED_GPIO_PORT) = LED_PIN;
}
void longan_led_on()
{
/*
* LED is hardwired with 3.3V on the anode, we control the cathode
* (negative side) so we need to use reversed logic: bit clear is on.
*/
GPIO_BC(LED_GPIO_PORT) = LED_PIN;
}
void longan_led_off()
{
GPIO_BOP(LED_GPIO_PORT) = LED_PIN;
}
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
longan_led_init();
while(1){
/* turn on builtin led */
longan_led_on();
delay_1ms(1000);
/* turn off uiltin led */
longan_led_off();
delay_1ms(1000);
}
}