Skip to content

Commit 0663e76

Browse files
committed
pbio/os: Move IRQ hooks to platform.
Proceed to make pbio more independent from MicroPython. Also restore them as static inline as they used to be prior to #298 which reduces build size.
1 parent 78bb2d6 commit 0663e76

File tree

20 files changed

+166
-85
lines changed

20 files changed

+166
-85
lines changed

bricks/_common_stm32/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef unsigned mp_uint_t; // must be pointer size
2424

2525
typedef long mp_off_t;
2626

27-
#include <pbio/os.h>
27+
#include "pbio_os_config.h"
2828

2929
#define MICROPY_BEGIN_ATOMIC_SECTION() pbio_os_hook_disable_irq()
3030
#define MICROPY_END_ATOMIC_SECTION(state) pbio_os_hook_enable_irq(state)

bricks/_common_stm32/mphalport.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ void pb_stack_get_info(char **sstack, char **estack) {
2424
*estack = (char *)&_estack;
2525
}
2626

27-
pbio_os_irq_flags_t pbio_os_hook_disable_irq(void) {
28-
mp_uint_t flags = __get_PRIMASK();
29-
__disable_irq();
30-
return flags;
31-
}
32-
33-
void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags) {
34-
__set_PRIMASK(flags);
35-
}
36-
37-
void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags) {
38-
__WFI();
39-
}
40-
4127
// using "internal" pbdrv variable
4228
extern volatile uint32_t pbdrv_clock_ticks;
4329

bricks/ev3/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef unsigned mp_uint_t; // must be pointer size
7979

8080
typedef long mp_off_t;
8181

82-
#include <pbio/os.h>
82+
#include "pbio_os_config.h"
8383

8484
#define MICROPY_BEGIN_ATOMIC_SECTION() pbio_os_hook_disable_irq()
8585
#define MICROPY_END_ATOMIC_SECTION(state) pbio_os_hook_enable_irq(state)

bricks/ev3/mphalport.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,13 @@
1818
#include "py/mpconfig.h"
1919
#include "py/stream.h"
2020

21-
#include <tiam1808/armv5/am1808/interrupt.h>
22-
2321
void pb_stack_get_info(char **sstack, char **estack) {
2422
extern uint32_t _estack;
2523
extern uint32_t _sstack;
2624
*sstack = (char *)&_sstack;
2725
*estack = (char *)&_estack;
2826
}
2927

30-
pbio_os_irq_flags_t pbio_os_hook_disable_irq(void) {
31-
return IntDisable();
32-
}
33-
34-
void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags) {
35-
IntEnable(flags);
36-
}
37-
38-
void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags) {
39-
__asm volatile (
40-
"mov r0, #0\n"
41-
"mcr p15, 0, r0, c7, c0, 4\n" /* wait for interrupt */
42-
::: "r0"
43-
);
44-
}
45-
4628
// Core delay function that does an efficient sleep and may switch thread context.
4729
// If IRQs are enabled then we must have the GIL.
4830
void mp_hal_delay_ms(mp_uint_t Delay) {

bricks/nxt/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef long mp_off_t;
7979
// We need to provide a declaration/definition of alloca()
8080
#include <alloca.h>
8181

82-
#include <pbio/os.h>
82+
#include "pbio_os_config.h"
8383

8484
#define MICROPY_BEGIN_ATOMIC_SECTION() pbio_os_hook_disable_irq()
8585
#define MICROPY_END_ATOMIC_SECTION(state) pbio_os_hook_enable_irq(state)

bricks/nxt/mphalport.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
#include <stdint.h>
66

7-
#include <at91sam7s256.h>
87
#include <contiki.h>
98

10-
#include <nxos/interrupts.h>
119
#include <nxos/drivers/systick.h>
1210
#include <nxos/drivers/bt.h>
1311

@@ -20,19 +18,6 @@
2018
#include "py/mpconfig.h"
2119
#include "py/stream.h"
2220

23-
pbio_os_irq_flags_t pbio_os_hook_disable_irq(void) {
24-
return nx_interrupts_disable();
25-
}
26-
27-
void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags) {
28-
nx_interrupts_enable(flags);
29-
}
30-
31-
void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags) {
32-
// disable the processor clock which puts it in Idle Mode.
33-
AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
34-
}
35-
3621
void pb_stack_get_info(char **sstack, char **estack) {
3722
extern uint32_t __stack_start__;
3823
extern uint32_t __stack_end__;

bricks/virtualhub/mp_port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <contiki.h>
1616

17+
#include "pbio_os_config.h"
18+
1719
#include <pbio/main.h>
1820
#include <pbio/os.h>
1921
#include <pbsys/core.h>

lib/pbio/include/pbio/os.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -279,29 +279,4 @@ void pbio_os_process_start(pbio_os_process_t *process, pbio_os_process_func_t fu
279279

280280
void pbio_os_process_init(pbio_os_process_t *process, pbio_os_process_func_t func);
281281

282-
/**
283-
* Disables interrupts and returns the previous interrupt state.
284-
*
285-
* Must be implemented by the platform.
286-
*
287-
* @return The previous interrupt state.
288-
*/
289-
pbio_os_irq_flags_t pbio_os_hook_disable_irq(void);
290-
291-
/**
292-
* Enables interrupts.
293-
*
294-
* Must be implemented by the platform.
295-
*
296-
* @param [in] flags The previous interrupt state.
297-
*/
298-
void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags);
299-
300-
/**
301-
* Waits for an interrupt.
302-
*
303-
* Must be implemented by the platform.
304-
*/
305-
void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags);
306-
307282
#endif // _PBIO_OS_H_
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdint.h>
2+
3+
#include "stm32f0xx.h"
4+
5+
typedef uint32_t pbio_os_irq_flags_t;
6+
7+
static inline pbio_os_irq_flags_t pbio_os_hook_disable_irq(void) {
8+
uint32_t flags = __get_PRIMASK();
9+
__disable_irq();
10+
return flags;
11+
}
12+
13+
static inline void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags) {
14+
__set_PRIMASK(flags);
15+
}
16+
17+
static inline void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags) {
18+
__WFI();
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdint.h>
2+
3+
#include "stm32f4xx.h"
4+
5+
typedef uint32_t pbio_os_irq_flags_t;
6+
7+
static inline pbio_os_irq_flags_t pbio_os_hook_disable_irq(void) {
8+
uint32_t flags = __get_PRIMASK();
9+
__disable_irq();
10+
return flags;
11+
}
12+
13+
static inline void pbio_os_hook_enable_irq(pbio_os_irq_flags_t flags) {
14+
__set_PRIMASK(flags);
15+
}
16+
17+
static inline void pbio_os_hook_wait_for_interrupt(pbio_os_irq_flags_t flags) {
18+
__WFI();
19+
}

0 commit comments

Comments
 (0)