forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathmachine_scb.c
More file actions
108 lines (94 loc) · 3.74 KB
/
Copy pathmachine_scb.c
File metadata and controls
108 lines (94 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2026 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "mpconfigport.h"
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_I2C_TARGET || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART
#include "py/runtime.h"
#include "genhdr/pins_af.h"
#include "machine_scb.h"
/* Forward declaration */
static void machine_scb_irq_handler(uint8_t scb);
#define DEFINE_SCB_IRQ_HANDLER(scb) \
void SCB##scb##_IRQ_Handler(void) { \
machine_scb_irq_handler(scb); \
}
/**
* The file build-<board>/genhdr/pins_af.h contains the macro
*
* MICROPY_PY_MACHINE_FOR_ALL_SCB(DO)
*
* which uses the X-macro (as argument) pattern to pass a worker
* macro DO(port) for the list of all user available ports.
*
* The available (not hidden) user SCBs are those alternate
* functions defined in the boards/pse8x_af.csv file, for which
* the corresponding pin are available for the user.
* The available pins are those defined in the
* boards/<board>/pins.csv file, which are not prefixed
* with a hyphen(-).
* See tools/boardgen.py and psoc-edge/boards/make-pins.py
* for more information.
*/
MICROPY_PY_MACHINE_FOR_ALL_SCB(DEFINE_SCB_IRQ_HANDLER)
#define MAP_SCB_IRQ_CONFIG(scb) \
[scb] = { \
scb, \
SCB##scb, \
{ \
scb_##scb##_interrupt_IRQn, \
SYS_INT_IRQ_LOWEST_PRIORITY, \
SCB##scb##_IRQ_Handler \
}, \
PCLK_SCB##scb##_CLOCK_SCB_EN, \
CY_MMIO_SCB##scb##_SLAVE_NR, \
NULL, \
NULL, \
},
static machine_scb_obj_t machine_scb_obj[MICROPY_PY_MACHINE_SCB_NUM_ENTRIES] = {
MICROPY_PY_MACHINE_FOR_ALL_SCB(MAP_SCB_IRQ_CONFIG)
};
static void machine_scb_irq_handler(uint8_t scb) {
machine_scb_obj_t *scb_obj = &machine_scb_obj[scb];
if (scb_obj->parent != NULL && scb_obj->parent_handler != NULL) {
scb_obj->parent_handler(scb_obj->parent);
}
}
machine_scb_obj_t *machine_scb_obj_alloc(uint8_t scb, mp_obj_t parent, machine_scb_parent_irq_handler_t handler) {
machine_scb_obj_t *obj = &machine_scb_obj[scb];
if (obj->parent != NULL) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SCB %u is already in use by another I2C, SPI or UART instance."), scb);
}
obj->parent = parent;
obj->parent_handler = handler;
return &machine_scb_obj[scb];
}
void machine_scb_obj_free(machine_scb_obj_t *scb) {
scb->parent = NULL;
scb->parent_handler = NULL;
}
bool machine_scb_is_free(uint8_t scb) {
return machine_scb_obj[scb].parent == NULL;
}
#endif // MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_I2C_TARGET || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART