This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RE: RTOS/MSP432E401Y: semaphore for UART read

Hi Bob,
Sorry for the late reply.
Actually in my application whenever i send the command to the sensor, for that command it will reply some data. and i need to capture it.
Earlier when i am using atmel avr microcontrollers (and some other controllers) , there are some ISR functions which automatically executed when data comes from the sensor. There in that function i have written my code based in my application.

However here in this case i need to call "uart read" every time after "uart write". And i think it will leads to timing issue.

Could you please let me know , how to write the code to ensure that there will not be any timing issues. I have seen in previous posts, in that there are some functions like "semaphore _post & pend".
Actually i am new to this thread programming.
so please help me on this.

Thank you

Regards
Kalyan.
  • This is a continuation of this thread. e2e.ti.com/.../719325

    Regards,
    Chris
  • Can you send me the code that you have written that has the issue? Also, Can you include a link to the previous post for tracking purposes?
    Thanks,
    Bob L.
  • Kalyan,

    You can see how to set up a callback in this E2E post(UART Callback on TI-RTOS).  This is an altered version of the uartecho TI driver example and shows how to send a byte and then provide a means to have the system receive the byte when it's available without blocking you from other activities. 

    That's all the examples that are available.

    -Bob L.

  • Hello Bob,

    Thank you for the reply.

    I have already tried similar thing however i am not succeeded.

    I am using tcp echo example to transmit data from ethernet to serial and serial to ethernet. ethernet to serial transmission happening properly and serial to ethernet  transmission is not happening properly.

    I am attaching the code please guide me to solve this.

    void tcpworker(uint32_t arg0, uint32_t arg1)
    {
        int  clientfd = (int)arg0;
        int  bytesRcvd;
    //    int  bytesSent;
    //    char buffer[TCPPACKETSIZE];
    
        UART_read(uart4, &buffer1, 1);
        while(1)
        {
            while((bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0)) > 0)          // Ethernet 2 serial
            {
                //  bytesSent = send(clientfd, buffer, bytesRcvd, 0);
                UART_write(uart4, &buffer, bytesRcvd);
            }
    
            if(Rx_flag  ==  1)
            {
                send(clientfd, buffer1, 1, 0);                                       // Serial 2 Ethernet
                Rx_flag =   0;
            }
    
        }
    
        close(clientfd);
    }
    
    
    /*********** tcp worker2 for Serial to Ethernet transmission  ***********************/
    //void Serial2Ethernet(uint32_t arg0, uint32_t arg1)
    //{
    //    int  clientfd = (int)arg0;
    //    if(UART_read(uart4, &buffer, 1) >   0)
    //    {
    //        send(clientfd, buffer, 1, 0);
    //    }
    //
    ////    UART_readCancel(uart4);
    ////    UART_read(uart4, &buffer, 1);
    ////    if(Rx_flag  ==  1)
    ////    {
    ////        send(clientfd, buffer, 1, 0);
    ////    }
    //    close(clientfd);
    //}
    
    /************* uart read ready function  ********************************/
    void uart4_read_ready_fxn(UART_Handle uart4, void *buffer, size_t num)
    {
    //    send(clientfd_Rx, buffer1, 1, 0);
        Rx_flag =   1;
    //    UART_readCancel(uart4);
    }
    

  • Hello Bob,
    Could you please help me on this code.
    Thank you

    Kalyan
  • Hi..
    Can any one help me on this code example i have posted.

    thank you
    kalyan.
  • Hello,
    In response to the original query about semaphores, please see the simpleLink academy training on RTOS consepts and TI-RTOS basics. You will find examples and explanation of the different RTOS components.

    dev.ti.com/.../

    Regards,
    Chris
  • Hi chris,
    Thank you for the reply.
    Could you please see the code and suggest me to get the desired output.

    Regards
    Kalyan.
  • When trying to get both sides to work, do you have the serial-> ethernet and ethernet->serial operating in separate threads?
    It's difficult to tell from here, since you simply have the serial to ethernet section commented out.
    -Bob L
  • Hi Bob,
    Thank you for the reply.
    No I am not using different threads. That case also I have tried but couldn't succeed.
    Now I am using single thread in that I'm checking for a flag. If it is one then I'm trying to send from serial to ethernet.
    Is it the right way to do it.

    Regards
    Kalyan.
  • If you get it working, then it's the right way to do it! Just ensure that you don't let one direction (ie. Serial to Ethernet) block the other.
    Bob
  • Hi Bob,

    First of all thanks for responding.

    Here Ethernet to serial is working perfectly.

    However serial to ethernet transmission happening only when I try to send some data from Ethernet(then only I am able to receive the data, which I previously try to send from uart, in Ethernet side).

    Here problem is we don't have any ISR function to execute directly whenever I am sending data from serial port.

    Should I use two threads like I commented in the program or any other idea.

    Thank you

    Regards

    Kalyan.

  • Kalyan,

     Here's some feedback from one of our Ethernet experts:

    Looks like he is reading the UART in the tcpworker task. This means only when tcpworker task is invoked will the UART_read work.

    UART_read should be in another task or a handler function. The data received should be sent to the tcpworker task using mechanisms like Queue and mailbox (global variables is a bad idea).

    -Bob L.

  • Hi Bob,
    Thank you for the reply.
    I try using multitasking.

    Regards
    Kalyan.

**Attention** This is a public forum