Skip to content

Commit

Permalink
clang format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanbsolak committed Jan 30, 2024
1 parent f0c937e commit fa69200
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 60 deletions.
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/facial_recognition/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ void init_names()
char default_names[DEFAULT_EMBS_NUM][7] = DEFAULT_NAMES;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
for (int i = 0; i < DEFAULT_EMBS_NUM; i++) { strncpy((char *)names[i], default_names[i], 7); }
for (int i = 0; i < DEFAULT_EMBS_NUM; i++) {
strncpy((char *)names[i], default_names[i], 7);
}
#pragma GCC diagnostic pop
}
#ifdef TFT_ENABLE
Expand Down
8 changes: 6 additions & 2 deletions Examples/MAX78000/CNN/facial_recognition/src/cnn_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ int cnn_stop(void)

void memcpy32(uint32_t *dst, const uint32_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

static const uint32_t kernels[] = KERNELS;
Expand All @@ -113,7 +115,9 @@ static const uint8_t bias_3[] = BIAS_3;

static void memcpy_8to32(uint32_t *dst, const uint8_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

int cnn_1_load_bias(void)
Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/facial_recognition/src/cnn_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ static const uint8_t bias_3[] = BIAS_3;

static void memcpy_8to32(uint32_t *dst, const uint8_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

int cnn_2_load_bias(void)
Expand Down
19 changes: 14 additions & 5 deletions Examples/MAX78000/CNN/facial_recognition/src/facedetection.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ static void setup_dma_tft(uint32_t *src_ptr)

static void start_tft_dma(uint32_t *src_ptr)
{
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) { ; }
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) {
{
}
}

if (MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_CTZ_IF) {
MXC_DMA->ch[g_dma_channel_tft].status = MXC_F_DMA_STATUS_CTZ_IF;
Expand Down Expand Up @@ -168,13 +171,19 @@ static void run_cnn_1(int x_offset, int y_offset)
setup_dma_tft((uint32_t *)raw);
start_tft_dma((uint32_t *)raw);
// Wait for DMA to finish
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) { ; }
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) {
{
}
}

setup_dma_tft((uint32_t *)(raw + IMAGE_XRES * IMAGE_YRES));
// Send a second half of captured image to TFT
start_tft_dma((uint32_t *)(raw + IMAGE_XRES * IMAGE_YRES));
// Wait for DMA to finish
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) { ; }
while ((MXC_DMA->ch[g_dma_channel_tft].status & MXC_F_DMA_STATUS_STATUS)) {
{
}
}
PR_DEBUG("DMA time : %d", utils_get_time_ms() - dma_time);
//MXC_TFT_ShowImageCameraRGB565(X_START, Y_START, raw, w, h);

Expand Down Expand Up @@ -206,8 +215,8 @@ static void run_cnn_1(int x_offset, int y_offset)
r = ur - 128;

// Loading data into the CNN fifo
while (((*((volatile uint32_t *)0x50000004) & 1)) != 0)
; // Wait for FIFO 0
while (((*((volatile uint32_t *)0x50000004) & 1)) != 0) {}
// Wait for FIFO 0

number = 0x00FFFFFF & ((((uint8_t)b) << 16) | (((uint8_t)g) << 8) | ((uint8_t)r));

