rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions | Variables
PAL

Data Structures

struct  PortConfig
 Port Configuration. More...
 
struct  PALConfig
 Generic I/O ports static initializer. More...
 

Typedefs

typedef uint32_t ioportmask_t
 Digital I/O port sized unsigned type.
 
typedef uint32_t iomode_t
 Digital I/O modes.
 
typedef uint32_t ioline_t
 Type of an I/O line.
 
typedef uint32_t ioeventmode_t
 Type of an event mode.
 
typedef GPIO_TypeDef * ioportid_t
 Port Identifier.
 
typedef uint32_t iopadid_t
 Type of an pad identifier.
 

Functions

void dmaInit (void)
 
void _pal_lld_irq_handler (PORT_Type *base)
 
PORT_TypeDef * _pal_lld_get_port_config (ioportid_t port)
 
uint8_t _pal_lld_readpad (ioportid_t port, uint8_t pad)
 Reads a logical state from an I/O pad.
 
void _pal_lld_writepad (ioportid_t port, uint8_t pad, uint8_t bit)
 Writes a logical state on an output pad.
 
void _pal_lld_setpadmode (ioportid_t port, uint8_t pad, iomode_t mode)
 Pad mode setup.
 
void _pal_lld_init (void)
 Kinetis I/O ports configuration.
 
void _pal_lld_init (const PALConfig *config)
 
void _pal_lld_setgroupmode (ioportid_t port, ioportmask_t mask, iomode_t mode)
 Pads mode setup.
 
void _pal_lld_enablepadevent (ioportid_t port, iopadid_t pad, ioeventmode_t mode)
 
void _pal_lld_disablepadevent (ioportid_t port, iopadid_t pad)
 

Variables

palevent_t _pal_events [KINETIS_GPIO_NUM_LINES]
 Event records for the 16 GPIO EXTI channels.
 
palevent_t _pal_events [KINETIS_GPIO_NUM_LINES]
 Event records for the 16 GPIO EXTI channels.
 

Detailed Description

Typedef Documentation

◆ ioeventmode_t

typedef uint32_t ioeventmode_t

Type of an event mode.

Definition at line 93 of file hal_pal_lld.h.

◆ ioline_t

typedef uint32_t ioline_t

Type of an I/O line.

Definition at line 88 of file hal_pal_lld.h.

◆ iomode_t

typedef uint32_t iomode_t

Digital I/O modes.

Definition at line 83 of file hal_pal_lld.h.

◆ iopadid_t

typedef uint32_t iopadid_t

Type of an pad identifier.

Definition at line 107 of file hal_pal_lld.h.

◆ ioportid_t

typedef GPIO_TypeDef* ioportid_t

Port Identifier.

This type can be a scalar or some kind of pointer, do not make any assumption about it, use the provided macros when populating variables of this type.

Definition at line 102 of file hal_pal_lld.h.

◆ ioportmask_t

typedef uint32_t ioportmask_t

Digital I/O port sized unsigned type.

Definition at line 78 of file hal_pal_lld.h.

Function Documentation

◆ _pal_lld_disablepadevent()

void _pal_lld_disablepadevent ( ioportid_t  port,
iopadid_t  pad 
)

Definition at line 325 of file hal_pal_lld.c.

325 {
326 PORT_TypeDef *portcfg = _pal_lld_get_port_config(port);
327 PORT_SetPinInterruptConfig(portcfg, pad, PAL_EVENT_MODE_DISABLED);
328 PORT_ClearPinsInterruptFlags(portcfg, 0xffffffff);
329}
uint8_t pad[3]
PORT_TypeDef * _pal_lld_get_port_config(ioportid_t port)
Definition hal_pal_lld.c:71
static void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
Configures the port pin interrupt/DMA request.
Definition fsl_port.h:415
static void PORT_ClearPinsInterruptFlags(PORT_Type *base, uint32_t mask)
Clears the multiple pin interrupt status flag.
Definition fsl_port.h:462
Here is the call graph for this function:

◆ _pal_lld_enablepadevent()

