Skip to content

Commit 1e8b3f3

Browse files
TomoYamanakabulislaw
authored andcommitted
Implementation of USTICKER feature for Renesas mbed boards
I implemented USTICKER feature. The mainly changing is here. - I added a macro to mbed_drv_cfg.h for commonalizing code for GR-PEACH and GR-LYCHEE with different clock frequencies, and referenced it's macro at us_ticker.c. - ticker_init() Currently, ticker_init() keep counting, disables the ticker interrupt, and is safe to call repeatedly. Therefore, in order to satisfy specifications, I removed GIC_EnableIRQ at end of function and added GIC_DisableIRQ at begin of function. When an interrupt is required, it will be set with ticker_set_interrupt(). If executing the following, the counter has been initialized. So it will not call after executing the first time. OSTM1TT = 0x01; /* Stop the counter and clears the OSTM1TE bit. */ OSTM1TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */ - ticker_free() this function stops the counting and powerdown the us_ticker. To satisfy the mbed specificationm, I implemented free() function. - ticker_read() Currently, Mbed spec's frequeny is between 250KHz and 8MHz, but the frequency that is used at my ticker is 33MHz. Therefore, in order to satisfy specifications, I changed the process to return the timer counter value divided by 32(33MHz / 32). Since the calcurate function by using 64 bit is no longer necessay, I removed it. - ticker_set_interrupt() Same as the above read(), In order to satisfy specifications, I changed the process to set the value multiplied by 32. - ticker_fire_interrupt() In order to satisfy specifications, I implemented fire_interrupt() function. Also I added GIC_EnableIRQ for allowing the interrupt at end of function. - ticker_get_info() To satisfy the mbed specificationm, I implemented ticker_get_info() function. The value of freq includes rounding off.
1 parent 2e7cf42 commit 1e8b3f3

File tree

5 files changed

+50
-105
lines changed

5 files changed

+50
-105
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/mbed_drv_cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
//#define USE_EXTAL_CLK
3333
//#define USE_RTCX3_CLK
3434

35+
#define RENESAS_RZ_A1_P0_CLK CM1_RENESAS_RZ_A1_P0_CLK
36+
3537
#endif

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/mbed_drv_cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
#define USE_EXTAL_CLK
3333
//#define USE_RTCX3_CLK
3434

35+
#define RENESAS_RZ_A1_P0_CLK CM0_RENESAS_RZ_A1_P0_CLK
36+
3537
#endif

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_VK_RZ_A1H/mbed_drv_cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
//#define USE_EXTAL_CLK
3333
//#define USE_RTCX3_CLK
3434

35+
#define RENESAS_RZ_A1_P0_CLK CM0_RENESAS_RZ_A1_P0_CLK
36+
3537
#endif

targets/TARGET_RENESAS/TARGET_RZ_A1XX/us_ticker.c

Lines changed: 43 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -13,139 +13,78 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#include <stddef.h>
1716
#include "us_ticker_api.h"
18-
#include "PeripheralNames.h"
19-
#include "iodefine.h"
20-
#include "cmsis.h"
17+
#include "mbed_drv_cfg.h"
2118

22-
#include "RZ_A1_Init.h"
23-
#include "vfp_neon_push_pop.h"
24-
#include "mbed_critical.h"
19+
#define SHIFT_NUM 5 /* P0/32 */
2520

26-
#define US_TICKER_TIMER_IRQn (OSTMI1TINT_IRQn)
27-
#define CPG_STBCR5_BIT_MSTP50 (0x01u) /* OSTM1 */
21+
static int us_ticker_inited = 0;
2822

