PROJ515 / Mbed 2 deprecated PROJ514-MASTER

Dependencies:   mbed mbed-rtos ShiftReg2 TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Serial_Board.cpp Source File

Serial_Board.cpp

00001 #include "Serial_Board.hpp"
00002 
00003 SERIAL_BOARD::SERIAL_BOARD()//Constructor
00004 {
00005     _POST_Value_Mutex.lock();
00006     _POST_Value = 77;//Need a post test value to get a echo confirm
00007     _POST_Value_Mutex.unlock();
00008     _Received_Data_Mutex.lock();
00009     _Received_Data = 0;//Set data to 0
00010     _Received_Data_Mutex.unlock();
00011     _Output_Data_Mutex.lock();
00012     _Output_Data = 0;//Set the output data to 0
00013     _Output_Data_Mutex.unlock();
00014 }
00015 SERIAL_BOARD::~SERIAL_BOARD(){}//Destructor
00016 void SERIAL_BOARD::Init(){}
00017 int SERIAL_BOARD::Post()
00018 {   
00019     _POST_Value_Mutex.lock();
00020     _Received_Data_Mutex.lock();
00021     Board.printf("%d\n", _POST_Value);
00022     Board.scanf("%d", &_Received_Data);
00023     _POST_Value_Mutex.unlock();
00024     _Received_Data_Mutex.unlock();
00025     if(_POST_Value == _Received_Data)
00026     {
00027         return 1;//Pass
00028     }
00029     else
00030     {
00031         return 0;//Fail
00032     }
00033 }
00034 void SERIAL_BOARD::Main()
00035 {
00036     if(PC.readable())
00037     {
00038         PC.printf("In Serial board\n");
00039     }
00040     while(1)
00041     {
00042         for(int loop = 0; loop < 16; loop++)
00043         {
00044             _Output_Data_Mutex.lock();
00045             _Received_Data_Mutex.lock();
00046             _Output_Data = _Output_Data + 1;
00047             Board.printf("%d\n", _Output_Data);
00048             Board.scanf("%d", &_Received_Data);
00049             PC.printf("Data is %d\n",_Received_Data);
00050             _Output_Data_Mutex.unlock();
00051             _Received_Data_Mutex.unlock();
00052             Thread::wait(1000);
00053         }
00054     _Output_Data = 0;
00055     Thread::wait(1000);
00056     }
00057 }