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 1009 of file mc33810.cpp.

1009 {
1010switch(value) {
1011case DWELL_16MS:
1012 return 16;
1013case DWELL_2MS:
1014 return 2;
1015case DWELL_32MS:
1016 return 32;
1017case DWELL_4MS:
1018 return 4;
1019case DWELL_64MS:
1020 return 64;
1021case DWELL_8MS:
1022 return 8;
1023 }
1024 return 0;
1025}

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 949 of file mc33810.cpp.

949 {
950
951 /* no config or no such chip */
952 if ((!cfg) || (!cfg->spi_bus) || (index >= BOARD_MC33810_COUNT))
953 return -16;
954
955 /* check for valid cs.
956 * TODO: remove this check? CS can be driven by SPI */
957 //if (cfg->spi_config.ssport == NULL)
958 // return -1;
959
960 Mc33810& chip = chips[index];
961
962 /* already initted? */
963 if (chip.cfg != NULL)
964 return -13;
965
966 chip.cfg = cfg;
967 chip.o_state = 0;
968 chip.o_state_cached = 0;
969 chip.o_direct_mask = 0;
970 for (int i = 0; i < MC33810_DIRECT_OUTPUTS; i++) {
971 if (cfg->direct_io[i].port != 0)
972 chip.o_direct_mask |= BIT(i);
973 }
974
975#if 0
976 // Some Ignition channels may be unused, so skip this check for now
977 /* GPGD mode is not supported yet, ignition mode does not support spi on/off commands
978 * so ignition signals should be directly driven */
979 if ((chip.o_direct_mask & 0xf0) != 0xf0)
980 return -4;
981#endif
982
983 /* register, return gpio chip base */
984 int ret = gpiochip_register(base, DRIVER_NAME, chip, MC33810_OUTPUTS);
985 if (ret < 0)
986 return ret;
987
988 /* set default pin names, board init code can rewrite */
990
991 chip.drv_state = MC33810_WAIT_INIT;
992
993 return ret;
994}
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 999 of file mc33810.cpp.

999 {
1000 size_t i;
1001
1002 for (i = 0; i < BOARD_MC33810_COUNT; i++) {
1003 auto& chip = chips[i];
1004
1005 chip.need_init = true;
1006 }
1007}

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 795 of file mc33810.cpp.

796{
797 Mc33810 *chip = (Mc33810 *)ptr;
798
799 chip->on_spkdur(now);
800}

◆ mc33810getLiveData()

const mc33810_state_s * mc33810getLiveData ( size_t  idx)

Definition at line 1027 of file mc33810.cpp.

1027 {
1028 if (idx >= BOARD_MC33810_COUNT)
1029 return nullptr;
1030 return &chips[idx];
1031}

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 745 of file mc33810.cpp.

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