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.

[参考译文] TM4C129ENCZAD:Telnet 和 GPIO 性能

Guru**** 1831610 points
Other Parts Discussed in Thread: TM4C129ENCZAD
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1107257/tm4c129enczad-telnet-and-gpio-performance

器件型号:TM4C129ENCZAD

我有一个 TM4C129ENCZAD 微控制器、用于通过 Telnet 控制 GPIO。 我已经修改了 shell 环境、通过 telnet 通过一些简单的命令来控制 GPIO 输出。  

使用以下代码关闭了中的 GPIO、

static void open(char *str)
{
    if (str[1] == '0'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, 0);
        shell_output("<0>","");
    }
    if (str[1] == '1'){
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);
        shell_output("<0>","");
    }
    if (str[1] == '2'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);
        shell_output("<0>","");
    }
    if (str[1] == '3'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, 0);
        shell_output("<0>","");
    }
    if (str[1] == '4'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0);
        shell_output("<0>","");
    }
    if (str[1] == '5'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0);
        shell_output("<0>","");
    }
    if (str[1] == '6'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0);
        shell_output("<0>","");
    }
    if (str[1] == '7'){
        ROM_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_1, 0);
        shell_output("<0>","");
    }
    if (str[1] == '8'){
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, 0);
        shell_output("<0>","");
    }
    if (str[1] == '9'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'A'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'B'){
        ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'C'){
        ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'D'){
        ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'E'){
        ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'F'){
        ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_6, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'G'){
        ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_5, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'H'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'I'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_3, 0);
        shell_output("<0>","");
    }
    if (str[1] == 'J'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_6, 0);
        shell_output("<0>","");
    }
}

 使用 以下代码打开 GPIO 引脚、

static void close(char *str)
{
    if (str[1] == '0'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, GPIO_PIN_6);
        shell_output("<1>","");
    }
    if (str[1] == '1'){
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);
        shell_output("<1>","");
    }
    if (str[1] == '2'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4);
        shell_output("<1>","");
    }
    if (str[1] == '3'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_4, GPIO_PIN_4);
        shell_output("<1>","");
    }
    if (str[1] == '4'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_PIN_6);
        shell_output("<1>","");
    }
    if (str[1] == '5'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1);
        shell_output("<1>","");
    }
    if (str[1] == '6'){
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3);
        shell_output("<1>","");
    }
    if (str[1] == '7'){
        ROM_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_1, GPIO_PIN_1);
        shell_output("<1>","");
    }
    if (str[1] == '8'){
        ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_7, GPIO_PIN_7);
        shell_output("<1>","");
    }
    if (str[1] == '9'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_PIN_2);
        shell_output("<1>","");
    }
    if (str[1] == 'A'){
        ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1);
        shell_output("<1>","");
    }
    if (str[1] == 'B'){
        ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0, GPIO_PIN_0);
        shell_output("<1>","");
    }
    if (str[1] == 'C'){
        ROM_GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, GPIO_PIN_2);
        shell_output("<1>","");
    }
    if (str[1] == 'D'){
        ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_PIN_6);
        shell_output("<1>","");
    }
    if (str[1] == 'E'){
        ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5, GPIO_PIN_5);
        shell_output("<1>","");
    }
    if (str[1] == 'F'){
        ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_6, GPIO_PIN_6);
        shell_output("<1>","");
    }
    if (str[1] == 'G'){
        ROM_GPIOPinWrite(GPIO_PORTR_BASE, GPIO_PIN_5, GPIO_PIN_5);
        shell_output("<1>","");
    }
    if (str[1] == 'H'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, GPIO_PIN_2);
        shell_output("<1>","");
    }
    if (str[1] == 'I'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_3, GPIO_PIN_3);
        shell_output("<1>","");
    }
    if (str[1] == 'J'){
        ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_6, GPIO_PIN_6);
        shell_output("<1>","");
    }
}

使用以下代码检查 GPIO 引脚、

