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/app/main_ns.c b/app/main_ns.c
index 0205b1b..c648dfe 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -57,6 +57,7 @@
  */
 };
 
+#if defined(__ARMCC_VERSION)
 /* Struct FILE is implemented in stdio.h. Used to redirect printf to
  * NS_DRIVER_STDIO
  */
@@ -68,6 +69,7 @@
     /* Return character written */
     return ch;
 }
+#elif defined(__GNUC__)
 /* redirects gcc printf to NS_DRIVER_STDIO */
 int _write(int fd, char * str, int len)
 {
@@ -75,6 +77,15 @@
 
     return len;
 }
+#elif defined(__ICCARM__)
+int putchar(int ch)
+{
+    /* Send byte to NS_DRIVER_STDIO */
+    (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
+    /* Return character written */
+    return ch;
+}
+#endif
 
 /**
  * \brief List of RTOS thread attributes