Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_ioPorts.h
Go to the documentation of this file.
1 
48 #ifndef IO_PORTS_H
49 #define IO_PORTS_H
50 
51 #include "nz_ioPortDefs.h"
52 
53 
54 
58 void portInit(void);
59 
94 BYTE portConfig(BYTE portID, WORD typeConf);
95 
117 BYTE ucportGetIndex(BYTE portID);
118 
119 
139 BYTE portGetUcportID(BYTE portID);
140 
141 
154 BYTE getPortIdForStr(const char* str);
155 
156 
177 BOOL portReadBitadr(WORD bitAdr);
178 
179 
202 #define portReadBitadr_MACRO(bitAdr) (*((volatile WORD*)((bitAdr)&0xFFF)) & (0x01 << ((bitAdr)>>12)))
203 
204 
225 #if !defined(DOXY_FUNC)
226 #if defined(IOPORTS_OPTIMIZE_SIZE)
227 #define portSetBitadr(bitAdr) portWriteBitadr(bitAdr, 1)
228 #else
229 void portSetBitadr(WORD bitAdr);
230 #endif
231 #else
232 void portSetBitadr(WORD bitAdr);
233 #endif
234 
255 #define portSetBitadr_MACRO(bitAdr) (*((volatile WORD*)((bitAdr)&0xFFF)) |= (0x01 << ((bitAdr)>>12)))
256 
257 
278 #if !defined(DOXY_FUNC)
279 #if defined(IOPORTS_OPTIMIZE_SIZE)
280 #define portClearBitadr(bitAdr) portWriteBitadr(bitAdr, 0)
281 #else
282 void portClearBitadr(WORD bitAdr);
283 #endif
284 #else
285 void portClearBitadr(WORD bitAdr);
286 #endif
287 
308 #define portClearBitadr_MACRO(bitAdr) (*((volatile WORD*)((bitAdr)&0xFFF)) &= (~(0x01 << ((bitAdr)>>12))))
309 
310 
331 void portWriteBitadr(WORD bitAdr, BOOL value);
332 
333 
356 #define portWriteBitadr_MACRO(bitAdr, value) ((value==0) ? (*((volatile WORD*)((bitAdr)&0xFFF)) &= (~(0x01 << ((bitAdr)>>12)))) : (*((volatile WORD*)((bitAdr)&0xFFF)) |= (0x01 << ((bitAdr)>>12))))
357 
358 
383 #if !defined(DOXY_FUNC)
384 #if defined(__C30__)
385  //For PIC24F processors, the LAT register is 4 up from TRIS register
386  #define portGetLAT(portID) (portGetTRISwOffset(portID, 4))
387 #elif defined(__C32__)
388  //For PIC32MX and PIC32MZ processors, the LAT register is 0x30 up from TRIS register
389  #define portGetLAT(portID) (portGetTRISwOffset(portID, 0x30))
390 #else
391  #error "portGetLAT() not defined for this compiler!"
392 #endif
393 #else
394 WORD portGetLAT(BYTE portID);
395 #endif
396 
397 
418 #if !defined(DOXY_FUNC)
419 #if defined(__C30__)
420  //For PIC24F processors, the LAT register is 4 up from TRIS register
421  #define ucportGetLAT(ucportID) (ucportGetTRISwOffset(ucportID, 4))
422 #elif defined(__C32__)
423  //For PIC32MX and PIC32MZ processors, the LAT register is 0x30 up from TRIS register
424  #define ucportGetLAT(ucportID) (ucportGetTRISwOffset(ucportID, 0x30))
425 #else
426  #error "ucportGetLAT() not defined for this compiler!"
427 #endif
428 #else
429 WORD ucportGetLAT(BYTE ucportID);
430 #endif
431 
432 
459 #if !defined(DOXY_FUNC)
460 #if defined(__C30__)
461  //For PIC24F processors, the PORT register is 2 up from TRIS register
462  #define portGetPIN(portID) (portGetTRISwOffset(portID, 2))
463 #elif defined(__C32__)
464  //For PIC32MX and PIC32MZ processors, the PORT register is 0x20 up from TRIS register
465  #define portGetPIN(portID) (portGetTRISwOffset(portID, 0x20))
466 #else
467  #error "portGetPIN() not defined for this compiler!"
468 #endif
469 #else
470 WORD portGetPIN(BYTE portID);
471 #endif
472 
473 
491 #if !defined(DOXY_FUNC)
492 #if defined(__C30__)
493  //For PIC24F processors, the PORT register is 2 up from TRIS register
494  #define ucportGetPIN(ucportID) (ucportGetTRISwOffset(ucportID, 2))
495 #elif defined(__C32__)
496  //For PIC32MX and PIC32MZ processors, the PORT register is 0x20 up from TRIS register
497  #define ucportGetPIN(ucportID) (ucportGetTRISwOffset(ucportID, 0x20))
498 #else
499  #error "ucportGetPIN() not defined for this compiler!"
500 #endif
501 #else
502 WORD ucportGetPIN(BYTE ucportID);
503 #endif
504 
505 
506 
521 #if !defined(DOXY_FUNC)
522 #if defined(__C30__)
523  //For PIC24F processors, the ODC register is 6 up from TRIS register
524  #define portGetODC(portID) (portGetTRISwOffset(portID, 6))
525 #elif defined(__C32__)
526  //For PIC32MX and PIC32MZ processors, the ODC register is 0x40 up from TRIS register
527  #define portGetODC(portID) (portGetTRISwOffset(portID, 0x40))
528 #else
529  #error "portGetODC() not defined for this compiler!"
530 #endif
531 #else
532 WORD portGetODC(BYTE portID);
533 #endif
534 
535 
551 #if !defined(DOXY_FUNC)
552 #if defined(__C30__)
553  //For PIC24F processors, the ODC (Open Drain Control) register is 6 up from TRIS register
554  #define ucportGetODC(ucportID) (ucportGetTRISwOffset(ucportID, 6))
555 #elif defined(__C32__)
556  //For PIC32MX and PIC32MZ processors, the ODC (Open Drain Control) register is 0x40 up from
557  //the TRIS register
558  #define ucportGetODC(ucportID) (ucportGetTRISwOffset(ucportID, 0x40))
559 #else
560  #error "ucportGetODC() not defined for this compiler!"
561 #endif
562 #else
563 WORD ucportGetODC(BYTE ucportID);
564 #endif
565 
566 
580 #if !defined(DOXY_FUNC)
581 #if defined(IOPORTS_OPTIMIZE_SIZE)
582 #define portGetTRIS(portID) portGetTRISwOffset(portID, 0)
583 #else
584 WORD portGetTRIS(BYTE portID);
585 #endif
586 #else
587 WORD portGetTRIS(BYTE portID);
588 #endif
589 
590 
607 WORD portGetTRISwOffset(BYTE portID, BYTE offset);
608 
609 
623 #define portGetTRIS_MACRO(portID) ((portID>PORT_ID_MAX) ? (BITADR_NA/*Returns BITADR_NA if not available or error*/) : TRIS_PORTID_BITADR_MAP[portID])
624 
625 
638 #if !defined(DOXY_FUNC)
639 #if defined(IOPORTS_OPTIMIZE_SIZE)
640 #define ucportGetTRIS(ucportID) ucportGetTRISwOffset(ucportID, 0)
641 #else
642 WORD ucportGetTRIS(BYTE ucportID);
643 #endif
644 #else
645 WORD ucportGetTRIS(BYTE ucportID);
646 #endif
647 
648 
649 
664 WORD ucportGetTRISwOffset(BYTE ucportID, BYTE offset);
665 
666 
681 #if !defined(DOXY_FUNC)
682 #if defined(IOPORTS_OPTIMIZE_SIZE)
683 #define portGetCNPD(portID) portGetCNPDwOffset(portID, 0)
684 #else
685 WORD portGetCNPD(BYTE portID);
686 #endif
687 #else
688 WORD portGetCNPD(BYTE portID);
689 #endif
690 
691 
708 WORD portGetCNPDwOffset(BYTE portID, BYTE offset);
709 
710 
724 #if !defined(DOXY_FUNC)
725 #if defined(IOPORTS_OPTIMIZE_SIZE)
726 #define ucportGetCNPD(ucportID) ucportGetCNPDwOffset(ucportID, 0)
727 #else
728 WORD ucportGetCNPD(BYTE ucportID);
729 #endif
730 #else
731 WORD ucportGetCNPD(BYTE ucportID);
732 #endif
733 
734 
749 WORD ucportGetCNPDwOffset(BYTE ucportID, BYTE offset);
750 
751 
767 #if !defined(DOXY_FUNC)
768 #if defined(__C30__)
769  //For PIC24F processors, the CNPU (Pull-Up) register is 0x18 up from CNPD register
770  #define ucportGetCNPU(ucportID) (ucportGetCNPDwOffset(ucportID, 0x18))
771 #elif defined(__C32__)
772  //For PIC32MX and PIC32MZ processors, the CNPU (Pull-Up Control) register is 0x10 down from
773  //the CNPD register
774  #define ucportGetCNPU(ucportID) (ucportGetCNPDwOffset(ucportID, -0x10))
775 #else
776  #error "ucportGetCNPU() not defined for this compiler!"
777 #endif
778 #else
779 WORD ucportGetCNPU(BYTE ucportID);
780 #endif
781 
782 
797 #if !defined(DOXY_FUNC)
798 #if defined(__C30__)
799  //For PIC24F processors, the CNPU (Pull-Up) register is 0x18 up from CNPD register
800  #define portGetCNPU(portID) (portGetCNPDwOffset(portID, 0x18))
801 #elif defined(__C32__)
802  //For PIC32MX and PIC32MZ processors, the CNPU (Pull-Up Control) register is 0x10 down from
803  //the CNPD register
804  #define portGetCNPU(portID) (portGetCNPDwOffset(portID, -0x10))
805 #else
806  #error "portGetCNPU() not defined for this compiler!"
807 #endif
808 #else
809 WORD portGetCNIE(BYTE portID);
810 #endif
811 
812 
828 #if !defined(DOXY_FUNC)
829 #if defined(__C30__)
830  //For PIC24F processors, the CNIE (CN Interrupt Enable) register is 0x0c up from CNPD register
831  #define ucportGetCNIE(ucportID) (ucportGetCNPDwOffset(ucportID, 0x0c))
832 #elif defined(__C32__)
833  //For PIC32MX and PIC32MZ processors, the CNIE (CN Interrupt Enable) register is 0x20 up from
834  //the CNPD register
835  #define ucportGetCNIE(ucportID) (ucportGetCNPDwOffset(ucportID, 0x20))
836 #else
837  #error "ucportGetCNIE() not defined for this compiler!"
838 #endif
839 #else
840 WORD ucportGetCNIE(BYTE ucportID);
841 #endif
842 
843 
858 #if !defined(DOXY_FUNC)
859 #if defined(__C30__)
860  //For PIC24F processors, the CNIE (CN Interrupt Enable) register is 0x0c up from CNPD register
861  #define portGetCNIE(portID) (portGetCNPDwOffset(portID, 0x0c))
862 #elif defined(__C32__)
863  //For PIC32MX and PIC32MZ processors, the CNIE (CN Interrupt Enable) register is 0x20 up from
864  //the CNPD register
865  #define portGetCNIE(portID) (portGetCNPDwOffset(portID, 0x20))
866 #else
867  #error "portGetCNIE() not defined for this compiler!"
868 #endif
869 #else
870 WORD portGetCNIE(BYTE portID);
871 #endif
872 
873 
882 void portWritePullup(BYTE portID, BOOL val);
883 
884 
893 void portWritePulldown(BYTE portID, BOOL val);
894 
895 
903 void portConfigDir(BYTE portID, BOOL dir);
904 
905 
914 void portWrite(BYTE portID, BYTE value);
915 
916 
926 BOOL portRead(BYTE portID);
927 
928 
929 
931 //Arduino compatible functions
932 //All the following functions use the "Microcontroller port ID"(a UCPORT_ID_xx define)
933 //to identify a port. It is not as fast as using functions that take a "port bitAdr".
934 //But, all functions can use the same "Microcontroller port ID", where the "port bitAdr" is
935 //different for each function (LAT, TRIS, PORT...).
936 //To get the "Microcontroller port ID":
937 // - If the "Port ID" is know, the portGetUcportID() function will return the "port ID"
938 // - The "port ID" for each IO port (port of SBC) is defined in the "brd_xxx.h" include file
939 // for selected board, like UCPORT_ID_28 for example
940 #if !defined(HIGH)
941 #define HIGH 1
942 #endif
943 #if !defined(LOW)
944 #define LOW 0
945 #endif
946 
947 
958 #if !defined(DOXY_FUNC)
959 #define digitalWrite(portID, value) portWrite(portID, value)
960 #else
961 void digitalWrite(BYTE portID, BYTE value);
962 #endif
963 
964 
976 #if !defined(DOXY_FUNC)
977 #define digitalRead(portID) portRead(portID)
978 #else
979 BOOL digitalRead(BYTE portID);
980 #endif
981 
982 
983 
984 #endif
985