First Commit

Dependencies:   mbed Crypto_light mbed-rtos

Spin it 2 win it

Committer:
TrebleStick
Date:
Tue Mar 20 16:51:38 2018 +0000
Revision:
20:a435105305fe
Parent:
19:526fd700e1b3
Child:
21:0d1025dc6433
Working kinda

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TrebleStick 0:88c3d6c8a4eb 1 #include "mbed.h"
andrebharath 3:2e32d7974962 2 #include "Crypto_light/hash/SHA256.h"
andrebharath 3:2e32d7974962 3 #include "mbed-rtos/rtos/rtos.h"
TrebleStick 0:88c3d6c8a4eb 4
TrebleStick 0:88c3d6c8a4eb 5 //Photointerrupter input pins
TrebleStick 0:88c3d6c8a4eb 6 #define I1pin D2
TrebleStick 0:88c3d6c8a4eb 7 #define I2pin D11
TrebleStick 0:88c3d6c8a4eb 8 #define I3pin D12
andrebharath 9:ecef1e8cbe3d 9
TrebleStick 0:88c3d6c8a4eb 10 //Incremental encoder input pins
TrebleStick 0:88c3d6c8a4eb 11 #define CHA D7
TrebleStick 12:1b2e2540e4e1 12 #define CHB D8
andrebharath 9:ecef1e8cbe3d 13
TrebleStick 0:88c3d6c8a4eb 14 //Motor Drive output pins //Mask in output byte
TrebleStick 0:88c3d6c8a4eb 15 #define L1Lpin D4 //0x01
TrebleStick 0:88c3d6c8a4eb 16 #define L1Hpin D5 //0x02
TrebleStick 0:88c3d6c8a4eb 17 #define L2Lpin D3 //0x04
TrebleStick 0:88c3d6c8a4eb 18 #define L2Hpin D6 //0x08
TrebleStick 0:88c3d6c8a4eb 19 #define L3Lpin D9 //0x10
TrebleStick 0:88c3d6c8a4eb 20 #define L3Hpin D10 //0x20
TrebleStick 0:88c3d6c8a4eb 21
andrebharath 9:ecef1e8cbe3d 22 #define CHAR_ARR_SIZE 18 //Max length of input codes
andrebharath 17:80159ace5ddf 23 #define MAX_PWM_PERIOD 2000
andrebharath 18:05e5d280a082 24 #define MAX_TORQUE 1000
andrebharath 3:2e32d7974962 25
TrebleStick 0:88c3d6c8a4eb 26 //Mapping from sequential drive states to motor phase outputs
TrebleStick 0:88c3d6c8a4eb 27 /*
TrebleStick 0:88c3d6c8a4eb 28 State L1 L2 L3
TrebleStick 0:88c3d6c8a4eb 29 0 H - L
TrebleStick 0:88c3d6c8a4eb 30 1 - H L
TrebleStick 0:88c3d6c8a4eb 31 2 L H -
TrebleStick 0:88c3d6c8a4eb 32 3 L - H
TrebleStick 0:88c3d6c8a4eb 33 4 - L H
TrebleStick 0:88c3d6c8a4eb 34 5 H L -
TrebleStick 0:88c3d6c8a4eb 35 6 - - -
TrebleStick 0:88c3d6c8a4eb 36 7 - - -
TrebleStick 0:88c3d6c8a4eb 37 */
TrebleStick 0:88c3d6c8a4eb 38 //Drive state to output table
TrebleStick 0:88c3d6c8a4eb 39 const int8_t driveTable[] = {0x12,0x18,0x09,0x21,0x24,0x06,0x00,0x00};
andrebharath 9:ecef1e8cbe3d 40
TrebleStick 0:88c3d6c8a4eb 41 //Mapping from interrupter inputs to sequential rotor states. 0x00 and 0x07 are not valid
TrebleStick 12:1b2e2540e4e1 42 const int8_t stateMap[] = {0x07,0x05,0x03,0x04,0x01,0x00,0x02,0x07};
TrebleStick 0:88c3d6c8a4eb 43 //const int8_t stateMap[] = {0x07,0x01,0x03,0x02,0x05,0x00,0x04,0x07}; //Alternative if phase order of input or drive is reversed
andrebharath 9:ecef1e8cbe3d 44
TrebleStick 0:88c3d6c8a4eb 45 //Phase lead to make motor spin
TrebleStick 0:88c3d6c8a4eb 46 const int8_t lead = 2; //2 for forwards, -2 for backwards
andrebharath 9:ecef1e8cbe3d 47
andrebharath 9:ecef1e8cbe3d 48 //Rotor offset at motor state 0
andrebharath 18:05e5d280a082 49 volatile int8_t orState = 0;
andrebharath 9:ecef1e8cbe3d 50
andrebharath 17:80159ace5ddf 51 //Set initial torque of 1000
andrebharath 18:05e5d280a082 52 volatile uint32_t torque = 1000;
andrebharath 17:80159ace5ddf 53
andrebharath 9:ecef1e8cbe3d 54
TrebleStick 12:1b2e2540e4e1 55 enum MSG {MSG_RESET, MSG_HASHCOUNT, MSG_NONCE_OK,
TrebleStick 20:a435105305fe 56 MSG_OVERFLOW, MSG_ROT_PEN, MSG_MAX_SPD, MSG_NEW_KEY, MSG_INP_ERR, MSG_TORQUE,
TrebleStick 20:a435105305fe 57 MSG_TEST, MSG_CUR_SPD};
andrebharath 9:ecef1e8cbe3d 58
andrebharath 3:2e32d7974962 59 //Instantiate the serial port
andrebharath 9:ecef1e8cbe3d 60 RawSerial pc(SERIAL_TX, SERIAL_RX);
andrebharath 9:ecef1e8cbe3d 61
andrebharath 9:ecef1e8cbe3d 62 //Status LED
andrebharath 9:ecef1e8cbe3d 63 DigitalOut led1(LED1);
andrebharath 9:ecef1e8cbe3d 64
andrebharath 9:ecef1e8cbe3d 65 //Photointerrupter inputs
andrebharath 9:ecef1e8cbe3d 66 InterruptIn I1(I1pin);
andrebharath 9:ecef1e8cbe3d 67 InterruptIn I2(I2pin);
andrebharath 9:ecef1e8cbe3d 68 InterruptIn I3(I3pin);
andrebharath 9:ecef1e8cbe3d 69
andrebharath 9:ecef1e8cbe3d 70 //Motor Drive outputs
andrebharath 17:80159ace5ddf 71 PwmOut L1L(L1Lpin);
andrebharath 9:ecef1e8cbe3d 72 DigitalOut L1H(L1Hpin);
andrebharath 17:80159ace5ddf 73 PwmOut L2L(L2Lpin);
andrebharath 9:ecef1e8cbe3d 74 DigitalOut L2H(L2Hpin);
andrebharath 17:80159ace5ddf 75 PwmOut L3L(L3Lpin);
andrebharath 9:ecef1e8cbe3d 76 DigitalOut L3H(L3Hpin);
andrebharath 9:ecef1e8cbe3d 77
TrebleStick 0:88c3d6c8a4eb 78
andrebharath 3:2e32d7974962 79
TrebleStick 20:a435105305fe 80
andrebharath 3:2e32d7974962 81 typedef struct {
TrebleStick 20:a435105305fe 82 uint8_t code;
TrebleStick 20:a435105305fe 83 int32_t data;
andrebharath 3:2e32d7974962 84 } message_t ;
andrebharath 3:2e32d7974962 85
andrebharath 3:2e32d7974962 86 Mail<message_t,16> outMessages;
andrebharath 3:2e32d7974962 87
TrebleStick 12:1b2e2540e4e1 88
TrebleStick 15:bd303ab8a21f 89 void putMessage(uint8_t code, int32_t data) {//uint64_t
TrebleStick 12:1b2e2540e4e1 90 message_t *pMessage = outMessages.alloc();
TrebleStick 12:1b2e2540e4e1 91 pMessage->code = code;
TrebleStick 12:1b2e2540e4e1 92 pMessage->data = data;
TrebleStick 12:1b2e2540e4e1 93 outMessages.put(pMessage);
TrebleStick 12:1b2e2540e4e1 94 }
TrebleStick 12:1b2e2540e4e1 95
TrebleStick 20:a435105305fe 96 Thread commOutT (osPriorityNormal, 512);
andrebharath 3:2e32d7974962 97
TrebleStick 12:1b2e2540e4e1 98 void commOutFn() {
andrebharath 3:2e32d7974962 99 while(1) {
andrebharath 3:2e32d7974962 100 osEvent newEvent = outMessages.get();
andrebharath 3:2e32d7974962 101 message_t *pMessage = (message_t*)newEvent.value.p;
TrebleStick 15:bd303ab8a21f 102 pc.printf("Message: [%d], data: 0x%08x\r\n",
andrebharath 3:2e32d7974962 103 pMessage->code,pMessage->data);
andrebharath 3:2e32d7974962 104 outMessages.free(pMessage);
andrebharath 3:2e32d7974962 105 }
andrebharath 3:2e32d7974962 106 }
andrebharath 3:2e32d7974962 107
andrebharath 9:ecef1e8cbe3d 108
andrebharath 9:ecef1e8cbe3d 109
TrebleStick 14:66746291017c 110 //Global varible for the Bitcoin Key,maxspeed and rotations_pending
TrebleStick 12:1b2e2540e4e1 111 volatile uint64_t newKey = 0; //check initialise value? ****
TrebleStick 14:66746291017c 112 volatile float maxspeed = 0, rotations_pending = 0;
TrebleStick 14:66746291017c 113 //mutex variables
TrebleStick 14:66746291017c 114 Mutex newKey_mutex;
TrebleStick 14:66746291017c 115 Mutex maxspeed_mutex;
TrebleStick 14:66746291017c 116 Mutex rotations_pending_mutex;
andrebharath 9:ecef1e8cbe3d 117
andrebharath 9:ecef1e8cbe3d 118 //Instantiate a Queue to buffer incoming characters
andrebharath 9:ecef1e8cbe3d 119 Queue<void, 8> inCharQ;
andrebharath 9:ecef1e8cbe3d 120 //serial port ISR to receive each incoming byte and place into queue
andrebharath 9:ecef1e8cbe3d 121 void serialISR() {
andrebharath 9:ecef1e8cbe3d 122 uint8_t newChar = pc.getc();
andrebharath 9:ecef1e8cbe3d 123 inCharQ.put((void*)newChar);
andrebharath 9:ecef1e8cbe3d 124 }
TrebleStick 20:a435105305fe 125 Thread motorCtrlT (osPriorityNormal, 2048);
TrebleStick 20:a435105305fe 126
TrebleStick 20:a435105305fe 127 int8_t readRotorState();
TrebleStick 20:a435105305fe 128 void motorOut(int8_t,uint32_t);
TrebleStick 20:a435105305fe 129 volatile int32_t motorPosition;
TrebleStick 20:a435105305fe 130
TrebleStick 20:a435105305fe 131 void photointerrupter_isr() {
TrebleStick 20:a435105305fe 132 static int8_t oldRotorState = 0;
TrebleStick 20:a435105305fe 133 int8_t rotorState = readRotorState();
TrebleStick 20:a435105305fe 134 motorOut((rotorState-orState+lead+6)%6, torque); //+6 to make sure the remainder is positive
TrebleStick 20:a435105305fe 135 if (rotorState - oldRotorState == 5) motorPosition--;
TrebleStick 20:a435105305fe 136 else if (rotorState - oldRotorState == -5) motorPosition++;
TrebleStick 20:a435105305fe 137 else motorPosition += (rotorState - oldRotorState);
TrebleStick 20:a435105305fe 138 oldRotorState = rotorState;
TrebleStick 20:a435105305fe 139 }
TrebleStick 20:a435105305fe 140
TrebleStick 20:a435105305fe 141 //TODO Implement timer for greater accuracy
TrebleStick 20:a435105305fe 142 void motorCtrlTick(){
TrebleStick 20:a435105305fe 143 motorCtrlT.signal_set(0x1);
TrebleStick 20:a435105305fe 144 }
TrebleStick 20:a435105305fe 145
TrebleStick 20:a435105305fe 146 float currentSpeed = 0;
andrebharath 9:ecef1e8cbe3d 147
andrebharath 9:ecef1e8cbe3d 148
TrebleStick 20:a435105305fe 149 void motorCtrlFn(){
TrebleStick 20:a435105305fe 150 int32_t posStart, posEnd;
TrebleStick 20:a435105305fe 151 Ticker motorCtrlTicker;
TrebleStick 20:a435105305fe 152 motorCtrlTicker.attach_us(&motorCtrlTick,100000);
TrebleStick 20:a435105305fe 153 // putMessage(MSG_TEST, 0x505);
TrebleStick 20:a435105305fe 154 uint8_t cnt = 0;
TrebleStick 20:a435105305fe 155
TrebleStick 20:a435105305fe 156 while(1){
TrebleStick 20:a435105305fe 157 posStart = motorPosition;
TrebleStick 20:a435105305fe 158 motorCtrlT.signal_wait(0x1);
TrebleStick 20:a435105305fe 159 posEnd = motorPosition;
TrebleStick 20:a435105305fe 160 currentSpeed = (posEnd-posStart)*10;
TrebleStick 20:a435105305fe 161
TrebleStick 20:a435105305fe 162 if(cnt >= 9) {
TrebleStick 20:a435105305fe 163 // putMessage(MSG_CUR_SPD, currentSpeed);
TrebleStick 20:a435105305fe 164 cnt = 0;
TrebleStick 20:a435105305fe 165 }
TrebleStick 20:a435105305fe 166 else{ cnt++; }
TrebleStick 20:a435105305fe 167 }
TrebleStick 19:526fd700e1b3 168 }
andrebharath 9:ecef1e8cbe3d 169
TrebleStick 20:a435105305fe 170
andrebharath 9:ecef1e8cbe3d 171
TrebleStick 14:66746291017c 172 void setNewCmd(char s[CHAR_ARR_SIZE])
TrebleStick 14:66746291017c 173 {
TrebleStick 14:66746291017c 174 uint64_t newKey_;
andrebharath 17:80159ace5ddf 175 uint32_t torque_;
TrebleStick 14:66746291017c 176 float maxspeed_, rotations_pending_;
TrebleStick 14:66746291017c 177 //R
TrebleStick 14:66746291017c 178 if (sscanf(s, "R%f", &rotations_pending_)) {
andrebharath 17:80159ace5ddf 179 rotations_pending_mutex.lock();
andrebharath 17:80159ace5ddf 180 rotations_pending = rotations_pending_;
andrebharath 17:80159ace5ddf 181 rotations_pending_mutex.unlock();
andrebharath 17:80159ace5ddf 182 putMessage(MSG_ROT_PEN, rotations_pending);
TrebleStick 14:66746291017c 183 //V
TrebleStick 20:a435105305fe 184 }
TrebleStick 20:a435105305fe 185 else if (sscanf(s, "V%f", &maxspeed_)) {
andrebharath 17:80159ace5ddf 186 maxspeed_mutex.lock();
andrebharath 17:80159ace5ddf 187 maxspeed = maxspeed_;
andrebharath 17:80159ace5ddf 188 maxspeed_mutex.unlock();
andrebharath 17:80159ace5ddf 189 putMessage(MSG_MAX_SPD, maxspeed);
TrebleStick 14:66746291017c 190 //K
TrebleStick 20:a435105305fe 191 }
TrebleStick 20:a435105305fe 192 else if (sscanf(s, "K%llx", &newKey_)) {
andrebharath 17:80159ace5ddf 193 newKey_mutex.lock();
andrebharath 17:80159ace5ddf 194 newKey = newKey_;
andrebharath 17:80159ace5ddf 195 newKey_mutex.unlock();
andrebharath 17:80159ace5ddf 196 putMessage(MSG_NEW_KEY, newKey);
TrebleStick 20:a435105305fe 197 }
TrebleStick 20:a435105305fe 198 else if (sscanf(s, "T%u", &torque_)) {
andrebharath 17:80159ace5ddf 199 torque = torque_;
TrebleStick 19:526fd700e1b3 200 photointerrupter_isr(); //Give it a kick
andrebharath 17:80159ace5ddf 201 putMessage(MSG_TORQUE, torque);
TrebleStick 14:66746291017c 202 //ERROR
TrebleStick 20:a435105305fe 203 }
TrebleStick 20:a435105305fe 204 else{
TrebleStick 20:a435105305fe 205 putMessage(MSG_INP_ERR, 0x404);
TrebleStick 20:a435105305fe 206 }
TrebleStick 14:66746291017c 207 }
TrebleStick 12:1b2e2540e4e1 208
TrebleStick 20:a435105305fe 209 Thread decodeT (osPriorityNormal, 512);
andrebharath 9:ecef1e8cbe3d 210
andrebharath 9:ecef1e8cbe3d 211 void decodeFn() {
andrebharath 9:ecef1e8cbe3d 212 pc.attach(&serialISR);
andrebharath 9:ecef1e8cbe3d 213 char charSeq[CHAR_ARR_SIZE] = "";
andrebharath 9:ecef1e8cbe3d 214 uint8_t bufPos = 0;
andrebharath 9:ecef1e8cbe3d 215 while(1) {
TrebleStick 12:1b2e2540e4e1 216
andrebharath 9:ecef1e8cbe3d 217 if(bufPos >= CHAR_ARR_SIZE) {
andrebharath 9:ecef1e8cbe3d 218 putMessage(MSG_OVERFLOW, bufPos);
TrebleStick 12:1b2e2540e4e1 219 bufPos = 0;
andrebharath 9:ecef1e8cbe3d 220 }
TrebleStick 13:ecccfc611025 221 else{
TrebleStick 12:1b2e2540e4e1 222
TrebleStick 13:ecccfc611025 223 osEvent newEvent = inCharQ.get();
TrebleStick 13:ecccfc611025 224 uint8_t newChar = (uint8_t)newEvent.value.p;
TrebleStick 12:1b2e2540e4e1 225
TrebleStick 13:ecccfc611025 226 if(newChar == '\r' || newChar == '\n') {
TrebleStick 13:ecccfc611025 227 charSeq[bufPos] = '\0';
TrebleStick 13:ecccfc611025 228 bufPos = 0;
TrebleStick 13:ecccfc611025 229 setNewCmd(charSeq);
TrebleStick 13:ecccfc611025 230 }
TrebleStick 13:ecccfc611025 231 else {
TrebleStick 13:ecccfc611025 232 charSeq[bufPos] = newChar;
TrebleStick 13:ecccfc611025 233 bufPos++;
TrebleStick 13:ecccfc611025 234 }
TrebleStick 12:1b2e2540e4e1 235 }
andrebharath 9:ecef1e8cbe3d 236 }
andrebharath 9:ecef1e8cbe3d 237 }
andrebharath 9:ecef1e8cbe3d 238
andrebharath 3:2e32d7974962 239 volatile uint16_t hashcount = 0;
TrebleStick 0:88c3d6c8a4eb 240
andrebharath 9:ecef1e8cbe3d 241 void do_hashcount() {
TrebleStick 15:bd303ab8a21f 242 //putMessage(MSG_HASHCOUNT, hashcount);
andrebharath 3:2e32d7974962 243 hashcount = 0;
andrebharath 3:2e32d7974962 244 }
andrebharath 9:ecef1e8cbe3d 245
andrebharath 9:ecef1e8cbe3d 246
TrebleStick 0:88c3d6c8a4eb 247 //Set a given drive state
andrebharath 17:80159ace5ddf 248 void motorOut(int8_t driveState, uint32_t t){
TrebleStick 12:1b2e2540e4e1 249
TrebleStick 0:88c3d6c8a4eb 250 //Lookup the output byte from the drive state.
TrebleStick 0:88c3d6c8a4eb 251 int8_t driveOut = driveTable[driveState & 0x07];
TrebleStick 12:1b2e2540e4e1 252
TrebleStick 0:88c3d6c8a4eb 253 //Turn off first
andrebharath 17:80159ace5ddf 254 if (~driveOut & 0x01) L1L.pulsewidth_us(0);
TrebleStick 0:88c3d6c8a4eb 255 if (~driveOut & 0x02) L1H = 1;
andrebharath 17:80159ace5ddf 256 if (~driveOut & 0x04) L2L.pulsewidth_us(0);
TrebleStick 0:88c3d6c8a4eb 257 if (~driveOut & 0x08) L2H = 1;
andrebharath 17:80159ace5ddf 258 if (~driveOut & 0x10) L3L.pulsewidth_us(0);
TrebleStick 0:88c3d6c8a4eb 259 if (~driveOut & 0x20) L3H = 1;
TrebleStick 12:1b2e2540e4e1 260
TrebleStick 0:88c3d6c8a4eb 261 //Then turn on
andrebharath 17:80159ace5ddf 262 if (driveOut & 0x01) L1L.pulsewidth_us(t);
TrebleStick 0:88c3d6c8a4eb 263 if (driveOut & 0x02) L1H = 0;
andrebharath 17:80159ace5ddf 264 if (driveOut & 0x04) L2L.pulsewidth_us(t);
TrebleStick 0:88c3d6c8a4eb 265 if (driveOut & 0x08) L2H = 0;
andrebharath 17:80159ace5ddf 266 if (driveOut & 0x10) L3L.pulsewidth_us(t);
TrebleStick 0:88c3d6c8a4eb 267 if (driveOut & 0x20) L3H = 0;
andrebharath 17:80159ace5ddf 268 }
TrebleStick 12:1b2e2540e4e1 269
andrebharath 9:ecef1e8cbe3d 270 //Convert photointerrupter inputs to a rotor state
andrebharath 9:ecef1e8cbe3d 271 inline int8_t readRotorState(){
TrebleStick 0:88c3d6c8a4eb 272 return stateMap[I1 + 2*I2 + 4*I3];
andrebharath 17:80159ace5ddf 273 }
andrebharath 9:ecef1e8cbe3d 274
TrebleStick 12:1b2e2540e4e1 275 //Basic synchronisation routine
andrebharath 9:ecef1e8cbe3d 276 int8_t motorHome() {
TrebleStick 0:88c3d6c8a4eb 277 //Put the motor in drive state 0 and wait for it to stabilise
andrebharath 18:05e5d280a082 278 motorOut(0, MAX_TORQUE);
andrebharath 3:2e32d7974962 279 wait(2.0);
TrebleStick 12:1b2e2540e4e1 280
TrebleStick 0:88c3d6c8a4eb 281 //Get the rotor state
TrebleStick 0:88c3d6c8a4eb 282 return readRotorState();
TrebleStick 0:88c3d6c8a4eb 283 }
andrebharath 3:2e32d7974962 284
andrebharath 9:ecef1e8cbe3d 285
TrebleStick 12:1b2e2540e4e1 286
TrebleStick 0:88c3d6c8a4eb 287 //Main
andrebharath 9:ecef1e8cbe3d 288 int main() {
TrebleStick 12:1b2e2540e4e1 289
andrebharath 9:ecef1e8cbe3d 290 putMessage(MSG_RESET, 0);
andrebharath 9:ecef1e8cbe3d 291
TrebleStick 20:a435105305fe 292 commOutT.start(&commOutFn);
TrebleStick 12:1b2e2540e4e1 293
TrebleStick 20:a435105305fe 294 motorCtrlT.start(&motorCtrlFn);
TrebleStick 12:1b2e2540e4e1 295
TrebleStick 12:1b2e2540e4e1 296 decodeT.start(&decodeFn);
TrebleStick 12:1b2e2540e4e1 297
andrebharath 9:ecef1e8cbe3d 298 //Run the motor synchronisation
andrebharath 9:ecef1e8cbe3d 299 orState = motorHome();
TrebleStick 20:a435105305fe 300
andrebharath 9:ecef1e8cbe3d 301 //orState is subtracted from future rotor state inputs to align rotor and motor states
TrebleStick 12:1b2e2540e4e1 302
andrebharath 3:2e32d7974962 303 I1.rise(&photointerrupter_isr);
andrebharath 3:2e32d7974962 304 I2.rise(&photointerrupter_isr);
andrebharath 3:2e32d7974962 305 I3.rise(&photointerrupter_isr);
TrebleStick 12:1b2e2540e4e1 306
andrebharath 3:2e32d7974962 307 I1.fall(&photointerrupter_isr);
andrebharath 3:2e32d7974962 308 I2.fall(&photointerrupter_isr);
andrebharath 3:2e32d7974962 309 I3.fall(&photointerrupter_isr);
TrebleStick 12:1b2e2540e4e1 310
andrebharath 18:05e5d280a082 311
andrebharath 18:05e5d280a082 312 L1L.period_us(MAX_PWM_PERIOD);
andrebharath 18:05e5d280a082 313 L2L.period_us(MAX_PWM_PERIOD);
andrebharath 18:05e5d280a082 314 L3L.period_us(MAX_PWM_PERIOD);
andrebharath 18:05e5d280a082 315
andrebharath 9:ecef1e8cbe3d 316 //Calling the ISR once starts the motor movement
andrebharath 9:ecef1e8cbe3d 317 photointerrupter_isr();
TrebleStick 19:526fd700e1b3 318
TrebleStick 19:526fd700e1b3 319
TrebleStick 12:1b2e2540e4e1 320
andrebharath 9:ecef1e8cbe3d 321 SHA256 sha256;
TrebleStick 12:1b2e2540e4e1 322
andrebharath 3:2e32d7974962 323 uint8_t sequence[] = {0x45,0x6D,0x62,0x65,0x64,0x64,0x65,0x64,
andrebharath 3:2e32d7974962 324 0x20,0x53,0x79,0x73,0x74,0x65,0x6D,0x73,
andrebharath 3:2e32d7974962 325 0x20,0x61,0x72,0x65,0x20,0x66,0x75,0x6E,
andrebharath 3:2e32d7974962 326 0x20,0x61,0x6E,0x64,0x20,0x64,0x6F,0x20,
andrebharath 3:2e32d7974962 327 0x61,0x77,0x65,0x73,0x6F,0x6D,0x65,0x20,
andrebharath 3:2e32d7974962 328 0x74,0x68,0x69,0x6E,0x67,0x73,0x21,0x20,
andrebharath 3:2e32d7974962 329 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
andrebharath 3:2e32d7974962 330 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
andrebharath 3:2e32d7974962 331 uint64_t* key = (uint64_t*)((int)sequence + 48);
andrebharath 3:2e32d7974962 332 uint64_t* nonce = (uint64_t*)((int)sequence + 56);
andrebharath 3:2e32d7974962 333 uint8_t hash[32];
TrebleStick 12:1b2e2540e4e1 334
andrebharath 9:ecef1e8cbe3d 335 Ticker hashcounter;
andrebharath 9:ecef1e8cbe3d 336 hashcounter.attach(&do_hashcount, 1.0);
TrebleStick 12:1b2e2540e4e1 337
TrebleStick 0:88c3d6c8a4eb 338 //Poll the rotor state and set the motor outputs accordingly to spin the motor
TrebleStick 0:88c3d6c8a4eb 339 while (1) {
TrebleStick 12:1b2e2540e4e1 340
andrebharath 9:ecef1e8cbe3d 341 *key = newKey;
TrebleStick 12:1b2e2540e4e1 342
andrebharath 9:ecef1e8cbe3d 343 sha256.computeHash(hash, sequence, 64);
TrebleStick 12:1b2e2540e4e1 344
andrebharath 3:2e32d7974962 345 if (hash[0] == 0 && hash[1] == 0) {
TrebleStick 15:bd303ab8a21f 346 //putMessage(MSG_NONCE_OK, *nonce);
andrebharath 3:2e32d7974962 347 }
andrebharath 3:2e32d7974962 348
andrebharath 3:2e32d7974962 349 (*nonce)++;
andrebharath 3:2e32d7974962 350 hashcount++;
TrebleStick 0:88c3d6c8a4eb 351 }
TrebleStick 0:88c3d6c8a4eb 352 }