Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_netcruzer.h
Go to the documentation of this file.
1 
81 #ifndef NETCRUZER_H
82 #define NETCRUZER_H
83 
84 #if (defined(__PIC24F__)) && defined(__C30__) // Microchip C30 compiler
85  #include "PPS.h"
86 #elif defined(__dsPIC33F__) && defined(__C30__) // Microchip C30 compiler
87 #elif defined(__PIC32MX__) // Microchip C32 compiler
88 #else
89  #error Unknown processor or compiler. See Compiler.h
90 #endif
91 
92 
94 //Default Defines before any include file
95 #if !defined(NZ_ADC_DISABLE) && !defined(HAS_NZ_ADC)
96  #define HAS_NZ_ADC
97 #endif
98 #if defined(NZ_RTC_ENABLE) && !defined(HAS_NZ_RTC)
99  #define HAS_NZ_RTC
100 #endif
101 #if !defined(NZ_PWM_DISABLE) && !defined(HAS_NZ_PWM)
102  #define HAS_NZ_PWM
103 #endif
104 
105 //UART
106 #if defined(NZ_UART1_ENABLE) && !defined(HAS_SERPORT_UART1)
107  #define HAS_SERPORT_UART1
108 #endif
109 #if defined(NZ_UART2_ENABLE) && !defined(HAS_SERPORT_UART2)
110  #define HAS_SERPORT_UART2
111 #endif
112 #if defined(NZ_UART3_ENABLE) && !defined(HAS_SERPORT_UART3)
113  #define HAS_SERPORT_UART3
114 #endif
115 #if defined(NZ_UART4_ENABLE) && !defined(HAS_SERPORT_UART4)
116  #define HAS_SERPORT_UART4
117 #endif
118 #if defined(HAS_SERPORT_UART1) || defined(HAS_SERPORT_UART2) || defined(HAS_SERPORT_UART3) || defined(HAS_SERPORT_UART4)
119  #define HAS_SERPORT_UART
120 #endif
121 
122 //I2C
123 #if defined(NZ_I2C1_ENABLE) && !defined(HAS_SERPORT_I2C1)
124  #define HAS_SERPORT_I2C1
125 #endif
126 #if defined(NZ_I2C2_ENABLE) && !defined(HAS_SERPORT_I2C2)
127  #define HAS_SERPORT_I2C2
128 #endif
129 #if defined(NZ_I2C3_ENABLE) && !defined(HAS_SERPORT_I2C3)
130  #define HAS_SERPORT_I2C3
131 #endif
132 #if (defined(HAS_SERPORT_I2C1) || defined(HAS_SERPORT_I2C2) || defined(HAS_SERPORT_I2C3))
133  #define HAS_SERPORT_I2C
134 #endif
135 
136 //SPI
137 #if defined(NZ_SPI1_ENABLE) && !defined(HAS_SERPORT_SPI1)
138  #define HAS_SERPORT_SPI1
139 #endif
140 #if defined(NZ_SPI2_ENABLE) && !defined(HAS_SERPORT_SPI2)
141  #define HAS_SERPORT_SPI2
142 #endif
143 #if defined(NZ_SPI3_ENABLE) && !defined(HAS_SERPORT_SPI3)
144  #define HAS_SERPORT_SPI3
145 #endif
146 #if (defined(HAS_SERPORT_SPI1) || defined(HAS_SERPORT_SPI2) || defined(HAS_SERPORT_SPI3))
147  #define HAS_SERPORT_SPI
148 #endif
149 
150 
151 
153 //Include Files
154 
155 //Basic includes required for all projects (38 seconds)
156 #include "nz_tick.h"
157 #include "nz_helpers.h"
158 #include "nz_ioPortDefs.h"
159 #include "nz_ioPorts.h"
160 
161 //Netcruzer RTOS includes
162 #if (nzosENABLE==1)
163 #include "../rtos/nz_rtos.h"
164 #include "../rtos/nzos_main.h"
165 #endif
166 
167 
168 #if !defined(__INLINE_FUNCTION__)
169 #define __INLINE_FUNCTION__ extern inline __attribute__((always_inline))
170 #endif
171 
172 
174 //Default Defines
175 #ifndef DEBUG_CONF_DEFAULT
176  #ifdef DEBUG_LEVEL_ALLOFF
177  #define DEBUG_CONF_DEFAULT DEBUG_LEVEL_OFF
178  #else
179  #define DEBUG_CONF_DEFAULT DEBUG_LEVEL_ERROR
180  #endif
181 #endif
182 
183 #ifndef NZ_MALLOC
184  #define NZ_MALLOC(size) malloc(size)
185 #endif
186 
187 #if !defined(USER_RAM_SIZE)
188 //Default size of RAM User Memory
189 #define USER_RAM_SIZE 256
190 #endif
191 
192 #define MAIN_LOOP_TOP() \
193  static BOOL inMainLoop=0; \
194  nzSysTaskDefault(); \
195  if (inMainLoop == TRUE) return; \
196  inMainLoop = TRUE;
197 
198 #define MAIN_LOOP_BOTTOM() \
199  inMainLoop = FALSE;
200 
201 
203 //Global variables
204 #define BUFFER_DUMMY_SIZE 2
205 #define NZ_GLOBALS_SERPORT_DEBUG nzGlobals.serDebug //Pointer to first SERPORT object
206 #define NZ_GLOBALS_SERPORT_FIRST nzGlobals.serUart1 //Pointer to first SERPORT object, EXCLUDING Debug serport!
207 #define NZ_GLOBALS_SERPORT_LAST nzGlobals.serUser8 //Pointer to last SERPORT object
208 #define SERPORT_COUNT (NZ_GLOBALS_SERPORT_LAST - NZ_GLOBALS_SERPORT_FIRST)
209 
213 typedef struct __attribute__((aligned(2), packed))
214 {
215  union {
216  struct
217  {
218  unsigned int bPowerFail : 1; //If set, we are in power fail mode. Panic!!!
219  unsigned int bFill : 15; //Fill to ensure flags take up a 16-bit WORD
220  } flags;
221  WORD flagsVal;
222  };
223 
224  WORD testW;
225 } BOARD_STATUS;
226 
227 typedef struct __attribute__((__packed__)) WDT_FLAGS_
228 {
229  union {
230  struct
231  {
232  unsigned int main : 1;
233  unsigned int mainApp : 1;
234  unsigned int stackTask : 1;
235  unsigned int serUART : 1;
236  unsigned int serSPI : 1;
237  unsigned int serI2C : 1;
238  unsigned int serUDP : 1;
239  unsigned int serTCP : 1;
240  unsigned int serUSB : 1;
241  unsigned int fl9 : 1;
242  unsigned int fl10 : 1;
243  unsigned int fl11 : 1;
244  unsigned int fl12 : 1;
245  unsigned int fl13 : 1;
246  unsigned int fl14 : 1;
247  unsigned int fl15 : 1;
248 
249  unsigned int app0 : 1;
250  unsigned int app1 : 1;
251  unsigned int app2 : 1;
252  unsigned int app3 : 1;
253  unsigned int app4 : 1;
254  unsigned int app5 : 1;
255  unsigned int app6 : 1;
256  unsigned int app7 : 1;
257  unsigned int app8 : 1;
258  unsigned int app9 : 1;
259  unsigned int app10 : 1;
260  unsigned int app11 : 1;
261  unsigned int app12 : 1;
262  unsigned int app13 : 1;
263  unsigned int app14 : 1;
264  unsigned int app15 : 1;
265  } bits;
266  DWORD Val;
267  };
268 } WDT_FLAGS;
269 
270 
271 
275 typedef struct __attribute__((__packed__)) _GLOBAL_DEFS
276 {
277  BOARD_STATUS brdStatus;
278  WDT_FLAGS wdtFlags;
279 
280  WORD userRamSize;
281  BYTE userRam[USER_RAM_SIZE];
282 
283 
284  void* serDebug;
285 
286  //Pointers to "Serial Data Ports" (SERPORT structures). Pointer is NULL if that "Serial Data Port"
287  //does not exist.
289  void* serUart1;
290  void* serUart2;
291  void* serUart3;
292  void* serUart4;
293  void* serSPI1;
294  void* serSPI3;
295  void* serI2C1;
296  void* serI2C2;
297 
298  void* serI2C3;
299  void* serUDP1;
300  void* serUDP2;
301  void* serUDP3;
302  void* serTCP1;
303  void* serTCP2;
304  void* serTCP3;
305  void* serUSB;
306 
307  void* serUser1;
308  void* serUser2;
309  void* serUser3;
310  void* serUser4;
311  void* serUser5;
312  void* serUser6;
313  void* serUser7;
314  void* serUser8;
315 } GLOBAL_DEFS;
316 
317 
318 #ifndef THIS_IS_NZ_NETCRUZER_C
319  extern GLOBAL_DEFS nzGlobals;
320 #endif
321 
322 
323 
325 //The following defines will be included with all files!
326 #if !defined(NZSYS_DONT_MANAGE_TICK)
327 #if defined(NZSYS_ENABLE_COMPLEX_TICK)
328  #include "nz_tickCx.h" //In addition to nz_tick.h, also include nz_tickCx.h
329 #else
330  #define NZSYS_ENABLE_TICK
331 #endif
332 #endif //#ifndef NZSYS_DONT_MANAGE_TICK
333 
334 //LCD2S !!!!! This is broken, fix !!!!!
335 //#ifdef NZSYS_ENABLE_LCD2S_AND_I2C1
336 //#include "nz_i2c1.h"
337 //#include "nz_lcd2s.h"
338 //#endif
339 
340 
341 //USB "Serial Data Port"
342 #if defined(NZ_USBHID_ENABLE)
343  #if !defined(HAS_SERPORT_USB_HID)
344  #define HAS_SERPORT_USB_HID
345  #endif
346  #if !defined(USB_IS_HID)
347  #define USB_IS_HID
348  #endif
349 #endif
350 #if defined(NZ_USBCDC_ENABLE)
351  #if !defined(HAS_SERPORT_USB_CDC)
352  #define HAS_SERPORT_USB_CDC
353  #endif
354  #if !defined(USB_IS_CDC)
355  #define USB_IS_CDC
356  #endif
357 #endif
358 #if defined(NZ_USBMIDI_ENABLE)
359  #if !defined(HAS_SERPORT_USB_MIDI)
360  #define HAS_SERPORT_USB_MIDI
361  #endif
362  #if !defined(USB_IS_MIDI)
363  #define USB_IS_MIDI
364  #endif
365 #endif
366 #if defined(HAS_SERPORT_USB_HID) || defined(HAS_SERPORT_USB_CDC) || defined(HAS_SERPORT_USB_MIDI)
367  #if !defined(HAS_A_SERPORT)
368  #define HAS_A_SERPORT
369  #endif
370  #if !defined(HAS_SERPORT_USB)
371  #define HAS_SERPORT_USB
372  #endif
373 #endif
374 
375 
376 
378 //Debug - Includes required for USB
379 //If a known debugger is defined, define HAS_NZ_DEBUGGING. If a unknown debugger is added by
380 //application, then HAS_NZ_DEBUGGING should be defined by application in projdefs.h!
381 #if defined(NZ_USBHID_DEBUG_ENABLE) && !defined(HAS_USBHID_DEBUGGING)
382  #define HAS_USBHID_DEBUGGING
383 #endif
384 #if defined(NZ_USBCDC_DEBUG_ENABLE) && !defined(HAS_USBCDC_DEBUGGING)
385  #define HAS_USBCDC_DEBUGGING
386 #endif
387 #if defined(NZ_UART1_DEBUG_ENABLE) && !defined(HAS_UART1_DEBUGGING)
388  #define HAS_UART1_DEBUGGING
389 #endif
390 #if defined(NZ_USBHID_DEBUG_ENABLE) || defined(NZ_USBCDC_DEBUG_ENABLE) || defined(NZ_UART1_DEBUG_ENABLE)
391  #define HAS_NZ_DEBUGGING
392 #endif
393 #if !defined(NZSYS_DONT_MANAGE_DEBUG) && defined(HAS_NZ_DEBUGGING)
394  #define NZSYS_MANAGE_DEBUG
395 #endif
396 
397 
398 
400 //Other includes
401 #include "nz_analog.h"
402 #include "nz_pwm.h"
403 
404 
405 
407 //Functions prototypes
408 void mainLoop(void);
409 
410 #if defined(NZSYS_CALL_INITIALIZE_BOARD)
411 void initializeBoard(void);
412 #endif
413 
414 #if defined(NZSYS_CALL_APPCONF_FUNCTIONS)
415 void cfgInit(BYTE* pCfgStruct);
416 void appConfInit(void);
417 #endif
418 
419 
426 void nzSysInitDefault(void);
427 
432 void nzSysTaskDefault(void);
433 
437 void nzSysGlobalInit(void);
438 
439 
450 #define USER_RAM_WORD(adr) (*((WORD*)(&nzGlobals.userRam[adr])))
451 
462 #define USER_RAM_BYTE(adr) (nzGlobals.userRam[adr])
463 
464 
465 #if !defined(DOXY_FUNC) //Don't document in doxygen
466 
467 #define nzsysInitDefault() nzSysInitDefault()
468 
469 #define nzsysTaskDefault() nzSysTaskDefault()
470 
471 #define nzsysGlobalInit() nzSysGlobalInit()
472 #endif
473 
474 
475 #endif //#ifndef NETCRUZER_H