1 /*
2  * stream.h
3  *
4  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 
37 //! \ingroup MODULBIOS
38 //! \file stream.h
39 //! \brief
40 //!
41 //! \author  Detlef Fink (03/10/2011)
42 #ifndef _STREAM_H_
43 #define _STREAM_H_
44 
45 #include "../include/protocol.h"
46 #include "communicationDefs.h"
47 
48 #define MESSAGE_NEW_MSG 0x0001
49 #define MESSAGE_LAST_MSG 0x0002
50 #define MESSAGE_OUT_TO_DLL (unsigned char*)0x0001
51 #define MESSAGE_NO_OUT (unsigned char*)0x0000
52 
53 #define ID_SHARED_MEMORY_TYPE_SYNC_RUN 0xAA01
54 #define ID_SHARED_MEMORY_TYPE_TIMER_TICK 0xAA02
55 #define ID_SHARED_MEMORY_TYPE_I_TICK 0xAA03
56 #define ID_SHARED_MEMORY_TYPE_TIME_TICK 0xAA04
57 
58 struct _StreamSafe_
59 {
60     unsigned char rx[12];
61     unsigned short *ext_data;
62     unsigned short ext_size;
63     unsigned short ext_counter;
64 };
65 typedef struct _StreamSafe_ StreamSafe;
66 
67 struct stream_funcs
68 {
69     short (*out_init)(unsigned char, unsigned char);
70     short (*flush)(void);
71     short (*put_byte)(unsigned char);
72     short (*put_bytes)(void*, unsigned short);
73     short (*put_word)(unsigned short);
74     short (*put_long)(unsigned long);
75     short (*in_init)(void *, unsigned char);
76     short (*internal_stream)(unsigned char *, unsigned short, unsigned char *, unsigned short, StreamSafe *);
77     short (*external_stream)(StreamSafe *);
78     unsigned char (*change_type)(unsigned char);
79     short (*get_byte)(unsigned char *);
80     short (*get_word)(unsigned short *);
81     short (*get_long)(unsigned long *);
82     short (*get_buffer)(void **, unsigned short *);
83     short (*discard_bytes)(unsigned short);
84     short (*memcpy)(unsigned char*, unsigned char*, unsigned short);
85     short (*biosLedOn)(unsigned char);
86     short (*biosLedOff)(unsigned char);
87     short (*biosLedBlink)(unsigned char, unsigned short);
88     short (*biosLedFlash)(unsigned char, unsigned short);
89     short (*biosLedAlternate)(unsigned short);
90     short (*sendDebug)(char *, unsigned short size);
91     short (*getSharedVariable)(unsigned short IdMemoryType, unsigned short** Address);
92     short (*deleteSharedVariable)(unsigned short IdMemoryType);
93 };
94 
95 void STREAM_resetSharedVariables();
96 
97 #ifdef HAL_STREAM
98 
99 extern struct stream_funcs * _stream_Funcs;
100 
101 // add definitions for external use
102 // functions are located in core module
103 
104 /**
105  * STREAM Function Pointer - these are the STREAM Exports
106  */
107 #define STREAM_out_init             (*_stream_Funcs->out_init)
108 #define STREAM_flush                (*_stream_Funcs->flush)
109 #define STREAM_put_byte             (*_stream_Funcs->put_byte)
110 #define STREAM_put_bytes            (*_stream_Funcs->put_bytes)
111 #define STREAM_put_word             (*_stream_Funcs->put_word)
112 #define STREAM_put_long             (*_stream_Funcs->put_long)
113 #define STREAM_get_buffer           (*_stream_Funcs->get_buffer)
114 #define STREAM_in_init              (*_stream_Funcs->in_init)
115 #define STREAM_internal_stream      (*_stream_Funcs->internal_stream)
116 #define STREAM_external_stream      (*_stream_Funcs->external_stream)
117 #define STREAM_out_change_type      (*_stream_Funcs->change_type)
118 #define STREAM_get_byte             (*_stream_Funcs->get_byte)
119 #define STREAM_get_word             (*_stream_Funcs->get_word)
120 #define STREAM_get_long             (*_stream_Funcs->get_long)
121 #define STREAM_discard_bytes        (*_stream_Funcs->discard_bytes)
122 #define STREAM_memcpy               (*_stream_Funcs->memcpy)
123 #define STREAM_biosLedOn            (*_stream_Funcs->biosLedOn)
124 #define STREAM_biosLedOff           (*_stream_Funcs->biosLedOff)
125 #define STREAM_biosLedBlink         (*_stream_Funcs->biosLedBlink)
126 #define STREAM_biosLedFlash         (*_stream_Funcs->biosLedFlash)
127 #define STREAM_biosLedAlternate     (*_stream_Funcs->biosLedAlternate)
128 #define STREAM_getSharedVariable    (*_stream_Funcs->getSharedVariable)
129 #define STREAM_deleteSharedVariable (*_stream_Funcs->deleteSharedVariable)
130 
131 
132 
133 /**** Debug & Trace Functionality ****/
134 #define STREAM_sendDebug        (*_stream_Funcs->sendDebug)
135 /**** Debug & Trace Functionality ****/
136 
137 #else // HAL_STREAM
138 extern struct stream_funcs _stream_Funcs;
139 /**
140  * STREAM Function Pointer - these are the STREAM Exports
141  */
142 #define STREAM_out_init             (*_stream_Funcs.out_init)
143 #define STREAM_flush                (*_stream_Funcs.flush)
144 #define STREAM_put_byte             (*_stream_Funcs.put_byte)
145 #define STREAM_put_bytes            (*_stream_Funcs.put_bytes)
146 #define STREAM_put_word             (*_stream_Funcs.put_word)
147 #define STREAM_put_long             (*_stream_Funcs.put_long)
148 #define STREAM_in_init              (*_stream_Funcs.in_init)
149 #define STREAM_internal_stream      (*_stream_Funcs.internal_stream)
150 #define STREAM_external_stream      (*_stream_Funcs.external_stream)
151 #define STREAM_out_change_type      (*_stream_Funcs.change_type)
152 #define STREAM_get_byte             (*_stream_Funcs.get_byte)
153 #define STREAM_get_word             (*_stream_Funcs.get_word)
154 #define STREAM_get_long             (*_stream_Funcs.get_long)
155 #define STREAM_get_buffer           (*_stream_Funcs->get_buffer)
156 #define STREAM_discard_bytes        (*_stream_Funcs.discard_bytes)
157 #define STREAM_memcpy               (*_stream_Funcs.memcpy)
158 #define STREAM_biosLedOn            (*_stream_Funcs.biosLedOn)
159 #define STREAM_biosLedOff           (*_stream_Funcs.biosLedOff)
160 #define STREAM_biosLedBlink         (*_stream_Funcs.biosLedBlink)
161 #define STREAM_biosLedFlash         (*_stream_Funcs.biosLedFlash)
162 #define STREAM_biosLedAlternate     (*_stream_Funcs.biosLedAlternate)
163 #define STREAM_sendDebug            (*_stream_Funcs.sendDebug)
164 #define STREAM_getSharedVariable    (*_stream_Funcs.getSharedVariable)
165 #define STREAM_deleteSharedVariable (*_stream_Funcs.deleteSharedVariable)
166 
167 #define STREAM_CORE_ZERO_VERSION    0x00
168 #define STREAM_CORE_ZERO_MACRO_SIZE 0x01
169 #define STREAM_CORE_ZERO_MACRO_ADDR 0x02
170 #define STREAM_CORE_ZERO_PUC_RESET  0x03
171 // function numbers in "zero function(s) in HAL modul" must start at 0xFF and count downward
172 #endif // HAL_STREAM
173 
174 typedef void *(*HalMainFunc)(void *stream_adr, unsigned long, unsigned char v3opHilCrcOk, unsigned char v3opDcdcCrcOk);
175 typedef short (*FuncInOut)  (unsigned short id);
176 
177 #ifndef HAL_REC
178 #define HAL_REC
179 struct _HalRec_
180 {
181     unsigned short id;
182     void  *function;
183 };
184 typedef struct _HalRec_ HalRec;
185 #endif
186 
187 #define DEVICE_FLAG_XONOFF  0x00000001
188 #define DEVICE_FLAG_SBW4    0x00000002
189 #define DEVICE_FLAG_SBW2    0x00000004
190 #define DEVICE_FLAG_EASY    0x00000008
191 
192 #define DEVICE_FLAG_MSPFET  0x00000010
193 #define DEVICE_FLAG_EZFET   0x00000020
194 
195 struct _HAL_INFOS_
196 {
197     HalMainFunc init;
198     short sw_0;
199     short sw_1;
200     unsigned short hal_size;
201     HalRec *hal_list_ptr;
202     unsigned short hil_version;
203     unsigned short fpga_version;
204     short swCmp_0;
205     short swCmp_1;
206     unsigned short hil_versionCmp;
207 };
208 typedef struct _HAL_INFOS_ *HAL_INFOS_PTR;
209 typedef struct _HAL_INFOS_ HAL_INFOS;
210 
211 #endif
212