📄 mtel.lst
字号:
144
145 /*********************************************************************
146 * LOCAL VARIABLES
147 */
148
149 /*********************************************************************
150 * LOCAL FUNCTIONS
151 */
152 void MT_MsgQueueInit( void );
153 void MT_ProcessCommand( mtOSALSerialData_t *msg );
154 void MT_ProcessSerialCommand( byte *msg );
155 byte MT_RAMRead( UINT16 addr, byte *pData );
156 byte MT_RAMWrite( UINT16 addr , byte val );
157 void MT_ProcessDebugMsg( mtDebugMsg_t *pData );
158 void MT_ProcessDebugStr( mtDebugStr_t *pData );
159 byte MT_SetDebugThreshold( byte comp_id, byte threshold );
160 void MT_SendErrorNotification( byte err );
161 void MT_ResetMsgQueue( void );
162 byte MT_QueueMsg( byte *msg , byte len );
163 void MT_ProcessQueue( void );
164 void MT_SendSPIRespMsg( byte ret, uint16 cmd_id, byte msgLen, byte respLen);
165 void MT_Reset(byte typID);
166 byte MT_ProcessSetNV( byte *pData );
167 void MT_ProcessGetNV( byte *pData );
168 void MT_ProcessGetNvInfo( void );
169 void MT_ProcessGetDeviceInfo( void );
170 byte MTProcessAppMsg( byte *pData, byte len );
171 void MTProcessAppRspMsg( byte *pData, byte len );
172
173 #if (defined HAL_LED) && (HAL_LED == TRUE)
174 byte MTProcessLedControl( byte *pData );
175 #endif
176
177 #if defined ( MT_USER_TEST_FUNC )
178 void MT_ProcessAppUserCmd( byte *pData );
179 #endif
180
181 /*********************************************************************
182 * @fn MT_TaskInit
183 *
184 * @brief
185 *
186 * MonitorTest Task Initialization. This function is put into the
187 * task table.
188 *
189 * @param byte task_id - task ID of the MT Task
190 *
191 * @return void
192 *
193 *********************************************************************/
194 void MT_TaskInit( byte task_id )
195 {
196 MT_TaskID = task_id;
197
198 debugThreshold = 0;
199 debugCompId = 0;
200
201 // Initialize the Serial port
202 SPIMgr_Init();
203
204 } /* MT_TaskInit() */
205
206 #ifdef ZTOOL_PORT
207 /*********************************************************************
208 * @fn MT_IndReset()
209 *
210 * @brief Sends a ZTOOL "reset response" message.
211 *
212 * @param None
213 *
214 * @return None
215 *
216 *********************************************************************/
217 void MT_IndReset( void )
218 {
219
220 byte rsp = 0; // Reset type==0 indicates Z-Stack reset
221
222 // Send out Reset Response message
223 MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + sizeof( rsp )),
224 (SPI_RESPONSE_BIT | SPI_CMD_SYS_RESET),
225 sizeof( rsp ), &rsp );
226 }
227 #endif
228
229 /*********************************************************************
230 * @fn MT_ProcessEvent
231 *
232 * @brief
233 *
234 * MonitorTest Task Event Processor. This task is put into the
235 * task table.
236 *
237 * @param byte task_id - task ID of the MT Task
238 * @param UINT16 events - event(s) for the MT Task
239 *
240 * @return void
241 */
242 UINT16 MT_ProcessEvent( byte task_id, UINT16 events )
243 {
244 uint8 *msg_ptr;
245
246 // Could be multiple events, so switch won't work
247
248 if ( events & SYS_EVENT_MSG )
249 {
250 while ( (msg_ptr = osal_msg_receive( MT_TaskID )) )
251 {
252 MT_ProcessCommand( (mtOSALSerialData_t *)msg_ptr );
253 }
254
255 // Return unproccessed events
256 return (events ^ SYS_EVENT_MSG);
257 }
258
259 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
260 if ( events & MT_ZTOOL_SERIAL_RCV_BUFFER_FULL )
261 {
262 // Do sometype of error processing
263 MT_SendErrorNotification(RECEIVE_BUFFER_FULL);
264
265 // Return unproccessed events
266 return (events ^ MT_ZTOOL_SERIAL_RCV_BUFFER_FULL);
267 }
268 #endif
269
270 // Discard or make more handlers
271 return 0;
272
273 } /* MT_ProcessEvent() */
274
275 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
276 /*********************************************************************
277 * @fn MT_BuildSPIMsg
278 *
279 * @brief
280 *
281 * Format an SPI message.
282 *
283 * @param UINT16 cmd - command id
284 * @param byte *msg - pointer to message buffer
285 * @param byte dataLen - length of data field
286 * @param byte *pData - pointer to data field
287 *
288 * @return void
289 */
290 void MT_BuildSPIMsg( UINT16 cmd, byte *msg, byte dataLen, byte *pData )
291 {
292 byte *msgPtr;
293
294 *msg++ = SOP_VALUE;
295
296 msgPtr = msg;
297
298 *msg++ = (byte)(HI_UINT16( cmd ));
299 *msg++ = (byte)(LO_UINT16( cmd ));
300
301 if ( pData )
302 {
303 *msg++ = dataLen;
304
305 msg = osal_memcpy( msg, pData, dataLen );
306 }
307 else
308 *msg++ = 0;
309
310 *msg = SPIMgr_CalcFCS( msgPtr, (byte)(3 + dataLen) );
311 }
312 #endif
313
314 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
315 /*********************************************************************
316 * @fn MT_BuildAndSendZToolResponse
317 *
318 * @brief
319 *
320 * Build and send a ZTOOL msg
321 *
322 * @param byte err
323 *
324 * @return void
325 */
326 void MT_BuildAndSendZToolResponse( byte msgLen, uint16 cmd,
327 byte dataLen, byte *pData )
328 {
329 byte *msg_ptr;
330
331 // Get a message buffer to build response message
332 msg_ptr = osal_mem_alloc( msgLen );
333 if ( msg_ptr )
334 {
335 #ifdef SPI_MGR_DEFAULT_PORT
336 MT_BuildSPIMsg( cmd, msg_ptr, dataLen, pData );
337 HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msg_ptr, msgLen );
338 #endif
339 osal_mem_free( msg_ptr );
340 }
341 }
342 #endif
343
344 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
345 /*********************************************************************
346 * @fn MT_BuildAndSendZToolCB
347 *
348 * @brief
349 *
350 * Build and send a ZTOOL Callback msg
351 *
352 * @param len - length of data portion of the message
353 *
354 * @return void
355 */
356 void MT_BuildAndSendZToolCB( uint16 callbackID, byte len, byte *pData )
357 {
358 byte msgLen;
359 mtOSALSerialData_t *msgPtr;
360 byte *msg;
361
362 msgLen = sizeof ( mtOSALSerialData_t ) + SPI_0DATA_MSG_LEN + len;
363
364 msgPtr = (mtOSALSerialData_t *)osal_msg_allocate( msgLen );
365 if ( msgPtr )
366 {
367 msgPtr->hdr.event = CB_FUNC;
368 msgPtr->msg = (uint8 *)(msgPtr+1);
369 msg = msgPtr->msg;
370
371 //First byte is used as the event type for MT
372 *msg++ = SOP_VALUE;
373 *msg++ = HI_UINT16( callbackID );
374 *msg++ = LO_UINT16( callbackID );
375 *msg++ = len;
376
377 //Fill up the data bytes
378 osal_memcpy( msg, pData, len );
379
380 osal_msg_send( MT_TaskID, (uint8 *)msgPtr );
381 }
382 }
383 #endif
384
385 /*********************************************************************
386 * @fn MT_ProcessCommand
387 *
388 * @brief
389 *
390 * Process Event Messages.
391 *
392 * @param byte *msg - pointer to event message
393 *
394 * @return
395 */
396 void MT_ProcessCommand( mtOSALSerialData_t *msg )
397 {
398 byte deallocate;
399 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
400 byte *msg_ptr;
401 byte len;
402
403 // A little setup for AF, CB_FUNC and MT_SYS_APP_RSP_MSG
404 msg_ptr = msg->msg;
405 #endif // ZTOOL
406
407 deallocate = true;
408
409 // Use the first byte of the message as the command ID
410 switch ( msg->hdr.event )
411 {
412 #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
413 case CMD_SERIAL_MSG:
414 MT_ProcessSerialCommand( msg->msg );
415 break;
416
417 case CMD_DEBUG_MSG:
418 MT_ProcessDebugMsg( (mtDebugMsg_t *)msg );
419 break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -