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