rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
kinetis_common.cpp
Go to the documentation of this file.
1/**
2 * @file kinetis_common.cpp
3 * @brief Low level common Kinetis code
4 *
5 * @date Mar 28, 2019
6 * @author andreika <prometheus.pcb@gmail.com>
7 */
8
9#include "pch.h"
10
11#if HAL_USE_ADC || defined(__DOXYGEN__)
12
13// ADC_CHANNEL_IN0 // PA2 (def=VIGN)
14// ADC_CHANNEL_IN1 // PA3 (def=MAP4)
15// ADC_CHANNEL_IN2 // x
16// ADC_CHANNEL_IN3 // PD3 (def=MAP3)
17// ADC_CHANNEL_IN4 // x
18// ADC_CHANNEL_IN5 // x
19// ADC_CHANNEL_IN6 // x
20// ADC_CHANNEL_IN7 // PB12 (def=MAP2)
21// ADC_CHANNEL_IN8 // PB13 (def=MAP1)
22// ADC_CHANNEL_IN9 // x
23// ADC_CHANNEL_IN10 // PE2 (def=O2S2)
24// ADC_CHANNEL_IN11 // x
25// ADC_CHANNEL_IN12 // PC14 (def=O2S)
26// ADC_CHANNEL_IN13 // PC15 (def=TPS)
27// ADC_CHANNEL_IN14 // PC16 (def=CLT)
28// ADC_CHANNEL_IN15 // PC17 (def=IAT)
29
30brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel) {
31 static_assert(EFI_ADC_NONE == ADC_CHANNEL_NONE);
32
33 // todo: replace this with an array :)
34 switch (hwChannel) {
35 case EFI_ADC_0:
36 return Gpio::A2;
37 case EFI_ADC_1:
38 return Gpio::A3;
39 case EFI_ADC_2:
40 return Gpio::Invalid;
41 case EFI_ADC_3:
42 return Gpio::D3;
43 case EFI_ADC_4:
44 return Gpio::Invalid;
45 case EFI_ADC_5:
46 return Gpio::Invalid;
47 case EFI_ADC_6:
48 return Gpio::Invalid;
49 case EFI_ADC_7:
50 return Gpio::B12;
51 case EFI_ADC_8:
52 return Gpio::B13;
53 case EFI_ADC_9:
54 return Gpio::Invalid;
55 case EFI_ADC_10:
56 return Gpio::E2;
57 case EFI_ADC_11:
58 return Gpio::Invalid;
59 case EFI_ADC_12:
60 return Gpio::C14;
61 case EFI_ADC_13:
62 return Gpio::C15;
63 case EFI_ADC_14:
64 return Gpio::C16;
65 case EFI_ADC_15:
66 return Gpio::C17;
67 default:
68 firmwareError(ObdCode::CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg);
69 return Gpio::Invalid;
70 }
71}
72
74 switch (pin) {
75 case Gpio::A2:
76 return EFI_ADC_0;
77 case Gpio::A3:
78 return EFI_ADC_1;
79 //case Gpio::A2:
80 // return EFI_ADC_2;
81 case Gpio::D3:
82 return EFI_ADC_3;
83 //case Gpio::A4:
84 // return EFI_ADC_4;
85 //case Gpio::A5:
86 // return EFI_ADC_5;
87 //case Gpio::A6:
88 // return EFI_ADC_6;
89 case Gpio::B12:
90 return EFI_ADC_7;
91 case Gpio::B13:
92 return EFI_ADC_8;
93 //case Gpio::B1:
94 // return EFI_ADC_9;
95 case Gpio::E2:
96 return EFI_ADC_10;
97 //case Gpio::C1:
98 // return EFI_ADC_11;
99 case Gpio::C14:
100 return EFI_ADC_12;
101 case Gpio::C15:
102 return EFI_ADC_13;
103 case Gpio::C16:
104 return EFI_ADC_14;
105 case Gpio::C17:
106 return EFI_ADC_15;
107 default:
108 return EFI_ADC_ERROR;
109 }
110}
111
113 return false;
114}
115
117{
118 return hwChannel;
119}
120
121int getAdcInternalChannel(ADC_TypeDef *adc, adc_channel_e hwChannel) {
122 (void)adc;
123
124 return (hwChannel - EFI_ADC_0);
125}
126
127adc_channel_e getHwChannelForAdcInput(ADC_TypeDef *adc, size_t hwIndex)
128{
129 (void)adc;
130
131 return (EFI_ADC_0 + hwIndex);
132}
133
134// deprecated - migrate to 'getAdcChannelBrainPin'
135ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel) {
136 return getHwPort(msg, getAdcChannelBrainPin(msg, hwChannel));
137}
138
139// deprecated - migrate to 'getAdcChannelBrainPin'
141 return getHwPin("get_pin", getAdcChannelBrainPin("get_pin", hwChannel));
142}
143
144#endif /* HAL_USE_ADC */
145
146#if EFI_DFU_JUMP
147#define BOOTLOADER_LOCATION 0x1C00001CUL
149 typedef void (*bootloader_start_t)(void * arg);
150 // Read the function address from the ROM API tree and turn it into a function pointer
151 bootloader_start_t bootloaderStart = (bootloader_start_t)(**(uint32_t **)BOOTLOADER_LOCATION);
152 // Call the function!
153 bootloaderStart(NULL);
154 // Will not return from here
155 NVIC_SystemReset();
156}
157#endif /* EFI_DFU_JUMP */
158
159int getRemainingStack(thread_t *otp) {
160 // todo: would stm32 code actually work here since similar Cortex?
161 return 888888;
162}
uint16_t adc
Definition adc_inputs.h:103
@ Invalid
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
void firmwareError(ObdCode code, const char *fmt,...)
GPIO_TypeDef * ioportid_t
Port Identifier.
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel)
int getAdcInternalChannel(ADC_TypeDef *adc, adc_channel_e hwChannel)
int getAdcChannelPin(adc_channel_e hwChannel)
int getRemainingStack(thread_t *otp)
bool adcIsMuxedInput(adc_channel_e hwChannel)
void jump_to_bootloader()
adc_channel_e getHwChannelForAdcInput(ADC_TypeDef *adc, size_t hwIndex)
adc_channel_e getAdcChannel(brain_pin_e pin)
adc_channel_e adcMuxedGetParent(adc_channel_e hwChannel)
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel)
@ CUSTOM_ERR_ADC_UNKNOWN_CHANNEL
brain_pin_e pin
Definition stm32_adc.cpp:15