本文整理汇总了C++中chHeapStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ chHeapStatus函数的具体用法?C++ chHeapStatus怎么用?C++ chHeapStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chHeapStatus函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dyn1_execute
static void dyn1_execute(void) {
size_t n, sz;
void *p1;
tprio_t prio = chThdGetPriority();
(void)chHeapStatus(&heap1, &sz);
/* Starting threads from the heap. */
threads[0] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
prio-1, thread, "A");
threads[1] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
prio-2, thread, "B");
/* Allocating the whole heap in order to make the thread creation fail.*/
(void)chHeapStatus(&heap1, &n);
p1 = chHeapAlloc(&heap1, n);
threads[2] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
prio-3, thread, "C");
chHeapFree(p1);
test_assert(1, (threads[0] != NULL) &&
(threads[1] != NULL) &&
(threads[2] == NULL) &&
(threads[3] == NULL) &&
(threads[4] == NULL),
"thread creation failed");
/* Claiming the memory from terminated threads. */
test_wait_threads();
test_assert_sequence(2, "AB");
/* Heap status checked again.*/
test_assert(3, chHeapStatus(&heap1, &n) == 1, "heap fragmented");
test_assert(4, n == sz, "heap size changed");
}
开发者ID:Amirelecom,项目名称:brush-v1,代码行数:33,代码来源:testdyn.c
示例2: cmd_mem
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: mem\r\n");
return;
}
n = chHeapStatus(NULL, &size);
chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
开发者ID:barthess,项目名称:eeprom_burn,代码行数:13,代码来源:main.c
示例3: cmd_mem
static void cmd_mem( int argc, char *argv[] )
{
size_t n, size;
(void)argv;
if( argc > 0 )
{
usage( "mem" );
return;
}
n = chHeapStatus( NULL, &size );
chprint( "core free memory : %u bytes\r\n", chCoreGetStatusX() );
chprint( "heap fragments : %u\r\n", n );
chprint( "heap free total : %u bytes\r\n", size );
}
开发者ID:JeremySavonet,项目名称:Eurobot-2016_The-beach-bots,代码行数:16,代码来源:microshell.c
示例4: cmd_mem
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size;
char buf[52];
(void)argv;
if (argc > 0) {
shellPrintLine(chp, "Usage: mem");
return;
}
n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %lu bytes", chCoreStatus());
shellPrintLine(chp, buf);
siprintf(buf, "heap fragments : %lu", n);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %lu bytes", size);
shellPrintLine(chp, buf);
}
开发者ID:Amirelecom,项目名称:brush-v1,代码行数:17,代码来源:main.c
示例5: add_children
DebugMemoryView::DebugMemoryView(NavigationView& nav) {
add_children({ {
&text_title,
&text_label_m0_free,
&text_label_m0_free_value,
&text_label_m0_heap_fragmented_free,
&text_label_m0_heap_fragmented_free_value,
&text_label_m0_heap_fragments,
&text_label_m0_heap_fragments_value,
&button_done
} });
const auto m0_free = chCoreStatus();
text_label_m0_free_value.set(to_string_dec_uint(m0_free, 5));
size_t m0_fragmented_free_space = 0;
const auto m0_fragments = chHeapStatus(NULL, &m0_fragmented_free_space);
text_label_m0_heap_fragmented_free_value.set(to_string_dec_uint(m0_fragmented_free_space, 5));
text_label_m0_heap_fragments_value.set(to_string_dec_uint(m0_fragments, 5));
button_done.on_select = [&nav](Button&){ nav.pop(); };
}
开发者ID:EQ4,项目名称:portapack-hackrf,代码行数:22,代码来源:ui_debug.cpp
示例6: heap1_execute
static void heap1_execute(void) {
void *p1, *p2, *p3;
size_t n, sz;
/* Unrelated, for coverage only.*/
(void)chCoreStatus();
/*
* Test on the default heap in order to cover the core allocator at
* least one time.
*/
(void)chHeapStatus(NULL, &sz);
p1 = chHeapAlloc(NULL, SIZE);
test_assert(1, p1 != NULL, "allocation failed");
chHeapFree(p1);
p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(2, p1 == NULL, "allocation not failed");
/* Initial local heap state.*/
(void)chHeapStatus(&test_heap, &sz);
/* Same order.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
p3 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p1); /* Does not merge.*/
chHeapFree(p2); /* Merges backward.*/
chHeapFree(p3); /* Merges both sides.*/
test_assert(3, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
/* Reverse order.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
p3 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p3); /* Merges forward.*/
chHeapFree(p2); /* Merges forward.*/
chHeapFree(p1); /* Merges forward.*/
test_assert(4, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
/* Small fragments handling.*/
p1 = chHeapAlloc(&test_heap, SIZE + 1);
p2 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p1);
test_assert(5, chHeapStatus(&test_heap, &n) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, SIZE);
/* Note, the first situation happens when the alignment size is smaller
than the header size, the second in the other cases.*/
test_assert(6, (chHeapStatus(&test_heap, &n) == 1) ||
(chHeapStatus(&test_heap, &n) == 2), "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
test_assert(7, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
/* Skip fragment handling.*/
p1 = chHeapAlloc(&test_heap, SIZE);
p2 = chHeapAlloc(&test_heap, SIZE);
chHeapFree(p1);
test_assert(8, chHeapStatus(&test_heap, &n) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
test_assert(9, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
/* Allocate all handling.*/
(void)chHeapStatus(&test_heap, &n);
p1 = chHeapAlloc(&test_heap, n);
test_assert(10, chHeapStatus(&test_heap, &n) == 0, "not empty");
chHeapFree(p1);
test_assert(11, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
test_assert(12, n == sz, "size changed");
}
开发者ID:ColonelPanic42,项目名称:ChibiOS-RPi,代码行数:72,代码来源:testheap.c
示例7: terminal_process_string
void terminal_process_string(char *str) {
enum { kMaxArgs = 64 };
int argc = 0;
char *argv[kMaxArgs];
char *p2 = strtok(str, " ");
while (p2 && argc < kMaxArgs) {
argv[argc++] = p2;
p2 = strtok(0, " ");
}
if (argc == 0) {
commands_printf("No command received\n");
return;
}
if (strcmp(argv[0], "ping") == 0) {
commands_printf("pong\n");
} else if (strcmp(argv[0], "stop") == 0) {
mcpwm_set_duty(0);
commands_printf("Motor stopped\n");
} else if (strcmp(argv[0], "last_adc_duration") == 0) {
commands_printf("Latest ADC duration: %.4f ms", (double)(mcpwm_get_last_adc_isr_duration() * 1000.0));
commands_printf("Latest injected ADC duration: %.4f ms", (double)(mcpwm_get_last_inj_adc_isr_duration() * 1000.0));
commands_printf("Latest main ADC duration: %.4f ms\n", (double)(main_get_last_adc_isr_duration() * 1000.0));
} else if (strcmp(argv[0], "kv") == 0) {
commands_printf("Calculated KV: %.2f rpm/volt\n", (double)mcpwm_get_kv_filtered());
} else if (strcmp(argv[0], "mem") == 0) {
size_t n, size;
n = chHeapStatus(NULL, &size);
commands_printf("core free memory : %u bytes", chCoreStatus());
commands_printf("heap fragments : %u", n);
commands_printf("heap free total : %u bytes\n", size);
} else if (strcmp(argv[0], "threads") == 0) {
Thread *tp;
static const char *states[] = {THD_STATE_NAMES};
commands_printf(" addr stack prio refs state name time ");
commands_printf("-------------------------------------------------------------");
tp = chRegFirstThread();
do {
commands_printf("%.8lx %.8lx %4lu %4lu %9s %14s %lu",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
commands_printf("");
} else if (strcmp(argv[0], "fault") == 0) {
commands_printf("%s\n", mcpwm_fault_to_string(mcpwm_get_fault()));
} else if (strcmp(argv[0], "faults") == 0) {
if (fault_vec_write == 0) {
commands_printf("No faults registered since startup\n");
} else {
commands_printf("The following faults were registered since start:\n");
for (int i = 0;i < fault_vec_write;i++) {
commands_printf("Fault : %s", mcpwm_fault_to_string(fault_vec[i].fault));
commands_printf("Current : %.1f", (double)fault_vec[i].current);
commands_printf("Current filtered : %.1f", (double)fault_vec[i].current_filtered);
commands_printf("Voltage : %.2f", (double)fault_vec[i].voltage);
commands_printf("Duty : %.2f", (double)fault_vec[i].duty);
commands_printf("RPM : %.1f", (double)fault_vec[i].rpm);
commands_printf("Tacho : %d", fault_vec[i].tacho);
commands_printf("TIM PWM CNT : %d", fault_vec[i].tim_pwm_cnt);
commands_printf("TIM Samp CNT : %d", fault_vec[i].tim_samp_cnt);
commands_printf("Comm step : %d", fault_vec[i].comm_step);
commands_printf("Temperature : %.2f\n", (double)fault_vec[i].temperature);
}
}
} else if (strcmp(argv[0], "rpm") == 0) {
commands_printf("Electrical RPM: %.2f rpm\n", (double)mcpwm_get_rpm());
} else if (strcmp(argv[0], "tacho") == 0) {
commands_printf("Tachometer counts: %i\n", mcpwm_get_tachometer_value(0));
} else if (strcmp(argv[0], "tim") == 0) {
chSysLock();
volatile int t1_cnt = TIM1->CNT;
volatile int t8_cnt = TIM8->CNT;
chSysUnlock();
int duty = TIM1->CCR1;
int top = TIM1->ARR;
int voltage_samp = TIM8->CCR1;
int current1_samp = TIM1->CCR4;
int current2_samp = TIM8->CCR2;
commands_printf("Tim1 CNT: %i", t1_cnt);
commands_printf("Tim8 CNT: %u", t8_cnt);
commands_printf("Duty cycle: %u", duty);
commands_printf("Top: %u", top);
commands_printf("Voltage sample: %u", voltage_samp);
commands_printf("Current 1 sample: %u", current1_samp);
commands_printf("Current 2 sample: %u\n", current2_samp);
} else if (strcmp(argv[0], "volt") == 0) {
commands_printf("Input voltage: %.2f\n", (double)GET_INPUT_VOLTAGE());
} else if (strcmp(argv[0], "param_detect") == 0) {
// Use COMM_MODE_DELAY and try to figure out the motor parameters.
if (argc == 4) {
float current = -1.0;
float min_rpm = -1.0;
float low_duty = -1.0;
sscanf(argv[1], "%f", ¤t);
sscanf(argv[2], "%f", &min_rpm);
sscanf(argv[3], "%f", &low_duty);
//.........这里部分代码省略.........
开发者ID:g1pete,项目名称:bldc,代码行数:101,代码来源:terminal.c
示例8: terminal_process_string
void terminal_process_string(char *str) {
enum { kMaxArgs = 64 };
int argc = 0;
char *argv[kMaxArgs];
char *p2 = strtok(str, " ");
while (p2 && argc < kMaxArgs) {
argv[argc++] = p2;
p2 = strtok(0, " ");
}
if (argc == 0) {
commands_printf("No command received\n");
return;
}
static mc_configuration mcconf; // static to save some stack
static mc_configuration mcconf_old; // static to save some stack
mcconf = *mc_interface_get_configuration();
mcconf_old = mcconf;
if (strcmp(argv[0], "ping") == 0) {
commands_printf("pong\n");
} else if (strcmp(argv[0], "stop") == 0) {
mc_interface_set_duty(0);
commands_printf("Motor stopped\n");
} else if (strcmp(argv[0], "last_adc_duration") == 0) {
commands_printf("Latest ADC duration: %.4f ms", (double)(mcpwm_get_last_adc_isr_duration() * 1000.0));
commands_printf("Latest injected ADC duration: %.4f ms", (double)(mc_interface_get_last_inj_adc_isr_duration() * 1000.0));
commands_printf("Latest sample ADC duration: %.4f ms\n", (double)(mc_interface_get_last_sample_adc_isr_duration() * 1000.0));
} else if (strcmp(argv[0], "kv") == 0) {
commands_printf("Calculated KV: %.2f rpm/volt\n", (double)mcpwm_get_kv_filtered());
} else if (strcmp(argv[0], "mem") == 0) {
size_t n, size;
n = chHeapStatus(NULL, &size);
commands_printf("core free memory : %u bytes", chCoreGetStatusX());
commands_printf("heap fragments : %u", n);
commands_printf("heap free total : %u bytes\n", size);
} else if (strcmp(argv[0], "threads") == 0) {
thread_t *tp;
static const char *states[] = {CH_STATE_NAMES};
commands_printf(" addr stack prio refs state name time ");
commands_printf("-------------------------------------------------------------");
tp = chRegFirstThread();
do {
commands_printf("%.8lx %.8lx %4lu %4lu %9s %14s %lu",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
commands_printf("");
} else if (strcmp(argv[0], "fault") == 0) {
commands_printf("%s\n", mc_interface_fault_to_string(mc_interface_get_fault()));
} else if (strcmp(argv[0], "faults") == 0) {
if (fault_vec_write == 0) {
commands_printf("No faults registered since startup\n");
} else {
commands_printf("The following faults were registered since start:\n");
for (int i = 0;i < fault_vec_write;i++) {
commands_printf("Fault : %s", mc_interface_fault_to_string(fault_vec[i].fault));
commands_printf("Current : %.1f", (double)fault_vec[i].current);
commands_printf("Current filtered : %.1f", (double)fault_vec[i].current_filtered);
commands_printf("Voltage : %.2f", (double)fault_vec[i].voltage);
commands_printf("Duty : %.2f", (double)fault_vec[i].duty);
commands_printf("RPM : %.1f", (double)fault_vec[i].rpm);
commands_printf("Tacho : %d", fault_vec[i].tacho);
commands_printf("Cycles running : %d", fault_vec[i].cycles_running);
commands_printf("TIM duty : %d", (int)((float)fault_vec[i].tim_top * fault_vec[i].duty));
commands_printf("TIM val samp : %d", fault_vec[i].tim_val_samp);
commands_printf("TIM current samp : %d", fault_vec[i].tim_current_samp);
commands_printf("TIM top : %d", fault_vec[i].tim_top);
commands_printf("Comm step : %d", fault_vec[i].comm_step);
commands_printf("Temperature : %.2f\n", (double)fault_vec[i].temperature);
}
}
} else if (strcmp(argv[0], "rpm") == 0) {
commands_printf("Electrical RPM: %.2f rpm\n", (double)mc_interface_get_rpm());
} else if (strcmp(argv[0], "tacho") == 0) {
commands_printf("Tachometer counts: %i\n", mc_interface_get_tachometer_value(0));
} else if (strcmp(argv[0], "tim") == 0) {
chSysLock();
volatile int t1_cnt = TIM1->CNT;
volatile int t8_cnt = TIM8->CNT;
volatile int dir1 = !!(TIM1->CR1 & (1 << 4));
volatile int dir8 = !!(TIM8->CR1 & (1 << 4));
chSysUnlock();
int duty1 = TIM1->CCR1;
int duty2 = TIM1->CCR2;
int duty3 = TIM1->CCR3;
int top = TIM1->ARR;
int voltage_samp = TIM8->CCR1;
int current1_samp = TIM1->CCR4;
int current2_samp = TIM8->CCR2;
commands_printf("Tim1 CNT: %i", t1_cnt);
commands_printf("Tim8 CNT: %u", t8_cnt);
commands_printf("Duty cycle1: %u", duty1);
commands_printf("Duty cycle2: %u", duty2);
commands_printf("Duty cycle3: %u", duty3);
commands_printf("Top: %u", top);
//.........这里部分代码省略.........
开发者ID:451506709,项目名称:bldc,代码行数:101,代码来源:terminal.c
示例9: terminal_process_string
void terminal_process_string(char *str) {
enum { kMaxArgs = 64 };
int argc = 0;
char *argv[kMaxArgs];
#if MAIN_MODE == MAIN_MODE_CAR
static char buffer[256];
#endif
char *p2 = strtok(str, " ");
while (p2 && argc < kMaxArgs) {
argv[argc++] = p2;
p2 = strtok(0, " ");
}
if (argc == 0) {
commands_printf("No command received\n");
return;
}
if (strcmp(argv[0], "ping") == 0) {
commands_printf("pong\n");
} else if (strcmp(argv[0], "mem") == 0) {
size_t n, size;
n = chHeapStatus(NULL, &size);
commands_printf("core free memory : %u bytes", chCoreGetStatusX());
commands_printf("heap fragments : %u", n);
commands_printf("heap free total : %u bytes\n", size);
} else if (strcmp(argv[0], "threads") == 0) {
thread_t *tp;
static const char *states[] = {CH_STATE_NAMES};
commands_printf(" addr stack prio refs state name time ");
commands_printf("-------------------------------------------------------------");
tp = chRegFirstThread();
do {
commands_printf("%.8lx %.8lx %4lu %4lu %9s %14s %lu",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
commands_printf(" ");
}
#if MAIN_MODE == MAIN_MODE_CAR
else if (strcmp(argv[0], "vesc") == 0) {
buffer[0] = '\0';
int ind = 0;
for (int i = 1;i < argc;i++) {
sprintf(buffer + ind, " %s", argv[i]);
ind += strlen(argv[i]) + 1;
}
bldc_interface_terminal_cmd(buffer);
}
#if RADAR_EN
else if (strcmp(argv[0], "radar_sample") == 0) {
commands_printf("Sampling radar...");
radar_setup_measurement_default();
radar_sample();
} else if (strcmp(argv[0], "radar_cmd") == 0) {
buffer[0] = '\0';
int ind = 0;
for (int i = 1;i < argc;i++) {
if (i == 1) {
sprintf(buffer + ind, "%s", argv[i]);
ind += strlen(argv[i]);
} else {
sprintf(buffer + ind, " %s", argv[i]);
ind += strlen(argv[i]) + 1;
}
}
radar_cmd(buffer);
} else if (strcmp(argv[0], "radar_reset") == 0) {
commands_printf("Resetting radar...");
radar_reset_setup();
}
#endif
#endif
else if (strcmp(argv[0], "reset_att") == 0) {
pos_reset_attitude();
} else if (strcmp(argv[0], "reset_enu") == 0) {
pos_reset_enu_ref();
} else if (strcmp(argv[0], "cc1120_state") == 0) {
commands_printf("%s\n", cc1120_state_name());
} else if (strcmp(argv[0], "cc1120_update_rf") == 0) {
if (argc != 2) {
commands_printf("Invalid number of arguments\n");
} else {
int set = -1;
sscanf(argv[1], "%d", &set);
if (set < 0) {
commands_printf("Invalid argument\n");
} else {
cc1120_update_rf(set);
commands_printf("Done\n");
}
}
//.........这里部分代码省略.........
开发者ID:wellrun,项目名称:rise_sdvp,代码行数:101,代码来源:terminal.c
示例10: terminal_process_string
void terminal_process_string(char *str) {
enum { kMaxArgs = 64 };
int argc = 0;
char *argv[kMaxArgs];
static char buffer[256];
char *p2 = strtok(str, " ");
while (p2 && argc < kMaxArgs) {
argv[argc++] = p2;
p2 = strtok(0, " ");
}
if (argc == 0) {
comm_print("No command received\n");
return;
}
if (strcmp(argv[0], "ping") == 0) {
comm_print("pong\n");
} else if (strcmp(argv[0], "stop") == 0) {
mcpwm_set_duty(0);
comm_print("Motor stopped\n");
} else if (strcmp(argv[0], "last_adc_duration") == 0) {
sprintf(buffer, "Latest ADC duration: %.4f ms", (double)(mcpwm_get_last_adc_isr_duration() * 1000.0));
comm_print(buffer);
sprintf(buffer, "Latest injected ADC duration: %.4f ms", (double)(mcpwm_get_last_inj_adc_isr_duration() * 1000.0));
comm_print(buffer);
sprintf(buffer, "Latest main ADC duration: %.4f ms\n", (double)(main_get_last_adc_isr_duration() * 1000.0));
comm_print(buffer);
} else if (strcmp(argv[0], "kv") == 0) {
sprintf(buffer, "Calculated KV: %.2f rpm/volt\n", (double)mcpwm_get_kv_filtered());
comm_print(buffer);
} else if (strcmp(argv[0], "mem") == 0) {
size_t n, size;
n = chHeapStatus(NULL, &size);
sprintf(buffer, "core free memory : %u bytes", chCoreStatus());
comm_print(buffer);
sprintf(buffer, "heap fragments : %u", n);
comm_print(buffer);
sprintf(buffer, "heap free total : %u bytes\n", size);
comm_print(buffer);
} else if (strcmp(argv[0], "threads") == 0) {
Thread *tp;
static const char *states[] = {THD_STATE_NAMES};
comm_print(" addr stack prio refs state name time ");
comm_print("-------------------------------------------------------------");
tp = chRegFirstThread();
do {
sprintf(buffer, "%.8lx %.8lx %4lu %4lu %9s %14s %lu",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
comm_print(buffer);
tp = chRegNextThread(tp);
} while (tp != NULL);
comm_print("");
} else if (strcmp(argv[0], "fault") == 0) {
comm_print_fault_code(mcpwm_get_fault());
} else if (strcmp(argv[0], "rpm") == 0) {
sprintf(buffer, "Electrical RPM: %.2f rpm\n", (double)mcpwm_get_rpm());
comm_print(buffer);
} else if (strcmp(argv[0], "tacho") == 0) {
sprintf(buffer, "Tachometer counts: %i\n", mcpwm_get_tachometer_value(0));
comm_print(buffer);
} else if (strcmp(argv[0], "tim") == 0) {
TIM_Cmd(TIM1, DISABLE);
int t1_cnt = TIM1->CNT;
int t8_cnt = TIM8->CNT;
int duty = TIM1->CCR1;
int top = TIM1->ARR;
int voltage_samp = TIM8->CCR1;
int current1_samp = TIM1->CCR4;
int current2_samp = TIM8->CCR2;
TIM_Cmd(TIM1, ENABLE);
sprintf(buffer, "Tim1 CNT: %i", t1_cnt);
comm_print(buffer);
sprintf(buffer, "Tim8 CNT: %u", t8_cnt);
comm_print(buffer);
sprintf(buffer, "Duty cycle: %u", duty);
comm_print(buffer);
sprintf(buffer, "Top: %u", top);
comm_print(buffer);
sprintf(buffer, "Voltage sample: %u", voltage_samp);
comm_print(buffer);
sprintf(buffer, "Current 1 sample: %u", current1_samp);
comm_print(buffer);
sprintf(buffer, "Current 2 sample: %u\n", current2_samp);
comm_print(buffer);
} else if (strcmp(argv[0], "help") == 0) {
comm_print("Valid commands are:");
comm_print("help");
comm_print(" Show this help");
comm_print("ping");
comm_print(" Print pong here to see if the reply works");
comm_print("stop");
comm_print(" Stop the motor");
comm_print("last_adc_duration");
//.........这里部分代码省略.........
开发者ID:rewolff,项目名称:bldc,代码行数:101,代码来源:terminal.c
示例11: terminal_process_string
void terminal_process_string(char *str) {
enum { kMaxArgs = 64 };
int argc = 0;
char *argv[kMaxArgs];
char *p2 = strtok(str, " ");
while (p2 && argc < kMaxArgs) {
argv[argc++] = p2;
p2 = strtok(0, " ");
}
if (argc == 0) {
comm_printf("No command received\n");
return;
}
if (strcmp(argv[0], "ping") == 0) {
comm_printf("pong\n");
} else if (strcmp(argv[0], "stop") == 0) {
mcpwm_set_duty(0);
comm_printf("Motor stopped\n");
} else if (strcmp(argv[0], "last_adc_duration") == 0) {
comm_printf("Latest ADC duration: %.4f ms", (double)(mcpwm_get_last_adc_isr_duration() * 1000.0));
comm_printf("Latest injected ADC duration: %.4f ms", (double)(mcpwm_get_last_inj_adc_isr_duration() * 1000.0));
comm_printf("Latest main ADC duration: %.4f ms\n", (double)(main_get_last_adc_isr_duration() * 1000.0));
} else if (strcmp(argv[0], "kv") == 0) {
comm_printf("Calculated KV: %.2f rpm/volt\n", (double)mcpwm_get_kv_filtered());
} else if (strcmp(argv[0], "mem") == 0) {
size_t n, size;
n = chHeapStatus(NULL, &size);
comm_printf("core free memory : %u bytes", chCoreStatus());
comm_printf("heap fragments : %u", n);
comm_printf("heap free total : %u bytes\n", size);
} else if (strcmp(argv[0], "threads") == 0) {
Thread *tp;
static const char *states[] = {THD_STATE_NAMES};
comm_printf(" addr stack prio refs state name time ");
comm_printf("-------------------------------------------------------------");
tp = chRegFirstThread();
do {
comm_printf("%.8lx %.8lx %4lu %4lu %9s %14s %lu",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
comm_printf("");
} else if (strcmp(argv[0], "fault") == 0) {
comm_print_fault_code(mcpwm_get_fault());
} else if (strcmp(argv[0], "rpm") == 0) {
comm_printf("Electrical RPM: %.2f rpm\n", (double)mcpwm_get_rpm());
} else if (strcmp(argv[0], "tacho") == 0) {
comm_printf("Tachometer counts: %i\n", mcpwm_get_tachometer_value(0));
} else if (strcmp(argv[0], "tim") == 0) {
TIM_Cmd(TIM_PWM, DISABLE);
int t_pwm_cnt = TIM_PWM->CNT;
int t_adc_cnt = TIM_ADC->CNT;
int duty = TIM_PWM->CCR1;
int top = TIM_PWM->ARR;
int voltage_samp = TIM_ADC->CCR1;
int current1_samp = TIM_PWM->CCR4;
int current2_samp = TIM_ADC->CCR4;
TIM_Cmd(TIM_PWM, ENABLE);
comm_printf("TIM_PWM CNT: %i", t_pwm_cnt);
comm_printf("TIM_ADC CNT: %u", t_adc_cnt);
comm_printf("Duty cycle: %u", duty);
comm_printf("Top: %u", top);
comm_printf("Voltage sample: %u", voltage_samp);
comm_printf("Current 1 sample: %u", current1_samp);
comm_printf("Current 2 sample: %u\n", current2_samp);
} else if (strcmp(argv[0], "volt") == 0) {
comm_printf("Input voltage: %.2f\n", (double)GET_INPUT_VOLTAGE());
} else if (strcmp(argv[0], "reset_drv") == 0) {
comm_printf("reset driver\n");
mcpwm_reset_driver();
}
// Setters
else if (strcmp(argv[0], "set_hall_table") == 0) {
if (argc == 4) {
int dir = -1;
int fwd_add = -1;
int rev_add = -1;
sscanf(argv[1], "%i", &dir);
sscanf(argv[2], "%i", &fwd_add);
sscanf(argv[3], "%i", &rev_add);
if (dir >= 0 && fwd_add >= 0 && rev_add >= 0) {
mcpwm_init_hall_table(dir, fwd_add, rev_add);
comm_printf("New hall sensor dir: %i fwd_add %i rev_add %i\n",
dir, fwd_add, rev_add);
} else {
comm_printf("Invalid argument(s).\n");
}
} else {
comm_printf("This command requires three arguments.\n");
}
}
// The help command
//.........这里部分代码省略.........
开发者ID:cyrilh,项目名称:bldc,代码行数:101,代码来源:terminal.c
注:本文中的chHeapStatus函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论