rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
mc33810.cpp File Reference

Enumerations

enum  mc33810_drv_state { MC33810_DISABLED = 0 , MC33810_WAIT_INIT , MC33810_READY , MC33810_FAILED }
 
enum  mc33810_coil_state { COIL_IDLE = 0 , COIL_WAIT_SPARK_START , COIL_WAIT_SPARK_END }
 

Functions

 SEMAPHORE_DECL (mc33810_wake, 10)
 
static THD_WORKING_AREA (mc33810_thread_wa, 256)
 
bool isCor (uint16_t rx)
 
static void mc33810_spkdur_cb (void *ptr, efitick_t now)
 
static THD_FUNCTION (mc33810_driver_thread, p)
 
int mc33810_add (brain_pin_e base, unsigned int index, const mc33810_config *cfg)
 MC33810 driver add.
 
void mc33810_req_init ()
 
int getMc33810maxDwellTimer (mc33810maxDwellTimer_e value)
 
const mc33810_state_smc33810getLiveData (size_t idx)
 

Variables

static thread_t * mc33810_thread = NULL
 
static Mc33810 chips [BOARD_MC33810_COUNT]
 
static const charmc33810_pin_names [MC33810_OUTPUTS]
 

Enumeration Type Documentation

◆ mc33810_coil_state

Enumerator
COIL_IDLE 
COIL_WAIT_SPARK_START 
COIL_WAIT_SPARK_END 

Definition at line 51 of file mc33810.cpp.

