@@ -38,10 +38,10 @@ static volatile uint8_t wk_CPGSTBREQ1;
38
38
static volatile uint8_t wk_CPGSTBREQ2 ;
39
39
40
40
typedef 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 ;
45
45
uint8_t mstp ;
46
46
uint8_t stbrq ;
47
47
} module_stanby_t ;
@@ -63,10 +63,11 @@ static const module_stanby_t module_stanby[] = {
63
63
{0 , 0 , 0 , 0 , 0 } /* None */
64
64
};
65
65
66
- static void module_standby_in (void ) {
66
+ static void module_standby_in (void )
67
+ {
67
68
volatile uint32_t cnt ;
68
69
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 ];
70
71
71
72
while (p_module -> p_wk_stbcr != 0 ) {
72
73
if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -85,10 +86,11 @@ static void module_standby_in(void) {
85
86
(void )dummy_8 ;
86
87
}
87
88
88
- static void module_standby_out (void ) {
89
+ static void module_standby_out (void )
90
+ {
89
91
volatile uint32_t cnt ;
90
92
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 ];
92
94
93
95
while (p_module -> p_wk_stbcr != 0 ) {
94
96
if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -105,14 +107,28 @@ static void module_standby_out(void) {
105
107
(void )dummy_8 ;
106
108
}
107
109
108
- void hal_sleep (void ) {
110
+ void hal_sleep (void )
111
+ {
109
112
// Transition to Sleep Mode
110
113
__WFI ();
111
114
}
112
115
113
- void hal_deepsleep (void ) {
116
+ void hal_deepsleep (void )
117
+ {
114
118
volatile uint8_t dummy_8 ;
115
119
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
+
116
132
core_util_critical_section_enter ();
117
133
/* For powerdown the peripheral module, save current standby control register values(just in case) */
118
134
wk_CPGSTBCR3 = CPGSTBCR3 ;
@@ -129,17 +145,6 @@ void hal_deepsleep(void) {
129
145
wk_CPGSTBCR13 = CPGSTBCR13 ;
130
146
#endif
131
147
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
-
143
148
/* MTU2 (for low power ticker) */
144
149
CPGSTBCR3 |= ~(CPG_STBCR3_BIT_MSTP33 );
145
150
dummy_8 = CPGSTBCR3 ;
0 commit comments