OSAL_SampleApp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**************************************************************************************************
  2. Filename: OSAL_SampleApp.c
  3. Revised: $Date: 2008-02-07 12:10:00 -0800 (Thu, 07 Feb 2008) $
  4. Revision: $Revision: 16360 $
  5. Description: This file contains all the settings and other functions
  6. that the user should set and change.
  7. Copyright 2007 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. **************************************************************************************************/
  34. /*********************************************************************
  35. * INCLUDES
  36. */
  37. #include "ZComDef.h"
  38. #include "hal_drivers.h"
  39. #include "OSAL.h"
  40. #include "OSAL_Tasks.h"
  41. #if defined ( MT_TASK )
  42. #include "MT.h"
  43. #include "MT_TASK.h"
  44. #endif
  45. #include "nwk.h"
  46. #include "APS.h"
  47. #include "ZDApp.h"
  48. #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  49. #include "ZDNwkMgr.h"
  50. #endif
  51. #if defined ( ZIGBEE_FRAGMENTATION )
  52. #include "aps_frag.h"
  53. #endif
  54. #include "SampleApp.h"
  55. /*********************************************************************
  56. * GLOBAL VARIABLES
  57. */
  58. // The order in this table must be identical to the task initialization calls below in osalInitTask.
  59. const pTaskEventHandlerFn tasksArr[] = {
  60. macEventLoop,
  61. nwk_event_loop,
  62. Hal_ProcessEvent,
  63. #if defined( MT_TASK )//如果定义串口任务
  64. MT_ProcessEvent,
  65. #endif
  66. APS_event_loop,
  67. #if defined ( ZIGBEE_FRAGMENTATION )
  68. APSF_ProcessEvent,
  69. #endif
  70. ZDApp_event_loop,
  71. #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  72. ZDNwkMgr_event_loop,
  73. #endif
  74. SD_App_ProcessEvent//应用层处理函数
  75. };
  76. const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] );
  77. uint16 *tasksEvents;
  78. /*********************************************************************
  79. * FUNCTIONS
  80. *********************************************************************/
  81. /*********************************************************************
  82. * @fn osalInitTasks
  83. *
  84. * @brief This function invokes the initialization function for each task.
  85. *
  86. * @param void
  87. *
  88. * @return none
  89. */
  90. void osalInitTasks( void )
  91. {
  92. uint8 taskID = 0;
  93. // 分配内存,返回指向缓冲区的指针
  94. tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
  95. // 设置所分配的内存空间单元值为0
  96. osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));
  97. // 任务优先级由高向低依次排列,高优先级对应taskID 的值反而小
  98. macTaskInit( taskID++ ); //macTaskInit(0) ,用户不需考虑
  99. nwk_init( taskID++ ); //nwk_init(1),用户不需考虑
  100. Hal_Init( taskID++ ); //Hal_Init(2) ,用户需考虑
  101. #if defined( MT_TASK )
  102. MT_TaskInit( taskID++ );
  103. #endif
  104. APS_Init( taskID++ ); //APS_Init(3) ,用户不需考虑
  105. #if defined ( ZIGBEE_FRAGMENTATION )
  106. APSF_Init( taskID++ );
  107. #endif
  108. ZDApp_Init( taskID++ ); //ZDApp_Init(4) ,用户需考虑
  109. #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )
  110. ZDNwkMgr_Init( taskID++ );
  111. #endif
  112. //用户创建的任务
  113. SD_App_Init( taskID ); // SampleApp_Init _Init(5) ,用户需考虑
  114. }
  115. /*********************************************************************
  116. *********************************************************************/