void _pal_lld_enablepadevent ( ioportid_t  port,
iopadid_t  pad,
ioeventmode_t  mode 
)

Definition at line 301 of file hal_pal_lld.c.

303 {
305 switch (mode) {
306 case PAL_EVENT_MODE_RISING_EDGE:
308 break;
309 case PAL_EVENT_MODE_FALLING_EDGE:
311 break;
312 case PAL_EVENT_MODE_BOTH_EDGES:
314 break;
315 case PAL_EVENT_MODE_DISABLED:
316 default:
318 }
319
320 PORT_TypeDef *portcfg = _pal_lld_get_port_config(port);
321 PORT_SetPinInterruptConfig(portcfg, pad, cfg);
322
323}
enum _port_interrupt port_interrupt_t
Configures the interrupt generation condition.
@ kPORT_InterruptEitherEdge
Definition fsl_port.h:129
@ kPORT_InterruptRisingEdge
Definition fsl_port.h:127
@ kPORT_InterruptOrDMADisabled
Definition fsl_port.h:115
@ kPORT_InterruptFallingEdge
Definition fsl_port.h:128
Here is the call graph for this function:

◆ _pal_lld_get_port_config()

PORT_TypeDef * _pal_lld_get_port_config ( ioportid_t  port)

Definition at line 71 of file hal_pal_lld.c.

71 {
72 PORT_TypeDef *portcfg = NULL;
73 if (port == IOPORT1)
74 portcfg = PORTA;
75 else if (port == IOPORT2)
76 portcfg = PORTB;
77 else if (port == IOPORT3)
78 portcfg = PORTC;
79 else if (port == IOPORT4)
80 portcfg = PORTD;
81 else if (port == IOPORT5)
82 portcfg = PORTE;
83 return portcfg;
84}

Referenced by _pal_lld_disablepadevent(), _pal_lld_enablepadevent(), and _pal_lld_setpadmode().

Here is the caller graph for this function:

◆ _pal_lld_init() [1/2]

void _pal_lld_init ( const PALConfig config)

Definition at line 253 of file hal_pal_lld.c.

253 {
254
255 int i, j;
256
257 /* Enable clocking on all Ports */
258 SIM->SCGC5 |= SIM_SCGC5_PORTA |
259 SIM_SCGC5_PORTB |
260 SIM_SCGC5_PORTC |
261 SIM_SCGC5_PORTD |
262 SIM_SCGC5_PORTE;
263
264 /* Initial PORT and GPIO setup */
265 for (i = 0; i < TOTAL_PORTS; i++) {
266 for (j = 0; j < PADS_PER_PORT; j++) {
267 pal_lld_setpadmode(config->ports[i].port,
268 j,
269 config->ports[i].pads[j]);
270 }
271 }
272}
static constexpr persistent_config_s * config

◆ _pal_lld_init() [2/2]

void _pal_lld_init ( void  )

Kinetis I/O ports configuration.

Ports A-E clocks enabled.

Parameters
[in]configthe Kinetis ports configuration

@notapi

Definition at line 238 of file hal_pal_lld.c.

238 {
239 /* Enable clocking on all Ports */
240 PCC->CLKCFG[PCC_PORTA_INDEX] |= PCC_CLKCFG_CGC_MASK;
241 PCC->CLKCFG[PCC_PORTB_INDEX] |= PCC_CLKCFG_CGC_MASK;
242 PCC->CLKCFG[PCC_PORTC_INDEX] |= PCC_CLKCFG_CGC_MASK;
243 PCC->CLKCFG[PCC_PORTD_INDEX] |= PCC_CLKCFG_CGC_MASK;
244 PCC->CLKCFG[PCC_PORTE_INDEX] |= PCC_CLKCFG_CGC_MASK;
245
246 nvicEnableVector(PORTA_IRQn, KINETIS_GPIO_IRQ_PRIORITY);
247 nvicEnableVector(PORTB_IRQn, KINETIS_GPIO_IRQ_PRIORITY);
248 nvicEnableVector(PORTC_IRQn, KINETIS_GPIO_IRQ_PRIORITY);
249 nvicEnableVector(PORTD_IRQn, KINETIS_GPIO_IRQ_PRIORITY);
250 nvicEnableVector(PORTE_IRQn, KINETIS_GPIO_IRQ_PRIORITY);
251}