51 {
52 COIL_IDLE = 0,
mc33810_coil_state
Definition mc33810.cpp:51
@ COIL_IDLE
Definition mc33810.cpp:52
@ COIL_WAIT_SPARK_END
Definition mc33810.cpp:54
@ COIL_WAIT_SPARK_START
Definition mc33810.cpp:53

◆ mc33810_drv_state

Enumerator
MC33810_DISABLED 
MC33810_WAIT_INIT 
MC33810_READY 
MC33810_FAILED 

Definition at line 44 of file mc33810.cpp.

44 {
mc33810_drv_state
Definition mc33810.cpp:44
@ MC33810_WAIT_INIT
Definition mc33810.cpp:46
@ MC33810_FAILED
Definition mc33810.cpp:48
@ MC33810_READY
Definition mc33810.cpp:47
@ MC33810_DISABLED
Definition mc33810.cpp:45

Function Documentation

◆ getMc33810maxDwellTimer()

int getMc33810maxDwellTimer ( mc33810maxDwellTimer_e  value)

Definition at line 1003 of file mc33810.cpp.

1003 {
1004switch(value) {
1005case DWELL_16MS:
1006 return 16;
1007case DWELL_2MS:
1008 return 2;
1009case DWELL_32MS:
1010 return 32;
1011case DWELL_4MS:
1012 return 4;
1013case DWELL_64MS:
1014 return 64;
1015case DWELL_8MS:
1016 return 8;
1017 }
1018 return 0;
1019}

Referenced by validateConfigOnStartUpOrBurn().

Here is the caller graph for this function:

◆ isCor()

bool isCor ( uint16_t  rx)
inline

Definition at line 214 of file mc33810.cpp.

214 {
215 return rx & REP_FLAG_COR;
216}

◆ mc33810_add()

int mc33810_add ( brain_pin_e  base,
unsigned int  index,
const mc33810_config cfg 
)

MC33810 driver add.

Checks for valid config

Definition at line 946 of file mc33810.cpp.

946 {
947
948 /* no config or no such chip */
949 if ((!cfg) || (!cfg->spi_bus) || (index >= BOARD_MC33810_COUNT))
950 return -16;
951
952 /* check for valid cs.
953 * TODO: remove this check? CS can be driven by SPI */
954 //if (cfg->spi_config.ssport == NULL)
955 // return -1;
956
957 Mc33810& chip = chips[index];
958
959 /* already initted? */
960 if (chip.cfg != NULL)
961 return -13;
962
963 chip.cfg = cfg;
964 chip.o_state = 0;
965 chip.o_state_cached = 0;
966 chip.o_direct_mask = 0;
967 for (int i = 0; i < MC33810_DIRECT_OUTPUTS; i++) {
968 if (cfg->direct_io[i].port != 0)
969 chip.o_direct_mask |= BIT(i);
970 }
971
972 /* GPGD mode is not supported yet, ignition mode does not support spi on/off commands
973 * so ignition signals should be directly driven */
974 if ((chip.o_direct_mask & 0xf0) != 0xf0)
975 return -4;
976
977 /* register, return gpio chip base */
978 int ret = gpiochip_register(base, DRIVER_NAME, chip, MC33810_OUTPUTS);
979 if (ret < 0)
980 return ret;
981
982 /* set default pin names, board init code can rewrite */
984
985 chip.drv_state = MC33810_WAIT_INIT;
986
987 return ret;
988}
int gpiochip_register(brain_pin_e base, const char *name, GpioChip &gpioChip, size_t size)
Register gpiochip.
Definition core.cpp:186
int gpiochips_setPinNames(brain_pin_e base, const char **names)
Set pins names for registered gpiochip.
Definition core.cpp:266
static Mc33810 chips[BOARD_MC33810_COUNT]
Definition mc33810.cpp:203
static const char * mc33810_pin_names[MC33810_OUTPUTS]
Definition mc33810.cpp:205
ioportid_t port
Definition mc33810.h:35
struct mc33810_config::@36 direct_io[MC33810_DIRECT_OUTPUTS]
SPIDriver * spi_bus
Definition mc33810.h:30

Referenced by board_init_ext_gpios(), f407_discovery_boardInitHardware(), and hellen154hyundai_f7_boardInitHardware().

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

◆ mc33810_req_init()

void mc33810_req_init ( )

Definition at line 993 of file mc33810.cpp.

993 {
994 size_t i;
995
996 for (i = 0; i < BOARD_MC33810_COUNT; i++) {
997 auto& chip = chips[i];
998
999 chip.need_init = true;
1000 }
1001}

Referenced by handleCommandX14().

Here is the caller graph for this function:

◆ mc33810_spkdur_cb()

static void mc33810_spkdur_cb ( void *  ptr,
efitick_t  now 
)
static

Definition at line 792 of file mc33810.cpp.

793{
794 Mc33810 *chip = (Mc33810 *)ptr;
795
796 chip->on_spkdur(now);
797}

◆ mc33810getLiveData()

const mc33810_state_s * mc33810getLiveData ( size_t  idx)

Definition at line 1021 of file mc33810.cpp.

1021 {
1022 if (idx >= BOARD_MC33810_COUNT)
1023 return nullptr;
1024 return &chips[idx];
1025}

Referenced by getLiveData().

Here is the caller graph for this function:

◆ SEMAPHORE_DECL()

SEMAPHORE_DECL ( mc33810_wake  ,
10   
)

◆ THD_FUNCTION()

static THD_FUNCTION ( mc33810_driver_thread  ,
 
)
static

Definition at line 742 of file mc33810.cpp.

742 {
743 (void)p;
744
745 chRegSetThreadName(DRIVER_NAME);
746
747 chThdSleepMilliseconds(2); // let's wait BatteryVoltage to appear. TODO: more proper way of synchronization with BatteryVoltage!
748
749
750 while (true) {
751 msg_t msg = chSemWaitTimeout(&mc33810_wake, TIME_MS2I(MC33810_POLL_INTERVAL_MS));
752
753 /* should we care about msg == MSG_TIMEOUT? */
754 (void)msg;
755
756 for (int i = 0; i < BOARD_MC33810_COUNT; i++) {
757 auto chip = &chips[i];
758
759 if (i == 0) {
761 engine->engineState.smartChipAliveCounter = chip->alive_cnt;
762 }
763
764 if (chip->need_init) {
765 int ret = chip->chip_init();
766 if (ret == 0) {
767 chip->drv_state = MC33810_READY;
768 chip->need_init = false;
769 }
770 }
771
772 if ((chip->cfg == NULL) ||
773 (chip->drv_state == MC33810_DISABLED) ||
774 (chip->drv_state == MC33810_FAILED)) {
775 chip->need_init = true;
776 continue;
777 }
778
779 /* TODO: implement indirect driven gpios */
780 int ret = chip->update_output_and_diag();
781 if (ret) {
782 /* set state to MC33810_FAILED? */
783 }
784 }
785 }
786}
EngineState engineState
Definition engine.h:344
static EngineAccessor engine
Definition engine.h:413

◆ THD_WORKING_AREA()

static THD_WORKING_AREA ( mc33810_thread_wa  ,
256   
)
static

Variable Documentation

◆ chips

Mc33810 chips[BOARD_MC33810_COUNT]
static

Definition at line 203 of file mc33810.cpp.

Referenced by mc33810_add(), mc33810_req_init(), mc33810getLiveData(), and THD_FUNCTION().

◆ mc33810_pin_names

const char* mc33810_pin_names[MC33810_OUTPUTS]
static
Initial value:
= {
"mc33810.OUT1", "mc33810.OUT2", "mc33810.OUT3", "mc33810.OUT4",
"mc33810.GD0", "mc33810.GD1", "mc33810.GD2", "mc33810.GD3",
}

Definition at line 205 of file mc33810.cpp.

205 {
206 "mc33810.OUT1", "mc33810.OUT2", "mc33810.OUT3", "mc33810.OUT4",
207 "mc33810.GD0", "mc33810.GD1", "mc33810.GD2", "mc33810.GD3",
208};

Referenced by mc33810_add().

◆ mc33810_thread

thread_t* mc33810_thread = NULL
static

Definition at line 126 of file mc33810.cpp.

Go to the source code of this file.