From 2b98dc3de8ecb3ed5c9d1be2c49eb99df45567f6 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 17 Nov 2017 11:44:56 +0900 Subject: [PATCH] Update example-fsm-55. --- ChangeLog | 2 ++ doc/chopstx.texi | 8 +++--- example-fsm-55/Makefile | 2 ++ example-fsm-55/debian-logo.c | 54 +++--------------------------------- example-fsm-55/hh.c | 6 ++-- 5 files changed, 15 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index cdac545..f98980c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2017-11-17 NIIBE Yutaka + * example-fsm-55: Update for new sleep API. + * rules.mk (CSRC): Add mcu/chx-$(CHIP).c. * chopstx-cortex-m.c (idle, chx_sleep_mode): Remove. diff --git a/doc/chopstx.texi b/doc/chopstx.texi index 12b7d4f..762a4b0 100644 --- a/doc/chopstx.texi +++ b/doc/chopstx.texi @@ -97,12 +97,12 @@ enables coherent code for ease of maintenance. @node Use of sleep mode Calling the chopstx_conf_idle function with 1 to allow the idle thread going to sleep. MCU will be in sleep mode when no threads are -running. By setting relevant system registers, MCU will be able to be -into deep sleep or stand-by mode. +running. By setting relevant bits of system registers, MCU will be +able to be into stop or stand-by mode, which is MCU dependent. If you use this sleep feature, please consider and implement -carefully. Enabling sleep, it may result bricked board; A board with -no RESET pin cannot be debugged by JTAG/SWD. +carefully. Enabling sleep, it may result a bricked board; A board +with no RESET pin cannot be debugged by JTAG/SWD. @node API diff --git a/example-fsm-55/Makefile b/example-fsm-55/Makefile index 4ec6257..791b2b9 100644 --- a/example-fsm-55/Makefile +++ b/example-fsm-55/Makefile @@ -7,6 +7,8 @@ LDSCRIPT= hacker-emblem.ld CSRC = reset.c hh.c +CHIP=stm32f0 + # Hacker Emblem and "Happy Hacking!" demonstration # CSRC = reset.c hh.c diff --git a/example-fsm-55/debian-logo.c b/example-fsm-55/debian-logo.c index de7ca5c..091d909 100644 --- a/example-fsm-55/debian-logo.c +++ b/example-fsm-55/debian-logo.c @@ -378,6 +378,8 @@ main (int argc, const char *argv[]) (void)argc; (void)argv; + chopstx_conf_idle (1); + chopstx_mutex_init (&mtx); chopstx_cond_init (&cnd0); chopstx_cond_init (&cnd1); @@ -418,56 +420,8 @@ main (int argc, const char *argv[]) chopstx_join (button_thd, NULL); chopstx_join (led_thd, NULL); - setup_scr_sleepdeep (); - for (;;) - asm volatile ("wfi" : : : "memory"); + chopstx_conf_idle (4); + chopstx_poll (NULL, 0, NULL); return 0; } - -struct SCB -{ - volatile uint32_t CPUID; - volatile uint32_t ICSR; - volatile uint32_t VTOR; - volatile uint32_t AIRCR; - volatile uint32_t SCR; - volatile uint32_t CCR; - volatile uint8_t SHP[12]; - volatile uint32_t SHCSR; - volatile uint32_t CFSR; - volatile uint32_t HFSR; - volatile uint32_t DFSR; - volatile uint32_t MMFAR; - volatile uint32_t BFAR; - volatile uint32_t AFSR; - volatile uint32_t PFR[2]; - volatile uint32_t DFR; - volatile uint32_t ADR; - volatile uint32_t MMFR[4]; - volatile uint32_t ISAR[5]; -}; - -#define SCS_BASE (0xE000E000) -#define SCB_BASE (SCS_BASE + 0x0D00) -static struct SCB *const SCB = ((struct SCB *)SCB_BASE); - -#define SCB_SCR_SLEEPDEEP (1 << 2) - -struct PWR -{ - volatile uint32_t CR; - volatile uint32_t CSR; -}; -#define PWR_CR_PDDS 0x0002 -#define PWR_CR_CWUF 0x0004 - -#define PWR_BASE (APBPERIPH_BASE + 0x00007000) -#define PWR ((struct PWR *) PWR_BASE) - -static void setup_scr_sleepdeep (void) -{ - PWR->CR |= PWR_CR_CWUF; - PWR->CR |= PWR_CR_PDDS; - SCB->SCR |= SCB_SCR_SLEEPDEEP; -} diff --git a/example-fsm-55/hh.c b/example-fsm-55/hh.c index 45e2638..9c77d9d 100644 --- a/example-fsm-55/hh.c +++ b/example-fsm-55/hh.c @@ -364,7 +364,7 @@ main (int argc, const char *argv[]) (void)argc; (void)argv; - chopstx_conf_idle (4); + chopstx_conf_idle (1); chopstx_mutex_init (&mtx); chopstx_cond_init (&cnd0); @@ -406,8 +406,8 @@ main (int argc, const char *argv[]) chopstx_join (button_thd, NULL); chopstx_join (led_thd, NULL); - for (;;) - asm volatile ("wfi" : : : "memory"); + chopstx_conf_idle (4); + chopstx_poll (NULL, 0, NULL); return 0; }