annotate src/gpf/tst/drv/usart.c @ 6:8b2a9a374324

src/gpf: addition of Magnetite src/gpf2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 08:15:49 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 | File: usart.c
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 | Copyright 2002 Texas Instruments Berlin, AG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 | All rights reserved.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 | This file is confidential and a trade secret of Texas
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 | Instruments Berlin, AG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 | The receipt of or possession of this file does not convey
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 | any rights to reproduce or disclose its contents or to
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 | manufacture, use, or sell anything it may describe, in
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 | whole, or in part, without the specific written consent of
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 | Texas Instruments Berlin, AG.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 +-----------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 | Purpose : This Modul defines functions for actual or simulated
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 | USART comunication between two PS-Frames.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 | Use US_set_mode() to select actual USART under windows95 or
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 | under windowsNT, or to select simulated USART under win95/NT
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 +-----------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #ifndef __USART_C__
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #define __USART_C__
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /*==== INCLUDES ===================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include <windows.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 #ifndef _VXWORKS_
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include <stdarg.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #include <stdio.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 #include "typedefs.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #include "usart.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include "printtofile.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*==== CONSTANTS ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 #define COM_ERROR (CE_FRAME | CE_IOE | CE_OVERRUN)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #define XON 0x11
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 #define XOFF 0x13
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 #define READER_THREAD_EXIT_CODE 4711
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 #define USART_BUFFER_SIZE 0x10000 /* 65536 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 #define FILE_MAX_CHUNK 0x0ffff
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 #define FILE_SLOW_DOWN 0x01
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 #ifdef _TOOLS_
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 #define USART_SEND_TIMEOUT 60000
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 #define USART_RCV_TIMEOUT 120000
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 #else /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 #define USART_SEND_TIMEOUT INFINITE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 #define USART_RCV_TIMEOUT INFINITE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 #endif /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /*==== TYPES ======================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 typedef struct
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 UBYTE Connects;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 UBYTE Type;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 USHORT CH1_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 USHORT CH2_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 UBYTE CH1_CTS;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 UBYTE CH2_CTS;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 UBYTE CH1_data[USART_BUFFER_SIZE];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 UBYTE CH2_data[USART_BUFFER_SIZE];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 } T_USARTStream;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 /*==== EXPORT =====================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 /*==== PRIVATE ====================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /*==== VARIABLES ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 static int m_mode=UT_MODE_NT;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 static long int m_send_timeout=(long int)USART_SEND_TIMEOUT;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 static long int m_rcv_timeout =(long int)USART_RCV_TIMEOUT;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 static int first_ut_init = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 static FILE* m_file=NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 static OVERLAPPED gWriteOverLap;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 static OVERLAPPED gReadOverLap;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 static int ReaderThreadExitRequest = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 LOCAL void (*ReceiveCallback)(void) = NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 static int initialized = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 #ifdef COM_AUTOSEARCH
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 static int P = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 static int usart_in, usart_out;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 T_USARTStream *Stream;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 HANDLE SemCH1_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 HANDLE SemCH2_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 HANDLE SemCH1_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 HANDLE SemCH2_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 HANDLE USARTMemHandle;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 HANDLE *semRCVFull=0, *semRCVEmpty=0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 HANDLE *semSNDFull=0, *semSNDEmpty=0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 HANDLE ut_sema_handle;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 UBYTE *InBuffer, *OutBuffer, *readPointer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 USHORT *InCounter, *OutCounter;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 UBYTE *CTS = NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 static HANDLE hComDev = INVALID_HANDLE_VALUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 static HANDLE hThread = INVALID_HANDLE_VALUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 static int mem_closed = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 static int cls_cnt = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 static int snd_cnt = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 /*==== FUNCTIONS ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 | STATE : code ROUTINE : US_set_mode |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 PURPOSE : With this function you can select the UART mode
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 #define US_MODE_95 1
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 #define US_MODE_NT 2
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 #define US_MODE_SIM 3
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 #define US_MODE_FILE 4
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 void US_set_mode(int mode)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 m_mode=mode;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 | STATE : code ROUTINE : US_set_mode |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 PURPOSE : With this function get the seleced UART mode
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 #define US_MODE_95 1
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 #define US_MODE_NT 2
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 #define US_MODE_SIM 3
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 #define US_MODE_FILE 4
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 int US_get_mode()
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 return m_mode;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 | PROJECT : GSM-PS (6147) MODULE : USARTSIM |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 | STATE : code ROUTINE : unlockUSARTMemory |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 PURPOSE : unlocks the previously locked shared memory area.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 LOCAL void markRCVBufferEmpty (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 ReleaseSemaphore (*semRCVEmpty,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 LOCAL void markSNDBufferFull (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 ReleaseSemaphore (*semSNDFull,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 | PROJECT : GSM-PS (6147) MODULE : USARTSIM |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 | STATE : code ROUTINE : waitForSNDBufferEmpty |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 PURPOSE : waits for send buffer becoming empty
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 RETURNS : 0 .. send buffer is empty
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 -1 .. given up
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 LOCAL int waitForSNDBufferEmpty (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (WaitForSingleObject (*semSNDEmpty, m_send_timeout) NEQ WAIT_OBJECT_0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 int err = GetLastError();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 PrintToFile("USART: error code %d\n", err);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 PrintToFile("USART: giving up sending with %d ms timeout :-(\n", m_send_timeout);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 return -1; /* give up */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 return 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 | PROJECT : GSM-PS (6147) MODULE : USARTSIM |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 | STATE : code ROUTINE : createUSARTMemory |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 PURPOSE : Create two pipes for byte oriented data exchange
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 between two win32 processes
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 LOCAL void *createUSARTMemory (char *name, ULONG size)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 char newname[40];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 * create two Semaphores pairs to protect the send data to be
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 * overwritten before they have read by the receiver
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 sprintf (newname, "%s_CH1empty", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 SemCH1_empty = CreateSemaphore (NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 if (SemCH1_empty EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 sprintf (newname, "%s_CH1full", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 SemCH1_full = CreateSemaphore (NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 if (SemCH1_full EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 sprintf (newname, "%s_CH2empty", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 SemCH2_empty = CreateSemaphore (NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 if (SemCH2_empty EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 sprintf (newname, "%s_CH2full", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 SemCH2_full = CreateSemaphore (NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 1,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 if (SemCH2_full EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 * create a shared memory area
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 sprintf (newname, "UT_Mem_%s", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 USARTMemHandle
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 = CreateFileMapping (
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 (HANDLE) 0xffffffff, /* memory-mapped */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 NULL, /* no security */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 PAGE_READWRITE, /* read/write access */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 (DWORD) 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 /* memory size */ (DWORD) size,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 newname /* name of sh. mem */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 if (USARTMemHandle EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 * map the shared memory area into the address space of the process
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 * and return the startaddress.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 return MapViewOfFile (USARTMemHandle,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 FILE_MAP_WRITE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 | PROJECT : GSM-PS (6147) MODULE : USARTSIM |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 | STATE : code ROUTINE : openUSARTMemory |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 PURPOSE : open a shared memory area for character exchange
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 between two WIN32 processes
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 LOCAL void *openUSARTMemory (char *name, ULONG size)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 char newname[30];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 * open the Semaphores
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 sprintf (newname, "%s_CH1empty", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 SemCH1_empty = OpenSemaphore (SEMAPHORE_MODIFY_STATE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 | SYNCHRONIZE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 FALSE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 if (SemCH1_empty EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 sprintf (newname, "%s_CH1full", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 SemCH1_full = OpenSemaphore (SEMAPHORE_MODIFY_STATE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 | SYNCHRONIZE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 FALSE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 if (SemCH1_full EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 sprintf (newname, "%s_CH2empty", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 SemCH2_empty = OpenSemaphore (SEMAPHORE_MODIFY_STATE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 | SYNCHRONIZE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 FALSE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 if (SemCH2_empty EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 sprintf (newname, "%s_CH2full", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 SemCH2_full = OpenSemaphore (SEMAPHORE_MODIFY_STATE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 | SYNCHRONIZE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 FALSE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 newname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 if (SemCH2_full EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 * open the shared memory area
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 sprintf (newname, "UT_Mem_%s", name);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 USARTMemHandle =
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 OpenFileMapping (FILE_MAP_WRITE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 FALSE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 newname); /* name of sh. mem */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 if (USARTMemHandle EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 return NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 * map the shared memory area into the address space of the process
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373 * and return the startaddress.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 return MapViewOfFile (USARTMemHandle,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 FILE_MAP_WRITE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 | STATE : code ROUTINE : waitForRCVBufferFull |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 PURPOSE : This function waits until an incoming character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 is signaled with the EV_RXCHAR Event
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 LOCAL void waitForRCVBufferFull (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 case US_MODE_95: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 static COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 static DWORD dwErrors;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 static DWORD EvtMask = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 BOOL validReceive = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 do
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 SetCommMask (hComDev, EV_RXCHAR) ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 WaitCommEvent (hComDev, &EvtMask, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 ClearCommError (hComDev, &dwErrors, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 if (dwErrors & COM_ERROR)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 PurgeComm (hComDev, PURGE_RXCLEAR|PURGE_RXABORT);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 validReceive = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 } while (!validReceive);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419 static COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 static DWORD dwErrors;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 static DWORD EvtMask = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 BOOL validReceive = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 do
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 SetCommMask (hComDev, EV_RXCHAR) ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 WaitCommEvent (hComDev, &EvtMask, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428 ClearCommError (hComDev, &dwErrors, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 if (dwErrors & COM_ERROR)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431 PurgeComm (hComDev, PURGE_RXCLEAR|PURGE_RXABORT);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 validReceive = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 } while (!validReceive && !ReaderThreadExitRequest);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 if (WaitForSingleObject (*semRCVFull, m_rcv_timeout) NEQ WAIT_OBJECT_0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 PrintToFile("USART: no stack connected\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 | STATE : code ROUTINE : _readerThread |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 PURPOSE : This function is the central signal handling function. It is
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458 installed as a thread and waits for the occurance of an
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 event and then calls the installed callback function
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 of the application.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 LOCAL void _readerThread (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 while (ReaderThreadExitRequest == FALSE)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 waitForRCVBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 ReceiveCallback ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 ReaderThreadExitRequest = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 ExitThread(READER_THREAD_EXIT_CODE);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 | STATE : code ROUTINE : convertBaudrate |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 PURPOSE : This function convert the constants for the baudrates in
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 usart.h into the equvalent constants for WIN32 comm.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485 LOCAL DWORD convertBaudrate (DWORD br)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 switch (br)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489 case US_BAUD_256000:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 return CBR_256000;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492 case US_BAUD_128000:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 return CBR_128000;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 case US_BAUD_115200:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496 return CBR_115200;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498 case US_BAUD_57600:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 return CBR_57600;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 case US_BAUD_38400:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 return CBR_38400;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 case US_BAUD_19200:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505 return CBR_19200;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 case US_BAUD_14400:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 return CBR_14400;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
510 case US_BAUD_9600:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511 return CBR_9600;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513 case US_BAUD_4800:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514 return CBR_4800;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 case US_BAUD_2400:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 return CBR_2400;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 case US_BAUD_1200:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 return CBR_1200;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 case US_BAUD_600:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 return CBR_600;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525 case US_BAUD_300:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 return CBR_300;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529 /* no CBR_xxx constant found -> return value itsself */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530 return br;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
534 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537 | STATE : code ROUTINE : sioInit |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540 PURPOSE : This function opens the given comm port and initiializes
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 the DCB with baudrate and flowcontrol parameters.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
544
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 LOCAL BOOL sioInit (int portNr,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 unsigned int baudrate,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 unsigned int bufSize,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 char flowCtrl)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 char szPort[10];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 DCB stDCB;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 COMMTIMEOUTS stTimeout ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 DWORD dwErrorFlags;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554 COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 sprintf (szPort, "\\\\.\\COM%d", portNr) ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 // open the communication device
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561 if (m_mode==UT_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 hComDev = CreateFile
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563 (
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 szPort,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565 GENERIC_READ | GENERIC_WRITE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
566 0, /* exclusive access */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
567 NULL, /* no security attrs */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 OPEN_EXISTING,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 FILE_FLAG_OVERLAPPED,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
570 NULL
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573 hComDev = CreateFile
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 (
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
575 szPort,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
576 GENERIC_READ | GENERIC_WRITE,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
577 0, // exclusive access
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
578 NULL, // no security attrs
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
579 OPEN_EXISTING,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
580 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
581 NULL
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
582 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
583 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
584
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
585 if (hComDev EQ INVALID_HANDLE_VALUE)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
586 return FALSE; // device not available
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
587
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
588 if (m_mode==UT_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
589 gReadOverLap.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
590 if (!gReadOverLap.hEvent)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
591 return ( FALSE );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
592
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
593 gReadOverLap.Offset = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
594 gReadOverLap.OffsetHigh = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
595
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
596 gWriteOverLap.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
597 if (!(gWriteOverLap.hEvent))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
598 return ( FALSE );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
599
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
600 gWriteOverLap.Offset = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
601 gWriteOverLap.OffsetHigh = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
602 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
603
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
604 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
605 // get any early notifications
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
606 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
607 SetCommMask (hComDev, EV_RXCHAR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
608
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
609 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
610 // setup device buffers
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
611 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
612 SetupComm (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
613 bufSize,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
614 bufSize
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
615 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
616
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
617 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
618 // purge any information in the buffer
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
619 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
620 PurgeComm (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
621 PURGE_TXABORT | PURGE_RXABORT |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
622 PURGE_TXCLEAR | PURGE_RXCLEAR
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
623 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
624
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
625 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
626 // setup up and enable communication
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
627 // device. If not possible close
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
628 // communication and abort function.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
629 // ------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
630 if (!GetCommState (hComDev, &stDCB))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
631 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
632 SetCommMask (hComDev, 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
633 CloseHandle (hComDev);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
634 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
635 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
636
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
637 stDCB.DCBlength = sizeof (stDCB); // sizeof(DCB)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
638
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
639 switch (flowCtrl)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
640 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
641 case 'N':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
642 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
643 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
644 stDCB.fDtrControl = DTR_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
645 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
646 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
647 case 'D':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
648 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
649 stDCB.fOutxDsrFlow = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
650 stDCB.fDtrControl = DTR_CONTROL_HANDSHAKE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
651 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
652 stDCB.XonLim = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
653 stDCB.XoffLim = 50;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
654 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
655 case 'R':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
656 stDCB.fOutxCtsFlow = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
657 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
658 stDCB.fDtrControl = DTR_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
659 stDCB.fRtsControl = RTS_CONTROL_HANDSHAKE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
660 stDCB.XonLim = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
661 stDCB.XoffLim = 50;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
662 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
663 case 'P':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
664 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
665 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
666 stDCB.fDtrControl = DTR_CONTROL_ENABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
667 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
668 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
669 case 'V':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
670 if (m_mode==US_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
671 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
672 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
673 stDCB.fDtrControl = DTR_CONTROL_ENABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
674 stDCB.fRtsControl = RTS_CONTROL_ENABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
675 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
676 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
677 /*lint -fallthrough*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
678 /* go on if not US_MODE_NT */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
679 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
680 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
681 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
682 fprintf (stdout,"flow control: %c ...", flowCtrl);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
683
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
684 stDCB.BaudRate = baudrate; // current baud rate
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
685 stDCB.fBinary = TRUE; // binary mode, no EOF check
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
686 stDCB.fParity = FALSE; // enable parity checking
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
687 stDCB.fDsrSensitivity = FALSE; // DSR sensitivity
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
688 stDCB.fTXContinueOnXoff = FALSE; // XOFF continues Tx
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
689 stDCB.fOutX = FALSE; // XON/XOFF out flow control
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
690 stDCB.fInX = FALSE; // XON/XOFF in flow control
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
691 stDCB.fErrorChar = FALSE; // enable error replacement
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
692 stDCB.fNull = FALSE; // enable null stripping
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
693 stDCB.fAbortOnError = FALSE; // abort reads/writes on error
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
694 stDCB.ByteSize = 8; // number of bits/byte, 4-8
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
695 stDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
696 stDCB.StopBits = ONESTOPBIT;// 0,1,2 = 1, 1.5, 2
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
697 stDCB.XonChar = 0; // Tx and Rx XON character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
698 stDCB.XoffChar = 0; // Tx and Rx XOFF character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
699 stDCB.ErrorChar = 0; // error replacement character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
700 stDCB.EofChar = 0; // end of input character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
701 stDCB.EvtChar = 0; // received event character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
702
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
703 if (!SetCommState (hComDev, &stDCB))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
704 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
705 SetCommMask (hComDev, 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
706 CloseHandle (hComDev);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
707 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
708 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
709
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
710 if (!GetCommTimeouts (hComDev, &stTimeout))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
711 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
712
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
713 stTimeout.WriteTotalTimeoutConstant = 0xffff;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
714 stTimeout.WriteTotalTimeoutMultiplier = 0xffff;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
715 stTimeout.ReadTotalTimeoutConstant = 0xffff;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
716 stTimeout.ReadIntervalTimeout = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
717 stTimeout.ReadTotalTimeoutMultiplier = 0xffff;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
718
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
719 if (!SetCommTimeouts (hComDev, &stTimeout))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
720 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
721
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
722 PurgeComm (hComDev, PURGE_RXCLEAR
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
723 |PURGE_TXCLEAR
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
724 |PURGE_TXABORT
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
725 |PURGE_RXABORT);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
726
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
727 ClearCommError (hComDev, &dwErrorFlags, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
728
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
729 return TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
730 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
731
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
732 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
733 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
734 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
735 | STATE : code ROUTINE : sioRead |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
736 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
737
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
738 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
739
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
740 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
741
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
742 LOCAL BOOL sioRead (BYTE *bpRXBuffer, // RX Buffer
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
743 DWORD *pdwLength) // IN: Bytes to read
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
744 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
745 DWORD dwBytesToRead = *pdwLength ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
746 DWORD dwErrorFlags;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
747 COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
748
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
749 if (hComDev == INVALID_HANDLE_VALUE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
750 OR *pdwLength == 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
751 return FALSE; // device not available
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
752
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
753 if (m_mode==US_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
754 if (!ReadFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
755 bpRXBuffer,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
756 dwBytesToRead,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
757 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
758 &gReadOverLap))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
759 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
760 // if there was a problem
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
761 if (GetLastError() == ERROR_IO_PENDING)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
762 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
763 /* asynchronous i/o is still in progress */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
764
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
765 /* do something else for a while */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
766 /* check on the results of the asynchronous read */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
767 if (GetOverlappedResult(gReadOverLap.hEvent, &gReadOverLap,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
768 pdwLength, TRUE))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
769 return TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
770 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
771
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
772 ClearCommError(hComDev, &dwErrorFlags, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
773 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
774 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
775 ClearCommError(hComDev, &dwErrorFlags, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
776 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
777 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
778 if (!ReadFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
779 bpRXBuffer,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
780 dwBytesToRead,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
781 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
782 NULL))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
783 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
784 // if there was a problem
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
785 ClearCommError(hComDev, &dwErrorFlags, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
786 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
787 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
788 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
789 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
790 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
791 char traceBuf[255];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
792 unsigned int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
793
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
794 traceBuf[0] = '\0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
795
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
796 if (bpRXBuffer[0] EQ 0xff)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
797 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
798 Sleep(1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
799 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
800
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
801 for (i=0; i<*pdwLength; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
802 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
803 if (!isprint (bpRXBuffer[i]))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
804 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
805 sprintf (traceBuf+strlen(traceBuf),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
806 "[%02x]%c",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
807 (USHORT) bpRXBuffer[i],
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
808 ((bpRXBuffer[i] EQ '\n') ? '\n' : ' ')
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
809 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
810 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
811 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
812 sprintf (traceBuf+strlen(traceBuf),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
813 "%c",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
814 bpRXBuffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
815 if (strlen (traceBuf) > 200)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
816 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
817 write (usart_in, traceBuf, strlen (traceBuf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
818 traceBuf[0] = '\0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
819 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
820 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
821 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
822 * write the string to the tracefile
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
823 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
824 write (usart_in, traceBuf, strlen (traceBuf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
825 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
826 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
827 return TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
828 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
829
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
830 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
831 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
832 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
833 | STATE : code ROUTINE : sioWrite |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
834 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
835
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
836 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
837
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
838 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
839
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
840 LOCAL BOOL sioWrite (BYTE *bpTXBuffer, // TX Buffer
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
841 DWORD *pdwLength) // IN: Bytes to read
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
842 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
843 DWORD dwBytesToSend = *pdwLength, toSend, realySend;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
844 int ret;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
845 DWORD dwErrorFlags;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
846 COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
847 DWORD dwNumberOfBytesTransferred; /* Windows 95: */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
848 /* The number of transferred bytes returned by the */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
849 /* GetOverlappedResult function is always zero, also */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
850 /* if there are bytes received by the communication */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
851 /* partner via the serial line. */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
852
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
853 if (hComDev EQ INVALID_HANDLE_VALUE
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
854 OR !bpTXBuffer
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
855 OR *pdwLength ==0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
856 return FALSE; // device not available
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
857
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
858 realySend = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
859 toSend = dwBytesToSend;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
860
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
861 while (toSend > 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
862 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
863 if (m_mode==US_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
864 if (toSend > 20) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
865 ret = WriteFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
866 bpTXBuffer+realySend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
867 20,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
868 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
869 &gWriteOverLap);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
870 dwNumberOfBytesTransferred = 20;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
871 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
872 ret = WriteFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
873 bpTXBuffer+realySend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
874 toSend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
875 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
876 &gWriteOverLap);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
877 dwNumberOfBytesTransferred = toSend;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
878 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
879 /* if there was a problem, or the async. operation's still pending ... */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
880 if (!ret)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
881 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
882 /* deal with the error code */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
883 if (GetLastError() == ERROR_IO_PENDING)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
884 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
885 /* asynchronous i/o is still in progress */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
886
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
887 /* do something else for a while */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
888 /* check on the results of the asynchronous read */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
889 while (!GetOverlappedResult(gWriteOverLap.hEvent, &gWriteOverLap, pdwLength, TRUE))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
890 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
891 if(GetLastError() == ERROR_IO_INCOMPLETE) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
892 continue;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
893 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
894 break ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
895 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
896 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
897 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
898 ClearCommError(hComDev, &dwErrorFlags, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
899 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
900 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
901 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
902 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
903 if (toSend > 20) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
904 ret = WriteFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
905 bpTXBuffer+realySend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
906 20,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
907 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
908 NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
909 dwNumberOfBytesTransferred = 20; /* US_MODE_NT */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
910 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
911 ret = WriteFile (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
912 bpTXBuffer+realySend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
913 toSend,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
914 pdwLength,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
915 NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
916 dwNumberOfBytesTransferred = toSend; /* US_MODE_NT */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
917 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
918 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
919
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
920 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
921 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
922 char traceBuf[255];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
923 unsigned int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
924
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
925 traceBuf[0] = '\0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
926
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
927 for (i=0; i<*pdwLength; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
928 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
929 if (!isprint (bpTXBuffer[realySend+i]))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
930 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
931 sprintf (traceBuf+strlen(traceBuf),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
932 "[%02x]%c",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
933 (USHORT) bpTXBuffer[realySend+i],
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
934 ((bpTXBuffer[realySend+i] EQ '\n') ? '\n': ' ')
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
935 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
936 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
937 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
938 sprintf (traceBuf+strlen(traceBuf),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
939 "%c",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
940 bpTXBuffer[realySend+i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
941 if (strlen (traceBuf) > 200)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
942 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
943 write (usart_out, traceBuf, strlen (traceBuf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
944 traceBuf[0] = '\0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
945 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
946 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
947 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
948 * write the string to the tracefile
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
949 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
950 write (usart_out, traceBuf, strlen (traceBuf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
951 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
952 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
953
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
954 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
955 case US_MODE_NT:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
956 realySend += dwNumberOfBytesTransferred;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
957 toSend -= dwNumberOfBytesTransferred;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
958 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
959 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
960 realySend += *pdwLength;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
961 toSend -= *pdwLength;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
962 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
963 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
964 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
965 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
966 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
967
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
968 *pdwLength = dwBytesToSend;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
969
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
970 return TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
971 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
972
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
973 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
974 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
975 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
976 | STATE : code ROUTINE : UT_Init |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
977 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
978
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
979 PURPOSE : initializes the USART driver
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
980
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
981 RETURNS : 0 ... initialization succeeded
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
982 -1 ... error
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
983
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
984 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
985
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
986
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
987 int UT_Init (unsigned int baudRate, int fifoSize, char flow_ctrl, void (func(void)), const char* fname )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
988 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
989 if (initialized == TRUE)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
990 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
991 return 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
992 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
993
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
994 switch (m_mode)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
995 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
996 case US_MODE_FILE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
997 if (!fname || !strlen(fname) || (m_file=fopen(fname,"rb"))==NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
998 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
999 fprintf (stdout, "USART: failed to open %s :-(\n",fname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1000 return -1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1001 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1002 fprintf (stdout, "USART: \"%s\" opened\n",fname);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1003 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1004 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1005 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1006 BOOL ret;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1007 DWORD dwThreadID;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1008 #ifdef COM_AUTOSEARCH
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1009 int from, to;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1010 int portNr;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1011 #else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1012 EXTERN int extPort;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1013 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1014
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1015 ReceiveCallback = func;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1016
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1017 #ifdef COM_AUTOSEARCH
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1018 if (P NEQ 0) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1019 from = to = P;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1020 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1021 from = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1022 to = 4;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1023 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1024
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1025 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1026 * try COMn: to COMm: where n is from and m is to
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1027 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1028 for (portNr = from; portNr <= to; portNr++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1029 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1030 fprintf (stdout,"USART: Trying COM%d ... ", portNr);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1031
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1032 if ((ret = sioInit (portNr,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1033 convertBaudrate (baudRate),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1034 10000 /*fifoSize*/,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1035 flow_ctrl)) EQ FALSE) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1036 fprintf (stdout, "fail\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1037 } else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1038 fprintf (stdout, "success!\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1039 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1040 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1041 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1042
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1043 #else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1044 fprintf (stdout, "USART: Trying COM%d ... ", extPort);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1045
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1046 if ((ret = sioInit (extPort,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1047 convertBaudrate (baudRate),
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1048 10000 /*fifoSize*/,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1049 flow_ctrl)) EQ FALSE) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1050 fprintf (stdout, "fail\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1051 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1052 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1053
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1054 if (ret)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1055 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1056 fprintf (stdout, "success!\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1057
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1058 if (ReceiveCallback NEQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1059 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1060 hThread = CreateThread ((LPSECURITY_ATTRIBUTES) NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1061 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1062 (LPTHREAD_START_ROUTINE) _readerThread,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1063 (LPVOID) NULL,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1064 0,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1065 &dwThreadID
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1066 );
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1067 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1068 initialized = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1069 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1070 else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1071 fprintf (stdout, "USART: COM-port not free or baudrate not supported !\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1072 return -1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1073 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1074 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1075 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1076
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1077 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1078 int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1079
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1080 if ( first_ut_init )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1081 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1082 if ( (ut_sema_handle = OpenSemaphore (SEMAPHORE_MODIFY_STATE | SYNCHRONIZE, FALSE, "UT_SIM_SEMA")) == NULL )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1083 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1084 ut_sema_handle = CreateSemaphore (NULL, 1, 1, "UT_SIM_SEMA");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1085 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1086 first_ut_init = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1087 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1088
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1089 WaitForSingleObject (ut_sema_handle, INFINITE);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1090
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1091 if ((Stream = (T_USARTStream *) openUSARTMemory
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1092 (
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1093 (char*)"GSM",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1094 sizeof (T_USARTStream)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1095 )) EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1096 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1097 if ((Stream = (T_USARTStream *) createUSARTMemory
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1098 (
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1099 (char*)"GSM",
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1100 sizeof (T_USARTStream)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1101 )) EQ NULL)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1102 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1103 PrintToFile ("USART: simulation could not create a shared memory area\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1104 return -1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1105 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1106 PrintToFile ("USART: shared memory area created\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1107
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1108 Stream->CH1_numOfBytes = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1109 Stream->CH2_numOfBytes = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1110
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1111 Stream->CH1_CTS = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1112 Stream->CH2_CTS = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1113
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1114 for (i=0; i<USART_BUFFER_SIZE; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1115 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1116 Stream->CH1_data[i] = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1117 Stream->CH2_data[i] = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1118 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1119
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1120 Stream->Connects = 0; /* init connection counter (!! CURRENTLY NOT USED !!) */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1121 Stream->Type=1; /* signaling new type */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1122 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1123 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1124 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1125 PrintToFile ("USART: shared memory area opened\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1126 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1127
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1128 /* set pointers to semaphores and data buffers */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1129 #ifdef _TOOLS_
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1130 if (Stream->Type==0) // shared mem created by old stack
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1131 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1132 PrintToFile ("USART: connecting to old stack !\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1133
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1134 Stream->CH1_CTS = 1; // (baudRate NEQ -1); removed because baudrate never negative
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1135
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1136 InBuffer = Stream->CH1_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1137 OutBuffer = Stream->CH2_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1138 InCounter = &Stream->CH1_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1139 OutCounter = &Stream->CH2_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1140 semRCVFull = &SemCH1_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1141 semRCVEmpty = &SemCH1_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1142 semSNDFull = &SemCH2_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1143 semSNDEmpty = &SemCH2_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1144 CTS = &Stream->CH2_CTS;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1145 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1146 else // shared mem created by us or new stack
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1147 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1148 Stream->CH2_CTS = 1; // (baudRate NEQ -1); removed because baudrate never negative
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1149
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1150 InBuffer = Stream->CH2_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1151 OutBuffer = Stream->CH1_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1152 InCounter = &Stream->CH2_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1153 OutCounter = &Stream->CH1_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1154 semRCVFull = &SemCH2_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1155 semRCVEmpty = &SemCH2_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1156 semSNDFull = &SemCH1_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1157 semSNDEmpty = &SemCH1_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1158 CTS = &Stream->CH1_CTS;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1159 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1160 #else /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1161 Stream->CH1_CTS = 1; // (baudRate NEQ -1); removed because baudrate never negative
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1162
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1163 InBuffer = Stream->CH1_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1164 OutBuffer = Stream->CH2_data;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1165 InCounter = &Stream->CH1_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1166 OutCounter = &Stream->CH2_numOfBytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1167 semRCVFull = &SemCH1_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1168 semRCVEmpty = &SemCH1_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1169 semSNDFull = &SemCH2_full;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1170 semSNDEmpty = &SemCH2_empty;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1171 CTS = &Stream->CH2_CTS;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1172 #endif /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1173
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1174 readPointer = InBuffer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1175
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1176 ReceiveCallback = func;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1177
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1178 Stream->Connects++; /* mark connection (!! CURRENTLY NOT USED !!) */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1179 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1180
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1181 ReleaseSemaphore (ut_sema_handle, 1, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1182
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1183 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1184 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1185 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1186 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1187 initialized = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1188 mem_closed = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1189
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1190 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1191 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1192 * Open protocol file and initialize
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1193 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1194
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1195 usart_in = open ("USART.IN", O_WRONLY| O_TEXT| O_TRUNC| O_CREAT, 0666);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1196 usart_out = open ("USART.OUT", O_WRONLY| O_TEXT| O_TRUNC| O_CREAT, 0666);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1197 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1198
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1199 return 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1200 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1201
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1202
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1203 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1204 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1205 | PROJECT : GSM-PS (6147) MODULE : USARTSIM |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1206 | STATE : code ROUTINE : UT_Close |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1207 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1208
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1209 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1210
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1211 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1212
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1213 GLOBAL BOOL UT_Close(void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1214 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1215
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1216 if (initialized == FALSE)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1217 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1218
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1219 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1220 case US_MODE_FILE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1221 if (m_file)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1222 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1223 fclose(m_file);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1224 m_file=NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1225 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1226 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1227 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1228 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1229 DWORD ExitCode;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1230
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1231 if (ReceiveCallback != NULL) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1232 /* Initialize stop _readerThread */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1233 ReaderThreadExitRequest = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1234 while (ReaderThreadExitRequest == TRUE)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1235 SetCommMask (hComDev, 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1236 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1237
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1238 /* Close Communication port. */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1239 PurgeComm (hComDev,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1240 PURGE_TXABORT | PURGE_RXABORT |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1241 PURGE_TXCLEAR | PURGE_RXCLEAR ) ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1242 if (m_mode==UT_MODE_NT) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1243 CloseHandle (gReadOverLap.hEvent);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1244 gReadOverLap.hEvent = INVALID_HANDLE_VALUE ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1245 CloseHandle (gWriteOverLap.hEvent);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1246 gWriteOverLap.hEvent = INVALID_HANDLE_VALUE ;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1247 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1248 CloseHandle (hComDev);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1249 hComDev = INVALID_HANDLE_VALUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1250
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1251 if (ReceiveCallback != NULL) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1252 /* Stop _readerThread */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1253 do {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1254 GetExitCodeThread(hThread, (LPDWORD) &ExitCode);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1255 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1256 while (ExitCode == STILL_ACTIVE);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1257 CloseHandle (hThread);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1258 hThread = INVALID_HANDLE_VALUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1259 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1260
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1261 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1262 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1263 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1264 PrintToFile("USART: shared memory closed (%d)\n",cls_cnt);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1265 mem_closed = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1266 /* mark disconnection */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1267 Stream->Connects=(Stream->Connects>1) ? 1 : 0; /* (!! CURRENTLY NOT USED !!) */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1268
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1269 #ifdef _TOOLS_
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1270 if (Stream->Type==0) /* shared mem created by old stack */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1271 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1272 fprintf (stdout, "USART: disconnecting from old stack !\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1273 Stream->CH1_CTS = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1274 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1275 else /* shared mem created by us or new stack */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1276 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1277 Stream->CH2_CTS = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1278 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1279 #else /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1280 Stream->CH1_CTS = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1281 #endif /* _TOOLS_ */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1282
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1283 CTS = NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1284 /* close all handles */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1285 UnmapViewOfFile((void*)Stream);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1286 CloseHandle(USARTMemHandle);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1287 CloseHandle(SemCH1_full);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1288 CloseHandle(SemCH2_full);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1289 CloseHandle(SemCH1_empty);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1290 CloseHandle(SemCH2_empty);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1291 cls_cnt++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1292 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1293 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1294 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1295 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1296 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1297
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1298 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1299 /* close tracefiles for usart-in and out */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1300 close(usart_in);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1301 close(usart_out);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1302 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1303
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1304 /* Deinitialize */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1305 ReceiveCallback = NULL;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1306 initialized = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1307
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1308 return TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1309 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1310
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1311
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1312 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1313 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1314 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1315 | STATE : code ROUTINE : UT_InitBlk |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1316 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1317
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1318 PURPOSE : Initialize the USART for reading blocks
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1319
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1320 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1321
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1322 int UT_InitBlk ( unsigned int baudRate, int fifoSize, char flow_ctrl, void *hP)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1323 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1324 return UT_Init (baudRate, fifoSize, flow_ctrl, NULL, NULL);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1325 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1326
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1327 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1328 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1329 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1330 | STATE : code ROUTINE : UT_IsChar |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1331 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1332
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1333 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1334
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1335 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1336
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1337 GLOBAL int UT_IsChar (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1338 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1339 int ret;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1340
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1341 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1342 case US_MODE_FILE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1343 Sleep(FILE_SLOW_DOWN);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1344 while (feof(m_file))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1345 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1346 Sleep(1000);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1347 fseek(m_file,0,SEEK_CUR);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1348 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1349 ret=1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1350 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1351 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1352 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1353 static COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1354 static DWORD dwErrors;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1355
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1356 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1357 return FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1358
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1359 waitForRCVBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1360
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1361 ClearCommError (hComDev, &dwErrors, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1362
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1363 ret= (stComStat.cbInQue > 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1364 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1365 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1366
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1367 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1368 waitForRCVBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1369 ret = (*InCounter NEQ 0);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1370
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1371 if (ret EQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1372 readPointer = InBuffer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1373 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1374 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1375 ret = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1376 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1377 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1378 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1379
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1380 return ret;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1381 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1382
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1383 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1384 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1385 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1386 | STATE : code ROUTINE : UT_ReadChar |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1387 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1388
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1389 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1390
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1391 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1392
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1393 GLOBAL BYTE UT_ReadChar (void)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1394 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1395 BYTE ret=0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1396
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1397 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1398 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1399 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1400
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1401 BYTE buffer[1];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1402 ULONG bytesRead;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1403
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1404 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1405 return 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1406
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1407 sioRead (buffer, &bytesRead);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1408
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1409 if (!bytesRead)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1410 buffer[0] = 0xff;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1411
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1412 ret=buffer[0];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1413 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1414 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1415
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1416 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1417 if (*InCounter NEQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1418 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1419 ret = *readPointer++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1420
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1421 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1422 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1423 BYTE buf[20];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1424 sprintf (buf, "R[1 of %d]: ", *InCounter);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1425 write (usart_in,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1426 buf,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1427 strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1428 if (isprint (ret))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1429 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1430 sprintf (buf, "%c\n", ret);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1431 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1432 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1433 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1434 sprintf (buf, "(%02X)\n", ret);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1435 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1436 write (usart_in,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1437 buf,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1438 strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1439 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1440 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1441
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1442 (*InCounter)--;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1443
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1444 if (*InCounter EQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1445 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1446 readPointer = InBuffer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1447 markRCVBufferEmpty ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1448 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1449 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1450 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1451 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1452 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1453 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1454 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1455 return ret;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1456 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1457
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1458 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1459 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1460 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1461 | STATE : code ROUTINE : UT_ReadNChars |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1462 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1463
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1464 PURPOSE : Called from the HISR - Reads a block of characters
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1465 Parameters : buffer for holding received characters,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1466 max. size of buffer
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1467 Returns the number of characters read
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1468
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1469 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1470
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1471 GLOBAL ULONG UT_ReadNChars (int usart_id, BYTE *buffer, ULONG bufferSize)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1472 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1473 ULONG bytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1474
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1475 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1476 case US_MODE_FILE:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1477 if (bufferSize>FILE_MAX_CHUNK)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1478 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1479 bufferSize=FILE_MAX_CHUNK;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1480 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1481 bytes=fread(buffer,1,bufferSize,m_file);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1482 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1483 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1484 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1485
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1486 COMSTAT stComStat;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1487 DWORD dwErrors;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1488
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1489 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1490 return 0L;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1491
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1492 ClearCommError (hComDev, &dwErrors, &stComStat);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1493
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1494 bytes = MINIMUM (stComStat.cbInQue, bufferSize);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1495
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1496 if (bytes EQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1497 return 0L;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1498
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1499 sioRead (buffer, &bytes);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1500 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1501 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1502
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1503 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1504 if ((bytes = MINIMUM (*InCounter, bufferSize)) NEQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1505 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1506 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1507 unsigned int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1508 char buf[50];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1509 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1510
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1511 memcpy (buffer, readPointer, bytes);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1512
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1513 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1514 sprintf (buf, "R[%d of %d]: ", bytes, *InCounter);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1515 write (usart_in, buf, strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1516
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1517 for (i=0; i<bytes; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1518 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1519 if (isprint (buffer[i]))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1520 sprintf (buf, "%c", buffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1521 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1522 sprintf (buf, "(%02X)", buffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1523 write (usart_in,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1524 buf,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1525 strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1526 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1527 write (usart_in, "\n", 1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1528 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1529
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1530 (*InCounter) -= (USHORT)bytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1531
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1532 if (*InCounter EQ 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1533 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1534 readPointer = InBuffer;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1535 markRCVBufferEmpty ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1536 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1537 else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1538 readPointer += bytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1539 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1540 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1541 else {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1542 markRCVBufferEmpty ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1543 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1544 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1545 default: bytes = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1546 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1547 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1548 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1549
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1550 return bytes;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1551 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1552
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1553 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1554 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1555 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1556 | STATE : code ROUTINE : UT_WriteChar |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1557 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1558
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1559 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1560
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1561 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1562
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1563 GLOBAL void UT_WriteChar (int usart_id, char ch)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1564 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1565 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1566 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1567 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1568 BYTE buffer[1];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1569 ULONG bytesWritten = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1570
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1571 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1572 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1573
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1574 buffer[0] = (BYTE)ch;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1575
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1576 sioWrite (buffer, &bytesWritten);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1577 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1578 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1579
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1580 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1581 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1582 char buf[50];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1583 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1584
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1585 if ( CTS == NULL || !*CTS) /* no testtools connected */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1586 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1587 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1588 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1589
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1590 if (waitForSNDBufferEmpty () != 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1591 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1592 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1593 return; /* we gave up sending to avoid dead lock */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1594 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1595
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1596 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1597 sprintf (buf, "W[1]: %02X", ch);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1598 write (usart_out, buf, strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1599 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1600
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1601 *OutBuffer = (UBYTE)ch;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1602 *OutCounter = 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1603
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1604 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1605 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1606 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1607 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1608 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1609 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1610 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1611
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1612 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1613 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1614 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1615 | STATE : code ROUTINE : UT_WriteString |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1616 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1617
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1618 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1619
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1620 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1621
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1622 GLOBAL void UT_WriteString (int usart_id, char *s)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1623 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1624 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1625 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1626 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1627 ULONG bytesWritten = strlen (s);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1628
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1629 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1630 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1631
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1632 sioWrite ((BYTE *) s, &bytesWritten);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1633 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1634 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1635
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1636 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1637 unsigned int numOfChars;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1638 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1639 int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1640 char buf[50];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1641 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1642
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1643 if ( CTS == NULL || !*CTS) /* no testtools connected */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1644 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1645 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1646 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1647
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1648 if (waitForSNDBufferEmpty () != 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1649 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1650 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1651 return; /* we gave up sending to avoid dead lock */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1652 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1653
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1654 numOfChars = strlen (s);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1655
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1656 memcpy (OutBuffer, s, numOfChars);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1657 *OutCounter = numOfChars;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1658
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1659 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1660 sprintf (buf, "W[%d]:", numOfChars);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1661 write (usart_out, buf, strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1662
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1663 for (i=0; i<numOfChars; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1664 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1665 if (isprint (OutBuffer[i]))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1666 sprintf (buf, "%c", OutBuffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1667 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1668 sprintf (buf, "(%02X)", OutBuffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1669 write (usart_out,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1670 buf,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1671 strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1672
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1673 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1674 write (usart_out,"\n", 1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1675 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1676
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1677 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1678 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1679 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1680 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1681 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1682 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1683 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1684
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1685
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1686 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1687 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1688 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1689 | STATE : code ROUTINE : UT_WriteNChars |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1690 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1691
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1692 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1693
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1694 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1695
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1696 GLOBAL void UT_WriteNChars (int usart_id, BYTE *s, unsigned int n)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1697 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1698 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1699 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1700 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1701 ULONG bytesWritten = (ULONG) n;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1702
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1703 if (!initialized)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1704 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1705
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1706 if (!sioWrite ((BYTE *) s, &bytesWritten))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1707 fprintf (stderr, "USART: Error1\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1708 if (bytesWritten NEQ (ULONG) n)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1709 fprintf (stderr, "USART: Error2\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1710 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1711 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1712
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1713 case US_MODE_SIM: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1714 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1715 int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1716 char buf[50];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1717 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1718
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1719 if ( CTS == NULL || !*CTS) /* no testtools connected */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1720 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1721 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1722 printf("-");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1723 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1724 snd_cnt++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1725 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1726 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1727
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1728 if ( mem_closed == TRUE )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1729 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1730 PrintToFile("USART:tried to write on closed memory (%d)\n",snd_cnt);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1731 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1732 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1733 if (waitForSNDBufferEmpty () != 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1734 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1735 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1736 PrintToFile("USART: gave up sending\n");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1737 snd_cnt++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1738 return; /* we gave up sending to avoid dead lock */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1739 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1740 memcpy (OutBuffer, s, n);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1741 *OutCounter = n;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1742
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1743 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1744 sprintf (buf, "W[%d]:", n);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1745 write (usart_out, buf, strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1746
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1747 for (i=0; i<n; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1748 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1749 if (isprint (OutBuffer[i]))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1750 sprintf (buf, "%c", OutBuffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1751 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1752 sprintf (buf, "(%02X)", OutBuffer[i]);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1753 write (usart_out,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1754 buf,
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1755 strlen (buf));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1756 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1757 write (usart_out,"\n", 1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1758 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1759
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1760 if ( mem_closed == TRUE )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1761 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1762 PrintToFile("USART: written on closed memory (%d)\n",snd_cnt);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1763 snd_cnt++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1764 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1765 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1766 #ifdef DEBUG_USART
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1767 printf("+");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1768 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1769 markSNDBufferFull ();
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1770 snd_cnt++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1771 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1772 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1773 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1774 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1775 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1776 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1777
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1778 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1779 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1780 | PROJECT : GSM-PS (6147) MODULE : USART |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1781 | STATE : code ROUTINE : UT_SetFlowCtrl |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1782 +--------------------------------------------------------------------+
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1783
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1784 PURPOSE :
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1785
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1786 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1787
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1788 GLOBAL void UT_SetFlowCtrl (char flowCtrl)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1789 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1790 switch (m_mode) {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1791 case US_MODE_95:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1792 case US_MODE_NT: {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1793 DCB stDCB;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1794
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1795 if (!GetCommState (hComDev, &stDCB))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1796 return;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1797
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1798 stDCB.DCBlength = sizeof (stDCB); // sizeof(DCB)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1799
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1800 switch (flowCtrl)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1801 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1802 case 'N':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1803 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1804 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1805 stDCB.fDtrControl = DTR_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1806 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1807 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1808 case 'D':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1809 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1810 stDCB.fOutxDsrFlow = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1811 stDCB.fDtrControl = DTR_CONTROL_HANDSHAKE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1812 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1813 stDCB.XonLim = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1814 stDCB.XoffLim = 50;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1815 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1816 case 'R':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1817 stDCB.fOutxCtsFlow = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1818 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1819 stDCB.fDtrControl = DTR_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1820 stDCB.fRtsControl = RTS_CONTROL_HANDSHAKE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1821 stDCB.XonLim = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1822 stDCB.XoffLim = 50;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1823 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1824 case 'P':
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1825 stDCB.fOutxCtsFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1826 stDCB.fOutxDsrFlow = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1827 stDCB.fDtrControl = DTR_CONTROL_ENABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1828 stDCB.fRtsControl = RTS_CONTROL_DISABLE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1829 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1830 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1831 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1832 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1833
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1834 SetCommState (hComDev, &stDCB);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1835 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1836 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1837
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1838 case US_MODE_SIM:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1839 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1840 default:
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1841 break;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1842 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1843 }