![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Skeleton code. LCD, Serial, Feedback, MOSFETS
Dependencies: mbed mbed-rtos ShiftReg2 TextLCD
Revision 4:020f93d35f6e, committed 2019-05-07
- Comitter:
- thomasmorris
- Date:
- Tue May 07 21:55:57 2019 +0000
- Parent:
- 3:5665939d31ca
- Commit message:
- Added mutex and safey coding needs more. Added board and serial functions that need testing. As well as a more thorough post function.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Control/Control.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,33 @@ +#include "Control.hpp" +int PWM_on_time = 0; +int PWM_off_time = 100; +ShiftReg SR(PA_10, PA_12, PA_15, PA_11); //data, store, clock, output enable +int Output = 0; +int Data = 0; +void Control_Main()//This is where the control of the board will be run from, just to not have all of the code inside of the main +{ + Control_Shift_Regs(0xF0F0,20);//Pass in the muscle and fan selection along with the PWM +} +void Control_Shift_Regs(uint16_t Selection, int PWM)//Controling the output of the shift registers +{ + if(PWM < 0 || PWM > 100) + { + PWM = 0; + //Also run an error + } + PWM_on_time = PWM; + PWM_off_time = PWM_off_time - PWM; + while(1) + { + SR.Write(0x0000);//All off + SR.Write(Selection);//Turn the selection on + Thread::wait(PWM_on_time);//20ms on + SR.Write(0x0000); + Thread::wait(PWM_off_time);//80ms off + } +} +void Control_Post()//The POST function runs here +{ + POST();//Run the power on self test routine +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Control/Control.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,32 @@ +#ifndef _CONTROL_HPP_ +#define _CONTROL_HPP_ + +#include "mbed.h" +#include "rtos.h" + + +#include "Post.hpp" +#include "Interface.hpp" +#include "Post.hpp" +#include "Schedules.hpp" +#include "Feedback.hpp" +#include "Serial_PC.hpp" +#include "Serial_Board.hpp" +#include "ShiftReg.h" + +extern ShiftReg SR; //data, store, clock, output enable +extern DigitalOut myled; //Onboard LED + +//Class instances +extern INTERFACE INTERFACE_1; +extern SCHEDULES SCHEDULES_1; +extern FEEDBACK FEEDBACK_1; +extern SERIAL_PC SERIAL_PC_1; +extern SERIAL_BOARD SERIAL_BOARD_1; + + +void Control_Main(); +void Control_Shift_Regs(uint16_t Selection, int PWM); +void Control_Post(); +void Control_Sensing(); +#endif //_CONTROL_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FEEDBACK/Feedback.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,64 @@ +#include "Feedback.hpp" +//Constructor +FEEDBACK::FEEDBACK(PinName N1, PinName N2, PinName N3, PinName N4, PinName N5, PinName N6, PinName N7, PinName N8, PinName N9, PinName N10) : +_Battery_Measurement(N1),_Temperature_Sensor_1(N2),_Temperature_Sensor_2(N3),_Temperature_Sensor_3(N4), +_Feedback_Sensor_1(N5),_Feedback_Sensor_2(N6),_Feedback_Sensor_3(N7),_Feedback_Sensor_4(N8),_Feedback_Sensor_5(N9),_Feedback_Sensor_6(N10) +{ + _Battery_Measurement_Value_Mutex.lock(); + _Battery_Measurement_Value = 0; + _Battery_Measurement_Value_Mutex.unlock(); + _Temp_1_Value_Mutex.lock(); + _Temp_1_Value = 0; + _Temp_1_Value_Mutex.unlock(); + _Temp_2_Value_Mutex.lock(); + _Temp_2_Value = 0; + _Temp_2_Value_Mutex.unlock(); + _Temp_3_Value_Mutex.lock(); + _Temp_3_Value = 0; + _Temp_3_Value_Mutex.unlock(); + _Feedback_1_Value_Mutex.lock(); + _Feedback_1_Value = 0; + _Feedback_1_Value_Mutex.unlock(); + _Feedback_2_Value_Mutex.lock(); + _Feedback_2_Value = 0; + _Feedback_2_Value_Mutex.unlock(); + _Feedback_3_Value_Mutex.lock(); + _Feedback_3_Value = 0; + _Feedback_3_Value_Mutex.unlock(); + _Feedback_4_Value_Mutex.lock(); + _Feedback_4_Value = 0; + _Feedback_4_Value_Mutex.unlock(); + _Feedback_5_Value_Mutex.unlock(); + _Feedback_5_Value = 0; + _Feedback_5_Value_Mutex.lock(); + _Feedback_6_Value_Mutex.unlock(); + _Feedback_6_Value = 0; + _Feedback_6_Value_Mutex.unlock(); +} +FEEDBACK::~FEEDBACK(){}//Destructor +void FEEDBACK::Init(){}//Initialisation Routine +int FEEDBACK::Post()//Power on self test +{ + return 1;//Success +} + +float FEEDBACK::Get_Battery_Measurement_Value(){_Battery_Measurement_Value_Mutex.lock(); +_Battery_Measurement_Value = _Battery_Measurement.read();_Battery_Measurement_Value_Mutex.unlock();return _Battery_Measurement_Value;} +float FEEDBACK::Get_Temp_1_Value(){_Temp_1_Value_Mutex.lock(); +_Temp_1_Value = _Temperature_Sensor_1.read();_Temp_1_Value_Mutex.unlock(); return _Temp_1_Value;} +float FEEDBACK::Get_Temp_2_Value(){_Temp_2_Value_Mutex.lock(); +_Temp_2_Value = _Temperature_Sensor_2.read();_Temp_2_Value_Mutex.unlock(); return _Temp_2_Value;} +float FEEDBACK::Get_Temp_3_Value(){_Temp_3_Value_Mutex.lock(); +_Temp_3_Value = _Temperature_Sensor_3.read();_Temp_3_Value_Mutex.unlock(); return _Temp_3_Value;} +float FEEDBACK::Get_Feedback_1_Value(){_Feedback_1_Value_Mutex.lock(); +_Feedback_1_Value = _Feedback_Sensor_1.read(); _Feedback_1_Value_Mutex.unlock();return _Feedback_1_Value;} +float FEEDBACK::Get_Feedback_2_Value(){_Feedback_2_Value_Mutex.lock(); +_Feedback_2_Value = _Feedback_Sensor_2.read(); _Feedback_2_Value_Mutex.unlock();return _Feedback_2_Value;} +float FEEDBACK::Get_Feedback_3_Value(){_Feedback_3_Value_Mutex.lock(); +_Feedback_3_Value = _Feedback_Sensor_3.read(); _Feedback_3_Value_Mutex.unlock();return _Feedback_3_Value;} +float FEEDBACK::Get_Feedback_4_Value(){_Feedback_4_Value_Mutex.lock(); +_Feedback_4_Value = _Feedback_Sensor_4.read(); _Feedback_4_Value_Mutex.unlock();return _Feedback_4_Value;} +float FEEDBACK::Get_Feedback_5_Value(){_Feedback_5_Value_Mutex.lock(); +_Feedback_5_Value = _Feedback_Sensor_5.read(); _Feedback_5_Value_Mutex.unlock();return _Feedback_5_Value;} +float FEEDBACK::Get_Feedback_6_Value(){_Feedback_6_Value_Mutex.lock(); +_Feedback_6_Value = _Feedback_Sensor_6.read(); _Feedback_6_Value_Mutex.unlock();return _Feedback_6_Value;}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FEEDBACK/Feedback.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,75 @@ +#ifndef _FEEDBACK_HPP_ +#define _FEEDBACK_HPP_ + +#include "mbed.h" +#include "rtos.h" + +//Libraries and header file includes + + +class FEEDBACK +{ + public://Public member functions and variables + + FEEDBACK(PinName N1, PinName N2, PinName N3, PinName N4, PinName N5, PinName N6, PinName N7, PinName N8, PinName N9, PinName N10); + ~FEEDBACK(); + void Init(); + int Post(); + //Public Functions + + + //Getters + float Get_Battery_Measurement_Value();//Return the batter measurement value + float Get_Temp_1_Value();//Return the temperature value 1 + float Get_Temp_2_Value();//Return the temperature value 2 + float Get_Temp_3_Value();//Return the temperature value 3 + float Get_Feedback_1_Value();//Return the feedback value 1 + float Get_Feedback_2_Value();//Return the feedback value 2 + float Get_Feedback_3_Value();//Return the feedback value 3 + float Get_Feedback_4_Value();//Return the feedback value 4 + float Get_Feedback_5_Value();//Return the feedback value 5 + float Get_Feedback_6_Value();//Return the feedback value 6 + + + private://Private member functions and variables + + //Private Functions + + //Private GPIO connections + //Measurement These set the values + AnalogIn _Battery_Measurement; + AnalogIn _Temperature_Sensor_1; + AnalogIn _Temperature_Sensor_2; + AnalogIn _Temperature_Sensor_3; + AnalogIn _Feedback_Sensor_1; + AnalogIn _Feedback_Sensor_2; + AnalogIn _Feedback_Sensor_3; + AnalogIn _Feedback_Sensor_4; + AnalogIn _Feedback_Sensor_5; + AnalogIn _Feedback_Sensor_6; + //Private member variables + + float _Battery_Measurement_Value;//Value of the battery measurement circuit + float _Temp_1_Value; //Temperature sensor feedback 1 + float _Temp_2_Value; //Temperature sensor feedback 2 + float _Temp_3_Value; //Temperature sensor feedback 3 + float _Feedback_1_Value;//Feedback sensor 1 + float _Feedback_2_Value;//Feedback sensor 2 + float _Feedback_3_Value;//Feedback sensor 3 + float _Feedback_4_Value;//Feedback sensor 4 + float _Feedback_5_Value;//Feedback sensor 5 + float _Feedback_6_Value;//Feedback sensor 6 + + //Mutex Locks + Mutex _Battery_Measurement_Value_Mutex;//Value of the battery measurement circuit mutex lock + Mutex _Temp_1_Value_Mutex; //Temperature sensor feedback 1 mutex lock + Mutex _Temp_2_Value_Mutex; //Temperature sensor feedback 2 mutex lock + Mutex _Temp_3_Value_Mutex; //Temperature sensor feedback 3 mutex lock + Mutex _Feedback_1_Value_Mutex;//Feedback sensor 1 mutex lock + Mutex _Feedback_2_Value_Mutex;//Feedback sensor 2 mutex lock + Mutex _Feedback_3_Value_Mutex;//Feedback sensor 3 mutex lock + Mutex _Feedback_4_Value_Mutex;//Feedback sensor 4 mutex lock + Mutex _Feedback_5_Value_Mutex;//Feedback sensor 5 mutex lock + Mutex _Feedback_6_Value_Mutex;//Feedback sensor 6 mutex lock +}; +#endif //_FEEDBACK_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INTERFACE/Interface.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,44 @@ +#include "Interface.hpp" +//Define the variables here +Serial PC(PB_10, PB_11); //TX, RX +Serial Board(PB_6, PB_7); //TX, RX +//TextLCD Lcd(PB_12, PB_13, PB_14, PB_15, PA_8, PA_9); // rs, e, d4-d7 +TextLCD Lcd(PB_12, PB_13, PB_14, PB_15, PA_8, PA_9); // rs, e, d4-d7 +DigitalOut On_board_led(PC_13);//Onborad LED needs no pass in parameter + +INTERFACE::INTERFACE(PinName N1, PinName N2, PinName N3, PinName N4,PinName N5, PinName N6, PinName N7, PinName N8,PinName N9, PinName N10, PinName N11): _Rotary_Encoder_A(N1),_Rotary_Encoder_B(N2),_Rotary_Encoder_Button(N3),_Button_1(N4), _Button_2(N5), _Button_3(N6), _MOSFET_Safety(N7), _Shift_SCLK(N8),_Shift_Latch(N9), _Shift_Enable(N10), _Shift_Data(N11) +{ + +} + +INTERFACE::~INTERFACE(){} +void INTERFACE::Init(){} +int INTERFACE::Post() +{ + return 1;//Success +} +void INTERFACE::On_board_LED_Flash() +{ + while(1) + { + On_board_led = !On_board_led; + Thread::wait(1000); + } +} +void INTERFACE::Serial() +{ + while(1) + { + PC.printf("Testing Serial\n"); + Thread::wait(1000); + } +} +void INTERFACE::LCD() +{ + while(1) + { + Lcd.printf("Testing\nINTERFACE"); + Thread::wait(1000); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INTERFACE/Interface.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,58 @@ +#ifndef _INTERFACE_HPP_ +#define _INTERFACE_HPP_ + +#include "mbed.h" +#include "rtos.h" +#include "TextLCD.h" + +//Libraries and header file includes + + +extern Serial PC; //TX, RX +extern Serial Board; //TX, RX +extern TextLCD Lcd; // rs, e, d4-d7 +//extern DigitalOut On_board_led;//Onboard LED +class INTERFACE +{ + public://Public member functions and variables + INTERFACE(PinName N1, PinName N2, PinName N3, PinName N4, PinName N5, PinName N6, PinName N7, PinName N8, PinName N9, PinName N10, PinName N11); + ~INTERFACE(); + void Init(); + int Post(); + void Serial(); + void LCD(); + void On_board_LED_Flash(); + //Public Functions + + //Public Variabls + + private://Private member functions and variables + //Inputs + + //Rotary Encoder + DigitalIn _Rotary_Encoder_A;//N1 + DigitalIn _Rotary_Encoder_B;//N2 + DigitalIn _Rotary_Encoder_Button;//N3 + + + //Buttons + DigitalIn _Button_1;//N4 + DigitalIn _Button_2;//N5 + DigitalIn _Button_3;//N6 + + //MOSFET Safety Pin + DigitalOut _MOSFET_Safety;//Active low N7 + + //Shift Register Control + DigitalOut _Shift_SCLK;//N8 + DigitalOut _Shift_Latch;//N9 + DigitalOut _Shift_Enable;//N10 + DigitalOut _Shift_Data;//N11 + + + //Private Functions + + //Private Variables + //DigitalOut On_board_led;//Onboard LED +}; +#endif //_INTERFACE_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/POST/Post.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,74 @@ +#include "Post.hpp" +int POST_Sum = 0; +bool Power_Post = 0; +bool Interface_Post = 0; +bool Schedules_Post = 0; +bool Feedback_Post = 0; +bool Serial_PC_Post = 0; +bool Serial_BOARD_Post = 0; + + +INTERFACE INTERFACE_1(PC_13,PC_14,PC_15,PB_9,PB_8,PB_5,PB_4,PA_15,PA_12,PA_11,PA_10);//Rotary encoderA, Rotary Encoder B, Rotary encoder button, button 1, button 2, button 3, MOSFET safety, shift sclk, shift latch, shift enable, shift in +SCHEDULES SCHEDULES_1; +FEEDBACK FEEDBACK_1(PA_0,PA_1,PA_2,PA_3,PB_0,PB_1,PA_7,PA_6,PA_5,PA_4);//This is where all of the feedback pins are defined +SERIAL_PC SERIAL_PC_1; +SERIAL_BOARD SERIAL_BOARD_1; +void POST() +{ + POST_Sum = 0; + Interface_Post = INTERFACE_1.Post(); + Schedules_Post = SCHEDULES_1.Post(); + Feedback_Post = FEEDBACK_1.Post(); + Serial_PC_Post = SERIAL_PC_1.Post(); + Serial_BOARD_Post = SERIAL_BOARD_1.Post(); + + if(Interface_Post == 1)//Success + { + PC.printf("Interface Post pass\n"); + POST_Sum = POST_Sum + 1; + } + else if(Interface_Post != 1)//Fail + { + PC.printf("Interface Post fail\n"); + } + if(Schedules_Post == 1)//Success + { + PC.printf("Schedules Post Pass\n"); + POST_Sum = POST_Sum + 1; + } + else if (Schedules_Post != 1)//Fail + { + PC.printf("Schedules Post fail\n"); + } + if(Feedback_Post == 1)//Success + { + PC.printf("Feedback Post Pass\n"); + POST_Sum = POST_Sum + 1; + } + else if(Feedback_Post != 1)//Fail + { + PC.printf("Feedback Post Fail\n"); + } + if(Serial_PC_Post == 1)//Success + { + PC.printf("Serial PC Post Pass\n"); + POST_Sum = POST_Sum + 1; + } + else if(Serial_PC_Post != 1)//Fail + { + PC.printf("Serial PC Post Fail\n"); + } + if(Serial_BOARD_Post == 1)//Pass + { + PC.printf("Serial Board Pass\n"); + POST_Sum = POST_Sum + 1; + } + else if (Serial_BOARD_Post != 1)//Fail + { + PC.printf("Serial Board Fail\n"); + } + if(POST_Sum == 5) + { + PC.printf("Post Nominal\n"); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/POST/Post.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,13 @@ +#ifndef _POST_HPP_ +#define _POST_HPP_ + +#include "mbed.h" +#include "rtos.h" + +#include "Interface.hpp" +#include "Setup.hpp" +void POST();//Power on self test + + + +#endif //_POST_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SCHEDULES/Schedules.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,16 @@ +#include "Schedules.hpp" + +SCHEDULES::SCHEDULES(){} +SCHEDULES::~SCHEDULES(){} +void SCHEDULES::Init(){} +int SCHEDULES::Post() +{ + return 1;//Success +} +void SCHEDULES::Schedules_output() +{ + while(1) + { + //Do somthing + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SCHEDULES/Schedules.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,34 @@ +#ifndef _SCHEDULES_HPP_ +#define _SCHEDULES_HPP_ + +#include "mbed.h" +#include "rtos.h" +#include "TextLCD.h" + +//Libraries and header file includes + + +extern Serial PC; //TX, RX +extern TextLCD Lcd; // rs, e, d4-d7 + +class SCHEDULES +{ + public://Public member functions and variables + SCHEDULES(); + ~SCHEDULES(); + void Init(); + int Post(); + void Schedules_output(); + //Public Functions + + //Public Variabls + + private://Private member functions and variables + + //Private Functions + + //Private Variables + + +}; +#endif //_INTERFACE_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial/Serial_Board.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,57 @@ +#include "Serial_Board.hpp" + +SERIAL_BOARD::SERIAL_BOARD()//Constructor +{ + _POST_Value_Mutex.lock(); + _POST_Value = 77;//Need a post test value to get a echo confirm + _POST_Value_Mutex.unlock(); + _Received_Data_Mutex.lock(); + _Received_Data = 0;//Set data to 0 + _Received_Data_Mutex.unlock(); + _Output_Data_Mutex.lock(); + _Output_Data = 0;//Set the output data to 0 + _Output_Data_Mutex.unlock(); +} +SERIAL_BOARD::~SERIAL_BOARD(){}//Destructor +void SERIAL_BOARD::Init(){} +int SERIAL_BOARD::Post() +{ + _POST_Value_Mutex.lock(); + _Received_Data_Mutex.lock(); + Board.printf("%d\n", _POST_Value); + Board.scanf("%d", &_Received_Data); + _POST_Value_Mutex.unlock(); + _Received_Data_Mutex.unlock(); + if(_POST_Value == _Received_Data) + { + return 1;//Pass + } + else + { + return 0;//Fail + } +} +void SERIAL_BOARD::Main() +{ + if(PC.readable()) + { + PC.printf("In Serial board\n"); + } + while(1) + { + for(int loop = 0; loop < 16; loop++) + { + _Output_Data_Mutex.lock(); + _Received_Data_Mutex.lock(); + _Output_Data = _Output_Data + 1; + Board.printf("%d\n", _Output_Data); + Board.scanf("%d", &_Received_Data); + PC.printf("Data is %d\n",_Received_Data); + _Output_Data_Mutex.unlock(); + _Received_Data_Mutex.unlock(); + Thread::wait(1000); + } + _Output_Data = 0; + Thread::wait(1000); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial/Serial_Board.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,33 @@ +#ifndef _SERIAL_Board_HPP_ +#define _SERIAL_Board_HPP_ + +#include "mbed.h" +#include "rtos.h" + +#include "Serial_PC.hpp" + +class SERIAL_BOARD +{ + public://Public member functions and variables + + SERIAL_BOARD(); + ~SERIAL_BOARD(); + void Init(); + int Post(); + void Main(); + //Public Functions + + + private://Private member functions and variables + int _POST_Value; + int _Received_Data; + int _Output_Data; + + //Mutex Locks + Mutex _POST_Value_Mutex; + Mutex _Received_Data_Mutex; + Mutex _Output_Data_Mutex; +}; + + +#endif //_SERIAL_BOARD_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial/Serial_PC.cpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,26 @@ +#include "Serial_PC.hpp" +int Logging = 0; +SERIAL_PC::SERIAL_PC(){} +SERIAL_PC::~SERIAL_PC(){} +void SERIAL_PC::Init(){} +int SERIAL_PC::Post() +{ + return 1; +} +void SERIAL_PC::Main() +{ + while(1) + { + if(PC.readable())//Check that you can write to the PC + { + PC.printf("Testing for serial\n"); + } + PC.scanf("%s",&_buffer); + if(_buffer == "Log") + { + PC.printf("Logging\n"); + Logging = 1; + } + Thread::wait(1000); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial/Serial_PC.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,28 @@ +#ifndef _SERIAL_PC_HPP_ +#define _SERIAL_PC_HPP_ + +#include "mbed.h" +#include "rtos.h" +#include "Interface.hpp" + +extern int Logging; +class SERIAL_PC +{ + public://Public member functions and variables + + SERIAL_PC(); + ~SERIAL_PC(); + void Init(); + int Post(); + void Main(); + //Public Functions + + + private://Private member functions and variables + char _buffer[32];//Character buffer for the serial data to be stored within + + +}; + + +#endif //_SERIAL_PC_HPP_ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Setup.hpp Tue May 07 21:55:57 2019 +0000 @@ -0,0 +1,17 @@ +#ifndef _SETUP_HPP_ +#define _SETUP_HPP_ +//Libraries +#include "mbed.h" +#include "rtos.h" //Real Time Operating System. https://os.mbed.com/handbook/RTOS +//#include "ShiftReg.h" + + +//Header Files +#include "Control.hpp" +//Digital Outputs +static Thread Control_Interboard_Comms_Thread; +static Thread Control_power_Thread; +static Thread Feedback_Thread; +static Thread Serial_PC_Thread; +static Thread Serial_Board_Thread; +#endif //_SETUP_HPP_
--- a/main.cpp Tue May 07 14:05:31 2019 +0000 +++ b/main.cpp Tue May 07 21:55:57 2019 +0000 @@ -1,68 +1,19 @@ -#include "mbed.h" -#include "rtos.h" //Real Time Operating System. https://os.mbed.com/handbook/RTOS -#include "TextLCD.h" -#include "ShiftReg.h" - -//Pinouts for the bluepill can be found here -//https://os.mbed.com/users/hudakz/code/STM32F103C8T6_Hello/ +#include "Setup.hpp" -DigitalOut myled(PC_13); //Onboard LED -Serial PC(PB_10, PB_11); //TX, RX -//TextLCD LCD(PB_12, PB_13, PB_14, PB_15, PA_8, PA_9); // rs, e, d4-d7 -ShiftReg SR(PA_10, PA_12, PA_15, PA_11); //data, store, clock, output enable - - -//DigitalOut Muscle0(PA_10); -//DigitalOut Muscle1(PA_10); - -//AnalogIn FEEDBACK_0(PB_0); -//AnalogIn FEEDBACK_1(PB_1); - - +void Control_Power_Function(){Control_Main();} +void Serial_PC_Thread_Function(){SERIAL_PC_1.Main();} +void Serial_Board_Thread_Function(){SERIAL_BOARD_1.Main();} int main() { - /* - //outen = 0; - SR.ShiftByte(0x0000, ShiftReg::MSBFirst); - //SR.ShiftByte(0x00,0x80); - SR.Latch(); - wait(0.2); - SR.ShiftByte(0xF0F0, ShiftReg::MSBFirst); - SR.Latch(); - //outen = 0; - wait(2); - SR.ShiftByte(0x0000, ShiftReg::MSBFirst); - SR.Latch(); - */ - SR.Write(0x0000); - wait(1); + //Thread starting + Control_Post();//Power on self test + Thread::wait(1000); + Control_power_Thread.start(Control_Power_Function); + Serial_PC_Thread.start(Serial_PC_Thread_Function); + Serial_Board_Thread.start(Serial_Board_Thread_Function); + while(1) { - SR.Write(0xF0F0); - wait(1); - SR.Write(0x0F0F); - wait(1); - /* - SR.ShiftBit(1); - SR.Latch(); - wait(0.2); - for (int i = 0; i < 16; i++) { - SR.ShiftBit(0); - SR.Latch(); - wait(0.2); - } - */ - //myled = 1; // LED is ON - //Muscle0 = 1; - //wait(1); // 200 ms - - //myled = 0; // LED is OFF - //Muscle0 = 0; - //wait(1); // 1 sec - - PC.printf("troll lol lol lol lol lol lol\n\r"); - //PC.printf("%.6f %.6f\n\r",FEEDBACK_0.read(),FEEDBACK_1.read()); - //LCD.printf("Hello World!\n"); - + Thread::signal_wait(1);//Sleep the main thread } }