Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers error.c Source File

error.c

Go to the documentation of this file.
00001 /**
00002  * @file    error.c
00003  * @brief   Implementation of error.h
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include "error.h"
00023 #include "util.h"
00024 #include "compiler.h"
00025 
00026 static const char *const error_message[] = {
00027 
00028     /* Shared errors */
00029 
00030     // ERROR_SUCCESS
00031     "Operation was successful",
00032     // ERROR_FAILURE
00033     "An error has occurred",
00034     // ERROR_INTERNAL
00035     "An internal error has occurred",
00036 
00037     /* VFS user errors */
00038 
00039     // ERROR_ERROR_DURING_TRANSFER
00040     "An error occurred during the transfer",
00041     // ERROR_TRANSFER_TIMEOUT
00042     "The transfer timed out.",
00043     // ERROR_FILE_BOUNDS
00044     "Possible mismatch between file size and size programmed",
00045     // ERROR_OOO_SECTOR
00046     "File sent out of order by PC. Target might not be programmed correctly.",
00047 
00048     /* Target flash errors */
00049 
00050     // ERROR_RESET
00051     "The interface firmware FAILED to reset/halt the target MCU",
00052     // ERROR_ALGO_DL
00053     "The interface firmware FAILED to download the flash programming algorithms to the target MCU",
00054     //ERROR_ALGO_MISSING
00055     "The flash algo missing for a region",
00056     // ERROR_ALGO_DATA_SEQ
00057     "The interface firmware FAILED to download the flash data contents to be programmed",
00058     // ERROR_INIT
00059     "The interface firmware FAILED to initialize the target MCU",
00060     // ERROR_UNINIT
00061     "The interface firmware FAILED to uninitialize the target MCU",
00062     // ERROR_SECURITY_BITS
00063     "The interface firmware ABORTED programming. Image is trying to set security bits",
00064     // ERROR_UNLOCK
00065     "The interface firmware FAILED to unlock the target for programming",
00066     // ERROR_ERASE_SECTOR
00067     "Flash algorithm erase sector command FAILURE",
00068     // ERROR_ERASE_ALL
00069     "Flash algorithm erase all command FAILURE",
00070     // ERROR_WRITE
00071     "Flash algorithm write command FAILURE",
00072     // ERROR_WRITE_VERIFY
00073     "Flash algorithm write verify command FAILURE",
00074 
00075     /* File stream errors */
00076 
00077     // ERROR_SUCCESS_DONE
00078     "End of stream has been reached",
00079     // ERROR_SUCCESS_DONE_OR_CONTINUE
00080     "End of stream is unknown",
00081     // ERROR_HEX_CKSUM
00082     "The hex file cannot be decoded. Checksum calculation failure occurred.",
00083     // ERROR_HEX_PARSER
00084     "The hex file cannot be decoded. Parser logic failure occurred.",
00085     // ERROR_HEX_PROGRAM
00086     "The hex file cannot be programmed. Logic failure occurred.",
00087     // ERROR_HEX_INVALID_ADDRESS
00088     "The hex file you dropped isn't compatible with this mode or device. Are you in MAINTENANCE mode? See HELP FAQ.HTM",
00089     // ERROR_HEX_INVALID_APP_OFFSET
00090     "The hex file offset load address is not correct.",
00091 
00092     /* Flash decoder errors */
00093 
00094     // ERROR_FD_BL_UPDT_ADDR_WRONG
00095     "The starting address for the bootloader update is wrong.",
00096     // ERROR_FD_INTF_UPDT_ADDR_WRONG
00097     "The starting address for the interface update is wrong.",
00098     // ERROR_FD_UNSUPPORTED_UPDATE
00099     "The application file format is unknown and cannot be parsed and/or processed.",
00100 
00101     /* Flash IAP interface */
00102 
00103     // ERROR_IAP_INIT
00104     "In application programming initialization failed.",
00105     // ERROR_IAP_UNINIT
00106     "In application programming uninit failed.",
00107     // ERROR_IAP_WRITE
00108     "In application programming write failed.",
00109     // ERROR_IAP_ERASE_SECTOR
00110     "In application programming sector erase failed.",
00111     // ERROR_IAP_ERASE_ALL
00112     "In application programming mass erase failed.",
00113     // ERROR_IAP_OUT_OF_BOUNDS
00114     "In application programming aborted due to an out of bounds address.",
00115     // ERROR_IAP_UPDT_NOT_SUPPORTED
00116     "In application programming not supported on this device.",
00117     // ERROR_IAP_UPDT_INCOMPLETE
00118     "In application programming failed because the update sent was incomplete.",
00119     // ERROR_IAP_NO_INTERCEPT
00120     "",
00121     // ERROR_BL_UPDT_BAD_CRC
00122     "The bootloader CRC did not pass.",
00123 
00124 };
00125 
00126 static error_type_t error_type[] = {
00127 
00128     /* These should always stay the same for each error type. */
00129 
00130     // ERROR_SUCCESS
00131     0,
00132     // ERROR_FAILURE
00133     ERROR_TYPE_INTERNAL,
00134     // ERROR_INTERNAL
00135     ERROR_TYPE_INTERNAL,
00136 
00137     /* VFS user errors */
00138 
00139     // ERROR_ERROR_DURING_TRANSFER
00140     ERROR_TYPE_TRANSIENT,
00141     // ERROR_TRANSFER_TIMEOUT
00142     ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
00143     // ERROR_FILE_BOUNDS
00144     ERROR_TYPE_TRANSIENT,
00145     // ERROR_OOO_SECTOR
00146     ERROR_TYPE_TRANSIENT,
00147 
00148     /* Target flash errors */
00149 
00150     // ERROR_RESET
00151     ERROR_TYPE_TARGET,
00152     // ERROR_ALGO_DL
00153     ERROR_TYPE_TARGET,
00154     //ERROR_ALGO_MISSING
00155     ERROR_TYPE_TARGET,
00156     // ERROR_ALGO_DATA_SEQ
00157     ERROR_TYPE_TARGET,
00158     // ERROR_INIT
00159     ERROR_TYPE_TARGET,
00160     // ERROR_UNINIT
00161     ERROR_TYPE_TARGET,
00162     // ERROR_SECURITY_BITS
00163     ERROR_TYPE_USER,
00164     // ERROR_UNLOCK
00165     ERROR_TYPE_TARGET,
00166     // ERROR_ERASE_SECTOR
00167     ERROR_TYPE_TARGET,
00168     // ERROR_ERASE_ALL
00169     ERROR_TYPE_TARGET,
00170     // ERROR_WRITE
00171     ERROR_TYPE_TARGET,
00172     // ERROR_WRITE_VERIFY
00173     ERROR_TYPE_TARGET,
00174 
00175     /* File stream errors */
00176 
00177     // ERROR_SUCCESS_DONE
00178     ERROR_TYPE_INTERNAL,
00179     // ERROR_SUCCESS_DONE_OR_CONTINUE
00180     ERROR_TYPE_INTERNAL,
00181     // ERROR_HEX_CKSUM
00182     ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
00183     // ERROR_HEX_PARSER
00184     ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
00185     // ERROR_HEX_PROGRAM
00186     ERROR_TYPE_USER | ERROR_TYPE_TRANSIENT,
00187     // ERROR_HEX_INVALID_ADDRESS
00188     ERROR_TYPE_USER,
00189     // ERROR_HEX_INVALID_APP_OFFSET
00190     ERROR_TYPE_USER,
00191 
00192     /* Flash decoder errors */
00193 
00194     // ERROR_FD_BL_UPDT_ADDR_WRONG
00195     ERROR_TYPE_USER,
00196     // ERROR_FD_INTF_UPDT_ADDR_WRONG
00197     ERROR_TYPE_USER,
00198     // ERROR_FD_UNSUPPORTED_UPDATE
00199     ERROR_TYPE_USER,
00200 
00201     /* Flash IAP interface */
00202 
00203     // ERROR_IAP_INIT
00204     ERROR_TYPE_INTERFACE,
00205     // ERROR_IAP_UNINIT
00206     ERROR_TYPE_INTERFACE,
00207     // ERROR_IAP_WRITE
00208     ERROR_TYPE_INTERFACE,
00209     // ERROR_IAP_ERASE_SECTOR
00210     ERROR_TYPE_INTERFACE,
00211     // ERROR_IAP_ERASE_ALL
00212     ERROR_TYPE_INTERFACE,
00213     // ERROR_IAP_OUT_OF_BOUNDS
00214     ERROR_TYPE_INTERFACE,
00215     // ERROR_IAP_UPDT_NOT_SUPPORTED
00216     ERROR_TYPE_INTERFACE,
00217     // ERROR_IAP_UPDT_INCOMPLETE
00218     ERROR_TYPE_INTERFACE,
00219     // ERROR_IAP_NO_INTERCEPT
00220     ERROR_TYPE_INTERFACE,
00221     // ERROR_BL_UPDT_BAD_CRC
00222     ERROR_TYPE_INTERFACE,
00223 };
00224 
00225 COMPILER_ASSERT(ERROR_COUNT == ARRAY_SIZE(error_message));
00226 
00227 const char *error_get_string(error_t error)
00228 {
00229     const char *msg = 0;
00230 
00231     if (error < ERROR_COUNT) {
00232         msg = error_message[error];
00233     }
00234 
00235     if (0 == msg) {
00236         util_assert(0);
00237         msg = "";
00238     }
00239 
00240     return msg;
00241 }
00242 
00243 error_type_t error_get_type(error_t error)
00244 {
00245     error_type_t type = ERROR_TYPE_INTERNAL;
00246 
00247     if (error < ERROR_COUNT) {
00248         type = error_type[error];
00249     }
00250 
00251     return type;
00252 }