Skip to content

Commit 15c28e9

Browse files
Modified the timing to wait UART completion in deep sleep function.
Moved waiting UART transmission completion to the out of critical section. This is issued by the following pull request. ARMmbed#11816
1 parent ad40b1b commit 15c28e9

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
@@ -37,10 +37,10 @@ static volatile uint8_t wk_CPGSTBREQ1;
3737
static volatile uint8_t wk_CPGSTBREQ2;
3838

3939
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;
4444
uint8_t mstp;
4545
uint8_t stbrq;
4646
} module_stanby_t;
@@ -62,10 +62,11 @@ static const module_stanby_t module_stanby[] = {
6262
{0, 0, 0, 0, 0} /* None */
6363
};
6464

65-
static void module_standby_in(void) {
65+
static void module_standby_in(void)
66+
{
6667
volatile uint32_t cnt;
6768
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];
6970

7071
while (p_module->p_wk_stbcr != 0) {
7172
if ((*p_module->p_wk_stbcr & p_module->mstp) == 0) {
@@ -84,10 +85,11 @@ static void module_standby_in(void) {
8485
(void)dummy_8;
8586
}
8687

87-
static void module_standby_out(void) {
88+
static void module_standby_out(void)
89+
{
8890
volatile uint32_t cnt;
8991
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];
9193

9294
while (p_module->p_wk_stbcr != 0) {
9395
if ((*p_module->p_wk_stbcr & p_module->mstp) == 0) {
@@ -104,14 +106,28 @@ static void module_standby_out(void) {
104106
(void)dummy_8;
105107
}
106108

107-
void hal_sleep(void) {
109+
void hal_sleep(void)
110+
{
108111
// Transition to Sleep Mode
109112
__WFI();
110113
}
111114

112-
void hal_deepsleep(void) {
115+
void hal_deepsleep(void)
116+
{
113117
volatile uint8_t dummy_8;
114118

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+
115131
core_util_critical_section_enter();
116132
/* For powerdown the peripheral module, save current standby control register values(just in case) */
117133
wk_CPGSTBCR3 = CPGSTBCR3;
@@ -128,17 +144,6 @@ void hal_deepsleep(void) {
128144
wk_CPGSTBCR13 = CPGSTBCR13;
129145
#endif
130146

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-
142147
/* MTU2 (for low power ticker) */
143148
CPGSTBCR3 |= ~(CPG_STBCR3_BIT_MSTP33);
144149
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)