{"id":24452666,"url":"https://github.com/hiperiondev/ladderlib","last_synced_at":"2026-04-28T19:02:07.759Z","repository":{"id":282356535,"uuid":"942326411","full_name":"hiperiondev/ladderlib","owner":"hiperiondev","description":"Library for execute ladder logic","archived":false,"fork":false,"pushed_at":"2025-12-14T12:54:44.000Z","size":450,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-29T23:28:55.475Z","etag":null,"topics":["automation","iec61131","iec61131-3","ladder","ladder-diagram","ladder-logic","ladder-network","ladder-programming","ladders","microcontroller","microcontrollers","plc","plc-controller","plc-programming"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hiperiondev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-03T23:51:32.000Z","updated_at":"2025-12-17T07:39:38.000Z","dependencies_parsed_at":"2025-12-28T00:02:38.015Z","dependency_job_id":null,"html_url":"https://github.com/hiperiondev/ladderlib","commit_stats":null,"previous_names":["hiperiondev/ladderlib"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/hiperiondev/ladderlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2Fladderlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2Fladderlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2Fladderlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2Fladderlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hiperiondev","download_url":"https://codeload.github.com/hiperiondev/ladderlib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hiperiondev%2Fladderlib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32394478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","iec61131","iec61131-3","ladder","ladder-diagram","ladder-logic","ladder-network","ladder-programming","ladders","microcontroller","microcontrollers","plc","plc-controller","plc-programming"],"created_at":"2025-01-21T01:16:41.051Z","updated_at":"2026-04-28T19:02:07.751Z","avatar_url":"https://github.com/hiperiondev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"readme-top\"\u003e\u003c/a\u003e\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/hiperiondev/ladderlib\"\u003e\n    \u003cimg src=\"images/logo.png\" alt=\"Logo\" width=\"140\" height=\"80\"\u003e\n  \u003c/a\u003e\n\n\u003ch3 align=\"center\"\u003eLadderlib\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    C library for ladder logic programming\n    \u003cbr /\u003e   \n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\nLadderlib is a C library designed for implementing ladder logic programming, a method widely used in Programmable Logic Controllers (PLCs) for industrial automation. It provides a robust framework to define, execute, and manage ladder logic programs, supporting hardware interactions and custom function extensions.\n\nLadderlib enables developers to create ladder logic programs, which are graphical representations of control logic resembling electrical relay circuits. These programs are executed cyclically by PLCs to automate industrial processes, such as controlling machinery in manufacturing or chemical processing. The library  supports defining logic through cells and networks, managing execution states, handling hardware inputs/outputs, and integrating custom functions for enhanced flexibility.  \n  \nKey features include:  \n- **Instruction Set**: 39 instructions for defining logic operations.  \n- **State Management**: 6 states to control program execution.  \n- **Error Handling**: 8 error codes for robust operation.  \n- **Hardware Integration**: Function pointers for reading inputs and writing outputs.  \n- **Custom Extensions**: Support for adding user-defined functions.  \n  \nThe library is likely optimized for embedded systems.\n \n## Introduction to Ladder Logic  \nLadder logic programming stands as the fundamental programming language for Programmable Logic Controllers (PLCs), powering approximately 80% of industrial automation systems worldwide.\n\nIt’s a visual programming methodology that evolved from traditional relay-based control systems, provides an intuitive approach to implementing complex control logic in manufacturing processes.\nThe purpose of ladder logic programming is to simplify the process of programming and controlling complex machinery, such as assembly lines and manufacturing equipment.\nThe transition from physical relay panels to digital programming has maintained the familiar ladder diagram format while incorporating advanced digital capabilities, making it the preferred choice for automation engineers and technicians.\n\nLadder logic is a fast and simple way of creating logic expressions for a PLC in order to automate repetitive machine tasks and sequences. It is used in a multitude of industrial automation applications.\n\n[Ladder in Wikipedia](https://en.wikipedia.org/wiki/Ladder_logic)\n\n# Table of Contents\n\n- [Basic Logic Instructions](#INSTRUCTIONS)\n- [API Documentation](#APIDOC)\n- [Enums and Structures](#ENUMS)\n- [Callback Prototypes](#CALLBACKS)\n- [Basic Usage](#BASICUSAGE)\n- [Contributing](#CONTRIBUTING)\n- [License](#LICENCE)\n- [Contact](#CONTACT)\n\n\u003c!-- INSTRUCTIONS --\u003e\n## Basic Logic Instructions  \n\n### Instruction Summary Table  \nThe following table summarizes the instructions, their codes, categories, and symbols.  \n  \n| Instruction | Code | Category | Symbol | Description |  \n|-------------|------|----------|--------|-------------|  \n| NOP | 0 | Specialized | None | No operation, placeholder |  \n| CONN | 1 | Specialized | Vertical lines | Connects rungs or branches |  \n| NEG | 2 | Specialized |  \u003cimg src=\"images/png/NEG.png\" alt=\"Image\"\u003e | Inverts logic state |  \n| NO | 3 | Basic Logic | \u003cimg src=\"images/png/NO.png\" alt=\"Image\"\u003e | Normally Open contact |  \n| NC | 4 | Basic Logic |  \u003cimg src=\"images/png/NC.png\" alt=\"Image\"\u003e | Normally Closed contact |  \n| RE | 5 | Specialized |  \u003cimg src=\"images/png/RE.png\" alt=\"Image\"\u003e | Rising edge detection |  \n| FE | 6 | Specialized |  \u003cimg src=\"images/png/FE.png\" alt=\"Image\"\u003e | Falling edge detection |  \n| COIL | 7 | Basic Logic |  \u003cimg src=\"images/png/COIL.png\" alt=\"Image\"\u003e | Output coil |  \n| COILL | 8 | Basic Logic |  \u003cimg src=\"images/png/COILL.png\" alt=\"Image\"\u003e | Latched coil |  \n| COILU | 9 | Basic Logic |  \u003cimg src=\"images/png/COILU.png\" alt=\"Image\"\u003e | Unlatched coil |  \n| TON | 10 | Timer |  \u003cimg src=\"images/png/TON.png\" alt=\"Image\"\u003e | Timer On Delay |  \n| TOFF | 11 | Timer |  \u003cimg src=\"images/png/TOF.png\" alt=\"Image\"\u003e | Timer Off Delay |  \n| TP | 12 | Timer |  \u003cimg src=\"images/png/TP.png\" alt=\"Image\"\u003e | Timer Pulse |  \n| CTU | 13 | Counter |  \u003cimg src=\"images/png/CTU.png\" alt=\"Image\"\u003e | Count Up |  \n| CTD | 14 | Counter |  \u003cimg src=\"images/png/CTD.png\" alt=\"Image\"\u003e | Count Down |  \n| MOVE | 15 | Specialized | \u003cimg src=\"images/png/MOV.png\" alt=\"Image\"\u003e | Moves data |  \n| SUB | 16 | Arithmetic |  \u003cimg src=\"images/png/SUB.png\" alt=\"Image\"\u003e | Subtraction |  \n| ADD | 17 | Arithmetic | \u003cimg src=\"images/png/ADD.png\" alt=\"Image\"\u003e | Addition |  \n| MUL | 18 | Arithmetic | \u003cimg src=\"images/png/MUL.png\" alt=\"Image\"\u003e | Multiplication |  \n| DIV | 19 | Arithmetic | \u003cimg src=\"images/png/DIV.png\" alt=\"Image\"\u003e| Division |  \n| MOD | 20 | Arithmetic | \u003cimg src=\"images/png/MOD.png\" alt=\"Image\"\u003e | Modulus |  \n| SHL | 21 | Bitwise | \u003cimg src=\"images/png/SHL.png\" alt=\"Image\"\u003e | Shift Left |  \n| SHR | 22 | Bitwise | \u003cimg src=\"images/png/SHR.png\" alt=\"Image\"\u003e | Shift Right |  \n| ROL | 23 | Bitwise | \u003cimg src=\"images/png/ROL.png\" alt=\"Image\"\u003e | Rotate Left |  \n| ROR | 24 | Bitwise | \u003cimg src=\"images/png/ROR.png\" alt=\"Image\"\u003e | Rotate Right |  \n| AND | 25 | Bitwise | \u003cimg src=\"images/png/AND.png\" alt=\"Image\"\u003e | Bitwise AND |  \n| OR | 26 | Bitwise | \u003cimg src=\"images/png/OR.png\" alt=\"Image\"\u003e | Bitwise OR |  \n| XOR | 27 | Bitwise | \u003cimg src=\"images/png/XOR.png\" alt=\"Image\"\u003e | Bitwise XOR |  \n| NOT | 28 | Bitwise | \u003cimg src=\"images/png/NOT.png\" alt=\"Image\"\u003e | Bitwise NOT |  \n| EQ | 29 | Comparison | \u003cimg src=\"images/png/EQ.png\" alt=\"Image\"\u003e | Equal |  \n| GT | 30 | Comparison | \u003cimg src=\"images/png/GT.png\" alt=\"Image\"\u003e | Greater Than |  \n| GE | 31 | Comparison | \u003cimg src=\"images/png/GE.png\" alt=\"Image\"\u003e | Greater Than or Equal |  \n| LT | 32 | Comparison | \u003cimg src=\"images/png/LT.png\" alt=\"Image\"\u003e | Less Than |  \n| LE | 33 | Comparison | \u003cimg src=\"images/png/LE.png\" alt=\"Image\"\u003e | Less Than or Equal |  \n| NE | 34 | Comparison | \u003cimg src=\"images/png/NE.png\" alt=\"Image\"\u003e | Not Equal |  \n| FOREIGN | 35 | Specialized | Box labeled \"FOREIGN\" | External function call |  \n| TMOVE | 36 | Specialized | \u003cimg src=\"images/png/TMOV.png\" alt=\"Image\"\u003e | Table data move |  \n| INV | 37 | Specialized | None | Invalid instruction |\n\n## Basic Instructions\nBasic instructions manage Input/Output functions\n  \n### NO (Normally Open Contact)  \n- **Instruction Code:** `LADDER_INS_NO` (3)  \n- **Description:** The Normally Open contact allows logic flow when its associated input is true, acting like a switch that closes when activated. It is used to check if an input condition (e.g., a sensor) is met.  \n- **Example Use:** Checking if a pushbutton is pressed to activate a motor.  \n  \n### NC (Normally Closed Contact)  \n- **Instruction Code:** `LADDER_INS_NC` (4)  \n- **Description:** The Normally Closed contact allows logic flow when its associated input is false, acting like a switch that opens when activated. It is used to proceed when a condition is not met.  \n- **Example Use:** Ensuring a safety switch is not triggered before starting a process.  \n  \n### COIL (Output Coil)  \n- **Instruction Code:** `LADDER_INS_COIL` (7)  \n- **Description:** The Coil instruction sets an output to true when the rung's logic is true, controlling devices like motors or lights. It represents the action taken when conditions are satisfied.  \n- **Example Use:** Turning on a conveyor belt when all conditions are met.  \n  \n### COILL (Coil Latch)  \n- **Instruction Code:** `LADDER_INS_COILL` (8)  \n- **Description:** The Coil Latch sets an output to true and maintains it (latches) even if the input conditions change, until unlatched. It is used for memory functions in control systems.  \n- **Example Use:** Keeping a pump running after a start button is released.  \n  \n### COILU (Coil Unlatch)  \n- **Instruction Code:** `LADDER_INS_COILU` (9)  \n- **Description:** The Coil Unlatch resets a latched output to false, releasing the latched state. It is paired with `COILL` for set/reset operations.  \n- **Example Use:** Stopping a latched pump when a stop button is pressed.  \n  \n## Timer Instructions  \nTimer instructions manage time-based operations, delaying or pulsing outputs.  \n  \n### TON (Timer On Delay)  \n- **Instruction Code:** `LADDER_INS_TON` (10)  \n- **Description:** The Timer On Delay starts timing when its input is true. After a preset time, the output becomes true. It is used to delay actions, such as waiting before starting a motor.  \n- **Example Use:** Delaying a fan activation for 10 seconds after a heater starts.  \n  \n### TOFF (Timer Off Delay)  \n- **Instruction Code:** `LADDER_INS_TOFF` (11)  \n- **Description:** The Timer Off Delay starts timing when its input goes false. After a preset time, the output becomes false. It is used to extend the duration of an output.  \n- **Example Use:** Keeping a light on for 5 seconds after a switch is turned off.  \n  \n### TP (Timer Pulse)  \n- **Instruction Code:** `LADDER_INS_TP` (12)  \n- **Description:** The Timer Pulse generates a pulse of a specified duration when triggered by a true input. It is used for creating timed signals, such as a brief alarm.  \n- **Example Use:** Activating a buzzer for 2 seconds when a fault is detected.  \n  \n## Counter Instructions  \nCounter instructions track the number of events or occurrences.  \n  \n### CTU (Count Up)  \n- **Instruction Code:** `LADDER_INS_CTU` (13)  \n- **Description:** The Count Up counter increments its count each time the input transitions from false to true, up to a preset value. It is used to count items or events.  \n- **Example Use:** Counting the number of boxes on a conveyor belt.  \n  \n### CTD (Count Down)  \n- **Instruction Code:** `LADDER_INS_CTD` (14)  \n- **Description:** The Count Down counter decrements its count each time the input transitions from false to true, down to zero. It is used for countdown tasks.  \n- **Example Use:** Tracking remaining items in a batch process.  \n  \n## Arithmetic Instructions  \nThese instructions perform mathematical operations on data.  \n  \n### ADD (Addition)  \n- **Instruction Code:** `LADDER_INS_ADD` (17)  \n- **Description:** Adds two values and stores the result in a specified location. It is used for calculations like summing sensor readings.  \n- **Example Use:** Adding the outputs of two flow sensors.  \n  \n### SUB (Subtraction)  \n- **Instruction Code:** `LADDER_INS_SUB` (16)  \n- **Description:** Subtracts one value from another and stores the result. It is used for differential calculations.  \n- **Example Use:** Calculating the difference in pressure between two points.  \n  \n### MUL (Multiplication)  \n- **Instruction Code:** `LADDER_INS_MUL` (18)  \n- **Description:** Multiplies two values and stores the result. It is used for scaling or area calculations.  \n- **Example Use:** Calculating power by multiplying voltage and current.  \n  \n### DIV (Division)  \n- **Instruction Code:** `LADDER_INS_DIV` (19)  \n- **Description:** Divides one value by another and stores the result. It is used for ratio calculations.  \n- **Example Use:** Determining speed by dividing distance by time.  \n  \n### MOD (Modulus)  \n- **Instruction Code:** `LADDER_INS_MOD` (20)  \n- **Description:** Computes the remainder of dividing one value by another. It is used for cyclic operations or remainder checks.  \n- **Example Use:** Checking if a counter value is even or odd.  \n  \n## Bitwise Operation Instructions  \nThese instructions manipulate bits within data values.  \n  \n### SHL (Shift Left)  \n- **Instruction Code:** `LADDER_INS_SHL` (21)  \n- **Description:** Shifts the bits of a value to the left by a specified number of positions, filling with zeros. It is used for bit manipulation or scaling.  \n- **Example Use:** Doubling a binary value by shifting left.  \n  \n### SHR (Shift Right)  \n- **Instruction Code:** `LADDER_INS_SHR` (22)  \n- **Description:** Shifts the bits of a value to the right by a specified number of positions, filling with zeros or sign bits. It is used for division or bit extraction.  \n- **Example Use:** Halving a binary value by shifting right.  \n  \n### ROL (Rotate Left)  \n- **Instruction Code:** `LADDER_INS_ROL` (23)  \n- **Description:** Rotates the bits of a value to the left, with the most significant bit wrapping around to the least significant position. It is used for circular shifts.  \n- **Example Use:** Rotating status flags in a control word.  \n  \n### ROR (Rotate Right)  \n- **Instruction Code:** `LADDER_INS_ROR` (24)  \n- **Description:** Rotates the bits of a value to the right, with the least significant bit wrapping around to the most significant position. It is used for circular shifts.  \n- **Example Use:** Cycling through a set of control bits.  \n  \n### AND (Bitwise AND)  \n- **Instruction Code:** `LADDER_INS_AND` (25)  \n- **Description:** Performs a bitwise AND operation on two values, setting output bits to 1 only where both inputs are 1. It is used for masking or condition checks.  \n- **Example Use:** Masking specific bits in a status register.  \n  \n### OR (Bitwise OR)  \n- **Instruction Code:** `LADDER_INS_OR` (26)  \n- **Description:** Performs a bitwise OR operation on two values, setting output bits to 1 where either input is 1. It is used for combining conditions.  \n- **Example Use:** Combining multiple fault flags.  \n  \n### XOR (Bitwise XOR)  \n- **Instruction Code:** `LADDER_INS_XOR` (27)  \n- **Description:** Performs a bitwise XOR operation on two values, setting output bits to 1 where inputs differ. It is used for toggling or comparison.  \n- **Example Use:** Detecting changes in bit patterns.  \n  \n### NOT (Bitwise NOT)  \n- **Instruction Code:** `LADDER_INS_NOT` (28)  \n- **Description:** Performs a bitwise NOT operation, inverting all bits of a value. It is used for logical negation.  \n- **Example Use:** Inverting a control signal.  \n  \n## Comparison Instructions  \nThese instructions compare values and produce boolean outputs.  \n  \n### EQ (Equal)  \n- **Instruction Code:** `LADDER_INS_EQ` (29)  \n- **Description:** Checks if two values are equal, outputting true if they are. It is used for equality checks in control logic.  \n- **Example Use:** Verifying if a temperature reading matches a setpoint.  \n  \n### GT (Greater Than)  \n- **Instruction Code:** `LADDER_INS_GT` (30)  \n- **Description:** Checks if one value is greater than another, outputting true if so. It is used for threshold checks.  \n- **Example Use:** Checking if pressure exceeds a safe limit.  \n  \n### GE (Greater Than or Equal)  \n- **Instruction Code:** `LADDER_INS_GE` (31)  \n- **Description:** Checks if one value is greater than or equal to another, outputting true if so. It is used for inclusive threshold checks.  \n- **Example Use:** Ensuring a tank level is at or above a minimum.  \n  \n### LT (Less Than)  \n- **Instruction Code:** `LADDER_INS_LT` (32)  \n- **Description:** Checks if one value is less than another, outputting true if so. It is used for lower-bound checks.  \n- **Example Use:** Detecting if a speed is below a target.  \n  \n### LE (Less Than or Equal)  \n- **Instruction Code:** `LADDER_INS_LE` (33)  \n- **Description:** Checks if one value is less than or equal to another, outputting true if so. It is used for inclusive lower-bound checks.  \n- **Example Use:** Verifying a flow rate is at or below a maximum.  \n  \n### NE (Not Equal)  \n- **Instruction Code:** `LADDER_INS_NE` (34)  \n- **Description:** Checks if two values are not equal, outputting true if they differ. It is used for change detection.  \n- **Example Use:** Detecting a change in a sensor value.  \n  \n## Specialized Instructions  \nThese instructions provide additional functionality, some of which may be specific to ladderlib.  \n  \n### NOP (No Operation)  \n- **Instruction Code:** `LADDER_INS_NOP` (0)  \n- **Description:** Performs no operation, acting as a placeholder or for timing purposes. It does not affect the program state.  \n- **Example Use:** Reserving space for future instructions.  \n  \n### CONN (Connection)  \n- **Instruction Code:** `LADDER_INS_CONN` (1)  \n- **Description:** Likely used to connect different parts of the ladder diagram, such as branching or joining rungs. It facilitates complex logic structures.  \n- **Example Use:** Linking parallel branches in a rung.  \n  \n### NEG (Negate)  \n- **Instruction Code:** `LADDER_INS_NEG` (2)  \n- **Description:** Inverts the logic state of an input, turning true to false or vice versa. It is used to reverse conditions.  \n- **Example Use:** Inverting a stop signal to enable a process.  \n  \n### RE (Rising Edge)  \n- **Instruction Code:** `LADDER_INS_RE` (5)  \n- **Description:** Detects a rising edge, triggering when an input transitions from false to true. It is used for event-driven actions.  \n- **Example Use:** Starting a counter when a button is pressed.  \n  \n### FE (Falling Edge)  \n- **Instruction Code:** `LADDER_INS_FE` (6)  \n- **Description:** Detects a falling edge, triggering when an input transitions from true to false. It is used for event-driven actions.  \n- **Example Use:** Resetting a system when a sensor deactivates.  \n  \n### MOVE (Move Data)  \n- **Instruction Code:** `LADDER_INS_MOVE` (15)  \n- **Description:** Copies data from one memory location to another without modification. It is used for data transfer.  \n- **Example Use:** Transferring a sensor value to a display register.  \n  \n### TMOVE (Table Move)  \n- **Instruction Code:** `LADDER_INS_TMOVE` (36)  \n- **Description:** Likely used for moving data within tables or arrays, possibly for batch processing or data manipulation. The exact functionality may depend a lot on ladderlib's implementation.  \n- **Example Use:** Moving a set of values to a new memory block.  \n  \n### FOREIGN (Foreign Function)  \n- **Instruction Code:** `LADDER_INS_FOREIGN` (35)  \n- **Description:** Allows calling external or user-defined functions not natively supported by ladder logic. It enables integration with custom code.  \n- **Example Use:** Calling a custom algorithm for complex calculations.  \n  \n### INV (Invalid)  \n- **Instruction Code:** `LADDER_INS_INV` (37)  \n- **Description:** Marks the beginning of invalid instruction codes, not intended for use in programs. It serves as a boundary for valid instructions.  \n- **Example Use:** None, as it is not used in programming.  \n  \n### MULTI (Multi-cell Instruction)  \n- **Instruction Code:** `LADDER_INS_MULTI` (255, 0xff)  \n- **Description:** Indicates that the cell is part of a larger instruction spanning multiple cells, used for complex operations requiring additional data.  \n- **Example Use:** Implementing a multi-step operation like a sequence control.\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- APIDOC --\u003e\n## API Documentation  \n  \nThis section provides detailed documentation for the core API functions of LadderLib, extracted from the header files `ladder.h`, `ladder_instructions.h`, and `ladder_internals.h`.  \n  \n### ladder_init  \n  \nInitializes the ladder context with specified parameters for networks, memory, inputs, outputs, timers, counters, and blocks.  \n  \n```c  \nbool ladder_ctx_init(ladder_ctx_t *ladder_ctx, uint8_t net_columns_qty, uint8_t net_rows_qty, uint32_t networks_qty, uint32_t qty_m, uint32_t qty_c, uint32_t qty_t, uint32_t qty_d, uint32_t qty_r, bool init_netwok)  \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `net_columns_qty` | Number of columns in networks (max 32). Defines the width of each network grid. |  \n| `net_rows_qty` | Number of rows in networks. Defines the height of each network grid. |  \n| `networks_qty` | Number of networks. Specifies how many ladder networks the context will manage. |  \n| `qty_m` | Quantity of memory bits. Number of general-purpose memory bits available. |  \n| `qty_c` | Quantity of counters. Number of counter instances available for counting events |  \n| `qty_t` | Quantity of timers. Number of timer instances available for timing operations. |  \n| `qty_d` | Quantity of memory areas quantities. |  \n| `qty_r` | Quantity of nemory areas quantities. Float or Real registers.. |  \n| `init_netwok` | If false not initialize Networks. |  \n  \n**Returns**: Pointer to the initialized `ladder_ctx_t` structure, or `NULL` if initialization fails.  \n  \n### ladder_deinit  \n  \nDeinitializes the ladder context, freeing all associated resources.  \n  \n```c  \nvoid ladder_deinit(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context to be deinitialized. |  \n  \n**Returns**: None.  \n  \n### ladder_add_read_fn  \n  \nRegisters a callback function for reading input values from hardware.  \n  \n```c  \nbool ladder_add_read_fn(ladder_ctx_t *ladder_ctx, _io_read read, _io_init read_init)  \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n| `read`       | Pointer to the read callback function. |  \n| `read_init`  | Initialize/deinitialize read function. |\n  \n**Returns**: None.  \n  \n### ladder_add_write_fn  \n  \nRegisters a callback function for writing output values to hardware.  \n  \n```c  \nbool ladder_add_write_fn(ladder_ctx_t *ladder_ctx, _io_write write, _io_init write_init);\n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx`  | Pointer to the ladder context. |  \n| `write`       | Pointer to the write callback function. |\n| `write_init`  | Initialize/deinitialize write function. |\n  \n**Returns**: None.\n\n### ladder_add_foreign\n\nAdd a foreign function\n\n```c\nbool ladder_add_foreign(ladder_ctx_t *ladder_ctx, _foreign_fn_init fn_init, void *init_data, uint32_t qty);\n```\n\n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Ladder context. |\n| `fn_init` | Initialize internal foreign function. |\n| `init_data` | Generic foreign function data. |\n| `qty` | Quantity. |\n\n\n## Utility Functions  \n  \nThis section documents utility functions from the header files `ladder_print.h`, `ladder_program_json.h`, and `ladder_program_check.h`.  \n  \n### ladder_print_program  \n  \nPrints the entire ladder program to the console for debugging purposes.  \n  \n```c  \nvoid ladder_print_program(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: None.  \n  \n### ladder_print  \n  \nPrint networks in ascii graphical format.  \n  \n```c  \nvoid ladder_print(ladder_ctx_t ladder_ctx)\n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. | \n  \n**Returns**: None.  \n  \n### ladder_program_to_json  \n  \nSave ladder program to a JSON file.  \n  \n```c  \nladder_json_error_t ladder_program_to_json(const char *prg, ladder_ctx_t *ladder_ctx) \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `prg` | File name. |\n| `ladder_ctx` | Pointer to the ladder context. |\n  \n**Returns**: Status.\n\n### ladder_json_to_program  \n  \nLoad ladder program from a JSON file.  \n  \n```c  \nladder_json_error_t ladder_json_to_program(const char *prg, ladder_ctx_t *ladder_ctx) \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `prg` | File name. |\n| `ladder_ctx` | Pointer to the ladder context. |\n  \n**Returns**: Status.  \n  \n### ladder_program_check  \n  \nChecks the integrity and validity of the ladder program.  \n  \n```c  \nbool ladder_program_check(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |\n  \n**Returns**: `true` if the program is valid, `false` otherwise.  \n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- ENUMS --\u003e\n## Enums and Structures  \n  \nThis section documents all enums and structures from the header files.  \n\n### Enums  \n  \n#### ladder_instruction_t \n  \nDefines the types of instructions supported by LadderLib.  \n  \n```c  \ntypedef enum LADDER_INSTRUCTIONS {\n    LADDER_INS_NOP,     /**\u003c Instruction NOP */\n    LADDER_INS_CONN,    /**\u003c Instruction CONN */\n    LADDER_INS_NEG,     /**\u003c Instruction NEG */\n    LADDER_INS_NO,      /**\u003c Instruction NO */\n    LADDER_INS_NC,      /**\u003c Instruction NC */\n    LADDER_INS_RE,      /**\u003c Instruction RE */\n    LADDER_INS_FE,      /**\u003c Instruction FE */\n    LADDER_INS_COIL,    /**\u003c Instruction COIL */\n    LADDER_INS_COILL,   /**\u003c Instruction COILL */\n    LADDER_INS_COILU,   /**\u003c Instruction COILU */\n    LADDER_INS_TON,     /**\u003c Instruction TON */\n    LADDER_INS_TOFF,    /**\u003c Instruction TOFF */\n    LADDER_INS_TP,      /**\u003c Instruction TP */\n    LADDER_INS_CTU,     /**\u003c Instruction CTU */\n    LADDER_INS_CTD,     /**\u003c Instruction CTD */\n    LADDER_INS_MOVE,    /**\u003c Instruction MOVE */\n    LADDER_INS_SUB,     /**\u003c Instruction SUB */\n    LADDER_INS_ADD,     /**\u003c Instruction ADD */\n    LADDER_INS_MUL,     /**\u003c Instruction MUL */\n    LADDER_INS_DIV,     /**\u003c Instruction DIV */\n    LADDER_INS_MOD,     /**\u003c Instruction MOD */\n    LADDER_INS_SHL,     /**\u003c Instruction SHL */\n    LADDER_INS_SHR,     /**\u003c Instruction SHR */\n    LADDER_INS_ROL,     /**\u003c Instruction ROL */\n    LADDER_INS_ROR,     /**\u003c Instruction ROR */\n    LADDER_INS_AND,     /**\u003c Instruction AND */\n    LADDER_INS_OR,      /**\u003c Instruction OR */\n    LADDER_INS_XOR,     /**\u003c Instruction XOR */\n    LADDER_INS_NOT,     /**\u003c Instruction NOT */\n    LADDER_INS_EQ,      /**\u003c Instruction EQ */\n    LADDER_INS_GT,      /**\u003c Instruction GT */\n    LADDER_INS_GE,      /**\u003c Instruction GE */\n    LADDER_INS_LT,      /**\u003c Instruction LT */\n    LADDER_INS_LE,      /**\u003c Instruction LE */\n    LADDER_INS_NE,      /**\u003c Instruction NE */\n    LADDER_INS_FOREIGN, /**\u003c Instruction FOREIGN */\n    LADDER_INS_TMOVE,   /**\u003c Instruction TMOVE */\n    ///////////////////\n    LADDER_INS_INV,     /**\u003c First invalid */\n    LADDER_INS_MULTI,   /**\u003c cell is a part of multi cell instruction */\n} ladder_instruction_t;\n```\n\n#### ladder_state_t\n\nGeneral state\n\n```c\ntypedef enum LADDER_STATE {\n    LADDER_ST_STOPPED,  /**\u003c Stopped */\n    LADDER_ST_RUNNING,  /**\u003c Running */\n    LADDER_ST_ERROR,    /**\u003c Error */\n    LADDER_ST_EXIT_TSK, /**\u003c Exit task */\n    LADDER_ST_NULLFN,   /**\u003c pointer to NULL function */\n    LADDER_ST_INV,      /**\u003c Invalid */\n} ladder_state_t;\n```\n\n#### ladder_ins_err_t\n\nInstruction status\n\n```c\ntypedef enum LADDER_INS_ERROR {\n    LADDER_INS_ERR_OK,         /**\u003c OK */\n    LADDER_INS_ERR_GETPREVVAL, /**\u003c Error get previous value */\n    LADDER_INS_ERR_GETDATAVAL, /**\u003c Error get data value */\n    LADDER_INS_ERR_SETDATAVAL, /**\u003c Error set data value */\n    LADDER_INS_ERR_NOFOREIGN,  /**\u003c Error foreign function not exist */\n    LADDER_INS_ERR_NOTABLE,    /**\u003c Table not exist or net not disabled */\n    LADDER_INS_ERR_OUTOFRANGE, /**\u003c Value out of range */\n    //...//\n    LADDER_INS_ERR_FAIL,       /**\u003c Generic fail */\n} ladder_ins_err_t;\n```\n\n#### ladder_type_t\n\nData types\n\n```c\ntypedef enum LADDER_DATA_TYPE {\n    LADDER_DATATYPE_U8,       /**\u003c Unsigned 8 bits */\n    LADDER_DATATYPE_U16,      /**\u003c Unsigned 16 bits */\n    LADDER_DATATYPE_U32,      /**\u003c Unsigned 32 bits */\n    LADDER_DATATYPE_I8,       /**\u003c Signed 8 bits */\n    LADDER_DATATYPE_I16,      /**\u003c Signed 16 bits */\n    LADDER_DATATYPE_I32,      /**\u003c Signed 32 bits */\n    LADDER_DATATYPE_REAL,     /**\u003c Float 32 bits */\n    LADDER_DATATYPE_CSTR,     /**\u003c Constant string */\n    LADDER_DATATYPE_MOD_PORT, /**\u003c Module.port format */\n} ladder_data_type_t;\n```\n\n#### ladder_basetime_t\n\n```c\ntypedef enum LADDER_BASETIME {\n    LADDER_BASETIME_MS,    /**\u003c Basetime ms */\n    LADDER_BASETIME_10MS,  /**\u003c Basetime 10 ms */\n    LADDER_BASETIME_100MS, /**\u003c Basetime 100 ms */\n    LADDER_BASETIME_SEC,   /**\u003c Basetime seconds */\n    LADDER_BASETIME_MIN,   /**\u003c Basetime minutes */\n} ladder_basetime_t;\n```\n\n#### ladder_register_t\n\n```c\ntypedef enum LADDER_REGISTERS {\n    LADDER_REGISTER_NONE, /**\u003c Register None */\n    LADDER_REGISTER_M,    /**\u003c Register M */\n    LADDER_REGISTER_Q,    /**\u003c Register Q */\n    LADDER_REGISTER_I,    /**\u003c Register I */\n    LADDER_REGISTER_Cd,   /**\u003c Register Cd */\n    LADDER_REGISTER_Cr,   /**\u003c Register Cr */\n    LADDER_REGISTER_Td,   /**\u003c Register Td */\n    LADDER_REGISTER_Tr,   /**\u003c Register Tr */\n    LADDER_REGISTER_IW,   /**\u003c Register IW */\n    LADDER_REGISTER_QW,   /**\u003c Register QW */\n    LADDER_REGISTER_C,    /**\u003c Register C */\n    LADDER_REGISTER_T,    /**\u003c Register T */\n    LADDER_REGISTER_D,    /**\u003c Register D */\n    LADDER_REGISTER_S,    /**\u003c Register string */\n    LADDER_REGISTER_R,    /**\u003c Register real (float) */\n    //...//\n    LADDER_REGISTER_INV,  /**\u003c Register invalid */\n} ladder_register_t;\n```\n\n### Structures  \n  \n#### `ladder_instructions_ioc_s`\n\nDescribes an instruction's input/output configuration and cell occupancy.\n\n```c\ntypedef struct ladder_instructions_ioc_s {\n    uint8_t inputs;   /**\u003c Inputs quantity */\n    uint8_t outputs;  /**\u003c Outputs quantity */\n    uint8_t cells;    /**\u003c Cells quantity */\n    uint8_t data_qty; /**\u003c Quantity */\n} ladder_instructions_iocd_t;\n```\n\n- **Fields**:\n  - **`inputs`**: Number of input connections to the instruction.\n  - **`outputs`**: Number of output connections from the instruction.\n  - **`cells`**: Number of cells occupied by the instruction in the ladder diagram.\n  - **`data_qty`**: Quantity of data elements associated with the instruction.\n\n#### `ladder_moduleportvalue_s`\n\nRepresents a value tied to a specific module and port, typically for I/O operations.\n\n```c\ntypedef struct ladder_moduleportvalue_s {\n    uint8_t module; /**\u003c Module */\n    uint8_t port;   /**\u003c Port */\n} ladder_moduleportvalue_t;\n```\n\n- **Fields**:\n  - **`module`**: Identifier of the module.\n  - **`port`**: Identifier of the port within the module.\n\n#### `ladder_value_s`\n\nA versatile container for values of different types used in ladder logic.\n\n```c\ntypedef struct ladder_value_s {\n    ladder_register_t type; /**\u003c Data type */\n    union {\n             uint8_t u8;    /**\u003c Unsigned integer 8 bits */\n            uint16_t u16;   /**\u003c Unsigned integer 16 bits */\n            uint32_t u32;   /**\u003c Unsigned integer 32 bits */\n              int8_t i8;    /**\u003c Signed integer 8 bits */\n             int16_t i16;   /**\u003c Signed integer 16 bits */\n             int32_t i32;   /**\u003c Signed integer 32 bits */\n          const char *cstr; /**\u003c Constant string */\n               float real;  /**\u003c Float */\n        moduleport_t mp;    /**\u003c Module.port value */\n    } value; /**\u003c Data */\n} ladder_value_t;\n```\n\n- **Fields**:\n  - **`type`**: Specifies the value's data type (e.g., `u32`, `i32`, `cstr`, `real`, `mp`).\n  - **`value`**: Union containing the actual value, interpreted based on `type`. Supports:\n    -  Unsigned integer 8 bits  (`u8`).\n    -  Unsigned integer 16 bits  (`u16`).\n    -  Unsigned integer 32 bits  (`u32`).\n    -  Signed integer 8 bits  (`i8`).\n    -  Signed integer 16 bits  (`i16`).\n    -  Signed integer 32 bits  (`i32`).\n    -  Constant string  (`cstr`).\n    -  Float  (`real`).\n    -  Module.port value  (`mp`).\n\n#### `ladder_cell_s`\n\nRepresents a single cell in the ladder diagram, encapsulating an instruction and its data.\n\n```c\ntypedef struct ladder_cell_s {\n                    bool state;        /**\u003c Output state */\n                    bool vertical_bar; /**\u003c Have vertical bar */\n    ladder_instruction_t code;         /**\u003c Code */\n                 uint8_t data_qty;     /**\u003c Data quantity */\n          ladder_value_t *data;        /**\u003c Data */\n} ladder_cell_t;\n```\n\n- **Fields**:\n  - **`state`**: Output state of the cell (`true` for active, `false` for inactive).\n  - **`vertical_bar`**: Indicates the presence of a vertical bar (for ladder diagram rendering).\n  - **`code`**: Instruction code executed by the cell.\n  - **`data_qty`**: Number of data elements associated with the instruction.\n  - **`data`**: Pointer to an array of `ladder_value_t` containing instruction data.\n\n#### `ladder_network_s`\n\nA network is a grid of cells forming a segment of the ladder logic program.\n\n```c\ntypedef struct ladder_network_s {\n             bool enable;  /**\u003c Enabled for execution */\n         uint32_t rows;    /**\u003c Rows qty */\n         uint32_t cols;    /**\u003c Columns qty */\n    ladder_cell_t **cells; /**\u003c Cells */\n} ladder_network_t;\n```\n\n- **Fields**:\n  - **`enable`**: Indicates whether the network is active for execution.\n  - **`rows`**: Number of rows in the network grid.\n  - **`cols`**: Number of columns in the network grid.\n  - **`cells`**: 2D array of pointers to `ladder_cell_t`, representing the network's cells.\n\n#### `ladder_s`\n\nHolds the internal state and configuration of the ladder logic system.\n\n```c\ntypedef struct ladder_s {\n    ladder_state_t state; /**\u003c State */\n    struct {\n         uint8_t instr;       /**\u003c Last executed instruction */\n        uint32_t network;     /**\u003c Last executed network */\n        uint32_t cell_column; /**\u003c Last executed cell column */\n        uint32_t cell_row;    /**\u003c Last executed cell row */\n         uint8_t err;         /**\u003c Last executed error */\n    } last;\n    struct {\n        uint32_t m;        /**\u003c Quantity of regular flags */\n        uint32_t c;        /**\u003c Quantity of counters */\n        uint32_t t;        /**\u003c Quantity of timers */\n        uint32_t d;        /**\u003c Quantity of regular registers */\n        uint32_t r;        /**\u003c Quantity of floating point registers */\n        uint32_t networks; /**\u003c Quantity of networks */\n    } quantity;\n} ladder_t;\n```\n\n- **Fields**:\n  - **`state`**: Current operational state of the ladder system.\n  - **`last`**: Substructure tracking the last executed instruction:\n    - **`instr`**: Instruction code.\n    - **`network`**: Network index.\n    - **`cell_column`**: Column of the executed cell.\n    - **`cell_row`**: Row of the executed cell.\n    - **`err`**: Error code from the last execution.\n  - **`quantity`**: Substructure defining the system's capacity:\n    - **`m`**: Number of regular flags.\n    - **`c`**: Number of counters.\n    - **`t`**: Number of timers.\n    - **`d`**: Number of regular registers.\n    - **`r`**: Number of floating-point registers.\n    - **`networks`**: Number of networks.\n\n#### `ladder_hw_s`\n\nDefines hardware-dependent functions for I/O and time management.\n\n```c\ntypedef struct ladder_hw_s {\n    struct {\n         uint32_t fn_read_qty;  /**\u003c Quantity of read functions */\n         uint32_t fn_write_qty; /**\u003c Quantity of write functions */\n         _io_read *read;        /**\u003c Read hardware values */\n        _io_write *write;       /**\u003c Write hardware values */\n         _io_init *init_read;   /**\u003c Initialize read functions */\n         _io_init *init_write;  /**\u003c Initialize write functions */\n    } io;\n    struct {\n        _millis millis; /**\u003c Milliseconds from system start */\n         _delay delay;  /**\u003c Delay in milliseconds */\n    } time;\n} ladder_hw_t;\n```\n\n- **Fields**:\n  - **`io`**: Substructure for I/O operations:\n    - **`fn_read_qty`**: Number of read functions.\n    - **`fn_write_qty`**: Number of write functions.\n    - **`read`**: Array of read function pointers.\n    - **`write`**: Array of write function pointers.\n    - **`init_read`**: Array of read initialization functions.\n    - **`init_write`**: Array of write initialization functions.\n  - **`time`**: Substructure for time management:\n    - **`millis`**: Function to get current time.\n    - **`delay`**: Function to delay execution.\n\n#### `ladder_hw_input_vals_s`\n\nStores input values read from hardware.\n\n```c\ntypedef struct ladder_hw_input_vals_s {\n    uint32_t fn_id;  /**\u003c Function id */\n    uint32_t i_qty;  /**\u003c Digital inputs quantity */\n    uint32_t iw_qty; /**\u003c Analog inputs quantity */\n     uint8_t *I;     /**\u003c Digital inputs */\n     int32_t *IW;    /**\u003c Analog inputs */\n     uint8_t *Ih;    /**\u003c Digital inputs previous */\n} ladder_hw_input_vals_t;\n```\n\n- **Fields**:\n  - **`fn_id`**: Identifier of the read function.\n  - **`i_qty`**: Number of digital inputs.\n  - **`iw_qty`**: Number of analog inputs.\n  - **`I`**: Array of digital input values.\n  - **`IW`**: Array of analog input values.\n  - **`Ih`**: Array of previous digital input values (for change detection).\n\n#### `ladder_hw_output_vals_s`\n\nStores output values to be written to hardware.\n\n```c\ntypedef struct ladder_hw_output_vals_s {\n    uint32_t fn_id;  /**\u003c Function id */\n    uint32_t q_qty;  /**\u003c Digital outputs quantity */\n    uint32_t qw_qty; /**\u003c Analog outputs quantity */\n     uint8_t *Q;     /**\u003c Digital outputs */\n     int32_t *QW;    /**\u003c Analog outputs */\n     uint8_t *Qh;    /**\u003c Digital outputs previous */\n} ladder_hw_output_vals_t;\n```\n\n- **Fields**:\n  - **`fn_id`**: Identifier of the write function.\n  - **`q_qty`**: Number of digital outputs.\n  - **`qw_qty`**: Number of analog outputs.\n  - **`Q`**: Array of digital output values.\n  - **`QW`**: Array of analog output values.\n  - **`Qh`**: Array of previous digital output values.\n\n#### `ladder_memory_s`\n\nContains memory flags and status bits for counters and timers.\n\n```c\ntypedef struct ladder_memory_s {\n    uint8_t *M;  /**\u003c Regular flags */\n       bool *Cr; /**\u003c Counter running */\n       bool *Cd; /**\u003c Counter done */\n       bool *Tr; /**\u003c Timer running */\n       bool *Td; /**\u003c Timer done */\n} ladder_memory_t;\n```\n\n- **Fields**:\n  - **`M`**: Array of regular memory flags.\n  - **`Cr`**: Array indicating if counters are running.\n  - **`Cd`**: Array indicating if counters are done.\n  - **`Tr`**: Array indicating if timers are running.\n  - **`Td`**: Array indicating if timers are done.\n\n#### `ladder_prev_scan_vals_s`\n\nStores previous scan values for memory flags and status bits.\n\n```c\ntypedef struct ladder_prev_scan_vals_s {\n    uint8_t *Mh;  /**\u003c Regular flags previous */\n       bool *Crh; /**\u003c Counter running previous */\n       bool *Cdh; /**\u003c Counter done previous */\n       bool *Trh; /**\u003c Timer running previous */\n       bool *Tdh; /**\u003c Timer done previous */\n} ladder_prev_scan_vals_t;\n```\n\n- **Fields**:\n  - **`Mh`**: Previous regular memory flags.\n  - **`Crh`**: Previous counter running states.\n  - **`Cdh`**: Previous counter done states.\n  - **`Trh`**: Previous timer running states.\n  - **`Tdh`**: Previous timer done states.\n\n#### `ladder_registers_s`\n\nManages counter, integer, and floating-point registers.\n\n```c\ntypedef struct ladder_registers_s {\n    uint32_t *C; /**\u003c Counter registers */\n     int32_t *D; /**\u003c Regular registers */\n       float *R; /**\u003c Floating point registers */\n} ladder_registers_t;\n```\n\n- **Fields**:\n  - **`C`**: Array of counter register values.\n  - **`D`**: Array of regular integer register values.\n  - **`R`**: Array of floating-point register values.\n\n#### `ladder_timer_s`\n\nRepresents a timer with its timestamp and accumulator.\n\n```c\ntypedef struct ladder_timer_s {\n    uint64_t time_stamp; /**\u003c Time stamp */\n    uint32_t acc;        /**\u003c Activated counter */\n} ladder_timer_t;\n```\n\n- **Fields**:\n  - **`time_stamp`**: Time when the timer was last updated.\n  - **`acc`**: Accumulated time or count for the timer.\n\n#### `ladder_scan_internals_s`\n\nManages timing data for scan cycles.\n\n```c\ntypedef struct ladder_scan_internals_s {\n    uint64_t actual_scan_time; /**\u003c Actual scan time */\n    uint64_t start_time;       /**\u003c Start time for calculate scan time */\n} ladder_scan_internals_t;\n```\n\n- **Fields**:\n  - **`actual_scan_time`**: Duration of the last scan cycle.\n  - **`start_time`**: Starting time of the current scan cycle.\n\n#### `ladder_foreign_function_s`\n\nDefines a foreign function with its properties and execution logic.\n\n```c\ntypedef struct ladder_foreign_function_s {\n                      uint32_t id;          /**\u003c Foreign function id */\n                          char name[4];     /**\u003c Foreign function name */\n    ladder_instructions_iocd_t description; /**\u003c Foreign function description */\n                   ladder_fn_t exec;        /**\u003c Foreign functions pointers */\n            _foreign_fn_deinit deinit;      /**\u003c Foreign functions deinitializer pointers */\n                         void *data;        /**\u003c Internal data for foreign functions */\n} ladder_foreign_function_t;\n```\n\n- **Fields**:\n  - **`id`**: Unique identifier for the function.\n  - **`name`**: Short name (up to 3 characters + null terminator).\n  - **`description`**: Input/output configuration (`ladder_instructions_iocd_t`).\n  - **`exec`**: Pointer to the execution function.\n  - **`deinit`**: Pointer to the deinitialization function.\n  - **`data`**: Pointer to internal data for the function.\n\n#### `ladder_foreign_s`\n\nManages a collection of foreign functions.\n\n```c\ntypedef struct ladder_foreign_s {\n                     uint32_t qty; /**\u003c Foreign functions quantity */\n    ladder_foreign_function_t *fn; /**\u003c Main foreign function definition */\n} ladder_foreign_t;\n```\n\n- **Fields**:\n  - **`qty`**: Number of foreign functions.\n  - **`fn`**: Array of `ladder_foreign_function_t` structures.\n\n#### `ladder_ctx_s`\n\nThe central structure tying together all components of the ladder logic system.\n\n```c\ntypedef struct ladder_ctx_s {\n                   ladder_t ladder;         /**\u003c Internals */\n                ladder_hw_t hw;             /**\u003c Hardware functions */\n            ladder_manage_t on;             /**\u003c Manage functions */\n            ladder_memory_t memory;         /**\u003c Memory */\n    ladder_prev_scan_vals_t prev_scan_vals; /**\u003c Previous scan values */\n    ladder_hw_input_vals_t *input;          /**\u003c Hw inputs */\n    ladder_hw_output_vals_t *output;        /**\u003c Hw outputs */\n         ladder_registers_t registers;      /**\u003c Registers */\n             ladder_timer_t *timers;        /**\u003c Timers */\n    ladder_scan_internals_t scan_internals; /**\u003c Scan internals */\n           ladder_network_t *network;       /**\u003c Networks */\n           ladder_network_t *exec_network;  /**\u003c Network in execution */\n           ladder_foreign_t foreign;        /**\u003c Foreign functions */\n} ladder_ctx_t;\n```\n\n- **Fields**:\n  - **`ladder`**: Internal state and configuration (`ladder_t`).\n  - **`hw`**: Hardware interface functions (`ladder_hw_t`).\n  - **`on`**: Management callbacks (`ladder_manage_t`):\n    - **`scan_end`**: Called at the end of each scan cycle.\n    - **`instruction`**: Called for each instruction.\n    - **`task_before`**: Called before each task cycle.\n    - **`task_after`**: Called after each task cycle.\n    - **`panic`**: Called during panic conditions.\n    - **`end_task`**: Called at task completion.\n  - **`memory`**: Memory flags and status bits (`ladder_memory_t`).\n  - **`prev_scan_vals`**: Previous scan values (`ladder_prev_scan_vals_t`).\n  - **`input`**: Array of hardware input values (`ladder_hw_input_vals_t`).\n  - **`output`**: Array of hardware output values (`ladder_hw_output_vals_t`).\n  - **`registers`**: Register storage (`ladder_registers_t`).\n  - **`timers`**: Array of timers (`ladder_timer_t`).\n  - **`scan_internals`**: Scan cycle timing data (`ladder_scan_internals_t`).\n  - **`network`**: Array of networks (`ladder_network_t`).\n  - **`exec_network`**: Currently executing network (`ladder_network_t`).\n  - **`foreign`**: Foreign function definitions (`ladder_foreign_t`).\n  - \n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- CALLBACKS --\u003e\n## Callback Prototypes  \n  \nThis section lists all callback prototypes used by LadderLib, with their exact function signatures and purposes.  \n  \n### _io_read  \n  \n```c  \nvoid (*_io_read)(ladder_ctx_t* ladder_ctx, uint32_t id)  \n```  \n  \n**Description**: Reads hardware values and updates the input bits in the ladder context.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n| `id` | Identifier of the input to read. |  \n  \n**Returns**: None.  \n  \n### _io_write  \n  \n```c  \nvoid (*_io_write)(ladder_ctx_t* ladder_ctx, uint32_t id)  \n```  \n  \n**Description**: Writes hardware values based on the output bits in the ladder context.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n| `id` | Identifier of the output to write. |  \n  \n**Returns**: None.  \n  \n### _io_init  \n  \n```c  \nbool (*_io_init)(ladder_ctx_t* ladder_ctx, uint32_t id, bool init_deinit)  \n```  \n  \n**Description**: Initializes or deinitializes an I/O function.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n| `id` | Identifier of the I/O function. |  \n| `init_deinit` | `true` to initialize, `false` to deinitialize. |  \n  \n**Returns**: `true` if successful, `false` otherwise.  \n  \n### _on_scan_end  \n  \n```c  \nbool (*_on_scan_end)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Called at the end of each scan cycle for custom processing.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: `true` to continue execution, `false` to stop.  \n  \n### _on_instruction  \n  \n```c  \nbool (*_on_instruction)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Called for each instruction executed during a scan.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: `true` to continue execution, `false` to stop.  \n  \n### _on_task_before  \n  \n```c  \nbool (*_on_task_before)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Called before each task cycle scan begins.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: `true` to proceed with the scan, `false` to skip.  \n  \n### _on_task_after  \n  \n```c  \nbool (*_on_task_after)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Called after each task cycle scan completes.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: `true` to continue, `false` to stop.  \n  \n### _on_panic  \n  \n```c  \nvoid (*_on_panic)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Handles panic situations, such as critical errors.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: None.  \n  \n### _on_end_task  \n  \n```c  \nvoid (*_on_end_task)(ladder_ctx_t* ladder_ctx)  \n```  \n  \n**Description**: Called when a task ends, for cleanup or final actions.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `ladder_ctx` | Pointer to the ladder context. |  \n  \n**Returns**: None.  \n  \n### _delay  \n  \n```c  \nvoid (*_delay)(long msec)  \n```  \n  \n**Description**: Implements a delay in milliseconds.  \n  \n**Parameters:**  \n  \n| **Parameter** | **Description** |  \n|---------------|-----------------|  \n| `msec` | Duration of the delay in milliseconds. |  \n  \n**Returns**: None.  \n  \n### _millis  \n  \n```c  \nuint64_t (*_millis)(void)  \n```  \n  \n**Description**: Returns the time elapsed since system start in milliseconds.  \n  \n**Parameters**: None.  \n  \n**Returns**: Number of milliseconds as a 64-bit unsigned integer.\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- BASICUSAGE --\u003e  \n## Basic Usage  \nTo use Ladderlib, follow these steps:  \n1. **Initialize Context**: Call `ladder_ctx_init` with appropriate quantities for networks, memory areas, counters, timers, data, and registers.  \n2. **Define Program**: Populate the `ladder_s` structure by defining networks (`ladder_network_s`) and cells (`ladder_cell_s`), assigning instructions from `LADDER_INSTRUCTIONS` and configuring data or timers as needed.  \n3. **Set Hardware Callbacks**: Provide functions for hardware interactions in `ladder_hw_s`, such as `_io_read` and `_io_write`, to interface with physical devices.  \n4. **Set Event Callbacks**: Optionally, assign callbacks in `ladder_manage_s` for events like scan end (`_on_scan_end`) or panic handling (`_on_panic`).  \n5. **Run Task**: Execute the ladder logic by calling `ladder_task` to process the program and interact with hardware.  \n6. **Monitor and Handle Errors**: Check ladder.state and ladder.err to monitor execution status and handle errors.  \n7. **Deinitialize**: Call `ladder_ctx_deinit` to free resources when the program is no longer needed.\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- CONTRIBUTING --\u003e\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag \"enhancement\".\nDon't forget to give the project a star! Thanks again!\n\n1. Fork it (\u003chttps://github.com/hiperiondev/ladderlib/fork\u003e)\n2. Create your feature branch (`git checkout -b feature/fooBar`)\n3. Commit your changes (`git commit -am 'Add some fooBar'`)\n4. Push to the branch (`git push origin feature/fooBar`)\n5. Create a new Pull Request\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- LICENSE --\u003e\n## License\n\nDistributed under the MIT License. See `LICENSE.txt` for more information.\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- CONTACT --\u003e\n## Contact\n\n*Emiliano Augusto Gonzalez - egonzalez.hiperion@gmail.com*\n\n\u003cdiv align=\"right\"\u003e\n  \u003ca href=\"#readme-top\"\u003e\n    \u003cimg src=\"images/backtotop.png\" alt=\"backtotop\" width=\"30\" height=\"30\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiperiondev%2Fladderlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhiperiondev%2Fladderlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhiperiondev%2Fladderlib/lists"}