ST / X_NUCLEO_PLC01A1

Dependents:   HelloWorld_PLC01A1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VNI8200XP.cpp Source File

VNI8200XP.cpp

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    VNI8200XP.cpp
00004   * @author  System Lab Noida
00005   * @version V1.0.0
00006   * @date    08-July-2015
00007   * @brief   PLC_CLT01-38SQ7
00008   * This file provides firmware functions for how  to manage I/O from VNI8200XP
00009   ==============================================================================    
00010  
00011            
00012   ******************************************************************************
00013   * @attention
00014   *
00015   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00016   *
00017   * Redistribution and use in source and binary forms, with or without modification,
00018   * are permitted provided that the following conditions are met:
00019   *   1. Redistributions of source code must retain the above copyright notice,
00020   *      this list of conditions and the following disclaimer.
00021   *   2. Redistributions in binary form must reproduce the above copyright notice,
00022   *      this list of conditions and the following disclaimer in the documentation
00023   *      and/or other materials provided with the distribution.
00024   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00025   *      may be used to endorse or promote products derived from this software
00026   *      without specific prior written permission.
00027   *
00028   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00029   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00031   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00032   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038   *
00039   ******************************************************************************  
00040   */
00041   
00042   /* Includes ------------------------------------------------------------------*/
00043 #include "plc.h"
00044 
00045 #include "VNI8200XP.h"
00046     
00047 /** @addtogroup Drivers     Drivers
00048   * @{
00049   * @brief Demo Driver Layer
00050   */    
00051   
00052 /** @addtogroup BSP     BSP
00053   * @{
00054   */    
00055     
00056 /** @addtogroup Components     Components
00057   * @{
00058   */
00059 
00060 /** @defgroup VNI8200XP    VNI8200XP
00061   * @{ 
00062   * @brief Digital Output Driver Layer
00063   */
00064 
00065 /** @defgroup VNI8200XP_Private_variables     VNI8200XP Private variables
00066   * @{
00067   * @brief Digital Output Private variables
00068   */
00069 
00070 /* Number of components */
00071 uint8_t VNI8200XP::number_of_plc_output_components = 0;
00072 
00073 
00074 /** @defgroup VNI8200XP_Exported_Functions     VNI8200XP Exported Functions
00075   * @{
00076   * @brief Digital Input exported Function 
00077   */
00078 
00079 /**********************************************************
00080  * @brief Starts the VNI8200XP library
00081  * @param  init Initialization structure.
00082  * @retval COMPONENT_OK in case of success.
00083  **********************************************************/
00084 status_t VNI8200XP::VNI8200XP_Init(void *init)
00085 {
00086     VNI_PARITY_Buffer = 0x00;
00087     VNI_FAULT_Buffer = 0x00;
00088     VNI_FB_OK = 0x00;
00089     VNI_TEMP_WARNING = 0x00;
00090     VNI_PARITY_CHECK = 0x00;
00091     VNI_POWER_GOOD = 0x00;
00092     VNI_PARITY_FALL_Buffer = 0x00;
00093 
00094     /* Unselect the Ssrelay chip at startup to avoid FAULT */
00095     ssel = 1;
00096 
00097     /* Enable Ssrelay Outputs */
00098     out_en = 1;
00099 
00100     return COMPONENT_OK;
00101 }
00102 
00103 /**********************************************************
00104  * @brief Read id
00105  * @param id pointer to the identifier to be read.
00106  * @retval COMPONENT_OK in case of success.
00107  **********************************************************/
00108 status_t VNI8200XP::VNI8200XP_ReadID(uint8_t *id)
00109 {
00110   *id = plc_output_component_instance;
00111 
00112   return COMPONENT_OK;
00113 }
00114 
00115 /**********************************************************
00116   * @brief      Set output channels state
00117   * @param      Out_array, output channel data 
00118   * @retval     None
00119  **********************************************************/
00120 void VNI8200XP::VNI8200XP_SetChannels(uint8_t Out_array)
00121 {
00122   spi_tx_buff[1] = Out_array;
00123 }
00124 
00125 /**********************************************************
00126   * @brief      Get output fault status
00127   * @param      None
00128   * @retval     Output channel fault data
00129  **********************************************************/
00130 uint8_t VNI8200XP::VNI8200XP_ManageFault(void)
00131 {
00132   VNI_FAULT_Buffer = spi_rx_buff[1];
00133   return VNI_FAULT_Buffer;
00134 }
00135 
00136 /**********************************************************
00137   * @brief      Get VNI8200XP DC-DC status
00138   * @param      None
00139   * @retval     Feedback status, COMPONENT_OK if OK
00140  **********************************************************/
00141 status_t VNI8200XP::VNI8200XP_CheckDCDCStatus(void)
00142 {
00143   VNI_FB_OK = spi_rx_buff[0];
00144   VNI_FB_OK = VNI_FB_OK & 0x80;
00145   if(VNI_FB_OK == 0x80) {
00146     return COMPONENT_ERROR;
00147   } else {
00148     return COMPONENT_OK;
00149   }
00150 }
00151 
00152 /**********************************************************
00153   * @brief      Get temperature warning status
00154   * @param      None
00155   * @retval     Temperature warning status, COMPONENT_ERROR if over temperature
00156  **********************************************************/
00157 status_t VNI8200XP::VNI8200XP_TemperatureWarning(void)
00158 {
00159   VNI_TEMP_WARNING = spi_rx_buff[0];
00160   VNI_TEMP_WARNING = VNI_TEMP_WARNING & 0x40;
00161   if(VNI_TEMP_WARNING == 0x40) {
00162     return COMPONENT_ERROR;
00163   } else {
00164     return COMPONENT_OK;
00165   }
00166 }
00167 
00168 /**********************************************************
00169   * @brief      Get parity check status
00170   * @param      None
00171   * @retval     Parity check flag, COMPONENT_ERROR if 0x20
00172  **********************************************************/
00173 status_t VNI8200XP::VNI8200XP_CheckParity(void)
00174 {
00175   VNI_PARITY_CHECK = spi_rx_buff[0];
00176   VNI_PARITY_CHECK = VNI_PARITY_CHECK & 0x20;
00177   if(VNI_PARITY_CHECK == 0x20) {
00178     return COMPONENT_ERROR;
00179   } else {
00180     return COMPONENT_OK;
00181   }
00182 }
00183 
00184 /**********************************************************
00185   * @brief      Get power supply status
00186   * @param      None
00187   * @retval     Power good bit, COMPONENT_OK in case of power good
00188  **********************************************************/
00189 status_t VNI8200XP::VNI8200XP_CheckPowerGood(void)
00190 {
00191   VNI_POWER_GOOD = spi_rx_buff[0];
00192   VNI_POWER_GOOD = VNI_POWER_GOOD & 0x10;
00193   if(VNI_POWER_GOOD == 0x10) {
00194     return COMPONENT_OK;
00195   } else {
00196     return COMPONENT_ERROR;
00197   }
00198 }
00199 
00200 /**********************************************************
00201   * @brief      Get parity bits for input data from VNI
00202   * @param      None
00203   * @retval     Parity bits from VNI
00204  **********************************************************/
00205 uint8_t VNI8200XP::VNI8200XP_CheckCommError(void)
00206 {
00207     VNI_PARITY_FALL_Buffer = spi_rx_buff[0];
00208     VNI_PARITY_FALL_Buffer = VNI_PARITY_FALL_Buffer & 0x0F;
00209     return VNI_PARITY_FALL_Buffer;
00210 }
00211 
00212 /**********************************************************
00213  * @brief  Set output channels component 
00214  * @param  txBuff
00215  * @retval None
00216  **********************************************************/
00217 void VNI8200XP::VNI8200XP_Ssrelay_SetOutput(uint8_t *outputArray)
00218 {
00219   spi_tx_buff[0] = outputArray[0];
00220   spi_tx_buff[1] = outputArray[1];
00221 
00222   if(VNI8200XP_SpiWriteBytes(spi_tx_buff, spi_rx_buff) != 0) {
00223       /* Aborting the program */
00224       exit(EXIT_FAILURE);
00225   }
00226 }
00227 
00228 /**
00229   * @} //end VNI8200XP Exported Functions
00230   */
00231 
00232 /**
00233   * @}  //end VNI8200XP Device Driver
00234   */
00235 /**
00236   * @}  //end Components
00237    */
00238 /**
00239   * @}  //close group  BSP
00240   */
00241 
00242 /**
00243   * @}  //close group  Drivers
00244   */
00245 
00246 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/