annotate gsm-fw/services/etm/etm_task.c @ 164:d78219c43fbf

gsm-fw/services/etm: initial import from the Leonardo semi-src
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 18 Nov 2013 06:39:44 +0000
parents
children 13af69b6a3dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /********************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Enhanced TestMode (ETM)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * @file etm.c
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 *
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * @author Kim T. Peteren (ktp@ti.com)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * @version 0.1
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 *
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 *
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 * History:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 *
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 * Date Modification
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 * ------------------------------------
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 * 16/06/2003 Creation
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 * 03/03/2004 Upadted regarding the ATP + minor ETM DB handling updates
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 * 28/07/2004 Fixed ETM database issue
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 *
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 *********************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 #include "etm/etm.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 #include "etm/etm_api.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 #include "etm/etm_messages_i.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 #include "etm/etm_trace.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 #include "etm/etm_env.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 #include "audio/audio_api.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 #include "rv/rv_general.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 #include "rvf/rvf_api.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 #include "rvt/rvt_gen.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 #include "rvf/rvf_target.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 #include "rv/rv_defined_swe.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 #include <string.h>
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 #ifdef RVM_LCC_SWE
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 #include "lcc/lcc_api.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 #include "lcc/lcc_cfg_i.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 #include "lcc/lcc.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 #include "lcc/lcc_env.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 #include "lcc/lcc_trace.h"
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 #endif
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 // Version of the ETM TASK moved to etm_version.h
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 //const uint16 etm_task_revision = (1<<12) | (0x1);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 * Globals
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 *****************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 #define ETM_DB_MAX 16 // Limited of registered SWEntities into ETM DB
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 #define ETM_DB_NO_USE 0xFFFFFFFF //
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 typedef struct
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 char swe_name[ETM_NAME_MAX_LEN];
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 int mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 int task_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 T_RVF_ADDR_ID addr_id; // Unique mailbox (ID) of the SWE which will
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 //receive the message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 ETM_CALLBACK_FUNC rx_callback_func;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 } T_ETM_USER_DB;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 static T_ETM_USER_DB etm_user_db[ETM_DB_MAX];
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 static int etm_db_counter = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 * Prototypes
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 *****************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 #ifdef RVM_LCC_SWE
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 extern T_PWR_CTRL_BLOCK *pwr_ctrl;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 #endif
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 int etm_database_manager(T_RV_HDR *msg_p);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 int etm_forward_packet(int mid, T_RV_HDR *msg);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 void etm_error_packet_send(int mid, int error);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 void etm_receive(unsigned char *inbuf, unsigned short size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 int etm_ffs_pkt_receive(uint8 *data, int size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 extern int etm_at_atp_message(void *msg);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 #ifdef RVM_LCC_SWE
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 extern int etm_pwr_ul(void *msg);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 extern int etm_pwr_dl(T_ETM_PKT *pkt, uint8 *buf, int insize);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 #endif
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 * Main Testmode Task Loop
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 *****************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 T_RV_RET etm_task(void)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 extern int etm_core_init(void);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 extern int etm_audio_init(void);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 #ifdef RVM_LCC_SWE
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 extern int etm_pwr_init(void);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 #endif
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 T_RV_HDR *msg = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 T_ETM_PKT *pkt = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 UINT32 start_time = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 UINT32 end_time = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 UINT16 recv_event, i;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 int status = RV_OK, buf_size;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 /* Entity registration to ETM */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 /* This should be in the individual SWE init. function*/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 status = etm_core_init();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 status = etm_audio_init();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 #ifdef RVM_LCC_SWE
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 status = etm_pwr_init();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 #endif
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 while (1)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 recv_event = rvf_wait(0xffff,0); /* Wait (infinite) for all events. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 start_time = rvf_get_tick_count();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 tr_etm(TgTrEtmLow,"ETM: _task: Time Waiting (%d) tick", start_time - end_time);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 tr_etm(TgTrEtmLow,"ETM: _task: Time Start(%d)", start_time);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 tr_etm(TgTrEtmLow,"ETM: _task: Got message passing to bit filter (0x%x)", recv_event);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 if (!(recv_event & RVF_TASK_MBOX_0_EVT_MASK))
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 continue;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 /* Read the message in the ETM mailbox */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 if ((msg = rvf_read_mbox(ETM_MAILBOX)) == NULL)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 continue;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 tr_etm(TgTrEtmLow,"ETM: _task: msg_id(0x%x)", msg->msg_id);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 switch (msg->msg_id) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 /* Entity registration request or unregistration */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 case ETM_REGISTER_REQ:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 case ETM_UNREGISTER:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 status = etm_database_manager(msg);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 break;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 /* ETM packet received */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 case ETM_DATA_FWR:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 if ((status = etm_forward_packet(((T_ETM_DATA_FWR *) msg)->mid, msg))
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 != ETM_OK)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 etm_error_packet_send(((T_ETM_DATA_FWR *) msg)->mid, status);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 break;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 /* TM3 packet received */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 case ETM_TM3_DATA_FWR:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 if ((status = etm_forward_packet(ETM_TM3, msg)) != ETM_OK)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 etm_error_packet_send(ETM_TM3, status);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 break;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 default:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 tr_etm(TgTrEtmLow,"ETM: _task: msg_id '0x%x' NOT supported",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 msg->msg_id);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 if (status != ETM_OK) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 tr_etm(TgTrFatal,"ETM: _task: mid(0x%x) ERROR(%d)",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 ((T_ETM_DATA_FWR *) msg)->mid, status);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 etm_free(msg); // Free the message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 end_time = rvf_get_tick_count();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 tr_etm(TgTrEtmLow,"ETM: _task: Time End (%d)", end_time);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 tr_etm(TgTrEtmLow,"ETM: _task: Time Total (%d) tick", end_time - start_time);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 return RV_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 void etm_error_packet_send(int mid, int error)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 T_ETM_PKT *pkt;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 tr_etm(TgTrFatal,"ETM: _error_packet_send: Module(0x%x) ERROR(%d)", mid, error);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 if (error == ETM_NOMEM) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 rvf_dump_mem();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 rvf_dump_mem();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 return;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 // Init. of return packet
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 pkt->mid = mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 pkt->status = -error;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 pkt->size = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 pkt->index = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 etm_pkt_send(pkt);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 etm_free(pkt); // Free return packet
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 /* Forwarding of DATA to the SWE can either be done by message/primitive or callback */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 int etm_forward_packet(int mid, T_RV_HDR* msg)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 ETM_CALLBACK_FUNC rx_callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 int i, cid, status = ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 T_ETM_DATA_READY* message_p;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 T_RVF_ADDR_ID swe_addr_id = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 // Search for supported MID in the table
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 for (i = 0; etm_user_db[i].mid != TABLE_END; i++)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 tr_etm(TgTrEtmLow,"ETM: _forward_packet: Lookup in db for mid(0x%x)", mid);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 if (etm_user_db[i].mid == mid) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 rx_callback_func = etm_user_db[i].rx_callback_func;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 swe_addr_id = etm_user_db[i].addr_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 break;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 tr_etm(TgTrEtmLow,"ETM: _forward_packet: rx_callback_func(%d) swe_addr_id(%d)",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 *rx_callback_func, swe_addr_id);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 // Invoke the SWE mailbox
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 if (swe_addr_id) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 /* Allocate the memory for the message to send */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 if ((message_p = (T_ETM_DATA_READY*) etm_malloc(sizeof(T_ETM_DATA_READY))) == NULL)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 return ETM_NOMEM;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 /* Fill the header of the message */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 message_p->header.msg_id = ETM_DATA_READY;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 /* Fill the address source id */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 message_p->header.src_addr_id = rvf_get_taskid();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 message_p->header.dest_addr_id = etm_env_ctrl_blk->addr_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 message_p->header.callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 /* Fill the data in the message */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 memcpy(((T_ETM_DATA_READY*) message_p)->data, ((T_ETM_DATA_FWR*) msg)->data,
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 ((T_ETM_DATA_FWR*) msg)->size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 /* Send the message to the entity */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 if ((status = rvf_send_msg(swe_addr_id, message_p)) != RV_OK) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 tr_etm(TgTrFatal,"ETM: _forward_packet: Failed to sent message - ERROR(%d)",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 status);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 return ETM_RV_FATAL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 etm_free(msg); // Free the message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 // Invoke the SWE callback function
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 else if (rx_callback_func) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 tr_etm(TgTrEtmLow,"ETM: _forward_packet: to mid(0x%x)", mid);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 status = rx_callback_func (((T_ETM_DATA_FWR*) msg)->data, ((T_ETM_DATA_FWR*) msg)->size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 rx_callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 if (status != ETM_OK)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 return status;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 etm_free(msg); // Free the message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 else {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 return ETM_NOSYS;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 * Get and Free buffer (Internal Functions)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 *****************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 void *etm_malloc(int size)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 /* Memory bank status (red, yellow, green) */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 T_RVF_MB_STATUS mb_status;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 void *addr;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 mb_status = rvf_get_buf(etm_env_ctrl_blk->prim_id, size, &addr);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 /* The flag returned by rvf_get_buf is red, there is not enough
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 * memory to allocate the buffer. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 if (mb_status == RVF_RED) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 tr_etm(TgTrFatal, "ETM: _malloc: Error to get memory");
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 return NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 /* The flag is yellow, there will soon be not enough memory anymore. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 else if (mb_status == RVF_YELLOW) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 tr_etm(TgTrFatal, "ETM: _malloc: Getting short on memory");
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 tr_etm(TgTrEtmLow,"ETM: _malloc: size(%d) at addr(0x%x)", size, addr);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 return addr;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 int etm_free(void *addr)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 int status;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 tr_etm(TgTrEtmLow,"ETM: _free: addr(0x%x)", addr);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304 if ((status = rvf_free_buf(addr)) != RV_OK) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 tr_etm(TgTrFatal, "ETM: _free: ERROR(%d)", status);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 return ETM_RV_FATAL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 * ETM receive Functions API (Internal Functions)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 ******************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 /* The input pointer buf point at a complete TM3 packet. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 int etm_tm3_data_forward(uint8 *buf, int size)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319 /* Type for a registration event. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 T_ETM_TM3_DATA_FWR *msg;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322 tr_etm(TgTrEtmLow, "ETM: _tm3_data_forward: cid(0x%x) size(%d)", *buf, size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 /* Allocate the memory for the message to send */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 if ((msg = (T_ETM_TM3_DATA_FWR*) etm_malloc(sizeof(T_ETM_TM3_DATA_FWR))) == NULL)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326 return ETM_NOMEM;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
328 /* Fill the message id */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
329 msg->header.msg_id = ETM_TM3_DATA_FWR;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331 /* Fill the address source id */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 msg->header.src_addr_id = rvf_get_taskid();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
333 msg->header.dest_addr_id = etm_env_ctrl_blk->addr_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
334 msg->header.callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336 /* Fill the message parameters */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337 msg->size = size;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338 msg->cid = *buf;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
339 memcpy(&msg->data, buf, size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 // At this point, all the data have been parsed and copied into
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342 // the ETM primitive. Now we send the primitive to the ETM task.
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 if (rvf_send_msg(etm_env_ctrl_blk->addr_id, msg) != RV_OK) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344 tr_etm(TgTrFatal, "ETM: _tm3_data_forward: FAILED");
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 return ETM_RV_FATAL; // msg is auto freed by rvf_send_msg() if error
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
346 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
347
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
348 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
349 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
350
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
351
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 /* The input pointer buf point at payload of the TM packet, minus mid and cksum. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
353 int etm_data_forward(char mid, uint8 *inbuf, int size)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
354 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
355 /* Type for a registration event. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356 T_ETM_DATA_FWR *msg;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
357
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 tr_etm(TgTrEtmLow, "ETM: _data_forward: mid(0x%x) size(%d)", mid, size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
359
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 /* Allocate the memory for the message to send */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
361 if ((msg = (T_ETM_DATA_FWR*) etm_malloc(sizeof(T_ETM_DATA_FWR))) == NULL)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
362 return ETM_NOMEM;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
363
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
364 /* Fill the message id */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 msg->header.msg_id = ETM_DATA_FWR;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
367 /* Fill the address source id */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 msg->header.src_addr_id = rvf_get_taskid();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369 msg->header.dest_addr_id = etm_env_ctrl_blk->addr_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
370 msg->header.callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
371
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
372 /* Fill the message parameters */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 msg->size = size;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 msg->mid = mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
375 memcpy(&msg->data, inbuf, size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
376
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
377 // At this point, all the data have been parsed and copied into
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
378 // the ETM primitive. Now we send the primitive to the ETM task.
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
379 if (rvf_send_msg(etm_env_ctrl_blk->addr_id, msg) != RV_OK) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 tr_etm(TgTrFatal, "ETM: _data_forward: FAILED");
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
381 return ETM_RV_FATAL; // msg is auto freed by rvf_send_msg() if error
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
384 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
385 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 /* This function is registred in the RVT module as the TestMode receive function */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 /* It's called every time a TestMode packet is received on the UART and the */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 /* data is forwarded to the ETM Entity via a message/primitiv */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
391 /* The function is a callback func. used by the RVT TASK -> UART RX. */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
392
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 void etm_receive(uint8 *inbuf, unsigned short size)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
394 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
395 int error = ETM_NOSYS, i, index;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 char mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
397 unsigned char cksum;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
398 T_ETM_PKT *pkt;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 tr_etm(TgTrEtmLow, "ETM: _receive: inbuf size(%d)", size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 // Copy data payload size (size minus MID/CID byte and checksum byte)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403 mid = *inbuf++;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
404
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405 cksum = mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
406 for (i = 0; i < size - 1; i++) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 cksum ^= inbuf[i];
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
408 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
410 if (cksum != 0) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
411 error = ETM_PACKET;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
412 goto ETM_RECEIVE_END;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
413 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
414
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
415 // Check it's a TM3 packet
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
416 if ((0x20 <= mid && mid < 0x27) ||
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
417 (0x30 <= mid && mid < 0x3A) ||
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
418 (0x40 <= mid && mid < 0x49) ||
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
419 (0x50 <= mid && mid < 0x57)) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
420 // Forward complete TM3 packet
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
421 error = etm_tm3_data_forward(--inbuf, size);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
422 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
423 else {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
424 /* Controlling of receptor for regisration */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
425 for (index=0; index < etm_db_counter; index++)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
426 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
427 if (etm_user_db[index].mid == mid) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
428 // Forward ETM packet without <mid> and <cksum>, -2 in size
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
429 error = etm_data_forward(mid, inbuf, size - 2);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
430 break;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
431 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
432 else if ((index == etm_db_counter) && (etm_user_db[index].mid != mid)) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
433 tr_etm(TgTrFatal, "ETM: _receive: mid(0x%x) not supported", mid);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
434 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
435 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
436 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
437
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
438 ETM_RECEIVE_END:
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
439 /* Fill in Error status in ETM packet and send */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
440 if (error) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
441 if (error == ETM_NOMEM) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
442 rvf_dump_mem();
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
443 return;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
444 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
445
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
446 if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
447 return;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
448 pkt->size = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
449 pkt->mid = mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
450 pkt->status = -error;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
451
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
452 etm_pkt_send(pkt);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
453 etm_free(pkt); // Free return Packet
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
454 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
455 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
456
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
457
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
458 /******************************************************************************
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
459 * Registration manager Functions API (Internal function)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
460 ******************************************************************************/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
461
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
462 int etm_database_add(T_ETM_REGISTER_REQ *msg_p, int index)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
463 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
464
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
465 memcpy(etm_user_db[index].swe_name, msg_p->name, strlen(msg_p->name));
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
466 etm_user_db[index].mid = msg_p->mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
467 etm_user_db[index].task_id = msg_p->task_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
468 etm_user_db[index].addr_id = msg_p->addr_id;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
469 etm_user_db[index].rx_callback_func = msg_p->rx_callback_func;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
470
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
471 etm_user_db[index+1].mid = TABLE_END;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
472
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
473 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
474 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
475
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
476
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
477 int etm_database_manager(T_RV_HDR *msg_p)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
478 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
479 int index, mid, status;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
480
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
481 if (msg_p->msg_id == ETM_REGISTER_REQ) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
482 mid = ((T_ETM_REGISTER_REQ *) msg_p)->mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
483
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
484 tr_etm(TgTrEtmLow,"ETM: _database_manager: _REGISTER_REQ reguest is received from (%s)",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
485 ((T_ETM_REGISTER_REQ *) msg_p)->name);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
486
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
487 /* Lookup in the ETM DB array */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
488 for (index=0; index < ETM_DB_MAX; index++)
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
489 {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
490 /* Use unregistrered space */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
491 if ((etm_user_db[index].mid == ETM_DB_NO_USE) && (etm_user_db[index].addr_id == 0) &&
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
492 (etm_user_db[index].rx_callback_func == NULL)) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
493 status = etm_database_add((T_ETM_REGISTER_REQ*) msg_p, index);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
494 etm_db_counter++;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
495 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
496 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
497 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
498 /* Reject double registration */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
499 else if ((etm_user_db[index].mid == mid) &&
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
500 ((etm_user_db[index].addr_id != 0) || (etm_user_db[index].rx_callback_func != NULL))) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
501 tr_etm(TgTrFatal,"ETM: _database_manager: The Module(0x%x) is registrered", mid);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
502 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
503 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
504 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
505 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
506
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
507 /* Add the entity to the etm database */
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
508 if (etm_db_counter < ETM_DB_MAX) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
509 status = etm_database_add((T_ETM_REGISTER_REQ*) msg_p, etm_db_counter);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
510 etm_db_counter++;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
511 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
512 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
513 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
514
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
515 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
516 return ETM_DB_LIMIT;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
517 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
518
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
519
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
520 if (msg_p->msg_id == ETM_UNREGISTER) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
521 mid = ((T_ETM_UNREGISTER *) msg_p)->mid;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
522 tr_etm(TgTrEtmLow,"ETM: _database_manager: _UNREGISTER reguest is received from (%s)",
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
523 ((T_ETM_REGISTER_REQ *) msg_p)->name);
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
524
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
525 /* Lookup in the array, if the SWE is stocked then clean it*/
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
526 for (index=0; index < ETM_DB_MAX; index++) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
527 if (etm_user_db[index].mid == mid) {
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
528 etm_user_db[index].mid = ETM_DB_NO_USE;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
529 etm_user_db[index].addr_id = 0;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
530 etm_user_db[index].rx_callback_func = NULL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
531 etm_db_counter--;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
532 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
533 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
534 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
535 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
536
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
537 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
538 return ETM_INVAL;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
539 }
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
540
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
541 etm_free(msg_p); // Free Message
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
542 return ETM_OK;
d78219c43fbf gsm-fw/services/etm: initial import from the Leonardo semi-src
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
543 }