[debug] remove lib/debug and move to the top/ module
Most of the functions for this was declared in a top level lk/ include space, so go ahead and move it there. A few exceptions: - Moved spin() over to platform/time.h and platform/time.c since the function more logically belongs to platform/time.h. Any users of spin() will need to update their headers to include platform/time.h instead. - Renamed spin_cycles() to arm_cm_spin_cycles() and moved over into arm/cm.h since it is currently defined in arch/arm-m and only used for targets that implicitly are for arm-m.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <printf.h>
|
||||
|
||||
#include <platform.h>
|
||||
#include <platform/time.h>
|
||||
#include <arch/arm.h>
|
||||
#include <kernel/thread.h>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <kernel/semaphore.h>
|
||||
#include <kernel/event.h>
|
||||
#include <platform.h>
|
||||
#include <platform/time.h>
|
||||
#include <arch/atomic.h>
|
||||
|
||||
static int sleep_thread(void *arg) {
|
||||
|
||||
@@ -177,6 +177,8 @@ static inline bool arm_cm_is_preempt_triggered(void) {
|
||||
return SCB->ICSR & SCB_ICSR_PENDSVSET_Msk;
|
||||
}
|
||||
|
||||
void arm_cm_spin_cycles(uint32_t cycles);
|
||||
|
||||
/* systick */
|
||||
void arm_cm_systick_init(uint32_t mhz);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
__ALIGNED(8) __NAKED
|
||||
#if (__CORTEX_M >= 0x03) || (CORTEX_SC >= 300)
|
||||
|
||||
void spin_cycles(uint32_t cycles) {
|
||||
void arm_cm_spin_cycles(uint32_t cycles) {
|
||||
asm (
|
||||
/* 4 cycles per loop, subtract out 8 cycles for the overhead of the next
|
||||
* 4 instructions, plus the call into and return from the function.
|
||||
@@ -48,7 +48,7 @@ void spin_cycles(uint32_t cycles) {
|
||||
|
||||
#else
|
||||
/* Cortex-M0 & Cortex-M0+ */
|
||||
void spin_cycles(uint32_t cycles) {
|
||||
void arm_cm_spin_cycles(uint32_t cycles) {
|
||||
asm (
|
||||
/* 4 cycles per loop, subtract out 8 cycles for the overhead of the next
|
||||
* 4 instructions, plus the call into and return from the function.
|
||||
|
||||
@@ -40,28 +40,28 @@ static gpio_i2c_state_t gpio_i2c_states[GPIO_I2C_BUS_COUNT];
|
||||
******************************************************************************/
|
||||
static inline void send_start(const gpio_i2c_info_t *i) {
|
||||
gpio_config(i->sda, GPIO_OUTPUT);
|
||||
spin_cycles(i->qcd);
|
||||
arm_cm_spin_cycles(i->qcd);
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
}
|
||||
|
||||
static inline void send_stop(const gpio_i2c_info_t *i) {
|
||||
gpio_config(i->sda, GPIO_OUTPUT);
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->qcd);
|
||||
arm_cm_spin_cycles(i->qcd);
|
||||
gpio_config(i->sda, GPIO_I2C_INPUT);
|
||||
}
|
||||
|
||||
static inline void send_restart(const gpio_i2c_info_t *i) {
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->qcd);
|
||||
arm_cm_spin_cycles(i->qcd);
|
||||
send_start(i);
|
||||
}
|
||||
|
||||
static inline void send_nack(const gpio_i2c_info_t *i) {
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
gpio_config(i->sda, GPIO_I2C_INPUT);
|
||||
}
|
||||
@@ -86,19 +86,19 @@ static inline bool send_byte(const gpio_i2c_info_t *i, uint32_t b) {
|
||||
* here in order to hit that timing, they are welcome to add a spin
|
||||
* right here.
|
||||
*/
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
}
|
||||
|
||||
gpio_config(i->sda, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
ret = (0 == gpio_get(i->sda));
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -108,16 +108,16 @@ static inline void recv_byte(const gpio_i2c_info_t *i, uint8_t *b) {
|
||||
|
||||
for (size_t j = 0; j < 7; ++j) {
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
if (gpio_get(i->sda))
|
||||
tmp |= 1;
|
||||
tmp <<= 1;
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
}
|
||||
|
||||
gpio_config(i->scl, GPIO_I2C_INPUT);
|
||||
spin_cycles(i->hcd);
|
||||
arm_cm_spin_cycles(i->hcd);
|
||||
if (gpio_get(i->sda))
|
||||
tmp |= 1;
|
||||
gpio_config(i->scl, GPIO_OUTPUT);
|
||||
|
||||
@@ -4,7 +4,6 @@ MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_DEPS := \
|
||||
lib/libc \
|
||||
lib/debug \
|
||||
lib/heap
|
||||
|
||||
MODULE_SRCS := \
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/debug.c
|
||||
|
||||
include make/module.mk
|
||||
@@ -3,7 +3,6 @@ LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_DEPS += \
|
||||
lib/debug \
|
||||
lib/console
|
||||
|
||||
MODULE_SRCS += \
|
||||
|
||||
@@ -22,5 +22,8 @@ lk_time_t current_time(void);
|
||||
/* Time in units of microseconds */
|
||||
lk_bigtime_t current_time_hires(void);
|
||||
|
||||
/* spin the cpu for a period of (short) time */
|
||||
void spin(uint32_t usecs);
|
||||
|
||||
__END_CDECLS
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void platform_early_init(void) {
|
||||
// Enable, HF=0 BYPASS=0
|
||||
writel(0, XTAL_OSC_CTRL);
|
||||
// Wait
|
||||
spin_cycles(3000); // 250uS @ 12MHz
|
||||
arm_cm_spin_cycles(3000); // 250uS @ 12MHz
|
||||
|
||||
// PLL1: 12MHz -> N=(/2) -> M=(x32) -> P=(/2) 96MHz
|
||||
cfg = PLL1_CTRL_NSEL_2 | PLL1_CTRL_PSEL_1 | PLL1_CTRL_MSEL(32) |
|
||||
@@ -56,7 +56,7 @@ void platform_early_init(void) {
|
||||
|
||||
// when moving from < 90 MHz to > 110MHz, must spend 50uS
|
||||
// at 90-110MHz before shifting to high speeds
|
||||
spin_cycles(4800); // 50uS @ 96MHz
|
||||
arm_cm_spin_cycles(4800); // 50uS @ 96MHz
|
||||
|
||||
// disable P divider 192MHz
|
||||
writel(cfg | PLL1_CTRL_DIRECT, PLL1_CTRL);
|
||||
|
||||
@@ -6,7 +6,8 @@ MODULE := $(LOCAL_DIR)
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/debug.c \
|
||||
$(LOCAL_DIR)/init.c \
|
||||
$(LOCAL_DIR)/power.c
|
||||
$(LOCAL_DIR)/power.c \
|
||||
$(LOCAL_DIR)/time.c \
|
||||
|
||||
MODULE_OPTIONS := extra_warnings
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <dev/gpio.h>
|
||||
#include <platform/stm32.h>
|
||||
#include <platform/sdram.h>
|
||||
#include <platform/time.h>
|
||||
|
||||
/*
|
||||
* sdram initialization sequence, taken from
|
||||
|
||||
15
platform/time.c
Normal file
15
platform/time.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Travis Geiselbrecht
|
||||
*
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include <platform/time.h>
|
||||
|
||||
void spin(uint32_t usecs) {
|
||||
lk_bigtime_t start = current_time_hires();
|
||||
|
||||
while ((current_time_hires() - start) < usecs)
|
||||
;
|
||||
}
|
||||
@@ -18,13 +18,6 @@
|
||||
#include <platform/debug.h>
|
||||
#include <kernel/spinlock.h>
|
||||
|
||||
void spin(uint32_t usecs) {
|
||||
lk_bigtime_t start = current_time_hires();
|
||||
|
||||
while ((current_time_hires() - start) < usecs)
|
||||
;
|
||||
}
|
||||
|
||||
void panic(const char *fmt, ...) {
|
||||
printf("panic (caller %p): ", __GET_CALLER());
|
||||
|
||||
@@ -56,10 +56,4 @@ void panic(const char *fmt, ...) __PRINTFLIKE(1, 2) __NO_RETURN;
|
||||
#define PANIC_UNIMPLEMENTED panic("%s:%d unimplemented\n", __PRETTY_FUNCTION__, __LINE__)
|
||||
#define PANIC_UNIMPLEMENTED_MSG(x...) panic("%s:%d unimplemented: %s\n", __PRETTY_FUNCTION__, __LINE__, x)
|
||||
|
||||
/* spin the cpu for a period of (short) time */
|
||||
void spin(uint32_t usecs);
|
||||
|
||||
/* spin the cpu for a certain number of cpu cycles */
|
||||
void spin_cycles(uint32_t usecs);
|
||||
|
||||
__END_CDECLS
|
||||
|
||||
@@ -11,6 +11,7 @@ MODULE_DEPS := \
|
||||
target
|
||||
|
||||
MODULE_SRCS := \
|
||||
$(LOCAL_DIR)/debug.c \
|
||||
$(LOCAL_DIR)/init.c \
|
||||
$(LOCAL_DIR)/main.c \
|
||||
|
||||
|
||||
Reference in New Issue
Block a user