annotate gsm-fw/gpf/tst_drv/usart.c @ 660:a0014ba30d71

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