diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index d948c17879..2ae48baf83 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -20,64 +20,21 @@ #ifndef Arduino_h #define Arduino_h -#include -#include -#include -#include -#include - -#include "binary.h" -#include "itoa.h" - -#ifdef __cplusplus -extern "C"{ -#endif // __cplusplus - -// Includes CMSIS -#include - -#include "wiring_constants.h" - -#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) -#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) -#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) - -void yield(void); +#include "wiring.h" /* sketch */ extern void setup( void ) ; extern void loop( void ) ; -/* Define attribute */ -#if defined ( __CC_ARM ) /* Keil uVision 4 */ - #define WEAK (__attribute__ ((weak))) -#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ - #define WEAK __weak -#elif defined ( __GNUC__ ) /* GCC CS */ - #define WEAK __attribute__ ((weak)) -#endif - #ifdef __cplusplus -} // extern "C" +extern "C"{ #endif // __cplusplus - +void yield(void); #ifdef __cplusplus -#include "WCharacter.h" -#include "WString.h" -#include "Tone.h" -#include "WMath.h" -#include "HardwareSerial.h" -#include "wiring_pulse.h" +} // extern "C" #endif // __cplusplus - // Include board variant #include "pins_arduino.h" -#include "wiring.h" -#include "wiring_digital.h" -#include "wiring_analog.h" -#include "wiring_shift.h" -#include "WInterrupts.h" - #endif // Arduino_h diff --git a/cores/arduino/Tone.h b/cores/arduino/Tone.h index 932a875e12..99a387bfce 100644 --- a/cores/arduino/Tone.h +++ b/cores/arduino/Tone.h @@ -20,9 +20,6 @@ #define _WIRING_TONE_ #ifdef __cplusplus -extern "C" { -#endif - /* * \brief Generate a tone to a pin. * @@ -39,8 +36,6 @@ extern void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = */ extern void noTone(uint8_t _pin); -#ifdef __cplusplus -} #endif #endif /* _WIRING_TONE_ */ diff --git a/cores/arduino/board.c b/cores/arduino/board.c new file mode 100644 index 0000000000..fa69510fda --- /dev/null +++ b/cores/arduino/board.c @@ -0,0 +1,16 @@ +#include "board.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void __libc_init_array(void); + +WEAK void init( void ) +{ + hw_config_init(); +} + +#ifdef __cplusplus +} +#endif diff --git a/cores/arduino/board.h b/cores/arduino/board.h new file mode 100644 index 0000000000..a167457c11 --- /dev/null +++ b/cores/arduino/board.h @@ -0,0 +1,40 @@ +#ifndef _BOARD_H_ +#define _BOARD_H_ + +/* + * Core and peripherals registers definitions + */ +#include "analog.h" +#include "clock.h" +#include "digital_io.h" +#include "ethernet.h" +#include "hal_uart_emul.h" +#include "hw_config.h" +#include "interrupt.h" +#include "spi_com.h" +#include "stm32_eeprom.h" +#include "timer.h" +#include "twi.h" +#include "uart.h" +#include "uart_emul.h" +#ifdef USBCON +#include "usb_interface.h" +#endif //USBCON + +/* Define attribute */ +#if defined ( __GNUC__ ) /* GCC CS3 */ + #define WEAK __attribute__ ((weak)) +#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ + #define WEAK __weak +#endif + +/* Define NO_INIT attribute */ +#if defined ( __GNUC__ ) + #define NO_INIT +#elif defined ( __ICCARM__ ) + #define NO_INIT __no_init +#endif + +void init( void ) ; + +#endif /* _BOARD_H_ */ diff --git a/cores/arduino/chip.h b/cores/arduino/chip.h deleted file mode 100644 index d4bcdc90a0..0000000000 --- a/cores/arduino/chip.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2011 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _CHIP_H_ -#define _CHIP_H_ - -/* - * Core and peripherals registers definitions - */ -#include "hw_config.h" -#include "digital_io.h" -#include "clock.h" -#include "hal_uart_emul.h" -#include "uart.h" -#include "uart_emul.h" -#include "analog.h" -#include "interrupt.h" -#include "spi_com.h" -#include "timer.h" -#include "twi.h" -#include "stm32_eeprom.h" -#ifdef USBCON -#include "usb_interface.h" -#endif //USBCON - -#include "ethernet.h" - -/* Define attribute */ -#if defined ( __GNUC__ ) /* GCC CS3 */ - #define WEAK __attribute__ ((weak)) -#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ - #define WEAK __weak -#endif - -/* Define NO_INIT attribute */ -#if defined ( __GNUC__ ) - #define NO_INIT -#elif defined ( __ICCARM__ ) - #define NO_INIT __no_init -#endif - -/* - * Peripherals - */ - - -#endif /* _CHIP_H_ */ diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c index eeebdd8e15..cebc377375 100644 --- a/cores/arduino/pins_arduino.c +++ b/cores/arduino/pins_arduino.c @@ -22,8 +22,6 @@ extern "C" { #endif -void __libc_init_array(void); - WEAK uint32_t pinNametoDigitalPin(PinName p) { uint32_t i = NC; @@ -36,11 +34,6 @@ WEAK uint32_t pinNametoDigitalPin(PinName p) return i; } -WEAK void init( void ) -{ - hw_config_init(); -} - #ifdef __cplusplus } #endif diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index 094efb41d6..d464f07f1a 100644 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -17,62 +17,46 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _WIRING_ -#define _WIRING_ +#ifndef _WIRING_H_ +#define _WIRING_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include +#include +#include +#include +#include -/** - * - */ -extern void initVariant( void ) ; -extern void init( void ) ; +#include "binary.h" +#include "itoa.h" -/** - * \brief Returns the number of milliseconds since the Arduino board began running the current program. - * - * This number will overflow (go back to zero), after approximately 50 days. - * - * \return Number of milliseconds since the program started (uint32_t) - */ -extern uint32_t millis( void ) ; +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus +#include +#ifdef __cplusplus +} +#endif -/** - * \brief Returns the number of microseconds since the Arduino board began running the current program. - * - * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards - * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is - * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution - * of eight microseconds. - * - * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. - */ -extern uint32_t micros( void ) ; +#include "wiring_analog.h" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include "wiring_pulse.h" +#include "wiring_shift.h" +#include "wiring_time.h" +#include "WInterrupts.h" -/** - * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. - * (There are 1000 milliseconds in a second.) - * - * \param dwMs the number of milliseconds to pause (uint32_t) - */ -extern void delay( uint32_t dwMs ) ; +#ifdef __cplusplus +#include "HardwareSerial.h" +#include "Tone.h" +#include "WCharacter.h" +#include "WMath.h" +#include "WString.h" +#endif // __cplusplus -/** - * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. - * - * \param dwUs the number of microseconds to pause (uint32_t) - */ -static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); -static inline void delayMicroseconds(uint32_t usec){ - uint32_t start = GetCurrentMicro(); +#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) +#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) +#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) - while((start+usec) > GetCurrentMicro()); -} -#ifdef __cplusplus -} -#endif -#endif /* _WIRING_ */ +#endif /* _WIRING_H_ */ diff --git a/cores/arduino/wiring_private.h b/cores/arduino/wiring_private.h index 82bea80f64..a9608cef04 100644 --- a/cores/arduino/wiring_private.h +++ b/cores/arduino/wiring_private.h @@ -19,24 +19,4 @@ #ifndef WiringPrivate_h #define WiringPrivate_h -#include -#include -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -// Includes ST CMSIS -#include - -#include "wiring_constants.h" - -#ifdef __cplusplus -} // extern "C" - -#include "HardwareSerial.h" - -#endif - #endif diff --git a/cores/arduino/wiring_pulse.cpp b/cores/arduino/wiring_pulse.cpp index c2bca8f2cb..bdb33431d9 100644 --- a/cores/arduino/wiring_pulse.cpp +++ b/cores/arduino/wiring_pulse.cpp @@ -17,7 +17,6 @@ */ #include "Arduino.h" -#include "wiring_private.h" /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds @@ -28,11 +27,6 @@ * This function performs better with short pulses in noInterrupt() context */ -#ifdef __cplusplus - extern "C" { -#endif - - uint32_t pulseIn( uint32_t pin, uint32_t state, uint32_t timeout ) { uint32_t startMicros = micros(); @@ -78,7 +72,3 @@ uint32_t pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout) { return pulseIn(pin, state, timeout); } - -#ifdef __cplusplus -} -#endif diff --git a/cores/arduino/wiring_pulse.h b/cores/arduino/wiring_pulse.h index 3087cb93c8..2fd17ea672 100644 --- a/cores/arduino/wiring_pulse.h +++ b/cores/arduino/wiring_pulse.h @@ -20,9 +20,6 @@ #define _WIRING_PULSE_ #ifdef __cplusplus - extern "C" { -#endif - unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_t stateMask, unsigned long maxloops); /* * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH @@ -32,9 +29,6 @@ unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_ */ extern uint32_t pulseIn( uint32_t ulPin, uint32_t ulState, uint32_t ulTimeout = 1000000L ) ; extern uint32_t pulseInLong( uint8_t pin, uint8_t state, unsigned long timeout = 1000000L ) ; - -#ifdef __cplusplus -} #endif #endif /* _WIRING_PULSE_ */ diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring_time.c similarity index 81% rename from cores/arduino/wiring.c rename to cores/arduino/wiring_time.c index 619778fb37..9435f64750 100644 --- a/cores/arduino/wiring.c +++ b/cores/arduino/wiring_time.c @@ -44,21 +44,6 @@ void delay( uint32_t ms ) } while (GetCurrentMilli() - start < ms); } -#if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ -extern signed int putchar( signed int c ) ; -/** - * \brief - * - * \param c Character to output. - * - * \return The character that was output. - */ -extern WEAK signed int putchar( signed int c ) -{ - return c ; -} -#endif /* __ICCARM__ */ - #ifdef __cplusplus } #endif diff --git a/cores/arduino/wiring_time.h b/cores/arduino/wiring_time.h new file mode 100644 index 0000000000..fe8f2a5954 --- /dev/null +++ b/cores/arduino/wiring_time.h @@ -0,0 +1,73 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + Copyright (c) 2013 by Paul Stoffregen (delayMicroseconds) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _WIRING_TIME_H_ +#define _WIRING_TIME_H_ + +#include "clock.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * \brief Returns the number of milliseconds since the Arduino board began running the current program. + * + * This number will overflow (go back to zero), after approximately 50 days. + * + * \return Number of milliseconds since the program started (uint32_t) + */ +extern uint32_t millis( void ) ; + +/** + * \brief Returns the number of microseconds since the Arduino board began running the current program. + * + * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards + * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is + * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution + * of eight microseconds. + * + * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. + */ +extern uint32_t micros( void ) ; + +/** + * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. + * (There are 1000 milliseconds in a second.) + * + * \param dwMs the number of milliseconds to pause (uint32_t) + */ +extern void delay( uint32_t dwMs ) ; + +/** + * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. + * + * \param dwUs the number of microseconds to pause (uint32_t) + */ +static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); +static inline void delayMicroseconds(uint32_t usec){ + uint32_t start = GetCurrentMicro(); + + while((start+usec) > GetCurrentMicro()); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _WIRING_TIME_H_ */