Code Search for Developers
 
 
  

tos_emstar.h from EmStar at Krugle


Show tos_emstar.h syntax highlighted

/* -*- Mode: C; c-basic-indent: 4; indent-tabs-mode: nil -*- */
/* ex: set tabstop=4 expandtab shiftwidth=4 softtabstop=4: */


#ifndef _TOS_EMSTAR_
#define _TOS_EMSTAR_

// LEDS defintions
#define RED		0x1
#define GREEN	0x2
#define YELLOW	0x3

#define OFF		0x0
#define ON		0x1

#ifndef bool
#define bool uint8_t
#endif


typedef struct _tos_state {
        long long tos_time;
	uint16_t current_node;
	uint8_t pad[2];
} TOS_state_t;

// function pointer struct. All function pointers that brigde the
// platform/library boundary should go here
typedef struct fp_list {
	// main() callbacks
	void (*start)(uint16_t moteID, uint8_t groupID);
	void (*stop)();

	// Berkeley Radio callbacks
	void (*RadioSendDone)(int8_t retval);
	void (*RadioReceive)(link_pkt_t *data, int16_t length, int8_t valid, int8_t ignore_group);

	// SMAC callbacks
	void (*SmacBroadcastDone)();
	void (*SmacFragDone)();
	void (*SmacUnicastDone)();
	void (*SmacReceive)(void *data);

	// SMAC LinkState callbacks
	void (*SmacNodeJoin)(uint16_t nodeAddr);
	void (*SmacNodeGone)(uint16_t nodeAddr);
	void (*SmacRxSyncPkt)(uint16_t fromAddr, uint8_t seqNo);
	void (*SmacRxBcastPkt)(uint16_t fromAddr, uint8_t seqNo);
	void (*SmacRxUcastPkt)(uint16_t fromAddr, uint8_t seqNo,
                        uint8_t numTx, uint8_t numRx);
	
	// Clock (timer0) callback
	void (*clockcb)();

	// EEPROM callbacks
	void (*Eeprom_readDone)(uint8_t *buffer, int8_t retcode);
	void (*Eeprom_writeDone)(uint8_t *buffer);

	// TimerHeap callbacks
	void (*timerheap_cb)();

    // ADC callbacks
    void (*AdcDataReady)(uint8_t port, uint16_t data);
    // AdcDataReady was used for both ADC and for temp/batt/humidity,
    // as a result, the second module to set the callback clobbered the previous cb
    void (*OnBoardDataReady)(uint8_t port, uint16_t data);

	// Extra callback, used to set the mote's TOS_LOCAL_ADDRESS
	void (*setID)(uint16_t moteID);
  
	// Emstar Comm callback
	void (*EmstarCommReceive)(uint8_t id, void *msg, int16_t length);

    // EmPdServer send callback
    int (*EmPdServerSend)(uint8_t id, void *msg, int16_t length);

    // EmLinkServer callbacks
    int (*EmLinkServerSend)(uint8_t id, link_pkt_t *msg, int16_t data_length);
    void (*EmLinkServerStatus)(uint8_t id, link_status_t *status);
    int (*EmLinkServerCommand)(uint8_t id, void *cmd_input); /* void* is parser_t* */
    void (*EmLinkServerUsage)(uint8_t id, void *fill);  /* void* is buf_t* */

	// EmStatusServer callbacks (all voids are buf_t's)
	void (*EmStatusServerPrintable)(uint8_t id, void *msg);
	void (*EmStatusServerBinary)(uint8_t id, void *msg);
    void (*EmStatusServerWrite)(uint8_t id, void *msg);

  // EmSocketServer callbacks
  //void (*EmSocketServerConnected)(uint8_t id);
  //void (*EmSocketServerDisconnected)(uint8_t id);
  void (*EmSocketServerDataReady)(uint8_t id, void *data, uint16_t length);

} fp_list_t;




// Functions implemented in platform/emstar and called from the library go
// here
// 
// TODO: Those defs should probably go inside the files

// startup
void start_mote(uint16_t moteID);
void stop_mote();

// Radio
void sendDone();
void pktReceived(void *data);

// Eeprom
void eeprom_read_done(uint8_t *buffer, int8_t retcode);
void eeprom_write_done(uint8_t *buffer);


// library functions go here

// main :)
int emtos_main(int argc, char *argv[], fp_list_t *fplist);

/* extended task interface with private data pointers */
void *emtos_get_task_data();
int emtos_post_task(void(*tp)(), void *private_data);

// random number generator
void emtos_init_rand();
uint16_t emtos_random();

// Clock (timer0)
void emtos_start_clock(long ticks, void (*ccb));

// Radio (berkeley)
int emtos_init_bradio_link(fp_list_t *fplist);
int emtos_send_bradio_packet(link_pkt_t *pkt, int16_t datalen);
int emtos_bradio_set_txmode(uint8_t power);
int emtos_bradio_set_listenmode(uint8_t power);
uint8_t emtos_bradio_get_txmode();
uint8_t emtos_bradio_get_listenmode();
void emtos_bradio_enable_readable();