Expand Down
24 changes: 18 additions & 6 deletions Examples/MAX78000/CNN/facial_recognition/src/post_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ int get_prior_idx(int ar_idx, int scale_idx, int rel_idx)
{
int prior_idx = 0;

for (int s = 0; s < scale_idx; ++s) { prior_idx += NUM_ARS * MULT(dims[s][0], dims[s][1]); }
for (int s = 0; s < scale_idx; ++s) {
prior_idx += NUM_ARS * MULT(dims[s][0], dims[s][1]);
}

prior_idx += NUM_ARS * rel_idx + ar_idx;
return prior_idx;
Expand All @@ -74,7 +76,9 @@ void get_indices(int *ar_idx, int *scale_idx, int *rel_idx, int prior_idx)

int in_scale_idx = prior_idx;

for (s = 0; s < *scale_idx; ++s) { in_scale_idx -= (NUM_ARS * MULT(dims[s][0], dims[s][1])); }
for (s = 0; s < *scale_idx; ++s) {
in_scale_idx -= (NUM_ARS * MULT(dims[s][0], dims[s][1]));
}

*ar_idx = in_scale_idx % NUM_ARS;
*rel_idx = in_scale_idx / NUM_ARS;
Expand Down Expand Up @@ -214,7 +218,9 @@ void gcxgcy_to_cxcy(float *cxcy, int prior_idx, float *priors_cxcy)
{
float gcxgcy[4];

for (int i = 0; i < 4; i++) { gcxgcy[i] = (float)prior_locs[4 * prior_idx + i] / 128.0; }
for (int i = 0; i < 4; i++) {
gcxgcy[i] = (float)prior_locs[4 * prior_idx + i] / 128.0;
}

cxcy[0] = priors_cxcy[0] + gcxgcy[0] * priors_cxcy[2] / 10;
cxcy[1] = priors_cxcy[1] + gcxgcy[1] * priors_cxcy[3] / 10;
Expand All @@ -236,7 +242,9 @@ void insert_val(uint16_t val, uint16_t *arr, int arr_len, int idx)
arr[arr_len] = arr[arr_len - 1];
}

for (int j = (arr_len - 1); j > idx; --j) { arr[j] = arr[j - 1]; }
for (int j = (arr_len - 1); j > idx; --j) {
arr[j] = arr[j - 1];
}

arr[idx] = val;
}
Expand All @@ -247,7 +255,9 @@ void insert_idx(uint16_t val, uint16_t *arr, int arr_len, int idx)
arr[arr_len] = arr[arr_len - 1];
}

for (int j = (arr_len - 1); j > idx; --j) { arr[j] = arr[j - 1]; }
for (int j = (arr_len - 1); j > idx; --j) {
arr[j] = arr[j - 1];
}

arr[idx] = val;
}
Expand Down Expand Up @@ -457,7 +467,9 @@ void localize_objects(void)
area = calculate_area(xy);
if (area > max_area) {
max_area = area;
for (int i = 0; i < 4; ++i) { max_xy[i] = xy[i]; }
for (int i = 0; i < 4; ++i) {
max_xy[i] = xy[i];
}
}
#else

Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/facial_recognition/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void utils_send_bytes(mxc_uart_regs_t *uart, uint8_t *ptr, int length)
{
int i;

for (i = 0; i < length; i++) { utils_send_byte(uart, ptr[i]); }
for (i = 0; i < length; i++) {
utils_send_byte(uart, ptr[i]);
}
}

#pragma GCC optimize("-O0")
Expand Down
17 changes: 4 additions & 13 deletions Examples/MAX78002/CNN/facial_recognition/include/cnn_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ typedef int16_t q15_t;
#define Threshold 64

/* Stopwatch - holds the runtime when accelerator finishes */
extern volatile uint32_t cnn_time;



extern volatile uint32_t cnn_time;

/* Enable clocks and power to accelerator, enable interrupt */
int cnn_3_enable(uint32_t clock_source, uint32_t clock_divider);


int cnn_3_enable(uint32_t clock_source, uint32_t clock_divider);

/* Perform minimum accelerator initialization so it can be configured */
int cnn_3_init(void);
Expand All @@ -64,13 +59,9 @@ int cnn_3_verify_weights(void);
int cnn_3_load_bias(void);

/* Start accelerator processing */
int cnn_3_start(void);


int cnn_3_start(void);

/* Unload results from accelerator */
int cnn_3_unload(uint32_t *out_buf);


int cnn_3_unload(uint32_t *out_buf);

#endif // __CNN_3_H__
4 changes: 3 additions & 1 deletion Examples/MAX78002/CNN/facial_recognition/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ void init_names()
char default_names[DEFAULT_EMBS_NUM][7] = DEFAULT_NAMES;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
for (int i = 0; i < DEFAULT_EMBS_NUM; i++) { strncpy((char *)names[i], default_names[i], 7); }
for (int i = 0; i < DEFAULT_EMBS_NUM; i++) {
strncpy((char *)names[i], default_names[i], 7);
}
#pragma GCC diagnostic pop
}

