added DI unit

This commit is contained in:
2017-12-28 21:01:13 +01:00
parent 37f712f054
commit 8768dc31ab
12 changed files with 313 additions and 29 deletions
+25
View File
@@ -5,6 +5,7 @@
#include "platform.h"
#include "unit.h"
#include "resources.h"
#include "pin_utils.h"
static bool rsc_initialized = false;
@@ -82,6 +83,30 @@ bool rsc_claim_range(Unit *unit, Resource rsc0, Resource rsc1)
return true;
}
bool rsc_claim_gpios(Unit *unit, char port_name, uint16_t pins)
{
bool suc = true;
for (int i = 0; i < 16; i++) {
if (pins & (1 << i)) {
Resource rsc = pin2resource(port_name, (uint8_t) i, &suc);
if (!suc) {
unit->status = E_BAD_CONFIG;
rsc_teardown(unit);
return false;
}
suc = rsc_claim(unit, rsc);
if (!suc) {
rsc_teardown(unit);
return false;
}
}
}
return true;
}
/**
* Free a resource for other use
*
+11
View File
@@ -88,4 +88,15 @@ void rsc_teardown(Unit *unit);
void rsc_free(Unit *unit, Resource rsc);
void rsc_free_range(Unit *unit, Resource rsc0, Resource rsc1);
/**
* Claim GPIOs by bitmask and port name, atomically.
* Tear down the unit on failure.
*
* @param unit - claiming unit
* @param port_name - port (eg. 'A')
* @param pins - pins, bitmask
* @return success
*/
bool rsc_claim_gpios(Unit *unit, char port_name, uint16_t pins);
#endif //GEX_RESOURCES_H
+2 -2
View File
@@ -16,7 +16,7 @@ static bool savebuf_ovhandler(PayloadBuilder *pb, uint32_t more);
// This is the first entry in a valid config.
// Change with each breaking change to force config reset.
#define CONFIG_MARKER 0xA55D
#define CONFIG_MARKER 0xA55E
void settings_load(void)
{
@@ -270,7 +270,7 @@ void settings_load_ini_begin(void)
void settings_load_ini_key(const char *restrict section, const char *restrict key, const char *restrict value)
{
dbg("[%s] %s = %s", section, key, value);
// dbg("[%s] %s = %s", section, key, value);
static char namebuf[INI_KEY_MAX];
if (streq(section, "SYSTEM")) {
+2
View File
@@ -6,6 +6,8 @@
#include "unit.h"
#include "resources.h"
char unit_tmp64[64];
// Abort partly inited unit
void clean_failed_unit(Unit *unit)
{
+2
View File
@@ -11,6 +11,8 @@
#include "utils/payload_builder.h"
#include "utils/payload_parser.h"
extern char unit_tmp64[64]; // temporary static buffer
typedef struct unit Unit;
typedef struct unit_driver UnitDriver;