• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

mComm.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2012 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    mTouch Framework v2.1
00005  *  FileName:        mComm.h
00006  *  Dependencies:    mComm_config.h
00007  *
00008  *  Processor:       See documentation for supported PIC® microcontrollers 
00009  *  Compiler:        HI-TECH Ver. 9.81 or later
00010  *  IDE:             MPLAB® IDE v8.50 (or later) or MPLAB® X                        
00011  *  Hardware:         
00012  *  Company:         
00013  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00014  *  Description:     mTouch Framework Include File
00015  *                   - No application code should be implemented in this
00016  *                     or any other mTouch framework file. This will allow
00017  *                     for better customer support and easier upgrades to
00018  *                     later firmware versions. Use the main.c and user-
00019  *                     generated files to implement your application.
00020  *                   - See the documentation located in the docs/ folder
00021  *                     for a more information about how the framework is
00022  *                     implemented.
00023  *************************************************************************/
00024 /**************************************************************************
00025  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00026  * any derivatives created by any person or entity by or on your behalf, 
00027  * exclusively with Microchip's products in accordance with applicable
00028  * software license terms and conditions, a copy of which is provided for
00029  * your referencein accompanying documentation. Microchip and its licensors 
00030  * retain all ownership and intellectual property rights in the 
00031  * accompanying software and in all derivatives hereto. 
00032  * 
00033  * This software and any accompanying information is for suggestion only. 
00034  * It does not modify Microchip's standard warranty for its products. You 
00035  * agree that you are solely responsible for testing the software and 
00036  * determining its suitability. Microchip has no obligation to modify, 
00037  * test, certify, or support the software. 
00038  * 
00039  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00040  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00041  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00042  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00043  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00044  * APPLICATION. 
00045  * 
00046  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00047  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00048  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00049  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00050  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00051  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00052  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00053  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00054  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00055  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00056  * 
00057  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00058  * THESE TERMS. 
00059  *************************************************************************/
00060 //=============================================================================================
00064 #ifndef __MCOMM_H
00065 #define __MCOMM_H
00066 
00067 //================================================================================================
00068 //  ___            _           _           
00069 // |_ _|_ __   ___| |_   _  __| | ___  ___ 
00070 //  | || '_ \ / __| | | | |/ _` |/ _ \/ __|
00071 //  | || | | | (__| | |_| | (_| |  __/\__ \
00072 // |___|_| |_|\___|_|\__,_|\__,_|\___||___/
00073 //                                                                    
00074 //================================================================================================
00075     #if defined(HI_TECH_C)
00076         #include <htc.h>                // Provides PIC microcontroller SFR information
00077         #include <stdint.h>             // Provides "uint#_t" typedefs for each compiler
00078     #else
00079         #include <p18cxxx.h>
00080     #endif
00081 
00082     #include "mTouch.h"                 
00083     #include "mComm_config.h"           // Stores the mComm configuration details
00084     #include "mComm_processConfiguration.h"
00085 
00086     
00087 //================================================================================================
00088 //  ____  _                   _       
00089 // / ___|| |_ _ __ _   _  ___| |_ ___ 
00090 // \___ \| __| '__| | | |/ __| __/ __|
00091 //  ___) | |_| |  | |_| | (__| |_\__ \
00092 // |____/ \__|_|   \__,_|\___|\__|___/
00093 //                                
00094 //================================================================================================
00095     typedef struct 
00096     {   
00097         uint8_t*    pointer;
00098         uint8_t     length;
00099     } mComm_Vector;                     
00100 
00101     typedef struct 
00102     {   
00103         union
00104         {
00105             uint8_t     all;
00106             
00107             struct
00108             {
00109                 unsigned        first   :1;     
00110                 #if defined(MCOMM_UART_IMPLEMENTED)
00111                 unsigned        second  :1;     
00112                 #endif
00113                 unsigned        hasNext :1;     
00114                 unsigned        high    :1;     
00115                 unsigned        gieLatch:1;     
00116             } bits;
00117             
00118         } flags;                        
00119         
00120         uint8_t         counter;        
00121         uint8_t         latch;          
00122         uint8_t         opcode;         
00123         uint8_t         checksum;       
00124         
00125         uint8_t (*iterator)(void);      
00126         
00127         mComm_Vector    vector;         
00128     } mComm_OutputVector;               
00129     
00130     typedef struct 
00131     {       
00132         uint8_t         index;
00133         uint8_t         counter;
00134         uint8_t         checksum;
00135         #if defined(MCOMM_UART_IMPLEMENTED) || defined(MCOMM_SPI_IMPLEMENTED)
00136         uint8_t         state;
00137         #endif
00138         
00139         union
00140         {
00141             uint8_t     all;
00142             struct
00143             {
00144                 unsigned        full:1;                     
00145                 
00146                 #if defined(MCOMM_UART_IMPLEMENTED)
00147                 unsigned        invalid:1;                  
00148                 #endif
00149                 
00150                 #if defined(MCOMM_I2C_IMPLEMENTED)
00151                 unsigned        write:1;                    
00152                 #endif
00153                 
00154                 #if defined(MCOMM_SPI_IMPLEMENTED)
00155                 unsigned        startPacket:1;
00156                 unsigned        ssLatch:1;                  
00157                 #endif
00158                 
00159             } bits;
00160         } flags;
00161         
00162         uint8_t         buffer[MCOMM_INPUTBUFFER_SIZE];     
00163         
00164     } mComm_InputBuffer;                
00165     
00166     typedef struct 
00167     {   
00168         void (*initialize)(void);       
00169         uint8_t (*iterator)(void);      
00170     } mComm_Opcode;                     
00171     
00172     typedef struct 
00173     {   
00174         unsigned    enabled:1;          
00175         unsigned    go:1;               
00176         unsigned    empty:6;
00177         
00178         uint8_t     index;              
00179     } mComm_StreamConfig;               
00180     
00181     
00182 //================================================================================================
00183 //  _____                 _   _                            ____ _       _           _ 
00184 // |  ___|   _ _ __   ___| |_(_) ___  _ __  ___           / ___| | ___ | |__   __ _| |
00185 // | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|  _____  | |  _| |/ _ \| '_ \ / _` | |
00186 // |  _|| |_| | | | | (__| |_| | (_) | | | \__ \ |_____| | |_| | | (_) | |_) | (_| | |
00187 // |_|   \__,_|_| |_|\___|\__|_|\___/|_| |_|___/          \____|_|\___/|_.__/ \__,_|_| 
00188 //
00189 //================================================================================================
00190     void    mComm_Init                  (void);     // Initializes mComm and its hardware module
00191     
00192     #if defined(MCOMM_TWO_WAY_ENABLED)
00193     void    mComm_Receive               (void);     // ISR Receive Function
00194     #endif
00195     
00196     #if defined(MCOMM_UART_IMPLEMENTED)
00197     void    mComm_Service               (void);     // Output servicing for UART
00198     #endif
00199     
00200     #if defined(MCOMM_TWO_WAY_ENABLED)
00201         void    mComm_processRAM            (void); // Initialize for RAM access
00202         uint8_t mComm_ramReadIterator       (void); // RAM Memory               - Read Iterator 
00203         uint8_t mComm_ramWriteIterator      (void); // RAM Memory               - Write Iterator
00204         
00205         #if defined(MCOMM_ENABLE_NVM_ACCESS)
00206         void    mComm_processNVM            (void); // Initialize for NVM access
00207         uint8_t mComm_nvmReadIterator       (void); // Non-Volatile Memory      - Read Iterator
00208         uint8_t mComm_nvmWriteIterator      (void); // Non-Volatile Memory      - Write Iterator
00209         #endif
00210         
00211         #if defined(MCOMM_ENABLE_STREAM)
00212         void    mComm_processStream         (void); // Initialize for Stream access
00213         uint8_t mComm_StreamReadIterator    (void); // Streamed List            - Read Iterator
00214         #endif
00215         
00216         void    mComm_ErrorProcess          (void); // Opcode not found - Error behavior definition
00217         uint8_t mComm_ErrorIterator         (void); // Opcode not found - Error behavior definition
00218         
00219         #if defined(MCOMM_ENABLE_CUSTOM_OPCODE)
00220         uint8_t mComm_CustomCallback(void);
00221         void    mComm_CustomProcess(void);
00222         uint8_t mComm_CustomWriteIterator(void);
00223         #endif
00224     #endif
00225     
00226 //================================================================================================
00227 // __     __         _       _     _                      ____ _       _           _ 
00228 // \ \   / /_ _ _ __(_) __ _| |__ | | ___  ___           / ___| | ___ | |__   __ _| |
00229 //  \ \ / / _` | '__| |/ _` | '_ \| |/ _ \/ __|  _____  | |  _| |/ _ \| '_ \ / _` | |
00230 //   \ V / (_| | |  | | (_| | |_) | |  __/\__ \ |_____| | |_| | | (_) | |_) | (_| | |
00231 //    \_/ \__,_|_|  |_|\__,_|_.__/|_|\___||___/          \____|_|\___/|_.__/ \__,_|_|
00232 // 
00233 //================================================================================================
00234     #if defined(MCOMM_TWO_WAY_ENABLED)
00235     extern          mComm_OutputVector  mComm_output;                   // Output vector and flags
00236     extern          mComm_InputBuffer   mComm_input;                    // Input buffer and flags
00237     extern          mComm_StreamConfig  mComm_streamConfig;
00238     extern const    mComm_Opcode        mComm_opcode[MCOMM_NUMBER_OPCODES];
00239     extern const    uint8_t             mComm_ConfigBlock_Literals[MCOMM_CONFIG_LIT_SIZE]; 
00240     extern          uint8_t * const     mComm_ConfigBlock_Addrs[MCOMM_CONFIG_ADDR_SIZE];
00241     #if defined(MCOMM_STREAM_STORED_IN_RAM)
00242     extern          mComm_Vector        mComm_stream[MCOMM_STREAM_SIZE + 1];
00243     #else
00244     extern const    mComm_Vector        mComm_stream[MCOMM_STREAM_SIZE + 1];
00245     #endif
00246     #endif
00247     
00248     #if defined(MCOMM_ENABLE_CUSTOM_OPCODE)
00249     extern          uint8_t             mComm_GUICustomVariable;
00250     #endif
00251 //================================================================================================
00252 //  _____                           
00253 // | ____|_ __  _   _ _ __ ___  ___ 
00254 // |  _| | '_ \| | | | '_ ` _ \/ __|
00255 // | |___| | | | |_| | | | | | \__ \
00256 // |_____|_| |_|\__,_|_| |_| |_|___/
00257 //                               
00258 //================================================================================================
00259     enum    mComm_UART_States
00260             {
00261                 MCOMM_IDLE,          
00262                 MCOMM_START,         
00263                 MCOMM_BUFFER,        
00264                 MCOMM_PROCESS_DATA   
00265             };
00266 
00267     enum    mComm_SPI_States
00268             {
00269                 MCOMM_SPI_IDLE,          
00270                 MCOMM_SPI_START,         
00271                 MCOMM_SPI_PACKET_LENGTH, 
00272                 MCOMM_SPI_BUFFER,        
00273                 MCOMM_SPI_PROCESS_DATA,  
00274                 MCOMM_SPI_OUTPUT
00275             };
00276             
00277             
00278 #endif      // end: ifndef __MCOMM_H
00279 
00280 

mTouch Framework v2.1 documentation by  Click here to visit our website at www.microchip.com