fork of what I have been writing
Diff: ES_CW2_Starter_STARFISH/main.cpp
- Revision:
- 13:f6e37c21d31d
- Parent:
- 12:38afe92e67d0
diff -r 38afe92e67d0 -r f6e37c21d31d ES_CW2_Starter_STARFISH/main.cpp --- a/ES_CW2_Starter_STARFISH/main.cpp Mon Mar 09 15:02:47 2020 +0000 +++ b/ES_CW2_Starter_STARFISH/main.cpp Mon Mar 09 17:19:39 2020 +0000 @@ -3,11 +3,27 @@ #include "rtos.h" #include <stdlib.h> #include <string> -#include "mutexes.h" + +Mutex NewKey_mutex; +Mutex NewMotorCommand_mutex; +Mutex Music_mutex; + +// Global Variable Shared between threads +float NewRotation; +float NewSpeed; +uint64_t NewKey; + +bool NewSpeed_flag; +bool NewRotation_flag; + #include "SerialCommunication.h" #include "CryptoMining.h" #include "MotorControl.h" + + + + // Declaration of threads Thread thread_crypto; Thread thread_processor; @@ -16,23 +32,46 @@ 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); + //NewSpeed = 30; + //thread_motorCtrl.start(&NewSpeed, motorCtrlFn); + uint8_t hash[32]; while (1) { + //Luccas' Code until we can move rest into seperate thread + + NewMotorCommand_mutex.lock(); + + pc.printf("Thread Actual %d\r\n", thread_motorCtrl.get_state()); + pc.printf("Thread state Expected %d\r\n",Thread::Running); + + + + if(NewSpeed_flag && thread_motorCtrl.get_state() != Thread::Deleted){ + pc.printf("Ending Previous Thread"); + thread_motorCtrl.terminate(); + } + + if(NewSpeed_flag){ + pc.printf("starting thread"); + thread_motorCtrl.start(&NewSpeed, motorCtrlFn); + NewSpeed_flag = false; + } + + NewMotorCommand_mutex.unlock(); + + wait(1); + // Set main as lowest priority thread - NewKey_mutex.lock(); *key = NewKey; NewKey_mutex.unlock();