TELECOMMAND MANAGER V1

Dependencies:   mbed SLCD mbed-rtos

main.cpp

Committer:
shreeshas95
Date:
2015-07-17
Revision:
11:109f16cc35d7
Parent:
10:024c2ef51cb1

File content as of revision 11:109f16cc35d7:

//how to handle interrupt while running other thread ?

#include "mbed.h"
#include "rtos.h"
#define ENDL "\r" << endl

#include "SLCD.h"
SLCD lcd;

#define RX_TIMEOUT_LIMIT 2
#define PASS_TIME_LIMIT 1200

Serial PC(USBTX, USBRX);
RawSerial rx1m(PTE0, PTE1);

DigitalOut ledr(LED_RED);
DigitalOut ledg(LED_GREEN);

#include "Structures.h"

struct data_list{
   unsigned char val;
   struct data_list* next;
};

namespace VAR_SPACE{
    
    TC_list *Head_node = NULL;
    TC_list *last_node = NULL;
    
    int rx_state = 0;
    /*
    0 : idle
    1 : executing normal
    2 : executing obosc
    3 : idle 2 : obosc received incorrectly
    */
    
    struct data_list *head_data;
    data_list *data_node;
    struct data_list *rx_new_node;
    
    bool new_tc_received = false;
    bool execute_obosc = false;
    
    Thread *mng_tmtc_thread = NULL;
    Thread *COM_RCV_TC_thread = NULL;
}

Timeout rx_timeout;
bool pass_over = false;
bool first_time = true;
Timeout pass_time;

void after_pass(){
    pass_time.detach();
    pass_over = true;
}

#include "crc.h"
#include "Convolution.h"
#include "SND_TM.h"
#include "COM_RCV_TC.h"
#include "MNG_TC.h"
#include "ThreadFunctions.h"

void rx_read() {
//    store value
//    rx_char = UART1->D;
    VAR_SPACE::rx_new_node->val = rx1m.getc();
    
    VAR_SPACE::COM_RCV_TC_thread->signal_set(0x01);
}

int main(){
    
    printf("welcome to mng_tm_tc\r\n");
    
    PC.baud(9600);
    
    rx1m.baud(1200);
    rx1m.attach(&rx_read, Serial::RxIrq);
    VAR_SPACE::head_data = new data_list;
    VAR_SPACE::head_data->next = NULL;
    VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
    
    VAR_SPACE::mng_tmtc_thread = new Thread(com_mng_fun);
    MNG_TC::init();
    VAR_SPACE::COM_RCV_TC_thread = new Thread(com_rcv_tc_fun);
    
    lcd.printf("0");
    
    struct data_list *hehe = VAR_SPACE::head_data;
    while( hehe != NULL ){
        printf("%x ", hehe->val);
        hehe = hehe->next;
    }
    printf("\r\n");
    
    while(true){
//        ledg = !ledg;
        if(pass_over){
            pass_over = false;
            first_time = true;
            // pass got over reset all
            reset_all();
            //also consider frame_no
        }
    }
}