Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Wed Aug 15 21:34:59 2018 +0000
Revision:
57:aba1296e51b1
Parent:
56:bc5345bc6650
Final Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 53:71f59e195f06 1
thomasmorris 25:36699ed589ab 2 #include "SETUP.hpp"
thomasmorris 52:99915f5240b2 3
thomasmorris 54:a4c5949707ca 4 #define Cubelet_data_ready 1
thomasmorris 54:a4c5949707ca 5 #define Not_Cubelet_data_ready 0
thomasmorris 54:a4c5949707ca 6 /*
thomasmorris 54:a4c5949707ca 7 Colour lookup table
thomasmorris 54:a4c5949707ca 8 1 = White
thomasmorris 54:a4c5949707ca 9 2 = Red
thomasmorris 54:a4c5949707ca 10 3 = Orange
thomasmorris 54:a4c5949707ca 11 4 = Blue
thomasmorris 54:a4c5949707ca 12 5 = Green
thomasmorris 54:a4c5949707ca 13 6 = Yellow
thomasmorris 54:a4c5949707ca 14 */
thomasmorris 57:aba1296e51b1 15 int SPI_RX_DATA = 0;
thomasmorris 55:e0e684531825 16
thomasmorris 54:a4c5949707ca 17
thomasmorris 56:bc5345bc6650 18 void Serial_Commands(){while(1){Serial_Commands_Output();}}//Enable Serial Commands
thomasmorris 56:bc5345bc6650 19 void LED_Logging(){while(1){Log_Leds();}} //Flashes the yellow led to indicate the logging mode
thomasmorris 57:aba1296e51b1 20 //void SPI_INTERFACE(){while(1){SPI_INTERFACE_SERIAL();}} //Outputs SPI data to serial
thomasmorris 57:aba1296e51b1 21 void SPI_INTERFACE()
thomasmorris 57:aba1296e51b1 22 {
thomasmorris 57:aba1296e51b1 23 //pc.printf("SPI Test \n");
thomasmorris 57:aba1296e51b1 24 Thread::wait(1000);
thomasmorris 57:aba1296e51b1 25 while(1)
thomasmorris 57:aba1296e51b1 26 {
thomasmorris 57:aba1296e51b1 27 cs= 0;
thomasmorris 57:aba1296e51b1 28 SPI_RX_DATA = spi.write(0xF0);
thomasmorris 57:aba1296e51b1 29 wait_us(3);
thomasmorris 57:aba1296e51b1 30 cs= 1;
thomasmorris 57:aba1296e51b1 31 colour_data = SPI_RX_DATA;
thomasmorris 57:aba1296e51b1 32 if(Log_Value == 1){pc.printf("Received data = %d\n", SPI_RX_DATA);}
thomasmorris 57:aba1296e51b1 33
thomasmorris 57:aba1296e51b1 34 Thread::wait(1000);
thomasmorris 57:aba1296e51b1 35 }
thomasmorris 57:aba1296e51b1 36 }
thomasmorris 53:71f59e195f06 37 void Motor_Control()
thomasmorris 5:2594b953f111 38 {
thomasmorris 53:71f59e195f06 39 while(1)
thomasmorris 53:71f59e195f06 40 {
thomasmorris 53:71f59e195f06 41 if(Motor_To_Select !=0 and steps !=0)
thomasmorris 53:71f59e195f06 42 {
thomasmorris 53:71f59e195f06 43 if(Motor_To_Select == 1)
thomasmorris 53:71f59e195f06 44 {
thomasmorris 53:71f59e195f06 45 STEPPER_MOTOR_1.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 46 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 47 }
thomasmorris 53:71f59e195f06 48 else if(Motor_To_Select == 2)
thomasmorris 53:71f59e195f06 49 {
thomasmorris 53:71f59e195f06 50 STEPPER_MOTOR_2.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 51 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 52 }
thomasmorris 53:71f59e195f06 53 else if(Motor_To_Select == 3)
thomasmorris 53:71f59e195f06 54 {
thomasmorris 53:71f59e195f06 55 STEPPER_MOTOR_3.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 56 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 57 }
thomasmorris 53:71f59e195f06 58 else if(Motor_To_Select == 4)
thomasmorris 53:71f59e195f06 59 {
thomasmorris 53:71f59e195f06 60 STEPPER_MOTOR_4.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 61 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 62 }
thomasmorris 53:71f59e195f06 63 else if(Motor_To_Select == 5)
thomasmorris 53:71f59e195f06 64 {
thomasmorris 53:71f59e195f06 65 STEPPER_MOTOR_5.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 66 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 67 }
thomasmorris 53:71f59e195f06 68
thomasmorris 53:71f59e195f06 69 else if(Motor_To_Select == 6)
thomasmorris 53:71f59e195f06 70 {
thomasmorris 53:71f59e195f06 71 STEPPER_MOTOR_6.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 72 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 73 }
thomasmorris 53:71f59e195f06 74
thomasmorris 53:71f59e195f06 75 }
thomasmorris 53:71f59e195f06 76 }
thomasmorris 25:36699ed589ab 77 }
thomasmorris 25:36699ed589ab 78 int main()
thomasmorris 25:36699ed589ab 79 {
thomasmorris 52:99915f5240b2 80 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 53:71f59e195f06 81 //SPI_INIT();
thomasmorris 53:71f59e195f06 82 cs = 1; //Active Low
thomasmorris 53:71f59e195f06 83
thomasmorris 53:71f59e195f06 84 // Setup the spi for 8 bit data, high steady state clock,
thomasmorris 53:71f59e195f06 85 // second edge capture, with a 1MHz clock rate
thomasmorris 55:e0e684531825 86 spi.format(16,1); // 8 Data bits phase 0 polarity 0 //CHECK THIS
thomasmorris 53:71f59e195f06 87 spi.frequency(1000000);//Output clock frequency 1Mhz
thomasmorris 53:71f59e195f06 88 //post(); //Power on Self Test
thomasmorris 57:aba1296e51b1 89 memset(Move_list, 0, sizeof(Move_list));
thomasmorris 57:aba1296e51b1 90 Move_list_pointer = 0;
thomasmorris 52:99915f5240b2 91 //Start Threads
thomasmorris 53:71f59e195f06 92 t1.start(Motor_Control);
thomasmorris 53:71f59e195f06 93 t2.start(SPI_INTERFACE);
thomasmorris 53:71f59e195f06 94 t3.start(Serial_Commands);
thomasmorris 52:99915f5240b2 95 //Interrupts
thomasmorris 56:bc5345bc6650 96
thomasmorris 52:99915f5240b2 97
thomasmorris 5:2594b953f111 98 //Main thread ID
thomasmorris 5:2594b953f111 99 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 100
thomasmorris 53:71f59e195f06 101
thomasmorris 5:2594b953f111 102 //Thread ID
thomasmorris 5:2594b953f111 103 id1 = t1.gettid();
thomasmorris 5:2594b953f111 104 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 105 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 106 id4 = t4.gettid();
chills 24:7d2da96e05ad 107 id5 = t5.gettid();
thomasmorris 48:244d6d81bb52 108 id6 = t6.gettid();
thomasmorris 53:71f59e195f06 109
thomasmorris 48:244d6d81bb52 110 while(true)
thomasmorris 48:244d6d81bb52 111 {
thomasmorris 53:71f59e195f06 112 //Do nothing main thread will sleep
noutram 0:36e89e3ed7c4 113 }
thomasmorris 45:875f7e18a386 114 }