打印
[抢楼250]

菜地公告:即日起创建《菜农Cortex-M0助学园地》(盖楼入口)

[复制链接]
楼主: hotpower
手机看帖
扫描二维码
随时随地手机跟帖
5921
hotpower|  楼主 | 2011-12-3 01:38 | 只看该作者 回帖奖励 |倒序浏览
mbox_buff.cpp
#include "Look_mbox_buff.h"
#include "utils/debug.h"
#include "numicro/sfr/gpio"

mbox_t<int, 250> Mbox;// 创建 int 型邮箱
int sum;

instance_task1_Look_mbox_buff_t task1_Look_mbox_buff(1);        // 任务实例

// 任务类 task1_Look_mbox_buff_t 的例程
__DEBUG//debug调试不优化便于调试
void task1_Look_mbox_buff_t::routine()
{
        // TODO: 在此编写例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写例程的内容
                for(int i = 0; i < 250; i++)
                {
                        Mbox.tryput_front(i);
                }
                sum = 0;
                GPIOA.DOUT().DOUT2 = 0;//LED1亮
                delay(LOOK_TICKS_PER_SEC / 5);
                GPIOA.DOUT().DOUT3(1)//LED2灭
                            .DOUT2(1);//LED1灭
                delay(LOOK_TICKS_PER_SEC / 5);
        }
}

instance_task2_Look_mbox_buff_t task2_Look_mbox_buff(2);        // 任务实例

// 任务类 task2_Look_mbox_buff_t 的例程
__DEBUG//debug调试不优化便于调试
void task2_Look_mbox_buff_t::routine()
{
        // TODO: 在此编写例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写例程的内容
                int msg;
                if (Mbox.get(msg))
                {
                        sum += msg;
                        if (sum == 0x7995)
                        {
                                GPIOA.DOUT().DOUT3 = 0;//LED2亮
                        }

                }
        }
}

使用特权

评论回复
5922
hotpower|  楼主 | 2011-12-3 01:38 | 只看该作者
mbox_buff.cpp
#include "Look_mbox_buff.h"
#include "utils/debug.h"
#include "numicro/sfr/gpio"

mbox_t<int, 250> Mbox;// 创建 int 型邮箱
int sum;

instance_task1_Look_mbox_buff_t task1_Look_mbox_buff(1);        // 任务实例

// 任务类 task1_Look_mbox_buff_t 的例程
__DEBUG//debug调试不优化便于调试
void task1_Look_mbox_buff_t::routine()
{
        // TODO: 在此编写例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写例程的内容
                for(int i = 0; i < 250; i++)
                {
                        Mbox.tryput_front(i);
                }
                sum = 0;
                GPIOA.DOUT().DOUT2 = 0;//LED1亮
                delay(LOOK_TICKS_PER_SEC / 5);
                GPIOA.DOUT().DOUT3(1)//LED2灭
                            .DOUT2(1);//LED1灭
                delay(LOOK_TICKS_PER_SEC / 5);
        }
}

instance_task2_Look_mbox_buff_t task2_Look_mbox_buff(2);        // 任务实例

// 任务类 task2_Look_mbox_buff_t 的例程
__DEBUG//debug调试不优化便于调试
void task2_Look_mbox_buff_t::routine()
{
        // TODO: 在此编写例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写例程的内容
                int msg;
                if (Mbox.get(msg))
                {
                        sum += msg;
                        if (sum == 0x7995)
                        {
                                GPIOA.DOUT().DOUT3 = 0;//LED2亮
                        }

                }
        }
}

使用特权

评论回复
5923
hotpower|  楼主 | 2011-12-3 01:39 | 只看该作者
cond.cpp
#include "Look_cond.h"
#include "utils/debug.h"
#include "numicro/sfr/gpio"

int Sum = 0;
flag_t Flag(0);
mutex_t Mutex;
cond_t Cond;

// eint_t 类提供了 INT0/INT1 的接口
// 当 INT0/INT1 发生时,对象将发送相应的 int 消息到 mbox。
class eint_t : public interrupt_t {
public:
        __INLINE eint_t();

protected:
        bool isr(int vector);
        void dsr(int vector, uintptr_t count);
};

// eint 构造函数
__DEBUG//debug调试不优化便于调试
__INLINE eint_t::eint_t()
{
        using namespace sfr::gpio;
        attach(EINT0_IRQn);//绑定外部中断0
        attach(EINT1_IRQn);//绑定外部中断1
        GPIOB.IEN(0).IF_EN15(1).IF_EN14(1);//开启Key1,Key2中断
        vector_t::enable(EINT0_IRQn);//使能外部中断0即Key1中断
        vector_t::enable(EINT1_IRQn);//使能外部中断1即Key2中断
}

// eint 中断服务例程
__DEBUG//debug调试不优化便于调试
bool eint_t::isr(int vector)
{
        using namespace sfr::gpio;
        GPIOB.ISRC = GPIOB.ISRC;                        // 清中断 flag
        return true;
}

