aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-05-10 16:41:37 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-05-10 16:41:37 -0400
commit9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb (patch)
treec002f6a389e38576fec44777557e62064e342d02 /examples
parent19ea6ba4ea3f1ecb9830cf4d3e1366513f4f96e3 (diff)
downloadlibrambutan-9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb.tar.gz
librambutan-9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb.zip
Converting all files to UNIX newlines.
Committing the results of running the following on the libmaple root directory: $ fromdos `grep --exclude-dir='[.]git' -Ilsr $'\r$' .`
Diffstat (limited to 'examples')
-rw-r--r--examples/blinky.cpp64
-rw-r--r--examples/spi_master.cpp154
-rw-r--r--examples/test-fsmc.cpp250
3 files changed, 234 insertions, 234 deletions
diff --git a/examples/blinky.cpp b/examples/blinky.cpp
index 91d1a47..dd72514 100644
--- a/examples/blinky.cpp
+++ b/examples/blinky.cpp
@@ -1,32 +1,32 @@
-// Blinks the built-in LED
-
-#include "wirish.h"
-
-void setup() {
- pinMode(BOARD_LED_PIN, OUTPUT);
-}
-
-int toggle = 1;
-
-void loop() {
- // You could just use toggleLED() instead, but this illustrates
- // the use of digitalWrite():
- digitalWrite(BOARD_LED_PIN, toggle);
- toggle ^= 1;
- delay(100);
-}
-
-// Force init to be called *first*, i.e. before static object allocation.
-// Otherwise, statically allocated objects that need libmaple may fail.
-__attribute__((constructor)) void premain() {
- init();
-}
-
-int main(void) {
- setup();
-
- while (true) {
- loop();
- }
- return 0;
-}
+// Blinks the built-in LED
+
+#include "wirish.h"
+
+void setup() {
+ pinMode(BOARD_LED_PIN, OUTPUT);
+}
+
+int toggle = 1;
+
+void loop() {
+ // You could just use toggleLED() instead, but this illustrates
+ // the use of digitalWrite():
+ digitalWrite(BOARD_LED_PIN, toggle);
+ toggle ^= 1;
+ delay(100);
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated objects that need libmaple may fail.
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+ return 0;
+}
diff --git a/examples/spi_master.cpp b/examples/spi_master.cpp
index af3e709..100fc53 100644
--- a/examples/spi_master.cpp
+++ b/examples/spi_master.cpp
@@ -1,77 +1,77 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 LeafLabs LLC.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *****************************************************************************/
-
-/**
- * @brief Sample main.cpp file. Sends "Hello world!" out SPI1.
- *
- * SPI1 is set up to be a master transmitter at 4.5MHz, little
- * endianness, and SPI mode 0.
- *
- * Pin 10 is used as slave select.
- */
-
-#include "wirish.h"
-
-#define NSS 10
-
-byte buf[] = "Hello world!";
-
-HardwareSPI spi1(1);
-
-void setup() {
- /* Set up chip select as output */
- pinMode(NSS, OUTPUT);
-
- /* NSS is usually active LOW, so initialize it HIGH */
- digitalWrite(NSS, HIGH);
-
- /* Initialize SPI */
- spi1.begin(SPI_4_5MHZ, LSBFIRST, 0);
-}
-
-void loop() {
- /* Send message */
- digitalWrite(NSS, LOW);
- spi1.write(buf, sizeof buf);
- digitalWrite(NSS, HIGH);
- delay(1000);
-}
-
-// Force init to be called *first*, i.e. before static object allocation.
-// Otherwise, statically allocated objects that need libmaple may fail.
-__attribute__((constructor)) void premain() {
- init();
-}
-
-int main(void) {
- setup();
-
- while (true) {
- loop();
- }
- return 0;
-}
-
+/******************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *****************************************************************************/
+
+/**
+ * @brief Sample main.cpp file. Sends "Hello world!" out SPI1.
+ *
+ * SPI1 is set up to be a master transmitter at 4.5MHz, little
+ * endianness, and SPI mode 0.
+ *
+ * Pin 10 is used as slave select.
+ */
+
+#include "wirish.h"
+
+#define NSS 10
+
+byte buf[] = "Hello world!";
+
+HardwareSPI spi1(1);
+
+void setup() {
+ /* Set up chip select as output */
+ pinMode(NSS, OUTPUT);
+
+ /* NSS is usually active LOW, so initialize it HIGH */
+ digitalWrite(NSS, HIGH);
+
+ /* Initialize SPI */
+ spi1.begin(SPI_4_5MHZ, LSBFIRST, 0);
+}
+
+void loop() {
+ /* Send message */
+ digitalWrite(NSS, LOW);
+ spi1.write(buf, sizeof buf);
+ digitalWrite(NSS, HIGH);
+ delay(1000);
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated objects that need libmaple may fail.
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+ return 0;
+}
+
diff --git a/examples/test-fsmc.cpp b/examples/test-fsmc.cpp
index 7db3bb7..3aa6c6d 100644
--- a/examples/test-fsmc.cpp
+++ b/examples/test-fsmc.cpp
@@ -1,125 +1,125 @@
-#include <stddef.h> // for ptrdiff_t
-
-#include "wirish.h"
-#include "fsmc.h"
-
-#ifndef BOARD_maple_native
-#error "Sorry, this example only works on Maple Native."
-#endif
-
-// Start of FSMC SRAM bank 1
-static uint16 *const sram_start = (uint16*)0x60000000;
-// End of Maple Native SRAM chip address space (512K 16-bit words)
-static uint16 *const sram_end = (uint16*)0x60080000;
-
-void test_single_write(void);
-void test_all_addresses(void);
-
-void setup() {
- pinMode(BOARD_LED_PIN, OUTPUT);
- digitalWrite(BOARD_LED_PIN, HIGH);
-
- Serial1.begin(115200);
- Serial1.println("*** Beginning RAM chip test");
-
- test_single_write();
- test_all_addresses();
-
- Serial1.println("Tests pass, finished.");
-}
-
-void loop() {
-}
-
-void test_single_write() {
- uint16 *ptr = sram_start;
- uint16 tmp;
-
- Serial1.print("Writing 0x1234... ");
- *ptr = 0x1234;
- Serial1.println("Done.");
-
- Serial1.print("Reading... ");
- tmp = *ptr;
- Serial1.print("Done: 0x");
- Serial1.println(tmp, HEX);
-
- if (tmp != 0x1234) {
- Serial1.println("Mismatch; abort.");
- ASSERT(0);
- }
-}
-
-void test_all_addresses() {
- uint32 start, end;
- uint16 count = 0;
- uint16 *ptr;
-
- Serial1.println("Now writing all memory addresses (unrolled loop)");
- // Turn off the USB interrupt, as it interferes most with timing
- // (don't turn off SysTick, or we won't get micros()).
- SerialUSB.end();
- start = micros();
- for (ptr = sram_start; ptr < sram_end;) {
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- }
- end = micros();
- SerialUSB.begin();
- Serial1.print("Done. Elapsed time (us): ");
- Serial1.println(end - start);
-
- Serial1.println("Validating writes.");
- for (ptr = sram_start, count = 0; ptr < sram_end; ptr++, count++) {
- uint16 value = *ptr;
- if (value != count) {
- Serial1.print("mismatch: 0x");
- Serial1.print((uint32)ptr);
- Serial1.print(" = 0x");
- Serial1.print(value, HEX);
- Serial1.print(", should be 0x");
- Serial1.print(count, HEX);
- Serial1.println(".");
- ASSERT(0);
- }
- }
- Serial1.println("Done; all writes seem valid.");
-
- ptrdiff_t nwrites = sram_end - sram_start;
- double us_per_write = double(end-start) / double(nwrites);
- Serial1.print("Number of writes = ");
- Serial1.print(nwrites);
- Serial1.print("; avg. time per write = ");
- Serial1.print(us_per_write);
- Serial1.print(" us (");
- Serial1.print(1 / us_per_write);
- Serial1.println(" MHz)");
-}
-
-__attribute__((constructor)) void premain() {
- init();
-}
-
-int main(void) {
- setup();
-
- while (true) {
- loop();
- }
-
- return 0;
-}
+#include <stddef.h> // for ptrdiff_t
+
+#include "wirish.h"
+#include "fsmc.h"
+
+#ifndef BOARD_maple_native
+#error "Sorry, this example only works on Maple Native."
+#endif
+
+// Start of FSMC SRAM bank 1
+static uint16 *const sram_start = (uint16*)0x60000000;
+// End of Maple Native SRAM chip address space (512K 16-bit words)
+static uint16 *const sram_end = (uint16*)0x60080000;
+
+void test_single_write(void);
+void test_all_addresses(void);
+
+void setup() {
+ pinMode(BOARD_LED_PIN, OUTPUT);
+ digitalWrite(BOARD_LED_PIN, HIGH);
+
+ Serial1.begin(115200);
+ Serial1.println("*** Beginning RAM chip test");
+
+ test_single_write();
+ test_all_addresses();
+
+ Serial1.println("Tests pass, finished.");
+}
+
+void loop() {
+}
+
+void test_single_write() {
+ uint16 *ptr = sram_start;
+ uint16 tmp;
+
+ Serial1.print("Writing 0x1234... ");
+ *ptr = 0x1234;
+ Serial1.println("Done.");
+
+ Serial1.print("Reading... ");
+ tmp = *ptr;
+ Serial1.print("Done: 0x");
+ Serial1.println(tmp, HEX);
+
+ if (tmp != 0x1234) {
+ Serial1.println("Mismatch; abort.");
+ ASSERT(0);
+ }
+}
+
+void test_all_addresses() {
+ uint32 start, end;
+ uint16 count = 0;
+ uint16 *ptr;
+
+ Serial1.println("Now writing all memory addresses (unrolled loop)");
+ // Turn off the USB interrupt, as it interferes most with timing
+ // (don't turn off SysTick, or we won't get micros()).
+ SerialUSB.end();
+ start = micros();
+ for (ptr = sram_start; ptr < sram_end;) {
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ *ptr++ = count++;
+ }
+ end = micros();
+ SerialUSB.begin();
+ Serial1.print("Done. Elapsed time (us): ");
+ Serial1.println(end - start);
+
+ Serial1.println("Validating writes.");
+ for (ptr = sram_start, count = 0; ptr < sram_end; ptr++, count++) {
+ uint16 value = *ptr;
+ if (value != count) {
+ Serial1.print("mismatch: 0x");
+ Serial1.print((uint32)ptr);
+ Serial1.print(" = 0x");
+ Serial1.print(value, HEX);
+ Serial1.print(", should be 0x");
+ Serial1.print(count, HEX);
+ Serial1.println(".");
+ ASSERT(0);
+ }
+ }
+ Serial1.println("Done; all writes seem valid.");
+
+ ptrdiff_t nwrites = sram_end - sram_start;
+ double us_per_write = double(end-start) / double(nwrites);
+ Serial1.print("Number of writes = ");
+ Serial1.print(nwrites);
+ Serial1.print("; avg. time per write = ");
+ Serial1.print(us_per_write);
+ Serial1.print(" us (");
+ Serial1.print(1 / us_per_write);
+ Serial1.println(" MHz)");
+}
+
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+
+ return 0;
+}