📄 genericapp.s51
字号:
// 8
// 9 This application isn't intended to do anything useful,
// 10 it is intended to be a simple example of an application's
// 11 structure.
// 12
// 13 This application sends "Hello World" to another "Generic"
// 14 application every 15 seconds. The application will also
// 15 receive "Hello World" packets.
// 16
// 17 The "Hello World" messages are sent/received as MSG type
// 18 message.
// 19
// 20 This applications doesn't have a profile, so it handles
// 21 everything directly - itself.
// 22
// 23 Key control:
// 24 SW1:
// 25 SW2: initiates end device binding
// 26 SW3:
// 27 SW4: initiates a match description request
// 28
// 29 Notes:
// 30
// 31 Copyright (c) 2006 by Texas Instruments, Inc.
// 32 All Rights Reserved. Permission to use, reproduce, copy, prepare
// 33 derivative works, modify, distribute, perform, display or sell this
// 34 software and/or its documentation for any purpose is prohibited
// 35 without the express written consent of Texas Instruments, Inc.
// 36 *********************************************************************/
// 37
// 38 /*********************************************************************
// 39 * INCLUDES
// 40 */
// 41 #include "OSAL.h"
// 42 #include "AF.h"
// 43 #include "ZDApp.h"
// 44
// 45 #include "GenericApp.h"
// 46 #include "DebugTrace.h"
// 47
// 48 #if !defined( WIN32 )
// 49 #include "OnBoard.h"
// 50 #endif
// 51
// 52 /* HAL */
// 53 #include "hal_lcd.h"
// 54 #include "hal_led.h"
// 55 #include "hal_key.h"
// 56 #include "hal_uart.h"
// 57
// 58 /*********************************************************************
// 59 * MACROS
// 60 */
// 61
// 62 /*********************************************************************
// 63 * CONSTANTS
// 64 */
// 65
// 66 /*********************************************************************
// 67 * TYPEDEFS
// 68 */
// 69
// 70 /*********************************************************************
// 71 * GLOBAL VARIABLES
// 72 */
// 73
// 74 // This list should be filled with Application specific Cluster IDs.
RSEG XDATA_I:XDATA:NOROOT(0)
// 75 const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
GenericApp_ClusterList:
DS 2
REQUIRE `?<Initializer for GenericApp_ClusterList>`
REQUIRE __INIT_XDATA_I
// 76 {
// 77 GENERICAPP_CLUSTERID
// 78 };
// 79
RSEG XDATA_I:XDATA:NOROOT(0)
// 80 const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
GenericApp_SimpleDesc:
DS 12
REQUIRE `?<Initializer for GenericApp_SimpleDesc>`
REQUIRE __INIT_XDATA_I
// 81 {
// 82 GENERICAPP_ENDPOINT, // int Endpoint;
// 83 GENERICAPP_PROFID, // uint16 AppProfId[2];
// 84 GENERICAPP_DEVICEID, // uint16 AppDeviceId[2];
// 85 GENERICAPP_DEVICE_VERSION, // int AppDevVer:4;
// 86 GENERICAPP_FLAGS, // int AppFlags:4;
// 87 GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
// 88 (cId_t *)GenericApp_ClusterList, // byte *pAppInClusterList;
// 89 GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
// 90 (cId_t *)GenericApp_ClusterList // byte *pAppInClusterList;
// 91 };
// 92
// 93 // This is the Endpoint/Interface description. It is defined here, but
// 94 // filled-in in GenericApp_Init(). Another way to go would be to fill
// 95 // in the structure here and make it a "const" (in code space). The
// 96 // way it's defined in this sample app it is define in RAM.
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 97 endPointDesc_t GenericApp_epDesc;
GenericApp_epDesc:
DS 6
// 98
// 99 /*********************************************************************
// 100 * EXTERNAL VARIABLES
// 101 */
// 102
// 103 /*********************************************************************
// 104 * EXTERNAL FUNCTIONS
// 105 */
// 106
// 107 /*********************************************************************
// 108 * LOCAL VARIABLES
// 109 */
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 110 byte GenericApp_TaskID; // Task ID for internal task/event processing
GenericApp_TaskID:
DS 1
// 111 // This variable will be received when
// 112 // GenericApp_Init() is called.
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 113 devStates_t GenericApp_NwkState;
GenericApp_NwkState:
DS 1
// 114
// 115
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 116 byte GenericApp_TransID; // This is the unique message ID (counter)
GenericApp_TransID:
DS 1
// 117
RSEG XDATA_Z:XDATA:NOROOT(0)
REQUIRE __INIT_XDATA_Z
// 118 afAddrType_t GenericApp_DstAddr;
GenericApp_DstAddr:
DS 4
// 119
// 120 /*********************************************************************
// 121 * LOCAL FUNCTIONS
// 122 */
// 123 void GenericApp_HandleKeys( byte shift, byte keys );
// 124 void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
// 125 void GenericApp_SendTheMessage( void );
// 126
// 127 /*********************************************************************
// 128 * NETWORK LAYER CALLBACKS
// 129 */
// 130
// 131 /*********************************************************************
// 132 * PUBLIC FUNCTIONS
// 133 */
// 134
// 135 /*********************************************************************
// 136 * @fn GenericApp_Init
// 137 *
// 138 * @brief Initialization function for the Generic App Task.
// 139 * This is called during initialization and should contain
// 140 * any application specific initialization (ie. hardware
// 141 * initialization/setup, table initialization, power up
// 142 * notificaiton ... ).
// 143 *
// 144 * @param task_id - the ID assigned by OSAL. This ID should be
// 145 * used to send messages and set timers.
// 146 *
// 147 * @return none
// 148 */
RSEG BANKED_CODE:CODE:NOROOT(0)
// 149 void GenericApp_Init( byte task_id )
GenericApp_Init:
CFI Block cfiBlock0 Using cfiCommon0
CFI Function GenericApp_Init
// 150 {
FUNCALL GenericApp_Init, afRegister
LOCFRAME ISTACK, 2, STACK
ARGFRAME ISTACK, 2, STACK
FUNCALL GenericApp_Init, RegisterForKeys
LOCFRAME ISTACK, 2, STACK
ARGFRAME ISTACK, 2, STACK
PUSH DPL
CFI DPL0 Frame(CFA_SP, 4)
CFI CFA_SP SP+-4
PUSH DPH
CFI DPH0 Frame(CFA_SP, 5)
CFI CFA_SP SP+-5
; Saved register size: 2
; Auto size: 0
// 151 GenericApp_TaskID = task_id;
MOV A,R1
MOV DPTR,#GenericApp_TaskID
MOVX @DPTR,A
// 152 GenericApp_NwkState = DEV_INIT;
MOV A,#0x1
MOV DPTR,#GenericApp_NwkState
MOVX @DPTR,A
// 153 GenericApp_TransID = 0;
CLR A
MOV DPTR,#GenericApp_TransID
MOVX @DPTR,A
// 154
// 155 // Device hardware initialization can be added here or in main() (Zmain.c).
// 156 // If the hardware is application specific - add it here.
// 157 // If the hardware is other parts of the device add it in main().
// 158
// 159 GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
MOV DPTR,#(GenericApp_DstAddr + 2)
MOVX @DPTR,A
// 160 GenericApp_DstAddr.endPoint = 0;
MOV DPTR,#(GenericApp_DstAddr + 3)
MOVX @DPTR,A
// 161 GenericApp_DstAddr.addr.shortAddr = 0;
MOV DPTR,#GenericApp_DstAddr
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
// 162
// 163 // Fill out the endpoint description.
// 164 GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
MOV A,#0xa
MOV DPTR,#GenericApp_epDesc
MOVX @DPTR,A
// 165 GenericApp_epDesc.task_id = &GenericApp_TaskID;
MOV DPTR,#(GenericApp_epDesc + 1)
MOV A,#(GenericApp_TaskID & 0xff)
MOVX @DPTR,A
INC DPTR
MOV A,#((GenericApp_TaskID >> 8) & 0xff)
MOVX @DPTR,A
// 166 GenericApp_epDesc.simpleDesc
// 167 = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
MOV DPTR,#(GenericApp_epDesc + 3)
MOV A,#(GenericApp_SimpleDesc & 0xff)
MOVX @DPTR,A
INC DPTR
MOV A,#((GenericApp_SimpleDesc >> 8) & 0xff)
MOVX @DPTR,A
// 168 GenericApp_epDesc.latencyReq = noLatencyReqs;
CLR A
MOV DPTR,#(GenericApp_epDesc + 5)
MOVX @DPTR,A
// 169
// 170 // Register the endpoint description with the AF
// 171 afRegister( &GenericApp_epDesc );
; Setup parameters for call to function afRegister
MOV R2,#(GenericApp_epDesc & 0xff)
MOV R3,#((GenericApp_epDesc >> 8) & 0xff)
MOV DPTR,#(afRegister & 0xffff)
MOV A,#((afRegister >> 16) & 0xff)
LCALL ?BCALL ; Banked call to: DPTR()
// 172
// 173 // Register for all key events - This app will handle all key events
// 174 RegisterForKeys( GenericApp_TaskID );
; Setup parameters for call to function RegisterForKeys
MOV DPTR,#GenericApp_TaskID
MOVX A,@DPTR
MOV R1,A
MOV DPTR,#(RegisterForKeys & 0xffff)
MOV A,#((RegisterForKeys >> 16) & 0xff)
LCALL ?BCALL ; Banked call to: DPTR()
// 175
// 176 // Update the display
// 177 #if defined ( LCD_SUPPORTED )
// 178 HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
// 179 #endif
// 180 }
POP DPH
CFI DPH0 SameValue
CFI CFA_SP SP+-4
POP DPL
CFI DPL0 SameValue
CFI CFA_SP SP+-3
LJMP ?BRET
CFI EndBlock cfiBlock0
// 181
// 182 /*********************************************************************
// 183 * @fn GenericApp_ProcessEvent
// 184 *
// 185 * @brief Generic Application Task event processor. This function
// 186 * is called to process all events for the task. Events
// 187 * include timers, messages and any other user defined events.
// 188 *
// 189 * @param task_id - The OSAL assigned task ID.
// 190 * @param events - events to process. This is a bit map and can
// 191 * contain more than one event.
// 192 *
// 193 * @return none
// 194 */
RSEG BANKED_CODE:CODE:NOROOT(0)
// 195 UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events )
GenericApp_ProcessEvent:
CFI Block cfiBlock1 Using cfiCommon0
CFI Function GenericApp_ProcessEvent
// 196 {
FUNCALL GenericApp_ProcessEvent, osal_msg_receive
LOCFRAME XSTACK, 12, STACK
ARGFRAME XSTACK, 12, STACK
FUNCALL GenericApp_ProcessEvent, osal_start_timer
LOCFRAME XSTACK, 12, STACK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -