retarget.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* retarget.c
  2. *
  3. * Copyright (C) 2006-2017 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. #include "hw.h"
  22. #include "user_settings.h"
  23. #include <stdio.h>
  24. void __assert(const char *__expression, const char *__filename, int __line)
  25. {
  26. printf("Assert: %s, File %s (%d)\n", __expression, __filename, __line);
  27. }
  28. unsigned long ksdk_time(unsigned long* timer)
  29. {
  30. (void)timer;
  31. return hw_get_time_sec();
  32. }
  33. unsigned int LowResTimer(void)
  34. {
  35. return hw_get_time_sec();
  36. }
  37. double current_time(int reset)
  38. {
  39. double time;
  40. (void)reset;
  41. time = hw_get_time_sec();
  42. time += (double)hw_get_time_msec() / 1000;
  43. return time;
  44. }
  45. unsigned int custom_rand_generate(void)
  46. {
  47. return hw_rand();
  48. }
  49. int custom_rand_generate_block(unsigned char* output, unsigned int sz)
  50. {
  51. uint32_t i = 0;
  52. while (i < sz)
  53. {
  54. /* If not aligned or there is odd/remainder */
  55. if( (i + sizeof(CUSTOM_RAND_TYPE)) > sz ||
  56. ((uint32_t)&output[i] % sizeof(CUSTOM_RAND_TYPE)) != 0
  57. ) {
  58. /* Single byte at a time */
  59. output[i++] = (unsigned char)custom_rand_generate();
  60. }
  61. else {
  62. /* Use native 8, 16, 32 or 64 copy instruction */
  63. *((CUSTOM_RAND_TYPE*)&output[i]) = custom_rand_generate();
  64. i += sizeof(CUSTOM_RAND_TYPE);
  65. }
  66. }
  67. return 0;
  68. }
  69. // Debug print handler
  70. int __putchar(int c, __printf_tag_ptr ctx)
  71. {
  72. hw_uart_printchar(c);
  73. }
  74. extern unsigned char __stack_process_start__[];
  75. unsigned char * __aeabi_read_tp(void)
  76. {
  77. // thread-local storage addressing refers to the thread pointer
  78. // This is returning start address of stack process
  79. return (__stack_process_start__);
  80. }
  81. /* Stubs */
  82. void __heap_lock(void)
  83. {
  84. }
  85. void __heap_unlock(void)
  86. {
  87. }
  88. void __printf_lock(void)
  89. {
  90. }
  91. void __printf_unlock(void)
  92. {
  93. }
  94. void __scanf_lock(void)
  95. {
  96. }
  97. void __scanf_unlock(void)
  98. {
  99. }
  100. void __debug_io_lock(void)
  101. {
  102. }
  103. void __debug_io_unlock(void)
  104. {
  105. }