52 uint32_t idle_transmit;
56 #define WITH_POWERGRAPH 0
59 PROCESS(shell_power_process,
"power");
62 "power: print power profile",
63 &shell_power_process);
64 PROCESS(shell_energy_process,
"energy");
67 "energy: print energy profile",
68 &shell_energy_process);
69 PROCESS(shell_powerconv_process,
"powerconv");
72 "powerconv: convert power profile to human readable output",
73 &shell_powerconv_process);
75 PROCESS(shell_powergraph_process,
"powergraph");
78 "powergraph: convert power profile to a 'graphical' repressentation",
79 &shell_powergraph_process);
84 static uint32_t last_cpu, last_lpm, last_transmit, last_listen;
85 static uint32_t last_idle_transmit, last_idle_listen;
93 msg.cpu = energest_type_time(ENERGEST_TYPE_CPU) - last_cpu;
94 msg.lpm = energest_type_time(ENERGEST_TYPE_LPM) - last_lpm;
95 msg.transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT) - last_transmit;
96 msg.listen = energest_type_time(ENERGEST_TYPE_LISTEN) - last_listen;
101 last_cpu = energest_type_time(ENERGEST_TYPE_CPU);
102 last_lpm = energest_type_time(ENERGEST_TYPE_LPM);
103 last_transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
104 last_listen = energest_type_time(ENERGEST_TYPE_LISTEN);
115 struct power_msg msg;
122 msg.cpu = energest_type_time(ENERGEST_TYPE_CPU);
123 msg.lpm = energest_type_time(ENERGEST_TYPE_LPM);
124 msg.transmit = energest_type_time(ENERGEST_TYPE_TRANSMIT);
125 msg.listen = energest_type_time(ENERGEST_TYPE_LISTEN);
129 shell_output(&energy_command, &msg,
sizeof(msg),
"", 0);
134 #define DEC2FIX(h,d) ((h * 64L) + (unsigned long)((d * 64L) / 1000L))
136 printpower(
struct power_msg *msg)
139 unsigned long avg_power;
142 time = msg->cpu + msg->lpm;
145 (msg->cpu * DEC2FIX(1L,800L) +
146 msg->lpm * DEC2FIX(0L,545L) +
147 msg->transmit * DEC2FIX(17L,700L) +
148 msg->listen * DEC2FIX(20L,0))) / ((64L * time) / 1000);
149 snprintf(buf,
sizeof(buf),
"CPU %d%% LPM %d%% tx %d%% rx %d%% idle tx %d%% idle rx %d%% tot %lu uW",
150 (
int)((100L * (
unsigned long)msg->cpu) / time),
151 (
int)((100L * (
unsigned long)msg->lpm) / time),
152 (
int)((100L * (
unsigned long)msg->transmit) / time),
153 (
int)((100L * (
unsigned long)msg->listen) / time),
154 (
int)((100L * (
unsigned long)msg->idle_transmit) / time),
155 (
int)((100L * (
unsigned long)msg->idle_listen) / time),
162 struct power_msg *msg;
171 if(input->len1 + input->len2 == 0) {
175 for(msg = (
struct power_msg *)input->data1;
177 msg++, len -=
sizeof(
struct power_msg)) {
181 for(msg = (
struct power_msg *)input->data2;
183 msg++, len -=
sizeof(
struct power_msg)) {
193 #define MAX_POWERGRAPH 34
195 printpowergraph(
struct power_msg *msg)
198 unsigned long avg_power;
200 char buf[MAX_POWERGRAPH];
202 time = msg->cpu + msg->lpm;
205 (msg->cpu * DEC2FIX(1L,800L) +
206 msg->lpm * DEC2FIX(0L,545L) +
207 msg->transmit * DEC2FIX(17L,700L) +
208 msg->listen * DEC2FIX(20L,0))) / ((64L * time) / 1000);
209 memset(buf, 0, MAX_POWERGRAPH);
210 for(i = 0; avg_power > 0 && i < MAX_POWERGRAPH; ++i) {
212 avg_power -= MIN(2000, avg_power);
219 struct power_msg *msg;
228 if(input->len1 + input->len2 == 0) {
232 for(msg = (
struct power_msg *)input->data1;
234 msg++, len -=
sizeof(
struct power_msg)) {
235 printpowergraph(msg);
238 for(msg = (
struct power_msg *)input->data2;
240 msg++, len -=
sizeof(
struct power_msg)) {
241 printpowergraph(msg);
251 shell_power_init(
void)
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_EXIT()
Exit the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
Main header file for the Contiki shell
struct compower_activity compower_idle_activity
The default idle communication activity.
Header file for the communication power accounting module
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
Header file for the energy estimation mechanism
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
Structure for shell input data.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.