Dummy program to demonstrate problems: working code

Dependencies:   SLCD mbed-rtos mbed

Fork of MNG_TC by Shreesha S

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //how to handle interrupt while running other thread ?
00002 
00003 #include "mbed.h"
00004 #include "rtos.h"
00005 
00006 #include "iostream"
00007 #include "bitset"
00008 using namespace std;
00009 
00010 #define ENDL "\r" << endl
00011 
00012 #include "SLCD.h"
00013 SLCD lcd;
00014 
00015 #define RX_TIMEOUT_LIMIT 1
00016 #define PASS_TIME_LIMIT 1200
00017 #define PAYLOAD_DMA_SIZE 2190
00018 
00019 Serial PC(USBTX, USBRX);
00020 RawSerial rx1m(PTE0, PTE1);
00021 
00022 SPI spi(PTA16, PTA17, PTA15); //MOSI, MISO, CLOCK
00023 Mutex SPI_mutex;
00024 
00025 DigitalOut ledr(LED_RED);
00026 DigitalOut ledg(LED_GREEN);
00027 
00028 #include "Structures.h"
00029 
00030 struct data_list{
00031    unsigned char val;
00032    struct data_list* next;
00033 };
00034 
00035 namespace VAR_SPACE{
00036     
00037     TC_list *Head_node = NULL;
00038     TC_list *last_node = NULL;
00039     
00040     int rx_state = 0;
00041     /*
00042     0 : idle
00043     1 : executing normal
00044     2 : executing obosc
00045     3 : idle 2 : obosc received incorrectly
00046     */
00047     
00048     struct data_list *head_data;
00049     data_list *data_node;
00050     struct data_list *rx_new_node;
00051     
00052     bool new_tc_received = false;
00053     bool execute_obosc = false;
00054     
00055     uint8_t payload_dma_buffer[PAYLOAD_DMA_SIZE];
00056     
00057     Thread *mng_tmtc_thread = NULL;
00058     Thread *COM_RCV_TC_thread = NULL;
00059 //    Thread *COM_payload_thread = NULL;
00060 }
00061 
00062 Timeout rx_timeout;
00063 bool pass_over = false;
00064 bool first_time = true;
00065 Timeout pass_time;
00066 
00067 void after_pass(){
00068     pass_time.detach();
00069     pass_over = true;
00070 }
00071 
00072 #include "crc.h"
00073 #include "mbed_debug.h"
00074 #include "Convolution.h"
00075 #include "interleave.h"
00076 #include "snd_tm_class.h"
00077 #include "SD_read.h"
00078 #include "adf.h"
00079 #include "compression.h"
00080 #include "SDCard_initionalisation.h"
00081 #include "COM_RCV_TC.h"
00082 #include "MNG_TC.h"
00083 #include "ThreadFunctions.h"
00084 
00085 void rx_read() {
00086 //    store value
00087 //    rx_char = UART1->D;
00088     ledg = !ledg;
00089     VAR_SPACE::rx_new_node->val = rx1m.getc();
00090     
00091     VAR_SPACE::COM_RCV_TC_thread->signal_set(0x01);
00092 }
00093 
00094 int main(){
00095     
00096     printf("welcome to mng_tm_tc\r\n");
00097     cs_adf=1;
00098     cs_SDCard=1;
00099     PC.baud(9600);
00100     
00101     rx1m.baud(1200);
00102     VAR_SPACE::head_data = new data_list;
00103     VAR_SPACE::head_data->next = NULL;
00104     VAR_SPACE::rx_new_node = VAR_SPACE::head_data;
00105     rx1m.attach(&rx_read, Serial::RxIrq);
00106     
00107     VAR_SPACE::mng_tmtc_thread = new Thread(com_mng_fun);
00108     MNG_TC::init();
00109     VAR_SPACE::COM_RCV_TC_thread = new Thread(com_rcv_tc_fun);
00110 //    VAR_SPACE::COM_payload_thread = new Thread(com_pay_thread_fun);
00111     
00112     lcd.printf("0");
00113     
00114 //    DUMMY PROGRAM START
00115     unsigned char dummy_tc[] = {0x7e, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x7e};
00116     for(int i = 0 ; i < 13 ; ++i){
00117         VAR_SPACE::rx_new_node->val = dummy_tc[i];
00118         VAR_SPACE::COM_RCV_TC_thread->signal_set(0x01);
00119         Thread::wait(0.01);
00120     }
00121 //    DUMMY PROGRAM END
00122     
00123     while(true){
00124 //        ledg = !ledg;
00125         if(pass_over){
00126             pass_over = false;
00127             first_time = true;
00128             // pass got over reset all
00129             reset_all();
00130             //also consider frame_no
00131         }
00132     }
00133 }