summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorMegan Wachs <megan@sifive.com>2016-12-12 11:42:14 -0800
committerAlbert Ou <albert@sifive.com>2016-12-13 17:53:56 -0800
commit546b9e62d3efd2c4dd021f5592d04c1c98ceda7f (patch)
treecf7a53a3ad711f06123274968aaba8cbf8e6076f /software
parent85c0fe762ba9bccf5aa0fd31d8012c958cbf658e (diff)
Correct ifdef guards for HiFive1 demo_gpio
Diffstat (limited to 'software')
-rw-r--r--software/demo_gpio/demo_gpio.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c
index f568ae8..dec91b5 100644
--- a/software/demo_gpio/demo_gpio.c
+++ b/software/demo_gpio/demo_gpio.c
@@ -49,26 +49,26 @@ void handle_m_ext_interrupt(){
void handle_m_time_interrupt(){
clear_csr(mie, MIP_MTIP);
-
+
// Reset the timer for 3s in the future.
// This also clears the existing timer interrupt.
-
+
volatile uint64_t * mtime = (uint64_t*) (CLINT_BASE_ADDR + CLINT_MTIME);
volatile uint64_t * mtimecmp = (uint64_t*) (CLINT_BASE_ADDR + CLINT_MTIMECMP);
uint64_t now = *mtime;
uint64_t then = now + 1.5 * RTC_FREQUENCY;
*mtimecmp = then;
-
+
// read the current value of the LEDS and invert them.
uint32_t leds = *g_output_vals;
-
+
*g_output_vals ^= ((0x1 << RED_LED_OFFSET) |
(0x1 << GREEN_LED_OFFSET) |
(0x1 << BLUE_LED_OFFSET));
-
+
// Re-enable the timer interrupt.
set_csr(mie, MIP_MTIP);
-
+
}
@@ -105,18 +105,18 @@ Every 1.5 second, the Timer Interrupt will invert the LEDs.\n\
";
void print_instructions() {
-
+
write (STDOUT_FILENO, instructions_msg, strlen(instructions_msg));
-
+
}
+#ifdef HAS_BOARD_BUTTONS
void button_0_handler(void) {
// Red LED on
* g_output_vals |= (0x1 << RED_LED_OFFSET);
-
- // Clear the GPIO Pending interrupt by writing 1.
+ // Clear the GPIO Pending interrupt by writing 1.
GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_0_OFFSET);
};
@@ -126,25 +126,26 @@ void button_1_handler(void) {
// Green LED On
* g_output_vals |= (1 << GREEN_LED_OFFSET);
+ // Clear the GPIO Pending interrupt by writing 1.
GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_1_OFFSET);
-
+
};
-
+
void button_2_handler(void) {
// Blue LED On
* g_output_vals |= (1 << BLUE_LED_OFFSET);
GPIO_REG(GPIO_RISE_IP) = (0x1 << BUTTON_2_OFFSET);
-
-};
+};
+#endif
void reset_demo (){
- // Disable the machine & timer interrupts until setup is done.
-
+ // Disable the machine & timer interrupts until setup is done.
+
clear_csr(mie, MIP_MEIP);
clear_csr(mie, MIP_MTIP);
@@ -157,7 +158,7 @@ void reset_demo (){
g_ext_interrupt_handlers[INT_DEVICE_BUTTON_1] = button_1_handler;
g_ext_interrupt_handlers[INT_DEVICE_BUTTON_2] = button_2_handler;
#endif
-
+
print_instructions();
#ifdef HAS_BOARD_BUTTONS
@@ -172,13 +173,13 @@ void reset_demo (){
PLIC_set_priority(&g_plic, INT_DEVICE_BUTTON_0, 1);
PLIC_set_priority(&g_plic, INT_DEVICE_BUTTON_1, 1);
PLIC_set_priority(&g_plic, INT_DEVICE_BUTTON_2, 1);
-
+
GPIO_REG(GPIO_RISE_IE) |= (1 << BUTTON_0_OFFSET);
GPIO_REG(GPIO_RISE_IE) |= (1 << BUTTON_1_OFFSET);
GPIO_REG(GPIO_RISE_IE) |= (1 << BUTTON_2_OFFSET);
-
+
#endif
-
+
// Set the machine timer to go off in 3 seconds.
// The
volatile uint64_t * mtime = (uint64_t*) (CLINT_BASE_ADDR + CLINT_MTIME);
@@ -186,13 +187,13 @@ void reset_demo (){
uint64_t now = *mtime;
uint64_t then = now + 1.5*RTC_FREQUENCY;
*mtimecmp = then;
-
+
// Enable the Machine-External bit in MIE
set_csr(mie, MIP_MEIP);
// Enable the Machine-Timer bit in MIE
set_csr(mie, MIP_MTIP);
-
+
// Enable interrupts in general.
set_csr(mstatus, MSTATUS_MIE);
}
@@ -207,7 +208,7 @@ int main(int argc, char **argv)
* g_pullup_en &= ~((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));
* g_input_en |= ((0x1 << BUTTON_0_OFFSET) | (0x1 << BUTTON_1_OFFSET) | (0x1 << BUTTON_2_OFFSET));
#endif
-
+
* g_input_en &= ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
* g_output_en |= ((0x1<< RED_LED_OFFSET)| (0x1<< GREEN_LED_OFFSET) | (0x1 << BLUE_LED_OFFSET)) ;
* g_output_vals |= (0x1 << BLUE_LED_OFFSET) ;
@@ -215,7 +216,7 @@ int main(int argc, char **argv)
/**************************************************************************
* Set up the PLIC
- *
+ *
*************************************************************************/
PLIC_init(&g_plic,
PLIC_BASE_ADDR,