arm studio build

Dependencies:   libxDot-mbed5

inc/commI2C.h

Committer:
alan1974
Date:
2018-08-10
Revision:
7:fba1e8fc7693
Parent:
6:b2039a285d7f
Child:
9:cc23b2049639

File content as of revision 7:fba1e8fc7693:

/*
 * WaterBit, Inc. ("COMPANY") CONFIDENTIAL
 * Unpublished Copyright (c) 2015-2016 WaterBit, Inc, All Rights Reserved.
 * NOTICE: All information contained herein is, and remains the property of COMPANY. The intellectual and technical concepts contained herein are proprietary to COMPANY and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
 * 
 * Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from COMPANY.
 *
 * Access to the source code contained herein is hereby forbidden to anyone except current COMPANY employees, managers or contractors who have executed Confidentiality and Non-disclosure agreements explicitly covering such access.
 *
 * The copyright notice above does not evidence any actual or intended publication or disclosure of this source code, which includes information that is confidential and/or proprietary, and is a trade secret, of COMPANY.
 *
 * ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLICPE RFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE EXPRESS WRITTEN CONSENT OF COMPANY IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
 */

#ifndef _COMMI2C_H_
#define _COMMi2C_H_

#include "mbed.h"
#include "global.h"



#define BUFFER_SIZE_I2C     64
#define I2C_MIN_WAIT_DELAY  200      //minimum time between rcv/xmit i2c data and pulsing wake
#define I2C_ACK_PROC       0xff     //first byte of i2c ack msg back to proc
#define I2C_MAX_ACK_DATA     32     //max data bytes accepted from Rx downstream pkt

//cmds to xdot    
enum{
   XDOT_CMD_XMIT_PKT = 1,   //transmit data
   XDOT_CMD_GET_EUI,        //get xdot EUI       
   XDOT_CMD_SET_KEY_X,      //set one of the security keys
   XDOT_CMD_GOTO_SLEEP,     //go to sleep 
   XDOT_CMD_GATEWAY_PING,   //ping gateway for RSSI
   XDOT_CMD_SET_NTWKSESS,   //write/read network session to/from flash      
   XDOT_CMD_SET_RADIO,      //set's radio parameters   
   XDOT_CMD_SET_NVM,        //write params to xdot nvm memory 
   XDOT_CMD_UNDEFINED,      //last cmd, not used 
};


enum I2C_XFR_TYPE{
 I2C_READ =0,
 I2C_WRITE};   
 
 //structure: upstream pkt for xdot to transmit
 //txData bfr: is located in the struc immediately after dataLen parameter
 //          : this allows extending pkt_upstrm struc as new control parameters are needed 
#define PKT_UPSTRM_RSVD  (BUFFER_SIZE_I2C- (I2C_MAX_ACK_DATA + 7))
typedef struct {   
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  uint8_t   txData[I2C_MAX_ACK_DATA];   //array for tx Data     
  uint8_t   joinAttemps;                //max attempts to join network before quitting 
  uint8_t   appPort;                    //set app port (rev 0307)
  uint8_t   linkThreshCnt;              //set link threshold count, 0 == disable
  uint8_t   bSetAdr;                    //not used
  uint8_t   rxvd[PKT_UPSTRM_RSVD];      //rserved filler bytes
  uint8_t   chksum;                     //chksum of all previous, last byte in pkt
 }pkt_upstrm;
//structure: results returned to proc  of upstream data transmit
typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  uint8_t   bXmitAttempted;             //true if xmit attempted, (fail of pkt len too big)  
  uint8_t   joinAttempts;               //# of join attempts before join occured, if bJoined=0 this = max attempts
  uint8_t   bJoined;                    //true if successfully joined  
  uint8_t   bAck;                       //true if ack return from xmit
  uint8_t   bRx1;                       //true if rx1 return
  uint8_t   bAckdata;                   //true if rx data
  int8_t    rssi;                       //last rssi, 0 if no rx1/2 ack
  uint8_t   rxLen;                      //length of returned rxdata
  uint8_t   rxData[I2C_MAX_ACK_DATA];   //array for rx Data    
  int16_t   mdot_ret;                   //mdot return code after calling send function
  uint8_t   chksum_err;                 //1 if chksum err on proc upstream pkt
  int8_t    snr;                        //last snr, 0 if no rx1/2 ack
  uint8_t   rsvd[15];                   //reserved for future use
}pkt_ack;
//structure: results returned to proc for eui and api_level
//v0307: eui pkt now used to read/set radio params also
typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  uint8_t   euiData[16];                //eui 
  uint8_t   apiLvlData[4];              //api level 
  uint8_t   verLvlData[4];              //ver level   
}pkt_eui;

//structure: cmd structure to proc for setting radio parameters
//upstream pkt struc
typedef struct {  
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt  
  bool      bSetParams;                 //if true then set and save variable params to nvm; false=> read params
  xdot_radio_params params;
}pkt_setradioup;

//downstream pkt struc
//structure: cmd structure to proc for setting radio parameters
typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt  
  xdot_radio_params params;
}pkt_setradiodwn;

//nvm ptks
//structure: cmd structure to proc for setting nvm parameters
//upstream pkt struc
typedef struct {  
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt  
  uint8_t   bWriteNvm;                  //if false, just read nvm
  nvm       nvmData;
}pkt_setnvmup;
//dwnstream pkt struc
typedef struct {  
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc    
  uint8_t   dataLen;                    //datalen found in pkt  
  uint8_t   bChkSumOK; 
  nvm       nvmData;
}pkt_setnvmdwn;




//structure: results returned to proc network session
typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  uint8_t   bSetNetwrk;                 //1 if wrote network session, 0 if read   
}pkt_ntwrk;

//structure: results returned to proc of gateway ping
typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  int8_t   status;                      //ping status return, 0 = success
  int8_t   rssi;                        //rssi that gateway heard from node
  int8_t   snr;                         //snr  that ....
}pkt_ping;




typedef struct {
  uint8_t   ack;                        //ack header response
  uint8_t   cmd;                        //cmd received from proc
  uint8_t   dataLen;                    //datalen found in pkt
  uint8_t   rxData[I2C_MAX_ACK_DATA];   //Data    
}data_ack;


void i2c_proc_init();
void i2c_wait4wake_lo(void);
void i2c_pulse_wake(void);
I2C_XFR_TYPE i2c_proc_comm();

#endif