This repo contains the libraries of Mbed for LPC1549 with following changes: - IAP commands. - EEPROM write and read. - UART write and read (public) - CAN can_s -> LPC_C_CAN0_Type *can

Committer:
gmatarrubia
Date:
Tue Apr 14 15:00:13 2015 +0200
Revision:
0:820a69dfd200
Initial repo. IAP commands, EEPROM write/read, UART write/read, CAN

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmatarrubia 0:820a69dfd200 1 /* mbed Microcontroller Library
gmatarrubia 0:820a69dfd200 2 * Copyright (c) 2006-2013 ARM Limited
gmatarrubia 0:820a69dfd200 3 *
gmatarrubia 0:820a69dfd200 4 * Licensed under the Apache License, Version 2.0 (the "License");
gmatarrubia 0:820a69dfd200 5 * you may not use this file except in compliance with the License.
gmatarrubia 0:820a69dfd200 6 * You may obtain a copy of the License at
gmatarrubia 0:820a69dfd200 7 *
gmatarrubia 0:820a69dfd200 8 * http://www.apache.org/licenses/LICENSE-2.0
gmatarrubia 0:820a69dfd200 9 *
gmatarrubia 0:820a69dfd200 10 * Unless required by applicable law or agreed to in writing, software
gmatarrubia 0:820a69dfd200 11 * distributed under the License is distributed on an "AS IS" BASIS,
gmatarrubia 0:820a69dfd200 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
gmatarrubia 0:820a69dfd200 13 * See the License for the specific language governing permissions and
gmatarrubia 0:820a69dfd200 14 * limitations under the License.
gmatarrubia 0:820a69dfd200 15 */
gmatarrubia 0:820a69dfd200 16 #ifndef MBED_FUNCTIONPOINTER_H
gmatarrubia 0:820a69dfd200 17 #define MBED_FUNCTIONPOINTER_H
gmatarrubia 0:820a69dfd200 18
gmatarrubia 0:820a69dfd200 19 #include <string.h>
gmatarrubia 0:820a69dfd200 20
gmatarrubia 0:820a69dfd200 21 namespace mbed {
gmatarrubia 0:820a69dfd200 22
gmatarrubia 0:820a69dfd200 23 typedef void (*pvoidf_t)(void);
gmatarrubia 0:820a69dfd200 24
gmatarrubia 0:820a69dfd200 25 /** A class for storing and calling a pointer to a static or member void function
gmatarrubia 0:820a69dfd200 26 */
gmatarrubia 0:820a69dfd200 27 class FunctionPointer {
gmatarrubia 0:820a69dfd200 28 public:
gmatarrubia 0:820a69dfd200 29
gmatarrubia 0:820a69dfd200 30 /** Create a FunctionPointer, attaching a static function
gmatarrubia 0:820a69dfd200 31 *
gmatarrubia 0:820a69dfd200 32 * @param function The void static function to attach (default is none)
gmatarrubia 0:820a69dfd200 33 */
gmatarrubia 0:820a69dfd200 34 FunctionPointer(void (*function)(void) = 0);
gmatarrubia 0:820a69dfd200 35
gmatarrubia 0:820a69dfd200 36 /** Create a FunctionPointer, attaching a member function
gmatarrubia 0:820a69dfd200 37 *
gmatarrubia 0:820a69dfd200 38 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
gmatarrubia 0:820a69dfd200 39 * @param function The address of the void member function to attach
gmatarrubia 0:820a69dfd200 40 */
gmatarrubia 0:820a69dfd200 41 template<typename T>
gmatarrubia 0:820a69dfd200 42 FunctionPointer(T *object, void (T::*member)(void)) {
gmatarrubia 0:820a69dfd200 43 attach(object, member);
gmatarrubia 0:820a69dfd200 44 }
gmatarrubia 0:820a69dfd200 45
gmatarrubia 0:820a69dfd200 46 /** Attach a static function
gmatarrubia 0:820a69dfd200 47 *
gmatarrubia 0:820a69dfd200 48 * @param function The void static function to attach (default is none)
gmatarrubia 0:820a69dfd200 49 */
gmatarrubia 0:820a69dfd200 50 void attach(void (*function)(void) = 0);
gmatarrubia 0:820a69dfd200 51
gmatarrubia 0:820a69dfd200 52 /** Attach a member function
gmatarrubia 0:820a69dfd200 53 *
gmatarrubia 0:820a69dfd200 54 * @param object The object pointer to invoke the member function on (i.e. the this pointer)
gmatarrubia 0:820a69dfd200 55 * @param function The address of the void member function to attach
gmatarrubia 0:820a69dfd200 56 */
gmatarrubia 0:820a69dfd200 57 template<typename T>
gmatarrubia 0:820a69dfd200 58 void attach(T *object, void (T::*member)(void)) {
gmatarrubia 0:820a69dfd200 59 _object = static_cast<void*>(object);
gmatarrubia 0:820a69dfd200 60 memcpy(_member, (char*)&member, sizeof(member));
gmatarrubia 0:820a69dfd200 61 _membercaller = &FunctionPointer::membercaller<T>;
gmatarrubia 0:820a69dfd200 62 _function = 0;
gmatarrubia 0:820a69dfd200 63 }
gmatarrubia 0:820a69dfd200 64
gmatarrubia 0:820a69dfd200 65 /** Call the attached static or member function
gmatarrubia 0:820a69dfd200 66 */
gmatarrubia 0:820a69dfd200 67 void call();
gmatarrubia 0:820a69dfd200 68
gmatarrubia 0:820a69dfd200 69 pvoidf_t get_function() const {
gmatarrubia 0:820a69dfd200 70 return (pvoidf_t)_function;
gmatarrubia 0:820a69dfd200 71 }
gmatarrubia 0:820a69dfd200 72
gmatarrubia 0:820a69dfd200 73 #ifdef MBED_OPERATORS
gmatarrubia 0:820a69dfd200 74 void operator ()(void);
gmatarrubia 0:820a69dfd200 75 #endif
gmatarrubia 0:820a69dfd200 76
gmatarrubia 0:820a69dfd200 77 private:
gmatarrubia 0:820a69dfd200 78 template<typename T>
gmatarrubia 0:820a69dfd200 79 static void membercaller(void *object, char *member) {
gmatarrubia 0:820a69dfd200 80 T* o = static_cast<T*>(object);
gmatarrubia 0:820a69dfd200 81 void (T::*m)(void);
gmatarrubia 0:820a69dfd200 82 memcpy((char*)&m, member, sizeof(m));
gmatarrubia 0:820a69dfd200 83 (o->*m)();
gmatarrubia 0:820a69dfd200 84 }
gmatarrubia 0:820a69dfd200 85
gmatarrubia 0:820a69dfd200 86 void (*_function)(void); // static function pointer - 0 if none attached
gmatarrubia 0:820a69dfd200 87 void *_object; // object this pointer - 0 if none attached
gmatarrubia 0:820a69dfd200 88 char _member[16]; // raw member function pointer storage - converted back by registered _membercaller
gmatarrubia 0:820a69dfd200 89 void (*_membercaller)(void*, char*); // registered membercaller function to convert back and call _member on _object
gmatarrubia 0:820a69dfd200 90 };
gmatarrubia 0:820a69dfd200 91
gmatarrubia 0:820a69dfd200 92 } // namespace mbed
gmatarrubia 0:820a69dfd200 93
gmatarrubia 0:820a69dfd200 94 #endif