Revision 0128be0f os/core/src/aos_system.c
os/core/src/aos_system.c | ||
---|---|---|
25 | 25 |
#include <stdlib.h> |
26 | 26 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) |
27 | 27 |
#include <ch_test.h> |
28 |
#include <rt_test_root.h> |
|
28 | 29 |
#endif |
29 | 30 |
|
30 | 31 |
/** |
31 | 32 |
* @brief Period of the system timer. |
32 | 33 |
*/ |
33 |
#define SYSTIMER_PERIOD (TIME_MAXIMUM - CH_CFG_ST_TIMEDELTA)
|
|
34 |
#define SYSTIMER_PERIOD (TIME_MAX_INTERVAL - CH_CFG_ST_TIMEDELTA)
|
|
34 | 35 |
|
35 | 36 |
/** |
36 | 37 |
* @brief Width of the printable system info text. |
... | ... | |
577 | 578 |
|
578 | 579 |
tprio_t prio = chThdGetPriorityX(); |
579 | 580 |
chThdSetPriority(HIGHPRIO - 5); // some tests increase priorirty by 5, so this is the maximum priority permitted |
580 |
msg_t retval = test_execute(stream); |
|
581 |
msg_t retval = test_execute(stream, &rt_test_suite);
|
|
581 | 582 |
chThdSetPriority(prio); |
582 | 583 |
|
583 | 584 |
return retval; |
... | ... | |
590 | 591 |
* @param[in] extp Pointer to the interrupt driver object. |
591 | 592 |
* @param[in] channel Interrupt channel identifier. |
592 | 593 |
*/ |
593 |
static void _signalPdCallback(EXTDriver* extp, expchannel_t channel)
|
|
594 |
static void _signalPdCallback(void *args)
|
|
594 | 595 |
{ |
595 |
(void)extp;
|
|
596 |
(void)args;
|
|
596 | 597 |
|
597 | 598 |
chSysLockFromISR(); |
598 |
chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
|
|
599 |
chEvtBroadcastFlagsI(&aos.events.io, 0);
|
|
599 | 600 |
chSysUnlockFromISR(); |
600 | 601 |
|
601 | 602 |
return; |
... | ... | |
607 | 608 |
* @param[in] extp Pointer to the interrupt driver object. |
608 | 609 |
* @param[in] channel Interrupt channel identifier. |
609 | 610 |
*/ |
610 |
static void _signalSyncCallback(EXTDriver* extp, expchannel_t channel)
|
|
611 |
static void _signalSyncCallback(void *args)
|
|
611 | 612 |
{ |
612 |
(void)extp;
|
|
613 |
(void)args;
|
|
613 | 614 |
|
614 | 615 |
#if (AMIROOS_CFG_SSSP_MASTER == true) |
615 | 616 |
chSysLockFromISR(); |
616 |
chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
|
|
617 |
chEvtBroadcastFlagsI(&aos.events.io, 0);
|
|
617 | 618 |
chSysUnlockFromISR(); |
618 | 619 |
#else |
619 | 620 |
apalControlGpioState_t s_state; |
... | ... | |
643 | 644 |
} |
644 | 645 |
} |
645 | 646 |
// broadcast event |
646 |
chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
|
|
647 |
chEvtBroadcastFlagsI(&aos.events.io, 0);
|
|
647 | 648 |
chSysUnlockFromISR(); |
648 | 649 |
#endif |
649 | 650 |
|
... | ... | |
663 | 664 |
// read current time in system ticks |
664 | 665 |
register const systime_t st = chVTGetSystemTimeX(); |
665 | 666 |
// update the uptime variables |
666 |
_uptime += LL_ST2US(st - _synctime);
|
|
667 |
_uptime += TIME_I2US(st - _synctime);
|
|
667 | 668 |
_synctime = st; |
668 | 669 |
// enable the timer again |
669 | 670 |
chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL); |
... | ... | |
695 | 696 |
// reconfigure the timer precisely, because the logically falling edge (next interrupt) snychronizes the system time |
696 | 697 |
_syssynctime += AMIROOS_CFG_SSSP_SYSSYNCPERIOD; |
697 | 698 |
aosSysGetUptimeX(&uptime); |
698 |
chVTSetI(&_syssynctimer, LL_US2ST(_syssynctime - uptime), _sysSyncTimerCallback, NULL);
|
|
699 |
chVTSetI(&_syssynctimer, TIME_US2I(_syssynctime - uptime), _sysSyncTimerCallback, NULL);
|
|
699 | 700 |
} |
700 | 701 |
// if S was toggled from on to off |
701 | 702 |
else /* if (s_state == APAL_GPIO_OFF) */ { |
702 | 703 |
// reconfigure the timer (lazy) |
703 |
chVTSetI(&_syssynctimer, LL_US2ST(AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2), _sysSyncTimerCallback, NULL);
|
|
704 |
chVTSetI(&_syssynctimer, TIME_US2I(AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2), _sysSyncTimerCallback, NULL);
|
|
704 | 705 |
} |
705 | 706 |
chSysUnlockFromISR(); |
706 | 707 |
|
... | ... | |
743 | 744 |
chEvtObjectInit(&aos.events.os); |
744 | 745 |
|
745 | 746 |
// setup external interrupt system |
746 |
moduleHalExtConfig.channels[moduleSsspGpioPd.gpio->pad].cb = _signalPdCallback; |
|
747 |
moduleHalExtConfig.channels[moduleSsspGpioSync.gpio->pad].cb = _signalSyncCallback; |
|
748 |
extStart(&MODULE_HAL_EXT, &moduleHalExtConfig); |
|
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); |
|
749 | 753 |
|
750 | 754 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
751 | 755 |
// init shell |
... | ... | |
784 | 788 |
aos_timestamp_t t; |
785 | 789 |
aosSysGetUptimeX(&t); |
786 | 790 |
t = AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (t % AMIROOS_CFG_SSSP_SYSSYNCPERIOD); |
787 |
chVTSetI(&_syssynctimer, LL_US2ST((t > (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) ? (t - (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) : (t + (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2))), _sysSyncTimerCallback, NULL);
|
|
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);
|
|
788 | 792 |
chSysUnlock(); |
789 | 793 |
} |
790 | 794 |
#endif |
... | ... | |
861 | 865 |
{ |
862 | 866 |
aosDbgCheck(ut != NULL); |
863 | 867 |
|
864 |
*ut = _uptime + LL_ST2US(chVTGetSystemTimeX() - _synctime);
|
|
868 |
*ut = _uptime + TIME_I2US(chVTGetSystemTimeX() - _synctime);
|
|
865 | 869 |
|
866 | 870 |
return; |
867 | 871 |
} |
... | ... | |
986 | 990 |
* @param[in] extDrv Pointer to the interrupt driver. |
987 | 991 |
* @param[in] shutdown Type of shutdown. |
988 | 992 |
*/ |
989 |
void aosSysShutdownFinal(EXTDriver* extDrv, aos_shutdown_t shutdown)
|
|
993 |
void aosSysShutdownFinal(aos_interrupt_driver_t* intDrv, aos_shutdown_t shutdown)
|
|
990 | 994 |
{ |
991 | 995 |
// check arguments |
992 |
aosDbgCheck(extDrv != NULL);
|
|
996 |
aosDbgCheck(intDrv != NULL);
|
|
993 | 997 |
aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE); |
994 | 998 |
|
995 | 999 |
// stop external interrupt system |
996 |
extStop(extDrv);
|
|
1000 |
aosIntDriverStop(intDrv);
|
|
997 | 1001 |
|
998 | 1002 |
// update the system SSSP stage |
999 | 1003 |
aos.sssp.stage = AOS_SSSP_SHUTDOWN_1_3; |
Also available in: Unified diff