Skip to content

Commit efa5688

Browse files
committed
porting/linux: Fix some coding style issues
This code didn't follow coding style guidelines.
1 parent d5e471c commit efa5688

File tree

6 files changed

+91
-78
lines changed

6 files changed

+91
-78
lines changed

porting/npl/linux/include/nimble/nimble_npl_os.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
extern "C" {
3232
#endif
3333

34-
#define BLE_NPL_OS_ALIGNMENT (__WORDSIZE / 8)
34+
#define BLE_NPL_OS_ALIGNMENT (__WORDSIZE / 8)
3535

36-
#define BLE_NPL_TIME_FOREVER UINT32_MAX
36+
#define BLE_NPL_TIME_FOREVER UINT32_MAX
3737

38-
struct ble_npl_eventq * ble_npl_eventq_dflt_get(void);
38+
struct ble_npl_eventq *ble_npl_eventq_dflt_get(void);
3939
void ble_npl_eventq_run(struct ble_npl_eventq *evq);
4040

4141
#ifdef __cplusplus
4242
}
4343
#endif
4444

45-
#endif /* _NPL_H_ */
45+
#endif /* _NPL_H_ */

porting/npl/linux/include/nimble/nimble_npl_os_log.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
#include <stdio.h>
2525

2626
/* Example on how to use macro to generate module logging functions */
27-
#define BLE_NPL_LOG_IMPL(lvl) \
28-
static inline void _BLE_NPL_LOG_CAT(BLE_NPL_LOG_MODULE, \
29-
_BLE_NPL_LOG_CAT(_, lvl))(const char *fmt, ...)\
30-
{ \
31-
va_list args; \
32-
va_start(args, fmt); \
33-
vprintf(fmt, args); \
34-
va_end(args); \
35-
}
27+
#define BLE_NPL_LOG_IMPL(lvl) \
28+
static inline void _BLE_NPL_LOG_CAT( \
29+
BLE_NPL_LOG_MODULE, _BLE_NPL_LOG_CAT(_, lvl))(const char *fmt, ...) \
30+
{ \
31+
va_list args; \
32+
va_start(args, fmt); \
33+
vprintf(fmt, args); \
34+
va_end(args); \
35+
}
3636

37-
#endif /* _NIMBLE_NPL_OS_LOG_H_ */
37+
#endif /* _NIMBLE_NPL_OS_LOG_H_ */

porting/npl/linux/include/nimble/os_types.h

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,55 +32,54 @@
3232
typedef uint32_t ble_npl_time_t;
3333
typedef int32_t ble_npl_stime_t;
3434

35-
//typedef int os_sr_t;
3635
typedef int ble_npl_stack_t;
3736

38-
3937
struct ble_npl_event {
40-
uint8_t ev_queued;
41-
ble_npl_event_fn *ev_cb;
42-
void *ev_arg;
38+
uint8_t ev_queued;
39+
ble_npl_event_fn *ev_cb;
40+
void *ev_arg;
4341
};
4442

4543
struct ble_npl_eventq {
46-
void *q;
44+
void *q;
4745
};
4846

4947
struct ble_npl_callout {
50-
struct ble_npl_event c_ev;
51-
struct ble_npl_eventq *c_evq;
52-
uint32_t c_ticks;
53-
timer_t c_timer;
54-
bool c_active;
48+
struct ble_npl_event c_ev;
49+
struct ble_npl_eventq *c_evq;
50+
uint32_t c_ticks;
51+
timer_t c_timer;
52+
bool c_active;
5553
};
5654

5755
struct ble_npl_mutex {
58-
pthread_mutex_t lock;
59-
pthread_mutexattr_t attr;
60-
struct timespec wait;
56+
pthread_mutex_t lock;
57+
pthread_mutexattr_t attr;
58+
struct timespec wait;
6159
};
6260

6361
struct ble_npl_sem {
64-
sem_t lock;
62+
sem_t lock;
6563
};
6664

6765
struct ble_npl_task {
68-
pthread_t handle;
69-
pthread_attr_t attr;
70-
struct sched_param param;
71-
const char* name;
66+
pthread_t handle;
67+
pthread_attr_t attr;
68+
struct sched_param param;
69+
const char *name;
7270
};
7371

