cpuport.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020/11/18 greedyhao Bluetrum RISC-V porting code.
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. volatile rt_ubase_t rt_interrupt_from_thread = 0;
  13. volatile rt_ubase_t rt_interrupt_to_thread = 0;
  14. volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0;
  15. volatile rt_uint32_t rt_switch_flag = 0;
  16. rt_uint32_t rt_cur_thread_sp = 0;
  17. /**
  18. * This function will initialize thread stack
  19. *
  20. * @param tentry the entry of thread
  21. * @param parameter the parameter of entry
  22. * @param stack_addr the beginning stack address
  23. * @param texit the function will be called when thread exit
  24. *
  25. * @return stack address
  26. */
  27. rt_uint8_t *rt_hw_stack_init(void *tentry,
  28. void *parameter,
  29. rt_uint8_t *stack_addr,
  30. void *texit)
  31. {
  32. rt_uint32_t *stk;
  33. register int *tp asm("x3");
  34. stack_addr += sizeof(rt_uint32_t);
  35. stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
  36. stk = (rt_uint32_t *)stack_addr;
  37. stk--;
  38. *stk = (rt_uint32_t)tentry; /* Start address */
  39. stk -= 22;
  40. *stk = (rt_uint32_t)parameter; /* Register a0 parameter*/
  41. stk -= 6;
  42. *stk = (rt_uint32_t)tp; /* Register thread pointer */
  43. stk --;
  44. *stk = (rt_uint32_t)texit; /* Register ra texit*/
  45. /* return task's current stack address */
  46. return (rt_uint8_t *)stk;
  47. }
  48. /** shutdown CPU */
  49. void rt_hw_cpu_shutdown(void)
  50. {
  51. rt_uint32_t level;
  52. rt_kprintf("shutdown...\n");
  53. level = rt_hw_interrupt_disable();
  54. while (level)
  55. {
  56. RT_ASSERT(0);
  57. }
  58. }