dataXferImpl.h

Go to the documentation of this file.
00001 /*
00002  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00003  * All rights reserved.
00004  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00005  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00006  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00007  *
00008  * Permission to use, copy, modify, and distribute this software and its
00009  * documentation for any purpose, without fee, and without written agreement is
00010  * hereby granted, provided that the above copyright notice, the following
00011  * two paragraphs and the authors appear in all copies of this software.
00012  *
00013  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00014  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00015  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00016  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00017  *
00018  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00019  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00020  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00021  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00022  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00023  *
00024  * Please maintain this header in its entirety when copying/modifying
00025  * these files.
00026  *
00027  *
00028  */
00029 
00030 #ifndef __DATA_XFER_IMPL_H__
00031 #define __DATA_XFER_IMPL_H__
00032 
00098 #include <stdlib.h>
00099 
00100 // Determine if we're compiling for the PIC or not.
00101 #if defined(__PIC24H__) || defined(__PIC24F__) || defined(__dsPIC33F__) || defined(__PIC24FK__)
00102 #define __PIC__
00103 #include "pic24_all.h"
00104 #endif
00105 
00106 
00107 // Specify that this is C code for proper C++ linking
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #endif
00111 
00119 // @{
00120 #if defined(__cplusplus)
00121 #ifndef NULL
00123 #define NULL nullptr
00124 #endif
00125 
00126 #ifndef FALSE
00128 #define FALSE false
00129 #endif
00130 
00131 #ifndef TRUE
00133 #define TRUE true
00134 #endif
00135 
00138 #define BOOL bool
00139 
00142 #ifndef ASSERT
00143         #ifdef _NOASSERT
00144         #define ASSERT(placeholder) (void)0
00145         #else
00146                 #define ASSERT(x) if (!(x)) throw #x
00147         #endif
00148 #endif
00149 
00151 #ifndef ASSERTM
00152         #ifdef _NOASSERT
00153         #define ASSERT(msg, expr) (void)0
00154         #else
00155                 #define ASSERTM(msg, expr) if (! (expr)) throw msg ": " #expr
00156         #endif
00157 #endif
00158 
00159 
00160 #else
00161 
00162 #ifndef FALSE
00163 #define FALSE 0
00164 #endif
00165 
00166 #ifndef TRUE
00167 #define TRUE 1
00168 #endif
00169 
00170 #ifndef ASSERT
00171         #ifdef _NOASSERT
00172         #define ASSERT(placeholder) (void)0
00173         #else
00174                 #include <assert.h>
00175                 #define ASSERT(x) assert(x)
00176         #endif
00177 #endif
00178 
00180 #ifndef ASSERTM
00181 #define ASSERTM(msg, expr) ASSERT(expr)
00182 #endif
00183 
00184 #define BOOL unsigned char
00185 #endif
00186 // @}
00187 
00189 typedef unsigned int uint;
00190 
00191 #ifndef __PIC__
00193 typedef unsigned char uint8;
00194 #endif
00195 
00196 
00197 // Unit testing: uncomment the following line to run PIC tests on PC.
00198 //#define __PIC__
00199 
00201 
00202 
00207 #define CMD_TOKEN ((char) 0xAA)
00208 
00211 #define ESCAPED_CMD  ((char) 0xFC)
00212 
00215 #define CMD_LONG_VAR  ((char) 0xFD)
00216 
00219 #define CMD_SEND_ONLY ((char) 0xFE)
00220 
00223 #define CMD_SEND_RECEIVE_VAR ((char) 0xFF)
00224 
00227 #define VAR_SIZE_BITS 2
00228 
00230 #define VAR_SIZE_MASK ((1 << VAR_SIZE_BITS) - 1)
00231 
00234 #define SHORT_VAR_MAX_LEN (1 << VAR_SIZE_BITS)
00235 
00238 typedef enum { 
00240         STATE_CMD_START,
00242         STATE_CMD_WAIT1,
00244         STATE_CMD_WAIT2
00245 } CMD_STATE;
00246 
00249 typedef enum {
00251         OUTPUT_CMD_NONE,
00253         OUTPUT_CMD_CHAR,
00255         OUTPUT_CMD_CMD,
00257         OUTPUT_CMD_REPEATED_CMD,
00261         OUTPUT_CMD_REPEATED_WAIT
00262 } CMD_OUTPUT;
00263 
00264 void resetCommandFindMachine();
00265 CMD_OUTPUT stepCommandFindMachine(char c_inChar, char* c_outChar);
00267 
00268 
00269 
00271 
00272 
00275 typedef struct {
00278   uint8* pu8_data;
00280   uint8 u8_size;
00281 #if !defined(__PIC__) || defined(__DOXYGEN__)
00283   char* psz_format;
00286   char* psz_name;
00288   char* psz_desc;
00289 #endif
00290 } XFER_VAR;
00291 
00293 #define MAX_NUM_XFER_VARS ((1 << (8 - VAR_SIZE_BITS)) - 1)
00294 
00297 #define NUM_XFER_VARS 62
00298 #if NUM_XFER_VARS > MAX_NUM_XFER_VARS
00299 #error Too many transfer variables; there must be MAX_NUM_XFER_VARS or fewer.
00300 #endif
00301 
00303 extern XFER_VAR xferVar[NUM_XFER_VARS];
00304 
00308 extern uint8 au8_xferVarWriteable[NUM_XFER_VARS/8 + ((NUM_XFER_VARS % 8) > 0)];
00309 
00311 
00312 
00313 
00315 
00316 
00320 #define CHAR_RECEIVED_INDEX 0xFF
00321 
00324 typedef enum {
00326                 STATE_RECV_START,
00328                 STATE_RECV_CMD_WAIT,
00330                 STATE_RECV_READ_BYTES,
00332                 STATE_RECV_LONG_INDEX,
00334                 STATE_RECV_LONG_LENGTH,
00336                 STATE_RECV_SPEC_INDEX,
00337 } RECEIVE_STATE;
00338 
00339 
00343 typedef enum {
00347         ERR_NONE = 0,
00351         ERR_REPEATED_CMD,
00354         ERR_TIMEOUT,
00357         ERR_INTERRUPTED_CMD,
00360         ERR_UNSPECIFIED_INDEX,
00363         ERR_INDEX_TOO_HIGH,
00366         ERR_VAR_SIZE_MISMATCH,
00368         ERR_READ_ONLY_VAR,
00370         ERR_PIC_VAR_SPEC
00371 } RECEIVE_ERROR;
00372 
00374 #define NUM_ERROR_CODES (ERR_PIC_VAR_SPEC + 1)
00375 
00376 RECEIVE_STATE getReceiveMachineState();
00377 char getReceiveMachineOutChar();
00378 uint getReceiveMachineIndex();
00379 RECEIVE_ERROR getReceiveMachineError();
00380 #if !defined(__PIC__) || defined(__DOXYGEN__)
00381 BOOL getReceiveMachineIsSpec();
00382 #endif
00383 void resetReceiveMachine();
00384 void clearReceiveMachineError();
00385 void clearReceiveStruct();
00386 BOOL isReceiveMachineChar(char* c_receivedChar);
00387 BOOL isReceiveMachineData(uint* u_receivedIndex);
00388 #if !defined(__PIC__) || defined(__DOXYGEN__)
00389 BOOL isReceiveMachineSpec(uint* u_receivedIndex);
00390 #endif
00391 uint getVarIndex(char c_cmd);
00392 uint getVarLength(char c_cmd);
00393 void assignBit(uint u_index, BOOL b_bitVal);
00394 BOOL isVarWriteable(uint u_index);
00395 RECEIVE_ERROR stepReceiveMachine(char c_inChar, BOOL b_isTimeout);
00396 const char* getReceiveErrorString();
00397 
00398 #ifdef __cplusplus
00399 }
00400 #endif
00401 
00402 #endif

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9