AR := $(TRIPLE)ar
LD := $(TRIPLE)ld
-CFLAGS := -fvisibility=hidden -march=rv32i -mabi=ilp32 -nostdlib -Os -Iinclude
-LDFLAGS := -melf32lriscv -nostdlib
+CFLAGS += -fvisibility=hidden -nostdlib -Os -Iinclude
+LDFLAGS += -nostdlib
+
+ifeq ($(TRIPLE),riscv64-unknown-elf-)
+CFLAGS += -march=rv32i -mabi=ilp32
+LDFLAGS += -melf32lriscv
+endif
all: libgram.a
# libgram, the C companion for gram
-libgram is the C library for gram core initialization.
+libgram is the C library for gram core initialization and memory testing.
## HowTo
GRAM_ERR_NONE: No error happened (hardcoded to zero)
GRAM_ERR_UNDOCUMENTED: Undocumented error, shame on us lazy coders (take a look at the code)
```
+
+## Using libgram when you can't directly access the bus
+
+Compile libgram with `CFLAGS="-DGRAM_RW_FUNC"` (run `make clean` beforehand) then define the following functions:
+
+```c
+uint32_t gram_read(struct gramCtx *ctx, void *addr);
+int gram_write(struct gramCtx *ctx, void *addr, uint32_t value);
+```
+
+If you want to use the default compiler on your computer, use `CFLAGS="-DGRAM_RW_FUNC" make TRIPLE=""`.
#ifndef GRAM_H
#define GRAM_H
+#include <stdint.h>
+
enum GramError {
GRAM_ERR_NONE = 0,
GRAM_ERR_UNDOCUMENTED,
volatile void *ddr_base;
volatile struct gramCoreRegs *core;
volatile struct gramPHYRegs *phy;
+ void *user_data;
};
extern __attribute__((visibility ("default"))) int gram_init(struct gramCtx *ctx, void *ddr_base, void *core_base, void *phy_base);
extern __attribute__((visibility ("default"))) int gram_memtest(struct gramCtx *ctx);
+#ifdef GRAM_RW_FUNC
+extern uint32_t gram_read(struct gramCtx *ctx, void *addr);
+extern int gram_write(struct gramCtx *ctx, void *addr, uint32_t value);
+#endif /* GRAM_RW_FUNC */
+
#endif /* GRAM_H */
#include "helpers.h"
static void dfii_setcontrol(struct gramCtx *ctx, uint8_t val) {
+#ifdef GRAM_RW_FUNC
+ gram_write(ctx, &(ctx->core->control), val);
+#else
ctx->core->control = val;
+#endif
}
void dfii_setsw(struct gramCtx *ctx, bool software_control) {
}
static void dfii_set_p0_address(struct gramCtx *ctx, uint32_t val) {
+#ifdef GRAM_RW_FUNC
+ gram_write(ctx, &(ctx->core->phases[0].address), val);
+#else
ctx->core->phases[0].address = val;
+#endif
}
static void dfii_set_p0_baddress(struct gramCtx *ctx, uint32_t val) {
+#ifdef GRAM_RW_FUNC
+ gram_write(ctx, &(ctx->core->phases[0].baddress), val);
+#else
ctx->core->phases[0].baddress = val;
+#endif
}
static void dfii_p0_command(struct gramCtx *ctx, uint32_t cmd) {
+#ifdef GRAM_RW_FUNC
+ gram_write(ctx, &(ctx->core->phases[0].command), cmd);
+ gram_write(ctx, &(ctx->core->phases[0].command_issue), 1);
+#else
ctx->core->phases[0].command = cmd;
ctx->core->phases[0].command_issue = 1;
+#endif
}
/* TODO: those values are hardcoded for ECPIX-5's RAM */
#include <gram.h>
int gram_memtest(struct gramCtx *ctx) {
- return 0;
+ return GRAM_ERR_NONE;
}