Skip to content

Commit

Permalink
[sw] update example programs
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Jan 6, 2024
1 parent 47fd737 commit 3871dc8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions sw/example/demo_dma/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// # ********************************************************************************************* #
// # BSD 3-Clause License #
// # #
// # Copyright (c) 2023, Stephan Nolting. All rights reserved. #
// # Copyright (c) 2024, Stephan Nolting. All rights reserved. #
// # #
// # Redistribution and use in source and binary forms, with or without modification, are #
// # permitted provided that the following conditions are met: #
Expand Down Expand Up @@ -223,8 +223,8 @@ int main() {

// configure GPTMR
neorv32_gptmr_setup(CLK_PRSC_2, // GPTM clock = 1/2 main clock
0, // single-shot mode
2000); // counter to threshold for triggering IRQ
4096, // counter threshold for triggering IRQ
1); // enable timer-match interrupt

// configure transfer type
cmd = DMA_CMD_B2B | // read source in byte quantities, write destination in byte quantities
Expand Down Expand Up @@ -283,5 +283,6 @@ void show_arrays(void) {
void dma_firq_handler(void) {

neorv32_cpu_csr_clr(CSR_MIP, 1 << DMA_FIRQ_PENDING); // clear/ack pending FIRQ
neorv32_gptmr_disable(); // disable GPTMR
neorv32_uart0_printf("<<DMA interrupt>>\n");
}
12 changes: 6 additions & 6 deletions sw/example/demo_gptmr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// # ********************************************************************************************* #
// # BSD 3-Clause License #
// # #
// # Copyright (c) 2023, Stephan Nolting. All rights reserved. #
// # Copyright (c) 2024, Stephan Nolting. All rights reserved. #
// # #
// # Redistribution and use in source and binary forms, with or without modification, are #
// # permitted provided that the following conditions are met: #
Expand Down Expand Up @@ -36,7 +36,7 @@
/**********************************************************************//**
* @file demo_gptmr/main.c
* @author Stephan Nolting
* @brief Simple GPTMR usage example.
* @brief Simple GPTMR timer-match interrupt example.
**************************************************************************/

#include <neorv32.h>
Expand All @@ -63,7 +63,7 @@ void gptmr_firq_handler(void);
* @return Should not return;
**************************************************************************/
int main() {

// setup NEORV32 runtime environment (for trap handling)
neorv32_rte_setup();

Expand All @@ -79,7 +79,7 @@ int main() {

// Intro
neorv32_uart0_puts("General purpose timer (GPTMR) demo Program.\n"
"Toggles GPIO.output(0) at 1Hz using the GPTMR interrupt.\n\n");
"Toggles GPIO.output(0) at 1Hz using the GPTMR timer-match interrupt.\n\n");


// clear GPIO output port
Expand All @@ -89,8 +89,8 @@ int main() {
// install GPTMR interrupt handler
neorv32_rte_handler_install(GPTMR_RTE_ID, gptmr_firq_handler);

// configure timer for 1Hz ticks in continuous mode (with clock divisor = 8)
neorv32_gptmr_setup(CLK_PRSC_8, 1, NEORV32_SYSINFO->CLK / (8 * 2));
// configure timer for 1Hz ticks with clock divisor = 8 and enable timer-match interrupt
neorv32_gptmr_setup(CLK_PRSC_8, NEORV32_SYSINFO->CLK / (8 * 2), 1);

// enable interrupt
neorv32_cpu_csr_clr(CSR_MIP, 1 << GPTMR_FIRQ_PENDING); // make sure there is no GPTMR IRQ pending already
Expand Down
15 changes: 10 additions & 5 deletions sw/example/processor_check/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// # ********************************************************************************************* #
// # BSD 3-Clause License #
// # #
// # Copyright (c) 2023, Stephan Nolting. All rights reserved. #
// # Copyright (c) 2024, Stephan Nolting. All rights reserved. #
// # #
// # Redistribution and use in source and binary forms, with or without modification, are #
// # permitted provided that the following conditions are met: #
Expand Down Expand Up @@ -1555,22 +1555,27 @@ int main() {
// enable GPTMR FIRQ
neorv32_cpu_irq_enable(GPTMR_FIRQ_ENABLE);

// configure timer IRQ for one-shot mode after CLK_PRSC_2*2=4 clock cycles
neorv32_gptmr_setup(CLK_PRSC_2, 0, 2);
// match-interrupt after CLK_PRSC_2*THRESHOLD = 2*2 = 8 clock cycles
neorv32_gptmr_setup(CLK_PRSC_2, 2, 1);

// wait for interrupt
asm volatile ("nop");
asm volatile ("nop");

neorv32_cpu_csr_write(CSR_MIE, 0);

// check if IRQ
if (neorv32_cpu_csr_read(CSR_MCAUSE) == GPTMR_TRAP_CODE) {
if ((neorv32_cpu_csr_read(CSR_MCAUSE) == GPTMR_TRAP_CODE) && // correct interrupt?
(neorv32_gptmr_trigger_matched() == 1) && // IRQ caused by timer match?
(neorv32_gptmr_trigger_captured() == 0)) { // no capture trigger?
test_ok();
}
else {
test_fail();
}

// disable GPTMR
neorv32_gptmr_disable();

}
else {
PRINT_STANDARD("[n.a.]\n");
Expand Down

0 comments on commit 3871dc8

Please sign in to comment.