1 // ********************************************************************* 2 // DPA Autoexec example * 3 // ********************************************************************* 4 // Copyright (c) IQRF Tech s.r.o. 5 // 6 // File: $RCSfile: DpaAutoexec.c,v $ 7 // Version: $Revision: 1.17 $ 8 // Date: $Date: 2017/10/19 07:50:19 $ 9 // 10 // Revision history: 11 // 2017/03/13 Release for DPA 3.00 12 // 2015/08/05 Release for DPA 2.20 13 // 2014/04/30 Release for DPA 2.10 14 // 15 // ********************************************************************* 16 17 // Online DPA documentation http://www.iqrf.org/DpaTechGuide/ 18 19 // Before uploading this example make sure: 20 // 1. Autoexec is enabled at HWP Configuration 21 // 2. Used peripherals are enabled at HWP Configuration 22 // 3. External EEPROM upload is selected at IQRF IDE. Please note external EEPROM cannot be uploaded using RFPGM. 23 24 // Default IQRF include (modify the path according to your setup) 25 #include "IQRF.h" 26 27 // Do not check for the Custom DPA Handler existence (we only wrote to the external EEPROM) 28 #define NO_CUSTOM_DPA_HANDLER 29 30 // Uncomment in order to test Example #3 at [C] device (EEEPROM peripheral space starts at different address) 31 //#define COORDINATOR_CUSTOM_HANDLER 32 33 // Default DPA header (modify the path according to your setup) 34 #include "DPA.h" 35 // Default Custom DPA Handler header (modify the path according to your setup) 36 #include "DPAcustomHandler.h" 37 38 //############################################################################################ 39 40 // Choose example number 1-4 41 #define EXAMPLE 1 42 43 // ------------------------------------------------------------------------------------------- 44 #if EXAMPLE == 1 45 // Example #1: Switch on both LEDs 46 #pragma cdata[ __EEESTART + AUTOEXEC_EEEPROM_ADDR ] = \ 47 /* 1. Green LED ON */ \ 48 5, PNUM_LEDG, CMD_LED_SET_ON, 0xff, 0xff, \ 49 /* 2. Red LED ON */ \ 50 5, PNUM_LEDR, CMD_LED_SET_ON, 0xff, 0xff, \ 51 /* 3. Delay 1s (LEDs will be visible at LP mode) */ \ 52 8, PNUM_IO, CMD_IO_SET, 0xff, 0xff, PNUM_IO_DELAY, 0xe8, 0x03, \ 53 /* 4. End of Autoexec */ \ 54 0 55 #endif 56 57 // ------------------------------------------------------------------------------------------- 58 #if EXAMPLE == 2 59 // Example #2: Open UART @ 9600 baud, write "Hello" to UART 60 #pragma cdata[ __EEESTART + AUTOEXEC_EEEPROM_ADDR ] = \ 61 /* 1. Open UART at 9600 baud */ \ 62 6, PNUM_UART, CMD_UART_OPEN, 0xff, 0xff, DpaBaud_9600, \ 63 /* 2. Write "Hello" to UART */ \ 64 11, PNUM_UART, CMD_UART_WRITE_READ, 0xff, 0xff, /* no read */ 0xff, 'H', 'e', 'l', 'l', 'o', \ 65 /* 3. End of Autoexec */ \ 66 0 67 #endif 68 69 // ------------------------------------------------------------------------------------------- 70 #if EXAMPLE == 3 71 // Example #3: Self modifying Autoexec 72 #pragma cdata[ __EEESTART + AUTOEXEC_EEEPROM_ADDR ] = \ 73 /* 1. Red LED ON, after the 1st boot it will be self-modified to the Green LED ON + end of Autoexec */ \ 74 5, PNUM_LEDR, CMD_LED_SET_ON, 0xff, 0xff, \ 75 /* 2. Delay 1s (red LED will be visible at LP mode) */ \ 76 8, PNUM_IO, CMD_IO_SET, 0xff, 0xff, PNUM_IO_DELAY, 0xe8, 0x03, \ 77 /* 3. Write to the EEEPROM a modified Autoexec so next time a Green LED will be ON */ \ 78 7 + 16, PNUM_EEEPROM, CMD_EEEPROM_XWRITE, 0xff, 0xff, AUTOEXEC_EEEPROM_ADDR & 0xFF, AUTOEXEC_EEEPROM_ADDR >> 8, \ 79 /* new 1. Green LED ON */ \ 80 5, PNUM_LEDG, CMD_LED_SET_ON, 0xff, 0xff, \ 81 /* new 2. Delay 1s (green LED will be visible at LP mode) */ \ 82 8, PNUM_IO, CMD_IO_SET, 0xff, 0xff, PNUM_IO_DELAY, 0xe8, 0x03, \ 83 /* new 3. End of autoexec */ \ 84 0, \ 85 /* 4. End of Autoexec */ \ 86 0 87 #endif 88 89 // ------------------------------------------------------------------------------------------- 90 #if EXAMPLE == 4 91 // Example #4: set green LED output pin and set LED on for 1s and then off for 1s, works also at LP mode 92 #pragma cdata[ __EEESTART + AUTOEXEC_EEEPROM_ADDR ] = \ 93 /* 1. Green LED IO is output */ \ 94 8, PNUM_IO, CMD_IO_DIRECTION, 0xff, 0xff, /* PORTB.7 = LEDG = Output */ PNUM_IO_TRISB, 0x80, 0x00, \ 95 /* 2. Green LED on for 1s, Green LED off for 1s */ \ 96 17, PNUM_IO, CMD_IO_SET, 0xff, 0xff, \ 97 /* PORTB.7 = 1 => LEDG on */ PNUM_IO_PORTB, 0x80, 0x80, \ 98 /* delay 1s */ PNUM_IO_DELAY, 0xe8, 0x03, \ 99 /* PORTB.7 = 0 => LEDG off */ PNUM_IO_PORTB, 0x80, 0x00, \ 100 /* delay 1s */ PNUM_IO_DELAY, 0xe8, 0x03, \ 101 /* 3. End of Autoexec */ \ 102 0 103 #endif 104 105 //############################################################################################