|
@@ -1,52 +1,53 @@
|
|
|
-#include "common.h"
|
|
|
+#include "board.h"
|
|
|
+#include <string.h>
|
|
|
|
|
|
#include "xparameters.h"
|
|
|
#include "xtmrctr.h"
|
|
|
#include "xintc.h"
|
|
|
+#include "xgpio.h"
|
|
|
|
|
|
-#define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID
|
|
|
-#define TMRCTR_BASEADDR XPAR_TMRCTR_0_BASEADDR
|
|
|
-#define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
|
|
|
-#define TMRCTR_INTERRUPT_ID XPAR_MICROBLAZE_0_AXI_INTC_AXI_TIMER_0_INTERRUPT_INTR
|
|
|
-#define TIMER_CNTR_0 0
|
|
|
+#define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID
|
|
|
+#define TMRCTR_BASEADDR XPAR_TMRCTR_0_BASEADDR
|
|
|
+#define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID
|
|
|
+#define TMRCTR_INTERRUPT_ID XPAR_MICROBLAZE_0_AXI_INTC_AXI_TIMER_0_INTERRUPT_INTR
|
|
|
+#define TIMER_CNTR_0 0
|
|
|
+#define GPIO_OUTPUT_DEVICE_ID XPAR_GPIO_0_DEVICE_ID
|
|
|
+#define LED_CHANNEL 1
|
|
|
|
|
|
// reset after 1 sec
|
|
|
-#define RESET_VALUE (0xFFFFFFFF - XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ)
|
|
|
+#define RESET_VALUE (0xFFFFFFFF - XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ)
|
|
|
|
|
|
XIntc InterruptController;
|
|
|
XTmrCtr xil_timer;
|
|
|
+XGpio GpioOutput;
|
|
|
|
|
|
void TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber);
|
|
|
|
|
|
+static uint32_t gpio_flag = 0xFFFF;
|
|
|
std::uint64_t gpt_system_tick = 0;
|
|
|
|
|
|
-void adjust_timer(const rotor_light::Duration &value) {
|
|
|
- gpt_system_tick += value;
|
|
|
+void Board::toggle_led() {
|
|
|
+ XGpio_Out32(GpioOutput.BaseAddress + XGPIO_DATA_OFFSET, gpio_flag);
|
|
|
+ gpio_flag ^= 0xFFFF;
|
|
|
}
|
|
|
|
|
|
-// return seconds from the Big Start
|
|
|
-rl::TimePoint get_now() {
|
|
|
- return gpt_system_tick;
|
|
|
-}
|
|
|
+void Board::init_start() {
|
|
|
+ XGpio_Initialize(&GpioOutput, GPIO_OUTPUT_DEVICE_ID);
|
|
|
+ XGpio_SetDataDirection(&GpioOutput, LED_CHANNEL, 0x0);
|
|
|
|
|
|
-void enable_timer() {
|
|
|
XTmrCtr_Initialize(&xil_timer, TMRCTR_DEVICE_ID);
|
|
|
XTmrCtr_SelfTest(&xil_timer, TIMER_CNTR_0);
|
|
|
+
|
|
|
XIntc_Initialize(&InterruptController, INTC_DEVICE_ID);
|
|
|
XIntc_Connect(&InterruptController,
|
|
|
TMRCTR_INTERRUPT_ID,
|
|
|
(XInterruptHandler)XTmrCtr_InterruptHandler,
|
|
|
(void*) &xil_timer);
|
|
|
|
|
|
- XIntc_Start(&InterruptController, XIN_REAL_MODE);
|
|
|
-
|
|
|
- XIntc_Enable(&InterruptController, TMRCTR_INTERRUPT_ID);
|
|
|
-
|
|
|
Xil_ExceptionInit();
|
|
|
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
|
|
|
(Xil_ExceptionHandler) XIntc_InterruptHandler,
|
|
|
&InterruptController);
|
|
|
- Xil_ExceptionEnable();
|
|
|
|
|
|
XTmrCtr_SetHandler(&xil_timer,
|
|
|
TimerCounterHandler,
|
|
@@ -55,14 +56,39 @@ void enable_timer() {
|
|
|
TIMER_CNTR_0,
|
|
|
XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION);
|
|
|
XTmrCtr_SetResetValue(&xil_timer, TIMER_CNTR_0, RESET_VALUE);
|
|
|
+}
|
|
|
+
|
|
|
+void Board::enable_interrupts() {
|
|
|
+ microblaze_enable_interrupts();
|
|
|
+
|
|
|
+ XIntc_Start(&InterruptController, XIN_REAL_MODE);
|
|
|
+ XIntc_Enable(&InterruptController, TMRCTR_INTERRUPT_ID);
|
|
|
+ Xil_ExceptionEnable();
|
|
|
+}
|
|
|
+
|
|
|
+void Board::disable_interrupts() {
|
|
|
+ microblaze_disable_interrupts();
|
|
|
+}
|
|
|
+
|
|
|
+void Board::enable_timer() {
|
|
|
XTmrCtr_Start(&xil_timer, TIMER_CNTR_0);
|
|
|
}
|
|
|
|
|
|
-void disable_timer() {
|
|
|
+void Board::disable_timer() {
|
|
|
XTmrCtr_Stop(&xil_timer, TIMER_CNTR_0);
|
|
|
XIntc_Disable(&InterruptController, TMRCTR_INTERRUPT_ID);
|
|
|
}
|
|
|
|
|
|
+rl::TimePoint Board::get_now() {
|
|
|
+ return gpt_system_tick;
|
|
|
+}
|
|
|
+
|
|
|
+void adjust_timer(const rotor_light::Duration &value) {
|
|
|
+ gpt_system_tick += value;
|
|
|
+}
|
|
|
+
|
|
|
+void Board::delay() {}
|
|
|
+
|
|
|
// on interrupt add 1 second
|
|
|
void TimerCounterHandler(void *CallBackRef, u8 TmrCtrNumber)
|
|
|
{
|