Skip to content

Instantly share code, notes, and snippets.

@OrsoEric
Created August 2, 2020 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrsoEric/26d0a186bc7d59ab6ec0f87b92817d18 to your computer and use it in GitHub Desktop.
Save OrsoEric/26d0a186bc7d59ab6ec0f87b92817d18 to your computer and use it in GitHub Desktop.
Longan Nano RTC PA8 Interrupts
/****************************************************************************
** OrangeBot Project
*****************************************************************************
** /
** /
** /
** ______ \
** \
** \
*****************************************************************************
** Longan Nano Example - Blink RTC IST
*****************************************************************************
** Author: Orso Eric
** Version:
****************************************************************************/
/****************************************************************************
** DESCRIPTION
*****************************************************************************
** Blink the LEDs using the interrupt service rutine generated by the RTC timer
****************************************************************************/
/****************************************************************************
** HYSTORY VERSION
*****************************************************************************
** 2020-07-05
** Interrupt Service Routine working!
** 2020-07-06
** Format source code
****************************************************************************/
/****************************************************************************
** KNOWN BUG
*****************************************************************************
**
****************************************************************************/
/****************************************************************************
** INCLUDE
****************************************************************************/
#include <gd32vf103.h>
//Onboard RBG LEDs of the Longan Nano
#include "longan_nano_led.hpp"
/****************************************************************************
** NAMESPACES
****************************************************************************/
//using namespace std;
/****************************************************************************
** DEFINES
****************************************************************************/
//forEVER
#define EVER (;;)
/****************************************************************************
** GLOBAL VARIABILE
****************************************************************************/
/****************************************************************************
** FUNCTION PROTOTYPES
****************************************************************************/
//Initialize the board
extern bool init( void );
//Busy delay using the SysTick timer
extern void delay_us(unsigned int us);
/****************************************************************************
** FUNCTION
****************************************************************************/
/***************************************************************************/
//! @brief maim
//! main | void
/***************************************************************************/
//! @param delay | unsigned int | how long to wait for in microseconds
//! @return void |
//! @details \n
//! Handles the ISR lines generated by the GPIO lines 5 to 9
/***************************************************************************/
int main( void )
{
//----------------------------------------------------------------
// VARS
//----------------------------------------------------------------
bool f_ret = false;
//----------------------------------------------------------------
// INIT
//----------------------------------------------------------------
//Initialize the board and return success status
f_ret |= init();
//----------------------------------------------------------------
// MAIN LOOP
//----------------------------------------------------------------
for EVER
{
//Toggle the RED LED
//Longan_nano::Leds::toggle( Longan_nano::Led_color::RED );
//2Hz blink
//delay_us(250000);
}
//----------------------------------------------------------------
// RETURN
//----------------------------------------------------------------
return 0;
} //End function: main
/***************************************************************************/
//! @brief utility
//! delay_us
/***************************************************************************/
//! @param delay | unsigned int | how long to wait for in microseconds
//! @return void |
//! @details \n
//! Use the SysTic timer counter to busy wait for the correct number of microseconds
/***************************************************************************/
void delay_us(unsigned int delay)
{
//----------------------------------------------------------------
// VARS
//----------------------------------------------------------------
uint64_t start_mtime, delta_mtime;
//----------------------------------------------------------------
// BODY
//----------------------------------------------------------------
// Wait for the first tick
// Wait for the correct number of ticks
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/4000000.0 *delay ));
//----------------------------------------------------------------
// RETURN
//----------------------------------------------------------------
return;
} //End function: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment