basics.h
Go to the documentation of this file.
00001 #ifndef BASICS_H_INCLUDED
00002 #define BASICS_H_INCLUDED
00003 
00004 /*   
00005         Authors:
00006         Hugo Elias
00007         Moritz "Morty" Struebe (morty@gmx.net)
00008 
00009         (c) Shadow Robot Company 2007
00010         This code is licensed under the GPL.
00011 
00012 */
00013 
00014 #ifdef S_SPLINT_S
00015     #define rom 
00016     #define overlay 
00017     #define near
00018     #define __wparam 
00019 #else
00020     #ifdef SDCC
00021         #define rom __code
00022         #define overlay 
00023         #define near
00024     #else
00025         #define __wparam 
00026     #endif
00027 #endif
00028 
00029 /* Data type abbreviations*/
00030 
00031 #ifdef SDCC
00032     #define int8u  unsigned char
00033     #define int8s    signed char
00034 
00035     #define int16u unsigned int
00036     #define int16s   signed int
00037 
00038     #define int24u unsigned long
00039     #define int24s   signed long
00040 
00041     #define int32u unsigned long
00042     #define int32s   signed long
00043 #else
00044     #define int8u  unsigned char
00045     #define int8s    signed char
00046 
00047     #define int16u unsigned short
00048     #define int16s   signed short
00049 
00050     #define int24u unsigned short long
00051     #define int24s   signed short long
00052 
00053     #define int32u unsigned long
00054     #define int32s   signed long
00055 #endif
00056 
00057 
00058 // Long long / 64 bit is not supported by C16 - C30 does, though.
00059 // #define int64u unsigned long long
00060 // #define int64s   signed long long
00061 
00062 typedef struct int64
00063 {
00064         int32u low;
00065         int32u high;    
00066 } int64u;
00067 
00068 
00069 //#include "this_node.h"
00070 
00071 typedef union union16
00072 {
00073         int16u  word;
00074         int8u   byte[2];
00075 } union16_t;
00076 
00077 typedef union union32
00078 {
00079         int32u  dword;
00080         int16u  word[2];
00081         int8u   byte[4];
00082 } union32_t;
00083 
00084 typedef union union64
00085 {
00086         int32u  dword[2];
00087         int16u  word[4];
00088         int8u   byte[8];
00089 } union64_t;
00090 
00091 
00092 // WARNING: Only works with overlay or global values. NOT VALUES ON THE STACK!
00093 #ifdef SDCC
00094     #define shift_right_signed_32(x)    x >>= 1;
00095 #else
00096     #define shift_right_signed_32(x)    x >>= 1;                \
00097                                         _asm                    \
00098                                             btfsc x+3, 6, 1     \
00099                                             bsf   x+3, 7, 1     \
00100                                         _endasm                        
00101 #endif
00102 
00103 #ifdef SDCC
00104     #define shift_right_signed_16(x)    x >>= 1;
00105 #else
00106     #define shift_right_signed_16(x)    x >>= 1;                \
00107                                         _asm                    \
00108                                             btfsc x+1, 6, 1     \
00109                                             bsf   x+1, 7, 1     \
00110                                         _endasm                        
00111 #endif
00112 
00113 void ShiftLeft64(union union64 *p);
00114 
00115 void Reset_func(void);                  
00116 void ClrWdt_func(void);                 
00117 
00118 extern const int8u basic_lshift[];
00119 
00120 /* The @sef tells splint these parameters must be side-effect free, because they may be invoked more
00121  * than once */
00122 
00123 /*@notfunction@*/
00124 #define abs(x ) ((x) > 0 ? (x) : -(x))
00125 /*@notfunction@*/
00126 #define abslimit(val, lim)  {                                               \
00127                                     if      ((val) >  (lim))  (val) =  (lim);   \
00128                                     else if ((val) < -(lim))  (val) = -(lim);   \
00129                             }
00130 
00131 /*@notfunction@*/
00132 #define rshift_sgn(val, shift) (((val) > 0) ? ((val) >> (shift)) : -((-(val))>>(shift))) 
00133 
00134 
00135 #ifdef SDCC
00136     /* These defines map from non-SDCC bit variables to SDCC bit variables. */
00137     #define RXM0SIDL_EXIDEN RXM0SIDLbits.EXIDEN
00138     #define RXM1SIDL_EXIDEN RXM1SIDLbits.EXIDEN
00139     #define ECANCON_MDSEL1 ECANCONbits.MDSEL1
00140     #define ECANCON_MDSEL0 ECANCONbits.MDSEL0
00141     #define COMSTAT_FIFOEMPTY COMSTATbits.FIFOEMPTY
00142     #define PIR3_RXBnIF PIR3bits.RXBnIF
00143     #define COMSTAT_RXBnOVFL COMSTATbits.RXBnOVFL
00144     #define PIR3_IRXIF PIR3bits.IRXIF
00145     
00146     #define TXB0CON_TXREQ TXB0CONbits.TXREQ 
00147     #define TXB1CON_TXREQ TXB1CONbits.TXREQ
00148     #define TXB2CON_TXREQ TXB2CONbits.TXREQ
00149     #define BSEL0_B0TXEN BSEL0bits.B0TXEN
00150     #define B0CON_TXREQ B0CONbits.TXREQ
00151     
00152     #define BSEL0_B1TXEN BSEL0bits.B1TXEN
00153     #define B1CON_TXREQ B1CONbits.TXREQ
00154     #define BSEL0_B2TXEN BSEL0bits.B2TXEN
00155     #define B2CON_TXREQ B2CONbits.TXREQ
00156     #define BSEL0_B3TXEN BSEL0bits.B3TXEN
00157     #define B3CON_TXREQ B3CONbits.TXREQ
00158     #define BSEL0_B4TXEN BSEL0bits.B4TXEN
00159     #define B4CON_TXREQ B4CONbits.TXREQ
00160     #define BSEL0_B5TXEN BSEL0bits.B5TXEN
00161     #define B5CON_TXREQ B5CONbits.TXREQ
00162     #define RXB0CON_RXFUL RXB0CONbits.RXFUL
00163     #define PIR3_RXB0IF PIR3bits.RXB0IF
00164     #define COMSTAT_RXB0OVFL COMSTATbits.RXB0OVFL
00165     
00166     #define RXB0CON_FILHIT0 RXB0CONbits.FILHIT0
00167     #define RXB1CON_RXFUL RXB1CONbits.RXFUL
00168     #define PIR3_RXB1IF PIR3bits.RXB1IF
00169     #define COMSTAT_RXB1OVFL COMSTATbits.RXB1OVFL
00170     
00171     #define RXFCON0_RXF0EN RXFCON0bits.RXF0EN
00172     #define RXFCON0_RXF1EN RXFCON0bits.RXF1EN
00173     #define RXFCON0_RXF2EN RXFCON0bits.RXF2EN
00174     #define RXFCON0_RXF3EN RXFCON0bits.RXF3EN
00175     #define B0CON_RXFUL B0CONbits.RXFUL
00176     #define B1CON_RXFUL B1CONbits.RXFUL
00177     #define B2CON_RXFUL B2CONbits.RXFUL
00178     #define B3CON_RXFUL B3CONbits.RXFUL
00179     #define B4CON_RXFUL B4CONbits.RXFUL
00180     #define B5CON_RXFUL B5CONbits.RXFUL
00181     
00182     
00183     
00184     #define _asm __asm
00185     #define _endasm __endasm
00186     
00187     /* Can't copy aggregates! */
00188     #define msg_copy(dest, src) { dest.messageID=src.messageID; dest.d.dword[0]=src.d.dword[0]; dest.d.dword[1]=src.d.dword[1]; dest.length=src.length; dest.flags=src.flags; }
00189 #else /* !SDCC */
00190     #define msg_copy(dest, src) dest=src
00191 #endif /* SDCC */
00192 
00193 
00194 /* Delays code */
00195 #ifdef SDCC
00196     #include <delay.h>
00197     #define Delay1TCY Nop
00198     #define Delay10TCYx delay10tcy
00199     #define Delay100TCYx delay100tcy
00200     #define Delay10KTCYx delay10ktcy;
00201     #define Delay1KTCYx delay1ktcy;
00202 #else /* !SDCC */
00203     #ifdef GCC
00204         #define Delay1TCY 
00205         #define Delay10TCYx(x)
00206         #define Delay100TCYx(x)
00207         #define Delay10KTCYx(x)
00208         #define Delay1KTCYx(x)
00209         #define delay1mtcy(x)
00210         #define CARRY_BIT 0
00211     #else /* !GCC */
00212         #include <delays.h>
00213         #define delay1mtcy(x) { int8u d; for (d=0;d<100; d++) Delay10KTCYx(d); }
00214         #define CARRY_BIT 0
00215     #endif /* GCC */
00216 #endif /* SDCC */
00217 
00218 
00219 
00220 #endif


sr_external_dependencies
Author(s): Ugo Cupcic/ ugo@shadowrobot.com, software@shadowrobot.com
autogenerated on Thu Jan 2 2014 12:01:42