Subdirectory provided by Embedded Artists
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Dependents: lpc4088_displaymodule_hello_world_Sept_2018
Fork of DMSupport by
Bios/BiosLoader.cpp@40:6df4f63aa406, 2015-06-10 (annotated)
- Committer:
- alindvall
- Date:
- Wed Jun 10 09:54:15 2015 +0000
- Revision:
- 40:6df4f63aa406
- Parent:
- 34:fc366bab393f
Updated USBDevice, mbed-src and mbed-rtos libraries to latest version. Fixed compiler errors related to us_ticker_read() that was introduced in latest mbed-src version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 22:1a58a518435c | 1 | /* |
embeddedartists | 22:1a58a518435c | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 22:1a58a518435c | 3 | * |
embeddedartists | 22:1a58a518435c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 22:1a58a518435c | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 22:1a58a518435c | 6 | * You may obtain a copy of the License at |
embeddedartists | 22:1a58a518435c | 7 | * |
embeddedartists | 22:1a58a518435c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 22:1a58a518435c | 9 | * |
embeddedartists | 22:1a58a518435c | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 22:1a58a518435c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 22:1a58a518435c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 22:1a58a518435c | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 22:1a58a518435c | 14 | * limitations under the License. |
embeddedartists | 22:1a58a518435c | 15 | */ |
embeddedartists | 22:1a58a518435c | 16 | |
embeddedartists | 22:1a58a518435c | 17 | #include "mbed.h" |
alindvall | 40:6df4f63aa406 | 18 | #include "us_ticker_api.h" |
embeddedartists | 22:1a58a518435c | 19 | #include "BiosLoader.h" |
embeddedartists | 22:1a58a518435c | 20 | #include "DMBoard.h" |
embeddedartists | 22:1a58a518435c | 21 | #include "BiosEEPROM.h" |
embeddedartists | 22:1a58a518435c | 22 | #include "crc.h" |
embeddedartists | 22:1a58a518435c | 23 | #include "bios.h" |
embeddedartists | 28:8ae20cb0b943 | 24 | #include "meas.h" |
embeddedartists | 22:1a58a518435c | 25 | |
embeddedartists | 22:1a58a518435c | 26 | #if defined(DM_BOARD_BIOS_DEVELOPMENT) |
embeddedartists | 22:1a58a518435c | 27 | #ifdef __cplusplus |
embeddedartists | 22:1a58a518435c | 28 | extern "C" { |
embeddedartists | 22:1a58a518435c | 29 | #endif |
embeddedartists | 26:a65fbb4bde5c | 30 | void bios_debug_aid(bios_header_t* header, const char** pMsg, uint32_t* paramSize); |
embeddedartists | 22:1a58a518435c | 31 | #ifdef __cplusplus |
embeddedartists | 22:1a58a518435c | 32 | } |
embeddedartists | 22:1a58a518435c | 33 | #endif |
embeddedartists | 22:1a58a518435c | 34 | #endif |
embeddedartists | 22:1a58a518435c | 35 | |
embeddedartists | 22:1a58a518435c | 36 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 37 | * Defines and typedefs |
embeddedartists | 22:1a58a518435c | 38 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 39 | |
embeddedartists | 22:1a58a518435c | 40 | #define MOVE_POINTER(__x, __off) ( ( (uint32_t*)(__x) ) = (uint32_t*)( (uint32_t)(__x) + (__off) ) ) |
embeddedartists | 22:1a58a518435c | 41 | |
embeddedartists | 22:1a58a518435c | 42 | /* |
embeddedartists | 22:1a58a518435c | 43 | * Make sure that we reserve at least this amount of RAM for future |
embeddedartists | 22:1a58a518435c | 44 | * expansion of the BIOS. This prevents the user from squeezing out |
embeddedartists | 22:1a58a518435c | 45 | * the last drop of available RAM in his application. |
embeddedartists | 22:1a58a518435c | 46 | */ |
embeddedartists | 22:1a58a518435c | 47 | #define BIOS_RESERVED_CHUNK 0x1000 |
embeddedartists | 22:1a58a518435c | 48 | #define BIOS_MAX_SIZE 0x100000 |
embeddedartists | 22:1a58a518435c | 49 | #ifndef MAX |
embeddedartists | 22:1a58a518435c | 50 | #define MAX(__a, __b) (((__a)>(__b))?(__a):(__b)) |
embeddedartists | 22:1a58a518435c | 51 | #endif |
embeddedartists | 22:1a58a518435c | 52 | |
embeddedartists | 26:a65fbb4bde5c | 53 | /* |
embeddedartists | 26:a65fbb4bde5c | 54 | * The BIOS is API compatible as long as the Major component of the |
embeddedartists | 26:a65fbb4bde5c | 55 | * version is the same. |
embeddedartists | 26:a65fbb4bde5c | 56 | */ |
embeddedartists | 26:a65fbb4bde5c | 57 | #define SUPPORTED_BIOS_VER 0x000000 |
embeddedartists | 26:a65fbb4bde5c | 58 | #define SUPPORTED_BIOS_MASK 0xff0000 // only look at the Major component |
embeddedartists | 26:a65fbb4bde5c | 59 | #define SUPPORTED_VERSION(__ver) (((__ver)&SUPPORTED_BIOS_MASK) == SUPPORTED_BIOS_VER) |
embeddedartists | 28:8ae20cb0b943 | 60 | |
embeddedartists | 34:fc366bab393f | 61 | //#define MAC_IN_SDK |
embeddedartists | 28:8ae20cb0b943 | 62 | |
embeddedartists | 22:1a58a518435c | 63 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 64 | * Local variables |
embeddedartists | 22:1a58a518435c | 65 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 66 | |
embeddedartists | 22:1a58a518435c | 67 | /****************************************************************************** |
embeddedartists | 28:8ae20cb0b943 | 68 | * Global functions |
embeddedartists | 28:8ae20cb0b943 | 69 | *****************************************************************************/ |
embeddedartists | 28:8ae20cb0b943 | 70 | |
embeddedartists | 28:8ae20cb0b943 | 71 | #if !defined(MAC_IN_SDK) |
embeddedartists | 28:8ae20cb0b943 | 72 | /* The LPC4088QSB platform in the MBED SDK have defined the WEAK function |
embeddedartists | 28:8ae20cb0b943 | 73 | * mbed_mac_address (ethernet_api.c) to read a unique MAC address from the |
embeddedartists | 28:8ae20cb0b943 | 74 | * onboard EEPROM. |
embeddedartists | 28:8ae20cb0b943 | 75 | * The LPC4088DM platform in the MBED SDK does not have the WEAK function |
embeddedartists | 28:8ae20cb0b943 | 76 | * so it is implemented here instead. This version of the function will ask |
embeddedartists | 28:8ae20cb0b943 | 77 | * the bios for a MAC address. |
embeddedartists | 28:8ae20cb0b943 | 78 | */ |
embeddedartists | 28:8ae20cb0b943 | 79 | void mbed_mac_address(char *mac) { |
embeddedartists | 28:8ae20cb0b943 | 80 | static char cache[6]; |
embeddedartists | 28:8ae20cb0b943 | 81 | static bool haveIt = false; |
embeddedartists | 28:8ae20cb0b943 | 82 | if (!haveIt) { |
embeddedartists | 28:8ae20cb0b943 | 83 | BiosLoader::instance().getMacAddress(cache); |
embeddedartists | 28:8ae20cb0b943 | 84 | haveIt = true; |
embeddedartists | 28:8ae20cb0b943 | 85 | } |
embeddedartists | 28:8ae20cb0b943 | 86 | memcpy(mac, cache, 6); |
embeddedartists | 28:8ae20cb0b943 | 87 | } |
embeddedartists | 28:8ae20cb0b943 | 88 | #endif |
embeddedartists | 28:8ae20cb0b943 | 89 | |
embeddedartists | 28:8ae20cb0b943 | 90 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 91 | * Private Functions |
embeddedartists | 22:1a58a518435c | 92 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 93 | |
embeddedartists | 28:8ae20cb0b943 | 94 | // Called by the NVIC |
embeddedartists | 28:8ae20cb0b943 | 95 | static void loader_i2c0_irq_handler() |
embeddedartists | 28:8ae20cb0b943 | 96 | { |
embeddedartists | 28:8ae20cb0b943 | 97 | BiosLoader::instance().handleI2CInterrupt(); |
embeddedartists | 28:8ae20cb0b943 | 98 | } |
embeddedartists | 28:8ae20cb0b943 | 99 | |
embeddedartists | 28:8ae20cb0b943 | 100 | |
embeddedartists | 22:1a58a518435c | 101 | // Function called from the BIOS |
embeddedartists | 22:1a58a518435c | 102 | static uint32_t readTimeMs() |
embeddedartists | 22:1a58a518435c | 103 | { |
embeddedartists | 22:1a58a518435c | 104 | return us_ticker_read()/1000; |
embeddedartists | 22:1a58a518435c | 105 | } |
embeddedartists | 22:1a58a518435c | 106 | |
embeddedartists | 22:1a58a518435c | 107 | |
embeddedartists | 22:1a58a518435c | 108 | BiosLoader::BiosLoader() : |
embeddedartists | 22:1a58a518435c | 109 | _initialized(false), |
embeddedartists | 22:1a58a518435c | 110 | _biosData(NULL), |
embeddedartists | 22:1a58a518435c | 111 | _conf(NULL), |
embeddedartists | 31:d47cffcb0a3e | 112 | _confSize(0), |
embeddedartists | 31:d47cffcb0a3e | 113 | _stats(0) |
embeddedartists | 22:1a58a518435c | 114 | { |
embeddedartists | 22:1a58a518435c | 115 | } |
embeddedartists | 22:1a58a518435c | 116 | |
embeddedartists | 22:1a58a518435c | 117 | BiosLoader::~BiosLoader() |
embeddedartists | 22:1a58a518435c | 118 | { |
embeddedartists | 22:1a58a518435c | 119 | if (_biosData != NULL) { |
embeddedartists | 22:1a58a518435c | 120 | free(_biosData); |
embeddedartists | 22:1a58a518435c | 121 | _biosData = NULL; |
embeddedartists | 22:1a58a518435c | 122 | } |
embeddedartists | 22:1a58a518435c | 123 | if (_conf != NULL) { |
embeddedartists | 22:1a58a518435c | 124 | free(_conf); |
embeddedartists | 22:1a58a518435c | 125 | _conf = NULL; |
embeddedartists | 22:1a58a518435c | 126 | _confSize = 0; |
embeddedartists | 22:1a58a518435c | 127 | } |
embeddedartists | 22:1a58a518435c | 128 | } |
embeddedartists | 22:1a58a518435c | 129 | |
embeddedartists | 22:1a58a518435c | 130 | DMBoard::BoardError BiosLoader::readBIOS(uint8_t** data, uint32_t* size) |
embeddedartists | 22:1a58a518435c | 131 | { |
embeddedartists | 22:1a58a518435c | 132 | DMBoard::BoardError err = DMBoard::Ok; |
embeddedartists | 22:1a58a518435c | 133 | BiosEEPROM eeprom; |
embeddedartists | 22:1a58a518435c | 134 | file_header_t fh; |
embeddedartists | 22:1a58a518435c | 135 | |
embeddedartists | 22:1a58a518435c | 136 | if (_conf != NULL) { |
embeddedartists | 22:1a58a518435c | 137 | *data = _conf; |
embeddedartists | 22:1a58a518435c | 138 | *size = _confSize; |
embeddedartists | 22:1a58a518435c | 139 | return DMBoard::Ok; |
embeddedartists | 22:1a58a518435c | 140 | } |
embeddedartists | 22:1a58a518435c | 141 | |
embeddedartists | 22:1a58a518435c | 142 | do { |
embeddedartists | 22:1a58a518435c | 143 | if (!eeprom.read(0, (char*)&fh, sizeof(file_header_t))) { |
embeddedartists | 22:1a58a518435c | 144 | resetI2C(); |
embeddedartists | 22:1a58a518435c | 145 | if (!eeprom.read(0, (char*)&fh, sizeof(file_header_t))) { |
embeddedartists | 22:1a58a518435c | 146 | err = DMBoard::BiosStorageError; |
embeddedartists | 22:1a58a518435c | 147 | break; |
embeddedartists | 22:1a58a518435c | 148 | } |
embeddedartists | 22:1a58a518435c | 149 | } |
embeddedartists | 22:1a58a518435c | 150 | |
embeddedartists | 22:1a58a518435c | 151 | if (fh.magic != BIOS_MAGIC) { |
embeddedartists | 22:1a58a518435c | 152 | err = DMBoard::BiosInvalidError; |
embeddedartists | 22:1a58a518435c | 153 | break; |
embeddedartists | 22:1a58a518435c | 154 | } |
embeddedartists | 22:1a58a518435c | 155 | |
embeddedartists | 26:a65fbb4bde5c | 156 | if (!SUPPORTED_VERSION(fh.version)) { |
embeddedartists | 22:1a58a518435c | 157 | err = DMBoard::BiosVersionError; |
embeddedartists | 22:1a58a518435c | 158 | break; |
embeddedartists | 22:1a58a518435c | 159 | } |
embeddedartists | 22:1a58a518435c | 160 | |
embeddedartists | 22:1a58a518435c | 161 | if ((fh.headerSize + fh.size) > BIOS_MAX_SIZE) { |
embeddedartists | 22:1a58a518435c | 162 | err = DMBoard::BiosInvalidError; |
embeddedartists | 22:1a58a518435c | 163 | break; |
embeddedartists | 22:1a58a518435c | 164 | } |
embeddedartists | 22:1a58a518435c | 165 | |
embeddedartists | 22:1a58a518435c | 166 | _confSize = fh.headerSize + fh.size; |
embeddedartists | 22:1a58a518435c | 167 | _conf = (uint8_t*)malloc(MAX(_confSize,BIOS_RESERVED_CHUNK)); |
embeddedartists | 22:1a58a518435c | 168 | if (_conf == NULL) { |
embeddedartists | 22:1a58a518435c | 169 | _confSize = 0; |
embeddedartists | 22:1a58a518435c | 170 | err = DMBoard::MemoryError; |
embeddedartists | 22:1a58a518435c | 171 | break; |
embeddedartists | 22:1a58a518435c | 172 | } |
embeddedartists | 22:1a58a518435c | 173 | |
embeddedartists | 22:1a58a518435c | 174 | if (!eeprom.read(0, (char*)_conf, _confSize)) { |
embeddedartists | 22:1a58a518435c | 175 | err = DMBoard::BiosStorageError; |
embeddedartists | 22:1a58a518435c | 176 | break; |
embeddedartists | 22:1a58a518435c | 177 | } |
embeddedartists | 22:1a58a518435c | 178 | |
embeddedartists | 22:1a58a518435c | 179 | uint32_t crc = crc_Buffer((uint32_t*)(&_conf[fh.headerSize]), fh.size/4); |
embeddedartists | 22:1a58a518435c | 180 | if (crc != fh.crc) { |
embeddedartists | 22:1a58a518435c | 181 | err = DMBoard::BiosInvalidError; |
embeddedartists | 22:1a58a518435c | 182 | break; |
embeddedartists | 22:1a58a518435c | 183 | } |
embeddedartists | 22:1a58a518435c | 184 | |
embeddedartists | 22:1a58a518435c | 185 | // Bios header has been verified and seems ok |
embeddedartists | 22:1a58a518435c | 186 | *data = _conf; |
embeddedartists | 22:1a58a518435c | 187 | *size = _confSize; |
embeddedartists | 31:d47cffcb0a3e | 188 | _stats = fh.version; |
embeddedartists | 22:1a58a518435c | 189 | err = DMBoard::Ok; |
embeddedartists | 22:1a58a518435c | 190 | } while (false); |
embeddedartists | 22:1a58a518435c | 191 | |
embeddedartists | 22:1a58a518435c | 192 | if (err != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 193 | if (_conf != NULL) { |
embeddedartists | 22:1a58a518435c | 194 | free(_conf); |
embeddedartists | 22:1a58a518435c | 195 | _conf = NULL; |
embeddedartists | 22:1a58a518435c | 196 | _confSize = 0; |
embeddedartists | 22:1a58a518435c | 197 | } |
embeddedartists | 22:1a58a518435c | 198 | } |
embeddedartists | 22:1a58a518435c | 199 | |
embeddedartists | 22:1a58a518435c | 200 | return err; |
embeddedartists | 22:1a58a518435c | 201 | } |
embeddedartists | 22:1a58a518435c | 202 | |
embeddedartists | 22:1a58a518435c | 203 | DMBoard::BoardError BiosLoader::params(bios_header_t** header, void** instanceData) |
embeddedartists | 22:1a58a518435c | 204 | { |
embeddedartists | 22:1a58a518435c | 205 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 206 | DMBoard::BoardError err = init(); |
embeddedartists | 22:1a58a518435c | 207 | if (err != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 208 | return err; |
embeddedartists | 22:1a58a518435c | 209 | } |
embeddedartists | 22:1a58a518435c | 210 | } |
embeddedartists | 22:1a58a518435c | 211 | if (_initialized) { |
embeddedartists | 22:1a58a518435c | 212 | *header = &_bios; |
embeddedartists | 22:1a58a518435c | 213 | *instanceData = _biosData; |
embeddedartists | 22:1a58a518435c | 214 | return DMBoard::Ok; |
embeddedartists | 22:1a58a518435c | 215 | } else { |
embeddedartists | 22:1a58a518435c | 216 | return DMBoard::BiosInvalidError; |
embeddedartists | 22:1a58a518435c | 217 | } |
embeddedartists | 22:1a58a518435c | 218 | } |
embeddedartists | 22:1a58a518435c | 219 | |
embeddedartists | 22:1a58a518435c | 220 | DMBoard::BoardError BiosLoader::init() |
embeddedartists | 22:1a58a518435c | 221 | { |
embeddedartists | 22:1a58a518435c | 222 | DMBoard::BoardError err = DMBoard::Ok; |
embeddedartists | 22:1a58a518435c | 223 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 224 | do { |
embeddedartists | 22:1a58a518435c | 225 | |
embeddedartists | 22:1a58a518435c | 226 | // Get the display bios from the DMBoard. DMBoard will have verified it |
embeddedartists | 22:1a58a518435c | 227 | // and will keep it in RAM so there is no need to copy it. |
embeddedartists | 22:1a58a518435c | 228 | uint8_t* p = NULL; |
embeddedartists | 22:1a58a518435c | 229 | uint32_t size = 0; |
embeddedartists | 22:1a58a518435c | 230 | err = readBIOS(&p, &size); |
embeddedartists | 29:b1ec19000e15 | 231 | if (err != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 232 | break; |
embeddedartists | 22:1a58a518435c | 233 | } |
embeddedartists | 22:1a58a518435c | 234 | |
embeddedartists | 28:8ae20cb0b943 | 235 | #if defined(MAC_IN_SDK) |
embeddedartists | 27:0499c29688cc | 236 | // The BIOS has been read so we know that the I2C bus is working. After the |
embeddedartists | 27:0499c29688cc | 237 | // BIOS is "started" it will take ownership of the bus and it can cause |
embeddedartists | 27:0499c29688cc | 238 | // problems for other peripherals on it. The only other peripheral today |
embeddedartists | 27:0499c29688cc | 239 | // is the EEPROM with the MAC address. It is read by mbed_mac_address() in |
embeddedartists | 27:0499c29688cc | 240 | // ethernet_api.c in the SDK and it will be cached. By reading it here now |
embeddedartists | 27:0499c29688cc | 241 | // we prevent future access to the I2C bus. |
embeddedartists | 27:0499c29688cc | 242 | char mac[6] = {0}; |
embeddedartists | 27:0499c29688cc | 243 | mbed_mac_address(mac); |
embeddedartists | 28:8ae20cb0b943 | 244 | #endif |
embeddedartists | 27:0499c29688cc | 245 | |
embeddedartists | 22:1a58a518435c | 246 | // Extract the function pointers so that they can be modified to match the |
embeddedartists | 22:1a58a518435c | 247 | // actual location of the code |
embeddedartists | 22:1a58a518435c | 248 | file_header_t* file_header = (file_header_t*)p; |
embeddedartists | 22:1a58a518435c | 249 | memcpy(&_bios, &file_header->header, sizeof(bios_header_t)); |
embeddedartists | 22:1a58a518435c | 250 | |
embeddedartists | 22:1a58a518435c | 251 | // Allocate memory for the BIOS instance data |
embeddedartists | 22:1a58a518435c | 252 | _biosData = malloc(file_header->paramSize); |
embeddedartists | 22:1a58a518435c | 253 | if (_biosData == NULL) { |
embeddedartists | 22:1a58a518435c | 254 | err = DMBoard::MemoryError; |
embeddedartists | 22:1a58a518435c | 255 | break; |
embeddedartists | 22:1a58a518435c | 256 | } |
embeddedartists | 22:1a58a518435c | 257 | |
embeddedartists | 22:1a58a518435c | 258 | // All offsets must be moved by two factors: |
embeddedartists | 22:1a58a518435c | 259 | // 1) The position of the code in RAM (location of "p") |
embeddedartists | 22:1a58a518435c | 260 | // 2) The header size (the code/data comes after it) |
embeddedartists | 22:1a58a518435c | 261 | uint32_t offset = ((uint32_t)p) + file_header->headerSize; |
embeddedartists | 22:1a58a518435c | 262 | uint32_t* functions = (uint32_t*)&_bios; |
embeddedartists | 29:b1ec19000e15 | 263 | for (uint32_t i = 0; i < (sizeof(bios_header_t)/sizeof(uint32_t)); i++) { |
embeddedartists | 22:1a58a518435c | 264 | functions[i] += offset; |
embeddedartists | 22:1a58a518435c | 265 | } |
embeddedartists | 22:1a58a518435c | 266 | |
embeddedartists | 22:1a58a518435c | 267 | #if defined(DM_BOARD_BIOS_DEVELOPMENT) |
embeddedartists | 22:1a58a518435c | 268 | // This requires that the project contains the source code for the BIOS |
embeddedartists | 24:9a677afc86f1 | 269 | const char* msg; |
embeddedartists | 26:a65fbb4bde5c | 270 | uint32_t tmp = 0; |
embeddedartists | 26:a65fbb4bde5c | 271 | bios_debug_aid(&_bios, &msg, &tmp); |
embeddedartists | 26:a65fbb4bde5c | 272 | if (tmp > file_header->paramSize) { |
embeddedartists | 26:a65fbb4bde5c | 273 | free(_biosData); |
embeddedartists | 26:a65fbb4bde5c | 274 | _biosData = malloc(tmp); |
embeddedartists | 26:a65fbb4bde5c | 275 | if (_biosData == NULL) { |
embeddedartists | 26:a65fbb4bde5c | 276 | err = DMBoard::MemoryError; |
embeddedartists | 26:a65fbb4bde5c | 277 | break; |
embeddedartists | 26:a65fbb4bde5c | 278 | } |
embeddedartists | 26:a65fbb4bde5c | 279 | } |
embeddedartists | 24:9a677afc86f1 | 280 | DMBoard::instance().logger()->printf("BIOS info: %s\n", msg); |
embeddedartists | 22:1a58a518435c | 281 | #endif |
embeddedartists | 22:1a58a518435c | 282 | |
embeddedartists | 22:1a58a518435c | 283 | // Prepare the BIOS instance data before calling the first function |
embeddedartists | 22:1a58a518435c | 284 | BiosError_t e = _bios.initParams(_biosData, SystemCoreClock, PeripheralClock, wait_us, readTimeMs); |
embeddedartists | 22:1a58a518435c | 285 | if (e != BiosError_Ok) { |
embeddedartists | 22:1a58a518435c | 286 | err = DMBoard::BiosInvalidError; |
embeddedartists | 22:1a58a518435c | 287 | break; |
embeddedartists | 22:1a58a518435c | 288 | } |
embeddedartists | 28:8ae20cb0b943 | 289 | |
embeddedartists | 28:8ae20cb0b943 | 290 | // Setup the mandatory I2C0 interrupt handler after initParams but before all other calls |
embeddedartists | 28:8ae20cb0b943 | 291 | NVIC_DisableIRQ(I2C0_IRQn); |
embeddedartists | 28:8ae20cb0b943 | 292 | NVIC_SetVector(I2C0_IRQn, (uint32_t)loader_i2c0_irq_handler); |
embeddedartists | 28:8ae20cb0b943 | 293 | NVIC_EnableIRQ(I2C0_IRQn); |
embeddedartists | 22:1a58a518435c | 294 | |
embeddedartists | 22:1a58a518435c | 295 | _initialized = true; |
embeddedartists | 22:1a58a518435c | 296 | } while(0); |
embeddedartists | 22:1a58a518435c | 297 | } |
embeddedartists | 22:1a58a518435c | 298 | return err; |
embeddedartists | 22:1a58a518435c | 299 | } |
embeddedartists | 22:1a58a518435c | 300 | |
embeddedartists | 22:1a58a518435c | 301 | void BiosLoader::resetI2C() |
embeddedartists | 22:1a58a518435c | 302 | { |
embeddedartists | 22:1a58a518435c | 303 | DMBoard::instance().logger()->printf("BiosLoader::resetI2C()\n"); |
embeddedartists | 22:1a58a518435c | 304 | DigitalOut reset(P0_23); |
embeddedartists | 22:1a58a518435c | 305 | reset = 0; |
embeddedartists | 22:1a58a518435c | 306 | wait_ms(1); |
embeddedartists | 22:1a58a518435c | 307 | reset = 1; |
embeddedartists | 22:1a58a518435c | 308 | wait_ms(10); |
embeddedartists | 22:1a58a518435c | 309 | } |
embeddedartists | 22:1a58a518435c | 310 | |
embeddedartists | 22:1a58a518435c | 311 | |
embeddedartists | 22:1a58a518435c | 312 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 313 | * Public Functions |
embeddedartists | 22:1a58a518435c | 314 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 315 | |
embeddedartists | 22:1a58a518435c | 316 | bool BiosLoader::isKnownSPIFIMemory(uint8_t mfgr, uint8_t devType, uint8_t devID, uint32_t memSize, uint32_t* eraseBlockSize) |
embeddedartists | 22:1a58a518435c | 317 | { |
embeddedartists | 22:1a58a518435c | 318 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 319 | DMBoard::BoardError err = init(); |
embeddedartists | 22:1a58a518435c | 320 | if (err != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 321 | return false; |
embeddedartists | 22:1a58a518435c | 322 | } |
embeddedartists | 22:1a58a518435c | 323 | } |
embeddedartists | 22:1a58a518435c | 324 | if (_initialized) { |
embeddedartists | 22:1a58a518435c | 325 | bool known = false; |
embeddedartists | 22:1a58a518435c | 326 | BiosError_t err = _bios.spifiIsSupported(_biosData, mfgr,devType,devID,memSize,&known,eraseBlockSize); |
embeddedartists | 22:1a58a518435c | 327 | if (err == BiosError_Ok) { |
embeddedartists | 22:1a58a518435c | 328 | return known; |
embeddedartists | 22:1a58a518435c | 329 | } |
embeddedartists | 22:1a58a518435c | 330 | } |
embeddedartists | 22:1a58a518435c | 331 | return false; |
embeddedartists | 22:1a58a518435c | 332 | } |
embeddedartists | 28:8ae20cb0b943 | 333 | |
embeddedartists | 28:8ae20cb0b943 | 334 | void BiosLoader::getMacAddress(char mac[6]) |
embeddedartists | 28:8ae20cb0b943 | 335 | { |
embeddedartists | 28:8ae20cb0b943 | 336 | if (!_initialized) { |
embeddedartists | 28:8ae20cb0b943 | 337 | init(); |
embeddedartists | 28:8ae20cb0b943 | 338 | } |
embeddedartists | 28:8ae20cb0b943 | 339 | if (_initialized) { |
embeddedartists | 28:8ae20cb0b943 | 340 | BiosError_t err = _bios.ethernetMac(_biosData, mac); |
embeddedartists | 28:8ae20cb0b943 | 341 | if (err == BiosError_Ok) { |
embeddedartists | 28:8ae20cb0b943 | 342 | return; |
embeddedartists | 28:8ae20cb0b943 | 343 | } |
embeddedartists | 28:8ae20cb0b943 | 344 | } |
embeddedartists | 28:8ae20cb0b943 | 345 | |
embeddedartists | 28:8ae20cb0b943 | 346 | // We always consider the MAC address to be retrieved even though |
embeddedartists | 28:8ae20cb0b943 | 347 | // reading is failed. If it wasn't possible to read then the default |
embeddedartists | 28:8ae20cb0b943 | 348 | // address will be used. |
embeddedartists | 28:8ae20cb0b943 | 349 | mac[0] = 0x00; |
embeddedartists | 28:8ae20cb0b943 | 350 | mac[1] = 0x02; |
embeddedartists | 28:8ae20cb0b943 | 351 | mac[2] = 0xF7; |
embeddedartists | 28:8ae20cb0b943 | 352 | mac[3] = 0xF0; |
embeddedartists | 28:8ae20cb0b943 | 353 | mac[4] = 0x00; |
embeddedartists | 28:8ae20cb0b943 | 354 | mac[5] = 0x01; |
embeddedartists | 28:8ae20cb0b943 | 355 | } |
embeddedartists | 28:8ae20cb0b943 | 356 | |
embeddedartists | 28:8ae20cb0b943 | 357 | void BiosLoader::handleI2CInterrupt() |
embeddedartists | 28:8ae20cb0b943 | 358 | { |
embeddedartists | 28:8ae20cb0b943 | 359 | _bios.i2cIRQHandler(_biosData); |
embeddedartists | 28:8ae20cb0b943 | 360 | } |
embeddedartists | 28:8ae20cb0b943 | 361 | |
embeddedartists | 31:d47cffcb0a3e | 362 | void BiosLoader::getBiosStats(uint8_t& type, uint8_t& major, uint8_t& minor, uint8_t& rev) |
embeddedartists | 31:d47cffcb0a3e | 363 | { |
embeddedartists | 31:d47cffcb0a3e | 364 | type = (_stats >> 24) & 0xff; |
embeddedartists | 31:d47cffcb0a3e | 365 | major = (_stats >> 16) & 0xff; |
embeddedartists | 31:d47cffcb0a3e | 366 | minor = (_stats >> 8) & 0xff; |
embeddedartists | 31:d47cffcb0a3e | 367 | rev = (_stats >> 0) & 0xff; |
embeddedartists | 31:d47cffcb0a3e | 368 | } |
embeddedartists | 31:d47cffcb0a3e | 369 |