T398: Source cleanup for tool chain integration

This is a code cleanup to improve portability.

Specific issues addressed:
- Added type casts to (void *) here and there
- Changed non-standard \e escapes to \033
- Added cmake function to handle preinclude
- Changed a few Image$$ references to make use of the REGION_DECLARE
  macro
- Reordered code slightly to avoid the need for a "void *rangeptr"
  variable
- Changed compile time check typedef "err_msg" to avoid declaring
  zero sized array, which is not standards compliant. It will now
  either be -1 (error) or 1 (ok), not -1 and 0
- Reordered the *nfsptr_t typedef to make the cmse_nonsecure_call
  standards compliant
- Added null tests to both secure and non_secure suites to avoid
  defining zero length array. Also use this to find end of list
- Only define __stdout for ARMCLANG builds and conditionalize ns printf
  output for ARMCLANG/GCC/IAR
- Cleaned up some enum type mismatches
- Changed non standard EINVAL error return to -1. The value was only
  checked against 0 anyway
- Added type cast for conversion from float to int

Have tested with IAR, which starts and runs the idle thread. Changes
related to this is not included in this commit.

       Author: Thomas Tornblom <thomas.tornblom@iar.com>
       Signed-off-by: Thomas Tornblom <thomas.tornblom@iar.com>

       Note: Sign off authority needs to adhere to the [DCO](./dco.txt)
       rules.

Change-Id: I3e5229c0777623b128474af0311020ccacc1b797
diff --git a/BuildMbedtls.cmake b/BuildMbedtls.cmake
index afb5307..3856248 100644
--- a/BuildMbedtls.cmake
+++ b/BuildMbedtls.cmake
@@ -43,7 +43,8 @@
 if((NOT DEFINED MBEDTLS_PREINCLUDE_PREFIX) OR (NOT DEFINED MBEDTLS_PREINCLUDE_HEADER))
 	message(STATUS "Building mbedTLS without pre-included headers and global symbols prefixing.")
 else()
-	set(MBEDTLS_PREINCLUDE_C_FLAGS " -DLIB_PREFIX_NAME=${MBEDTLS_PREINCLUDE_PREFIX} -include ${MBEDTLS_PREINCLUDE_HEADER}")
+        compiler_get_preinclude_option_string(${MBEDTLS_PREINCLUDE_HEADER} _PRE_INC_STRING)
+	set(MBEDTLS_PREINCLUDE_C_FLAGS " -DLIB_PREFIX_NAME=${MBEDTLS_PREINCLUDE_PREFIX} ${_PRE_INC_STRING}")
 	string(APPEND MBEDTLS_C_FLAGS ${MBEDTLS_PREINCLUDE_C_FLAGS})
 endif()