// Radio (smac)	
int emtos_init_smac_link(fp_list_t *fplist);
int emtos_send_broadcast_smac_packet(void *data, uint8_t length);
int emtos_send_unicast_smac_packet(void *data, uint8_t length, 
		uint16_t toAddr, uint8_t numFrags);
int emtos_send_next_smac_frag(void *frag);
void emtos_smac_enable_readable();
void emtos_reset_smac();

// Radio (common)
int emtos_link_set_power(uint8_t power);
uint8_t emtos_link_get_power();

// Leds
void emtos_init_leds();
void emtos_set_led(uint8_t led, uint8_t state);

// EEPROM
void emtos_eeprom_init(fp_list_t *fplist);
int emtos_eeprom_read(uint16_t line, uint8_t *buffer);
int emtos_eeprom_write(uint16_t line, uint8_t *buffer);

// PAGE EEPROM
void emtos_pageeeprom_init(fp_list_t *fplist);
int emtos_pageeeprom_read(uint16_t pagenum, uint8_t *buffer);
int emtos_pageeeprom_write(uint16_t pagenum, uint8_t *buffer);


// TimerHeap
void emtos_init_timerheap(fp_list_t *fplist);
void emtos_set_timer(uint32_t interval);
uint32_t emtos_get_time();	// timer1 is 16-bit

// SysTime
uint32_t emtos_gettimeofday();

// Debug/Loglevel
void emtos_log(int log_level, long long mode, int node_num, const char *format);

/* dbg support for emtos */
void emtos_init_logger(int *argc, char **argv);

// EmstarComm
int emtos_comm_init(fp_list_t *fplist, uint8_t numClients);
int emtos_comm_pclient_init(uint8_t id, char *name);
int emtos_comm_pclient_send(uint8_t id, void *msg, int16_t length);

// EmPdServer
int emtos_pd_server_init(fp_list_t *fplist, uint8_t numClients);
int emtos_packet_device_init(uint8_t id, char *name);
int emtos_pd_server_receive(uint8_t id, void *msg, int16_t length);
int emtos_pd_server_unblock(uint8_t id);

// EmLinkServer
int emtos_link_server_init(fp_list_t *fplist, uint8_t numClients);
int emtos_link_device_init(uint8_t id, char *name, char *description, 
                           int mtu_adjust, int fixed_mtu);
int emtos_link_server_receive(uint8_t id, link_pkt_t *msg, int16_t data_length);
int emtos_lp_unblock(uint8_t id);

// EmStatusServer
int emtos_status_server_init(fp_list_t *fplist, uint8_t numClients);
int emtos_status_device_init(uint8_t id, char *name);
void emtos_status_device_notify(uint8_t id);

// EmSocketServer
int emtos_socket_server_init(fp_list_t *fplist, uint8_t numClients);
int emtos_socket_new(uint8_t id, int port, char *name);
int emtos_socket_kill(uint8_t id);
int emtos_socket_send(uint8_t id, void *data, uint16_t length);

// ADC
int emtos_adc_init(fp_list_t *fplist);
// type: distinguishes between ADC data and onboard sensors (otherwise
// ADC port 1 collides w/ BATTERY, port 1 w/ onboard temp, port 2 w/ onboard humidity
int emtos_adc_register_port(uint8_t port, uint8_t type, char *sensor_name, char *sensor_nick);
int emtos_adc_get_data(uint8_t port, uint8_t type);

void emtos_adc_defer_mapping(char *nick, char *sensor);
char *emtos_adc_nick_to_sensor(char *nick);
int emtos_adc_lookup_port_by_nick(char *sensor_nick);

// Location
void emtos_get_loc(float *x, float *y, float *z);


// Inter-component fucntions go here
//fp_list_t *get_fplist();

// initializer function for static variables
#ifdef PLATFORM_EMSTAR
static void __nesc_nido_initialise(int __nesc_mote);
#endif

#endif // TOS_EMSTAR




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  avr/
    pgmspace.h
  .gdbinit
  .platform
  ADCC.nc
  ADCM.nc
  AM.h
  BRadioM.nc
  ByteEEPROM_platform.h
  CC1000Control.nc
  CC1000ControlM.nc
  CC1000RadioIntM.nc
  EEPROM.h
  EEPROM.nc
  Emstar.nc
  HPLADCC.nc
  HPLClock.nc
  HPLConstants.h
  HPLPotC.nc
  HPLPowerManagementM.nc
  HPLUARTC.nc
  HPLUARTM.nc
  InjectMsg.nc
  LedsC.nc
  MacControl.nc
  Main.nc
  PageEEPROM.h
  PageEEPROM.nc
  PageEEPROMC.nc
  PageEEPROMM.nc
  PageEEPROMShare.nc
  PhyRadioMsg.h
  README
  RadioCRCPacket.nc
  SysTimeC.nc
  SysTimeM.nc
  TimerC.nc
  TimerHeap.nc
  Voltage.h
  VoltageM.nc
  avr_eeprom.h
  dbg.c
  dbg.h
  emstar.target
  fplist.c
  hardware.c
  hardware.h
  hardware.nido.h
  hpl.c
  install.sh
  sched.c
  tos_emstar.h