Skip to content
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

More LBR Updates #50

Merged
merged 10 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ADD: mada timer driver
  • Loading branch information
iansseijelly committed Jan 12, 2025
commit f8896212d43356b37c7c34adf7a5db186c0c0afa
7 changes: 7 additions & 0 deletions driver/mada/timer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

add_library(mada_timer STATIC mada_timer.c)

target_include_directories(mada_timer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(mada_timer PUBLIC rocketcore)
target_link_libraries(mada_timer PUBLIC metal)
1 change: 1 addition & 0 deletions driver/mada/timer/mada_timer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "mada_timer.h"
54 changes: 54 additions & 0 deletions driver/mada/timer/mada_timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef __MADA_TIMER_H
#define __MADA_TIMER_H

#include "metal.h"

/*
register map
0x00: control and status
0x04: counter value (r)
0x08: auto-reload value (rw)
0x0c: prescaler value (rw)
0x10: capture and control 0 (rw)
0x14: capture and control 1 (rw)
0x18: capture and control 2 (rw)
0x1c: capture and control 3 (rw)
*/

typedef struct {
uint32_t MD_TM_CSR;
uint32_t MD_TM_COUNTER_VAL;
uint32_t MD_TM_AUTO_RELAOD;
uint32_t MD_TM_PRESCALER;
uint32_t MD_TM_CCR0;
uint32_t MD_TM_CCR1;
uint32_t MD_TM_CCR2;
} MadaTimerType;

#define MADA_ADDR 0x11000000
#define MADA_ENCODER0 ((MadaTimerType*)MADA_ADDR)

static inline void mada_timer_enable(MadaTimerType *timer){
timer->MD_TM_CSR = 0x1;
}

static inline void mada_timer_disable(MadaTimerType *timer){
timer->MD_TM_CSR = 0x0;
}

static inline uint32_t mada_timer_read_raw_counter(MadaTimerType *timer){
return timer->MD_TM_COUNTER_VAL;
}

static inline void mada_timer_configure(MadaTimerType* timer, uint32_t auto_reload, uint32_t prescaler){
timer->MD_TM_AUTO_RELAOD = auto_reload;
timer->MD_TM_PRESCALER = prescaler;
}

static inline void mada_timer_pwm_set(MadaTimerType* timer, uint32_t ccr0, uint32_t ccr1, uint32_t ccr2){
timer->MD_TM_CCR0 = ccr0;
timer->MD_TM_CCR1 = ccr1;
timer->MD_TM_CCR2 = ccr2;
}

#endif
Loading