Line 1... |
Line 1... |
// #################################################################################################
|
// #################################################################################################
|
// # << NEORV32 - General Purpose Timer (GPTMR) Demo Program >> #
|
// # << NEORV32 - General Purpose Timer (GPTMR) Demo Program >> #
|
// # ********************************************************************************************* #
|
// # ********************************************************************************************* #
|
// # BSD 3-Clause License #
|
// # BSD 3-Clause License #
|
// # #
|
// # #
|
// # Copyright (c) 2021, Stephan Nolting. All rights reserved. #
|
// # Copyright (c) 2022, Stephan Nolting. All rights reserved. #
|
// # #
|
// # #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
// # permitted provided that the following conditions are met: #
|
// # permitted provided that the following conditions are met: #
|
// # #
|
// # #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
Line 56... |
Line 56... |
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* This program blinks an LED at GPIO.output(0) at 1Hz using the general purpose timer interrupt.
|
* This program blinks an LED at GPIO.output(0) at 1Hz using the general purpose timer interrupt.
|
*
|
*
|
* @note This program requires the GPTMR unit to be synthesized.
|
* @note This program requires the GPTMR unit to be synthesized (and UART0 and GPIO).
|
*
|
*
|
* @return Should not return;
|
* @return Should not return;
|
**************************************************************************/
|
**************************************************************************/
|
int main() {
|
int main() {
|
|
|
// capture all exceptions and give debug info via UART
|
// capture all exceptions and give debug info via UART
|
neorv32_rte_setup();
|
neorv32_rte_setup();
|
|
|
// init UART at default baud rate, no parity bits, ho hw flow control
|
// init UART at default baud rate, no parity bits, no HW flow control
|
neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
|
neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
|
|
|
|
|
// check if GPTMR unit is implemented at all
|
// check if GPTMR unit is implemented at all
|
if (neorv32_gptmr_available() == 0) {
|
if (neorv32_gptmr_available() == 0) {
|
neorv32_uart0_print("General purpose timer not implemented!\n");
|
neorv32_uart0_print("ERROR! General purpose timer not implemented!\n");
|
return 1;
|
return 1;
|
}
|
}
|
|
|
// Intro
|
// Intro
|
neorv32_uart0_print("General purpose timer (GPTMR) demo Program.\n"
|
neorv32_uart0_print("General purpose timer (GPTMR) demo Program.\n"
|
Line 87... |
Line 87... |
|
|
|
|
// install GPTMR interrupt handler
|
// install GPTMR interrupt handler
|
neorv32_rte_exception_install(GPTMR_RTE_ID, gptmr_firq_handler);
|
neorv32_rte_exception_install(GPTMR_RTE_ID, gptmr_firq_handler);
|
|
|
// configure timer for 1Hz in continuous mode
|
// configure timer for 1Hz ticks in continuous mode (with clock divisor = 8)
|
uint32_t soc_clock = NEORV32_SYSINFO.CLK;
|
neorv32_gptmr_setup(CLK_PRSC_8, 1, NEORV32_SYSINFO.CLK / (8 * 2));
|
soc_clock = soc_clock / 2; // divide by two as we are using the 1/2 clock prescaler
|
|
neorv32_gptmr_setup(CLK_PRSC_2, 1, soc_clock);
|
|
|
|
// enable interrupt
|
// enable interrupt
|
neorv32_cpu_irq_enable(GPTMR_FIRQ_ENABLE); // enable GPTRM FIRQ channel
|
neorv32_cpu_irq_enable(GPTMR_FIRQ_ENABLE); // enable GPTMR FIRQ channel
|
neorv32_cpu_eint(); // enable global interrupt flag
|
neorv32_cpu_eint(); // enable global interrupt flag
|
|
|
|
|
// do nothing, wait for interrupt
|
// go to sleep mode and wait for interrupt
|
while(1);
|
while(1) {
|
|
neorv32_cpu_sleep();
|
|
}
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
Line 113... |
Line 113... |
**************************************************************************/
|
**************************************************************************/
|
void gptmr_firq_handler(void) {
|
void gptmr_firq_handler(void) {
|
|
|
neorv32_cpu_csr_write(CSR_MIP, 1<<GPTMR_FIRQ_PENDING); // clear/ack pending FIRQ
|
neorv32_cpu_csr_write(CSR_MIP, 1<<GPTMR_FIRQ_PENDING); // clear/ack pending FIRQ
|
|
|
neorv32_uart0_putc('.'); // send tick symbol via UART
|
neorv32_uart0_putc('.'); // send tick symbol via UART0
|
neorv32_gpio_pin_toggle(0); // toggle output port bit 0
|
neorv32_gpio_pin_toggle(0); // toggle output port bit 0
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|