Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lypinator 0:bb348c97df44 1 /* mbed Microcontroller Library
lypinator 0:bb348c97df44 2 * Copyright (c) 2006-2013 ARM Limited
lypinator 0:bb348c97df44 3 *
lypinator 0:bb348c97df44 4 * Licensed under the Apache License, Version 2.0 (the "License");
lypinator 0:bb348c97df44 5 * you may not use this file except in compliance with the License.
lypinator 0:bb348c97df44 6 * You may obtain a copy of the License at
lypinator 0:bb348c97df44 7 *
lypinator 0:bb348c97df44 8 * http://www.apache.org/licenses/LICENSE-2.0
lypinator 0:bb348c97df44 9 *
lypinator 0:bb348c97df44 10 * Unless required by applicable law or agreed to in writing, software
lypinator 0:bb348c97df44 11 * distributed under the License is distributed on an "AS IS" BASIS,
lypinator 0:bb348c97df44 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lypinator 0:bb348c97df44 13 * See the License for the specific language governing permissions and
lypinator 0:bb348c97df44 14 * limitations under the License.
lypinator 0:bb348c97df44 15 */
lypinator 0:bb348c97df44 16 #include <stdio.h>
lypinator 0:bb348c97df44 17 #include "platform/mbed_interface.h"
lypinator 0:bb348c97df44 18
lypinator 0:bb348c97df44 19 #include "hal/gpio_api.h"
lypinator 0:bb348c97df44 20 #include "platform/mbed_wait_api.h"
lypinator 0:bb348c97df44 21 #include "platform/mbed_semihost_api.h"
lypinator 0:bb348c97df44 22 #include "platform/mbed_error.h"
lypinator 0:bb348c97df44 23 #include "platform/mbed_toolchain.h"
lypinator 0:bb348c97df44 24
lypinator 0:bb348c97df44 25 #if DEVICE_SEMIHOST
lypinator 0:bb348c97df44 26
lypinator 0:bb348c97df44 27 // return true if a debugger is attached, indicating mbed interface is connected
lypinator 0:bb348c97df44 28 int mbed_interface_connected(void)
lypinator 0:bb348c97df44 29 {
lypinator 0:bb348c97df44 30 return semihost_connected();
lypinator 0:bb348c97df44 31 }
lypinator 0:bb348c97df44 32
lypinator 0:bb348c97df44 33 int mbed_interface_reset(void)
lypinator 0:bb348c97df44 34 {
lypinator 0:bb348c97df44 35 if (mbed_interface_connected()) {
lypinator 0:bb348c97df44 36 semihost_reset();
lypinator 0:bb348c97df44 37 return 0;
lypinator 0:bb348c97df44 38 } else {
lypinator 0:bb348c97df44 39 return -1;
lypinator 0:bb348c97df44 40 }
lypinator 0:bb348c97df44 41 }
lypinator 0:bb348c97df44 42
lypinator 0:bb348c97df44 43 WEAK int mbed_interface_uid(char *uid)
lypinator 0:bb348c97df44 44 {
lypinator 0:bb348c97df44 45 if (mbed_interface_connected()) {
lypinator 0:bb348c97df44 46 return semihost_uid(uid); // Returns 0 if successful, -1 on failure
lypinator 0:bb348c97df44 47 } else {
lypinator 0:bb348c97df44 48 uid[0] = 0;
lypinator 0:bb348c97df44 49 return -1;
lypinator 0:bb348c97df44 50 }
lypinator 0:bb348c97df44 51 }
lypinator 0:bb348c97df44 52
lypinator 0:bb348c97df44 53 int mbed_interface_disconnect(void)
lypinator 0:bb348c97df44 54 {
lypinator 0:bb348c97df44 55 int res;
lypinator 0:bb348c97df44 56 if (mbed_interface_connected()) {
lypinator 0:bb348c97df44 57 if ((res = semihost_disabledebug()) != 0) {
lypinator 0:bb348c97df44 58 return res;
lypinator 0:bb348c97df44 59 }
lypinator 0:bb348c97df44 60 while (mbed_interface_connected());
lypinator 0:bb348c97df44 61 return 0;
lypinator 0:bb348c97df44 62 } else {
lypinator 0:bb348c97df44 63 return -1;
lypinator 0:bb348c97df44 64 }
lypinator 0:bb348c97df44 65 }
lypinator 0:bb348c97df44 66
lypinator 0:bb348c97df44 67 int mbed_interface_powerdown(void)
lypinator 0:bb348c97df44 68 {
lypinator 0:bb348c97df44 69 int res;
lypinator 0:bb348c97df44 70 if (mbed_interface_connected()) {
lypinator 0:bb348c97df44 71 if ((res = semihost_powerdown()) != 0) {
lypinator 0:bb348c97df44 72 return res;
lypinator 0:bb348c97df44 73 }
lypinator 0:bb348c97df44 74 while (mbed_interface_connected());
lypinator 0:bb348c97df44 75 return 0;
lypinator 0:bb348c97df44 76 } else {
lypinator 0:bb348c97df44 77 return -1;
lypinator 0:bb348c97df44 78 }
lypinator 0:bb348c97df44 79 }
lypinator 0:bb348c97df44 80
lypinator 0:bb348c97df44 81 MBED_DEPRECATED_SINCE("mbed-os-5.9", "This function shouldn't be used in new code."
lypinator 0:bb348c97df44 82 "For system reset funcionality use system_reset()")
lypinator 0:bb348c97df44 83 void mbed_reset(void)
lypinator 0:bb348c97df44 84 {
lypinator 0:bb348c97df44 85 mbed_interface_reset();
lypinator 0:bb348c97df44 86 }
lypinator 0:bb348c97df44 87
lypinator 0:bb348c97df44 88 WEAK int mbed_uid(char *uid)
lypinator 0:bb348c97df44 89 {
lypinator 0:bb348c97df44 90 return mbed_interface_uid(uid);
lypinator 0:bb348c97df44 91 }
lypinator 0:bb348c97df44 92 #endif
lypinator 0:bb348c97df44 93
lypinator 0:bb348c97df44 94 WEAK void mbed_mac_address(char *mac)
lypinator 0:bb348c97df44 95 {
lypinator 0:bb348c97df44 96 #if DEVICE_SEMIHOST
lypinator 0:bb348c97df44 97 char uid[DEVICE_ID_LENGTH + 1];
lypinator 0:bb348c97df44 98 int i;
lypinator 0:bb348c97df44 99
lypinator 0:bb348c97df44 100 // if we have a UID, extract the MAC
lypinator 0:bb348c97df44 101 if (mbed_interface_uid(uid) == 0) {
lypinator 0:bb348c97df44 102 char *p = uid;
lypinator 0:bb348c97df44 103 #if defined(DEVICE_MAC_OFFSET)
lypinator 0:bb348c97df44 104 p += DEVICE_MAC_OFFSET;
lypinator 0:bb348c97df44 105 #endif
lypinator 0:bb348c97df44 106 for (i = 0; i < 6; i++) {
lypinator 0:bb348c97df44 107 int byte;
lypinator 0:bb348c97df44 108 sscanf(p, "%2x", &byte);
lypinator 0:bb348c97df44 109 mac[i] = byte;
lypinator 0:bb348c97df44 110 p += 2;
lypinator 0:bb348c97df44 111 }
lypinator 0:bb348c97df44 112 mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
lypinator 0:bb348c97df44 113 } else { // else return a default MAC
lypinator 0:bb348c97df44 114 #endif
lypinator 0:bb348c97df44 115 mac[0] = 0x00;
lypinator 0:bb348c97df44 116 mac[1] = 0x02;
lypinator 0:bb348c97df44 117 mac[2] = 0xF7;
lypinator 0:bb348c97df44 118 mac[3] = 0xF0;
lypinator 0:bb348c97df44 119 mac[4] = 0x00;
lypinator 0:bb348c97df44 120 mac[5] = 0x00;
lypinator 0:bb348c97df44 121 #if DEVICE_SEMIHOST
lypinator 0:bb348c97df44 122 }
lypinator 0:bb348c97df44 123 #endif
lypinator 0:bb348c97df44 124 }