Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers zg_drv.h Source File

zg_drv.h

Go to the documentation of this file.
00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 /**
00025 @file
00026 ZG2100 Low-level driver
00027 */
00028 //Donatien Garnier 2010
00029 
00030 #ifndef ZG_DRV_H
00031 #define ZG_DRV_H
00032 
00033 #include "zg_defs.h"
00034 #include "zg_err.h"
00035 
00036 //Stores relevant data
00037 typedef struct _ZG_DATA
00038 {
00039   byte mac_addr[6];
00040   ZG_SYSV sys_version;
00041   
00042 } ZG_DATA;
00043 
00044 //Stores which data is actually available
00045 typedef struct _ZG_DATA_MASK
00046 {
00047   bool mac_addr;
00048   bool sys_version;
00049 
00050 } ZG_DATA_MASK; //true when the corresponding data field is valid, false otherwise
00051 
00052 //Exported Data
00053 extern byte fifo_buf[ZG_FIFO_BUF_SIZE] ZG_MEM; //Big buffer used for fifo transfers
00054 extern ZG_DATA zg_data; //Container for all data received from the chip
00055 extern ZG_DATA_MASK zg_data_mask; //Flags valid data
00056 
00057 //Spi intf, Chip Select pin, Interrupt pin
00058 ///Initializes driver (zg_com_init must be called before).
00059 zg_err zg_drv_init();
00060 
00061 //FIXME: Not implemented, not used (to be deleted?)
00062 void zg_on_data_attach( void (*on_data)() );
00063 
00064 ///Must be called regularly to process interrupts.
00065 void zg_process(); //Must be called regularly by user
00066 
00067 ///Processes interrupt. (Called by zg_process if needed)
00068 void zg_int_process(); //Process interrupt
00069 
00070 ///Can a management request be sent?
00071 bool zg_mgmt_is_busy();
00072 
00073 ///Sends management request
00074 void zg_mgmt_req(byte subtype, byte* buf, int len, bool close = true);
00075 
00076 ///Writes additional management data
00077 void zg_mgmt_data(byte* buf, int len, bool close = true);
00078 
00079 ///Gets parameter
00080 void zg_mgmt_get_param(byte param);
00081 
00082 ///Sets parameter
00083 void zg_mgmt_set_param(byte param, byte* buf, int len);
00084 
00085 ///Called on management request result
00086 void zg_on_mgmt_avl(byte subtype, byte* buf, int len); //Data is available
00087 
00088 ///Called on management event
00089 void zg_on_mgmt_evt(byte subtype, byte* buf, int len); //Management event
00090 
00091 ///Called when get parameter request completes
00092 void zg_on_mgmt_get_param(byte* buf, int len); //Get param completed
00093 
00094 //uint32_t zg_fifo_room();
00095 
00096 //Useful to be split in several function because Lwip stores buffers in chunks
00097 ///Sends Data (start)
00098 void zg_send_start();
00099 ///Sends Data (main)
00100 void zg_send(byte* buf, int len);
00101 ///Sends Data (end)
00102 void zg_send_end();
00103 
00104 ///Can more data be sent?
00105 bool zg_send_is_busy();
00106 
00107 //Callbacks implemented in zg_if
00108 void zg_on_scan_results(byte* buf, int len);
00109 void zg_on_psk_key(byte* buf, int len);
00110 void zg_on_connect(zg_err result);
00111 
00112 //Handled by zg_net
00113 ///Data received
00114 void zg_on_input(byte* buf, int len); 
00115 
00116 //Callbacks from zg_com
00117 void zg_on_int(); //On data available interrupt
00118 
00119 #endif