1 /* retarget.c
2  *
3  * Copyright (C) 2006-2021 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * wolfSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20  */
21 
22 
23 #include "hw.h"
24 #include "user_settings.h"
25 #include <stdio.h>
26 
__assert(const char * __expression,const char * __filename,int __line)27 void __assert(const char *__expression, const char *__filename, int __line)
28 {
29     printf("Assert: %s, File %s (%d)\n", __expression, __filename, __line);
30 }
31 
ksdk_time(unsigned long * timer)32 unsigned long ksdk_time(unsigned long* timer)
33 {
34     (void)timer;
35     return hw_get_time_sec();
36 }
37 
LowResTimer(void)38 unsigned int LowResTimer(void)
39 {
40     return hw_get_time_sec();
41 }
42 
current_time(int reset)43 double current_time(int reset)
44 {
45     double time;
46     (void)reset;
47     time = hw_get_time_sec();
48     time += (double)hw_get_time_msec() / 1000;
49     return time;
50 }
51 
custom_rand_generate(void)52 unsigned int custom_rand_generate(void)
53 {
54     return hw_rand();
55 }
56 
custom_rand_generate_block(unsigned char * output,unsigned int sz)57 int custom_rand_generate_block(unsigned char* output, unsigned int sz)
58 {
59     uint32_t i = 0;
60 
61     while (i < sz)
62     {
63         /* If not aligned or there is odd/remainder */
64         if( (i + sizeof(CUSTOM_RAND_TYPE)) > sz ||
65             ((uint32_t)&output[i] % sizeof(CUSTOM_RAND_TYPE)) != 0
66         ) {
67             /* Single byte at a time */
68             output[i++] = (unsigned char)custom_rand_generate();
69         }
70         else {
71             /* Use native 8, 16, 32 or 64 copy instruction */
72             *((CUSTOM_RAND_TYPE*)&output[i]) = custom_rand_generate();
73             i += sizeof(CUSTOM_RAND_TYPE);
74         }
75     }
76 
77     return 0;
78 }
79 
80 // Debug print handler
__putchar(int c,__printf_tag_ptr ctx)81 int __putchar(int c, __printf_tag_ptr ctx)
82 {
83     hw_uart_printchar(c);
84 }
85 
86 extern unsigned char __stack_process_start__[];
__aeabi_read_tp(void)87 unsigned char * __aeabi_read_tp(void)
88 {
89     // thread-local storage addressing refers to the thread pointer
90     // This is returning start address of stack process
91     return (__stack_process_start__);
92 }
93 
94 /* Stubs */
__heap_lock(void)95 void __heap_lock(void)
96 {
97 }
98 
__heap_unlock(void)99 void __heap_unlock(void)
100 {
101 }
102 
__printf_lock(void)103 void __printf_lock(void)
104 {
105 }
106 
__printf_unlock(void)107 void __printf_unlock(void)
108 {
109 }
110 
__scanf_lock(void)111 void __scanf_lock(void)
112 {
113 }
114 
__scanf_unlock(void)115 void __scanf_unlock(void)
116 {
117 }
118 
__debug_io_lock(void)119 void __debug_io_lock(void)
120 {
121 }
122 
__debug_io_unlock(void)123 void __debug_io_unlock(void)
124 {
125 }
126