cpuport.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. 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)0x10003; /* Start address */
  39. stk--;
  40. *stk = (rt_uint32_t)tentry; /* Start address */
  41. stk -= 22;
  42. *stk = (rt_uint32_t)parameter; /* Register a0 parameter*/
  43. stk -= 6;
  44. *stk = (rt_uint32_t)tp; /* Register thread pointer */
  45. stk --;
  46. *stk = (rt_uint32_t)texit; /* Register ra texit*/
  47. /* return task's current stack address */
  48. return (rt_uint8_t *)stk;
  49. }
  50. /** shutdown CPU */
  51. void rt_hw_cpu_shutdown(void)
  52. {
  53. rt_uint32_t level;
  54. rt_kprintf("shutdown...\n");
  55. level = rt_hw_interrupt_disable();
  56. while (level)
  57. {
  58. RT_ASSERT(0);
  59. }
  60. }