Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 42b5203a9 -> 17252a2de
documentation and whitespace fixes. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/17252a2d Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/17252a2d Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/17252a2d Branch: refs/heads/develop Commit: 17252a2deccdebeee2b679e24fed861b8598916c Parents: 42b5203 Author: Sterling Hughes <[email protected]> Authored: Sun May 22 10:17:41 2016 -0700 Committer: Sterling Hughes <[email protected]> Committed: Sun May 22 10:17:52 2016 -0700 ---------------------------------------------------------------------- libs/os/src/os_task.c | 95 ++++++++++++++++++++++++++++++++++++---------- libs/os/src/os_time.c | 38 ++++++++++++++++++- 2 files changed, 111 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17252a2d/libs/os/src/os_task.c ---------------------------------------------------------------------- diff --git a/libs/os/src/os_task.c b/libs/os/src/os_task.c index 89ea988..55c1da2 100644 --- a/libs/os/src/os_task.c +++ b/libs/os/src/os_task.c @@ -6,7 +6,7 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, @@ -27,16 +27,16 @@ uint8_t g_task_id; STAILQ_HEAD(, os_task) g_os_task_list = STAILQ_HEAD_INITIALIZER(g_os_task_list); static void -_clear_stack(os_stack_t *stack_bottom, int size) +_clear_stack(os_stack_t *stack_bottom, int size) { - int i; + int i; for (i = 0; i < size; i++) { stack_bottom[i] = OS_STACK_PATTERN; } } -static inline uint8_t +static inline uint8_t os_task_next_id(void) { uint8_t rc; @@ -50,42 +50,67 @@ os_task_next_id(void) return (rc); } -uint8_t +/** + * Return the number of tasks initialized. + * + * @return number of tasks initialized + */ +uint8_t os_task_count(void) { return (g_task_id); } - -int -os_task_init(struct os_task *t, char *name, os_task_func_t func, void *arg, - uint8_t prio, os_time_t sanity_itvl, os_stack_t *stack_bottom, +/** + * Initialize a task. + * + * This function initializes the task structure pointed to by t, + * clearing and setting it's stack pointer, provides sane defaults + * and sets the task as ready to run, and inserts it into the operating + * system scheduler. + * + * @param t The task to initialize + * @param name The name of the task to initialize + * @param func The task function to call + * @param arg The argument to pass to this task function + * @param prio The priority at which to run this task + * @param sanity_itvl The time at which this task should check in with the + * sanity task. OS_WAIT_FOREVER means never check in + * here. + * @param stack_bottom A pointer to the bottom of a task's stack + * @param stack_size The overall size of the task's stack. + * + * @return 0 on success, non-zero on failure. + */ +int +os_task_init(struct os_task *t, char *name, os_task_func_t func, void *arg, + uint8_t prio, os_time_t sanity_itvl, os_stack_t *stack_bottom, uint16_t stack_size) { - struct os_sanity_check *sc; - int rc; + struct os_sanity_check *sc; + int rc; memset(t, 0, sizeof(*t)); t->t_func = func; t->t_arg = arg; - - t->t_taskid = os_task_next_id(); + + t->t_taskid = os_task_next_id(); t->t_prio = prio; t->t_state = OS_TASK_READY; t->t_name = name; - t->t_next_wakeup = 0; + t->t_next_wakeup = 0; - rc = os_sanity_check_init(&t->t_sanity_check); + rc = os_sanity_check_init(&t->t_sanity_check); if (rc != OS_OK) { goto err; } if (sanity_itvl != OS_WAIT_FOREVER) { - sc = (struct os_sanity_check *) &t->t_sanity_check; + sc = (struct os_sanity_check *) &t->t_sanity_check; sc->sc_checkin_itvl = sanity_itvl; - + rc = os_sanity_check_register(sc); if (rc != OS_OK) { goto err; @@ -93,7 +118,7 @@ os_task_init(struct os_task *t, char *name, os_task_func_t func, void *arg, } _clear_stack(stack_bottom, stack_size); - t->t_stackptr = os_arch_task_stack_init(t, &stack_bottom[stack_size], + t->t_stackptr = os_arch_task_stack_init(t, &stack_bottom[stack_size], stack_size); t->t_stacktop = &stack_bottom[stack_size]; t->t_stacksize = stack_size; @@ -113,6 +138,36 @@ err: return (rc); } +/** + * Iterate through tasks, and return the following information about them: + * + * - Priority + * - Task ID + * - State (ACTIVE, SLEEP) + * - Total Stack Usage + * - Stack Size + * - Context Switch Count + * - Runtime + * - Last & Next Sanity checkin + * - Task Name + * + * To get the first task in the list, call os_task_info_get_next() with a + * NULL pointer in the prev argument, and os_task_info_get_next() will + * return a pointer to the task structure, and fill out the os_task_info + * structure pointed to by oti. + * + * To get the next task in the list, provide the task structure returned + * by the previous call to os_task_info_get_next(), and os_task_info_get_next() + * will fill out the task structure pointed to by oti again, and return + * the next task in the list. + * + * @param prev The previous task returned by os_task_info_get_next(), or NULL + * to begin iteration. + * @param oti The OS task info structure to fill out. + * + * @return A pointer to the OS task that has been read, or NULL when finished + * iterating through all tasks. + */ struct os_task * os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti) { @@ -130,7 +185,7 @@ os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti) return (NULL); } - /* Otherwise, copy OS task information into the OTI structure, and + /* Otherwise, copy OS task information into the OTI structure, and * return 1, which means continue */ oti->oti_prio = next->t_prio; @@ -151,7 +206,7 @@ os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti) oti->oti_cswcnt = next->t_ctx_sw_cnt; oti->oti_runtime = next->t_run_time; oti->oti_last_checkin = next->t_sanity_check.sc_checkin_last; - oti->oti_next_checkin = next->t_sanity_check.sc_checkin_last + + oti->oti_next_checkin = next->t_sanity_check.sc_checkin_last + next->t_sanity_check.sc_checkin_itvl; strncpy(oti->oti_name, next->t_name, sizeof(oti->oti_name)); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/17252a2d/libs/os/src/os_time.c ---------------------------------------------------------------------- diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c index a92e9a9..e401ff4 100644 --- a/libs/os/src/os_time.c +++ b/libs/os/src/os_time.c @@ -6,7 +6,7 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, @@ -50,6 +50,11 @@ os_deltatime(os_time_t delta, const struct os_timeval *base, os_timeradd(base, &tvdelta, result); } +/** + * Get the current OS time in ticks + * + * @return OS time in ticks + */ os_time_t os_time_get(void) { @@ -81,6 +86,11 @@ os_time_tick(int ticks) OS_EXIT_CRITICAL(sr); } +/** + * Move OS time forward ticks. + * + * @param ticks The number of ticks to move time forward. + */ void os_time_advance(int ticks) { @@ -113,6 +123,15 @@ os_time_delay(int32_t osticks) } } +/** + * Set the time of day. This does not modify os time, but rather just modifies + * the offset by which we are tracking real time against os time. + * + * @param utctime A timeval representing the UTC time we are setting + * @param tz The time-zone to apply against the utctime being set. + * + * @return 0 on success, non-zero on failure. + */ int os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz) { @@ -138,6 +157,16 @@ os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz) return (0); } +/** + * Get the current time of day. Returns the time of day in UTC + * into the tv argument, and returns the timezone (if set) into + * tz. + * + * @param tv The structure to put the UTC time of day into + * @param tz The structure to put the timezone information into + * + * @return 0 on success, non-zero on failure + */ int os_gettimeofday(struct os_timeval *tv, struct os_timezone *tz) { @@ -158,8 +187,13 @@ os_gettimeofday(struct os_timeval *tv, struct os_timezone *tz) return (0); } +/** + * Get time since boot in microseconds. + * + * @return time since boot in microseconds + */ int64_t -os_get_uptime_usec(void) +os_get_uptime_usec(void) { struct os_timeval tv; os_time_t delta;
