![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
PROJ515-MASTER-No-PWM
Dependencies: mbed mbed-rtos ShiftReg2 TextLCD
Serial/Serial_Board.cpp@4:020f93d35f6e, 2019-05-07 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue May 07 21:55:57 2019 +0000
- Revision:
- 4:020f93d35f6e
- Child:
- 5:dbb984e01ded
Added mutex and safey coding needs more. Added board and serial functions that need testing. As well as a more thorough post function.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 4:020f93d35f6e | 1 | #include "Serial_Board.hpp" |
thomasmorris | 4:020f93d35f6e | 2 | |
thomasmorris | 4:020f93d35f6e | 3 | SERIAL_BOARD::SERIAL_BOARD()//Constructor |
thomasmorris | 4:020f93d35f6e | 4 | { |
thomasmorris | 4:020f93d35f6e | 5 | _POST_Value_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 6 | _POST_Value = 77;//Need a post test value to get a echo confirm |
thomasmorris | 4:020f93d35f6e | 7 | _POST_Value_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 8 | _Received_Data_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 9 | _Received_Data = 0;//Set data to 0 |
thomasmorris | 4:020f93d35f6e | 10 | _Received_Data_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 11 | _Output_Data_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 12 | _Output_Data = 0;//Set the output data to 0 |
thomasmorris | 4:020f93d35f6e | 13 | _Output_Data_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 14 | } |
thomasmorris | 4:020f93d35f6e | 15 | SERIAL_BOARD::~SERIAL_BOARD(){}//Destructor |
thomasmorris | 4:020f93d35f6e | 16 | void SERIAL_BOARD::Init(){} |
thomasmorris | 4:020f93d35f6e | 17 | int SERIAL_BOARD::Post() |
thomasmorris | 4:020f93d35f6e | 18 | { |
thomasmorris | 4:020f93d35f6e | 19 | _POST_Value_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 20 | _Received_Data_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 21 | Board.printf("%d\n", _POST_Value); |
thomasmorris | 4:020f93d35f6e | 22 | Board.scanf("%d", &_Received_Data); |
thomasmorris | 4:020f93d35f6e | 23 | _POST_Value_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 24 | _Received_Data_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 25 | if(_POST_Value == _Received_Data) |
thomasmorris | 4:020f93d35f6e | 26 | { |
thomasmorris | 4:020f93d35f6e | 27 | return 1;//Pass |
thomasmorris | 4:020f93d35f6e | 28 | } |
thomasmorris | 4:020f93d35f6e | 29 | else |
thomasmorris | 4:020f93d35f6e | 30 | { |
thomasmorris | 4:020f93d35f6e | 31 | return 0;//Fail |
thomasmorris | 4:020f93d35f6e | 32 | } |
thomasmorris | 4:020f93d35f6e | 33 | } |
thomasmorris | 4:020f93d35f6e | 34 | void SERIAL_BOARD::Main() |
thomasmorris | 4:020f93d35f6e | 35 | { |
thomasmorris | 4:020f93d35f6e | 36 | if(PC.readable()) |
thomasmorris | 4:020f93d35f6e | 37 | { |
thomasmorris | 4:020f93d35f6e | 38 | PC.printf("In Serial board\n"); |
thomasmorris | 4:020f93d35f6e | 39 | } |
thomasmorris | 4:020f93d35f6e | 40 | while(1) |
thomasmorris | 4:020f93d35f6e | 41 | { |
thomasmorris | 4:020f93d35f6e | 42 | for(int loop = 0; loop < 16; loop++) |
thomasmorris | 4:020f93d35f6e | 43 | { |
thomasmorris | 4:020f93d35f6e | 44 | _Output_Data_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 45 | _Received_Data_Mutex.lock(); |
thomasmorris | 4:020f93d35f6e | 46 | _Output_Data = _Output_Data + 1; |
thomasmorris | 4:020f93d35f6e | 47 | Board.printf("%d\n", _Output_Data); |
thomasmorris | 4:020f93d35f6e | 48 | Board.scanf("%d", &_Received_Data); |
thomasmorris | 4:020f93d35f6e | 49 | PC.printf("Data is %d\n",_Received_Data); |
thomasmorris | 4:020f93d35f6e | 50 | _Output_Data_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 51 | _Received_Data_Mutex.unlock(); |
thomasmorris | 4:020f93d35f6e | 52 | Thread::wait(1000); |
thomasmorris | 4:020f93d35f6e | 53 | } |
thomasmorris | 4:020f93d35f6e | 54 | _Output_Data = 0; |
thomasmorris | 4:020f93d35f6e | 55 | Thread::wait(1000); |
thomasmorris | 4:020f93d35f6e | 56 | } |
thomasmorris | 4:020f93d35f6e | 57 | } |