◆ _pal_lld_irq_handler()

void _pal_lld_irq_handler ( PORT_Type *  base)

Definition at line 58 of file hal_pal_lld.c.

58 {
59 uint32_t flags = PORT_GetPinsInterruptFlags(base);
60 for (int i = 0; i < 16; i++) {
61 if (flags & (1 << i)) {
62 // todo: add port-dependent lines?
63 _pal_isr_code(i);
64 }
65 }
67}
static uint32_t PORT_GetPinsInterruptFlags(PORT_Type *base)
Reads the whole port status flag.
Definition fsl_port.h:451
Here is the call graph for this function:

◆ _pal_lld_readpad()

uint8_t _pal_lld_readpad ( ioportid_t  port,
uint8_t  pad 
)

Reads a logical state from an I/O pad.

Note
The PAL provides a default software implementation of this functionality, implement this function if can optimize it by using special hardware functionalities or special coding.
Parameters
[in]portport identifier
[in]padpad number within the port
Returns
The logical state.
Return values
PAL_LOWlow logical state.
PAL_HIGHhigh logical state.

@notapi

Definition at line 100 of file hal_pal_lld.c.

101 {
102
103 return (port->PDIR & ((uint32_t) 1 << pad)) ? PAL_HIGH : PAL_LOW;
104}

◆ _pal_lld_setgroupmode()

void _pal_lld_setgroupmode ( ioportid_t  port,
ioportmask_t  mask,
iomode_t  mode 
)

Pads mode setup.

This function programs a pads group belonging to the same port with the specified mode.

Parameters
[in]portthe port identifier
[in]maskthe group mask
[in]modethe mode

@notapi

Definition at line 286 of file hal_pal_lld.c.

288 {
289
290 int i;
291
292 (void)mask;
293
294 for (i = 0; i < PADS_PER_PORT; i++) {
295 pal_lld_setpadmode(port, i, mode);
296 }
297}

◆ _pal_lld_setpadmode()

void _pal_lld_setpadmode ( ioportid_t  port,
uint8_t  pad,
iomode_t  mode 
)

Pad mode setup.

This function programs a pad with the specified mode.

Note
The PAL provides a default software implementation of this functionality, implement this function if can optimize it by using special hardware functionalities or special coding.
Programming an unknown or unsupported mode is silently ignored.
Parameters
[in]portport identifier
[in]padpad number within the port
[in]modepad mode

@notapi

Definition at line 145 of file hal_pal_lld.c.

