MCU driver/HAL for the Picocell Gateway concentrator board. The firmware implements either a USB CDC protocol or a UART protocol to bridge commands coming from host to the SX1308 SPI interface.

Committer:
dgabino
Date:
Wed Apr 11 14:42:47 2018 +0000
Revision:
0:c76361bd82e8
Initial commit

Who changed what in which revision?

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