test

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nrf_assert.h Source File

nrf_assert.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) Nordic Semiconductor ASA
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  *   1. Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  *   2. Redistributions in binary form must reproduce the above copyright notice, this
00012  *   list of conditions and the following disclaimer in the documentation and/or
00013  *   other materials provided with the distribution.
00014  *
00015  *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
00016  *   contributors to this software may be used to endorse or promote products
00017  *   derived from this software without specific prior written permission.
00018  *
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00024  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  */
00032 
00033 /** @file
00034  * @brief Utilities for verifying program logic
00035  */
00036 
00037 #ifndef NRF_ASSERT_H_
00038 #define NRF_ASSERT_H_
00039 
00040 #include <stdint.h>
00041 #include "compiler_abstraction.h"
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
00047 
00048 /** @brief Function for handling assertions.
00049  *
00050  *
00051  * @note
00052  * This function is called when an assertion has triggered.
00053  *
00054  *
00055  * @post
00056  * All hardware is put into an idle non-emitting state (in particular the radio is highly
00057  * important to switch off since the radio might be in a state that makes it send
00058  * packets continiously while a typical final infinit ASSERT loop is executing).
00059  *
00060  *
00061  * @param line_num The line number where the assertion is called
00062  * @param file_name Pointer to the file name
00063  */
00064 void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
00065 
00066 /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 
00067 /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \
00068 
00069 /** @brief Function for checking intended for production code.
00070  *
00071  * Check passes if "expr" evaluates to true. */
00072 #define ASSERT(expr) \
00073 if (expr)                                                                     \
00074 {                                                                             \
00075 }                                                                             \
00076 else                                                                          \
00077 {                                                                             \
00078   assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__);               \
00079 }
00080 #else
00081 #define ASSERT(expr) //!< Assert empty when disabled
00082 __WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
00083 #endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */
00084 
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088 
00089 #endif /* NRF_ASSERT_H_ */