├── .gitignore
├── README.md
├── ccs
├── nfc-eink-img-update-demo
│ ├── .ccsproject
│ ├── .cproject
│ ├── .gitignore
│ ├── .launches
│ │ ├── nfc-eink-dataLog-demo.launch
│ │ ├── nfc-eink-demo.launch
│ │ ├── nfc-eink-img-update-demo.launch
│ │ └── nfc-eink-imgUpdater-demo.launch
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.cdt.codan.core.prefs
│ │ ├── org.eclipse.cdt.core.prefs
│ │ ├── org.eclipse.cdt.debug.core.prefs
│ │ └── org.eclipse.core.resources.prefs
│ ├── MSP430F5310.ccxml
│ ├── NFC_protocol
│ │ ├── 15693_Protocol.c
│ │ ├── 15693_Protocol.h
│ │ ├── 1outof256.c
│ │ ├── 1outof256.h
│ │ ├── RX_ISR.asm
│ │ ├── _14443_B.c
│ │ ├── _14443_B.h
│ │ ├── _14443_B_protocol.c
│ │ ├── _14443_B_protocol.h
│ │ ├── crc_checker.c
│ │ ├── crc_checker.h
│ │ ├── doNFC.c
│ │ ├── doNFC.h
│ │ ├── send_bpsk.c
│ │ ├── send_bpsk.h
│ │ ├── send_hdr.c
│ │ └── send_hdr.h
│ ├── UserApp
│ │ ├── img_data.h
│ │ ├── myApp.c
│ │ ├── myApp.h
│ │ ├── myE-paperApp.c
│ │ ├── myE-paperApp.h
│ │ ├── myNFC_Protocol.c
│ │ ├── myNFC_Protocol.h
│ │ ├── tempSense.c
│ │ └── tempSense.h
│ ├── common
│ │ ├── NFC_WISP_Rev1.0.h
│ │ ├── _system_pre_init.c
│ │ ├── accel.c
│ │ ├── accel.h
│ │ ├── accel_registers.h
│ │ ├── e-paper.c
│ │ ├── e-paper.h
│ │ ├── fram_memory.c
│ │ ├── fram_memory.h
│ │ ├── globals.c
│ │ ├── globals.h
│ │ ├── img_data_full_temp_range.h
│ │ ├── img_data_without_motion.h
│ │ ├── spi.c
│ │ ├── spi.h
│ │ ├── timer.c
│ │ └── timer.h
│ ├── lnk_msp430f5310.cmd
│ └── main.c
└── nfc-eink-temp-accel-data-logger-demo
│ ├── .ccsproject
│ ├── .cproject
│ ├── .gitignore
│ ├── .launches
│ ├── nfc-eink-dataLog-demo.launch
│ ├── nfc-eink-demo.launch
│ ├── nfc-eink-img-update-demo.launch
│ ├── nfc-eink-imgUpdater-demo.launch
│ └── nfc-eink-temp-accel-data-logger-demo.launch
│ ├── .project
│ ├── .settings
│ ├── org.eclipse.cdt.codan.core.prefs
│ ├── org.eclipse.cdt.core.prefs
│ ├── org.eclipse.cdt.debug.core.prefs
│ └── org.eclipse.core.resources.prefs
│ ├── MSP430F5310.ccxml
│ ├── NFC_protocol
│ ├── 15693_Protocol.c
│ ├── 15693_Protocol.h
│ ├── 1outof256.c
│ ├── 1outof256.h
│ ├── RX_ISR.asm
│ ├── _14443_B.c
│ ├── _14443_B.h
│ ├── _14443_B_protocol.c
│ ├── _14443_B_protocol.h
│ ├── crc_checker.c
│ ├── crc_checker.h
│ ├── doNFC.c
│ ├── doNFC.h
│ ├── send_bpsk.c
│ ├── send_bpsk.h
│ ├── send_hdr.c
│ └── send_hdr.h
│ ├── UserApp
│ ├── img_data.h
│ ├── myApp.c
│ ├── myApp.h
│ ├── myE-paperApp.c
│ ├── myE-paperApp.h
│ ├── myNFC_Protocol.c
│ ├── myNFC_Protocol.h
│ ├── tempSense.c
│ └── tempSense.h
│ ├── common
│ ├── NFC_WISP_Rev1.0.h
│ ├── _system_pre_init.c
│ ├── accel.c
│ ├── accel.h
│ ├── accel_registers.h
│ ├── e-paper.c
│ ├── e-paper.h
│ ├── fram_memory.c
│ ├── fram_memory.h
│ ├── globals.c
│ ├── globals.h
│ ├── img_data_full_temp_range.h
│ ├── img_data_without_motion.h
│ ├── spi.c
│ ├── spi.h
│ ├── timer.c
│ └── timer.h
│ ├── lnk_msp430f5310.cmd
│ └── main.c
└── license.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata
2 | dvt
3 | RemoteSystemsTempFiles
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #NFC-WISP Firmware
2 | ---
3 | ### Version
4 | 1.0
5 |
6 |
7 | #Resource
8 | ---
9 | ###Tutorial & Discussion:
10 | See NFC-WISP wiki: http://nfc-wisp.wikispaces.com/
11 |
12 | Please send your questions and suggestions to the [**discussion board**](http://nfc-wisp.wikispaces.com/wiki/messages) in wiki!!!
13 |
14 |
15 | ###Hardware Design repository:
16 | https://github.com/wisp/nfc-wisp-hw.git
17 |
18 | ###Andriod App repository
19 | Use cell-phone to updates E-ink display when loading “nfc-eink-img-update-demo” firmware
20 |
21 | https://github.com/wisp/nfc-reader-app.git
22 |
23 | #Features
24 | ---
25 | 1. Software defended NFC protocol
26 | 2. Optimized for low power consumption and low duty-cycle
27 | 3. Easy integration with user application
28 | 4. Includes accelerometer, FRAM, E-ink drivers
29 |
30 | #Introduction
31 | ---
32 | 1. The tagged version **"v1.0"** is the released stable version for **NFC-WISP 1.0** hardware and implement ISO 14443-Type B protocol, we put partially implemented ISO 15693 in the source code, but haven't fully tested it yet.
33 | The older pre-release firmware code is taged as **"pre-release"**.
34 | 2. A programed **NFC-WISP 1.0** tag using this firmware can be read as normal NFC tag using some NFC reading app (such as [NFC TagInfo](https://play.google.com/store/apps/details?id=at.mroland.android.apps.nfctaginfo&hl=en)) on NFC-enabled andriod smartphone. We test it on Nexus S, Galaxy S4 and Nexus S. But the nfc-eink-img-update-demo (see below) is only tested with Nexus S with our andriod phone app [Display Tag Updater]( https://github.com/wisp/nfc-reader-app.git).
35 |
36 | #Configuration
37 | ---
38 | 1. Set your Code Composer Studio v6x workspace to nfc-wisp-fw/ccs and import the following projects:
39 |
40 | * **nfc-eink-img-update-demo**
41 | An application which updates E-ink paper using our andriod app [**Display Tag Updater**]( https://github.com/wisp/nfc-reader-app.git):
42 | * **nfc-eink-temp-accel-data-logger-demo**
43 | An application which sample temerature and accelerometer motion state(in static or in motion)every 3s, and plots the result on the 2.7 inch E-ink in real time (motion state is indicated by a black bar on the right up corner).
44 |
45 | 2. Choose your build configuration under build list based on different **hardware** configuration.
46 |
47 | * **nfc-eink-img-update-demo**
48 | - _BUILD_E_INK_2.0_BATT_ : Update [2 inch E-ink](http://www.pervasivedisplays.com/products/2inch) (Gen 2) with battery.
49 | - _BUILD_E_INK_2.0_BATT_FREE_ : Update [2 inch E-ink](http://www.pervasivedisplays.com/products/2inch) (Gen 2) without connecting battery.
50 | - _BUILD_E_INK_2.7_BATT_ : Update [2.7 inch E-ink](http://www.pervasivedisplays.com/products/27) (Gen 2) with battery.
51 |
52 |
53 | * **nfc-eink-temp-accel-data-logger-demo**
54 | - _BUILD_E_INK_2.7_BATT_ : only works when use [2.7 inch E-ink](http://www.pervasivedisplays.com/products/27) (Gen 2) with battery
55 |
56 | * **hardware configuration**
57 | - Remove the Rz0 to disconnect battery
58 | - keep Rz0 on with re-chargeable li-ion battery connected on the back of hardware to use more energy(see [hardware repo](https://github.com/wisp/nfc-wisp-hw)).
59 | - by-default, the battery connection is enabled with Rz0, external FRAM chip is connected with , Accelerometer
60 |
61 | 3. Please read the **warning** when you build your project.
62 |
63 | 4. If it doesn't work, please check it load the correct build file and check if the debugger in Code Composer Studio is setted to offer 2.5V (when right-click-yourproject->Properties->Debug->MSP properties->Target Voltage(mV) should be 2500) and take a look of the **warning**.
64 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.ccsproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.gitignore:
--------------------------------------------------------------------------------
1 | Debug
2 | BUILD_E_INK_2.7_BATT
3 | BUILD_E_INK_2.0_BATT
4 | BUILD_E_INK_2.0_BATT_FREE
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.launches/nfc-eink-img-update-demo.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.launches/nfc-eink-imgUpdater-demo.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | nfc-eink-img-update-demo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 |
11 |
12 | ?name?
13 |
14 |
15 |
16 | org.eclipse.cdt.make.core.append_environment
17 | true
18 |
19 |
20 | org.eclipse.cdt.make.core.autoBuildTarget
21 | all
22 |
23 |
24 | org.eclipse.cdt.make.core.buildArguments
25 | -k
26 |
27 |
28 | org.eclipse.cdt.make.core.buildCommand
29 | ${CCS_UTILS_DIR}/bin/gmake
30 |
31 |
32 | org.eclipse.cdt.make.core.buildLocation
33 | ${workspace_loc:/nfc-eink-demo/Debug}
34 |
35 |
36 | org.eclipse.cdt.make.core.cleanBuildTarget
37 | clean
38 |
39 |
40 | org.eclipse.cdt.make.core.contents
41 | org.eclipse.cdt.make.core.activeConfigSettings
42 |
43 |
44 | org.eclipse.cdt.make.core.enableAutoBuild
45 | true
46 |
47 |
48 | org.eclipse.cdt.make.core.enableCleanBuild
49 | true
50 |
51 |
52 | org.eclipse.cdt.make.core.enableFullBuild
53 | true
54 |
55 |
56 | org.eclipse.cdt.make.core.fullBuildTarget
57 | all
58 |
59 |
60 | org.eclipse.cdt.make.core.stopOnError
61 | true
62 |
63 |
64 | org.eclipse.cdt.make.core.useDefaultBuildCmd
65 | true
66 |
67 |
68 |
69 |
70 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
71 | full,incremental,
72 |
73 |
74 |
75 |
76 |
77 | com.ti.ccstudio.core.ccsNature
78 | org.eclipse.cdt.core.cnature
79 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
80 | org.eclipse.cdt.core.ccnature
81 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
82 |
83 |
84 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.settings/org.eclipse.cdt.codan.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | inEditor=false
3 | onBuild=false
4 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.settings/org.eclipse.cdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1020810214.340259034/append=true
3 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1020810214.340259034/appendContributed=true
4 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1025076629/append=true
5 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1025076629/appendContributed=true
6 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.settings/org.eclipse.cdt.debug.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker
3 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//BUILD_E_INK_2.0_BATT_FREE/NFC_protocol/subdir_rules.mk=UTF-8
3 | encoding//BUILD_E_INK_2.0_BATT_FREE/NFC_protocol/subdir_vars.mk=UTF-8
4 | encoding//BUILD_E_INK_2.0_BATT_FREE/UserApp/subdir_rules.mk=UTF-8
5 | encoding//BUILD_E_INK_2.0_BATT_FREE/UserApp/subdir_vars.mk=UTF-8
6 | encoding//BUILD_E_INK_2.0_BATT_FREE/common/subdir_rules.mk=UTF-8
7 | encoding//BUILD_E_INK_2.0_BATT_FREE/common/subdir_vars.mk=UTF-8
8 | encoding//BUILD_E_INK_2.0_BATT_FREE/makefile=UTF-8
9 | encoding//BUILD_E_INK_2.0_BATT_FREE/objects.mk=UTF-8
10 | encoding//BUILD_E_INK_2.0_BATT_FREE/sources.mk=UTF-8
11 | encoding//BUILD_E_INK_2.0_BATT_FREE/subdir_rules.mk=UTF-8
12 | encoding//BUILD_E_INK_2.0_BATT_FREE/subdir_vars.mk=UTF-8
13 | encoding//BUILD_E_INK_2.7_BATT/NFC_protocol/subdir_rules.mk=UTF-8
14 | encoding//BUILD_E_INK_2.7_BATT/NFC_protocol/subdir_vars.mk=UTF-8
15 | encoding//BUILD_E_INK_2.7_BATT/UserApp/subdir_rules.mk=UTF-8
16 | encoding//BUILD_E_INK_2.7_BATT/UserApp/subdir_vars.mk=UTF-8
17 | encoding//BUILD_E_INK_2.7_BATT/common/subdir_rules.mk=UTF-8
18 | encoding//BUILD_E_INK_2.7_BATT/common/subdir_vars.mk=UTF-8
19 | encoding//BUILD_E_INK_2.7_BATT/makefile=UTF-8
20 | encoding//BUILD_E_INK_2.7_BATT/objects.mk=UTF-8
21 | encoding//BUILD_E_INK_2.7_BATT/sources.mk=UTF-8
22 | encoding//BUILD_E_INK_2.7_BATT/subdir_rules.mk=UTF-8
23 | encoding//BUILD_E_INK_2.7_BATT/subdir_vars.mk=UTF-8
24 | encoding//Debug/NFC_protocol/subdir_rules.mk=UTF-8
25 | encoding//Debug/NFC_protocol/subdir_vars.mk=UTF-8
26 | encoding//Debug/UserApp/subdir_rules.mk=UTF-8
27 | encoding//Debug/UserApp/subdir_vars.mk=UTF-8
28 | encoding//Debug/common/subdir_rules.mk=UTF-8
29 | encoding//Debug/common/subdir_vars.mk=UTF-8
30 | encoding//Debug/makefile=UTF-8
31 | encoding//Debug/objects.mk=UTF-8
32 | encoding//Debug/sources.mk=UTF-8
33 | encoding//Debug/subdir_rules.mk=UTF-8
34 | encoding//Debug/subdir_vars.mk=UTF-8
35 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/MSP430F5310.ccxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/15693_Protocol.c:
--------------------------------------------------------------------------------
1 | /*
2 | * protocol.c
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy Gummeson, Derek Thrasher
6 | */
7 |
8 | #include "15693_Protocol.h"
9 | //#include "globals.h"
10 |
11 |
12 |
13 | //Derek Thrasher
14 | //mask_length and AFI not currently being used for anything
15 | unsigned char *mask_length;
16 | unsigned char *AFI;
17 | unsigned char mask_value[8];
18 |
19 | //Can do away with both of these and just assign transmitCommand a value straight from receiveCommand...
20 | unsigned char response_flags;
21 | unsigned char DSFID; //Data Storage Format ID
22 |
23 | uint8_t read_command_number;
24 |
25 | uint16_t VICC_state;
26 | uint16_t process_request_flag;
27 |
28 | void initialize_15693_protocol()
29 | {
30 | uid[0] = 0xFE;
31 | uid[1] = 0xDC;
32 | uid[2] = 0xBA;
33 | uid[3] = 0x98;
34 | uid[4] = 0x76;
35 | uid[5] = 0x54;
36 | uid[6] = 0x32;
37 | uid[7] = 0x10;
38 |
39 | VICC_state = 0x0001;
40 | process_request_flag = 0;
41 | read_command_number = 0;
42 | }
43 |
44 | //used by protocol to see if the reader sent command is targeting us
45 | uint16_t uid_is_match(uint16_t start){
46 | uint8_t i;
47 | //start = the first byte position of uid in receiveCommand
48 | for(i=0 ; i<8 ; i++){
49 | if(uid[i] != receiveCommand[i+start]){
50 | //UIDs do NOT match
51 | return 0x0000;
52 | }
53 | }
54 | //UID Match
55 | return 0x0001;
56 | }
57 |
58 | /*Partial implementation of the 15693 Protocol Logic*/
59 | /**
60 | bitCount is the number of valid bits in the receiveCommand array [guaranteed to be >0]
61 | user should update the following:
62 | transmitCommand[] << data to be sent, index 0 is least significant word
63 | numberOfBits << number of bits out of the command array to send (when set to 0:
64 | cyclesToDelay does not need to be set)
65 | cyclesToDelay << number of cycles to delay after the last rising edge of received
66 | data
67 | NOTE: as numberOfBits increases, the amount of time available to the user decreases
68 | worst case: ~25 cycles/bit, best case: ~15 cycles/bit (includes all edges beyond
69 | beyond the start bit)
70 | NOTE: if the user's computation requires more time than the requested delay, data will
71 | not be sent as the reader may or may not acknowledge the command
72 | */
73 | void _15693_protocol(){
74 | // The PICC can be in 4 states
75 | // Power-Off / Ready / Quiet / Selected
76 | //State= 0 / 1 / 2 / 3
77 |
78 | uint8_t i;
79 |
80 | uint8_t index;
81 |
82 | index = 0;//initialize index so it can be used in dynamic responses
83 | numberOfBits = 0;
84 |
85 | if(receiveCommand[1]==0x01)
86 | {
87 | response_flags = 0x00; //no error, no protocol format extension
88 | DSFID = 0x00; //VICC programming not supported
89 | transmitCommand[index++] = response_flags;
90 | transmitCommand[index++] = DSFID;
91 | for(i=0 ; i<8 ; i++){
92 | transmitCommand[index++] = uid[i];
93 | }
94 | numberOfBits = index*8;
95 | }
96 |
97 |
98 | //single block write
99 | else if(receiveCommand[1] == 0x21)
100 | {
101 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3];
102 | cat_2_7_bits[image_byte_counter++] = receiveCommand[4];
103 | cat_2_7_bits[image_byte_counter++] = receiveCommand[5];
104 | cat_2_7_bits[image_byte_counter++] = receiveCommand[6];
105 | response_flags = 0x00; //no error, no protocol format extension
106 | DSFID = 0x00; //VICC programming not supported
107 | transmitCommand[index++] = response_flags;
108 | transmitCommand[index++] = DSFID;
109 | numberOfBits = index*8;
110 | toggle_debug();
111 | }
112 |
113 | else if(receiveCommand[1] == 0x24)
114 | {
115 | int i;
116 | int j = (receiveCommand[2]+1);
117 | j=j*4;
118 | for(i = 0 ; i < j ; i++)
119 | {
120 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3+i];
121 | }
122 | /*
123 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3];
124 | cat_2_7_bits[image_byte_counter++] = receiveCommand[4];
125 | cat_2_7_bits[image_byte_counter++] = receiveCommand[5];
126 | cat_2_7_bits[image_byte_counter++] = receiveCommand[6];
127 | cat_2_7_bits[image_byte_counter++] = receiveCommand[7];
128 | cat_2_7_bits[image_byte_counter++] = receiveCommand[8];
129 | cat_2_7_bits[image_byte_counter++] = receiveCommand[9];
130 | cat_2_7_bits[image_byte_counter++] = receiveCommand[10];
131 | */
132 | response_flags = 0x00; //no error, no protocol format extension
133 | DSFID = 0x00; //VICC programming not supported
134 | transmitCommand[index++] = response_flags;
135 | transmitCommand[index++] = DSFID;
136 | numberOfBits = index*8;
137 | }
138 |
139 |
140 | hw_crc_ccitt(&transmitCommand[0], index);
141 | numberOfBits = numberOfBits + 16;
142 | /*
143 | if(numberOfBits){
144 | if(receiveCommand[1] == 0x01)
145 | {
146 | //generate_crc(transmitCommand, numberOfBits);
147 | transmitCommand[10] = 0x21; //precomputed CRC Byte #2
148 | transmitCommand[11] = 0xBE; //precomputed CRC Byte #2
149 | numberOfBits = numberOfBits +16;
150 | }
151 |
152 | else if((receiveCommand[1] == 0x21) || (receiveCommand[1] == 0x24))
153 | {
154 | transmitCommand[2] = 0x47; //precomputed CRC Byte #2
155 | transmitCommand[3] = 0x0F; //precomputed CRC Byte #2
156 | numberOfBits = numberOfBits +16;
157 | //numberOfBits = 0;
158 | }
159 | }
160 | */
161 | return;
162 | }
163 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/15693_Protocol.h:
--------------------------------------------------------------------------------
1 | /*
2 | * protocol.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy
6 | */
7 |
8 | #ifndef PROTOCOL_H_
9 | #define PROTOCOL_H_
10 |
11 | //globals
12 | #include
13 | #include "msp430f5310.h"
14 | #include "send_hdr.h"
15 | #include "1outof256.h"
16 | #include "crc_checker.h"
17 | #include "../common/globals.h"
18 |
19 |
20 | #ifdef _15693_1of256
21 | #define UID_SIZE 8
22 | #else
23 | #define UID_SIZE 4 //size of PUPI
24 | #endif
25 |
26 | extern uint16_t numberOfBits; //number of bits to transmit
27 | extern unsigned char receiveCommand[RECEIVE_BUF_SIZE]; //received command
28 | extern unsigned char transmitCommand[CMD_BUF_SIZE];
29 | extern unsigned char uid[UID_SIZE];
30 |
31 | extern uint8_t cat_2_7_bits[E_INK_SIZE];
32 | extern uint8_t command_number;
33 | extern uint16_t image_byte_counter;
34 |
35 | //function prototypes
36 | void _15693_protocol(void);
37 | uint16_t uid_is_match(uint16_t);
38 | void initialize_15693_protocol(void);
39 |
40 | #endif /* PROTOCOL_H_ */
41 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/1outof256.h:
--------------------------------------------------------------------------------
1 | /*
2 | * 1outof256.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy
6 | */
7 |
8 | #ifndef ONE_OUT_OF_TWO_FIFTY_SIX_H_
9 | #define ONE_OUT_OF_TWO_FIFTY_SIX_H_
10 |
11 | #include
12 | #include "../common/globals.h"
13 | #include "doNFC.h"
14 |
15 | //receiver state machine constants
16 | #define FINDING_DELIMITER 0
17 | #define PROCESSING_BYTES 1
18 |
19 | //static buffer sizes
20 | #define RECEIVE_BUF_SIZE 40
21 | #define NUM_COMMANDS 15
22 | #define DATA_BUF_SIZE 64
23 |
24 |
25 | //PROTOCOL CONSTANTS
26 | //Protocol timeout. This is equal to 2 1outof256 byte times. If receiving a valid fr ame, the next byte pulse should always arrive before this timeout value.
27 | //Longest valid time is 0x00 followed by 0xff, which is 1 slot shorter than 2 byte times.
28 | //#define TIMEOUT 16386 //more than two byte times worth of timer ticks (2*4.833 ms @ 13.56 MHz / 8).
29 | #define SOF_WIDTH 112 // nominal number of timer ticks for the start of frame delimiter
30 | #define SOF_DELTA 1 //will tolerate this many ticks deviation from nominal value
31 |
32 | #define TICKS_PER_SLOT 32 //There are 32 (13.56/8)MHz clock ticks per bit period
33 | #define TICKS_PER_BYTE (TICKS_PER_SLOT * 256)
34 |
35 | #define SOF_LOW (SOF_WIDTH - SOF_DELTA)
36 | #define SOF_HIGH (SOF_WIDTH + SOF_DELTA)
37 |
38 | #define EOF_SLOT_POSITION 2 //splitting a byte into 512 slots, the EOF will always occupy the 3rd slot (index 2). This should never be true for 0x01 (4th slot)
39 |
40 | //The galaxy nexus sends 0x26 as the first byte containing flags.
41 | //There might be more definitions here for different readers
42 | #define NEXUS_FLAGS 0x26
43 |
44 | //Change this guy to a particular reader
45 | #define FLAGS NEXUS_FLAGS
46 |
47 | //minimum length of a 15693 message (including CRC)
48 | #define MIN_VALID_LENGTH 5
49 |
50 | //from main.c and other header file
51 | //extern uint8_t num_frame_bytes;
52 | extern uint8_t pending_captures;
53 | extern unsigned int numReceivedMessages;
54 | extern unsigned char receiveCommand[RECEIVE_BUF_SIZE]; //received command
55 |
56 | void initialize_1outof256(void);
57 |
58 | //this function processes outstanding 1 out of 256 pulses.
59 | void process_bits(void);
60 |
61 |
62 | #endif /* 1OUTOF256_H_ */
63 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/_14443_B.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * 14443_B.c
3 | *
4 | * @date May 31, 2013
5 | * @author Derek Thrasher (UMass Amherst)
6 | ******************************************************************************/
7 |
8 | #include "_14443_B.h"
9 |
10 | uint8_t validRx=0;
11 |
12 | //************************************************************************************************************
13 | /* @func if detect delimiter within Five ETU(5*9.3us) then decode data otherwise wake up
14 | * @note doNFC_state=1 is set in sleep_untill_read
15 | *************************************************************************************************************/
16 | unsigned short doNFC_Rx(void){
17 | //----//
18 | // TODO Are we intending to clear particular other bits in RX_IE and RX_IES?
19 | // !!!-Comm's doesn't work when we DON'T clear the other bits... why not?
20 | // RX comparator on
21 | Enable_Rx();
22 | //toggle_led_2();
23 | validRx = 0;//reset in RX_WAKEUP ISR
24 | delay_us(T_35us); //let RX comparator stable, because sometimes there is a noise when enable rx comparator
25 | doNFC_state = NFC_Rx0; //Flag is Rx,used for measure the EOF
26 | RX_IE |= RX_BIT;
27 | //toggle_led_1();
28 | /*test delimiter, if find set the timeout and wait for rx data*/
29 | TA0CCR0 = FIVE_PULSES;//timeout should larger than 22.2us
30 | TA0CCTL0 = CCIE;
31 | TA0CTL = TASSEL_2 + MC_2+ ID_3 + TACLR; // time the delimiter length and then used for send_bpsk
32 | __bis_SR_register(LPM3_bits | GIE);
33 | TA0CTL = 0;
34 | Disable_Rx();
35 | TA0CCTL0 = 0; //Disable CCIE and TA0CCR0
36 |
37 | //toggle_led_1();
38 | //doNFC_state = 0;
39 | return validRx;
40 | }
41 |
42 |
43 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/_14443_B.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************
2 | * _14443_B.h
3 | *
4 | * @date May 31, 2013
5 | * @author Eve(Yi Zhao), Sensor Systems Lab, UW
6 | * Derek Thrasher
7 | **************************************************************************************/
8 | #ifndef _B_H
9 | #define _B_H
10 |
11 |
12 | //=======================================================================================
13 | // Includes
14 | //=======================================================================================
15 | #include "../common/globals.h"
16 |
17 | //for 6.78Mhz clock
18 | #ifdef _15693_1of256
19 | #define TIME_OUT 90
20 | #else
21 | #define TIME_OUT 196
22 | #endif
23 |
24 |
25 | //for NFC_rev1.0, the SOF is 45us
26 | //#define SOF 115
27 | //#define Dt 8 //10/time tolerance +/-
28 | #define Dt 10 //10/time tolerance +/-
29 | #define zDt 8 //extra tolerance for zero
30 | #define ErrDt 15 //Dt+Dt/2
31 | #define SOB 11 //start bit
32 | #define ONE_PULSES 13 //7.6us~11.2us 16-/+3
33 | #define TWO_PULSES 29 //17.1~20.6us 32-/+3
34 | #define THREE_PULSES 45 //26.54~30.08us 48-/+3
35 | #define FOUR_PULSES 61 //35.98~39.08us 64-/+3
36 | #define FIVE_PULSES 77 //45.42~48.9us 80-/+3
37 | #define SIX_PULSES 93 //54.86~58.4us 96-/+3
38 | #define SEVEN_PULSES 109 //64.3~67.8.9us 112-/+3
39 | #define EIGHT_PULSES 125 //73.7~77.2us 128-/+3
40 | #define NINE_PULSES 141 //83.1~86.7us 144-/+3
41 | #define TEN_PULSES 157 //92.6~96.16us 160-/+3
42 | #define ELEVEN_PULSES 173 //102.0~105.6us 176-/+3
43 | #define SOF 19 //@note: from 22 to 8 at leaset 18us should change depending differenct range
44 | #define TIMEOUT ELEVEN_PULSES
45 | #define EOF 175
46 | //#define SOF 180;
47 |
48 | //=======================================================================================
49 | // Micros
50 | //=======================================================================================
51 | #define Enable_Rx() \
52 | RX_ENABLE_OUT |= RX_ENABLE_BIT; \
53 | RX_ENABLE_DIR |= RX_ENABLE_BIT; \
54 | RX_IES &= ~RX_BIT; //detect rising edge
55 |
56 | #define Disable_Rx() \
57 | RX_ENABLE_DIR &= ~RX_ENABLE_BIT; \
58 | RX_IE &= ~RX_BIT; \
59 | RX_IFG &= ~RX_BIT;
60 | //RX_ENABLE_DIR &= ~RX_ENABLE_BIT; \
61 | //RX_ENABLE_OUT &= ~RX_ENABLE_BIT; \
62 |
63 | //=======================================================================================
64 | // External variable
65 | //=======================================================================================
66 | //extern uint8_t _14443_buf_ptr = 0;
67 | extern uint8_t validRx;
68 | extern uint8_t rx_buffer[CMD_BUF_SIZE];
69 | extern uint8_t _14443_buf_ptr;
70 | extern uint8_t volatile doNFC_state;
71 |
72 | //=======================================================================================
73 | // External functions
74 | //=======================================================================================
75 | unsigned short doNFC_Rx(void);
76 |
77 |
78 | #endif /* 14443_B_H_ */
79 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/_14443_B_protocol.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wisp/nfc-wisp-fw/d8a9c55edbdaff62484961dc6eac6d66843e4d02/ccs/nfc-eink-img-update-demo/NFC_protocol/_14443_B_protocol.c
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/_14443_B_protocol.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * _14443_B_protocol.h
3 | *
4 | * @date April 5, 2014
5 | * @author Eve(Yi Zhao), Sensor Systems Lab, UW
6 | * Derek Thrasher
7 | ******************************************************************************/
8 |
9 | #ifndef _14443_B_PROTOCOL_H_
10 | #define _14443_B_PROTOCOL_H_
11 |
12 | //globals
13 | #include "_14443_B.h"
14 | #include
15 |
16 | #define CID_Enable BIT0
17 | #define CID_Disable 0
18 |
19 | extern unsigned int numberOfBitsTX; //number of bits to transmit
20 | extern uint8_t uid[UID_SIZE];
21 | extern uint8_t _14443_buf_ptr;
22 | extern uint8_t rx_buffer[CMD_BUF_SIZE];
23 | extern uint8_t transmitCommand[CMD_BUF_SIZE];
24 |
25 | //extern unsigned char imageBuffer[E_INK_SIZE];
26 | //extern unsigned char imageBuffer[2];
27 | extern unsigned char command_number;
28 | extern unsigned int imageBytesReceived;
29 |
30 | //function prototypes
31 | void initialize_14443_B_protocol(void);
32 | uint8_t _14443_B_protocol(uint8_t numb_bytes);
33 | uint8_t uid_is_match(unsigned int);
34 | unsigned int add_pupi(unsigned int start);
35 | void toggle_block_number(void);
36 | #endif /* PROTOCOL_H_ */
37 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/crc_checker.c:
--------------------------------------------------------------------------------
1 | /*
2 | * crc_checker.c
3 | *
4 | * Created on: Jan 8, 2013
5 | * Author: Derek Thrasher (UMass Amherst)
6 | */
7 |
8 | #include
9 | #include
10 | #include "crc_checker.h"
11 |
12 | #define POLYNOMIAL 0x8408 // x^16 + x^12 + x^5 + 1
13 | #define PRESET_VALUE 0xFFFF
14 | #define CHECK_VALUE 0xF0B8
15 | //#define NUMBER_OF_BYTES 4 // Example: 4 data bytes
16 | //#define CALC_CRC 1
17 | //#define CHECK_CRC 0
18 |
19 |
20 |
21 | /*
22 | //returns 1 is data is correct
23 | uint8_t validate_crc(unsigned char* receive_array, uint8_t number_of_bytes){
24 | unsigned int current_crc_value = PRESET_VALUE;
25 | int i, j;
26 | for (i = 0; i < number_of_bytes; i++){
27 | current_crc_value = current_crc_value ^ ((unsigned int)receive_array[i]);
28 | for (j = 0; j < 8; j++){
29 | if (current_crc_value & 0x0001){
30 | current_crc_value = (current_crc_value >> 1) ^ POLYNOMIAL;
31 | }
32 | else{
33 | current_crc_value = (current_crc_value >> 1);
34 | }
35 | }
36 | }
37 |
38 | if (current_crc_value == CHECK_VALUE){
39 | //printf ("Checked CRC is ok (0x%04X)\n", current_crc_value);
40 | return (number_of_bytes - 0x02);
41 | }else{
42 | //printf ("Checked CRC is NOT ok (0x%04X)\n", current_crc_value);
43 | return 0x00;
44 | }
45 | }
46 |
47 | unsigned int generate_crc(unsigned char* transmitCommand, uint16_t numberOfBits){
48 | unsigned int current_crc_value = PRESET_VALUE;
49 | int i, j;
50 | unsigned char number_of_bytes = numberOfBits/8;
51 | numberOfBits = numberOfBits + 16;
52 | for (i = 0; i < number_of_bytes; i++){
53 | current_crc_value = current_crc_value ^ ((unsigned int)transmitCommand[i]);
54 | for (j = 0; j < 8; j++){
55 | if (current_crc_value & 0x0001){
56 | current_crc_value = (current_crc_value >> 1) ^ POLYNOMIAL;
57 | }
58 | else{
59 | current_crc_value = (current_crc_value >> 1);
60 | }
61 | }
62 | }
63 | current_crc_value = ~current_crc_value;
64 | transmitCommand[number_of_bytes] = current_crc_value & 0xFF;
65 | transmitCommand[number_of_bytes + 1] = (current_crc_value & 0xFF00)>>8;
66 | return 1;
67 | }
68 | */
69 |
70 |
71 | /**
72 | * Use the hardware CRC-CCITT module of the MSP430 to generate a CRC as
73 | * per ISO/IEC 13239 CRC16 specification used in ISO 15693. Generating
74 | * polynomial is 0x8408, preset value is 0xFFFF.
75 | *
76 | * CRC is appended to end of transmitCommand array.
77 | *
78 | * @author Aaron Parks
79 | */
80 | unsigned int hw_crc_ccitt(unsigned char* transmitCommand, unsigned int number_of_bytes) {
81 | // Preset CRC result as per ISO/IEC 13239
82 | CRCINIRES = 0xFFFF;
83 |
84 | // Iterate over transmitCommand array
85 | unsigned int crc_i;
86 | for(crc_i=0; crc_i
12 | unsigned char validate_crc(unsigned char* receive_array, unsigned char number_of_bytes);
13 | unsigned int generate_crc(unsigned char* transmitCommand, unsigned int numberOfBits);
14 | unsigned int hw_crc_ccitt(unsigned char* transmitCommand, unsigned int numberOfBits);
15 | unsigned int hw_crc_validate(unsigned char* receiveCommand, unsigned int numberOfBits);
16 |
17 | #endif /* CRC_CHECKER_H_ */
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/doNFC.h:
--------------------------------------------------------------------------------
1 | /*
2 | * doNFC.h
3 | *
4 | * Created on: Aug 22, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef DONFC_H_
9 | #define DONFC_H_
10 |
11 | //=======================================================================================
12 | // Includes
13 | //=======================================================================================
14 | //#include
15 | #include "../common/globals.h"
16 | #include "../UserApp/myApp.h"
17 | // TODO Get rid of ifdefs if possible
18 | #ifdef _15693_1of256
19 | #include "1outof256.h"
20 | #include "send_hdr.h"
21 | #include "15693_Protocol.h"
22 | #else
23 | #include "_14443_B_protocol.h"
24 | //#include "NFC_WISP_Protocol.h"
25 | //#include "send_bpsk.h"
26 | //#include "crc_checker.h"
27 | //include "_14443_B.h"
28 | #endif
29 |
30 | //=============================================================================
31 | // NFC Globals
32 | //=============================================================================
33 |
34 | //This stuff is totally global in nature. I'm not sure it belongs here. But here it is.
35 | //After the CRC is verified, this gets set to the number of bytes we received.
36 | extern uint8_t num_frame_bytes;
37 | extern uint8_t volatile doNFC_state;
38 | // TODO Get rid of ifdefs if possible
39 | #ifdef _15693_1of256
40 |
41 | extern uint8_t transmitCommand[CMD_BUF_SIZE];
42 |
43 | extern uint8_t uid[UID_SIZE]; /**< Byte array that stores the UID. Initialized by _15693_protocol.c. */
44 | extern unsigned int numReceivedMessages; /**< Number of messages received from a reader. Used to track image transfer progress. */
45 | extern uint8_t pending_captures; /**< Tracks pending captures for ISO_15693. This is the number of outstanding pulses to be processed. */
46 | extern unsigned int numberOfBitsTX; /**< Number of bits to transmit. Transmit function uses this to know how much of the buffer to send. */
47 | //unsigned int bit_count; //used which checking crc
48 |
49 | //externs
50 | extern unsigned int capture_buffer[CAPTURE_BUFFER_SIZE];
51 | extern uint8_t capture_buffer_write_index;
52 |
53 | extern uint8_t receiveCommand[RECEIVE_BUF_SIZE];//received command
54 | #else // otherwise assume 14443_B
55 | extern uint8_t _14443_buf_ptr; /**< 14443_rx buffer pointer. Points to the current buffer index of received buffer. */
56 | extern uint8_t rx_buffer[CMD_BUF_SIZE]; /**< 14443_B RX message buffer. Stores CMD_BUF_SIZE bytes. */
57 | extern uint8_t transmitCommand[CMD_BUF_SIZE]; /**< 14443_B TX message buffer. Stores CMD_BUF_SIZE bytes. */
58 | //extern uint8_t doNFC_state;
59 | extern uint8_t uid[UID_SIZE]; /**< Byte array that stores the PUPI. Initialized by _14443_B_protocol.c. */
60 |
61 | extern unsigned int numberOfBitsTX; /**< Number of bits to transmit. Transmit function uses this to know how much of the buffer to send. */
62 | #endif /* _15693_1of256 */
63 | //=============================================================================
64 | // Macros
65 | //=============================================================================
66 | // Setup interrupt on edges
67 | // 1 Falling edge wakeup, but it is actually rising edge for RX_WAKE_UP pin
68 | // 2 Enable interrupt
69 | #define enable_Rx_Wakeup() \
70 | RX_WAKEUP_EN_OUT |= RX_WAKEUP_EN_BIT; \
71 | RX_WAKEUP_EN_DIR |= RX_WAKEUP_EN_BIT; \
72 | lowPowerSleep(4); \
73 | RX_WAKEUP_IES &= ~RX_WAKEUP_BIT; \
74 | RX_WAKEUP_DIR &=~ RX_WAKEUP_BIT; \
75 | RX_WAKEUP_IFG = 0; \
76 | RX_WAKEUP_IE = RX_WAKEUP_BIT;
77 |
78 | // Disable Rx Wakeup and may start RX
79 | #define disable_Rx_Wakeup() \
80 | RX_WAKEUP_IE &= ~RX_WAKEUP_BIT; \
81 | RX_WAKEUP_EN_DIR &= ~RX_WAKEUP_EN_BIT; \
82 | RX_WAKEUP_IFG &= ~(RX_WAKEUP_BIT);
83 |
84 | #define Sleep_TimeOut 2000//2000*0.25ms = 0.5s
85 | #define tempSense_TimeOut 0xF000 //1s is 0x1000 15s is 0xF000
86 | //==============================================================================
87 | // Functions
88 | //==============================================================================
89 | void initRFID(void);
90 | //void doRFID_15693(void);
91 | //void doRFID_14443B(void);
92 | //void sleep_until_edges(void);
93 | //void sleep_until_read(void);
94 | void doNFC(void);
95 | #endif /* DONFC_H_ */
96 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/send_bpsk.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * send_bpsk.h
3 | *
4 | * @date June 5, 2013
5 | * @author Derek Thrasher (UMass Amherst)
6 | ******************************************************************************/
7 |
8 | #ifndef SEND_BPSK_H_
9 | #define SEND_BPSK_H_
10 |
11 | #include "../common/globals.h"
12 | //#include "../common/NFC_WISP_Rev1.0.h"
13 |
14 | //6.78Mhz where 1etu = 8clock pulses
15 | // TODO Get rid of ifdefs if possible
16 | #ifdef _6_78Mhz
17 | #define ONE_ETU 8
18 | #define TWO_ETU 16
19 | #define TEN_ETU 80
20 | #else
21 | #define ONE_ETU 16
22 | #define TWO_ETU 32
23 | #define TWO_ETU_SLEEP 22
24 | #define TEN_ETU 160//160
25 | #define TEN_ETU_SLEEP 150
26 | #endif
27 | //assembly constants used for send routine
28 | asm("SEND_BIT_MASK .set R6");
29 | asm("SEND_COMMAND .set R7");
30 | //asm("SEND_BIT_SIZE .set R6");
31 | asm("SEND_CURRENT_WORD .set R8");
32 | asm("SEND_BIT .set R12");
33 | //asm("SEND_BIT_COUNT .set R8");
34 |
35 | asm("TBCTL_ADR .set 0180h"); //timer control address
36 | asm("ASM_MC_1 .set 0010h"); //continuous mode bits
37 |
38 | //=============================================================================
39 | // Macros
40 | //=============================================================================
41 | //TB0CCR0 = 8; //upper bound compare
42 | //TB0CCR2 = 0; //lower bound compare
43 | //ensures that we will get a rising edge imediately
44 | #define ENABLE_PWM() \
45 | TB0R = 7; \
46 | TB0CCTL2 = OUTMOD_3; \
47 | TB0CTL = TBSSEL_2+MC_3; //SMCLK 13.56Mhz,pwm up/down mode
48 |
49 |
50 | #define DISABLE_PWM() TB0CTL = 0; //disable
51 |
52 |
53 | //********************************************************************************
54 | // Protocol Constants
55 | //********************************************************************************
56 | // TODO Get rid of ifdefs if possible
57 | #ifdef _6_78Mhz
58 | #define POST_RX_WAIT 64 //75.56 us@ 6.78 MHz / 8
59 | #else//13.56Mhz
60 | #define POST_RX_WAIT 128//128 //75.56 us@ 13.56 MHz / 8
61 | #endif
62 |
63 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
64 | void initialize_bpsk(void);
65 | void send_bpsk(void);
66 | void delay(uint16_t);
67 | void shift_mask();
68 | uint8_t next_bit();
69 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
70 | #endif /* SEND_LDR_H_ */
71 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/send_hdr.c:
--------------------------------------------------------------------------------
1 | /*
2 | * send_hdr.c
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy Gummeson
6 | */
7 |
8 | /*
9 | send a command [start bit and stop bit inserted automatically]
10 | command is an array containing the bits to be sent
11 | command size is the number of bits in the given command to send
12 | command array: R12 (ARG_1), bit size: R13 (ARG_2)
13 | NOTE: must call 8 cycles prior to first bit (7 starts timer, 8 to get high on PWM)
14 | */
15 |
16 | #include "send_hdr.h"
17 |
18 | unsigned char transmitCommand[CMD_BUF_SIZE];
19 | uint16_t numberOfBits; //number of bits to transmit
20 |
21 | void initialize_hdr(void)
22 | {
23 |
24 | //configure timer output pin
25 |
26 | TB0CTL = TBSSEL_2;
27 | TB0CCTL1 = OUTMOD_3; // sets at TBCCR1 / resets at TBCCR0 (SEE BELOW)
28 |
29 | TB0CCR0 = 16; //upper bound compare
30 | TB0CCR1 = 0; //lower bound compare
31 |
32 | //This set of register writes configures Pin4.7 output to Timer B CCR1 output
33 | //I based these settings on the TI sample code. It works
34 | PMAPPWD = 0x02D52; // Enable Write-access to modify port mapping registers
35 | PMAPCTL = PMAPRECFG; // Allow reconfiguration during runtime
36 | //disables output driver
37 | P4MAP7 = PM_ANALOG;
38 | P4MAP7 = PM_TB0CCR1A; //Need to remap 4.7 pin to PWM Output (need to double check this)
39 | //PMAPPWD = 0; // Disable Write-Access to modify port mapping registers
40 | PMAPPWD = 0x096A5;
41 | P4DIR |= PWM_PIN; //output direction
42 | P4SEL |= PWM_PIN; //PWM mode
43 | }
44 |
45 | void delay(uint16_t cycles)
46 | {
47 | int i = 0;
48 | for(i = 0; i < cycles; i++)
49 | asm(" nop");
50 | }
51 |
52 | void send(void)
53 | {
54 | TB0CCTL1 = OUTMOD_3;
55 | //reset bit mask and bit count
56 | asm(" MOV #0001h, SEND_BIT_MASK"); //1
57 | //move number of bits into SEND_BIT_SIZE register
58 | asm(" MOV &numberOfBits, SEND_BIT_SIZE");
59 | // Clear SEND_BIT_COUNT
60 | asm(" CLR SEND_BIT_COUNT"); //1
61 | //Store transmitCommand adr into SEND_COMMAND
62 | asm(" MOV #transmitCommand, SEND_COMMAND");
63 | //send start bit
64 | while(TA0R < (LONG_TX + POST_RX_WAIT)); //will get rid of magic number eventually.
65 | ENABLE_PWM() //on for 225us
66 | TA0R = 0;
67 |
68 | while(TA0R < LONG_TX);
69 | DISABLE_PWM()
70 | TA0R = 0;
71 | //on for 75us
72 | while(TA0R < HALF_TX_PERIOD);
73 | ENABLE_PWM()
74 | TA0R = 0;
75 |
76 | asm("SEND_BEGIN:");
77 | //SAVE START TIME - Derek Thrasher - This will be used when CRC is implemented in between ENABLE and DISABLE of PWM
78 | //Will implement a dynamic delay instead of the static ones that are currently implemented.
79 |
80 |
81 | //check that bits remain and increment if true
82 | asm(" CMP SEND_BIT_COUNT, SEND_BIT_SIZE"); //1
83 | asm(" JEQ SEND_END"); //2
84 | asm(" INC SEND_BIT_COUNT"); //1
85 |
86 | //read command
87 | //Derek Thrasher - Better to have this occur every time even though the data is SEND_CURRENT_WORD is only being updated every 8 iterations
88 | //Derek Thrasher - Keeps the timing consistent
89 | asm(" MOV @SEND_COMMAND, SEND_CURRENT_WORD"); //2
90 |
91 | //get current bit from current word
92 | asm(" BIT SEND_BIT_MASK, SEND_CURRENT_WORD"); //1
93 | asm(" JC SEND_LOGIC_ONE"); //2
94 |
95 | //TAKES 5 CYCLES TO GET HERE FROM SEND_BEGIN:
96 | //logic zero
97 | while(TA0R < HALF_TX_PERIOD);
98 | ENABLE_PWM()
99 | TA0R = 0;
100 | //on for 75us
101 | //shift mask
102 | asm(" RLA SEND_BIT_MASK"); //1
103 | //increase address/reset bit mask if needed
104 | asm(" CMP #0, SEND_BIT_MASK"); //1
105 | asm(" JEQ SEND_DELAY_RESET_A"); //2
106 | asm(" JMP SEND_DELAY_RESET_POST_A"); //2
107 | //otherwise shift mask and continue
108 | asm("SEND_DELAY_RESET_A:");
109 | asm(" MOV #0001h, SEND_BIT_MASK"); //1
110 | asm(" ADD #2, SEND_COMMAND"); //1
111 | asm("SEND_DELAY_RESET_POST_A:");
112 |
113 | //enable pwm
114 | while(TA0R < HALF_TX_PERIOD);
115 | DISABLE_PWM()
116 | TA0R = 0;
117 | //off for 75us
118 | //repeat
119 | asm(" JMP SEND_BEGIN"); //2
120 |
121 | //logic one
122 | asm("SEND_LOGIC_ONE:");
123 | //TAKES 7 CYCLES TO GET HERE FROM SEND_BEGIN:
124 | while(TA0R < HALF_TX_PERIOD);
125 | DISABLE_PWM()
126 | TA0R = 0;
127 | //off for 75us
128 |
129 | //shift mask
130 | asm(" RLA SEND_BIT_MASK"); //1
131 |
132 | //increase address/reset bit mask if needed
133 | asm(" CMP #0, SEND_BIT_MASK"); //1
134 | asm(" JEQ SEND_DELAY_RESET_B"); //2
135 | asm(" JMP SEND_DELAY_RESET_POST_B"); //2
136 |
137 | //otherwise shift mask and continue
138 | asm("SEND_DELAY_RESET_B:");
139 | asm(" MOV #0001h, SEND_BIT_MASK"); //1
140 | asm(" ADD #2, SEND_COMMAND"); //1
141 | asm("SEND_DELAY_RESET_POST_B:");
142 |
143 | while(TA0R < HALF_TX_PERIOD);
144 | ENABLE_PWM()
145 | TA0R = 0;
146 | //on for 75us
147 |
148 | //repeat
149 | asm(" JMP SEND_BEGIN"); //2
150 |
151 | //send stop bit
152 | asm("SEND_END:");
153 | //send eof bitS
154 | while(TA0R < HALF_TX_PERIOD);
155 | ENABLE_PWM()
156 | TA0R = 0;
157 | //on for 75us
158 |
159 | while(TA0R < HALF_TX_PERIOD);
160 | DISABLE_PWM()
161 | TA0R = 0;
162 | //off for 75us
163 |
164 | while(TA0R < HALF_TX_PERIOD);
165 | ENABLE_PWM()
166 | TA0R = 0;
167 | //on for 263us
168 |
169 |
170 | while(TA0R < LONG_TX);
171 | DISABLE_PWM()
172 | TA0R = 0;
173 |
174 |
175 | P4OUT &= ~PWM_PIN;
176 | TB0CCTL1 = OUTMOD_0;
177 | //reset the comparator to get ready to receive the next frame.
178 | /*PJOUT &= ~RX_EN_PIN;
179 | TA0R = 0;
180 | while(TA0R < 60000);
181 | PJOUT |= RX_EN_PIN;*/
182 |
183 | return;
184 | }
185 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/NFC_protocol/send_hdr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * send_hdr.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy Gummeson
6 | */
7 |
8 | #ifndef SEND_LDR_H_
9 | #define SEND_LDR_H_
10 |
11 | #include "../common/globals.h"
12 |
13 |
14 |
15 | //assembly constants used for send routine
16 | asm("SEND_BIT_MASK .set R4");
17 | asm("SEND_COMMAND .set R5");
18 | asm("SEND_BIT_SIZE .set R6");
19 | asm("SEND_CURRENT_WORD .set R7");
20 | asm("SEND_BIT_COUNT .set R8");
21 |
22 | asm("TBCTL_ADR .set 0180h"); //timer control address
23 | asm("ASM_MC_1 .set 0010h"); //continuous mode bits
24 |
25 | //=============================================================================
26 | // Macros
27 | //=============================================================================
28 | #define ENABLE_PWM() TB0CTL |= MC_3;//asm(" BIS #ASM_MC_1, &TBCTL_ADR"); //asm(" BIS #0040h, &0186h"); asm(" NOP");//enable pwm
29 | #define DISABLE_PWM() TB0CTL &= ~MC_3;//asm(" BIC #ASM_MC_1, &TBCTL_ADR"); //asm(" BIS #0040h, &0186h");//asm(" MOV &TBR_ADR, R8"); //code does not work
30 |
31 |
32 | //********************************************************************************
33 | // Protocol Constants
34 | //********************************************************************************
35 | #define POST_RX_WAIT 510 //300 us@ 13.56 MHz / 8
36 | #define LONG_TX 96 //56.64 us @ 13.56 MHz / 8
37 | #define HALF_TX_PERIOD 31 //18.88 us @ 13.56 MHz / 8
38 |
39 | void initialize_hdr(void);
40 | void send(void);
41 | //void delay(uint16_t);
42 |
43 | #endif /* SEND_LDR_H_ */
44 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/myApp.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @fun Demo for Temperature/Acceleration display&logging
3 | * @author Yi Zhao(Eve)
4 | * @date -09/29/2014
5 | *****************************************************************************/
6 |
7 | //=============================================================================
8 | // Includes
9 | //=============================================================================
10 | #include "../common/globals.h"
11 | #include "../common/e-paper.h"
12 | #include "myE-paperApp.h"
13 | #include "tempSense.h"
14 | #include "img_data.h"
15 | #include "../common/accel.h"
16 | #include "myApp.h"
17 | #include
18 |
19 | //=============================================================================
20 | // E-paper Globals
21 | //=============================================================================
22 | //@note the imageBuffer now is 1 byte since we need more buffer for sense_buf
23 | //uint8_t imageBuffer[E_INK_SIZE]; // big array that stores all the display bits
24 | uint8_t sense_buf[BUF_SIZE];
25 | uint8_t* sense_buf_ptr;
26 | uint8_t* sense_read_ptr;
27 | uint8_t buf_full;
28 | uint16_t senseCtr;
29 | //=============================================================================
30 | // Globals
31 | //=============================================================================
32 | volatile unsigned long RTC_ctr;//real time clcok counter
33 | //uint8_t imageUpdateState;
34 | volatile uint8_t senseState;
35 | volatile uint8_t accelState;
36 |
37 |
38 | //=============================================================================
39 | // User App & Functions
40 | //=============================================================================
41 |
42 | /**
43 | * @fun initial real time clock for sampling temperature/accelerometer data
44 | * for temerature/accelerometer logger demo
45 | */
46 | void initMyDemo1(void){
47 |
48 | //Initialize the real time clock for sample sensor at given intervals
49 | initRTC(RTC_3s);
50 |
51 | //Initial sensing state machine
52 | imageUpdateState = IMG_UPDATE;
53 | //imageUpdateState = IMG_HALT;
54 |
55 | //inital senseng state and senseng data buffer
56 | accelState = 0;
57 | senseCtr=0;
58 | buf_full=0;
59 | sense_buf_ptr = &sense_buf[0];
60 | sense_read_ptr = &sense_buf[0];
61 | }
62 |
63 |
64 | /**
65 | * @fun initial imageUpdateState for image updates demo
66 | */
67 | void initMyDemo2(void){
68 | //TA1CTL = 0; //ACLK, upmode, 4khz clk
69 | //TA1CCTL0 &=~CCIE;
70 | //initRTC(RTC_15s);
71 | imageUpdateState = IMG_HALT;
72 | }
73 |
74 |
75 |
76 |
77 | /**
78 | * @fun temerature/accelerator logger and display demo
79 | * will not save sensor data into the buffer
80 | */
81 | void Demo1(void) {
82 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState)){
83 | updateDisplay1((uint8_t*)templete);
84 | imageUpdateState = IMG_HALT;
85 | }
86 | }
87 |
88 | /**
89 | * @fun image updates demo when response to cellphone
90 | * if it receive the whole image and update it
91 | * @note NFC-WISP Reader App 1.0 will sending dummy data for power
92 | * after finishing image transfer.
93 | * If you build *BUILD_E_INK_2_0_BATT_FREE*
94 | * we add more lowPowerSleep during E-ink updating to
95 | * reive more energy from cell-phone
96 | */
97 | void Demo2(void){
98 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState==IMG_UPDATE)||(imageUpdateState==IMG_FORCE_UPDATE)){
99 | //memset(imageBuffer,0,E_INK_SIZE);//Comment this line to save power
100 | #ifdef BATT_FREE
101 | lowPowerSleep(LPM_120ms);
102 | #endif
103 | updateDisplay2((uint8_t*)imageBuffer);
104 | #ifdef BATT_FREE
105 | lowPowerSleep(LPM_10ms);
106 | #endif
107 | imageUpdateState = IMG_HALT;
108 | }
109 | }
110 |
111 | /**
112 | * @fun temperature/acceleration data logger demo
113 | * save the sensor data to the buffer for reader to read
114 | * @note need to change sense_buf size for your application
115 | */
116 | void Demo3(void) {
117 |
118 | /****************Sensing handle routine 1 *********************************
119 | * @fun log sensor result to buffer when reading sensor result
120 | * put 4 byte accelerometer data into app[0]-[3]
121 | * put 4 byte temperature data into uid[0]-[3]
122 | * if write is full than sense_read_ptr then stop write
123 | * @note when use this demo, must modify the command response to transmit
124 | * sensor result to the uid or app buffer
125 | ***********************************************************************/
126 |
127 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState)){
128 |
129 | //if sense_buf will be out of the range of queue
130 | if((sense_buf_ptr+8)>(&sense_buf[BUF_SIZE-1])){
131 | memset(sense_buf,0x00,&sense_buf[BUF_SIZE-1]-sense_buf_ptr+1);
132 | sense_buf_ptr=&sense_buf[0];
133 | buf_full++;
134 | }
135 |
136 | //if the queue is full, then do nothing
137 | if((sense_buf_ptr+8>sense_read_ptr)&&(buf_full>0)){
138 | asm("NOP");
139 | }else if(imageUpdateState){
140 | updateDisplay1((uint8_t*)templete);
141 | ACCEL_singleSample(sense_buf_ptr);
142 | sense_buf_ptr +=4;
143 | senseCtr++;
144 | }
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/myApp.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | ** myApp.h
3 | * @fun Demo for Temperature/Acceleration display&logging
4 | * @author Yi Zhao(Eve), Sensor System Lab,UW and Disney Research Pittsburgh
5 | * @date -09/29/2014
6 | *****************************************************************************/
7 | #ifndef MYAPP_H_
8 | #define MYAPP_H_
9 |
10 | //=============================================================================
11 | // Define
12 | //=============================================================================
13 | //Buffer if needed for data logger
14 | #define BUF_SIZE 2//2600//4000
15 |
16 | //=============================================================================
17 | // Micros
18 | //=============================================================================
19 | // We must disable sensor ISR in NFC rx&tx routine
20 | #warning "Must disable sensor interrupt here for different Usesr App\
21 | otherwise there is a conflict with NFC reading ISR"
22 | //implement "enable or disable custermized ISR" for UserApp
23 | #define disable_sensor_ISR() \
24 | TA1CCTL0 = 0;
25 | //ACCEL_INT1_IE &= ~ACCEL_INT1_BIT;
26 |
27 | #define enable_sensor_ISR() \
28 | TA1CCTL0 |= CCIE;
29 | //ACCEL_INT1_IE |= ACCEL_INT1_BIT;
30 |
31 |
32 | //=============================================================================
33 | // myApp Globals
34 | //=============================================================================
35 | extern uint8_t volatile doNFC_state;
36 | extern volatile unsigned long RTC_ctr;
37 | extern uint8_t volatile imageUpdateState;
38 | extern volatile uint8_t senseState;
39 | extern volatile uint8_t accelState;
40 | extern uint8_t sense_buf[BUF_SIZE];
41 | extern uint8_t* sense_buf_ptr;
42 | extern uint8_t* sense_read_ptr;
43 | extern uint8_t buf_full;
44 | extern uint16_t senseCtr;
45 | //extern const char[5808] templete;
46 |
47 | //=============================================================================
48 | // Function
49 | //=============================================================================
50 | void initMyDemo1(void);
51 | void initMyDemo2(void);
52 | void Demo1(void);
53 | void Demo2(void);
54 | void Demo3(void);
55 |
56 |
57 | #endif /* MYAPP_H_ */
58 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/myE-paperApp.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file myE-paperApp.c
3 | *
4 | * @brief Demo of customized E-paper update
5 | *
6 | * @details Use the E-paper driver in common/e-paper.h to determine how to
7 | * update the display line by line.
8 | *
9 | * @note More details about driver reference can be found
10 | * http://www.pervasivedisplays.com/products/27
11 | *
12 | * @author Eve (Yi Zhao) - Sensor Systems Lab (UW)
13 | * @date 09/29/2014
14 | *****************************************************************************/
15 | #include "../common/e-paper.h"
16 | #include "tempSense.h"
17 | #include "../common/globals.h"
18 | #include "../common/accel.h"
19 | #include "myE-paperApp.h"
20 |
21 | /**
22 | * @brief Update EPD display from image templete and display real time sensor data
23 | * @param imgPtr - the pointer pointed to the entry of image templete
24 | * @time EPD powerOn&Off takes around 325ms
25 | */
26 | uint8_t updateDisplay1(unsigned char* imagePtr){
27 |
28 | volatile resultData newData;
29 |
30 | //Sample temperature
31 | newData = tempSense();
32 |
33 | //Sample Accelerometer
34 | uint8_t st,value,indicator;
35 |
36 | ACCEL_Status(&st);
37 | if(((st&0xF0)==0x40)){
38 | value=0x00;
39 | indicator =4; //update motion indicator
40 | }else {
41 | value = 0xFF;
42 | if(indicator>0)indicator--;//reduce counter in order to stop indicator after refresh
43 | }
44 |
45 | //Update E-ink based on data
46 | if(EPD_power_init()==RES_OK){
47 |
48 | //Update E-ink frame
49 | if(imageUpdateState== IMG_UPDATE){
50 | EPD_frame_newImg(imagePtr,0,cog.lines_per_display);
51 | imageUpdateState = SENSE_UPDATE;
52 | senseState=0;
53 | }
54 |
55 | //Update motion indicator
56 | if(indicator)EPD_frame_singleDot(18,24,28,value);
57 |
58 | //Update temerature result in the plot
59 | EPD_frame_singleDot(newData.y,newData.y+1,newData.x,0xC3);
60 | return EPD_power_off();
61 | }
62 | return FAIL;
63 | }
64 |
65 |
66 | /**
67 | * @brief Update EPD display from imgBuffer
68 | * @param imgPtr - the pointer pointed to the start of updated content
69 | * @time EPD powerOn&Off takes around 325ms
70 | * @note imgBuffer is filled from NFC I-block reading in myNFC_protocol.c,
71 | * the updateDisplay2 is only be called when receive whole image
72 | * @note NFC-WISP Reader App 1.0 will sending dummy data for power
73 | * after finishing image transfer.
74 | * If you build *BUILD_E_INK_2_0_BATT_FREE*
75 | * we add more lowPowerSleep during E-ink updating to reive more energy from cell-phone
76 | */
77 |
78 | uint8_t updateDisplay2(unsigned char* imagePtr){
79 | //Update E-ink based on data
80 | if(EPD_power_init()==RES_OK){
81 |
82 | //Update E-ink frame
83 | if(imageUpdateState){
84 | EPD_frame_newImg(imagePtr,0,cog.lines_per_display);
85 | }
86 |
87 | return EPD_power_off();
88 | }
89 | return FAIL;
90 |
91 | //TODO:indicate end update
92 | //LED_2_BIT_auto_pulse();
93 | }
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/myE-paperApp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * myE-paperApp.h
3 | *
4 | * Created on: Mar 5, 2015
5 | * Author: yizhao
6 | */
7 |
8 | #ifndef MYE_PAPERAPP_H_
9 | #define MYE_PAPERAPP_H_
10 |
11 | uint8_t updateDisplay1(unsigned char* imagePtr); //Temerature/Accelerometer dataLogger demo
12 | uint8_t updateDisplay2(unsigned char* imagePtr); //E-ink display update demo
13 | #endif /* MYE_PAPERAPP_H_ */
14 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/myNFC_Protocol.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * myNFC_protocol.h
3 | * @brief: Higher Layer Application Response (INF) (to I-Block and \
4 | * decides how to fill in INF field of Response to ATTRIB)
5 | * @date: Aug 22, 2014
6 | * @author: Yi Zhao (Eve)-Sensor System Lab, UW
7 | * @note: Only Implement response in ISO 14443-B protocol here
8 | * @TODO: Test and Implement _15693_1of256 protocol
9 | ******************************************************************************/
10 |
11 | #ifndef MYNFC_PROTOCOL_H_
12 | #define MYNFC_WISP_PROTOCOL_H_
13 |
14 | //globals
15 | #include
16 | #include "msp430f5310.h"
17 | #include "../common/globals.h"
18 | #include "../NFC_protocol/crc_checker.h"
19 |
20 | extern unsigned char _14443_buf_ptr;
21 | //extern unsigned char rx_buffer[CMD_BUF_SIZE];
22 | //extern unsigned char transmitCommand[CMD_BUF_SIZE];
23 | //extern unsigned char imageBuffer[E_INK_SIZE];
24 | //extern unsigned char imageBuffer[2];
25 | extern unsigned char command_number;
26 | extern unsigned int imageBytesReceived;
27 |
28 | //function prototypes
29 | void initialize_nfc_wisp_protocol(void);
30 | uint8_t nfc_wisp_protocol(unsigned char * receiveCommand, unsigned char index);
31 | #endif /* NFC_WISP_PROTOCOL_H_ */
32 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/tempSense.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * tempSense.c
3 | * @breif temperature sensing funtion
4 | * @date 10/15/2014
5 | * @author Yi Zhao, Sensor Systems Lab,UW and Disney Research Pittsburgh
6 | * @note Vtemp=0.00252*Temp(C)+0.688, so -50~100(oC) result in 0.06~1v
7 | * ADC sample period is 75us(30 reference, 45 sampling)
8 | *****************************************************************************/
9 |
10 | //=============================================================================
11 | // Includes
12 | //=============================================================================
13 | #include "../common/globals.h"
14 | #include "tempSense.h"
15 | #include "../common/timer.h"
16 | #include "../common/e-paper.h"
17 |
18 | //=============================================================================
19 | // Variables
20 | //=============================================================================
21 | static volatile uint16_t temp;
22 |
23 | //=============================================================================
24 | // Functions
25 | //=============================================================================
26 | /**
27 | * @fun Sense temerator sensor in MSP430 (single ADC sampling)
28 | * @note Must fine tuning the offset of temerature sensor reading
29 | *
30 | */
31 | resultData tempSense(void){
32 | // uint16_t IntDegF;
33 | uint16_t volatile IntDegC;
34 | //uint16_t temp;
35 | resultData volatile data;
36 |
37 | REFCTL0 |= REFON | REFVSEL_0; //1.5v
38 |
39 | ADC10CTL0 |= ADC10SHT_3 | ADC10ON ;//64 sampling cycles=37us
40 | ADC10CTL1 |= ADC10DIV_7 |ADC10SSEL_3 |ADC10CONSEQ_0 |ADC10SHP;//SMCLK@13.56Mhz/8=1.69Hz
41 | //ADC10CTL2 |= ADC10SR;
42 | ADC10MCTL0 |= ADC10SREF_1 | ADC10INCH_10; //select temperature sensor
43 | ADC10IE = ADC10IE0;
44 | delay_us(T_30us);//delay at lease 25us for reference to be stable
45 | ADC10CTL0 |= ADC10ENC;
46 | ADC10CTL0 |= ADC10SC; //start sampling
47 | __bis_SR_register(LPM4_bits+GIE);
48 | ADC10CTL0 = 0;//stop ADC
49 | REFCTL0 &= ~REFON;
50 |
51 | // Temperature in Celsius
52 | //actual IntDegC = (temp*0.5819-273.0159)*10;
53 | //format is t*10+50oC*10+offest (the result will have 50oC offet)
54 | //IntDegC = ((temp*93)>>4)-2308-385;
55 | //(tempAverage - 630) * 761) / 1024 );
56 | data.ADC_data = temp;
57 |
58 | //data.y=176-(IntDegC>>1); //TEST:suppose detected range is half of the Y_range
59 |
60 | //Version: paper (large temp range)
61 | //IntDegC = ((temp*93)>>4)-2730;
62 | //data.y=Y_offset-(IntDegC>>2);//
63 |
64 | #warning "temerature offset in different board is different \
65 | must adjust it for your board here"
66 | IntDegC = ((temp*93)>>4)-2850; //2860 is the offset for some board , 2650 for other board
67 | data.y=Y_offset-(IntDegC>>1);//
68 |
69 | //data.x = senseState + X_start;
70 | data.x = senseState + 3;
71 |
72 | //TODO what should we do if the Y is out of the range
73 | if(!((Y_start=X_end){
77 | data.x= X_end;
78 | //TODO clear E-ink Display and redraw
79 | imageUpdateState=IMG_UPDATE;
80 | //temp = 0;
81 | senseState = X_end-1;
82 | }
83 | // Temperature in Fahrenheit
84 | //actual IntDegF = (temp*1.0474 - 241.0159)*10
85 | //format is t*10+1220
86 | //IntDegF = (temp*670)>>6 - 1910;
87 |
88 | return data;
89 | }
90 |
91 | //=============================================================================
92 | // ISR
93 | //=============================================================================
94 | #pragma vector=ADC10_VECTOR
95 | __interrupt void ADC10ISR (void)
96 | {
97 | if(ADC10IFG&ADC10IFG0){
98 | temp = ADC10MEM0;
99 | __bic_SR_register_on_exit(LPM4_bits); // Exit active CPU
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/UserApp/tempSense.h:
--------------------------------------------------------------------------------
1 | /*
2 | * temSense.h
3 | *
4 | * Created on: Nov 17, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef TEMPSENSE_H_
9 | #define TEMPSENSE_H_
10 |
11 | /* Screen range for 10~40 temperature range is:
12 | * (start from 0)
13 | * X= 28 (col3~col31,total is 0~32)
14 | * Y= 152 (line5~line156)
15 | */
16 |
17 | /*Version: Paper (large range)
18 | //test supporse temp range is half of the Y_range
19 | #define Y_start 7
20 | #define Y_end 156
21 | #define Y_range (Y_end - Y_start) //150 points *4= 600 can represent -10~50oC,
22 | #define Y_offset 123 //the y axis start from -10oC 156-102=54/27~26
23 | #define X_start 3
24 | #define X_end 31
25 | #define X_range (X_end - X_start)*8 //right now is 30 samples dot30*8=224 cycles suppose min
26 | */
27 |
28 |
29 | //Version: Demo (small temp range)
30 | //test supporse temp range is half of the Y_range
31 | #define Y_start 5
32 | #define Y_end 156
33 | #define Y_range (Y_end - Y_start+1) //152 *4= 608 can represent 10~40oC,
34 | #define Y_offset 206 //the y axis start from 10oC =156 + (10oC)=156 + 100/2 = 206
35 | #define X_start 3
36 | #define X_end 31
37 | #define X_range (X_end - X_start)*8 //right now is 30 samples dot30*8=224 cycles suppose min
38 | //*/
39 | typedef struct{
40 | uint8_t y; //lines number
41 | uint8_t x; //byte position in E-ink
42 | uint16_t ADC_data;
43 | //uint8_t value; // the image value
44 | }resultData;
45 |
46 | resultData tempSense(void);
47 | void updateSense(void);
48 | #endif /* TEMSENSE_H_ */
49 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/_system_pre_init.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * @file NFC_WISP_Rev1.0.c
3 | * @fun MSP430 _system_pre_init() and Interrupt Routine
4 | * @date 10/25/2014
5 | * @author Eve (Yi Zhao), Sensor systems Lab. UW
6 | * @notes note that the system_pre_init and interrupt vectors do not need \
7 | * definitions in the header files. This is because
8 | * compiler automatically links them.
9 | */
10 | /******************************************************************************/
11 |
12 |
13 | //=============================================================================
14 | // Includes
15 | //=============================================================================
16 | #include "globals.h"
17 | uint16_t bad_interrupts;
18 | //uint8_t isDoingLowPwrSleep;
19 |
20 | //=============================================================================
21 | // Functions
22 | //=============================================================================
23 | /**
24 | * @fcn void _system_pre_init (void)
25 | * @brief routine called by boot() right before main() is called.
26 | * @pre c_int00 was just called after a POR/PUC event
27 | * @post the RAM, clock and peripherals are initialized for use
28 | * @note ACLK,FLL is disabled in _system_pre_init, \
29 | * UCSCTL8 used to clear SMCLKREQEN,MCLKREQEN,ACLKREQEN \
30 | * if do not want in LPM
31 | */
32 | int _system_pre_init (void) {
33 |
34 | //--------------------Setup Watchdog, IO----------------------------------//
35 | WDTCTL = WDTPW + WDTHOLD; /* disable the watchdog timer -*/
36 | setupDflt_IO();
37 | _bic_SR_register(GIE); //Turn off GIE while we initialize.
38 | bad_interrupts = 0;
39 |
40 | //Turn LDO off
41 | LDOKEYPID = LDOKEY;
42 | LDOPWRCTL = 0x00;
43 | LDOKEYPID = 0;
44 |
45 | // Turn off high/low voltage supervisors
46 | PMMCTL0_H = PMMPW_H;
47 | SVSMHCTL &= ~(SVMHE+SVSHE);
48 | SVSMLCTL &= ~(SVMLE+SVSLE);
49 | PMMCTL0_H = 0x00;
50 |
51 | //---------------------------Setup Clock----------------------------------//
52 |
53 | // ACLK=REFO,SMCLK=DCO,MCLK=DCO During initialization
54 | UCSCTL4 |= SELA__REFOCLK + SELM__DCOCLK + SELS__DCOCLK;
55 | //turn off the FLL and ACLK since we do not use it at the very beginning
56 | //_BIS_SR(SCG0+OSCOFF); //@note: must keep ACLK on for timeout system
57 |
58 | UCSCTL6 &= ~XT2OFF; // Turn on XT2OFF
59 | //UCSCTL4 |= SELA_2; // ACLK=REFO,SMCLK=DCO,MCLK=DCO During initialization
60 | /*Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles*/
61 | do
62 | {
63 | UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags
64 | SFRIFG1 &= ~OFIFG; // Clear fault flags
65 | }while (SFRIFG1&OFIFG); // Test oscillator fault flag
66 |
67 | UCSCTL6 &= ~XT2DRIVE1; // Decrease XT2 Drive according to expected frequency
68 | UCSCTL4 |= SELS_5 | SELM_5 | SELA_0; // SMCLK=MCLK=XT2, ACLK=XT1,
69 | UCSCTL7 = 0; //clear fault flags
70 | return 0;
71 | }
72 |
73 |
74 |
75 |
76 | /**
77 | * Catch any bad interrupts to prevent them from resetting the CPU.
78 | * Keep count of all bad interrupts that occur.
79 | */
80 | #pragma vector=RTC_VECTOR
81 | #pragma vector=PORT2_VECTOR
82 | #pragma vector=TIMER2_A1_VECTOR
83 | #pragma vector= USCI_A1_VECTOR
84 | //#pragma vector=TIMER2_A0_VECTOR
85 | //#pragma vector=USCI_B1_VECTOR
86 | //#pragma vector=PORT1_VECTOR
87 | #pragma vector=TIMER1_A1_VECTOR
88 | //#pragma vector=TIMER1_A0_VECTOR
89 | #pragma vector=DMA_VECTOR
90 | #pragma vector=LDO_PWR_VECTOR
91 | #pragma vector=TIMER0_A1_VECTOR
92 | //#pragma vector=TIMER0_A0_VECTOR
93 | //#pragma vector=ADC10_VECTOR
94 | #pragma vector=USCI_B0_VECTOR
95 | #pragma vector=USCI_A0_VECTOR
96 | #pragma vector=WDT_VECTOR
97 | #pragma vector=TIMER0_B1_VECTOR
98 | #pragma vector=TIMER0_B0_VECTOR
99 | #pragma vector=COMP_B_VECTOR
100 | #pragma vector=UNMI_VECTOR
101 | #pragma vector=SYSNMI_VECTOR
102 | __interrupt void CATCH_ALL(void) {
103 | asm(" NOP");
104 | bad_interrupts++;
105 | }
106 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/accel.h:
--------------------------------------------------------------------------------
1 | /**
2 | * accel.h
3 | *
4 | * @date Aug 2013
5 | * @author Aaron Parks, Eve(Yi Zhao), Sensor Systems Lab, UW
6 | */
7 |
8 | #ifndef ACCEL_H_
9 | #define ACCEL_H_
10 |
11 | #include "globals.h"
12 |
13 | typedef struct {
14 | uint16_t x;
15 | uint16_t y;
16 | uint16_t z;
17 | } threeAxis_t;
18 |
19 | void initACCEL(void);
20 | void ACCEL_standby(void);
21 | BOOL ACCEL_Status(uint8_t* result);
22 | //BOOL ACCEL_satus(threeAxis_t* result);
23 | BOOL ACCEL_singleSample(uint8_t* result);
24 | BOOL ACCEL_Status(uint8_t* result);
25 | BOOL activity(uint8_t* preACC);
26 |
27 | //ACCEL I/O Macros
28 | #define ACCEL_Enable() \
29 | //;
30 | //POUT_EN_ACCEL |= PIN_ACCEL_CS; \
31 | //PDIR_EN_ACCEL |= PIN_ACCEL_CS;
32 | #define ACCEL_Disable() \
33 | ;
34 | //PDIR_EN_ACCEL &= ~PIN_EN_ACCEL + PIN_ACCEL_CS;
35 | #endif /* ACCEL_H_ */
36 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/accel_registers.h:
--------------------------------------------------------------------------------
1 | /**
2 | * accel_registers.h
3 | *
4 | * @date Aug 2014
5 | * @author Aaron Parks, Eve(Yi Zhao)
6 | */
7 |
8 | #ifndef ACCEL_REGISTERS_H_
9 | #define ACCEL_REGISTERS_H_
10 |
11 | //
12 | // Commands used for ADXL362 read/write access. Commands are sent prior to data/adx.
13 | //
14 | #define ADXL_CMD_WRITE_REG 0x0A
15 | #define ADXL_CMD_READ_REG 0x0B
16 | #define ADXL_CMD_READ_FIFO 0x0D
17 |
18 | //
19 | // Registers in the ADXL362. Created from the register map given in Table 11 of the datasheet.
20 | //
21 | #define ADXL_REG_DEVID_AD 0x00
22 | #define ADXL_REG_DEVID_MST 0x01
23 | #define ADXL_REG_PARTID 0x02
24 | #define ADXL_REG_REVID 0x03
25 | #define ADXL_REG_XDATA 0x08
26 | #define ADXL_REG_YDATA 0x09
27 | #define ADXL_REG_ZDATA 0x0A
28 | #define ADXL_REG_STATUS 0x0B
29 | #define ADXL_REG_FIFO_ENTRIES_L 0x0C
30 | #define ADXL_REG_FIFO_ENTRIES_H 0x0D
31 | #define ADXL_REG_XDATA_L 0x0E
32 | #define ADXL_REG_XDATA_H 0x0F
33 | #define ADXL_REG_YDATA_L 0x10
34 | #define ADXL_REG_YDATA_H 0x11
35 | #define ADXL_REG_ZDATA_L 0x12
36 | #define ADXL_REG_ZDATA_H 0x13
37 | #define ADXL_REG_TEMP_L 0x14
38 | #define ADXL_REG_TEMP_H 0x15
39 | #define ADXL_REG_Reserved0 0x16
40 | #define ADXL_REG_Reserved1 0x17
41 | #define ADXL_REG_SOFT_RESET 0x1F
42 | #define ADXL_REG_THRESH_ACT_L 0x20
43 | #define ADXL_REG_THRESH_ACT_H 0x21
44 | #define ADXL_REG_TIME_ACT 0x22
45 | #define ADXL_REG_THRESH_INACT_L 0x23
46 | #define ADXL_REG_THRESH_INACT_H 0x24
47 | #define ADXL_REG_TIME_INACT_L 0x25
48 | #define ADXL_REG_TIME_INACT_H 0x26
49 | #define ADXL_REG_ACT_INACT_CTL 0x27
50 | #define ADXL_REG_FIFO_CONTROL 0x28
51 | #define ADXL_REG_FIFO_SAMPLES 0x29
52 | #define ADXL_REG_INTMAP1 0x2A
53 | #define ADXL_REG_INTMAP2 0x2B
54 | #define ADXL_REG_FILTER_CTL 0x2C
55 | #define ADXL_REG_POWER_CTL 0x2D
56 | #define ADXL_REG_SELF_TEST 0x2E
57 |
58 | //value used to configure ADXL362
59 | #define AUTOSLEEP 0x0E
60 | #define WAKE_UP 0x0A
61 | #endif /* ACCEL_REGISTERS_H_ */
62 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/e-paper.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * e-paper.h
3 | *
4 | * @bref EPD(E-paer Driver) COG drive for Gen2 EPD EM027BS013
5 | * @note Modify cog for different EPD size of display (must using Gen2 COG)
6 | *
7 | *****************************************************************************/
8 |
9 | #include
10 | #include
11 | #include "../UserApp/myE-paperApp.h"
12 | //#include "tempSense.h"
13 |
14 |
15 | //------------------------------------------------------------------------------
16 | // Defines
17 | //------------------------------------------------------------------------------
18 | /*******E_INK image buffer size *******/
19 | /*
20 | * Max should be
21 | * cog.bytes_per_line * cog.lines_per_display
22 | * @note: adjust the cog in e-paper.c to match the type of e-paper
23 | *
24 | * 176*33 = 5808 for 2.7" e-paper
25 | * 96*200/8 for 2.7" e-paper
26 | * 96*128/8 for 1.4" e-paper
27 | */
28 | #if defined(E_INK_2_0)
29 | #define E_INK_SIZE 96*200/8 //2.0 e-paper
30 | #elif defined(E_INK_2_7)
31 | #define E_INK_SIZE 5808
32 | #endif
33 |
34 |
35 | /*******Update cycles for image *******/
36 | //@note The large cycle number results in better image
37 | #warning "if the image is not clear, then increase the NEW_IMG_CYCLES(Notice:more power consumption"
38 | #define NEW_IMG_CYCLES 4
39 | #define SINGLE_COLOR_CYCLES 1
40 | #define SINGLE_DOT_CYCLES 4
41 |
42 | /************E-ink Update state for variable imageState************************/
43 | #define IMG_HALT 0
44 | #define IMG_UPDATE 1
45 | #define SENSE_UPDATE 2
46 | #define IMG_FORCE_UPDATE 3
47 | #define IMG_UPDATE_COMPLETE 4
48 | /*
49 | * The definition for driving stage to compare with
50 | * for getting Odd and Even data
51 | */
52 | #define BLACK0 (uint8_t)(0x03) /**< getting bit1 or bit0 as black color(11) */
53 | #define BLACK1 (uint8_t)(0x0C) /**< getting bit3 or bit2 as black color(11) */
54 | #define BLACK2 (uint8_t)(0x30) /**< getting bit5 or bit4 as black color(11) */
55 | #define BLACK3 (uint8_t)(0xC0) /**< getting bit7 or bit6 as black color(11) */
56 | #define WHITE0 (uint8_t)(0x02) /**< getting bit1 or bit0 as white color(10) */
57 | #define WHITE1 (uint8_t)(0x08) /**< getting bit3 or bit2 as white color(10) */
58 | #define WHITE2 (uint8_t)(0x20) /**< getting bit5 or bit4 as white color(10) */
59 | #define WHITE3 (uint8_t)(0x80) /**< getting bit7 or bit6 as white color(10) */
60 | #define NOTHING0 (uint8_t)(0x01) /**< getting bit1 or bit0 as nothing input(01) */
61 | #define NOTHING1 (uint8_t)(0x04) /**< getting bit3 or bit2 as nothing input(01) */
62 | #define NOTHING2 (uint8_t)(0x10) /**< getting bit5 or bit4 as nothing input(01) */
63 | #define NOTHING3 (uint8_t)(0x40) /**< getting bit7 or bit6 as nothing input(01) */
64 | #define NOTHING (uint8_t)(0x55) /**< sending Nothing frame, 01=Nothing, 0101=0x5 */
65 |
66 |
67 | #define ALL_BLACK (uint8_t)(0xFF)
68 | #define ALL_WHITE (uint8_t)(0xAA)
69 | #define BORDER_BYTE_B (uint8_t)(0xFF)
70 | #define BORDER_BYTE_W (uint8_t)(0xAA)
71 | #define ERROR_BUSY (uint8_t)(0xF0)
72 | #define ERROR_COG_ID (uint8_t)(0xF1)
73 | #define ERROR_BREAKAGE (uint8_t)(0xF2)
74 | #define ERROR_DC (uint8_t)(0xF3)
75 | #define ERROR_CHARGEPUMP (uint8_t)(0xF4)
76 | #define RES_OK (uint8_t)(0x00)
77 |
78 |
79 | //------------------------------------------------------------------------------
80 | // Micros
81 | //------------------------------------------------------------------------------
82 | #define initEPD() \
83 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_CS_EPD_BIT); \
84 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_CS_EPD_BIT); \
85 | PDIR_SPI &= ~(SPI_MISO_BIT); \
86 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
87 | EPD_RESET_OUT &= ~(EPD_RESET_BIT); \
88 | EPD_PANEL_ON_OUT &= ~(EPD_PANEL_ON_BIT);\
89 |
90 | /**
91 | * \brief Define the COG driver's parameters */
92 | struct EPD_type{
93 | uint8_t channel_select[8]; /**< SPI register data of Channel Select */
94 | uint8_t voltage_level; /**< SPI register data of Voltage Level */
95 | uint8_t bytes_per_line; /**< bytes of width of EPD */
96 | uint8_t lines_per_display; /**< the bytes of height of EPD */
97 | uint8_t data_line_size; /**< Data + Scan + Dummy bytes */
98 | uint8_t bytes_per_scan;
99 | };
100 |
101 | //------------------------------------------------------------------------------
102 | // globals
103 | //------------------------------------------------------------------------------
104 | extern uint8_t imageBuffer[E_INK_SIZE];
105 | extern uint8_t volatile imageUpdateState;
106 | //extern EPD_type;
107 | extern const struct EPD_type cog;
108 |
109 | //------------------------------------------------------------------------------
110 | // Functions
111 | //------------------------------------------------------------------------------
112 | //Initial EPD Dirver
113 | uint8_t EPD_power_init(void);
114 | //Turn off EPD Driver
115 | uint8_t EPD_power_off(void);
116 | //Update one line
117 |
118 | //Update multiple lines to all White or all Black
119 | void EPD_frame_fixed(const uint8_t start, const uint8_t end, const uint8_t color);
120 | //Update multiple lines of new image
121 | void EPD_frame_newImg(uint8_t* imgPtr,const uint8_t start, const uint8_t end);
122 | //Update singleDot (4 pixels) in E-ink display
123 | void EPD_frame_singleDot(const uint8_t start, const uint8_t end, uint8_t byte_pos,const uint8_t value);
124 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/fram_memory.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * fram_memory.c
3 | * @date Jun 15, 2013
4 | * @author Artem Dementyev, Aaron Parks,Eve(Yi Zhao)
5 | *****************************************************************************/
6 |
7 | #include "fram_memory.h"
8 | #include "e-paper.h"
9 |
10 | uint8_t const FRAM_Sleep[] = {0xB9};
11 | uint8_t const ReadStatus[] = {0x05,0x00};
12 | uint8_t const ReadDeviceID[]={0x9F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
13 |
14 | void SPI_FRAM_Wake_Up(void) {
15 | // CS low
16 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
17 | delay_us(T_10us);
18 |
19 | lowPowerSleep(LPM_500us);
20 |
21 | // CS high
22 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
23 | }
24 |
25 | void SPI_FRAM_Write_Enable_Latch(void) {
26 | // CS low
27 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
28 |
29 | //send the op code
30 | uint16_t i;
31 | for (i = 0; i < 1; ++i) {
32 | while (0 == (UCB1IFG & UCTXIFG)) {
33 | }
34 | UCB1TXBUF = 0x06; //op code for enabling write latch (WREN)
35 | }
36 |
37 | // wait for last byte to clear SPI
38 | while (0 != (UCB1STAT & UCBUSY)) {
39 | }
40 |
41 | // CS high
42 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
43 | }
44 |
45 | void SPI_FRAM_Enter_Sleep() {
46 | //Note: must make sure SPI clock is SMCLK =13MHz
47 | // Select MEMERY SPI
48 | SPI_transaction(gpRxBuf,(uint8_t*)&FRAM_Sleep, sizeof(FRAM_Sleep),FRAM_SPI);
49 | //Disable SPI
50 | }
51 |
52 | uint8_t SPI_FRAM_Read_Status_Register(void) {
53 |
54 | SPI_transaction(gpRxBuf,(uint8_t*)&ReadStatus, sizeof(ReadStatus),FRAM_SPI);
55 | return gpRxBuf[1];
56 | }
57 |
58 | void SPI_FRAM_Write_Memory(const uint8_t *bufferAddress,
59 | const uint8_t *bufferData, uint16_t lengthData) {
60 |
61 | // CS low
62 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
63 |
64 | // send the op code
65 | uint16_t i;
66 | for ( i = 0; i < 1; ++i) {
67 | while (0 == (UCB1IFG & UCTXIFG)) {
68 | }
69 | UCB1TXBUF = 0x02; //op code for writing memory (WRITE)
70 | }
71 |
72 | // wait for last byte to clear SPI
73 | while (0 != (UCB1STAT & UCBUSY)) {
74 | }
75 |
76 | //send the 18-bit address of first data byte (we use 8 * 3 = 24 bits to represent address)
77 |
78 | for (i = 0; i < 3; ++i) {
79 | while (0 == (UCB1IFG & UCTXIFG)) {
80 | }
81 | UCB1TXBUF = *bufferAddress++;
82 | }
83 |
84 | // send the 8-byte data
85 | while (0 != (UCB1STAT & UCBUSY)) {
86 | }
87 |
88 | for ( i = 0; i < lengthData; ++i) {
89 | while (0 == (UCB1IFG & UCTXIFG)) {
90 | }
91 | UCB1TXBUF = *bufferData++;
92 | }
93 |
94 | // wait for last byte to clear SPI
95 | while (0 != (UCB1STAT & UCBUSY)) {
96 | }
97 |
98 | // CS high
99 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
100 |
101 | } //end SPI write memory
102 |
103 | uint8_t * SPI_FRAM_Read_Memory(const uint8_t *bufferAddress,
104 | uint16_t lengthData) {
105 |
106 | // TODO We don't have space in RAM for the following array.
107 | //uint8_t testArray[5807];
108 |
109 | // CS low
110 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
111 |
112 | // send the op code
113 | uint16_t i;
114 | for (i = 0; i < 1; ++i) {
115 | while (0 == (UCB1IFG & UCTXIFG)) {
116 | }
117 | UCB1TXBUF = 0x03; //op code for reading memory (READ)
118 | }
119 |
120 | // wait for last byte to clear SPI
121 | while (0 != (UCB1STAT & UCBUSY)) {
122 | }
123 |
124 | //send the 18-bit address
125 | for ( i = 0; i < 3; ++i) {
126 | while (0 == (UCB1IFG & UCTXIFG)) {
127 | }
128 | UCB1TXBUF = *bufferAddress++;
129 | }
130 |
131 | // clock out the 8-byte data
132 | while (0 != (UCB1STAT & UCBUSY)) {
133 | }
134 |
135 | for (i = 0; i < lengthData; ++i) {
136 | while (0 == (UCB1IFG & UCTXIFG)) {
137 | }
138 | UCB1TXBUF = 0xff;
139 | gpRxBuf[i] = UCB1RXBUF;
140 | }
141 |
142 | // wait for last byte to clear SPI
143 | while (0 != (UCB1STAT & UCBUSY)) {
144 | }
145 |
146 | // CS high
147 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
148 |
149 | // TODO This will fail in many circumstances: We're returning a pointer to a local variable.
150 | return gpRxBuf;
151 |
152 | } //end SPI write memory
153 |
154 | void SPI_FRAM_Read_Image(const uint8_t *bufferAddress,
155 | uint16_t lengthData) {
156 | // CS low
157 |
158 | //uint8_t testArray[5807];
159 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
160 |
161 | // send the op code
162 | uint16_t i;
163 | for (i = 0; i < 1; ++i) {
164 | while (0 == (UCB1IFG & UCTXIFG)) {
165 | }
166 | UCB1TXBUF = 0x03; //op code for reading memory (READ)
167 | }
168 |
169 | // wait for last byte to clear SPI
170 | while (0 != (UCB1STAT & UCBUSY)) {
171 | }
172 |
173 | //send the 18-bit address
174 | for (i= 0; i < 3; ++i) {
175 | while (0 == (UCB1IFG & UCTXIFG)) {
176 | }
177 | UCB1TXBUF = *bufferAddress++;
178 | }
179 |
180 | // clock out the 8-byte data
181 | while (0 != (UCB1STAT & UCBUSY)) {
182 | }
183 |
184 | for (i = 0; i < lengthData; ++i) {
185 | while (0 == (UCB1IFG & UCTXIFG)) {
186 | }
187 | UCB1TXBUF = 0xff;
188 | imageBuffer[i] = UCB1RXBUF;
189 | }
190 |
191 | // wait for last byte to clear SPI
192 | while (0 != (UCB1STAT & UCBUSY)) {
193 | }
194 |
195 | // CS high
196 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
197 | } //end SPI write memory
198 |
199 | /**
200 | * Initialize the FRAM module and put it to sleep
201 | *
202 | * @note must wait 1ms before SPI
203 | */
204 | void initFRAM(void) {
205 |
206 | /*sleep 1ms to allow FRAM startup*/
207 | lowPowerSleep(LPM_1ms);
208 |
209 | /*Coomment it out to test if SPI works well,
210 | *the status register should return 0x40*/
211 | //SPI_FRAM_Read_Status_Register();
212 |
213 | /* Put FRAM to sleep*/
214 | SPI_FRAM_Enter_Sleep();
215 | }
216 |
217 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/fram_memory.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * fram_memory.h
3 | *
4 | * @date Jun 15, 2013
5 | * @author Artem Dementyev, Aaron Parks
6 | *****************************************************************************/
7 | #include "globals.h"
8 | #include "spi.h"
9 |
10 |
11 | //void SPI_FRAM_Write_Enable_Latch(unsigned char portj_cs_pin);
12 | void initFRAM(void);
13 | void SPI_FRAM_Write_Enable_Latch(void);
14 | unsigned char SPI_FRAM_Read_Status_Register(void);
15 | void SPI_FRAM_Write_Memory(const uint8_t *bufferAddress,const uint8_t *bufferData, uint16_t lengthData);
16 | uint8_t * SPI_FRAM_Read_Memory(const uint8_t *bufferAddress,uint16_t lengthData);
17 | void SPI_FRAM_Enter_Sleep(void);
18 | void SPI_FRAM_Wake_Up(void);
19 | void SPI_FRAM_Read_Image(const uint8_t *bufferAddress,uint16_t lengthData);
20 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/globals.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * globals.c
3 | * @breif global functions
4 | * @date 8/15/2014
5 | * @author Yi Zhao, Uw Sensor systems Lab
6 | *****************************************************************************/
7 | //-----------------------------------------------------------------------------
8 | // Includes
9 | //------------------------------------------------------------------------------
10 | #include "globals.h"
11 |
12 | //------------------------------------------------------------------------------
13 | // Functions
14 | //------------------------------------------------------------------------------
15 | /**
16 | * Configure LED 1 to pulse once without further intervention
17 | */
18 | void led_1_auto_pulse(void) {
19 | led_pulse_flags|=LED_1_PULSE_FLAG;
20 | }
21 |
22 | /**
23 | * Configure LED 2 to pulse once without further intervention
24 | */
25 | void LED_2_BIT_auto_pulse(void) {
26 | led_pulse_flags|=LED_2_BIT_PULSE_FLAG;
27 | }
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/globals.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************************/
2 | /** @file globals.h
3 | * @brief NFC global defines and funcs
4 | * @author Yi Zhao(Eve), UW Sensor Systems Lab
5 | * @created 8.15.2014
6 | */
7 | /************************************************************************************************************************************/
8 | #ifndef GLOBALS_H_
9 | #define GLOBALS_H_
10 |
11 | //=============================================================================
12 | // Includes
13 | //=============================================================================
14 | #include "NFC_WISP_Rev1.0.h"
15 | #include "spi.h"
16 | #include
17 | #include
18 | #include
19 | #include "timer.h"
20 | //#include "e-paper.h"
21 | //=============================================================================
22 | // Configuration
23 | //=============================================================================
24 | /*******SELECT PROTOCOL*************/
25 | //#define _15693_1of256
26 | #define _14443_B
27 |
28 | /******SELECT CLOCK FREQUENCY******/
29 | //#define _6_78MHz
30 | #define _13_56MHz
31 |
32 | //=============================================================================
33 | // General Defines
34 | //=============================================================================
35 | #define CMD_BUF_SIZE 64
36 | //#define CMD_BUF_SIZE 1
37 | //@modify only for RFID 2015
38 | #ifdef TempDemo
39 | #define UID_SIZE 8
40 | #else
41 | #define UID_SIZE 4
42 | #endif
43 |
44 | #define APP_SIZE 4
45 | #define CAPTURE_BUFFER_SIZE 10 //maximum number of pulse capture times we can store
46 |
47 | #define CRYSTAL_FREQ 32768
48 | #define TIMEOUT_MS 100 //low power timeout in ms
49 | #define TIMEOUT_VAL (CRYSTAL_FREQ/(TIMEOUT/10))
50 |
51 |
52 |
53 |
54 |
55 |
56 | #define LED_1_PULSE_FLAG 0x01
57 | #define LED_2_BIT_PULSE_FLAG 0x02
58 | #define KILL_LEDS_FLAG 0x80
59 |
60 |
61 | #define FOREVER (1)
62 | #define NEVER (0)
63 |
64 | #define TRUE (1)
65 | #define FALSE (0)
66 |
67 | #define HIGH (1)
68 | #define LOW (0)
69 | //#define NULL (void *)0 /**< define NULL */
70 |
71 | #define FAIL (0)
72 | #define SUCCESS (1)
73 |
74 |
75 | //=============================================================================
76 | // NFC Defines
77 | //=============================================================================
78 | //6.78Mhz where 1 etu is clock periods
79 | // TODO Get rid of ifdefs if possible
80 | #ifdef _14443_B
81 |
82 | /****************state for NFC state machine **********************************/
83 | //Start NFC routine after first power up or sleep_untill_read
84 | //@note Change below bits setting have to change TimerA0 ISR in timer.c
85 | #define NFC_Stop 0 // NFC halt
86 | #define NFC_Start BIT7 // doNFC_state = BIT7
87 | #define NFC_Rx0 BIT0 // doNFC_state =BIT0 detect delimeter start
88 | #define NFC_Rx1 BIT1 // doNFC_state =BIT1 detect start of first byte start
89 | #define NFC_Rx2 BIT2 // doNFC_state =BIT2 decode data
90 | #define NFC_Tx 0x07 // doNFC_state =0x07 transmit data
91 | #define NFC_Sleep BIT3 // doNFC_state = BIT3
92 | #define NFC_LPM4 BIT4 // doNFC_state is in LMP4 now
93 |
94 |
95 |
96 | #ifdef _6_78MHz // 6.78 MHz clock frequency
97 |
98 | #define TEN_PULSES 70//80
99 | #define ELEVEN_PULSES 98//88
100 | #define EOF 86
101 |
102 | #else // Otherwise assume 13.56Mhz/8 clock frequency
103 | //threshold should be 70us
104 | #endif /* _6_78MHz */
105 | #endif /* _14443_B */
106 |
107 |
108 | //=============================================================================
109 | // Globals
110 | //=============================================================================
111 | /***************NFC Globals****************************/
112 | extern uint8_t volatile doNFC_state;
113 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
114 | /************E-ink Update state************************/
115 | //extern uint8_t imageBuffer[E_INK_SIZE];
116 | //extern uint8_t volatile imageUpdateState;
117 | //***********Sensing Update state**********************/
118 | extern volatile unsigned long RTC_ctr;
119 | extern volatile uint8_t senseState;
120 | extern volatile uint8_t accelState;
121 |
122 | /****Sense data cicular queue structure***************/
123 | extern uint8_t buf_full;
124 | extern uint8_t led_pulse_flags; // Flags indicating which LED to pulse in the timer ISR
125 | //=============================================================================
126 | // Functions
127 | //=============================================================================
128 | void led_1_auto_pulse();
129 | void LED_2_BIT_auto_pulse();
130 |
131 | //=============================================================================
132 | // Macros
133 | //=============================================================================
134 | // LED Macros
135 | #define toggle_led_1() LED_1_OUT ^= LED_1_BIT
136 | #define toggle_led_2() LED_2_OUT ^= LED_2_BIT
137 | #define led_1_off() LED_1_OUT &= ~(LED_1_BIT)
138 | #define led_2_off() LED_2_OUT &= ~(LED_2_BIT)
139 | #define led_1_on() LED_1_OUT |= LED_1_BIT
140 | #define led_2_on() LED_2_OUT |= LED_2_BIT
141 | #endif
142 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/spi.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file spi.h
3 | * @brief spi interface
4 | * @author Aaron Parks, Eve (Yi Zhao) - Sensor Systems Lab (UW)
5 | * @date 03/29/2015
6 | *****************************************************************************/
7 |
8 | #ifndef SENSOR_SPI_H_
9 | #define SENSOR_SPI_H_
10 |
11 | #include
12 | //=============================================================================
13 | // SPI Defines
14 | //=============================================================================
15 | //TODO: the size of SPI depends on application
16 | #warning "modify the size of SPI buffer for different requirement"
17 | #define SPI_GP_RXBUF_SIZE 17
18 |
19 | //#define CLK_MHz 13.56
20 | //#define SPI_BPS 10000000
21 | //#define SPI_BR_VALUE (1000000 * CLK_MHz / SPI_BPS)
22 | //SPI CLK is 13.56 Mhz
23 | //Baudrate now is 13.56Mhz/SPI_BR_LOW = 4.39Mhz
24 | #define SPI_BR_HIGH 0x00
25 | #define SPI_BR_LOW 0x03//0x03
26 |
27 | //Define index for different SPI slave
28 | //TODO: Add more depends on different SPI applications
29 | #define FRAM_SPI 0x00
30 | #define EPD_SPI 0x01
31 | #define ACCEL_SPI 0x02
32 | #define EPD_LONG_DATA 0x03
33 |
34 |
35 | //=============================================================================
36 | // SPI Micros
37 | //=============================================================================
38 | //SPI_CS_xx configureation used in SPI_transaction
39 | #define MEM_SPI_ON() \
40 | PSEL_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
41 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
42 | //reset CLK,MOSI to be 0/output MISO input and SPI_CS to be 1
43 | #define MEM_SPI_OFF() \
44 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT); \
45 | PDIR_SPI &= ~(SPI_MISO_BIT); \
46 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT); \
47 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT; \
48 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT);
49 |
50 | #define EPD_SPI_ON() \
51 | SPI_CS_EPD_OUT &=~ SPI_CS_EPD_BIT;
52 | #define EPD_SPI_OFF() \
53 | SPI_CS_EPD_OUT |= SPI_CS_EPD_BIT;
54 | #define ACCEL_SPI_ON() \
55 | PSEL_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
56 | SPI_CS_ACCEL_OUT &=~ SPI_CS_ACCEL_BIT;
57 | #define ACCEL_SPI_OFF() \
58 | SPI_CS_ACCEL_OUT |= SPI_CS_ACCEL_BIT; \
59 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT); \
60 | PDIR_SPI &= ~(SPI_MISO_BIT); \
61 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT); \
62 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT);
63 |
64 | //=============================================================================
65 | // Variables
66 | //=============================================================================
67 |
68 |
69 | extern uint8_t gpRxBuf[SPI_GP_RXBUF_SIZE];
70 | //extern uint8_t gpTxBuf[SPI_GP_RXBUF_SIZE];
71 | typedef uint8_t BOOL;
72 |
73 |
74 | //=============================================================================
75 | // SPI Functions
76 | //=============================================================================
77 | BOOL SPI_initialize();
78 | BOOL SPI_acquirePort();
79 | BOOL SPI_releasePort();
80 | void SPI_transaction(uint8_t* rxBuf, uint8_t* txBuf, uint16_t size, uint8_t spiSlaveIndex);
81 | void SPI_put_wait(unsigned char c);
82 | void epd_spi_send_byte (const uint8_t register_index, const uint8_t register_data);
83 | void epd_spi_send (uint8_t register_index, uint8_t *dataPtr, uint8_t length);
84 | uint8_t SPI_READ(const uint8_t Register);
85 |
86 |
87 | #endif /* SENSOR_SPI_H_ */
88 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/timer.c:
--------------------------------------------------------------------------------
1 | /*
2 | * timer.c
3 | *
4 | * Created on: Aug 26, 2014
5 | * Author: evezhao
6 | * @fun timeout and lowPowerSleep timming
7 | */
8 |
9 | #include "timer.h"
10 | #include "e-paper.h"
11 |
12 |
13 | /******************************************************************************
14 | * @brief TA0 Timeout system for monitor timeout such as in sleep_untill_edges
15 | * @CLK 32K/8=4K, 250us/cycles
16 | *****************************************************************************/
17 | void timeout_init(uint16_t time) {
18 | // Set up TA1.0 for periodic interrupt
19 | //_BIC_SR(OSCOFF); // ENABLE ACLK
20 | TA0CCR0 = time; // 10 ms with 32768 Hz ACLK
21 | TA0CTL = TASSEL_1 | ID_3 | MC_1 | TACLR; //ACLK, upmode, 4khz clk
22 | TA0CCTL0 = CCIE; //Enable interrupt
23 | }
24 |
25 | //Halt the timeout system (e.g., to save power)
26 | void timeout_halt(void) {
27 | TA0CTL = 0x00;
28 | TA0CCTL0 = 0;
29 | //_BIS_SR(OSCOFF);
30 | }
31 |
32 | /******************************************************************************
33 | * init real time clk count for every 15s for tempSense
34 | *****************************************************************************/
35 | void initRTC(uint16_t time){
36 | //_BIC_SR(OSCOFF); //Enable ACLK
37 | TA1CCR0 = time; // 10 ms with 32768 Hz ACLK
38 | //TA1CCR0 = 0xFFFE;
39 | TA1CTL = TASSEL_1 | ID_3 | MC__UP | TACLR; //ACLK, upmode, 4khz clk
40 | TA1CCTL0 |= CCIE;
41 | RTC_ctr = 0; //couting is 0;
42 | //senseState = 0; //
43 | }
44 |
45 | /*******************************************************************************/
46 | /* @brief sleep the CPU for duration(us~ms) using TimerA2
47 | * @note must use when ACLKREQEN=1
48 | *******************************************************************************/
49 | //low power and more accurate sleep delay
50 | //SMCLK @13.56Mhz/8
51 | void delay_us(uint16_t delay){
52 | TA2CTL = 0;
53 | TA2CCR0 = delay;
54 | TA2CCTL0 = CCIE;
55 | TA2CTL = TASSEL_2 | ID_3 | MC__UP; //SMCLK, 1.695Mhz
56 | __bis_SR_register(LPM4_bits | GIE);
57 | }
58 |
59 | //lowPower sleep for ms level sleep
60 | void lowPowerSleep (uint16_t duration) {
61 | //isDoingLowPwrSleep = TRUE;
62 | //_BIC_SR(OSCOFF); //Enable ACLK
63 | TA2CCR0 = duration;
64 | TA2CTL = 0;
65 | TA2CCTL0 = CCIE;
66 | TA2CTL = TASSEL__ACLK + MC__UP + TACLR; //ACLK, 32Khz,
67 | __bis_SR_register(LPM3_bits | GIE); //LPM3 sleep
68 | //_BIS_SR(OSCOFF); // Disable ACLK
69 | //isDoingLowPwrSleep = FALSE;
70 | return;
71 | }
72 |
73 | //low power Sleep for above 10ms sleep
74 | void long_lowPowerSleep (uint16_t duration) {
75 | //_BIC_SR(OSCOFF); //Enable ACLK
76 | TA2CCR0 = duration;
77 | TA2CTL = 0;
78 | TA2CCTL0 = CCIE;
79 | TA2CTL = TASSEL__ACLK | MC__UP | TACLR | ID_3; //ACLK, 4k=32K/8hz,
80 | __bis_SR_register(LPM3_bits | GIE); //LPM3 sleep
81 |
82 | return;
83 | }
84 | /*******************************************************************************
85 | @brief LPM3 sleep or NFC timeout ISR for NFC Rx using SMCLK or ACLK
86 | @note only used when MCLKREQEN=1
87 | *******************************************************************************/
88 | #pragma vector=TIMER0_A0_VECTOR
89 | __interrupt void timeTrackingISR(void) {
90 | //it is in doRFID_14443B routine
91 | if(doNFC_state=senseDelay){
111 | senseState++;
112 | RTC_ctr=0;
113 | if((doNFC_state&NFC_LPM4)){
114 | RX_WAKEUP_IE &= ~RX_WAKEUP_BIT;
115 | RX_WAKEUP_EN_DIR &= ~RX_WAKEUP_EN_BIT;
116 | RX_WAKEUP_IFG &= ~(RX_WAKEUP_BIT);
117 | doNFC_state = NFC_Sleep;
118 | imageUpdateState = SENSE_UPDATE;
119 | RTC_ctr = 0;
120 | __bic_SR_register_on_exit(LPM4_bits | GIE);
121 | }
122 |
123 | }
124 | }
125 |
126 |
127 | /*******************************************************************************/
128 | /** @fcn lowPowerSleep ISR for TimerA2
129 | * @brief LPM3 sleep for us~ms level
130 | * @note only used when ACLKREQEN=1
131 | */
132 | /*******************************************************************************/
133 | #pragma vector=TIMER2_A0_VECTOR
134 | __interrupt void LPM3_TimerISR(void) {
135 | TA2CTL = 0x00;
136 | TA2CCTL0 = 0x00;
137 | __bic_SR_register_on_exit(LPM3_bits | GIE);
138 | }
139 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/common/timer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * timer.h
3 | *
4 | * Created on: Aug 26, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef TIMER_H_
9 | #define TIMER_H_
10 |
11 |
12 | #include
13 | #include
14 | #include "globals.h"
15 |
16 | /*-----------------------Low Freq LowPower TIME OUT DELAY--------------------*/
17 | #define RTC_15s 0xF000//15s when senseDelay is 1
18 | #define RTC_5s 0x5000//5s when senseDelay is 1
19 | #define RTC_2s 0x2000
20 | #define RTC_3s 0x3000
21 |
22 | #define senseDelay 1//4 //Set to larger value if we need more delay
23 | #define TIMEOUT_COUNTS 100
24 | #define TIMEOUT_10MS 328
25 | #define TIMEOUT_20MS 654
26 | #define TIMEOUT_5MS 164
27 | #define TIMEOUT_240uS 8
28 | #define lowPowerSleep_30us 2
29 | #define lowPowerSleep_10MS 333
30 | #define lowPowerSleep_5MS 165
31 | #define lowPowerSleep_1MS 33
32 |
33 | /*-----------------------High Freq CLCK LowPower DELAY--------------------*/
34 | /**********************************
35 | * Constant used in delay_us()
36 | * num of 13.56Mhz/8 cycles
37 | **********************************/
38 | #define T_5us 0x0A
39 | #define T_10us 18
40 | #define T_25us 0x2C
41 | #define T_30us 0x34
42 | #define T_35us 64
43 | #define T_40us T_10us*4
44 | #define T_50us 90
45 | #define T_100us T_10us*10
46 | #define T_500us T_100us*5
47 | /*
48 | #define T_1ms 0x6A4
49 | #define T_5ms 0x2134
50 | #define T_10ms 0x4268
51 | #define T_25ms 0xA604
52 | #define T_20ms 0x84D0
53 | */
54 | /**********************************
55 | * Constant used in long_delay_ms()
56 | * num of T_20ms cycles
57 | **********************************/
58 | /*
59 | #define T_40ms 0x02
60 | #define T_120ms 0x06
61 | #define T_240ms 0x0C
62 | */
63 | /**********************************
64 | * Constant used in lowPowerSleep()
65 | * for 32K CLK
66 | **********************************/
67 | #define LPM_50us 0x3
68 | #define LPM_500us 0x12
69 | #define LPM_1ms 0x23
70 | #define LPM_3ms LPM_1ms*3
71 | #define LPM_4ms LPM_1ms*4
72 | #define LPM_5ms 0xA5
73 | #define LPM_10ms LPM_5ms*2
74 | #define LPM_20ms 0x294
75 | #define LPM_25ms LPM_5ms*5
76 | #define LPM_40ms 0x520
77 | #define LPM_80ms 0x520*2
78 | #define LPM_120ms LPM_40ms*3
79 | #define LPM_240ms LPM_40ms*6
80 |
81 |
82 |
83 |
84 | //extern unsigned long timeout_ctr;
85 | //extern uint8_t led_pulse_flags; // Flags indicating which LED to pulse in the timer ISR
86 | //extern uint8_t isDoingLowPwrSleep;
87 | extern uint8_t volatile doNFC_state; //Flags used for TimerA0 when receive command
88 | extern uint8_t volatile imageUpdateState;
89 | unsigned int timeout_occurred(void) ;
90 | void timeout_init(uint16_t time) ;
91 | void lowPowerSleep (uint16_t duration);
92 | void long_lowPowerSleep (uint16_t duration);
93 | void timeout_halt(void);
94 | void delay_us(uint16_t delay);
95 | void initRTC(uint16_t time);
96 | void ACLK_on(void);
97 | #endif /* TIMER_H_ */
98 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-img-update-demo/main.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file main.c
3 | *
4 | * @brief Main structure for NFC WISP application
5 | *
6 | * @details The demo is designed to configure NFC-WISP as ISO-14443B tag,
7 | * and update the E-ink display.
8 | * User application can be modified in UserApp/myApp.c
9 | * User E-ink App can be modified in UserApp/myE-apperApp.c
10 | * NFC protocol in NFC_protocol can be modified if needed.
11 | *
12 | * @note NFC WISP Tag can be read by Nexus S, Nexus 5, Samsung Galaxy S4
13 | * But the E-ink image updates only works on Nexus S (API 19).
14 | * We do not use FRAM in this version
15 | *
16 | * @note Must set debuger voltage to be 2.5V(2500) when debuging the board,
17 | * otherwise, some periferial may not work correctly!
18 | * @author Eve (Yi Zhao) - Sensor Systems Lab (UW)
19 | * @date 09/29/2014
20 | * @TODO Impelment ISO_15693
21 | *****************************************************************************/
22 |
23 | //=============================================================================
24 | // Includes
25 | //=============================================================================
26 | // we will use ISO 14443B
27 | //#define _15693_1of256 //havenet implement it yet
28 |
29 | #include "common/globals.h"
30 | #include "NFC_protocol/doNFC.h"
31 | #include "common/e-paper.h"
32 | #include "common/fram_memory.h"
33 | #include "common/accel.h"
34 | #include "UserApp/myApp.h"
35 |
36 | /**
37 | * Main loop for application.
38 | */
39 | int16_t main(void) {
40 | // Initialize MSP430 and peripherals
41 | //already done in _system_pre_init.c;
42 |
43 | // Initialize the RFID subsystem
44 | initRFID();
45 |
46 | // Initialize the EPD subsystem (optional)
47 | initEPD();
48 |
49 |
50 | // Set up SPI and baud rate the ACCEL SPI clk are recommand as 1MHz~ 5 MHz
51 | SPI_initialize();
52 |
53 | //Put FRAM memory module into sleep, must wait at least for 1ms after whole chip power-up
54 | initFRAM();
55 |
56 | // Initialize the Accelerometer must wait at least for 5ms after whole chip power-up
57 | initACCEL();
58 | // ACCEL_standby(); //Put ACCEL into sleep mode if not use
59 |
60 | //User App initial
61 | //initMyDemo1(); //temperature/acceleration dataLoggor demo
62 | initMyDemo2(); //E-ink display update demo
63 |
64 | while (1) {
65 | #ifdef _15693_1of256
66 | doRFID_15693();
67 | #else
68 |
69 | /******************NFC and custermized App handle routine********************
70 | * doNFC(), system will goto sleep if no NFC signal
71 | * and will wakeup if there is interrupt
72 | * **************************************************************************/
73 | doNFC();
74 |
75 | /******************Sensing handle routine************************************/
76 |
77 | /**
78 | * Temerature and Movement logger demo,
79 | * @note temperature offset in different
80 | * PCB is diffenrent, need to be manually adjust in tempSense.c
81 | * line #56 IntDegC = ((temp*93)>>4)-2650; //2860 is the offset for board 2
82 | */
83 | //Demo1();
84 |
85 |
86 | /**
87 | * Updating E-ink screen with/withou battery using Nexus S and Andriod readerApp1.0 app
88 | */
89 | Demo2();
90 | #endif
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.ccsproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.gitignore:
--------------------------------------------------------------------------------
1 | Debug
2 | BUILD_E_INK_2.7_BATT
3 | BUILD_E_INK_2.0_BATT
4 | BUILD_E_INK_2.0_BATT_FREE
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.launches/nfc-eink-img-update-demo.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.launches/nfc-eink-imgUpdater-demo.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.launches/nfc-eink-temp-accel-data-logger-demo.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | nfc-eink-temp-accel-data-logger-demo
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 |
11 |
12 | ?name?
13 |
14 |
15 |
16 | org.eclipse.cdt.make.core.append_environment
17 | true
18 |
19 |
20 | org.eclipse.cdt.make.core.autoBuildTarget
21 | all
22 |
23 |
24 | org.eclipse.cdt.make.core.buildArguments
25 | -k
26 |
27 |
28 | org.eclipse.cdt.make.core.buildCommand
29 | ${CCS_UTILS_DIR}/bin/gmake
30 |
31 |
32 | org.eclipse.cdt.make.core.buildLocation
33 | ${workspace_loc:/nfc-eink-demo/Debug}
34 |
35 |
36 | org.eclipse.cdt.make.core.cleanBuildTarget
37 | clean
38 |
39 |
40 | org.eclipse.cdt.make.core.contents
41 | org.eclipse.cdt.make.core.activeConfigSettings
42 |
43 |
44 | org.eclipse.cdt.make.core.enableAutoBuild
45 | true
46 |
47 |
48 | org.eclipse.cdt.make.core.enableCleanBuild
49 | true
50 |
51 |
52 | org.eclipse.cdt.make.core.enableFullBuild
53 | true
54 |
55 |
56 | org.eclipse.cdt.make.core.fullBuildTarget
57 | all
58 |
59 |
60 | org.eclipse.cdt.make.core.stopOnError
61 | true
62 |
63 |
64 | org.eclipse.cdt.make.core.useDefaultBuildCmd
65 | true
66 |
67 |
68 |
69 |
70 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
71 | full,incremental,
72 |
73 |
74 |
75 |
76 |
77 | com.ti.ccstudio.core.ccsNature
78 | org.eclipse.cdt.core.cnature
79 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
80 | org.eclipse.cdt.core.ccnature
81 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
82 |
83 |
84 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.settings/org.eclipse.cdt.codan.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | inEditor=false
3 | onBuild=false
4 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.settings/org.eclipse.cdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1020810214.340259034/append=true
3 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1020810214.340259034/appendContributed=true
4 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1025076629/append=true
5 | environment/project/com.ti.ccstudio.buildDefinitions.MSP430.Debug.1025076629/appendContributed=true
6 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.settings/org.eclipse.cdt.debug.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker
3 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//BUILD_E_INK_2.7_BATT/NFC_protocol/subdir_rules.mk=UTF-8
3 | encoding//BUILD_E_INK_2.7_BATT/NFC_protocol/subdir_vars.mk=UTF-8
4 | encoding//BUILD_E_INK_2.7_BATT/UserApp/subdir_rules.mk=UTF-8
5 | encoding//BUILD_E_INK_2.7_BATT/UserApp/subdir_vars.mk=UTF-8
6 | encoding//BUILD_E_INK_2.7_BATT/common/subdir_rules.mk=UTF-8
7 | encoding//BUILD_E_INK_2.7_BATT/common/subdir_vars.mk=UTF-8
8 | encoding//BUILD_E_INK_2.7_BATT/makefile=UTF-8
9 | encoding//BUILD_E_INK_2.7_BATT/objects.mk=UTF-8
10 | encoding//BUILD_E_INK_2.7_BATT/sources.mk=UTF-8
11 | encoding//BUILD_E_INK_2.7_BATT/subdir_rules.mk=UTF-8
12 | encoding//BUILD_E_INK_2.7_BATT/subdir_vars.mk=UTF-8
13 | encoding//Debug/NFC_protocol/subdir_rules.mk=UTF-8
14 | encoding//Debug/NFC_protocol/subdir_vars.mk=UTF-8
15 | encoding//Debug/UserApp/subdir_rules.mk=UTF-8
16 | encoding//Debug/UserApp/subdir_vars.mk=UTF-8
17 | encoding//Debug/common/subdir_rules.mk=UTF-8
18 | encoding//Debug/common/subdir_vars.mk=UTF-8
19 | encoding//Debug/makefile=UTF-8
20 | encoding//Debug/objects.mk=UTF-8
21 | encoding//Debug/sources.mk=UTF-8
22 | encoding//Debug/subdir_rules.mk=UTF-8
23 | encoding//Debug/subdir_vars.mk=UTF-8
24 | encoding//common/e-paper.h=UTF-8
25 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/MSP430F5310.ccxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/15693_Protocol.c:
--------------------------------------------------------------------------------
1 | /*
2 | * protocol.c
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy Gummeson, Derek Thrasher
6 | */
7 |
8 | #include "15693_Protocol.h"
9 | //#include "globals.h"
10 |
11 |
12 |
13 | //Derek Thrasher
14 | //mask_length and AFI not currently being used for anything
15 | unsigned char *mask_length;
16 | unsigned char *AFI;
17 | unsigned char mask_value[8];
18 |
19 | //Can do away with both of these and just assign transmitCommand a value straight from receiveCommand...
20 | unsigned char response_flags;
21 | unsigned char DSFID; //Data Storage Format ID
22 |
23 | uint8_t read_command_number;
24 |
25 | uint16_t VICC_state;
26 | uint16_t process_request_flag;
27 |
28 | void initialize_15693_protocol()
29 | {
30 | uid[0] = 0xFE;
31 | uid[1] = 0xDC;
32 | uid[2] = 0xBA;
33 | uid[3] = 0x98;
34 | uid[4] = 0x76;
35 | uid[5] = 0x54;
36 | uid[6] = 0x32;
37 | uid[7] = 0x10;
38 |
39 | VICC_state = 0x0001;
40 | process_request_flag = 0;
41 | read_command_number = 0;
42 | }
43 |
44 | //used by protocol to see if the reader sent command is targeting us
45 | uint16_t uid_is_match(uint16_t start){
46 | uint8_t i;
47 | //start = the first byte position of uid in receiveCommand
48 | for(i=0 ; i<8 ; i++){
49 | if(uid[i] != receiveCommand[i+start]){
50 | //UIDs do NOT match
51 | return 0x0000;
52 | }
53 | }
54 | //UID Match
55 | return 0x0001;
56 | }
57 |
58 | /*Partial implementation of the 15693 Protocol Logic*/
59 | /**
60 | bitCount is the number of valid bits in the receiveCommand array [guaranteed to be >0]
61 | user should update the following:
62 | transmitCommand[] << data to be sent, index 0 is least significant word
63 | numberOfBits << number of bits out of the command array to send (when set to 0:
64 | cyclesToDelay does not need to be set)
65 | cyclesToDelay << number of cycles to delay after the last rising edge of received
66 | data
67 | NOTE: as numberOfBits increases, the amount of time available to the user decreases
68 | worst case: ~25 cycles/bit, best case: ~15 cycles/bit (includes all edges beyond
69 | beyond the start bit)
70 | NOTE: if the user's computation requires more time than the requested delay, data will
71 | not be sent as the reader may or may not acknowledge the command
72 | */
73 | void _15693_protocol(){
74 | // The PICC can be in 4 states
75 | // Power-Off / Ready / Quiet / Selected
76 | //State= 0 / 1 / 2 / 3
77 |
78 | uint8_t i;
79 |
80 | uint8_t index;
81 |
82 | index = 0;//initialize index so it can be used in dynamic responses
83 | numberOfBits = 0;
84 |
85 | if(receiveCommand[1]==0x01)
86 | {
87 | response_flags = 0x00; //no error, no protocol format extension
88 | DSFID = 0x00; //VICC programming not supported
89 | transmitCommand[index++] = response_flags;
90 | transmitCommand[index++] = DSFID;
91 | for(i=0 ; i<8 ; i++){
92 | transmitCommand[index++] = uid[i];
93 | }
94 | numberOfBits = index*8;
95 | }
96 |
97 |
98 | //single block write
99 | else if(receiveCommand[1] == 0x21)
100 | {
101 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3];
102 | cat_2_7_bits[image_byte_counter++] = receiveCommand[4];
103 | cat_2_7_bits[image_byte_counter++] = receiveCommand[5];
104 | cat_2_7_bits[image_byte_counter++] = receiveCommand[6];
105 | response_flags = 0x00; //no error, no protocol format extension
106 | DSFID = 0x00; //VICC programming not supported
107 | transmitCommand[index++] = response_flags;
108 | transmitCommand[index++] = DSFID;
109 | numberOfBits = index*8;
110 | toggle_debug();
111 | }
112 |
113 | else if(receiveCommand[1] == 0x24)
114 | {
115 | int i;
116 | int j = (receiveCommand[2]+1);
117 | j=j*4;
118 | for(i = 0 ; i < j ; i++)
119 | {
120 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3+i];
121 | }
122 | /*
123 | cat_2_7_bits[image_byte_counter++] = receiveCommand[3];
124 | cat_2_7_bits[image_byte_counter++] = receiveCommand[4];
125 | cat_2_7_bits[image_byte_counter++] = receiveCommand[5];
126 | cat_2_7_bits[image_byte_counter++] = receiveCommand[6];
127 | cat_2_7_bits[image_byte_counter++] = receiveCommand[7];
128 | cat_2_7_bits[image_byte_counter++] = receiveCommand[8];
129 | cat_2_7_bits[image_byte_counter++] = receiveCommand[9];
130 | cat_2_7_bits[image_byte_counter++] = receiveCommand[10];
131 | */
132 | response_flags = 0x00; //no error, no protocol format extension
133 | DSFID = 0x00; //VICC programming not supported
134 | transmitCommand[index++] = response_flags;
135 | transmitCommand[index++] = DSFID;
136 | numberOfBits = index*8;
137 | }
138 |
139 |
140 | hw_crc_ccitt(&transmitCommand[0], index);
141 | numberOfBits = numberOfBits + 16;
142 | /*
143 | if(numberOfBits){
144 | if(receiveCommand[1] == 0x01)
145 | {
146 | //generate_crc(transmitCommand, numberOfBits);
147 | transmitCommand[10] = 0x21; //precomputed CRC Byte #2
148 | transmitCommand[11] = 0xBE; //precomputed CRC Byte #2
149 | numberOfBits = numberOfBits +16;
150 | }
151 |
152 | else if((receiveCommand[1] == 0x21) || (receiveCommand[1] == 0x24))
153 | {
154 | transmitCommand[2] = 0x47; //precomputed CRC Byte #2
155 | transmitCommand[3] = 0x0F; //precomputed CRC Byte #2
156 | numberOfBits = numberOfBits +16;
157 | //numberOfBits = 0;
158 | }
159 | }
160 | */
161 | return;
162 | }
163 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/15693_Protocol.h:
--------------------------------------------------------------------------------
1 | /*
2 | * protocol.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy
6 | */
7 |
8 | #ifndef PROTOCOL_H_
9 | #define PROTOCOL_H_
10 |
11 | //globals
12 | #include
13 | #include "msp430f5310.h"
14 | #include "send_hdr.h"
15 | #include "1outof256.h"
16 | #include "crc_checker.h"
17 | #include "../common/globals.h"
18 |
19 |
20 | #ifdef _15693_1of256
21 | #define UID_SIZE 8
22 | #else
23 | #define UID_SIZE 4 //size of PUPI
24 | #endif
25 |
26 | extern uint16_t numberOfBits; //number of bits to transmit
27 | extern unsigned char receiveCommand[RECEIVE_BUF_SIZE]; //received command
28 | extern unsigned char transmitCommand[CMD_BUF_SIZE];
29 | extern unsigned char uid[UID_SIZE];
30 |
31 | extern uint8_t cat_2_7_bits[E_INK_SIZE];
32 | extern uint8_t command_number;
33 | extern uint16_t image_byte_counter;
34 |
35 | //function prototypes
36 | void _15693_protocol(void);
37 | uint16_t uid_is_match(uint16_t);
38 | void initialize_15693_protocol(void);
39 |
40 | #endif /* PROTOCOL_H_ */
41 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/1outof256.h:
--------------------------------------------------------------------------------
1 | /*
2 | * 1outof256.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy
6 | */
7 |
8 | #ifndef ONE_OUT_OF_TWO_FIFTY_SIX_H_
9 | #define ONE_OUT_OF_TWO_FIFTY_SIX_H_
10 |
11 | #include
12 | #include "../common/globals.h"
13 | #include "doNFC.h"
14 |
15 | //receiver state machine constants
16 | #define FINDING_DELIMITER 0
17 | #define PROCESSING_BYTES 1
18 |
19 | //static buffer sizes
20 | #define RECEIVE_BUF_SIZE 40
21 | #define NUM_COMMANDS 15
22 | #define DATA_BUF_SIZE 64
23 |
24 |
25 | //PROTOCOL CONSTANTS
26 | //Protocol timeout. This is equal to 2 1outof256 byte times. If receiving a valid fr ame, the next byte pulse should always arrive before this timeout value.
27 | //Longest valid time is 0x00 followed by 0xff, which is 1 slot shorter than 2 byte times.
28 | //#define TIMEOUT 16386 //more than two byte times worth of timer ticks (2*4.833 ms @ 13.56 MHz / 8).
29 | #define SOF_WIDTH 112 // nominal number of timer ticks for the start of frame delimiter
30 | #define SOF_DELTA 1 //will tolerate this many ticks deviation from nominal value
31 |
32 | #define TICKS_PER_SLOT 32 //There are 32 (13.56/8)MHz clock ticks per bit period
33 | #define TICKS_PER_BYTE (TICKS_PER_SLOT * 256)
34 |
35 | #define SOF_LOW (SOF_WIDTH - SOF_DELTA)
36 | #define SOF_HIGH (SOF_WIDTH + SOF_DELTA)
37 |
38 | #define EOF_SLOT_POSITION 2 //splitting a byte into 512 slots, the EOF will always occupy the 3rd slot (index 2). This should never be true for 0x01 (4th slot)
39 |
40 | //The galaxy nexus sends 0x26 as the first byte containing flags.
41 | //There might be more definitions here for different readers
42 | #define NEXUS_FLAGS 0x26
43 |
44 | //Change this guy to a particular reader
45 | #define FLAGS NEXUS_FLAGS
46 |
47 | //minimum length of a 15693 message (including CRC)
48 | #define MIN_VALID_LENGTH 5
49 |
50 | //from main.c and other header file
51 | //extern uint8_t num_frame_bytes;
52 | extern uint8_t pending_captures;
53 | extern unsigned int numReceivedMessages;
54 | extern unsigned char receiveCommand[RECEIVE_BUF_SIZE]; //received command
55 |
56 | void initialize_1outof256(void);
57 |
58 | //this function processes outstanding 1 out of 256 pulses.
59 | void process_bits(void);
60 |
61 |
62 | #endif /* 1OUTOF256_H_ */
63 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/_14443_B.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * 14443_B.c
3 | *
4 | * @date May 31, 2013
5 | * @author Derek Thrasher (UMass Amherst)
6 | ******************************************************************************/
7 |
8 | #include "_14443_B.h"
9 |
10 | uint8_t validRx=0;
11 |
12 | //************************************************************************************************************
13 | /* @func if detect delimiter within Five ETU(5*9.3us) then decode data otherwise wake up
14 | * @note doNFC_state=1 is set in sleep_untill_read
15 | *************************************************************************************************************/
16 | unsigned short doNFC_Rx(void){
17 | //----//
18 | // TODO Are we intending to clear particular other bits in RX_IE and RX_IES?
19 | // !!!-Comm's doesn't work when we DON'T clear the other bits... why not?
20 | // RX comparator on
21 | Enable_Rx();
22 | //toggle_led_2();
23 | validRx = 0;//reset in RX_WAKEUP ISR
24 | delay_us(T_35us); //let RX comparator stable, because sometimes there is a noise when enable rx comparator
25 | doNFC_state = NFC_Rx0; //Flag is Rx,used for measure the EOF
26 | RX_IE |= RX_BIT;
27 | //toggle_led_1();
28 | /*test delimiter, if find set the timeout and wait for rx data*/
29 | TA0CCR0 = FIVE_PULSES;//timeout should larger than 22.2us
30 | TA0CCTL0 = CCIE;
31 | TA0CTL = TASSEL_2 + MC_2+ ID_3 + TACLR; // time the delimiter length and then used for send_bpsk
32 | __bis_SR_register(LPM3_bits | GIE);
33 | TA0CTL = 0;
34 | Disable_Rx();
35 | TA0CCTL0 = 0; //Disable CCIE and TA0CCR0
36 |
37 | //toggle_led_1();
38 | //doNFC_state = 0;
39 | return validRx;
40 | }
41 |
42 |
43 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/_14443_B.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************************
2 | * _14443_B.h
3 | *
4 | * @date May 31, 2013
5 | * @author Eve(Yi Zhao), Sensor Systems Lab, UW
6 | * Derek Thrasher
7 | **************************************************************************************/
8 | #ifndef _B_H
9 | #define _B_H
10 |
11 |
12 | //=======================================================================================
13 | // Includes
14 | //=======================================================================================
15 | #include "../common/globals.h"
16 |
17 | //for 6.78Mhz clock
18 | #ifdef _15693_1of256
19 | #define TIME_OUT 90
20 | #else
21 | #define TIME_OUT 196
22 | #endif
23 |
24 |
25 | //for NFC_rev1.0, the SOF is 45us
26 | //#define SOF 115
27 | //#define Dt 8 //10/time tolerance +/-
28 | #define Dt 10 //10/time tolerance +/-
29 | #define zDt 8 //extra tolerance for zero
30 | #define ErrDt 15 //Dt+Dt/2
31 | #define SOB 11 //start bit
32 | #define ONE_PULSES 13 //7.6us~11.2us 16-/+3
33 | #define TWO_PULSES 29 //17.1~20.6us 32-/+3
34 | #define THREE_PULSES 45 //26.54~30.08us 48-/+3
35 | #define FOUR_PULSES 61 //35.98~39.08us 64-/+3
36 | #define FIVE_PULSES 77 //45.42~48.9us 80-/+3
37 | #define SIX_PULSES 93 //54.86~58.4us 96-/+3
38 | #define SEVEN_PULSES 109 //64.3~67.8.9us 112-/+3
39 | #define EIGHT_PULSES 125 //73.7~77.2us 128-/+3
40 | #define NINE_PULSES 141 //83.1~86.7us 144-/+3
41 | #define TEN_PULSES 157 //92.6~96.16us 160-/+3
42 | #define ELEVEN_PULSES 173 //102.0~105.6us 176-/+3
43 | #define SOF 19 //@note: from 22 to 8 at leaset 18us should change depending differenct range
44 | #define TIMEOUT ELEVEN_PULSES
45 | #define EOF 175
46 | //#define SOF 180;
47 |
48 | //=======================================================================================
49 | // Micros
50 | //=======================================================================================
51 | #define Enable_Rx() \
52 | RX_ENABLE_OUT |= RX_ENABLE_BIT; \
53 | RX_ENABLE_DIR |= RX_ENABLE_BIT; \
54 | RX_IES &= ~RX_BIT; //detect rising edge
55 |
56 | #define Disable_Rx() \
57 | RX_ENABLE_DIR &= ~RX_ENABLE_BIT; \
58 | RX_IE &= ~RX_BIT; \
59 | RX_IFG &= ~RX_BIT;
60 | //RX_ENABLE_DIR &= ~RX_ENABLE_BIT; \
61 | //RX_ENABLE_OUT &= ~RX_ENABLE_BIT; \
62 |
63 | //=======================================================================================
64 | // External variable
65 | //=======================================================================================
66 | //extern uint8_t _14443_buf_ptr = 0;
67 | extern uint8_t validRx;
68 | extern uint8_t rx_buffer[CMD_BUF_SIZE];
69 | extern uint8_t _14443_buf_ptr;
70 | extern uint8_t volatile doNFC_state;
71 |
72 | //=======================================================================================
73 | // External functions
74 | //=======================================================================================
75 | unsigned short doNFC_Rx(void);
76 |
77 |
78 | #endif /* 14443_B_H_ */
79 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/_14443_B_protocol.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wisp/nfc-wisp-fw/d8a9c55edbdaff62484961dc6eac6d66843e4d02/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/_14443_B_protocol.c
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/_14443_B_protocol.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * _14443_B_protocol.h
3 | *
4 | * @date April 5, 2014
5 | * @author Eve(Yi Zhao), Sensor Systems Lab, UW
6 | * Derek Thrasher
7 | ******************************************************************************/
8 |
9 | #ifndef _14443_B_PROTOCOL_H_
10 | #define _14443_B_PROTOCOL_H_
11 |
12 | //globals
13 | #include "_14443_B.h"
14 | #include
15 |
16 | #define CID_Enable BIT0
17 | #define CID_Disable 0
18 |
19 | extern unsigned int numberOfBitsTX; //number of bits to transmit
20 | extern uint8_t uid[UID_SIZE];
21 | extern uint8_t _14443_buf_ptr;
22 | extern uint8_t rx_buffer[CMD_BUF_SIZE];
23 | extern uint8_t transmitCommand[CMD_BUF_SIZE];
24 |
25 | //extern unsigned char imageBuffer[E_INK_SIZE];
26 | //extern unsigned char imageBuffer[2];
27 | extern unsigned char command_number;
28 | extern unsigned int imageBytesReceived;
29 |
30 | //function prototypes
31 | void initialize_14443_B_protocol(void);
32 | uint8_t _14443_B_protocol(uint8_t numb_bytes);
33 | uint8_t uid_is_match(unsigned int);
34 | unsigned int add_pupi(unsigned int start);
35 | void toggle_block_number(void);
36 | #endif /* PROTOCOL_H_ */
37 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/crc_checker.c:
--------------------------------------------------------------------------------
1 | /*
2 | * crc_checker.c
3 | *
4 | * Created on: Jan 8, 2013
5 | * Author: Derek Thrasher (UMass Amherst)
6 | */
7 |
8 | #include
9 | #include
10 | #include "crc_checker.h"
11 |
12 | #define POLYNOMIAL 0x8408 // x^16 + x^12 + x^5 + 1
13 | #define PRESET_VALUE 0xFFFF
14 | #define CHECK_VALUE 0xF0B8
15 | //#define NUMBER_OF_BYTES 4 // Example: 4 data bytes
16 | //#define CALC_CRC 1
17 | //#define CHECK_CRC 0
18 |
19 |
20 |
21 | /*
22 | //returns 1 is data is correct
23 | uint8_t validate_crc(unsigned char* receive_array, uint8_t number_of_bytes){
24 | unsigned int current_crc_value = PRESET_VALUE;
25 | int i, j;
26 | for (i = 0; i < number_of_bytes; i++){
27 | current_crc_value = current_crc_value ^ ((unsigned int)receive_array[i]);
28 | for (j = 0; j < 8; j++){
29 | if (current_crc_value & 0x0001){
30 | current_crc_value = (current_crc_value >> 1) ^ POLYNOMIAL;
31 | }
32 | else{
33 | current_crc_value = (current_crc_value >> 1);
34 | }
35 | }
36 | }
37 |
38 | if (current_crc_value == CHECK_VALUE){
39 | //printf ("Checked CRC is ok (0x%04X)\n", current_crc_value);
40 | return (number_of_bytes - 0x02);
41 | }else{
42 | //printf ("Checked CRC is NOT ok (0x%04X)\n", current_crc_value);
43 | return 0x00;
44 | }
45 | }
46 |
47 | unsigned int generate_crc(unsigned char* transmitCommand, uint16_t numberOfBits){
48 | unsigned int current_crc_value = PRESET_VALUE;
49 | int i, j;
50 | unsigned char number_of_bytes = numberOfBits/8;
51 | numberOfBits = numberOfBits + 16;
52 | for (i = 0; i < number_of_bytes; i++){
53 | current_crc_value = current_crc_value ^ ((unsigned int)transmitCommand[i]);
54 | for (j = 0; j < 8; j++){
55 | if (current_crc_value & 0x0001){
56 | current_crc_value = (current_crc_value >> 1) ^ POLYNOMIAL;
57 | }
58 | else{
59 | current_crc_value = (current_crc_value >> 1);
60 | }
61 | }
62 | }
63 | current_crc_value = ~current_crc_value;
64 | transmitCommand[number_of_bytes] = current_crc_value & 0xFF;
65 | transmitCommand[number_of_bytes + 1] = (current_crc_value & 0xFF00)>>8;
66 | return 1;
67 | }
68 | */
69 |
70 |
71 | /**
72 | * Use the hardware CRC-CCITT module of the MSP430 to generate a CRC as
73 | * per ISO/IEC 13239 CRC16 specification used in ISO 15693. Generating
74 | * polynomial is 0x8408, preset value is 0xFFFF.
75 | *
76 | * CRC is appended to end of transmitCommand array.
77 | *
78 | * @author Aaron Parks
79 | */
80 | unsigned int hw_crc_ccitt(unsigned char* transmitCommand, unsigned int number_of_bytes) {
81 | // Preset CRC result as per ISO/IEC 13239
82 | CRCINIRES = 0xFFFF;
83 |
84 | // Iterate over transmitCommand array
85 | unsigned int crc_i;
86 | for(crc_i=0; crc_i
12 | unsigned char validate_crc(unsigned char* receive_array, unsigned char number_of_bytes);
13 | unsigned int generate_crc(unsigned char* transmitCommand, unsigned int numberOfBits);
14 | unsigned int hw_crc_ccitt(unsigned char* transmitCommand, unsigned int numberOfBits);
15 | unsigned int hw_crc_validate(unsigned char* receiveCommand, unsigned int numberOfBits);
16 |
17 | #endif /* CRC_CHECKER_H_ */
18 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/doNFC.h:
--------------------------------------------------------------------------------
1 | /*
2 | * doNFC.h
3 | *
4 | * Created on: Aug 22, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef DONFC_H_
9 | #define DONFC_H_
10 |
11 | //=======================================================================================
12 | // Includes
13 | //=======================================================================================
14 | //#include
15 | #include "../common/globals.h"
16 | #include "../UserApp/myApp.h"
17 | // TODO Get rid of ifdefs if possible
18 | #ifdef _15693_1of256
19 | #include "1outof256.h"
20 | #include "send_hdr.h"
21 | #include "15693_Protocol.h"
22 | #else
23 | #include "_14443_B_protocol.h"
24 | //#include "NFC_WISP_Protocol.h"
25 | //#include "send_bpsk.h"
26 | //#include "crc_checker.h"
27 | //include "_14443_B.h"
28 | #endif
29 |
30 | //=============================================================================
31 | // NFC Globals
32 | //=============================================================================
33 |
34 | //This stuff is totally global in nature. I'm not sure it belongs here. But here it is.
35 | //After the CRC is verified, this gets set to the number of bytes we received.
36 | extern uint8_t num_frame_bytes;
37 | extern uint8_t volatile doNFC_state;
38 | // TODO Get rid of ifdefs if possible
39 | #ifdef _15693_1of256
40 |
41 | extern uint8_t transmitCommand[CMD_BUF_SIZE];
42 |
43 | extern uint8_t uid[UID_SIZE]; /**< Byte array that stores the UID. Initialized by _15693_protocol.c. */
44 | extern unsigned int numReceivedMessages; /**< Number of messages received from a reader. Used to track image transfer progress. */
45 | extern uint8_t pending_captures; /**< Tracks pending captures for ISO_15693. This is the number of outstanding pulses to be processed. */
46 | extern unsigned int numberOfBitsTX; /**< Number of bits to transmit. Transmit function uses this to know how much of the buffer to send. */
47 | //unsigned int bit_count; //used which checking crc
48 |
49 | //externs
50 | extern unsigned int capture_buffer[CAPTURE_BUFFER_SIZE];
51 | extern uint8_t capture_buffer_write_index;
52 |
53 | extern uint8_t receiveCommand[RECEIVE_BUF_SIZE];//received command
54 | #else // otherwise assume 14443_B
55 | extern uint8_t _14443_buf_ptr; /**< 14443_rx buffer pointer. Points to the current buffer index of received buffer. */
56 | extern uint8_t rx_buffer[CMD_BUF_SIZE]; /**< 14443_B RX message buffer. Stores CMD_BUF_SIZE bytes. */
57 | extern uint8_t transmitCommand[CMD_BUF_SIZE]; /**< 14443_B TX message buffer. Stores CMD_BUF_SIZE bytes. */
58 | //extern uint8_t doNFC_state;
59 | extern uint8_t uid[UID_SIZE]; /**< Byte array that stores the PUPI. Initialized by _14443_B_protocol.c. */
60 |
61 | extern unsigned int numberOfBitsTX; /**< Number of bits to transmit. Transmit function uses this to know how much of the buffer to send. */
62 | #endif /* _15693_1of256 */
63 | //=============================================================================
64 | // Macros
65 | //=============================================================================
66 | // Setup interrupt on edges
67 | // 1 Falling edge wakeup, but it is actually rising edge for RX_WAKE_UP pin
68 | // 2 Enable interrupt
69 | #define enable_Rx_Wakeup() \
70 | RX_WAKEUP_EN_OUT |= RX_WAKEUP_EN_BIT; \
71 | RX_WAKEUP_EN_DIR |= RX_WAKEUP_EN_BIT; \
72 | lowPowerSleep(4); \
73 | RX_WAKEUP_IES &= ~RX_WAKEUP_BIT; \
74 | RX_WAKEUP_DIR &=~ RX_WAKEUP_BIT; \
75 | RX_WAKEUP_IFG = 0; \
76 | RX_WAKEUP_IE = RX_WAKEUP_BIT;
77 |
78 | // Disable Rx Wakeup and may start RX
79 | #define disable_Rx_Wakeup() \
80 | RX_WAKEUP_IE &= ~RX_WAKEUP_BIT; \
81 | RX_WAKEUP_EN_DIR &= ~RX_WAKEUP_EN_BIT; \
82 | RX_WAKEUP_IFG &= ~(RX_WAKEUP_BIT);
83 |
84 | #define Sleep_TimeOut 2000//2000*0.25ms = 0.5s
85 | #define tempSense_TimeOut 0xF000 //1s is 0x1000 15s is 0xF000
86 | //==============================================================================
87 | // Functions
88 | //==============================================================================
89 | void initRFID(void);
90 | //void doRFID_15693(void);
91 | //void doRFID_14443B(void);
92 | //void sleep_until_edges(void);
93 | //void sleep_until_read(void);
94 | void doNFC(void);
95 | #endif /* DONFC_H_ */
96 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/send_bpsk.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * send_bpsk.h
3 | *
4 | * @date June 5, 2013
5 | * @author Derek Thrasher (UMass Amherst)
6 | ******************************************************************************/
7 |
8 | #ifndef SEND_BPSK_H_
9 | #define SEND_BPSK_H_
10 |
11 | #include "../common/globals.h"
12 | //#include "../common/NFC_WISP_Rev1.0.h"
13 |
14 | //6.78Mhz where 1etu = 8clock pulses
15 | // TODO Get rid of ifdefs if possible
16 | #ifdef _6_78Mhz
17 | #define ONE_ETU 8
18 | #define TWO_ETU 16
19 | #define TEN_ETU 80
20 | #else
21 | #define ONE_ETU 16
22 | #define TWO_ETU 32
23 | #define TWO_ETU_SLEEP 22
24 | #define TEN_ETU 160//160
25 | #define TEN_ETU_SLEEP 150
26 | #endif
27 | //assembly constants used for send routine
28 | asm("SEND_BIT_MASK .set R6");
29 | asm("SEND_COMMAND .set R7");
30 | //asm("SEND_BIT_SIZE .set R6");
31 | asm("SEND_CURRENT_WORD .set R8");
32 | asm("SEND_BIT .set R12");
33 | //asm("SEND_BIT_COUNT .set R8");
34 |
35 | asm("TBCTL_ADR .set 0180h"); //timer control address
36 | asm("ASM_MC_1 .set 0010h"); //continuous mode bits
37 |
38 | //=============================================================================
39 | // Macros
40 | //=============================================================================
41 | //TB0CCR0 = 8; //upper bound compare
42 | //TB0CCR2 = 0; //lower bound compare
43 | //ensures that we will get a rising edge imediately
44 | #define ENABLE_PWM() \
45 | TB0R = 7; \
46 | TB0CCTL2 = OUTMOD_3; \
47 | TB0CTL = TBSSEL_2+MC_3; //SMCLK 13.56Mhz,pwm up/down mode
48 |
49 |
50 | #define DISABLE_PWM() TB0CTL = 0; //disable
51 |
52 |
53 | //********************************************************************************
54 | // Protocol Constants
55 | //********************************************************************************
56 | // TODO Get rid of ifdefs if possible
57 | #ifdef _6_78Mhz
58 | #define POST_RX_WAIT 64 //75.56 us@ 6.78 MHz / 8
59 | #else//13.56Mhz
60 | #define POST_RX_WAIT 128//128 //75.56 us@ 13.56 MHz / 8
61 | #endif
62 |
63 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
64 | void initialize_bpsk(void);
65 | void send_bpsk(void);
66 | void delay(uint16_t);
67 | void shift_mask();
68 | uint8_t next_bit();
69 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
70 | #endif /* SEND_LDR_H_ */
71 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/NFC_protocol/send_hdr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * send_hdr.h
3 | *
4 | * Created on: Mar 8, 2013
5 | * Author: Jeremy Gummeson
6 | */
7 |
8 | #ifndef SEND_LDR_H_
9 | #define SEND_LDR_H_
10 |
11 | #include "../common/globals.h"
12 |
13 |
14 |
15 | //assembly constants used for send routine
16 | asm("SEND_BIT_MASK .set R4");
17 | asm("SEND_COMMAND .set R5");
18 | asm("SEND_BIT_SIZE .set R6");
19 | asm("SEND_CURRENT_WORD .set R7");
20 | asm("SEND_BIT_COUNT .set R8");
21 |
22 | asm("TBCTL_ADR .set 0180h"); //timer control address
23 | asm("ASM_MC_1 .set 0010h"); //continuous mode bits
24 |
25 | //=============================================================================
26 | // Macros
27 | //=============================================================================
28 | #define ENABLE_PWM() TB0CTL |= MC_3;//asm(" BIS #ASM_MC_1, &TBCTL_ADR"); //asm(" BIS #0040h, &0186h"); asm(" NOP");//enable pwm
29 | #define DISABLE_PWM() TB0CTL &= ~MC_3;//asm(" BIC #ASM_MC_1, &TBCTL_ADR"); //asm(" BIS #0040h, &0186h");//asm(" MOV &TBR_ADR, R8"); //code does not work
30 |
31 |
32 | //********************************************************************************
33 | // Protocol Constants
34 | //********************************************************************************
35 | #define POST_RX_WAIT 510 //300 us@ 13.56 MHz / 8
36 | #define LONG_TX 96 //56.64 us @ 13.56 MHz / 8
37 | #define HALF_TX_PERIOD 31 //18.88 us @ 13.56 MHz / 8
38 |
39 | void initialize_hdr(void);
40 | void send(void);
41 | //void delay(uint16_t);
42 |
43 | #endif /* SEND_LDR_H_ */
44 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/myApp.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @fun Demo for Temperature/Acceleration display&logging
3 | * @author Yi Zhao(Eve)
4 | * @date -09/29/2014
5 | *****************************************************************************/
6 |
7 | //=============================================================================
8 | // Includes
9 | //=============================================================================
10 | #include "../common/globals.h"
11 | #include "../common/e-paper.h"
12 | #include "myE-paperApp.h"
13 | #include "tempSense.h"
14 | #include "img_data.h"
15 | #include "../common/accel.h"
16 | #include "myApp.h"
17 | #include
18 |
19 | //=============================================================================
20 | // E-paper Globals
21 | //=============================================================================
22 | //@note the imageBuffer now is 1 byte since we need more buffer for sense_buf
23 | //uint8_t imageBuffer[E_INK_SIZE]; // big array that stores all the display bits
24 | uint8_t sense_buf[BUF_SIZE];
25 | uint8_t* sense_buf_ptr;
26 | uint8_t* sense_read_ptr;
27 | uint8_t buf_full;
28 | uint16_t senseCtr;
29 | //=============================================================================
30 | // Globals
31 | //=============================================================================
32 | volatile unsigned long RTC_ctr;//real time clcok counter
33 | //uint8_t imageUpdateState;
34 | volatile uint8_t senseState;
35 | volatile uint8_t accelState;
36 |
37 |
38 | //=============================================================================
39 | // User App & Functions
40 | //=============================================================================
41 |
42 | /**
43 | * @fun initial real time clock for sampling temperature/accelerometer data
44 | * for temerature/accelerometer logger demo
45 | */
46 | void initMyDemo1(void){
47 |
48 | //Initialize the real time clock for sample sensor at given intervals
49 | initRTC(RTC_3s);
50 |
51 | //Initial sensing state machine
52 | imageUpdateState = IMG_UPDATE;
53 | //imageUpdateState = IMG_HALT;
54 |
55 | //inital senseng state and senseng data buffer
56 | accelState = 0;
57 | senseCtr=0;
58 | buf_full=0;
59 | sense_buf_ptr = &sense_buf[0];
60 | sense_read_ptr = &sense_buf[0];
61 | }
62 |
63 |
64 | /**
65 | * @fun initial imageUpdateState for image updates demo
66 | */
67 | void initMyDemo2(void){
68 | //TA1CTL = 0; //ACLK, upmode, 4khz clk
69 | //TA1CCTL0 &=~CCIE;
70 | //initRTC(RTC_15s);
71 | imageUpdateState = IMG_HALT;
72 | }
73 |
74 |
75 |
76 |
77 | /**
78 | * @fun temerature/accelerator logger and display demo
79 | * will not save sensor data into the buffer
80 | */
81 | void Demo1(void) {
82 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState)){
83 | updateDisplay1((uint8_t*)templete);
84 | imageUpdateState = IMG_HALT;
85 | }
86 | }
87 |
88 | /**
89 | * @fun image updates demo when response to cellphone
90 | * if it receive the whole image and update it
91 | * @note NFC-WISP Reader App 1.0 will sending dummy data for power
92 | * after finishing image transfer.
93 | * If you build *BUILD_E_INK_2_0_BATT_FREE*
94 | * we add more lowPowerSleep during E-ink updating to
95 | * reive more energy from cell-phone
96 | */
97 | void Demo2(void){
98 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState==IMG_UPDATE)||(imageUpdateState==IMG_FORCE_UPDATE)){
99 | //memset(imageBuffer,0,E_INK_SIZE);//Comment this line to save power
100 | #ifdef BATT_FREE
101 | lowPowerSleep(LPM_120ms);
102 | #endif
103 | updateDisplay2((uint8_t*)imageBuffer);
104 | #ifdef BATT_FREE
105 | lowPowerSleep(LPM_10ms);
106 | #endif
107 | imageUpdateState = IMG_HALT;
108 | }
109 | }
110 |
111 | /**
112 | * @fun temperature/acceleration data logger demo
113 | * save the sensor data to the buffer for reader to read
114 | * @note need to change sense_buf size for your application
115 | */
116 | void Demo3(void) {
117 |
118 | /****************Sensing handle routine 1 *********************************
119 | * @fun log sensor result to buffer when reading sensor result
120 | * put 4 byte accelerometer data into app[0]-[3]
121 | * put 4 byte temperature data into uid[0]-[3]
122 | * if write is full than sense_read_ptr then stop write
123 | * @note when use this demo, must modify the command response to transmit
124 | * sensor result to the uid or app buffer
125 | ***********************************************************************/
126 |
127 | if((doNFC_state==NFC_Sleep)&&(imageUpdateState)){
128 |
129 | //if sense_buf will be out of the range of queue
130 | if((sense_buf_ptr+8)>(&sense_buf[BUF_SIZE-1])){
131 | memset(sense_buf,0x00,&sense_buf[BUF_SIZE-1]-sense_buf_ptr+1);
132 | sense_buf_ptr=&sense_buf[0];
133 | buf_full++;
134 | }
135 |
136 | //if the queue is full, then do nothing
137 | if((sense_buf_ptr+8>sense_read_ptr)&&(buf_full>0)){
138 | asm("NOP");
139 | }else if(imageUpdateState){
140 | updateDisplay1((uint8_t*)templete);
141 | ACCEL_singleSample(sense_buf_ptr);
142 | sense_buf_ptr +=4;
143 | senseCtr++;
144 | }
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/myApp.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | ** myApp.h
3 | * @fun Demo for Temperature/Acceleration display&logging
4 | * @author Yi Zhao(Eve), Sensor System Lab,UW and Disney Research Pittsburgh
5 | * @date -09/29/2014
6 | *****************************************************************************/
7 | #ifndef MYAPP_H_
8 | #define MYAPP_H_
9 |
10 | //=============================================================================
11 | // Define
12 | //=============================================================================
13 | //Buffer if needed for data logger
14 | #define BUF_SIZE 2//2600//4000
15 |
16 | //=============================================================================
17 | // Micros
18 | //=============================================================================
19 | // We must disable sensor ISR in NFC rx&tx routine
20 | #warning "Must disable sensor interrupt here for different Usesr App\
21 | otherwise there is a conflict with NFC reading ISR"
22 | //implement "enable or disable custermized ISR" for UserApp
23 | #define disable_sensor_ISR() \
24 | TA1CCTL0 = 0;
25 | //ACCEL_INT1_IE &= ~ACCEL_INT1_BIT;
26 |
27 | #define enable_sensor_ISR() \
28 | TA1CCTL0 |= CCIE;
29 | //ACCEL_INT1_IE |= ACCEL_INT1_BIT;
30 |
31 |
32 | //=============================================================================
33 | // myApp Globals
34 | //=============================================================================
35 | extern uint8_t volatile doNFC_state;
36 | extern volatile unsigned long RTC_ctr;
37 | extern uint8_t volatile imageUpdateState;
38 | extern volatile uint8_t senseState;
39 | extern volatile uint8_t accelState;
40 | extern uint8_t sense_buf[BUF_SIZE];
41 | extern uint8_t* sense_buf_ptr;
42 | extern uint8_t* sense_read_ptr;
43 | extern uint8_t buf_full;
44 | extern uint16_t senseCtr;
45 | //extern const char[5808] templete;
46 |
47 | //=============================================================================
48 | // Function
49 | //=============================================================================
50 | void initMyDemo1(void);
51 | void initMyDemo2(void);
52 | void Demo1(void);
53 | void Demo2(void);
54 | void Demo3(void);
55 |
56 |
57 | #endif /* MYAPP_H_ */
58 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/myE-paperApp.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file myE-paperApp.c
3 | *
4 | * @brief Demo of customized E-paper update
5 | *
6 | * @details Use the E-paper driver in common/e-paper.h to determine how to
7 | * update the display line by line.
8 | *
9 | * @note More details about driver reference can be found
10 | * http://www.pervasivedisplays.com/products/27
11 | *
12 | * @author Eve (Yi Zhao) - Sensor Systems Lab (UW)
13 | * @date 09/29/2014
14 | *****************************************************************************/
15 | #include "../common/e-paper.h"
16 | #include "tempSense.h"
17 | #include "../common/globals.h"
18 | #include "../common/accel.h"
19 | #include "myE-paperApp.h"
20 |
21 | /**
22 | * @brief Update EPD display from image templete and display real time sensor data
23 | * @param imgPtr - the pointer pointed to the entry of image templete
24 | * @time EPD powerOn&Off takes around 325ms
25 | */
26 | uint8_t updateDisplay1(unsigned char* imagePtr){
27 |
28 | volatile resultData newData;
29 |
30 | //Sample temperature
31 | newData = tempSense();
32 |
33 | //Sample Accelerometer
34 | uint8_t st,value,indicator;
35 |
36 | ACCEL_Status(&st);
37 | if(((st&0xF0)==0x40)){
38 | value=0x00;
39 | indicator =4; //update motion indicator
40 | }else {
41 | value = 0xFF;
42 | if(indicator>0)indicator--;//reduce counter in order to stop indicator after refresh
43 | }
44 |
45 | //Update E-ink based on data
46 | if(EPD_power_init()==RES_OK){
47 |
48 | //Update E-ink frame
49 | if(imageUpdateState== IMG_UPDATE){
50 | EPD_frame_newImg(imagePtr,0,cog.lines_per_display);
51 | imageUpdateState = SENSE_UPDATE;
52 | senseState=0;
53 | }
54 |
55 | //Update motion indicator
56 | if(indicator)EPD_frame_singleDot(18,24,28,value);
57 |
58 | //Update temerature result in the plot
59 | EPD_frame_singleDot(newData.y,newData.y+1,newData.x,0xC3);
60 | return EPD_power_off();
61 | }
62 | return FAIL;
63 | }
64 |
65 |
66 | /**
67 | * @brief Update EPD display from imgBuffer
68 | * @param imgPtr - the pointer pointed to the start of updated content
69 | * @time EPD powerOn&Off takes around 325ms
70 | * @note imgBuffer is filled from NFC I-block reading in myNFC_protocol.c,
71 | * the updateDisplay2 is only be called when receive whole image
72 | * @note NFC-WISP Reader App 1.0 will sending dummy data for power
73 | * after finishing image transfer.
74 | * If you build *BUILD_E_INK_2_0_BATT_FREE*
75 | * we add more lowPowerSleep during E-ink updating to reive more energy from cell-phone
76 | */
77 |
78 | uint8_t updateDisplay2(unsigned char* imagePtr){
79 | //Update E-ink based on data
80 | if(EPD_power_init()==RES_OK){
81 |
82 | //Update E-ink frame
83 | if(imageUpdateState){
84 | EPD_frame_newImg(imagePtr,0,cog.lines_per_display);
85 | }
86 |
87 | return EPD_power_off();
88 | }
89 | return FAIL;
90 |
91 | //TODO:indicate end update
92 | //LED_2_BIT_auto_pulse();
93 | }
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/myE-paperApp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * myE-paperApp.h
3 | *
4 | * Created on: Mar 5, 2015
5 | * Author: yizhao
6 | */
7 |
8 | #ifndef MYE_PAPERAPP_H_
9 | #define MYE_PAPERAPP_H_
10 |
11 | uint8_t updateDisplay1(unsigned char* imagePtr); //Temerature/Accelerometer dataLogger demo
12 | uint8_t updateDisplay2(unsigned char* imagePtr); //E-ink display update demo
13 | #endif /* MYE_PAPERAPP_H_ */
14 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/myNFC_Protocol.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * myNFC_protocol.h
3 | * @brief: Higher Layer Application Response (INF) (to I-Block and \
4 | * decides how to fill in INF field of Response to ATTRIB)
5 | * @date: Aug 22, 2014
6 | * @author: Yi Zhao (Eve)-Sensor System Lab, UW
7 | * @note: Only Implement response in ISO 14443-B protocol here
8 | * @TODO: Test and Implement _15693_1of256 protocol
9 | ******************************************************************************/
10 |
11 | #ifndef MYNFC_PROTOCOL_H_
12 | #define MYNFC_WISP_PROTOCOL_H_
13 |
14 | //globals
15 | #include
16 | #include "msp430f5310.h"
17 | #include "../common/globals.h"
18 | #include "../NFC_protocol/crc_checker.h"
19 |
20 | extern unsigned char _14443_buf_ptr;
21 | //extern unsigned char rx_buffer[CMD_BUF_SIZE];
22 | //extern unsigned char transmitCommand[CMD_BUF_SIZE];
23 | //extern unsigned char imageBuffer[E_INK_SIZE];
24 | //extern unsigned char imageBuffer[2];
25 | extern unsigned char command_number;
26 | extern unsigned int imageBytesReceived;
27 |
28 | //function prototypes
29 | void initialize_nfc_wisp_protocol(void);
30 | uint8_t nfc_wisp_protocol(unsigned char * receiveCommand, unsigned char index);
31 | #endif /* NFC_WISP_PROTOCOL_H_ */
32 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/tempSense.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * tempSense.c
3 | * @breif temperature sensing funtion
4 | * @date 10/15/2014
5 | * @author Yi Zhao, Sensor Systems Lab,UW and Disney Research Pittsburgh
6 | * @note Vtemp=0.00252*Temp(C)+0.688, so -50~100(oC) result in 0.06~1v
7 | * ADC sample period is 75us(30 reference, 45 sampling)
8 | *****************************************************************************/
9 |
10 | //=============================================================================
11 | // Includes
12 | //=============================================================================
13 | #include "../common/globals.h"
14 | #include "tempSense.h"
15 | #include "../common/timer.h"
16 | #include "../common/e-paper.h"
17 |
18 | //=============================================================================
19 | // Variables
20 | //=============================================================================
21 | static volatile uint16_t temp;
22 |
23 | //=============================================================================
24 | // Functions
25 | //=============================================================================
26 | /**
27 | * @fun Sense temerator sensor in MSP430 (single ADC sampling)
28 | * @note Must fine tuning the offset of temerature sensor reading
29 | *
30 | */
31 | resultData tempSense(void){
32 | // uint16_t IntDegF;
33 | uint16_t volatile IntDegC;
34 | //uint16_t temp;
35 | resultData volatile data;
36 |
37 | REFCTL0 |= REFON | REFVSEL_0; //1.5v
38 |
39 | ADC10CTL0 |= ADC10SHT_3 | ADC10ON ;//64 sampling cycles=37us
40 | ADC10CTL1 |= ADC10DIV_7 |ADC10SSEL_3 |ADC10CONSEQ_0 |ADC10SHP;//SMCLK@13.56Mhz/8=1.69Hz
41 | //ADC10CTL2 |= ADC10SR;
42 | ADC10MCTL0 |= ADC10SREF_1 | ADC10INCH_10; //select temperature sensor
43 | ADC10IE = ADC10IE0;
44 | delay_us(T_30us);//delay at lease 25us for reference to be stable
45 | ADC10CTL0 |= ADC10ENC;
46 | ADC10CTL0 |= ADC10SC; //start sampling
47 | __bis_SR_register(LPM4_bits+GIE);
48 | ADC10CTL0 = 0;//stop ADC
49 | REFCTL0 &= ~REFON;
50 |
51 | // Temperature in Celsius
52 | //actual IntDegC = (temp*0.5819-273.0159)*10;
53 | //format is t*10+50oC*10+offest (the result will have 50oC offet)
54 | //IntDegC = ((temp*93)>>4)-2308-385;
55 | //(tempAverage - 630) * 761) / 1024 );
56 | data.ADC_data = temp;
57 |
58 | //data.y=176-(IntDegC>>1); //TEST:suppose detected range is half of the Y_range
59 |
60 | //Version: paper (large temp range)
61 | //IntDegC = ((temp*93)>>4)-2730;
62 | //data.y=Y_offset-(IntDegC>>2);//
63 |
64 | #warning "temerature offset in different board is different \
65 | must adjust it for your board here"
66 | IntDegC = ((temp*93)>>4)-2850; //2860 is the offset for some board , 2650 for other board
67 | data.y=Y_offset-(IntDegC>>1);//
68 |
69 | //data.x = senseState + X_start;
70 | data.x = senseState + 3;
71 |
72 | //TODO what should we do if the Y is out of the range
73 | if(!((Y_start=X_end){
77 | data.x= X_end;
78 | //TODO clear E-ink Display and redraw
79 | imageUpdateState=IMG_UPDATE;
80 | //temp = 0;
81 | senseState = X_end-1;
82 | }
83 | // Temperature in Fahrenheit
84 | //actual IntDegF = (temp*1.0474 - 241.0159)*10
85 | //format is t*10+1220
86 | //IntDegF = (temp*670)>>6 - 1910;
87 |
88 | return data;
89 | }
90 |
91 | //=============================================================================
92 | // ISR
93 | //=============================================================================
94 | #pragma vector=ADC10_VECTOR
95 | __interrupt void ADC10ISR (void)
96 | {
97 | if(ADC10IFG&ADC10IFG0){
98 | temp = ADC10MEM0;
99 | __bic_SR_register_on_exit(LPM4_bits); // Exit active CPU
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/UserApp/tempSense.h:
--------------------------------------------------------------------------------
1 | /*
2 | * temSense.h
3 | *
4 | * Created on: Nov 17, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef TEMPSENSE_H_
9 | #define TEMPSENSE_H_
10 |
11 | /* Screen range for 10~40 temperature range is:
12 | * (start from 0)
13 | * X= 28 (col3~col31,total is 0~32)
14 | * Y= 152 (line5~line156)
15 | */
16 |
17 | /*Version: Paper (large range)
18 | //test supporse temp range is half of the Y_range
19 | #define Y_start 7
20 | #define Y_end 156
21 | #define Y_range (Y_end - Y_start) //150 points *4= 600 can represent -10~50oC,
22 | #define Y_offset 123 //the y axis start from -10oC 156-102=54/27~26
23 | #define X_start 3
24 | #define X_end 31
25 | #define X_range (X_end - X_start)*8 //right now is 30 samples dot30*8=224 cycles suppose min
26 | */
27 |
28 |
29 | //Version: Demo (small temp range)
30 | //test supporse temp range is half of the Y_range
31 | #define Y_start 5
32 | #define Y_end 156
33 | #define Y_range (Y_end - Y_start+1) //152 *4= 608 can represent 10~40oC,
34 | #define Y_offset 206 //the y axis start from 10oC =156 + (10oC)=156 + 100/2 = 206
35 | #define X_start 3
36 | #define X_end 31
37 | #define X_range (X_end - X_start)*8 //right now is 30 samples dot30*8=224 cycles suppose min
38 | //*/
39 | typedef struct{
40 | uint8_t y; //lines number
41 | uint8_t x; //byte position in E-ink
42 | uint16_t ADC_data;
43 | //uint8_t value; // the image value
44 | }resultData;
45 |
46 | resultData tempSense(void);
47 | void updateSense(void);
48 | #endif /* TEMSENSE_H_ */
49 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/_system_pre_init.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * @file NFC_WISP_Rev1.0.c
3 | * @fun MSP430 _system_pre_init() and Interrupt Routine
4 | * @date 10/25/2014
5 | * @author Eve (Yi Zhao), Sensor systems Lab. UW
6 | * @notes note that the system_pre_init and interrupt vectors do not need \
7 | * definitions in the header files. This is because
8 | * compiler automatically links them.
9 | */
10 | /******************************************************************************/
11 |
12 |
13 | //=============================================================================
14 | // Includes
15 | //=============================================================================
16 | #include "globals.h"
17 | uint16_t bad_interrupts;
18 | //uint8_t isDoingLowPwrSleep;
19 |
20 | //=============================================================================
21 | // Functions
22 | //=============================================================================
23 | /**
24 | * @fcn void _system_pre_init (void)
25 | * @brief routine called by boot() right before main() is called.
26 | * @pre c_int00 was just called after a POR/PUC event
27 | * @post the RAM, clock and peripherals are initialized for use
28 | * @note ACLK,FLL is disabled in _system_pre_init, \
29 | * UCSCTL8 used to clear SMCLKREQEN,MCLKREQEN,ACLKREQEN \
30 | * if do not want in LPM
31 | */
32 | int _system_pre_init (void) {
33 |
34 | //--------------------Setup Watchdog, IO----------------------------------//
35 | WDTCTL = WDTPW + WDTHOLD; /* disable the watchdog timer -*/
36 | setupDflt_IO();
37 | _bic_SR_register(GIE); //Turn off GIE while we initialize.
38 | bad_interrupts = 0;
39 |
40 | //Turn LDO off
41 | LDOKEYPID = LDOKEY;
42 | LDOPWRCTL = 0x00;
43 | LDOKEYPID = 0;
44 |
45 | // Turn off high/low voltage supervisors
46 | PMMCTL0_H = PMMPW_H;
47 | SVSMHCTL &= ~(SVMHE+SVSHE);
48 | SVSMLCTL &= ~(SVMLE+SVSLE);
49 | PMMCTL0_H = 0x00;
50 |
51 | //---------------------------Setup Clock----------------------------------//
52 |
53 | // ACLK=REFO,SMCLK=DCO,MCLK=DCO During initialization
54 | UCSCTL4 |= SELA__REFOCLK + SELM__DCOCLK + SELS__DCOCLK;
55 | //turn off the FLL and ACLK since we do not use it at the very beginning
56 | //_BIS_SR(SCG0+OSCOFF); //@note: must keep ACLK on for timeout system
57 |
58 | UCSCTL6 &= ~XT2OFF; // Turn on XT2OFF
59 | //UCSCTL4 |= SELA_2; // ACLK=REFO,SMCLK=DCO,MCLK=DCO During initialization
60 | /*Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles*/
61 | do
62 | {
63 | UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG); // Clear XT2,XT1,DCO fault flags
64 | SFRIFG1 &= ~OFIFG; // Clear fault flags
65 | }while (SFRIFG1&OFIFG); // Test oscillator fault flag
66 |
67 | UCSCTL6 &= ~XT2DRIVE1; // Decrease XT2 Drive according to expected frequency
68 | UCSCTL4 |= SELS_5 | SELM_5 | SELA_0; // SMCLK=MCLK=XT2, ACLK=XT1,
69 | UCSCTL7 = 0; //clear fault flags
70 | return 0;
71 | }
72 |
73 |
74 |
75 |
76 | /**
77 | * Catch any bad interrupts to prevent them from resetting the CPU.
78 | * Keep count of all bad interrupts that occur.
79 | */
80 | #pragma vector=RTC_VECTOR
81 | #pragma vector=PORT2_VECTOR
82 | #pragma vector=TIMER2_A1_VECTOR
83 | #pragma vector= USCI_A1_VECTOR
84 | //#pragma vector=TIMER2_A0_VECTOR
85 | //#pragma vector=USCI_B1_VECTOR
86 | //#pragma vector=PORT1_VECTOR
87 | #pragma vector=TIMER1_A1_VECTOR
88 | //#pragma vector=TIMER1_A0_VECTOR
89 | #pragma vector=DMA_VECTOR
90 | #pragma vector=LDO_PWR_VECTOR
91 | #pragma vector=TIMER0_A1_VECTOR
92 | //#pragma vector=TIMER0_A0_VECTOR
93 | //#pragma vector=ADC10_VECTOR
94 | #pragma vector=USCI_B0_VECTOR
95 | #pragma vector=USCI_A0_VECTOR
96 | #pragma vector=WDT_VECTOR
97 | #pragma vector=TIMER0_B1_VECTOR
98 | #pragma vector=TIMER0_B0_VECTOR
99 | #pragma vector=COMP_B_VECTOR
100 | #pragma vector=UNMI_VECTOR
101 | #pragma vector=SYSNMI_VECTOR
102 | __interrupt void CATCH_ALL(void) {
103 | asm(" NOP");
104 | bad_interrupts++;
105 | }
106 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/accel.h:
--------------------------------------------------------------------------------
1 | /**
2 | * accel.h
3 | *
4 | * @date Aug 2013
5 | * @author Aaron Parks, Eve(Yi Zhao), Sensor Systems Lab, UW
6 | */
7 |
8 | #ifndef ACCEL_H_
9 | #define ACCEL_H_
10 |
11 | #include "globals.h"
12 |
13 | typedef struct {
14 | uint16_t x;
15 | uint16_t y;
16 | uint16_t z;
17 | } threeAxis_t;
18 |
19 | void initACCEL(void);
20 | void ACCEL_standby(void);
21 | BOOL ACCEL_Status(uint8_t* result);
22 | //BOOL ACCEL_satus(threeAxis_t* result);
23 | BOOL ACCEL_singleSample(uint8_t* result);
24 | BOOL ACCEL_Status(uint8_t* result);
25 | BOOL activity(uint8_t* preACC);
26 |
27 | //ACCEL I/O Macros
28 | #define ACCEL_Enable() \
29 | //;
30 | //POUT_EN_ACCEL |= PIN_ACCEL_CS; \
31 | //PDIR_EN_ACCEL |= PIN_ACCEL_CS;
32 | #define ACCEL_Disable() \
33 | ;
34 | //PDIR_EN_ACCEL &= ~PIN_EN_ACCEL + PIN_ACCEL_CS;
35 | #endif /* ACCEL_H_ */
36 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/accel_registers.h:
--------------------------------------------------------------------------------
1 | /**
2 | * accel_registers.h
3 | *
4 | * @date Aug 2014
5 | * @author Aaron Parks, Eve(Yi Zhao)
6 | */
7 |
8 | #ifndef ACCEL_REGISTERS_H_
9 | #define ACCEL_REGISTERS_H_
10 |
11 | //
12 | // Commands used for ADXL362 read/write access. Commands are sent prior to data/adx.
13 | //
14 | #define ADXL_CMD_WRITE_REG 0x0A
15 | #define ADXL_CMD_READ_REG 0x0B
16 | #define ADXL_CMD_READ_FIFO 0x0D
17 |
18 | //
19 | // Registers in the ADXL362. Created from the register map given in Table 11 of the datasheet.
20 | //
21 | #define ADXL_REG_DEVID_AD 0x00
22 | #define ADXL_REG_DEVID_MST 0x01
23 | #define ADXL_REG_PARTID 0x02
24 | #define ADXL_REG_REVID 0x03
25 | #define ADXL_REG_XDATA 0x08
26 | #define ADXL_REG_YDATA 0x09
27 | #define ADXL_REG_ZDATA 0x0A
28 | #define ADXL_REG_STATUS 0x0B
29 | #define ADXL_REG_FIFO_ENTRIES_L 0x0C
30 | #define ADXL_REG_FIFO_ENTRIES_H 0x0D
31 | #define ADXL_REG_XDATA_L 0x0E
32 | #define ADXL_REG_XDATA_H 0x0F
33 | #define ADXL_REG_YDATA_L 0x10
34 | #define ADXL_REG_YDATA_H 0x11
35 | #define ADXL_REG_ZDATA_L 0x12
36 | #define ADXL_REG_ZDATA_H 0x13
37 | #define ADXL_REG_TEMP_L 0x14
38 | #define ADXL_REG_TEMP_H 0x15
39 | #define ADXL_REG_Reserved0 0x16
40 | #define ADXL_REG_Reserved1 0x17
41 | #define ADXL_REG_SOFT_RESET 0x1F
42 | #define ADXL_REG_THRESH_ACT_L 0x20
43 | #define ADXL_REG_THRESH_ACT_H 0x21
44 | #define ADXL_REG_TIME_ACT 0x22
45 | #define ADXL_REG_THRESH_INACT_L 0x23
46 | #define ADXL_REG_THRESH_INACT_H 0x24
47 | #define ADXL_REG_TIME_INACT_L 0x25
48 | #define ADXL_REG_TIME_INACT_H 0x26
49 | #define ADXL_REG_ACT_INACT_CTL 0x27
50 | #define ADXL_REG_FIFO_CONTROL 0x28
51 | #define ADXL_REG_FIFO_SAMPLES 0x29
52 | #define ADXL_REG_INTMAP1 0x2A
53 | #define ADXL_REG_INTMAP2 0x2B
54 | #define ADXL_REG_FILTER_CTL 0x2C
55 | #define ADXL_REG_POWER_CTL 0x2D
56 | #define ADXL_REG_SELF_TEST 0x2E
57 |
58 | //value used to configure ADXL362
59 | #define AUTOSLEEP 0x0E
60 | #define WAKE_UP 0x0A
61 | #endif /* ACCEL_REGISTERS_H_ */
62 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/e-paper.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * e-paper.h
3 | *
4 | * @bref EPD(E-paer Driver) COG drive for Gen2 EPD EM027BS013
5 | * @note Modify cog for different EPD size of display (must using Gen2 COG)
6 | *
7 | *****************************************************************************/
8 |
9 | #include
10 | #include
11 | #include "../UserApp/myE-paperApp.h"
12 | //#include "tempSense.h"
13 |
14 |
15 | //------------------------------------------------------------------------------
16 | // Defines
17 | //------------------------------------------------------------------------------
18 | /*******E_INK image buffer size *******/
19 | /*
20 | * Max should be
21 | * cog.bytes_per_line * cog.lines_per_display
22 | * @note: adjust the cog in e-paper.c to match the type of e-paper
23 | *
24 | * 176*33 = 5808 for 2.7" e-paper
25 | * 96*200/8 for 2.7" e-paper
26 | * 96*128/8 for 1.4" e-paper
27 | */
28 | #if defined(E_INK_2_0)
29 | #define E_INK_SIZE 96*200/8 //2.0 e-paper
30 | #elif defined(E_INK_2_7)
31 | #define E_INK_SIZE 5808
32 | #endif
33 |
34 |
35 | /*******Update cycles for image *******/
36 | //@note The large cycle number results in better image
37 | #warning "if the image update quality is not good, then increase the NEW_IMG_CYCLES(need more power)"
38 | #define NEW_IMG_CYCLES 4
39 | #define SINGLE_COLOR_CYCLES 1
40 | #define SINGLE_DOT_CYCLES 4
41 |
42 | /************E-ink Update state for variable imageState************************/
43 | #define IMG_HALT 0
44 | #define IMG_UPDATE 1
45 | #define SENSE_UPDATE 2
46 | #define IMG_FORCE_UPDATE 3
47 | #define IMG_UPDATE_COMPLETE 4
48 | /*
49 | * The definition for driving stage to compare with
50 | * for getting Odd and Even data
51 | */
52 | #define BLACK0 (uint8_t)(0x03) /**< getting bit1 or bit0 as black color(11) */
53 | #define BLACK1 (uint8_t)(0x0C) /**< getting bit3 or bit2 as black color(11) */
54 | #define BLACK2 (uint8_t)(0x30) /**< getting bit5 or bit4 as black color(11) */
55 | #define BLACK3 (uint8_t)(0xC0) /**< getting bit7 or bit6 as black color(11) */
56 | #define WHITE0 (uint8_t)(0x02) /**< getting bit1 or bit0 as white color(10) */
57 | #define WHITE1 (uint8_t)(0x08) /**< getting bit3 or bit2 as white color(10) */
58 | #define WHITE2 (uint8_t)(0x20) /**< getting bit5 or bit4 as white color(10) */
59 | #define WHITE3 (uint8_t)(0x80) /**< getting bit7 or bit6 as white color(10) */
60 | #define NOTHING0 (uint8_t)(0x01) /**< getting bit1 or bit0 as nothing input(01) */
61 | #define NOTHING1 (uint8_t)(0x04) /**< getting bit3 or bit2 as nothing input(01) */
62 | #define NOTHING2 (uint8_t)(0x10) /**< getting bit5 or bit4 as nothing input(01) */
63 | #define NOTHING3 (uint8_t)(0x40) /**< getting bit7 or bit6 as nothing input(01) */
64 | #define NOTHING (uint8_t)(0x55) /**< sending Nothing frame, 01=Nothing, 0101=0x5 */
65 |
66 |
67 | #define ALL_BLACK (uint8_t)(0xFF)
68 | #define ALL_WHITE (uint8_t)(0xAA)
69 | #define BORDER_BYTE_B (uint8_t)(0xFF)
70 | #define BORDER_BYTE_W (uint8_t)(0xAA)
71 | #define ERROR_BUSY (uint8_t)(0xF0)
72 | #define ERROR_COG_ID (uint8_t)(0xF1)
73 | #define ERROR_BREAKAGE (uint8_t)(0xF2)
74 | #define ERROR_DC (uint8_t)(0xF3)
75 | #define ERROR_CHARGEPUMP (uint8_t)(0xF4)
76 | #define RES_OK (uint8_t)(0x00)
77 |
78 |
79 | //------------------------------------------------------------------------------
80 | // Micros
81 | //------------------------------------------------------------------------------
82 | #define initEPD() \
83 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_CS_EPD_BIT); \
84 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_CS_EPD_BIT); \
85 | PDIR_SPI &= ~(SPI_MISO_BIT); \
86 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
87 | EPD_RESET_OUT &= ~(EPD_RESET_BIT); \
88 | EPD_PANEL_ON_OUT &= ~(EPD_PANEL_ON_BIT);\
89 |
90 | /**
91 | * \brief Define the COG driver's parameters */
92 | struct EPD_type{
93 | uint8_t channel_select[8]; /**< SPI register data of Channel Select */
94 | uint8_t voltage_level; /**< SPI register data of Voltage Level */
95 | uint8_t bytes_per_line; /**< bytes of width of EPD */
96 | uint8_t lines_per_display; /**< the bytes of height of EPD */
97 | uint8_t data_line_size; /**< Data + Scan + Dummy bytes */
98 | uint8_t bytes_per_scan;
99 | };
100 |
101 | //------------------------------------------------------------------------------
102 | // globals
103 | //------------------------------------------------------------------------------
104 | extern uint8_t imageBuffer[E_INK_SIZE];
105 | extern uint8_t volatile imageUpdateState;
106 | //extern EPD_type;
107 | extern const struct EPD_type cog;
108 |
109 | //------------------------------------------------------------------------------
110 | // Functions
111 | //------------------------------------------------------------------------------
112 | //Initial EPD Dirver
113 | uint8_t EPD_power_init(void);
114 | //Turn off EPD Driver
115 | uint8_t EPD_power_off(void);
116 | //Update one line
117 |
118 | //Update multiple lines to all White or all Black
119 | void EPD_frame_fixed(const uint8_t start, const uint8_t end, const uint8_t color);
120 | //Update multiple lines of new image
121 | void EPD_frame_newImg(uint8_t* imgPtr,const uint8_t start, const uint8_t end);
122 | //Update singleDot (4 pixels) in E-ink display
123 | void EPD_frame_singleDot(const uint8_t start, const uint8_t end, uint8_t byte_pos,const uint8_t value);
124 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/fram_memory.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * fram_memory.c
3 | * @date Jun 15, 2013
4 | * @author Artem Dementyev, Aaron Parks,Eve(Yi Zhao)
5 | *****************************************************************************/
6 |
7 | #include "fram_memory.h"
8 | #include "e-paper.h"
9 |
10 | uint8_t const FRAM_Sleep[] = {0xB9};
11 | uint8_t const ReadStatus[] = {0x05,0x00};
12 | uint8_t const ReadDeviceID[]={0x9F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
13 |
14 | void SPI_FRAM_Wake_Up(void) {
15 | // CS low
16 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
17 | delay_us(T_10us);
18 |
19 | lowPowerSleep(LPM_500us);
20 |
21 | // CS high
22 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
23 | }
24 |
25 | void SPI_FRAM_Write_Enable_Latch(void) {
26 | // CS low
27 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
28 |
29 | //send the op code
30 | uint16_t i;
31 | for (i = 0; i < 1; ++i) {
32 | while (0 == (UCB1IFG & UCTXIFG)) {
33 | }
34 | UCB1TXBUF = 0x06; //op code for enabling write latch (WREN)
35 | }
36 |
37 | // wait for last byte to clear SPI
38 | while (0 != (UCB1STAT & UCBUSY)) {
39 | }
40 |
41 | // CS high
42 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
43 | }
44 |
45 | void SPI_FRAM_Enter_Sleep() {
46 | //Note: must make sure SPI clock is SMCLK =13MHz
47 | // Select MEMERY SPI
48 | SPI_transaction(gpRxBuf,(uint8_t*)&FRAM_Sleep, sizeof(FRAM_Sleep),FRAM_SPI);
49 | //Disable SPI
50 | }
51 |
52 | uint8_t SPI_FRAM_Read_Status_Register(void) {
53 |
54 | SPI_transaction(gpRxBuf,(uint8_t*)&ReadStatus, sizeof(ReadStatus),FRAM_SPI);
55 | return gpRxBuf[1];
56 | }
57 |
58 | void SPI_FRAM_Write_Memory(const uint8_t *bufferAddress,
59 | const uint8_t *bufferData, uint16_t lengthData) {
60 |
61 | // CS low
62 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
63 |
64 | // send the op code
65 | uint16_t i;
66 | for ( i = 0; i < 1; ++i) {
67 | while (0 == (UCB1IFG & UCTXIFG)) {
68 | }
69 | UCB1TXBUF = 0x02; //op code for writing memory (WRITE)
70 | }
71 |
72 | // wait for last byte to clear SPI
73 | while (0 != (UCB1STAT & UCBUSY)) {
74 | }
75 |
76 | //send the 18-bit address of first data byte (we use 8 * 3 = 24 bits to represent address)
77 |
78 | for (i = 0; i < 3; ++i) {
79 | while (0 == (UCB1IFG & UCTXIFG)) {
80 | }
81 | UCB1TXBUF = *bufferAddress++;
82 | }
83 |
84 | // send the 8-byte data
85 | while (0 != (UCB1STAT & UCBUSY)) {
86 | }
87 |
88 | for ( i = 0; i < lengthData; ++i) {
89 | while (0 == (UCB1IFG & UCTXIFG)) {
90 | }
91 | UCB1TXBUF = *bufferData++;
92 | }
93 |
94 | // wait for last byte to clear SPI
95 | while (0 != (UCB1STAT & UCBUSY)) {
96 | }
97 |
98 | // CS high
99 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
100 |
101 | } //end SPI write memory
102 |
103 | uint8_t * SPI_FRAM_Read_Memory(const uint8_t *bufferAddress,
104 | uint16_t lengthData) {
105 |
106 | // TODO We don't have space in RAM for the following array.
107 | //uint8_t testArray[5807];
108 |
109 | // CS low
110 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
111 |
112 | // send the op code
113 | uint16_t i;
114 | for (i = 0; i < 1; ++i) {
115 | while (0 == (UCB1IFG & UCTXIFG)) {
116 | }
117 | UCB1TXBUF = 0x03; //op code for reading memory (READ)
118 | }
119 |
120 | // wait for last byte to clear SPI
121 | while (0 != (UCB1STAT & UCBUSY)) {
122 | }
123 |
124 | //send the 18-bit address
125 | for ( i = 0; i < 3; ++i) {
126 | while (0 == (UCB1IFG & UCTXIFG)) {
127 | }
128 | UCB1TXBUF = *bufferAddress++;
129 | }
130 |
131 | // clock out the 8-byte data
132 | while (0 != (UCB1STAT & UCBUSY)) {
133 | }
134 |
135 | for (i = 0; i < lengthData; ++i) {
136 | while (0 == (UCB1IFG & UCTXIFG)) {
137 | }
138 | UCB1TXBUF = 0xff;
139 | gpRxBuf[i] = UCB1RXBUF;
140 | }
141 |
142 | // wait for last byte to clear SPI
143 | while (0 != (UCB1STAT & UCBUSY)) {
144 | }
145 |
146 | // CS high
147 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
148 |
149 | // TODO This will fail in many circumstances: We're returning a pointer to a local variable.
150 | return gpRxBuf;
151 |
152 | } //end SPI write memory
153 |
154 | void SPI_FRAM_Read_Image(const uint8_t *bufferAddress,
155 | uint16_t lengthData) {
156 | // CS low
157 |
158 | //uint8_t testArray[5807];
159 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
160 |
161 | // send the op code
162 | uint16_t i;
163 | for (i = 0; i < 1; ++i) {
164 | while (0 == (UCB1IFG & UCTXIFG)) {
165 | }
166 | UCB1TXBUF = 0x03; //op code for reading memory (READ)
167 | }
168 |
169 | // wait for last byte to clear SPI
170 | while (0 != (UCB1STAT & UCBUSY)) {
171 | }
172 |
173 | //send the 18-bit address
174 | for (i= 0; i < 3; ++i) {
175 | while (0 == (UCB1IFG & UCTXIFG)) {
176 | }
177 | UCB1TXBUF = *bufferAddress++;
178 | }
179 |
180 | // clock out the 8-byte data
181 | while (0 != (UCB1STAT & UCBUSY)) {
182 | }
183 |
184 | for (i = 0; i < lengthData; ++i) {
185 | while (0 == (UCB1IFG & UCTXIFG)) {
186 | }
187 | UCB1TXBUF = 0xff;
188 | imageBuffer[i] = UCB1RXBUF;
189 | }
190 |
191 | // wait for last byte to clear SPI
192 | while (0 != (UCB1STAT & UCBUSY)) {
193 | }
194 |
195 | // CS high
196 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT;
197 | } //end SPI write memory
198 |
199 | /**
200 | * Initialize the FRAM module and put it to sleep
201 | *
202 | * @note must wait 1ms before SPI
203 | */
204 | void initFRAM(void) {
205 |
206 | /*sleep 1ms to allow FRAM startup*/
207 | lowPowerSleep(LPM_1ms);
208 |
209 | /*Coomment it out to test if SPI works well,
210 | *the status register should return 0x40*/
211 | //SPI_FRAM_Read_Status_Register();
212 |
213 | /* Put FRAM to sleep*/
214 | SPI_FRAM_Enter_Sleep();
215 | }
216 |
217 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/fram_memory.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * fram_memory.h
3 | *
4 | * @date Jun 15, 2013
5 | * @author Artem Dementyev, Aaron Parks
6 | *****************************************************************************/
7 | #include "globals.h"
8 | #include "spi.h"
9 |
10 |
11 | //void SPI_FRAM_Write_Enable_Latch(unsigned char portj_cs_pin);
12 | void initFRAM(void);
13 | void SPI_FRAM_Write_Enable_Latch(void);
14 | unsigned char SPI_FRAM_Read_Status_Register(void);
15 | void SPI_FRAM_Write_Memory(const uint8_t *bufferAddress,const uint8_t *bufferData, uint16_t lengthData);
16 | uint8_t * SPI_FRAM_Read_Memory(const uint8_t *bufferAddress,uint16_t lengthData);
17 | void SPI_FRAM_Enter_Sleep(void);
18 | void SPI_FRAM_Wake_Up(void);
19 | void SPI_FRAM_Read_Image(const uint8_t *bufferAddress,uint16_t lengthData);
20 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/globals.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * globals.c
3 | * @breif global functions
4 | * @date 8/15/2014
5 | * @author Yi Zhao, Uw Sensor systems Lab
6 | *****************************************************************************/
7 | //-----------------------------------------------------------------------------
8 | // Includes
9 | //------------------------------------------------------------------------------
10 | #include "globals.h"
11 |
12 | //------------------------------------------------------------------------------
13 | // Functions
14 | //------------------------------------------------------------------------------
15 | /**
16 | * Configure LED 1 to pulse once without further intervention
17 | */
18 | void led_1_auto_pulse(void) {
19 | led_pulse_flags|=LED_1_PULSE_FLAG;
20 | }
21 |
22 | /**
23 | * Configure LED 2 to pulse once without further intervention
24 | */
25 | void LED_2_BIT_auto_pulse(void) {
26 | led_pulse_flags|=LED_2_BIT_PULSE_FLAG;
27 | }
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/globals.h:
--------------------------------------------------------------------------------
1 | /************************************************************************************************************************************/
2 | /** @file globals.h
3 | * @brief NFC global defines and funcs
4 | * @author Yi Zhao(Eve), UW Sensor Systems Lab
5 | * @created 8.15.2014
6 | */
7 | /************************************************************************************************************************************/
8 | #ifndef GLOBALS_H_
9 | #define GLOBALS_H_
10 |
11 | //=============================================================================
12 | // Includes
13 | //=============================================================================
14 | #include "NFC_WISP_Rev1.0.h"
15 | #include "spi.h"
16 | #include
17 | #include
18 | #include
19 | #include "timer.h"
20 | //#include "e-paper.h"
21 | //=============================================================================
22 | // Configuration
23 | //=============================================================================
24 | /*******SELECT PROTOCOL*************/
25 | //#define _15693_1of256
26 | #define _14443_B
27 |
28 | /******SELECT CLOCK FREQUENCY******/
29 | //#define _6_78MHz
30 | #define _13_56MHz
31 |
32 | //=============================================================================
33 | // General Defines
34 | //=============================================================================
35 | #define CMD_BUF_SIZE 64
36 | //#define CMD_BUF_SIZE 1
37 | //@modify only for RFID 2015
38 | #ifdef TempDemo
39 | #define UID_SIZE 8
40 | #else
41 | #define UID_SIZE 4
42 | #endif
43 |
44 | #define APP_SIZE 4
45 | #define CAPTURE_BUFFER_SIZE 10 //maximum number of pulse capture times we can store
46 |
47 | #define CRYSTAL_FREQ 32768
48 | #define TIMEOUT_MS 100 //low power timeout in ms
49 | #define TIMEOUT_VAL (CRYSTAL_FREQ/(TIMEOUT/10))
50 |
51 |
52 |
53 |
54 |
55 |
56 | #define LED_1_PULSE_FLAG 0x01
57 | #define LED_2_BIT_PULSE_FLAG 0x02
58 | #define KILL_LEDS_FLAG 0x80
59 |
60 |
61 | #define FOREVER (1)
62 | #define NEVER (0)
63 |
64 | #define TRUE (1)
65 | #define FALSE (0)
66 |
67 | #define HIGH (1)
68 | #define LOW (0)
69 | //#define NULL (void *)0 /**< define NULL */
70 |
71 | #define FAIL (0)
72 | #define SUCCESS (1)
73 |
74 |
75 | //=============================================================================
76 | // NFC Defines
77 | //=============================================================================
78 | //6.78Mhz where 1 etu is clock periods
79 | // TODO Get rid of ifdefs if possible
80 | #ifdef _14443_B
81 |
82 | /****************state for NFC state machine **********************************/
83 | //Start NFC routine after first power up or sleep_untill_read
84 | //@note Change below bits setting have to change TimerA0 ISR in timer.c
85 | #define NFC_Stop 0 // NFC halt
86 | #define NFC_Start BIT7 // doNFC_state = BIT7
87 | #define NFC_Rx0 BIT0 // doNFC_state =BIT0 detect delimeter start
88 | #define NFC_Rx1 BIT1 // doNFC_state =BIT1 detect start of first byte start
89 | #define NFC_Rx2 BIT2 // doNFC_state =BIT2 decode data
90 | #define NFC_Tx 0x07 // doNFC_state =0x07 transmit data
91 | #define NFC_Sleep BIT3 // doNFC_state = BIT3
92 | #define NFC_LPM4 BIT4 // doNFC_state is in LMP4 now
93 |
94 |
95 |
96 | #ifdef _6_78MHz // 6.78 MHz clock frequency
97 |
98 | #define TEN_PULSES 70//80
99 | #define ELEVEN_PULSES 98//88
100 | #define EOF 86
101 |
102 | #else // Otherwise assume 13.56Mhz/8 clock frequency
103 | //threshold should be 70us
104 | #endif /* _6_78MHz */
105 | #endif /* _14443_B */
106 |
107 |
108 | //=============================================================================
109 | // Globals
110 | //=============================================================================
111 | /***************NFC Globals****************************/
112 | extern uint8_t volatile doNFC_state;
113 | //extern uint8_t transmitCommand[CMD_BUF_SIZE];
114 | /************E-ink Update state************************/
115 | //extern uint8_t imageBuffer[E_INK_SIZE];
116 | //extern uint8_t volatile imageUpdateState;
117 | //***********Sensing Update state**********************/
118 | extern volatile unsigned long RTC_ctr;
119 | extern volatile uint8_t senseState;
120 | extern volatile uint8_t accelState;
121 |
122 | /****Sense data cicular queue structure***************/
123 | extern uint8_t buf_full;
124 | extern uint8_t led_pulse_flags; // Flags indicating which LED to pulse in the timer ISR
125 | //=============================================================================
126 | // Functions
127 | //=============================================================================
128 | void led_1_auto_pulse();
129 | void LED_2_BIT_auto_pulse();
130 |
131 | //=============================================================================
132 | // Macros
133 | //=============================================================================
134 | // LED Macros
135 | #define toggle_led_1() LED_1_OUT ^= LED_1_BIT
136 | #define toggle_led_2() LED_2_OUT ^= LED_2_BIT
137 | #define led_1_off() LED_1_OUT &= ~(LED_1_BIT)
138 | #define led_2_off() LED_2_OUT &= ~(LED_2_BIT)
139 | #define led_1_on() LED_1_OUT |= LED_1_BIT
140 | #define led_2_on() LED_2_OUT |= LED_2_BIT
141 | #endif
142 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/spi.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file spi.h
3 | * @brief spi interface
4 | * @author Aaron Parks, Eve (Yi Zhao) - Sensor Systems Lab (UW)
5 | * @date 03/29/2015
6 | *****************************************************************************/
7 |
8 | #ifndef SENSOR_SPI_H_
9 | #define SENSOR_SPI_H_
10 |
11 | #include
12 | //=============================================================================
13 | // SPI Defines
14 | //=============================================================================
15 | //TODO: the size of SPI depends on application
16 | #warning "modify the size of SPI buffer for different requirement"
17 | #define SPI_GP_RXBUF_SIZE 17
18 |
19 | //#define CLK_MHz 13.56
20 | //#define SPI_BPS 10000000
21 | //#define SPI_BR_VALUE (1000000 * CLK_MHz / SPI_BPS)
22 | //SPI CLK is 13.56 Mhz
23 | //Baudrate now is 13.56Mhz/SPI_BR_LOW = 4.39Mhz
24 | #define SPI_BR_HIGH 0x00
25 | #define SPI_BR_LOW 0x03//0x03
26 |
27 | //Define index for different SPI slave
28 | //TODO: Add more depends on different SPI applications
29 | #define FRAM_SPI 0x00
30 | #define EPD_SPI 0x01
31 | #define ACCEL_SPI 0x02
32 | #define EPD_LONG_DATA 0x03
33 |
34 |
35 | //=============================================================================
36 | // SPI Micros
37 | //=============================================================================
38 | //SPI_CS_xx configureation used in SPI_transaction
39 | #define MEM_SPI_ON() \
40 | PSEL_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
41 | SPI_CS_MEM_OUT &= ~SPI_CS_MEM_BIT;
42 | //reset CLK,MOSI to be 0/output MISO input and SPI_CS to be 1
43 | #define MEM_SPI_OFF() \
44 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT); \
45 | PDIR_SPI &= ~(SPI_MISO_BIT); \
46 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT); \
47 | SPI_CS_MEM_OUT |= SPI_CS_MEM_BIT; \
48 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT);
49 |
50 | #define EPD_SPI_ON() \
51 | SPI_CS_EPD_OUT &=~ SPI_CS_EPD_BIT;
52 | #define EPD_SPI_OFF() \
53 | SPI_CS_EPD_OUT |= SPI_CS_EPD_BIT;
54 | #define ACCEL_SPI_ON() \
55 | PSEL_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT); \
56 | SPI_CS_ACCEL_OUT &=~ SPI_CS_ACCEL_BIT;
57 | #define ACCEL_SPI_OFF() \
58 | SPI_CS_ACCEL_OUT |= SPI_CS_ACCEL_BIT; \
59 | POUT_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT); \
60 | PDIR_SPI &= ~(SPI_MISO_BIT); \
61 | PDIR_SPI |= (SPI_CLK_BIT | SPI_MOSI_BIT); \
62 | PSEL_SPI &= ~(SPI_CLK_BIT | SPI_MOSI_BIT | SPI_MISO_BIT);
63 |
64 | //=============================================================================
65 | // Variables
66 | //=============================================================================
67 |
68 |
69 | extern uint8_t gpRxBuf[SPI_GP_RXBUF_SIZE];
70 | //extern uint8_t gpTxBuf[SPI_GP_RXBUF_SIZE];
71 | typedef uint8_t BOOL;
72 |
73 |
74 | //=============================================================================
75 | // SPI Functions
76 | //=============================================================================
77 | BOOL SPI_initialize();
78 | BOOL SPI_acquirePort();
79 | BOOL SPI_releasePort();
80 | void SPI_transaction(uint8_t* rxBuf, uint8_t* txBuf, uint16_t size, uint8_t spiSlaveIndex);
81 | void SPI_put_wait(unsigned char c);
82 | void epd_spi_send_byte (const uint8_t register_index, const uint8_t register_data);
83 | void epd_spi_send (uint8_t register_index, uint8_t *dataPtr, uint8_t length);
84 | uint8_t SPI_READ(const uint8_t Register);
85 |
86 |
87 | #endif /* SENSOR_SPI_H_ */
88 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/timer.c:
--------------------------------------------------------------------------------
1 | /*
2 | * timer.c
3 | *
4 | * Created on: Aug 26, 2014
5 | * Author: evezhao
6 | * @fun timeout and lowPowerSleep timming
7 | */
8 |
9 | #include "timer.h"
10 | #include "e-paper.h"
11 |
12 |
13 | /******************************************************************************
14 | * @brief TA0 Timeout system for monitor timeout such as in sleep_untill_edges
15 | * @CLK 32K/8=4K, 250us/cycles
16 | *****************************************************************************/
17 | void timeout_init(uint16_t time) {
18 | // Set up TA1.0 for periodic interrupt
19 | //_BIC_SR(OSCOFF); // ENABLE ACLK
20 | TA0CCR0 = time; // 10 ms with 32768 Hz ACLK
21 | TA0CTL = TASSEL_1 | ID_3 | MC_1 | TACLR; //ACLK, upmode, 4khz clk
22 | TA0CCTL0 = CCIE; //Enable interrupt
23 | }
24 |
25 | //Halt the timeout system (e.g., to save power)
26 | void timeout_halt(void) {
27 | TA0CTL = 0x00;
28 | TA0CCTL0 = 0;
29 | //_BIS_SR(OSCOFF);
30 | }
31 |
32 | /******************************************************************************
33 | * init real time clk count for every 15s for tempSense
34 | *****************************************************************************/
35 | void initRTC(uint16_t time){
36 | //_BIC_SR(OSCOFF); //Enable ACLK
37 | TA1CCR0 = time; // 10 ms with 32768 Hz ACLK
38 | //TA1CCR0 = 0xFFFE;
39 | TA1CTL = TASSEL_1 | ID_3 | MC__UP | TACLR; //ACLK, upmode, 4khz clk
40 | TA1CCTL0 |= CCIE;
41 | RTC_ctr = 0; //couting is 0;
42 | //senseState = 0; //
43 | }
44 |
45 | /*******************************************************************************/
46 | /* @brief sleep the CPU for duration(us~ms) using TimerA2
47 | * @note must use when ACLKREQEN=1
48 | *******************************************************************************/
49 | //low power and more accurate sleep delay
50 | //SMCLK @13.56Mhz/8
51 | void delay_us(uint16_t delay){
52 | TA2CTL = 0;
53 | TA2CCR0 = delay;
54 | TA2CCTL0 = CCIE;
55 | TA2CTL = TASSEL_2 | ID_3 | MC__UP; //SMCLK, 1.695Mhz
56 | __bis_SR_register(LPM4_bits | GIE);
57 | }
58 |
59 | //lowPower sleep for ms level sleep
60 | void lowPowerSleep (uint16_t duration) {
61 | //isDoingLowPwrSleep = TRUE;
62 | //_BIC_SR(OSCOFF); //Enable ACLK
63 | TA2CCR0 = duration;
64 | TA2CTL = 0;
65 | TA2CCTL0 = CCIE;
66 | TA2CTL = TASSEL__ACLK + MC__UP + TACLR; //ACLK, 32Khz,
67 | __bis_SR_register(LPM3_bits | GIE); //LPM3 sleep
68 | //_BIS_SR(OSCOFF); // Disable ACLK
69 | //isDoingLowPwrSleep = FALSE;
70 | return;
71 | }
72 |
73 | //low power Sleep for above 10ms sleep
74 | void long_lowPowerSleep (uint16_t duration) {
75 | //_BIC_SR(OSCOFF); //Enable ACLK
76 | TA2CCR0 = duration;
77 | TA2CTL = 0;
78 | TA2CCTL0 = CCIE;
79 | TA2CTL = TASSEL__ACLK | MC__UP | TACLR | ID_3; //ACLK, 4k=32K/8hz,
80 | __bis_SR_register(LPM3_bits | GIE); //LPM3 sleep
81 |
82 | return;
83 | }
84 | /*******************************************************************************
85 | @brief LPM3 sleep or NFC timeout ISR for NFC Rx using SMCLK or ACLK
86 | @note only used when MCLKREQEN=1
87 | *******************************************************************************/
88 | #pragma vector=TIMER0_A0_VECTOR
89 | __interrupt void timeTrackingISR(void) {
90 | //it is in doRFID_14443B routine
91 | if(doNFC_state=senseDelay){
111 | senseState++;
112 | RTC_ctr=0;
113 | if((doNFC_state&NFC_LPM4)){
114 | RX_WAKEUP_IE &= ~RX_WAKEUP_BIT;
115 | RX_WAKEUP_EN_DIR &= ~RX_WAKEUP_EN_BIT;
116 | RX_WAKEUP_IFG &= ~(RX_WAKEUP_BIT);
117 | doNFC_state = NFC_Sleep;
118 | imageUpdateState = SENSE_UPDATE;
119 | RTC_ctr = 0;
120 | __bic_SR_register_on_exit(LPM4_bits | GIE);
121 | }
122 |
123 | }
124 | }
125 |
126 |
127 | /*******************************************************************************/
128 | /** @fcn lowPowerSleep ISR for TimerA2
129 | * @brief LPM3 sleep for us~ms level
130 | * @note only used when ACLKREQEN=1
131 | */
132 | /*******************************************************************************/
133 | #pragma vector=TIMER2_A0_VECTOR
134 | __interrupt void LPM3_TimerISR(void) {
135 | TA2CTL = 0x00;
136 | TA2CCTL0 = 0x00;
137 | __bic_SR_register_on_exit(LPM3_bits | GIE);
138 | }
139 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/common/timer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * timer.h
3 | *
4 | * Created on: Aug 26, 2014
5 | * Author: evezhao
6 | */
7 |
8 | #ifndef TIMER_H_
9 | #define TIMER_H_
10 |
11 |
12 | #include
13 | #include
14 | #include "globals.h"
15 |
16 | /*-----------------------Low Freq LowPower TIME OUT DELAY--------------------*/
17 | #define RTC_15s 0xF000//15s when senseDelay is 1
18 | #define RTC_5s 0x5000//5s when senseDelay is 1
19 | #define RTC_2s 0x2000
20 | #define RTC_3s 0x3000
21 |
22 | #define senseDelay 1//4 //Set to larger value if we need more delay
23 | #define TIMEOUT_COUNTS 100
24 | #define TIMEOUT_10MS 328
25 | #define TIMEOUT_20MS 654
26 | #define TIMEOUT_5MS 164
27 | #define TIMEOUT_240uS 8
28 | #define lowPowerSleep_30us 2
29 | #define lowPowerSleep_10MS 333
30 | #define lowPowerSleep_5MS 165
31 | #define lowPowerSleep_1MS 33
32 |
33 | /*-----------------------High Freq CLCK LowPower DELAY--------------------*/
34 | /**********************************
35 | * Constant used in delay_us()
36 | * num of 13.56Mhz/8 cycles
37 | **********************************/
38 | #define T_5us 0x0A
39 | #define T_10us 18
40 | #define T_25us 0x2C
41 | #define T_30us 0x34
42 | #define T_35us 64
43 | #define T_40us T_10us*4
44 | #define T_50us 90
45 | #define T_100us T_10us*10
46 | #define T_500us T_100us*5
47 | /*
48 | #define T_1ms 0x6A4
49 | #define T_5ms 0x2134
50 | #define T_10ms 0x4268
51 | #define T_25ms 0xA604
52 | #define T_20ms 0x84D0
53 | */
54 | /**********************************
55 | * Constant used in long_delay_ms()
56 | * num of T_20ms cycles
57 | **********************************/
58 | /*
59 | #define T_40ms 0x02
60 | #define T_120ms 0x06
61 | #define T_240ms 0x0C
62 | */
63 | /**********************************
64 | * Constant used in lowPowerSleep()
65 | * for 32K CLK
66 | **********************************/
67 | #define LPM_50us 0x3
68 | #define LPM_500us 0x12
69 | #define LPM_1ms 0x23
70 | #define LPM_3ms LPM_1ms*3
71 | #define LPM_4ms LPM_1ms*4
72 | #define LPM_5ms 0xA5
73 | #define LPM_10ms LPM_5ms*2
74 | #define LPM_20ms 0x294
75 | #define LPM_25ms LPM_5ms*5
76 | #define LPM_40ms 0x520
77 | #define LPM_80ms 0x520*2
78 | #define LPM_120ms LPM_40ms*3
79 | #define LPM_240ms LPM_40ms*6
80 |
81 |
82 |
83 |
84 | //extern unsigned long timeout_ctr;
85 | //extern uint8_t led_pulse_flags; // Flags indicating which LED to pulse in the timer ISR
86 | //extern uint8_t isDoingLowPwrSleep;
87 | extern uint8_t volatile doNFC_state; //Flags used for TimerA0 when receive command
88 | extern uint8_t volatile imageUpdateState;
89 | unsigned int timeout_occurred(void) ;
90 | void timeout_init(uint16_t time) ;
91 | void lowPowerSleep (uint16_t duration);
92 | void long_lowPowerSleep (uint16_t duration);
93 | void timeout_halt(void);
94 | void delay_us(uint16_t delay);
95 | void initRTC(uint16_t time);
96 | void ACLK_on(void);
97 | #endif /* TIMER_H_ */
98 |
--------------------------------------------------------------------------------
/ccs/nfc-eink-temp-accel-data-logger-demo/main.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file main.c
3 | *
4 | * @brief Main structure for NFC WISP application
5 | *
6 | * @details The demo is designed to configure NFC-WISP as ISO-14443B tag,
7 | * and update the E-ink display.
8 | * User application can be modified in UserApp/myApp.c
9 | * User E-ink App can be modified in UserApp/myE-apperApp.c
10 | * NFC protocol in NFC_protocol can be modified if needed.
11 | *
12 | * @note NFC WISP Tag can be read by Nexus S, Nexus 5, Samsung Galaxy S4
13 | * But the E-ink image updates only works on Nexus S (API 19).
14 | * We do not use FRAM in this version
15 | *
16 | * @note Must set debuger voltage to be 2.5V(2500) when debuging the board,
17 | * otherwise, some periferial may not work correctly!
18 | * @author Eve (Yi Zhao) - Sensor Systems Lab (UW)
19 | * @date 09/29/2014
20 | * @TODO Impelment ISO_15693
21 | *****************************************************************************/
22 |
23 | //=============================================================================
24 | // Includes
25 | //=============================================================================
26 | // we will use ISO 14443B
27 | //#define _15693_1of256 //havenet implement it yet
28 |
29 | #include "common/globals.h"
30 | #include "NFC_protocol/doNFC.h"
31 | #include "common/e-paper.h"
32 | #include "common/fram_memory.h"
33 | #include "common/accel.h"
34 | #include "UserApp/myApp.h"
35 |
36 | /**
37 | * Main loop for application.
38 | */
39 | int16_t main(void) {
40 | // Initialize MSP430 and peripherals
41 | //already done in _system_pre_init.c;
42 |
43 | // Initialize the RFID subsystem
44 | initRFID();
45 |
46 | // Initialize the EPD subsystem (optional)
47 | initEPD();
48 |
49 |
50 | // Set up SPI and baud rate the ACCEL SPI clk are recommand as 1MHz~ 5 MHz
51 | SPI_initialize();
52 |
53 | //Put FRAM memory module into sleep, must wait at least for 1ms after whole chip power-up
54 | initFRAM();
55 |
56 | // Initialize the Accelerometer must wait at least for 5ms after whole chip power-up
57 | initACCEL();
58 | // ACCEL_standby(); //Put ACCEL into sleep mode if not use
59 |
60 | //User App initial
61 | initMyDemo1(); //temperature/acceleration dataLoggor demo
62 | //initMyDemo2(); //E-ink display update demo
63 |
64 | while (1) {
65 | #ifdef _15693_1of256
66 | doRFID_15693();
67 | #else
68 |
69 | /******************NFC and custermized App handle routine********************
70 | * doNFC(), system will goto sleep if no NFC signal
71 | * and will wakeup if there is interrupt
72 | * **************************************************************************/
73 | doNFC();
74 |
75 | /******************Sensing handle routine************************************/
76 |
77 | /**
78 | * Temerature and Movement logger demo,
79 | * @note temperature offset in different
80 | * PCB is diffenrent, need to be manually adjust in tempSense.c
81 | * line #56 IntDegC = ((temp*93)>>4)-2650; //2860 is the offset for board 2
82 | */
83 | Demo1();
84 |
85 |
86 | /**
87 | * Updating E-ink screen with/withou battery using Nexus S and Andriod readerApp1.0 app
88 | */
89 | //Demo2();
90 | #endif
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014, University of Washington
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 |
8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 |
10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 |
--------------------------------------------------------------------------------