ST / X_NUCLEO_PLC01A1

Dependents:   HelloWorld_PLC01A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleoPLC01A1.h Source File

XNucleoPLC01A1.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleoPLC01A1.h
00004  * @author  AST/CL
00005  * @version V1.1.0
00006  * @date    February 23rd, 2016
00007  * @brief   Class header file for the X_NUCLEO_PLC01A1 expansion board.
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 
00039 /* Define to prevent recursive inclusion -------------------------------------*/
00040 
00041 #ifndef __X_NUCLEO_PLC01A1_CLASS_H
00042 #define __X_NUCLEO_PLC01A1_CLASS_H
00043 
00044 
00045 /* Includes ------------------------------------------------------------------*/
00046 
00047 /* ACTION 1 ------------------------------------------------------------------*
00048  * Include here platform specific header files.                               *
00049  *----------------------------------------------------------------------------*/
00050 #include "mbed.h"
00051 /* ACTION 2 ------------------------------------------------------------------*
00052  * Include here expansion board configuration's header files.                 *
00053  *----------------------------------------------------------------------------*/
00054 #include "x_nucleo_plc01a1_config.h"
00055 /* ACTION 3 ------------------------------------------------------------------*
00056  * Include here expansion board's components' header files.                   *
00057  *                                                                            *
00058  * Example:                                                                   *
00059  *   #include "COMPONENT_1.h"                                                 *
00060  *   #include "COMPONENT_2.h"                                                 *
00061  *----------------------------------------------------------------------------*/
00062 #include "CLT01_38S.h"
00063 #include "VNI8200XP.h"
00064 
00065 
00066 /* Classes  ------------------------------------------------------------------*/
00067 
00068 class XNucleoPLC01A1
00069 {
00070 public:
00071 
00072     /*** Constructor and Destructor Methods ***/
00073 
00074     /**
00075      * @brief Constructor.
00076      * @param input_ssel    pin name of the SSEL pin of the SPI device to be used for communication with Input Channels component
00077      * @param output_ssel   pin name of the SSEL pin of the SPI device to be used for communication with Output Channels component
00078      * @param spi           SPI device to be used for communication.
00079      */
00080     XNucleoPLC01A1(PinName input_ssel, PinName output_ssel, PinName out_en, SPI &spi) : plcIn(input_ssel, spi), plcOut(out_en, output_ssel, spi), freezeTo(false), attached(false)
00081     {
00082         if (plcIn.init() != COMPONENT_OK)
00083             exit(EXIT_FAILURE);
00084 
00085         if (plcOut.init() != COMPONENT_OK)
00086             exit(EXIT_FAILURE);
00087 
00088         outBuff[0] = 0;
00089         outBuff[1] = 0;        
00090     }
00091     
00092     /**
00093      * @brief Destructor.
00094      */
00095     virtual ~XNucleoPLC01A1(void) {}
00096 
00097     /*
00098      * Accessors to PLC input channels component. Please refer to "PLCInput.h".
00099      * All PLCInput related unctionality requires going through this accessor.
00100      */
00101     const PLCInput& plc_input() const {
00102         return plcIn;
00103     }
00104     PLCInput& plc_input() {
00105         return plcIn;
00106     }
00107 
00108     /*
00109      * Accessors to PLC output channels component. Please refer to "PLCOutput.h".
00110      * All PLCOutput related functionality requires going through this accessor.
00111      */
00112     const PLCOutput& plc_output() const {
00113         return plcOut;
00114     }
00115     PLCOutput& plc_output() {
00116         return plcOut;
00117     }
00118 
00119     /*
00120      * @brief      Mirrors input data
00121      * @param      Input channel state buffer
00122      * @retval     Input buffer state
00123      */
00124     uint8_t signal_mirror(uint8_t In_Array);
00125 
00126     /*
00127      * @brief      Freeze selected output for a given time
00128      * @param      Output channels to be freezed
00129      * @param      Duration of freeze
00130      * @retval     Output value
00131      */
00132     uint8_t output_freeze(uint8_t N_Channel, uint16_t msec);
00133     
00134     /*
00135      * @brief      Regroup output buffer according to out_Array
00136      * @param      Regroup array
00137      * @retval     Value
00138      */
00139     uint8_t output_regroup(uint8_t Out_Array);
00140     
00141     /*
00142      * @brief      Sum all the inputs at high state
00143      * @param      Input channel state data
00144      * @retval     Value corresponding to the sum of inputs at high
00145      */
00146     uint8_t input_sum(uint8_t* Buffer, uint8_t In_Array);
00147 
00148     /*
00149      * @brief      Set the output channels on/off
00150      * @param      Output to set
00151      * @retval     Output value
00152      */
00153     uint8_t set_output(uint8_t Out_Array);
00154 
00155     /*
00156      * @brief      AND Inputs for selected output channels
00157      * @param      Input channels state
00158      * @param      Outputs to be AND with inputs
00159      * @retval     Result of AND operation
00160      */
00161     uint8_t inputs_and(uint8_t In_Array, uint8_t Out_Channel);
00162 
00163     /*
00164      * @brief      OR Inputs for selected output channels
00165      * @param      Input channels state
00166      * @param      Outputs to be OR with inputs
00167      * @retval     Result of OR operation
00168      */
00169     uint8_t inputs_or(uint8_t In_Array, uint8_t Out_Channel);
00170     
00171     /*
00172      * @brief      NOT Inputs
00173      * @param      Input channels state
00174      * @retval     Result of OR operation
00175      */
00176     uint8_t inputs_not(uint8_t In_Array);
00177 
00178     /*
00179      * @brief      XOR Inputs for selected output channels
00180      * @param      Input channels state
00181      * @param      Outputs to be XOR with inputs
00182      * @retval     Result of XOR operation
00183      */
00184     uint8_t inputs_xor(uint8_t In_Array, uint8_t Out_Channel);
00185 
00186     /*
00187      * @brief      Calculate and set parity bits for Ssrelay transmission
00188      * @param      Output value buffer
00189      * @retval     None
00190      */
00191     void output_parity_bits(uint8_t* Buffer);
00192 
00193     /*
00194      * @brief      Toggle selected output for given frequency
00195      * @param      Output channels to be toggled
00196      * @retval     None
00197      */
00198     void output_cycling(void);
00199 
00200 protected:
00201     void handle_freeze_to(void);
00202     void toggle_output(void);
00203 
00204     CLT01_38S plcIn;
00205     VNI8200XP plcOut;
00206 
00207     Timeout timeout;
00208     bool freezeTo;
00209     bool attached;
00210     
00211     Ticker ticker;
00212     uint8_t outBuff[2];
00213 };
00214 
00215 #endif /* __X_NUCLEO_PLC01A1_CLASS_H */
00216 
00217 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/