5884|6

6117

帖子

4

TA的资源

版主

楼主
 

【KW41z】一起来玩 thread +用coap点灯 [复制链接]

本帖最后由 damiaa 于 2017-7-19 21:23 编辑

一起来玩 thread
刚开始,所以只会点皮毛哦。哈哈。
1,看看这图

还有这图

基本上就清楚了。
都是基于802.15.4,但支持6lowpan,ipv6,udp还有应用层可以跑socket,coap等。


2,如果有兴趣,可以看看Kinetis Thread Stack Shell Interface User's Guide这个文档,这个在KW41Z的开发包的文档里有。这个SHELL可以帮你快速
了解 。
3,准备putty和两块板子。都烧写router_eligible_device的固件。用IAR什么的都可以烧。
4,插上两块板子,看到两个串口。用
putty连上他们 (选串口连接,波特率115200).
5,一个敲入thr create,另一个敲入thr join成功了会告诉你。这个时候thread网络就创建起来并且连网了。
6,两个串口里敲敲
     ifconfig
     thr get channel     thr get panid
     thr get neighbors

来关心关心网络配置,通道,PANID和邻居。看看他们的 地址,好像高位都一样。就低位不一样

7,coap点灯试验
在一个板子的串口敲入:
coap CON POST  fd57:ba6:36b4:b6a8::ff:fe00:400 /led on 打开另一个板子的灯LED4

coap CON POST  fd57:ba6:36b4:b6a8::ff:fe00:400 /led off 关闭另一个板子的灯LED4

fd57:ba6:36b4:b6a8::ff:fe00:400是另一个板子的Mesh local address (ML16)地址。

反之,从另一个板子也可以同样操作。另一个板子的地址不一样fd57:ba6:36b4:b6a8::ff:fe00:0 !!!


shell的有些功能不能用,比如echo 是因为没开启这个功能。在程序的app_thread_config.h中有相关的配置选择,选TRUE


下次继续。哈哈。


此内容由EEWORLD论坛网友damiaa原创,如需转载或用于商业用途需征得作者同意并注明出处










此帖出自NXP MCU论坛

最新回复

强大的大米哥,coap看起来很好玩啊  详情 回复 发表于 2017-7-20 09:22
点赞(1) 关注(1)
 

回复
举报

1297

帖子

2

TA的资源

纯净的硅(中级)

推荐
 
强大的大米哥,coap看起来很好玩啊
此帖出自NXP MCU论坛

点评

谢谢,搞不懂,所以写一下。也许就懂点了。  详情 回复 发表于 2017-7-24 11:32
 
 
 

回复

6117

帖子

4

TA的资源

版主

沙发
 
本帖最后由 damiaa 于 2017-7-19 21:42 编辑

读码 读码 读码....
图一 总体:
图二:板子硬件相关代码文件


图三:基本设备驱动

图四:框架:


图五:Freertos代码
图六:ieee_802.15.4
图七:Nwk_IP
图八:Source


此帖出自NXP MCU论坛
 
 
 

回复

6117

帖子

4

TA的资源

版主

板凳
 
本帖最后由 damiaa 于 2017-7-19 21:54 编辑

读码 读码 读码....
Board:
Board.h Board.c 板子各种的初始化
Clock_config.h Clock_config.c基本时钟配置,先路过。
Gpio.h Gpio.c GPIO的定义 比如SWITCH,LEDS 要修改按键和LED要注意这里
gpioInputPinConfig_t switchPins[] = {
    {
        .gpioPort = gpioPort_C_c,
        .gpioPin = 5,
        .pullSelect = pinPull_Up_c,
        .interruptSelect = pinInt_FallingEdge_c
    },
    {
        .gpioPort = gpioPort_C_c,
        .gpioPin = 4,
        .pullSelect = pinPull_Up_c,
        .interruptSelect = pinInt_FallingEdge_c
    }
};

/* Declare Output GPIO pins */
gpioOutputPinConfig_t ledPins[] = {
    {
        .gpioPort = gpioPort_B_c,
        .gpioPin = 0,
        .outputLogic = 1,
        .slewRate = pinSlewRate_Slow_c,
        .driveStrength = pinDriveStrength_Low_c
    },
    {
        .gpioPort = gpioPort_C_c,
        .gpioPin = 1,
        .outputLogic = 1,
        .slewRate = pinSlewRate_Slow_c,
        .driveStrength = pinDriveStrength_Low_c
    },
    {
        .gpioPort = gpioPort_A_c,
        .gpioPin = 19,
        .outputLogic = 1,
        .slewRate = pinSlewRate_Slow_c,
        .driveStrength = pinDriveStrength_Low_c
    },
    {
        .gpioPort = gpioPort_A_c,
        .gpioPin = 18,
        .outputLogic = 1,
        .slewRate = pinSlewRate_Slow_c,
        .driveStrength = pinDriveStrength_Low_c
    },
    {
        .gpioPort = gpioPort_C_c,
        .gpioPin = 18,
        .outputLogic = 1,
        .slewRate = pinSlewRate_Slow_c,
        .driveStrength = pinDriveStrength_High_c
    }
};   
当然也要注意下面的文件的时钟和IO口方向配置
Pin_mux.h Pin_mux.c 两文件初始化板子的PIN,BUTTON,LED,RGB,SPI,IC,UART的基本定义,如IO口的时钟允许和方向,PWM配置时钟和IO口,SPI,I2C,UART,配置时钟和IO口

