aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2021-10-26 01:55:33 -0600
committerJosh Rahm <joshuarahm@gmail.com>2021-10-26 01:55:33 -0600
commit2c94d5baaec9e65550df942cf976db48bd36d9b5 (patch)
tree6eb68deb9ab93d53539ef3cab283991140ddf0e6
parent969c054e5b1aee7fb034667f09240216ea0c6abf (diff)
downloadstm32l4-2c94d5baaec9e65550df942cf976db48bd36d9b5.tar.gz
stm32l4-2c94d5baaec9e65550df942cf976db48bd36d9b5.tar.bz2
stm32l4-2c94d5baaec9e65550df942cf976db48bd36d9b5.zip
run clang-format.
-rw-r--r--src/drv/ir/ir.c30
-rw-r--r--src/kern/init.c15
-rw-r--r--src/kern/log.c2
-rw-r--r--src/kern/main.c2
-rw-r--r--src/kern/mem.c2
-rw-r--r--src/kern/mpu/mpu_manager.c3
-rw-r--r--src/kern/panic.c17
-rw-r--r--src/kern/priv.c4
-rw-r--r--src/kern/svc.c4
-rw-r--r--src/kern/syscalls/logs.c2
-rw-r--r--src/user/init.c7
-rw-r--r--src/user/syscall.c13
-rw-r--r--test_harness/fake_env.c28
-rw-r--r--test_harness/test_harness.c2
-rw-r--r--tests/test_array_list.c6
-rw-r--r--tests/test_avl_tree.c6
-rw-r--r--tests/test_linked_list.c5
-rw-r--r--tests/test_map.c9
-rw-r--r--tests/test_memory.c12
-rw-r--r--tests/test_mpu.c7
20 files changed, 82 insertions, 94 deletions
diff --git a/src/drv/ir/ir.c b/src/drv/ir/ir.c
index c84417d..9b7cd20 100644
--- a/src/drv/ir/ir.c
+++ b/src/drv/ir/ir.c
@@ -6,8 +6,8 @@
#include "arch/stm32l4xxx/peripherals/syscfg.h"
#include "arch/stm32l4xxx/peripherals/tim.h"
#include "kern/gpio/gpio_manager.h"
-#include "kern/mem.h"
#include "kern/log.h"
+#include "kern/mem.h"
#include "kern/panic.h"
#include "shared/linked_list.h"
@@ -27,7 +27,7 @@ void on_exti9_5()
if (read_into.n == 0) {
/* Starting fresh, start the timer. */
regset(TIM2.c_r1, tim_cen, 1);
- read_into.ts[read_into.n ++] = 0;
+ read_into.ts[read_into.n++] = 0;
} else {
uint32_t ts = TIM2.cnt;
if (read_into.n < 64) {
@@ -36,21 +36,18 @@ void on_exti9_5()
}
}
-typedef enum {
- PARITY_LOW = 0,
- PARITY_HIGH = 1
-} ir_parity_t;
+typedef enum { PARITY_LOW = 0, PARITY_HIGH = 1 } ir_parity_t;
static ir_parity_t ir_discover_parity(const ir_code_t* code)
{
uint32_t max_even = 0;
- uint32_t min_even = (uint32_t) -1;
+ uint32_t min_even = (uint32_t)-1;
uint32_t max_odd = 0;
- uint32_t min_odd = (uint32_t) -1;
+ uint32_t min_odd = (uint32_t)-1;
- for (int i = 3; i < code->n; ++ i) {
- uint32_t n = code->ts[i] - code->ts[i-1];
+ for (int i = 3; i < code->n; ++i) {
+ uint32_t n = code->ts[i] - code->ts[i - 1];
if (i % 2 == 0) {
if (n < min_even) {
min_even = n;
@@ -73,20 +70,19 @@ static ir_parity_t ir_discover_parity(const ir_code_t* code)
}
}
-int ir_generic_decode(
- const ir_code_t* code, uint32_t* out_)
+int ir_generic_decode(const ir_code_t* code, uint32_t* out_)
{
if (code->n < 5) {
return 0;
}
- uint32_t min = (uint32_t) -1;
+ uint32_t min = (uint32_t)-1;
uint32_t max = 0;
uint32_t start = 4 + ir_discover_parity(code);
for (int i = start; i < code->n; i += 2) {
- uint32_t n = code->ts[i] - code->ts[i-1];
+ uint32_t n = code->ts[i] - code->ts[i - 1];
if (n > max) {
max = n;
@@ -101,7 +97,7 @@ int ir_generic_decode(
uint32_t mask = 0x80000000;
for (int i = start; i < code->n; i += 2) {
- if ((code->ts[i] - code->ts[i-1]) >= mid) {
+ if ((code->ts[i] - code->ts[i - 1]) >= mid) {
out |= mask;
}
mask >>= 1;
@@ -143,8 +139,8 @@ void ir_begin_listen()
enable_interrupt(IRQ_EXTI9_5);
/* Configure the timer. */
- TIM2.psc = 80; /* Counts every microsecond. */
- TIM2.ar_r = 50000; /* Stop after 50ms. */
+ TIM2.psc = 80; /* Counts every microsecond. */
+ TIM2.ar_r = 50000; /* Stop after 50ms. */
regset(TIM2.die_r, tim_uie, 1); /* Enable interrupts. */
regset(TIM2.c_r1, tim_opm, 1); /* Set one-pulse-mode. */
diff --git a/src/kern/init.c b/src/kern/init.c
index 247c44f..5120745 100644
--- a/src/kern/init.c
+++ b/src/kern/init.c
@@ -38,12 +38,12 @@ extern uint32_t INIT_7_END;
init2()
{
- volatile uint32_t bss_start_ptr = (uint32_t) &BSS_START;
- volatile uint32_t bss_end_ptr = (uint32_t) &BSS_END;
- volatile uint32_t init_data_values_ptr = (uint32_t) &INIT_DATA_VALUES;
- volatile uint32_t data_segment_start_ptr = (uint32_t) &DATA_SEGMENT_START;
- volatile uint32_t data_segment_stop_ptr = (uint32_t) &DATA_SEGMENT_STOP;
-
+ volatile uint32_t bss_start_ptr = (uint32_t)&BSS_START;
+ volatile uint32_t bss_end_ptr = (uint32_t)&BSS_END;
+ volatile uint32_t init_data_values_ptr = (uint32_t)&INIT_DATA_VALUES;
+ volatile uint32_t data_segment_start_ptr = (uint32_t)&DATA_SEGMENT_START;
+ volatile uint32_t data_segment_stop_ptr = (uint32_t)&DATA_SEGMENT_STOP;
+
klogf("Copy data segments from flash ... \n");
klogf(" .data ...\n");
@@ -109,7 +109,8 @@ void run_init_routines()
void (**initfn)();
- klogf("Init routines at (%p - %p)\n",
+ klogf(
+ "Init routines at (%p - %p)\n",
&INIT_ROUTINES_FLASH_START,
&INIT_ROUTINES_FLASH_STOP);
diff --git a/src/kern/log.c b/src/kern/log.c
index e6bbec6..3eb61a1 100644
--- a/src/kern/log.c
+++ b/src/kern/log.c
@@ -3,9 +3,9 @@
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "arch/stm32l4xxx/peripherals/usart.h"
#include "kern/common.h"
+#include "kern/delay.h"
#include "kern/gpio/gpio_manager.h"
#include "kern/init.h"
-#include "kern/delay.h"
void setup_usart2(uint32_t baud_rate);
diff --git a/src/kern/main.c b/src/kern/main.c
index cdaa2b1..957e43f 100644
--- a/src/kern/main.c
+++ b/src/kern/main.c
@@ -198,7 +198,7 @@ static void set_red()
static void reset_state()
{
ws2812b_t* tmp = state.drv;
- memset((void*) &state, 0, sizeof(state));
+ memset((void*)&state, 0, sizeof(state));
state.drv = tmp;
state.brightness = 255;
state.n_leds = 250;
diff --git a/src/kern/mem.c b/src/kern/mem.c
index d7f7dc3..8960883 100644
--- a/src/kern/mem.c
+++ b/src/kern/mem.c
@@ -224,7 +224,7 @@ void debug_print_blocks()
cur->prev,
kalloc_node_get_canary(cur));
total_words += cur->size_words;
- total_blocks ++;
+ total_blocks++;
cur = kalloc_node_next(cur);
}
diff --git a/src/kern/mpu/mpu_manager.c b/src/kern/mpu/mpu_manager.c
index 0d03c39..1cff2a2 100644
--- a/src/kern/mpu/mpu_manager.c
+++ b/src/kern/mpu/mpu_manager.c
@@ -63,8 +63,7 @@ static int find_unused_region_slot()
// memory_region_opts_t memory_regions[8];
int i;
- for (i = 0; i < sizeof(memory_regions) / sizeof(memory_region_opts_t);
- ++i) {
+ for (i = 0; i < sizeof(memory_regions) / sizeof(memory_region_opts_t); ++i) {
if (!memory_regions[i].enable) {
return i;
}
diff --git a/src/kern/panic.c b/src/kern/panic.c
index e005bcc..75ce52a 100644
--- a/src/kern/panic.c
+++ b/src/kern/panic.c
@@ -1,14 +1,15 @@
-#include "arch.h"
#include "kern/panic.h"
-#include "kern/log.h"
-#include "kern/init.h"
-#include "arch/stm32l4xxx/peripherals/clock.h"
-#include "kern/gpio/sysled.h"
-#include "kern/gpio/gpio_manager.h"
-#include "kern/delay.h"
#include <stdarg.h>
+#include "arch.h"
+#include "arch/stm32l4xxx/peripherals/clock.h"
+#include "kern/delay.h"
+#include "kern/gpio/gpio_manager.h"
+#include "kern/gpio/sysled.h"
+#include "kern/init.h"
+#include "kern/log.h"
+
#ifdef ARCH_STM32L4
_Noreturn void panic(const char* fmt, ...)
{
@@ -23,7 +24,7 @@ _Noreturn void panic(const char* fmt, ...)
kerr_logf("** Stack:\n");
int i = 0;
- for (; i < 20 && &base[i] != (void*)STACK_TOP; ++ i) {
+ for (; i < 20 && &base[i] != (void*)STACK_TOP; ++i) {
kerr_logf(" (%p) %p\n", &base[i], base[i]);
}
diff --git a/src/kern/priv.c b/src/kern/priv.c
index ba25c26..6698350 100644
--- a/src/kern/priv.c
+++ b/src/kern/priv.c
@@ -37,6 +37,8 @@ void jump_to_user_mode()
"msr control, r0\n\t"
"isb\n\t"
"dsb\n\t"
- "b usermode_start\n\t" : : "r"(new_stack));
+ "b usermode_start\n\t"
+ :
+ : "r"(new_stack));
}
#endif
diff --git a/src/kern/svc.c b/src/kern/svc.c
index ceca5fa..16bfd3a 100644
--- a/src/kern/svc.c
+++ b/src/kern/svc.c
@@ -10,8 +10,8 @@ void handle_svc_call(
case 0x04:
switch (syscall_id) {
#define SYSCALL(id, fn, kernfn, argt) \
- case id: \
- kernfn((argt)syscall_arg); \
+ case id: \
+ kernfn((argt)syscall_arg); \
break;
#include "kern/syscall/syscall_tbl.inc"
#undef SYSCALL
diff --git a/src/kern/syscalls/logs.c b/src/kern/syscalls/logs.c
index 855672c..61a65da 100644
--- a/src/kern/syscalls/logs.c
+++ b/src/kern/syscalls/logs.c
@@ -1,5 +1,5 @@
-#include "kern/syscall.h"
#include "kern/log.h"
+#include "kern/syscall.h"
void kern_logs(const char* str)
{
diff --git a/src/user/init.c b/src/user/init.c
index bb60454..1130916 100644
--- a/src/user/init.c
+++ b/src/user/init.c
@@ -1,6 +1,6 @@
-#include "user/syscall.h"
-#include "kern/log.h"
#include "kern/common.h"
+#include "kern/log.h"
+#include "user/syscall.h"
void usermode_start()
{
@@ -8,5 +8,6 @@ void usermode_start()
logs("I'm still in usermode!\n");
logs("I'm super still in usermode!\n");
- for(;;);
+ for (;;)
+ ;
}
diff --git a/src/user/syscall.c b/src/user/syscall.c
index 601c7a3..9ed75da 100644
--- a/src/user/syscall.c
+++ b/src/user/syscall.c
@@ -1,11 +1,11 @@
-#include "arch.h"
#include "user/syscall.h"
#include <stdint.h>
-void __attribute__ ((noinline)) do_syscall(
- volatile uint32_t id,
- volatile uint32_t arg)
+#include "arch.h"
+
+void __attribute__((noinline))
+do_syscall(volatile uint32_t id, volatile uint32_t arg)
{
#ifdef ARCH_STM32L4
asm volatile("svc #0x04");
@@ -13,8 +13,5 @@ void __attribute__ ((noinline)) do_syscall(
}
#define SYSCALL(id, fn, kernfn, argt) \
- void fn(argt arg) \
-{ \
- do_syscall(id, (uint32_t) arg); \
-}
+ void fn(argt arg) { do_syscall(id, (uint32_t)arg); }
#include "kern/syscall/syscall_tbl.inc"
diff --git a/test_harness/fake_env.c b/test_harness/fake_env.c
index bae6298..02c9b2d 100644
--- a/test_harness/fake_env.c
+++ b/test_harness/fake_env.c
@@ -1,27 +1,27 @@
#include "fake_env.h"
#include <assert.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
struct fakeenv_memseg {
const char* name;
void* segment;
};
-#define DEFINE_MEMORY_SEGMENT(seg, start_addr, end_addr) \
- static __attribute( \
- (__section__("fakeenv"))) struct fakeenv_memseg fake_##seg = { \
- .name = #seg, \
- .segment = NULL, \
- }; \
- void* load_fake_##seg##__() \
- { \
- if (fake_##seg.segment == NULL) { \
- fake_##seg.segment = malloc((end_addr) - (start_addr)); \
- assert(fake_##seg.segment != NULL); \
- } \
- return fake_##seg.segment; \
+#define DEFINE_MEMORY_SEGMENT(seg, start_addr, end_addr) \
+ static __attribute(( \
+ __section__("fakeenv"))) struct fakeenv_memseg fake_##seg = { \
+ .name = #seg, \
+ .segment = NULL, \
+ }; \
+ void* load_fake_##seg##__() \
+ { \
+ if (fake_##seg.segment == NULL) { \
+ fake_##seg.segment = malloc((end_addr) - (start_addr)); \
+ assert(fake_##seg.segment != NULL); \
+ } \
+ return fake_##seg.segment; \
}
extern struct fakeenv_memseg __start_fakeenv;
diff --git a/test_harness/test_harness.c b/test_harness/test_harness.c
index 2bd6194..fcbc55e 100644
--- a/test_harness/test_harness.c
+++ b/test_harness/test_harness.c
@@ -2,12 +2,12 @@
#include <assert.h>
#include <setjmp.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <stdarg.h>
#include "fake_env.h"
diff --git a/tests/test_array_list.c b/tests/test_array_list.c
index 71ffa55..86ef27d 100644
--- a/tests/test_array_list.c
+++ b/tests/test_array_list.c
@@ -51,9 +51,10 @@ TEST(array_list, foreach)
int i = 0;
int values[3];
- array_list_foreach(arl, val) {
+ array_list_foreach(arl, val)
+ {
values[i] = val;
- ++ i;
+ ++i;
}
ASSERT_EQ(values[0], 3);
@@ -61,5 +62,4 @@ TEST(array_list, foreach)
ASSERT_EQ(values[2], 1);
return 0;
-
}
diff --git a/tests/test_avl_tree.c b/tests/test_avl_tree.c
index 2a7260f..dd14917 100644
--- a/tests/test_avl_tree.c
+++ b/tests/test_avl_tree.c
@@ -125,7 +125,7 @@ TEST(avl_tree, find)
{
avl_tree_t(int)* tree = avl_tree_new(int)();
- for (int i = 0; i < 16; ++ i) {
+ for (int i = 0; i < 16; ++i) {
avl_tree_insert(int)(tree, i);
}
@@ -138,10 +138,10 @@ TEST(avl_tree, find)
return 0;
}
-TEST (avl_tree, stress)
+TEST(avl_tree, stress)
{
avl_tree_t(int)* tree = avl_tree_new(int)();
- for (int i = 0; i < 512; ++ i) {
+ for (int i = 0; i < 512; ++i) {
avl_tree_insert(int)(tree, i);
}
diff --git a/tests/test_linked_list.c b/tests/test_linked_list.c
index 2c51625..3b665f3 100644
--- a/tests/test_linked_list.c
+++ b/tests/test_linked_list.c
@@ -49,9 +49,10 @@ TEST(linked_list, foreach)
int i = 0;
int values[3];
- linked_list_foreach(ll, val) {
+ linked_list_foreach(ll, val)
+ {
values[i] = val;
- ++ i;
+ ++i;
}
ASSERT_EQ(values[0], 1);
diff --git a/tests/test_map.c b/tests/test_map.c
index 29704f0..db0fd9a 100644
--- a/tests/test_map.c
+++ b/tests/test_map.c
@@ -34,8 +34,8 @@ MAP_DECL(int, int_ptr);
MAP_IMPL(int, int_ptr, integer_cmp_, kfree);
static inline void loose_map_print(
- avl_tree_node_t(map_entry_t(int, int_ptr))* node,
- int tab) {
+ avl_tree_node_t(map_entry_t(int, int_ptr)) * node, int tab)
+{
if (node) {
loose_map_print(node->right, tab + 1);
}
@@ -49,8 +49,7 @@ static inline void loose_map_print(
printf("(%d => %d)\n", node->value.key, *node->value.value);
loose_map_print(node->left, tab + 1);
}
-static inline void map_debug_print(
- map_t(int, int_ptr) * map)
+static inline void map_debug_print(map_t(int, int_ptr) * map)
{
printf("------\n");
if (map->tree) {
@@ -96,7 +95,7 @@ TEST(map, stress)
erased[e] = 1;
}
- for (int i = 0; i < N; ++ i) {
+ for (int i = 0; i < N; ++i) {
if (erased[i]) {
continue;
}
diff --git a/tests/test_memory.c b/tests/test_memory.c
index c85e228..407aa3d 100644
--- a/tests/test_memory.c
+++ b/tests/test_memory.c
@@ -262,11 +262,7 @@ TEST(memory, alloc1)
kalloc(1);
if (debug_kalloc_assert_consistency(buf, 1024)) {
- fprintf(
- stderr,
- "Consistency check failed. (%s:%d)\n",
- __FILE__,
- __LINE__);
+ fprintf(stderr, "Consistency check failed. (%s:%d)\n", __FILE__, __LINE__);
fprintf(stderr, "%s", buf);
ASSERT_TRUE(false);
}
@@ -282,11 +278,7 @@ TEST(memory, alloc0)
kalloc(0);
if (debug_kalloc_assert_consistency(buf, 1024)) {
- fprintf(
- stderr,
- "Consistency check failed. (%s:%d)\n",
- __FILE__,
- __LINE__);
+ fprintf(stderr, "Consistency check failed. (%s:%d)\n", __FILE__, __LINE__);
fprintf(stderr, "%s", buf);
ASSERT_TRUE(false);
}
diff --git a/tests/test_mpu.c b/tests/test_mpu.c
index 551e079..9ffaa5d 100644
--- a/tests/test_mpu.c
+++ b/tests/test_mpu.c
@@ -1,12 +1,11 @@
-#include "test_harness.c"
-
#include "arch/arm/cortex-m4/mpu.h"
#include "kern/mpu/mpu_manager.h"
+#include "test_harness.c"
TEST(mpu, smell)
{
- memory_region_opts_t memopts = { 0 };
- memopts.region = (void*) 0;
+ memory_region_opts_t memopts = {0};
+ memopts.region = (void*)0;
memopts.bufferable = 0;
memopts.cacheable = 1;
memopts.sharable = 1;