source: UsbWattMeter/trunk/asp_dcre/library/histogram.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 4.9 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2006-2011 by Embedded and Real-Time Systems Laboratory
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 *
8 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
9 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
10 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
11 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
12 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
13 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
14 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
15 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
16ƒƒ“ƒgi—˜—p
17 * ŽÒƒ}ƒjƒ…
18ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
19 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
20 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
21 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
22 * ‚ƁD
23 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
24ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
25ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
26 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
27 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
28 * •ñ‚·‚邱‚ƁD
29 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
30 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
31 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
32 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
33 * –Ɛӂ·‚邱‚ƁD
34 *
35 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
36 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
37 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
38 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
39 * ‚̐ӔC‚𕉂í‚È‚¢D
40 *
41 * @(#) $Id: histogram.c 164 2016-03-07 11:33:50Z coas-nagasima $
42 */
43
44/*
45 * ŽÀsŽžŠÔ•ª•zWŒvƒ‚ƒWƒ…
46[ƒ‹
47 */
48
49#include <kernel.h>
50#include <t_syslog.h>
51#include <test_lib.h>
52#include <histogram.h>
53#include "target_test.h"
54
55/*
56 * ŽÀsŽžŠÔ•ª•zŒv‘ª‚̐”
57 */
58#ifndef TNUM_HIST
59#define TNUM_HIST 10
60#endif /* TNUM_HIST */
61
62/*
63 * ƒ^[ƒQƒbƒgˆË‘¶•”‚Őݒè•ÏX‚·‚邽‚߂̃}ƒNƒ
64 */
65#ifndef HISTTIM /* ŽÀsŽžŠÔŒv‘ª—p‚ÌŽž‚̃f[ƒ^Œ^ */
66#define HISTTIM SYSUTM
67#endif /* HISTTIM */
68
69#ifndef HIST_GET_TIM /* ŽÀsŽžŠÔŒv‘ª—p‚ÌŒ»ÝŽž‚̎擾 */
70#ifndef TOPPERS_SUPPORT_GET_UTM
71#error get_utm is not supported.
72#endif /* TOPPERS_SUPPORT_GET_UTM */
73#define HIST_GET_TIM(p_time) ((void) get_utm(p_time))
74#endif /* HIST_GET_TIM */
75
76#ifndef HIST_CONV_TIM /* Žž‚̍·‚©‚çŽÀsŽžŠÔ‚Ö‚Ì•ÏŠ· */
77#define HIST_CONV_TIM(time) ((uint_t)(time))
78#endif /* HIST_CONV_TIM */
79
80#ifndef HIST_BM_HOOK /* ŽÀsŽžŠÔŒv‘ª’¼‘O‚ɍs‚¤‚ׂ«ˆ— */
81#define HIST_BM_HOOK() ((void) 0)
82#endif
83
84/*
85 * ŽÀsŽžŠÔ•ª•zŒv‘ªŠÇ—ƒuƒƒbƒN
86 */
87typedef struct histogram_control_block {
88 HISTTIM begin_time; /* Œv‘ªŠJŽnŽž */
89 uint_t maxval; /* •ª•z‚ð‹L˜^‚·‚éÅ‘厞ŠÔ */
90 uint_t *histarea; /* •ª•z‚ð‹L˜^‚·‚郁ƒ‚ƒŠ—̈æ */
91 uint_t over; /* Å‘厞ŠÔ‚ð’´‚¦‚½“x” */
92 uint_t under; /* ŽžŠÔ‚Ì‹t“]‚ª‹^‚í‚ê‚é“x” */
93} HISTCB;
94
95/*
96 * ŽÀsŽžŠÔ•ª•zŒv‘ªŠÇ—ƒuƒƒbƒN‚̃GƒŠƒA
97 */
98static HISTCB histcb_table[TNUM_HIST];
99
100/*
101 * ŽÀsŽžŠÔ•ª•zŒv‘ªID‚̍ŏ¬’l‚ƍőå’l
102 */
103#define TMIN_HISTID 1
104#define TMAX_HISTID (TMIN_HISTID + TNUM_HIST - 1)
105
106/*
107 * ŽÀsŽžŠÔ•ª•zŒv‘ª‚̏‰Šú‰»
108 */
109void
110init_hist(ID histid, uint_t maxval, uint_t histarea[])
111{
112 HISTCB *p_histcb;
113 uint_t i;
114
115 assert(TMIN_HISTID <= histid && histid <= TMAX_HISTID);
116 p_histcb = &(histcb_table[histid - TMIN_HISTID]);
117
118 for (i = 0; i <= maxval; i++) {
119 histarea[i] = 0U;
120 }
121 p_histcb->maxval = maxval;
122 p_histcb->histarea = histarea;
123 p_histcb->over = 0U;
124 p_histcb->under = 0U;
125}
126
127/*
128 * ŽÀsŽžŠÔŒv‘ª‚ÌŠJŽn
129 */
130void
131begin_measure(ID histid)
132{
133 HISTCB *p_histcb;
134
135 assert(TMIN_HISTID <= histid && histid <= TMAX_HISTID);
136 p_histcb = &(histcb_table[histid - TMIN_HISTID]);
137
138 HIST_BM_HOOK();
139 HIST_GET_TIM(&(p_histcb->begin_time));
140}
141
142/*
143 * ŽÀsŽžŠÔŒv‘ª‚̏I—¹
144 */
145void
146end_measure(ID histid)
147{
148 HISTCB *p_histcb;
149 HISTTIM end_time;
150 uint_t val;
151
152 HIST_GET_TIM(&end_time);
153
154 assert(TMIN_HISTID <= histid && histid <= TMAX_HISTID);
155 p_histcb = &(histcb_table[histid - TMIN_HISTID]);
156
157 val = HIST_CONV_TIM(end_time - p_histcb->begin_time);
158 if (val <= p_histcb->maxval) {
159 p_histcb->histarea[val]++;
160 }
161 else if (val <= ((uint_t) INT_MAX)) {
162 p_histcb->over++;
163 }
164 else {
165 p_histcb->under++;
166 }
167}
168
169/*
170 * ŽÀsŽžŠÔ•ª•zŒv‘ª‚Ì•\Ž¦
171 */
172void
173print_hist(ID histid)
174{
175 HISTCB *p_histcb;
176 uint_t i;
177
178 assert(TMIN_HISTID <= histid && histid <= TMAX_HISTID);
179 p_histcb = &(histcb_table[histid - TMIN_HISTID]);
180
181 for (i = 0; i <= p_histcb->maxval; i++) {
182 if (p_histcb->histarea[i] > 0) {
183 syslog_2(LOG_NOTICE, "%d : %d", i, p_histcb->histarea[i]);
184 syslog_flush();
185 }
186 }
187 if (p_histcb->over > 0) {
188 syslog_2(LOG_NOTICE, "> %d : %d", p_histcb->maxval, p_histcb->over);
189 }
190 if (p_histcb->under > 0) {
191 syslog_1(LOG_NOTICE, "> INT_MAX : %d", p_histcb->under);
192 }
193 syslog_flush();
194}
Note: See TracBrowser for help on using the repository browser.