matter_shell.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include "matter_shell.h"
  18. #include <ChipShellCollection.h>
  19. #include <FreeRTOS.h>
  20. #include <lib/core/CHIPCore.h>
  21. #include <lib/shell/Engine.h>
  22. #include <task.h>
  23. using namespace ::chip;
  24. using chip::Shell::Engine;
  25. namespace {
  26. #define SHELL_TASK_STACK_SIZE 2048
  27. #define SHELL_TASK_PRIORITY 5
  28. TaskHandle_t shellTaskHandle;
  29. StackType_t shellStack[SHELL_TASK_STACK_SIZE / sizeof(StackType_t)];
  30. StaticTask_t shellTaskStruct;
  31. void MatterShellTask(void * args)
  32. {
  33. chip::Shell::Engine::Root().RunMainLoop();
  34. }
  35. } // namespace
  36. extern "C" unsigned int sleep(unsigned int seconds)
  37. {
  38. const TickType_t xDelay = 1000 * seconds / portTICK_PERIOD_MS;
  39. vTaskDelay(xDelay);
  40. return 0;
  41. }
  42. namespace chip {
  43. void NotifyShellProcess()
  44. {
  45. xTaskNotifyGive(shellTaskHandle);
  46. }
  47. void NotifyShellProcessFromISR(void)
  48. {
  49. BaseType_t yieldRequired = pdFALSE;
  50. if (shellTaskHandle != NULL)
  51. {
  52. vTaskNotifyGiveFromISR(shellTaskHandle, &yieldRequired);
  53. }
  54. portYIELD_FROM_ISR(yieldRequired);
  55. }
  56. void WaitForShellActivity(void)
  57. {
  58. ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
  59. }
  60. void startShellTask(void)
  61. {
  62. int status = chip::Shell::Engine::Root().Init();
  63. assert(status == 0);
  64. // For now also register commands from shell_common (shell app).
  65. // TODO move at least OTCLI to default commands in lib/shell/commands
  66. cmd_misc_init();
  67. cmd_otcli_init();
  68. shellTaskHandle = xTaskCreateStatic(MatterShellTask, "matter_cli", ArraySize(shellStack), NULL, SHELL_TASK_PRIORITY, shellStack,
  69. &shellTaskStruct);
  70. }
  71. } // namespace chip