mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-06 05:21:36 +08:00
Ran Astyle
This commit is contained in:
committed by
Lorenz Meier
parent
8268161b18
commit
0d13c41108
@@ -176,7 +176,7 @@ typedef struct input_capture_config_t {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
__EXPORT int up_input_capture_set(unsigned channel, input_capture_edge edge, capture_filter_t filter,
|
__EXPORT int up_input_capture_set(unsigned channel, input_capture_edge edge, capture_filter_t filter,
|
||||||
capture_callback_t callback, void *context);
|
capture_callback_t callback, void *context);
|
||||||
|
|
||||||
__EXPORT int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter);
|
__EXPORT int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter);
|
||||||
__EXPORT int up_input_capture_set_filter(unsigned channel, capture_filter_t filter);
|
__EXPORT int up_input_capture_set_filter(unsigned channel, capture_filter_t filter);
|
||||||
|
|||||||
+81
-52
@@ -127,8 +127,8 @@ public:
|
|||||||
int set_i2c_bus_clock(unsigned bus, unsigned clock_hz);
|
int set_i2c_bus_clock(unsigned bus, unsigned clock_hz);
|
||||||
|
|
||||||
static void capture_trampoline(void *context, uint32_t chan_index,
|
static void capture_trampoline(void *context, uint32_t chan_index,
|
||||||
hrt_abstime edge_time, uint32_t edge_state,
|
hrt_abstime edge_time, uint32_t edge_state,
|
||||||
uint32_t overflow);
|
uint32_t overflow);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum RC_SCAN {
|
enum RC_SCAN {
|
||||||
@@ -206,7 +206,7 @@ private:
|
|||||||
uint8_t control_index,
|
uint8_t control_index,
|
||||||
float &input);
|
float &input);
|
||||||
void capture_callback(uint32_t chan_index,
|
void capture_callback(uint32_t chan_index,
|
||||||
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
|
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
|
||||||
void subscribe();
|
void subscribe();
|
||||||
int set_pwm_rate(unsigned rate_map, unsigned default_rate, unsigned alt_rate);
|
int set_pwm_rate(unsigned rate_map, unsigned default_rate, unsigned alt_rate);
|
||||||
int pwm_ioctl(file *filp, int cmd, unsigned long arg);
|
int pwm_ioctl(file *filp, int cmd, unsigned long arg);
|
||||||
@@ -429,8 +429,9 @@ PX4FMU::set_mode(Mode mode)
|
|||||||
case MODE_2PWM2CAP: // v1 multi-port with flow control lines as PWM
|
case MODE_2PWM2CAP: // v1 multi-port with flow control lines as PWM
|
||||||
up_input_capture_set(2, Rising, 0, NULL, NULL);
|
up_input_capture_set(2, Rising, 0, NULL, NULL);
|
||||||
up_input_capture_set(3, Rising, 0, NULL, NULL);
|
up_input_capture_set(3, Rising, 0, NULL, NULL);
|
||||||
DEVICE_DEBUG("MODE_2PWM2CAP");
|
DEVICE_DEBUG("MODE_2PWM2CAP");
|
||||||
// no break
|
|
||||||
|
// no break
|
||||||
case MODE_2PWM: // v1 multi-port with flow control lines as PWM
|
case MODE_2PWM: // v1 multi-port with flow control lines as PWM
|
||||||
DEVICE_DEBUG("MODE_2PWM");
|
DEVICE_DEBUG("MODE_2PWM");
|
||||||
|
|
||||||
@@ -448,7 +449,8 @@ PX4FMU::set_mode(Mode mode)
|
|||||||
case MODE_3PWM1CAP: // v1 multi-port with flow control lines as PWM
|
case MODE_3PWM1CAP: // v1 multi-port with flow control lines as PWM
|
||||||
DEVICE_DEBUG("MODE_3PWM1CAP");
|
DEVICE_DEBUG("MODE_3PWM1CAP");
|
||||||
up_input_capture_set(3, Rising, 0, NULL, NULL);
|
up_input_capture_set(3, Rising, 0, NULL, NULL);
|
||||||
// no break
|
|
||||||
|
// no break
|
||||||
case MODE_3PWM: // v1 multi-port with flow control lines as PWM
|
case MODE_3PWM: // v1 multi-port with flow control lines as PWM
|
||||||
DEVICE_DEBUG("MODE_3PWM");
|
DEVICE_DEBUG("MODE_3PWM");
|
||||||
|
|
||||||
@@ -680,16 +682,16 @@ PX4FMU::cycle_trampoline(void *arg)
|
|||||||
|
|
||||||
void
|
void
|
||||||
PX4FMU::capture_trampoline(void *context, uint32_t chan_index,
|
PX4FMU::capture_trampoline(void *context, uint32_t chan_index,
|
||||||
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
|
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
|
||||||
{
|
{
|
||||||
PX4FMU *dev = reinterpret_cast<PX4FMU *>(context);
|
PX4FMU *dev = reinterpret_cast<PX4FMU *>(context);
|
||||||
dev->capture_callback(chan_index, edge_time, edge_state, overflow);
|
dev->capture_callback(chan_index, edge_time, edge_state, overflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PX4FMU::capture_callback(uint32_t chan_index,
|
void PX4FMU::capture_callback(uint32_t chan_index,
|
||||||
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
|
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "FMU: Capture chan:%d time:%lld state:%d overflow:%d\n", chan_index, edge_time, edge_state,overflow);
|
fprintf(stdout, "FMU: Capture chan:%d time:%lld state:%d overflow:%d\n", chan_index, edge_time, edge_state, overflow);
|
||||||
}
|
}
|
||||||
void PX4FMU::fill_rc_in(uint16_t raw_rc_count,
|
void PX4FMU::fill_rc_in(uint16_t raw_rc_count,
|
||||||
uint16_t raw_rc_values[input_rc_s::RC_INPUT_MAX_CHANNELS],
|
uint16_t raw_rc_values[input_rc_s::RC_INPUT_MAX_CHANNELS],
|
||||||
@@ -1583,6 +1585,7 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg)
|
|||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case PWM_SERVO_GET(2):
|
case PWM_SERVO_GET(2):
|
||||||
if (_mode < MODE_3PWM) {
|
if (_mode < MODE_3PWM) {
|
||||||
@@ -2150,8 +2153,7 @@ PX4FMU::capture_ioctl(struct file *filp, int cmd, unsigned long arg)
|
|||||||
|
|
||||||
input_capture_stats_t *stats = (input_capture_stats_t *)arg;
|
input_capture_stats_t *stats = (input_capture_stats_t *)arg;
|
||||||
|
|
||||||
if (_mode == MODE_3PWM1CAP || _mode == MODE_2PWM2CAP)
|
if (_mode == MODE_3PWM1CAP || _mode == MODE_2PWM2CAP) {
|
||||||
{
|
|
||||||
|
|
||||||
pconfig = (input_capture_config_t *)arg;
|
pconfig = (input_capture_config_t *)arg;
|
||||||
}
|
}
|
||||||
@@ -2159,100 +2161,112 @@ PX4FMU::capture_ioctl(struct file *filp, int cmd, unsigned long arg)
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
|
||||||
case INPUT_CAP_SET:
|
case INPUT_CAP_SET:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_set(pconfig->channel, pconfig->edge, pconfig->filter,
|
ret = up_input_capture_set(pconfig->channel, pconfig->edge, pconfig->filter,
|
||||||
pconfig->callback, pconfig->context);
|
pconfig->callback, pconfig->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_SET_CALLBACK:
|
case INPUT_CAP_SET_CALLBACK:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_set_callback(pconfig->channel, pconfig->callback, pconfig->context);
|
ret = up_input_capture_set_callback(pconfig->channel, pconfig->callback, pconfig->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_CALLBACK:
|
case INPUT_CAP_GET_CALLBACK:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_get_callback(pconfig->channel, &pconfig->callback, &pconfig->context);
|
ret = up_input_capture_get_callback(pconfig->channel, &pconfig->callback, &pconfig->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_STATS:
|
case INPUT_CAP_GET_STATS:
|
||||||
if (arg)
|
if (arg) {
|
||||||
{
|
|
||||||
ret = up_input_capture_get_stats(stats->chan_in_edges_out, stats, false);
|
ret = up_input_capture_get_stats(stats->chan_in_edges_out, stats, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_CLR_STATS:
|
case INPUT_CAP_GET_CLR_STATS:
|
||||||
if (arg)
|
if (arg) {
|
||||||
{
|
|
||||||
ret = up_input_capture_get_stats(stats->chan_in_edges_out, stats, true);
|
ret = up_input_capture_get_stats(stats->chan_in_edges_out, stats, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_SET_EDGE:
|
case INPUT_CAP_SET_EDGE:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_set_trigger(pconfig->channel, pconfig->edge);
|
ret = up_input_capture_set_trigger(pconfig->channel, pconfig->edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_EDGE:
|
case INPUT_CAP_GET_EDGE:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_get_trigger(pconfig->channel, &pconfig->edge);
|
ret = up_input_capture_get_trigger(pconfig->channel, &pconfig->edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_SET_FILTER:
|
case INPUT_CAP_SET_FILTER:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_set_filter(pconfig->channel, pconfig->filter);
|
ret = up_input_capture_set_filter(pconfig->channel, pconfig->filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_FILTER:
|
case INPUT_CAP_GET_FILTER:
|
||||||
if (pconfig)
|
if (pconfig) {
|
||||||
{
|
|
||||||
ret = up_input_capture_get_filter(pconfig->channel, &pconfig->filter);
|
ret = up_input_capture_get_filter(pconfig->channel, &pconfig->filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_GET_COUNT:
|
case INPUT_CAP_GET_COUNT:
|
||||||
ret = OK;
|
ret = OK;
|
||||||
switch(_mode) {
|
|
||||||
|
switch (_mode) {
|
||||||
case MODE_3PWM1CAP:
|
case MODE_3PWM1CAP:
|
||||||
*(unsigned *)arg = 1;
|
*(unsigned *)arg = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_2PWM2CAP:
|
case MODE_2PWM2CAP:
|
||||||
*(unsigned *)arg = 2;
|
*(unsigned *)arg = 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_CAP_SET_COUNT:
|
case INPUT_CAP_SET_COUNT:
|
||||||
ret = OK;
|
ret = OK;
|
||||||
switch(_mode) {
|
|
||||||
|
switch (_mode) {
|
||||||
case MODE_3PWM1CAP:
|
case MODE_3PWM1CAP:
|
||||||
set_mode(MODE_3PWM1CAP);
|
set_mode(MODE_3PWM1CAP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_2PWM2CAP:
|
case MODE_2PWM2CAP:
|
||||||
set_mode(MODE_2PWM2CAP);
|
set_mode(MODE_2PWM2CAP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -ENOTTY;
|
ret = -ENOTTY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -2557,24 +2571,29 @@ test(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, INPUT_CAP_GET_COUNT, (unsigned long)&capture_count) != 0) {
|
if (ioctl(fd, INPUT_CAP_GET_COUNT, (unsigned long)&capture_count) != 0) {
|
||||||
fprintf(stdout,"Not in a capture mode\n");
|
fprintf(stdout, "Not in a capture mode\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
warnx("Testing %u servos and %u input captures", (unsigned)servo_count, capture_count);
|
warnx("Testing %u servos and %u input captures", (unsigned)servo_count, capture_count);
|
||||||
memset(capture_conf, 0, sizeof(capture_conf));
|
memset(capture_conf, 0, sizeof(capture_conf));
|
||||||
if (capture_count !=0 ) {
|
|
||||||
for(unsigned i = 0; i < capture_count; i++) {
|
if (capture_count != 0) {
|
||||||
|
for (unsigned i = 0; i < capture_count; i++) {
|
||||||
// Map to channel number
|
// Map to channel number
|
||||||
capture_conf[i].chan.channel = i+ servo_count;
|
capture_conf[i].chan.channel = i + servo_count;
|
||||||
|
|
||||||
/* Save handler */
|
/* Save handler */
|
||||||
if (ioctl(fd, INPUT_CAP_GET_CALLBACK, (unsigned long)&capture_conf[i].chan.channel) != 0) {
|
if (ioctl(fd, INPUT_CAP_GET_CALLBACK, (unsigned long)&capture_conf[i].chan.channel) != 0) {
|
||||||
err(1, "Unable to get capture callback for chan %u\n", capture_conf[i].chan.channel);
|
err(1, "Unable to get capture callback for chan %u\n", capture_conf[i].chan.channel);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
input_capture_config_t conf = capture_conf[i].chan;
|
input_capture_config_t conf = capture_conf[i].chan;
|
||||||
conf.callback = &PX4FMU::capture_trampoline;
|
conf.callback = &PX4FMU::capture_trampoline;
|
||||||
conf.context = g_fmu;
|
conf.context = g_fmu;
|
||||||
|
|
||||||
if (ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) {
|
if (ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) {
|
||||||
capture_conf[i].valid = true;
|
capture_conf[i].valid = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err(1, "Unable to set capture callback for chan %u\n", capture_conf[i].chan.channel);
|
err(1, "Unable to set capture callback for chan %u\n", capture_conf[i].chan.channel);
|
||||||
}
|
}
|
||||||
@@ -2584,7 +2603,9 @@ test(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct pollfd fds;
|
struct pollfd fds;
|
||||||
|
|
||||||
fds.fd = 0; /* stdin */
|
fds.fd = 0; /* stdin */
|
||||||
|
|
||||||
fds.events = POLLIN;
|
fds.events = POLLIN;
|
||||||
|
|
||||||
warnx("Press CTRL-C or 'c' to abort.");
|
warnx("Press CTRL-C or 'c' to abort.");
|
||||||
@@ -2643,26 +2664,30 @@ test(void)
|
|||||||
errx(1, "servo %d readback error, got %u expected %u", i, value, servos[i]);
|
errx(1, "servo %d readback error, got %u expected %u", i, value, servos[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (capture_count !=0 && (++rate_limit % 500 == 0)) {
|
|
||||||
for(unsigned i = 0; i < capture_count; i++) {
|
if (capture_count != 0 && (++rate_limit % 500 == 0)) {
|
||||||
|
for (unsigned i = 0; i < capture_count; i++) {
|
||||||
if (capture_conf[i].valid) {
|
if (capture_conf[i].valid) {
|
||||||
input_capture_stats_t stats;
|
input_capture_stats_t stats;
|
||||||
stats.chan_in_edges_out = capture_conf[i].chan.channel;
|
stats.chan_in_edges_out = capture_conf[i].chan.channel;
|
||||||
|
|
||||||
if (ioctl(fd, INPUT_CAP_GET_STATS, (unsigned long)&stats) != 0) {
|
if (ioctl(fd, INPUT_CAP_GET_STATS, (unsigned long)&stats) != 0) {
|
||||||
err(1, "Unable to get stats for chan %u\n", capture_conf[i].chan.channel);
|
err(1, "Unable to get stats for chan %u\n", capture_conf[i].chan.channel);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, "FMU: Status chan:%u edges: %d last time:%lld last state:%d overflows:%d lantency:%u\n",
|
fprintf(stdout, "FMU: Status chan:%u edges: %d last time:%lld last state:%d overflows:%d lantency:%u\n",
|
||||||
capture_conf[i].chan.channel,
|
capture_conf[i].chan.channel,
|
||||||
stats.chan_in_edges_out,
|
stats.chan_in_edges_out,
|
||||||
stats.last_time,
|
stats.last_time,
|
||||||
stats.last_edge,
|
stats.last_edge,
|
||||||
stats.overflows,
|
stats.overflows,
|
||||||
stats.latnecy);
|
stats.latnecy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if user wants to quit */
|
/* Check if user wants to quit */
|
||||||
char c;
|
char c;
|
||||||
ret = poll(&fds, 1, 0);
|
ret = poll(&fds, 1, 0);
|
||||||
@@ -2678,11 +2703,11 @@ test(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (capture_count !=0 ) {
|
if (capture_count != 0) {
|
||||||
for(unsigned i = 0; i < capture_count; i++) {
|
for (unsigned i = 0; i < capture_count; i++) {
|
||||||
// Map to channel number
|
// Map to channel number
|
||||||
if (capture_conf[i].valid) {
|
if (capture_conf[i].valid) {
|
||||||
/* Save handler */
|
/* Save handler */
|
||||||
if (ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&capture_conf[i].chan) != 0) {
|
if (ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&capture_conf[i].chan) != 0) {
|
||||||
err(1, "Unable to set capture callback for chan %u\n", capture_conf[i].chan.channel);
|
err(1, "Unable to set capture callback for chan %u\n", capture_conf[i].chan.channel);
|
||||||
}
|
}
|
||||||
@@ -2774,12 +2799,16 @@ fmu_main(int argc, char *argv[])
|
|||||||
|
|
||||||
} else if (!strcmp(verb, "mode_pwm4")) {
|
} else if (!strcmp(verb, "mode_pwm4")) {
|
||||||
new_mode = PORT_PWM4;
|
new_mode = PORT_PWM4;
|
||||||
|
|
||||||
} else if (!strcmp(verb, "mode_pwm2")) {
|
} else if (!strcmp(verb, "mode_pwm2")) {
|
||||||
new_mode = PORT_PWM2;
|
new_mode = PORT_PWM2;
|
||||||
|
|
||||||
} else if (!strcmp(verb, "mode_pwm3")) {
|
} else if (!strcmp(verb, "mode_pwm3")) {
|
||||||
new_mode = PORT_PWM3;
|
new_mode = PORT_PWM3;
|
||||||
|
|
||||||
} else if (!strcmp(verb, "mode_pwm3cap1")) {
|
} else if (!strcmp(verb, "mode_pwm3cap1")) {
|
||||||
new_mode = PORT_PWM3CAP1;
|
new_mode = PORT_PWM3CAP1;
|
||||||
|
|
||||||
} else if (!strcmp(verb, "mode_pwm2cap2")) {
|
} else if (!strcmp(verb, "mode_pwm2cap2")) {
|
||||||
new_mode = PORT_PWM2CAP2;
|
new_mode = PORT_PWM2CAP2;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -154,7 +154,9 @@ int up_input_capture_set(unsigned channel, input_capture_edge edge, capture_filt
|
|||||||
if (edge > Both) {
|
if (edge > Both) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
if (edge == Disabled) {
|
if (edge == Disabled) {
|
||||||
|
|
||||||
@@ -176,20 +178,24 @@ int up_input_capture_set(unsigned channel, input_capture_edge edge, capture_filt
|
|||||||
}
|
}
|
||||||
|
|
||||||
rv = up_input_capture_set_filter(channel, filter);
|
rv = up_input_capture_set_filter(channel, filter);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
rv = up_input_capture_set_trigger(channel, edge);
|
rv = up_input_capture_set_trigger(channel, edge);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
rv = io_timer_set_enable(true, IOTimerChanMode_Capture, 1 << channel);
|
rv = io_timer_set_enable(true, IOTimerChanMode_Capture, 1 << channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter)
|
int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -201,6 +207,7 @@ int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter)
|
|||||||
uint32_t timer = timer_io_channels[channel].timer_index;
|
uint32_t timer = timer_io_channels[channel].timer_index;
|
||||||
uint16_t rvalue;
|
uint16_t rvalue;
|
||||||
rv = OK;
|
rv = OK;
|
||||||
|
|
||||||
switch (timer_io_channels[channel].timer_channel) {
|
switch (timer_io_channels[channel].timer_channel) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
@@ -228,6 +235,7 @@ int up_input_capture_get_filter(unsigned channel, capture_filter_t *filter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
||||||
@@ -237,6 +245,7 @@ int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -280,15 +289,18 @@ int up_input_capture_set_filter(unsigned channel, capture_filter_t filter)
|
|||||||
default:
|
default:
|
||||||
rv = -EIO;
|
rv = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int up_input_capture_get_trigger(unsigned channel, input_capture_edge *edge)
|
int up_input_capture_get_trigger(unsigned channel, input_capture_edge *edge)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -301,6 +313,7 @@ int up_input_capture_get_trigger(unsigned channel, input_capture_edge *edge)
|
|||||||
|
|
||||||
uint32_t timer = timer_io_channels[channel].timer_index;
|
uint32_t timer = timer_io_channels[channel].timer_index;
|
||||||
uint16_t rvalue;
|
uint16_t rvalue;
|
||||||
|
|
||||||
switch (timer_io_channels[channel].timer_channel) {
|
switch (timer_io_channels[channel].timer_channel) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
@@ -325,29 +338,35 @@ int up_input_capture_get_trigger(unsigned channel, input_capture_edge *edge)
|
|||||||
default:
|
default:
|
||||||
rv = -EIO;
|
rv = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
switch(rvalue) {
|
switch (rvalue) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
*edge = Rising;
|
*edge = Rising;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (GTIM_CCER_CC1P | GTIM_CCER_CC1NP):
|
case (GTIM_CCER_CC1P | GTIM_CCER_CC1NP):
|
||||||
*edge = Both;
|
*edge = Both;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (GTIM_CCER_CC1P):
|
case (GTIM_CCER_CC1P):
|
||||||
*edge = Falling;
|
*edge = Falling;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rv = -EIO;
|
rv = -EIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
|
int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -417,15 +436,18 @@ int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
|
|||||||
default:
|
default:
|
||||||
rv = -EIO;
|
rv = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback, void **context)
|
int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback, void **context)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -441,6 +463,7 @@ int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback
|
|||||||
rv = OK;
|
rv = OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -448,6 +471,7 @@ int up_input_capture_get_callback(unsigned channel, capture_callback_t *callback
|
|||||||
int up_input_capture_set_callback(unsigned channel, capture_callback_t callback, void *context)
|
int up_input_capture_set_callback(unsigned channel, capture_callback_t callback, void *context)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
|
|
||||||
rv = -ENXIO;
|
rv = -ENXIO;
|
||||||
@@ -459,19 +483,24 @@ int up_input_capture_set_callback(unsigned channel, capture_callback_t callback,
|
|||||||
rv = 0;
|
rv = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int up_input_capture_get_stats(unsigned channel, input_capture_stats_t *stats, bool clear)
|
int up_input_capture_get_stats(unsigned channel, input_capture_stats_t *stats, bool clear)
|
||||||
{
|
{
|
||||||
int rv = io_timer_validate_channel_index(channel);
|
int rv = io_timer_validate_channel_index(channel);
|
||||||
|
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
irqstate_t flags = irqsave();
|
irqstate_t flags = irqsave();
|
||||||
*stats = channel_stats[channel];
|
*stats = channel_stats[channel];
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
memset(&channel_stats[channel], 0, sizeof(*stats));
|
memset(&channel_stats[channel], 0, sizeof(*stats));
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ int io_timer_get_mode_channels(io_timer_channel_mode_t mode)
|
|||||||
if (mode < IOTimerChanModeSize) {
|
if (mode < IOTimerChanModeSize) {
|
||||||
return channel_allocations[mode];
|
return channel_allocations[mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,7 +672,7 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
rCR1(actions) = 0;
|
rCR1(actions) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
irqrestore(flags);
|
irqrestore(flags);
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ int up_pwm_servo_init(uint32_t channel_mask)
|
|||||||
channel_mask &= ~(1 << channel);
|
channel_mask &= ~(1 << channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user