分类
设计开发

无线嵌入平台编程模式

无线嵌入平台(wbed)是TinyWSN无线模块的一种使用方式,用户程序(usr)和系统程序(sys)运行在同一处理器上,用户程序可以独立开发,动态下载,类似unix系统中多进程(multi-process)的模式,下面是wbed sdk的源码链接:
https://gitee.com/tinywsn/fw-stm32l1-wbed-usr
支持GCC和IAR两种开发环境,使用这种模式可以带来很多好处

  • 共有同一硬件平台,系统更加精简,成本可以更低
  • 用户程序和系统程序之间消息通信模式,更加简单和可靠
  • 可以同步高效地工作,包括接收,发送,睡眠,唤醒等等节拍,系统功耗可以更低
  • wbed sdk可以提供底层驱动以及各类常见传感器驱动

编程需注意的事项:

  • 可使用的内存空间通过参数ctx传入,避免使用全局变量
  • 使用可重入的库函数,对于STM32而言,使用LL_DRV,对于glibc,使用其中可重入版本 xxxx_r
  • 使用异步消息模式,避免毫秒以上的轮询等待操作

具体实现可以参考下面的例程

接口消息定义和说明
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-intf/

例1-简单的上下行数据的收发
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex1/

例2-单总线DHT1X温湿度传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex2/

例3-模拟输出的光敏电阻传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex3/

例4-I2C总线AM2320温湿度传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex4/

例5-单总线DS18B20温度传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex5/

例6-I2C总线BH1750光照传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex6/

例7-I2C总线SHT2X温湿度传感器
http://www.tinywsn.net/wordpress/index.php/docs/manual/node/node-wbed/node-wbed-ex7/

更多传感器支持增加中…

分类
设计开发

TinyGW软件的接口定义

TinyGW是网关软件的一个简易实现,主要完成TinyWSN和MQTT之间双向数据转换,节点数据采集的传感器数据,通过网关TinyGW发送到MQTT服务器,各种MQTT的客户端(PC端,Android端,等等)接受传感器数据,同时还可以发起下行的控制。为了便于客户端展示和输入,确定数据的格式为文本,同时由于TinyWSN空中数据帧有效负载比较小(41字节),命令和数据格式尽可能短。下图是TinyGW在MQTT注册的接口, xxxx是在TinyGW在cfg.jsn中配置的标识。

类型topic说明
publictinygw_xxxx/node_tx节点发布数据
subscribetinygw_xxxx/node_rx节点接受数据
publictinygw_xxxx/gate_tx网关发布数据
subscribetinygw_xxxx/gate_rx网关接受数据

node_tx格式

测量告警:addr/type, data [,data]
type -> val | ala
data -> id, digits [scale unit]
id -> t | rh | irf | irb | vib | snd | smk | heat | rain | ang | lgt
scale -> f | p | n | u | m | k | M
unit-> C | % | V | A

命令响应:addr/rsp, obj, val
obj -> led | wdt

node_rx格式

设置查询:addr/cmd, obj [,val] [/flag]
cmd -> set | qry
obj -> led | wdt
flag -> b | f

gate_tx格式

设置查询:cmd, obj [,val]
cmd -> dsc
obj -> wsn

gate_tx格式

命令响应:rsp, obj ,val
obj -> wsn
val -> init

通知消息:urc ,obj ,val
obj -> wsn
val -> done

网关软件TinyGW的功能具体描述:
http://www.tinywsn.net/wordpress/index.php/docs/manual/gateway/gateway-tinygw/

分类
设计开发

一种CRC代码生成工具

在数据通讯领域,为了保证数据的正确,就不得不采用检错的手段,CRC是最常见的一种,它的有长度8位,16位,32位的各种生成多项式,输入和输出还可能翻转,可以直接bit操作或表驱动进行编解码,手工编写编解码程序不但繁琐,而且容易出错。
pycrc是一种基于python的CRC嵌入C代码生成器,它下载链接
https://pycrc.org/, 它可以直接输出符合C89, ANSI, C99的C代码,它是一个命令行工具,下面是它的一些常见选项

选项说明
--width=NUMuse NUM bits in the Polynomial
--poly=HEXuse HEX as Polynomial
-reflect-in=BOOLreflect the octets in the input message
xor-in=HEXuse HEX as initial value
--reflect-out=BOOLreflect the resulting checksum before applying the XorOut
--xor-out=HEXxor the final CRC value with HEX
--algorithm=ALGOchoose an algorithm from {bit-by-bit, bbb, bit-by-bit-fast, bbf, table-driven, tbl, all}

生成接口

typedef uint16_t crc_t;

typedef uint16_t crc_t;

crc_t crc_init( void);

crc_t crc_update( crc_t crc,
const unsigned char *data,
size_t data_len);

crc_t crc_finalize( crc_t crc);

使用示例

#include “pycrc_generated_crc.h”
#include <stdio.h>

int main(void)
{

static const unsigned char str1[] = "1234";
static const unsigned char str2[] = "56789";
crc_t crc;

crc = crc_init();
crc = crc_update(crc, str1, sizeof(str1) - 1);
crc = crc_update(crc, str2, sizeof(str2) - 1);
/* more calls to crc_update... */
crc = crc_finalize(crc);

printf("0x%lx\n", (long)crc);
return 0;

}

在线CRC计算器

https://crccalc.com/

分类
设计开发

iMX6UL的Boot模式

拨码开关

配置说明

拨码示例

NAND flash

In case the NAND memory is the boot devices, this implies that the boot partition must be organized in order fulfill the bootrom requirements. Specifically, it contains:

  • A 1MB area (named Flash Control Block, FCB) which, in turn, includes
    • A data structure called NAND Control Block (NCB)
    • Three addresses which indicate where are located
      • The Discovered Bad Block Table (DBBT) which is the data structure used to manage the bad blocks of the NAND flash
      • The first copy of the firmware to load
      • The second (redundant) copy of the firmware to load
  • The DBBT
  • The first copy of the firmware
  • The second copy of the firmware.

u-boot对于Kernel和DTB区域中的坏块进行管理,rootfs中的坏块由UBIFS文件系统进行处理。

分类
设计开发

一种交互式BOM工具

在开发过程中,手工焊接/贴片是一件繁琐的工作,KiCAD的一个插件interactivehtmlbom,可以提供帮助,它可以生成交互式的BOM表,物料可以按标号或按值进行归类,在浏览物料过程可以直接定位在PCB板中的位置,它的代码链接
https://github.com/openscopeproject/InteractiveHtmlBom/

而且它还支持EasyEDA, Eagle and Fusion360。并且KiCAD还可以直接导入Eagle的工程,然后进行生成BOM。