FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/serial/serialswitch.c @ 143:afceeeb2cba1
Our nuc-fw is destined to become gsm-fw, so I went ahead and did the big hg mv
| author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
|---|---|
| date | Tue, 12 Nov 2013 05:35:48 +0000 |
| parents | nuc-fw/serial/serialswitch.c@e40d8661ecab |
| children |
comparison
equal
deleted
inserted
replaced
| 142:15d5977390c2 | 143:afceeeb2cba1 |
|---|---|
| 1 /******************************************************************************* | |
| 2 * | |
| 3 * SERIALSWITCH.C | |
| 4 * | |
| 5 * This module allows managing the use of the serial ports of TI GSM Evaluation | |
| 6 * Boards. | |
| 7 * An application may have to send several serial data flows. The board on which | |
| 8 * the application is running may have one or several devices. The purpose of | |
| 9 * this module is to establish connections between the serial data flows and the | |
| 10 * serial devices at runtime, when the application is started. | |
| 11 * | |
| 12 * (C) Texas Instruments 1999 - 2003 | |
| 13 * | |
| 14 ******************************************************************************/ | |
| 15 | |
| 16 #define __SERIALSWITCH_C__ | |
| 17 | |
| 18 #define __STANDARD_H__ /* Avoid to define UBYTE, SYS_UWORD16 and UINT32. */ | |
| 19 | |
| 20 #include "../include/config.h" | |
| 21 #include "../include/sys_types.h" | |
| 22 #include "../nucleus/nucleus.h" | |
| 23 | |
| 24 #include "serialswitch.h" | |
| 25 | |
| 26 #include "uart.h" | |
| 27 #include "uartfax.h" | |
| 28 | |
| 29 #include "../bsp/mem.h" | |
| 30 | |
| 31 #include <string.h> /* needed for memcmp & memset */ | |
| 32 | |
| 33 #if SERIAL_DYNAMIC_SWITCH | |
| 34 #include "ffs/ffs.h" | |
| 35 #include "rvf/rvf_api.h" | |
| 36 #include "inth/iq.h" | |
| 37 #include "rvt/rvt_def_i.h" /* needed for Riviera/Layer1 Trace's callback function */ | |
| 38 #endif | |
| 39 | |
| 40 #if defined(BTEMOBILE) | |
| 41 #include "hci_ser.h" | |
| 42 #endif | |
| 43 | |
| 44 #define DUMMY_DEVICE (0) | |
| 45 | |
| 46 #define IIR (0x02) /* UART interrupt ident. register - Read only */ | |
| 47 #define SCR (0x10) /* UART suppl. control register - Read/Write */ | |
| 48 #define SSR (0x11) /* UART suppl. status register - Read only */ | |
| 49 | |
| 50 /* | |
| 51 * Interrupt identification register. | |
| 52 * Bit 0 is set to 0 if an IT is pending. | |
| 53 * Bits 1 and 2 are used to identify the IT. | |
| 54 */ | |
| 55 | |
| 56 #define IIR_BITS_USED (0x07) | |
| 57 #define IT_NOT_PENDING (0x01) | |
| 58 | |
| 59 /* | |
| 60 * Supplementary Control Register | |
| 61 */ | |
| 62 | |
| 63 #define RX_CTS_WAKE_UP_ENABLE_BIT (4) | |
| 64 | |
| 65 /* | |
| 66 * Supplementary Status Register | |
| 67 */ | |
| 68 | |
| 69 #define RX_CTS_WAKE_UP_STS (0x02) /* Wake-up interrupt occurred */ | |
| 70 | |
| 71 /* | |
| 72 * This macro allows to read an UART register. | |
| 73 */ | |
| 74 | |
| 75 #define READ_UART_REGISTER(UART,REG) \ | |
| 76 *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG))) | |
| 77 | |
| 78 | |
| 79 /* | |
| 80 * This macro allows to disable the UART's wake-up interrupt. | |
| 81 */ | |
| 82 | |
| 83 #define DISABLE_WAKE_UP_INTERRUPT(UART) \ | |
| 84 *((volatile SYS_UWORD8 *) ((UART)->base_address + SCR)) &= \ | |
| 85 ~(1 << (RX_CTS_WAKE_UP_ENABLE_BIT)); | |
| 86 | |
| 87 /* | |
| 88 * Wake-up time duration in seconds and in number of TDMAs. | |
| 89 * 1 TDMA = (6 / 1300) s = 0.004615 s (= 4.615 ms). | |
| 90 */ | |
| 91 | |
| 92 #define WAKE_UP_TIME_DURATION (10) /* 10 seconds */ | |
| 93 #define WAKE_UP_TIME_IN_TDMA (WAKE_UP_TIME_DURATION * 1300 / 6) | |
| 94 | |
| 95 | |
| 96 /* | |
| 97 * Global uartswitch variable as read from FFS. | |
| 98 * It is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART | |
| 99 * and NUMBER_OF_BT_UART have the same values. | |
| 100 */ | |
| 101 | |
| 102 #define DUMMY ('0') | |
| 103 #define G23_PANEL ('G') | |
| 104 #define RIVIERA_TRACE_MUX ('R') | |
| 105 #define FD_AT_COMMAND ('D') | |
| 106 #define BLUETOOTH_HCI ('B') | |
| 107 | |
| 108 #if (CHIPSET == 12) | |
| 109 char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY, DUMMY}; | |
| 110 #else | |
| 111 char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY}; | |
| 112 #endif | |
| 113 static SYS_UWORD16 serial_cfg = 0x0048; /* All dummies */ | |
| 114 | |
| 115 #if SERIAL_DYNAMIC_SWITCH | |
| 116 /* | |
| 117 * Global variables used for Dynamic Switch. | |
| 118 */ | |
| 119 | |
| 120 static char ser_new_cfg[NUMBER_OF_TR_UART] = {DUMMY, DUMMY}; | |
| 121 const static char uart_config_file[] = "/sys/uartswitch"; | |
| 122 static SYS_BOOL dynamic_switch = 0; | |
| 123 | |
| 124 /* Import Serial Info structure. */ | |
| 125 extern T_AppliSerialInfo appli_ser_cfg_info; | |
| 126 #endif | |
| 127 | |
| 128 /* | |
| 129 * Types of flows supported. | |
| 130 */ | |
| 131 | |
| 132 typedef enum { | |
| 133 TRACE_FLOW, | |
| 134 FAX_DATA_FLOW, | |
| 135 BLUETOOTH_HCI_FLOW | |
| 136 } t_flow_type; | |
| 137 | |
| 138 /* | |
| 139 * For each serial data flow, a set of function pointers allows calling the | |
| 140 * functions associated to a serial device. | |
| 141 */ | |
| 142 | |
| 143 typedef struct s_tr_functions { | |
| 144 | |
| 145 T_tr_UartId device; | |
| 146 | |
| 147 void (*tr_Init) (T_tr_UartId device, | |
| 148 T_tr_Baudrate baudrate, | |
| 149 void (callback_function (void))); | |
| 150 | |
| 151 SYS_UWORD32 (*tr_ReadNChars) (T_tr_UartId device, | |
| 152 char *buffer, | |
| 153 SYS_UWORD32 chars_to_read); | |
| 154 | |
| 155 SYS_UWORD32 (*tr_ReadNBytes) (T_tr_UartId device, | |
| 156 char *buffer, | |
| 157 SYS_UWORD32 chars_to_read, | |
| 158 SYS_BOOL *eof_detected); | |
| 159 | |
| 160 SYS_UWORD32 (*tr_WriteNChars) (T_tr_UartId device, | |
| 161 char *buffer, | |
| 162 SYS_UWORD32 chars_to_write); | |
| 163 | |
| 164 SYS_UWORD32 (*tr_EncapsulateNChars) (T_tr_UartId device, | |
| 165 char *buffer, | |
| 166 SYS_UWORD32 chars_to_write); | |
| 167 | |
| 168 SYS_UWORD32 (*tr_WriteNBytes) (T_tr_UartId device, | |
| 169 SYS_UWORD8 *buffer, | |
| 170 SYS_UWORD32 chars_to_write); | |
| 171 | |
| 172 void (*tr_WriteChar) (T_tr_UartId device, | |
| 173 char character); | |
| 174 | |
| 175 void (*tr_WriteString) (T_tr_UartId device, | |
| 176 char *buffer); | |
| 177 | |
| 178 SYS_BOOL (*tr_EnterSleep) (T_tr_UartId device); | |
| 179 | |
| 180 void (*tr_WakeUp) (T_tr_UartId device); | |
| 181 | |
| 182 } t_tr_functions; | |
| 183 | |
| 184 /* | |
| 185 * Set of function pointers for fax & data functions. | |
| 186 */ | |
| 187 | |
| 188 typedef struct s_fd_functions { | |
| 189 | |
| 190 T_fd_UartId device; | |
| 191 | |
| 192 T_FDRET (*fd_Initialize) (T_fd_UartId device); | |
| 193 | |
| 194 T_FDRET (*fd_Enable) (T_fd_UartId device, | |
| 195 SYS_BOOL enable); | |
| 196 | |
| 197 T_FDRET (*fd_SetComPar) (T_fd_UartId device, | |
| 198 T_baudrate baudrate, | |
| 199 T_bitsPerCharacter bpc, | |
| 200 T_stopBits sb, | |
| 201 T_parity parity); | |
| 202 | |
| 203 T_FDRET (*fd_SetBuffer) (T_fd_UartId device, | |
| 204 SYS_UWORD16 bufSize, | |
| 205 SYS_UWORD16 rxThreshold, | |
| 206 SYS_UWORD16 txThreshold); | |
| 207 | |
| 208 T_FDRET (*fd_SetFlowCtrl) (T_fd_UartId device, | |
| 209 T_flowCtrlMode fcMode, | |
| 210 SYS_UWORD8 XON, | |
| 211 SYS_UWORD8 XOFF); | |
| 212 | |
| 213 T_FDRET (*fd_SetEscape) (T_fd_UartId device, | |
| 214 SYS_UWORD8 escChar, | |
| 215 SYS_UWORD16 guardPeriod); | |
| 216 | |
| 217 T_FDRET (*fd_InpAvail) (T_fd_UartId device); | |
| 218 | |
| 219 T_FDRET (*fd_OutpAvail) (T_fd_UartId device); | |
| 220 | |
| 221 T_FDRET (*fd_EnterSleep) (T_fd_UartId device); | |
| 222 | |
| 223 T_FDRET (*fd_WakeUp) (T_fd_UartId device); | |
| 224 | |
| 225 T_FDRET (*fd_ReadData) (T_fd_UartId device, | |
| 226 T_suspendMode suspend, | |
| 227 void (readOutFunc (SYS_BOOL cldFromIrq, | |
| 228 T_reInstMode *reInstall, | |
| 229 SYS_UWORD8 nsource, | |
| 230 SYS_UWORD8 *source[], | |
| 231 SYS_UWORD16 size[], | |
| 232 SYS_UWORD32 state))); | |
| 233 | |
| 234 T_FDRET (*fd_WriteData) (T_fd_UartId device, | |
| 235 T_suspendMode suspend, | |
| 236 void (writeInFunc (SYS_BOOL cldFromIrq, | |
| 237 T_reInstMode *reInstall, | |
| 238 SYS_UWORD8 ndest, | |
| 239 SYS_UWORD8 *dest[], | |
| 240 SYS_UWORD16 size[]))); | |
| 241 | |
| 242 T_FDRET (*fd_StopRec) (T_fd_UartId device); | |
| 243 | |
| 244 T_FDRET (*fd_StartRec) (T_fd_UartId device); | |
| 245 | |
| 246 T_FDRET (*fd_GetLineState) (T_fd_UartId device, | |
| 247 SYS_UWORD32 *state); | |
| 248 | |
| 249 T_FDRET (*fd_SetLineState) (T_fd_UartId device, | |
| 250 SYS_UWORD32 state, | |
| 251 SYS_UWORD32 mask); | |
| 252 | |
| 253 T_FDRET (*fd_CheckXEmpty) (T_fd_UartId device); | |
| 254 | |
| 255 } t_fd_functions; | |
| 256 | |
| 257 #ifdef BTEMOBILE | |
| 258 /* | |
| 259 * Set of function pointers for Bluetooth HCI functions. | |
| 260 */ | |
| 261 | |
| 262 typedef struct s_bt_functions { | |
| 263 | |
| 264 T_bt_UartId device; | |
| 265 | |
| 266 T_HCI_RET (*bt_Init) (T_bt_UartId uart_device); | |
| 267 | |
| 268 T_HCI_RET (*bt_Start) (void); | |
| 269 | |
| 270 T_HCI_RET (*bt_Stop) (void); | |
| 271 | |
| 272 T_HCI_RET (*bt_Kill) (void); | |
| 273 | |
| 274 T_HCI_RET (*bt_SetBaudrate) (UINT8 baudrate); | |
| 275 | |
| 276 T_HCI_RET (*bt_TransmitPacket) (void *uart_tx_buffer); | |
| 277 | |
| 278 SYS_BOOL (*bt_EnterSleep) (void); | |
| 279 | |
| 280 void (*bt_WakeUp) (void); | |
| 281 | |
| 282 } t_bt_functions; | |
| 283 #endif | |
| 284 | |
| 285 /* | |
| 286 * Prototypes of dummy functions. | |
| 287 * Dummy functions for Trace. | |
| 288 */ | |
| 289 | |
| 290 static void dummy_tr_Init (T_tr_UartId device, | |
| 291 T_tr_Baudrate baudrate, | |
| 292 void (callback_function (void))); | |
| 293 | |
| 294 static SYS_UWORD32 dummy_tr_ReadNChars (T_tr_UartId device, | |
| 295 char *buffer, | |
| 296 SYS_UWORD32 chars_to_read); | |
| 297 | |
| 298 static SYS_UWORD32 dummy_tr_ReadNBytes (T_tr_UartId device, | |
| 299 char *buffer, | |
| 300 SYS_UWORD32 chars_to_read, | |
| 301 SYS_BOOL *eof_detected); | |
| 302 | |
| 303 static SYS_UWORD32 dummy_tr_WriteNChars (T_tr_UartId device, | |
| 304 char *buffer, | |
| 305 SYS_UWORD32 chars_to_write); | |
| 306 | |
| 307 static SYS_UWORD32 dummy_tr_EncapsulateNChars (T_tr_UartId device, | |
| 308 char *buffer, | |
| 309 SYS_UWORD32 chars_to_write); | |
| 310 | |
| 311 static SYS_UWORD32 dummy_tr_WriteNBytes (T_tr_UartId device, | |
| 312 SYS_UWORD8 *buffer, | |
| 313 SYS_UWORD32 chars_to_write); | |
| 314 | |
| 315 static void dummy_tr_WriteChar (T_tr_UartId device, | |
| 316 char character); | |
| 317 | |
| 318 static void dummy_tr_WriteString (T_tr_UartId device, | |
| 319 char *buffer); | |
| 320 | |
| 321 static SYS_BOOL dummy_tr_EnterSleep (T_tr_UartId device); | |
| 322 | |
| 323 static void dummy_tr_WakeUp (T_tr_UartId device); | |
| 324 | |
| 325 /* | |
| 326 * Dummy functions for Fax & Data. | |
| 327 */ | |
| 328 | |
| 329 static T_FDRET dummy_fd_Init (T_fd_UartId device); | |
| 330 | |
| 331 static T_FDRET dummy_fd_Enable (T_fd_UartId device, | |
| 332 SYS_BOOL enable); | |
| 333 | |
| 334 static T_FDRET dummy_fd_SetComPar (T_fd_UartId device, | |
| 335 T_baudrate baudrate, | |
| 336 T_bitsPerCharacter bpc, | |
| 337 T_stopBits sb, | |
| 338 T_parity parity); | |
| 339 | |
| 340 static T_FDRET dummy_fd_SetBuffer (T_fd_UartId device, | |
| 341 SYS_UWORD16 bufSize, | |
| 342 SYS_UWORD16 rxThreshold, | |
| 343 SYS_UWORD16 txThreshold); | |
| 344 | |
| 345 static T_FDRET dummy_fd_SetFlowCtrl (T_fd_UartId device, | |
| 346 T_flowCtrlMode fcMode, | |
| 347 SYS_UWORD8 XON, | |
| 348 SYS_UWORD8 XOFF); | |
| 349 | |
| 350 static T_FDRET dummy_fd_SetEscape (T_fd_UartId device, | |
| 351 SYS_UWORD8 escChar, | |
| 352 SYS_UWORD16 guardPeriod); | |
| 353 | |
| 354 static T_FDRET dummy_fd_InpAvail (T_fd_UartId device); | |
| 355 | |
| 356 static T_FDRET dummy_fd_OutpAvail (T_fd_UartId device); | |
| 357 | |
| 358 static T_FDRET dummy_fd_EnterSleep (T_fd_UartId device); | |
| 359 | |
| 360 static T_FDRET dummy_fd_WakeUp (T_fd_UartId device); | |
| 361 | |
| 362 static T_FDRET dummy_fd_ReadData (T_fd_UartId device, | |
| 363 T_suspendMode suspend, | |
| 364 void (readOutFunc (SYS_BOOL cldFromIrq, | |
| 365 T_reInstMode *reInstall, | |
| 366 SYS_UWORD8 nsource, | |
| 367 SYS_UWORD8 *source[], | |
| 368 SYS_UWORD16 size[], | |
| 369 SYS_UWORD32 state))); | |
| 370 | |
| 371 static T_FDRET dummy_fd_WriteData (T_fd_UartId device, | |
| 372 T_suspendMode suspend, | |
| 373 void (writeInFunc (SYS_BOOL cldFromIrq, | |
| 374 T_reInstMode *reInstall, | |
| 375 SYS_UWORD8 ndest, | |
| 376 SYS_UWORD8 *dest[], | |
| 377 SYS_UWORD16 size[]))); | |
| 378 | |
| 379 static T_FDRET dummy_fd_StopRec (T_fd_UartId device); | |
| 380 | |
| 381 static T_FDRET dummy_fd_StartRec (T_fd_UartId device); | |
| 382 | |
| 383 static T_FDRET dummy_fd_GetLineState (T_fd_UartId device, | |
| 384 SYS_UWORD32 *state); | |
| 385 | |
| 386 static T_FDRET dummy_fd_SetLineState (T_fd_UartId device, | |
| 387 SYS_UWORD32 state, | |
| 388 SYS_UWORD32 mask); | |
| 389 | |
| 390 static T_FDRET dummy_fd_CheckXEmpty (T_fd_UartId device); | |
| 391 | |
| 392 #ifdef BTEMOBILE | |
| 393 /* | |
| 394 * Dummy functions for Bluetooth HCI. | |
| 395 */ | |
| 396 | |
| 397 static T_HCI_RET dummy_bt_Init (T_bt_UartId uart_device); | |
| 398 | |
| 399 static T_HCI_RET dummy_bt_Start (void); | |
| 400 | |
| 401 static T_HCI_RET dummy_bt_Stop (void); | |
| 402 | |
| 403 static T_HCI_RET dummy_bt_Kill (void); | |
| 404 | |
| 405 static T_HCI_RET dummy_bt_SetBaudrate (UINT8 baudrate); | |
| 406 | |
| 407 static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer); | |
| 408 | |
| 409 static SYS_BOOL dummy_bt_EnterSleep (void); | |
| 410 | |
| 411 static void dummy_bt_WakeUp (void); | |
| 412 | |
| 413 #endif | |
| 414 | |
| 415 /* | |
| 416 * Constants tables representing the various possible configurations | |
| 417 * for Trace, Fax & Data and Bluetooth HCI according to the different devices. | |
| 418 * Constant table for Trace using no device. | |
| 419 */ | |
| 420 | |
| 421 static const t_tr_functions dummy_trace = { | |
| 422 | |
| 423 DUMMY_DEVICE, | |
| 424 dummy_tr_Init, | |
| 425 dummy_tr_ReadNChars, | |
| 426 dummy_tr_ReadNBytes, | |
| 427 dummy_tr_WriteNChars, | |
| 428 dummy_tr_EncapsulateNChars, | |
| 429 dummy_tr_WriteNBytes, | |
| 430 dummy_tr_WriteChar, | |
| 431 dummy_tr_WriteString, | |
| 432 dummy_tr_EnterSleep, | |
| 433 dummy_tr_WakeUp | |
| 434 }; | |
| 435 | |
| 436 /* | |
| 437 * Constant table for Trace using UART IrDA. | |
| 438 */ | |
| 439 | |
| 440 static const t_tr_functions uart_irda_trace = { | |
| 441 | |
| 442 UA_UART_0, | |
| 443 UA_Init, | |
| 444 UA_ReadNChars, | |
| 445 UA_ReadNBytes, | |
| 446 UA_WriteNChars, | |
| 447 UA_EncapsulateNChars, | |
| 448 UA_WriteNBytes, | |
| 449 UA_WriteChar, | |
| 450 UA_WriteString, | |
| 451 UA_EnterSleep, | |
| 452 UA_WakeUp | |
| 453 }; | |
| 454 | |
| 455 /* | |
| 456 * Constant table for Trace using UART Modem. | |
| 457 */ | |
| 458 | |
| 459 static const t_tr_functions uart_modem_trace = { | |
| 460 | |
| 461 UA_UART_1, | |
| 462 UA_Init, | |
| 463 UA_ReadNChars, | |
| 464 UA_ReadNBytes, | |
| 465 UA_WriteNChars, | |
| 466 UA_EncapsulateNChars, | |
| 467 UA_WriteNBytes, | |
| 468 UA_WriteChar, | |
| 469 UA_WriteString, | |
| 470 UA_EnterSleep, | |
| 471 UA_WakeUp | |
| 472 }; | |
| 473 | |
| 474 #if (CHIPSET == 12) | |
| 475 /* | |
| 476 * Constant table for Trace using UART Modem2. | |
| 477 */ | |
| 478 | |
| 479 static const t_tr_functions uart_modem2_trace = { | |
| 480 | |
| 481 UA_UART_2, | |
| 482 UA_Init, | |
| 483 UA_ReadNChars, | |
| 484 UA_ReadNBytes, | |
| 485 UA_WriteNChars, | |
| 486 UA_EncapsulateNChars, | |
| 487 UA_WriteNBytes, | |
| 488 UA_WriteChar, | |
| 489 UA_WriteString, | |
| 490 UA_EnterSleep, | |
| 491 UA_WakeUp | |
| 492 }; | |
| 493 #endif | |
| 494 | |
| 495 /* | |
| 496 * Constant table for Fax & Data using no device. | |
| 497 */ | |
| 498 | |
| 499 static const t_fd_functions dummy_fax_data = { | |
| 500 | |
| 501 DUMMY_DEVICE, | |
| 502 dummy_fd_Init, | |
| 503 dummy_fd_Enable, | |
| 504 dummy_fd_SetComPar, | |
| 505 dummy_fd_SetBuffer, | |
| 506 dummy_fd_SetFlowCtrl, | |
| 507 dummy_fd_SetEscape, | |
| 508 dummy_fd_InpAvail, | |
| 509 dummy_fd_OutpAvail, | |
| 510 dummy_fd_EnterSleep, | |
| 511 dummy_fd_WakeUp, | |
| 512 dummy_fd_ReadData, | |
| 513 dummy_fd_WriteData, | |
| 514 dummy_fd_StopRec, | |
| 515 dummy_fd_StartRec, | |
| 516 dummy_fd_GetLineState, | |
| 517 dummy_fd_SetLineState, | |
| 518 dummy_fd_CheckXEmpty | |
| 519 }; | |
| 520 | |
| 521 /* | |
| 522 * Constant table for Fax & Data using UART Modem. | |
| 523 */ | |
| 524 | |
| 525 #if CONFIG_FDMODEM | |
| 526 static const t_fd_functions uart_modem_fax_data = { | |
| 527 | |
| 528 UAF_UART_1, | |
| 529 UAF_Init, | |
| 530 UAF_Enable, | |
| 531 UAF_SetComPar, | |
| 532 UAF_SetBuffer, | |
| 533 UAF_SetFlowCtrl, | |
| 534 UAF_SetEscape, | |
| 535 UAF_InpAvail, | |
| 536 UAF_OutpAvail, | |
| 537 UAF_EnterSleep, | |
| 538 UAF_WakeUp, | |
| 539 UAF_ReadData, | |
| 540 UAF_WriteData, | |
| 541 UAF_StopRec, | |
| 542 UAF_StartRec, | |
| 543 UAF_GetLineState, | |
| 544 UAF_SetLineState, | |
| 545 UAF_CheckXEmpty | |
| 546 }; | |
| 547 #endif | |
| 548 | |
| 549 #ifdef BTEMOBILE | |
| 550 /* | |
| 551 * Constant table for BT HCI using no device. | |
| 552 */ | |
| 553 | |
| 554 static const t_bt_functions dummy_bt_hci = { | |
| 555 | |
| 556 DUMMY_DEVICE, | |
| 557 dummy_bt_Init, | |
| 558 dummy_bt_Start, | |
| 559 dummy_bt_Stop, | |
| 560 dummy_bt_Kill, | |
| 561 dummy_bt_SetBaudrate, | |
| 562 dummy_bt_TransmitPacket, | |
| 563 dummy_bt_EnterSleep, | |
| 564 dummy_bt_WakeUp | |
| 565 }; | |
| 566 | |
| 567 /* | |
| 568 * Constant table for BT HCI using UART IrDA. | |
| 569 */ | |
| 570 | |
| 571 static const t_bt_functions uart_irda_bt_hci = { | |
| 572 | |
| 573 UABT_UART_0, | |
| 574 hciu_init, | |
| 575 hciu_start, | |
| 576 hciu_stop, | |
| 577 hciu_kill, | |
| 578 hciu_set_baudrate, | |
| 579 hciu_transmit_packet, | |
| 580 hciu_enter_sleep, | |
| 581 hciu_wakeup | |
| 582 }; | |
| 583 | |
| 584 /* | |
| 585 * Constant table for BT HCI using UART Modem. | |
| 586 */ | |
| 587 | |
| 588 static const t_bt_functions uart_modem_bt_hci = { | |
| 589 | |
| 590 UABT_UART_1, | |
| 591 hciu_init, | |
| 592 hciu_start, | |
| 593 hciu_stop, | |
| 594 hciu_kill, | |
| 595 hciu_set_baudrate, | |
| 596 hciu_transmit_packet, | |
| 597 hciu_enter_sleep, | |
| 598 hciu_wakeup | |
| 599 }; | |
| 600 | |
| 601 #if (CHIPSET == 12) | |
| 602 /* | |
| 603 * Constant table for BT HCI using UART Modem2. | |
| 604 */ | |
| 605 | |
| 606 static const t_bt_functions uart_modem2_bt_hci = { | |
| 607 | |
| 608 UABT_UART_2, | |
| 609 hciu_init, | |
| 610 hciu_start, | |
| 611 hciu_stop, | |
| 612 hciu_kill, | |
| 613 hciu_set_baudrate, | |
| 614 hciu_transmit_packet, | |
| 615 hciu_go_to_sleep, | |
| 616 hciu_wakeup | |
| 617 }; | |
| 618 #endif | |
| 619 #endif | |
| 620 | |
| 621 #if SERIAL_DYNAMIC_SWITCH | |
| 622 /* | |
| 623 * Structure used to store initialization parameters related to the AT-Cmd/F&D flow. | |
| 624 * Numbers of paramaters (in case of multiple calls) have been figured out from | |
| 625 * Condat AT-Command/F&D flow initialization. | |
| 626 */ | |
| 627 | |
| 628 typedef struct s_data_flow { | |
| 629 | |
| 630 /* | |
| 631 * Parameters related to SER_fd_SetComPar (2 calls) | |
| 632 */ | |
| 633 T_baudrate baudrate[2]; | |
| 634 T_bitsPerCharacter bpc[2]; | |
| 635 T_stopBits sb[2]; | |
| 636 T_parity parity[2]; | |
| 637 | |
| 638 /* | |
| 639 * Parameters related to SER_fd_SetBuffer | |
| 640 */ | |
| 641 SYS_WORD16 bufSize; | |
| 642 SYS_WORD16 rxThreshold; | |
| 643 SYS_WORD16 txThreshold; | |
| 644 | |
| 645 /* | |
| 646 * Parameters related to SER_fd_SetFlowCtrl (2 calls) | |
| 647 */ | |
| 648 T_flowCtrlMode fcMode[2]; | |
| 649 SYS_UWORD8 XON[2]; | |
| 650 SYS_UWORD8 XOFF[2]; | |
| 651 | |
| 652 /* | |
| 653 * Parameters related to SER_fd_SetEscape (2 calls) | |
| 654 */ | |
| 655 SYS_UWORD8 escChar[2]; | |
| 656 SYS_UWORD16 guardPeriod[2]; | |
| 657 | |
| 658 /* | |
| 659 * Parameters related to SER_fd_SetLineState (4 calls) | |
| 660 */ | |
| 661 SYS_UWORD32 state[4]; | |
| 662 SYS_UWORD32 mask[4]; | |
| 663 | |
| 664 /* | |
| 665 * Parameters related to SER_fd_ReadData | |
| 666 */ | |
| 667 T_suspendMode suspend_rd; | |
| 668 void (*readOutFunc) (SYS_BOOL cldFromIrq, | |
| 669 T_reInstMode *reInstall, | |
| 670 SYS_UWORD8 nsource, | |
| 671 SYS_UWORD8 *source[], | |
| 672 SYS_UWORD16 size[], | |
| 673 SYS_UWORD32 state); | |
| 674 /* | |
| 675 * Parameters related to SER_fd_WriteData | |
| 676 */ | |
| 677 T_suspendMode suspend_wr; | |
| 678 void (*writeInFunc) (SYS_BOOL cldFromIrq, | |
| 679 T_reInstMode *reInstall, | |
| 680 SYS_UWORD8 ndest, | |
| 681 SYS_UWORD8 *dest[], | |
| 682 SYS_UWORD16 size[]); | |
| 683 | |
| 684 } t_data_flow; | |
| 685 #endif /* (defined BTEMOBILE && (CHIPSET != 12)) */ | |
| 686 | |
| 687 /* | |
| 688 * UART structure used for UARTs. | |
| 689 */ | |
| 690 | |
| 691 typedef struct s_uart { | |
| 692 | |
| 693 SYS_UWORD32 base_address; | |
| 694 SYS_BOOL device_used; | |
| 695 SYS_BOOL deep_sleep_set_up; | |
| 696 t_flow_type flow_type; | |
| 697 SYS_WORD16 flow_id; | |
| 698 void (*interrupt_handler) (int uart_id, | |
| 699 SYS_UWORD8 interrupt_status); | |
| 700 | |
| 701 } t_uart; | |
| 702 | |
| 703 static const t_tr_functions *tr_functions[SER_MAX_NUMBER_OF_FLOWS]; | |
| 704 static const t_fd_functions *fd_functions; | |
| 705 | |
| 706 #ifdef BTEMOBILE | |
| 707 static const t_bt_functions *bt_functions; | |
| 708 #endif | |
| 709 | |
| 710 #if SERIAL_DYNAMIC_SWITCH | |
| 711 static SYS_BOOL uart_fd_initialized = 0; | |
| 712 #endif | |
| 713 | |
| 714 static SYS_UWORD8 fd_buffer[FD_MAX_BUFFER_SIZE]; | |
| 715 static SYS_BOOL fd_driver_enabled; | |
| 716 | |
| 717 #if SERIAL_DYNAMIC_SWITCH | |
| 718 static t_data_flow data_flow_parameters; | |
| 719 #else | |
| 720 static SYS_WORD16 bufSize; | |
| 721 #endif | |
| 722 | |
| 723 #if SERIAL_DYNAMIC_SWITCH | |
| 724 /* | |
| 725 * Variables used to count calls to SER_fd_XXX functions. | |
| 726 */ | |
| 727 | |
| 728 static SYS_UWORD8 fd_UAF_SetBuffer = 0; | |
| 729 static SYS_UWORD8 fd_UAF_SetEscape = 0; | |
| 730 static SYS_UWORD8 fd_UAF_SetComPar = 0; | |
| 731 static SYS_UWORD8 fd_UAF_SetFlowCtrl = 0; | |
| 732 static SYS_UWORD8 fd_UAF_ReadData = 0; | |
| 733 static SYS_UWORD8 fd_UAF_SetLineState = 0; | |
| 734 static SYS_UWORD8 fd_UAF_WriteData = 0; | |
| 735 #endif | |
| 736 | |
| 737 /* | |
| 738 * Timer used for duration control when UARTs are waked up by an interrupt or | |
| 739 * each time any new incoming characters are received; This timer prevents the | |
| 740 * system to enter deep sleep mode. | |
| 741 */ | |
| 742 | |
| 743 static NU_TIMER uart_sleep_timer; | |
| 744 SYS_BOOL uart_sleep_timer_enabled; | |
| 745 | |
| 746 /* | |
| 747 * HISR used to reset and restart the sleep timer from an UART use by a Trace | |
| 748 * flow in case of incoming characters. | |
| 749 */ | |
| 750 | |
| 751 #define TIMER_HISR_PRIORITY (2) | |
| 752 #define TIMER_HISR_STACK_SIZE (512) /* Bytes. */ | |
| 753 | |
| 754 static NU_HISR timer_hisr_ctrl_block; | |
| 755 static char timer_hisr_stack[TIMER_HISR_STACK_SIZE]; | |
| 756 | |
| 757 /* | |
| 758 * For next arrays, it is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART | |
| 759 * and NUMBER_OF_BT_UART have the same values. | |
| 760 * An index on an internal uart for trace, fax & data or bluetooth hci reffers | |
| 761 * to the same uart device. | |
| 762 */ | |
| 763 | |
| 764 static t_uart int_uart[NUMBER_OF_TR_UART]; | |
| 765 | |
| 766 #if ((CHIPSET == 2) || (CHIPSET == 3)) | |
| 767 static SYS_UWORD32 uart_spurious_interrupts; | |
| 768 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) | |
| 769 static SYS_UWORD32 uart_modem_spurious_interrupts; | |
| 770 static SYS_UWORD32 uart_irda_spurious_interrupts; | |
| 771 #endif | |
| 772 #if (CHIPSET == 12) | |
| 773 static SYS_UWORD32 uart_modem2_spurious_interrupts; | |
| 774 #endif | |
| 775 | |
| 776 static const SYS_UWORD32 uart_base_address[NUMBER_OF_TR_UART] = | |
| 777 { | |
| 778 MEM_UART_IRDA, | |
| 779 MEM_UART_MODEM | |
| 780 #if (CHIPSET == 12) | |
| 781 , MEM_UART_MODEM2 | |
| 782 #endif | |
| 783 }; | |
| 784 | |
| 785 | |
| 786 /******************************************************************************* | |
| 787 * | |
| 788 * dummy_tr_Init | |
| 789 * | |
| 790 * Purpose: No action. | |
| 791 * | |
| 792 * Parameters: See SER_tr_Init. | |
| 793 * | |
| 794 * Return: none | |
| 795 * | |
| 796 ******************************************************************************/ | |
| 797 | |
| 798 static void | |
| 799 dummy_tr_Init (T_tr_UartId device, | |
| 800 T_tr_Baudrate baudrate, | |
| 801 void (callback_function (void))) | |
| 802 { | |
| 803 /* | |
| 804 * No action. | |
| 805 */ | |
| 806 } | |
| 807 | |
| 808 /******************************************************************************* | |
| 809 * | |
| 810 * dummy_tr_ReadNChars | |
| 811 * | |
| 812 * Purpose: No action. | |
| 813 * | |
| 814 * Parameters: See SER_tr_ReadNChars. | |
| 815 * | |
| 816 * Return: 0 | |
| 817 * | |
| 818 ******************************************************************************/ | |
| 819 | |
| 820 static SYS_UWORD32 | |
| 821 dummy_tr_ReadNChars (T_tr_UartId device, | |
| 822 char *buffer, | |
| 823 SYS_UWORD32 chars_to_read) | |
| 824 { | |
| 825 return (0); | |
| 826 } | |
| 827 | |
| 828 /******************************************************************************* | |
| 829 * | |
| 830 * dummy_tr_ReadNBytes | |
| 831 * | |
| 832 * Purpose: No action. | |
| 833 * | |
| 834 * Parameters: See SER_tr_ReadNBytes. | |
| 835 * | |
| 836 * Return: 0 | |
| 837 * | |
| 838 ******************************************************************************/ | |
| 839 | |
| 840 static SYS_UWORD32 | |
| 841 dummy_tr_ReadNBytes (T_tr_UartId device, | |
| 842 char *buffer, | |
| 843 SYS_UWORD32 chars_to_read, | |
| 844 SYS_BOOL *eof_detected) | |
| 845 { | |
| 846 return (0); | |
| 847 } | |
| 848 | |
| 849 /******************************************************************************* | |
| 850 * | |
| 851 * dummy_tr_WriteNChars | |
| 852 * | |
| 853 * Purpose: No action. | |
| 854 * | |
| 855 * Parameters: See SER_tr_WriteNChars. | |
| 856 * | |
| 857 * Return: The number of character to write. | |
| 858 * | |
| 859 ******************************************************************************/ | |
| 860 | |
| 861 static SYS_UWORD32 | |
| 862 dummy_tr_WriteNChars (T_tr_UartId device, | |
| 863 char *buffer, | |
| 864 SYS_UWORD32 chars_to_write) | |
| 865 { | |
| 866 return (chars_to_write); | |
| 867 } | |
| 868 | |
| 869 /******************************************************************************* | |
| 870 * | |
| 871 * dummy_tr_EncapsulateNChars | |
| 872 * | |
| 873 * Purpose: No action. | |
| 874 * | |
| 875 * Parameters: See SER_tr_EncapsulateNChars. | |
| 876 * | |
| 877 * Return: The number of character to write. | |
| 878 * | |
| 879 ******************************************************************************/ | |
| 880 | |
| 881 static SYS_UWORD32 | |
| 882 dummy_tr_EncapsulateNChars (T_tr_UartId device, | |
| 883 char *buffer, | |
| 884 SYS_UWORD32 chars_to_write) | |
| 885 { | |
| 886 return (chars_to_write); | |
| 887 } | |
| 888 | |
| 889 /******************************************************************************* | |
| 890 * | |
| 891 * dummy_tr_WriteNBytes | |
| 892 * | |
| 893 * Purpose: No action. | |
| 894 * | |
| 895 * Parameters: See SER_tr_WriteNBytes. | |
| 896 * | |
| 897 * Return: The number of byte to write. | |
| 898 * | |
| 899 ******************************************************************************/ | |
| 900 | |
| 901 static SYS_UWORD32 | |
| 902 dummy_tr_WriteNBytes (T_tr_UartId device, | |
| 903 SYS_UWORD8 *buffer, | |
| 904 SYS_UWORD32 chars_to_write) | |
| 905 { | |
| 906 return (chars_to_write); | |
| 907 } | |
| 908 | |
| 909 /******************************************************************************* | |
| 910 * | |
| 911 * dummy_tr_WriteChar | |
| 912 * | |
| 913 * Purpose: No action. | |
| 914 * | |
| 915 * Parameters: See SER_tr_WriteChar. | |
| 916 * | |
| 917 * Return: none | |
| 918 * | |
| 919 ******************************************************************************/ | |
| 920 | |
| 921 static void | |
| 922 dummy_tr_WriteChar (T_tr_UartId device, | |
| 923 char character) | |
| 924 { | |
| 925 /* | |
| 926 * No action. | |
| 927 */ | |
| 928 } | |
| 929 | |
| 930 /******************************************************************************* | |
| 931 * | |
| 932 * dummy_tr_WriteString | |
| 933 * | |
| 934 * Purpose: No action. | |
| 935 * | |
| 936 * Parameters: See SER_tr_WriteString. | |
| 937 * | |
| 938 * Return: none | |
| 939 * | |
| 940 ******************************************************************************/ | |
| 941 | |
| 942 static void | |
| 943 dummy_tr_WriteString (T_tr_UartId device, | |
| 944 char *buffer) | |
| 945 { | |
| 946 /* | |
| 947 * No action. | |
| 948 */ | |
| 949 } | |
| 950 | |
| 951 /******************************************************************************* | |
| 952 * | |
| 953 * dummy_tr_EnterSleep | |
| 954 * | |
| 955 * Purpose: No action. | |
| 956 * | |
| 957 * Parameters: See SER_tr_EnterSleep. | |
| 958 * | |
| 959 * Return: 1 | |
| 960 * | |
| 961 ******************************************************************************/ | |
| 962 | |
| 963 static SYS_BOOL | |
| 964 dummy_tr_EnterSleep (T_tr_UartId device) | |
| 965 { | |
| 966 return (1); | |
| 967 } | |
| 968 | |
| 969 /******************************************************************************* | |
| 970 * | |
| 971 * dummy_tr_WakeUp | |
| 972 * | |
| 973 * Purpose: No action. | |
| 974 * | |
| 975 * Parameters: See SER_tr_WakeUp. | |
| 976 * | |
| 977 * Return: none | |
| 978 * | |
| 979 ******************************************************************************/ | |
| 980 | |
| 981 static void | |
| 982 dummy_tr_WakeUp (T_tr_UartId device) | |
| 983 { | |
| 984 /* | |
| 985 * No action. | |
| 986 */ | |
| 987 } | |
| 988 | |
| 989 /******************************************************************************* | |
| 990 * | |
| 991 * dummy_fd_Init | |
| 992 * | |
| 993 * Purpose: Sets the size of the circular buffer to the maximum value and the | |
| 994 * state of the driver to 'disabled'. | |
| 995 * | |
| 996 * Parameters: See SER_fd_Init. | |
| 997 * | |
| 998 * Return: FD_OK: Successful operation. | |
| 999 * | |
| 1000 ******************************************************************************/ | |
| 1001 | |
| 1002 static T_FDRET | |
| 1003 dummy_fd_Init (T_fd_UartId device) | |
| 1004 { | |
| 1005 #if SERIAL_DYNAMIC_SWITCH | |
| 1006 data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE; | |
| 1007 #else | |
| 1008 bufSize = FD_MAX_BUFFER_SIZE; | |
| 1009 #endif | |
| 1010 fd_driver_enabled = 0; | |
| 1011 | |
| 1012 return (FD_OK); | |
| 1013 } | |
| 1014 | |
| 1015 /******************************************************************************* | |
| 1016 * | |
| 1017 * dummy_fd_Enable | |
| 1018 * | |
| 1019 * Purpose: Stores the state of the driver. | |
| 1020 * | |
| 1021 * Parameters: See SER_fd_Enable. | |
| 1022 * | |
| 1023 * Return: FD_OK: Successful operation. | |
| 1024 * | |
| 1025 ******************************************************************************/ | |
| 1026 | |
| 1027 static T_FDRET | |
| 1028 dummy_fd_Enable (T_fd_UartId device, | |
| 1029 SYS_BOOL enable) | |
| 1030 { | |
| 1031 fd_driver_enabled = enable; | |
| 1032 | |
| 1033 return (FD_OK); | |
| 1034 } | |
| 1035 | |
| 1036 /******************************************************************************* | |
| 1037 * | |
| 1038 * dummy_fd_SetComPar | |
| 1039 * | |
| 1040 * Purpose: No action. | |
| 1041 * | |
| 1042 * Parameters: See SER_fd_SetComPar. | |
| 1043 * | |
| 1044 * Return: FD_OK: Successful operation. | |
| 1045 * | |
| 1046 ******************************************************************************/ | |
| 1047 | |
| 1048 static T_FDRET | |
| 1049 dummy_fd_SetComPar (T_fd_UartId device, | |
| 1050 T_baudrate baudrate, | |
| 1051 T_bitsPerCharacter bpc, | |
| 1052 T_stopBits sb, | |
| 1053 T_parity parity) | |
| 1054 { | |
| 1055 return (FD_OK); | |
| 1056 } | |
| 1057 | |
| 1058 /******************************************************************************* | |
| 1059 * | |
| 1060 * dummy_fd_SetBuffer | |
| 1061 * | |
| 1062 * Purpose: No action. | |
| 1063 * | |
| 1064 * Parameters: See SER_fd_SetBuffer. | |
| 1065 * | |
| 1066 * Return: FD_OK: Successful operation. | |
| 1067 * | |
| 1068 ******************************************************************************/ | |
| 1069 | |
| 1070 static T_FDRET | |
| 1071 dummy_fd_SetBuffer (T_fd_UartId device, | |
| 1072 SYS_UWORD16 bufSize, | |
| 1073 SYS_UWORD16 rxThreshold, | |
| 1074 SYS_UWORD16 txThreshold) | |
| 1075 { | |
| 1076 return (FD_OK); | |
| 1077 } | |
| 1078 | |
| 1079 /******************************************************************************* | |
| 1080 * | |
| 1081 * dummy_fd_SetFlowCtrl | |
| 1082 * | |
| 1083 * Purpose: No action. | |
| 1084 * | |
| 1085 * Parameters: See SER_fd_SetFlowCtrl. | |
| 1086 * | |
| 1087 * Return: FD_OK: Successful operation. | |
| 1088 * | |
| 1089 ******************************************************************************/ | |
| 1090 | |
| 1091 static T_FDRET | |
| 1092 dummy_fd_SetFlowCtrl (T_fd_UartId device, | |
| 1093 T_flowCtrlMode fcMode, | |
| 1094 SYS_UWORD8 XON, | |
| 1095 SYS_UWORD8 XOFF) | |
| 1096 { | |
| 1097 return (FD_OK); | |
| 1098 } | |
| 1099 | |
| 1100 /******************************************************************************* | |
| 1101 * | |
| 1102 * dummy_fd_SetEscape | |
| 1103 * | |
| 1104 * Purpose: No action. | |
| 1105 * | |
| 1106 * Parameters: See SER_fd_SetEscape. | |
| 1107 * | |
| 1108 * Return: FD_OK: Successful operation. | |
| 1109 * | |
| 1110 ******************************************************************************/ | |
| 1111 | |
| 1112 static T_FDRET | |
| 1113 dummy_fd_SetEscape (T_fd_UartId device, | |
| 1114 SYS_UWORD8 escChar, | |
| 1115 SYS_UWORD16 guardPeriod) | |
| 1116 { | |
| 1117 return (FD_OK); | |
| 1118 } | |
| 1119 | |
| 1120 /******************************************************************************* | |
| 1121 * | |
| 1122 * dummy_fd_InpAvail | |
| 1123 * | |
| 1124 * Purpose: No action. | |
| 1125 * | |
| 1126 * Parameters: See SER_fd_InpAvail. | |
| 1127 * | |
| 1128 * Return: The size of the circular buffer. | |
| 1129 * | |
| 1130 ******************************************************************************/ | |
| 1131 | |
| 1132 static T_FDRET | |
| 1133 dummy_fd_InpAvail (T_fd_UartId device) | |
| 1134 { | |
| 1135 #if SERIAL_DYNAMIC_SWITCH | |
| 1136 return (data_flow_parameters.bufSize); | |
| 1137 #else | |
| 1138 return (bufSize); | |
| 1139 #endif | |
| 1140 } | |
| 1141 | |
| 1142 /******************************************************************************* | |
| 1143 * | |
| 1144 * dummy_fd_OutpAvail | |
| 1145 * | |
| 1146 * Purpose: No action. | |
| 1147 * | |
| 1148 * Parameters: See SER_fd_OutpAvail. | |
| 1149 * | |
| 1150 * Return: The size of the circular buffer. | |
| 1151 * | |
| 1152 ******************************************************************************/ | |
| 1153 | |
| 1154 static T_FDRET | |
| 1155 dummy_fd_OutpAvail (T_fd_UartId device) | |
| 1156 { | |
| 1157 #if SERIAL_DYNAMIC_SWITCH | |
| 1158 return (data_flow_parameters.bufSize); | |
| 1159 #else | |
| 1160 return (bufSize); | |
| 1161 #endif | |
| 1162 } | |
| 1163 | |
| 1164 /******************************************************************************* | |
| 1165 * | |
| 1166 * dummy_fd_EnterSleep | |
| 1167 * | |
| 1168 * Purpose: No action. | |
| 1169 * | |
| 1170 * Parameters: See SER_tr_EnterSleep. | |
| 1171 * | |
| 1172 * Return: 1 | |
| 1173 * | |
| 1174 ******************************************************************************/ | |
| 1175 | |
| 1176 static T_FDRET | |
| 1177 dummy_fd_EnterSleep (T_fd_UartId device) | |
| 1178 { | |
| 1179 return (1); | |
| 1180 } | |
| 1181 | |
| 1182 /******************************************************************************* | |
| 1183 * | |
| 1184 * dummy_fd_WakeUp | |
| 1185 * | |
| 1186 * Purpose: No action. | |
| 1187 * | |
| 1188 * Parameters: See SER_tr_WakeUp. | |
| 1189 * | |
| 1190 * Return: FD_OK: Successful operation. | |
| 1191 * | |
| 1192 ******************************************************************************/ | |
| 1193 | |
| 1194 static T_FDRET | |
| 1195 dummy_fd_WakeUp (T_fd_UartId device) | |
| 1196 { | |
| 1197 return (FD_OK); | |
| 1198 } | |
| 1199 | |
| 1200 /******************************************************************************* | |
| 1201 * | |
| 1202 * dummy_fd_ReadData | |
| 1203 * | |
| 1204 * Purpose: No action. | |
| 1205 * | |
| 1206 * Parameters: See SER_fd_ReadData. | |
| 1207 * | |
| 1208 * Return: 0 if the suspend parameter is set to 'sm_noSuspend'. | |
| 1209 * FD_SUSPENDED if the suspend parameter is set to 'sm_suspend'. | |
| 1210 * | |
| 1211 ******************************************************************************/ | |
| 1212 | |
| 1213 static T_FDRET | |
| 1214 dummy_fd_ReadData (T_fd_UartId device, | |
| 1215 T_suspendMode suspend, | |
| 1216 void (readOutFunc (SYS_BOOL cldFromIrq, | |
| 1217 T_reInstMode *reInstall, | |
| 1218 SYS_UWORD8 nsource, | |
| 1219 SYS_UWORD8 *source[], | |
| 1220 SYS_UWORD16 size[], | |
| 1221 SYS_UWORD32 state))) | |
| 1222 { | |
| 1223 T_FDRET result; | |
| 1224 | |
| 1225 if (suspend == sm_noSuspend) | |
| 1226 result = 0; | |
| 1227 else | |
| 1228 result = FD_SUSPENDED; | |
| 1229 | |
| 1230 return (result); | |
| 1231 } | |
| 1232 | |
| 1233 /******************************************************************************* | |
| 1234 * | |
| 1235 * dummy_fd_WriteData | |
| 1236 * | |
| 1237 * Purpose: The user's function is called with: | |
| 1238 * - cldFromIrq = 0 | |
| 1239 * - ndest = 1 | |
| 1240 * - dest[0] is a SYS_UWORD8 pointer on the beginning address of a local | |
| 1241 * buffer | |
| 1242 * - size[0] is set to data_flow_parameters.bufSize. | |
| 1243 * | |
| 1244 * Parameters: See SER_fd_WriteData. | |
| 1245 * | |
| 1246 * Return: The number of bytes written in the local buffer. | |
| 1247 * | |
| 1248 ******************************************************************************/ | |
| 1249 | |
| 1250 static T_FDRET | |
| 1251 dummy_fd_WriteData (T_fd_UartId device, | |
| 1252 T_suspendMode suspend, | |
| 1253 void (writeInFunc (SYS_BOOL cldFromIrq, | |
| 1254 T_reInstMode *reInstall, | |
| 1255 SYS_UWORD8 ndest, | |
| 1256 SYS_UWORD8 *dest[], | |
| 1257 SYS_UWORD16 size[]))) | |
| 1258 { | |
| 1259 T_reInstMode dummyInstall; | |
| 1260 SYS_UWORD8 *destination[2]; | |
| 1261 SYS_UWORD16 buffer_size[2]; | |
| 1262 | |
| 1263 destination[0] = &(fd_buffer[0]); | |
| 1264 #if SERIAL_DYNAMIC_SWITCH | |
| 1265 buffer_size[0] = data_flow_parameters.bufSize; | |
| 1266 #else | |
| 1267 buffer_size[0] = bufSize; | |
| 1268 #endif | |
| 1269 | |
| 1270 (*writeInFunc) (0, &dummyInstall, 1, &(destination[0]), &(buffer_size[0])); | |
| 1271 | |
| 1272 #if SERIAL_DYNAMIC_SWITCH | |
| 1273 return ((T_FDRET) (data_flow_parameters.bufSize - buffer_size[0])); | |
| 1274 #else | |
| 1275 return ((T_FDRET) (bufSize - buffer_size[0])); | |
| 1276 #endif | |
| 1277 } | |
| 1278 | |
| 1279 /******************************************************************************* | |
| 1280 * | |
| 1281 * dummy_fd_StopRec | |
| 1282 * | |
| 1283 * Purpose: No action. | |
| 1284 * | |
| 1285 * Parameters: See SER_fd_StopRec. | |
| 1286 * | |
| 1287 * Return: FD_OK: Successful operation. | |
| 1288 * | |
| 1289 ******************************************************************************/ | |
| 1290 | |
| 1291 static T_FDRET | |
| 1292 dummy_fd_StopRec (T_fd_UartId device) | |
| 1293 { | |
| 1294 return (FD_OK); | |
| 1295 } | |
| 1296 | |
| 1297 /******************************************************************************* | |
| 1298 * | |
| 1299 * dummy_fd_StartRec | |
| 1300 * | |
| 1301 * Purpose: No action. | |
| 1302 * | |
| 1303 * Parameters: See SER_fd_StartRec. | |
| 1304 * | |
| 1305 * Return: FD_OK: Successful operation. | |
| 1306 * | |
| 1307 ******************************************************************************/ | |
| 1308 | |
| 1309 static T_FDRET | |
| 1310 dummy_fd_StartRec (T_fd_UartId device) | |
| 1311 { | |
| 1312 return (FD_OK); | |
| 1313 } | |
| 1314 | |
| 1315 /******************************************************************************* | |
| 1316 * | |
| 1317 * dummy_fd_GetLineState | |
| 1318 * | |
| 1319 * Purpose: Sets the RXBLEV field to the bufSize value. | |
| 1320 * | |
| 1321 * Parameters: See SER_fd_GetLineState. | |
| 1322 * | |
| 1323 * Return: FD_OK: Successful operation. | |
| 1324 * | |
| 1325 ******************************************************************************/ | |
| 1326 | |
| 1327 static T_FDRET | |
| 1328 dummy_fd_GetLineState (T_fd_UartId device, | |
| 1329 SYS_UWORD32 *state) | |
| 1330 { | |
| 1331 #if SERIAL_DYNAMIC_SWITCH | |
| 1332 *state = data_flow_parameters.bufSize << RXBLEV; | |
| 1333 #else | |
| 1334 *state = bufSize << RXBLEV; | |
| 1335 #endif | |
| 1336 | |
| 1337 return (FD_OK); | |
| 1338 } | |
| 1339 | |
| 1340 /******************************************************************************* | |
| 1341 * | |
| 1342 * dummy_fd_SetLineState | |
| 1343 * | |
| 1344 * Purpose: No action. | |
| 1345 * | |
| 1346 * Parameters: See SER_fd_SetLineState. | |
| 1347 * | |
| 1348 * Return: FD_OK: Successful operation. | |
| 1349 * | |
| 1350 ******************************************************************************/ | |
| 1351 | |
| 1352 static T_FDRET | |
| 1353 dummy_fd_SetLineState (T_fd_UartId device, | |
| 1354 SYS_UWORD32 state, | |
| 1355 SYS_UWORD32 mask) | |
| 1356 { | |
| 1357 return (FD_OK); | |
| 1358 } | |
| 1359 | |
| 1360 /******************************************************************************* | |
| 1361 * | |
| 1362 * dummy_fd_CheckXEmpty | |
| 1363 * | |
| 1364 * Purpose: No action. | |
| 1365 * | |
| 1366 * Parameters: See SER_fd_CheckXEmpty. | |
| 1367 * | |
| 1368 * Return: FD_OK: Successful operation. | |
| 1369 * | |
| 1370 ******************************************************************************/ | |
| 1371 | |
| 1372 static T_FDRET | |
| 1373 dummy_fd_CheckXEmpty (T_fd_UartId device) | |
| 1374 { | |
| 1375 return (FD_OK); | |
| 1376 } | |
| 1377 | |
| 1378 #ifdef BTEMOBILE | |
| 1379 /******************************************************************************* | |
| 1380 * | |
| 1381 * dummy_bt_Init | |
| 1382 * | |
| 1383 * Purpose: No action. | |
| 1384 * | |
| 1385 * Parameters: See SER_bt_Init. | |
| 1386 * | |
| 1387 * Return: HCI_OK: Successful operation. | |
| 1388 * | |
| 1389 ******************************************************************************/ | |
| 1390 | |
| 1391 static T_HCI_RET | |
| 1392 dummy_bt_Init (T_bt_UartId uart_device) | |
| 1393 { | |
| 1394 return (HCI_OK); | |
| 1395 } | |
| 1396 | |
| 1397 /******************************************************************************* | |
| 1398 * | |
| 1399 * dummy_bt_Start | |
| 1400 * | |
| 1401 * Purpose: No action. | |
| 1402 * | |
| 1403 * Parameters: See SER_bt_Start. | |
| 1404 * | |
| 1405 * Return: HCI_OK: Successful operation. | |
| 1406 * | |
| 1407 ******************************************************************************/ | |
| 1408 | |
| 1409 static T_HCI_RET | |
| 1410 dummy_bt_Start (void) | |
| 1411 { | |
| 1412 return (HCI_OK); | |
| 1413 } | |
| 1414 | |
| 1415 /******************************************************************************* | |
| 1416 * | |
| 1417 * dummy_bt_Stop | |
| 1418 * | |
| 1419 * Purpose: No action. | |
| 1420 * | |
| 1421 * Parameters: See SER_bt_Stop. | |
| 1422 * | |
| 1423 * Return: HCI_OK: Successful operation. | |
| 1424 * | |
| 1425 ******************************************************************************/ | |
| 1426 | |
| 1427 static T_HCI_RET | |
| 1428 dummy_bt_Stop (void) | |
| 1429 { | |
| 1430 return (HCI_OK); | |
| 1431 } | |
| 1432 | |
| 1433 /******************************************************************************* | |
| 1434 * | |
| 1435 * dummy_bt_Kill | |
| 1436 * | |
| 1437 * Purpose: No action. | |
| 1438 * | |
| 1439 * Parameters: See SER_bt_Kill. | |
| 1440 * | |
| 1441 * Return: HCI_OK: Successful operation. | |
| 1442 * | |
| 1443 ******************************************************************************/ | |
| 1444 | |
| 1445 static T_HCI_RET | |
| 1446 dummy_bt_Kill (void) | |
| 1447 { | |
| 1448 return (HCI_OK); | |
| 1449 } | |
| 1450 | |
| 1451 /******************************************************************************* | |
| 1452 * | |
| 1453 * dummy_bt_SetBaudrate | |
| 1454 * | |
| 1455 * Purpose: No action. | |
| 1456 * | |
| 1457 * Parameters: See SER_bt_SetBaudrate. | |
| 1458 * | |
| 1459 * Return: HCI_OK: Successful operation. | |
| 1460 * | |
| 1461 ******************************************************************************/ | |
| 1462 | |
| 1463 static T_HCI_RET | |
| 1464 dummy_bt_SetBaudrate (UINT8 baudrate) | |
| 1465 { | |
| 1466 return (HCI_OK); | |
| 1467 } | |
| 1468 | |
| 1469 /******************************************************************************* | |
| 1470 * | |
| 1471 * dummy_bt_TransmitPacket | |
| 1472 * | |
| 1473 * Purpose: No action. | |
| 1474 * | |
| 1475 * Parameters: See SER_bt_TransmitPacket. | |
| 1476 * | |
| 1477 * Return: HCI_OK: Successful operation. | |
| 1478 * | |
| 1479 ******************************************************************************/ | |
| 1480 | |
| 1481 static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer) | |
| 1482 | |
| 1483 { | |
| 1484 return (HCI_OK); | |
| 1485 } | |
| 1486 | |
| 1487 /******************************************************************************* | |
| 1488 * | |
| 1489 * dummy_bt_EnterSleep | |
| 1490 * | |
| 1491 * Purpose: No action. | |
| 1492 * | |
| 1493 * Parameters: See SER_bt_EnterSleep. | |
| 1494 * | |
| 1495 * Return: TRUE. | |
| 1496 * | |
| 1497 ******************************************************************************/ | |
| 1498 | |
| 1499 static SYS_BOOL | |
| 1500 dummy_bt_EnterSleep (void) | |
| 1501 { | |
| 1502 return (TRUE); | |
| 1503 } | |
| 1504 | |
| 1505 /******************************************************************************* | |
| 1506 * | |
| 1507 * dummy_bt_WakeUp | |
| 1508 * | |
| 1509 * Purpose: No action. | |
| 1510 * | |
| 1511 * Parameters: See SER_bt_WakeUp | |
| 1512 * | |
| 1513 * Return: HCI_OK: none | |
| 1514 * | |
| 1515 ******************************************************************************/ | |
| 1516 | |
| 1517 static void | |
| 1518 dummy_bt_WakeUp (void) | |
| 1519 { | |
| 1520 /* | |
| 1521 * No action. | |
| 1522 */ | |
| 1523 } | |
| 1524 | |
| 1525 #endif /* BTEMOBILE */ | |
| 1526 | |
| 1527 /******************************************************************************* | |
| 1528 * | |
| 1529 * analyze_uart_sleep_timer_expiration | |
| 1530 * | |
| 1531 * Purpose : The timer has just expired. If requested, UARTs can again be set | |
| 1532 * up to enter Deep Sleep. | |
| 1533 * | |
| 1534 * Arguments: In : id: parameter not used. | |
| 1535 * Out: none | |
| 1536 * | |
| 1537 * Returns : none | |
| 1538 * | |
| 1539 ******************************************************************************/ | |
| 1540 | |
| 1541 static VOID | |
| 1542 analyze_uart_sleep_timer_expiration (UNSIGNED id) | |
| 1543 { | |
| 1544 /* | |
| 1545 * Timer has expired. | |
| 1546 * UARTs can again be set up for Deep Sleep. | |
| 1547 */ | |
| 1548 | |
| 1549 (void) NU_Control_Timer (&uart_sleep_timer, | |
| 1550 NU_DISABLE_TIMER); | |
| 1551 | |
| 1552 uart_sleep_timer_enabled = 0; | |
| 1553 } | |
| 1554 | |
| 1555 /******************************************************************************* | |
| 1556 * | |
| 1557 * start_uart_sleep_timer | |
| 1558 * | |
| 1559 * Purpose : Starts the sleep timer once UARTs have been waked-up by an | |
| 1560 * interrupt or if new incoming characters have been received. | |
| 1561 * | |
| 1562 * Arguments: In : none | |
| 1563 * Out: none | |
| 1564 * | |
| 1565 * Returns : none | |
| 1566 * | |
| 1567 ******************************************************************************/ | |
| 1568 | |
| 1569 static void | |
| 1570 start_uart_sleep_timer (void) | |
| 1571 { | |
| 1572 /* | |
| 1573 * UART sleep timer is started. | |
| 1574 * UARTs can't no more be set up for Deep Sleep until the timer expires. | |
| 1575 */ | |
| 1576 | |
| 1577 (void) NU_Reset_Timer (&uart_sleep_timer, | |
| 1578 &analyze_uart_sleep_timer_expiration, | |
| 1579 WAKE_UP_TIME_IN_TDMA, | |
| 1580 0, /* The timer expires once. */ | |
| 1581 NU_DISABLE_TIMER); | |
| 1582 | |
| 1583 (void) NU_Control_Timer (&uart_sleep_timer, | |
| 1584 NU_ENABLE_TIMER); | |
| 1585 } | |
| 1586 | |
| 1587 /******************************************************************************* | |
| 1588 * | |
| 1589 * set_flow_functions | |
| 1590 * | |
| 1591 * Purpose: Initializes a serial data flow functions set with the set of | |
| 1592 * functions of the selected device. | |
| 1593 * | |
| 1594 * Parameters: In : flow : index of the serial data flow | |
| 1595 * serial_driver: allows knowing which set of functions must | |
| 1596 * be selected | |
| 1597 * Out: none | |
| 1598 * | |
| 1599 * Return: none | |
| 1600 * | |
| 1601 ******************************************************************************/ | |
| 1602 | |
| 1603 static void | |
| 1604 set_flow_functions (int flow, | |
| 1605 T_SerialDriver serial_driver) | |
| 1606 { | |
| 1607 | |
| 1608 switch (serial_driver) { | |
| 1609 | |
| 1610 case UART_MODEM_FAX_DATA: | |
| 1611 | |
| 1612 #if CONFIG_FDMODEM | |
| 1613 fd_functions = &uart_modem_fax_data; | |
| 1614 int_uart[fd_functions->device].device_used = 1; | |
| 1615 int_uart[fd_functions->device].flow_type = FAX_DATA_FLOW; | |
| 1616 int_uart[fd_functions->device].flow_id = flow; | |
| 1617 int_uart[fd_functions->device].interrupt_handler = | |
| 1618 UAF_InterruptHandler; | |
| 1619 break; | |
| 1620 #endif | |
| 1621 | |
| 1622 case DUMMY_FAX_DATA: | |
| 1623 | |
| 1624 fd_functions = &dummy_fax_data; | |
| 1625 break; | |
| 1626 | |
| 1627 | |
| 1628 case UART_IRDA_TRACE: | |
| 1629 case UART_MODEM_TRACE: | |
| 1630 #if (CHIPSET == 12) | |
| 1631 case UART_MODEM2_TRACE: | |
| 1632 #endif | |
| 1633 | |
| 1634 if (serial_driver == UART_IRDA_TRACE) | |
| 1635 tr_functions[flow] = &uart_irda_trace; | |
| 1636 else { | |
| 1637 #if (CHIPSET == 12) | |
| 1638 if (serial_driver == UART_MODEM2_TRACE) | |
| 1639 tr_functions[flow] = &uart_modem2_trace; | |
| 1640 else | |
| 1641 #endif | |
| 1642 tr_functions[flow] = &uart_modem_trace; | |
| 1643 } | |
| 1644 | |
| 1645 int_uart[tr_functions[flow]->device].device_used = 1; | |
| 1646 int_uart[tr_functions[flow]->device].flow_type = TRACE_FLOW; | |
| 1647 int_uart[tr_functions[flow]->device].flow_id = flow; | |
| 1648 int_uart[tr_functions[flow]->device].interrupt_handler = | |
| 1649 UA_InterruptHandler; | |
| 1650 break; | |
| 1651 | |
| 1652 case DUMMY_TRACE: | |
| 1653 | |
| 1654 tr_functions[flow] = &dummy_trace; | |
| 1655 break; | |
| 1656 | |
| 1657 case DUMMY_BT_HCI: | |
| 1658 | |
| 1659 /* | |
| 1660 * if serial_driver = DUMMY_BT_HCI & if BTEMOBILE is not defined | |
| 1661 * no action is performed. | |
| 1662 */ | |
| 1663 | |
| 1664 #ifdef BTEMOBILE | |
| 1665 bt_functions = &dummy_bt_hci; | |
| 1666 break; | |
| 1667 | |
| 1668 case UART_IRDA_BT_HCI: | |
| 1669 case UART_MODEM_BT_HCI: | |
| 1670 #if (CHIPSET == 12) | |
| 1671 case UART_MODEM2_BT_HCI: | |
| 1672 #endif | |
| 1673 | |
| 1674 if (serial_driver == UART_IRDA_BT_HCI) | |
| 1675 bt_functions = &uart_irda_bt_hci; | |
| 1676 else { | |
| 1677 #if (CHIPSET == 12) | |
| 1678 if (serial_driver == UART_MODEM2_BT_HCI) | |
| 1679 bt_functions = &uart_modem2_bt_hci; | |
| 1680 else | |
| 1681 #endif | |
| 1682 bt_functions = &uart_modem_bt_hci; | |
| 1683 } | |
| 1684 | |
| 1685 int_uart[bt_functions->device].device_used = 1; | |
| 1686 int_uart[bt_functions->device].flow_type = BLUETOOTH_HCI_FLOW; | |
| 1687 int_uart[bt_functions->device].flow_id = flow; | |
| 1688 int_uart[bt_functions->device].interrupt_handler = | |
| 1689 hciu_interrupt_handler; | |
| 1690 #endif /* BTEMOBILE */ | |
| 1691 break; | |
| 1692 } | |
| 1693 } | |
| 1694 | |
| 1695 /******************************************************************************* | |
| 1696 * | |
| 1697 * SER_InitSerialConfig | |
| 1698 * | |
| 1699 * Purpose: The parameter serial_info allows knowing all serial information | |
| 1700 * necessary to set up the serial configuration of an application. | |
| 1701 * From this information, the function is able to determine if the | |
| 1702 * current serial configuration read out from the flash memory is | |
| 1703 * valid. If it does not correspond to an allowed configuration, the | |
| 1704 * default configuration is selected. This function must be called at | |
| 1705 * the application's initialization, but never after. | |
| 1706 * | |
| 1707 * Parameters: In : serial_info: application serial information like the default | |
| 1708 * configuration and all allowed configurations. | |
| 1709 * Out: none | |
| 1710 * | |
| 1711 * Return: none | |
| 1712 * | |
| 1713 ******************************************************************************/ | |
| 1714 | |
| 1715 void | |
| 1716 SER_InitSerialConfig (const T_AppliSerialInfo *serial_info) | |
| 1717 { | |
| 1718 int uart_id; | |
| 1719 int flow; | |
| 1720 SYS_UWORD16 serial_driver; | |
| 1721 SYS_UWORD16 *allowed_config; | |
| 1722 SYS_UWORD8 nb_allowed_config; | |
| 1723 SYS_BOOL valid_config_selected; | |
| 1724 SYS_BOOL uart_used; | |
| 1725 SYS_BOOL uart_used_for_trace; | |
| 1726 SYS_UWORD16 current_config; | |
| 1727 SYS_UWORD16 *pt_current_config = &(current_config); | |
| 1728 | |
| 1729 /* | |
| 1730 * Basic UARTs initializations. | |
| 1731 */ | |
| 1732 | |
| 1733 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 1734 | |
| 1735 int_uart[uart_id].base_address = uart_base_address[uart_id]; | |
| 1736 int_uart[uart_id].device_used = 0; | |
| 1737 int_uart[uart_id].deep_sleep_set_up = 0; | |
| 1738 } | |
| 1739 | |
| 1740 #if ((CHIPSET == 2) || (CHIPSET == 3)) | |
| 1741 uart_spurious_interrupts = 0; | |
| 1742 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) | |
| 1743 uart_modem_spurious_interrupts = 0; | |
| 1744 uart_irda_spurious_interrupts = 0; | |
| 1745 #endif | |
| 1746 #if (CHIPSET == 12) | |
| 1747 uart_modem2_spurious_interrupts = 0; | |
| 1748 #endif | |
| 1749 uart_sleep_timer_enabled = 0; | |
| 1750 | |
| 1751 /* | |
| 1752 * Compute the current serial configuration. | |
| 1753 */ | |
| 1754 | |
| 1755 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 1756 | |
| 1757 switch (ser_cfg_info[uart_id]) { | |
| 1758 | |
| 1759 case G23_PANEL: | |
| 1760 serial_cfg = serial_cfg + | |
| 1761 ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK))); | |
| 1762 break; | |
| 1763 | |
| 1764 case RIVIERA_TRACE_MUX: | |
| 1765 serial_cfg = serial_cfg + | |
| 1766 ((uart_id + 1) << (12 - (4 * SER_LAYER_1))); | |
| 1767 break; | |
| 1768 | |
| 1769 case FD_AT_COMMAND: | |
| 1770 serial_cfg = serial_cfg + | |
| 1771 ((uart_id + 1) << (12 - (4 * SER_FAX_DATA))); | |
| 1772 break; | |
| 1773 | |
| 1774 case BLUETOOTH_HCI: | |
| 1775 serial_cfg = serial_cfg + | |
| 1776 ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI))); | |
| 1777 break; | |
| 1778 | |
| 1779 case DUMMY: | |
| 1780 break; | |
| 1781 } | |
| 1782 } | |
| 1783 | |
| 1784 current_config = serial_cfg; | |
| 1785 valid_config_selected = 0; | |
| 1786 nb_allowed_config = serial_info->num_config; | |
| 1787 | |
| 1788 /* | |
| 1789 * Checks if the current serial config is one of the allowed. | |
| 1790 */ | |
| 1791 | |
| 1792 while ((nb_allowed_config > 0) && !valid_config_selected) { | |
| 1793 | |
| 1794 nb_allowed_config--; | |
| 1795 allowed_config = (SYS_UWORD16 *) | |
| 1796 &(serial_info->allowed_config[nb_allowed_config]); | |
| 1797 | |
| 1798 if (*pt_current_config == *allowed_config) | |
| 1799 valid_config_selected = 1; | |
| 1800 } | |
| 1801 | |
| 1802 /* | |
| 1803 * If not, the default configuration is selected. | |
| 1804 */ | |
| 1805 | |
| 1806 if (!valid_config_selected) { | |
| 1807 | |
| 1808 pt_current_config = (SYS_UWORD16 *)&(serial_info->default_config); | |
| 1809 | |
| 1810 #if SERIAL_DYNAMIC_SWITCH | |
| 1811 /* | |
| 1812 * Setup the global variable accordingly. | |
| 1813 * The following default value are identical to the ones defined at | |
| 1814 * the application initialization in init.c. | |
| 1815 */ | |
| 1816 | |
| 1817 #ifdef BT_UART_USED_MODEM | |
| 1818 memcpy (ser_cfg_info, "RB", NUMBER_OF_TR_UART); | |
| 1819 #else | |
| 1820 memcpy (ser_cfg_info, "BR", NUMBER_OF_TR_UART); | |
| 1821 #endif | |
| 1822 #endif | |
| 1823 } | |
| 1824 | |
| 1825 /* | |
| 1826 * The serial data flow functions set is initialized. | |
| 1827 */ | |
| 1828 | |
| 1829 flow = 0; | |
| 1830 while (flow < SER_MAX_NUMBER_OF_FLOWS) { | |
| 1831 | |
| 1832 serial_driver = (T_SerialDriver) | |
| 1833 (((*pt_current_config) >> (12 - flow * 4)) & 0x000F); | |
| 1834 | |
| 1835 set_flow_functions (flow, serial_driver); | |
| 1836 flow++; | |
| 1837 } | |
| 1838 | |
| 1839 /* | |
| 1840 * Checks if both UARTs are used. | |
| 1841 * If not, performs minimum initialization including Sleep Mode. | |
| 1842 * Checks also if at least one UART is used by a Trace flow. | |
| 1843 * If so, create a HISR in order to reset and restart the sleep timer | |
| 1844 * in case of incoming characters. | |
| 1845 */ | |
| 1846 | |
| 1847 uart_used = 0; | |
| 1848 uart_used_for_trace = 0; | |
| 1849 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 1850 | |
| 1851 if (!(int_uart[uart_id].device_used)) | |
| 1852 initialize_uart_sleep (uart_id); | |
| 1853 | |
| 1854 else { /* if (int_uart[uart_id].device_used) */ | |
| 1855 | |
| 1856 uart_used = 1; /* At least one UART is used */ | |
| 1857 | |
| 1858 if (int_uart[uart_id].flow_type == TRACE_FLOW) { | |
| 1859 | |
| 1860 /* At least one UART used by a Trace flow */ | |
| 1861 uart_used_for_trace = 1; | |
| 1862 } | |
| 1863 } | |
| 1864 } | |
| 1865 | |
| 1866 /* | |
| 1867 * If at least one uart is used, create a timer to figure out if the system | |
| 1868 * can enter deep sleep mode regarding the UARTs. | |
| 1869 */ | |
| 1870 | |
| 1871 if (uart_used) { | |
| 1872 | |
| 1873 (void) NU_Create_Timer ( | |
| 1874 &uart_sleep_timer, | |
| 1875 "Sleep", | |
| 1876 &analyze_uart_sleep_timer_expiration, | |
| 1877 0, /* Parameter supplied to the routine: not used. */ | |
| 1878 WAKE_UP_TIME_IN_TDMA, | |
| 1879 0, /* The timer expires once. */ | |
| 1880 NU_DISABLE_TIMER); | |
| 1881 | |
| 1882 /* | |
| 1883 * If at least one uart is used by a Trace flow, create a HISR to reset | |
| 1884 * and restart the sleep timer. | |
| 1885 */ | |
| 1886 | |
| 1887 if (uart_used_for_trace) { | |
| 1888 | |
| 1889 /* | |
| 1890 * The stack is entirely filled with the pattern 0xFE. | |
| 1891 */ | |
| 1892 | |
| 1893 memset (&(timer_hisr_stack[0]), 0xFE, TIMER_HISR_STACK_SIZE); | |
| 1894 | |
| 1895 /* | |
| 1896 * The HISR entry function is the same function than the one called | |
| 1897 * by the Rx HISR of the UARTFAX, since the only aim is to reset | |
| 1898 * and restart the sleep timer in case of incoming characters on | |
| 1899 * the Trace UART. | |
| 1900 */ | |
| 1901 | |
| 1902 (void) NU_Create_HISR ( | |
| 1903 &timer_hisr_ctrl_block, | |
| 1904 "Tim_HISR", | |
| 1905 SER_restart_uart_sleep_timer, | |
| 1906 TIMER_HISR_PRIORITY, | |
| 1907 &(timer_hisr_stack[0]), | |
| 1908 TIMER_HISR_STACK_SIZE); | |
| 1909 } | |
| 1910 } | |
| 1911 } | |
| 1912 | |
| 1913 | |
| 1914 /******************************************************************************* | |
| 1915 * | |
| 1916 * SER_WriteConfig | |
| 1917 * | |
| 1918 * Purpose: TBD | |
| 1919 * | |
| 1920 * Parameters: In : new_config: TBD | |
| 1921 * write_to_flash: TBD | |
| 1922 * Out: none | |
| 1923 * | |
| 1924 * Return: 0 (FALSE) : In case of error while trying to write file in FFS | |
| 1925 * >= 1 (TRUE) : Successful operation. | |
| 1926 * | |
| 1927 ******************************************************************************/ | |
| 1928 | |
| 1929 SYS_BOOL | |
| 1930 SER_WriteConfig (char *new_config, | |
| 1931 SYS_BOOL write_to_flash) | |
| 1932 { | |
| 1933 #if SERIAL_DYNAMIC_SWITCH | |
| 1934 int uart_id; | |
| 1935 SYS_BOOL status = 1; | |
| 1936 | |
| 1937 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) | |
| 1938 ser_new_cfg[uart_id] = *new_config++; | |
| 1939 | |
| 1940 /* | |
| 1941 * Write in flash the new serial configuration if requested. | |
| 1942 */ | |
| 1943 | |
| 1944 if (write_to_flash) { | |
| 1945 if (ffs_fwrite (uart_config_file, | |
| 1946 ser_new_cfg, | |
| 1947 NUMBER_OF_TR_UART) < EFFS_OK) { | |
| 1948 status = 0; | |
| 1949 } | |
| 1950 } | |
| 1951 | |
| 1952 return (status); | |
| 1953 #else | |
| 1954 /* | |
| 1955 * Real Dynamic Switch is only available with Bluetooth AND all chips but | |
| 1956 * Calypso+. | |
| 1957 */ | |
| 1958 | |
| 1959 return (1); | |
| 1960 #endif | |
| 1961 } | |
| 1962 | |
| 1963 /******************************************************************************* | |
| 1964 * | |
| 1965 * SER_ImmediateSwitch | |
| 1966 * | |
| 1967 * Purpose: TBD | |
| 1968 * | |
| 1969 * Parameters: In : none | |
| 1970 * Out: none | |
| 1971 * | |
| 1972 * Return: 0 (FALSE) : In case of error. | |
| 1973 * >= 1 (TRUE) : Successful operation. | |
| 1974 * | |
| 1975 ******************************************************************************/ | |
| 1976 | |
| 1977 SYS_BOOL | |
| 1978 SER_ImmediateSwitch (void) | |
| 1979 { | |
| 1980 #if SERIAL_DYNAMIC_SWITCH | |
| 1981 int uart_id; | |
| 1982 SYS_BOOL valid_config = 0; | |
| 1983 T_AppliSerialInfo *serial_info = &appli_ser_cfg_info; | |
| 1984 SYS_UWORD8 nb_allowed_config = serial_info->num_config; | |
| 1985 SYS_UWORD16 *allowed_config; | |
| 1986 int flow; | |
| 1987 T_SerialDriver serial_flows[SER_MAX_NUMBER_OF_FLOWS]; | |
| 1988 T_tr_UartId uart_nb; | |
| 1989 | |
| 1990 /* | |
| 1991 * First check if the new serial configuration is actually different from | |
| 1992 * the previous one. A return is used to simplify the code. | |
| 1993 */ | |
| 1994 | |
| 1995 if (!memcmp (ser_new_cfg, | |
| 1996 ser_cfg_info, | |
| 1997 NUMBER_OF_TR_UART)) | |
| 1998 return (1); /* new config and old config are identical => nothing to do */ | |
| 1999 | |
| 2000 /* | |
| 2001 * Then check if the new serial config is valid or not. | |
| 2002 * At that point, we assume that a serial config is valid if and only if the | |
| 2003 * Bluetooth HCI flow is still enabled and still uses the same UART. | |
| 2004 * Reset the current serial config, and compute the new one. | |
| 2005 */ | |
| 2006 | |
| 2007 serial_cfg = 0x0048; /* All dummies */ | |
| 2008 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 2009 | |
| 2010 switch (ser_new_cfg[uart_id]) { | |
| 2011 | |
| 2012 case G23_PANEL: | |
| 2013 serial_cfg = serial_cfg + | |
| 2014 ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK))); | |
| 2015 break; | |
| 2016 | |
| 2017 case RIVIERA_TRACE_MUX: | |
| 2018 serial_cfg = serial_cfg + | |
| 2019 ((uart_id + 1) << (12 - (4 * SER_LAYER_1))); | |
| 2020 break; | |
| 2021 | |
| 2022 case FD_AT_COMMAND: | |
| 2023 serial_cfg = serial_cfg + | |
| 2024 ((uart_id + 1) << (12 - (4 * SER_FAX_DATA))); | |
| 2025 break; | |
| 2026 | |
| 2027 case BLUETOOTH_HCI: | |
| 2028 serial_cfg = serial_cfg + | |
| 2029 ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI))); | |
| 2030 | |
| 2031 /* | |
| 2032 * Check if the Bluetooth HCI flow is enabled on the same UART. | |
| 2033 */ | |
| 2034 | |
| 2035 if (ser_cfg_info[uart_id] == BLUETOOTH_HCI) | |
| 2036 valid_config = 1; | |
| 2037 | |
| 2038 break; | |
| 2039 | |
| 2040 case DUMMY: | |
| 2041 break; | |
| 2042 } | |
| 2043 } | |
| 2044 | |
| 2045 if (!valid_config) | |
| 2046 return (0); /* Bluetooth HCI flow not enabled in the new serial config, | |
| 2047 or enabled but using a different UART. */ | |
| 2048 | |
| 2049 /* | |
| 2050 * Finally check if the new serial config is allowed by the application. | |
| 2051 */ | |
| 2052 | |
| 2053 valid_config = 0; | |
| 2054 while ((nb_allowed_config > 0) && !valid_config) { | |
| 2055 | |
| 2056 nb_allowed_config--; | |
| 2057 allowed_config = (SYS_UWORD16 *) | |
| 2058 &(serial_info->allowed_config[nb_allowed_config]); | |
| 2059 | |
| 2060 if (serial_cfg == *allowed_config) | |
| 2061 valid_config = 1; | |
| 2062 } | |
| 2063 | |
| 2064 if (!valid_config) /* the new config is not allowed by the application */ | |
| 2065 return (0); | |
| 2066 | |
| 2067 /* | |
| 2068 * From now on, Dynamic Switch is being processed. | |
| 2069 */ | |
| 2070 | |
| 2071 dynamic_switch = 1; | |
| 2072 | |
| 2073 /* | |
| 2074 * Disable UART interrupts until new serial config setup is complete. | |
| 2075 */ | |
| 2076 | |
| 2077 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11)) | |
| 2078 IQ_Mask (IQ_UART_IRDA_IT); | |
| 2079 #endif | |
| 2080 IQ_Mask (IQ_UART_IT); | |
| 2081 | |
| 2082 /* | |
| 2083 * Reset UARTs set-up. | |
| 2084 */ | |
| 2085 | |
| 2086 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 2087 | |
| 2088 int_uart[uart_id].device_used = 0; | |
| 2089 int_uart[uart_id].deep_sleep_set_up = 0; | |
| 2090 int_uart[uart_id].interrupt_handler = NULL; | |
| 2091 } | |
| 2092 | |
| 2093 /* | |
| 2094 * All function pointers are set to dummy functions. | |
| 2095 */ | |
| 2096 | |
| 2097 rvf_disable (21); /* beginning of the critical section */ | |
| 2098 | |
| 2099 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++) | |
| 2100 tr_functions[flow] = &dummy_trace; | |
| 2101 | |
| 2102 fd_functions = &dummy_fax_data; | |
| 2103 bt_functions = &dummy_bt_hci; | |
| 2104 | |
| 2105 rvf_enable (); /* end of the critical section */ | |
| 2106 | |
| 2107 /* | |
| 2108 * Calls the Exit function of the UARTFAX driver if it was previously used. | |
| 2109 */ | |
| 2110 | |
| 2111 if (uart_fd_initialized) { | |
| 2112 | |
| 2113 /* | |
| 2114 * UART IrDA can't be used for F&D/AT-Cmd flow => UART Modem was used | |
| 2115 * by the F&D/AT-Cmd flow. | |
| 2116 */ | |
| 2117 | |
| 2118 if (UAF_Exit (UAF_UART_1) == FD_OK) { | |
| 2119 uart_fd_initialized = 0; | |
| 2120 } | |
| 2121 } | |
| 2122 else { | |
| 2123 | |
| 2124 /* | |
| 2125 * AT that point, since the Bluetooth HCI flow already uses one UART, | |
| 2126 * and since the second UART was not used by the F&D/AT-Cmd flow, we | |
| 2127 * assume it was used by a Trace flow. Therefore, the HISR used to | |
| 2128 * reset and restart the sleep timer is deleted. | |
| 2129 */ | |
| 2130 | |
| 2131 (void) NU_Delete_HISR (&timer_hisr_ctrl_block); | |
| 2132 } | |
| 2133 | |
| 2134 /* | |
| 2135 * Initialization of the new flows (Only AT-Cmd/F&D or Riviera/Layer1 Trace) | |
| 2136 * and their associated UARTs HW (Irda or Modem) & SW (Trace or Fax&Data). | |
| 2137 */ | |
| 2138 | |
| 2139 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++) { | |
| 2140 | |
| 2141 serial_flows[flow] = (T_SerialDriver) | |
| 2142 ((serial_cfg >> (12 - flow * 4)) & 0x000F); | |
| 2143 | |
| 2144 switch (serial_flows[flow]) { | |
| 2145 | |
| 2146 /* | |
| 2147 * For Riviera/Layer1 Trace flow, default baudrate is 115200 bps | |
| 2148 * and callback function is defined in rvt_def_i.h. | |
| 2149 */ | |
| 2150 | |
| 2151 case UART_IRDA_TRACE: | |
| 2152 case UART_MODEM_TRACE: | |
| 2153 | |
| 2154 if (serial_flows[flow] == UART_IRDA_TRACE) | |
| 2155 uart_nb = UA_UART_0; | |
| 2156 else /* if (serial_flows[flow] == UART_MODEM_TRACE) */ | |
| 2157 uart_nb = UA_UART_1; | |
| 2158 | |
| 2159 if (flow == SER_LAYER_1) { | |
| 2160 | |
| 2161 UA_Init (uart_nb, | |
| 2162 TR_BAUD_CONFIG, | |
| 2163 rvt_activate_RX_HISR); | |
| 2164 | |
| 2165 /* | |
| 2166 * Create the HISR used to reset and restart the sleep | |
| 2167 * timer in case of incoming characters on the Trace flow. | |
| 2168 * The stack is entirely filled with the pattern 0xFE. | |
| 2169 */ | |
| 2170 | |
| 2171 memset (&(timer_hisr_stack[0]), | |
| 2172 0xFE, | |
| 2173 TIMER_HISR_STACK_SIZE); | |
| 2174 | |
| 2175 (void) NU_Create_HISR ( | |
| 2176 &timer_hisr_ctrl_block, | |
| 2177 "Tim_HISR", | |
| 2178 SER_restart_uart_sleep_timer, | |
| 2179 TIMER_HISR_PRIORITY, | |
| 2180 &(timer_hisr_stack[0]), | |
| 2181 TIMER_HISR_STACK_SIZE); | |
| 2182 } | |
| 2183 else /* Other Trace flows are disabled */ | |
| 2184 initialize_uart_sleep (uart_nb); | |
| 2185 break; | |
| 2186 | |
| 2187 /* | |
| 2188 * For At-Cmd/F&D flow, functions are called in the appropriate | |
| 2189 * order with the saved parameters. | |
| 2190 * This has been figured out from the G23 initialization. | |
| 2191 */ | |
| 2192 | |
| 2193 case UART_MODEM_FAX_DATA: | |
| 2194 | |
| 2195 /* Global Initialization */ | |
| 2196 if (UAF_Init (UAF_UART_1) == FD_OK) { | |
| 2197 uart_fd_initialized = 1; | |
| 2198 } | |
| 2199 | |
| 2200 /* Disable the driver */ | |
| 2201 UAF_Enable (UAF_UART_1, | |
| 2202 0); | |
| 2203 | |
| 2204 /* Set the SW Buffers parameters */ | |
| 2205 UAF_SetBuffer (UAF_UART_1, | |
| 2206 data_flow_parameters.bufSize, | |
| 2207 data_flow_parameters.rxThreshold, | |
| 2208 data_flow_parameters.txThreshold); | |
| 2209 | |
| 2210 /* Set the Escape Sequence parameters (1st call) */ | |
| 2211 UAF_SetEscape (UAF_UART_1, | |
| 2212 data_flow_parameters.escChar[0], | |
| 2213 data_flow_parameters.guardPeriod[0]); | |
| 2214 | |
| 2215 /* Set the Communication parameters (1st call) */ | |
| 2216 UAF_SetComPar (UAF_UART_1, | |
| 2217 data_flow_parameters.baudrate[0], | |
| 2218 data_flow_parameters.bpc[0], | |
| 2219 data_flow_parameters.sb[0], | |
| 2220 data_flow_parameters.parity[0]); | |
| 2221 | |
| 2222 /* Set the Flow Control parameters (1st call) */ | |
| 2223 UAF_SetFlowCtrl (UAF_UART_1, | |
| 2224 data_flow_parameters.fcMode[0], | |
| 2225 data_flow_parameters.XON[0], | |
| 2226 data_flow_parameters.XOFF[0]); | |
| 2227 | |
| 2228 /* Set the Communication parameters (2nd call) */ | |
| 2229 UAF_SetComPar (UAF_UART_1, | |
| 2230 data_flow_parameters.baudrate[1], | |
| 2231 data_flow_parameters.bpc[1], | |
| 2232 data_flow_parameters.sb[1], | |
| 2233 data_flow_parameters.parity[1]); | |
| 2234 | |
| 2235 /* Set the Flow Control parameters (2nd call) */ | |
| 2236 UAF_SetFlowCtrl (UAF_UART_1, | |
| 2237 data_flow_parameters.fcMode[1], | |
| 2238 data_flow_parameters.XON[1], | |
| 2239 data_flow_parameters.XOFF[1]); | |
| 2240 | |
| 2241 /* Set the Escape Sequence parameters (2nd call) */ | |
| 2242 UAF_SetEscape (UAF_UART_1, | |
| 2243 data_flow_parameters.escChar[1], | |
| 2244 data_flow_parameters.guardPeriod[1]); | |
| 2245 | |
| 2246 /* Enable the driver */ | |
| 2247 UAF_Enable (UAF_UART_1, | |
| 2248 1); | |
| 2249 | |
| 2250 /* Get the number of input bytes available */ | |
| 2251 UAF_InpAvail (UAF_UART_1); | |
| 2252 | |
| 2253 /* Set the readOutFunc and the suspend mode */ | |
| 2254 UAF_ReadData (UAF_UART_1, | |
| 2255 data_flow_parameters.suspend_rd, | |
| 2256 data_flow_parameters.readOutFunc); | |
| 2257 | |
| 2258 /* Get the number of output bytes available (1st call) */ | |
| 2259 UAF_OutpAvail (UAF_UART_1); | |
| 2260 | |
| 2261 /* Set the states of the V.24 status lines (1st call) */ | |
| 2262 UAF_SetLineState (UAF_UART_1, | |
| 2263 data_flow_parameters.state[0], | |
| 2264 data_flow_parameters.mask[0]); | |
| 2265 | |
| 2266 /* Set the states of the V.24 status lines (2nd call) */ | |
| 2267 UAF_SetLineState (UAF_UART_1, | |
| 2268 data_flow_parameters.state[1], | |
| 2269 data_flow_parameters.mask[1]); | |
| 2270 | |
| 2271 /* Set the states of the V.24 status lines (3rd call) */ | |
| 2272 UAF_SetLineState (UAF_UART_1, | |
| 2273 data_flow_parameters.state[2], | |
| 2274 data_flow_parameters.mask[2]); | |
| 2275 | |
| 2276 /* Set the states of the V.24 status lines (4th call) */ | |
| 2277 UAF_SetLineState (UAF_UART_1, | |
| 2278 data_flow_parameters.state[3], | |
| 2279 data_flow_parameters.mask[3]); | |
| 2280 | |
| 2281 /* Set the writeInFunc and the suspend mode */ | |
| 2282 UAF_WriteData (UAF_UART_1, | |
| 2283 data_flow_parameters.suspend_wr, | |
| 2284 data_flow_parameters.writeInFunc); | |
| 2285 | |
| 2286 /* Get the number of output bytes available (2nd call) */ | |
| 2287 UAF_OutpAvail (UAF_UART_1); | |
| 2288 | |
| 2289 break; | |
| 2290 | |
| 2291 case UART_IRDA_BT_HCI: | |
| 2292 case UART_MODEM_BT_HCI: | |
| 2293 /* | |
| 2294 * Nothing to initialize for Bluetooth HCI flow since it does | |
| 2295 * use the same UART. | |
| 2296 */ | |
| 2297 | |
| 2298 case DUMMY_TRACE: | |
| 2299 case DUMMY_FAX_DATA: | |
| 2300 case DUMMY_BT_HCI: | |
| 2301 /* | |
| 2302 * Of course nothing to perform for Dummy flows. | |
| 2303 */ | |
| 2304 | |
| 2305 break; | |
| 2306 } | |
| 2307 } | |
| 2308 | |
| 2309 /* | |
| 2310 * All function pointers are set to the appropriate functions set. | |
| 2311 */ | |
| 2312 | |
| 2313 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++){ | |
| 2314 | |
| 2315 /* | |
| 2316 * For Dummy flows, pointers to dummy functions are already set. | |
| 2317 */ | |
| 2318 | |
| 2319 if ((serial_flows[flow] != DUMMY_TRACE) && | |
| 2320 (serial_flows[flow] != DUMMY_FAX_DATA) && | |
| 2321 (serial_flows[flow] != DUMMY_BT_HCI)) { | |
| 2322 | |
| 2323 rvf_disable (21); /* beginning of the critical section */ | |
| 2324 set_flow_functions (flow, serial_flows[flow]); | |
| 2325 rvf_enable (); /* end of the critical section */ | |
| 2326 } | |
| 2327 } | |
| 2328 | |
| 2329 /* | |
| 2330 * Dynamic Switch has been processed. | |
| 2331 * The new serial config is actually stored. | |
| 2332 */ | |
| 2333 | |
| 2334 dynamic_switch = 0; | |
| 2335 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) | |
| 2336 ser_cfg_info[uart_id] = ser_new_cfg[uart_id]; | |
| 2337 | |
| 2338 /* | |
| 2339 * Re-enable UART interrupts. | |
| 2340 */ | |
| 2341 | |
| 2342 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11)) | |
| 2343 IQ_Unmask (IQ_UART_IRDA_IT); | |
| 2344 #endif | |
| 2345 IQ_Unmask (IQ_UART_IT); | |
| 2346 | |
| 2347 #endif | |
| 2348 /* | |
| 2349 * Real Dynamic Switch is only available with Bluetooth AND all chips but | |
| 2350 * Calypso+. | |
| 2351 */ | |
| 2352 | |
| 2353 return (1); | |
| 2354 } | |
| 2355 | |
| 2356 /******************************************************************************* | |
| 2357 * | |
| 2358 * All functions SER_tr_xxx and SER_fd_xxx call a function of the UART trace | |
| 2359 * driver or the UART fax & data driver. | |
| 2360 * All functions SER_bt_xxx call a function of the UART Bluetooth HCI driver. | |
| 2361 * See the function call for parameters and return values. | |
| 2362 * | |
| 2363 ******************************************************************************/ | |
| 2364 | |
| 2365 void | |
| 2366 SER_tr_Init (int serial_data_flow, | |
| 2367 T_tr_Baudrate baudrate, | |
| 2368 void (callback_function (void))) | |
| 2369 { | |
| 2370 tr_functions[serial_data_flow]->tr_Init ( | |
| 2371 tr_functions[serial_data_flow]->device, baudrate, callback_function); | |
| 2372 } | |
| 2373 | |
| 2374 SYS_UWORD32 | |
| 2375 SER_tr_ReadNChars (int serial_data_flow, | |
| 2376 char *buffer, | |
| 2377 SYS_UWORD32 chars_to_read) | |
| 2378 { | |
| 2379 return (tr_functions[serial_data_flow]->tr_ReadNChars ( | |
| 2380 tr_functions[serial_data_flow]->device, buffer, chars_to_read)); | |
| 2381 } | |
| 2382 | |
| 2383 SYS_UWORD32 | |
| 2384 SER_tr_ReadNBytes (int serial_data_flow, | |
| 2385 char *buffer, | |
| 2386 SYS_UWORD32 chars_to_read, | |
| 2387 SYS_BOOL *eof_detected) | |
| 2388 { | |
| 2389 return (tr_functions[serial_data_flow]->tr_ReadNBytes ( | |
| 2390 tr_functions[serial_data_flow]->device, buffer, chars_to_read, eof_detected)); | |
| 2391 } | |
| 2392 | |
| 2393 SYS_UWORD32 | |
| 2394 SER_tr_WriteNChars (int serial_data_flow, | |
| 2395 char *buffer, | |
| 2396 SYS_UWORD32 chars_to_write) | |
| 2397 { | |
| 2398 return (tr_functions[serial_data_flow]->tr_WriteNChars ( | |
| 2399 tr_functions[serial_data_flow]->device, buffer, chars_to_write)); | |
| 2400 } | |
| 2401 | |
| 2402 SYS_UWORD32 | |
| 2403 SER_tr_EncapsulateNChars (int serial_data_flow, | |
| 2404 char *buffer, | |
| 2405 SYS_UWORD32 chars_to_write) | |
| 2406 { | |
| 2407 return (tr_functions[serial_data_flow]->tr_EncapsulateNChars ( | |
| 2408 tr_functions[serial_data_flow]->device, buffer, chars_to_write)); | |
| 2409 } | |
| 2410 | |
| 2411 SYS_UWORD32 | |
| 2412 SER_tr_WriteNBytes (int serial_data_flow, | |
| 2413 SYS_UWORD8 *buffer, | |
| 2414 SYS_UWORD32 chars_to_write) | |
| 2415 { | |
| 2416 return (tr_functions[serial_data_flow]->tr_WriteNBytes ( | |
| 2417 tr_functions[serial_data_flow]->device, buffer, chars_to_write)); | |
| 2418 } | |
| 2419 | |
| 2420 void | |
| 2421 SER_tr_WriteChar (int serial_data_flow, | |
| 2422 char character) | |
| 2423 { | |
| 2424 tr_functions[serial_data_flow]->tr_WriteChar ( | |
| 2425 tr_functions[serial_data_flow]->device, character); | |
| 2426 } | |
| 2427 | |
| 2428 void | |
| 2429 SER_tr_WriteString (int serial_data_flow, | |
| 2430 char *buffer) | |
| 2431 { | |
| 2432 tr_functions[serial_data_flow]->tr_WriteString ( | |
| 2433 tr_functions[serial_data_flow]->device, buffer); | |
| 2434 } | |
| 2435 | |
| 2436 SYS_BOOL | |
| 2437 SER_tr_EnterSleep (int serial_data_flow) | |
| 2438 { | |
| 2439 return (tr_functions[serial_data_flow]->tr_EnterSleep ( | |
| 2440 tr_functions[serial_data_flow]->device)); | |
| 2441 } | |
| 2442 | |
| 2443 void | |
| 2444 SER_tr_WakeUp (int serial_data_flow) | |
| 2445 { | |
| 2446 tr_functions[serial_data_flow]->tr_WakeUp ( | |
| 2447 tr_functions[serial_data_flow]->device); | |
| 2448 } | |
| 2449 | |
| 2450 /* Dummy function for backward compatibility. */ | |
| 2451 T_FDRET | |
| 2452 SER_fd_Init (void) | |
| 2453 { | |
| 2454 return (FD_OK); | |
| 2455 } | |
| 2456 | |
| 2457 T_FDRET | |
| 2458 SER_fd_Initialize (void) | |
| 2459 { | |
| 2460 T_FDRET status; | |
| 2461 | |
| 2462 #if SERIAL_DYNAMIC_SWITCH | |
| 2463 data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE; | |
| 2464 #else | |
| 2465 bufSize = FD_MAX_BUFFER_SIZE; | |
| 2466 #endif | |
| 2467 status = fd_functions->fd_Initialize (fd_functions->device); | |
| 2468 | |
| 2469 #if SERIAL_DYNAMIC_SWITCH | |
| 2470 /* | |
| 2471 * Check if the UARTFAX driver has actually been initialized. | |
| 2472 */ | |
| 2473 | |
| 2474 if ((fd_functions->fd_Initialize == UAF_Init) && | |
| 2475 (status = FD_OK)) { | |
| 2476 | |
| 2477 uart_fd_initialized = 1; | |
| 2478 } | |
| 2479 #endif | |
| 2480 | |
| 2481 return (status); | |
| 2482 } | |
| 2483 | |
| 2484 T_FDRET | |
| 2485 SER_fd_Enable (SYS_BOOL enable) | |
| 2486 { | |
| 2487 return (fd_functions->fd_Enable (fd_functions->device, enable)); | |
| 2488 } | |
| 2489 | |
| 2490 T_FDRET | |
| 2491 SER_fd_SetComPar (T_baudrate baudrate, | |
| 2492 T_bitsPerCharacter bpc, | |
| 2493 T_stopBits sb, | |
| 2494 T_parity parity) | |
| 2495 { | |
| 2496 #if SERIAL_DYNAMIC_SWITCH | |
| 2497 if (fd_UAF_SetComPar < 2) { | |
| 2498 | |
| 2499 /* | |
| 2500 * Stores the parameters in order to be able to retrieve them in case of | |
| 2501 * Dynamic Sitch. | |
| 2502 */ | |
| 2503 | |
| 2504 data_flow_parameters.baudrate[fd_UAF_SetComPar] = baudrate; | |
| 2505 data_flow_parameters.bpc[fd_UAF_SetComPar] = bpc; | |
| 2506 data_flow_parameters.sb[fd_UAF_SetComPar] = sb; | |
| 2507 data_flow_parameters.parity[fd_UAF_SetComPar] = parity; | |
| 2508 | |
| 2509 /* | |
| 2510 * Number of calls to SER_fd_SetComPar. | |
| 2511 */ | |
| 2512 | |
| 2513 fd_UAF_SetComPar++; | |
| 2514 } | |
| 2515 #endif | |
| 2516 | |
| 2517 return (fd_functions->fd_SetComPar ( | |
| 2518 fd_functions->device, baudrate, bpc, sb, parity)); | |
| 2519 } | |
| 2520 | |
| 2521 T_FDRET | |
| 2522 SER_fd_SetBuffer (SYS_UWORD16 bufSize, | |
| 2523 SYS_UWORD16 rxThreshold, | |
| 2524 SYS_UWORD16 txThreshold) | |
| 2525 { | |
| 2526 #if SERIAL_DYNAMIC_SWITCH | |
| 2527 if (fd_UAF_SetBuffer < 1) { | |
| 2528 | |
| 2529 /* | |
| 2530 * Stores the parameters in order to be able to retrieve them in case of | |
| 2531 * Dynamic Sitch. | |
| 2532 */ | |
| 2533 | |
| 2534 data_flow_parameters.bufSize = bufSize; | |
| 2535 data_flow_parameters.rxThreshold = rxThreshold; | |
| 2536 data_flow_parameters.txThreshold = txThreshold; | |
| 2537 | |
| 2538 /* | |
| 2539 * Number of calls to SER_fd_SetBuffer. | |
| 2540 */ | |
| 2541 | |
| 2542 fd_UAF_SetBuffer++; | |
| 2543 } | |
| 2544 #endif | |
| 2545 | |
| 2546 return (fd_functions->fd_SetBuffer ( | |
| 2547 fd_functions->device, bufSize, rxThreshold, txThreshold)); | |
| 2548 } | |
| 2549 | |
| 2550 T_FDRET | |
| 2551 SER_fd_SetFlowCtrl (T_flowCtrlMode fcMode, | |
| 2552 SYS_UWORD8 XON, | |
| 2553 SYS_UWORD8 XOFF) | |
| 2554 { | |
| 2555 #if SERIAL_DYNAMIC_SWITCH | |
| 2556 if (fd_UAF_SetFlowCtrl < 2) { | |
| 2557 | |
| 2558 /* | |
| 2559 * Stores the parameters in order to be able to retrieve them in case of | |
| 2560 * Dynamic Sitch. | |
| 2561 */ | |
| 2562 | |
| 2563 data_flow_parameters.fcMode[fd_UAF_SetFlowCtrl] = fcMode; | |
| 2564 data_flow_parameters.XON[fd_UAF_SetFlowCtrl] = XON; | |
| 2565 data_flow_parameters.XOFF[fd_UAF_SetFlowCtrl] = XOFF; | |
| 2566 | |
| 2567 /* | |
| 2568 * Number of calls to SER_fd_SetFlowCtrl. | |
| 2569 */ | |
| 2570 | |
| 2571 fd_UAF_SetFlowCtrl++; | |
| 2572 } | |
| 2573 #endif | |
| 2574 | |
| 2575 return (fd_functions->fd_SetFlowCtrl ( | |
| 2576 fd_functions->device, fcMode, XON, XOFF)); | |
| 2577 } | |
| 2578 | |
| 2579 T_FDRET | |
| 2580 SER_fd_SetEscape (char escChar, | |
| 2581 SYS_UWORD16 guardPeriod) | |
| 2582 { | |
| 2583 #if SERIAL_DYNAMIC_SWITCH | |
| 2584 if (fd_UAF_SetEscape < 2) { | |
| 2585 | |
| 2586 /* | |
| 2587 * Stores the parameters in order to be able to retrieve them in case of | |
| 2588 * Dynamic Sitch. | |
| 2589 */ | |
| 2590 | |
| 2591 data_flow_parameters.escChar[fd_UAF_SetEscape] = escChar; | |
| 2592 data_flow_parameters.guardPeriod[fd_UAF_SetEscape] = guardPeriod; | |
| 2593 | |
| 2594 /* | |
| 2595 * Number of calls to SER_fd_SetEscape. | |
| 2596 */ | |
| 2597 | |
| 2598 fd_UAF_SetEscape++; | |
| 2599 } | |
| 2600 #endif | |
| 2601 | |
| 2602 return (fd_functions->fd_SetEscape ( | |
| 2603 fd_functions->device, escChar, guardPeriod)); | |
| 2604 } | |
| 2605 | |
| 2606 T_FDRET | |
| 2607 SER_fd_InpAvail (void) | |
| 2608 { | |
| 2609 return (fd_functions->fd_InpAvail (fd_functions->device)); | |
| 2610 } | |
| 2611 | |
| 2612 T_FDRET | |
| 2613 SER_fd_OutpAvail (void) | |
| 2614 { | |
| 2615 return (fd_functions->fd_OutpAvail (fd_functions->device)); | |
| 2616 } | |
| 2617 | |
| 2618 T_FDRET | |
| 2619 SER_fd_EnterSleep (void) | |
| 2620 { | |
| 2621 return (fd_functions->fd_EnterSleep (fd_functions->device)); | |
| 2622 } | |
| 2623 | |
| 2624 T_FDRET | |
| 2625 SER_fd_WakeUp (void) | |
| 2626 { | |
| 2627 return (fd_functions->fd_WakeUp (fd_functions->device)); | |
| 2628 } | |
| 2629 | |
| 2630 T_FDRET | |
| 2631 SER_fd_ReadData (T_suspendMode suspend, | |
| 2632 void (readOutFunc (SYS_BOOL cldFromIrq, | |
| 2633 T_reInstMode *reInstall, | |
| 2634 SYS_UWORD8 nsource, | |
| 2635 SYS_UWORD8 *source[], | |
| 2636 SYS_UWORD16 size[], | |
| 2637 SYS_UWORD32 state))) | |
| 2638 { | |
| 2639 #if SERIAL_DYNAMIC_SWITCH | |
| 2640 if (fd_UAF_ReadData < 1) { | |
| 2641 | |
| 2642 /* | |
| 2643 * Stores the parameters in order to be able to retrieve them in case of | |
| 2644 * Dynamic Sitch. | |
| 2645 */ | |
| 2646 | |
| 2647 data_flow_parameters.suspend_rd = suspend; | |
| 2648 data_flow_parameters.readOutFunc = readOutFunc; | |
| 2649 | |
| 2650 /* | |
| 2651 * Number of calls to SER_fd_ReadData. | |
| 2652 */ | |
| 2653 | |
| 2654 fd_UAF_ReadData++; | |
| 2655 } | |
| 2656 #endif | |
| 2657 | |
| 2658 return (fd_functions->fd_ReadData ( | |
| 2659 fd_functions->device, suspend, readOutFunc)); | |
| 2660 } | |
| 2661 | |
| 2662 T_FDRET | |
| 2663 SER_fd_WriteData (T_suspendMode suspend, | |
| 2664 void (writeInFunc (SYS_BOOL cldFromIrq, | |
| 2665 T_reInstMode *reInstall, | |
| 2666 SYS_UWORD8 ndest, | |
| 2667 SYS_UWORD8 *dest[], | |
| 2668 SYS_UWORD16 size[]))) | |
| 2669 { | |
| 2670 #if SERIAL_DYNAMIC_SWITCH | |
| 2671 if (fd_UAF_WriteData < 1) { | |
| 2672 | |
| 2673 /* | |
| 2674 * Stores the parameters in order to be able to retrieve them in case of | |
| 2675 * Dynamic Sitch. | |
| 2676 */ | |
| 2677 | |
| 2678 data_flow_parameters.suspend_wr = suspend; | |
| 2679 data_flow_parameters.writeInFunc = writeInFunc; | |
| 2680 | |
| 2681 /* | |
| 2682 * Number of calls to SER_fd_WriteData. | |
| 2683 */ | |
| 2684 | |
| 2685 fd_UAF_WriteData++; | |
| 2686 } | |
| 2687 #endif | |
| 2688 | |
| 2689 return (fd_functions->fd_WriteData ( | |
| 2690 fd_functions->device, suspend, writeInFunc)); | |
| 2691 } | |
| 2692 | |
| 2693 T_FDRET | |
| 2694 SER_fd_StopRec (void) | |
| 2695 { | |
| 2696 return (fd_functions->fd_StopRec (fd_functions->device)); | |
| 2697 } | |
| 2698 | |
| 2699 T_FDRET | |
| 2700 SER_fd_StartRec (void) | |
| 2701 { | |
| 2702 return (fd_functions->fd_StartRec (fd_functions->device)); | |
| 2703 } | |
| 2704 | |
| 2705 T_FDRET | |
| 2706 SER_fd_GetLineState (SYS_UWORD32 *state) | |
| 2707 { | |
| 2708 return (fd_functions->fd_GetLineState (fd_functions->device, state)); | |
| 2709 } | |
| 2710 | |
| 2711 T_FDRET | |
| 2712 SER_fd_SetLineState (SYS_UWORD32 state, | |
| 2713 SYS_UWORD32 mask) | |
| 2714 { | |
| 2715 #if SERIAL_DYNAMIC_SWITCH | |
| 2716 if (fd_UAF_SetLineState < 4) { | |
| 2717 | |
| 2718 /* | |
| 2719 * Stores the parameters in order to be able to retrieve them in case of | |
| 2720 * Dynamic Sitch. | |
| 2721 */ | |
| 2722 | |
| 2723 data_flow_parameters.state[fd_UAF_SetLineState] = state; | |
| 2724 data_flow_parameters.mask[fd_UAF_SetLineState] = mask; | |
| 2725 | |
| 2726 /* | |
| 2727 * Number of calls to SER_fd_SetLineState. | |
| 2728 */ | |
| 2729 | |
| 2730 fd_UAF_SetLineState++; | |
| 2731 } | |
| 2732 #endif | |
| 2733 | |
| 2734 return (fd_functions->fd_SetLineState (fd_functions->device, state, mask)); | |
| 2735 } | |
| 2736 | |
| 2737 T_FDRET | |
| 2738 SER_fd_CheckXEmpty (void) | |
| 2739 { | |
| 2740 return (fd_functions->fd_CheckXEmpty (fd_functions->device)); | |
| 2741 } | |
| 2742 | |
| 2743 #ifdef BTEMOBILE | |
| 2744 T_HCI_RET | |
| 2745 SER_bt_Init (void) | |
| 2746 { | |
| 2747 return (bt_functions->bt_Init (bt_functions->device)); | |
| 2748 } | |
| 2749 | |
| 2750 T_HCI_RET | |
| 2751 SER_bt_Start (void) | |
| 2752 { | |
| 2753 return (bt_functions->bt_Start ()); | |
| 2754 } | |
| 2755 | |
| 2756 T_HCI_RET | |
| 2757 SER_bt_Stop (void) | |
| 2758 { | |
| 2759 return (bt_functions->bt_Stop ()); | |
| 2760 } | |
| 2761 | |
| 2762 T_HCI_RET | |
| 2763 SER_bt_Kill (void) | |
| 2764 { | |
| 2765 return (bt_functions->bt_Kill ()); | |
| 2766 } | |
| 2767 | |
| 2768 T_HCI_RET | |
| 2769 SER_bt_SetBaudrate (UINT8 baudrate) | |
| 2770 { | |
| 2771 return (bt_functions->bt_SetBaudrate (baudrate)); | |
| 2772 } | |
| 2773 | |
| 2774 T_HCI_RET SER_bt_TransmitPacket (void *uart_tx_buffer) | |
| 2775 { | |
| 2776 return (bt_functions->bt_TransmitPacket (uart_tx_buffer)); | |
| 2777 } | |
| 2778 | |
| 2779 SYS_BOOL SER_bt_EnterSleep (void) | |
| 2780 { | |
| 2781 return (bt_functions->bt_EnterSleep()); | |
| 2782 } | |
| 2783 | |
| 2784 void SER_bt_WakeUp (void) | |
| 2785 { | |
| 2786 bt_functions->bt_WakeUp(); | |
| 2787 } | |
| 2788 #endif /* BTEMOBILE */ | |
| 2789 | |
| 2790 /******************************************************************************* | |
| 2791 * | |
| 2792 * SER_UartSleepStatus | |
| 2793 * | |
| 2794 * Purpose: This function checks if both UARTs are ready to enter Deep Sleep. | |
| 2795 * | |
| 2796 * Parameters: In : none | |
| 2797 * Out: none | |
| 2798 * | |
| 2799 * Return: 0 : Deep Sleep is not possible. | |
| 2800 * >= 1 : Deep Sleep is possible. | |
| 2801 * | |
| 2802 ******************************************************************************/ | |
| 2803 | |
| 2804 SYS_BOOL | |
| 2805 SER_UartSleepStatus (void) | |
| 2806 { | |
| 2807 t_uart *uart; | |
| 2808 int uart_id; | |
| 2809 SYS_BOOL status; | |
| 2810 | |
| 2811 /* | |
| 2812 * Check first if the sleep timer is active or if a Dynamic Switch is | |
| 2813 * being processed. A return is used to simplify the code. | |
| 2814 */ | |
| 2815 | |
| 2816 #if SERIAL_DYNAMIC_SWITCH | |
| 2817 if (uart_sleep_timer_enabled || dynamic_switch) | |
| 2818 #else | |
| 2819 if (uart_sleep_timer_enabled) | |
| 2820 #endif | |
| 2821 return (0); | |
| 2822 | |
| 2823 /* | |
| 2824 * Check if both UARTs are ready to enter Deep Sleep. | |
| 2825 */ | |
| 2826 | |
| 2827 status = 1; | |
| 2828 uart_id = 0; | |
| 2829 while ((uart_id < NUMBER_OF_TR_UART) && | |
| 2830 (status)) { | |
| 2831 | |
| 2832 uart = &(int_uart[uart_id]); | |
| 2833 | |
| 2834 /* | |
| 2835 * Check if the specified UART is actually used. | |
| 2836 */ | |
| 2837 | |
| 2838 if (uart->device_used) { | |
| 2839 | |
| 2840 /* | |
| 2841 * Check if the specified UART is used by a Trace or | |
| 2842 * by a Fax & Data flow. | |
| 2843 */ | |
| 2844 | |
| 2845 if (uart->flow_type == TRACE_FLOW) | |
| 2846 status = SER_tr_EnterSleep (uart->flow_id); | |
| 2847 | |
| 2848 else | |
| 2849 if (uart->flow_type == FAX_DATA_FLOW) | |
| 2850 status = (SYS_BOOL) SER_fd_EnterSleep (); | |
| 2851 #ifdef BTEMOBILE | |
| 2852 else | |
| 2853 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 2854 status = SER_bt_EnterSleep(); | |
| 2855 #endif | |
| 2856 else | |
| 2857 status = 0; | |
| 2858 | |
| 2859 if (status) { | |
| 2860 | |
| 2861 /* | |
| 2862 * The specified UART is now set up for Deep Sleep. | |
| 2863 */ | |
| 2864 | |
| 2865 uart->deep_sleep_set_up = 1; | |
| 2866 | |
| 2867 } | |
| 2868 } | |
| 2869 | |
| 2870 uart_id++; | |
| 2871 } | |
| 2872 | |
| 2873 /* | |
| 2874 * Check if Deep Sleep is finally possible. | |
| 2875 * If not revert eventual Deep Sleep settings. | |
| 2876 */ | |
| 2877 | |
| 2878 if (!status) { | |
| 2879 | |
| 2880 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 2881 | |
| 2882 uart = &(int_uart[uart_id]); | |
| 2883 | |
| 2884 /* | |
| 2885 * If the specified used UART has already been set up for | |
| 2886 * Deep Sleep, revert these settings. | |
| 2887 */ | |
| 2888 | |
| 2889 if ((uart->device_used) && | |
| 2890 (uart->deep_sleep_set_up)) { | |
| 2891 | |
| 2892 /* | |
| 2893 * Check if the specified UART is used by a Trace or | |
| 2894 * by a Fax & Data flow. | |
| 2895 * Bluetooth HCI can not yet handled Deep Sleep Mode. | |
| 2896 */ | |
| 2897 | |
| 2898 if (uart->flow_type == TRACE_FLOW) | |
| 2899 SER_tr_WakeUp (uart->flow_id); | |
| 2900 | |
| 2901 else | |
| 2902 if (uart->flow_type == FAX_DATA_FLOW) | |
| 2903 SER_fd_WakeUp (); | |
| 2904 #ifdef BTEMOBILE | |
| 2905 else | |
| 2906 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 2907 SER_bt_WakeUp (); | |
| 2908 #endif | |
| 2909 uart->deep_sleep_set_up = 0; | |
| 2910 | |
| 2911 } | |
| 2912 } | |
| 2913 } | |
| 2914 | |
| 2915 return (status); | |
| 2916 } | |
| 2917 | |
| 2918 | |
| 2919 /******************************************************************************* | |
| 2920 * | |
| 2921 * SER_WakeUpUarts | |
| 2922 * | |
| 2923 * Purpose: This function wakes up used UARTs after Deep Sleep. | |
| 2924 * | |
| 2925 * Parameters: In : none | |
| 2926 * Out: none | |
| 2927 * | |
| 2928 * Return: none | |
| 2929 * | |
| 2930 ******************************************************************************/ | |
| 2931 | |
| 2932 void | |
| 2933 SER_WakeUpUarts (void) | |
| 2934 { | |
| 2935 t_uart *uart; | |
| 2936 int uart_id; | |
| 2937 | |
| 2938 if (uart_sleep_timer_enabled) | |
| 2939 start_uart_sleep_timer (); | |
| 2940 | |
| 2941 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 2942 | |
| 2943 uart = &(int_uart[uart_id]); | |
| 2944 | |
| 2945 /* | |
| 2946 * Check if the specified UART is actually used, and has not yet | |
| 2947 * been waked up. | |
| 2948 */ | |
| 2949 | |
| 2950 if ((uart->device_used) && | |
| 2951 (uart->deep_sleep_set_up)) { | |
| 2952 | |
| 2953 /* | |
| 2954 * Check if the specified UART is used by a Trace or | |
| 2955 * by a Fax & Data flow. | |
| 2956 * Bluetooth HCI can not yet handled Deep Sleep Mode. | |
| 2957 */ | |
| 2958 | |
| 2959 if (uart->flow_type == TRACE_FLOW) | |
| 2960 SER_tr_WakeUp (uart->flow_id); | |
| 2961 | |
| 2962 else | |
| 2963 if (uart->flow_type == FAX_DATA_FLOW) | |
| 2964 SER_fd_WakeUp (); | |
| 2965 #ifdef BTEMOBILE | |
| 2966 else | |
| 2967 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 2968 SER_bt_WakeUp (); | |
| 2969 #endif | |
| 2970 /* | |
| 2971 * The specified UART is no more set up for Deep Sleep. | |
| 2972 */ | |
| 2973 | |
| 2974 uart->deep_sleep_set_up = 0; | |
| 2975 | |
| 2976 } | |
| 2977 } | |
| 2978 } | |
| 2979 | |
| 2980 | |
| 2981 /******************************************************************************* | |
| 2982 * | |
| 2983 * SER_restart_uart_sleep_timer | |
| 2984 * | |
| 2985 * Purpose : Resets and restarts the sleep timer each time some characters are | |
| 2986 * received. | |
| 2987 * | |
| 2988 * Arguments: In : none | |
| 2989 * Out: none | |
| 2990 * | |
| 2991 * Returns : none | |
| 2992 * | |
| 2993 ******************************************************************************/ | |
| 2994 | |
| 2995 void | |
| 2996 SER_restart_uart_sleep_timer (void) | |
| 2997 { | |
| 2998 /* | |
| 2999 * First disable the timer. | |
| 3000 */ | |
| 3001 | |
| 3002 (void) NU_Control_Timer (&uart_sleep_timer, | |
| 3003 NU_DISABLE_TIMER); | |
| 3004 | |
| 3005 /* | |
| 3006 * Then start again this timer for a new period. | |
| 3007 */ | |
| 3008 | |
| 3009 start_uart_sleep_timer (); | |
| 3010 } | |
| 3011 | |
| 3012 | |
| 3013 /******************************************************************************* | |
| 3014 * | |
| 3015 * SER_activate_timer_hisr | |
| 3016 * | |
| 3017 * Purpose : Activates the timer HISR to reset and restart the sleep timer | |
| 3018 * each time some characters are received. | |
| 3019 * | |
| 3020 * Arguments: In : none | |
| 3021 * Out: none | |
| 3022 * | |
| 3023 * Returns : none | |
| 3024 * | |
| 3025 ******************************************************************************/ | |
| 3026 | |
| 3027 void | |
| 3028 SER_activate_timer_hisr (void) | |
| 3029 { | |
| 3030 (void) NU_Activate_HISR (&timer_hisr_ctrl_block); | |
| 3031 } | |
| 3032 | |
| 3033 | |
| 3034 #if ((CHIPSET == 2) || (CHIPSET == 3)) | |
| 3035 | |
| 3036 /******************************************************************************* | |
| 3037 * | |
| 3038 * SER_uart_handler | |
| 3039 * | |
| 3040 * Purpose : UART interrupt handler. | |
| 3041 * | |
| 3042 * Arguments: In : none | |
| 3043 * Out: none | |
| 3044 * | |
| 3045 * Returns : none | |
| 3046 * | |
| 3047 ******************************************************************************/ | |
| 3048 | |
| 3049 void | |
| 3050 SER_uart_handler (void) | |
| 3051 { | |
| 3052 SYS_UWORD8 interrupt_status; | |
| 3053 t_uart *uart; | |
| 3054 int uart_id; | |
| 3055 SYS_BOOL it_identified; | |
| 3056 | |
| 3057 it_identified = 0; | |
| 3058 | |
| 3059 /* | |
| 3060 * Check first for a wake-up interrupt. | |
| 3061 */ | |
| 3062 | |
| 3063 uart_id = 0; | |
| 3064 while ((uart_id < NUMBER_OF_TR_UART) && | |
| 3065 (!it_identified)) { | |
| 3066 | |
| 3067 uart = &(int_uart[uart_id]); | |
| 3068 interrupt_status = READ_UART_REGISTER (uart, SSR); | |
| 3069 | |
| 3070 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ | |
| 3071 | |
| 3072 it_identified = 1; | |
| 3073 uart_sleep_timer_enabled = 1; | |
| 3074 DISABLE_WAKE_UP_INTERRUPT (uart); | |
| 3075 } | |
| 3076 | |
| 3077 uart_id++; | |
| 3078 } | |
| 3079 | |
| 3080 /* | |
| 3081 * If no wake-up interrupt has been detected, check then systematically | |
| 3082 * both UARTs for other interrupt causes. | |
| 3083 */ | |
| 3084 | |
| 3085 if (!it_identified) { | |
| 3086 | |
| 3087 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { | |
| 3088 | |
| 3089 uart = &(int_uart[uart_id]); | |
| 3090 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3091 | |
| 3092 if (!(interrupt_status & IT_NOT_PENDING)) { | |
| 3093 | |
| 3094 it_identified = 1; | |
| 3095 (*(uart->interrupt_handler)) (uart_id, interrupt_status); | |
| 3096 | |
| 3097 } else { | |
| 3098 | |
| 3099 if ((uart_id == UA_UART_1) && (!it_identified)) | |
| 3100 uart_spurious_interrupts++; | |
| 3101 } | |
| 3102 } | |
| 3103 } | |
| 3104 } | |
| 3105 | |
| 3106 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) | |
| 3107 | |
| 3108 /******************************************************************************* | |
| 3109 * | |
| 3110 * SER_uart_modem_handler | |
| 3111 * | |
| 3112 * Purpose : UART MODEM interrupt handler. | |
| 3113 * | |
| 3114 * Arguments: In : none | |
| 3115 * Out: none | |
| 3116 * | |
| 3117 * Returns : none | |
| 3118 * | |
| 3119 ******************************************************************************/ | |
| 3120 | |
| 3121 void | |
| 3122 SER_uart_modem_handler (void) | |
| 3123 { | |
| 3124 SYS_UWORD8 interrupt_status; | |
| 3125 t_uart *uart; | |
| 3126 SYS_BOOL it_wakeup_identified; | |
| 3127 | |
| 3128 it_wakeup_identified = 0; | |
| 3129 uart = &(int_uart[UA_UART_1]); | |
| 3130 | |
| 3131 /* | |
| 3132 * Check first for a wake-up interrupt. | |
| 3133 */ | |
| 3134 | |
| 3135 interrupt_status = READ_UART_REGISTER (uart, SSR); | |
| 3136 | |
| 3137 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ | |
| 3138 | |
| 3139 it_wakeup_identified = 1; | |
| 3140 uart_sleep_timer_enabled = 1; | |
| 3141 #ifdef BTEMOBILE | |
| 3142 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 3143 { | |
| 3144 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3145 (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status); | |
| 3146 } | |
| 3147 #endif /* BTEMOBILE */ | |
| 3148 DISABLE_WAKE_UP_INTERRUPT (uart); | |
| 3149 } | |
| 3150 | |
| 3151 /* | |
| 3152 * If no wake-up interrupt has been detected, check UART for other | |
| 3153 * interrupt causes. | |
| 3154 */ | |
| 3155 | |
| 3156 if (!it_wakeup_identified) { | |
| 3157 | |
| 3158 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3159 | |
| 3160 if (!(interrupt_status & IT_NOT_PENDING)) | |
| 3161 (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status); | |
| 3162 | |
| 3163 else | |
| 3164 uart_modem_spurious_interrupts++; | |
| 3165 } | |
| 3166 } | |
| 3167 | |
| 3168 | |
| 3169 /******************************************************************************* | |
| 3170 * | |
| 3171 * SER_uart_irda_handler | |
| 3172 * | |
| 3173 * Purpose : UART IrDA interrupt handler. | |
| 3174 * | |
| 3175 * Arguments: In : none | |
| 3176 * Out: none | |
| 3177 * | |
| 3178 * Returns : none | |
| 3179 * | |
| 3180 ******************************************************************************/ | |
| 3181 | |
| 3182 void | |
| 3183 SER_uart_irda_handler (void) | |
| 3184 { | |
| 3185 SYS_UWORD8 interrupt_status; | |
| 3186 t_uart *uart; | |
| 3187 SYS_BOOL it_wakeup_identified; | |
| 3188 | |
| 3189 it_wakeup_identified = 0; | |
| 3190 uart = &(int_uart[UA_UART_0]); | |
| 3191 | |
| 3192 /* | |
| 3193 * Check first for a wake-up interrupt. | |
| 3194 */ | |
| 3195 | |
| 3196 interrupt_status = READ_UART_REGISTER (uart, SSR); | |
| 3197 | |
| 3198 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ | |
| 3199 | |
| 3200 it_wakeup_identified = 1; | |
| 3201 uart_sleep_timer_enabled = 1; | |
| 3202 #ifdef BTEMOBILE | |
| 3203 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 3204 { | |
| 3205 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3206 (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status); | |
| 3207 } | |
| 3208 #endif /* BTEMOBILE */ | |
| 3209 DISABLE_WAKE_UP_INTERRUPT (uart); | |
| 3210 } | |
| 3211 | |
| 3212 /* | |
| 3213 * If no wake-up interrupt has been detected, check UART for other | |
| 3214 * interrupt causes. | |
| 3215 */ | |
| 3216 | |
| 3217 if (!it_wakeup_identified) { | |
| 3218 | |
| 3219 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3220 | |
| 3221 if (!(interrupt_status & IT_NOT_PENDING)) | |
| 3222 (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status); | |
| 3223 | |
| 3224 else | |
| 3225 uart_irda_spurious_interrupts++; | |
| 3226 } | |
| 3227 } | |
| 3228 | |
| 3229 #endif | |
| 3230 | |
| 3231 #if (CHIPSET == 12) | |
| 3232 /******************************************************************************* | |
| 3233 * | |
| 3234 * SER_uart_modem2_handler | |
| 3235 * | |
| 3236 * Purpose : UART IrDA interrupt handler. | |
| 3237 * | |
| 3238 * Arguments: In : none | |
| 3239 * Out: none | |
| 3240 * | |
| 3241 * Returns : none | |
| 3242 * | |
| 3243 ******************************************************************************/ | |
| 3244 | |
| 3245 void | |
| 3246 SER_uart_modem2_handler (void) | |
| 3247 { | |
| 3248 SYS_UWORD8 interrupt_status; | |
| 3249 t_uart *uart; | |
| 3250 SYS_BOOL it_wakeup_identified; | |
| 3251 | |
| 3252 it_wakeup_identified = 0; | |
| 3253 uart = &(int_uart[UA_UART_2]); | |
| 3254 | |
| 3255 /* | |
| 3256 * Check first for a wake-up interrupt. | |
| 3257 */ | |
| 3258 | |
| 3259 interrupt_status = READ_UART_REGISTER (uart, SSR); | |
| 3260 | |
| 3261 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ | |
| 3262 | |
| 3263 it_wakeup_identified = 1; | |
| 3264 uart_sleep_timer_enabled = 1; | |
| 3265 #ifdef BTEMOBILE | |
| 3266 if (uart->flow_type == BLUETOOTH_HCI_FLOW) | |
| 3267 { | |
| 3268 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3269 (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status); | |
| 3270 } | |
| 3271 #endif /* BTEMOBILE */ | |
| 3272 DISABLE_WAKE_UP_INTERRUPT (uart); | |
| 3273 } | |
| 3274 | |
| 3275 /* | |
| 3276 * If no wake-up interrupt has been detected, check UART for other | |
| 3277 * interrupt causes. | |
| 3278 */ | |
| 3279 | |
| 3280 if (!it_wakeup_identified) { | |
| 3281 | |
| 3282 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; | |
| 3283 | |
| 3284 if (!(interrupt_status & IT_NOT_PENDING)) | |
| 3285 (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status); | |
| 3286 | |
| 3287 else | |
| 3288 uart_modem2_spurious_interrupts++; | |
| 3289 } | |
| 3290 } | |
| 3291 | |
| 3292 #endif | |
| 3293 | |
| 3294 /* | |
| 3295 * Temporary functions. | |
| 3296 * | |
| 3297 * FreeCalypso note: I'll put them back in if they are actually needed. | |
| 3298 */ | |
| 3299 | |
| 3300 #if 0 | |
| 3301 | |
| 3302 void | |
| 3303 UT_Init (int device_id, | |
| 3304 int baudrate, | |
| 3305 void (callback_function (void))) | |
| 3306 { | |
| 3307 SER_tr_Init (SER_PROTOCOL_STACK, baudrate, callback_function); | |
| 3308 } | |
| 3309 | |
| 3310 SYS_UWORD32 | |
| 3311 UT_ReadNChars (int device_id, | |
| 3312 char *buffer, | |
| 3313 SYS_UWORD32 chars_to_read) | |
| 3314 { | |
| 3315 return (SER_tr_ReadNChars (SER_PROTOCOL_STACK, buffer, chars_to_read)); | |
| 3316 } | |
| 3317 | |
| 3318 SYS_UWORD32 | |
| 3319 UT_WriteNChars (int device_id, | |
| 3320 char *buffer, | |
| 3321 SYS_UWORD32 chars_to_write) | |
| 3322 { | |
| 3323 return (SER_tr_WriteNChars (SER_PROTOCOL_STACK, buffer, chars_to_write)); | |
| 3324 } | |
| 3325 | |
| 3326 void | |
| 3327 UT_WriteChar (int device_id, | |
| 3328 char character) | |
| 3329 { | |
| 3330 SER_tr_WriteChar (SER_PROTOCOL_STACK, character); | |
| 3331 } | |
| 3332 | |
| 3333 void | |
| 3334 UT_WriteString (int device_id, | |
| 3335 char *buffer) | |
| 3336 { | |
| 3337 SER_tr_WriteString (SER_PROTOCOL_STACK, buffer); | |
| 3338 } | |
| 3339 | |
| 3340 short | |
| 3341 UF_Init (SYS_UWORD8 deviceNo) | |
| 3342 { | |
| 3343 return (SER_fd_Init ()); | |
| 3344 } | |
| 3345 | |
| 3346 short | |
| 3347 UF_Enable (SYS_UWORD8 deviceNo, | |
| 3348 SYS_BOOL enable) | |
| 3349 { | |
| 3350 return (SER_fd_Enable (enable)); | |
| 3351 } | |
| 3352 | |
| 3353 short | |
| 3354 UF_SetComPar (SYS_UWORD8 deviceNo, | |
| 3355 T_baudrate baudrate, | |
| 3356 T_bitsPerCharacter bpc, | |
| 3357 T_stopBits sb, | |
| 3358 T_parity parity) | |
| 3359 { | |
| 3360 return (SER_fd_SetComPar (baudrate, | |
| 3361 bpc, | |
| 3362 sb, | |
| 3363 parity)); | |
| 3364 } | |
| 3365 | |
| 3366 short | |
| 3367 UF_SetBuffer (SYS_UWORD8 deviceNo, | |
| 3368 SYS_UWORD16 bufSize, | |
| 3369 SYS_UWORD16 rxThreshold, | |
| 3370 SYS_UWORD16 txThreshold) | |
| 3371 { | |
| 3372 return (SER_fd_SetBuffer (bufSize, rxThreshold, txThreshold)); | |
| 3373 } | |
| 3374 | |
| 3375 short | |
| 3376 UF_SetFlowCtrl (SYS_UWORD8 deviceNo, | |
| 3377 T_flowCtrlMode fcMode, | |
| 3378 SYS_UWORD8 XON, | |
| 3379 SYS_UWORD8 XOFF) | |
| 3380 { | |
| 3381 return (SER_fd_SetFlowCtrl (fcMode, XON, XOFF)); | |
| 3382 } | |
| 3383 | |
| 3384 short | |
| 3385 UF_SetEscape (SYS_UWORD8 deviceNo, | |
| 3386 SYS_UWORD8 escChar, | |
| 3387 SYS_UWORD16 guardPeriod) | |
| 3388 { | |
| 3389 return (SER_fd_SetEscape (escChar, guardPeriod)); | |
| 3390 } | |
| 3391 | |
| 3392 short | |
| 3393 UF_InpAvail (SYS_UWORD8 deviceNo) | |
| 3394 { | |
| 3395 return (SER_fd_InpAvail ()); | |
| 3396 } | |
| 3397 | |
| 3398 short | |
| 3399 UF_OutpAvail (SYS_UWORD8 deviceNo) | |
| 3400 { | |
| 3401 return (SER_fd_OutpAvail ()); | |
| 3402 } | |
| 3403 | |
| 3404 short | |
| 3405 UF_ReadData (SYS_UWORD8 deviceNo, | |
| 3406 T_suspendMode suspend, | |
| 3407 void (readOutFunc (SYS_BOOL cldFromIrq, | |
| 3408 T_reInstMode *reInstall, | |
| 3409 SYS_UWORD8 nsource, | |
| 3410 SYS_UWORD8 *source[], | |
| 3411 SYS_UWORD16 size[], | |
| 3412 SYS_UWORD32 state))) | |
| 3413 { | |
| 3414 return (SER_fd_ReadData (suspend, readOutFunc)); | |
| 3415 } | |
| 3416 | |
| 3417 short | |
| 3418 UF_WriteData (SYS_UWORD8 deviceNo, | |
| 3419 T_suspendMode suspend, | |
| 3420 void (writeInFunc (SYS_BOOL cldFromIrq, | |
| 3421 T_reInstMode *reInstall, | |
| 3422 SYS_UWORD8 ndest, | |
| 3423 SYS_UWORD8 *dest[], | |
| 3424 SYS_UWORD16 size[]))) | |
| 3425 { | |
| 3426 return (SER_fd_WriteData (suspend, writeInFunc)); | |
| 3427 } | |
| 3428 | |
| 3429 short | |
| 3430 UF_StopRec (SYS_UWORD8 deviceNo) | |
| 3431 { | |
| 3432 return (SER_fd_StopRec ()); | |
| 3433 } | |
| 3434 | |
| 3435 short | |
| 3436 UF_StartRec (SYS_UWORD8 deviceNo) | |
| 3437 { | |
| 3438 return (SER_fd_StartRec ()); | |
| 3439 } | |
| 3440 | |
| 3441 short | |
| 3442 UF_GetLineState (SYS_UWORD8 deviceNo, | |
| 3443 SYS_UWORD32 *state) | |
| 3444 { | |
| 3445 return (SER_fd_GetLineState (state)); | |
| 3446 } | |
| 3447 | |
| 3448 short | |
| 3449 UF_SetLineState (SYS_UWORD8 deviceNo, | |
| 3450 SYS_UWORD32 state, | |
| 3451 SYS_UWORD32 mask) | |
| 3452 { | |
| 3453 return (SER_fd_SetLineState (state, mask)); | |
| 3454 } | |
| 3455 | |
| 3456 short | |
| 3457 UF_CheckXEmpty (SYS_UWORD8 deviceNo) | |
| 3458 { | |
| 3459 return (SER_fd_CheckXEmpty ()); | |
| 3460 } | |
| 3461 #endif |
