Callum and Adel's changes on 12/02/19
Dependencies: Crypto
main.cpp@30:fbae0e5f200d, 2019-03-18 (annotated)
- Committer:
- adehadd
- Date:
- Mon Mar 18 16:24:55 2019 +0000
- Revision:
- 30:fbae0e5f200d
- Parent:
- 29:c96439a60184
- Child:
- 31:b10ca6cf39bf
fml plz;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CallumAlder | 14:4e312fb83330 | 1 | #include "SHA256.h" |
estott | 0:de4320f74764 | 2 | #include "mbed.h" |
adehadd | 20:c60f4785b556 | 3 | // #include <iostream> |
adehadd | 20:c60f4785b556 | 4 | // #include "rtos.h" |
CallumAlder | 14:4e312fb83330 | 5 | |
CallumAlder | 19:805c87360b55 | 6 | /*TODO: |
iachinweze1 | 23:ab1cb51527d1 | 7 | Change |
CallumAlder | 19:805c87360b55 | 8 | Indx |
CallumAlder | 19:805c87360b55 | 9 | newCmd |
CallumAlder | 19:805c87360b55 | 10 | MAXCMDLENGTH |
CallumAlder | 28:4f02ac845e5d | 11 | move the global variables to a class because we arent paeasents |
CallumAlder | 19:805c87360b55 | 12 | */ |
estott | 0:de4320f74764 | 13 | |
estott | 0:de4320f74764 | 14 | //Photointerrupter input pins |
estott | 10:a4b5723b6c9d | 15 | #define I1pin D3 |
estott | 10:a4b5723b6c9d | 16 | #define I2pin D6 |
estott | 10:a4b5723b6c9d | 17 | #define I3pin D5 |
estott | 2:4e88faab6988 | 18 | |
estott | 2:4e88faab6988 | 19 | //Incremental encoder input pins |
estott | 10:a4b5723b6c9d | 20 | #define CHApin D12 |
estott | 10:a4b5723b6c9d | 21 | #define CHBpin D11 |
estott | 0:de4320f74764 | 22 | |
estott | 0:de4320f74764 | 23 | //Motor Drive output pins //Mask in output byte |
estott | 10:a4b5723b6c9d | 24 | #define L1Lpin D1 //0x01 |
estott | 10:a4b5723b6c9d | 25 | #define L1Hpin A3 //0x02 |
estott | 10:a4b5723b6c9d | 26 | #define L2Lpin D0 //0x04 |
estott | 10:a4b5723b6c9d | 27 | #define L2Hpin A6 //0x08 |
estott | 10:a4b5723b6c9d | 28 | #define L3Lpin D10 //0x10 |
estott | 10:a4b5723b6c9d | 29 | #define L3Hpin D2 //0x20 |
estott | 10:a4b5723b6c9d | 30 | |
estott | 10:a4b5723b6c9d | 31 | #define PWMpin D9 |
estott | 5:08f338b5e4d9 | 32 | |
estott | 5:08f338b5e4d9 | 33 | //Motor current sense |
estott | 5:08f338b5e4d9 | 34 | #define MCSPpin A1 |
estott | 5:08f338b5e4d9 | 35 | #define MCSNpin A0 |
estott | 0:de4320f74764 | 36 | |
estott | 0:de4320f74764 | 37 | //Mapping from sequential drive states to motor phase outputs |
estott | 0:de4320f74764 | 38 | /* |
estott | 0:de4320f74764 | 39 | State L1 L2 L3 |
estott | 0:de4320f74764 | 40 | 0 H - L |
estott | 0:de4320f74764 | 41 | 1 - H L |
estott | 0:de4320f74764 | 42 | 2 L H - |
estott | 0:de4320f74764 | 43 | 3 L - H |
estott | 0:de4320f74764 | 44 | 4 - L H |
estott | 0:de4320f74764 | 45 | 5 H L - |
estott | 0:de4320f74764 | 46 | 6 - - - |
estott | 0:de4320f74764 | 47 | 7 - - - |
estott | 0:de4320f74764 | 48 | */ |
CallumAlder | 28:4f02ac845e5d | 49 | |
CallumAlder | 29:c96439a60184 | 50 | //Status LED |
CallumAlder | 29:c96439a60184 | 51 | DigitalOut led1(LED1); |
CallumAlder | 28:4f02ac845e5d | 52 | |
CallumAlder | 29:c96439a60184 | 53 | //Photointerrupter inputs |
CallumAlder | 29:c96439a60184 | 54 | InterruptIn I1(I1pin); |
CallumAlder | 29:c96439a60184 | 55 | InterruptIn I2(I2pin); |
CallumAlder | 29:c96439a60184 | 56 | InterruptIn I3(I3pin); |
CallumAlder | 28:4f02ac845e5d | 57 | |
CallumAlder | 29:c96439a60184 | 58 | //Motor Drive outputs |
CallumAlder | 29:c96439a60184 | 59 | DigitalOut L1L(L1Lpin); |
CallumAlder | 29:c96439a60184 | 60 | DigitalOut L1H(L1Hpin); |
CallumAlder | 29:c96439a60184 | 61 | DigitalOut L2L(L2Lpin); |
CallumAlder | 29:c96439a60184 | 62 | DigitalOut L2H(L2Hpin); |
CallumAlder | 29:c96439a60184 | 63 | DigitalOut L3L(L3Lpin); |
CallumAlder | 29:c96439a60184 | 64 | DigitalOut L3H(L3Hpin); |
CallumAlder | 28:4f02ac845e5d | 65 | |
CallumAlder | 29:c96439a60184 | 66 | PwmOut pwmCtrl(PWMpin); |
CallumAlder | 28:4f02ac845e5d | 67 | |
estott | 0:de4320f74764 | 68 | //Drive state to output table |
estott | 0:de4320f74764 | 69 | const int8_t driveTable[] = {0x12,0x18,0x09,0x21,0x24,0x06,0x00,0x00}; |
estott | 2:4e88faab6988 | 70 | |
estott | 0:de4320f74764 | 71 | //Mapping from interrupter inputs to sequential rotor states. 0x00 and 0x07 are not valid |
iachinweze1 | 23:ab1cb51527d1 | 72 | const int8_t stateMap[] = {0x07,0x05,0x03,0x04,0x01,0x00,0x02,0x07}; |
estott | 2:4e88faab6988 | 73 | //const int8_t stateMap[] = {0x07,0x01,0x03,0x02,0x05,0x00,0x04,0x07}; //Alternative if phase order of input or drive is reversed |
estott | 2:4e88faab6988 | 74 | |
estott | 2:4e88faab6988 | 75 | //Phase lead to make motor spin |
estott | 3:569b35e2a602 | 76 | const int8_t lead = 2; //2 for forwards, -2 for backwards |
estott | 0:de4320f74764 | 77 | |
CallumAlder | 19:805c87360b55 | 78 | |
adehadd | 20:c60f4785b556 | 79 | class Comm /*: public T_*/{ |
iachinweze1 | 23:ab1cb51527d1 | 80 | |
iachinweze1 | 23:ab1cb51527d1 | 81 | public: |
iachinweze1 | 23:ab1cb51527d1 | 82 | |
iachinweze1 | 23:ab1cb51527d1 | 83 | Thread t_comm_out; |
iachinweze1 | 23:ab1cb51527d1 | 84 | // Thread *p_motor_ctrl; |
CallumAlder | 19:805c87360b55 | 85 | |
iachinweze1 | 23:ab1cb51527d1 | 86 | bool _RUN; |
iachinweze1 | 23:ab1cb51527d1 | 87 | |
iachinweze1 | 23:ab1cb51527d1 | 88 | RawSerial pc; |
iachinweze1 | 23:ab1cb51527d1 | 89 | // Queue<void, 8> inCharQ; // Input Character Queue |
iachinweze1 | 23:ab1cb51527d1 | 90 | |
iachinweze1 | 23:ab1cb51527d1 | 91 | |
iachinweze1 | 23:ab1cb51527d1 | 92 | static const char MsgChar[11]; |
CallumAlder | 19:805c87360b55 | 93 | |
iachinweze1 | 23:ab1cb51527d1 | 94 | uint8_t MAXCMDLENGTH; |
iachinweze1 | 23:ab1cb51527d1 | 95 | |
iachinweze1 | 23:ab1cb51527d1 | 96 | volatile uint8_t cmdIndx; |
iachinweze1 | 23:ab1cb51527d1 | 97 | volatile uint8_t inCharQIdx; |
CallumAlder | 19:805c87360b55 | 98 | |
iachinweze1 | 23:ab1cb51527d1 | 99 | volatile uint32_t motorPower; // motor toque |
iachinweze1 | 23:ab1cb51527d1 | 100 | volatile float targetVel; |
iachinweze1 | 23:ab1cb51527d1 | 101 | volatile float targetRot; |
CallumAlder | 19:805c87360b55 | 102 | |
iachinweze1 | 23:ab1cb51527d1 | 103 | enum msgType {motorState, posIn, velIn, posOut, velOut, |
iachinweze1 | 23:ab1cb51527d1 | 104 | |
iachinweze1 | 23:ab1cb51527d1 | 105 | hashRate, keyAdded, nonceMatch, |
iachinweze1 | 23:ab1cb51527d1 | 106 | |
iachinweze1 | 23:ab1cb51527d1 | 107 | torque, rotations, |
adehadd | 16:db7ef0a4aa23 | 108 | |
iachinweze1 | 23:ab1cb51527d1 | 109 | error}; |
iachinweze1 | 23:ab1cb51527d1 | 110 | |
iachinweze1 | 23:ab1cb51527d1 | 111 | typedef struct { |
iachinweze1 | 23:ab1cb51527d1 | 112 | msgType type; |
iachinweze1 | 23:ab1cb51527d1 | 113 | uint32_t message; |
iachinweze1 | 23:ab1cb51527d1 | 114 | } msg; |
iachinweze1 | 23:ab1cb51527d1 | 115 | |
iachinweze1 | 23:ab1cb51527d1 | 116 | Mail<msg, 32> mailStack; |
iachinweze1 | 23:ab1cb51527d1 | 117 | |
iachinweze1 | 23:ab1cb51527d1 | 118 | void serialISR(){ |
iachinweze1 | 23:ab1cb51527d1 | 119 | if (pc.readable()) { |
iachinweze1 | 23:ab1cb51527d1 | 120 | char newChar = pc.getc(); |
iachinweze1 | 23:ab1cb51527d1 | 121 | // inCharQ.put((void*)newChar); // void* = pointer to an unknown type that cannot be dereferenced |
CallumAlder | 19:805c87360b55 | 122 | |
iachinweze1 | 23:ab1cb51527d1 | 123 | if (inCharQIdx == (MAXCMDLENGTH)) { |
iachinweze1 | 23:ab1cb51527d1 | 124 | inCharQ[MAXCMDLENGTH] = '\0'; // force the string to have an end character |
iachinweze1 | 23:ab1cb51527d1 | 125 | putMessage(error, 1); |
iachinweze1 | 23:ab1cb51527d1 | 126 | inCharQIdx = 0; // reset buffer index |
iachinweze1 | 23:ab1cb51527d1 | 127 | // pc.putc('\r'); // carriage return moves to the start of the line |
iachinweze1 | 23:ab1cb51527d1 | 128 | // for (int i = 0; i < MAXCMDLENGTH; ++i) |
iachinweze1 | 23:ab1cb51527d1 | 129 | // { |
iachinweze1 | 23:ab1cb51527d1 | 130 | // inCharQ[i] = ' '; |
iachinweze1 | 23:ab1cb51527d1 | 131 | // pc.putc(' '); |
iachinweze1 | 23:ab1cb51527d1 | 132 | // } |
iachinweze1 | 23:ab1cb51527d1 | 133 | |
iachinweze1 | 23:ab1cb51527d1 | 134 | // pc.putc('\r'); // carriage return moves to the start of the line |
iachinweze1 | 23:ab1cb51527d1 | 135 | } |
iachinweze1 | 23:ab1cb51527d1 | 136 | else{ |
iachinweze1 | 23:ab1cb51527d1 | 137 | if(newChar != '\r'){ //While the command is not over, |
iachinweze1 | 23:ab1cb51527d1 | 138 | inCharQ[inCharQIdx] = newChar; //save input character and |
iachinweze1 | 23:ab1cb51527d1 | 139 | inCharQIdx++; //advance index |
iachinweze1 | 23:ab1cb51527d1 | 140 | pc.putc(newChar); |
adehadd | 20:c60f4785b556 | 141 | } |
adehadd | 20:c60f4785b556 | 142 | else{ |
iachinweze1 | 23:ab1cb51527d1 | 143 | inCharQ[inCharQIdx] = '\0'; //When the command is finally over, |
iachinweze1 | 23:ab1cb51527d1 | 144 | strncpy(newCmd, inCharQ, MAXCMDLENGTH); // Will copy 18 characters from inCharQ to newCmd |
iachinweze1 | 23:ab1cb51527d1 | 145 | cmdParser(); //parse the command for decoding. |
iachinweze1 | 23:ab1cb51527d1 | 146 | for (int i = 0; i < MAXCMDLENGTH; ++i) // reset buffer |
iachinweze1 | 23:ab1cb51527d1 | 147 | inCharQ[i] = ' '; |
iachinweze1 | 23:ab1cb51527d1 | 148 | inCharQIdx = 0; // reset index |
CallumAlder | 19:805c87360b55 | 149 | } |
CallumAlder | 19:805c87360b55 | 150 | } |
CallumAlder | 19:805c87360b55 | 151 | } |
CallumAlder | 19:805c87360b55 | 152 | |
iachinweze1 | 23:ab1cb51527d1 | 153 | |
iachinweze1 | 23:ab1cb51527d1 | 154 | } |
iachinweze1 | 23:ab1cb51527d1 | 155 | |
iachinweze1 | 23:ab1cb51527d1 | 156 | void returnCursor() { |
iachinweze1 | 23:ab1cb51527d1 | 157 | pc.putc('>'); |
iachinweze1 | 23:ab1cb51527d1 | 158 | for (int i = 0; i < inCharQIdx; ++i) // reset cursor position |
iachinweze1 | 23:ab1cb51527d1 | 159 | pc.putc(inCharQ[i]); |
iachinweze1 | 23:ab1cb51527d1 | 160 | // for (int i = inCharQIdx; i < MAXCMDLENGTH; ++i) // fill remaining with blanks |
iachinweze1 | 23:ab1cb51527d1 | 161 | // pc.putc(' '); |
iachinweze1 | 23:ab1cb51527d1 | 162 | // pc.putc('<'); |
iachinweze1 | 23:ab1cb51527d1 | 163 | } |
iachinweze1 | 23:ab1cb51527d1 | 164 | |
iachinweze1 | 23:ab1cb51527d1 | 165 | void cmdParser(){ |
iachinweze1 | 23:ab1cb51527d1 | 166 | switch(newCmd[0]) { |
iachinweze1 | 23:ab1cb51527d1 | 167 | case 'K': //(MsgChar[keyAdded]):// |
iachinweze1 | 23:ab1cb51527d1 | 168 | newKey_mutex.lock(); //Ensure there is no deadlock |
iachinweze1 | 23:ab1cb51527d1 | 169 | sscanf(newCmd, "K%x", &newKey); //Find desired the Key code |
iachinweze1 | 23:ab1cb51527d1 | 170 | putMessage(keyAdded, newKey); //Print it out |
iachinweze1 | 23:ab1cb51527d1 | 171 | newKey_mutex.unlock(); |
iachinweze1 | 23:ab1cb51527d1 | 172 | break; |
iachinweze1 | 23:ab1cb51527d1 | 173 | case 'V': //(MsgChar[velIn]):// |
iachinweze1 | 23:ab1cb51527d1 | 174 | sscanf(newCmd, "V%f", &targetVel); //Find desired the target velocity |
iachinweze1 | 23:ab1cb51527d1 | 175 | putMessage(velIn, targetVel); //Print it out |
iachinweze1 | 23:ab1cb51527d1 | 176 | break; |
iachinweze1 | 23:ab1cb51527d1 | 177 | case 'R': //(MsgChar[posIn]):// |
iachinweze1 | 23:ab1cb51527d1 | 178 | sscanf(newCmd, "R%f", &targetRot); //Find desired target rotation |
iachinweze1 | 23:ab1cb51527d1 | 179 | putMessage(posIn, targetRot); //Print it out |
iachinweze1 | 23:ab1cb51527d1 | 180 | break; |
iachinweze1 | 23:ab1cb51527d1 | 181 | case 'T': //(MsgChar[torque]):// |
iachinweze1 | 23:ab1cb51527d1 | 182 | sscanf(newCmd, "T%d", &motorPower); //Find desired target torque |
iachinweze1 | 23:ab1cb51527d1 | 183 | putMessage(torque, motorPower); //Print it out |
iachinweze1 | 23:ab1cb51527d1 | 184 | break; |
iachinweze1 | 23:ab1cb51527d1 | 185 | default: break; |
iachinweze1 | 23:ab1cb51527d1 | 186 | } |
iachinweze1 | 23:ab1cb51527d1 | 187 | } |
CallumAlder | 19:805c87360b55 | 188 | |
iachinweze1 | 23:ab1cb51527d1 | 189 | //~~~~~Decode messages to print on serial port~~~~~ |
iachinweze1 | 23:ab1cb51527d1 | 190 | void commOutFn() { |
iachinweze1 | 23:ab1cb51527d1 | 191 | while (_RUN) { |
iachinweze1 | 23:ab1cb51527d1 | 192 | osEvent newEvent = mailStack.get(); |
iachinweze1 | 23:ab1cb51527d1 | 193 | msg *pMessage = (msg *) newEvent.value.p; |
iachinweze1 | 23:ab1cb51527d1 | 194 | |
iachinweze1 | 23:ab1cb51527d1 | 195 | //Case switch to choose serial output based on incoming message |
iachinweze1 | 23:ab1cb51527d1 | 196 | switch (pMessage->type) { |
iachinweze1 | 23:ab1cb51527d1 | 197 | case motorState: |
iachinweze1 | 23:ab1cb51527d1 | 198 | pc.printf("The motor is currently in state %x\n\r", pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 199 | break; |
iachinweze1 | 23:ab1cb51527d1 | 200 | case hashRate: |
iachinweze1 | 23:ab1cb51527d1 | 201 | pc.printf("\r>%s< Mining: %.4u Hash/s\r", inCharQ, (uint32_t) pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 202 | returnCursor(); |
iachinweze1 | 23:ab1cb51527d1 | 203 | break; |
iachinweze1 | 23:ab1cb51527d1 | 204 | case nonceMatch: |
iachinweze1 | 23:ab1cb51527d1 | 205 | pc.printf("\r>%s< Nonce found: %x\r", inCharQ, pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 206 | returnCursor(); |
iachinweze1 | 23:ab1cb51527d1 | 207 | break; |
iachinweze1 | 23:ab1cb51527d1 | 208 | case keyAdded: |
iachinweze1 | 23:ab1cb51527d1 | 209 | pc.printf("New Key Added:\t0x%016x\n\r", pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 210 | break; |
iachinweze1 | 23:ab1cb51527d1 | 211 | case torque: |
iachinweze1 | 23:ab1cb51527d1 | 212 | pc.printf("Motor Torque set to:\t%d\n\r", pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 213 | break; |
iachinweze1 | 23:ab1cb51527d1 | 214 | case velIn: |
iachinweze1 | 23:ab1cb51527d1 | 215 | pc.printf("Target Velocity set to:\t%.2f\n\r", targetVel); |
iachinweze1 | 23:ab1cb51527d1 | 216 | break; |
iachinweze1 | 23:ab1cb51527d1 | 217 | case velOut: |
iachinweze1 | 23:ab1cb51527d1 | 218 | pc.printf("Current Velocity:\t%.2f\n\r", \ |
iachinweze1 | 23:ab1cb51527d1 | 219 | (float) ((int32_t) pMessage->message / 6)); |
iachinweze1 | 23:ab1cb51527d1 | 220 | break; |
iachinweze1 | 23:ab1cb51527d1 | 221 | case posIn: |
iachinweze1 | 23:ab1cb51527d1 | 222 | pc.printf("Target Rotation set to:\t%.2f\n\r", \ |
iachinweze1 | 23:ab1cb51527d1 | 223 | (float) ((int32_t) pMessage->message / 6)); |
iachinweze1 | 23:ab1cb51527d1 | 224 | break; |
iachinweze1 | 23:ab1cb51527d1 | 225 | case posOut: |
iachinweze1 | 23:ab1cb51527d1 | 226 | pc.printf("Current Position:\t%.2f\n\r", \ |
iachinweze1 | 23:ab1cb51527d1 | 227 | (float) ((int32_t) pMessage->message / 6)); |
iachinweze1 | 23:ab1cb51527d1 | 228 | break; |
iachinweze1 | 23:ab1cb51527d1 | 229 | case error: |
iachinweze1 | 23:ab1cb51527d1 | 230 | pc.printf("\r>%s< Debugging position:%x\n\r", inCharQ, pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 231 | for (int i = 0; i < MAXCMDLENGTH; ++i) // reset buffer |
iachinweze1 | 23:ab1cb51527d1 | 232 | inCharQ[i] = ' '; |
iachinweze1 | 23:ab1cb51527d1 | 233 | break; |
iachinweze1 | 23:ab1cb51527d1 | 234 | default: |
iachinweze1 | 23:ab1cb51527d1 | 235 | pc.printf("Unknown Error. Message: %x\n\r", pMessage->message); |
iachinweze1 | 23:ab1cb51527d1 | 236 | break; |
CallumAlder | 19:805c87360b55 | 237 | } |
iachinweze1 | 23:ab1cb51527d1 | 238 | mailStack.free(pMessage); |
iachinweze1 | 23:ab1cb51527d1 | 239 | } |
iachinweze1 | 23:ab1cb51527d1 | 240 | } |
adehadd | 20:c60f4785b556 | 241 | |
adehadd | 20:c60f4785b556 | 242 | |
adehadd | 20:c60f4785b556 | 243 | |
adehadd | 20:c60f4785b556 | 244 | |
iachinweze1 | 23:ab1cb51527d1 | 245 | //TODO: stop function, maybe use parent de-constructor |
iachinweze1 | 23:ab1cb51527d1 | 246 | //void stop_comm{} |
iachinweze1 | 23:ab1cb51527d1 | 247 | |
iachinweze1 | 23:ab1cb51527d1 | 248 | // public: |
iachinweze1 | 23:ab1cb51527d1 | 249 | |
iachinweze1 | 23:ab1cb51527d1 | 250 | volatile uint64_t newKey; // hash key |
iachinweze1 | 23:ab1cb51527d1 | 251 | Mutex newKey_mutex; // Restrict access to prevent deadlock. |
adehadd | 20:c60f4785b556 | 252 | |
iachinweze1 | 23:ab1cb51527d1 | 253 | Comm() : pc(SERIAL_TX, SERIAL_RX), |
adehadd | 30:fbae0e5f200d | 254 | t_comm_out(osPriorityAboveNormal, 1024) |
iachinweze1 | 23:ab1cb51527d1 | 255 | { // inherit from the RawSerial constructor |
adehadd | 20:c60f4785b556 | 256 | |
iachinweze1 | 23:ab1cb51527d1 | 257 | pc.printf("%s\n\r", "Welcome" ); |
iachinweze1 | 23:ab1cb51527d1 | 258 | MAXCMDLENGTH = 18; |
adehadd | 20:c60f4785b556 | 259 | |
iachinweze1 | 23:ab1cb51527d1 | 260 | // reset buffer |
iachinweze1 | 23:ab1cb51527d1 | 261 | // MbedOS prints 'Embedded Systems are fun and do awesome things!' |
iachinweze1 | 23:ab1cb51527d1 | 262 | // if you print a null terminator |
iachinweze1 | 23:ab1cb51527d1 | 263 | pc.putc('>'); |
iachinweze1 | 23:ab1cb51527d1 | 264 | for (int i = 0; i < MAXCMDLENGTH; ++i) { |
iachinweze1 | 23:ab1cb51527d1 | 265 | inCharQ[i] = '.'; |
iachinweze1 | 23:ab1cb51527d1 | 266 | pc.putc('.'); |
CallumAlder | 19:805c87360b55 | 267 | } |
iachinweze1 | 23:ab1cb51527d1 | 268 | pc.putc('<'); |
iachinweze1 | 23:ab1cb51527d1 | 269 | pc.putc('\r'); |
iachinweze1 | 23:ab1cb51527d1 | 270 | |
iachinweze1 | 23:ab1cb51527d1 | 271 | inCharQ[MAXCMDLENGTH] = '\0'; |
iachinweze1 | 23:ab1cb51527d1 | 272 | strncpy(newCmd, inCharQ, MAXCMDLENGTH); |
iachinweze1 | 23:ab1cb51527d1 | 273 | |
iachinweze1 | 23:ab1cb51527d1 | 274 | cmdIndx = 0; |
iachinweze1 | 23:ab1cb51527d1 | 275 | |
iachinweze1 | 23:ab1cb51527d1 | 276 | inCharQIdx = 0; |
iachinweze1 | 23:ab1cb51527d1 | 277 | // inCharQIdx = MAXCMDLENGTH-1; |
iachinweze1 | 23:ab1cb51527d1 | 278 | |
iachinweze1 | 23:ab1cb51527d1 | 279 | |
iachinweze1 | 23:ab1cb51527d1 | 280 | |
iachinweze1 | 23:ab1cb51527d1 | 281 | pc.attach(callback(this, &Comm::serialISR)); |
iachinweze1 | 23:ab1cb51527d1 | 282 | |
iachinweze1 | 23:ab1cb51527d1 | 283 | // Thread t_comm_in(osPriorityAboveNormal, 1024); |
iachinweze1 | 23:ab1cb51527d1 | 284 | // Thread t_comm_out(osPriorityAboveNormal, 1024); |
iachinweze1 | 23:ab1cb51527d1 | 285 | // Thread t_motor_ctrl(osPriorityAboveNormal, 1024); |
iachinweze1 | 23:ab1cb51527d1 | 286 | |
iachinweze1 | 23:ab1cb51527d1 | 287 | motorPower = 300; |
iachinweze1 | 23:ab1cb51527d1 | 288 | targetVel = 45.0; |
iachinweze1 | 23:ab1cb51527d1 | 289 | targetRot = 459.0; |
iachinweze1 | 23:ab1cb51527d1 | 290 | |
adehadd | 20:c60f4785b556 | 291 | |
CallumAlder | 19:805c87360b55 | 292 | |
iachinweze1 | 23:ab1cb51527d1 | 293 | /*MsgChar = {'m', 'R', 'V', 'r', 'v', |
iachinweze1 | 23:ab1cb51527d1 | 294 | |
iachinweze1 | 23:ab1cb51527d1 | 295 | 'h', 'K', 'n', |
iachinweze1 | 23:ab1cb51527d1 | 296 | |
iachinweze1 | 23:ab1cb51527d1 | 297 | 'T', 'r', |
iachinweze1 | 23:ab1cb51527d1 | 298 | |
iachinweze1 | 23:ab1cb51527d1 | 299 | 'e'};*/ |
iachinweze1 | 23:ab1cb51527d1 | 300 | } |
iachinweze1 | 23:ab1cb51527d1 | 301 | |
iachinweze1 | 23:ab1cb51527d1 | 302 | |
iachinweze1 | 23:ab1cb51527d1 | 303 | void putMessage(msgType type, uint32_t message){ |
iachinweze1 | 23:ab1cb51527d1 | 304 | msg *p_msg = mailStack.alloc(); |
iachinweze1 | 23:ab1cb51527d1 | 305 | p_msg->type = type; |
iachinweze1 | 23:ab1cb51527d1 | 306 | p_msg->message = message; |
iachinweze1 | 23:ab1cb51527d1 | 307 | mailStack.put(p_msg); |
iachinweze1 | 23:ab1cb51527d1 | 308 | } |
iachinweze1 | 23:ab1cb51527d1 | 309 | |
iachinweze1 | 23:ab1cb51527d1 | 310 | void start_comm(){ |
iachinweze1 | 23:ab1cb51527d1 | 311 | _RUN = true; |
iachinweze1 | 23:ab1cb51527d1 | 312 | |
adehadd | 20:c60f4785b556 | 313 | |
iachinweze1 | 23:ab1cb51527d1 | 314 | // reset buffer |
iachinweze1 | 23:ab1cb51527d1 | 315 | // MbedOS prints 'Embedded Systems are fun and do awesome things!' |
iachinweze1 | 23:ab1cb51527d1 | 316 | // if you print a null terminator |
iachinweze1 | 23:ab1cb51527d1 | 317 | pc.putc('>'); |
iachinweze1 | 23:ab1cb51527d1 | 318 | for (int i = 0; i < MAXCMDLENGTH; ++i) { |
iachinweze1 | 23:ab1cb51527d1 | 319 | inCharQ[i] = '.'; |
iachinweze1 | 23:ab1cb51527d1 | 320 | pc.putc('.'); |
iachinweze1 | 23:ab1cb51527d1 | 321 | } |
iachinweze1 | 23:ab1cb51527d1 | 322 | pc.putc('<'); |
iachinweze1 | 23:ab1cb51527d1 | 323 | pc.putc('\r'); |
iachinweze1 | 23:ab1cb51527d1 | 324 | |
iachinweze1 | 23:ab1cb51527d1 | 325 | inCharQ[MAXCMDLENGTH] = '\0'; |
iachinweze1 | 23:ab1cb51527d1 | 326 | strncpy(newCmd, inCharQ, MAXCMDLENGTH); |
adehadd | 20:c60f4785b556 | 327 | |
iachinweze1 | 23:ab1cb51527d1 | 328 | // returnCursor(); |
adehadd | 20:c60f4785b556 | 329 | |
iachinweze1 | 23:ab1cb51527d1 | 330 | // t_comm_in.start(callback(this, &Comm::commInFn)); |
iachinweze1 | 23:ab1cb51527d1 | 331 | // this::thread::wait() |
iachinweze1 | 23:ab1cb51527d1 | 332 | // wait(1.0); |
iachinweze1 | 23:ab1cb51527d1 | 333 | t_comm_out.start(callback(this, &Comm::commOutFn)); |
adehadd | 30:fbae0e5f200d | 334 | |
iachinweze1 | 23:ab1cb51527d1 | 335 | |
iachinweze1 | 23:ab1cb51527d1 | 336 | |
iachinweze1 | 23:ab1cb51527d1 | 337 | } |
iachinweze1 | 23:ab1cb51527d1 | 338 | |
iachinweze1 | 23:ab1cb51527d1 | 339 | char newCmd[]; // because unallocated must be defined at the bottom of the class |
iachinweze1 | 23:ab1cb51527d1 | 340 | char inCharQ[]; |
CallumAlder | 19:805c87360b55 | 341 | }; |
CallumAlder | 19:805c87360b55 | 342 | |
iachinweze1 | 12:41b3112021a3 | 343 | |
adehadd | 20:c60f4785b556 | 344 | |
adehadd | 30:fbae0e5f200d | 345 | class Motor { |
CallumAlder | 28:4f02ac845e5d | 346 | |
CallumAlder | 28:4f02ac845e5d | 347 | |
CallumAlder | 28:4f02ac845e5d | 348 | protected: |
adehadd | 30:fbae0e5f200d | 349 | const int8_t orState; //Rotor offset at motor state 0, motor specific |
adehadd | 30:fbae0e5f200d | 350 | volatile int8_t currentState; //Current Rotor State |
adehadd | 30:fbae0e5f200d | 351 | volatile int8_t stateList[6]; //All possible rotor states stored |
adehadd | 30:fbae0e5f200d | 352 | |
adehadd | 30:fbae0e5f200d | 353 | //Phase lead to make motor spin |
adehadd | 30:fbae0e5f200d | 354 | int8_t lead; |
adehadd | 30:fbae0e5f200d | 355 | |
adehadd | 30:fbae0e5f200d | 356 | Comm* p_comm; |
adehadd | 30:fbae0e5f200d | 357 | |
CallumAlder | 28:4f02ac845e5d | 358 | //Run the motor synchronisation |
CallumAlder | 28:4f02ac845e5d | 359 | |
adehadd | 30:fbae0e5f200d | 360 | float dutyC; // 1 = 100% |
adehadd | 30:fbae0e5f200d | 361 | float mtrPeriod; // motor period |
adehadd | 30:fbae0e5f200d | 362 | uint8_t stateCount[3]; // State Counter |
adehadd | 30:fbae0e5f200d | 363 | uint8_t theStates[3]; // The Key states |
iachinweze1 | 23:ab1cb51527d1 | 364 | |
adehadd | 30:fbae0e5f200d | 365 | Thread t_motor_ctrl; // Thread for motor Control |
CallumAlder | 28:4f02ac845e5d | 366 | |
CallumAlder | 28:4f02ac845e5d | 367 | public: |
CallumAlder | 28:4f02ac845e5d | 368 | |
adehadd | 30:fbae0e5f200d | 369 | Motor() : t_motor_ctrl(osPriorityAboveNormal, 1024) |
adehadd | 30:fbae0e5f200d | 370 | { |
adehadd | 30:fbae0e5f200d | 371 | // Set Power to maximum to drive motorHome() |
adehadd | 30:fbae0e5f200d | 372 | dutyC = 1; |
CallumAlder | 29:c96439a60184 | 373 | mtrPeriod = 2e-3; // motor period |
adehadd | 30:fbae0e5f200d | 374 | pwmCtrl.period(mtrPeriod); |
CallumAlder | 28:4f02ac845e5d | 375 | pwmCtrl.pulsewidth(mtrPeriod*dutyC); |
CallumAlder | 28:4f02ac845e5d | 376 | |
adehadd | 30:fbae0e5f200d | 377 | orState = motorHome(); //Rotot offset at motor state 0 |
adehadd | 30:fbae0e5f200d | 378 | currentState = readRotorState(); //Current Rotor State |
adehadd | 30:fbae0e5f200d | 379 | // stateList[6] = {0,0,0, 0,0,0}; //All possible rotor states stored |
adehadd | 30:fbae0e5f200d | 380 | |
adehadd | 30:fbae0e5f200d | 381 | theStates[0] = orState; |
adehadd | 30:fbae0e5f200d | 382 | theStates[1] = (orState + lead) % 6; |
adehadd | 30:fbae0e5f200d | 383 | theStates[2] = (orState + (lead*2)) % 6; |
iachinweze1 | 23:ab1cb51527d1 | 384 | |
adehadd | 30:fbae0e5f200d | 385 | lead = 2; //2 for forwards, -2 for backwards |
adehadd | 30:fbae0e5f200d | 386 | |
adehadd | 30:fbae0e5f200d | 387 | stateCount = 0; |
adehadd | 30:fbae0e5f200d | 388 | |
adehadd | 30:fbae0e5f200d | 389 | // p_comm = null; // null pointer for now |
adehadd | 30:fbae0e5f200d | 390 | |
adehadd | 30:fbae0e5f200d | 391 | } |
adehadd | 30:fbae0e5f200d | 392 | |
adehadd | 30:fbae0e5f200d | 393 | |
adehadd | 30:fbae0e5f200d | 394 | void motorStart(Comm &comm) { |
adehadd | 30:fbae0e5f200d | 395 | |
adehadd | 30:fbae0e5f200d | 396 | // Establish Photointerrupter Service Routines (auto choose next state) |
CallumAlder | 29:c96439a60184 | 397 | I1.fall(callback(this, &Motor::stateUpdate)); |
CallumAlder | 29:c96439a60184 | 398 | I2.fall(callback(this, &Motor::stateUpdate)); |
CallumAlder | 29:c96439a60184 | 399 | I3.fall(callback(this, &Motor::stateUpdate)); |
CallumAlder | 29:c96439a60184 | 400 | I1.rise(callback(this, &Motor::stateUpdate)); |
CallumAlder | 29:c96439a60184 | 401 | I2.rise(callback(this, &Motor::stateUpdate)); |
CallumAlder | 29:c96439a60184 | 402 | I3.rise(callback(this, &Motor::stateUpdate)); |
CallumAlder | 28:4f02ac845e5d | 403 | |
adehadd | 30:fbae0e5f200d | 404 | // push digitally so if motor is static it will start moving |
adehadd | 30:fbae0e5f200d | 405 | motorOut((currentState-orState+lead+6)%6); // We push it digitally |
adehadd | 30:fbae0e5f200d | 406 | |
adehadd | 30:fbae0e5f200d | 407 | // Default a lower duty cylce |
adehadd | 30:fbae0e5f200d | 408 | dutyC = 0.8; |
CallumAlder | 28:4f02ac845e5d | 409 | pwmCtrl.period(mtrPeriod); |
CallumAlder | 28:4f02ac845e5d | 410 | pwmCtrl.pulsewidth(mtrPeriod*dutyC); |
CallumAlder | 28:4f02ac845e5d | 411 | |
adehadd | 30:fbae0e5f200d | 412 | // Start motor control thread |
adehadd | 30:fbae0e5f200d | 413 | t_motor_ctrl.start(callback(this, &Comm::motorCtrlFn)); |
CallumAlder | 28:4f02ac845e5d | 414 | } |
CallumAlder | 28:4f02ac845e5d | 415 | |
CallumAlder | 28:4f02ac845e5d | 416 | //Set a given drive state |
adehadd | 30:fbae0e5f200d | 417 | void motorOut(int8_t driveState) { |
CallumAlder | 28:4f02ac845e5d | 418 | |
CallumAlder | 28:4f02ac845e5d | 419 | //Lookup the output byte from the drive state. |
CallumAlder | 28:4f02ac845e5d | 420 | int8_t driveOut = driveTable[driveState & 0x07]; |
CallumAlder | 28:4f02ac845e5d | 421 | |
CallumAlder | 28:4f02ac845e5d | 422 | //Turn off first |
CallumAlder | 28:4f02ac845e5d | 423 | if (~driveOut & 0x01) L1L = 0; |
CallumAlder | 28:4f02ac845e5d | 424 | if (~driveOut & 0x02) L1H = 1; |
CallumAlder | 28:4f02ac845e5d | 425 | if (~driveOut & 0x04) L2L = 0; |
CallumAlder | 28:4f02ac845e5d | 426 | if (~driveOut & 0x08) L2H = 1; |
CallumAlder | 28:4f02ac845e5d | 427 | if (~driveOut & 0x10) L3L = 0; |
CallumAlder | 28:4f02ac845e5d | 428 | if (~driveOut & 0x20) L3H = 1; |
iachinweze1 | 23:ab1cb51527d1 | 429 | |
CallumAlder | 28:4f02ac845e5d | 430 | //Then turn on |
CallumAlder | 28:4f02ac845e5d | 431 | if (driveOut & 0x01) L1L = 1; |
CallumAlder | 28:4f02ac845e5d | 432 | if (driveOut & 0x02) L1H = 0; |
CallumAlder | 28:4f02ac845e5d | 433 | if (driveOut & 0x04) L2L = 1; |
CallumAlder | 28:4f02ac845e5d | 434 | if (driveOut & 0x08) L2H = 0; |
CallumAlder | 28:4f02ac845e5d | 435 | if (driveOut & 0x10) L3L = 1; |
CallumAlder | 28:4f02ac845e5d | 436 | if (driveOut & 0x20) L3H = 0; |
CallumAlder | 28:4f02ac845e5d | 437 | } |
CallumAlder | 28:4f02ac845e5d | 438 | |
CallumAlder | 28:4f02ac845e5d | 439 | //Convert photointerrupter inputs to a rotor state |
adehadd | 30:fbae0e5f200d | 440 | inline int8_t readRotorState() { |
CallumAlder | 28:4f02ac845e5d | 441 | return stateMap[I1 + 2*I2 + 4*I3]; |
CallumAlder | 28:4f02ac845e5d | 442 | } |
adehadd | 20:c60f4785b556 | 443 | |
CallumAlder | 28:4f02ac845e5d | 444 | //Basic synchronisation routine |
CallumAlder | 28:4f02ac845e5d | 445 | int8_t motorHome() { |
CallumAlder | 28:4f02ac845e5d | 446 | //Put the motor in drive state 0 and wait for it to stabilise |
CallumAlder | 28:4f02ac845e5d | 447 | motorOut(0); |
CallumAlder | 28:4f02ac845e5d | 448 | wait(2.0); |
CallumAlder | 28:4f02ac845e5d | 449 | |
CallumAlder | 28:4f02ac845e5d | 450 | //Get the rotor state |
CallumAlder | 28:4f02ac845e5d | 451 | return readRotorState(); |
CallumAlder | 28:4f02ac845e5d | 452 | } |
iachinweze1 | 23:ab1cb51527d1 | 453 | |
CallumAlder | 28:4f02ac845e5d | 454 | |
CallumAlder | 29:c96439a60184 | 455 | void stateUpdate() { // () { // **params |
adehadd | 30:fbae0e5f200d | 456 | currentState = readRotorState(); |
CallumAlder | 28:4f02ac845e5d | 457 | |
adehadd | 30:fbae0e5f200d | 458 | // Store into state counter |
adehadd | 30:fbae0e5f200d | 459 | switch (currentState) { |
adehadd | 30:fbae0e5f200d | 460 | case 1: |
adehadd | 30:fbae0e5f200d | 461 | stateCount[0]++; |
adehadd | 30:fbae0e5f200d | 462 | break; |
adehadd | 30:fbae0e5f200d | 463 | case (1 + lead): |
adehadd | 30:fbae0e5f200d | 464 | stateCount[1]++; |
adehadd | 30:fbae0e5f200d | 465 | break; |
adehadd | 30:fbae0e5f200d | 466 | case (1 + (lead*2)): |
adehadd | 30:fbae0e5f200d | 467 | stateCount[2]++; |
adehadd | 30:fbae0e5f200d | 468 | break; |
CallumAlder | 29:c96439a60184 | 469 | } |
adehadd | 30:fbae0e5f200d | 470 | // (Current - Offset + lead + 6) %6 |
adehadd | 30:fbae0e5f200d | 471 | motorOut((currentState - orState + lead + 6) % 6); |
adehadd | 30:fbae0e5f200d | 472 | |
adehadd | 30:fbae0e5f200d | 473 | } |
adehadd | 30:fbae0e5f200d | 474 | |
adehadd | 30:fbae0e5f200d | 475 | |
adehadd | 30:fbae0e5f200d | 476 | |
adehadd | 30:fbae0e5f200d | 477 | // attach_us -> runs funtion every 100ms |
adehadd | 30:fbae0e5f200d | 478 | void motorCtrlFn() { |
adehadd | 30:fbae0e5f200d | 479 | Ticker motorCtrlTicker; |
adehadd | 30:fbae0e5f200d | 480 | motorCtrlTicker.attach_us(callback(this,&Comm::motorCtrlTick), 1e5); |
adehadd | 30:fbae0e5f200d | 481 | while (1) { |
adehadd | 30:fbae0e5f200d | 482 | t_motor_ctrl.signal_wait((int32_t)0x1); |
adehadd | 30:fbae0e5f200d | 483 | pc.printf("B4115"); |
CallumAlder | 29:c96439a60184 | 484 | } |
adehadd | 30:fbae0e5f200d | 485 | } |
adehadd | 30:fbae0e5f200d | 486 | |
adehadd | 30:fbae0e5f200d | 487 | void motorCtrlTick(){ |
adehadd | 30:fbae0e5f200d | 488 | t_motor_ctrl.signal_set(0x1); |
CallumAlder | 28:4f02ac845e5d | 489 | } |
CallumAlder | 28:4f02ac845e5d | 490 | |
CallumAlder | 29:c96439a60184 | 491 | }; |
adehadd | 20:c60f4785b556 | 492 | |
adehadd | 20:c60f4785b556 | 493 | |
adehadd | 20:c60f4785b556 | 494 | |
estott | 0:de4320f74764 | 495 | //Main |
estott | 0:de4320f74764 | 496 | int main() { |
CallumAlder | 19:805c87360b55 | 497 | |
iachinweze1 | 23:ab1cb51527d1 | 498 | // std::ios::sync_with_stdio(false); |
iachinweze1 | 23:ab1cb51527d1 | 499 | Comm comm_plz; |
adehadd | 20:c60f4785b556 | 500 | |
adehadd | 20:c60f4785b556 | 501 | // comm_plz.pc.printf("%s\n", "do i work bruh" ); // using printf of class is calm |
adehadd | 20:c60f4785b556 | 502 | SHA256 Miner; |
iachinweze1 | 23:ab1cb51527d1 | 503 | |
CallumAlder | 28:4f02ac845e5d | 504 | Motor motor; |
CallumAlder | 28:4f02ac845e5d | 505 | |
CallumAlder | 14:4e312fb83330 | 506 | uint8_t sequence[] = {0x45,0x6D,0x62,0x65,0x64,0x64,0x65,0x64, |
CallumAlder | 14:4e312fb83330 | 507 | 0x20,0x53,0x79,0x73,0x74,0x65,0x6D,0x73, |
CallumAlder | 14:4e312fb83330 | 508 | 0x20,0x61,0x72,0x65,0x20,0x66,0x75,0x6E, |
CallumAlder | 14:4e312fb83330 | 509 | 0x20,0x61,0x6E,0x64,0x20,0x64,0x6F,0x20, |
CallumAlder | 14:4e312fb83330 | 510 | 0x61,0x77,0x65,0x73,0x6F,0x6D,0x65,0x20, |
CallumAlder | 14:4e312fb83330 | 511 | 0x74,0x68,0x69,0x6E,0x67,0x73,0x21,0x20, |
CallumAlder | 14:4e312fb83330 | 512 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
CallumAlder | 14:4e312fb83330 | 513 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
CallumAlder | 14:4e312fb83330 | 514 | uint64_t* key = (uint64_t*)((int)sequence + 48); |
CallumAlder | 14:4e312fb83330 | 515 | uint64_t* nonce = (uint64_t*)((int)sequence + 56); |
CallumAlder | 14:4e312fb83330 | 516 | uint8_t hash[32]; |
CallumAlder | 14:4e312fb83330 | 517 | uint32_t length64 = 64; |
CallumAlder | 15:2f95f2fb68e3 | 518 | uint32_t hashCounter = 0; |
iachinweze1 | 23:ab1cb51527d1 | 519 | Timer timer; |
iachinweze1 | 23:ab1cb51527d1 | 520 | |
adehadd | 20:c60f4785b556 | 521 | comm_plz.start_comm(); |
adehadd | 20:c60f4785b556 | 522 | |
adehadd | 16:db7ef0a4aa23 | 523 | // Motor States |
iachinweze1 | 23:ab1cb51527d1 | 524 | |
adehadd | 20:c60f4785b556 | 525 | // pc.printf("Rotor origin: %x\n\r",orState); |
adehadd | 20:c60f4785b556 | 526 | // orState is subtracted from future rotor state inputs to align rotor and motor states |
adehadd | 20:c60f4785b556 | 527 | // intState = readRotorState(); |
adehadd | 20:c60f4785b556 | 528 | //if (intState != intStateOld) { |
iachinweze1 | 23:ab1cb51527d1 | 529 | // pc.printf("old:%d \t new:%d \t next:%d \n\r",intStateOld, intState, (intState-orState+lead+6)%6); |
iachinweze1 | 23:ab1cb51527d1 | 530 | // intStateOld = intState; |
iachinweze1 | 23:ab1cb51527d1 | 531 | // motorOut((intState-orState+lead+6)%6); //+6 to make sure the remainder is positive |
iachinweze1 | 23:ab1cb51527d1 | 532 | // } |
iachinweze1 | 23:ab1cb51527d1 | 533 | |
iachinweze1 | 12:41b3112021a3 | 534 | // Keep the program running indefinitely |
CallumAlder | 15:2f95f2fb68e3 | 535 | timer.start(); // start timer |
CallumAlder | 29:c96439a60184 | 536 | |
CallumAlder | 15:2f95f2fb68e3 | 537 | while (1) { |
iachinweze1 | 23:ab1cb51527d1 | 538 | // pc.printf("Current:%d \t Next:%d \n\r", currentState, (currentState-orState+lead+6)%6); |
iachinweze1 | 23:ab1cb51527d1 | 539 | comm_plz.newKey_mutex.lock(); |
adehadd | 20:c60f4785b556 | 540 | *key = comm_plz.newKey; |
iachinweze1 | 23:ab1cb51527d1 | 541 | comm_plz.newKey_mutex.unlock(); |
CallumAlder | 15:2f95f2fb68e3 | 542 | Miner.computeHash(hash, sequence, length64); |
CallumAlder | 15:2f95f2fb68e3 | 543 | hashCounter++; |
CallumAlder | 15:2f95f2fb68e3 | 544 | if ((hash[0]==0) && (hash[1]==0)){ |
adehadd | 20:c60f4785b556 | 545 | comm_plz.putMessage((Comm::msgType)7, *nonce); |
CallumAlder | 15:2f95f2fb68e3 | 546 | } |
CallumAlder | 15:2f95f2fb68e3 | 547 | |
adehadd | 20:c60f4785b556 | 548 | // Try a new nonce |
CallumAlder | 15:2f95f2fb68e3 | 549 | (*nonce)++; |
CallumAlder | 15:2f95f2fb68e3 | 550 | |
adehadd | 20:c60f4785b556 | 551 | // Per Second i.e. when greater or equal to 1 |
CallumAlder | 15:2f95f2fb68e3 | 552 | if (timer.read() >= 1){ |
adehadd | 20:c60f4785b556 | 553 | comm_plz.putMessage((Comm::msgType)5, hashCounter); |
CallumAlder | 19:805c87360b55 | 554 | //pc.printf("HashRate = %02u \n\r",hashCounter); |
CallumAlder | 15:2f95f2fb68e3 | 555 | hashCounter=0; |
CallumAlder | 15:2f95f2fb68e3 | 556 | timer.reset(); |
CallumAlder | 15:2f95f2fb68e3 | 557 | } |
CallumAlder | 15:2f95f2fb68e3 | 558 | } |
CallumAlder | 19:805c87360b55 | 559 | } |