Library to handle the X-NUCLEO-PLC01A1 Programmable Logic Controller Expansion Board based on the VNI8200XP (solid state relay) and CLT01-38SQ7 (octal digital termination array) components.
Dependents: HelloWorld_PLC01A1
Programmable Logic Controller Library
Library to handle the X-NUCLEO-PLC01A1 Programmable Logic Controller Expansion Board based on the VNI8200XP (solid state relay) and CLT01-38SQ7 (octal digital termination array) components.
Information
For further details on VNI8200XP (Octal high side smart power solid state relay with serial/parallel selectable interface on chip) please refer to ST's web site.
For further details on CLT01-38SQ7 (High speed digital input current limiter) please refer to ST's web site.
SPI configuration
Pin D3 and D13 providing the SPI serial clock are short-circuited in the X-NUCLEO-PLC01A1 Expansion Board.
Please be aware that you may not drive the base board LED if it is connected to pin D13 (as it happens on STM32 Nucleo boards) or D3, otherwise you will get a conflict.
Platform compatibility
- STM32 NUCLEO boards have been tested with the default configuration provided by the HelloWorld_PLC01A1 example.
- FRDM-K64F board has been tested with the following patch:
return DSPI_HAL_ReadData(spi_address[obj->instance]);
X-NUCLEO-PLC01A1 board powering and startup
The following steps must be followed to run the X-NUCLEO-PLC01A1:
- Plug the X-NUCLEO-PLC01A1 onto a base board
- Connect the base board to a PC via a standard Type A / mini (or micro) B USB cable
- Download the firmware on the MCU hosted on the base board
- Supply 24 V to the X-NUCLEO-PLC01A1 board through the J8 connector
- The HelloWorld_PLC01A1 demonstration firmware is ready to run: connect any of the 8 inputs on the J8 connector to see the corresponding output on the J10 connector capable of driving a load (i.e. short-circuit input “x” with the 24 V and connect the corresponding output “x” to a load).
Components/CLT01_38SQ7/CLT01_38S.h@7:5d4336d0e372, 2021-07-12 (annotated)
- Committer:
- apalmieri
- Date:
- Mon Jul 12 10:09:44 2021 +0000
- Revision:
- 7:5d4336d0e372
- Parent:
- 5:0845d4141a01
Update to mbed-os 6 (mbed-os-6.12.0)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Davidroid | 5:0845d4141a01 | 1 | /** |
| Davidroid | 5:0845d4141a01 | 2 | ****************************************************************************** |
| Davidroid | 5:0845d4141a01 | 3 | * @file CLT01_38S.h |
| Davidroid | 5:0845d4141a01 | 4 | * @author AST/CL |
| Davidroid | 5:0845d4141a01 | 5 | * @version V1.0.0 |
| Davidroid | 5:0845d4141a01 | 6 | * @date Feb 4th, 2016 |
| Davidroid | 5:0845d4141a01 | 7 | * @brief This file contains the class of an CLT01_38SQ7 PLC component. |
| Davidroid | 5:0845d4141a01 | 8 | ****************************************************************************** |
| Davidroid | 5:0845d4141a01 | 9 | * @attention |
| Davidroid | 5:0845d4141a01 | 10 | * |
| Davidroid | 5:0845d4141a01 | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| Davidroid | 5:0845d4141a01 | 12 | * |
| Davidroid | 5:0845d4141a01 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
| Davidroid | 5:0845d4141a01 | 14 | * are permitted provided that the following conditions are met: |
| Davidroid | 5:0845d4141a01 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
| Davidroid | 5:0845d4141a01 | 16 | * this list of conditions and the following disclaimer. |
| Davidroid | 5:0845d4141a01 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| Davidroid | 5:0845d4141a01 | 18 | * this list of conditions and the following disclaimer in the documentation |
| Davidroid | 5:0845d4141a01 | 19 | * and/or other materials provided with the distribution. |
| Davidroid | 5:0845d4141a01 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| Davidroid | 5:0845d4141a01 | 21 | * may be used to endorse or promote products derived from this software |
| Davidroid | 5:0845d4141a01 | 22 | * without specific prior written permission. |
| Davidroid | 5:0845d4141a01 | 23 | * |
| Davidroid | 5:0845d4141a01 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| Davidroid | 5:0845d4141a01 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| Davidroid | 5:0845d4141a01 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| Davidroid | 5:0845d4141a01 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| Davidroid | 5:0845d4141a01 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| Davidroid | 5:0845d4141a01 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| Davidroid | 5:0845d4141a01 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| Davidroid | 5:0845d4141a01 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| Davidroid | 5:0845d4141a01 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Davidroid | 5:0845d4141a01 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Davidroid | 5:0845d4141a01 | 34 | * |
| Davidroid | 5:0845d4141a01 | 35 | ****************************************************************************** |
| Davidroid | 5:0845d4141a01 | 36 | */ |
| Davidroid | 5:0845d4141a01 | 37 | |
| Davidroid | 5:0845d4141a01 | 38 | |
| Davidroid | 5:0845d4141a01 | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 40 | |
| Davidroid | 5:0845d4141a01 | 41 | #ifndef __CLT01_38S_CLASS_H |
| Davidroid | 5:0845d4141a01 | 42 | #define __CLT01_38S_CLASS_H |
| Davidroid | 5:0845d4141a01 | 43 | |
| Davidroid | 5:0845d4141a01 | 44 | |
| Davidroid | 5:0845d4141a01 | 45 | /* Includes ------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 46 | |
| Davidroid | 5:0845d4141a01 | 47 | /* ACTION 1 ------------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 48 | * Include here platform specific header files. * |
| Davidroid | 5:0845d4141a01 | 49 | *----------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 50 | #include "mbed.h" |
| Davidroid | 5:0845d4141a01 | 51 | |
| Davidroid | 5:0845d4141a01 | 52 | /* ACTION 2 ------------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 53 | * Include here component specific header files. * |
| Davidroid | 5:0845d4141a01 | 54 | *----------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 55 | #include "../Common/plc.h" |
| Davidroid | 5:0845d4141a01 | 56 | |
| Davidroid | 5:0845d4141a01 | 57 | /* ACTION 3 ------------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 58 | * Include here interface specific header files. * |
| Davidroid | 5:0845d4141a01 | 59 | * * |
| Davidroid | 5:0845d4141a01 | 60 | * Example: * |
| Davidroid | 5:0845d4141a01 | 61 | * #include "../Interfaces/PLCInput.h" * |
| Davidroid | 5:0845d4141a01 | 62 | *----------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 63 | #include "../Interfaces/PLCInput.h" |
| Davidroid | 5:0845d4141a01 | 64 | |
| Davidroid | 5:0845d4141a01 | 65 | |
| Davidroid | 5:0845d4141a01 | 66 | /* Classes -------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 67 | |
| Davidroid | 5:0845d4141a01 | 68 | /** |
| Davidroid | 5:0845d4141a01 | 69 | * @brief Class representing an CLT01_38S component. |
| Davidroid | 5:0845d4141a01 | 70 | */ |
| Davidroid | 5:0845d4141a01 | 71 | class CLT01_38S : public PLCInput |
| Davidroid | 5:0845d4141a01 | 72 | { |
| Davidroid | 5:0845d4141a01 | 73 | public: |
| Davidroid | 5:0845d4141a01 | 74 | |
| Davidroid | 5:0845d4141a01 | 75 | /*** Constructor and Destructor Methods ***/ |
| Davidroid | 5:0845d4141a01 | 76 | |
| Davidroid | 5:0845d4141a01 | 77 | /** |
| Davidroid | 5:0845d4141a01 | 78 | * @brief Constructor. |
| Davidroid | 5:0845d4141a01 | 79 | * @param ssel pin name of the SSEL pin of the SPI device to be used for communication. |
| Davidroid | 5:0845d4141a01 | 80 | * @param spi SPI device to be used for communication. |
| Davidroid | 5:0845d4141a01 | 81 | */ |
| Davidroid | 5:0845d4141a01 | 82 | CLT01_38S(PinName input_ssel, SPI &spi) : PLCInput(), ssel(input_ssel), dev_spi(spi) |
| Davidroid | 5:0845d4141a01 | 83 | { |
| Davidroid | 5:0845d4141a01 | 84 | /* Checking stackability. */ |
| Davidroid | 5:0845d4141a01 | 85 | if (!(number_of_plc_input_components < MAX_NUMBER_OF_PLC_INPUT_COMPONENTS)) { |
| Davidroid | 5:0845d4141a01 | 86 | error("Instantiation of the CLT01_38S component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_PLC_INPUT_COMPONENTS); |
| Davidroid | 5:0845d4141a01 | 87 | } |
| Davidroid | 5:0845d4141a01 | 88 | |
| Davidroid | 5:0845d4141a01 | 89 | plc_input_component_instance = number_of_plc_input_components++; |
| Davidroid | 5:0845d4141a01 | 90 | memset(spi_tx_buff, 0, NB_BYTES * sizeof(uint8_t)); |
| Davidroid | 5:0845d4141a01 | 91 | memset(spi_rx_buff, 0, NB_BYTES * sizeof(uint8_t)); |
| Davidroid | 5:0845d4141a01 | 92 | } |
| Davidroid | 5:0845d4141a01 | 93 | |
| Davidroid | 5:0845d4141a01 | 94 | /** |
| Davidroid | 5:0845d4141a01 | 95 | * @brief Destructor. |
| Davidroid | 5:0845d4141a01 | 96 | */ |
| Davidroid | 5:0845d4141a01 | 97 | virtual ~CLT01_38S(void) {} |
| Davidroid | 5:0845d4141a01 | 98 | |
| Davidroid | 5:0845d4141a01 | 99 | |
| Davidroid | 5:0845d4141a01 | 100 | /*** Public Component Related Methods ***/ |
| Davidroid | 5:0845d4141a01 | 101 | |
| Davidroid | 5:0845d4141a01 | 102 | /* ACTION 5 --------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 103 | * Implement here the component's public methods, as wrappers of the C * |
| Davidroid | 5:0845d4141a01 | 104 | * component's functions. * |
| Davidroid | 5:0845d4141a01 | 105 | * They should be: * |
| Davidroid | 5:0845d4141a01 | 106 | * + Methods with the same name of the C component's virtual table's * |
| Davidroid | 5:0845d4141a01 | 107 | * functions (1); * |
| Davidroid | 5:0845d4141a01 | 108 | * + Methods with the same name of the C component's extended virtual * |
| Davidroid | 5:0845d4141a01 | 109 | * table's functions, if any (2). * |
| Davidroid | 5:0845d4141a01 | 110 | * * |
| Davidroid | 5:0845d4141a01 | 111 | * Example: * |
| Davidroid | 5:0845d4141a01 | 112 | * virtual int get_value(float *pData) //(1) * |
| Davidroid | 5:0845d4141a01 | 113 | * { * |
| Davidroid | 5:0845d4141a01 | 114 | * return COMPONENT_get_value(float *pfData); * |
| Davidroid | 5:0845d4141a01 | 115 | * } * |
| Davidroid | 5:0845d4141a01 | 116 | * * |
| Davidroid | 5:0845d4141a01 | 117 | * virtual int enable_feature(void) //(2) * |
| Davidroid | 5:0845d4141a01 | 118 | * { * |
| Davidroid | 5:0845d4141a01 | 119 | * return COMPONENT_enable_feature(); * |
| Davidroid | 5:0845d4141a01 | 120 | * } * |
| Davidroid | 5:0845d4141a01 | 121 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 122 | /** |
| Davidroid | 5:0845d4141a01 | 123 | * @brief Initializing the component in 1/16 Microstepping mode. |
| Davidroid | 5:0845d4141a01 | 124 | * @param init Pointer to device specific initalization structure. |
| Davidroid | 5:0845d4141a01 | 125 | * @retval "0" in case of success, an error code otherwise. |
| Davidroid | 5:0845d4141a01 | 126 | */ |
| Davidroid | 5:0845d4141a01 | 127 | virtual int init(void *init = NULL) |
| Davidroid | 5:0845d4141a01 | 128 | { |
| Davidroid | 5:0845d4141a01 | 129 | return (int) CLT01_38S_Init((void *) init); |
| Davidroid | 5:0845d4141a01 | 130 | } |
| Davidroid | 5:0845d4141a01 | 131 | |
| Davidroid | 5:0845d4141a01 | 132 | /** |
| Davidroid | 5:0845d4141a01 | 133 | * @brief Getting the ID of the component. |
| Davidroid | 5:0845d4141a01 | 134 | * @param id Pointer to an allocated variable to store the ID into. |
| Davidroid | 5:0845d4141a01 | 135 | * @retval "0" in case of success, an error code otherwise. |
| Davidroid | 5:0845d4141a01 | 136 | */ |
| Davidroid | 5:0845d4141a01 | 137 | virtual int read_id(uint8_t *id = NULL) |
| Davidroid | 5:0845d4141a01 | 138 | { |
| Davidroid | 5:0845d4141a01 | 139 | return (int) CLT01_38S_ReadID((uint8_t *) id); |
| Davidroid | 5:0845d4141a01 | 140 | } |
| Davidroid | 5:0845d4141a01 | 141 | |
| Davidroid | 5:0845d4141a01 | 142 | /** |
| Davidroid | 5:0845d4141a01 | 143 | * @brief Set Read Status |
| Davidroid | 5:0845d4141a01 | 144 | * @param None |
| Davidroid | 5:0845d4141a01 | 145 | * @retval Status |
| Davidroid | 5:0845d4141a01 | 146 | */ |
| Davidroid | 5:0845d4141a01 | 147 | virtual uint8_t get_read_status(void) |
| Davidroid | 5:0845d4141a01 | 148 | { |
| Davidroid | 5:0845d4141a01 | 149 | return (uint8_t) CLT01_38S_GetReadStatus(); |
| Davidroid | 5:0845d4141a01 | 150 | } |
| Davidroid | 5:0845d4141a01 | 151 | |
| Davidroid | 5:0845d4141a01 | 152 | /** |
| Davidroid | 5:0845d4141a01 | 153 | * @brief Set Read Status |
| Davidroid | 5:0845d4141a01 | 154 | * @param Status |
| Davidroid | 5:0845d4141a01 | 155 | * @retval None |
| Davidroid | 5:0845d4141a01 | 156 | */ |
| Davidroid | 5:0845d4141a01 | 157 | virtual void set_read_status(uint8_t status) |
| Davidroid | 5:0845d4141a01 | 158 | { |
| Davidroid | 5:0845d4141a01 | 159 | CLT01_38S_SetReadStatus(status); |
| Davidroid | 5:0845d4141a01 | 160 | } |
| Davidroid | 5:0845d4141a01 | 161 | |
| Davidroid | 5:0845d4141a01 | 162 | /** |
| Davidroid | 5:0845d4141a01 | 163 | * @brief Get Input Status |
| Davidroid | 5:0845d4141a01 | 164 | * @param None |
| Davidroid | 5:0845d4141a01 | 165 | * @retval Channels status corresponding to 8 inputs |
| Davidroid | 5:0845d4141a01 | 166 | */ |
| Davidroid | 5:0845d4141a01 | 167 | virtual uint8_t get_input_data(void) |
| Davidroid | 5:0845d4141a01 | 168 | { |
| Davidroid | 5:0845d4141a01 | 169 | return (uint8_t) CLT01_38S_GetInputData(); |
| Davidroid | 5:0845d4141a01 | 170 | } |
| Davidroid | 5:0845d4141a01 | 171 | |
| Davidroid | 5:0845d4141a01 | 172 | /** |
| Davidroid | 5:0845d4141a01 | 173 | * @brief Over Temperature Alarm bit |
| Davidroid | 5:0845d4141a01 | 174 | * @param None |
| Davidroid | 5:0845d4141a01 | 175 | * @retval Overtemperature bit, 1 in case of alarm |
| Davidroid | 5:0845d4141a01 | 176 | */ |
| Davidroid | 5:0845d4141a01 | 177 | virtual uint8_t over_temp_alarm(void) |
| Davidroid | 5:0845d4141a01 | 178 | { |
| Davidroid | 5:0845d4141a01 | 179 | return (uint8_t) CLT01_38S_OverTempAlarm(); |
| Davidroid | 5:0845d4141a01 | 180 | } |
| Davidroid | 5:0845d4141a01 | 181 | |
| Davidroid | 5:0845d4141a01 | 182 | /** |
| Davidroid | 5:0845d4141a01 | 183 | * @brief Parity Check bits |
| Davidroid | 5:0845d4141a01 | 184 | * @param None |
| Davidroid | 5:0845d4141a01 | 185 | * @retval Parity bits for diagnosing inconsistency in data transmission |
| Davidroid | 5:0845d4141a01 | 186 | */ |
| Davidroid | 5:0845d4141a01 | 187 | virtual uint8_t check_parity(void) |
| Davidroid | 5:0845d4141a01 | 188 | { |
| Davidroid | 5:0845d4141a01 | 189 | return (uint8_t) CLT01_38S_CheckParity(); |
| Davidroid | 5:0845d4141a01 | 190 | } |
| Davidroid | 5:0845d4141a01 | 191 | |
| Davidroid | 5:0845d4141a01 | 192 | /** |
| Davidroid | 5:0845d4141a01 | 193 | * @brief Under Voltage Alarm bit |
| Davidroid | 5:0845d4141a01 | 194 | * @param None |
| Davidroid | 5:0845d4141a01 | 195 | * @retval Under voltage alarm bit, 1 in case of alarm |
| Davidroid | 5:0845d4141a01 | 196 | */ |
| Davidroid | 5:0845d4141a01 | 197 | virtual uint8_t under_volt_alarm(void) |
| Davidroid | 5:0845d4141a01 | 198 | { |
| Davidroid | 5:0845d4141a01 | 199 | return (uint8_t) CLT01_38S_UnderVoltAlarm(); |
| Davidroid | 5:0845d4141a01 | 200 | } |
| Davidroid | 5:0845d4141a01 | 201 | |
| Davidroid | 5:0845d4141a01 | 202 | /** |
| Davidroid | 5:0845d4141a01 | 203 | * @brief Get input information from output channels component |
| Davidroid | 5:0845d4141a01 | 204 | * @param TX buffer |
| Davidroid | 5:0845d4141a01 | 205 | * @param RX buffer |
| Davidroid | 5:0845d4141a01 | 206 | * @retval None |
| Davidroid | 5:0845d4141a01 | 207 | */ |
| Davidroid | 5:0845d4141a01 | 208 | virtual void dig_inp_array_get_input(uint8_t *inputArray) |
| Davidroid | 5:0845d4141a01 | 209 | { |
| Davidroid | 5:0845d4141a01 | 210 | CLT01_38S_DigInpArray_GetInput(inputArray); |
| Davidroid | 5:0845d4141a01 | 211 | } |
| Davidroid | 5:0845d4141a01 | 212 | |
| Davidroid | 5:0845d4141a01 | 213 | /* Auxiliary method to enable or disable SPI CS pin */ |
| Davidroid | 5:0845d4141a01 | 214 | virtual void set_input_spi(uint8_t l) |
| Davidroid | 5:0845d4141a01 | 215 | { |
| Davidroid | 5:0845d4141a01 | 216 | ssel = l; |
| Davidroid | 5:0845d4141a01 | 217 | } |
| Davidroid | 5:0845d4141a01 | 218 | |
| Davidroid | 5:0845d4141a01 | 219 | protected: |
| Davidroid | 5:0845d4141a01 | 220 | |
| Davidroid | 5:0845d4141a01 | 221 | /*** Protected Component Related Methods ***/ |
| Davidroid | 5:0845d4141a01 | 222 | |
| Davidroid | 5:0845d4141a01 | 223 | /* ACTION 7 --------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 224 | * Declare here the component's specific methods. * |
| Davidroid | 5:0845d4141a01 | 225 | * They should be: * |
| Davidroid | 5:0845d4141a01 | 226 | * + Methods with the same name of the C component's virtual table's * |
| Davidroid | 5:0845d4141a01 | 227 | * functions (1); * |
| Davidroid | 5:0845d4141a01 | 228 | * + Methods with the same name of the C component's extended virtual * |
| Davidroid | 5:0845d4141a01 | 229 | * table's functions, if any (2); * |
| Davidroid | 5:0845d4141a01 | 230 | * + Helper methods, if any, like functions declared in the component's * |
| Davidroid | 5:0845d4141a01 | 231 | * source files but not pointed by the component's virtual table (3). * |
| Davidroid | 5:0845d4141a01 | 232 | * * |
| Davidroid | 5:0845d4141a01 | 233 | * Example: * |
| Davidroid | 5:0845d4141a01 | 234 | * status_t COMPONENT_Init(void *init); * |
| Davidroid | 5:0845d4141a01 | 235 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 236 | status_t CLT01_38S_Init(void *init); |
| Davidroid | 5:0845d4141a01 | 237 | status_t CLT01_38S_ReadID(uint8_t *id); |
| Davidroid | 5:0845d4141a01 | 238 | uint8_t CLT01_38S_GetReadStatus(void); |
| Davidroid | 5:0845d4141a01 | 239 | void CLT01_38S_SetReadStatus(uint8_t status); |
| Davidroid | 5:0845d4141a01 | 240 | uint8_t CLT01_38S_GetInputData(void); |
| Davidroid | 5:0845d4141a01 | 241 | status_t CLT01_38S_OverTempAlarm(void); |
| Davidroid | 5:0845d4141a01 | 242 | uint8_t CLT01_38S_CheckParity(void); |
| Davidroid | 5:0845d4141a01 | 243 | status_t CLT01_38S_UnderVoltAlarm(void); |
| Davidroid | 5:0845d4141a01 | 244 | void CLT01_38S_DigInpArray_GetInput(uint8_t *inputArray); |
| Davidroid | 5:0845d4141a01 | 245 | |
| Davidroid | 5:0845d4141a01 | 246 | /*** Component's I/O Methods ***/ |
| Davidroid | 5:0845d4141a01 | 247 | |
| Davidroid | 5:0845d4141a01 | 248 | /** |
| Davidroid | 5:0845d4141a01 | 249 | * @brief Utility function to read and write data from/to CLT01_38S at the same time. |
| Davidroid | 5:0845d4141a01 | 250 | * @param[out] pBufferToRead pointer to the buffer to read data into. |
| Davidroid | 5:0845d4141a01 | 251 | * @param[in] pBufferToWrite pointer to the buffer of data to send. |
| Davidroid | 5:0845d4141a01 | 252 | * @param[in] NumValues number of values to read and write. |
| Davidroid | 5:0845d4141a01 | 253 | * @retval COMPONENT_OK in case of success, COMPONENT_ERROR otherwise. |
| Davidroid | 5:0845d4141a01 | 254 | */ |
| Davidroid | 5:0845d4141a01 | 255 | status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumValues) |
| Davidroid | 5:0845d4141a01 | 256 | { |
| Davidroid | 5:0845d4141a01 | 257 | (void) NumValues; |
| Davidroid | 5:0845d4141a01 | 258 | uint16_t dataToRead; |
| Davidroid | 5:0845d4141a01 | 259 | uint16_t dataToWrite; |
| Davidroid | 5:0845d4141a01 | 260 | |
| Davidroid | 5:0845d4141a01 | 261 | // Converts two uint8_t words into one of uint16_t |
| Davidroid | 5:0845d4141a01 | 262 | dataToWrite = convertFrom8To16(pBufferToWrite); |
| Davidroid | 5:0845d4141a01 | 263 | |
| Davidroid | 5:0845d4141a01 | 264 | // Select the chip. |
| Davidroid | 5:0845d4141a01 | 265 | ssel = 0; |
| Davidroid | 5:0845d4141a01 | 266 | |
| Davidroid | 5:0845d4141a01 | 267 | dataToRead = dev_spi.write(dataToWrite); |
| Davidroid | 5:0845d4141a01 | 268 | |
| Davidroid | 5:0845d4141a01 | 269 | // Unselect the chip. |
| Davidroid | 5:0845d4141a01 | 270 | ssel = 1; |
| Davidroid | 5:0845d4141a01 | 271 | |
| Davidroid | 5:0845d4141a01 | 272 | // Converts one uint16_t word into two uint8_t |
| Davidroid | 5:0845d4141a01 | 273 | convertFrom16To8(dataToRead, pBufferToRead); |
| Davidroid | 5:0845d4141a01 | 274 | |
| Davidroid | 5:0845d4141a01 | 275 | return COMPONENT_OK; |
| Davidroid | 5:0845d4141a01 | 276 | } |
| Davidroid | 5:0845d4141a01 | 277 | |
| Davidroid | 5:0845d4141a01 | 278 | /* ACTION 8 --------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 279 | * Implement here other I/O methods beyond those already implemented * |
| Davidroid | 5:0845d4141a01 | 280 | * above, which are declared extern within the component's header file. * |
| Davidroid | 5:0845d4141a01 | 281 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 282 | /** |
| Davidroid | 5:0845d4141a01 | 283 | * @brief Making the CPU wait. |
| Davidroid | 5:0845d4141a01 | 284 | * @param None. |
| Davidroid | 5:0845d4141a01 | 285 | * @retval None. |
| Davidroid | 5:0845d4141a01 | 286 | */ |
| Davidroid | 5:0845d4141a01 | 287 | void CLT01_38S_Delay(uint32_t delay) |
| Davidroid | 5:0845d4141a01 | 288 | { |
| apalmieri | 7:5d4336d0e372 | 289 | ThisThread::sleep_for(chrono::milliseconds(delay)); |
| Davidroid | 5:0845d4141a01 | 290 | } |
| Davidroid | 5:0845d4141a01 | 291 | |
| Davidroid | 5:0845d4141a01 | 292 | /** |
| Davidroid | 5:0845d4141a01 | 293 | * @brief Writing and reading bytes to/from the component through the SPI at the same time. |
| Davidroid | 5:0845d4141a01 | 294 | * @param[in] pByteToTransmit pointer to the buffer of data to send. |
| Davidroid | 5:0845d4141a01 | 295 | * @param[out] pReceivedByte pointer to the buffer to read data into. |
| Davidroid | 5:0845d4141a01 | 296 | * @retval "0" in case of success, "1" otherwise. |
| Davidroid | 5:0845d4141a01 | 297 | */ |
| Davidroid | 5:0845d4141a01 | 298 | uint8_t CLT01_38S_SpiReadBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte) |
| Davidroid | 5:0845d4141a01 | 299 | { |
| Davidroid | 5:0845d4141a01 | 300 | return (uint8_t) (ReadWrite(pReceivedByte, pByteToTransmit, BUFFERSIZE) == COMPONENT_OK ? 0 : 1); |
| Davidroid | 5:0845d4141a01 | 301 | } |
| Davidroid | 5:0845d4141a01 | 302 | |
| Davidroid | 5:0845d4141a01 | 303 | |
| Davidroid | 5:0845d4141a01 | 304 | /*** Component's Instance Variables ***/ |
| Davidroid | 5:0845d4141a01 | 305 | |
| Davidroid | 5:0845d4141a01 | 306 | /* ACTION 9 --------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 307 | * Declare here interrupt related variables, if needed. * |
| Davidroid | 5:0845d4141a01 | 308 | * Note that interrupt handling is platform dependent, see * |
| Davidroid | 5:0845d4141a01 | 309 | * "Interrupt Related Methods" above. * |
| Davidroid | 5:0845d4141a01 | 310 | * * |
| Davidroid | 5:0845d4141a01 | 311 | * Example: * |
| Davidroid | 5:0845d4141a01 | 312 | * + mbed: * |
| Davidroid | 5:0845d4141a01 | 313 | * InterruptIn feature_irq; * |
| Davidroid | 5:0845d4141a01 | 314 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 315 | |
| Davidroid | 5:0845d4141a01 | 316 | /* ACTION 10 -------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 317 | * Declare here other pin related variables, if needed. * |
| Davidroid | 5:0845d4141a01 | 318 | * * |
| Davidroid | 5:0845d4141a01 | 319 | * Example: * |
| Davidroid | 5:0845d4141a01 | 320 | * + mbed: * |
| Davidroid | 5:0845d4141a01 | 321 | * PwmOut pwm; * |
| Davidroid | 5:0845d4141a01 | 322 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 323 | |
| Davidroid | 5:0845d4141a01 | 324 | /* ACTION 11 -------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 325 | * Declare here communication related variables, if needed. * |
| Davidroid | 5:0845d4141a01 | 326 | * * |
| Davidroid | 5:0845d4141a01 | 327 | * Example: * |
| Davidroid | 5:0845d4141a01 | 328 | * + mbed: * |
| Davidroid | 5:0845d4141a01 | 329 | * DigitalOut ssel; * |
| Davidroid | 5:0845d4141a01 | 330 | * SPI &dev_spi; * |
| Davidroid | 5:0845d4141a01 | 331 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 332 | /* Configuration. */ |
| Davidroid | 5:0845d4141a01 | 333 | DigitalOut ssel; |
| Davidroid | 5:0845d4141a01 | 334 | |
| Davidroid | 5:0845d4141a01 | 335 | /* IO Device. */ |
| Davidroid | 5:0845d4141a01 | 336 | SPI &dev_spi; |
| Davidroid | 5:0845d4141a01 | 337 | |
| Davidroid | 5:0845d4141a01 | 338 | /* ACTION 12 -------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 339 | * Declare here identity related variables, if needed. * |
| Davidroid | 5:0845d4141a01 | 340 | * Note that there should be only a unique identifier for each component, * |
| Davidroid | 5:0845d4141a01 | 341 | * which should be the "who_am_i" parameter. * |
| Davidroid | 5:0845d4141a01 | 342 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 343 | /* Identity */ |
| Davidroid | 5:0845d4141a01 | 344 | uint8_t who_am_i; |
| Davidroid | 5:0845d4141a01 | 345 | |
| Davidroid | 5:0845d4141a01 | 346 | /* ACTION 13 -------------------------------------------------------------* |
| Davidroid | 5:0845d4141a01 | 347 | * Declare here the component's static and non-static data, one variable * |
| Davidroid | 5:0845d4141a01 | 348 | * per line. * |
| Davidroid | 5:0845d4141a01 | 349 | * * |
| Davidroid | 5:0845d4141a01 | 350 | * Example: * |
| Davidroid | 5:0845d4141a01 | 351 | * float measure; * |
| Davidroid | 5:0845d4141a01 | 352 | * int instance_id; * |
| Davidroid | 5:0845d4141a01 | 353 | * static int number_of_instances; * |
| Davidroid | 5:0845d4141a01 | 354 | *------------------------------------------------------------------------*/ |
| Davidroid | 5:0845d4141a01 | 355 | /* Data. */ |
| Davidroid | 5:0845d4141a01 | 356 | uint8_t plc_input_component_instance; |
| Davidroid | 5:0845d4141a01 | 357 | |
| Davidroid | 5:0845d4141a01 | 358 | uint8_t OTA_Buffer; |
| Davidroid | 5:0845d4141a01 | 359 | uint8_t CLT_PARITY_Buffer; |
| Davidroid | 5:0845d4141a01 | 360 | uint8_t UVA_Buffer; |
| Davidroid | 5:0845d4141a01 | 361 | uint8_t CLT_INPUT_STATUS_Buffer; |
| Davidroid | 5:0845d4141a01 | 362 | uint8_t FLAG_CLT_READ; |
| Davidroid | 5:0845d4141a01 | 363 | |
| Davidroid | 5:0845d4141a01 | 364 | /* Static data. */ |
| Davidroid | 5:0845d4141a01 | 365 | static uint8_t number_of_plc_input_components; |
| Davidroid | 5:0845d4141a01 | 366 | |
| Davidroid | 5:0845d4141a01 | 367 | /* Digital Input Array buffers for SPI communication */ |
| Davidroid | 5:0845d4141a01 | 368 | uint8_t spi_tx_buff[NB_BYTES]; |
| Davidroid | 5:0845d4141a01 | 369 | uint8_t spi_rx_buff[NB_BYTES]; |
| Davidroid | 5:0845d4141a01 | 370 | |
| Davidroid | 5:0845d4141a01 | 371 | |
| Davidroid | 5:0845d4141a01 | 372 | public: |
| Davidroid | 5:0845d4141a01 | 373 | |
| Davidroid | 5:0845d4141a01 | 374 | /* Static data. */ |
| Davidroid | 5:0845d4141a01 | 375 | }; |
| Davidroid | 5:0845d4141a01 | 376 | |
| Davidroid | 5:0845d4141a01 | 377 | #endif // __CLT01_38S_CLASS_H |
| Davidroid | 5:0845d4141a01 | 378 | |
| Davidroid | 5:0845d4141a01 | 379 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
X-NUCLEO-PLC01A1 Programmable Logic Controller