Dummy program to demonstrate problems: working code

Dependencies:   SLCD mbed-rtos mbed

Fork of MNG_TC by Shreesha S

ThreadFunctions.h

Committer:
shreeshas95
Date:
2015-09-17
Revision:
17:2b04e53f3b1d
Parent:
14:a4c259ca0325

File content as of revision 17:2b04e53f3b1d:

void reset_all(){
    printf("resetting all\r\n");
    // reset MNG_TC
    MNG_TC::init();
    TC_list *tcp = VAR_SPACE::Head_node;
    while(tcp != NULL){
        TC_list *temp = tcp->next_TC;
        delete tcp;
        tcp = temp;
    }
    
    // reset COM_RCV_TC
//    handle reset
    
    // reset data linked list
    data_list *dataptr = VAR_SPACE::head_data;
    while( dataptr != NULL ){
        data_list *temp = dataptr->next;
        delete dataptr;
        dataptr = temp;
    }
    VAR_SPACE::head_data = new data_list;
    VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
}

void after_receive(void){
    rx_timeout.detach();
    VAR_SPACE::rx_new_node->val = 0x00;
    
    if(first_time){
        first_time = false;
        pass_time.attach(&after_pass, PASS_TIME_LIMIT);
    }
    
    VAR_SPACE::new_tc_received = true;
    VAR_SPACE::mng_tmtc_thread->signal_set(0x01);
}


void com_rcv_tc_fun(const void *args){
    
    while(true){
        Thread::signal_wait(0x01);
        
        //~ allocate new node
        VAR_SPACE::rx_new_node->next = new data_list;
        VAR_SPACE::rx_new_node = VAR_SPACE::rx_new_node->next;
        VAR_SPACE::rx_new_node->next = NULL;
        
        rx_timeout.attach(&after_receive, RX_TIMEOUT_LIMIT);
    }
}

void com_mng_fun(const void *args){
    while(true){
        
        Thread::signal_wait(0x01);
        ledr = !ledr;
        
        if( VAR_SPACE::new_tc_received ){
            VAR_SPACE::new_tc_received = false;
            struct data_list *haha = VAR_SPACE::head_data;
            
            unsigned int count = 0;
            while( haha != NULL ){
                ++count;
                printf("%x ", haha->val);
                haha = haha->next;
            }
            printf("\t count = %u \r\n", count);
            printf("new tc received : state = %u\r\n", VAR_SPACE::rx_state);
            
            if( VAR_SPACE::rx_state == 0 ){
                VAR_SPACE::data_node = VAR_SPACE::head_data;
                COM_RCV_TC::rx_rcv_tc();
                MNG_TC::start_with();
                if( MNG_TC::check_for_missing_TC() ){
                    printf("everything pass\r\n");
                    VAR_SPACE::rx_state = 1;
                    MNG_TC::execute_TC();
                }
            }
            else if( VAR_SPACE::rx_state == 3 ){
                VAR_SPACE::data_node = VAR_SPACE::head_data;
                COM_RCV_TC::rx_rcv_tc();
                MNG_TC::start_with();
                if( MNG_TC::check_for_missing_TC() ){
                    VAR_SPACE::execute_obosc = true;
                    VAR_SPACE::rx_state = 2;
                    MNG_TC::execute_TC();
                }
            }
            else{
                // invalid state in main found reset
                reset_all();
            }
        }
    }
}


//void com_pay_thread_fun(void const *args){
//    while(true){
//        VAR_SPACE::COM_payload_thread->signal_wait(0x01);
//        //read rtc time later
//        uint64_t RTC_time = 0;
//        Science_Data_Compression::complete_compression( VAR_SPACE::payload_dma_buffer , RTC_time);
//    }
//}