rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
sense_core1.c File Reference

Core 1: the sensor bus and the hand-over. More...

#include "sense_core1.h"
#include <string.h>
#include "hardware/sync.h"
#include "pico/flash.h"
#include "pico/multicore.h"
#include "pico/stdlib.h"
#include "sense_i2c.h"
#include "tone_core1.h"
#include "sense_trace_hw.h"

Functions

static uint64_t clock_us (void *ctx)
 Reads the 64-bit microsecond timer for the sensor schedule.
static void recover (void *ctx)
 Clears the sensor bus with sense_i2c_recover().
static bool bus_open (void *ctx, uint8_t sda, uint8_t scl)
 Opens the sensor bus on the given pins.
static void bus_close (void *ctx)
 Closes the sensor bus.
static sense_err_t bus_ask (void *ctx, uint8_t addr)
 Asks whether a device acknowledges on the sensor bus.
static void core1_main (void)
 Core 1's entry point: runs the sensor loop, one step per tick, forever.
bool sense_core1_start (const sense_cmd_t *first)
 Launch core 1 with first as its first order.
void sense_core1_order (const sense_cmd_t *cmd)
 A new order for core 1, taken at its next tick.
bool sense_core1_snapshot (sense_snap_t *out)
 The newest snapshot into out when one has arrived since the last call; false, and out untouched, when none has.

Variables

static spin_lock_t * s_lock
static sense_cmd_t s_order
static sense_snap_t s_shared
static volatile uint32_t s_shared_seq
static sense_svc_t s_svc
static sense_cmd_t s_cmd
static sense_snap_t s_snap
static uint32_t s_stack [1024]
static uint32_t s_taken_seq

Detailed Description

Core 1: the sensor bus and the hand-over.

See sense_core1.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ bus_ask()

sense_err_t bus_ask ( void * ctx,
uint8_t addr )
static

Asks whether a device acknowledges on the sensor bus.

Parameters
ctxUnused.
addrI2C address of the device.
Returns
The result of sense_i2c_ask().

◆ bus_close()

void bus_close ( void * ctx)
static

Closes the sensor bus.

Parameters
ctxUnused.

◆ bus_open()

bool bus_open ( void * ctx,
uint8_t sda,
uint8_t scl )
static

Opens the sensor bus on the given pins.

Parameters
ctxUnused.
sdaGPIO number of SDA.
sclGPIO number of SCL.
Returns
True when the bus opened.

◆ clock_us()

uint64_t clock_us ( void * ctx)
static

Reads the 64-bit microsecond timer for the sensor schedule.

Parameters
ctxUnused.
Returns
The current time, in microseconds.

◆ recover()

void recover ( void * ctx)
static

Clears the sensor bus with sense_i2c_recover().

Parameters
ctxUnused.

◆ sense_core1_order()

void sense_core1_order ( const sense_cmd_t * cmd)

A new order for core 1, taken at its next tick.

Parameters
cmdThe order to copy into the shared slot.

◆ sense_core1_snapshot()

bool sense_core1_snapshot ( sense_snap_t * out)

The newest snapshot into out when one has arrived since the last call; false, and out untouched, when none has.

Parameters
outReceives the snapshot when one has arrived.
Returns
True when a snapshot was copied. False when none has arrived since the last call.

◆ sense_core1_start()

bool sense_core1_start ( const sense_cmd_t * first)

Launch core 1 with first as its first order.

Returns whether core 1 registered for the flash lock-out within SENSE_CORE1_START_MS. False means no flash window may open this boot: flash_safe_execute() would refuse it, or assert where asserts are on.

Parameters
firstThe first order for core 1.
Returns
True when core 1 registered for the flash lock-out within SENSE_CORE1_START_MS. False otherwise.