drivers是所有驱动的集中,就是一些函数操作具体的CPU的硬件。具体使用时可以看看。
Framework框架包括各种操作 比如LED的具体操作,在LED。C,GPIO的具体操作在GPIO ,Keyboard的具体操作,DCDC,FLASH,存储保存NVM,SHELL实现等等。不过这里的shell.cnwk_ip中的shell_ip.c什么关系呢?后面细细理解等等。Source:
config.h:thread的基本配置:比如,要不要shell,能不能创建网络,打不打开thread协议栈,要不要coap观察 服务
freertosconfig.h
route_eligible_device_app.h
route_eligible_device_app..c
此帖出自NXP MCU论坛
 
 
 

回复

6117

帖子

4

TA的资源

版主

5
 
本帖最后由 damiaa 于 2017-7-24 11:52 编辑


l
描述抽象层的文件fs_os_abstraction_free_rtos.c文件中:
说明:操作系统抽象
使用RTOS服务的框架和其他连接软件模块从不直接使用RTOS API。
相反,它们使用操作系统抽象暴露的API,
确保跨多个操作系统的可移植性。OS抽象层为RTOS服务和裸机环境提供了共同的任务创建和控制服务方法。!!!!套一层啊。!!!

In the OS Abstraction layer, the task named main_task() is used as the starting point.
The user must implement a function with the prototype extern void main_task(void *) and treat it like a task. The OS Abstraction implementation declares this function external.
在操作系统抽象层、任务main_task()作为出发点。用户必须与原型extern void main_task实现一个函数(void *),把它当作一个任务。操作系统抽象实现对外声明这个函数。

OSA_TASK_DEFINE(startup_task, gMainThreadPriority_c, 1, gMainThreadStackSize_c, 0)  ;
nt main (void)
{
    /* Initialize MCU clock */
    hardware_init();
    OSA_TaskCreate(OSA_TASK(startup_task), NULL);
    vTaskStartScheduler();

    return 0;
}
OSA_TASK_DEFINE 宏(第一个参数是任务名)和函数 OSA_TaskCreate()申明并创建任务
程序开始初始化硬件,然后就转入freertos的启动任务去了。
hardware_init();初始化硬件在board.c中 关于硬件的时钟,DCDC等问题初始化。
fsl_os_abstraction_free_rtos.c文件中:启动任务
     fsl_os_abstraction_free_rtos.c FREERTOS抽象 与 fsl_os_abstraction_bm.c裸机抽象      fsl_os_abstraction_ucosii.c USOSII抽象

