cmux_sample_gsm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-15 xiangxistu the first version
  9. */
  10. #include <cmux.h>
  11. #include <rtthread.h>
  12. #define CMUX_PPP_NAME "cmux_ppp"
  13. #define CMUX_PPP_PORT 1
  14. #define CMUX_AT_NAME "cmux_at"
  15. #define CMUX_AT_PORT 2
  16. #define DBG_TAG "cmux.sample"
  17. #ifdef CMUX_DEBUG
  18. #define DBG_LVL DBG_LOG
  19. #else
  20. #define DBG_LVL DBG_INFO
  21. #endif
  22. #include <rtdbg.h>
  23. struct cmux *sample = RT_NULL;
  24. int cmux_sample(void)
  25. {
  26. rt_err_t result;
  27. /* find cmux object through the actual serial name < the actual serial has been related in the cmux.c file > */
  28. sample = cmux_object_find(CMUX_DEPEND_NAME);
  29. if (sample == RT_NULL)
  30. {
  31. result = -RT_ERROR;
  32. LOG_E("Can't find %s", CMUX_DEPEND_NAME);
  33. goto end;
  34. }
  35. /* startup the cmux receive thread, attach control chananel and open it */
  36. result = cmux_start(sample);
  37. if (result != RT_EOK)
  38. {
  39. LOG_E("cmux sample start error. Can't find %s", CMUX_DEPEND_NAME);
  40. goto end;
  41. }
  42. LOG_I("cmux sample (%s) start successful.", CMUX_DEPEND_NAME);
  43. /* attach AT function into cmux */
  44. result = cmux_attach(sample, CMUX_AT_PORT, CMUX_AT_NAME, RT_DEVICE_FLAG_DMA_RX, RT_NULL);
  45. if (result != RT_EOK)
  46. {
  47. LOG_E("cmux attach (%s) failed.", CMUX_AT_NAME);
  48. goto end;
  49. }
  50. LOG_I("cmux object channel (%s) attach successful.", CMUX_AT_NAME);
  51. /* attach PPP function into cmux */
  52. result = cmux_attach(sample, CMUX_PPP_PORT, CMUX_PPP_NAME, RT_DEVICE_FLAG_DMA_RX, RT_NULL);
  53. if (result != RT_EOK)
  54. {
  55. LOG_E("cmux attach %s failed.", CMUX_PPP_NAME);
  56. goto end;
  57. }
  58. LOG_I("cmux object channel (%s) attach successful.", CMUX_PPP_NAME);
  59. end:
  60. return RT_EOK;
  61. }
  62. #ifdef CMUX_ATUO_INITIZATION
  63. INIT_APP_EXPORT(cmux_sample);
  64. #endif
  65. MSH_CMD_EXPORT_ALIAS(cmux_sample, cmux_start, a sample of cmux function);