147 {
148
149 osalDbgAssert(pad < PADS_PER_PORT, "pal_lld_setpadmode() #1, invalid pad");
150
151 if (mode == PAL_MODE_OUTPUT_PUSHPULL || mode == PAL_MODE_OUTPUT_OPENDRAIN)
152 port->PDDR |= ((uint32_t) 1 << pad);
153 else
154 port->PDDR &= ~((uint32_t) 1 << pad);
155
156 PORT_TypeDef *portcfg = _pal_lld_get_port_config(port);
157 osalDbgAssert(portcfg != NULL, "pal_lld_setpadmode() #2, invalid port");
158
159 switch (mode) {
160 case PAL_MODE_RESET:
161 case PAL_MODE_INPUT:
162 case PAL_MODE_OUTPUT_PUSHPULL:
163 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(1);
164 break;
165#if KINETIS_GPIO_HAS_OPENDRAIN
166 case PAL_MODE_OUTPUT_OPENDRAIN:
167 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(1) |
168 PORTx_PCRn_ODE;
169 break;
170#else
171#undef PAL_MODE_OUTPUT_OPENDRAIN
172#endif
173 case PAL_MODE_INPUT_PULLUP:
174 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(1) |
175 PORTx_PCRn_PE |
176 PORTx_PCRn_PS;
177 break;
178 case PAL_MODE_INPUT_PULLDOWN:
179 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(1) |
180 PORTx_PCRn_PE;
181 break;
182 case PAL_MODE_UNCONNECTED:
183 case PAL_MODE_INPUT_ANALOG:
184 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(0);
185 break;
186 case PAL_MODE_ALTERNATIVE_1:
187 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(1);
188 break;
189 case PAL_MODE_ALTERNATIVE_2:
190 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(2);
191 break;
192 case PAL_MODE_ALTERNATIVE_3:
193 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(3);
194 break;
195 case PAL_MODE_ALTERNATIVE_4:
196 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(4);
197 break;
198 case PAL_MODE_ALTERNATIVE_5:
199 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(5);
200 break;
201 case PAL_MODE_ALTERNATIVE_6:
202 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(6);
203 break;
204 case PAL_MODE_ALTERNATIVE_7:
205 portcfg->PCR[pad] = PIN_MUX_ALTERNATIVE(7);
206 break;
207 }
208
209 // a little 'hack' for complex pin modes like MISO+PULLUP
210 if (mode & PAL_STM32_PUPDR_PULLUP) {
211 portcfg->PCR[pad] |= PAL_STM32_PUPDR_PULLUP;
212 }
213
214 // enable high-current drive strength for push-pull outputs (Kinetis-specific feature)
215 if (mode & PAL_MODE_OUTPUT_PUSHPULL) {
216 // todo: Not all pins are capable of high-drive. Is is a problem?
218 }
219}
static void PORT_SetPinDriveStrength(PORT_Type *base, uint32_t pin, uint8_t strength)
Configures the port pin drive strength.
Definition fsl_port.h:431
@ kPORT_HighDriveStrength
Definition fsl_port.h:75
Here is the call graph for this function:

◆ _pal_lld_writepad()

void _pal_lld_writepad ( ioportid_t  port,
uint8_t  pad,
uint8_t  bit 
)

Writes a logical state on an output pad.

Note
This function is not meant to be invoked directly by the application code.
The PAL provides a default software implementation of this functionality, implement this function if can optimize it by using special hardware functionalities or special coding.
Parameters
[in]portport identifier
[in]padpad number within the port
[in]bitlogical value, the value must be PAL_LOW or PAL_HIGH

@notapi

Definition at line 121 of file hal_pal_lld.c.

123 {
124
125 if (bit == PAL_HIGH)
126 port->PDOR |= ((uint32_t) 1 << pad);
127 else
128 port->PDOR &= ~((uint32_t) 1 << pad);
129}

◆ dmaInit()

void dmaInit ( void  )

Definition at line 31 of file kinetis_dma.c.

31 {
32 DMAMUX_Init(DMAMUX);
33
34 edma_config_t eConfig;
35 EDMA_GetDefaultConfig(&eConfig);
36 eConfig.enableHaltOnError = false;
37 //eConfig.enableDebugMode = false;
38 EDMA_Init(DMA0, &eConfig);
39}
void DMAMUX_Init(DMAMUX_Type *base)
Initializes the DMAMUX peripheral.
Definition fsl_dmamux.c:73
bool enableHaltOnError
Definition fsl_edma.h:157
void EDMA_GetDefaultConfig(edma_config_t *config)
Gets the eDMA default configuration structure.
Definition fsl_edma.c:165
void EDMA_Init(DMA_Type *base, const edma_config_t *config)
Initializes the eDMA peripheral.
Definition fsl_edma.c:113
eDMA global configuration structure.
Definition fsl_edma.h:153

Referenced by hal_lld_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _pal_events [1/2]

palevent_t _pal_events[KINETIS_GPIO_NUM_LINES]

Event records for the 16 GPIO EXTI channels.

Definition at line 45 of file hal_pal_lld.c.

◆ _pal_events [2/2]

palevent_t _pal_events[KINETIS_GPIO_NUM_LINES]
extern

Event records for the 16 GPIO EXTI channels.

Definition at line 45 of file hal_pal_lld.c.