29-
#define US_TICKER_CLOCK_US_DEV (1000000)
23+
void us_ticker_init(void)
24+
{
25+
GIC_DisableIRQ(OSTMI1TINT_IRQn);
26+
GIC_ClearPendingIRQ(OSTMI1TINT_IRQn);
3027

31-
int us_ticker_inited = 0;
32-
static double count_clock = 0;
33-
static uint32_t last_read = 0;
34-
static uint32_t wrap_arround = 0;
35-
static uint64_t ticker_us_last64 = 0;
36-
static uint64_t set_cmp_val64 = 0;
37-
static uint64_t timestamp64 = 0;
38-
39-
void us_ticker_interrupt(void) {
40-
us_ticker_irq_handler();
41-
}
28+
/* Power Control for Peripherals */
29+
CPGSTBCR5 &= ~(CPG_STBCR5_BIT_MSTP50); /* enable OSTM1 clock */
4230

43-
void us_ticker_init(void) {
4431
if (us_ticker_inited) return;
4532
us_ticker_inited = 1;
4633

47-
/* set Counter Clock(us) */
48-
if (false == RZ_A1_IsClockMode0()) {
49-
count_clock = ((double)CM1_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
50-
} else {
51-
count_clock = ((double)CM0_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
52-
}
53-
54-
/* Power Control for Peripherals */
55-
CPGSTBCR5 &= ~(CPG_STBCR5_BIT_MSTP50); /* enable OSTM1 clock */
56-
5734
// timer settings
5835
OSTM1TT = 0x01; /* Stop the counter and clears the OSTM1TE bit. */
5936
OSTM1CTL = 0x02; /* Free running timer mode. Interrupt disabled when star counter */
6037

61-
OSTM1TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */
38+
OSTM1TS = 0x1; /* Start the counter and sets the OSTM0TE bit. */
6239

6340
// INTC settings
64-
InterruptHandlerRegister(US_TICKER_TIMER_IRQn, (void (*)(uint32_t))us_ticker_interrupt);
65-
GIC_SetPriority(US_TICKER_TIMER_IRQn, 5);
66-
GIC_SetConfiguration(US_TICKER_TIMER_IRQn, 3);
67-
GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
41+
InterruptHandlerRegister(OSTMI1TINT_IRQn, (void (*)(uint32_t))us_ticker_irq_handler);
42+
GIC_SetPriority(OSTMI1TINT_IRQn, 5);
43+
GIC_SetConfiguration(OSTMI1TINT_IRQn, 3);
6844
}
6945

70-
static uint64_t ticker_read_counter64(void) {
71-
uint32_t cnt_val;
72-
uint64_t cnt_val64;
73-
74-
if (!us_ticker_inited)
75-
us_ticker_init();
46+
void us_ticker_free(void)
47+
{
48+
GIC_DisableIRQ(OSTMI1TINT_IRQn);
49+
GIC_ClearPendingIRQ(OSTMI1TINT_IRQn);
7650

77-
/* read counter */
78-
cnt_val = OSTM1CNT;
79-
if (last_read > cnt_val) {
80-
wrap_arround++;
81-
}
82-
last_read = cnt_val;
83-
cnt_val64 = ((uint64_t)wrap_arround << 32) + cnt_val;
84-
85-
return cnt_val64;
51+
/* Power Control for Peripherals */
52+
CPGSTBCR5 |= (CPG_STBCR5_BIT_MSTP50); /* disable OSTM1 clock */
8653
}
8754

88-
static void us_ticker_read_last(void) {
89-
uint64_t cnt_val64;
90-
91-
cnt_val64 = ticker_read_counter64();
92-
93-
ticker_us_last64 = (cnt_val64 / count_clock);
55+
uint32_t us_ticker_read()
56+
{
57+
return (uint32_t)(OSTM1CNT >> SHIFT_NUM);
9458
}
9559

96-
uint32_t us_ticker_read() {
97-
core_util_critical_section_enter();
98-
99-
__vfp_neon_push();
100-
us_ticker_read_last();
101-
__vfp_neon_pop();
102-
103-
core_util_critical_section_exit();
104-
105-
/* clock to us */
106-
return (uint32_t)ticker_us_last64;
60+
void us_ticker_set_interrupt(timestamp_t timestamp)
61+
{
62+
OSTM1CMP = (uint32_t)(timestamp << SHIFT_NUM);
63+
GIC_EnableIRQ(OSTMI1TINT_IRQn);
10764
}
10865

109-
static void us_ticker_calc_compare_match(void) {
110-
set_cmp_val64 = timestamp64 * count_clock;
66+
void us_ticker_fire_interrupt(void)
67+
{
68+
GIC_SetPendingIRQ(OSTMI1TINT_IRQn);
69+
GIC_EnableIRQ(OSTMI1TINT_IRQn);
11170
}
11271

113-
void us_ticker_set_interrupt(timestamp_t timestamp) {
114-
// set match value
115-
volatile uint32_t set_cmp_val;
116-
uint64_t count_val_64;
117-
118-
/* calc compare mach timestamp */
119-
timestamp64 = (ticker_us_last64 & 0xFFFFFFFF00000000) + timestamp;
120-
if (timestamp < (ticker_us_last64 & 0x00000000FFFFFFFF)) {
121-
/* This event is wrap arround */
122-
timestamp64 += 0x100000000;
123-
}
124-
125-
/* calc compare mach timestamp */
126-
__vfp_neon_push();
127-
us_ticker_calc_compare_match();
128-
__vfp_neon_pop();
129-
130-
set_cmp_val = (uint32_t)(set_cmp_val64 & 0x00000000FFFFFFFF);
131-
count_val_64 = ticker_read_counter64();
132-
if (set_cmp_val64 <= (count_val_64 + 500)) {
133-
GIC_SetPendingIRQ(US_TICKER_TIMER_IRQn);
134-
GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
135-
return;
136-
}
137-
OSTM1CMP = set_cmp_val;
138-
GIC_EnableIRQ(US_TICKER_TIMER_IRQn);
72+
void us_ticker_disable_interrupt(void)
73+
{
74+
GIC_DisableIRQ(OSTMI1TINT_IRQn);
13975
}
14076

141-
void us_ticker_fire_interrupt(void) {
142-
GIC_SetPendingIRQ(US_TICKER_TIMER_IRQn);
77+
void us_ticker_clear_interrupt(void)
78+
{
79+
GIC_ClearPendingIRQ(OSTMI1TINT_IRQn);
14380
}
14481

145-
void us_ticker_disable_interrupt(void) {
146-
GIC_DisableIRQ(US_TICKER_TIMER_IRQn);
82+
const ticker_info_t* us_ticker_get_info()
83+
{
84+
static const ticker_info_t info = {
85+
(uint32_t)((float)RENESAS_RZ_A1_P0_CLK / (float)(1 << SHIFT_NUM) + 0.5f),
86+
(32 - SHIFT_NUM)
87+
};
88+
return &info;
14789
}
14890

149-
void us_ticker_clear_interrupt(void) {
150-
GIC_ClearPendingIRQ(US_TICKER_TIMER_IRQn);
151-
}

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@
27182718
"core": "Cortex-A9",
27192719
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
27202720
"extra_labels": ["RENESAS", "RZ_A1XX"],
2721-
"device_has": ["ANALOGIN", "CAN", "ETHERNET", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2721+
"device_has": ["USTICKER", "ANALOGIN", "CAN", "ETHERNET", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
27222722
"features": ["LWIP"],
27232723
"program_cycle_s": 2
27242724
},

0 commit comments

Comments
 (0)