From 8506e13ad51792dda49fc5ca450ae1d7aadd43bc Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 2 Jun 2014 20:55:20 +0300 Subject: [PATCH] Added "native" examples for embedded platforms --- examples/atmelavr-native-blink/platformio.ini | 10 +++++ examples/atmelavr-native-blink/src/main.c | 23 +++++++++++ examples/timsp430-native-blink/platformio.ini | 8 ++++ examples/timsp430-native-blink/src/main.c | 26 +++++++++++++ examples/titiva-native-blink/platformio.ini | 5 +++ examples/titiva-native-blink/src/main.c | 39 +++++++++++++++++++ .../platformio.ini | 6 ++- .../src/blink.cpp => wiring-blink/src/main.c} | 2 +- 8 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 examples/atmelavr-native-blink/platformio.ini create mode 100644 examples/atmelavr-native-blink/src/main.c create mode 100644 examples/timsp430-native-blink/platformio.ini create mode 100644 examples/timsp430-native-blink/src/main.c create mode 100644 examples/titiva-native-blink/platformio.ini create mode 100644 examples/titiva-native-blink/src/main.c rename examples/{embedded-blink => wiring-blink}/platformio.ini (71%) rename examples/{embedded-blink/src/blink.cpp => wiring-blink/src/main.c} (99%) diff --git a/examples/atmelavr-native-blink/platformio.ini b/examples/atmelavr-native-blink/platformio.ini new file mode 100644 index 00000000..cfcfd083 --- /dev/null +++ b/examples/atmelavr-native-blink/platformio.ini @@ -0,0 +1,10 @@ +[env:arduino_pro5v] +platform = atmelavr +board_mcu = atmega168 +board_f_cpu = 16000000L + +upload_port = /dev/tty.SLAB_USBtoUART +upload_protocol = arduino +upload_speed = 19200 + +targets = upload diff --git a/examples/atmelavr-native-blink/src/main.c b/examples/atmelavr-native-blink/src/main.c new file mode 100644 index 00000000..757d3c5f --- /dev/null +++ b/examples/atmelavr-native-blink/src/main.c @@ -0,0 +1,23 @@ +/** + * Copyright (C) Ivan Kravets + * See LICENSE for details. + */ + +#include +#include + +int main(void) +{ + // make the LED pin an output for PORTB5 + DDRB = 1 << 5; + + while (1) + { + _delay_ms(500); + + // toggle the LED + PORTB ^= 1 << 5; + } + + return 0; +} diff --git a/examples/timsp430-native-blink/platformio.ini b/examples/timsp430-native-blink/platformio.ini new file mode 100644 index 00000000..ee05492f --- /dev/null +++ b/examples/timsp430-native-blink/platformio.ini @@ -0,0 +1,8 @@ +[env:launchpad_msp430g2] +platform = timsp430 +board_mcu = msp430g2553 +board_f_cpu = 16000000L + +upload_protocol = rf2500 + +targets = upload diff --git a/examples/timsp430-native-blink/src/main.c b/examples/timsp430-native-blink/src/main.c new file mode 100644 index 00000000..38a421a5 --- /dev/null +++ b/examples/timsp430-native-blink/src/main.c @@ -0,0 +1,26 @@ +/** + * Copyright (C) Ivan Kravets + * See LICENSE for details. + */ + +#include + +int main(void) +{ + WDTCTL = WDTPW + WDTHOLD; + + // make the LED pin an output for P1.0 + P1DIR |= 0x01; + + volatile int i; + + while (1) + { + for (i = 0; i < 10000; i++); + + // toggle the LED + P1OUT ^= 0x01; + } + + return 0; +} diff --git a/examples/titiva-native-blink/platformio.ini b/examples/titiva-native-blink/platformio.ini new file mode 100644 index 00000000..e9401680 --- /dev/null +++ b/examples/titiva-native-blink/platformio.ini @@ -0,0 +1,5 @@ +[env:launchpad_lm4f120] +platform = titiva +framework = energia +board = lplm4f120h5qr +targets = upload diff --git a/examples/titiva-native-blink/src/main.c b/examples/titiva-native-blink/src/main.c new file mode 100644 index 00000000..5f3edee5 --- /dev/null +++ b/examples/titiva-native-blink/src/main.c @@ -0,0 +1,39 @@ +/** + * Copyright (C) Ivan Kravets + * See LICENSE for details. + */ + +#include +#include +#include "inc/hw_memmap.h" +#include "driverlib/gpio.h" +#include "driverlib/sysctl.h" + +#define LED_RED GPIO_PIN_1 +#define LED_BLUE GPIO_PIN_2 +#define LED_GREEN GPIO_PIN_3 + +int main(void) +{ + SysCtlClockSet( + SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); + + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); + GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); + + while (1) + { + GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN, LED_RED); + SysCtlDelay(3000000); + GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN, LED_BLUE); + SysCtlDelay(3000000); + GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN, LED_GREEN); + SysCtlDelay(3000000); + } + + return 0; +} + +// hook for Energia main.cpp where these methods are defined +void setup() {} +void loop() {} diff --git a/examples/embedded-blink/platformio.ini b/examples/wiring-blink/platformio.ini similarity index 71% rename from examples/embedded-blink/platformio.ini rename to examples/wiring-blink/platformio.ini index 30b333bf..5bd4f4d0 100644 --- a/examples/embedded-blink/platformio.ini +++ b/examples/wiring-blink/platformio.ini @@ -1,13 +1,15 @@ [env:arduino_pro5v] platform = atmelavr -board = pro5v +framework = arduino +board = pro16MHzatmega168 upload_port = /dev/tty.SLAB_USBtoUART -targets = upload [env:launchpad_msp430g2] platform = timsp430 +framework = energia board = lpmsp430g2553 [env:launchpad_lm4f120] platform = titiva +framework = energia board = lplm4f120h5qr diff --git a/examples/embedded-blink/src/blink.cpp b/examples/wiring-blink/src/main.c similarity index 99% rename from examples/embedded-blink/src/blink.cpp rename to examples/wiring-blink/src/main.c index fb032e3f..a86fe009 100644 --- a/examples/embedded-blink/src/blink.cpp +++ b/examples/wiring-blink/src/main.c @@ -31,4 +31,4 @@ void loop() delay(1000); // wait for a second digitalWrite(WLED, LOW); // set the LED off delay(1000); // wait for a second -} \ No newline at end of file +}