6#include "dawn/dawn.hxx"
8#ifdef CONFIG_DAWN_DESC_SWITCH
9# include "dawn/dev/descriptor.hxx"
10# include "dawn/dev/descswitch.hxx"
12#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
13# include "dawn/dev/shutdown.hxx"
19 : userIOFactory(iofactory)
20 , userProgFactory(progfactory)
21 , userProtoFactory(protofactory)
29 DAWNASSERT(bin !=
nullptr && len > 0,
"invalid input");
33 ret = desc.loadBin(bin, len,
false);
36 DAWNERR(
"ERROR: _desc.loadBin failed %d\n", ret);
42 ret = io.init(desc, userIOFactory);
45 DAWNERR(
"failed to initialize IO handler\n");
51 io.setDevDescriptor(&devDesc);
54 DAWNERR(
"failed to initialize IO handler\n");
63 DAWNERR(
"failed to initialize IOs\n");
69 ret = prog.init(desc, &io, userProgFactory);
72 DAWNERR(
"failed to initialize PROG handler\n");
81 DAWNERR(
"failed to initialize PROGs\n");
87 ret = proto.init(desc, &io, userProtoFactory);
90 DAWNERR(
"failed to initialize PROTO handler\n");
96 ret = proto.initAll();
99 DAWNERR(
"failed to initialize PROTOs\n");
105 ret = system.init(desc,
nullptr);
108 DAWNERR(
"failed to initialize SYSTEM handler\n");
114 ret = system.initAll();
117 DAWNERR(
"failed to initialize SYSTEM objects\n");
123 ret = io.bindObjects(io, prog, proto, system);
126 DAWNERR(
"failed to bind special IO objects\n");
133#ifdef CONFIG_DAWN_DESC_SWITCH
134int CDawn::load_descriptor_from_slot(uint8_t slot)
145 if (reg.
ptr ==
nullptr || reg.
len == 0)
157#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
160#ifdef CONFIG_DAWN_DESC_SWITCH
169#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
177#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
186 ret = system.startAll();
189#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
198 ret = prog.startAll();
201#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
210 ret = proto.startAll();
213#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
220 DAWNINFO(
"DAWN: START SUCCESS!\n");
224#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
227 DAWNINFO(
"shutdown requested - quit\n");
232#ifdef CONFIG_DAWN_DESC_SWITCH
235 DAWNINFO(
"descriptor switch requested\n");
240 if (!desc.getNoIdleQuit() && !(proto.hasThread() || prog.hasThread()))
242 DAWNINFO(
"no active protocols - quit\n");
252 dawn::oot::user_on_idle(
this);
255#ifdef CONFIG_DAWN_LIFECYCLE_TEARDOWN
259 tmp = dawn::oot::user_pre_shutdown(
this);
262 DAWNWARN(
"user_pre_shutdown returned %d\n", tmp);
265 tmp = proto.stopAll();
268 DAWNERR(
"failed to stop protos %d\n", tmp);
276 tmp = prog.stopAll();
279 DAWNERR(
"failed to stop programs %d\n", tmp);
287 tmp = system.stopAll();
290 DAWNERR(
"failed to stop SYSTEM objects %d\n", tmp);
301 DAWNERR(
"failed to stop IO %d\n", tmp);
309 tmp = proto.deinitAll();
312 DAWNERR(
"failed to deinit protos %d\n", tmp);
319 tmp = prog.deinitAll();
322 DAWNERR(
"failed to deinit programs %d\n", tmp);
329 tmp = system.deinitAll();
332 DAWNERR(
"failed to deinit SYSTEM objects %d\n", tmp);
339 tmp = io.deinitAll();
342 DAWNERR(
"failed to deinit IO %d\n", tmp);
352#ifdef CONFIG_DAWN_DESC_SWITCH
359 ret = load_descriptor_from_slot(newSlot);
362 DAWNERR(
"descriptor switch failed for slot %d\n", newSlot);
int load_descriptor(uint32_t *bin, size_t len)
Load and initialize descriptor.
int start(bool no_loop=false)
Start Dawn framework.
CDawn(IIOFactory *iofactory=nullptr, IProgFactory *progfactory=nullptr, IProtoFactory *protofactory=nullptr)
Construct CDawn framework.
static void setActiveSlot(uint8_t slot)
Set currently active descriptor slot.
static void clear()
Clear pending switch request.
static uint8_t getSwitchSlot()
Get pending switch target slot.
static bool isSwitchRequested()
Check if descriptor switch is pending.
int getDescriptor(int inst, SDescriptorReg ®)
Get registered descriptor data for an instance.
static void clear()
Clear pending shutdown request.
static bool isRequested()
Check if shutdown has been requested.
Abstract factory interface for extensible I/O object creation.
Abstract factory interface for PROG object creation.
Abstract factory interface for protocol creation.
Out-of-tree user-extension hooks for Dawn.
Registered descriptor information.
size_t len
Descriptor length in bytes.
void * ptr
Pointer to descriptor data.