static void status(char *str)
{
    if (str[1] == '0')
    {
        if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_6))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '1')
    {
        if (ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '2')
    {
        if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '3')
    {
        if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_4))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '4')
    {
        if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_6))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '5')
    {
        if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_1))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '6')
    {
        if (ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_3))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '7')
    {
        if (ROM_GPIOPinRead(GPIO_PORTQ_BASE, GPIO_PIN_1))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '8')
    {
        if (ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_7))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == '9')
    {
        if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'A')
    {
        if (ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'B')
    {
        if (ROM_GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_0))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'C')
    {
        if (ROM_GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_2))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'D')
    {
        if (ROM_GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'E')
    {
        if (ROM_GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'F')
    {
        if (ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_6))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'G')
    {
        if (ROM_GPIOPinRead(GPIO_PORTR_BASE, GPIO_PIN_5))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'H')
    {
        if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_2))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'I')
    {
        if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_3))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
    if (str[1] == 'J')
    {
        if (ROM_GPIOPinRead(GPIO_PORTH_BASE, GPIO_PIN_6))
        {
            shell_output("<1>","");
        }
        else
        {
            shell_output("<0>","");
        }
    }
}

我需要尽快打开/关闭 GPIO 引脚、但切换需要大约750毫秒。

在计算机中、我将通过 C#程序发送 telnet 命令来打开和关闭 GPIO 引脚。  

在不验证微控制器是否正确切换的情况下发送打开或关闭命令将阻止某些 GPIO 引脚正确关闭/打开。

 

do
{
    string close_result1 = cdf_muxes[card].close(channel);
    string close_result2 = cdf_muxes[card + 1].close(channel);
    if (close_result1.Contains("1")) cr1 = true; else cr1 = false;
    if (close_result2.Contains("1")) cr2 = true; else cr2 = false;
} while (!(cr1 == true & cr2 == true));

bool or1 = false;
bool or2 = false;
do
{
    string open_result1 = cdf_muxes[card].open(channel);
    string open_result2 = cdf_muxes[card + 1].open(channel);
    if (open_result1.Contains("0")) or1 = true; else or1 = false;
    if (open_result2.Contains("0")) or2 = true; else or2 = false;

} while (!(or1 == true & or2 == true));

是否有人对如何减少打开/关闭 GPIO 引脚所需的时间有任何建议?

谢谢、

Allan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Allan、

    750毫秒似乎需要很长时间,我不知道这种实施会有什么瓶颈,因为我不熟悉 Telnet。 从 MCU 代码的角度来看、不应该有这么慢的处理速度、我会说您最好使用 Switch Case 语句、而不是 IFS、因为从我可以告诉每个 打开/关闭的内容来看、它只能更改1个 GPIO、所以请执行 IFS 列表 比您所需的检查要多得多、因为您只需找到合适的 GPIO、然后退出即可。

    但这种效率低下不能解释它要持续一秒钟、因此我怀疑 Telnet 协议发送和接收方式有一些问题、这会进一步延迟它。

    此致、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [~用户名="392758 " URL" URL ="Δ 芯片/支持/微控制器/基于 ARM 的微控制器组/ARM 的微控制器/f/基于 ARM 的微控制器-论坛/1107257/tm4c129enczad-telnet-and-gpio-performance"]

    我需要尽快打开/关闭 GPIO 引脚、但切换需要大约750毫秒。

    在计算机中、我将通过 C#程序发送 telnet 命令来打开和关闭 GPIO 引脚。  

    [/报价]

    在计算机中、C#程序在  套接字上设置 NoDelay 属性?

    如果不是、 Nagle 的算法 可能是导致延迟的原因。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    切斯特、

    tcpSocket.NoDelay 属性已设置为 true。

     public TelnetConnection(string Hostname, int Port, ref bool result)
            {
                try
                {
                    tcpSocket = new TcpClient();
                    tcpSocket.ReceiveTimeout = 1;
                    tcpSocket.SendTimeout = 1;
                    tcpSocket.NoDelay = true;
    
                    tcpSocket.Connect(Hostname, Port);
                    result = true;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"TelnetConnection Error: {ex.Message}");
                    result = false;
                }
            }

    谢谢、

    Allan