7472
typedef void *(*ble_npl_task_func_t)(void *);
7573

76-
int ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func,
77-
void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
78-
ble_npl_stack_t *stack_bottom, uint16_t stack_size);
74+
int ble_npl_task_init(struct ble_npl_task *t, const char *name,
75+
ble_npl_task_func_t func, void *arg, uint8_t prio,
76+
ble_npl_time_t sanity_itvl,
77+
ble_npl_stack_t *stack_bottom, uint16_t stack_size);
7978

8079
int ble_npl_task_remove(struct ble_npl_task *t);
8180

8281
uint8_t ble_npl_task_count(void);
8382

8483
void ble_npl_task_yield(void);
8584

86-
#endif // _NPL_OS_TYPES_H
85+
#endif /* _NPL_OS_TYPES_H */

porting/npl/linux/src/os_callout.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ static void
3131
ble_npl_callout_timer_cb(union sigval sv)
3232
{
3333
struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
34+
3435
assert(c);
36+
3537
c->c_active = false;
3638
if (c->c_evq) {
3739
ble_npl_eventq_put(c->c_evq, &c->c_ev);
@@ -40,12 +42,11 @@ ble_npl_callout_timer_cb(union sigval sv)
4042
}
4143
}
4244

43-
void ble_npl_callout_init(struct ble_npl_callout *c,
44-
struct ble_npl_eventq *evq,
45-
ble_npl_event_fn *ev_cb,
46-
void *ev_arg)
45+
void
46+
ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq,
47+
ble_npl_event_fn *ev_cb, void *ev_arg)
4748
{
48-
struct sigevent event;
49+
struct sigevent event;
4950

5051
/* Initialize the callout. */
5152
memset(c, 0, sizeof(*c));
@@ -55,29 +56,32 @@ void ble_npl_callout_init(struct ble_npl_callout *c,
5556
c->c_active = false;
5657

5758
event.sigev_notify = SIGEV_THREAD;
58-
event.sigev_value.sival_ptr = c; // put callout obj in signal args
59+
event.sigev_value.sival_ptr = c; // put callout obj in signal args
5960
event.sigev_notify_function = ble_npl_callout_timer_cb;
6061
event.sigev_notify_attributes = NULL;
6162

6263
timer_create(CLOCK_REALTIME, &event, &c->c_timer);
6364
}
6465

65-
bool ble_npl_callout_is_active(struct ble_npl_callout *c)
66+
bool
67+
ble_npl_callout_is_active(struct ble_npl_callout *c)
6668
{
67-
// TODO: seek native posix method to determine whether timer_t is active.
68-
// TODO: fix bug where one-shot timer is still active after fired.
69+
/* TODO: seek native posix method to determine whether timer_t is active.
70+
* TODO: fix bug where one-shot timer is still active after fired.
71+
*/
6972
return c->c_active;
7073
}
7174

72-
int ble_npl_callout_inited(struct ble_npl_callout *c)
75+
int
76+
ble_npl_callout_inited(struct ble_npl_callout *c)
7377
{
7478
return (c->c_timer != NULL);
7579
}
7680

77-
ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
78-
ble_npl_time_t ticks)
81+
ble_npl_error_t
82+
ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks)
7983
{
80-
struct itimerspec its;
84+
struct itimerspec its;
8185

8286
if (ticks < 0) {
8387
return BLE_NPL_EINVAL;
@@ -90,7 +94,7 @@ ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
9094
c->c_ticks = ble_npl_time_get() + ticks;
9195

9296
its.it_interval.tv_sec = 0;
93-
its.it_interval.tv_nsec = 0; // one shot
97+
its.it_interval.tv_nsec = 0; // one shot
9498
its.it_value.tv_sec = (ticks / 1000);
9599
its.it_value.tv_nsec = (ticks % 1000) * 1000000; // expiration
96100
its.it_value.tv_nsec %= 1000000000;
@@ -100,16 +104,17 @@ ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
100104
return BLE_NPL_OK;
101105
}
102106

103-
int ble_npl_callout_queued(struct ble_npl_callout *c)
107+
int
108+
ble_npl_callout_queued(struct ble_npl_callout *c)
104109
{
105110
struct itimerspec its;
106111
timer_gettime(c->c_timer, &its);
107112

108-
return ((its.it_value.tv_sec > 0) ||
109-
(its.it_value.tv_nsec > 0));
113+
return ((its.it_value.tv_sec > 0) || (its.it_value.tv_nsec > 0));
110114
}
111115

112-
void ble_npl_callout_stop(struct ble_npl_callout *c)
116+
void
117+
ble_npl_callout_stop(struct ble_npl_callout *c)
113118
{
114119
if (!ble_npl_callout_inited(c)) {
115120
return;
@@ -137,13 +142,12 @@ ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
137142
}
138143

139144
uint32_t
140-
ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
141-
ble_npl_time_t now)
145+
ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, ble_npl_time_t now)
142146
{
143147
ble_npl_time_t rt;
144148
uint32_t exp;
145-
146149
struct itimerspec its;
150+
147151
timer_gettime(co->c_timer, &its);
148152

149153
exp = its.it_value.tv_sec * 1000;

porting/npl/linux/src/os_task.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,44 @@ extern "C" {
3434
* and sets the task as ready to run, and inserts it into the operating
3535
* system scheduler.
3636
*
37-
* @param t The task to initialize
38-
* @param name The name of the task to initialize
39-
* @param func The task function to call
40-
* @param arg The argument to pass to this task function
41-
* @param prio The priority at which to run this task
42-
* @param sanity_itvl The time at which this task should check in with the
43-
* sanity task. OS_WAIT_FOREVER means never check in
44-
* here.
45-
* @param stack_bottom A pointer to the bottom of a task's stack
46-
* @param stack_size The overall size of the task's stack.
37+
* @param t The task to initialize
38+
* @param name The name of the task to initialize
39+
* @param func The task function to call
40+
* @param arg The argument to pass to this task function
41+
* @param prio The priority at which to run this task
42+
* @param sanity_itvl The time at which this task should check in with the
43+
* sanity task. OS_WAIT_FOREVER means never check in here.
44+
* @param stack_bottom A pointer to the bottom of a task's stack
45+
* @param stack_size The overall size of the task's stack.
4746
*
4847
* @return 0 on success, non-zero on failure.
4948
*/
5049
int
5150
ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func,
52-
void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
53-
ble_npl_stack_t *stack_bottom, uint16_t stack_size)
51+
void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
52+
ble_npl_stack_t *stack_bottom, uint16_t stack_size)
5453
{
5554
int err;
5655
if ((t == NULL) || (func == NULL)) {
5756
return OS_INVALID_PARM;
5857
}
5958

6059
err = pthread_attr_init(&t->attr);
61-
if (err) return err;
62-
err = pthread_attr_getschedparam (&t->attr, &t->param);
63-
if (err) return err;
60+
if (err)
61+
return err;
62+
63+
err = pthread_attr_getschedparam(&t->attr, &t->param);
64+
if (err)
65+
return err;
66+
6467
err = pthread_attr_setschedpolicy(&t->attr, SCHED_RR);
65-
if (err) return err;
68+
if (err)
69+
return err;
70+
6671
t->param.sched_priority = prio;
67-
err = pthread_attr_setschedparam (&t->attr, &t->param);
68-
if (err) return err;
72+
err = pthread_attr_setschedparam(&t->attr, &t->param);
73+
if (err)
74+
return err;
6975

7076
t->name = name;
7177
err = pthread_create(&t->handle, &t->attr, func, arg);
@@ -101,12 +107,14 @@ ble_npl_get_current_task_id(void)
101107
return (void *)pthread_self();
102108
}
103109

104-
bool ble_npl_os_started(void)
110+
bool
111+
ble_npl_os_started(void)
105112
{
106113
return true;
107114
}
108115

109-
void ble_npl_task_yield(void)
116+
void
117+
ble_npl_task_yield(void)
110118
{
111119
sched_yield();
112120
}

porting/npl/linux/src/os_time.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ ble_npl_time_t
3333
ble_npl_time_get(void)
3434
{
3535
struct timespec now;
36+
3637
if (clock_gettime(CLOCK_MONOTONIC, &now)) {
3738
return 0;
3839
}
40+
3941
return now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0;
4042
}
4143

0 commit comments

Comments
 (0)