int8_t STM32F7USB::notify(ManuvrMsg* active_event) { int8_t return_value = 0; switch (active_event->eventCode()) { case MANUVR_MSG_XPORT_QUEUE_RDY: read_port(); if (_accumulator.count()) { char* working_chunk = _accumulator.position(0); if (write_port((uint8_t*) working_chunk, strlen(working_chunk))) { // TODO: Fail-over timer? Disconnection signal? _accumulator.drop_position(0); } } return_value++; break; case MANUVR_MSG_SYS_BOOTLOADER: case MANUVR_MSG_SYS_REBOOT: case MANUVR_MSG_SYS_SHUTDOWN: connected(false); listening(false); TM_USBD_Stop(TM_USB_FS); // DeInit() The USB device. return_value++; break; default: return_value += ManuvrXport::notify(active_event); break; } if (local_log.length() > 0) Kernel::log(&local_log); return return_value; }
/** * This is called when the kernel attaches the module. * This is the first time the class can be expected to have kernel access. * * @return 0 on no action, 1 on action, -1 on failure. */ int8_t STM32F7USB::attached() { if (EventReceiver::attached()) { read_abort_event.alterScheduleRecurrence(-1); read_abort_event.alterSchedulePeriod(50); read_abort_event.autoClear(false); read_abort_event.enableSchedule(true); #if !defined (__BUILD_HAS_THREADS) platform.kernel()->addSchedule(&read_abort_event); #endif reset(); if (_accumulator.count() > 0) { TM_USBD_CDC_Puts(TM_USB_FS, (const char*)_accumulator.string()); //_tx_in_progress = true; TM_USBD_CDC_Process(TM_USB_FS); } return 1; } return 0; }
/** * If we find ourselves in this fxn, it means an event that this class built (the argument) * has been serviced and we are now getting the chance to see the results. The argument * to this fxn will never be NULL. * * Depending on class implementations, we might choose to handle the completed Event differently. We * might add values to event's Argument chain and return RECYCLE. We may also free() the event * ourselves and return DROP. By default, we will return REAP to instruct the Kernel * to either free() the event or return it to it's preallocate queue, as appropriate. If the event * was crafted to not be in the heap in its own allocation, we will return DROP instead. * * @param event The event for which service has been completed. * @return A callback return code. */ int8_t STM32F7USB::callback_proc(ManuvrMsg* event) { /* Setup the default return code. If the event was marked as mem_managed, we return a DROP code. Otherwise, we will return a REAP code. Downstream of this assignment, we might choose differently. */ int8_t return_value = (0 == event->refCount()) ? EVENT_CALLBACK_RETURN_REAP : EVENT_CALLBACK_RETURN_DROP; /* Some class-specific set of conditionals below this line. */ switch (event->eventCode()) { case MANUVR_MSG_XPORT_SEND: event->clearArgs(); break; case MANUVR_MSG_XPORT_QUEUE_RDY: if (_accumulator.count()) { return_value = EVENT_CALLBACK_RETURN_RECYCLE; } break; default: break; } return return_value; }