FreeCalypso > hg > tcs211-fcmodem
comparison chipsetsw/services/atp/atp_port.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 * | |
| 3 * File Name : atp_port.c | |
| 4 * | |
| 5 * Functions used by atp_services.c file to handle port structure | |
| 6 * | |
| 7 * (C) Texas Instruments, all rights reserved | |
| 8 * | |
| 9 * Version number : 0.1 Date : 10-May-2000 from atp_port.c | |
| 10 * | |
| 11 * History : 0.1 - Created by E. Baissus . Gathers functions used only | |
| 12 * as internal services | |
| 13 * | |
| 14 * Author : Eric Baissus : e-baissus@ti.com | |
| 15 * | |
| 16 * (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved | |
| 17 ******************************************************************************/ | |
| 18 #include "rv/rv_general.h" | |
| 19 #include "rvf/rvf_api.h" | |
| 20 #include "atp/atp_api.h" | |
| 21 #include "atp/atp_i.h" | |
| 22 #include "atp/atp_messages.h" | |
| 23 #include "rvm/rvm_use_id_list.h" | |
| 24 | |
| 25 | |
| 26 | |
| 27 T_ATP_PORT_STRUCT * atp_first_port_p; /* Pointer on the first port structure */ | |
| 28 | |
| 29 T_ATP_RET atp_init_port(T_ATP_PORT_STRUCT *new_port_p); | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 /****************************************************************************** | |
| 40 * Function name: atp_init_port | |
| 41 * | |
| 42 * Description : Initialise a new port | |
| 43 * | |
| 44 * Parameters : pointer on the new port | |
| 45 * | |
| 46 * Return : Always return RV_OK | |
| 47 * | |
| 48 * History : 0.1 (1-Marsh-2000) - Created | |
| 49 * 0.9:(22-May-2000) - Added redirection | |
| 50 * | |
| 51 ******************************************************************************/ | |
| 52 | |
| 53 T_ATP_RET atp_init_port(T_ATP_PORT_STRUCT *new_port_p) | |
| 54 { | |
| 55 new_port_p->next_p = NULL; | |
| 56 new_port_p->port_state = ATP_OPEN_PENDING; | |
| 57 | |
| 58 (new_port_p->port_info[0]).port_nb = INVALID_PORT_NB; | |
| 59 (new_port_p->port_info[0]).sw_id = ATP_INVALID_SWE_ID; | |
| 60 (new_port_p->port_info[0]).tx_mb = RVF_INVALID_MB_ID; | |
| 61 (new_port_p->port_info[0]).rx_mb = RVF_INVALID_MB_ID; | |
| 62 (new_port_p->port_info[0]).rx_data_left = 0; | |
| 63 ((new_port_p->port_info[0]).no_copy_info).packet_mode = NORMAL_PACKET; | |
| 64 ((new_port_p->port_info[0]).no_copy_info).rx_head_size = 0; | |
| 65 ((new_port_p->port_info[0]).no_copy_info).rx_trail_size = 0; | |
| 66 ((new_port_p->port_info[0]).no_copy_info).tx_head_size = 0; | |
| 67 ((new_port_p->port_info[0]).no_copy_info).tx_trail_size = 0; | |
| 68 (new_port_p->port_info[0]).signal = (ATP_RX_FLOW_ON | ATP_TX_FLOW_ON); | |
| 69 | |
| 70 (new_port_p->port_info[1]).port_nb = INVALID_PORT_NB; | |
| 71 (new_port_p->port_info[1]).sw_id = ATP_INVALID_SWE_ID; | |
| 72 (new_port_p->port_info[1]).tx_mb = RVF_INVALID_MB_ID; | |
| 73 (new_port_p->port_info[1]).rx_mb = RVF_INVALID_MB_ID; | |
| 74 (new_port_p->port_info[1]).rx_data_left = 0; | |
| 75 ((new_port_p->port_info[1]).no_copy_info).packet_mode = NORMAL_PACKET; | |
| 76 ((new_port_p->port_info[1]).no_copy_info).rx_head_size = 0; | |
| 77 ((new_port_p->port_info[1]).no_copy_info).rx_trail_size = 0; | |
| 78 ((new_port_p->port_info[1]).no_copy_info).tx_head_size = 0; | |
| 79 ((new_port_p->port_info[1]).no_copy_info).tx_trail_size = 0; | |
| 80 (new_port_p->port_info[1]).signal = (ATP_RX_FLOW_ON | ATP_TX_FLOW_ON); | |
| 81 | |
| 82 /* Redirection information */ | |
| 83 new_port_p->redirect_mode = ATP_REDIRECT_OFF; | |
| 84 new_port_p->redirect_port_end_nb = 0; | |
| 85 new_port_p->redirect_port_p = NULL; | |
| 86 | |
| 87 /* Data queue information */ | |
| 88 (new_port_p->port_info[0]).rx_queue.p_first = NULL; | |
| 89 (new_port_p->port_info[0]).rx_queue.p_last = NULL; | |
| 90 (new_port_p->port_info[0]).rx_queue.count = 0; | |
| 91 | |
| 92 (new_port_p->port_info[1]).rx_queue.p_first = NULL; | |
| 93 (new_port_p->port_info[1]).rx_queue.p_last = NULL; | |
| 94 (new_port_p->port_info[1]).rx_queue.count = 0; | |
| 95 | |
| 96 /* Pointer on DCE information */ | |
| 97 new_port_p->dce_info_p = NULL; | |
| 98 | |
| 99 new_port_p->port_config = NOT_DEFINED_CONFIG; | |
| 100 | |
| 101 /* Flow control */ | |
| 102 new_port_p->port_waiting_for_mb_callback = ATP_MAX_SW_NB; | |
| 103 | |
| 104 /* Command info */ | |
| 105 new_port_p->cmd_info.cmd_txt_p = NULL; | |
| 106 | |
| 107 return (atp_init_cmd_info_struct (new_port_p)); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 /****************************************************************************** | |
| 117 * Function name: atp_create_port | |
| 118 * | |
| 119 * Description : Create a new port instance in the port chained list | |
| 120 * | |
| 121 * Parameters : Output = pointeur on the new port structure | |
| 122 * | |
| 123 * Return : Error flag : | |
| 124 * Possible values are RV_OK or RV_MEMORY_ERR | |
| 125 * | |
| 126 * History : 0.1 (1-Marsh-2000) - Created / E.Baissus | |
| 127 * | |
| 128 ******************************************************************************/ | |
| 129 | |
| 130 T_ATP_RET atp_create_port(T_ATP_PORT_STRUCT **port_pp) | |
| 131 { | |
| 132 | |
| 133 T_ATP_PORT_STRUCT *new_port_p,*p; | |
| 134 | |
| 135 /* get new buffer */ | |
| 136 switch(rvf_get_buf(atp_mb_prim,sizeof(T_ATP_PORT_STRUCT),(void **) &new_port_p)) | |
| 137 { | |
| 138 case RVF_GREEN: | |
| 139 { | |
| 140 break; | |
| 141 } | |
| 142 case RVF_YELLOW: | |
| 143 { | |
| 144 rvf_free_buf ((T_RVF_BUFFER *) new_port_p); | |
| 145 } | |
| 146 default: | |
| 147 { | |
| 148 return RV_MEMORY_ERR; | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 /* initialisation of the new instance */ | |
| 153 atp_init_port(new_port_p); | |
| 154 | |
| 155 | |
| 156 // START : THIS SECTION MUST BE PROTECTED BY A SEMAPHORE !!!!!! | |
| 157 | |
| 158 /* get latest port instance */ | |
| 159 if (atp_first_port_p==NULL) | |
| 160 { /* this new instance is the first one */ | |
| 161 atp_first_port_p=new_port_p; | |
| 162 } | |
| 163 else | |
| 164 { | |
| 165 p=atp_first_port_p; | |
| 166 while(p->next_p!=NULL) | |
| 167 { | |
| 168 p=p->next_p; | |
| 169 } | |
| 170 /* p points on the last port instance */ | |
| 171 p->next_p=new_port_p; | |
| 172 } | |
| 173 // END : THIS SECTION MUST BE PROTECTTED BY A SEMAPHORE !!!!!! | |
| 174 | |
| 175 *port_pp=new_port_p; | |
| 176 | |
| 177 return RV_OK; | |
| 178 } | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 /****************************************************************************** | |
| 187 * Function name: atp_delete_port | |
| 188 * | |
| 189 * Description : delete port instance | |
| 190 * | |
| 191 * Parameters : - port_p points on the port structure to remove | |
| 192 * | |
| 193 * Return : Standard error flag | |
| 194 * If OK, returns RV_OK | |
| 195 * | |
| 196 * History : 0.1 (1-Marsh-2000) - Created / E.Baissus | |
| 197 * | |
| 198 ******************************************************************************/ | |
| 199 | |
| 200 T_ATP_RET atp_delete_port(T_ATP_PORT_STRUCT *port_p) | |
| 201 { | |
| 202 T_ATP_PORT_STRUCT *p; | |
| 203 | |
| 204 p=atp_first_port_p; | |
| 205 | |
| 206 | |
| 207 // START : THIS SECTION MUST BE PROTECTED BY A SEMAPHORE !!!!!! | |
| 208 /* Delete buffer pointer by the port structure */ | |
| 209 if (port_p->dce_info_p != NULL) | |
| 210 { | |
| 211 // Reset fields used by the escape sequence algorithm | |
| 212 atp_reset_escape_sequence(port_p); | |
| 213 rvf_free_buf(port_p->dce_info_p); | |
| 214 } | |
| 215 if (port_p->cmd_info.cmd_txt_p != NULL) | |
| 216 { | |
| 217 rvf_free_buf(port_p->cmd_info.cmd_txt_p); | |
| 218 } | |
| 219 if (p==port_p) | |
| 220 { | |
| 221 /* The instance to delete is the first one */ | |
| 222 atp_first_port_p=port_p->next_p; | |
| 223 rvf_free_buf(port_p); | |
| 224 return RV_OK; | |
| 225 } | |
| 226 else | |
| 227 { | |
| 228 | |
| 229 while(p!=NULL) | |
| 230 { | |
| 231 if (p->next_p==port_p) | |
| 232 { | |
| 233 /* The instance to deleted has been found */ | |
| 234 if (port_p->next_p==NULL) | |
| 235 { | |
| 236 /* The instance to delete is the last instance of the chain */ | |
| 237 p->next_p=NULL; | |
| 238 } | |
| 239 else | |
| 240 { | |
| 241 p->next_p=port_p->next_p; | |
| 242 } | |
| 243 | |
| 244 rvf_free_buf(port_p); | |
| 245 return RV_OK; | |
| 246 | |
| 247 } | |
| 248 p=p->next_p; | |
| 249 | |
| 250 } /* end of the while loop */ | |
| 251 // END : THIS SECTION MUST BE PROTECTTED BY A SEMAPHORE !!!!!! | |
| 252 | |
| 253 /* The device has not been found */ | |
| 254 return RV_INTERNAL_ERR; | |
| 255 | |
| 256 }/* end of the if/else */ | |
| 257 } | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 /****************************************************************************** | |
| 264 * Function name: atp_get_port | |
| 265 * | |
| 266 * Description : provides the pointer pointing on the proper port structure | |
| 267 * value | |
| 268 * | |
| 269 * Parameters : - sw_id : SW entity ID related to the port | |
| 270 * - port_nb : associated port number | |
| 271 * - &port_p : output : pointer on the found port structure | |
| 272 * - &sw_nd : output : indicate which of the 2 sw entity of the port has been found | |
| 273 * | |
| 274 * Return : Standard error flag from BT | |
| 275 * If OK, returns RV_OK. If port not found, return RV_INTERNAL_ERR. | |
| 276 * | |
| 277 * History : 0.1 (1-Marsh-2000) - Created / E.Baissus | |
| 278 * | |
| 279 ******************************************************************************/ | |
| 280 | |
| 281 T_ATP_RET atp_get_port(T_ATP_SW_ENTITY_ID sw_id, T_ATP_PORT_NB port_nb, T_ATP_PORT_STRUCT **port_found_pp, T_ATP_SW_NB *sw_nb_p) | |
| 282 { | |
| 283 for (*port_found_pp = atp_first_port_p; | |
| 284 *port_found_pp != NULL; | |
| 285 *port_found_pp = (*port_found_pp)->next_p) | |
| 286 { | |
| 287 if ((((*port_found_pp)->port_info[0]).sw_id == sw_id) && \ | |
| 288 (((*port_found_pp)->port_info[0]).port_nb == port_nb)) | |
| 289 { | |
| 290 /* The port instance has been found : sw_nb = 0 (initiator) */ | |
| 291 *sw_nb_p = 0; | |
| 292 return (RV_OK); | |
| 293 } | |
| 294 if ((((*port_found_pp)->port_info[1]).sw_id == sw_id) && \ | |
| 295 (((*port_found_pp)->port_info[1]).port_nb == port_nb)) | |
| 296 { | |
| 297 /* The port instance has been found : sw_nb = 1 (target) */ | |
| 298 *sw_nb_p = 1; | |
| 299 return (RV_OK); | |
| 300 } | |
| 301 } | |
| 302 return (RV_INVALID_PARAMETER); | |
| 303 } | |
| 304 | |
| 305 | |
| 306 /****************************************************************************** | |
| 307 * Function name: atp_delete_all_port | |
| 308 * | |
| 309 * Description : delete all the ports | |
| 310 * | |
| 311 * Parameters : | |
| 312 * | |
| 313 * Return : Standard error flag | |
| 314 * If OK, returns RV_OK | |
| 315 * | |
| 316 * History : 0.1 (1-Marsh-2000) - Created / E.Baissus | |
| 317 * | |
| 318 ******************************************************************************/ | |
| 319 T_ATP_RET atp_delete_all_port(void) | |
| 320 { | |
| 321 T_ATP_PORT_STRUCT *p,*next_p; | |
| 322 T_ATP_RET return_status = RV_OK; | |
| 323 | |
| 324 p=atp_first_port_p; | |
| 325 while((p != NULL) && (return_status == RV_OK)) | |
| 326 { | |
| 327 next_p = p->next_p; | |
| 328 return_status = atp_delete_port(p); | |
| 329 p=next_p; | |
| 330 } | |
| 331 return return_status; | |
| 332 } | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 /****************************************************************************** | |
| 338 * Function name: atp_send_message | |
| 339 * | |
| 340 * Description : Generic function to send message | |
| 341 * | |
| 342 * Parameters : | |
| 343 * | |
| 344 * Return : RV_OK | |
| 345 * | |
| 346 * History : 0.1 (1-Marsh-2000) - Created | |
| 347 * 0.15 (15-Marsh-2000) - Added possibility to send to a mail box | |
| 348 * | |
| 349 ******************************************************************************/ | |
| 350 T_ATP_RET atp_send_message(T_ATP_CALLBACK path,T_ATP_MESSAGE * message_p) | |
| 351 { | |
| 352 | |
| 353 if (path.callback_func!= NULL) | |
| 354 { | |
| 355 path.callback_func((void *) message_p); | |
| 356 /* It is up to the target id to free the message buffer later on !!!!*/ | |
| 357 return RV_OK; | |
| 358 } | |
| 359 else | |
| 360 { | |
| 361 return rvf_send_msg(path.addr_id,(void *) message_p); | |
| 362 } | |
| 363 | |
| 364 } | |
| 365 | |
| 366 | |
| 367 |
