shared_fooの不要ディレクトリ削除前のもの
Revision | 563c3277e232a9ac0a0b6fa31101c9913f2d7b42 (tree) |
---|---|
Time | 2018-03-03 15:55:47 |
Author | takemasa <suikan@user...> |
Commiter | takemasa |
Removed ifdef
@@ -22,31 +22,13 @@ Debugger::Debugger(AbstractLogger * logger) | ||
22 | 22 | // initialize internal variable; |
23 | 23 | MURASAKI_ASSERT(logger != nullptr) |
24 | 24 | |
25 | - auto_history_enabled = false; | |
26 | - auto_history_task_ = nullptr; | |
27 | - | |
28 | -#ifdef OLDIMPLEMENTATION | |
29 | - logger_ = logger; | |
30 | - sem_notify_new_data_ = ::xSemaphoreCreateBinary(); // create semaphore as "empty" state | |
31 | - MURASAKI_ASSERT(sem_notify_new_data_); | |
32 | - | |
33 | - // set the circular buffer empty. | |
34 | - head_ = 0; | |
35 | - tail_ = 0; | |
36 | - | |
37 | - for (unsigned int i = 0; i < sizeof(buffer_); i++) | |
38 | - buffer_[i] = ' '; | |
39 | - // start the debug task | |
40 | - BaseType_t task_result = ::xTaskCreate( | |
41 | - Debugger::LaunchTxTask, // task entity; | |
42 | - "DebugTask", // name of task | |
43 | - PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth | |
44 | - this, // parameter to task | |
45 | - PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task | |
46 | - &tx_task_ // receive task handle | |
47 | - ); | |
48 | - MURASAKI_ASSERT(task_result != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY); | |
49 | -#else | |
25 | + | |
26 | + helpers_.fifo = nullptr; | |
27 | + tx_task_ = nullptr; | |
28 | + | |
29 | + auto_reprint_enable_ = false; | |
30 | + auto_reprint_task = nullptr; | |
31 | + | |
50 | 32 | helpers_.fifo = new murasaki::DebuggerFifo(PLATFORM_CONFIG_DEBUG_BUFFER_SIZE); |
51 | 33 | helpers_.logger = logger; |
52 | 34 |
@@ -59,66 +41,25 @@ Debugger::Debugger(AbstractLogger * logger) | ||
59 | 41 | |
60 | 42 | tx_task_->Start(); |
61 | 43 | |
62 | -#endif | |
63 | 44 | } |
64 | 45 | |
65 | 46 | Debugger::~Debugger() |
66 | 47 | { |
67 | -#ifdef OLDIMPLEMENTATION | |
68 | 48 | // Delete task; |
69 | 49 | if (tx_task_ != nullptr) |
70 | - ::vTaskDelete(tx_task_); | |
50 | + delete tx_task_; | |
71 | 51 | |
72 | 52 | // Delete task; |
73 | - if (auto_history_task_ != nullptr) | |
74 | - ::vTaskDelete(auto_history_task_); | |
53 | + if (auto_reprint_task != nullptr) | |
54 | + delete auto_reprint_task; | |
75 | 55 | |
76 | - // Delete semaphore. | |
77 | - if (sem_notify_new_data_ != nullptr) | |
78 | - ::vSemaphoreDelete( sem_notify_new_data_); | |
79 | -#else | |
80 | -#endif | |
56 | + // Delete FIFO | |
57 | + if (helpers_.fifo != nullptr) | |
58 | + delete helpers_.fifo; | |
81 | 59 | } |
82 | 60 | |
83 | 61 | void Debugger::printf(const char * fmt, ...) |
84 | 62 | { |
85 | -#ifdef OLDIMPLEMENTATION | |
86 | - // obtain variable parameter list | |
87 | - va_list argp; | |
88 | - | |
89 | - MURASAKI_ASSERT(nullptr != fmt); // nullptr check. Perhaps, overkill. | |
90 | - | |
91 | - portDISABLE_INTERRUPTS(); // ARM dependent API. OK to use in task and ISR. | |
92 | - { | |
93 | -#if 0 | |
94 | - // Test the remains of task stack in byte. | |
95 | - // To use the uxTaskGetStackHighWaterMark(), Add following to the | |
96 | - // FreeRTOSConfig.h | |
97 | - // #define INCLUDE_uxTaskGetStackHighWaterMark 1 | |
98 | - | |
99 | - ::snprintf((char *) line_, | |
100 | - sizeof(line_) - 1, | |
101 | - "stack remains : %8d bytes. ", | |
102 | - (int) uxTaskGetStackHighWaterMark(tx_task_)); | |
103 | - AppendToBuffer(); | |
104 | -#endif | |
105 | - ::va_start(argp, fmt); | |
106 | - // convert the number with formt string to the line string. | |
107 | - // The string length have to be N - 1. Where N is the length of the destination variable. | |
108 | - ::vsnprintf((char *) line_, sizeof(line_) - 1, fmt, argp); | |
109 | - | |
110 | - ::va_end(argp); | |
111 | - // Append the line to the buffer to be sent. | |
112 | - AppendToBuffer(); | |
113 | - } | |
114 | - portENABLE_INTERRUPTS(); | |
115 | - | |
116 | - // Notify to the consumer task, the new data has come. | |
117 | - if (isTaskContext()) // Are we in the task context? | |
118 | - ::xSemaphoreGive(sem_notify_new_data_); // if yes | |
119 | - else | |
120 | - ::xSemaphoreGiveFromISR(sem_notify_new_data_, nullptr); // if no. | |
121 | -#else | |
122 | 63 | // obtain variable parameter list |
123 | 64 | va_list argp; |
124 | 65 |
@@ -152,56 +93,16 @@ void Debugger::printf(const char * fmt, ...) | ||
152 | 93 | |
153 | 94 | // Notify to the consumer task, the new data has come. |
154 | 95 | helpers_.fifo->NotifyData(); |
155 | -#endif | |
156 | 96 | |
157 | 97 | } |
158 | 98 | |
159 | 99 | char Debugger::GetchFromTask() |
160 | 100 | { |
161 | 101 | MURASAKI_ASSERT(isTaskContext()); |
162 | -#ifdef OLDIMPLEMENTATION | |
163 | - return logger_->getCharacter(); // receive successfuly. | |
164 | -#else | |
102 | + | |
165 | 103 | return helpers_.logger->getCharacter(); |
166 | -#endif | |
167 | 104 | } |
168 | 105 | |
169 | -// Assumes this is called only in the critical section. | |
170 | -void Debugger::AppendToBuffer() | |
171 | -{ | |
172 | -#ifdef OLDIMPLEMENTATION | |
173 | - unsigned int avairable; | |
174 | - | |
175 | - // check the avairable area size. Data is append to the head | |
176 | - if (head_ > tail_) // there is no wrap around | |
177 | - avairable = sizeof(buffer_) - (head_ - tail_); | |
178 | - else if (tail_ > head_) | |
179 | - avairable = tail_ - head_; | |
180 | - else | |
181 | - avairable = sizeof(buffer_); | |
182 | - | |
183 | - // If we fill up buffer entirely, we can not distinguish full and empty from the | |
184 | - // comparing tail_ and head_. | |
185 | - // This can be fixed if we add new variable "length", but it get complex. | |
186 | - // To save this problem, we clip the vacant size by buffsersize-1. | |
187 | - if (avairable > 0) | |
188 | - avairable--; | |
189 | - | |
190 | - // clip the line size by available room in the buffer. | |
191 | - int line_length = std::min(::strlen((char *) line_), avairable); | |
192 | - | |
193 | - // Now, we can copy from line to buffer. | |
194 | - for (int i = 0; i < line_length; i++) { | |
195 | - // newest data is appended to the point of head_ | |
196 | - buffer_[head_] = line_[i]; | |
197 | - head_++; | |
198 | - | |
199 | - // wrap around the head index; | |
200 | - if (head_ >= sizeof(buffer_)) | |
201 | - head_ = 0; | |
202 | - } // end for loop. | |
203 | -#endif | |
204 | -} | |
205 | 106 | |
206 | 107 | |
207 | 108 | /* |
@@ -210,46 +111,15 @@ void Debugger::AppendToBuffer() | ||
210 | 111 | */ |
211 | 112 | void Debugger::RePrint() |
212 | 113 | { |
213 | -#ifdef OLDIMPLEMENTATION | |
214 | - MURASAKI_ASSERT(isTaskContext()); | |
215 | - | |
216 | - taskENTER_CRITICAL(); | |
217 | - { | |
218 | - // Mark the all old data as "not sent" | |
219 | - // By setting the circular buffer length maximumn. | |
220 | - tail_ = head_ + 1; | |
221 | - // wrap around the tail_index; | |
222 | - if (tail_ >= sizeof(buffer_)) | |
223 | - tail_ = 0; | |
224 | - } | |
225 | - taskEXIT_CRITICAL(); | |
226 | - | |
227 | - // tell there is data | |
228 | - ::xSemaphoreGive(sem_notify_new_data_); | |
229 | -#else | |
230 | 114 | helpers_.fifo->ReWind(); |
231 | -#endif | |
232 | 115 | } |
233 | 116 | |
234 | 117 | void Debugger::AutoHistory() |
235 | 118 | { |
236 | 119 | MURASAKI_ASSERT(isTaskContext()); |
237 | 120 | // protecting from double task creation |
238 | - if (auto_history_enabled) | |
121 | + if (auto_reprint_enable_) | |
239 | 122 | return; |
240 | -#ifdef OLDIMPLEMENTATION | |
241 | - | |
242 | - // start the debug task | |
243 | - BaseType_t task_result = ::xTaskCreate(Debugger::LaunchAutoHistoryTask, // task entity; | |
244 | - "AutoHistoryTask", // name of task | |
245 | - PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth | |
246 | - this, // parameter to task | |
247 | - PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task | |
248 | - &auto_history_task_ // receive task handle | |
249 | - ); | |
250 | - MURASAKI_ASSERT(task_result != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY); | |
251 | - | |
252 | -#else | |
253 | 123 | auto_reprint_task = new murasaki::DebuggerAutoRePrintTask("DebugTask", // name of task |
254 | 124 | PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth |
255 | 125 | PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task |
@@ -259,94 +129,8 @@ void Debugger::AutoHistory() | ||
259 | 129 | |
260 | 130 | auto_reprint_task->Start(); |
261 | 131 | |
262 | -#endif | |
263 | - auto_history_enabled = true; | |
264 | -} | |
265 | - | |
266 | -void Debugger::LaunchAutoHistoryTask(void* this_pointer) | |
267 | -{ | |
268 | - MURASAKI_ASSERT(nullptr != this_pointer); | |
269 | - | |
270 | - // This is "interface class method" to allow to use a private method as task. | |
271 | - // The caller passes the "this" pointer as parameter. | |
272 | - // The caller is always "Debug" task. | |
273 | - // The AutoHistoryTask() is private and task body. | |
274 | - static_cast<Debugger *>(this_pointer)->AutoHistoryTask(); | |
275 | - | |
276 | -} | |
277 | - | |
278 | -void Debugger::AutoHistoryTask() | |
279 | -{ | |
280 | - MURASAKI_ASSERT(isTaskContext()); | |
281 | - // Task body. Never return. | |
282 | - while (true) { | |
283 | - // wait for the arraival of inpu | |
284 | - GetchFromTask(); | |
285 | - // flush old data. | |
286 | - RePrint(); | |
287 | - } // end of while loop. | |
288 | - | |
132 | + auto_reprint_enable_ = true; | |
289 | 133 | } |
290 | 134 | |
291 | 135 | |
292 | -void Debugger::LaunchTxTask(void * this_pointer) | |
293 | -{ | |
294 | - MURASAKI_ASSERT(nullptr != this_pointer); | |
295 | - // This is "interface class method" to allow to use a private method as task. | |
296 | - // The caller passes the "this" pointer as parameter. | |
297 | - // The caller is always "Debug" task. | |
298 | - // The txTask() is private and task body. | |
299 | - static_cast<Debugger *>(this_pointer)->TxTask(); | |
300 | -} | |
301 | - | |
302 | -#define BLOCK_SIZE 50 | |
303 | -void Debugger::TxTask() | |
304 | -{ | |
305 | -#ifdef OLDIMPLEMENTATION | |
306 | - unsigned int copy_size = 0; | |
307 | - uint8_t block[BLOCK_SIZE]; | |
308 | - | |
309 | - // Task body. Never return. | |
310 | - while (true) { | |
311 | - // To avoid race condition, Take a snapshot of the head_ and tail_ pointer. | |
312 | - // head_ could be modified during this task is running but no problem. | |
313 | - taskENTER_CRITICAL(); | |
314 | - { | |
315 | - // check whether the data area is wrapped araound at the end of buffer. Note : Data is added to the head. | |
316 | - if (head_ > tail_) { // not wrapped around | |
317 | - // transmit at largest one block | |
318 | - copy_size = std::min(sizeof(block), head_ - tail_); | |
319 | - ::memcpy(block, &buffer_[tail_], copy_size); | |
320 | - // update tail. Wrap around never occur. | |
321 | - tail_ += copy_size; | |
322 | - } | |
323 | - else if (tail_ > head_) { // wrapped arraound | |
324 | - // transmit at largest one block | |
325 | - copy_size = std::min(sizeof(block), sizeof(buffer_) - tail_); | |
326 | - ::memcpy(block, &buffer_[tail_], copy_size); | |
327 | - // update tail. | |
328 | - tail_ += copy_size; | |
329 | - | |
330 | - // if tail_ reaches the end, wrap around. | |
331 | - if (tail_ >= sizeof(buffer_)) | |
332 | - tail_ = 0; | |
333 | - } | |
334 | - else | |
335 | - // head_ == tail_ . Do nothing. | |
336 | - copy_size = 0; | |
337 | - } | |
338 | - taskEXIT_CRITICAL(); | |
339 | - | |
340 | - if (copy_size != 0) // if copied | |
341 | - logger_->putMessage((char *) block, copy_size); | |
342 | - else | |
343 | - // if head_ == tail_ | |
344 | - // Wait for the arrival of the new data because buffer empty. | |
345 | - // To avoid race condition, we use time out. | |
346 | - ::xSemaphoreTake(sem_notify_new_data_, 1000 / portTICK_PERIOD_MS ); | |
347 | - | |
348 | - } // end of while loop. | |
349 | -#endif | |
350 | -} | |
351 | - | |
352 | 136 | } /* namespace platform */ |
@@ -18,14 +18,9 @@ | ||
18 | 18 | #include "murasaki_config.hpp" |
19 | 19 | #include "abstractlogger.hpp" |
20 | 20 | |
21 | -//#define OLDIMPLEMENTATION | |
22 | - | |
23 | -#ifdef OLDIMPLEMENTATION | |
24 | -#else | |
25 | 21 | #include "debuggerfifo.hpp" |
26 | 22 | #include "debuggertxtask.hpp" |
27 | 23 | #include "debuggerautoreprinttask.hpp" |
28 | -#endif | |
29 | 24 | |
30 | 25 | namespace murasaki { |
31 | 26 |
@@ -118,114 +113,33 @@ class Debugger | ||
118 | 113 | */ |
119 | 114 | void AutoHistory(); |
120 | 115 | protected: |
121 | -#ifdef OLDIMPLEMENTATION | |
122 | - /** | |
123 | - * \brief A pointer to the logger class. | |
124 | - */ | |
125 | - AbstractLogger* logger_; | |
126 | - /** | |
127 | - * @brief For protecting from the double creating of the internal task. | |
128 | - */ | |
129 | - /** | |
130 | - * \brief Transmission notification semaphore. | |
131 | - * \details | |
132 | - * This semaphoere is initialized as binary semaphore, and applied as data avairable | |
133 | - * notification. Whenever the printf() method added new data to the buffer_, a nothification | |
134 | - * is given through this semaphore. | |
135 | - */ | |
136 | - /** | |
137 | - * \brief Handle to the transmission control task. | |
138 | - */ | |
139 | - TaskHandle_t tx_task_; | |
140 | - SemaphoreHandle_t sem_notify_new_data_; | |
141 | - /** | |
142 | - * \brief transmission data circular buffer. | |
143 | - */ | |
144 | - char buffer_[PLATFORM_CONFIG_DEBUG_BUFFER_SIZE]; | |
145 | -#else | |
146 | 116 | murasaki::LoggingHelpers helpers_; |
147 | 117 | /** |
148 | 118 | * \brief Handle to the transmission control task. |
149 | 119 | */ |
150 | 120 | murasaki::DebuggerTxTask * tx_task_; |
151 | 121 | |
152 | - murasaki::DebuggerAutoRePrintTask * auto_reprint_task; | |
153 | -#endif | |
154 | - bool auto_history_enabled; | |
155 | - /** | |
156 | - * \brief temporal data buffer to store the formatted string. | |
157 | - */ | |
158 | - char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE]; | |
159 | 122 | /** |
160 | 123 | * @brief Handle to the auto history task. |
161 | 124 | */ |
162 | - TaskHandle_t auto_history_task_; | |
163 | - /** | |
164 | - * \brief Index of the "next of " newest data in the buffer. | |
165 | - * \details | |
166 | - * Pointing the location which the next new data will be stored. | |
167 | - * | |
168 | - * In case of the empty buffer, this index is same with the tail_. | |
169 | - */ | |
170 | - volatile unsigned int head_; | |
171 | - /** | |
172 | - * \brief Index of the oldest data in the buffer. | |
173 | - * \details | |
174 | - * Pointing the location where the next data to be read. | |
175 | - * | |
176 | - * In case of the empty buffer, this index is same with the head_. | |
177 | - */ | |
178 | - volatile unsigned int tail_; | |
125 | + murasaki::DebuggerAutoRePrintTask * auto_reprint_task; | |
179 | 126 | |
180 | 127 | /** |
181 | - * \brief Wrapper of the txTask. | |
182 | - * \param this_pointer The this pointer of the caller object have to be passed. | |
183 | - * \details | |
184 | - * | |
185 | - * Wrapper of the txTask() method. The txTask() is the private method. Then, it is | |
186 | - * unable to pass to the FreeRTOS API, while we have to pass that to run a task. | |
187 | - * | |
188 | - * To solve this problem, this wrapper method is declared as class method. The | |
189 | - * this pointer have to be passed to the this_pointer parameter. | |
190 | - * | |
191 | - * This method is dedicated to use in the constructor. User doesn't need to touch | |
128 | + * @brief For protecting from double enabled. | |
192 | 129 | */ |
193 | - static void LaunchTxTask(void * this_pointer); | |
194 | - | |
195 | - /* | |
196 | - * | |
197 | - * Wrapper of the AutoHistoryTask | |
198 | - */ | |
199 | - static void LaunchAutoHistoryTask(void * this_pointer); | |
130 | + bool auto_reprint_enable_; | |
200 | 131 | |
201 | 132 | /** |
202 | - * \brief Task body | |
203 | - * \details | |
204 | - * The task bordy of the transmission task. This method is called from launchTxTas(), and | |
205 | - * never returns. | |
206 | - * | |
207 | - * This task test the head_ and tail_ and if the length is not one, try to transmit | |
208 | - * the data inside buffer, throuth the uart. | |
133 | + * @brief as receiver for the snprintf() | |
134 | + * @details | |
135 | + * This variable can be local variable of the printf() member function. | |
136 | + * In thiss case, the implementation of the printf() is much easier. | |
137 | + * In the other hand, each task must has enough depth on its task stack. | |
209 | 138 | * |
210 | - * If there is no data, this task wait for the new data to transmit by sem_notify_new_data_ | |
211 | - * semaphore. In parallel to this waiting, it polls the data buffer length by time out | |
212 | - * of semaphore. This polling is essential, because perfect exclusive access and synchronization | |
213 | - * is expensive. | |
214 | - */ | |
215 | - void TxTask(); | |
216 | - | |
217 | - /* | |
218 | - * Task to watch the receive character and trigger the history. | |
139 | + * Probably, having bigger task for each task doesn't pay, and it may cuase stack overflow bug | |
140 | + * at the debug or assertion. This is not preferable. | |
219 | 141 | */ |
220 | - void AutoHistoryTask(); | |
221 | - /** | |
222 | - * \brief Copy the data in line_ to the buffer_ | |
223 | - * \details | |
224 | - * This helper method copies the data from line_ into the buffer. And then, udpate the | |
225 | - * head_ index. In case the vacant area is not enough to copy entire data in line_, | |
226 | - * This method transfer as long as possible, and returns. | |
227 | - */ | |
228 | - void AppendToBuffer(); | |
142 | + char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE]; | |
229 | 143 | |
230 | 144 | }; |
231 | 145 |