Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /*
switches 0:5c4d7b2438d3 2 * Platform abstraction layer
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
switches 0:5c4d7b2438d3 5 * SPDX-License-Identifier: Apache-2.0
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
switches 0:5c4d7b2438d3 8 * not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 9 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
switches 0:5c4d7b2438d3 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 16 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 17 * limitations under the License.
switches 0:5c4d7b2438d3 18 *
switches 0:5c4d7b2438d3 19 * This file is part of mbed TLS (https://tls.mbed.org)
switches 0:5c4d7b2438d3 20 */
switches 0:5c4d7b2438d3 21
switches 0:5c4d7b2438d3 22 #if !defined(MBEDTLS_CONFIG_FILE)
switches 0:5c4d7b2438d3 23 #include "mbedtls/config.h"
switches 0:5c4d7b2438d3 24 #else
switches 0:5c4d7b2438d3 25 #include MBEDTLS_CONFIG_FILE
switches 0:5c4d7b2438d3 26 #endif
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 #if defined(MBEDTLS_PLATFORM_C)
switches 0:5c4d7b2438d3 29
switches 0:5c4d7b2438d3 30 #include "mbedtls/platform.h"
switches 0:5c4d7b2438d3 31
switches 0:5c4d7b2438d3 32 #if defined(MBEDTLS_PLATFORM_MEMORY)
switches 0:5c4d7b2438d3 33 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
switches 0:5c4d7b2438d3 34 static void *platform_calloc_uninit( size_t n, size_t size )
switches 0:5c4d7b2438d3 35 {
switches 0:5c4d7b2438d3 36 ((void) n);
switches 0:5c4d7b2438d3 37 ((void) size);
switches 0:5c4d7b2438d3 38 return( NULL );
switches 0:5c4d7b2438d3 39 }
switches 0:5c4d7b2438d3 40
switches 0:5c4d7b2438d3 41 #define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
switches 0:5c4d7b2438d3 42 #endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
switches 0:5c4d7b2438d3 43
switches 0:5c4d7b2438d3 44 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
switches 0:5c4d7b2438d3 45 static void platform_free_uninit( void *ptr )
switches 0:5c4d7b2438d3 46 {
switches 0:5c4d7b2438d3 47 ((void) ptr);
switches 0:5c4d7b2438d3 48 }
switches 0:5c4d7b2438d3 49
switches 0:5c4d7b2438d3 50 #define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
switches 0:5c4d7b2438d3 51 #endif /* !MBEDTLS_PLATFORM_STD_FREE */
switches 0:5c4d7b2438d3 52
switches 0:5c4d7b2438d3 53 void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
switches 0:5c4d7b2438d3 54 void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
switches 0:5c4d7b2438d3 55
switches 0:5c4d7b2438d3 56 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
switches 0:5c4d7b2438d3 57 void (*free_func)( void * ) )
switches 0:5c4d7b2438d3 58 {
switches 0:5c4d7b2438d3 59 mbedtls_calloc = calloc_func;
switches 0:5c4d7b2438d3 60 mbedtls_free = free_func;
switches 0:5c4d7b2438d3 61 return( 0 );
switches 0:5c4d7b2438d3 62 }
switches 0:5c4d7b2438d3 63 #endif /* MBEDTLS_PLATFORM_MEMORY */
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 #if defined(_WIN32)
switches 0:5c4d7b2438d3 66 #include <stdarg.h>
switches 0:5c4d7b2438d3 67 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
switches 0:5c4d7b2438d3 68 {
switches 0:5c4d7b2438d3 69 int ret;
switches 0:5c4d7b2438d3 70 va_list argp;
switches 0:5c4d7b2438d3 71
switches 0:5c4d7b2438d3 72 /* Avoid calling the invalid parameter handler by checking ourselves */
switches 0:5c4d7b2438d3 73 if( s == NULL || n == 0 || fmt == NULL )
switches 0:5c4d7b2438d3 74 return( -1 );
switches 0:5c4d7b2438d3 75
switches 0:5c4d7b2438d3 76 va_start( argp, fmt );
switches 0:5c4d7b2438d3 77 #if defined(_TRUNCATE)
switches 0:5c4d7b2438d3 78 ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
switches 0:5c4d7b2438d3 79 #else
switches 0:5c4d7b2438d3 80 ret = _vsnprintf( s, n, fmt, argp );
switches 0:5c4d7b2438d3 81 if( ret < 0 || (size_t) ret == n )
switches 0:5c4d7b2438d3 82 {
switches 0:5c4d7b2438d3 83 s[n-1] = '\0';
switches 0:5c4d7b2438d3 84 ret = -1;
switches 0:5c4d7b2438d3 85 }
switches 0:5c4d7b2438d3 86 #endif
switches 0:5c4d7b2438d3 87 va_end( argp );
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 return( ret );
switches 0:5c4d7b2438d3 90 }
switches 0:5c4d7b2438d3 91 #endif
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
switches 0:5c4d7b2438d3 94 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
switches 0:5c4d7b2438d3 95 /*
switches 0:5c4d7b2438d3 96 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 97 */
switches 0:5c4d7b2438d3 98 static int platform_snprintf_uninit( char * s, size_t n,
switches 0:5c4d7b2438d3 99 const char * format, ... )
switches 0:5c4d7b2438d3 100 {
switches 0:5c4d7b2438d3 101 ((void) s);
switches 0:5c4d7b2438d3 102 ((void) n);
switches 0:5c4d7b2438d3 103 ((void) format);
switches 0:5c4d7b2438d3 104 return( 0 );
switches 0:5c4d7b2438d3 105 }
switches 0:5c4d7b2438d3 106
switches 0:5c4d7b2438d3 107 #define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
switches 0:5c4d7b2438d3 108 #endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 int (*mbedtls_snprintf)( char * s, size_t n,
switches 0:5c4d7b2438d3 111 const char * format,
switches 0:5c4d7b2438d3 112 ... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
switches 0:5c4d7b2438d3 113
switches 0:5c4d7b2438d3 114 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
switches 0:5c4d7b2438d3 115 const char * format,
switches 0:5c4d7b2438d3 116 ... ) )
switches 0:5c4d7b2438d3 117 {
switches 0:5c4d7b2438d3 118 mbedtls_snprintf = snprintf_func;
switches 0:5c4d7b2438d3 119 return( 0 );
switches 0:5c4d7b2438d3 120 }
switches 0:5c4d7b2438d3 121 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
switches 0:5c4d7b2438d3 122
switches 0:5c4d7b2438d3 123 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
switches 0:5c4d7b2438d3 124 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
switches 0:5c4d7b2438d3 125 /*
switches 0:5c4d7b2438d3 126 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 127 */
switches 0:5c4d7b2438d3 128 static int platform_printf_uninit( const char *format, ... )
switches 0:5c4d7b2438d3 129 {
switches 0:5c4d7b2438d3 130 ((void) format);
switches 0:5c4d7b2438d3 131 return( 0 );
switches 0:5c4d7b2438d3 132 }
switches 0:5c4d7b2438d3 133
switches 0:5c4d7b2438d3 134 #define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
switches 0:5c4d7b2438d3 135 #endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
switches 0:5c4d7b2438d3 136
switches 0:5c4d7b2438d3 137 int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
switches 0:5c4d7b2438d3 138
switches 0:5c4d7b2438d3 139 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
switches 0:5c4d7b2438d3 140 {
switches 0:5c4d7b2438d3 141 mbedtls_printf = printf_func;
switches 0:5c4d7b2438d3 142 return( 0 );
switches 0:5c4d7b2438d3 143 }
switches 0:5c4d7b2438d3 144 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
switches 0:5c4d7b2438d3 145
switches 0:5c4d7b2438d3 146 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
switches 0:5c4d7b2438d3 147 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
switches 0:5c4d7b2438d3 148 /*
switches 0:5c4d7b2438d3 149 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 150 */
switches 0:5c4d7b2438d3 151 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
switches 0:5c4d7b2438d3 152 {
switches 0:5c4d7b2438d3 153 ((void) stream);
switches 0:5c4d7b2438d3 154 ((void) format);
switches 0:5c4d7b2438d3 155 return( 0 );
switches 0:5c4d7b2438d3 156 }
switches 0:5c4d7b2438d3 157
switches 0:5c4d7b2438d3 158 #define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
switches 0:5c4d7b2438d3 159 #endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
switches 0:5c4d7b2438d3 160
switches 0:5c4d7b2438d3 161 int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
switches 0:5c4d7b2438d3 162 MBEDTLS_PLATFORM_STD_FPRINTF;
switches 0:5c4d7b2438d3 163
switches 0:5c4d7b2438d3 164 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
switches 0:5c4d7b2438d3 165 {
switches 0:5c4d7b2438d3 166 mbedtls_fprintf = fprintf_func;
switches 0:5c4d7b2438d3 167 return( 0 );
switches 0:5c4d7b2438d3 168 }
switches 0:5c4d7b2438d3 169 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
switches 0:5c4d7b2438d3 170
switches 0:5c4d7b2438d3 171 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
switches 0:5c4d7b2438d3 172 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
switches 0:5c4d7b2438d3 173 /*
switches 0:5c4d7b2438d3 174 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 175 */
switches 0:5c4d7b2438d3 176 static void platform_exit_uninit( int status )
switches 0:5c4d7b2438d3 177 {
switches 0:5c4d7b2438d3 178 ((void) status);
switches 0:5c4d7b2438d3 179 }
switches 0:5c4d7b2438d3 180
switches 0:5c4d7b2438d3 181 #define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
switches 0:5c4d7b2438d3 182 #endif /* !MBEDTLS_PLATFORM_STD_EXIT */
switches 0:5c4d7b2438d3 183
switches 0:5c4d7b2438d3 184 void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
switches 0:5c4d7b2438d3 185
switches 0:5c4d7b2438d3 186 int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
switches 0:5c4d7b2438d3 187 {
switches 0:5c4d7b2438d3 188 mbedtls_exit = exit_func;
switches 0:5c4d7b2438d3 189 return( 0 );
switches 0:5c4d7b2438d3 190 }
switches 0:5c4d7b2438d3 191 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
switches 0:5c4d7b2438d3 192
switches 0:5c4d7b2438d3 193 #if defined(MBEDTLS_HAVE_TIME)
switches 0:5c4d7b2438d3 194
switches 0:5c4d7b2438d3 195 #if defined(MBEDTLS_PLATFORM_TIME_ALT)
switches 0:5c4d7b2438d3 196 #if !defined(MBEDTLS_PLATFORM_STD_TIME)
switches 0:5c4d7b2438d3 197 /*
switches 0:5c4d7b2438d3 198 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 199 */
switches 0:5c4d7b2438d3 200 static mbedtls_time_t platform_time_uninit( mbedtls_time_t* timer )
switches 0:5c4d7b2438d3 201 {
switches 0:5c4d7b2438d3 202 ((void) timer);
switches 0:5c4d7b2438d3 203 return( 0 );
switches 0:5c4d7b2438d3 204 }
switches 0:5c4d7b2438d3 205
switches 0:5c4d7b2438d3 206 #define MBEDTLS_PLATFORM_STD_TIME platform_time_uninit
switches 0:5c4d7b2438d3 207 #endif /* !MBEDTLS_PLATFORM_STD_TIME */
switches 0:5c4d7b2438d3 208
switches 0:5c4d7b2438d3 209 mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* timer ) = MBEDTLS_PLATFORM_STD_TIME;
switches 0:5c4d7b2438d3 210
switches 0:5c4d7b2438d3 211 int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* timer ) )
switches 0:5c4d7b2438d3 212 {
switches 0:5c4d7b2438d3 213 mbedtls_time = time_func;
switches 0:5c4d7b2438d3 214 return( 0 );
switches 0:5c4d7b2438d3 215 }
switches 0:5c4d7b2438d3 216 #endif /* MBEDTLS_PLATFORM_TIME_ALT */
switches 0:5c4d7b2438d3 217
switches 0:5c4d7b2438d3 218 #endif /* MBEDTLS_HAVE_TIME */
switches 0:5c4d7b2438d3 219
switches 0:5c4d7b2438d3 220 #if defined(MBEDTLS_ENTROPY_NV_SEED)
switches 0:5c4d7b2438d3 221 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
switches 0:5c4d7b2438d3 222 /* Default implementations for the platform independent seed functions use
switches 0:5c4d7b2438d3 223 * standard libc file functions to read from and write to a pre-defined filename
switches 0:5c4d7b2438d3 224 */
switches 0:5c4d7b2438d3 225 int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len )
switches 0:5c4d7b2438d3 226 {
switches 0:5c4d7b2438d3 227 FILE *file;
switches 0:5c4d7b2438d3 228 size_t n;
switches 0:5c4d7b2438d3 229
switches 0:5c4d7b2438d3 230 if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL )
switches 0:5c4d7b2438d3 231 return -1;
switches 0:5c4d7b2438d3 232
switches 0:5c4d7b2438d3 233 if( ( n = fread( buf, 1, buf_len, file ) ) != buf_len )
switches 0:5c4d7b2438d3 234 {
switches 0:5c4d7b2438d3 235 fclose( file );
switches 0:5c4d7b2438d3 236 return -1;
switches 0:5c4d7b2438d3 237 }
switches 0:5c4d7b2438d3 238
switches 0:5c4d7b2438d3 239 fclose( file );
switches 0:5c4d7b2438d3 240 return( n );
switches 0:5c4d7b2438d3 241 }
switches 0:5c4d7b2438d3 242
switches 0:5c4d7b2438d3 243 int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
switches 0:5c4d7b2438d3 244 {
switches 0:5c4d7b2438d3 245 FILE *file;
switches 0:5c4d7b2438d3 246 size_t n;
switches 0:5c4d7b2438d3 247
switches 0:5c4d7b2438d3 248 if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL )
switches 0:5c4d7b2438d3 249 return -1;
switches 0:5c4d7b2438d3 250
switches 0:5c4d7b2438d3 251 if( ( n = fwrite( buf, 1, buf_len, file ) ) != buf_len )
switches 0:5c4d7b2438d3 252 {
switches 0:5c4d7b2438d3 253 fclose( file );
switches 0:5c4d7b2438d3 254 return -1;
switches 0:5c4d7b2438d3 255 }
switches 0:5c4d7b2438d3 256
switches 0:5c4d7b2438d3 257 fclose( file );
switches 0:5c4d7b2438d3 258 return( n );
switches 0:5c4d7b2438d3 259 }
switches 0:5c4d7b2438d3 260 #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
switches 0:5c4d7b2438d3 261
switches 0:5c4d7b2438d3 262 #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
switches 0:5c4d7b2438d3 263 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
switches 0:5c4d7b2438d3 264 /*
switches 0:5c4d7b2438d3 265 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 266 */
switches 0:5c4d7b2438d3 267 static int platform_nv_seed_read_uninit( unsigned char *buf, size_t buf_len )
switches 0:5c4d7b2438d3 268 {
switches 0:5c4d7b2438d3 269 ((void) buf);
switches 0:5c4d7b2438d3 270 ((void) buf_len);
switches 0:5c4d7b2438d3 271 return( -1 );
switches 0:5c4d7b2438d3 272 }
switches 0:5c4d7b2438d3 273
switches 0:5c4d7b2438d3 274 #define MBEDTLS_PLATFORM_STD_NV_SEED_READ platform_nv_seed_read_uninit
switches 0:5c4d7b2438d3 275 #endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_READ */
switches 0:5c4d7b2438d3 276
switches 0:5c4d7b2438d3 277 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
switches 0:5c4d7b2438d3 278 /*
switches 0:5c4d7b2438d3 279 * Make dummy function to prevent NULL pointer dereferences
switches 0:5c4d7b2438d3 280 */
switches 0:5c4d7b2438d3 281 static int platform_nv_seed_write_uninit( unsigned char *buf, size_t buf_len )
switches 0:5c4d7b2438d3 282 {
switches 0:5c4d7b2438d3 283 ((void) buf);
switches 0:5c4d7b2438d3 284 ((void) buf_len);
switches 0:5c4d7b2438d3 285 return( -1 );
switches 0:5c4d7b2438d3 286 }
switches 0:5c4d7b2438d3 287
switches 0:5c4d7b2438d3 288 #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE platform_nv_seed_write_uninit
switches 0:5c4d7b2438d3 289 #endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_WRITE */
switches 0:5c4d7b2438d3 290
switches 0:5c4d7b2438d3 291 int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
switches 0:5c4d7b2438d3 292 MBEDTLS_PLATFORM_STD_NV_SEED_READ;
switches 0:5c4d7b2438d3 293 int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
switches 0:5c4d7b2438d3 294 MBEDTLS_PLATFORM_STD_NV_SEED_WRITE;
switches 0:5c4d7b2438d3 295
switches 0:5c4d7b2438d3 296 int mbedtls_platform_set_nv_seed(
switches 0:5c4d7b2438d3 297 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
switches 0:5c4d7b2438d3 298 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len ) )
switches 0:5c4d7b2438d3 299 {
switches 0:5c4d7b2438d3 300 mbedtls_nv_seed_read = nv_seed_read_func;
switches 0:5c4d7b2438d3 301 mbedtls_nv_seed_write = nv_seed_write_func;
switches 0:5c4d7b2438d3 302 return( 0 );
switches 0:5c4d7b2438d3 303 }
switches 0:5c4d7b2438d3 304 #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
switches 0:5c4d7b2438d3 305 #endif /* MBEDTLS_ENTROPY_NV_SEED */
switches 0:5c4d7b2438d3 306
switches 0:5c4d7b2438d3 307 #endif /* MBEDTLS_PLATFORM_C */