Thomas Morris / Mbed OS PROJ324_Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "SETUP.hpp"
00003 
00004 #define Cubelet_data_ready 1
00005 #define Not_Cubelet_data_ready 0
00006 /*
00007 Colour lookup table
00008 1 = White
00009 2 = Red
00010 3 = Orange
00011 4 = Blue
00012 5 = Green
00013 6 = Yellow
00014 */
00015 int SPI_RX_DATA = 0;
00016 
00017 
00018 void Serial_Commands(){while(1){Serial_Commands_Output();}}//Enable Serial Commands
00019 void LED_Logging(){while(1){Log_Leds();}}                  //Flashes the yellow led to indicate the logging mode
00020 //void SPI_INTERFACE(){while(1){SPI_INTERFACE_SERIAL();}}    //Outputs SPI data to serial
00021 void SPI_INTERFACE()
00022 {
00023     //pc.printf("SPI Test \n");
00024     Thread::wait(1000);
00025     while(1)
00026     {
00027         cs= 0;
00028         SPI_RX_DATA = spi.write(0xF0);
00029         wait_us(3);
00030         cs= 1;
00031         colour_data = SPI_RX_DATA;
00032         if(Log_Value == 1){pc.printf("Received data = %d\n", SPI_RX_DATA);}
00033         
00034         Thread::wait(1000);
00035     }   
00036 }
00037 void Motor_Control()
00038 {
00039     while(1)
00040     {
00041         if(Motor_To_Select !=0 and steps !=0)
00042         {
00043             if(Motor_To_Select == 1)
00044             {
00045                 STEPPER_MOTOR_1.Rotate_Steps(steps ,direction);
00046                 //Motor_To_Select = 0;
00047             }
00048             else if(Motor_To_Select == 2)
00049             {
00050                 STEPPER_MOTOR_2.Rotate_Steps(steps ,direction);
00051                 //Motor_To_Select = 0;
00052             }
00053              else if(Motor_To_Select == 3)
00054             {
00055                 STEPPER_MOTOR_3.Rotate_Steps(steps ,direction);
00056                 //Motor_To_Select = 0;
00057             }
00058              else if(Motor_To_Select == 4)
00059             {
00060                 STEPPER_MOTOR_4.Rotate_Steps(steps ,direction);
00061                 //Motor_To_Select = 0;
00062             }
00063              else if(Motor_To_Select == 5)
00064             {
00065                 STEPPER_MOTOR_5.Rotate_Steps(steps ,direction);
00066                 //Motor_To_Select = 0;
00067             }
00068             
00069              else if(Motor_To_Select == 6)
00070             {
00071                 STEPPER_MOTOR_6.Rotate_Steps(steps ,direction);
00072                 //Motor_To_Select = 0;
00073             }
00074             
00075         }
00076     }
00077 }
00078 int main()
00079 {
00080     pc.baud(9600);                                          //Sets the Serial Comms Baud Rate
00081     //SPI_INIT();
00082     cs = 1; //Active Low
00083 
00084     // Setup the spi for 8 bit data, high steady state clock,
00085     // second edge capture, with a 1MHz clock rate
00086     spi.format(16,1); // 8 Data bits phase 0 polarity 0 //CHECK THIS
00087     spi.frequency(1000000);//Output clock frequency 1Mhz
00088     //post();                                                 //Power on Self Test
00089     memset(Move_list, 0, sizeof(Move_list));
00090     Move_list_pointer = 0;
00091     //Start Threads
00092     t1.start(Motor_Control);
00093     t2.start(SPI_INTERFACE);
00094     t3.start(Serial_Commands);
00095     //Interrupts
00096 
00097     
00098     //Main thread ID
00099     idMain = osThreadGetId();   //CMSIS RTOS call
00100 
00101 
00102     //Thread ID
00103     id1 = t1.gettid();
00104     id2 = t2.gettid();
00105     id3 = t3.gettid();
00106     id4 = t4.gettid();
00107     id5 = t5.gettid();
00108     id6 = t6.gettid();
00109     
00110     while(true) 
00111     {
00112         //Do nothing main thread will sleep        
00113     }
00114 }