mbed(SerialHalfDuplex入り)
Fork of mbed by
Revision 44:24d45a770a51, committed 2012-11-21
- Comitter:
- emilmont
- Date:
- Wed Nov 21 10:49:56 2012 +0000
- Parent:
- 43:e2ed12d17f06
- Child:
- 45:3d775a932e1d
- Commit message:
- Complete refactoring of the mbed library to move the target dependent code to a thin well defined layer, defining a proper object oriented C API to be implemented by the different silicon vendors.
Changed in this revision
--- a/AnalogIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/AnalogIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,22 +1,36 @@ -/* mbed Microcontroller Library - AnalogIn - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_ANALOGIN_H #define MBED_ANALOGIN_H -#include "device.h" +#include "platform.h" #if DEVICE_ANALOGIN -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "analogin_api.h" namespace mbed { -/** An analog input, used for reading the voltage on a pin +/** An analog input, used for reading the voltage on a pin * * Example: * @code @@ -29,13 +43,13 @@ * int main() { * while(1) { * if(temperature > 0.5) { - * printf("Too hot! (%f)", temperature.read()); + * printf("Too hot! (%f)", temperature.read()); * } * } * } * @endcode */ -class AnalogIn : public Base { +class AnalogIn { public: @@ -44,20 +58,26 @@ * @param pin AnalogIn pin to connect to * @param name (optional) A string to identify the object */ - AnalogIn(PinName pin, const char *name = NULL); + AnalogIn(PinName pin) { + analogin_init(&_adc, pin); + } /** Read the input voltage, represented as a float in the range [0.0, 1.0] * * @returns A floating-point value representing the current input voltage, measured as a percentage */ - float read(); + float read() { + return analogin_read(&_adc); + } /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF] * * @returns * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value */ - unsigned short read_u16(); + unsigned short read_u16() { + return analogin_read_u16(&_adc); + } #ifdef MBED_OPERATORS /** An operator shorthand for read() @@ -73,18 +93,13 @@ * if(volume > 0.25) { ... } * @endcode */ - operator float(); -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); + operator float() { + return read(); + } #endif protected: - - ADCName _adc; - + analogin_t _adc; }; } // namespace mbed
--- a/AnalogOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/AnalogOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,18 +1,32 @@ -/* mbed Microcontroller Library - AnalogOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_ANALOGOUT_H #define MBED_ANALOGOUT_H -#include "device.h" +#include "platform.h" #if DEVICE_ANALOGOUT -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "analogout_api.h" namespace mbed { @@ -36,7 +50,7 @@ * } * @endcode */ -class AnalogOut : public Base { +class AnalogOut { public: @@ -44,23 +58,29 @@ * * @param AnalogOut pin to connect to (18) */ - AnalogOut(PinName pin, const char *name = NULL); + AnalogOut(PinName pin) { + analogout_init(&_dac, pin); + } /** Set the output voltage, specified as a percentage (float) * * @param value A floating-point value representing the output voltage, * specified as a percentage. The value should lie between * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). - * Values outside this range will be saturated to 0.0f or 1.0f. + * Values outside this range will be saturated to 0.0f or 1.0f. */ - void write(float value); + void write(float value) { + analogout_write(&_dac, value); + } /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF] * * @param value 16-bit unsigned short representing the output voltage, - * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) + * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) */ - void write_u16(unsigned short value); + void write_u16(unsigned short value) { + analogout_write_u16(&_dac, value); + } /** Return the current output voltage setting, measured as a percentage (float) * @@ -71,30 +91,33 @@ * * @note * This value may not match exactly the value set by a previous write(). - */ - float read(); - + */ + float read() { + return analogout_read(&_dac); + } #ifdef MBED_OPERATORS /** An operator shorthand for write() */ - AnalogOut& operator= (float percent); - AnalogOut& operator= (AnalogOut& rhs); + AnalogOut& operator= (float percent) { + write(percent); + return *this; + } + + AnalogOut& operator= (AnalogOut& rhs) { + write(rhs.read()); + return *this; + } /** An operator shorthand for read() - */ - operator float(); -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); + */ + operator float() { + return read(); + } #endif protected: - - DACName _dac; - + dac_t _dac; }; } // namespace mbed
--- a/Base.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,216 +0,0 @@ -/* mbed Microcontroller Library - Base - * Copyright (c) 2006-2008 ARM Limited. All rights reserved. - */ - -#ifndef MBED_BASE_H -#define MBED_BASE_H - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include <cstdlib> -#include "DirHandle.h" - -namespace mbed { - -#ifdef MBED_RPC -struct rpc_function { - const char *name; - void (*caller)(const char*, char*); -}; - -struct rpc_class { - const char *name; - const rpc_function *static_functions; - struct rpc_class *next; -}; -#endif - -/** The base class for most things - */ -class Base { - -public: - - Base(const char *name = NULL); - - virtual ~Base(); - - /** Registers this object with the given name, so that it can be - * looked up with lookup. If this object has already been - * registered, then this just changes the name. - * - * @param name The name to give the object. If NULL we do nothing. - */ - void register_object(const char *name); - - /** Returns the name of the object - * - * @returns - * The name of the object, or NULL if it has no name. - */ - const char *name(); - -#ifdef MBED_RPC - - /** Call the given method with the given arguments, and write the - * result into the string pointed to by result. The default - * implementation calls rpc_methods to determine the supported - * methods. - * - * @param method The name of the method to call. - * @param arguments A list of arguments separated by spaces. - * @param result A pointer to a string to write the result into. May be NULL, in which case nothing is written. - * - * @returns - * true if method corresponds to a valid rpc method, or - * false otherwise. - */ - virtual bool rpc(const char *method, const char *arguments, char *result); - - /** Returns a pointer to an array describing the rpc methods - * supported by this object, terminated by either - * RPC_METHOD_END or RPC_METHOD_SUPER(Superclass). - * - * Example - * @code - * class Example : public Base { - * int foo(int a, int b) { return a + b; } - * virtual const struct rpc_method *get_rpc_methods() { - * static const rpc_method rpc_methods[] = { - * { "foo", generic_caller<int, Example, int, int, &Example::foo> }, - * RPC_METHOD_SUPER(Base) - * }; - * return rpc_methods; - * } - * }; - * @endcode - */ - virtual const struct rpc_method *get_rpc_methods(); - - /** Use the lookup function to lookup an object and, if - * successful, call its rpc method - * - * @returns - * false if name does not correspond to an object, - * otherwise the return value of the call to the object's rpc - * method. - */ - static bool rpc(const char *name, const char *method, const char *arguments, char *result); - -#endif - - /** Lookup and return the object that has the given name. - * - * @param name the name to lookup. - * @param len the length of name. - */ - static Base *lookup(const char *name, unsigned int len); - - static DirHandle *opendir(); - friend class BaseDirHandle; - -protected: - - static Base *_head; - Base *_next; - const char *_name; - bool _from_construct; - -private: - -#ifdef MBED_RPC - static rpc_class *_classes; - - static const rpc_function _base_funcs[]; - static rpc_class _base_class; -#endif - - void delete_self(); - static void list_objs(const char *arguments, char *result); - static void clear(const char*,char*); - - static char *new_name(Base *p); - -public: - -#ifdef MBED_RPC - /** Add the class to the list of classes which can have static - * methods called via rpc (the static methods which can be called - * are defined by that class' get_rpc_class() static method). - */ - template<class C> - static void add_rpc_class() { - rpc_class *c = C::get_rpc_class(); - c->next = _classes; - _classes = c; - } - - template<class C> - static const char *construct() { - Base *p = new C(); - p->_from_construct = true; - if(p->_name==NULL) { - p->register_object(new_name(p)); - } - return p->_name; - } - - template<class C, typename A1> - static const char *construct(A1 arg1) { - Base *p = new C(arg1); - p->_from_construct = true; - if(p->_name==NULL) { - p->register_object(new_name(p)); - } - return p->_name; - } - - template<class C, typename A1, typename A2> - static const char *construct(A1 arg1, A2 arg2) { - Base *p = new C(arg1,arg2); - p->_from_construct = true; - if(p->_name==NULL) { - p->register_object(new_name(p)); - } - return p->_name; - } - - template<class C, typename A1, typename A2, typename A3> - static const char *construct(A1 arg1, A2 arg2, A3 arg3) { - Base *p = new C(arg1,arg2,arg3); - p->_from_construct = true; - if(p->_name==NULL) { - p->register_object(new_name(p)); - } - return p->_name; - } - - template<class C, typename A1, typename A2, typename A3, typename A4> - static const char *construct(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { - Base *p = new C(arg1,arg2,arg3,arg4); - p->_from_construct = true; - if(p->_name==NULL) { - p->register_object(new_name(p)); - } - return p->_name; - } -#endif - -}; - -/** The maximum size of object name (including terminating null byte) - * that will be recognised when using fopen to open a FileLike - * object, or when using the rpc function. - */ -#define MBED_OBJECT_NAME_MAX 32 - -/** The maximum size of rpc method name (including terminating null - * byte) that will be recognised by the rpc function (in rpc.h). - */ -#define MBED_METHOD_NAME_MAX 32 - -} // namespace mbed - -#endif -
--- a/BusIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/BusIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,23 +1,38 @@ -/* mbed Microcontroller Library - DigitalIn - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. */ - #ifndef MBED_BUSIN_H #define MBED_BUSIN_H #include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" #include "DigitalIn.h" namespace mbed { /** A digital input bus, used for reading the state of a collection of pins */ -class BusIn : public Base { +class BusIn { public: + /* Group: Configuration Methods */ /** Create an BusIn, connected to the specified pins * @@ -30,13 +45,12 @@ BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, - PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC, - const char *name = NULL); + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); - BusIn(PinName pins[16], const char *name = NULL); - + BusIn(PinName pins[16]); + virtual ~BusIn(); - + /** Read the value of the input bus * * @returns @@ -50,22 +64,10 @@ operator int(); #endif -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - protected: - DigitalIn* _pin[16]; - -#ifdef MBED_RPC - static void construct(const char *arguments, char *res); -#endif - }; } // namespace mbed #endif -
--- a/BusInOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/BusInOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,44 +1,56 @@ -/* mbed Microcontroller Library - BusInOut - * Copyright (c) 2009 ARM Limited. All rights reserved. +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. */ - #ifndef MBED_BUSINOUT_H #define MBED_BUSINOUT_H -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" #include "DigitalInOut.h" namespace mbed { /** A digital input output bus, used for setting the state of a collection of pins */ -class BusInOut : public Base { +class BusInOut { public: - + /** Create an BusInOut, connected to the specified pins * * @param p<n> DigitalInOut pin to connect to bus bit p<n> (p5-p30, NC) * * @note - * It is only required to specify as many pin variables as is required - * for the bus; the rest will default to NC (not connected) - */ + * It is only required to specify as many pin variables as is required + * for the bus; the rest will default to NC (not connected) + */ BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, - PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC, - const char *name = NULL); + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); - BusInOut(PinName pins[16], const char *name = NULL); + BusInOut(PinName pins[16]); virtual ~BusInOut(); /* Group: Access Methods */ - + /** Write the value to the output bus * * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin @@ -78,22 +90,10 @@ operator int(); #endif -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - protected: - DigitalInOut* _pin[16]; - -#ifdef MBED_RPC - static void construct(const char *arguments, char *res); -#endif - }; } // namespace mbed #endif -
--- a/BusOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/BusOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,21 +1,34 @@ -/* mbed Microcontroller Library - BusOut - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. */ - #ifndef MBED_BUSOUT_H #define MBED_BUSOUT_H -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" #include "DigitalOut.h" namespace mbed { /** A digital output bus, used for setting the state of a collection of pins */ -class BusOut : public Base { +class BusOut { public: @@ -24,26 +37,24 @@ * @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC) * * @note - * It is only required to specify as many pin variables as is required - * for the bus; the rest will default to NC (not connected) - */ + * It is only required to specify as many pin variables as is required + * for the bus; the rest will default to NC (not connected) + */ BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, - PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC, - const char *name = NULL); + PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); - BusOut(PinName pins[16], const char *name = NULL); + BusOut(PinName pins[16]); virtual ~BusOut(); - + /** Write the value to the output bus * * @param value An integer specifying a bit to write for every corresponding DigitalOut pin */ void write(int value); - /** Read the value currently output on the bus * * @returns @@ -52,7 +63,6 @@ int read(); #ifdef MBED_OPERATORS - /** A shorthand for write() */ BusOut& operator= (int v); @@ -63,22 +73,10 @@ operator int(); #endif -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - protected: - DigitalOut* _pin[16]; - -#ifdef MBED_RPC - static void construct(const char *arguments, char *res); -#endif - }; } // namespace mbed #endif -
--- a/CAN.h Fri Oct 26 17:40:46 2012 +0100 +++ b/CAN.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,24 +1,35 @@ -/* mbed Microcontroller Library - can - * Copyright (c) 2009-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_CAN_H #define MBED_CAN_H -#include "device.h" +#include "platform.h" #if DEVICE_CAN -#include "Base.h" -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" - +#include "can_api.h" #include "can_helper.h" #include "FunctionPointer.h" -#include <string.h> - namespace mbed { /** CANMessage class @@ -26,15 +37,14 @@ class CANMessage : public CAN_Message { public: - /** Creates empty CAN message. */ CANMessage() { - len = 8; - type = CANData; - format = CANStandard; - id = 0; - memset(data, 0, 8); + len = 8; + type = CANData; + format = CANStandard; + id = 0; + memset(data, 0, 8); } /** Creates CAN message with specific content. @@ -56,50 +66,13 @@ id = _id; memset(data, 0, 8); } -#if 0 // Inhereted from CAN_Message, for documentation only - - /** The message id. - * - * - If format is CANStandard it must be an 11 bit long id. - * - If format is CANExtended it must be an 29 bit long id. - */ - unsigned int id; - - /** Space for 8 byte payload. - * - * If type is CANData data can store up to 8 byte data. - */ - unsigned char data[8]; - - /** Length of data in bytes. - * - * If type is CANData data can store up to 8 byte data. - */ - unsigned char len; - - /** Defines if the message has standard or extended format. - * - * Defines the type of message id: - * Default is CANStandard which implies 11 bit id. - * CANExtended means 29 bit message id. - */ - CANFormat format; - - /** Defines the type of a message. - * - * The message type can rather be CANData for a message with data (default). - * Or CANRemote for a request of a specific CAN message. - */ - CANType type; // 0 - DATA FRAME, 1 - REMOTE FRAME -#endif }; /** A can bus client, used for communicating with can devices */ -class CAN : public Base { +class CAN { public: - /** Creates an CAN interface connected to specific pins. * * @param rd read from transmitter @@ -176,7 +149,7 @@ * To use after error overflow. */ void reset(); - + /** Puts or removes the CAN interface into silent monitoring mode * * @param silent boolean indicating whether to go into silent mode or not @@ -215,16 +188,15 @@ } private: - - CANName _id; + can_t _can; FunctionPointer _rxirq; - + void setup_interrupt(void); void remove_interrupt(void); }; } // namespace mbed -#endif // MBED_CAN_H +#endif -#endif +#endif // MBED_CAN_H
--- a/DigitalIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/DigitalIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,14 +1,30 @@ -/* mbed Microcontroller Library - DigitalIn - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_DIGITALIN_H #define MBED_DIGITALIN_H #include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" + +#include "gpio_api.h" namespace mbed { @@ -33,17 +49,18 @@ * } * @endcode */ -class DigitalIn : public Base { +class DigitalIn { public: - /** Create a DigitalIn connected to the specified pin * * @param pin DigitalIn pin to connect to * @param name (optional) A string to identify the object */ - DigitalIn(PinName pin, const char *name = NULL); - + DigitalIn(PinName pin) { + gpio_init(&gpio, pin, PIN_INPUT); + } + /** Read the input, represented as 0 or 1 (int) * * @returns @@ -51,47 +68,29 @@ * 0 for logical 0, 1 for logical 1 */ int read() { -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - return ((_gpio->FIOPIN & _mask) ? 1 : 0); -#elif defined(TARGET_LPC11U24) - return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0); -#endif + return gpio_read(&gpio); } - - + /** Set the input pin mode * * @param mode PullUp, PullDown, PullNone, OpenDrain */ - void mode(PinMode pull); + void mode(PinMode pull) { + gpio_mode(&gpio, pull); + } -#ifdef MBED_OPERATORS +#ifdef MBED_OPERATORS /** An operator shorthand for read() */ operator int() { return read(); } - -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); #endif protected: - - PinName _pin; -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#elif defined(TARGET_LPC11U24) - int _index; -#endif - uint32_t _mask; - + gpio_t gpio; }; } // namespace mbed #endif -
--- a/DigitalInOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/DigitalInOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,122 +1,109 @@ -/* mbed Microcontroller Library - DigitalInOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_DIGITALINOUT_H -#define MBED_DIGITALINOUT_H - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" - -namespace mbed { - -/** A digital input/output, used for setting or reading a bi-directional pin - */ -class DigitalInOut : public Base { - -public: - - /** Create a DigitalInOut connected to the specified pin - * - * @param pin DigitalInOut pin to connect to - */ - DigitalInOut(PinName pin, const char* name = NULL); - - /** Set the output, specified as 0 or 1 (int) - * - * @param value An integer specifying the pin output value, - * 0 for logical 0, 1 (or any other non-zero value) for logical 1 - */ - void write(int value) { -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - - if(value) { - _gpio->FIOSET = _mask; - } else { - _gpio->FIOCLR = _mask; - } - -#elif defined(TARGET_LPC11U24) - - if(value) { - LPC_GPIO->SET[_index] = _mask; - } else { - LPC_GPIO->CLR[_index] = _mask; - } -#endif - } - - /** Return the output setting, represented as 0 or 1 (int) - * - * @returns - * an integer representing the output setting of the pin if it is an output, - * or read the input if set as an input - */ - int read() { -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - - return ((_gpio->FIOPIN & _mask) ? 1 : 0); -#elif defined(TARGET_LPC11U24) - return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0); -#endif - } - - - /** Set as an output - */ - void output(); - - /** Set as an input - */ - void input(); - - /** Set the input pin mode - * - * @param mode PullUp, PullDown, PullNone, OpenDrain - */ - void mode(PinMode pull); - -#ifdef MBED_OPERATORS - /** A shorthand for write() - */ - DigitalInOut& operator= (int value) { - write(value); - return *this; - } - - DigitalInOut& operator= (DigitalInOut& rhs) { - write(rhs.read()); - return *this; - } - - /** A shorthand for read() - */ - operator int() { - return read(); - } -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - -protected: - - PinName _pin; - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#elif defined(TARGET_LPC11U24) - int _index; -#endif - - uint32_t _mask; - -}; - -} // namespace mbed - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_DIGITALINOUT_H +#define MBED_DIGITALINOUT_H + +#include "platform.h" + +#include "gpio_api.h" + +namespace mbed { + +/** A digital input/output, used for setting or reading a bi-directional pin + */ +class DigitalInOut { + +public: + /** Create a DigitalInOut connected to the specified pin + * + * @param pin DigitalInOut pin to connect to + */ + DigitalInOut(PinName pin) { + gpio_init(&gpio, pin, PIN_INPUT); + } + + /** Set the output, specified as 0 or 1 (int) + * + * @param value An integer specifying the pin output value, + * 0 for logical 0, 1 (or any other non-zero value) for logical 1 + */ + void write(int value) { + gpio_write(&gpio, value); + } + + /** Return the output setting, represented as 0 or 1 (int) + * + * @returns + * an integer representing the output setting of the pin if it is an output, + * or read the input if set as an input + */ + int read() { + return gpio_read(&gpio); + } + + /** Set as an output + */ + void output() { + gpio_dir(&gpio, PIN_OUTPUT); + } + + /** Set as an input + */ + void input() { + gpio_dir(&gpio, PIN_INPUT); + } + + /** Set the input pin mode + * + * @param mode PullUp, PullDown, PullNone, OpenDrain + */ + void mode(PinMode pull) { + gpio_mode(&gpio, pull); + } + +#ifdef MBED_OPERATORS + /** A shorthand for write() + */ + DigitalInOut& operator= (int value) { + write(value); + return *this; + } + + DigitalInOut& operator= (DigitalInOut& rhs) { + write(rhs.read()); + return *this; + } + + /** A shorthand for read() + */ + operator int() { + return read(); + } +#endif + +protected: + gpio_t gpio; +}; + +} // namespace mbed + +#endif
--- a/DigitalOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/DigitalOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,14 +1,29 @@ -/* mbed Microcontroller Library - DigitalOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_DIGITALOUT_H #define MBED_DIGITALOUT_H #include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "gpio_api.h" namespace mbed { @@ -29,42 +44,26 @@ * } * @endcode */ -class DigitalOut : public Base { +class DigitalOut { public: - /** Create a DigitalOut connected to the specified pin * * @param pin DigitalOut pin to connect to */ - DigitalOut(PinName pin, const char* name = NULL); - + DigitalOut(PinName pin) { + gpio_init(&gpio, pin, PIN_OUTPUT); + } + /** Set the output, specified as 0 or 1 (int) * * @param value An integer specifying the pin output value, * 0 for logical 0, 1 (or any other non-zero value) for logical 1 */ void write(int value) { - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - - if(value) { - _gpio->FIOSET = _mask; - } else { - _gpio->FIOCLR = _mask; - } - -#elif defined(TARGET_LPC11U24) - - if(value) { - LPC_GPIO->SET[_index] = _mask; - } else { - LPC_GPIO->CLR[_index] = _mask; - } -#endif - + gpio_write(&gpio, value); } - + /** Return the output setting, represented as 0 or 1 (int) * * @returns @@ -72,15 +71,9 @@ * 0 for logical 0, 1 for logical 1 */ int read() { -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - return ((_gpio->FIOPIN & _mask) ? 1 : 0); -#elif defined(TARGET_LPC11U24) - return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0); -#endif - + return gpio_read(&gpio); } - - + #ifdef MBED_OPERATORS /** A shorthand for write() */ @@ -88,39 +81,21 @@ write(value); return *this; } - + DigitalOut& operator= (DigitalOut& rhs) { write(rhs.read()); return *this; } - /** A shorthand for read() */ operator int() { return read(); } - -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); #endif protected: - - PinName _pin; - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#elif defined(TARGET_LPC11U24) - int _index; -#endif - - uint32_t _mask; - - + gpio_t gpio; }; } // namespace mbed
--- a/DirHandle.h Fri Oct 26 17:40:46 2012 +0100 +++ b/DirHandle.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - DirHandler - * Copyright (c) 2008-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_DIRHANDLE_H #define MBED_DIRHANDLE_H @@ -25,7 +42,7 @@ * * If a FileSystemLike class defines the opendir method, then the * directories of an object of that type can be accessed by - * DIR *d = opendir("/example/directory") (or opendir("/example") + * DIR *d = opendir("/example/directory") (or opendir("/example") * to open the root of the filesystem), and then using readdir(d) etc. * * The root directory is considered to contain all FileLike and @@ -34,7 +51,7 @@ */ class DirHandle { - public: +public: /** Closes the directory. * * @returns @@ -42,14 +59,14 @@ * -1 on error. */ virtual int closedir()=0; - + /** Return the directory entry at the current position, and * advances the position to the next entry. * * @returns - * A pointer to a dirent structure representing the - * directory entry at the current position, or NULL on reaching - * end of directory or error. + * A pointer to a dirent structure representing the + * directory entry at the current position, or NULL on reaching + * end of directory or error. */ virtual struct dirent *readdir()=0; @@ -70,7 +87,8 @@ * @param location The location to seek to. Must be a value returned by telldir. */ virtual void seekdir(off_t location) { } - + + virtual ~DirHandle() {} }; } // namespace mbed
--- a/Ethernet.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Ethernet.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,162 +1,176 @@ -/* mbed Microcontroller Library - Ethernet - * Copyright (c) 2009-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_ETHERNET_H -#define MBED_ETHERNET_H - -#include "device.h" - -#if DEVICE_ETHERNET - -#include "Base.h" - -namespace mbed { - -/** An ethernet interface, to use with the ethernet pins. - * - * Example: - * @code - * // Read destination and source from every ethernet packet - * - * #include "mbed.h" - * - * Ethernet eth; - * - * int main() { - * char buf[0x600]; - * - * while(1) { - * int size = eth.receive(); - * if(size > 0) { - * eth.read(buf, size); - * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n", - * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); - * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n", - * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); - * } - * - * wait(1); - * } - * } - * @endcode - */ -class Ethernet : public Base { - -public: - - /** Initialise the ethernet interface. - */ - Ethernet(); - - /** Powers the hardware down. - */ - virtual ~Ethernet(); - - enum Mode { - AutoNegotiate - , HalfDuplex10 - , FullDuplex10 - , HalfDuplex100 - , FullDuplex100 - }; - - /** Writes into an outgoing ethernet packet. - * - * It will append size bytes of data to the previously written bytes. - * - * @param data An array to write. - * @param size The size of data. - * - * @returns - * The number of written bytes. - */ - int write(const char *data, int size); - - /** Send an outgoing ethernet packet. - * - * After filling in the data in an ethernet packet it must be send. - * Send will provide a new packet to write to. - * - * @returns - * 0 if the sending was failed, - * 1 if the package is successfully sent. - */ - int send(); - - /** Recevies an arrived ethernet packet. - * - * Receiving an ethernet packet will drop the last received ethernet packet - * and make a new ethernet packet ready to read. - * If no ethernet packet is arrived it will return 0. - * - * @returns - * 0 if no ethernet packet is arrived, - * or the size of the arrived packet. - */ - int receive(); - - /** Read from an recevied ethernet packet. - * - * After receive returnd a number bigger than 0it is - * possible to read bytes from this packet. - * Read will write up to size bytes into data. - * - * It is possible to use read multible times. - * Each time read will start reading after the last read byte before. - * - * @returns - * The number of byte read. - */ - int read(char *data, int size); - - /** Gives the ethernet address of the mbed. - * - * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in. - */ - void address(char *mac); - - /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. - * - * @returns - * 0 if no ethernet link is pressent, - * 1 if an ethernet link is pressent. - * - * Example: - * @code - * // Using the Ethernet link function - * #include "mbed.h" - * - * Ethernet eth; - * - * int main() { - * wait(1); // Needed after startup. - * if (eth.link()) { - * printf("online\n"); - * } else { - * printf("offline\n"); - * } - * } - * @endcode - */ - int link(); - - /** Sets the speed and duplex parameters of an ethernet link - * - * - AutoNegotiate Auto negotiate speed and duplex - * - HalfDuplex10 10 Mbit, half duplex - * - FullDuplex10 10 Mbit, full duplex - * - HalfDuplex100 100 Mbit, half duplex - * - FullDuplex100 100 Mbit, full duplex - * - * @param mode the speed and duplex mode to set the link to: - */ - void set_link(Mode mode); - -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_ETHERNET_H +#define MBED_ETHERNET_H + +#include "platform.h" + +#if DEVICE_ETHERNET + +namespace mbed { + +/** An ethernet interface, to use with the ethernet pins. + * + * Example: + * @code + * // Read destination and source from every ethernet packet + * + * #include "mbed.h" + * + * Ethernet eth; + * + * int main() { + * char buf[0x600]; + * + * while(1) { + * int size = eth.receive(); + * if(size > 0) { + * eth.read(buf, size); + * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n", + * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n", + * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); + * } + * + * wait(1); + * } + * } + * @endcode + */ +class Ethernet { + +public: + + /** Initialise the ethernet interface. + */ + Ethernet(); + + /** Powers the hardware down. + */ + virtual ~Ethernet(); + + enum Mode { + AutoNegotiate, + HalfDuplex10, + FullDuplex10, + HalfDuplex100, + FullDuplex100 + }; + + /** Writes into an outgoing ethernet packet. + * + * It will append size bytes of data to the previously written bytes. + * + * @param data An array to write. + * @param size The size of data. + * + * @returns + * The number of written bytes. + */ + int write(const char *data, int size); + + /** Send an outgoing ethernet packet. + * + * After filling in the data in an ethernet packet it must be send. + * Send will provide a new packet to write to. + * + * @returns + * 0 if the sending was failed, + * 1 if the package is successfully sent. + */ + int send(); + + /** Recevies an arrived ethernet packet. + * + * Receiving an ethernet packet will drop the last received ethernet packet + * and make a new ethernet packet ready to read. + * If no ethernet packet is arrived it will return 0. + * + * @returns + * 0 if no ethernet packet is arrived, + * or the size of the arrived packet. + */ + int receive(); + + /** Read from an recevied ethernet packet. + * + * After receive returnd a number bigger than 0it is + * possible to read bytes from this packet. + * Read will write up to size bytes into data. + * + * It is possible to use read multible times. + * Each time read will start reading after the last read byte before. + * + * @returns + * The number of byte read. + */ + int read(char *data, int size); + + /** Gives the ethernet address of the mbed. + * + * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in. + */ + void address(char *mac); + + /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. + * + * @returns + * 0 if no ethernet link is pressent, + * 1 if an ethernet link is pressent. + * + * Example: + * @code + * // Using the Ethernet link function + * #include "mbed.h" + * + * Ethernet eth; + * + * int main() { + * wait(1); // Needed after startup. + * if (eth.link()) { + * printf("online\n"); + * } else { + * printf("offline\n"); + * } + * } + * @endcode + */ + int link(); + + /** Sets the speed and duplex parameters of an ethernet link + * + * - AutoNegotiate Auto negotiate speed and duplex + * - HalfDuplex10 10 Mbit, half duplex + * - FullDuplex10 10 Mbit, full duplex + * - HalfDuplex100 100 Mbit, half duplex + * - FullDuplex100 100 Mbit, full duplex + * + * @param mode the speed and duplex mode to set the link to: + */ + void set_link(Mode mode); +}; + +} // namespace mbed + +#endif + +#endif
--- a/FileHandle.h Fri Oct 26 17:40:46 2012 +0100 +++ b/FileHandle.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - FileHandler - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_FILEHANDLE_H #define MBED_FILEHANDLE_H @@ -20,30 +37,29 @@ /** An OO equivalent of the internal FILEHANDLE variable * and associated _sys_* functions. * - * FileHandle is an abstract class, needing at least sys_write and + * FileHandle is an abstract class, needing at least sys_write and * sys_read to be implmented for a simple interactive device. * - * No one ever directly tals to/instanciates a FileHandle - it gets + * No one ever directly tals to/instanciates a FileHandle - it gets * created by FileSystem, and wrapped up by stdio. */ class FileHandle { public: - /** Write the contents of a buffer to the file * * @param buffer the buffer to write from * @param length the number of characters to write * * @returns - * The number of characters written (possibly 0) on success, -1 on error. + * The number of characters written (possibly 0) on success, -1 on error. */ virtual ssize_t write(const void* buffer, size_t length) = 0; /** Close the file * * @returns - * Zero on success, -1 on error. + * Zero on success, -1 on error. */ virtual int close() = 0; @@ -54,18 +70,18 @@ * @param length the number of characters to read * * @returns - * The number of characters read (zero at end of file) on success, -1 on error. + * The number of characters read (zero at end of file) on success, -1 on error. */ virtual ssize_t read(void* buffer, size_t length) = 0; /** Check if the handle is for a interactive terminal device. - * If so, line buffered behaviour is used by default + * If so, line buffered behaviour is used by default * * @returns * 1 if it is a terminal, * 0 otherwise */ - virtual int isatty() = 0 ; + virtual int isatty() = 0; /** Move the file position to a given offset from a given location. * @@ -98,10 +114,10 @@ lseek(pos, SEEK_SET); return res; } - + + virtual ~FileHandle(); }; } // namespace mbed #endif -
--- a/FileLike.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* mbed Microcontroller Library - FileLike - * Copyright (c) 2008-2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_FILELIKE_H -#define MBED_FILELIKE_H - -#include "Base.h" -#include "FileHandle.h" - -namespace mbed { - -/** A file-like object is one that can be opened with fopen by - * fopen("/name", mode). It is intersection of the classes Base and - * FileHandle. - */ -class FileLike : public Base, public FileHandle { - - public: - /** FileLike constructor - * - * @param name The name to use to open the file. - */ - FileLike(const char *name) : Base(name) { } - virtual ~FileLike(); - -}; - -} // namespace mbed - -#endif
--- a/FileSystemLike.h Fri Oct 26 17:40:46 2012 +0100 +++ b/FileSystemLike.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,99 +1,150 @@ -/* mbed Microcontroller Library - FileSystemLike - * Copyright (c) 2008-2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_FILESYSTEMLIKE_H -#define MBED_FILESYSTEMLIKE_H - -#ifdef __ARMCC_VERSION -# define O_RDONLY 0 -# define O_WRONLY 1 -# define O_RDWR 2 -# define O_CREAT 0x0200 -# define O_TRUNC 0x0400 -# define O_APPEND 0x0008 -typedef int mode_t; -#else -# include <sys/fcntl.h> -#endif -#include "Base.h" -#include "FileHandle.h" -#include "DirHandle.h" - -namespace mbed { - -/** A filesystem-like object is one that can be used to open files - * though it by fopen("/name/filename", mode) - * - * Implementations must define at least open (the default definitions - * of the rest of the functions just return error values). - */ -class FileSystemLike : public Base { - - public: - - /** FileSystemLike constructor - * - * @param name The name to use for the filesystem. - */ - FileSystemLike(const char *name) : Base(name) {} - - /** Opens a file from the filesystem - * - * @param filename The name of the file to open. - * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with - * zero or more of O_CREAT, O_TRUNC, or O_APPEND. - * - * @returns - * A pointer to a FileHandle object representing the - * file on success, or NULL on failure. - */ - virtual FileHandle *open(const char *filename, int flags) = 0; - - /** Remove a file from the filesystem. - * - * @param filename the name of the file to remove. - * @param returns 0 on success, -1 on failure. - */ - virtual int remove(const char *filename) { return -1; }; - - /** Rename a file in the filesystem. - * - * @param oldname the name of the file to rename. - * @param newname the name to rename it to. - * - * @returns - * 0 on success, - * -1 on failure. - */ - virtual int rename(const char *oldname, const char *newname) { return -1; }; - - /** Opens a directory in the filesystem and returns a DirHandle - * representing the directory stream. - * - * @param name The name of the directory to open. - * - * @returns - * A DirHandle representing the directory stream, or - * NULL on failure. - */ - virtual DirHandle *opendir(const char *name) { return NULL; }; - - /** Creates a directory in the filesystem. - * - * @param name The name of the directory to create. - * @param mode The permissions to create the directory with. - * - * @returns - * 0 on success, - * -1 on failure. - */ - virtual int mkdir(const char *name, mode_t mode) { return -1; } - - // TODO other filesystem functions (mkdir, rm, rn, ls etc) - -}; - -} // namespace mbed - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_FILESYSTEMLIKE_H +#define MBED_FILESYSTEMLIKE_H + +#ifdef __ARMCC_VERSION +# define O_RDONLY 0 +# define O_WRONLY 1 +# define O_RDWR 2 +# define O_CREAT 0x0200 +# define O_TRUNC 0x0400 +# define O_APPEND 0x0008 +typedef int mode_t; + +#else +# include <sys/fcntl.h> +#endif + +#include "platform.h" + +#include "FileHandle.h" +#include "DirHandle.h" + +namespace mbed { + +/** A filesystem-like object is one that can be used to open files + * though it by fopen("/name/filename", mode) + * + * Implementations must define at least open (the default definitions + * of the rest of the functions just return error values). + */ +class FileSystemLike { + +public: + /** FileSystemLike constructor + * + * @param name The name to use for the filesystem. + */ + FileSystemLike(const char *name); + + virtual ~FileSystemLike(); + + /* Function lookup + * Lookup and return the object that has the given name. + * + * Variables + * name - the name to lookup. + * len - the length of name. + */ + static FileSystemLike *lookup(const char *name, unsigned int len); + + static DirHandle *opendir(); + friend class BaseDirHandle; + + /** Opens a file from the filesystem + * + * @param filename The name of the file to open. + * @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with + * zero or more of O_CREAT, O_TRUNC, or O_APPEND. + * + * @returns + * A pointer to a FileHandle object representing the + * file on success, or NULL on failure. + */ + virtual FileHandle *open(const char *filename, int flags) = 0; + + /** Remove a file from the filesystem. + * + * @param filename the name of the file to remove. + * @param returns 0 on success, -1 on failure. + */ + virtual int remove(const char *filename) { return -1; }; + + /** Rename a file in the filesystem. + * + * @param oldname the name of the file to rename. + * @param newname the name to rename it to. + * + * @returns + * 0 on success, + * -1 on failure. + */ + virtual int rename(const char *oldname, const char *newname) { return -1; }; + + /** Opens a directory in the filesystem and returns a DirHandle + * representing the directory stream. + * + * @param name The name of the directory to open. + * + * @returns + * A DirHandle representing the directory stream, or + * NULL on failure. + */ + virtual DirHandle *opendir(const char *name) { return NULL; }; + + /** Creates a directory in the filesystem. + * + * @param name The name of the directory to create. + * @param mode The permissions to create the directory with. + * + * @returns + * 0 on success, + * -1 on failure. + */ + virtual int mkdir(const char *name, mode_t mode) { return -1; } + + // TODO other filesystem functions (mkdir, rm, rn, ls etc) + +protected: + static FileSystemLike *_head; + FileSystemLike *_next; + const char *_name; +}; + +class FilePath { +public: + FilePath(const char* file_path); + + const char* fileName(void); + FileSystemLike* fileSystem(void); + + static FileSystemLike* getFileSystem(const char* path); + +private: + const char* file_name; + FileSystemLike* fs; +}; + +} // namespace mbed + +#endif
--- a/FunctionPointer.h Fri Oct 26 17:40:46 2012 +0100 +++ b/FunctionPointer.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - FunctionPointer - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_FUNCTIONPOINTER_H #define MBED_FUNCTIONPOINTER_H @@ -12,7 +29,6 @@ /** A class for storing and calling a pointer to a static or member void function */ class FunctionPointer { - public: /** Create a FunctionPointer, attaching a static function @@ -26,11 +42,11 @@ * @param object The object pointer to invoke the member function on (i.e. the this pointer) * @param function The address of the void member function to attach */ - template<typename T> + template<typename T> FunctionPointer(T *object, void (T::*member)(void)) { attach(object, member); } - + /** Attach a static function * * @param function The void static function to attach (default is none) @@ -49,37 +65,24 @@ _membercaller = &FunctionPointer::membercaller<T>; _function = 0; } - + /** Call the attached static or member function - */ + */ void call(); - + private: - template<typename T> - static void membercaller(void *object, char *member) { + static void membercaller(void *object, char *member) { T* o = static_cast<T*>(object); void (T::*m)(void); memcpy((char*)&m, member, sizeof(m)); (o->*m)(); } - /** Static function pointer - 0 if none attached - */ - void (*_function)(void); - - /** Object this pointer - 0 if none attached - */ - void *_object; - - /** Raw member function pointer storage - converted back by registered _membercaller - */ - char _member[16]; - - /** Registered membercaller function to convert back and call _member on _object - */ - void (*_membercaller)(void*, char*); - + void (*_function)(void); // static function pointer - 0 if none attached + void *_object; // object this pointer - 0 if none attached + char _member[16]; // raw member function pointer storage - converted back by registered _membercaller + void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object }; } // namespace mbed
--- a/I2C.h Fri Oct 26 17:40:46 2012 +0100 +++ b/I2C.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,18 +1,32 @@ -/* mbed Microcontroller Library - I2C - * Copyright (c) 2007-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_I2C_H #define MBED_I2C_H -#include "device.h" +#include "platform.h" #if DEVICE_I2C -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "i2c_api.h" namespace mbed { @@ -33,20 +47,19 @@ * } * @endcode */ -class I2C : public Base { +class I2C { public: - enum RxStatus { - NoData - , MasterGeneralCall - , MasterWrite - , MasterRead + NoData, + MasterGeneralCall, + MasterWrite, + MasterRead }; enum Acknowledge { - NoACK = 0 - , ACK = 1 + NoACK = 0, + ACK = 1 }; /** Create an I2C Master interface, connected to the specified pins @@ -54,7 +67,7 @@ * @param sda I2C data line pin * @param scl I2C clock line pin */ - I2C(PinName sda, PinName scl, const char *name = NULL); + I2C(PinName sda, PinName scl); /** Set the frequency of the I2C interface * @@ -64,8 +77,8 @@ /** Read from an I2C slave * - * Performs a complete read transaction. The bottom bit of - * the address is forced to 1 to indicate a read. + * Performs a complete read transaction. The bottom bit of + * the address is forced to 1 to indicate a read. * * @param address 8-bit I2C slave address [ addr | 1 ] * @param data Pointer to the byte-array to read data in to @@ -76,7 +89,7 @@ * 0 on success (ack), * non-0 on failure (nack) */ - int read(int address, char *data, int length, bool repeated = false); + int read(int address, char *data, int length, bool repeated = false); /** Read a single byte from the I2C bus * @@ -89,8 +102,8 @@ /** Write to an I2C slave * - * Performs a complete write transaction. The bottom bit of - * the address is forced to 0 to indicate a write. + * Performs a complete write transaction. The bottom bit of + * the address is forced to 0 to indicate a write. * * @param address 8-bit I2C slave address [ addr | 0 ] * @param data Pointer to the byte-array data to send @@ -115,6 +128,7 @@ /** Creates a start condition on the I2C bus */ + void start(void); /** Creates a stop condition on the I2C bus @@ -122,13 +136,11 @@ void stop(void); protected: - void aquire(); - - I2CName _i2c; + + i2c_t _i2c; static I2C *_owner; int _hz; - }; } // namespace mbed @@ -136,4 +148,3 @@ #endif #endif -
--- a/I2CSlave.h Fri Oct 26 17:40:46 2012 +0100 +++ b/I2CSlave.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,18 +1,32 @@ -/* mbed Microcontroller Library - I2CSlave - * Copyright (c) 2007-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_I2C_SLAVE_H #define MBED_I2C_SLAVE_H -#include "device.h" +#include "platform.h" #if DEVICE_I2CSLAVE -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "i2c_api.h" namespace mbed { @@ -50,15 +64,14 @@ * } * @endcode */ -class I2CSlave : public Base { +class I2CSlave { public: - enum RxStatus { - NoData = 0 - , ReadAddressed = 1 - , WriteGeneral = 2 - , WriteAddressed = 3 + NoData = 0, + ReadAddressed = 1, + WriteGeneral = 2, + WriteAddressed = 3 }; /** Create an I2C Slave interface, connected to the specified pins. @@ -66,7 +79,7 @@ * @param sda I2C data line pin * @param scl I2C clock line pin */ - I2CSlave(PinName sda, PinName scl, const char *name = NULL); + I2CSlave(PinName sda, PinName scl); /** Set the frequency of the I2C interface * @@ -127,8 +140,8 @@ /** Sets the I2C slave address. * * @param address The address to set for the slave (ignoring the least - * signifcant bit). If set to 0, the slave will only respond to the - * general call address. + * signifcant bit). If set to 0, the slave will only respond to the + * general call address. */ void address(int address); @@ -137,8 +150,7 @@ void stop(void); protected: - - I2CName _i2c; + i2c_t _i2c; }; } // namespace mbed @@ -146,4 +158,3 @@ #endif #endif -
--- a/InterruptIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/InterruptIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,25 +1,35 @@ -/* mbed Microcontroller Library - InterruptIn - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_INTERRUPTIN_H #define MBED_INTERRUPTIN_H -#include "device.h" +#include "platform.h" #if DEVICE_INTERRUPTIN -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" -#include "FunctionPointer.h" +#include "gpio_api.h" +#include "gpio_irq_api.h" -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) -#define CHANNEL_NUM 48 -#elif defined(TARGET_LPC11U24) -#define CHANNEL_NUM 8 -#endif +#include "FunctionPointer.h" namespace mbed { @@ -47,7 +57,7 @@ * } * @endcode */ -class InterruptIn : public Base { +class InterruptIn { public: @@ -56,11 +66,9 @@ * @param pin InterruptIn pin to connect to * @param name (optional) A string to identify the object */ - InterruptIn(PinName pin, const char *name = NULL); -#if defined(TARGET_LPC11U24) + InterruptIn(PinName pin); virtual ~InterruptIn(); -#endif - + int read(); #ifdef MBED_OPERATORS operator int(); @@ -81,7 +89,7 @@ template<typename T> void rise(T* tptr, void (T::*mptr)(void)) { _rise.attach(tptr, mptr); - setup_interrupt(1, 1); + gpio_irq_set(&gpio_irq, IRQ_RISE, 1); } /** Attach a function to call when a falling edge occurs on the input @@ -98,7 +106,7 @@ template<typename T> void fall(T* tptr, void (T::*mptr)(void)) { _fall.attach(tptr, mptr); - setup_interrupt(0, 1); + gpio_irq_set(&gpio_irq, IRQ_FALL, 1); } /** Set the input pin mode @@ -107,28 +115,14 @@ */ void mode(PinMode pull); - static InterruptIn *_irq_objects[CHANNEL_NUM]; + static void _irq_handler(uint32_t id, gpio_irq_event event); -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - static void _irq(); -#elif defined(TARGET_LPC11U24) - static void handle_interrupt_in(unsigned int channel); - static void _irq0(); static void _irq1(); - static void _irq2(); static void _irq3(); - static void _irq4(); static void _irq5(); - static void _irq6(); static void _irq7(); -#endif - protected: - PinName _pin; -#if defined(TARGET_LPC11U24) - Channel _channel; -#endif + gpio_t gpio; + gpio_irq_t gpio_irq; + FunctionPointer _rise; FunctionPointer _fall; - - void setup_interrupt(int rising, int enable); - }; } // namespace mbed
Binary file LPC11U24/ARM/capi.ar has changed
Binary file LPC11U24/ARM/cmsis_nvic.o has changed
Binary file LPC11U24/ARM/core_cm0.o has changed
Binary file LPC11U24/ARM/cpp.ar has changed
Binary file LPC11U24/ARM/mbed.ar has changed
Binary file LPC11U24/ARM/startup_LPC11xx.o has changed
Binary file LPC11U24/ARM/sys.o has changed
Binary file LPC11U24/ARM/system_LPC11Uxx.o has changed
--- a/LPC11U24/LPC11Uxx.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC11U24/LPC11Uxx.h Wed Nov 21 10:49:56 2012 +0000 @@ -219,9 +219,9 @@ typedef struct { /*!< (@ 0x40014000) CT32B0 Structure */ __IO uint32_t IR; /*!< (@ 0x40014000) Interrupt Register */ __IO uint32_t TCR; /*!< (@ 0x40014004) Timer Control Register */ - __IO uint32_t TC; /*!< (@ 0x40014008) Timer Counter */ - __IO uint32_t PR; /*!< (@ 0x4001400C) Prescale Register */ - __IO uint32_t PC; /*!< (@ 0x40014010) Prescale Counter */ + __IO uint32_t TC; /*!< (@ 0x40014008) Timer Counter */ + __IO uint32_t PR; /*!< (@ 0x4001400C) Prescale Register */ + __IO uint32_t PC; /*!< (@ 0x40014010) Prescale Counter */ __IO uint32_t MCR; /*!< (@ 0x40014014) Match Control Register */ union { __IO uint32_t MR[4]; /*!< (@ 0x40014018) Match Register */ @@ -236,10 +236,10 @@ union{ __I uint32_t CR[4]; /*!< (@ 0x4001402C) Capture Register */ struct{ - __I uint32_t CR0; /*!< (@ 0x4001802C) Capture Register. CR 0 */ - __I uint32_t CR1; /*!< (@ 0x40018030) Capture Register. CR 1 */ - __I uint32_t CR2; /*!< (@ 0x40018034) Capture Register. CR 2 */ - __I uint32_t CR3; /*!< (@ 0x40018038) Capture Register. CR 3 */ + __I uint32_t CR0; /*!< (@ 0x4001802C) Capture Register. CR 0 */ + __I uint32_t CR1; /*!< (@ 0x40018030) Capture Register. CR 1 */ + __I uint32_t CR2; /*!< (@ 0x40018034) Capture Register. CR 2 */ + __I uint32_t CR3; /*!< (@ 0x40018038) Capture Register. CR 3 */ }; }; __IO uint32_t EMR; /*!< (@ 0x4001403C) External Match Register */ @@ -267,14 +267,14 @@ union{ __I uint32_t DR[8]; /*!< (@ 0x4001C010) A/D Channel Data Register*/ struct{ - __IO uint32_t DR0; /*!< (@ 0x40020010) A/D Channel Data Register 0*/ - __IO uint32_t DR1; /*!< (@ 0x40020014) A/D Channel Data Register 1*/ - __IO uint32_t DR2; /*!< (@ 0x40020018) A/D Channel Data Register 2*/ - __IO uint32_t DR3; /*!< (@ 0x4002001C) A/D Channel Data Register 3*/ - __IO uint32_t DR4; /*!< (@ 0x40020020) A/D Channel Data Register 4*/ - __IO uint32_t DR5; /*!< (@ 0x40020024) A/D Channel Data Register 5*/ - __IO uint32_t DR6; /*!< (@ 0x40020028) A/D Channel Data Register 6*/ - __IO uint32_t DR7; /*!< (@ 0x4002002C) A/D Channel Data Register 7*/ + __IO uint32_t DR0; /*!< (@ 0x40020010) A/D Channel Data Register 0*/ + __IO uint32_t DR1; /*!< (@ 0x40020014) A/D Channel Data Register 1*/ + __IO uint32_t DR2; /*!< (@ 0x40020018) A/D Channel Data Register 2*/ + __IO uint32_t DR3; /*!< (@ 0x4002001C) A/D Channel Data Register 3*/ + __IO uint32_t DR4; /*!< (@ 0x40020020) A/D Channel Data Register 4*/ + __IO uint32_t DR5; /*!< (@ 0x40020024) A/D Channel Data Register 5*/ + __IO uint32_t DR6; /*!< (@ 0x40020028) A/D Channel Data Register 6*/ + __IO uint32_t DR7; /*!< (@ 0x4002002C) A/D Channel Data Register 7*/ }; }; __I uint32_t STAT; /*!< (@ 0x4001C030) A/D Status Register. */ @@ -295,10 +295,10 @@ union{ __IO uint32_t GPREG[4]; /*!< (@ 0x40038004) General purpose register 0 */ struct{ - __IO uint32_t GPREG0; /*!< (@ 0x40038004) General purpose register 0 */ - __IO uint32_t GPREG1; /*!< (@ 0x40038008) General purpose register 1 */ - __IO uint32_t GPREG2; /*!< (@ 0x4003800C) General purpose register 2 */ - __IO uint32_t GPREG3; /*!< (@ 0x40038010) General purpose register 3 */ + __IO uint32_t GPREG0; /*!< (@ 0x40038004) General purpose register 0 */ + __IO uint32_t GPREG1; /*!< (@ 0x40038008) General purpose register 1 */ + __IO uint32_t GPREG2; /*!< (@ 0x4003800C) General purpose register 2 */ + __IO uint32_t GPREG3; /*!< (@ 0x40038010) General purpose register 3 */ }; }; } LPC_PMU_Type; @@ -587,19 +587,19 @@ __IO uint32_t W[64]; /*!< (@ 0x50001000) Word pin registers port 0/1 */ }; uint32_t RESERVED1[960]; - __IO uint32_t DIR[2]; /* 0x2000 */ + __IO uint32_t DIR[2]; /* 0x2000 */ uint32_t RESERVED2[30]; - __IO uint32_t MASK[2]; /* 0x2080 */ + __IO uint32_t MASK[2]; /* 0x2080 */ uint32_t RESERVED3[30]; - __IO uint32_t PIN[2]; /* 0x2100 */ + __IO uint32_t PIN[2]; /* 0x2100 */ uint32_t RESERVED4[30]; - __IO uint32_t MPIN[2]; /* 0x2180 */ + __IO uint32_t MPIN[2]; /* 0x2180 */ uint32_t RESERVED5[30]; - __IO uint32_t SET[2]; /* 0x2200 */ + __IO uint32_t SET[2]; /* 0x2200 */ uint32_t RESERVED6[30]; - __O uint32_t CLR[2]; /* 0x2280 */ + __O uint32_t CLR[2]; /* 0x2280 */ uint32_t RESERVED7[30]; - __O uint32_t NOT[2]; /* 0x2300 */ + __O uint32_t NOT[2]; /* 0x2300 */ } LPC_GPIO_Type;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/PeripheralNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,77 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = (int)LPC_USART_BASE +} UARTName; + +typedef enum { + I2C_0 = (int)LPC_I2C_BASE +} I2CName; + +typedef enum { + ADC0_0 = 0, + ADC0_1, + ADC0_2, + ADC0_3, + ADC0_4, + ADC0_5, + ADC0_6, + ADC0_7 +} ADCName; + +typedef enum { + SPI_0 = (int)LPC_SSP0_BASE, + SPI_1 = (int)LPC_SSP1_BASE +} SPIName; + +typedef enum { + PWM_1 = 0, + PWM_2, + PWM_3, + PWM_4, + PWM_5, + PWM_6, + PWM_7, + PWM_8, + PWM_9, + PWM_10, + PWM_11 +} PWMName; + +#define STDIO_UART_TX USBTX +#define STDIO_UART_RX USBRX +#define STDIO_UART UART_0 + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/PinNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,171 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PINNAMES_H +#define MBED_PINNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +#define PORT_SHIFT 5 + +typedef enum { + // LPC11U Pin Names + P0_0 = 0, + P0_1 = 1, + P0_2 = 2, + P0_3 = 3, + P0_4 = 4, + P0_5 = 5, + P0_6 = 6, + P0_7 = 7, + P0_8 = 8, + P0_9 = 9, + P0_10 = 10, + P0_11 = 11, + P0_12 = 12, + P0_13 = 13, + P0_14 = 14, + P0_15 = 15, + P0_16 = 16, + P0_17 = 17, + P0_18 = 18, + P0_19 = 19, + P0_20 = 20, + P0_21 = 21, + P0_22 = 22, + P0_23 = 23, + P0_24 = 24, + P0_25 = 25, + P0_26 = 26, + P0_27 = 27, + + P1_0 = 32, + P1_1 = 33, + P1_2 = 34, + P1_3 = 35, + P1_4 = 36, + P1_5 = 37, + P1_6 = 38, + P1_7 = 39, + P1_8 = 40, + P1_9 = 41, + P1_10 = 42, + P1_11 = 43, + P1_12 = 44, + P1_13 = 45, + P1_14 = 46, + P1_15 = 47, + P1_16 = 48, + P1_17 = 49, + P1_18 = 50, + P1_19 = 51, + P1_20 = 52, + P1_21 = 53, + P1_22 = 54, + P1_23 = 55, + P1_24 = 56, + P1_25 = 57, + P1_26 = 58, + P1_27 = 59, + P1_28 = 60, + P1_29 = 61, + + P1_31 = 63, + + // mbed DIP Pin Names + p5 = P0_9, + p6 = P0_8, + p7 = P1_29, + p8 = P0_2, + p9 = P1_27, + p10 = P1_26, + p11 = P1_22, + p12 = P1_21, + p13 = P1_20, + p14 = P1_23, + p15 = P0_11, + p16 = P0_12, + p17 = P0_13, + p18 = P0_14, + p19 = P0_16, + p20 = P0_22, + p21 = P0_7, + p22 = P0_17, + p23 = P1_17, + p24 = P1_18, + p25 = P1_24, + p26 = P1_25, + p27 = P0_4, + p28 = P0_5, + p29 = P1_5, + p30 = P1_2, + + p33 = P0_3, + p34 = P1_15, + p35 = P0_20, + p36 = P0_21, + + // Other mbed Pin Names + LED1 = P1_8, + LED2 = P1_9, + LED3 = P1_10, + LED4 = P1_11, + + USBTX = P0_19, + USBRX = P0_18, + + // Not connected + NC = (int)0xFFFFFFFF, +} PinName; + +typedef enum { + CHANNEL0 = FLEX_INT0_IRQn, + CHANNEL1 = FLEX_INT1_IRQn, + CHANNEL2 = FLEX_INT2_IRQn, + CHANNEL3 = FLEX_INT3_IRQn, + CHANNEL4 = FLEX_INT4_IRQn, + CHANNEL5 = FLEX_INT5_IRQn, + CHANNEL6 = FLEX_INT6_IRQn, + CHANNEL7 = FLEX_INT7_IRQn +} Channel; + +typedef enum { + PullUp = 2, + PullDown = 1, + PullNone = 0, + Repeater = 3, + OpenDrain = 4 +} PinMode; + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/PortNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,37 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + Port0 = 0, + Port1 = 1 +} PortName; + +#ifdef __cplusplus +} +#endif +#endif
--- a/LPC11U24/cmsis.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC11U24/cmsis.h Wed Nov 21 10:49:56 2012 +0000 @@ -7,10 +7,6 @@ #ifndef MBED_CMSIS_H #define MBED_CMSIS_H -#ifndef TARGET_LPC11U24 -#define TARGET_LPC11U24 -#endif - #include "LPC11Uxx.h" #include "cmsis_nvic.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/device.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 + +#define DEVICE_INTERRUPTIN 1 + +#define DEVICE_ANALOGIN 1 +#define DEVICE_ANALOGOUT 0 + +#define DEVICE_SERIAL 1 + +#define DEVICE_I2C 1 +#define DEVICE_I2CSLAVE 1 + +#define DEVICE_SPI 1 +#define DEVICE_SPISLAVE 1 + +#define DEVICE_CAN 0 + +#define DEVICE_RTC 0 + +#define DEVICE_ETHERNET 0 + +#define DEVICE_PWMOUT 1 + +#define DEVICE_LOCALFILESYSTEM 1 + +#define DEVICE_SLEEP 1 + +#define DEVICE_DEBUG_AWARENESS 0 + +#define DEVICE_STDIO_ERROR 1 + +#include "objects.h" + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/gpio_object.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_GPIO_OBJECT_H +#define MBED_GPIO_OBJECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + uint32_t mask; + + __IO uint32_t *reg_dir; + __IO uint32_t *reg_set; + __IO uint32_t *reg_clr; + __I uint32_t *reg_in; +} gpio_t; + +static inline void gpio_write(gpio_t *obj, int value) { + if (value) + *obj->reg_set = obj->mask; + else + *obj->reg_clr = obj->mask; +} + +static inline int gpio_read(gpio_t *obj) { + return ((*obj->reg_in & obj->mask) ? 1 : 0); +} + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC11U24/objects.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "cmsis.h" +#include "PortNames.h" +#include "PeripheralNames.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_irq_s { + uint32_t ch; +}; + +struct port_s { + __IO uint32_t *reg_dir; + __IO uint32_t *reg_mpin; + PortName port; + uint32_t mask; +}; + +struct pwmout_s { + PWMName pwm; +}; + +struct serial_s { + LPC_USART_Type *uart; + int index; +}; + +struct analogin_s { + ADCName adc; +}; + +struct i2c_s { + LPC_I2C_Type *i2c; +}; + +struct spi_s { + LPC_SSPx_Type *spi; +}; + +#include "gpio_object.h" + +#ifdef __cplusplus +} +#endif + +#endif
--- a/LPC11U24/power_api.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC11U24/power_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -26,12 +26,12 @@ #define PWRROMD_PRESENT -typedef struct _PWRD { +typedef struct _PWRD { void (*set_pll)(unsigned int cmd[], unsigned int resp[]); void (*set_power)(unsigned int cmd[], unsigned int resp[]); } PWRD; -typedef struct _ROM { +typedef struct _ROM { #ifdef USBROMD_PRESENT const USB * pUSBD; #else @@ -51,26 +51,26 @@ } ROM; //PLL setup related definitions -#define CPU_FREQ_EQU 0 //main PLL freq must be equal to the specified -#define CPU_FREQ_LTE 1 //main PLL freq must be less than or equal the specified -#define CPU_FREQ_GTE 2 //main PLL freq must be greater than or equal the specified -#define CPU_FREQ_APPROX 3 //main PLL freq must be as close as possible the specified +#define CPU_FREQ_EQU 0 //main PLL freq must be equal to the specified +#define CPU_FREQ_LTE 1 //main PLL freq must be less than or equal the specified +#define CPU_FREQ_GTE 2 //main PLL freq must be greater than or equal the specified +#define CPU_FREQ_APPROX 3 //main PLL freq must be as close as possible the specified -#define PLL_CMD_SUCCESS 0 //PLL setup successfully found -#define PLL_INVALID_FREQ 1 //specified freq out of range (either input or output) -#define PLL_INVALID_MODE 2 //invalid mode (see above for valid) specified -#define PLL_FREQ_NOT_FOUND 3 //specified freq not found under specified conditions -#define PLL_NOT_LOCKED 4 //PLL not locked => no changes to the PLL setup +#define PLL_CMD_SUCCESS 0 //PLL setup successfully found +#define PLL_INVALID_FREQ 1 //specified freq out of range (either input or output) +#define PLL_INVALID_MODE 2 //invalid mode (see above for valid) specified +#define PLL_FREQ_NOT_FOUND 3 //specified freq not found under specified conditions +#define PLL_NOT_LOCKED 4 //PLL not locked => no changes to the PLL setup //power setup elated definitions -#define PARAM_DEFAULT 0 //default power settings (voltage regulator, flash interface) -#define PARAM_CPU_PERFORMANCE 1 //setup for maximum CPU performance (higher current, more computation) -#define PARAM_EFFICIENCY 2 //balanced setting (power vs CPU performance) -#define PARAM_LOW_CURRENT 3 //lowest active current, lowest CPU performance +#define PARAM_DEFAULT 0 //default power settings (voltage regulator, flash interface) +#define PARAM_CPU_PERFORMANCE 1 //setup for maximum CPU performance (higher current, more computation) +#define PARAM_EFFICIENCY 2 //balanced setting (power vs CPU performance) +#define PARAM_LOW_CURRENT 3 //lowest active current, lowest CPU performance -#define PARAM_CMD_SUCCESS 0 //power setting successfully found -#define PARAM_INVALID_FREQ 1 //specified freq out of range (=0 or > 50 MHz) -#define PARAM_INVALID_MODE 2 //specified mode not valid (see above for valid) +#define PARAM_CMD_SUCCESS 0 //power setting successfully found +#define PARAM_INVALID_FREQ 1 //specified freq out of range (=0 or > 50 MHz) +#define PARAM_INVALID_MODE 2 //specified mode not valid (see above for valid) #define MAX_CLOCK_KHZ_PARAM 50000
Binary file LPC11U24/uARM/capi.ar has changed
Binary file LPC11U24/uARM/cmsis_nvic.o has changed
Binary file LPC11U24/uARM/core_cm0.o has changed
Binary file LPC11U24/uARM/cpp.ar has changed
Binary file LPC11U24/uARM/mbed.ar has changed
Binary file LPC11U24/uARM/startup_LPC11xx.o has changed
Binary file LPC11U24/uARM/sys.o has changed
Binary file LPC11U24/uARM/system_LPC11Uxx.o has changed
Binary file LPC1768/ARM/capi.ar has changed
Binary file LPC1768/ARM/cmsis_nvic.o has changed
Binary file LPC1768/ARM/core_cm3.o has changed
Binary file LPC1768/ARM/cpp.ar has changed
Binary file LPC1768/ARM/mbed.ar has changed
Binary file LPC1768/ARM/startup_LPC17xx.o has changed
Binary file LPC1768/ARM/sys.o has changed
Binary file LPC1768/ARM/system_LPC17xx.o has changed
--- a/LPC1768/GCC_ARM/LPC1768.ld Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC1768/GCC_ARM/LPC1768.ld Wed Nov 21 10:49:56 2012 +0000 @@ -1,5 +1,4 @@ /* Linker script for mbed LPC1768 */ -GROUP(-lstdc++ -lsupc++ -lm -lc -lnosys -lgcc) /* Linker script to configure memory regions. */ MEMORY
Binary file LPC1768/GCC_ARM/cmsis_nvic.o has changed
Binary file LPC1768/GCC_ARM/core_cm3.o has changed
Binary file LPC1768/GCC_ARM/libcapi.a has changed
Binary file LPC1768/GCC_ARM/libcpp.a has changed
Binary file LPC1768/GCC_ARM/libmbed.a has changed
Binary file LPC1768/GCC_ARM/startup_LPC17xx.o has changed
Binary file LPC1768/GCC_ARM/system_LPC17xx.o has changed
Binary file LPC1768/GCC_CR/libcapi.a has changed
Binary file LPC1768/GCC_CR/libcpp.a has changed
Binary file LPC1768/GCC_CR/libmbed.a has changed
Binary file LPC1768/GCC_CS/libcapi.a has changed
Binary file LPC1768/GCC_CS/libcpp.a has changed
Binary file LPC1768/GCC_CS/libmbed.a has changed
--- a/LPC1768/LPC17xx.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC1768/LPC17xx.h Wed Nov 21 10:49:56 2012 +0000 @@ -129,8 +129,8 @@ __IO uint32_t CCLKCFG; __IO uint32_t USBCLKCFG; __IO uint32_t CLKSRCSEL; - __IO uint32_t CANSLEEPCLR; - __IO uint32_t CANWAKEFLAGS; + __IO uint32_t CANSLEEPCLR; + __IO uint32_t CANWAKEFLAGS; uint32_t RESERVED4[10]; __IO uint32_t EXTINT; /* External Interrupts */ uint32_t RESERVED5;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/PeripheralNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,86 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = (int)LPC_UART0_BASE, + UART_1 = (int)LPC_UART1_BASE, + UART_2 = (int)LPC_UART2_BASE, + UART_3 = (int)LPC_UART3_BASE +} UARTName; + +typedef enum { + ADC0_0 = 0, + ADC0_1, + ADC0_2, + ADC0_3, + ADC0_4, + ADC0_5, + ADC0_6, + ADC0_7 +} ADCName; + +typedef enum { + DAC_0 = 0 +} DACName; + +typedef enum { + SPI_0 = (int)LPC_SSP0_BASE, + SPI_1 = (int)LPC_SSP1_BASE +} SPIName; + +typedef enum { + I2C_0 = (int)LPC_I2C0_BASE, + I2C_1 = (int)LPC_I2C1_BASE, + I2C_2 = (int)LPC_I2C2_BASE +} I2CName; + +typedef enum { + PWM_1 = 1, + PWM_2, + PWM_3, + PWM_4, + PWM_5, + PWM_6 +} PWMName; + +typedef enum { + CAN_1 = (int)LPC_CAN1_BASE, + CAN_2 = (int)LPC_CAN2_BASE +} CANName; + +#define STDIO_UART_TX USBTX +#define STDIO_UART_RX USBRX +#define STDIO_UART UART_0 + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/PinNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,115 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PINNAMES_H +#define MBED_PINNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +#define PORT_SHIFT 5 + +typedef enum { + // LPC Pin Names + P0_0 = LPC_GPIO0_BASE, + P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12, P0_13, P0_14, P0_15, P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23, P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31, + P1_0, P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7, P1_8, P1_9, P1_10, P1_11, P1_12, P1_13, P1_14, P1_15, P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23, P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31, + P2_0, P2_1, P2_2, P2_3, P2_4, P2_5, P2_6, P2_7, P2_8, P2_9, P2_10, P2_11, P2_12, P2_13, P2_14, P2_15, P2_16, P2_17, P2_18, P2_19, P2_20, P2_21, P2_22, P2_23, P2_24, P2_25, P2_26, P2_27, P2_28, P2_29, P2_30, P2_31, + P3_0, P3_1, P3_2, P3_3, P3_4, P3_5, P3_6, P3_7, P3_8, P3_9, P3_10, P3_11, P3_12, P3_13, P3_14, P3_15, P3_16, P3_17, P3_18, P3_19, P3_20, P3_21, P3_22, P3_23, P3_24, P3_25, P3_26, P3_27, P3_28, P3_29, P3_30, P3_31, + P4_0, P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7, P4_8, P4_9, P4_10, P4_11, P4_12, P4_13, P4_14, P4_15, P4_16, P4_17, P4_18, P4_19, P4_20, P4_21, P4_22, P4_23, P4_24, P4_25, P4_26, P4_27, P4_28, P4_29, P4_30, P4_31, + + // mbed DIP Pin Names + p5 = P0_9, + p6 = P0_8, + p7 = P0_7, + p8 = P0_6, + p9 = P0_0, + p10 = P0_1, + p11 = P0_18, + p12 = P0_17, + p13 = P0_15, + p14 = P0_16, + p15 = P0_23, + p16 = P0_24, + p17 = P0_25, + p18 = P0_26, + p19 = P1_30, + p20 = P1_31, + p21 = P2_5, + p22 = P2_4, + p23 = P2_3, + p24 = P2_2, + p25 = P2_1, + p26 = P2_0, + p27 = P0_11, + p28 = P0_10, + p29 = P0_5, + p30 = P0_4, + + // Other mbed Pin Names +#ifdef MCB1700 + LED1 = P1_28, + LED2 = P1_29, + LED3 = P1_31, + LED4 = P2_2, +#else + LED1 = P1_18, + LED2 = P1_20, + LED3 = P1_21, + LED4 = P1_23, +#endif + USBTX = P0_2, + USBRX = P0_3, + + // Not connected + NC = (int)0xFFFFFFFF +} PinName; + +typedef enum { + PullUp = 0, + PullDown = 3, + PullNone = 2, + OpenDrain = 4 +} PinMode; + +// version of PINCON_TypeDef using register arrays +typedef struct { + __IO uint32_t PINSEL[11]; + uint32_t RESERVED0[5]; + __IO uint32_t PINMODE[10]; + __IO uint32_t PINMODE_OD[5]; +} PINCONARRAY_TypeDef; + +#define PINCONARRAY ((PINCONARRAY_TypeDef *)LPC_PINCON_BASE) + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/PortNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,40 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + Port0 = 0, + Port1 = 1, + Port2 = 2, + Port3 = 3, + Port4 = 4 +} PortName; + +#ifdef __cplusplus +} +#endif +#endif
--- a/LPC1768/cmsis.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC1768/cmsis.h Wed Nov 21 10:49:56 2012 +0000 @@ -7,10 +7,6 @@ #ifndef MBED_CMSIS_H #define MBED_CMSIS_H -#ifndef TARGET_LPC1768 -#define TARGET_LPC1768 -#endif - #include "LPC17xx.h" #include "cmsis_nvic.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/device.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 + +#define DEVICE_INTERRUPTIN 1 + +#define DEVICE_ANALOGIN 1 +#define DEVICE_ANALOGOUT 1 + +#define DEVICE_SERIAL 1 + +#define DEVICE_I2C 1 +#define DEVICE_I2CSLAVE 1 + +#define DEVICE_SPI 1 +#define DEVICE_SPISLAVE 1 + +#define DEVICE_CAN 1 + +#define DEVICE_RTC 1 + +#define DEVICE_ETHERNET 1 + +#define DEVICE_PWMOUT 1 + +#define DEVICE_LOCALFILESYSTEM 1 + +#define DEVICE_SLEEP 0 + +#define DEVICE_DEBUG_AWARENESS 1 + +#define DEVICE_STDIO_ERROR 1 + +#include "objects.h" + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/gpio_object.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_GPIO_OBJECT_H +#define MBED_GPIO_OBJECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + uint32_t mask; + + __IO uint32_t *reg_dir; + __IO uint32_t *reg_set; + __IO uint32_t *reg_clr; + __I uint32_t *reg_in; +} gpio_t; + +static inline void gpio_write(gpio_t *obj, int value) { + if (value) + *obj->reg_set = obj->mask; + else + *obj->reg_clr = obj->mask; +} + +static inline int gpio_read(gpio_t *obj) { + return ((*obj->reg_in & obj->mask) ? 1 : 0); +} + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC1768/objects.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,84 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "cmsis.h" +#include "PortNames.h" +#include "PeripheralNames.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_irq_s { + uint32_t port; + uint32_t pin; + uint32_t ch; +}; + +struct port_s { + __IO uint32_t *reg_dir; + __IO uint32_t *reg_out; + __I uint32_t *reg_in; + PortName port; + uint32_t mask; +}; + +struct pwmout_s { + __IO uint32_t *MR; + PWMName pwm; +}; + +struct serial_s { + LPC_UART_TypeDef *uart; + int index; +}; + +struct analogin_s { + ADCName adc; +}; + +struct dac_s { + DACName dac; +}; + +struct can_s { + LPC_CAN_TypeDef *dev; +}; + +struct i2c_s { + LPC_I2C_TypeDef *i2c; +}; + +struct spi_s { + LPC_SSP_TypeDef *spi; +}; + +#include "gpio_object.h" + +#ifdef __cplusplus +} +#endif + +#endif
Binary file LPC2368/ARM/capi.ar has changed
Binary file LPC2368/ARM/cmsis_nvic.o has changed
Binary file LPC2368/ARM/core_arm7.o has changed
Binary file LPC2368/ARM/cpp.ar has changed
Binary file LPC2368/ARM/mbed.ar has changed
Binary file LPC2368/ARM/sys.o has changed
Binary file LPC2368/ARM/system_LPC23xx.o has changed
Binary file LPC2368/ARM/vector_functions.o has changed
Binary file LPC2368/ARM/vector_realmonitor.o has changed
Binary file LPC2368/ARM/vector_table.o has changed
--- a/LPC2368/LPC23xx.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC2368/LPC23xx.h Wed Nov 21 10:49:56 2012 +0000 @@ -766,7 +766,7 @@ #define CM3_BASE (0xE0000000UL) */ -// TODO - #define VIC_BASE_ADDR 0xFFFFF000 +// TODO - #define VIC_BASE_ADDR 0xFFFFF000 #define LPC_WDT_BASE (0xE0000000) #define LPC_TIM0_BASE (0xE0004000)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/PeripheralNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,86 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = (int)LPC_UART0_BASE, + UART_1 = (int)LPC_UART1_BASE, + UART_2 = (int)LPC_UART2_BASE, + UART_3 = (int)LPC_UART3_BASE +} UARTName; + +typedef enum { + ADC0_0 = 0, + ADC0_1, + ADC0_2, + ADC0_3, + ADC0_4, + ADC0_5, + ADC0_6, + ADC0_7 +} ADCName; + +typedef enum { + DAC_0 = 0 +} DACName; + +typedef enum { + SPI_0 = (int)LPC_SSP0_BASE, + SPI_1 = (int)LPC_SSP1_BASE +} SPIName; + +typedef enum { + I2C_0 = (int)LPC_I2C0_BASE, + I2C_1 = (int)LPC_I2C1_BASE, + I2C_2 = (int)LPC_I2C2_BASE +} I2CName; + +typedef enum { + PWM_1 = 1, + PWM_2, + PWM_3, + PWM_4, + PWM_5, + PWM_6 +} PWMName; + +typedef enum { + CAN_1 = (int)LPC_CAN1_BASE, + CAN_2 = (int)LPC_CAN2_BASE +} CANName; + +#define STDIO_UART_TX USBTX +#define STDIO_UART_RX USBRX +#define STDIO_UART UART_0 + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/PinNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,109 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ + +#ifndef MBED_PINNAMES_H +#define MBED_PINNAMES_H + +#include "cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +#define PORT_SHIFT 5 + +typedef enum { + // LPC Pin Names + P0_0 = LPC_GPIO0_BASE, + P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12, P0_13, P0_14, P0_15, P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23, P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31, + P1_0, P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7, P1_8, P1_9, P1_10, P1_11, P1_12, P1_13, P1_14, P1_15, P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23, P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31, + P2_0, P2_1, P2_2, P2_3, P2_4, P2_5, P2_6, P2_7, P2_8, P2_9, P2_10, P2_11, P2_12, P2_13, P2_14, P2_15, P2_16, P2_17, P2_18, P2_19, P2_20, P2_21, P2_22, P2_23, P2_24, P2_25, P2_26, P2_27, P2_28, P2_29, P2_30, P2_31, + P3_0, P3_1, P3_2, P3_3, P3_4, P3_5, P3_6, P3_7, P3_8, P3_9, P3_10, P3_11, P3_12, P3_13, P3_14, P3_15, P3_16, P3_17, P3_18, P3_19, P3_20, P3_21, P3_22, P3_23, P3_24, P3_25, P3_26, P3_27, P3_28, P3_29, P3_30, P3_31, + P4_0, P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7, P4_8, P4_9, P4_10, P4_11, P4_12, P4_13, P4_14, P4_15, P4_16, P4_17, P4_18, P4_19, P4_20, P4_21, P4_22, P4_23, P4_24, P4_25, P4_26, P4_27, P4_28, P4_29, P4_30, P4_31, + + // mbed DIP Pin Names + p5 = P0_9, + p6 = P0_8, + p7 = P0_7, + p8 = P0_6, + p9 = P0_0, + p10 = P0_1, + p11 = P0_18, + p12 = P0_17, + p13 = P0_15, + p14 = P0_16, + p15 = P0_23, + p16 = P0_24, + p17 = P0_25, + p18 = P0_26, + p19 = P1_30, + p20 = P1_31, + p21 = P2_5, + p22 = P2_4, + p23 = P2_3, + p24 = P2_2, + p25 = P2_1, + p26 = P2_0, + p27 = P0_11, + p28 = P0_10, + p29 = P0_5, + p30 = P0_4, + + // Other mbed Pin Names + LED1 = P1_18, + LED2 = P1_20, + LED3 = P1_21, + LED4 = P1_23, + + USBTX = P0_2, + USBRX = P0_3, + + // Not connected + NC = (int)0xFFFFFFFF +} PinName; + +typedef enum { + PullUp = 0, + PullDown = 3, + PullNone = 2, + OpenDrain = 4 +} PinMode; + +// version of PINCON_TypeDef using register arrays +typedef struct { + __IO uint32_t PINSEL[11]; + uint32_t RESERVED0[5]; + __IO uint32_t PINMODE[10]; +} PINCONARRAY_TypeDef; + +#define PINCONARRAY ((PINCONARRAY_TypeDef *)LPC_PINCON_BASE) + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/PortNames.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,40 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + Port0 = 0, + Port1 = 1, + Port2 = 2, + Port3 = 3, + Port4 = 4 +} PortName; + +#ifdef __cplusplus +} +#endif +#endif
--- a/LPC2368/cmsis.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC2368/cmsis.h Wed Nov 21 10:49:56 2012 +0000 @@ -7,10 +7,6 @@ #ifndef MBED_CMSIS_H #define MBED_CMSIS_H -#ifndef TARGET_LPC2368 -#define TARGET_LPC2368 -#endif - #include "LPC23xx.h" #include "cmsis_nvic.h"
--- a/LPC2368/core_arm7.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC2368/core_arm7.h Wed Nov 21 10:49:56 2012 +0000 @@ -178,6 +178,10 @@ #define __STREXH(value, ptr) __strex(value, ptr) #define __STREXW(value, ptr) __strex(value, ptr) +#define __disable_irq() unsigned tmp_IntEnable = LPC_VIC->IntEnable; \ + LPC_VIC->IntEnClr = 0xffffffff + +#define __enable_irq() LPC_VIC->IntEnable = tmp_IntEnable #elif (defined (__ICCARM__)) /*------------------ ICC Compiler -------------------*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/device.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 + +#define DEVICE_INTERRUPTIN 1 + +#define DEVICE_ANALOGIN 1 +#define DEVICE_ANALOGOUT 1 + +#define DEVICE_SERIAL 1 + +#define DEVICE_I2C 1 +#define DEVICE_I2CSLAVE 1 + +#define DEVICE_SPI 1 +#define DEVICE_SPISLAVE 1 + +#define DEVICE_CAN 1 + +#define DEVICE_RTC 1 + +#define DEVICE_ETHERNET 1 + +#define DEVICE_PWMOUT 1 + +#define DEVICE_LOCALFILESYSTEM 1 + +#define DEVICE_SLEEP 0 + +#define DEVICE_DEBUG_AWARENESS 0 + +#define DEVICE_STDIO_ERROR 1 + +#include "objects.h" + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/gpio_object.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,54 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_GPIO_OBJECT_H +#define MBED_GPIO_OBJECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + uint32_t mask; + + __IO uint32_t *reg_dir; + __IO uint32_t *reg_set; + __IO uint32_t *reg_clr; + __I uint32_t *reg_in; +} gpio_t; + +static inline void gpio_write(gpio_t *obj, int value) { + if (value) + *obj->reg_set = obj->mask; + else + *obj->reg_clr = obj->mask; +} + +static inline int gpio_read(gpio_t *obj) { + return ((*obj->reg_in & obj->mask) ? 1 : 0); +} + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LPC2368/objects.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,84 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "cmsis.h" +#include "PortNames.h" +#include "PeripheralNames.h" +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_irq_s { + uint32_t port; + uint32_t pin; + uint32_t ch; +}; + +struct port_s { + __IO uint32_t *reg_dir; + __IO uint32_t *reg_out; + __I uint32_t *reg_in; + PortName port; + uint32_t mask; +}; + +struct pwmout_s { + __IO uint32_t *MR; + PWMName pwm; +}; + +struct serial_s { + LPC_UART_TypeDef *uart; + int index; +}; + +struct analogin_s { + ADCName adc; +}; + +struct dac_s { + DACName dac; +}; + +struct can_s { + LPC_CAN_TypeDef *dev; +}; + +struct i2c_s { + LPC_I2C_TypeDef *i2c; +}; + +struct spi_s { + LPC_SSP_TypeDef *spi; +}; + +#include "gpio_object.h" + +#ifdef __cplusplus +} +#endif + +#endif
--- a/LPC2368/vector_defns.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LPC2368/vector_defns.h Wed Nov 21 10:49:56 2012 +0000 @@ -56,8 +56,8 @@ #define F_Bit 0x40 // when F bit is set, FIQ is disabled // MCU RAM -#define LPC2368_RAM_ADDRESS 0x40000000 // RAM Base -#define LPC2368_RAM_SIZE 0x8000 // 32KB +#define LPC2368_RAM_ADDRESS 0x40000000 // RAM Base +#define LPC2368_RAM_SIZE 0x8000 // 32KB // ISR Stack Allocation #define UND_stack_size 0x00000040 @@ -70,6 +70,6 @@ // Full Descending Stack, so top-most stack points to just above the top of RAM #define LPC2368_STACK_TOP (LPC2368_RAM_ADDRESS + LPC2368_RAM_SIZE) -#define USR_STACK_TOP (LPC2368_STACK_TOP - ISR_stack_size) +#define USR_STACK_TOP (LPC2368_STACK_TOP - ISR_stack_size) #endif
--- a/LocalFileSystem.h Fri Oct 26 17:40:46 2012 +0100 +++ b/LocalFileSystem.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,10 +1,31 @@ -/* mbed Microcontroller Library - LocalFileSystem - * Copyright (c) 2008-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_LOCALFILESYSTEM_H #define MBED_LOCALFILESYSTEM_H +#include "platform.h" + +#if DEVICE_LOCALFILESYSTEM + #include "FileSystemLike.h" namespace mbed { @@ -72,11 +93,10 @@ class LocalFileSystem : public FileSystemLike { public: - LocalFileSystem(const char* n) : FileSystemLike(n) { + + } - } - virtual FileHandle *open(const char* name, int flags); virtual int remove(const char *filename); virtual DirHandle *opendir(const char *name); @@ -85,3 +105,5 @@ } // namespace mbed #endif + +#endif
--- a/PeripheralNames.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* mbed Microcontroller Library - PeripheralNames - * Copyright (C) 2008-2011 ARM Limited. All rights reserved. - * - * Provides the mappings for peripherals - */ - -#ifndef MBED_PERIPHERALNAMES_H -#define MBED_PERIPHERALNAMES_H - -#include "cmsis.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - -enum UARTName { - UART_0 = (int)LPC_UART0_BASE - , UART_1 = (int)LPC_UART1_BASE - , UART_2 = (int)LPC_UART2_BASE - , UART_3 = (int)LPC_UART3_BASE -}; -typedef enum UARTName UARTName; - -enum ADCName { - ADC0_0 = 0 - , ADC0_1 - , ADC0_2 - , ADC0_3 - , ADC0_4 - , ADC0_5 - , ADC0_6 - , ADC0_7 -}; -typedef enum ADCName ADCName; - -enum DACName { - DAC_0 = 0 -}; -typedef enum DACName DACName; - -enum SPIName { - SPI_0 = (int)LPC_SSP0_BASE - , SPI_1 = (int)LPC_SSP1_BASE -}; -typedef enum SPIName SPIName; - -enum I2CName { - I2C_0 = (int)LPC_I2C0_BASE - , I2C_1 = (int)LPC_I2C1_BASE - , I2C_2 = (int)LPC_I2C2_BASE -}; -typedef enum I2CName I2CName; - -enum PWMName { - PWM_1 = 1 - , PWM_2 - , PWM_3 - , PWM_4 - , PWM_5 - , PWM_6 -}; -typedef enum PWMName PWMName; - -enum TimerName { - TIMER_0 = (int)LPC_TIM0_BASE - , TIMER_1 = (int)LPC_TIM1_BASE - , TIMER_2 = (int)LPC_TIM2_BASE - , TIMER_3 = (int)LPC_TIM3_BASE -}; -typedef enum TimerName TimerName; - -enum CANName { - CAN_1 = (int)LPC_CAN1_BASE, - CAN_2 = (int)LPC_CAN2_BASE -}; -typedef enum CANName CANName; - -#define US_TICKER_TIMER TIMER_3 -#define US_TICKER_TIMER_IRQn TIMER3_IRQn - -#elif defined(TARGET_LPC11U24) - -enum UARTName { - UART_0 = (int)LPC_USART_BASE -}; -typedef enum UARTName UARTName; - -enum I2CName { - I2C_0 = (int)LPC_I2C_BASE -}; -typedef enum I2CName I2CName; - -enum TimerName { - TIMER_0 = (int)LPC_CT32B0_BASE - , TIMER_1 = (int)LPC_CT32B1_BASE -}; -typedef enum TimerName TimerName; - -enum ADCName { - ADC0_0 = 0 - , ADC0_1 - , ADC0_2 - , ADC0_3 - , ADC0_4 - , ADC0_5 - , ADC0_6 - , ADC0_7 -}; -typedef enum ADCName ADCName; - -enum SPIName { - SPI_0 = (int)LPC_SSP0_BASE - , SPI_1 = (int)LPC_SSP1_BASE -}; -typedef enum SPIName SPIName; - -#define US_TICKER_TIMER TIMER_1 -#define US_TICKER_TIMER_IRQn TIMER_32_1_IRQn - -typedef enum PWMName { - PWM_1 = 0 - , PWM_2 - , PWM_3 - , PWM_4 - , PWM_5 - , PWM_6 - , PWM_7 - , PWM_8 - , PWM_9 - , PWM_10 - , PWM_11 -} PWMName; - -#endif - -#define STDIO_UART_TX USBTX -#define STDIO_UART_RX USBRX -#define STDIO_UART UART_0 - -#ifdef __cplusplus -} -#endif - -#endif
--- a/PinNames.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,254 +0,0 @@ -/* mbed Microcontroller Library - PinNames - * Copyright (C) 2008-2011 ARM Limited. All rights reserved. - * - * Provides the mapping of mbed DIP and LPC Pin Names - */ - -#ifndef MBED_PINNAMES_H -#define MBED_PINNAMES_H - -#include "cmsis.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - -enum PinName { - - // LPC Pin Names - P0_0 = LPC_GPIO0_BASE, P0_1, P0_2, P0_3, P0_4, P0_5, P0_6, P0_7 - , P0_8, P0_9, P0_10, P0_11, P0_12, P0_13, P0_14, P0_15 - , P0_16, P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23 - , P0_24, P0_25, P0_26, P0_27, P0_28, P0_29, P0_30, P0_31 - , P1_0, P1_1, P1_2, P1_3, P1_4, P1_5, P1_6, P1_7 - , P1_8, P1_9, P1_10, P1_11, P1_12, P1_13, P1_14, P1_15 - , P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23 - , P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31 - , P2_0, P2_1, P2_2, P2_3, P2_4, P2_5, P2_6, P2_7 - , P2_8, P2_9, P2_10, P2_11, P2_12, P2_13, P2_14, P2_15 - , P2_16, P2_17, P2_18, P2_19, P2_20, P2_21, P2_22, P2_23 - , P2_24, P2_25, P2_26, P2_27, P2_28, P2_29, P2_30, P2_31 - , P3_0, P3_1, P3_2, P3_3, P3_4, P3_5, P3_6, P3_7 - , P3_8, P3_9, P3_10, P3_11, P3_12, P3_13, P3_14, P3_15 - , P3_16, P3_17, P3_18, P3_19, P3_20, P3_21, P3_22, P3_23 - , P3_24, P3_25, P3_26, P3_27, P3_28, P3_29, P3_30, P3_31 - , P4_0, P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7 - , P4_8, P4_9, P4_10, P4_11, P4_12, P4_13, P4_14, P4_15 - , P4_16, P4_17, P4_18, P4_19, P4_20, P4_21, P4_22, P4_23 - , P4_24, P4_25, P4_26, P4_27, P4_28, P4_29, P4_30, P4_31 - - // mbed DIP Pin Names - , p5 = P0_9 - , p6 = P0_8 - , p7 = P0_7 - , p8 = P0_6 - , p9 = P0_0 - , p10 = P0_1 - , p11 = P0_18 - , p12 = P0_17 - , p13 = P0_15 - , p14 = P0_16 - , p15 = P0_23 - , p16 = P0_24 - , p17 = P0_25 - , p18 = P0_26 - , p19 = P1_30 - , p20 = P1_31 - , p21 = P2_5 - , p22 = P2_4 - , p23 = P2_3 - , p24 = P2_2 - , p25 = P2_1 - , p26 = P2_0 - , p27 = P0_11 - , p28 = P0_10 - , p29 = P0_5 - , p30 = P0_4 - - // Other mbed Pin Names -#ifdef MCB1700 - , LED1 = P1_28 - , LED2 = P1_29 - , LED3 = P1_31 - , LED4 = P2_2 -#else - , LED1 = P1_18 - , LED2 = P1_20 - , LED3 = P1_21 - , LED4 = P1_23 -#endif - , USBTX = P0_2 - , USBRX = P0_3 - - // Not connected - , NC = (int)0xFFFFFFFF - -}; -typedef enum PinName PinName; - -enum PinMode { - PullUp = 0 - , PullDown = 3 - , PullNone = 2 - , OpenDrain = 4 -}; -typedef enum PinMode PinMode; - -// version of PINCON_TypeDef using register arrays -typedef struct { - __IO uint32_t PINSEL[11]; - uint32_t RESERVED0[5]; - __IO uint32_t PINMODE[10]; -#ifndef TARGET_LPC2368 -// Open drain mode is not available on LPC2368 - __IO uint32_t PINMODE_OD[5]; -#endif -} PINCONARRAY_TypeDef; - -#define PINCONARRAY ((PINCONARRAY_TypeDef *)LPC_PINCON_BASE) - - -#elif defined(TARGET_LPC11U24) - -enum PinName { - - // LPC11U Pin Names - P0_0 = 0 - , P0_1 = 1 - , P0_2 = 2 - , P0_3 = 3 - , P0_4 = 4 - , P0_5 = 5 - , P0_6 = 6 - , P0_7 = 7 - , P0_8 = 8 - , P0_9 = 9 - , P0_10 = 10 - , P0_11 = 11 - , P0_12 = 12 - , P0_13 = 13 - , P0_14 = 14 - , P0_15 = 15 - , P0_16 = 16 - , P0_17 = 17 - , P0_18 = 18 - , P0_19 = 19 - , P0_20 = 20 - , P0_21 = 21 - , P0_22 = 22 - , P0_23 = 23 - , P0_24 = 24 - , P0_25 = 25 - , P0_26 = 26 - , P0_27 = 27 - - , P1_0 = 32 - , P1_1 = 33 - , P1_2 = 34 - , P1_3 = 35 - , P1_4 = 36 - , P1_5 = 37 - , P1_6 = 38 - , P1_7 = 39 - , P1_8 = 40 - , P1_9 = 41 - , P1_10 = 42 - , P1_11 = 43 - , P1_12 = 44 - , P1_13 = 45 - , P1_14 = 46 - , P1_15 = 47 - , P1_16 = 48 - , P1_17 = 49 - , P1_18 = 50 - , P1_19 = 51 - , P1_20 = 52 - , P1_21 = 53 - , P1_22 = 54 - , P1_23 = 55 - , P1_24 = 56 - , P1_25 = 57 - , P1_26 = 58 - , P1_27 = 59 - , P1_28 = 60 - , P1_29 = 61 - - , P1_31 = 63 - - // mbed DIP Pin Names - , p5 = P0_9 - , p6 = P0_8 - , p7 = P1_29 - , p8 = P0_2 - , p9 = P1_27 - , p10 = P1_26 - , p11 = P1_22 - , p12 = P1_21 - , p13 = P1_20 - , p14 = P1_23 - , p15 = P0_11 - , p16 = P0_12 - , p17 = P0_13 - , p18 = P0_14 - , p19 = P0_16 - , p20 = P0_22 - , p21 = P0_7 - , p22 = P0_17 - , p23 = P1_17 - , p24 = P1_18 - , p25 = P1_24 - , p26 = P1_25 - , p27 = P0_4 - , p28 = P0_5 - , p29 = P1_5 - , p30 = P1_2 - - , p33 = P0_3 - , p34 = P1_15 - , p35 = P0_20 - , p36 = P0_21 - - // Other mbed Pin Names - , LED1 = P1_8 - , LED2 = P1_9 - , LED3 = P1_10 - , LED4 = P1_11 - - , USBTX = P0_19 - , USBRX = P0_18 - - // Not connected - , NC = (int)0xFFFFFFFF - -}; -typedef enum PinName PinName; - -typedef enum { - CHANNEL0=FLEX_INT0_IRQn, - CHANNEL1=FLEX_INT1_IRQn, - CHANNEL2=FLEX_INT2_IRQn, - CHANNEL3=FLEX_INT3_IRQn, - CHANNEL4=FLEX_INT4_IRQn, - CHANNEL5=FLEX_INT5_IRQn, - CHANNEL6=FLEX_INT6_IRQn, - CHANNEL7=FLEX_INT7_IRQn -} Channel; - -enum PinMode { - PullUp = 2 - , PullDown = 1 - , PullNone = 0 - , Repeater = 3 - , OpenDrain = 4 -}; -typedef enum PinMode PinMode; -#endif - - -#ifdef __cplusplus -} -#endif - -#endif
--- a/PortIn.h Fri Oct 26 17:40:46 2012 +0100 +++ b/PortIn.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,81 +1,99 @@ -/* mbed Microcontroller Library - PortInOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_PORTIN_H -#define MBED_PORTIN_H - -#include "device.h" - -#if DEVICE_PORTIN - -#include "PortNames.h" -#include "PinNames.h" - -namespace mbed { - -/** A multiple pin digital input - * - * Example: - * @code - * // Switch on an LED if any of mbed pins 21-26 is high - * - * #include "mbed.h" - * - * PortIn p(Port2, 0x0000003F); // p21-p26 - * DigitalOut ind(LED4); - * - * int main() { - * while(1) { - * int pins = p.read(); - * if(pins) { - * ind = 1; - * } else { - * ind = 0; - * } - * } - * } - * @endcode - */ -class PortIn { -public: - - /** Create an PortIn, connected to the specified port - * - * @param port Port to connect to (Port0-Port5) - * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) - */ - PortIn(PortName port, int mask = 0xFFFFFFFF); - - /** Read the value currently output on the port - * - * @returns - * An integer with each bit corresponding to associated port pin setting - */ - int read(); - - /** Set the input pin mode - * - * @param mode PullUp, PullDown, PullNone, OpenDrain - */ - void mode(PinMode mode); - - /** A shorthand for read() - */ - operator int() { - return read(); - } - -private: -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#endif - PortName _port; - uint32_t _mask; -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTIN_H +#define MBED_PORTIN_H + +#include "platform.h" + +#if DEVICE_PORTIN + +#include "port_api.h" + +namespace mbed { + +/** A multiple pin digital input + * + * Example: + * @code + * // Switch on an LED if any of mbed pins 21-26 is high + * + * #include "mbed.h" + * + * PortIn p(Port2, 0x0000003F); // p21-p26 + * DigitalOut ind(LED4); + * + * int main() { + * while(1) { + * int pins = p.read(); + * if(pins) { + * ind = 1; + * } else { + * ind = 0; + * } + * } + * } + * @endcode + */ +class PortIn { +public: + + /** Create an PortIn, connected to the specified port + * + * @param port Port to connect to (Port0-Port5) + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) + */ + PortIn(PortName port, int mask = 0xFFFFFFFF) { + port_init(&_port, port, mask, PIN_INPUT); + } + + /** Read the value currently output on the port + * + * @returns + * An integer with each bit corresponding to associated port pin setting + */ + int read() { + return port_read(&_port); + } + + /** Set the input pin mode + * + * @param mode PullUp, PullDown, PullNone, OpenDrain + */ + void mode(PinMode mode) { + port_mode(&_port, mode); + } + + /** A shorthand for read() + */ + operator int() { + return read(); + } + +private: + port_t _port; +}; + +} // namespace mbed + +#endif + +#endif
--- a/PortInOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/PortInOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,86 +1,110 @@ -/* mbed Microcontroller Library - PortInOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_PORTINOUT_H -#define MBED_PORTINOUT_H - -#include "device.h" - -#if DEVICE_PORTINOUT - -#include "PortNames.h" -#include "PinNames.h" - -namespace mbed { - -/** A multiple pin digital in/out used to set/read multiple bi-directional pins - */ -class PortInOut { -public: - - /** Create an PortInOut, connected to the specified port - * - * @param port Port to connect to (Port0-Port5) - * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) - */ - PortInOut(PortName port, int mask = 0xFFFFFFFF); - - /** Write the value to the output port - * - * @param value An integer specifying a bit to write for every corresponding port pin - */ - void write(int value); - - /** Read the value currently output on the port - * - * @returns - * An integer with each bit corresponding to associated port pin setting - */ - int read(); - - /** Set as an output - */ - void output(); - - /** Set as an input - */ - void input(); - - /** Set the input pin mode - * - * @param mode PullUp, PullDown, PullNone, OpenDrain - */ - void mode(PinMode mode); - - /** A shorthand for write() - */ - PortInOut& operator= (int value) { - write(value); - return *this; - } - - PortInOut& operator= (PortInOut& rhs) { - write(rhs.read()); - return *this; - } - - /** A shorthand for read() - */ - operator int() { - return read(); - } - -private: -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#endif - PortName _port; - uint32_t _mask; -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTINOUT_H +#define MBED_PORTINOUT_H + +#include "platform.h" + +#if DEVICE_PORTINOUT + +#include "port_api.h" + +namespace mbed { + +/** A multiple pin digital in/out used to set/read multiple bi-directional pins + */ +class PortInOut { +public: + + /** Create an PortInOut, connected to the specified port + * + * @param port Port to connect to (Port0-Port5) + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) + */ + PortInOut(PortName port, int mask = 0xFFFFFFFF) { + port_init(&_port, port, mask, PIN_INPUT); + } + + /** Write the value to the output port + * + * @param value An integer specifying a bit to write for every corresponding port pin + */ + void write(int value) { + port_write(&_port, value); + } + + /** Read the value currently output on the port + * + * @returns + * An integer with each bit corresponding to associated port pin setting + */ + int read() { + return port_read(&_port); + } + + /** Set as an output + */ + void output() { + port_dir(&_port, PIN_OUTPUT); + } + + /** Set as an input + */ + void input() { + port_dir(&_port, PIN_INPUT); + } + + /** Set the input pin mode + * + * @param mode PullUp, PullDown, PullNone, OpenDrain + */ + void mode(PinMode mode) { + port_mode(&_port, mode); + } + + /** A shorthand for write() + */ + PortInOut& operator= (int value) { + write(value); + return *this; + } + + PortInOut& operator= (PortInOut& rhs) { + write(rhs.read()); + return *this; + } + + /** A shorthand for read() + */ + operator int() { + return read(); + } + +private: + port_t _port; +}; + +} // namespace mbed + +#endif + +#endif
--- a/PortNames.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* mbed Microcontroller Library - PortName - * Copyright (c) 2010-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_PORTNAMES_H -#define MBED_PORTNAMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - -enum PortName { - Port0 = 0 - , Port1 = 1 - , Port2 = 2 - , Port3 = 3 - , Port4 = 4 -}; -typedef enum PortName PortName; - -#elif defined(TARGET_LPC11U24) - -enum PortName { - Port0 = 0 - , Port1 = 1 -}; -typedef enum PortName PortName; - - -#endif - -#ifdef __cplusplus -} -#endif -#endif -
--- a/PortOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/PortOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,95 +1,110 @@ -/* mbed Microcontroller Library - PortOut - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_PORTOUT_H -#define MBED_PORTOUT_H - -#include "device.h" - -#if DEVICE_PORTOUT - -#include "platform.h" -#include "PinNames.h" -#include "Base.h" - -#include "PortNames.h" - -namespace mbed { -/** A multiple pin digital out - * - * Example: - * @code - * // Toggle all four LEDs - * - * #include "mbed.h" - * - * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 - * #define LED_MASK 0x00B40000 - * - * PortOut ledport(Port1, LED_MASK); - * - * int main() { - * while(1) { - * ledport = LED_MASK; - * wait(1); - * ledport = 0; - * wait(1); - * } - * } - * @endcode - */ -class PortOut { -public: - - /** Create an PortOut, connected to the specified port - * - * @param port Port to connect to (Port0-Port5) - * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) - */ - PortOut(PortName port, int mask = 0xFFFFFFFF); - - /** Write the value to the output port - * - * @param value An integer specifying a bit to write for every corresponding PortOut pin - */ - void write(int value); - - /** Read the value currently output on the port - * - * @returns - * An integer with each bit corresponding to associated PortOut pin setting - */ - int read(); - - /** A shorthand for write() - */ - PortOut& operator= (int value) { - write(value); - return *this; - } - - PortOut& operator= (PortOut& rhs) { - write(rhs.read()); - return *this; - } - - /** A shorthand for read() - */ - operator int() { - return read(); - } - -private: -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - LPC_GPIO_TypeDef *_gpio; -#endif - PortName _port; - uint32_t _mask; -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTOUT_H +#define MBED_PORTOUT_H + +#include "platform.h" + +#if DEVICE_PORTOUT + +#include "port_api.h" + +namespace mbed { +/** A multiple pin digital out + * + * Example: + * @code + * // Toggle all four LEDs + * + * #include "mbed.h" + * + * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 + * #define LED_MASK 0x00B40000 + * + * PortOut ledport(Port1, LED_MASK); + * + * int main() { + * while(1) { + * ledport = LED_MASK; + * wait(1); + * ledport = 0; + * wait(1); + * } + * } + * @endcode + */ +class PortOut { +public: + + /** Create an PortOut, connected to the specified port + * + * @param port Port to connect to (Port0-Port5) + * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) + */ + PortOut(PortName port, int mask = 0xFFFFFFFF) { + port_init(&_port, port, mask, PIN_OUTPUT); + } + + /** Write the value to the output port + * + * @param value An integer specifying a bit to write for every corresponding PortOut pin + */ + void write(int value) { + port_write(&_port, value); + } + + /** Read the value currently output on the port + * + * @returns + * An integer with each bit corresponding to associated PortOut pin setting + */ + int read() { + return port_read(&_port); + } + + /** A shorthand for write() + */ + PortOut& operator= (int value) { + write(value); + return *this; + } + + PortOut& operator= (PortOut& rhs) { + write(rhs.read()); + return *this; + } + + /** A shorthand for read() + */ + operator int() { + return read(); + } + +private: + port_t _port; +}; + +} // namespace mbed + +#endif + +#endif
--- a/PwmOut.h Fri Oct 26 17:40:46 2012 +0100 +++ b/PwmOut.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,18 +1,31 @@ -/* mbed Microcontroller Library - PwmOut - * Copyright (c) 2007-2011 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_PWMOUT_H #define MBED_PWMOUT_H -#include "device.h" +#include "platform.h" #if DEVICE_PWMOUT - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" +#include "pwmout_api.h" namespace mbed { @@ -43,7 +56,7 @@ * for its PWM, all other PWMs will require their duty cycle to be * refreshed. */ -class PwmOut : public Base { +class PwmOut { public: @@ -51,16 +64,20 @@ * * @param pin PwmOut pin to connect to */ - PwmOut(PinName pin, const char *name = NULL); + PwmOut(PinName pin) { + pwmout_init(&_pwm, pin); + } /** Set the ouput duty-cycle, specified as a percentage (float) * * @param value A floating-point value representing the output duty-cycle, * specified as a percentage. The value should lie between * 0.0f (representing on 0%) and 1.0f (representing on 100%). - * Values outside this range will be saturated to 0.0f or 1.0f. + * Values outside this range will be saturated to 0.0f or 1.0f. */ - void write(float value); + void write(float value) { + pwmout_write(&_pwm, value); + } /** Return the current output duty-cycle setting, measured as a percentage (float) * @@ -70,58 +87,74 @@ * 0.0f (representing on 0%) and 1.0f (representing on 100%). * * @note - * This value may not match exactly the value set by a previous <write>. + * This value may not match exactly the value set by a previous <write>. */ - float read(); + float read() { + return pwmout_read(&_pwm); + } /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. * * @note - * The resolution is currently in microseconds; periods smaller than this - * will be set to zero. + * The resolution is currently in microseconds; periods smaller than this + * will be set to zero. */ - void period(float seconds); + void period(float seconds) { + pwmout_period(&_pwm, seconds); + } /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. */ - void period_ms(int ms); + void period_ms(int ms) { + pwmout_period_ms(&_pwm, ms); + } /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. */ - void period_us(int us); + void period_us(int us) { + pwmout_period_us(&_pwm, us); + } /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. */ - void pulsewidth(float seconds); + void pulsewidth(float seconds) { + pwmout_pulsewidth(&_pwm, seconds); + } /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. */ - void pulsewidth_ms(int ms); + void pulsewidth_ms(int ms) { + pwmout_pulsewidth_ms(&_pwm, ms); + } /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. */ - void pulsewidth_us(int us); + void pulsewidth_us(int us) { + pwmout_pulsewidth_us(&_pwm, us); + } #ifdef MBED_OPERATORS /** A operator shorthand for write() */ - PwmOut& operator= (float value); - PwmOut& operator= (PwmOut& rhs); - + PwmOut& operator= (float value) { + write(value); + return *this; + } + + PwmOut& operator= (PwmOut& rhs) { + write(rhs.read()); + return *this; + } + /** An operator shorthand for read() */ - operator float(); -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); + operator float() { + return read(); + } #endif protected: - - PWMName _pwm; - + pwmout_t _pwm; }; } // namespace mbed
--- a/SPI.h Fri Oct 26 17:40:46 2012 +0100 +++ b/SPI.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,110 +1,115 @@ -/* mbed Microcontroller Library - SPI - * Copyright (c) 2010-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_SPI_H -#define MBED_SPI_H - -#include "device.h" - -#if DEVICE_SPI - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" - -namespace mbed { - -/** A SPI Master, used for communicating with SPI slave devices - * - * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz - * - * Most SPI devices will also require Chip Select and Reset signals. These - * can be controlled using <DigitalOut> pins - * - * Example: - * @code - * // Send a byte to a SPI slave, and record the response - * - * #include "mbed.h" - * - * SPI device(p5, p6, p7); // mosi, miso, sclk - * - * int main() { - * int response = device.write(0xFF); - * } - * @endcode - */ -class SPI : public Base { - -public: - - /** Create a SPI master connected to the specified pins - * - * Pin Options: - * (5, 6, 7) or (11, 12, 13) - * - * mosi or miso can be specfied as NC if not used - * - * @param mosi SPI Master Out, Slave In pin - * @param miso SPI Master In, Slave Out pin - * @param sclk SPI Clock pin - * @param name (optional) A string to identify the object - */ - SPI(PinName mosi, PinName miso, PinName sclk, const char *name = NULL); - - /** Configure the data transmission format - * - * @param bits Number of bits per SPI frame (4 - 16) - * @param mode Clock polarity and phase mode (0 - 3) - * - * @code - * mode | POL PHA - * -----+-------- - * 0 | 0 0 - * 1 | 0 1 - * 2 | 1 0 - * 3 | 1 1 - * @endcode - */ - void format(int bits, int mode = 0); - - /** Set the spi bus clock frequency - * - * @param hz SCLK frequency in hz (default = 1MHz) - */ - void frequency(int hz = 1000000); - - /** Write to the SPI Slave and return the response - * - * @param value Data to be sent to the SPI slave - * - * @returns - * Response from the SPI slave - */ - virtual int write(int value); - - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - -protected: - - SPIName _spi; - - void aquire(void); - static SPI *_owner; - int _bits; - int _mode; - int _hz; - -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SPI_H +#define MBED_SPI_H + +#include "platform.h" + +#if DEVICE_SPI + +#include "spi_api.h" + +namespace mbed { + +/** A SPI Master, used for communicating with SPI slave devices + * + * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz + * + * Most SPI devices will also require Chip Select and Reset signals. These + * can be controlled using <DigitalOut> pins + * + * Example: + * @code + * // Send a byte to a SPI slave, and record the response + * + * #include "mbed.h" + * + * SPI device(p5, p6, p7); // mosi, miso, sclk + * + * int main() { + * int response = device.write(0xFF); + * } + * @endcode + */ +class SPI { + +public: + + /** Create a SPI master connected to the specified pins + * + * Pin Options: + * (5, 6, 7) or (11, 12, 13) + * + * mosi or miso can be specfied as NC if not used + * + * @param mosi SPI Master Out, Slave In pin + * @param miso SPI Master In, Slave Out pin + * @param sclk SPI Clock pin + */ + SPI(PinName mosi, PinName miso, PinName sclk); + + /** Configure the data transmission format + * + * @param bits Number of bits per SPI frame (4 - 16) + * @param mode Clock polarity and phase mode (0 - 3) + * + * @code + * mode | POL PHA + * -----+-------- + * 0 | 0 0 + * 1 | 0 1 + * 2 | 1 0 + * 3 | 1 1 + * @endcode + */ + void format(int bits, int mode = 0); + + /** Set the spi bus clock frequency + * + * @param hz SCLK frequency in hz (default = 1MHz) + */ + void frequency(int hz = 1000000); + + /** Write to the SPI Slave and return the response + * + * @param value Data to be sent to the SPI slave + * + * @returns + * Response from the SPI slave + */ + virtual int write(int value); + +protected: + spi_t _spi; + + void aquire(void); + static SPI *_owner; + int _bits; + int _mode; + int _hz; +}; + +} // namespace mbed + +#endif + +#endif
--- a/SPIHalfDuplex.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -/* mbed Microcontroller Library - SPIHalfDuplex - * Copyright (c) 2010-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_SPIHALFDUPLEX_H -#define MBED_SPIHALFDUPLEX_H - -#include "device.h" - -#if DEVICE_SPI - -#include "SPI.h" - -namespace mbed { - -/** A SPI half-duplex master, used for communicating with SPI slave devices - * over a shared data line. - * - * The default format is set to 8-bits for both master and slave, and a - * clock frequency of 1MHz - * - * Most SPI devies will also require Chip Select and Reset signals. These - * can be controlled using <DigitalOut> pins. - * - * Although this is for a shared data line, both MISO and MOSI are defined, - * and should be tied together externally to the mbed. This class handles - * the tri-stating of the MOSI pin. - * - * Example: - * @code - * // Send a byte to a SPI half-duplex slave, and record the response - * - * #include "mbed.h" - * - * SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk - * - * int main() { - * int respone = device.write(0xAA); - * } - * @endcode - */ - -class SPIHalfDuplex : public SPI { - -public: - - /** Create a SPI half-duplex master connected to the specified pins - * - * Pin Options: - * (5, 6, 7) or (11, 12, 13) - * - * mosi or miso can be specfied as NC if not used - * - * @param mosi SPI Master Out, Slave In pin - * @param miso SPI Master In, Slave Out pin - * @param sclk SPI Clock pin - * @param name (optional) A string to identify the object - */ - SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk, - const char *name = NULL); - -#if 0 // Inherited from SPI - documentation only - /** Configure the data transmission format - * - * @param bits Number of bits per SPI frame (4 - 16) - * @param mode Clock polarity and phase mode (0 - 3) - * - * @code - * mode | POL PHA - * -----+-------- - * 0 | 0 0 - * 1 | 0 1 - * 2 | 1 0 - * 3 | 1 1 - * @endcode - */ - void format(int bits, int mode = 0); - - /** Set the spi bus clock frequency - * - * @param hz SCLK frequency in hz (default = 1MHz) - */ - void frequency(int hz = 1000000); -#endif - - /** Write to the SPI Slave and return the response - * - * @param value Data to be sent to the SPI slave - * - * @returns - * Response from the SPI slave - */ - virtual int write(int value); - - /** Set the number of databits expected from the slave, from 4-16 - * - * @param sbits Number of expected bits in the slave response - */ - void slave_format(int sbits); - -protected: - PinName _mosi; - PinName _miso; - int _sbits; - -}; // End of class - -} // End of namespace mbed - -#endif - -#endif
--- a/SPISlave.h Fri Oct 26 17:40:46 2012 +0100 +++ b/SPISlave.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,121 +1,132 @@ -/* mbed Microcontroller Library - SPISlave - * Copyright (c) 2010-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_SPISLAVE_H -#define MBED_SPISLAVE_H - -#include "device.h" - -#if DEVICE_SPISLAVE - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" - -namespace mbed { - -/** A SPI slave, used for communicating with a SPI Master device - * - * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz - * - * Example: - * @code - * // Reply to a SPI master as slave - * - * #include "mbed.h" - * - * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel - * - * int main() { - * device.reply(0x00); // Prime SPI with first reply - * while(1) { - * if(device.receive()) { - * int v = device.read(); // Read byte from master - * v = (v + 1) % 0x100; // Add one to it, modulo 256 - * device.reply(v); // Make this the next reply - * } - * } - * } - * @endcode - */ -class SPISlave : public Base { - -public: - - /** Create a SPI slave connected to the specified pins - * - * Pin Options: - * (5, 6, 7i, 8) or (11, 12, 13, 14) - * - * mosi or miso can be specfied as NC if not used - * - * @param mosi SPI Master Out, Slave In pin - * @param miso SPI Master In, Slave Out pin - * @param sclk SPI Clock pin - * @param ssel SPI chip select pin - * @param name (optional) A string to identify the object - */ - SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel, - const char *name = NULL); - - /** Configure the data transmission format - * - * @param bits Number of bits per SPI frame (4 - 16) - * @param mode Clock polarity and phase mode (0 - 3) - * - * @code - * mode | POL PHA - * -----+-------- - * 0 | 0 0 - * 1 | 0 1 - * 2 | 1 0 - * 3 | 1 1 - * @endcode - */ - void format(int bits, int mode = 0); - - /** Set the spi bus clock frequency - * - * @param hz SCLK frequency in hz (default = 1MHz) - */ - void frequency(int hz = 1000000); - - /** Polls the SPI to see if data has been received - * - * @returns - * 0 if no data, - * 1 otherwise - */ - int receive(void); - - /** Retrieve data from receive buffer as slave - * - * @returns - * the data in the receive buffer - */ - int read(void); - - /** Fill the transmission buffer with the value to be written out - * as slave on the next received message from the master. - * - * @param value the data to be transmitted next - */ - void reply(int value); - -protected: - - SPIName _spi; - - int _bits; - int _mode; - int _hz; - -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SPISLAVE_H +#define MBED_SPISLAVE_H + +#include "platform.h" + +#if DEVICE_SPISLAVE + +#include "spi_api.h" + +namespace mbed { + +/** A SPI slave, used for communicating with a SPI Master device + * + * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz + * + * Example: + * @code + * // Reply to a SPI master as slave + * + * #include "mbed.h" + * + * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel + * + * int main() { + * device.reply(0x00); // Prime SPI with first reply + * while(1) { + * if(device.receive()) { + * int v = device.read(); // Read byte from master + * v = (v + 1) % 0x100; // Add one to it, modulo 256 + * device.reply(v); // Make this the next reply + * } + * } + * } + * @endcode + */ +class SPISlave { + +public: + + /** Create a SPI slave connected to the specified pins + * + * Pin Options: + * (5, 6, 7i, 8) or (11, 12, 13, 14) + * + * mosi or miso can be specfied as NC if not used + * + * @param mosi SPI Master Out, Slave In pin + * @param miso SPI Master In, Slave Out pin + * @param sclk SPI Clock pin + * @param ssel SPI chip select pin + * @param name (optional) A string to identify the object + */ + SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel); + + /** Configure the data transmission format + * + * @param bits Number of bits per SPI frame (4 - 16) + * @param mode Clock polarity and phase mode (0 - 3) + * + * @code + * mode | POL PHA + * -----+-------- + * 0 | 0 0 + * 1 | 0 1 + * 2 | 1 0 + * 3 | 1 1 + * @endcode + */ + void format(int bits, int mode = 0); + + /** Set the spi bus clock frequency + * + * @param hz SCLK frequency in hz (default = 1MHz) + */ + void frequency(int hz = 1000000); + + /** Polls the SPI to see if data has been received + * + * @returns + * 0 if no data, + * 1 otherwise + */ + int receive(void); + + /** Retrieve data from receive buffer as slave + * + * @returns + * the data in the receive buffer + */ + int read(void); + + /** Fill the transmission buffer with the value to be written out + * as slave on the next received message from the master. + * + * @param value the data to be transmitted next + */ + void reply(int value); + +protected: + spi_t _spi; + + int _bits; + int _mode; + int _hz; +}; + +} // namespace mbed + +#endif + +#endif
--- a/Serial.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Serial.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,172 +1,159 @@ -/* mbed Microcontroller Library - Serial - * Copyright (c) 2007-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_SERIAL_H -#define MBED_SERIAL_H - -#include "device.h" - -#if DEVICE_SERIAL - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Stream.h" -#include "FunctionPointer.h" - -namespace mbed { - -/** A serial port (UART) for communication with other serial devices - * - * Can be used for Full Duplex communication, or Simplex by specifying - * one pin as NC (Not Connected) - * - * Example: - * @code - * // Print "Hello World" to the PC - * - * #include "mbed.h" - * - * Serial pc(USBTX, USBRX); - * - * int main() { - * pc.printf("Hello World\n"); - * } - * @endcode - */ -class Serial : public Stream { - -public: - - /** Create a Serial port, connected to the specified transmit and receive pins - * - * @param tx Transmit pin - * @param rx Receive pin - * - * @note - * Either tx or rx may be specified as NC if unused - */ - Serial(PinName tx, PinName rx, const char *name = NULL); - - /** Set the baud rate of the serial port - * - * @param baudrate The baudrate of the serial port (default = 9600). - */ - void baud(int baudrate); - - enum Parity { - None = 0 - , Odd - , Even - , Forced1 - , Forced0 - }; - - enum IrqType { - RxIrq = 0 - , TxIrq - }; - - /** Set the transmission format used by the Serial port - * - * @param bits The number of bits in a word (5-8; default = 8) - * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) - * @param stop The number of stop bits (1 or 2; default = 1) - */ - void format(int bits = 8, Parity parity = Serial::None, int stop_bits = 1); - -#if 0 // Inhereted from Stream, for documentation only - - /** Write a character - * - * @param c The character to write to the serial port - */ - int putc(int c); - - /** Reads a character from the serial port. This will block until - * a character is available. To see if a character is available, - * see readable() - * - * @returns - * The character read from the serial port - */ - int getc(); - - /** Write a formated string - * - * @param format A printf-style format string, followed by the - * variables to use in formating the string. - */ - int printf(const char* format, ...); - - /** Read a formated string - * - * @param format A scanf-style format string, - * followed by the pointers to variables to store the results. - */ - int scanf(const char* format, ...); - -#endif - - /** Determine if there is a character available to read - * - * @returns - * 1 if there is a character available to read, - * 0 otherwise - */ - int readable(); - - /** Determine if there is space available to write a character - * - * @returns - * 1 if there is space to write a character, - * 0 otherwise - */ - int writeable(); - - /** Attach a function to call whenever a serial interrupt is generated - * - * @param fptr A pointer to a void function, or 0 to set as none - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - */ - void attach(void (*fptr)(void), IrqType type = RxIrq); - - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - */ - template<typename T> - void attach(T* tptr, void (T::*mptr)(void), IrqType type = RxIrq) { - if((mptr != NULL) && (tptr != NULL)) { - _irq[type].attach(tptr, mptr); - setup_interrupt(type); - } - } - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - -protected: - - void setup_interrupt(IrqType type); - void remove_interrupt(IrqType type); - - virtual int _getc(); - virtual int _putc(int c); - - UARTName _uart; - FunctionPointer _irq[2]; - int _uidx; - -}; - -} // namespace mbed - -#endif - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SERIAL_H +#define MBED_SERIAL_H + +#include "platform.h" + +#if DEVICE_SERIAL + +#include "Stream.h" +#include "FunctionPointer.h" +#include "serial_api.h" + +namespace mbed { + +/** A serial port (UART) for communication with other serial devices + * + * Can be used for Full Duplex communication, or Simplex by specifying + * one pin as NC (Not Connected) + * + * Example: + * @code + * // Print "Hello World" to the PC + * + * #include "mbed.h" + * + * Serial pc(USBTX, USBRX); + * + * int main() { + * pc.printf("Hello World\n"); + * } + * @endcode + */ +class Serial : public Stream { + +public: + + /** Create a Serial port, connected to the specified transmit and receive pins + * + * @param tx Transmit pin + * @param rx Receive pin + * + * @note + * Either tx or rx may be specified as NC if unused + */ + Serial(PinName tx, PinName rx) { + serial_init(&_serial, tx, rx); + serial_irq_handler(&_serial, Serial::_irq_handler, (uint32_t)this); + } + + /** Set the baud rate of the serial port + * + * @param baudrate The baudrate of the serial port (default = 9600). + */ + void baud(int baudrate) { + serial_baud(&_serial, baudrate); + } + + /** Set the transmission format used by the Serial port + * + * @param bits The number of bits in a word (5-8; default = 8) + * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) + * @param stop The number of stop bits (1 or 2; default = 1) + */ + void format(int bits = 8, SerialParity parity=ParityNone, int stop_bits=1) { + serial_format(&_serial, bits, parity, stop_bits); + } + + /** Determine if there is a character available to read + * + * @returns + * 1 if there is a character available to read, + * 0 otherwise + */ + int readable() { + return serial_readable(&_serial); + } + + /** Determine if there is space available to write a character + * + * @returns + * 1 if there is space to write a character, + * 0 otherwise + */ + int writeable() { + return serial_writable(&_serial); + } + + /** Attach a function to call whenever a serial interrupt is generated + * + * @param fptr A pointer to a void function, or 0 to set as none + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + void attach(void (*fptr)(void), SerialIrq type=RxIrq) { + if (fptr) { + _irq[type].attach(fptr); + serial_irq_set(&_serial, type, 1); + } else { + serial_irq_set(&_serial, type, 0); + } + } + + /** Attach a member function to call whenever a serial interrupt is generated + * + * @param tptr pointer to the object to call the member function on + * @param mptr pointer to the member function to be called + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template<typename T> + void attach(T* tptr, void (T::*mptr)(void), SerialIrq type=RxIrq) { + if((mptr != NULL) && (tptr != NULL)) { + _irq[type].attach(tptr, mptr); + serial_irq_set(&_serial, type, 1); + } + } + + static void _irq_handler(uint32_t id, SerialIrq irq_type) { + Serial *handler = (Serial*)id; + handler->_irq[irq_type].call(); + } + +protected: + virtual int _getc() { + return serial_getc(&_serial); + } + + virtual int _putc(int c) { + serial_putc(&_serial, c); + return c; + } + + serial_t _serial; + FunctionPointer _irq[2]; +}; + +} // namespace mbed + +#endif + +#endif
--- a/SerialHalfDuplex.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* mbed Microcontroller Library - SerialHalfDuplex - * Copyright (c) 2010-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_SERIALHALFDUPLEX_H -#define MBED_SERIALHALFDUPLEX_H - -#include "device.h" - -#if DEVICE_SERIAL - -#include "Serial.h" -#include "PinNames.h" -#include "PeripheralNames.h" - -namespace mbed { - -/** A serial port (UART) for communication with other devices using - * Half-Duplex, allowing transmit and receive on a single - * shared transmit and receive line. Only one end should be transmitting - * at a time. - * - * Both the tx and rx pin should be defined, and wired together. - * This is in addition to them being wired to the other serial - * device to allow both read and write functions to operate. - * - * For Simplex and Full-Duplex Serial communication, see Serial() - * - * Example: - * @code - * // Send a byte to a second HalfDuplex device, and read the response - * - * #include "mbed.h" - * - * // p9 and p10 should be wired together to form "a" - * // p28 and p27 should be wired together to form "b" - * // p9/p10 should be wired to p28/p27 as the Half Duplex connection - * - * SerialHalfDuplex a(p9, p10); - * SerialHalfDuplex b(p28, p27); - * - * void b_rx() { // second device response - * b.putc(b.getc() + 4); - * } - * - * int main() { - * b.attach(&b_rx); - * for (int c = 'A'; c < 'Z'; c++) { - * a.putc(c); - * printf("sent [%c]\n", c); - * wait(0.5); // b should respond - * if (a.readable()) { - * printf("received [%c]\n", a.getc()); - * } - * } - * } - * @endcode - */ -class SerialHalfDuplex : public Serial { - -public: - /** Create a half-duplex serial port, connected to the specified transmit - * and receive pins. - * - * These pins should be wired together, as well as to the target device - * - * @param tx Transmit pin - * @param rx Receive pin - */ - SerialHalfDuplex(PinName tx, PinName rx, const char *name = NULL); - -#if 0 // Inherited from Serial class, for documentation - /** Set the baud rate of the serial port - * - * @param baudrate The baudrate of the serial port (default = 9600). - */ - void baud(int baudrate); - - enum Parity { - None = 0 - , Odd - , Even - , Forced1 - , Forced0 - }; - - /** Set the transmission format used by the Serial port - * - * @param bits The number of bits in a word (5-8; default = 8) - * @param parity The parity used (Serial::None, Serial::Odd, - * Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) - * @param stop The number of stop bits (1 or 2; default = 1) - */ - void format(int bits = 8, Parity parity = Serial::None, int stop_bits -= 1); - - /** Write a character - * - * @param c The character to write to the serial port - */ - int putc(int c); - - /** Read a character - * - * Read a character from the serial port. This call will block - * until a character is available. For testing if a character is - * available for reading, see <readable>. - * - * @returns - * The character read from the serial port - */ - int getc(); - - /** Write a formated string - * - * @param format A printf-style format string, followed by the - * variables to use in formating the string. - */ - int printf(const char* format, ...); - - /** Read a formated string - * - * @param format A scanf-style format string, - * followed by the pointers to variables to store the results. - */ - int scanf(const char* format, ...); - - /** Determine if there is a character available to read - * - * @returns - * 1 if there is a character available to read, - * 0 otherwise - */ - int readable(); - - /** Determine if there is space available to write a character - * - * @returns - * 1 if there is space to write a character, - * 0 otherwise - */ - int writeable(); - - /** Attach a function to call whenever a serial interrupt is generated - * - * @param fptr A pointer to a void function, or 0 to set as none - */ - void attach(void (*fptr)(void)); - - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template<typename T> - void attach(T* tptr, void (T::*mptr)(void)); - -#endif - -protected: - PinName _txpin; - - virtual int _putc(int c); - virtual int _getc(void); - -}; // End class SerialHalfDuplex - -} // End namespace - -#endif - -#endif
--- a/Stream.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Stream.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,50 +1,48 @@ -/* mbed Microcontroller Library - Stream - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_STREAM_H #define MBED_STREAM_H -#include "FileLike.h" #include "platform.h" -#include <cstdio> +#include "FileHandle.h" namespace mbed { -class Stream : public FileLike { +class Stream : public FileHandle { public: - - Stream(const char *name = NULL); + Stream(void); virtual ~Stream(); - int putc(int c) { - fflush(_file); - return std::fputc(c, _file); - } - int puts(const char *s) { - fflush(_file); - return std::fputs(s, _file); - } - int getc() { - fflush(_file); - return std::fgetc(_file); - } - char *gets(char *s, int size) { - fflush(_file); - return std::fgets(s,size,_file);; - } + int putc(int c); + int puts(const char *s); + int getc(); + char *gets(char *s, int size); int printf(const char* format, ...); int scanf(const char* format, ...); - operator std::FILE*() { return _file; } - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); -#endif + operator std::FILE*() {return _file;} protected: - virtual int close(); virtual ssize_t write(const void* buffer, size_t length); virtual ssize_t read(void* buffer, size_t length); @@ -57,10 +55,8 @@ virtual int _getc() = 0; std::FILE *_file; - }; } // namespace mbed #endif -
--- a/Ticker.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Ticker.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - Ticker - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_TICKER_H #define MBED_TICKER_H @@ -19,7 +36,7 @@ * // Toggle the blinking led after 5 seconds * * #include "mbed.h" - * + * * Ticker timer; * DigitalOut led1(LED1); * DigitalOut led2(LED2); @@ -48,7 +65,7 @@ public: /** Attach a function to be called by the Ticker, specifiying the interval in seconds - * + * * @param fptr pointer to the function to be called * @param t the time between calls in seconds */ @@ -57,7 +74,7 @@ } /** Attach a member function to be called by the Ticker, specifiying the interval in seconds - * + * * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called * @param t the time between calls in seconds @@ -68,7 +85,7 @@ } /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds - * + * * @param fptr pointer to the function to be called * @param t the time between calls in micro-seconds */ @@ -78,7 +95,7 @@ } /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds - * + * * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called * @param t the time between calls in micro-seconds @@ -90,17 +107,15 @@ } /** Detach the function - */ + */ void detach(); protected: - void setup(unsigned int t); virtual void handler(); - + unsigned int _delay; FunctionPointer _function; - }; } // namespace mbed
--- a/Timeout.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Timeout.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - Timeout - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_TIMEOUT_H #define MBED_TIMEOUT_H @@ -11,7 +28,7 @@ /** A Timeout is used to call a function at a point in the future * - * You can use as many seperate Timeout objects as you require. + * You can use as many seperate Timeout objects as you require. * * Example: * @code @@ -39,60 +56,8 @@ */ class Timeout : public Ticker { -#if 0 // For documentation - - /** Attach a function to be called by the Timeout, specifiying the delay in seconds - * - * @param fptr pointer to the function to be called - * @param t the time before the call in seconds - */ - void attach(void (*fptr)(void), float t) { - attach_us(fptr, t * 1000000.0f); - } - - /** Attach a member function to be called by the Timeout, specifiying the delay in seconds - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param t the time before the calls in seconds - */ - template<typename T> - void attach(T* tptr, void (T::*mptr)(void), float t) { - attach_us(tptr, mptr, t * 1000000.0f); - } - - /** Attach a function to be called by the Timeout, specifiying the delay in micro-seconds - * - * @param fptr pointer to the function to be called - * @param t the time before the call in micro-seconds - */ - void attach_us(void (*fptr)(void), unsigned int t) { - _function.attach(fptr); - setup(t); - } - - /** Attach a member function to be called by the Timeout, specifiying the delay in micro-seconds - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param t the time before the call in micro-seconds - */ - template<typename T> - void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { - _function.attach(tptr, mptr); - setup(t); - } - - /** Detach the function - */ - void detach(); - -#endif - protected: - virtual void handler(); - }; } // namespace mbed
--- a/Timer.h Fri Oct 26 17:40:46 2012 +0100 +++ b/Timer.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,89 +1,94 @@ -/* mbed Microcontroller Library - Timer - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_TIMER_H -#define MBED_TIMER_H - -#include "platform.h" -#include "PinNames.h" -#include "PeripheralNames.h" -#include "Base.h" - -namespace mbed { - -/** A general purpose timer - * - * Example: - * @code - * // Count the time to toggle a LED - * - * #include "mbed.h" - * - * Timer timer; - * DigitalOut led(LED1); - * int begin, end; - * - * int main() { - * timer.start(); - * begin = timer.read_us(); - * led = !led; - * end = timer.read_us(); - * printf("Toggle the led takes %d us", end - begin); - * } - * @endcode - */ -class Timer : public Base { - -public: - - Timer(const char *name = NULL); - - /** Start the timer - */ - void start(); - - /** Stop the timer - */ - void stop(); - - /** Reset the timer to 0. - * - * If it was already counting, it will continue - */ - void reset(); - - /** Get the time passed in seconds - */ - float read(); - - /** Get the time passed in mili-seconds - */ - int read_ms(); - - /** Get the time passed in micro-seconds - */ - int read_us(); - -#ifdef MBED_OPERATORS - operator float(); -#endif - -#ifdef MBED_RPC - virtual const struct rpc_method *get_rpc_methods(); - static struct rpc_class *get_rpc_class(); -#endif - -protected: - - int slicetime(); - int _running; // whether the timer is running - unsigned int _start; // the start time of the latest slice - int _time; // any accumulated time from previous slices - -}; - -} // namespace mbed - -#endif - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_TIMER_H +#define MBED_TIMER_H + +#include "platform.h" + +namespace mbed { + +/** A general purpose timer + * + * Example: + * @code + * // Count the time to toggle a LED + * + * #include "mbed.h" + * + * Timer timer; + * DigitalOut led(LED1); + * int begin, end; + * + * int main() { + * timer.start(); + * begin = timer.read_us(); + * led = !led; + * end = timer.read_us(); + * printf("Toggle the led takes %d us", end - begin); + * } + * @endcode + */ +class Timer { + +public: + Timer(); + + /** Start the timer + */ + void start(); + + /** Stop the timer + */ + void stop(); + + /** Reset the timer to 0. + * + * If it was already counting, it will continue + */ + void reset(); + + /** Get the time passed in seconds + */ + float read(); + + /** Get the time passed in mili-seconds + */ + int read_ms(); + + /** Get the time passed in micro-seconds + */ + int read_us(); + +#ifdef MBED_OPERATORS + operator float(); +#endif + +protected: + int slicetime(); + int _running; // whether the timer is running + unsigned int _start; // the start time of the latest slice + int _time; // any accumulated time from previous slices +}; + +} // namespace mbed + +#endif
--- a/TimerEvent.h Fri Oct 26 17:40:46 2012 +0100 +++ b/TimerEvent.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,60 +1,58 @@ -/* mbed Microcontroller Library - TimerEvent - * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_TIMEREVENT_H -#define MBED_TIMEREVENT_H - -namespace mbed { - -/** Base abstraction for timer interrupts -*/ -class TimerEvent { - -public: - - TimerEvent(); - - /** The handler registered with the underlying timer interrupt - */ - static void irq(); - - /** Destruction removes it... - */ - virtual ~TimerEvent(); - -protected: - - /** The handler called to service the timer event of the derived class - */ - virtual void handler() = 0; - - /** Insert in to linked list - */ - void insert(unsigned int timestamp); - - /** Remove from linked list, if in it - */ - void remove(); - - /** Get the current usec timestamp - */ - static unsigned int timestamp(); - - /** The head of the list of the events, NULL if none - */ - static TimerEvent *_head; - - /** Pointer to the next in the list, NULL if last - */ - TimerEvent *_next; - - /** The timestamp at which the even should be triggered - */ - unsigned int _timestamp; - -}; - -} // namespace mbed - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_TIMEREVENT_H +#define MBED_TIMEREVENT_H + +#include "us_ticker_api.h" + +namespace mbed { + +/** Base abstraction for timer interrupts +*/ +class TimerEvent { +public: + TimerEvent(); + + /** The handler registered with the underlying timer interrupt + */ + static void irq(uint32_t id); + + /** Destruction removes it... + */ + virtual ~TimerEvent(); + +protected: + // The handler called to service the timer event of the derived class + virtual void handler() = 0; + + // insert in to linked list + void insert(unsigned int timestamp); + + // remove from linked list, if in it + void remove(); + + ticker_event_t event; +}; + +} // namespace mbed + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/analogin_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,45 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_ANALOGIN_API_H +#define MBED_ANALOGIN_API_H + +#include "device.h" + +#if DEVICE_ANALOGIN + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct analogin_s analogin_t; + +void analogin_init (analogin_t *obj, PinName pin); +float analogin_read (analogin_t *obj); +uint16_t analogin_read_u16(analogin_t *obj); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/analogout_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,48 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_ANALOGOUT_API_H +#define MBED_ANALOGOUT_API_H + +#include "device.h" + +#if DEVICE_ANALOGOUT + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct dac_s dac_t; + +void analogout_init (dac_t *obj, PinName pin); +void analogout_free (dac_t *obj); +void analogout_write (dac_t *obj, float value); +void analogout_write_u16(dac_t *obj, uint16_t value); +float analogout_read (dac_t *obj); +uint16_t analogout_read_u16 (dac_t *obj); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/can_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,55 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_CAN_API_H +#define MBED_CAN_API_H + +#include "device.h" + +#if DEVICE_CAN + +#include "PinNames.h" +#include "PeripheralNames.h" +#include "can_helper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct can_s can_t; + +void can_init (can_t *obj, PinName rd, PinName td); +void can_free (can_t *obj); +int can_frequency(can_t *obj, int hz); +int can_write (can_t *obj, CAN_Message, int cc); +int can_read (can_t *obj, CAN_Message *msg); +void can_reset (can_t *obj); +unsigned char can_rderror (can_t *obj); +unsigned char can_tderror (can_t *obj); +void can_monitor (can_t *obj, int silent); + +#ifdef __cplusplus +}; +#endif + +#endif // MBED_CAN_API_H + +#endif
--- a/can_helper.h Fri Oct 26 17:40:46 2012 +0100 +++ b/can_helper.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,10 +1,29 @@ -/* mbed Microcontroller Library - can_helper - * Copyright (c) 2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_CAN_HELPER_H #define MBED_CAN_HELPER_H +#if DEVICE_CAN + #ifdef __cplusplus extern "C" { #endif @@ -34,4 +53,6 @@ }; #endif +#endif + #endif // MBED_CAN_HELPER_H
--- a/device.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ - -#ifndef MBED_DEVICE_H -#define MBED_DEVICE_H - -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - -#define DEVICE_PORTIN 1 -#define DEVICE_PORTOUT 1 -#define DEVICE_PORTINOUT 1 - -#define DEVICE_INTERRUPTIN 1 - -#define DEVICE_ANALOGIN 1 -#define DEVICE_ANALOGOUT 1 - -#define DEVICE_SERIAL 1 - -#define DEVICE_I2C 1 -#define DEVICE_I2CSLAVE 1 - -#define DEVICE_SPI 1 -#define DEVICE_SPISLAVE 1 - -#define DEVICE_CAN 1 - -#define DEVICE_RTC 1 - -#define DEVICE_ETHERNET 1 - -#define DEVICE_PWMOUT 1 - -#elif defined(TARGET_LPC11U24) - -#define DEVICE_PORTIN 1 -#define DEVICE_PORTOUT 1 -#define DEVICE_PORTINOUT 1 - -#define DEVICE_INTERRUPTIN 1 - -#define DEVICE_ANALOGIN 1 -#define DEVICE_ANALOGOUT 0 - -#define DEVICE_SERIAL 1 - -#define DEVICE_I2C 1 -#define DEVICE_I2CSLAVE 1 - -#define DEVICE_SPI 1 -#define DEVICE_SPISLAVE 1 - -#define DEVICE_CAN 0 - -#define DEVICE_RTC 0 - -#define DEVICE_ETHERNET 0 - -#define DEVICE_PWMOUT 1 - -#endif - -#endif -
--- a/error.h Fri Oct 26 17:40:46 2012 +0100 +++ b/error.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - error - * Copyright (c) 2006-2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_ERROR_H #define MBED_ERROR_H @@ -14,7 +31,7 @@ * If the compiler evaluates this line, it will report the error and stop the compile. * * For example, you could use this to check some user-defined compile-time variables: - * + * * @code * #define NUM_PORTS 7 * #if (NUM_PORTS > 4) @@ -41,25 +58,15 @@ * } * #endcode */ - -#if 0 // for documentation only -/** Report a fatal runtime error - * - * Outputs the specified error message to stderr so it will appear via the USB - * serial port, and then calls exit(1) to die with the blue lights of death. - * - * @param format printf-style format string, followed by associated variables - */ -void error(const char* format, ...); -#endif #include <stdlib.h> +#include "device.h" -#ifdef NDEBUG - #define error(...) (exit(1)) -#else +#ifdef DEVICE_STDIO_ERROR #include <stdio.h> #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1)) +#else + #define error(...) (exit(1)) #endif #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ethernet_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,69 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_ETHERNET_API_H +#define MBED_ETHERNET_API_H + +#include "device.h" + +#if DEVICE_ETHERNET + +#ifdef __cplusplus +extern "C" { +#endif + +// Connection constants + +int ethernet_init(void); +void ethernet_free(void); + +// write size bytes from data to ethernet buffer +// return num bytes written +// or -1 if size is too big +int ethernet_write(const char *data, int size); + +// send ethernet write buffer, returning the packet size sent +int ethernet_send(void); + +// recieve from ethernet buffer, returning packet size, or 0 if no packet +int ethernet_receive(void); + +// read size bytes in to data, return actual num bytes read (0..size) +// if data == NULL, throw the bytes away +int ethernet_read(char *data, int size); + +// get the ethernet address +void ethernet_address(char *mac); + +// see if the link is up +int ethernet_link(void); + +// force link settings +void ethernet_set_link(int speed, int duplex); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpio_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,46 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_GPIO_API_H +#define MBED_GPIO_API_H + +#include "device.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Set the given pin as GPIO + * @param pin The pin to be set as GPIO + * @return The GPIO port mask for this pin + **/ +uint32_t gpio_set(PinName pin); + +/* GPIO object */ +void gpio_init(gpio_t *obj, PinName pin, PinDirection direction); +void gpio_mode(gpio_t *obj, PinMode mode); +void gpio_dir (gpio_t *obj, PinDirection direction); + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpio_irq_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,53 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_GPIO_IRQ_API_H +#define MBED_GPIO_IRQ_API_H + +#include "device.h" + +#if DEVICE_INTERRUPTIN + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + IRQ_NONE, + IRQ_RISE, + IRQ_FALL +} gpio_irq_event; + +typedef struct gpio_irq_s gpio_irq_t; + +typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event); + +int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); +void gpio_irq_free(gpio_irq_t *obj); +void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2c_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,59 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_I2C_API_H +#define MBED_I2C_API_H + +#include "device.h" + +#if DEVICE_I2C + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct i2c_s i2c_t; + +void i2c_init (i2c_t *obj, PinName sda, PinName scl); +void i2c_frequency (i2c_t *obj, int hz); +int i2c_start (i2c_t *obj); +void i2c_stop (i2c_t *obj); +int i2c_read (i2c_t *obj, int address, char *data, int length, int stop); +int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop); +void i2c_reset (i2c_t *obj); +int i2c_byte_read (i2c_t *obj, int last); +int i2c_byte_write (i2c_t *obj, int data); + +#if DEVICE_I2CSLAVE +void i2c_slave_mode (i2c_t *obj, int enable_slave); +int i2c_slave_receive(i2c_t *obj); +int i2c_slave_read (i2c_t *obj, char *data, int length); +int i2c_slave_write (i2c_t *obj, const char *data, int length); +void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- a/mbed.h Fri Oct 26 17:40:46 2012 +0100 +++ b/mbed.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,26 +1,40 @@ /* mbed Microcontroller Library - * Copyright (c) 2006-2011 ARM Limited. All rights reserved. - */ - + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_H #define MBED_H -#define MBED_LIBRARY_VERSION 29 - +#define MBED_LIBRARY_VERSION 30 + +#include "platform.h" + // Useful C libraries -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <math.h> #include <time.h> // mbed Debug libraries - #include "error.h" #include "mbed_interface.h" // mbed Peripheral components - #include "DigitalIn.h" #include "DigitalOut.h" #include "DigitalInOut.h" @@ -34,10 +48,8 @@ #include "AnalogOut.h" #include "PwmOut.h" #include "Serial.h" -#include "SerialHalfDuplex.h" #include "SPI.h" #include "SPISlave.h" -#include "SPIHalfDuplex.h" #include "I2C.h" #include "I2CSlave.h" #include "Ethernet.h" @@ -52,8 +64,7 @@ #include "wait_api.h" #include "rtc_time.h" -using namespace mbed; -using namespace std; +using namespace mbed; +using namespace std; -#endif - +#endif
--- a/mbed_interface.h Fri Oct 26 17:40:46 2012 +0100 +++ b/mbed_interface.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,3 +1,31 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_INTERFACE_H +#define MBED_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + /** Functions to control the mbed interface * * mbed Microcontrollers have a built-in interface to provide functionality such as @@ -5,17 +33,6 @@ * system. These functions provide means to control the interface suing semihost * calls it supports. */ - -/* mbed Microcontroller Library - mbed_interface - * Copyright (c) 2009-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_INTERFACE_H -#define MBED_INTERFACE_H - -#ifdef __cplusplus -extern "C" { -#endif /** Determine whether the mbed interface is connected, based on whether debug is enabled * @@ -34,7 +51,7 @@ int mbed_interface_reset(void); /** This will disconnect the debug aspect of the interface, so semihosting will be disabled. - * The interface will still support the USB serial aspect + * The interface will still support the USB serial aspect * * @returns * 0 if successful, @@ -43,8 +60,8 @@ int mbed_interface_disconnect(void); /** This will disconnect the debug aspect of the interface, and if the USB cable is not - * connected, also power down the interface. If the USB cable is connected, the interface - * will remain powered up and visible to the host + * connected, also power down the interface. If the USB cable is connected, the interface + * will remain powered up and visible to the host * * @returns * 0 if successful, @@ -64,10 +81,10 @@ int mbed_interface_uid(char *uid); /** This returns a unique 6-byte MAC address, based on the interface UID - * If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00) + * If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00) * - * This is a weak function that can be overwritten if you want to provide your own mechanism to - * provide a MAC address. + * This is a weak function that can be overwritten if you want to provide your own mechanism to + * provide a MAC address. * * @param mac A 6-byte array to write the MAC address */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pinmap.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,50 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PINMAP_H +#define MBED_PINMAP_H + +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +PinName parse_pins(const char *str); + +typedef struct { + PinName pin; + int peripheral; + int function; +} PinMap; + +void pin_function(PinName pin, int function); +void pin_mode (PinName pin, PinMode mode); + +uint32_t pinmap_peripheral(PinName pin, const PinMap* map); +uint32_t pinmap_merge (uint32_t a, uint32_t b); +void pinmap_pinout (PinName pin, const PinMap *map); + +#ifdef __cplusplus +} +#endif + +#endif
--- a/platform.h Fri Oct 26 17:40:46 2012 +0100 +++ b/platform.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,12 +1,36 @@ -/* mbed Microcontroller Library - platform - * Copyright (c) 2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_PLATFORM_H -#define MBED_PLATFORM_H - -#define MBED_RPC - -#define MBED_OPERATORS - -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PLATFORM_H +#define MBED_PLATFORM_H + +#define MBED_OPERATORS 1 + +#include "device.h" +#include "PinNames.h" +#include "PeripheralNames.h" + +#include <cstddef> +#include <cstdlib> +#include <cstdio> +#include <cstring> + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/port_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,48 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PORTMAP_H +#define MBED_PORTMAP_H + +#include "device.h" + +#if DEVICE_PORTIN || DEVICE_PORTOUT + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct port_s port_t; + +PinName port_pin(PortName port, int pin_n); + +void port_init (port_t *obj, PortName port, int mask, PinDirection dir); +void port_mode (port_t *obj, PinMode mode); +void port_dir (port_t *obj, PinDirection dir); +void port_write(port_t *obj, int value); +int port_read (port_t *obj); + +#ifdef __cplusplus +} +#endif +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pwmout_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,55 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_PWMOUT_API_H +#define MBED_PWMOUT_API_H + +#include "device.h" + +#if DEVICE_PWMOUT + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct pwmout_s pwmout_t; + +void pwmout_init (pwmout_t* obj, PinName pin); +void pwmout_free (pwmout_t* obj); + +void pwmout_write (pwmout_t* obj, float percent); +float pwmout_read (pwmout_t* obj); + +void pwmout_period (pwmout_t* obj, float seconds); +void pwmout_period_ms (pwmout_t* obj, int ms); +void pwmout_period_us (pwmout_t* obj, int us); + +void pwmout_pulsewidth (pwmout_t* obj, float seconds); +void pwmout_pulsewidth_ms(pwmout_t* obj, int ms); +void pwmout_pulsewidth_us(pwmout_t* obj, int us); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- a/rpc.h Fri Oct 26 17:40:46 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,585 +0,0 @@ -/* mbed Microcontroller Library - RPC - * Copyright (c) 2008-2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_RPC_H -#define MBED_RPC_H - -/** Helpers for rpc handling. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "Base.h" - -#include "PinNames.h" -#include <stdint.h> - -namespace mbed { - -/** Parses and returns a value from a string. - * - * @param arg The string to pase - * @param next If not NULL a pointer to after the last - * character parsed is written here - */ -template<typename T> T parse_arg(const char *arg, const char **next); - -inline char parse_char(const char *arg, const char **next) { - char c = *arg++; - if(c == '\\') { - c = *arg++; - switch(c) { - case 'a': c = '\a'; break; - case 'b': c = '\b'; break; - case 't': c = '\t'; break; - case 'n': c = '\n'; break; - case 'v': c = '\v'; break; - case 'f': c = '\f'; break; - case 'r': c = '\r'; break; - case 'x': - { - /* two-character hexadecimal */ - char buf[3]; - buf[0] = *arg++; - buf[1] = *arg++; - buf[2] = 0; - c = strtol(buf, NULL, 16); - } - break; - default: - if(isdigit(c)) { - /* three-character octal */ - char buf[4]; - buf[0] = c; - buf[1] = *arg++; - buf[2] = *arg++; - buf[3] = 0; - c = strtol(buf, NULL, 8); - } - break; - } - } - *next = arg; - return c; -} - -/* signed integer types */ - -template<> inline int parse_arg<int>(const char *arg, const char **next) { - if(arg[0] == '\'') { - char c = parse_char(arg+1, &arg); - if(next != NULL) *next = arg+1; - return c; - } else { - return strtol(arg, const_cast<char**>(next), 0); - } -} - -template<> inline char parse_arg<char>(const char *arg, const char **next) { - return parse_arg<int>(arg,next); -} - -template<> inline short int parse_arg<short int>(const char *arg, const char **next) { - return parse_arg<int>(arg,next); -} - -template<> inline long int parse_arg<long int>(const char *arg, const char **next) { - return parse_arg<int>(arg,next); -} - -template<> inline long long parse_arg<long long>(const char *arg, const char **next) { - return strtoll(arg, const_cast<char**>(next), 0); -} - -/* unsigned integer types */ - -template<> inline unsigned int parse_arg<unsigned int>(const char *arg, const char **next) { - if(arg[0] == '\'') { - char c = parse_char(arg+1, &arg); - if(next != NULL) *next = arg+1; - return c; - } else { - return strtoul(arg, const_cast<char**>(next), 0); - } -} - -template<> inline unsigned char parse_arg<unsigned char>(const char *arg, const char **next) { - return parse_arg<unsigned int>(arg,next); -} - -template<> inline unsigned short int parse_arg<unsigned short int>(const char *arg, const char **next) { - return parse_arg<unsigned int>(arg,next); -} - -template<> inline unsigned long int parse_arg<unsigned long int>(const char *arg, const char **next) { - return parse_arg<unsigned int>(arg,next); -} - -template<> inline unsigned long long parse_arg<unsigned long long>(const char *arg, const char **next) { - return strtoull(arg, const_cast<char**>(next), 0); -} - -/* floating types */ - -template<> inline float parse_arg<float>(const char *arg, const char **next) { -#if !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 410000 - return strtof(arg,const_cast<char**>(next)); -#elif __ARMCC_VERSION >= 310000 - /* bug in header means no using declaration for strtof */ - return std::strtof(arg,const_cast<char**>(next)); -#else - /* strtof not supported */ - return strtod(arg,const_cast<char**>(next)); -#endif -} - -template<> inline double parse_arg<double>(const char *arg, const char **next) { - return strtod(arg,const_cast<char**>(next)); -} - -template<> inline long double parse_arg<long double>(const char *arg, const char **next) { - return strtod(arg,const_cast<char**>(next)); -} - -/* string */ - -template<> inline char *parse_arg<char*>(const char *arg, const char **next) { - const char *ptr = arg; - char *res = NULL; - if(*arg == '"') { - /* quoted string */ - ptr = ++arg; - int len = 0; - /* find the end (and length) of the quoted string */ - for(char c = *ptr; c != 0 && c != '"'; c = *++ptr) { - len++; - if(c == '\\') { - ptr++; - } - } - /* copy the quoted string, and unescape characters */ - if(len != 0) { - res = new char[len+1]; - char *resptr = res; - while(arg != ptr) { - *resptr++ = parse_char(arg, &arg); - } - *resptr = 0; - } - } else { - /* unquoted string */ - while(isalnum(*ptr) || *ptr=='_') { - ptr++; - } - int len = ptr-arg; - if(len!=0) { - res = new char[len+1]; - memcpy(res, arg, len); - res[len] = 0; - } - } - - if(next != NULL) { - *next = ptr; - } - return res; -} - -template<> inline const char *parse_arg<const char*>(const char *arg, const char **next) { - return parse_arg<char*>(arg,next); -} - -/* Pins */ - - -inline PinName parse_pins(const char *str) { - const PinName pin_names[] = {p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 - , p15, p16, p17, p18, p19, p20, p21, p22, p23 - , p24, p25, p26, p27, p28, p29, p30}; - - if(str[0] == 'P') { // Pn_n - uint32_t port = str[1] - '0'; - uint32_t pin = str[3] - '0'; // Pn_n - uint32_t pin2 = str[4] - '0'; // Pn_nn - if(pin2 <= 9) { - pin = pin * 10 + pin2; - } -#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) - return (PinName)(LPC_GPIO0_BASE + port * 32 + pin); -#elif defined(TARGET_LPC11U24) - return (PinName)(port * 32 + pin); -#endif - } else if(str[0] == 'p') { // pn - uint32_t pin = str[1] - '0'; // pn - uint32_t pin2 = str[2] - '0'; // pnn - if(pin2 <= 9) { - pin = pin * 10 + pin2; - } - if(pin < 5 || pin > 30) { - return NC; - } - return pin_names[pin - 5]; - } else if(str[0] == 'L') { // LEDn - switch(str[3]) { - case '1' : return LED1; - case '2' : return LED2; - case '3' : return LED3; - case '4' : return LED4; - } - } else if(str[0] == 'U') { // USB?X - switch(str[3]) { - case 'T' : return USBTX; - case 'R' : return USBRX; - } - } - return NC; -} - -template<> inline PinName parse_arg<PinName>(const char *arg, const char **next) { - const char *ptr = arg; - PinName pinname = NC; - while(isalnum(*ptr) || *ptr=='_') { - ptr++; - } - int len = ptr-arg; - if(len!=0) { - pinname = parse_pins(arg); - - } - if(next != NULL) { - *next = ptr; - } - return pinname; -} - - -/** Writes a value in to a result string in an appropriate manner - * - * @param val The value to write - * @param result A pointer to the array to write the value into - */ -template<typename T> void write_result(T val, char *result); - -/* signed integer types */ - -template<> inline void write_result<char>(char val, char *result) { - result[0] = val; - result[1] = '\0'; -} - -template<> inline void write_result<short int>(short int val, char *result) { - sprintf(result, "%hi", val); -} - -template<> inline void write_result<int>(int val, char *result) { - sprintf(result, "%i", val); -} - -template<> inline void write_result<long int>(long int val, char *result) { - sprintf(result, "%li", val); -} - -template<> inline void write_result<long long int>(long long int val, char *result) { - sprintf(result, "%lli", val); -} - -/* unsigned integer types */ - -template<> inline void write_result<unsigned char>(unsigned char val, char *result) { - result[0] = val; - result[1] = '\0'; -} - -template<> inline void write_result<unsigned short int>(unsigned short int val, char *result) { - sprintf(result, "%hu", val); -} - -template<> inline void write_result<unsigned int>(unsigned int val, char *result) { - sprintf(result, "%u", val); -} - -template<> inline void write_result<unsigned long int>(unsigned long int val, char *result) { - sprintf(result, "%lu", val); -} - -template<> inline void write_result<unsigned long long int>(unsigned long long int val, char *result) { - sprintf(result, "%llu", val); -} - -/* floating types */ - -template<> inline void write_result<float>(float val, char *result) { - sprintf(result, "%.17g", val); -} - -template<> inline void write_result<double>(double val, char *result) { - sprintf(result, "%.17g", val); -} - -template<> inline void write_result<long double>(long double val, char *result) { - sprintf(result, "%.17Lg", val); -} - - -/* string */ - -template<> inline void write_result<char*>(char *val, char *result) { - if(val==NULL) { - result[0] = 0; - } else { - strcpy(result, val); - } -} - -template<> inline void write_result<const char*>(const char *val, char *result) { - if(val==NULL) { - result[0] = 0; - } else { - strcpy(result, val); - } -} - - -inline const char *next_arg(const char* next) { - while(*next == ' ') next++; - if(*next == ',' || *next == '?') next++; - while(*next == ' ') next++; - return next; -} - - -/** rpc_method_caller - */ -template<class T, void (T::*member)(const char *,char *)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - (static_cast<T*>(this_ptr)->*member)(arguments,result); -} - - -/** rpc_method_caller - */ -template<class T, void (T::*member)()> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - (static_cast<T*>(this_ptr)->*member)(); - if(result != NULL) { - result[0] = '\0'; - } -} - - -/** rpc_method_caller - */ -template<class T, typename A1, void (T::*member)(A1)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),NULL); - - (static_cast<T*>(this_ptr)->*member)(arg1); - if(result != NULL) { - result[0] = '\0'; - } -} - - -/** rpc_method_caller - */ -template<class T, typename A1, typename A2, void (T::*member)(A1,A2)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),NULL); - - (static_cast<T*>(this_ptr)->*member)(arg1,arg2); - if(result != NULL) { - result[0] = '\0'; - } -} - - -/** rpc_method_caller - */ -template<class T, typename A1, typename A2, typename A3, void (T::*member)(A1,A2,A3)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),&next); - A3 arg3 = parse_arg<A3>(next_arg(next),NULL); - - (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); - if(result != NULL) { - result[0] = '\0'; - } -} - - -/** rpc_method_caller - */ -template<typename R, class T, R (T::*member)()> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - R res = (static_cast<T*>(this_ptr)->*member)(); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_method_caller - */ -template<typename R, class T, typename A1, R (T::*member)(A1)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),NULL); - - R res = (static_cast<T*>(this_ptr)->*member)(arg1); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_method_caller - */ -template<typename R, class T, typename A1, typename A2, R (T::*member)(A1,A2)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),NULL); - - R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_method_caller - */ -template<typename R, class T, typename A1, typename A2, typename A3, R (T::*member)(A1,A2,A3)> -void rpc_method_caller(Base *this_ptr, const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),&next); - A3 arg3 = parse_arg<A3>(next_arg(next),NULL); - - R res = (static_cast<T*>(this_ptr)->*member)(arg1,arg2,arg3); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_function caller - */ -template<typename R, R (*func)()> -void rpc_function_caller(const char *arguments, char *result) { - R res = (*func)(); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_function caller - */ -template<typename R, typename A1, R (*func)(A1)> -void rpc_function_caller(const char *arguments, char *result) { - A1 arg1 = parse_arg<A1>(next_arg(arguments),NULL); - R res = (*func)(arg1); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_function caller - */ -template<typename R, typename A1, typename A2, R (*func)(A1,A2)> -void rpc_function_caller(const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),NULL); - - R res = (*func)(arg1,arg2); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_function caller - */ -template<typename R, typename A1, typename A2, typename A3, R (*func)(A1,A2,A3)> -void rpc_function_caller(const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),&next); - A3 arg3 = parse_arg<A3>(next_arg(next),NULL); - - R res = (*func)(arg1,arg2,arg3); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -/** rpc_function caller - */ -template<typename R, typename A1, typename A2, typename A3, typename A4, R (*func)(A1,A2,A3,A4)> -void rpc_function_caller(const char *arguments, char *result) { - - const char *next = arguments; - A1 arg1 = parse_arg<A1>(next_arg(next),&next); - A2 arg2 = parse_arg<A2>(next_arg(next),&next); - A3 arg3 = parse_arg<A3>(next_arg(next),&next); - A4 arg4 = parse_arg<A4>(next_arg(next),NULL); - - R res = (*func)(arg1,arg2,arg3,arg4); - if(result != NULL) { - write_result<R>(res, result); - } -} - - -struct rpc_method { - const char *name; - typedef void (*caller_t)(Base*, const char*, char*); - typedef const struct rpc_method *(*super_t)(Base*); - union { - caller_t caller; - super_t super; - }; -}; - -template<class C> -const struct rpc_method *rpc_super(Base *this_ptr) { - return static_cast<C*>(this_ptr)->C::get_rpc_methods(); -} - -#define RPC_METHOD_END { NULL, NULL } -#define RPC_METHOD_SUPER(C) { NULL, (rpc_method::caller_t)(rpc_method::super_t)rpc_super<C> } - -/** Parse a string describing a call and then do it - * - * @param call A pointer to a string describing the call, which has - * the form /object/method arg ... argn. Arguments are - * delimited by space characters, and the string is terminated - * by a null character. - * @param result A pointer to an array to write the result into. - */ -bool rpc(const char *buf, char *result = 0); - - -} // namespace mbed - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtc_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,48 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_RTC_API_H +#define MBED_RTC_API_H + +#include "device.h" + +#if DEVICE_RTC + +#include <time.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void rtc_init(void); +void rtc_free(void); +int rtc_isenabled(void); + +time_t rtc_read(void); +void rtc_write(time_t t); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- a/rtc_time.h Fri Oct 26 17:40:46 2012 +0100 +++ b/rtc_time.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,211 +1,80 @@ -/** Implementation of the C time.h functions - * - * Provides mechanisms to set and read the current time, based - * on the microcontroller Real-Time Clock (RTC), plus some - * standard C manipulation and formating functions. - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 - * - * while(1) { - * time_t seconds = time(NULL); - * - * printf("Time as seconds since January 1, 1970 = %d\n", seconds); - * - * printf("Time as a basic string = %s", ctime(&seconds)); - * - * char buffer[32]; - * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); - * printf("Time as a custom formatted string = %s", buffer); - * - * wait(1); - * } - * } - * @endcode - */ - -/* mbed Microcontroller Library - rtc_time - * Copyright (c) 2009 ARM Limited. All rights reserved. - */ - -#include <time.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#if 0 // for documentation only -/** Get the current time - * - * Returns the current timestamp as the number of seconds since January 1, 1970 - * (the UNIX timestamp). The value is based on the current value of the - * microcontroller Real-Time Clock (RTC), which can be set using <set_time>. - * - * @param t Pointer to a time_t to be set, or NULL if not used - * - * @returns - * Number of seconds since January 1, 1970 (the UNIX timestamp) - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * time_t seconds = time(NULL); - * printf("It is %d seconds since January 1, 1970\n", seconds); - * } - * @endcode - */ -time_t time(time_t *t); -#endif - -/** Set the current time - * - * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) - * to the time represented by the number of seconds since January 1, 1970 - * (the UNIX timestamp). - * - * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 - * } - * @endcode - */ -void set_time(time_t t); - -#if 0 // for documentation only -/** Converts the tm structure in to a timestamp in seconds since January 1, 1970 - * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure - * are also updated to their appropriate values. - * - * @param t The tm structure to convert - * - * @returns - * The converted timestamp - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * // setup time structure for Wed, 28 Oct 2009 11:35:37 - * struct tm t; - * t.tm_sec = 37; // 0-59 - * t.tm_min = 35; // 0-59 - * t.tm_hour = 11; // 0-23 - * t.tm_mday = 28; // 1-31 - * t.tm_mon = 9; // 0-11 - * t.tm_year = 109; // year since 1900 - * - * // convert to timestamp and display (1256729737) - * time_t seconds = mktime(&t); - * printf("Time as seconds since January 1, 1970 = %d\n", seconds); - * } - * @endcode - */ -time_t mktime(struct tm *t); -#endif - -#if 0 // for documentation only -/** Converts the timestamp pointed to by t to a (statically allocated) - * tm structure. - * - * @param t Pointer to the timestamp - * - * @returns - * Pointer to the (statically allocated) tm structure - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * time_t seconds = 1256729737; - * struct tm *t = localtime(&seconds); - * } - * @endcode - */ -struct tm *localtime(const time_t *t); -#endif - -#if 0 // for documentation only -/** Converts a timestamp to a human-readable string - * - * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX - * timestamp) to a human readable string format. The result is of the - * format: "Wed Oct 28 11:35:37 2009\n" - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * time_t seconds = time(NULL); - * printf("Time as a string = %s", ctime(&seconds)); - * } - * @endcode - * - * @param t The timestamp to convert - * - * @returns Pointer to a (statically allocated) string containing the - * human readable representation, including a '\n' character - */ -char *ctime(const time_t *t); -#endif - -#if 0 // for documentation only -/** Converts a tm structure to a custom format human-readable string - * - * Creates a formated string from a tm structure, based on a string format - * specifier provided. - * - * Format Specifiers: - * - %S - Second (00-59) - * - %M - Minute (00-59) - * - %H - Hour (00-23) - * - %d - Day (01-31) - * - %m - Month (01-12) - * - %Y/%y - Year (2009/09) - * - %A/%a - Weekday Name (Monday/Mon) - * - %B/%b - Month Name (January/Jan) - * - %I - 12 Hour Format (01-12) - * - %p - "AM" or "PM" - * - %X - Time (14:55:02) - * - %x - Date (08/23/01) - * - * @param buffer String buffer to store the result - * @param max Maximum number of characters to store in the buffer - * @param format Format specifier string - * @param t Pointer to the tm structure to convert - * - * @returns - * Number of characters copied - * - * Example: - * @code - * #include "mbed.h" - * - * int main() { - * time_t seconds = time(NULL); - * - * char buffer[32]; - * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); - * printf("Time as a formatted string = %s", buffer); - * } - * @endcode - */ -size_t strftime(char *buffer, size_t max, const char *format, const struct tm *t); -#endif - -#ifdef __cplusplus -} -#endif +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ + +#include <time.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** Implementation of the C time.h functions + * + * Provides mechanisms to set and read the current time, based + * on the microcontroller Real-Time Clock (RTC), plus some + * standard C manipulation and formating functions. + * + * Example: + * @code + * #include "mbed.h" + * + * int main() { + * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 + * + * while(1) { + * time_t seconds = time(NULL); + * + * printf("Time as seconds since January 1, 1970 = %d\n", seconds); + * + * printf("Time as a basic string = %s", ctime(&seconds)); + * + * char buffer[32]; + * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); + * printf("Time as a custom formatted string = %s", buffer); + * + * wait(1); + * } + * } + * @endcode + */ + +/** Set the current time + * + * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) + * to the time represented by the number of seconds since January 1, 1970 + * (the UNIX timestamp). + * + * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) + * + * Example: + * @code + * #include "mbed.h" + * + * int main() { + * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 + * } + * @endcode + */ +void set_time(time_t t); + +#ifdef __cplusplus +} +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/semihost_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,102 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SEMIHOST_H +#define MBED_SEMIHOST_H + +#include "device.h" +#include "toolchain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* __semihost intrinsic + This intrinsic inserts an SVC or BKPT instruction into the instruction stream + generated by the compiler. It enables you to make semihosting calls from C or + C++ that are independent of the target architecture. + */ +#ifndef __CC_ARM +/* Semihost implementation taken from eLua (MIT license): + * git://github.com/elua/elua.git/src/semifs.c + */ + +/* SWI numbers for RDI (Angel) monitors */ +#ifdef __thumb__ +#define AngelSWI 0xAB +#else +#define AngelSWI 0x123456 +#endif +/* For Thumb-2 code use the BKPT instruction instead of SWI */ +#ifdef __thumb2__ +#define AngelSWIInsn "bkpt" +#define AngelSWIAsm bkpt +#else +#define AngelSWIInsn "swi" +#define AngelSWIAsm swi +#endif + +inline int __semihost(int reason, const void *arg) { + int value; + asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0" + : "=r" (value) /* Outputs */ + : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ + : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" + /* Clobbers r0 and r1, and lr if in supervisor mode */); + /* Accordingly to page 13-77 of ARM DUI 0040D other registers + can also be clobbered. Some memory positions may also be + changed by a system call, so they should not be kept in + registers. Note: we are assuming the manual is right and + Angel is respecting the APCS. */ + + return value; +} + +#endif + +#if DEVICE_LOCALFILESYSTEM +FILEHANDLE semihost_open(const char* name, int openmode); +int semihost_close (FILEHANDLE fh); +int semihost_read (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode); +int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode); +int semihost_ensure(FILEHANDLE fh); +long semihost_flen (FILEHANDLE fh); +int semihost_seek (FILEHANDLE fh, long position); +int semihost_istty (FILEHANDLE fh); + +int semihost_remove(const char *name); +int semihost_rename(const char *old_name, const char *new_name); +#endif + +int semihost_uid(char *uid); +int semihost_reset(void); +int semihost_vbus(void); +int semihost_powerdown(void); +int semihost_exit(void); + +int semihost_connected(void); +int semihost_disabledebug(void); + +#ifdef __cplusplus +} +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serial_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SERIAL_API_H +#define MBED_SERIAL_API_H + +#include "device.h" + +#if DEVICE_SERIAL + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + ParityNone = 0, + ParityOdd = 1, + ParityEven = 2, + ParityForced1 = 3, + ParityForced0 = 4 +} SerialParity; + +typedef enum { + TxIrq, + RxIrq +} SerialIrq; + +typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event); + +typedef struct serial_s serial_t; + +void serial_init (serial_t *obj, PinName tx, PinName rx); +void serial_free (serial_t *obj); +void serial_baud (serial_t *obj, int baudrate); +void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits); + +void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id); +void serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable); + +int serial_getc (serial_t *obj); +void serial_putc (serial_t *obj, int c); +int serial_readable (serial_t *obj); +int serial_writable (serial_t *obj); +void serial_clear (serial_t *obj); + +void serial_pinout_tx(PinName tx); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sleep_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,70 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SLEEP_API_H +#define MBED_SLEEP_API_H + +#include "device.h" + +#if DEVICE_SLEEP + +#ifdef __cplusplus +extern "C" { +#endif + +/** Send the microcontroller to sleep + * + * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the + * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates + * dynamic power used by the processor, memory systems and buses. The processor, peripheral and + * memory state are maintained, and the peripherals continue to work and can generate interrupts. + * + * The processor can be woken up by any internal peripheral interrupt or external pin interrupt. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void sleep(void); + +/** Send the microcontroller to deep sleep + * + * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode + * has the same sleep features as sleep plus it powers down peripherals and clocks. All state + * is still maintained. + * + * The processor can only be woken up by an external interrupt on a pin or a watchdog timer. + * + * @note + * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. + * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be + * able to access the LocalFileSystem + */ +void deepsleep(void); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spi_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,51 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_SPI_API_H +#define MBED_SPI_API_H + +#include "device.h" + +#if DEVICE_SPI + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct spi_s spi_t; + +void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel); +void spi_free (spi_t *obj); +void spi_format (spi_t *obj, int bits, int mode, int slave); +void spi_frequency (spi_t *obj, int hz); +int spi_master_write (spi_t *obj, int value); +int spi_slave_receive(spi_t *obj); +int spi_slave_read (spi_t *obj); +void spi_slave_write (spi_t *obj, int value); +int spi_busy (spi_t *obj); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolchain.h Wed Nov 21 10:49:56 2012 +0000 @@ -0,0 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_TOOLCHAIN_H +#define MBED_TOOLCHAIN_H + +#if defined(TOOLCHAIN_ARM) || defined(TOOLCHAIN_uARM) +#include <rt_sys.h> +#endif + +#ifndef FILEHANDLE +typedef int FILEHANDLE; +#endif + +#endif
--- a/us_ticker_api.h Fri Oct 26 17:40:46 2012 +0100 +++ b/us_ticker_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,7 +1,24 @@ -/* mbed Microcontroller Library - us_ticker_api - * Copyright (c) 2009 ARM Limited. All rights reserved. - */ - +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ #ifndef MBED_US_TICKER_API_H #define MBED_US_TICKER_API_H @@ -9,12 +26,24 @@ #ifdef __cplusplus extern "C" { -#endif +#endif uint32_t us_ticker_read(void); +typedef void (*ticker_event_handler)(uint32_t id); +void us_ticker_set_handler(ticker_event_handler handler); + +typedef struct ticker_event_s { + uint32_t timestamp; + uint32_t id; + struct ticker_event_s *next; +} ticker_event_t; + +void us_ticker_insert_event(ticker_event_t *obj, unsigned int timestamp, uint32_t id); +void us_ticker_remove_event(ticker_event_t *obj); + #ifdef __cplusplus } -#endif +#endif #endif
--- a/wait_api.h Fri Oct 26 17:40:46 2012 +0100 +++ b/wait_api.h Wed Nov 21 10:49:56 2012 +0000 @@ -1,3 +1,31 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * 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. + */ +#ifndef MBED_WAIT_API_H +#define MBED_WAIT_API_H + +#ifdef __cplusplus +extern "C" { +#endif + /** Generic wait functions. * * These provide simple NOP type wait capabilities. @@ -18,17 +46,6 @@ * } */ -/* mbed Microcontroller Library - wait_api - * Copyright (c) 2009 ARM Limited. All rights reserved. - */ - -#ifndef MBED_WAIT_API_H -#define MBED_WAIT_API_H - -#ifdef __cplusplus -extern "C" { -#endif - /** Waits for a number of seconds, with microsecond resolution (within * the accuracy of single precision floating point). * @@ -48,39 +65,6 @@ */ void wait_us(int us); -#ifdef TARGET_LPC11U24 -/** Send the microcontroller to sleep - * - * The processor is setup ready for sleep, and sent to sleep using __WFI(). In this mode, the - * system clock to the core is stopped until a reset or an interrupt occurs. This eliminates - * dynamic power used by the processor, memory systems and buses. The processor, peripheral and - * memory state are maintained, and the peripherals continue to work and can generate interrupts. - * - * The processor can be woken up by any internal peripheral interrupt or external pin interrupt. - * - * @note - * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. - * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be - * able to access the LocalFileSystem - */ -void sleep(void); - -/** Send the microcontroller to deep sleep - * - * This processor is setup ready for deep sleep, and sent to sleep using __WFI(). This mode - * has the same sleep features as sleep plus it powers down peripherals and clocks. All state - * is still maintained. - * - * The processor can only be woken up by an external interrupt on a pin or a watchdog timer. - * - * @note - * The mbed interface semihosting is disconnected as part of going to sleep, and can not be restored. - * Flash re-programming and the USB serial port will remain active, but the mbed program will no longer be - * able to access the LocalFileSystem - */ -void deepsleep(void); -#endif - #ifdef __cplusplus } #endif