搜索
bottom↓
回复: 8

rtt在at91sam9260平台上频繁按键中断后导致无法再次中断,同时在finsh中频繁执行list_

[复制链接]

出0入0汤圆

发表于 2011-2-22 22:51:31 | 显示全部楼层 |阅读模式
大家好,最近我把rt-thread-0.4.0移植到at91sam9260芯片上,并成功跑起来了,但是在这个过程中遇到了一些问题,请各位指教。

目前开启了三个测试线程,情况如下:
线程一:点亮led灯
线程二:打印串口信息
线程三:获取按键中断发的邮箱信号,并打印串口信息

代码如下:

static rt_thread_t key_tid1 = RT_NULL;
/* 邮箱控制块 */
static struct rt_mailbox mb;
/* 用于放邮件的内存池 */
static char mb_pool[16];

static char mb_str1[] = "PC15";
static char mb_str2[] = "PC7";

/* 线程1入口 */
static void key_thread_entry(void* parameter)
{
        unsigned char* str;

        while (1)
        {
                rt_kprintf("thread1: try to recv a mail\n");

                /* 从邮箱中收取邮件 */
                if (rt_mb_recv(&mb, (rt_uint32_t*)&str, RT_WAITING_FOREVER) == RT_EOK)
                {
                        rt_kprintf("KEY pressed on PC15:%s\n", str);

                        /* 延时10个OS Tick */
                        //rt_thread_delay(10);
                }
        }
}

void rt_pioc_handler(int vector)
{
        rt_uint32_t status;
        status = at91_sys_read(AT91_PIOC+0x4c);
        if (status & (1<<15))
        {
                //rt_kprintf("KEY pressed on PC15\n");
                rt_mb_send(&mb, (rt_uint32_t)&mb_str1[0]);
        }
        if (status & (1<<7))
        {
                //rt_kprintf("KEY pressed on PC7\n");
                rt_mb_send(&mb, (rt_uint32_t)&mb_str2[0]);
        }
}

