application.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2014-07-13 xiaonong port for lpc43xx
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #include <rtdevice.h>
  13. #include "drv_led.h"
  14. #ifdef RT_USING_FINSH
  15. #include <finsh.h>
  16. #include <shell.h>
  17. #endif
  18. static const unsigned char _M0_CODE[] rt_section("M0_CODE") = {
  19. // #include "M0_CODE.h"
  20. };
  21. static void _boot_M0(void)
  22. {
  23. volatile uint32_t u32REG, u32Val;
  24. LPC_CREG->M0APPMEMMAP = (uint32_t)&_M0_CODE[0];
  25. // Release Slave from reset, first read status
  26. u32REG = LPC_RGU->RESET_ACTIVE_STATUS1;
  27. // If the M0 is being held in reset, release it...
  28. // 1 = no reset, 0 = reset
  29. while(!(u32REG & (1u << 24)))
  30. {
  31. u32Val = (~(u32REG) & (~(1 << 24)));
  32. LPC_RGU->RESET_CTRL1 = u32Val;
  33. u32REG = LPC_RGU->RESET_ACTIVE_STATUS1;
  34. }
  35. rt_kprintf("M0 boot to %p\n", &_M0_CODE[0]);
  36. }
  37. /* thread phase init */
  38. void rt_init_thread_entry(void *parameter)
  39. {
  40. /*
  41. *register unsigned int _msp __asm("msp");
  42. *register unsigned int _psp __asm("psp");
  43. *rt_kprintf("msp@ %p, psp@ %p\n", _msp, _psp);
  44. */
  45. #ifdef RT_USING_FINSH
  46. /* initialize finsh */
  47. finsh_system_init();
  48. #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
  49. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  50. #endif
  51. #endif
  52. _boot_M0();
  53. }
  54. /*the led thread*/
  55. rt_align(RT_ALIGN_SIZE)
  56. static rt_uint8_t led_stack[ 512 ];
  57. static struct rt_thread led_thread;
  58. static void led_thread_entry(void *parameter)
  59. {
  60. rt_uint8_t led_value;
  61. rt_device_t led_dev;
  62. rt_led_hw_init();
  63. led_dev = rt_device_find("led");
  64. if (led_dev == RT_NULL)
  65. {
  66. rt_kprintf("can not find the led device\n");
  67. return;
  68. }
  69. led_value = 0;
  70. while (1)
  71. {
  72. led_dev->write(led_dev, 0, &led_value, sizeof(led_value));
  73. led_value = !led_value;
  74. rt_thread_delay(1000);
  75. }
  76. }
  77. int rt_application_init(void)
  78. {
  79. rt_thread_t tid;
  80. rt_err_t result;
  81. tid = rt_thread_create("init",
  82. rt_init_thread_entry, RT_NULL,
  83. 2048, 3, 20);
  84. if (tid != RT_NULL)
  85. rt_thread_startup(tid);
  86. /* init led thread */
  87. result = rt_thread_init(&led_thread, "led",
  88. led_thread_entry, RT_NULL,
  89. (rt_uint8_t *)&led_stack[0], sizeof(led_stack),
  90. 20, 5);
  91. if (result == RT_EOK)
  92. {
  93. rt_thread_startup(&led_thread);
  94. }
  95. return 0;
  96. }