[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/imote2/tos/lib/I2CBusSequence
I2CBusSequence.h, NONE, 1.1 I2CBusSequence.nc, NONE,
1.1 I2CBusSequenceC.nc, NONE, 1.1 I2CBusSequenceM.nc, NONE, 1.1
Lama Nachman
lnachman at users.sourceforge.net
Sun Mar 4 22:54:24 PST 2007
Update of /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/lib/I2CBusSequence
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18798/I2CBusSequence
Added Files:
I2CBusSequence.h I2CBusSequence.nc I2CBusSequenceC.nc
I2CBusSequenceM.nc
Log Message:
Pushed out new tree
--- NEW FILE: I2CBusSequence.h ---
/*
*I2C Bus Sequence definitions
*
*
*@authors Lama Nachman, Robbie Adler
*
*/
#ifndef __I2CBUSSEQUENCE_H__
#define __I2CBUSSEQUENCE_H__
enum {
I2C_OP_WRITE=0,
I2C_OP_READ=1
};
enum {
I2C_START=0,
I2C_END=1,
I2C_READ=2,
I2C_WRITE=3
};
typedef struct i2c_op_t {
uint8_t op;
uint8_t param;
uint8_t res;
} i2c_op_t;
#endif // __I2CBUSSEQUENCE_H__
--- NEW FILE: I2CBusSequence.nc ---
/*
*I2C Bus Sequence interface
*
*
*@authors Robbie Adler, Lama Nachman
*
*/
includes I2CBusSequence;
interface I2CBusSequence{
/*
* execute a sequence of I2C commands
*
* @return FAIL if bus module is unable to accept an additional sequence of commands to be processed (it is implementation defined how many command sequences the underlying module may accept
* returns SUCCESS otherwise.
*
*
*/
command result_t runI2CBusSequence(i2c_op_t *pOps, uint8_t numOps);
/*
* event that indicates that a previos sequence has been executed. The succes parameter indicates whether the sequ
* was succesfully exectued
*
*
* @return void
*
*/
event void runI2CBusSequenceDone(i2c_op_t *pOpsExecuted, uint8_t numOpsExecuted, result_t success);
}
--- NEW FILE: I2CBusSequenceC.nc ---
/*
*I2C Bus Sequence Module StateMachine
*
*
*@authors Lama Nachman, Robbie Adler
*
*/
configuration I2CBusSequenceC {
provides {
interface I2CBusSequence;
interface StdControl;
}
}
implementation {
components PXA27XI2CM as I2CM,
I2CBusSequenceM as I2CBus;
I2CBusSequence = I2CBus;
StdControl = I2CBus;
I2CBus.I2CControl -> I2CM;
I2CBus.I2C -> I2CM;
}
--- NEW FILE: I2CBusSequenceM.nc ---
/*
*I2C Bus Sequence Module StateMachine
*
*
*@authors Lama Nachman, Robbie Adler
*
*/
includes trace;
includes I2CBusSequence;
module I2CBusSequenceM {
provides {
interface I2CBusSequence;
interface StdControl;
}
uses {
interface StdControl as I2CControl;
interface I2C;
}
}
implementation {
i2c_op_t *pCurrentOps = NULL;
uint8_t num_ops;
uint8_t current_op;
bool gbInit = FALSE;
bool gbStart = FALSE;
/**
* Initialize the component.
*
* @return Always returns <code>SUCCESS</code>
**/
command result_t StdControl.init() {
call I2CControl.init();
num_ops = 0;
current_op = 0;
gbInit = TRUE;
return SUCCESS;
}
command result_t StdControl.start() {
gbStart = TRUE;
return call I2CControl.start();
}
command result_t StdControl.stop() {
return call I2CControl.stop();
}
task void processNextCmd() {
if (num_ops == 0) {
// empty queue
return;
}
if (current_op > (num_ops - 1)) { // changed gte to strictly greater so that the last op is performed
// finished last op
signal I2CBusSequence.runI2CBusSequenceDone(pCurrentOps, current_op, SUCCESS);
pCurrentOps = NULL;
num_ops = 0;
current_op = 0;
return;
}
// process next command
switch (pCurrentOps[current_op].op) {
case I2C_START:
call I2C.sendStart();
break;
case I2C_END:
call I2C.sendEnd();
break;
case I2C_READ:
call I2C.read(pCurrentOps[current_op].param);
break;
case I2C_WRITE:
call I2C.write(pCurrentOps[current_op].param);
break;
}
}
command result_t I2CBusSequence.runI2CBusSequence(i2c_op_t *pOps, uint8_t numOps){
if(gbInit == FALSE){
call StdControl.init();
}
if(gbStart == FALSE){
call StdControl.start();
}
if(pCurrentOps == NULL){
pCurrentOps = pOps;
current_op = 0;
num_ops = numOps;
post processNextCmd();
return SUCCESS;
}
else{
return FAIL;
}
}
/*
* I2C interface events
*/
event result_t I2C.sendStartDone() {
current_op++;
post processNextCmd();
return SUCCESS;
}
event result_t I2C.sendEndDone() {
current_op++;
post processNextCmd();
return SUCCESS;
}
event result_t I2C.readDone(char data) {
// Done reading, update the table
pCurrentOps[current_op].res = data;
current_op++;
post processNextCmd();
return SUCCESS;
}
event result_t I2C.writeDone(bool success) {
// Done writing, update the table with result
pCurrentOps[current_op].res = success;
current_op++;
post processNextCmd();
return SUCCESS;
}
}
More information about the Tinyos-contrib-commits
mailing list