查看: 877|回复: 0

[BCM943364WCD1]玩转WICED“建造自己的品牌”

[复制链接]
  • TA的每日心情

    2016-12-7 16:21
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2016-12-8 08:45:47 | 显示全部楼层 |阅读模式
    分享到:
    上一篇经验记录了如何跑一个DEMO程序。本文分享如何在WICED中增加自己的应用程序。
    一、目标
        实现的目标是:
              1、在APPS目录下增加自己的应用程序路径
              2、基于SCAN程序扩展,每按一次SW2,扫描一次而不是像DEMO程序里那样不停的扫描。


    二、动手操作啦
           首先在apps下新建文件夹,如下图所示:
          

    将demo程序中的scan.c和scan.mk复制到新建目录下,重要的来啦:将scan.mk重命名为icylinker.mk:

    然后将编译TARGET整理一下,多余的去掉,留下自己需要的:

    不解释,编译一下运行,效果和demo程序一样,下面继续开始写代码,完成我们自己定的功能。
    三、编程开始啦
          要用到按键SW2,是PA1,也可以看platform.h:

    流程大概如下:
      创建一个线程用于按键检测——》按键按下发送信号量——》主线程里等待信号量——》执行扫描;
    上代码:
    #include <stdlib.h>#include "wiced.h"#include "platform.h"/****************************************************** *                      Macros ******************************************************//****************************************************** *                    Constants ******************************************************/#define DELAY_BETWEEN_SCANS       (5000)/****************************************************** *                   Enumerations ******************************************************//****************************************************** *                 Type Definitions ******************************************************//****************************************************** *                    Structures ******************************************************//****************************************************** *               Static Function Declarations ******************************************************/wiced_result_t scan_result_handler( wiced_scan_handler_result_t* malloced_scan_result );/****************************************************** *               Variable Definitions ******************************************************/static int record_count;static wiced_time_t scan_start_time;wiced_semaphore_t        stIcylinkerButtonSem;wiced_thread_t                stIcylinkerButtonThread;#define BUTTON_PRIORITY                (9)#define BUTTON_STACK_SIZE        (1*1024)void vButtonFunction(void *);/****************************************************** *               Function Definitions ******************************************************/void application_start( ){    wiced_init( );    wiced_gpio_init(WICED_GPIO_2, INPUT_PULL_UP);    /*     * wiced_result_t wiced_gpio_init( wiced_gpio_t gpio, wiced_gpio_config_t configuration );     * wiced_result_t wiced_rtos_create_thread( wiced_thread_t* thread, uint8_t priority, const char* name, wiced_thread_function_t function, uint32_t stack_size, void* arg )     * */    wiced_rtos_create_thread(&stIcylinkerButtonThread, BUTTON_PRIORITY, "BUTTON", vButtonFunction, BUTTON_STACK_SIZE, NULL);    wiced_rtos_init_semaphore(&stIcylinkerButtonSem);    while(1)    {            WPRINT_APP_INFO(("<a href="https://www.eeboard.com/bbs/forum.php\n" ))"="">https://www.eeboard.com/bbs/forum.php\n"))</a>;            WPRINT_APP_INFO(("user: icylinker\n"));            WPRINT_APP_INFO(("board: BCM943364WCD1\n"));            WPRINT_APP_INFO( ("----------------------------------------------------------------------------------------------\n" ) );            wiced_rtos_get_semaphore(&stIcylinkerButtonSem, NEVER_TIMEOUT);        record_count = 0;        WPRINT_APP_INFO( ( "Waiting for scan results...\n" ) );        WPRINT_APP_INFO( ("  # Type  BSSID             RSSI  Rate Chan  Security         SSID\n" ) );        WPRINT_APP_INFO( ("----------------------------------------------------------------------------------------------\n" ) );        wiced_time_get_time(&scan_start_time);        wiced_wifi_scan_networks(scan_result_handler, NULL );        wiced_rtos_delay_milliseconds(DELAY_BETWEEN_SCANS);    }}/* * Callback function to handle scan results */wiced_result_t scan_result_handler( wiced_scan_handler_result_t* malloced_scan_result ){    if ( malloced_scan_result != NULL )    {        malloc_transfer_to_curr_thread( malloced_scan_result );        if ( malloced_scan_result->status == WICED_SCAN_INCOMPLETE )        {            wiced_scan_result_t* record = &malloced_scan_result->ap_details;            WPRINT_APP_INFO( ( "%3d ", record_count ) );            print_scan_result(record);            ++record_count;        }        else        {            wiced_time_t scan_end_time;            wiced_time_get_time(&scan_end_time);            WPRINT_APP_INFO( ("\nScan complete in %lu milliseconds\n", (unsigned long )(scan_end_time - scan_start_time) ) );        }        free( malloced_scan_result );        malloced_scan_result = NULL;    }    return WICED_SUCCESS;}void vButtonFunction(void *arg){        uint8_t button_status = 0;        while(1)        {                switch(button_status)                {                case 0:                                if(!wiced_gpio_input_get(WICED_GPIO_2))                                {                                        button_status = 1;                                }                                break;                case 1:                                wiced_rtos_delay_milliseconds(100);                                button_status = 2;                                break;                case 2:                                if(!wiced_gpio_input_get(WICED_GPIO_2))                                {                                        button_status = 3;                                }                                else                                        button_status = 0;                                break;                case 3:                                wiced_rtos_set_semaphore(&stIcylinkerButtonSem);                                button_status = 4;                                break;                case 4:                                if(wiced_gpio_input_get(WICED_GPIO_2))                                {                                        button_status = 0;                                }                                break;                default: break;                }        }}</stdlib.h>四、运行结果
      

    喜欢的点个赞!!!!
    回复

    使用道具 举报

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

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 13:55 , Processed in 0.127740 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.