diff options
| author | Megan Wachs <megan@sifive.com> | 2017-01-24 16:00:53 -0800 | 
|---|---|---|
| committer | Megan Wachs <megan@sifive.com> | 2017-01-24 16:00:53 -0800 | 
| commit | c72e4fcd4a77354d0d427cef263ebe438aeeae6e (patch) | |
| tree | 996dd96b8143ea68b75a1147faf67db25fc7560f /software | |
| parent | e57c482625638fc10d90eab282c77fd410c9b46d (diff) | |
Add atomic bit-banging to the demo
Diffstat (limited to 'software')
| -rw-r--r-- | software/demo_gpio/demo_gpio.c | 17 | 
1 files changed, 16 insertions, 1 deletions
diff --git a/software/demo_gpio/demo_gpio.c b/software/demo_gpio/demo_gpio.c index c780cbe..040d864 100644 --- a/software/demo_gpio/demo_gpio.c +++ b/software/demo_gpio/demo_gpio.c @@ -7,6 +7,7 @@  #include "plic_driver.h"  #include "encoding.h"  #include <unistd.h> +#include "stdatomic.h"  #define RTC_FREQUENCY 32768 @@ -95,6 +96,8 @@ const char * instructions_msg = " \  SiFive E-Series Software Development Kit 'demo_gpio' program.\n\  Every 1.5 second, the Timer Interrupt will invert the LEDs.\n\  (Arty Dev Kit Only): Press Buttons 0, 1, 2 to Set the LEDs.\n\ +Pin 19 (HiFive1) or A5 (Arty Dev Kit) is being bit-banged\n\ +for GPIO speed demonstration.\n\  \n\   "; @@ -208,6 +211,9 @@ int main(int argc, char **argv)    GPIO_REG(GPIO_OUTPUT_VAL)  |=   (0x1 << BLUE_LED_OFFSET) ;    GPIO_REG(GPIO_OUTPUT_VAL)  &=  ~((0x1<< RED_LED_OFFSET) | (0x1<< GREEN_LED_OFFSET)) ; +  // For Bit-banging with Atomics demo. +  GPIO_REG(GPIO_OUTPUT_EN)   |= (0x1 << PIN_19_OFFSET); +     /**************************************************************************     * Set up the PLIC     * @@ -219,8 +225,17 @@ int main(int argc, char **argv)    reset_demo(); -  while (1){ +  /************************************************************************** +   * Demonstrate fast GPIO bit-banging. +   * One can bang it faster than this if you know +   * the entire OUTPUT_VAL that you want to write, but  +   * Atomics give a quick way to control a single bit. +   *************************************************************************/ +  uint32_t  mask = (1 << PIN_19_OFFSET); +  uint32_t  other_mask = (1 << PIN_19_OFFSET); +  while (1){ +    atomic_fetch_xor(&GPIO_REG(GPIO_OUTPUT_VAL), mask);    }    return 0;  | 
