Skip to content

Standardize stm32 gpio driver error returns #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/platforms/stm32/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(HEADER_FILES
avm_devcfg.h
avm_log.h
gpio_driver.h
platform_defaultatoms.h
stm_sys.h
../../../../libAtomVM/platform_nifs.h
../../../../libAtomVM/portnifloader.h
Expand All @@ -33,6 +34,7 @@ set(HEADER_FILES

set(SOURCE_FILES
gpio_driver.c
platform_defaultatoms.c
platform_nifs.c
sys.c
../../../../libAtomVM/portnifloader.c
Expand Down
257 changes: 123 additions & 134 deletions src/platforms/stm32/src/lib/gpio_driver.c

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/platforms/stm32/src/lib/platform_defaultatoms.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of AtomVM.
*
* Copyright 2019 Davide Bettio <[email protected]>
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
*/

#include "platform_defaultatoms.h"

#include <stdlib.h>
#include <string.h>

void platform_defaultatoms_init(GlobalContext *glb)
{
// About X macro: https://en.wikipedia.org/wiki/X_macro
#define X(name, lenstr, str) \
lenstr str,

static const char *const atoms[] = {
#include "platform_defaultatoms.def"

// dummy value
NULL
};
#undef X

for (int i = 0; i < ATOM_FIRST_AVAIL_INDEX - PLATFORM_ATOMS_BASE_INDEX; i++) {
if (UNLIKELY((size_t) atoms[i][0] != strlen(atoms[i] + 1))) {
AVM_ABORT();
}

if (UNLIKELY(globalcontext_insert_atom(glb, atoms[i]) != i + PLATFORM_ATOMS_BASE_INDEX)) {
AVM_ABORT();
}
}
}
30 changes: 30 additions & 0 deletions src/platforms/stm32/src/lib/platform_defaultatoms.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of AtomVM.
*
* Copyright 2019-2024 Davide Bettio <[email protected]>
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
*/

X(STM32_ATOM, "\x5", "stm32")

#if !(defined(AVM_DISABLE_GPIO_PORT_DRIVER) && defined(AVM_DISABLE_GPIO_NIFS))
X(HIGH_ATOM, "\x4", "high")
X(LOW_ATOM, "\x3", "low")
#if !(defined(AVM_DISABLE_GPIO_PORT_DRIVER))
X(GPIO_ATOM, "\x4", "gpio")
X(GPIO_INTERRUPT_ATOM, "\xE", "gpio_interrupt")
#endif
#endif
58 changes: 58 additions & 0 deletions src/platforms/stm32/src/lib/platform_defaultatoms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of AtomVM.
*
* Copyright 2019-2024 Davide Bettio <[email protected]>
*
* Licensed 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
*/

#ifndef _PLATFORM_DEFAULTATOMS_H_
#define _PLATFORM_DEFAULTATOMS_H_

#include "defaultatoms.h"

// About X macro: https://en.wikipedia.org/wiki/X_macro

#define X(name, lenstr, str) \
name##_INDEX,

enum
{
PLATFORM_ATOMS_BASE_INDEX_MINUS_ONE = PLATFORM_ATOMS_BASE_INDEX - 1,

#include "platform_defaultatoms.def"

ATOM_FIRST_AVAIL_INDEX
};

#undef X

_Static_assert((int) ATOM_FIRST_AVAIL_INDEX > (int) PLATFORM_ATOMS_BASE_INDEX,
"default atoms and platform ones are overlapping");

#define X(name, lenstr, str) \
name = TERM_FROM_ATOM_INDEX(name##_INDEX),

enum
{
#include "platform_defaultatoms.def"

// dummy last item
ATOM_FIRST_AVAIL_DUMMY = TERM_FROM_ATOM_INDEX(ATOM_FIRST_AVAIL_INDEX)
};

#undef X

#endif
1 change: 1 addition & 0 deletions src/platforms/stm32/src/lib/platform_nifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//#define ENABLE_TRACE
#include <trace.h>

#include "platform_defaultatoms.h"
#include "stm_sys.h"

static term nif_atomvm_platform(Context *ctx, int argc, term argv[])
Expand Down
2 changes: 0 additions & 2 deletions src/platforms/stm32/src/lib/stm_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <portnifloader.h>
#include <sys.h>

#define STM32_ATOM globalcontext_make_atom(ctx->global, ATOM_STR("\x5", "stm32"))

/* Only on ARMv7EM and above
* TODO: These definitions are back-ported from libopencm3 `master`, if they ever release a new version this section should
* be removed, along with the included headers and replaced with only the following inclusion:
Expand Down
9 changes: 0 additions & 9 deletions src/platforms/stm32/src/lib/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,6 @@ static inline void sys_clock_gettime(struct timespec *t)
t->tv_nsec = ((int32_t) now % 1000) * 1000000;
}

/* TODO: Needed because `defaultatoms_init` in libAtomVM/defaultatoms.c calls this function.
* We should be able to remove this after `platform_defaulatoms.{c,h}` are removed on all platforms
* and `defaultatoms_init` is no longer called.
*/
void platform_defaultatoms_init(GlobalContext *glb)
{
UNUSED(glb);
}

void sys_enable_core_periph_clocks()
{
uint32_t list[] = GPIO_CLOCK_LIST;
Expand Down
Loading