main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. /* FreeRTOS kernel includes. */
  8. #include "FreeRTOS.h"
  9. #include "task.h"
  10. /* HPM example includes. */
  11. #include <stdio.h>
  12. #include "board.h"
  13. #include "hpm_clock_drv.h"
  14. #include "hpm_uart_drv.h"
  15. #include "shell.h"
  16. #include "hpm_gptmr_drv.h"
  17. #include "cia402_def.h"
  18. #include "ec_master.h"
  19. #ifdef CONFIG_EC_EOE
  20. #include "lwip/tcpip.h"
  21. #endif
  22. SDK_DECLARE_EXT_ISR_M(BOARD_CONSOLE_UART_IRQ, shell_uart_isr)
  23. #define task_start_PRIORITY (configMAX_PRIORITIES - 2U)
  24. ATTR_PLACE_AT_FAST_RAM_BSS ec_master_t g_ec_master;
  25. #ifdef CONFIG_EC_EOE
  26. ATTR_PLACE_AT_FAST_RAM_BSS ec_eoe_t g_ec_eoe;
  27. #endif
  28. static void task_start(void *param);
  29. int main(void)
  30. {
  31. board_init();
  32. if (pdPASS != xTaskCreate(task_start, "task_start", 1024U, NULL, task_start_PRIORITY, NULL)) {
  33. printf("Task start creation failed!\r\n");
  34. while (1) {
  35. };
  36. }
  37. #ifdef CONFIG_EC_EOE
  38. /* Initialize the LwIP stack */
  39. tcpip_init(NULL, NULL);
  40. #endif
  41. vTaskStartScheduler();
  42. printf("Unexpected scheduler exit!\r\n");
  43. while (1) {
  44. };
  45. return 0;
  46. }
  47. static void task_start(void *param)
  48. {
  49. (void)param;
  50. printf("Try to initialize the uart\r\n"
  51. " if you are using the console uart as the shell uart\r\n"
  52. " failure to initialize may result in no log\r\n");
  53. uart_config_t shell_uart_config = { 0 };
  54. uart_default_config(BOARD_CONSOLE_UART_BASE, &shell_uart_config);
  55. shell_uart_config.src_freq_in_hz = clock_get_frequency(BOARD_CONSOLE_UART_CLK_NAME);
  56. shell_uart_config.baudrate = 115200;
  57. if (status_success != uart_init(BOARD_CONSOLE_UART_BASE, &shell_uart_config)) {
  58. /* uart failed to be initialized */
  59. printf("Failed to initialize uart\r\n");
  60. while (1) {
  61. };
  62. }
  63. printf("Initialize shell uart successfully\r\n");
  64. /* default password is : 12345678 */
  65. /* shell_init() must be called in-task */
  66. if (0 != shell_init(BOARD_CONSOLE_UART_BASE, false)) {
  67. /* shell failed to be initialized */
  68. printf("Failed to initialize shell\r\n");
  69. while (1) {
  70. };
  71. }
  72. printf("Initialize shell successfully\r\n");
  73. /* irq must be enabled after shell_init() */
  74. uart_enable_irq(BOARD_CONSOLE_UART_BASE, uart_intr_rx_data_avail_or_timeout);
  75. intc_m_enable_irq_with_priority(BOARD_CONSOLE_UART_IRQ, 1);
  76. printf("Enable shell uart interrupt\r\n");
  77. ec_master_cmd_init(&g_ec_master);
  78. #ifdef CONFIG_EC_EOE
  79. ec_master_cmd_eoe_init(&g_ec_eoe);
  80. #endif
  81. ec_master_init(&g_ec_master, 0);
  82. printf("Exit start task\r\n");
  83. vTaskDelete(NULL);
  84. }
  85. CSH_CMD_EXPORT(ethercat, );
  86. unsigned char cherryecat_eepromdata[2048]; // EEPROM data buffer, please generate by esi_parse.py
  87. void ec_pdo_callback(ec_slave_t *slave, uint8_t *output, uint8_t *input)
  88. {
  89. }
  90. #ifdef CONFIG_EC_EOE
  91. #include "tcp_client.h"
  92. int tcp_client(int argc, const char **argv)
  93. {
  94. tcp_client_init(&g_ec_eoe.netif);
  95. return 0;
  96. }
  97. CSH_CMD_EXPORT(tcp_client, );
  98. #endif