Expand Down
28 changes: 16 additions & 12 deletions Examples/MAX78002/CNN/facial_recognition/src/cnn_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ int cnn_stop(void)

void memcpy32(uint32_t *dst, const uint32_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

static const uint32_t kernels_1[] = KERNELS_1;
Expand All @@ -127,7 +129,9 @@ static const uint8_t bias_3[] = BIAS_3;

static void memcpy_8to32(uint32_t *dst, const uint8_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

int cnn_1_load_bias(void)
Expand Down Expand Up @@ -155,14 +159,14 @@ int cnn_1_init(void)
*((volatile uint32_t *)0x5200000c) = 0x00001c80; // Clear registers
*((volatile uint32_t *)0x5300000c) = 0x00001c80; // Clear registers
*((volatile uint32_t *)0x5400000c) = 0x00001c80; // Clear registers
while ((*((volatile uint32_t *)0x5100000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5200000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5300000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5400000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5100000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5200000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5300000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5400000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
*((volatile uint32_t *)0x5100000c) = 0x00000000; // Reset BIST
*((volatile uint32_t *)0x5200000c) = 0x00000000; // Reset BIST
*((volatile uint32_t *)0x5300000c) = 0x00000000; // Reset BIST
Expand Down Expand Up @@ -1293,8 +1297,8 @@ int cnn_1_enable(uint32_t clock_source, uint32_t clock_divider)
MXC_GCFR->reg3 = 0x0; // Reset

if (clock_source == MXC_S_GCR_PCLKDIV_CNNCLKSEL_IPLL)
while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != MXC_F_GCR_IPLL_CTRL_RDY)
; // Wait for PLL
while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != MXC_F_GCR_IPLL_CTRL_RDY) {}
// Wait for PLL

MXC_GCR->pclkdiv =
(MXC_GCR->pclkdiv & ~(MXC_F_GCR_PCLKDIV_CNNCLKDIV | MXC_F_GCR_PCLKDIV_CNNCLKSEL)) |
Expand Down
24 changes: 13 additions & 11 deletions Examples/MAX78002/CNN/facial_recognition/src/cnn_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ static const uint8_t bias_3[] = BIAS_7;

static void memcpy_8to32(uint32_t *dst, const uint8_t *src, int n)
{
while (n-- > 0) { *dst++ = *src++; }
while (n-- > 0) {
*dst++ = *src++;
}
}

int cnn_2_load_bias(void)
Expand Down Expand Up @@ -192,14 +194,14 @@ int cnn_2_init(void)
*((volatile uint32_t *)0x5200000c) = 0x00001c80; // Clear registers
*((volatile uint32_t *)0x5300000c) = 0x00001c80; // Clear registers
*((volatile uint32_t *)0x5400000c) = 0x00001c80; // Clear registers
while ((*((volatile uint32_t *)0x5100000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5200000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5300000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5400000c) & 0x2000000) != 0x2000000)
; // Wait for clear
while ((*((volatile uint32_t *)0x5100000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5200000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5300000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
while ((*((volatile uint32_t *)0x5400000c) & 0x2000000) != 0x2000000) {}
// Wait for clear
*((volatile uint32_t *)0x5100000c) = 0x00000000; // Reset BIST
*((volatile uint32_t *)0x5200000c) = 0x00000000; // Reset BIST
*((volatile uint32_t *)0x5300000c) = 0x00000000; // Reset BIST
Expand Down Expand Up @@ -5140,8 +5142,8 @@ int cnn_2_enable(uint32_t clock_source, uint32_t clock_divider)
MXC_GCFR->reg3 = 0x0; // Reset

if (clock_source == MXC_S_GCR_PCLKDIV_CNNCLKSEL_IPLL)
while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != MXC_F_GCR_IPLL_CTRL_RDY)
; // Wait for PLL
while ((MXC_GCR->ipll_ctrl & MXC_F_GCR_IPLL_CTRL_RDY) != MXC_F_GCR_IPLL_CTRL_RDY) {}
// Wait for PLL

MXC_GCR->pclkdiv =
(MXC_GCR->pclkdiv & ~(MXC_F_GCR_PCLKDIV_CNNCLKDIV | MXC_F_GCR_PCLKDIV_CNNCLKSEL)) |
Expand Down
24 changes: 18 additions & 6 deletions Examples/MAX78002/CNN/facial_recognition/src/post_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ int get_prior_idx(int ar_idx, int scale_idx, int rel_idx)
{
int prior_idx = 0;

for (int s = 0; s < scale_idx; ++s) { prior_idx += NUM_ARS * MULT(dims[s][0], dims[s][1]); }
for (int s = 0; s < scale_idx; ++s) {
prior_idx += NUM_ARS * MULT(dims[s][0], dims[s][1]);
}

prior_idx += NUM_ARS * rel_idx + ar_idx;
return prior_idx;
Expand All @@ -86,7 +88,9 @@ void get_indices(int *ar_idx, int *scale_idx, int *rel_idx, int prior_idx)

int in_scale_idx = prior_idx;

for (s = 0; s < *scale_idx; ++s) { in_scale_idx -= (NUM_ARS * MULT(dims[s][0], dims[s][1])); }
for (s = 0; s < *scale_idx; ++s) {
in_scale_idx -= (NUM_ARS * MULT(dims[s][0], dims[s][1]));
}

*ar_idx = in_scale_idx % NUM_ARS;
*rel_idx = in_scale_idx / NUM_ARS;
Expand Down Expand Up @@ -230,7 +234,9 @@ void gcxgcy_to_cxcy(float *cxcy, int prior_idx, float *priors_cxcy)
{
float gcxgcy[4];

for (int i = 0; i < 4; i++) { gcxgcy[i] = (float)prior_locs[4 * prior_idx + i] / 128.0; }
for (int i = 0; i < 4; i++) {
gcxgcy[i] = (float)prior_locs[4 * prior_idx + i] / 128.0;
}

cxcy[0] = priors_cxcy[0] + gcxgcy[0] * priors_cxcy[2] / 10;
cxcy[1] = priors_cxcy[1] + gcxgcy[1] * priors_cxcy[3] / 10;
Expand All @@ -252,7 +258,9 @@ void insert_val(uint16_t val, uint16_t *arr, int arr_len, int idx)
arr[arr_len] = arr[arr_len - 1];
}

for (int j = (arr_len - 1); j > idx; --j) { arr[j] = arr[j - 1]; }
for (int j = (arr_len - 1); j > idx; --j) {
arr[j] = arr[j - 1];
}

arr[idx] = val;
}
Expand All @@ -263,7 +271,9 @@ void insert_idx(uint16_t val, uint16_t *arr, int arr_len, int idx)
arr[arr_len] = arr[arr_len - 1];
}

for (int j = (arr_len - 1); j > idx; --j) { arr[j] = arr[j - 1]; }
for (int j = (arr_len - 1); j > idx; --j) {
arr[j] = arr[j - 1];
}

arr[idx] = val;
}
Expand Down Expand Up @@ -430,7 +440,9 @@ void localize_objects(void)
area = calculate_area(xy);
if (area > max_area) {
max_area = area;
for (int i = 0; i < 4; ++i) { max_xy[i] = xy[i]; }
for (int i = 0; i < 4; ++i) {
max_xy[i] = xy[i];
}
}
#else

Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78002/CNN/facial_recognition/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void utils_send_bytes(mxc_uart_regs_t *uart, uint8_t *ptr, int length)
{
int i;

for (i = 0; i < length; i++) { utils_send_byte(uart, ptr[i]); }
for (i = 0; i < length; i++) {
utils_send_byte(uart, ptr[i]);
}
}

#pragma GCC optimize("-O0")
Expand Down

0 comments on commit fa69200

Please sign in to comment.