FreeCalypso > hg > tcs211-c139
comparison chipsetsw/services/tty/tty_env.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /** | |
2 * @file tty_env.c | |
3 * | |
4 * Coding of the Riviera Generic Functions, | |
5 * except handle_message and handle_timer, which are | |
6 * in tty_handle_message.c and tty_handle_timer.c | |
7 * | |
8 * @author Frederic Turgis (f-turgis@ti.com) & Gerard Cauvy (g-cauvy@ti.com) | |
9 * @version 0.1 | |
10 */ | |
11 | |
12 /* | |
13 * History: | |
14 * | |
15 * Date Modification | |
16 * ------------------------------------ | |
17 * 01/27/2003 Create | |
18 * | |
19 * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved | |
20 */ | |
21 | |
22 | |
23 #include "tty/tty_i.h" | |
24 | |
25 #include "rvm/rvm_priorities.h" | |
26 #include "tty/tty_env.h" | |
27 #include <string.h> | |
28 | |
29 /** | |
30 * Pointer on the structure gathering all the global variables | |
31 * used by TTY instance. | |
32 */ | |
33 T_TTY_ENV_CTRL_BLK *tty_env_ctrl_blk_p = NULL; | |
34 | |
35 | |
36 /* External declaration */ | |
37 extern T_RV_RET tty_core(void); | |
38 | |
39 /** | |
40 * Called by the RV manager to learn | |
41 * tty requirements in terms of memory, SWEs... | |
42 * | |
43 * @param swe_info Pointer to the structure to fill | |
44 * containing infos related to the tty SWE. | |
45 * | |
46 * @return RVM_OK | |
47 */ | |
48 T_RVM_RETURN tty_get_info(T_RVM_INFO_SWE * swe_info) | |
49 { | |
50 /* TTY is a Type 4 SWE. */ | |
51 swe_info->swe_type = RVM_SWE_TYPE_4; | |
52 | |
53 memcpy(swe_info->type_info.type4.swe_name, "TTY", sizeof("TTY")); | |
54 swe_info->type_info.type4.swe_use_id = TTY_USE_ID; | |
55 | |
56 /* SWE info */ | |
57 swe_info->type_info.type4.stack_size = TTY_STACK_SIZE; | |
58 swe_info->type_info.type4.priority = RVM_TTY_TASK_PRIORITY; | |
59 swe_info->type_info.type4.version = BUILD_VERSION_NUMBER(0,1,0); | |
60 | |
61 /* Memory bank info */ | |
62 swe_info->type_info.type4.nb_mem_bank = 1; | |
63 memcpy(swe_info->type_info.type4.mem_bank[0].bank_name, "TTY_PRIM", sizeof("TTY_PRIM")); | |
64 swe_info->type_info.type4.mem_bank[0].initial_params.size = TTY_MB_PRIM_SIZE; | |
65 swe_info->type_info.type4.mem_bank[0].initial_params.watermark = TTY_MB_PRIM_WATERMARK; | |
66 | |
67 /* | |
68 * Linked SWE info. | |
69 */ | |
70 swe_info->type_info.type4.nb_linked_swe = 0; | |
71 | |
72 /* Set the return path: NOT USED. */ | |
73 swe_info->type_info.type4.return_path.callback_func = NULL; | |
74 swe_info->type_info.type4.return_path.addr_id = 0; | |
75 | |
76 /* Generic functions */ | |
77 swe_info->type_info.type4.set_info = tty_set_info; | |
78 swe_info->type_info.type4.init = tty_init; | |
79 swe_info->type_info.type4.core = tty_core; | |
80 swe_info->type_info.type4.stop = tty_stop; | |
81 swe_info->type_info.type4.kill = tty_kill; | |
82 | |
83 return RVM_OK; | |
84 } | |
85 | |
86 | |
87 /** | |
88 * Called by the RV manager to inform the tty SWE about | |
89 * addr_id, return path, mb_id and error function. | |
90 * | |
91 * It is called only once. | |
92 * | |
93 * @param addr_id Address ID of the TTY SWE. | |
94 * Used to send messages to the SWE. | |
95 * @param return_path Return path array of the linked SWEs. | |
96 * @param bk_id_table Array of memory bank ids allocated to the SWE. | |
97 * @param call_back_error_ft Callback function to call in case of unrecoverable error. | |
98 * @return RVM_MEMORY_ERR ou RVM_OK. | |
99 */ | |
100 T_RVM_RETURN tty_set_info ( T_RVF_G_ADDR_ID addr_id, | |
101 T_RV_RETURN_PATH return_path[], | |
102 T_RVF_MB_ID bk_id_table[], | |
103 T_RVM_CB_FUNC call_back_error_ft) | |
104 { | |
105 /* Memory bank status (red, yellow, green). */ | |
106 T_RVF_MB_STATUS mb_status; | |
107 | |
108 | |
109 /* Create instance gathering all the variable used by TTY instance */ | |
110 mb_status = rvf_get_buf(bk_id_table[0], | |
111 sizeof(T_TTY_ENV_CTRL_BLK), | |
112 (T_RVF_BUFFER**)&tty_env_ctrl_blk_p); | |
113 if (mb_status == RVF_RED) | |
114 { | |
115 TTY_SEND_TRACE("TTY: Error to get memory ",RV_TRACE_LEVEL_ERROR); | |
116 return RVM_MEMORY_ERR; | |
117 } | |
118 else if (mb_status == RVF_YELLOW) | |
119 { | |
120 /* | |
121 * The flag is yellow, there will soon be not enough memory anymore. | |
122 */ | |
123 TTY_SEND_TRACE("TTY: Getting short on memory ", RV_TRACE_LEVEL_WARNING); | |
124 } | |
125 | |
126 /* Store the initial State; default is IDLE. */ | |
127 tty_env_ctrl_blk_p->state = TTY_IDLE; | |
128 | |
129 /* Store the address ID. */ | |
130 tty_env_ctrl_blk_p->addr_id = addr_id; | |
131 | |
132 /* Store the pointer to the error function. */ | |
133 tty_env_ctrl_blk_p->error_ft = call_back_error_ft; | |
134 | |
135 /* | |
136 * Store the mem bank id. | |
137 * Memory bank ID (mb_id) can be retrieved later using rvf_get_mb_id function. | |
138 */ | |
139 tty_env_ctrl_blk_p->prim_mb_id = bk_id_table[0]; | |
140 | |
141 /* | |
142 * Array return_path: Return path of linked SWE. | |
143 * If the linked SWE have an API based on messages, their return path given | |
144 * by the set_info function would be stored and used to communicate with them. | |
145 * But since the linked SWE of TTY have an API based on functions, it is not | |
146 * necessary to store their return path. | |
147 */ | |
148 | |
149 return RVM_OK; | |
150 } | |
151 | |
152 | |
153 /** | |
154 * Called by the RV manager to initialize the | |
155 * tty SWE before creating the task and calling tty_start. | |
156 * | |
157 * @return RVM_OK | |
158 */ | |
159 T_RVM_RETURN tty_init (void) | |
160 { | |
161 /* | |
162 * TTY Global Initialization. | |
163 */ | |
164 | |
165 return RVM_OK; | |
166 } | |
167 | |
168 | |
169 /** | |
170 * Called by the RV manager to stop the tty SWE. | |
171 * | |
172 * @return RVM_OK or RVM_INTERNAL_ERR | |
173 */ | |
174 T_RVM_RETURN tty_stop (void) | |
175 { | |
176 /* | |
177 * Here we should stop the activities of the SWE | |
178 * It is still possible to send messages to other SWE, to unregister for example. | |
179 */ | |
180 TTY_SEND_TRACE("TTY: stop called", RV_TRACE_LEVEL_DEBUG_LOW); | |
181 | |
182 return RVM_OK; | |
183 } | |
184 | |
185 | |
186 /** | |
187 * Called by the RV manager to kill the tty SWE, | |
188 * after the tty_stop function has been called. | |
189 * | |
190 * @return RVM_OK | |
191 */ | |
192 T_RVM_RETURN tty_kill (void) | |
193 { | |
194 /* | |
195 * Here we cannot send messages anymore. We only free the last | |
196 * used resources, like the control block buffer. | |
197 */ | |
198 TTY_SEND_TRACE("TTY: kill called", RV_TRACE_LEVEL_DEBUG_LOW); | |
199 | |
200 rvf_free_buf(tty_env_ctrl_blk_p); | |
201 | |
202 return RVM_OK; | |
203 } |