cpuport.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2020-2020, Bluetrum 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. rt_uint32_t rt_cur_thread_sp = 0;
  16. /**
  17. * This function will initialize thread stack
  18. *
  19. * @param tentry the entry of thread
  20. * @param parameter the parameter of entry
  21. * @param stack_addr the beginning stack address
  22. * @param texit the function will be called when thread exit
  23. *
  24. * @return stack address
  25. */
  26. rt_uint8_t *rt_hw_stack_init(void *tentry,
  27. void *parameter,
  28. rt_uint8_t *stack_addr,
  29. void *texit)
  30. {
  31. rt_uint32_t *stk;
  32. register int *tp asm("x3");
  33. stack_addr += sizeof(rt_uint32_t);
  34. stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
  35. stk = (rt_uint32_t *)stack_addr;
  36. stk--;
  37. *stk = (rt_uint32_t)0x10003; /* Start address */
  38. stk--;
  39. *stk = (rt_uint32_t)tentry; /* Start address */
  40. stk -= 22;
  41. *stk = (rt_uint32_t)parameter; /* Register a0 parameter*/
  42. stk -= 6;
  43. *stk = (rt_uint32_t)tp; /* Register thread pointer */
  44. stk --;
  45. *stk = (rt_uint32_t)texit; /* Register ra texit*/
  46. /* return task's current stack address */
  47. return (rt_uint8_t *)stk;
  48. }
  49. /** shutdown CPU */
  50. void rt_hw_cpu_shutdown(void)
  51. {
  52. rt_uint32_t level;
  53. rt_kprintf("shutdown...\n");
  54. level = rt_hw_interrupt_disable();
  55. while (level)
  56. {
  57. RT_ASSERT(0);
  58. }
  59. }