void key_init(void)
{
        at91_sys_write(AT91_PIOC, (1<<15)|(1<<7));
        at91_sys_write(AT91_PIOC+0x14, (1<<15)|(1<<7));
        at91_sys_write(AT91_PIOC+0x20, (1<<15)|(1<<7));
        at91_sys_write(AT91_PIOC+0x40, (1<<15)|(1<<7));
        at91_sys_write(AT91_PIOC+0x64, (1<<15)|(1<<7));
        at91_sys_read(AT91_PIOC+0x4c);

        /* 初始化一个mailbox */
        rt_mb_init(&mb,
                "key_mb",             /* 名称是mbt */
                &mb_pool[0],       /* 邮箱用到的内存池是mb_pool */
                sizeof(mb_pool)/4,   /* 大小是mb_pool大小除以4,因为一封邮件的大小是4字节 */
                RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */
        /* 创建线程1 */
        key_tid1 = rt_thread_create("key",
                key_thread_entry, RT_NULL, /* 线程入口是thread1_entry, 入口参数是RT_NULL */
                512, 20, 10);
        if (key_tid1 != RT_NULL)
                rt_thread_startup(key_tid1);
        else
                rt_kprintf("start thread key failed\n");

        rt_hw_interrupt_install(AT91SAM9260_ID_PIOC, rt_pioc_handler, RT_NULL);
        rt_hw_interrupt_umask(AT91SAM9260_ID_PIOC);
}

void rt_led_thread_entry(void* parameter)

{
        rt_uint8_t cnt = 0;
        led_init();
        while(1)
        {
                /* light on leds for one second */
                rt_thread_delay(40);
                cnt++;
                if (cnt&0x01)
                        led_on(1);
                else
                        led_off(1);
                if (cnt&0x02)
                        led_on(2);
                else
                        led_off(2);
                if (cnt&0x04)
                        led_on(3);
                else
                        led_off(3);
        }

}



void rt_test_thread_entry(void *parameter)
{
        while(1)
        {
                rt_kprintf("test thread enter\n");
                rt_thread_delay(400);
        }
}

int rt_application_init()
{
        rt_thread_t led_thread;
        rt_thread_t test_thread;
#if (RT_THREAD_PRIORITY_MAX == 32)
        led_thread = rt_thread_create("led",
                                                        rt_led_thread_entry, RT_NULL,
                                                        512, 20, 20);

        test_thread = rt_thread_create("test",

                                                        rt_test_thread_entry, RT_NULL,

                                                        512, 24, 20);
#else
        led_thread = rt_thread_create("led",
                                                        rt_led_thread_entry, RT_NULL,
                                                        512, 200, 20);
        test_thread = rt_thread_create("test",
                                                        rt_test_thread_entry, RT_NULL,
                                                        512, 240, 20);
#endif
        if(led_thread != RT_NULL)
                rt_thread_startup(led_thread);
        if(test_thread != RT_NULL)
                rt_thread_startup(test_thread);
        key_init();

        return 0;

}


目前遇到的问题是在频繁按键后,中断会消失,即按键不会进入中断,正常情况下在按键过程中,在按键信号的上升沿和下降沿都会产生中断。
串口打印信息如下:
thread1: try to recv a mail
finsh>>test thread enter

finsh>>test thread enter
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
test thread enter
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
KEY pressed on PC15:PC15
thread1: try to recv a mail
test thread enter              ------------> 之后无论怎样按键都不会进入中断处理函数,但是其他的功能都正常,
test thread enter                            不过有个奇怪的现象,在finsh中多次执行list_thread()命令会导致idle线程栈溢出死机
test thread enter
test thread enter
test thread enter
test thread enter


除此之外,不进行任何按键动作,只是在finsh终端中执行list_thread()命令,会出现idle线程栈溢出的警告信息,多次执行后会出现栈溢出死机。
串口打印信息如下:
finsh>>
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x0000007c 0x00000100 0x000000f4 0x0000001e 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000001cc 0x00001000 0x0000024c 0x00000009 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 suspend 0x000000ac 0x00000200 0x000000ac 0x00000014 000
        0, 0x00000000
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x0000007c 0x00000100 0x000000f4 0x0000000b 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000000a4 0x00001000 0x0000024c 0x00000004 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 suspend 0x000000ac 0x00000200 0x000000ac 0x00000014 000
        0, 0x00000000
finsh>>test thread enter
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x00000054 0x00000100 0x000000f4 0x00000018 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000000a4 0x00001000 0x0000024c 0x00000009 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 ready   0x000000ac 0x00000200 0x000000ac 0x00000014 -02
        0, 0x00000000
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x0000007c 0x00000100 0x000000f4 0x0000001c 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000000a4 0x00001000 0x0000024c 0x00000002 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 ready   0x000000ac 0x00000200 0x000000ac 0x00000014 -02
        0, 0x00000000
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x00000070 0x00000100 0x000000f4 0x00000010 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000000a4 0x00001000 0x0000024c 0x00000006 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 ready   0x000000ac 0x00000200 0x000000ac 0x00000014 -02
        0, 0x00000000
finsh>>list_thread()
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x0000006c 0x00000100 0x000000f4 0x00000007 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 ready   0x000000a4 0x00001000 0x0000024c 0x00000009 -04
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 suspend 0x000000ac 0x00000200 0x000000ac 0x00000014 000
        0, 0x00000000
finsh>>test thread enter
finsh>>list_thread()warning: tidle stack is close to end of stack address.
thread:tidle stack overflow
thread  pri  status      sp     stack size max used   left tick  error
-------- ---- ------- ---------- ---------- ---------- ---------- ---
tidle    0xff ready   0x00000124 0x00000100 0x00000100 0x0000001f 000
timer    0x08 suspend 0x00000094 0x00000200 0x000000e4 0x00000008 000
tshell   0x14 suspend 0x000000a4 0x00001000 0x0000024c 0x00000006 000
key      0x14 suspend 0x000000ac 0x00000200 0x000000ac 0x00000008 000
test     0xf0 suspend 0x000000a4 0x00000200 0x000000a4 0x00000014 000
led      0xc8 suspend 0x000000ac 0x00000200 0x00000170 0x00000014 000



请教一下,这些问题是什么原因导致?
谢谢!

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2011-2-22 23:14:14 | 显示全部楼层
回复【楼主位】lh-linux  
-----------------------------------------------------------------------
另外补充一下,如果没有在finsh中执行list_thread(),就不会出现tidle线程栈溢出的情况。

出0入0汤圆

 楼主| 发表于 2011-2-23 19:31:09 | 显示全部楼层
具体讨论见
http://www.rt-thread.org/phpbbforum/viewtopic.php?f=2&t=929&p=4666#p4666

出0入0汤圆

发表于 2011-2-23 19:50:39 | 显示全部楼层
看到贴我都会回的,不用两边发,你这个贴早上的时候不知道为什么没看到,有些奇怪。

出0入0汤圆

 楼主| 发表于 2011-2-23 20:04:09 | 显示全部楼层
回复【3楼】ffxz  
-----------------------------------------------------------------------
早上的时候还没有审核通过,我就发到官网了,^_^

出0入0汤圆

发表于 2011-2-24 14:04:13 | 显示全部楼层
可以搞一个at91sam9260的分支,让大家一起探讨!~

出0入0汤圆

发表于 2011-2-24 15:26:20 | 显示全部楼层
回复【5楼】ljt8015  
可以搞一个at91sam9260的分支,让大家一起探讨!~
-----------------------------------------------------------------------

你会一起贡献吗?

出0入0汤圆

发表于 2011-2-24 15:40:16 | 显示全部楼层
回复【6楼】ffxz
回复【5楼】ljt8015   
可以搞一个at91sam9260的分支,让大家一起探讨!~
-----------------------------------------------------------------------
你会一起贡献吗?
-----------------------------------------------------------------------

公司有计划搞at91sam9G20,是at91sam9260的升级版,版子还没买,有时间肯定会移植rt-thread!~

出0入0汤圆

 楼主| 发表于 2011-2-26 17:26:27 | 显示全部楼层
回复【5楼】ljt8015  
可以搞一个at91sam9260的分支,让大家一起探讨!~
-----------------------------------------------------------------------
现在还有点小问题,等相关驱动完善一些了就发上来。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-15 19:50

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表