arch.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-26 19:11:34
  5. * @LastEditTime: 2020-06-17 16:25:18
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #include "salof_defconfig.h"
  9. #ifdef SALOF_USING_LOG
  10. void *salof_alloc(unsigned int size)
  11. {
  12. return rt_malloc(size);
  13. }
  14. void salof_free(void *mem)
  15. {
  16. rt_free(mem);
  17. }
  18. salof_tcb salof_task_create(const char *name,
  19. void (*task_entry)(void *param),
  20. void * const param,
  21. unsigned int stack_size,
  22. unsigned int priority,
  23. unsigned int tick)
  24. {
  25. salof_tcb task;
  26. task = rt_thread_create((const char *)name,
  27. task_entry,
  28. param,
  29. stack_size,
  30. priority,
  31. tick);
  32. rt_thread_startup(task);
  33. return task;
  34. }
  35. salof_mutex salof_mutex_create(void)
  36. {
  37. return rt_mutex_create("salof_mutex", RT_IPC_FLAG_PRIO);
  38. }
  39. void salof_mutex_delete(salof_mutex mutex)
  40. {
  41. rt_mutex_delete(mutex);
  42. }
  43. int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
  44. {
  45. if(rt_mutex_take((salof_mutex)mutex, timeout) != RT_EOK)
  46. return -1;
  47. return 0;
  48. }
  49. int salof_mutex_post(salof_mutex mutex)
  50. {
  51. if(rt_mutex_release((salof_mutex)mutex) != RT_EOK)
  52. return -1;
  53. return 0;
  54. }
  55. salof_sem salof_sem_create(void)
  56. {
  57. return rt_sem_create("salof_sem", 0, RT_IPC_FLAG_PRIO);
  58. }
  59. void salof_sem_delete(salof_sem sem)
  60. {
  61. rt_sem_delete((salof_sem)sem);
  62. }
  63. int salof_sem_pend(salof_sem sem, unsigned int timeout)
  64. {
  65. if(rt_sem_take((salof_sem)sem, timeout) != RT_EOK)
  66. return -1;
  67. return 0;
  68. }
  69. int salof_sem_post(salof_sem sem)
  70. {
  71. if(rt_sem_release((salof_sem)sem) != RT_EOK)
  72. return -1;
  73. return 0;
  74. }
  75. unsigned int salof_get_tick(void)
  76. {
  77. return rt_tick_get();
  78. }
  79. char *salof_get_task_name(void)
  80. {
  81. return NULL;
  82. }
  83. static rt_device_t new_device = RT_NULL;
  84. int send_buff(char *buf, int len)
  85. {
  86. /* find new console device */
  87. if (new_device == RT_NULL)
  88. {
  89. new_device = rt_device_find(RT_CONSOLE_DEVICE_NAME);
  90. // rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
  91. }
  92. #ifdef RT_USING_DEVICE
  93. if (new_device == RT_NULL)
  94. {
  95. rt_hw_console_output(buf);
  96. }
  97. else
  98. {
  99. rt_uint16_t old_flag = new_device->open_flag;
  100. new_device->open_flag |= RT_DEVICE_FLAG_STREAM;
  101. rt_device_write(new_device, 0, buf, rt_strlen(buf));
  102. new_device->open_flag = old_flag;
  103. }
  104. #else
  105. rt_hw_console_output(buf);
  106. #endif
  107. return len;
  108. }
  109. #endif