Revision 1e5f7648 os/core/src/aos_system.c
os/core/src/aos_system.c | ||
---|---|---|
31 | 31 |
/** |
32 | 32 |
* @brief Period of the system timer. |
33 | 33 |
*/ |
34 |
#define SYSTIMER_PERIOD (TIME_MAX_INTERVAL - CH_CFG_ST_TIMEDELTA)
|
|
34 |
#define SYSTIMER_PERIOD (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA)
|
|
35 | 35 |
|
36 | 36 |
/** |
37 | 37 |
* @brief Width of the printable system info text. |
... | ... | |
576 | 576 |
(void)argc; |
577 | 577 |
(void)argv; |
578 | 578 |
|
579 |
tprio_t prio = chThdGetPriorityX(); |
|
580 |
chThdSetPriority(HIGHPRIO - 5); // some tests increase priorirty by 5, so this is the maximum priority permitted |
|
581 | 579 |
msg_t retval = test_execute(stream, &rt_test_suite); |
582 |
chThdSetPriority(prio); |
|
583 | 580 |
|
584 | 581 |
return retval; |
585 | 582 |
} |
586 | 583 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
587 | 584 |
|
588 | 585 |
/** |
589 |
* @brief Callback function for the PD signal interrupt.
|
|
586 |
* @brief Generic callback function for GPIO interrupts.
|
|
590 | 587 |
* |
591 |
* @param[in] extp Pointer to the interrupt driver object. |
|
592 |
* @param[in] channel Interrupt channel identifier. |
|
588 |
* @param[in] args Pointer to the GPIO pad identifier. |
|
593 | 589 |
*/ |
594 |
static void _signalPdCallback(void *args)
|
|
590 |
static void _intCallback(void* args)
|
|
595 | 591 |
{ |
596 |
(void)args;
|
|
592 |
aosDbgCheck((args != NULL) && (*((iopadid_t*)args) < sizeof(eventflags_t) * 8));
|
|
597 | 593 |
|
598 | 594 |
chSysLockFromISR(); |
599 |
chEvtBroadcastFlagsI(&aos.events.io, 0);
|
|
595 |
chEvtBroadcastFlagsI(&aos.events.io, (eventflags_t)1 << *((iopadid_t*)args));
|
|
600 | 596 |
chSysUnlockFromISR(); |
601 | 597 |
|
602 | 598 |
return; |
603 | 599 |
} |
604 | 600 |
|
601 |
#if (AMIROOS_CFG_SSSP_MASTER != true) || defined(__DOXYGEN__) |
|
605 | 602 |
/** |
606 | 603 |
* @brief Callback function for the Sync signal interrupt. |
607 | 604 |
* |
608 |
* @param[in] extp Pointer to the interrupt driver object. |
|
609 |
* @param[in] channel Interrupt channel identifier. |
|
605 |
* @param[in] args Pointer to the GPIO pad identifier. |
|
610 | 606 |
*/ |
611 | 607 |
static void _signalSyncCallback(void *args) |
612 | 608 |
{ |
613 |
(void)args;
|
|
609 |
aosDbgCheck((args != NULL) && (*((iopadid_t*)args) < sizeof(eventflags_t) * 8));
|
|
614 | 610 |
|
615 |
#if (AMIROOS_CFG_SSSP_MASTER == true) |
|
616 |
chSysLockFromISR(); |
|
617 |
chEvtBroadcastFlagsI(&aos.events.io, 0); |
|
618 |
chSysUnlockFromISR(); |
|
619 |
#else |
|
620 | 611 |
apalControlGpioState_t s_state; |
621 | 612 |
aos_timestamp_t uptime; |
622 | 613 |
|
... | ... | |
644 | 635 |
} |
645 | 636 |
} |
646 | 637 |
// broadcast event |
647 |
chEvtBroadcastFlagsI(&aos.events.io, 0);
|
|
638 |
chEvtBroadcastFlagsI(&aos.events.io, (eventflags_t)1 << *((iopadid_t*)args));
|
|
648 | 639 |
chSysUnlockFromISR(); |
649 |
#endif |
|
650 | 640 |
|
651 | 641 |
return; |
652 | 642 |
} |
643 |
#endif |
|
653 | 644 |
|
654 | 645 |
/** |
655 | 646 |
* @brief Callback function for the uptime accumulation timer. |
... | ... | |
664 | 655 |
// read current time in system ticks |
665 | 656 |
register const systime_t st = chVTGetSystemTimeX(); |
666 | 657 |
// update the uptime variables |
667 |
_uptime += TIME_I2US(st - _synctime);
|
|
658 |
_uptime += chTimeI2US(chTimeDiffX(_synctime, st));
|
|
668 | 659 |
_synctime = st; |
669 | 660 |
// enable the timer again |
670 | 661 |
chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL); |
... | ... | |
696 | 687 |
// reconfigure the timer precisely, because the logically falling edge (next interrupt) snychronizes the system time |
697 | 688 |
_syssynctime += AMIROOS_CFG_SSSP_SYSSYNCPERIOD; |
698 | 689 |
aosSysGetUptimeX(&uptime); |
699 |
chVTSetI(&_syssynctimer, TIME_US2I(_syssynctime - uptime), _sysSyncTimerCallback, NULL);
|
|
690 |
chVTSetI(&_syssynctimer, chTimeUS2I(_syssynctime - uptime), _sysSyncTimerCallback, NULL);
|
|
700 | 691 |
} |
701 | 692 |
// if S was toggled from on to off |
702 | 693 |
else /* if (s_state == APAL_GPIO_OFF) */ { |
703 | 694 |
// reconfigure the timer (lazy) |
704 |
chVTSetI(&_syssynctimer, TIME_US2I(AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2), _sysSyncTimerCallback, NULL);
|
|
695 |
chVTSetI(&_syssynctimer, chTimeUS2I(AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2), _sysSyncTimerCallback, NULL);
|
|
705 | 696 |
} |
706 | 697 |
chSysUnlockFromISR(); |
707 | 698 |
|
... | ... | |
721 | 712 |
void aosSysInit(void) |
722 | 713 |
#endif |
723 | 714 |
{ |
724 |
// set control thread to maximum priority
|
|
715 |
/* set control thread to maximum priority */
|
|
725 | 716 |
chThdSetPriority(AOS_THD_CTRLPRIO); |
726 | 717 |
|
727 |
// set local variables
|
|
718 |
/* set local variables */
|
|
728 | 719 |
chVTObjectInit(&_systimer); |
729 | 720 |
_synctime = 0; |
730 | 721 |
_uptime = 0; |
... | ... | |
736 | 727 |
_syssyncskew = 0.0f; |
737 | 728 |
#endif |
738 | 729 |
|
739 |
// set aos configuration
|
|
730 |
/* initialize aos configuration */
|
|
740 | 731 |
aos.sssp.stage = AOS_SSSP_STARTUP_2_1; |
741 | 732 |
aos.sssp.moduleId = 0; |
742 | 733 |
aosIOStreamInit(&aos.iostream); |
743 | 734 |
chEvtObjectInit(&aos.events.io); |
744 | 735 |
chEvtObjectInit(&aos.events.os); |
745 | 736 |
|
746 |
// setup external interrupt system |
|
747 |
aosIntDriverInit(&moduleIntDriver, moduleIntConfig); |
|
748 |
chSysLock(); |
|
749 |
palSetPadCallbackI(moduleGpioSysPd.port, moduleGpioSysPd.pad, _signalPdCallback, NULL); |
|
750 |
palSetPadCallbackI(moduleGpioSysSync.port, moduleGpioSysSync.pad, _signalSyncCallback, NULL); |
|
751 |
chSysUnlock(); |
|
752 |
aosIntDriverStart(&moduleIntDriver); |
|
737 |
/* interrupt setup */ |
|
738 |
// PD signal |
|
739 |
palSetPadCallback(moduleSsspGpioPd.gpio->port, moduleSsspGpioPd.gpio->pad, _intCallback, &moduleSsspGpioPd.gpio->pad); |
|
740 |
palEnablePadEvent(moduleSsspGpioPd.gpio->port, moduleSsspGpioPd.gpio->pad, APAL2CH_EDGE(moduleSsspGpioPd.meta.edge)); |
|
741 |
// SYNC signal |
|
742 |
#if (AMIROOS_CFG_SSSP_MASTER == true) |
|
743 |
palSetPadCallback(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, _intCallback, &moduleSsspGpioSync.gpio->pad); |
|
744 |
#else |
|
745 |
palSetPadCallback(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, _signalSyncCallback, &moduleSsspGpioSync.gpio->pad); |
|
746 |
#endif |
|
747 |
palEnablePadEvent(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, APAL2CH_EDGE(moduleSsspGpioSync.meta.edge)); |
|
748 |
#if (AMIROOS_CFG_SSSP_STACK_START != true) |
|
749 |
// DN signal |
|
750 |
palSetPadCallback(moduleSsspGpioDn.gpio->port, moduleSsspGpioDn.gpio->pad, _intCallback, &moduleSsspGpioDn.gpio->pad); |
|
751 |
palEnablePadEvent(moduleSsspGpioDn.gpio->port, moduleSsspGpioDn.gpio->pad, APAL2CH_EDGE(moduleSsspGpioDn.meta.edge)); |
|
752 |
#endif |
|
753 |
#if (AMIROOS_CFG_SSSP_STACK_END != true) |
|
754 |
// UP signal |
|
755 |
palSetPadCallback(moduleSsspGpioUp.gpio->port, moduleSsspGpioUp.gpio->pad, _intCallback, &moduleSsspGpioUp.gpio->pad); |
|
756 |
palEnablePadEvent(moduleSsspGpioUp.gpio->port, moduleSsspGpioUp.gpio->pad, APAL2CH_EDGE(moduleSsspGpioUp.meta.edge)); |
|
757 |
#endif |
|
758 |
#ifdef MODULE_INIT_INTERRUPTS |
|
759 |
// further interrupt signals |
|
760 |
MODULE_INIT_INTERRUPTS(); |
|
761 |
#endif |
|
753 | 762 |
|
754 | 763 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
755 |
// init shell
|
|
764 |
/* init shell */
|
|
756 | 765 |
aosShellInit(&aos.shell, |
757 | 766 |
&aos.events.os, |
758 | 767 |
shellPrompt, |
... | ... | |
788 | 797 |
aos_timestamp_t t; |
789 | 798 |
aosSysGetUptimeX(&t); |
790 | 799 |
t = AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (t % AMIROOS_CFG_SSSP_SYSSYNCPERIOD); |
791 |
chVTSetI(&_syssynctimer, TIME_US2I((t > (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) ? (t - (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) : (t + (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2))), _sysSyncTimerCallback, NULL);
|
|
800 |
chVTSetI(&_syssynctimer, chTimeUS2I((t > (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) ? (t - (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) : (t + (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2))), _sysSyncTimerCallback, NULL);
|
|
792 | 801 |
chSysUnlock(); |
793 | 802 |
} |
794 | 803 |
#endif |
... | ... | |
865 | 874 |
{ |
866 | 875 |
aosDbgCheck(ut != NULL); |
867 | 876 |
|
868 |
*ut = _uptime + TIME_I2US(chVTGetSystemTimeX() - _synctime);
|
|
877 |
*ut = _uptime + chTimeI2US(chTimeDiffX(_synctime, chVTGetSystemTimeX()));
|
|
869 | 878 |
|
870 | 879 |
return; |
871 | 880 |
} |
... | ... | |
987 | 996 |
* @brief Finally shuts down the system and calls the bootloader callback function. |
988 | 997 |
* @note This function should be called from the thtead with highest priority. |
989 | 998 |
* |
990 |
* @param[in] extDrv Pointer to the interrupt driver. |
|
991 | 999 |
* @param[in] shutdown Type of shutdown. |
992 | 1000 |
*/ |
993 |
void aosSysShutdownFinal(aos_interrupt_driver_t* intDrv, aos_shutdown_t shutdown)
|
|
1001 |
void aosSysShutdownFinal(aos_shutdown_t shutdown) |
|
994 | 1002 |
{ |
995 | 1003 |
// check arguments |
996 |
aosDbgCheck(intDrv != NULL); |
|
997 | 1004 |
aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE); |
998 | 1005 |
|
999 |
// stop external interrupt system
|
|
1000 |
aosIntDriverStop(intDrv);
|
|
1006 |
// disable all interrupts
|
|
1007 |
irqDeinit();
|
|
1001 | 1008 |
|
1002 | 1009 |
// update the system SSSP stage |
1003 | 1010 |
aos.sssp.stage = AOS_SSSP_SHUTDOWN_1_3; |
Also available in: Unified diff