// eint 中断滞后服务例程
__DEBUG//debug调试不优化便于调试
void eint_t::dsr(int vector, uintptr_t count)
{
        using namespace sfr::gpio;
        if (vector == EINT0_IRQn)//Key2中断
        {
                Flag.do_set_bits(2);//在中断中唤醒任务2
        }
        else if (vector == EINT1_IRQn)//Key1中断
        {
                Flag.do_set_bits(1);//在中断中唤醒任务1
        }
}

eint_t eint;                                                                        // 创建 eint 对象

instance_task1_Look_cond_t task1_Look_cond(1);        // 任务实例

// 任务类 task1_Look_cond_t 的例程
__DEBUG//debug调试不优化便于调试
void task1_Look_cond_t::routine()
{
        // TODO: 在此编写 task1_Look_cond_t 例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写 task1_Look_cond_t 例程的内容
                int flag = Flag.wait(1, flag_t::ANY_CONSUME);//阻塞等待Key1中断
                if (flag)
                {
                        GPIOA.DOUT().DOUT2 ^= 1;//LED1闪烁
                        Mutex.lock();
                        Sum++;
                        if (Sum < 3) Mutex.unlock();
                        else{
                                Mutex.unlock();
                                Cond.signal();

                        }
                }
        }
}

instance_task2_Look_cond_t task2_Look_cond(2);        // 任务实例

// 任务类 task1_Look_cond_t 的例程
__DEBUG//debug调试不优化便于调试
void task2_Look_cond_t::routine()
{
        // TODO: 在此编写 task2_Look_cond_t 例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写 task2_Look_cond_t 例程的内容
                int flag = Flag.wait(2, flag_t::ANY_CONSUME);//阻塞等待Key2中断
                if (flag)
                {
                        GPIOA.DOUT().DOUT3 ^= 1;//LED2闪烁
                        Sum++;
                        if (Sum < 3) Mutex.unlock();
                        else{
                                Mutex.unlock();
                                Cond.signal();

                        }
                }
        }
}

instance_task3_Look_cond_t task3_Look_cond(3);        // 任务实例

// 任务类 task3_Look_cond_t 的例程
__DEBUG//debug调试不优化便于调试
void task3_Look_cond_t::routine()
{
        // TODO: 在此编写 task3_Look_cond_t 例程的内容
        using namespace sfr::gpio;
        while (true) {
                // TODO: 在此编写 task3_Look_cond_t 例程的内容
                Mutex.lock();
                while (Sum < 3){//Key1或Key2按键合计次数为三次时激活
                        Cond.wait(Mutex);
                        Mutex.unlock();
                        Sum = 0;
                        GPIOA.DOUT().DOUT4(0).DOUT5(0);//LED3,LED4亮
                        delay(LOOK_TICKS_PER_SEC / 2);//延时亮0.5S
                        GPIOA.DOUT().DOUT4(1).DOUT5(1);//LED3,LED4灭
                        break;
                }
        }
}

使用特权

评论回复
5924
hotpower|  楼主 | 2011-12-3 02:21 | 只看该作者
迷糊

使用特权

评论回复
5925
hotpower|  楼主 | 2011-12-3 02:23 | 只看该作者
楼差1664

使用特权

评论回复
5926
hotpower|  楼主 | 2011-12-3 02:23 | 只看该作者
继续努力,俺要在此楼技术楼聊

使用特权

评论回复
5927
plc_avr| | 2011-12-3 06:29 | 只看该作者
盖楼......

使用特权

评论回复
5928
hotpower|  楼主 | 2011-12-3 07:21 | 只看该作者
起床

使用特权

评论回复
5929
hotpower|  楼主 | 2011-12-3 07:23 | 只看该作者
俺6点都起来了,到早市买条大鱼。

使用特权

评论回复
5930
Swallow_0322| | 2011-12-3 07:23 | 只看该作者
大叔开始测试LOOK,加油!:victory:

使用特权

评论回复
5931
Swallow_0322| | 2011-12-3 07:23 | 只看该作者
签到...

使用特权

评论回复
5932
hotpower|  楼主 | 2011-12-3 07:40 | 只看该作者
报到。

使用特权

评论回复
5933
hotpower|  楼主 | 2011-12-3 07:45 | 只看该作者
三心,俺开始测试了,look表现良好。
老师暴力的头文件非常给力。
实际俺可以做些其它cortexm的look测试。

使用特权

评论回复
5934
Ryanhsiung| | 2011-12-3 10:55 | 只看该作者
123

使用特权

评论回复
5935
Ryanhsiung| | 2011-12-3 10:56 | 只看该作者
456

使用特权

评论回复
5936
hotpower|  楼主 | 2011-12-3 11:55 | 只看该作者
晕,老套了,123,456

应该250

使用特权

评论回复
5937
51小刚| | 2011-12-3 15:52 | 只看该作者
盖楼!

使用特权

评论回复
5938
plc_avr| | 2011-12-3 15:59 | 只看该作者
盖楼....

使用特权

评论回复
5939
hotpower|  楼主 | 2011-12-3 17:06 | 只看该作者
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则