comparison gpf/tst/DRV/ser_tr.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +------------------------------------------------------------------------------
3 | File: ser_tr.c
4 +------------------------------------------------------------------------------
5 | Copyright 2004 Texas Instruments Deutschland, AG
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments Berlin, AG
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments Deutschland, AG.
15 +-----------------------------------------------------------------------------
16 | Purpose : This Modul contains the serial driver adaptation
17 +-----------------------------------------------------------------------------
18 */
19
20 #ifndef __SER_TR_C__
21 #define __SER_TR_C__
22 #endif
23
24 #include "typedefs.h"
25 #include "traceswitch.h"
26 #include "serialswitch.h"
27 #include "gdi.h"
28 #include "tstheader.h"
29
30 /*==== TYPES ======================================================*/
31
32 typedef struct
33 {
34 USHORT Handle;
35 USHORT EnabledSignalType;
36 T_DRV_CB_FUNC Callback;
37 char Connected;
38 } T_SER_TR_DATA;
39
40 /*==== CONSTANTS ==================================================*/
41
42 #define ALLOWED_SER_TR_SIGNALS (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT)
43
44 /*==== EXTERNALS ==================================================*/
45
46 #ifdef RUN_FLASH
47 USHORT SER_TR_Write ( void *Buffer, ULONG *BytesToWrite );
48 #endif
49
50 /*==== VARIABLES ==================================================*/
51
52 #ifndef RUN_INT_RAM
53 T_SER_TR_DATA SER_TR_Data;
54 #endif
55 static T_DRV_SIGNAL Signal;
56
57 /*==== FUNCTIONS ==================================================*/
58
59 #ifndef RUN_INT_RAM
60 /*
61 +--------------------------------------------------------------------+
62 | PROJECT : GSM-Frame (8415) MODULE : SER |
63 | STATE : code ROUTINE : Callback |
64 +--------------------------------------------------------------------+
65
66 PURPOSE : callback function of the driver
67
68 */
69 void Callback ( void )
70 {
71 if ( SER_TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
72 {
73 Signal.SignalType = DRV_SIGTYPE_READ;
74 Signal.DrvHandle = SER_TR_Data.Handle;
75
76 (SER_TR_Data.Callback)( &Signal );
77 }
78 }
79 #endif
80
81 #ifndef RUN_INT_RAM
82 /*
83 +--------------------------------------------------------------------+
84 | PROJECT : GSM-Frame (8415) MODULE : SER |
85 | STATE : code ROUTINE : SER_TR_Exit |
86 +--------------------------------------------------------------------+
87
88 PURPOSE : exit a driver
89
90 */
91 void SER_TR_Exit ( void )
92 {
93 }
94 #endif
95
96 #ifndef RUN_INT_RAM
97 /*
98 +--------------------------------------------------------------------+
99 | PROJECT : GSM-Frame (8415) MODULE : SER |
100 | STATE : code ROUTINE : SER_TR_Read |
101 +--------------------------------------------------------------------+
102
103 PURPOSE : read data from driver
104
105 */
106 USHORT SER_TR_Read ( void *Buffer, ULONG *BytesToRead )
107 {
108 *BytesToRead = (USHORT)SER_tr_ReadNChars ( SER_LAYER_1, Buffer, *BytesToRead );
109 return DRV_OK;
110 }
111 #endif
112
113
114 #ifndef RUN_FLASH
115 /*
116 +--------------------------------------------------------------------+
117 | PROJECT : GSM-Frame (8415) MODULE : SER |
118 | STATE : code ROUTINE : SER_TR_Write |
119 +--------------------------------------------------------------------+
120
121 PURPOSE : write data to driver
122
123 */
124 USHORT SER_TR_Write ( void *Buffer, ULONG *BytesToWrite )
125 {
126 ULONG ToWrite = *BytesToWrite & ~PRIM_FLAG_MASK;
127 ULONG BytesWritten;
128 char *ptr = (char*)Buffer;
129
130 ptr--;
131 *ptr = 0x13;
132 ToWrite += 1;
133 BytesWritten = (ULONG)SER_tr_WriteNBytes (SER_LAYER_1, (SYS_UWORD8*)ptr, (SYS_UWORD32)ToWrite);
134 *BytesToWrite = BytesWritten;
135
136 return ( DRV_OK );
137 }
138 #endif
139
140 #ifndef RUN_INT_RAM
141 /*
142 +--------------------------------------------------------------------+
143 | PROJECT : GSM-Frame (8415) MODULE : SER |
144 | STATE : code ROUTINE : SER_TR_SetSignal |
145 +--------------------------------------------------------------------+
146
147 PURPOSE : enable signal for the driver
148
149 */
150 USHORT SER_TR_SetSignal ( USHORT SignalType )
151 {
152 if ( !(SignalType & ALLOWED_SER_TR_SIGNALS) )
153 return DRV_INVALID_PARAMS;
154 else
155 SER_TR_Data.EnabledSignalType |= SignalType;
156
157 return DRV_OK;
158 }
159 #endif
160
161 #ifndef RUN_INT_RAM
162 /*
163 +--------------------------------------------------------------------+
164 | PROJECT : GSM-Frame (8415) MODULE : SER |
165 | STATE : code ROUTINE : SER_TR_ResetSignal |
166 +--------------------------------------------------------------------+
167
168 PURPOSE : disable signal for the driver
169
170 */
171 USHORT SER_TR_ResetSignal ( USHORT SignalType )
172 {
173 if ( !(SignalType & ALLOWED_SER_TR_SIGNALS) )
174 return DRV_INVALID_PARAMS;
175 else
176 SER_TR_Data.EnabledSignalType &= ~SignalType;
177
178 return DRV_OK;
179 }
180 #endif
181
182 #ifndef RUN_INT_RAM
183 /*
184 +--------------------------------------------------------------------+
185 | PROJECT : GSM-Frame (8415) MODULE : SER |
186 | STATE : code ROUTINE : SER_TR_SetConfig |
187 +--------------------------------------------------------------------+
188
189 PURPOSE : set configuration for the driver
190
191 */
192 USHORT SER_TR_SetConfig ( char *Buffer )
193 {
194
195 if ( !SER_TR_Data.Connected )
196 {
197 Signal.SignalType = DRV_SIGTYPE_CONNECT;
198 Signal.DrvHandle = SER_TR_Data.Handle;
199 Signal.UserData = NULL;
200 (SER_TR_Data.Callback)( &Signal );
201 SER_TR_Data.Connected = TRUE;
202 return DRV_OK;
203 }
204 return DRV_OK;
205 }
206 #endif
207
208
209 #ifndef RUN_INT_RAM
210 /*
211 +--------------------------------------------------------------------+
212 | PROJECT : GSM-Frame (8415) MODULE : SER |
213 | STATE : code ROUTINE : SER_TR_Init |
214 +--------------------------------------------------------------------+
215
216 PURPOSE : initialize driver
217
218 */
219 USHORT SER_TR_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
220 {
221 static const T_DRV_EXPORT SER_TR_Info =
222 {
223 "SER",
224 CALLED_FROM_ISR,
225 {
226 #ifdef _TOOLS_
227 SER_TR_TR_Init,
228 #endif
229 SER_TR_Exit,
230 SER_TR_Read,
231 SER_TR_Write,
232 NULL,
233 NULL,
234 NULL,
235 SER_TR_SetSignal,
236 SER_TR_ResetSignal,
237 SER_TR_SetConfig,
238 NULL,
239 NULL,
240 }
241 };
242
243 SER_TR_Data.Handle = DrvHandle;
244 SER_TR_Data.EnabledSignalType = 0;
245 SER_TR_Data.Callback = CallbackFunc;
246 SER_TR_Data.Connected = FALSE;
247
248 SER_tr_Init ( SER_LAYER_1, TR_BAUD_115200, Callback );
249 *DrvInfo = &SER_TR_Info;
250
251 return DRV_OK;
252 }
253 #endif