fork of what I have been writing
ES_CW2_Starter_STARFISH/main.cpp
- Committer:
- le1917
- Date:
- 2020-03-09
- Revision:
- 12:38afe92e67d0
- Parent:
- 11:038d3ba0d720
- Child:
- 13:f6e37c21d31d
File content as of revision 12:38afe92e67d0:
#include "mbed.h" #include "SHA256.h" #include "rtos.h" #include <stdlib.h> #include <string> #include "mutexes.h" #include "SerialCommunication.h" #include "CryptoMining.h" #include "MotorControl.h" // Declaration of threads Thread thread_crypto; Thread thread_processor; // Timing variables for printing calculation rate Timer timer_nonce; uint32_t previous_time; //Main int main() { pc.attach(&serialISR); thread_motorCtrl.start(motorCtrlFn); // Initialize threads and timers timer_nonce.start(); thread_crypto.start(thread_crypto_print); thread_processor.start(thread_processor_callback); uint8_t hash[32]; while (1) { // Set main as lowest priority thread NewKey_mutex.lock(); *key = NewKey; NewKey_mutex.unlock(); SHA256::computeHash(hash, (uint8_t *)sequence, 64); *nonce = *nonce + 1; if ((hash[0] == 0) && (hash[1] == 0)) { last_nonce_number = successful_nonce; putMessageCrypto(*nonce); successful_nonce++; } if ((timer_nonce.read_ms() - previous_time) > 1000) { //pc.printf("Computation Rate: %lu computation /sec\n\r", (*nonce - last_nonce_number)); last_nonce_number = *nonce; previous_time = timer_nonce.read_ms(); } } return 0; }