TinyOS大家不要理解成有thread模式;现在主流的应用基本都不需要thread,实际上也确实用不着;TinyOS的cthread,有些厂家也给出了代码,但是始终不温不火;因为对于应用这些根本用不上;
编程应该越简单越好,技巧用得越多带来的BUG可能越多,也越难让大家都读懂;
我们的分析是Contiki是在编译的时候给了process结构体初值,对于大家的实际应用可否使用动态的分配来实现呢;当然动态的分配并不是C的malloc和free;而是类似6lowpan的先弄一个静态数组,然后自己编写ip_malloc/ip_free;当然Contiki也有内存操作部分;TinyOS有Poll;quene;fragpoll等
SENSORS_SENSOR(button_select_sensor, BUTTON_SENSOR, NULL, config_select, NULL);
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, NULL, config_left, NULL);
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, NULL, config_right, NULL);
SENSORS_SENSOR(button_up_sensor, BUTTON_SENSOR, NULL, config_up, NULL);
SENSORS_SENSOR(button_down_sensor, BUTTON_SENSOR, NULL, config_down, NULL);
SENSORS(&button_select_sensor, &button_left_sensor, &button_right_sensor,
&button_up_sensor, &button_down_sensor, &als_sensor,
&cc2538_temp_sensor, &vdd3_sensor);
#ifndef SENSORS_H_
#define SENSORS_H_
#include "contiki.h"
/* some constants for the configure API */
#define SENSORS_HW_INIT 128 /* internal - used only for initialization */
#define SENSORS_ACTIVE 129 /* ACTIVE => 0 -> turn off, 1 -> turn on */
#define SENSORS_READY 130 /* read only */
#define SENSORS_ACTIVATE(sensor) (sensor).configure(SENSORS_ACTIVE, 1)
#define SENSORS_DEACTIVATE(sensor) (sensor).configure(SENSORS_ACTIVE, 0)
#define SENSORS_SENSOR(name, type, value, configure, status) \
const struct sensors_sensor name = { type, value, configure, status }
#define SENSORS_NUM (sizeof(sensors) / sizeof(struct sensors_sensor *))
#define SENSORS(...) \
const struct sensors_sensor *sensors[] = {__VA_ARGS__, NULL}; \
unsigned char sensors_flags[SENSORS_NUM]
struct sensors_sensor {
char * type;
int (* value) (int type);
int (* configure) (int type, int value);
int (* status) (int type);
};
const struct sensors_sensor *sensors_find(const char *type);
const struct sensors_sensor *sensors_next(const struct sensors_sensor *s);
const struct sensors_sensor *sensors_first(void);
void sensors_changed(const struct sensors_sensor *s);
extern process_event_t sensors_event;
PROCESS_NAME(sensors_process);
#endif /* SENSORS_H_ */
发现分析方法和PROCESS那些并没有什么不同,慢慢也清楚了Contiki作者的编程风格;至于core/lib/sensor.c,我就完全不去分析了;
如果让我去写传感器的处理,我才懒得这样去写;只是Contiki已经出现的这个宏定义,咱们也可以理解是他的关键字;
看看而已;路过路过...看到sensor_sensor不禁想起了超级爱听的歌:"斑马斑马,你来自南方的红色啊...."