fork of what I have been writing
ES_CW2_Starter_STARFISH/main.cpp@12:38afe92e67d0, 2020-03-09 (annotated)
- Committer:
- le1917
- Date:
- Mon Mar 09 15:02:47 2020 +0000
- Revision:
- 12:38afe92e67d0
- Parent:
- 11:038d3ba0d720
- Child:
- 13:f6e37c21d31d
Merger Motor with Noe - seems to work;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
le1917 | 12:38afe92e67d0 | 1 | #include "mbed.h" |
le1917 | 12:38afe92e67d0 | 2 | #include "SHA256.h" |
le1917 | 12:38afe92e67d0 | 3 | #include "rtos.h" |
le1917 | 12:38afe92e67d0 | 4 | #include <stdlib.h> |
le1917 | 12:38afe92e67d0 | 5 | #include <string> |
le1917 | 12:38afe92e67d0 | 6 | #include "mutexes.h" |
le1917 | 12:38afe92e67d0 | 7 | #include "SerialCommunication.h" |
le1917 | 12:38afe92e67d0 | 8 | #include "CryptoMining.h" |
le1917 | 12:38afe92e67d0 | 9 | #include "MotorControl.h" |
kubitz | 9:4135d0c8dc10 | 10 | |
kubitz | 9:4135d0c8dc10 | 11 | // Declaration of threads |
kubitz | 6:5f4a954cb8bc | 12 | Thread thread_crypto; |
kubitz | 9:4135d0c8dc10 | 13 | Thread thread_processor; |
kubitz | 10:3669e3d832ed | 14 | |
kubitz | 9:4135d0c8dc10 | 15 | // Timing variables for printing calculation rate |
kubitz | 9:4135d0c8dc10 | 16 | Timer timer_nonce; |
kubitz | 9:4135d0c8dc10 | 17 | uint32_t previous_time; |
kubitz | 9:4135d0c8dc10 | 18 | |
kubitz | 11:038d3ba0d720 | 19 | |
kubitz | 0:19fd8c1944fb | 20 | //Main |
kubitz | 9:4135d0c8dc10 | 21 | int main() |
kubitz | 9:4135d0c8dc10 | 22 | { |
kubitz | 9:4135d0c8dc10 | 23 | pc.attach(&serialISR); |
kubitz | 9:4135d0c8dc10 | 24 | |
le1917 | 12:38afe92e67d0 | 25 | thread_motorCtrl.start(motorCtrlFn); |
kubitz | 8:c30a4106d08c | 26 | |
kubitz | 9:4135d0c8dc10 | 27 | // Initialize threads and timers |
kubitz | 9:4135d0c8dc10 | 28 | timer_nonce.start(); |
kubitz | 7:aef5b29d7a7c | 29 | thread_crypto.start(thread_crypto_print); |
kubitz | 9:4135d0c8dc10 | 30 | thread_processor.start(thread_processor_callback); |
kubitz | 9:4135d0c8dc10 | 31 | uint8_t hash[32]; |
kubitz | 5:de6430aee646 | 32 | |
le1917 | 12:38afe92e67d0 | 33 | while (1) { |
kubitz | 10:3669e3d832ed | 34 | // Set main as lowest priority thread |
kubitz | 10:3669e3d832ed | 35 | |
kubitz | 10:3669e3d832ed | 36 | NewKey_mutex.lock(); |
le1917 | 12:38afe92e67d0 | 37 | *key = NewKey; |
kubitz | 10:3669e3d832ed | 38 | NewKey_mutex.unlock(); |
kubitz | 10:3669e3d832ed | 39 | |
kubitz | 9:4135d0c8dc10 | 40 | SHA256::computeHash(hash, (uint8_t *)sequence, 64); |
kubitz | 5:de6430aee646 | 41 | *nonce = *nonce + 1; |
kubitz | 5:de6430aee646 | 42 | |
le1917 | 12:38afe92e67d0 | 43 | if ((hash[0] == 0) && (hash[1] == 0)) { |
kubitz | 0:19fd8c1944fb | 44 | last_nonce_number = successful_nonce; |
kubitz | 10:3669e3d832ed | 45 | putMessageCrypto(*nonce); |
kubitz | 0:19fd8c1944fb | 46 | successful_nonce++; |
kubitz | 9:4135d0c8dc10 | 47 | } |
kubitz | 9:4135d0c8dc10 | 48 | |
le1917 | 12:38afe92e67d0 | 49 | if ((timer_nonce.read_ms() - previous_time) > 1000) { |
kubitz | 9:4135d0c8dc10 | 50 | //pc.printf("Computation Rate: %lu computation /sec\n\r", (*nonce - last_nonce_number)); |
kubitz | 0:19fd8c1944fb | 51 | last_nonce_number = *nonce; |
kubitz | 5:de6430aee646 | 52 | previous_time = timer_nonce.read_ms(); |
kubitz | 0:19fd8c1944fb | 53 | } |
kubitz | 0:19fd8c1944fb | 54 | } |
kubitz | 0:19fd8c1944fb | 55 | |
kubitz | 9:4135d0c8dc10 | 56 | return 0; |
le1917 | 12:38afe92e67d0 | 57 | } |