@@ -38,10 +38,10 @@ static volatile uint8_t wk_CPGSTBREQ1;
3838static volatile uint8_t wk_CPGSTBREQ2 ;
3939
4040typedef struct {
41- volatile uint8_t * p_wk_stbcr ;
42- volatile uint8_t * p_stbcr ;
43- volatile uint8_t * p_stbreq ;
44- volatile uint8_t * p_stback ;
41+ volatile uint8_t * p_wk_stbcr ;
42+ volatile uint8_t * p_stbcr ;
43+ volatile uint8_t * p_stbreq ;
44+ volatile uint8_t * p_stback ;
4545 uint8_t mstp ;
4646 uint8_t stbrq ;
4747} module_stanby_t ;
@@ -63,10 +63,11 @@ static const module_stanby_t module_stanby[] = {
6363 {0 , 0 , 0 , 0 , 0 } /* None */
6464};
6565
66- static void module_standby_in (void ) {
66+ static void module_standby_in (void )
67+ {
6768 volatile uint32_t cnt ;
6869 volatile uint8_t dummy_8 ;
69- const module_stanby_t * p_module = & module_stanby [0 ];
70+ const module_stanby_t * p_module = & module_stanby [0 ];
7071
7172 while (p_module -> p_wk_stbcr != 0 ) {
7273 if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -85,10 +86,11 @@ static void module_standby_in(void) {
8586 (void )dummy_8 ;
8687}
8788
88- static void module_standby_out (void ) {
89+ static void module_standby_out (void )
90+ {
8991 volatile uint32_t cnt ;
9092 volatile uint8_t dummy_8 ;
91- const module_stanby_t * p_module = & module_stanby [0 ];
93+ const module_stanby_t * p_module = & module_stanby [0 ];
9294
9395 while (p_module -> p_wk_stbcr != 0 ) {
9496 if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -105,14 +107,28 @@ static void module_standby_out(void) {
105107 (void )dummy_8 ;
106108}
107109
108- void hal_sleep (void ) {
110+ void hal_sleep (void )
111+ {
109112 // Transition to Sleep Mode
110113 __WFI ();
111114}
112115
113- void hal_deepsleep (void ) {
116+ void hal_deepsleep (void )
117+ {
114118 volatile uint8_t dummy_8 ;
115119
120+ /* Waits for the serial transmission to complete */
121+ const struct st_scif * SCIF [SCIF_COUNT ] = SCIF_ADDRESS_LIST ;
122+
123+ for (int uart = 0 ; uart < SCIF_COUNT ; uart ++ ) {
124+ if ((wk_CPGSTBCR4 & (1 << (7 - uart ))) == 0 ) { // Is the power turned on?
125+ if ((SCIF [uart ]-> SCSCR & 0x00A0 ) == 0x00A0 ) { // Is transmission enabled? (TE = 1, TIE = 1)
126+ /* Waits for the transmission to complete (TEND = 1) */
127+ while ((SCIF [uart ]-> SCFSR & 0x0040 ) == 0 ); // Waits for the transmission to complete (TEND = 1)
128+ }
129+ }
130+ }
131+
116132 core_util_critical_section_enter ();
117133 /* For powerdown the peripheral module, save current standby control register values(just in case) */
118134 wk_CPGSTBCR3 = CPGSTBCR3 ;
@@ -129,17 +145,6 @@ void hal_deepsleep(void) {
129145 wk_CPGSTBCR13 = CPGSTBCR13 ;
130146#endif
131147
132- /* Waits for the serial transmission to complete */
133- const struct st_scif * SCIF [SCIF_COUNT ] = SCIF_ADDRESS_LIST ;
134-
135- for (int uart = 0 ; uart < SCIF_COUNT ; uart ++ ) {
136- if ((wk_CPGSTBCR4 & (1 << (7 - uart ))) == 0 ) { // Is the power turned on?
137- if ((SCIF [uart ]-> SCSCR & 0x00A0 ) == 0x00A0 ) { // Is transmission enabled? (TE = 1, TIE = 1)
138- while ((SCIF [uart ]-> SCFSR & 0x0040 ) == 0 ); // Waits for the transmission to complete (TEND = 1)
139- }
140- }
141- }
142-
143148 /* MTU2 (for low power ticker) */
144149 CPGSTBCR3 |= ~(CPG_STBCR3_BIT_MSTP33 );
145150 dummy_8 = CPGSTBCR3 ;
0 commit comments