@@ -37,10 +37,10 @@ static volatile uint8_t wk_CPGSTBREQ1;
37
37
static volatile uint8_t wk_CPGSTBREQ2 ;
38
38
39
39
typedef struct {
40
- volatile uint8_t * p_wk_stbcr ;
41
- volatile uint8_t * p_stbcr ;
42
- volatile uint8_t * p_stbreq ;
43
- volatile uint8_t * p_stback ;
40
+ volatile uint8_t * p_wk_stbcr ;
41
+ volatile uint8_t * p_stbcr ;
42
+ volatile uint8_t * p_stbreq ;
43
+ volatile uint8_t * p_stback ;
44
44
uint8_t mstp ;
45
45
uint8_t stbrq ;
46
46
} module_stanby_t ;
@@ -62,10 +62,11 @@ static const module_stanby_t module_stanby[] = {
62
62
{0 , 0 , 0 , 0 , 0 } /* None */
63
63
};
64
64
65
- static void module_standby_in (void ) {
65
+ static void module_standby_in (void )
66
+ {
66
67
volatile uint32_t cnt ;
67
68
volatile uint8_t dummy_8 ;
68
- const module_stanby_t * p_module = & module_stanby [0 ];
69
+ const module_stanby_t * p_module = & module_stanby [0 ];
69
70
70
71
while (p_module -> p_wk_stbcr != 0 ) {
71
72
if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -84,10 +85,11 @@ static void module_standby_in(void) {
84
85
(void )dummy_8 ;
85
86
}
86
87
87
- static void module_standby_out (void ) {
88
+ static void module_standby_out (void )
89
+ {
88
90
volatile uint32_t cnt ;
89
91
volatile uint8_t dummy_8 ;
90
- const module_stanby_t * p_module = & module_stanby [0 ];
92
+ const module_stanby_t * p_module = & module_stanby [0 ];
91
93
92
94
while (p_module -> p_wk_stbcr != 0 ) {
93
95
if ((* p_module -> p_wk_stbcr & p_module -> mstp ) == 0 ) {
@@ -104,14 +106,28 @@ static void module_standby_out(void) {
104
106
(void )dummy_8 ;
105
107
}
106
108
107
- void hal_sleep (void ) {
109
+ void hal_sleep (void )
110
+ {
108
111
// Transition to Sleep Mode
109
112
__WFI ();
110
113
}
111
114
112
- void hal_deepsleep (void ) {
115
+ void hal_deepsleep (void )
116
+ {
113
117
volatile uint8_t dummy_8 ;
114
118
119
+ /* Waits for the serial transmission to complete */
120
+ const struct st_scif * SCIF [SCIF_COUNT ] = SCIF_ADDRESS_LIST ;
121
+
122
+ for (int uart = 0 ; uart < SCIF_COUNT ; uart ++ ) {
123
+ if ((wk_CPGSTBCR4 & (1 << (7 - uart ))) == 0 ) { // Is the power turned on?
124
+ if ((SCIF [uart ]-> SCSCR & 0x00A0 ) == 0x00A0 ) { // Is transmission enabled? (TE = 1, TIE = 1)
125
+ /* Waits for the transmission to complete (TEND = 1) */
126
+ while ((SCIF [uart ]-> SCFSR & 0x0040 ) == 0 ); // Waits for the transmission to complete (TEND = 1)
127
+ }
128
+ }
129
+ }
130
+
115
131
core_util_critical_section_enter ();
116
132
/* For powerdown the peripheral module, save current standby control register values(just in case) */
117
133
wk_CPGSTBCR3 = CPGSTBCR3 ;
@@ -128,17 +144,6 @@ void hal_deepsleep(void) {
128
144
wk_CPGSTBCR13 = CPGSTBCR13 ;
129
145
#endif
130
146
131
- /* Waits for the serial transmission to complete */
132
- const struct st_scif * SCIF [SCIF_COUNT ] = SCIF_ADDRESS_LIST ;
133
-
134
- for (int uart = 0 ; uart < SCIF_COUNT ; uart ++ ) {
135
- if ((wk_CPGSTBCR4 & (1 << (7 - uart ))) == 0 ) { // Is the power turned on?
136
- if ((SCIF [uart ]-> SCSCR & 0x00A0 ) == 0x00A0 ) { // Is transmission enabled? (TE = 1, TIE = 1)
137
- while ((SCIF [uart ]-> SCFSR & 0x0040 ) == 0 ); // Waits for the transmission to complete (TEND = 1)
138
- }
139
- }
140
- }
141
-
142
147
/* MTU2 (for low power ticker) */
143
148
CPGSTBCR3 |= ~(CPG_STBCR3_BIT_MSTP33 );
144
149
dummy_8 = CPGSTBCR3 ;
0 commit comments