bios: move I2C from liblitedram to libbase
This commit is contained in:
parent
472bf9ac71
commit
1172c10afb
|
@ -17,6 +17,7 @@ OBJECTS = isr.o \
|
|||
cmd_bios.o \
|
||||
cmd_mem.o \
|
||||
cmd_boot.o \
|
||||
cmd_i2c.o \
|
||||
cmd_spiflash.o \
|
||||
cmd_litedram.o \
|
||||
cmd_liteeth.o \
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
// SPDX-License-Identifier: BSD-Source-Code
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <generated/csr.h>
|
||||
#include <i2c.h>
|
||||
|
||||
#include "../command.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
|
||||
/**
|
||||
* Command "i2creset"
|
||||
*
|
||||
* Reset I2C line state in case a slave locks the line.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
define_command(i2creset, i2c_reset, "Reset I2C line state", I2C_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "i2cwr"
|
||||
*
|
||||
* Write I2C slave memory using 7-bit slave address and 8-bit memory address.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
static void i2cwr_handler(int nb_params, char **params)
|
||||
{
|
||||
int i;
|
||||
char *c;
|
||||
unsigned char write_params[32]; // also indirectly limited by CMD_LINE_BUFFER_SIZE
|
||||
|
||||
if (nb_params < 2) {
|
||||
printf("i2cwr <slaveaddr7bit> <addr> [<data>, ...]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nb_params - 1 > sizeof(write_params)) {
|
||||
printf("Max data length is %d", sizeof(write_params));
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < nb_params; ++i) {
|
||||
write_params[i] = strtoul(params[i], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect value of parameter %d", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i2c_write(write_params[0], write_params[1], &write_params[2], nb_params - 2)) {
|
||||
printf("Error during I2C write");
|
||||
return;
|
||||
}
|
||||
}
|
||||
define_command(i2cwr, i2cwr_handler, "Write over I2C", I2C_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "i2crd"
|
||||
*
|
||||
* Read I2C slave memory using 7-bit slave address and 8-bit memory address.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
static void i2crd_handler(int nb_params, char **params)
|
||||
{
|
||||
char *c;
|
||||
int len;
|
||||
unsigned char slave_addr, addr;
|
||||
unsigned char buf[256];
|
||||
bool send_stop = true;
|
||||
|
||||
if (nb_params < 3) {
|
||||
printf("i2crd <slaveaddr7bit> <addr> <len> [<send_stop>]");
|
||||
return;
|
||||
}
|
||||
|
||||
slave_addr = strtoul(params[0], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect slave address");
|
||||
return;
|
||||
}
|
||||
|
||||
addr = strtoul(params[1], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect memory address");
|
||||
return;
|
||||
}
|
||||
|
||||
len = strtoul(params[2], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect data length");
|
||||
return;
|
||||
}
|
||||
if (len > sizeof(buf)) {
|
||||
printf("Max data count is %d", sizeof(buf));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nb_params > 3) {
|
||||
send_stop = strtoul(params[3], &c, 0) != 0;
|
||||
if (*c != 0) {
|
||||
printf("Incorrect send_stop value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i2c_read(slave_addr, addr, buf, len, send_stop)) {
|
||||
printf("Error during I2C read");
|
||||
return;
|
||||
}
|
||||
|
||||
dump_bytes((unsigned int *) buf, len, addr);
|
||||
}
|
||||
define_command(i2crd, i2crd_handler, "Read over I2C", I2C_CMDS);
|
||||
#endif
|
|
@ -5,6 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
#include <generated/csr.h>
|
||||
#include <i2c.h>
|
||||
|
||||
#include "sdram.h"
|
||||
|
||||
|
@ -223,115 +224,6 @@ define_command(sdrlevel, sdrlevel, "Perform read/write leveling", LITEDRAM_CMDS)
|
|||
define_command(memtest, memtest, "Run a memory test", LITEDRAM_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "i2creset"
|
||||
*
|
||||
* Reset I2C line state in case a slave locks the line.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
define_command(i2creset, i2c_reset, "Reset I2C line state", LITEDRAM_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "i2cwr"
|
||||
*
|
||||
* Write I2C slave memory using 7-bit slave address and 8-bit memory address.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
static void i2cwr_handler(int nb_params, char **params)
|
||||
{
|
||||
int i;
|
||||
char *c;
|
||||
unsigned char write_params[32]; // also indirectly limited by CMD_LINE_BUFFER_SIZE
|
||||
|
||||
if (nb_params < 2) {
|
||||
printf("i2cwr <slaveaddr7bit> <addr> [<data>, ...]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nb_params - 1 > sizeof(write_params)) {
|
||||
printf("Max data length is %d", sizeof(write_params));
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < nb_params; ++i) {
|
||||
write_params[i] = strtoul(params[i], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect value of parameter %d", i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i2c_write(write_params[0], write_params[1], &write_params[2], nb_params - 2)) {
|
||||
printf("Error during I2C write");
|
||||
return;
|
||||
}
|
||||
}
|
||||
define_command(i2cwr, i2cwr_handler, "Write over I2C", LITEDRAM_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "i2crd"
|
||||
*
|
||||
* Read I2C slave memory using 7-bit slave address and 8-bit memory address.
|
||||
*
|
||||
*/
|
||||
#ifdef CSR_I2C_BASE
|
||||
static void i2crd_handler(int nb_params, char **params)
|
||||
{
|
||||
char *c;
|
||||
int len;
|
||||
unsigned char slave_addr, addr;
|
||||
unsigned char buf[256];
|
||||
bool send_stop = true;
|
||||
|
||||
if (nb_params < 3) {
|
||||
printf("i2crd <slaveaddr7bit> <addr> <len> [<send_stop>]");
|
||||
return;
|
||||
}
|
||||
|
||||
slave_addr = strtoul(params[0], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect slave address");
|
||||
return;
|
||||
}
|
||||
|
||||
addr = strtoul(params[1], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect memory address");
|
||||
return;
|
||||
}
|
||||
|
||||
len = strtoul(params[2], &c, 0);
|
||||
if (*c != 0) {
|
||||
printf("Incorrect data length");
|
||||
return;
|
||||
}
|
||||
if (len > sizeof(buf)) {
|
||||
printf("Max data count is %d", sizeof(buf));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nb_params > 3) {
|
||||
send_stop = strtoul(params[3], &c, 0) != 0;
|
||||
if (*c != 0) {
|
||||
printf("Incorrect send_stop value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!i2c_read(slave_addr, addr, buf, len, send_stop)) {
|
||||
printf("Error during I2C read");
|
||||
return;
|
||||
}
|
||||
|
||||
dump_bytes((unsigned int *) buf, len, addr);
|
||||
}
|
||||
define_command(i2crd, i2crd_handler, "Read over I2C", LITEDRAM_CMDS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Command "spdread"
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define MEM_CMDS 3
|
||||
#define BOOT_CMDS 3
|
||||
#define SPIFLASH_CMDS 4
|
||||
#define I2C_CMDS 4
|
||||
#define LITEDRAM_CMDS 4
|
||||
#define LITEETH_CMDS 5
|
||||
#define LITESDCARD_CMDS 7
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef __I2C_H
|
||||
#define __I2C_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <generated/csr.h>
|
||||
|
||||
/* I2C frequency defaults to a safe value in range 10-100 kHz to be compatible with SMBus */
|
||||
#ifndef I2C_FREQ_HZ
|
||||
|
@ -16,4 +19,8 @@ void i2c_reset(void);
|
|||
bool i2c_write(unsigned char slave_addr, unsigned char addr, const unsigned char *data, unsigned int len);
|
||||
bool i2c_read(unsigned char slave_addr, unsigned char addr, unsigned char *data, unsigned int len, bool send_stop);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __I2C_H */
|
|
@ -2,7 +2,7 @@ include ../include/generated/variables.mak
|
|||
include $(SOC_DIRECTORY)/software/common.mak
|
||||
|
||||
OBJECTS = exception.o libc.o errno.o crc16.o crc32.o console.o \
|
||||
system.o id.o uart.o time.o qsort.o strtod.o spiflash.o strcasecmp.o
|
||||
system.o id.o uart.o time.o qsort.o strtod.o spiflash.o strcasecmp.o i2c.o
|
||||
|
||||
all: crt0-ctr.o crt0-xip.o libbase.a libbase-nofloat.a
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "i2c.h"
|
||||
#include <i2c.h>
|
||||
#include <generated/csr.h>
|
||||
|
||||
#ifdef CSR_I2C_BASE
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
include ../include/generated/variables.mak
|
||||
include $(SOC_DIRECTORY)/software/common.mak
|
||||
|
||||
OBJECTS = sdram.o i2c.o
|
||||
OBJECTS = sdram.o
|
||||
|
||||
all: liblitedram.a
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define __SDRAM_H
|
||||
|
||||
#include <generated/csr.h>
|
||||
#include "i2c.h"
|
||||
|
||||
void sdrsw(void);
|
||||
void sdrhw(void);
|
||||
|
|
Loading…
Reference in New Issue