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