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

Enumerations

enum  mc33972_drv_state { MC33972_DISABLED = 0 , MC33972_WAIT_INIT , MC33972_READY , MC33972_FAILED }
 

Functions

static THD_FUNCTION (mc33972_driver_thread, p)
 
int mc33972_add (brain_pin_e base, unsigned int index, const struct mc33972_config *cfg)
 MC33972 driver add.
 

Variables

static Mc33972 chips [BOARD_MC33972_COUNT]
 

Enumeration Type Documentation

◆ mc33972_drv_state

Enumerator
MC33972_DISABLED 
MC33972_WAIT_INIT 
MC33972_READY 
MC33972_FAILED 

Definition at line 37 of file mc33972.cpp.

37 {
mc33972_drv_state
Definition mc33972.cpp:37
@ MC33972_READY
Definition mc33972.cpp:40
@ MC33972_FAILED
Definition mc33972.cpp:41
@ MC33972_WAIT_INIT
Definition mc33972.cpp:39
@ MC33972_DISABLED
Definition mc33972.cpp:38

Function Documentation

◆ mc33972_add()

int mc33972_add ( brain_pin_e  base,
unsigned int  index,
const struct mc33972_config cfg 
)

MC33972 driver add.

Checks for valid config

Definition at line 414 of file mc33972.cpp.

415{
416 /* no config or no such chip */
417 if ((!cfg) || (!cfg->spi_bus) || (index >= BOARD_MC33972_COUNT))
418 return -1;
419
420 /* check for valid cs.
421 * TODO: remove this check? CS can be driven by SPI */
422 if (!cfg->spi_config.ssport) {
423 return -1;
424 }
425
426 Mc33972& chip = chips[index];
427
428 /* already initted? */
429 if (chip.cfg != NULL)
430 return -1;
431
432 chip.cfg = cfg;
433 chip.i_state = 0;
434 chip.drv_state = MC33972_WAIT_INIT;
435
436 /* register, return gpio chip base */
437 return gpiochip_register(base, DRIVER_NAME, chip, MC33972_INPUTS);
438}
int gpiochip_register(brain_pin_e base, const char *name, GpioChip &gpioChip, size_t size)
Register gpiochip.
Definition core.cpp:186
static Mc33972 chips[BOARD_MC33972_COUNT]
Definition mc33972.cpp:124
SPIConfig spi_config
Definition mc33972.h:23
SPIDriver * spi_bus
Definition mc33972.h:22

Referenced by initSmartGpio().

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

◆ THD_FUNCTION()

static THD_FUNCTION ( mc33972_driver_thread  ,
 
)
static

Definition at line 291 of file mc33972.cpp.

292{
293 int ret;
294 Mc33972 *chip = reinterpret_cast<Mc33972*>(p);
295
296 chRegSetThreadName(DRIVER_NAME);
297
298 /* repeat init until success */
299 do {
300 ret = chip->chip_init();
301 if (ret) {
302 chThdSleepMilliseconds(1000);
303 continue;
304 }
305 /* else */
306 chip->drv_state = MC33972_READY;
307 } while (chip->drv_state != MC33972_READY);
308
309 while(1) {
310 msg_t msg = chSemWaitTimeout(&chip->wake, TIME_MS2I(MC33972_POLL_INTERVAL_MS));
311
312 if ((chip->cfg == NULL) ||
313 (chip->drv_state == MC33972_DISABLED) ||
314 (chip->drv_state == MC33972_FAILED))
315 continue;
316
317 if (msg == MSG_TIMEOUT) {
318 /* only input state update */
319 ret = chip->update_status();
320 } else {
321 /* someone waked thread and asks us to update pin config */
322 /* inputs state is also read */
323 ret = chip->update_pullups();
324 }
325
326 if (ret) {
327 /* set state to MC33972_FAILED? */
328 }
329 }
330}

Variable Documentation

◆ chips

Mc33972 chips[BOARD_MC33972_COUNT]
static

Definition at line 124 of file mc33972.cpp.

Referenced by mc33972_add().

Go to the source code of this file.