![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
First Commit
Dependencies: mbed Crypto_light mbed-rtos
Spin it 2 win it
main.cpp@10:cedc98128562, 2018-03-20 (annotated)
- Committer:
- andrebharath
- Date:
- Tue Mar 20 11:25:22 2018 +0000
- Revision:
- 10:cedc98128562
- Parent:
- 8:e7818c369bd3
- Child:
- 11:14ccee7c6b59
Reimplementation of first two lab instructions
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:cedc98128562 | 9 | |
TrebleStick | 0:88c3d6c8a4eb | 10 | //Incremental encoder input pins |
TrebleStick | 0:88c3d6c8a4eb | 11 | #define CHA D7 |
TrebleStick | 0:88c3d6c8a4eb | 12 | #define CHB D8 |
andrebharath | 10:cedc98128562 | 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 | 10:cedc98128562 | 22 | #define CHAR_ARR_SIZE 18 //Max length of input codes |
TrebleStick | 7:0d6632fba8d4 | 23 | |
TrebleStick | 0:88c3d6c8a4eb | 24 | //Mapping from sequential drive states to motor phase outputs |
TrebleStick | 0:88c3d6c8a4eb | 25 | /* |
TrebleStick | 0:88c3d6c8a4eb | 26 | State L1 L2 L3 |
TrebleStick | 0:88c3d6c8a4eb | 27 | 0 H - L |
TrebleStick | 0:88c3d6c8a4eb | 28 | 1 - H L |
TrebleStick | 0:88c3d6c8a4eb | 29 | 2 L H - |
TrebleStick | 0:88c3d6c8a4eb | 30 | 3 L - H |
TrebleStick | 0:88c3d6c8a4eb | 31 | 4 - L H |
TrebleStick | 0:88c3d6c8a4eb | 32 | 5 H L - |
TrebleStick | 0:88c3d6c8a4eb | 33 | 6 - - - |
TrebleStick | 0:88c3d6c8a4eb | 34 | 7 - - - |
TrebleStick | 0:88c3d6c8a4eb | 35 | */ |
TrebleStick | 0:88c3d6c8a4eb | 36 | //Drive state to output table |
TrebleStick | 0:88c3d6c8a4eb | 37 | const int8_t driveTable[] = {0x12,0x18,0x09,0x21,0x24,0x06,0x00,0x00}; |
andrebharath | 10:cedc98128562 | 38 | |
TrebleStick | 0:88c3d6c8a4eb | 39 | //Mapping from interrupter inputs to sequential rotor states. 0x00 and 0x07 are not valid |
TrebleStick | 0:88c3d6c8a4eb | 40 | const int8_t stateMap[] = {0x07,0x05,0x03,0x04,0x01,0x00,0x02,0x07}; |
TrebleStick | 0:88c3d6c8a4eb | 41 | //const int8_t stateMap[] = {0x07,0x01,0x03,0x02,0x05,0x00,0x04,0x07}; //Alternative if phase order of input or drive is reversed |
andrebharath | 10:cedc98128562 | 42 | |
TrebleStick | 0:88c3d6c8a4eb | 43 | //Phase lead to make motor spin |
TrebleStick | 0:88c3d6c8a4eb | 44 | const int8_t lead = 2; //2 for forwards, -2 for backwards |
andrebharath | 10:cedc98128562 | 45 | |
andrebharath | 10:cedc98128562 | 46 | //Rotor offset at motor state 0 |
andrebharath | 10:cedc98128562 | 47 | int8_t orState = 0; |
TrebleStick | 4:e1141c1d8b19 | 48 | |
TrebleStick | 0:88c3d6c8a4eb | 49 | |
andrebharath | 10:cedc98128562 | 50 | enum MSG {MSG_RESET, MSG_HASHCOUNT, MSG_NONCE_OK, |
andrebharath | 10:cedc98128562 | 51 | MSG_OVERFLOW, MSG_NEW_KEY, MSG_ASSIGN_KEY}; |
andrebharath | 10:cedc98128562 | 52 | |
andrebharath | 10:cedc98128562 | 53 | //Instantiate the serial port |
andrebharath | 10:cedc98128562 | 54 | RawSerial pc(SERIAL_TX, SERIAL_RX); |
andrebharath | 10:cedc98128562 | 55 | |
andrebharath | 10:cedc98128562 | 56 | //Status LED |
andrebharath | 10:cedc98128562 | 57 | DigitalOut led1(LED1); |
andrebharath | 10:cedc98128562 | 58 | |
andrebharath | 10:cedc98128562 | 59 | //Photointerrupter inputs |
andrebharath | 10:cedc98128562 | 60 | InterruptIn I1(I1pin); |
andrebharath | 10:cedc98128562 | 61 | InterruptIn I2(I2pin); |
andrebharath | 10:cedc98128562 | 62 | InterruptIn I3(I3pin); |
andrebharath | 10:cedc98128562 | 63 | |
andrebharath | 10:cedc98128562 | 64 | //Motor Drive outputs |
andrebharath | 10:cedc98128562 | 65 | DigitalOut L1L(L1Lpin); |
andrebharath | 10:cedc98128562 | 66 | DigitalOut L1H(L1Hpin); |
andrebharath | 10:cedc98128562 | 67 | DigitalOut L2L(L2Lpin); |
andrebharath | 10:cedc98128562 | 68 | DigitalOut L2H(L2Hpin); |
andrebharath | 10:cedc98128562 | 69 | DigitalOut L3L(L3Lpin); |
andrebharath | 10:cedc98128562 | 70 | DigitalOut L3H(L3Hpin); |
andrebharath | 10:cedc98128562 | 71 | |
andrebharath | 10:cedc98128562 | 72 | |
andrebharath | 10:cedc98128562 | 73 | |
andrebharath | 3:2e32d7974962 | 74 | typedef struct { |
andrebharath | 3:2e32d7974962 | 75 | uint8_t code; |
andrebharath | 3:2e32d7974962 | 76 | uint32_t data; |
andrebharath | 3:2e32d7974962 | 77 | } message_t ; |
andrebharath | 3:2e32d7974962 | 78 | |
andrebharath | 3:2e32d7974962 | 79 | Mail<message_t,16> outMessages; |
andrebharath | 3:2e32d7974962 | 80 | |
andrebharath | 3:2e32d7974962 | 81 | Thread commOutT; |
andrebharath | 3:2e32d7974962 | 82 | |
andrebharath | 10:cedc98128562 | 83 | void commOutFn() { |
andrebharath | 3:2e32d7974962 | 84 | while(1) { |
andrebharath | 3:2e32d7974962 | 85 | osEvent newEvent = outMessages.get(); |
andrebharath | 3:2e32d7974962 | 86 | message_t *pMessage = (message_t*)newEvent.value.p; |
andrebharath | 3:2e32d7974962 | 87 | pc.printf("Message %d with data 0x%016x\r\n", |
andrebharath | 3:2e32d7974962 | 88 | pMessage->code,pMessage->data); |
andrebharath | 3:2e32d7974962 | 89 | outMessages.free(pMessage); |
andrebharath | 3:2e32d7974962 | 90 | } |
andrebharath | 3:2e32d7974962 | 91 | } |
andrebharath | 3:2e32d7974962 | 92 | |
andrebharath | 10:cedc98128562 | 93 | |
andrebharath | 10:cedc98128562 | 94 | void putMessage(uint8_t code, uint32_t data) { |
andrebharath | 10:cedc98128562 | 95 | message_t *pMessage = outMessages.alloc(); |
andrebharath | 10:cedc98128562 | 96 | pMessage->code = code; |
andrebharath | 10:cedc98128562 | 97 | pMessage->data = data; |
andrebharath | 10:cedc98128562 | 98 | outMessages.put(pMessage); |
andrebharath | 10:cedc98128562 | 99 | } |
andrebharath | 10:cedc98128562 | 100 | |
andrebharath | 10:cedc98128562 | 101 | |
andrebharath | 10:cedc98128562 | 102 | //Instantiate a Queue to buffer incoming characters |
andrebharath | 10:cedc98128562 | 103 | Queue<void, 8> inCharQ; |
andrebharath | 10:cedc98128562 | 104 | //serial port ISR to receive each incoming byte and place into queue |
andrebharath | 10:cedc98128562 | 105 | void serialISR() { |
andrebharath | 10:cedc98128562 | 106 | uint8_t newChar = pc.getc(); |
andrebharath | 10:cedc98128562 | 107 | inCharQ.put((void*)newChar); |
andrebharath | 10:cedc98128562 | 108 | } |
andrebharath | 10:cedc98128562 | 109 | |
andrebharath | 10:cedc98128562 | 110 | |
TrebleStick | 7:0d6632fba8d4 | 111 | //Global varible for the Bitcoin Key |
TrebleStick | 7:0d6632fba8d4 | 112 | volatile uint64_t newKey = 0; //check initialise value? **** |
andrebharath | 10:cedc98128562 | 113 | |
TrebleStick | 8:e7818c369bd3 | 114 | Mutex newKey_mutex; //for mutex locking |
TrebleStick | 7:0d6632fba8d4 | 115 | |
TrebleStick | 7:0d6632fba8d4 | 116 | |
TrebleStick | 5:fe9b21ba2e33 | 117 | Thread decodeT; |
TrebleStick | 5:fe9b21ba2e33 | 118 | |
andrebharath | 10:cedc98128562 | 119 | void setNewCmd(char newCmd[CHAR_ARR_SIZE]){ |
TrebleStick | 8:e7818c369bd3 | 120 | //regex error checking **** |
TrebleStick | 8:e7818c369bd3 | 121 | |
TrebleStick | 7:0d6632fba8d4 | 122 | //K |
TrebleStick | 8:e7818c369bd3 | 123 | if(newCmd[0] == 'K'){ |
TrebleStick | 7:0d6632fba8d4 | 124 | newKey_mutex.lock(); |
TrebleStick | 7:0d6632fba8d4 | 125 | sscanf(newCmd, "K%x", &newKey); //Decode the command |
TrebleStick | 7:0d6632fba8d4 | 126 | newKey_mutex.unlock(); |
andrebharath | 10:cedc98128562 | 127 | putMessage(MSG_NEW_KEY, newKey); |
TrebleStick | 7:0d6632fba8d4 | 128 | } |
TrebleStick | 8:e7818c369bd3 | 129 | |
TrebleStick | 7:0d6632fba8d4 | 130 | //V |
TrebleStick | 8:e7818c369bd3 | 131 | if(newCmd[0] == 'V'){ |
TrebleStick | 8:e7818c369bd3 | 132 | //set new velocity*** |
TrebleStick | 8:e7818c369bd3 | 133 | } |
TrebleStick | 7:0d6632fba8d4 | 134 | |
TrebleStick | 7:0d6632fba8d4 | 135 | //R |
TrebleStick | 8:e7818c369bd3 | 136 | if(newCmd[0] == 'R'){ |
TrebleStick | 8:e7818c369bd3 | 137 | //set new rotation*** |
TrebleStick | 8:e7818c369bd3 | 138 | } |
TrebleStick | 7:0d6632fba8d4 | 139 | |
TrebleStick | 7:0d6632fba8d4 | 140 | } |
TrebleStick | 7:0d6632fba8d4 | 141 | |
andrebharath | 10:cedc98128562 | 142 | |
andrebharath | 10:cedc98128562 | 143 | void decodeFn() { |
TrebleStick | 5:fe9b21ba2e33 | 144 | pc.attach(&serialISR); |
andrebharath | 10:cedc98128562 | 145 | char charSeq[CHAR_ARR_SIZE] = ""; |
andrebharath | 10:cedc98128562 | 146 | uint8_t bufPos = 0; |
andrebharath | 10:cedc98128562 | 147 | while(1) { |
andrebharath | 10:cedc98128562 | 148 | |
andrebharath | 10:cedc98128562 | 149 | if(bufPos >= CHAR_ARR_SIZE) { |
andrebharath | 10:cedc98128562 | 150 | putMessage(MSG_OVERFLOW, bufPos); |
andrebharath | 10:cedc98128562 | 151 | break; |
andrebharath | 10:cedc98128562 | 152 | } |
andrebharath | 10:cedc98128562 | 153 | |
TrebleStick | 5:fe9b21ba2e33 | 154 | osEvent newEvent = inCharQ.get(); |
TrebleStick | 5:fe9b21ba2e33 | 155 | uint8_t newChar = (uint8_t)newEvent.value.p; |
TrebleStick | 5:fe9b21ba2e33 | 156 | |
andrebharath | 10:cedc98128562 | 157 | if(newChar == '\r' ) { |
andrebharath | 10:cedc98128562 | 158 | charSeq[bufPos] = '0'; |
andrebharath | 10:cedc98128562 | 159 | bufPos = 0; |
andrebharath | 10:cedc98128562 | 160 | setNewCmd(charSeq); |
TrebleStick | 6:44c53574bf84 | 161 | } |
andrebharath | 10:cedc98128562 | 162 | else { |
andrebharath | 10:cedc98128562 | 163 | charSeq[bufPos] = newChar; |
andrebharath | 10:cedc98128562 | 164 | bufPos++; |
andrebharath | 10:cedc98128562 | 165 | } |
andrebharath | 10:cedc98128562 | 166 | } |
andrebharath | 10:cedc98128562 | 167 | } |
TrebleStick | 5:fe9b21ba2e33 | 168 | |
andrebharath | 10:cedc98128562 | 169 | |
andrebharath | 10:cedc98128562 | 170 | |
andrebharath | 10:cedc98128562 | 171 | |
andrebharath | 10:cedc98128562 | 172 | |
andrebharath | 10:cedc98128562 | 173 | |
andrebharath | 3:2e32d7974962 | 174 | volatile uint16_t hashcount = 0; |
TrebleStick | 0:88c3d6c8a4eb | 175 | |
andrebharath | 10:cedc98128562 | 176 | void do_hashcount() { |
andrebharath | 3:2e32d7974962 | 177 | putMessage(MSG_HASHCOUNT, hashcount); |
andrebharath | 3:2e32d7974962 | 178 | hashcount = 0; |
andrebharath | 3:2e32d7974962 | 179 | } |
andrebharath | 10:cedc98128562 | 180 | |
andrebharath | 10:cedc98128562 | 181 | |
TrebleStick | 0:88c3d6c8a4eb | 182 | //Set a given drive state |
andrebharath | 10:cedc98128562 | 183 | void motorOut(int8_t driveState){ |
TrebleStick | 0:88c3d6c8a4eb | 184 | |
TrebleStick | 0:88c3d6c8a4eb | 185 | //Lookup the output byte from the drive state. |
TrebleStick | 0:88c3d6c8a4eb | 186 | int8_t driveOut = driveTable[driveState & 0x07]; |
TrebleStick | 0:88c3d6c8a4eb | 187 | |
TrebleStick | 0:88c3d6c8a4eb | 188 | //Turn off first |
TrebleStick | 0:88c3d6c8a4eb | 189 | if (~driveOut & 0x01) L1L = 0; |
TrebleStick | 0:88c3d6c8a4eb | 190 | if (~driveOut & 0x02) L1H = 1; |
TrebleStick | 0:88c3d6c8a4eb | 191 | if (~driveOut & 0x04) L2L = 0; |
TrebleStick | 0:88c3d6c8a4eb | 192 | if (~driveOut & 0x08) L2H = 1; |
TrebleStick | 0:88c3d6c8a4eb | 193 | if (~driveOut & 0x10) L3L = 0; |
TrebleStick | 0:88c3d6c8a4eb | 194 | if (~driveOut & 0x20) L3H = 1; |
TrebleStick | 0:88c3d6c8a4eb | 195 | |
TrebleStick | 0:88c3d6c8a4eb | 196 | //Then turn on |
TrebleStick | 0:88c3d6c8a4eb | 197 | if (driveOut & 0x01) L1L = 1; |
TrebleStick | 0:88c3d6c8a4eb | 198 | if (driveOut & 0x02) L1H = 0; |
TrebleStick | 0:88c3d6c8a4eb | 199 | if (driveOut & 0x04) L2L = 1; |
TrebleStick | 0:88c3d6c8a4eb | 200 | if (driveOut & 0x08) L2H = 0; |
TrebleStick | 0:88c3d6c8a4eb | 201 | if (driveOut & 0x10) L3L = 1; |
TrebleStick | 0:88c3d6c8a4eb | 202 | if (driveOut & 0x20) L3H = 0; |
andrebharath | 10:cedc98128562 | 203 | } |
TrebleStick | 0:88c3d6c8a4eb | 204 | |
andrebharath | 10:cedc98128562 | 205 | //Convert photointerrupter inputs to a rotor state |
andrebharath | 10:cedc98128562 | 206 | inline int8_t readRotorState(){ |
TrebleStick | 0:88c3d6c8a4eb | 207 | return stateMap[I1 + 2*I2 + 4*I3]; |
andrebharath | 10:cedc98128562 | 208 | } |
andrebharath | 10:cedc98128562 | 209 | |
TrebleStick | 0:88c3d6c8a4eb | 210 | //Basic synchronisation routine |
andrebharath | 10:cedc98128562 | 211 | int8_t motorHome() { |
TrebleStick | 0:88c3d6c8a4eb | 212 | //Put the motor in drive state 0 and wait for it to stabilise |
TrebleStick | 0:88c3d6c8a4eb | 213 | motorOut(0); |
andrebharath | 3:2e32d7974962 | 214 | wait(2.0); |
TrebleStick | 0:88c3d6c8a4eb | 215 | |
TrebleStick | 0:88c3d6c8a4eb | 216 | //Get the rotor state |
TrebleStick | 0:88c3d6c8a4eb | 217 | return readRotorState(); |
TrebleStick | 0:88c3d6c8a4eb | 218 | } |
andrebharath | 3:2e32d7974962 | 219 | |
andrebharath | 3:2e32d7974962 | 220 | void photointerrupter_isr() |
andrebharath | 3:2e32d7974962 | 221 | { |
andrebharath | 3:2e32d7974962 | 222 | int8_t intState = readRotorState(); |
andrebharath | 3:2e32d7974962 | 223 | motorOut((intState-orState+lead+6)%6); //+6 to make sure the remainder is positive |
andrebharath | 3:2e32d7974962 | 224 | } |
andrebharath | 10:cedc98128562 | 225 | |
TrebleStick | 0:88c3d6c8a4eb | 226 | |
TrebleStick | 0:88c3d6c8a4eb | 227 | //Main |
andrebharath | 10:cedc98128562 | 228 | int main() { |
andrebharath | 10:cedc98128562 | 229 | |
andrebharath | 10:cedc98128562 | 230 | putMessage(MSG_RESET, 0); |
andrebharath | 10:cedc98128562 | 231 | |
andrebharath | 10:cedc98128562 | 232 | |
andrebharath | 10:cedc98128562 | 233 | commOutT.start(&commOutFn); |
andrebharath | 10:cedc98128562 | 234 | |
andrebharath | 10:cedc98128562 | 235 | decodeT.start(&decodeFn); |
andrebharath | 10:cedc98128562 | 236 | |
andrebharath | 10:cedc98128562 | 237 | // pc.printf("Hello\n\r"); |
andrebharath | 10:cedc98128562 | 238 | |
andrebharath | 10:cedc98128562 | 239 | //Run the motor synchronisation |
andrebharath | 10:cedc98128562 | 240 | orState = motorHome(); |
andrebharath | 10:cedc98128562 | 241 | // pc.printf("Rotor origin: %x\n\r",orState); |
andrebharath | 10:cedc98128562 | 242 | //orState is subtracted from future rotor state inputs to align rotor and motor states |
andrebharath | 10:cedc98128562 | 243 | |
andrebharath | 3:2e32d7974962 | 244 | I1.rise(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 245 | I2.rise(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 246 | I3.rise(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 247 | |
andrebharath | 3:2e32d7974962 | 248 | I1.fall(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 249 | I2.fall(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 250 | I3.fall(&photointerrupter_isr); |
andrebharath | 3:2e32d7974962 | 251 | |
andrebharath | 10:cedc98128562 | 252 | //Calling the ISR once starts the motor movement |
andrebharath | 10:cedc98128562 | 253 | photointerrupter_isr(); |
TrebleStick | 0:88c3d6c8a4eb | 254 | |
andrebharath | 10:cedc98128562 | 255 | SHA256 sha256; |
TrebleStick | 4:e1141c1d8b19 | 256 | |
andrebharath | 3:2e32d7974962 | 257 | uint8_t sequence[] = {0x45,0x6D,0x62,0x65,0x64,0x64,0x65,0x64, |
andrebharath | 3:2e32d7974962 | 258 | 0x20,0x53,0x79,0x73,0x74,0x65,0x6D,0x73, |
andrebharath | 3:2e32d7974962 | 259 | 0x20,0x61,0x72,0x65,0x20,0x66,0x75,0x6E, |
andrebharath | 3:2e32d7974962 | 260 | 0x20,0x61,0x6E,0x64,0x20,0x64,0x6F,0x20, |
andrebharath | 3:2e32d7974962 | 261 | 0x61,0x77,0x65,0x73,0x6F,0x6D,0x65,0x20, |
andrebharath | 3:2e32d7974962 | 262 | 0x74,0x68,0x69,0x6E,0x67,0x73,0x21,0x20, |
andrebharath | 3:2e32d7974962 | 263 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
andrebharath | 3:2e32d7974962 | 264 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
andrebharath | 3:2e32d7974962 | 265 | uint64_t* key = (uint64_t*)((int)sequence + 48); |
TrebleStick | 8:e7818c369bd3 | 266 | |
andrebharath | 10:cedc98128562 | 267 | newKey_mutex.lock(); |
andrebharath | 10:cedc98128562 | 268 | newKey = *key; |
andrebharath | 10:cedc98128562 | 269 | newKey_mutex.unlock(); |
TrebleStick | 8:e7818c369bd3 | 270 | |
andrebharath | 3:2e32d7974962 | 271 | uint64_t* nonce = (uint64_t*)((int)sequence + 56); |
andrebharath | 3:2e32d7974962 | 272 | uint8_t hash[32]; |
TrebleStick | 0:88c3d6c8a4eb | 273 | |
andrebharath | 10:cedc98128562 | 274 | Ticker hashcounter; |
andrebharath | 10:cedc98128562 | 275 | hashcounter.attach(&do_hashcount, 1.0); |
andrebharath | 10:cedc98128562 | 276 | |
TrebleStick | 0:88c3d6c8a4eb | 277 | //Poll the rotor state and set the motor outputs accordingly to spin the motor |
TrebleStick | 0:88c3d6c8a4eb | 278 | while (1) { |
andrebharath | 10:cedc98128562 | 279 | newKey_mutex.lock(); |
andrebharath | 10:cedc98128562 | 280 | *key = newKey; |
andrebharath | 10:cedc98128562 | 281 | newKey_mutex.unlock(); |
andrebharath | 10:cedc98128562 | 282 | |
andrebharath | 10:cedc98128562 | 283 | putMessage(MSG_ASSIGN_KEY, newKey); |
andrebharath | 10:cedc98128562 | 284 | |
andrebharath | 10:cedc98128562 | 285 | sha256.computeHash(hash, sequence, 64); |
TrebleStick | 0:88c3d6c8a4eb | 286 | |
andrebharath | 3:2e32d7974962 | 287 | if (hash[0] == 0 && hash[1] == 0) { |
andrebharath | 3:2e32d7974962 | 288 | putMessage(MSG_NONCE_OK, *nonce); |
andrebharath | 3:2e32d7974962 | 289 | } |
andrebharath | 3:2e32d7974962 | 290 | |
andrebharath | 3:2e32d7974962 | 291 | (*nonce)++; |
andrebharath | 3:2e32d7974962 | 292 | hashcount++; |
TrebleStick | 0:88c3d6c8a4eb | 293 | } |
TrebleStick | 0:88c3d6c8a4eb | 294 | } |
andrebharath | 10:cedc98128562 | 295 |