rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
kinetis_common.cpp File Reference

Detailed Description

Low level common Kinetis code.

Date
Mar 28, 2019
Author
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition in file kinetis_common.cpp.

Functions

brain_pin_e getAdcChannelBrainPin (const char *msg, adc_channel_e hwChannel)
 
adc_channel_e getAdcChannel (brain_pin_e pin)
 
bool adcIsMuxedInput (adc_channel_e hwChannel)
 
adc_channel_e adcMuxedGetParent (adc_channel_e hwChannel)
 
int getAdcInternalChannel (ADC_TypeDef *adc, adc_channel_e hwChannel)
 
adc_channel_e getHwChannelForAdcInput (ADC_TypeDef *adc, size_t hwIndex)
 
ioportid_t getAdcChannelPort (const char *msg, adc_channel_e hwChannel)
 
int getAdcChannelPin (adc_channel_e hwChannel)
 
void jump_to_bootloader ()
 
int getRemainingStack (thread_t *otp)
 

Function Documentation

◆ adcIsMuxedInput()

bool adcIsMuxedInput ( adc_channel_e  hwChannel)

Definition at line 112 of file kinetis_common.cpp.

112 {
113 return false;
114}

◆ adcMuxedGetParent()

adc_channel_e adcMuxedGetParent ( adc_channel_e  hwChannel)

Definition at line 116 of file kinetis_common.cpp.

117{
118 return hwChannel;
119}

◆ getAdcChannel()

adc_channel_e getAdcChannel ( brain_pin_e  pin)

Definition at line 73 of file kinetis_common.cpp.

73 {
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}
brain_pin_e pin
Definition stm32_adc.cpp:15

◆ getAdcChannelBrainPin()

brain_pin_e getAdcChannelBrainPin ( const char msg,
adc_channel_e  hwChannel 
)

Definition at line 30 of file kinetis_common.cpp.

30 {
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}
@ Invalid
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_ADC_UNKNOWN_CHANNEL

Referenced by getAdcChannelPin(), and getAdcChannelPort().

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

◆ getAdcChannelPin()

int getAdcChannelPin ( adc_channel_e  hwChannel)

Definition at line 140 of file kinetis_common.cpp.

140 {
141 return getHwPin("get_pin", getAdcChannelBrainPin("get_pin", hwChannel));
142}
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel)
Here is the call graph for this function:

◆ getAdcChannelPort()

ioportid_t getAdcChannelPort ( const char msg,
adc_channel_e  hwChannel 
)

Definition at line 135 of file kinetis_common.cpp.

135 {
136 return getHwPort(msg, getAdcChannelBrainPin(msg, hwChannel));
137}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
Here is the call graph for this function:

◆ getAdcInternalChannel()

int getAdcInternalChannel ( ADC_TypeDef *  adc,
adc_channel_e  hwChannel 
)

Definition at line 121 of file kinetis_common.cpp.

121 {
122 (void)adc;
123
124 return (hwChannel - EFI_ADC_0);
125}
uint16_t adc
Definition adc_inputs.h:103

◆ getHwChannelForAdcInput()

adc_channel_e getHwChannelForAdcInput ( ADC_TypeDef *  adc,
size_t  hwIndex 
)

Definition at line 127 of file kinetis_common.cpp.

128{
129 (void)adc;
130
131 return (EFI_ADC_0 + hwIndex);
132}

◆ getRemainingStack()

int getRemainingStack ( thread_t *  otp)

Of note is that interrupts are NOT serviced on the stack of the thread that was running when the interrupt occurred. The only thing that happens on that thread's stack is that its registers are pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the main stack (currently 0x400=1024 bytes), where the ISR actually runs. see also main_stack_size see also process_stack_size

see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks

In the firmware we are using 'extern *Engine' - in the firmware Engine is a singleton

On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter

Definition at line 159 of file kinetis_common.cpp.

159 {
160 // todo: would stm32 code actually work here since similar Cortex?
161 return 888888;
162}

◆ jump_to_bootloader()

void jump_to_bootloader ( )

Definition at line 148 of file kinetis_common.cpp.

148 {
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}

Go to the source code of this file.