Subversion Repositories chibiosIgnition

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 mjames 1
/*
2
 * shellCmds.c
3
 *
4
 *  Created on: 1 Oct 2019
5
 *      Author: Mike
6
 */
7
 
8
 
9
#include <stdio.h>
10
#include <string.h>
11
 
12
#include "ch.h"
13
#include "hal.h"
14
//#include "test.h"
15
#include "shell.h"
16
#include "evtimer.h"
17
#include "chprintf.h"
18
 
19
#include "shellCmds.h"
20
 
21
 
22
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
23
        size_t n, size , largest;
24
 
25
        (void) argv;
26
        if (argc > 0) {
27
                chprintf(chp, "Usage: mem\r\n");
28
                return;
29
        }
30
        n = chHeapStatus(NULL, &size, &largest);
31
        chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
32
        chprintf(chp, "heap fragments   : %u \r\n",n);
33
        chprintf(chp, "largest fragment : %u \r\n",largest);
34
        chprintf(chp, "heap free total  : %u bytes\r\n", size);
35
}
36
 
37
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
38
          static const char *states[] = {CH_STATE_NAMES};
39
          thread_t *tp;
40
 
41
          (void)argv;
42
          if (argc > 0) {
43
            shellUsage(chp, "threads");
44
            return;
45
          }
46
          chprintf(chp, "stklimit    stack     addr refs prio     state         name\r\n" SHELL_NEWLINE_STR);
47
          tp = chRegFirstThread();
48
          do {
49
        #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
50
            uint32_t stklimit = (uint32_t)tp->wabase;
51
        #else
52
            uint32_t stklimit = 0U;
53
        #endif
54
            chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s" SHELL_NEWLINE_STR,
55
                     stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp,
56
                     (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state],
57
                     tp->name == NULL ? "" : tp->name);
58
            tp = chRegNextThread(tp);
59
          } while (tp != NULL);
60
        }
61
 
62
 
63
static void cmd_pll (BaseChannel *chp, int argc, char *argv[])
64
{
65
 
66
        chprintf(chp,"pll\r\n");
67
 
68
        if(argc > 0)
69
                chprintf(chp,"has %d args\r\n",argc);
70
 
71
}
72
 
73
 
74
 
75
 
76
 
77
 
78
const ShellCommand shellCommands[] = { { "mem", cmd_mem }, { "threads",
79
                cmd_threads }, { "pll", cmd_pll }, { NULL, NULL } };
80
 
81