void startup_task(void* argument)
{
    main_task(argument);
    while(1);
}
启动任务中调用app_init.c(这个在nwk==>app==>common) main_task函数:初始化,然后调用WHILE循环处理所有事物。
void main_task(uint32_t param)
{
    static uint8_t mainInitialized = FALSE;

    if (!mainInitialized)
    {
        mainInitialized = TRUE;
#if WDOG_ENABLE
        /* Init watchdog module */
        APP_WDOG_Init();
#endif
        /* Init memory blocks manager */
        MEM_Init();

        SecLib_Init();
        /* Init  timers module */
        TMR_Init();
        TMR_TimeStampInit();
        /* Init Led module */
        LED_Init();
        /* Non volatile memory module init */
        if (gNVM_OK_c != NvModuleInit())
        {
            panic(0, (uint32_t) NvModuleInit, 0, 0);
        }
        /* Init phy module */
        Phy_Init();
        /* RNG must be initialized after the PHY is Initialized */
        RNG_Init();
        /* Init mac module */
        MAC_Init();
        /* Initialize Thread Module */
        THR_Init();
#if gLpmIncluded_d
        PWR_Init();
#endif
        /* Initialize Keyboard (Switches) Module */
        KBD_Init(KBD_Callback);
        SerialManager_Init();

#if THREAD_USE_SHELL
        SHELLComm_Init(&appThreadMsgQueue);
#endif

#if THREAD_USE_THCI
        FSCI_Init((void*)&mFsciSerials);
#endif

#if THREAD_USE_THCI
        APP_FsciInterface(&appThreadMsgQueue);
#endif        
        
#if gHybridApp_d
        /* Initialize ble and peripheral drivers specific to the ble application */
        BleApp_Init();
#endif

        /* Init demo application */
        APP_Init();
    }

    /* Main Application Loop (idle state) */
    while (1)
    {
#if WDOG_ENABLE
        /* Restart the watchdog so it doesn't reset */
        APP_WDOG_Refresh();
#endif
#if NVM_NG_ENABLED
        /* Process NV Storage save-on-idle, save-on-count and save-on-interval requests */
        NvIdle();
#endif
        /* Debug Checks, Leader LED restore check */
        DBG_Check();
#if gHybridApp_d
        /* Ble app */
        BleApp_Thread(0);
#endif
        /* Application handler */
        APP_Handler();//看看这个函数,原来在route_eligible_device_app.c中!!!
        /* Treat low power */
#if gLpmIncluded_d
        APP_HandleLowPowerOnIdle();
#endif
        /* Reset MCU */
        APP_HandleMcuResetOnIdle();
        /* For BareMetal break the while(1) after 1 run */
        if (gUseRtos_c == 0)
        {
            break;
        }
也就是说程序先调用启动任务,初始化一些东西,然后就调用while 循环,里面最主要APP_Handler()。开始thread事件处理
route_eligible_device_app.c:
void APP_Handler
(
    void
)
{
    bool_t handleMsg = TRUE;
    while(handleMsg == TRUE)
    {
        handleMsg =NWKU_MsgHandler(&appThreadMsgQueue);
        // Network Utils module function used to dequeueand handle a task message.
       //pMsgQueue  Pointer to structure holding message queueand task id to receive message
        /* For BareMetal break the while(1)after 1 run */
        if(!gUseRtos_c &&MSG_Pending(&appThreadMsgQueue.msgQueue))// MSG_Pending检查thread消息对列
        {
            (void)OSA_EventSet(appThreadMsgQueue.taskEventId,NWKU_GENERIC_MSG_EVENT);
            //设置事件的标志Sets the specified signal flags of an event object.
            break;
        }
    }
}








此帖出自NXP MCU论坛
 
 
 

回复

6117

帖子

4

TA的资源

版主

6
 
本帖最后由 damiaa 于 2017-7-24 11:37 编辑

MKW41Z_ConnSw_1.02目录:
boards
  frdmkw41z
    demo_apps
        adc16_low_power
        bubble
        dac_adc
        ecompass
        hello_world
        power_manager
        power_mode_switch
        rtc_func
    driver_examples
        ...
    rtos_examples
        ...
    wireless_examples
        bluetooth
        common
        framework
        genfsk
        hybrid
        ieee_802_15_4
        smac
        thread
            end_device
            end_device_ota_client
            host_controlled_device
            host_controlled_device_ota_server
            low_power_end_device
            rote_eligible_device
            router_eligible_device_ota_client         
  usbkw41z_k22f
  usbkw41z)kw41z
CMSIS
devices
    MKW41Z4
        drivers
            fsl_adc16.c
            fsl_adc16.h
            fsl_XXX.c
            fsl_XXX.h           
docs
    Kinetis SDK v2.0.0 API Reference Manual
    rtos
    usb
    wireless
    Getting Started with Kinetis SDK (KSDK) v.2.0.pdf
    Kinetis SDK v2.0.0 Release Notes Supporting the FRDM-KW41Z Freedom Development Platform

   
middleware
    dma_manager_2.0.0
    fatfs_0.11a
    sdmmc_2.0.0
    usb_1.0.0
    wireless
        blue_tooth1.2.2
        framework_5.3.2
            Common
            DCDC
            DSP
            examples
            Flash
            FSCI
            FunctionLib
            GPIO
            Keyboard
            LED
            Lists
            LowPower
            MemManager
            Messaging
            ModuleInfo
            MWSCoexistence
            NVM
            OSAbstraction
                interface
                source
                    fsl_os_abstraction_bm.c
                    fsl_os_abstraction_free_rtos.c
                    fsl_os_abstraction_ucosii.c
            OtaSupport
            Panic
            Reset
            RNG
            SecLib
            SerialManager
            Shell
            TimersManager
            XCVR

        genfsk_1.0.2
        ieee_802_15_4_5.3.2
       nwk_ip_1.2.0
            base
                http
                interface
                ip_media_if
                shell
                stack_globals
                thci
                thread_config
                utils
            core
                interface
                lib
            examples
                examples
                    border_router
                    common
                    end_device
                    end_device_ota_client
                    host_controlled_device
                    host_controlled_device_ota_server
                    hybrid
                    low_power_end_device
                   router_eligible_device
                        config
                            config.h
                        src
                            router_eligible_device_app.c
                            router_eligible_device_app.h

                    router_eligible_device_ota_client
                    test_harness_app
        smac_3.3.2      
rtos
tools
此帖出自NXP MCU论坛
 
 
 

回复

6117

帖子

4

TA的资源

版主

7
 
johnrey 发表于 2017-7-20 09:22
强大的大米哥,coap看起来很好玩啊

谢谢,搞不懂,所以写一下。也许就懂点了。
此帖出自NXP MCU论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表