inport from local
Dependents: Hobbyking_Cheetah_0511
platform/mbed_interface.h@0:85b3fd62ea1a, 2020-03-16 (annotated)
- Committer:
- NYX
- Date:
- Mon Mar 16 06:35:48 2020 +0000
- Revision:
- 0:85b3fd62ea1a
reinport to mbed;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NYX | 0:85b3fd62ea1a | 1 | |
NYX | 0:85b3fd62ea1a | 2 | /** \addtogroup platform */ |
NYX | 0:85b3fd62ea1a | 3 | /** @{*/ |
NYX | 0:85b3fd62ea1a | 4 | /* mbed Microcontroller Library |
NYX | 0:85b3fd62ea1a | 5 | * Copyright (c) 2006-2013 ARM Limited |
NYX | 0:85b3fd62ea1a | 6 | * |
NYX | 0:85b3fd62ea1a | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
NYX | 0:85b3fd62ea1a | 8 | * you may not use this file except in compliance with the License. |
NYX | 0:85b3fd62ea1a | 9 | * You may obtain a copy of the License at |
NYX | 0:85b3fd62ea1a | 10 | * |
NYX | 0:85b3fd62ea1a | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
NYX | 0:85b3fd62ea1a | 12 | * |
NYX | 0:85b3fd62ea1a | 13 | * Unless required by applicable law or agreed to in writing, software |
NYX | 0:85b3fd62ea1a | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
NYX | 0:85b3fd62ea1a | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
NYX | 0:85b3fd62ea1a | 16 | * See the License for the specific language governing permissions and |
NYX | 0:85b3fd62ea1a | 17 | * limitations under the License. |
NYX | 0:85b3fd62ea1a | 18 | */ |
NYX | 0:85b3fd62ea1a | 19 | #ifndef MBED_INTERFACE_H |
NYX | 0:85b3fd62ea1a | 20 | #define MBED_INTERFACE_H |
NYX | 0:85b3fd62ea1a | 21 | |
NYX | 0:85b3fd62ea1a | 22 | #include <stdarg.h> |
NYX | 0:85b3fd62ea1a | 23 | |
NYX | 0:85b3fd62ea1a | 24 | #include "device.h" |
NYX | 0:85b3fd62ea1a | 25 | |
NYX | 0:85b3fd62ea1a | 26 | /* Mbed interface mac address |
NYX | 0:85b3fd62ea1a | 27 | * if MBED_MAC_ADD_x are zero, interface uid sets mac address, |
NYX | 0:85b3fd62ea1a | 28 | * otherwise MAC_ADD_x are used. |
NYX | 0:85b3fd62ea1a | 29 | */ |
NYX | 0:85b3fd62ea1a | 30 | #define MBED_MAC_ADDR_INTERFACE 0x00 |
NYX | 0:85b3fd62ea1a | 31 | #define MBED_MAC_ADDR_0 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 32 | #define MBED_MAC_ADDR_1 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 33 | #define MBED_MAC_ADDR_2 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 34 | #define MBED_MAC_ADDR_3 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 35 | #define MBED_MAC_ADDR_4 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 36 | #define MBED_MAC_ADDR_5 MBED_MAC_ADDR_INTERFACE |
NYX | 0:85b3fd62ea1a | 37 | #define MBED_MAC_ADDRESS_SUM (MBED_MAC_ADDR_0 | MBED_MAC_ADDR_1 | MBED_MAC_ADDR_2 | MBED_MAC_ADDR_3 | MBED_MAC_ADDR_4 | MBED_MAC_ADDR_5) |
NYX | 0:85b3fd62ea1a | 38 | |
NYX | 0:85b3fd62ea1a | 39 | #ifdef __cplusplus |
NYX | 0:85b3fd62ea1a | 40 | extern "C" { |
NYX | 0:85b3fd62ea1a | 41 | #endif |
NYX | 0:85b3fd62ea1a | 42 | |
NYX | 0:85b3fd62ea1a | 43 | #if DEVICE_SEMIHOST |
NYX | 0:85b3fd62ea1a | 44 | |
NYX | 0:85b3fd62ea1a | 45 | /** Functions to control the mbed interface |
NYX | 0:85b3fd62ea1a | 46 | * |
NYX | 0:85b3fd62ea1a | 47 | * mbed Microcontrollers have a built-in interface to provide functionality such as |
NYX | 0:85b3fd62ea1a | 48 | * drag-n-drop download, reset, serial-over-usb, and access to the mbed local file |
NYX | 0:85b3fd62ea1a | 49 | * system. These functions provide means to control the interface suing semihost |
NYX | 0:85b3fd62ea1a | 50 | * calls it supports. |
NYX | 0:85b3fd62ea1a | 51 | */ |
NYX | 0:85b3fd62ea1a | 52 | |
NYX | 0:85b3fd62ea1a | 53 | /** Determine whether the mbed interface is connected, based on whether debug is enabled |
NYX | 0:85b3fd62ea1a | 54 | * |
NYX | 0:85b3fd62ea1a | 55 | * @returns |
NYX | 0:85b3fd62ea1a | 56 | * 1 if interface is connected, |
NYX | 0:85b3fd62ea1a | 57 | * 0 otherwise |
NYX | 0:85b3fd62ea1a | 58 | */ |
NYX | 0:85b3fd62ea1a | 59 | int mbed_interface_connected(void); |
NYX | 0:85b3fd62ea1a | 60 | |
NYX | 0:85b3fd62ea1a | 61 | /** Instruct the mbed interface to reset, as if the reset button had been pressed |
NYX | 0:85b3fd62ea1a | 62 | * |
NYX | 0:85b3fd62ea1a | 63 | * @returns |
NYX | 0:85b3fd62ea1a | 64 | * 1 if successful, |
NYX | 0:85b3fd62ea1a | 65 | * 0 otherwise (e.g. interface not present) |
NYX | 0:85b3fd62ea1a | 66 | */ |
NYX | 0:85b3fd62ea1a | 67 | int mbed_interface_reset(void); |
NYX | 0:85b3fd62ea1a | 68 | |
NYX | 0:85b3fd62ea1a | 69 | /** This will disconnect the debug aspect of the interface, so semihosting will be disabled. |
NYX | 0:85b3fd62ea1a | 70 | * The interface will still support the USB serial aspect |
NYX | 0:85b3fd62ea1a | 71 | * |
NYX | 0:85b3fd62ea1a | 72 | * @returns |
NYX | 0:85b3fd62ea1a | 73 | * 0 if successful, |
NYX | 0:85b3fd62ea1a | 74 | * -1 otherwise (e.g. interface not present) |
NYX | 0:85b3fd62ea1a | 75 | */ |
NYX | 0:85b3fd62ea1a | 76 | int mbed_interface_disconnect(void); |
NYX | 0:85b3fd62ea1a | 77 | |
NYX | 0:85b3fd62ea1a | 78 | /** This will disconnect the debug aspect of the interface, and if the USB cable is not |
NYX | 0:85b3fd62ea1a | 79 | * connected, also power down the interface. If the USB cable is connected, the interface |
NYX | 0:85b3fd62ea1a | 80 | * will remain powered up and visible to the host |
NYX | 0:85b3fd62ea1a | 81 | * |
NYX | 0:85b3fd62ea1a | 82 | * @returns |
NYX | 0:85b3fd62ea1a | 83 | * 0 if successful, |
NYX | 0:85b3fd62ea1a | 84 | * -1 otherwise (e.g. interface not present) |
NYX | 0:85b3fd62ea1a | 85 | */ |
NYX | 0:85b3fd62ea1a | 86 | int mbed_interface_powerdown(void); |
NYX | 0:85b3fd62ea1a | 87 | |
NYX | 0:85b3fd62ea1a | 88 | /** This returns a string containing the 32-character UID of the mbed interface |
NYX | 0:85b3fd62ea1a | 89 | * This is a weak function that can be overwritten if required |
NYX | 0:85b3fd62ea1a | 90 | * |
NYX | 0:85b3fd62ea1a | 91 | * @param uid A 33-byte array to write the null terminated 32-byte string |
NYX | 0:85b3fd62ea1a | 92 | * |
NYX | 0:85b3fd62ea1a | 93 | * @returns |
NYX | 0:85b3fd62ea1a | 94 | * 0 if successful, |
NYX | 0:85b3fd62ea1a | 95 | * -1 otherwise (e.g. interface not present) |
NYX | 0:85b3fd62ea1a | 96 | */ |
NYX | 0:85b3fd62ea1a | 97 | int mbed_interface_uid(char *uid); |
NYX | 0:85b3fd62ea1a | 98 | |
NYX | 0:85b3fd62ea1a | 99 | #endif |
NYX | 0:85b3fd62ea1a | 100 | |
NYX | 0:85b3fd62ea1a | 101 | /** This returns a unique 6-byte MAC address, based on the interface UID |
NYX | 0:85b3fd62ea1a | 102 | * If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00) |
NYX | 0:85b3fd62ea1a | 103 | * |
NYX | 0:85b3fd62ea1a | 104 | * This is a weak function that can be overwritten if you want to provide your own mechanism to |
NYX | 0:85b3fd62ea1a | 105 | * provide a MAC address. |
NYX | 0:85b3fd62ea1a | 106 | * |
NYX | 0:85b3fd62ea1a | 107 | * @param mac A 6-byte array to write the MAC address |
NYX | 0:85b3fd62ea1a | 108 | */ |
NYX | 0:85b3fd62ea1a | 109 | void mbed_mac_address(char *mac); |
NYX | 0:85b3fd62ea1a | 110 | |
NYX | 0:85b3fd62ea1a | 111 | /** Cause the mbed to flash the BLOD (Blue LEDs Of Death) sequence |
NYX | 0:85b3fd62ea1a | 112 | */ |
NYX | 0:85b3fd62ea1a | 113 | void mbed_die(void); |
NYX | 0:85b3fd62ea1a | 114 | |
NYX | 0:85b3fd62ea1a | 115 | /** Print out an error message. This is typically called when |
NYX | 0:85b3fd62ea1a | 116 | * handling a crash. |
NYX | 0:85b3fd62ea1a | 117 | * |
NYX | 0:85b3fd62ea1a | 118 | * @note Synchronization level: Interrupt safe |
NYX | 0:85b3fd62ea1a | 119 | * |
NYX | 0:85b3fd62ea1a | 120 | * @param format C string that contains data stream to be printed. |
NYX | 0:85b3fd62ea1a | 121 | * Code snippets below show valid format. |
NYX | 0:85b3fd62ea1a | 122 | * |
NYX | 0:85b3fd62ea1a | 123 | * @code |
NYX | 0:85b3fd62ea1a | 124 | * mbed_error_printf("Failed: %s, file: %s, line %d \n", expr, file, line); |
NYX | 0:85b3fd62ea1a | 125 | * @endcode |
NYX | 0:85b3fd62ea1a | 126 | * |
NYX | 0:85b3fd62ea1a | 127 | */ |
NYX | 0:85b3fd62ea1a | 128 | void mbed_error_printf(const char* format, ...); |
NYX | 0:85b3fd62ea1a | 129 | |
NYX | 0:85b3fd62ea1a | 130 | /** Print out an error message. Similar to mbed_error_printf |
NYX | 0:85b3fd62ea1a | 131 | * but uses a va_list. |
NYX | 0:85b3fd62ea1a | 132 | * |
NYX | 0:85b3fd62ea1a | 133 | * @note Synchronization level: Interrupt safe |
NYX | 0:85b3fd62ea1a | 134 | * |
NYX | 0:85b3fd62ea1a | 135 | * @param format C string that contains data stream to be printed. |
NYX | 0:85b3fd62ea1a | 136 | * @param arg Variable arguments list |
NYX | 0:85b3fd62ea1a | 137 | * |
NYX | 0:85b3fd62ea1a | 138 | */ |
NYX | 0:85b3fd62ea1a | 139 | void mbed_error_vfprintf(const char * format, va_list arg); |
NYX | 0:85b3fd62ea1a | 140 | |
NYX | 0:85b3fd62ea1a | 141 | #ifdef __cplusplus |
NYX | 0:85b3fd62ea1a | 142 | } |
NYX | 0:85b3fd62ea1a | 143 | #endif |
NYX | 0:85b3fd62ea1a | 144 | |
NYX | 0:85b3fd62ea1a | 145 | #endif |
NYX | 0:85b3fd62ea1a | 146 | |
NYX | 0:85b3fd62ea1a | 147 | /** @}*/ |