Skip to content

Commit f57f265

Browse files
authored
Merge pull request #13747 from RyoheiHagimoto/modify_renesas_deepsleep
Renesas: fix timing to wait UART completion in deep sleep function
2 parents f9e62fe + 15c28e9 commit f57f265

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1XX/sleep.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ static volatile uint8_t wk_CPGSTBREQ1;
3838
static volatile uint8_t wk_CPGSTBREQ2;
3939

4040
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;
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;

targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/device/os_tick_ostm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
* limitations under the License.
2323
*/
2424

25-
#ifdef MBED_CONF_RTOS_PRESENT
26-
27-
#include "os_tick.h"
2825
#include "irq_ctrl.h"
2926

3027
#include <MBRZA2M.h>
@@ -41,6 +38,9 @@
4138
#define OSTM (OSTM0)
4239
#define OSTM_IRQn ((IRQn_ID_t)OSTMI0_IRQn)
4340

41+
#ifdef MBED_CONF_RTOS_PRESENT
42+
43+
#include "os_tick.h"
4444

4545
static uint32_t OSTM_Clock; // Timer tick frequency
4646
static uint8_t OSTM_PendIRQ; // Timer interrupt pending flag
@@ -188,11 +188,11 @@ uint32_t OS_Tick_GetOverflow(void)
188188
{
189189
return (IRQ_GetPending(OSTM_IRQn));
190190
}
191+
#endif
191192

192193
// Get Cortex-A9 OS Timer interrupt number
193194
IRQn_ID_t mbed_get_a9_tick_irqn()
194195
{
195196
return OSTM_IRQn;
196197
}
197-
#endif
198198

targets/TARGET_RENESAS/TARGET_RZ_A2XX/sleep.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ static const module_stanby_t module_stanby[] = {
5959
{0, 0, 0, 0, 0} /* None */
6060
};
6161

62+
/* Channel array defines of SCIF */
63+
/*(Sample) value = SCIF[ channel ]->SCSMR; */
64+
#define SCIFA_COUNT (5)
65+
#define SCIFA_ADDRESS_LIST \
66+
{ /* ->MISRA 11.3 */ /* ->SEC R2.7.1 */ \
67+
&SCIFA0, &SCIFA1, &SCIFA2, &SCIFA3, &SCIFA4 \
68+
} /* <-MISRA 11.3 */ /* <-SEC R2.7.1 */ /* { } is for MISRA 19.4 */
69+
70+
/* End of channel array defines of SCIF */
71+
6272
static void module_standby_in(void)
6373
{
6474
volatile uint32_t cnt;
@@ -113,6 +123,20 @@ void hal_deepsleep(void)
113123
{
114124
volatile uint8_t dummy_8;
115125

126+
/* Waits for the serial transmission to complete */
127+
volatile const struct st_scifa *SCIFA[SCIFA_COUNT] = SCIFA_ADDRESS_LIST;
128+
129+
for (int uart = 0; uart < SCIFA_COUNT; uart++) {
130+
/* Is the power turned on? */
131+
if ((wk_CPGSTBCR4 & (1 << (7 - uart))) == 0) {
132+
/* Is transmission enabled? (TE = 1, TIE = 1) */
133+
if ((SCIFA[uart]->SCR.WORD & 0x00A0) == 0x00A0) {
134+
/* Waits for the transmission to complete (TEND = 1) */
135+
while ((SCIFA[uart]->FSR.WORD & 0x0040) == 0);
136+
}
137+
}
138+
}
139+
116140
core_util_critical_section_enter();
117141
/* For powerdown the peripheral module, save current standby control register values(just in case) */
118142
wk_CPGSTBCR3 = CPG.STBCR3.BYTE;

0 commit comments

Comments
 (0)