forked from M-Labs/artiq
1
0
Fork 0

phaser: move ad9154 spi/jesd api to rust

This commit is contained in:
Robert Jördens 2016-11-24 15:53:14 +01:00
parent 8060652913
commit 6fa2a6ebd8
6 changed files with 96 additions and 110 deletions

View File

@ -0,0 +1,75 @@
use board::csr;
pub extern fn init() {
unsafe {
csr::ad9154::spi_offline_write(1);
csr::ad9154::spi_cs_polarity_write(0);
csr::ad9154::spi_clk_polarity_write(0);
csr::ad9154::spi_clk_phase_write(0);
csr::ad9154::spi_lsb_first_write(0);
csr::ad9154::spi_half_duplex_write(0);
csr::ad9154::spi_clk_div_write_write(16);
csr::ad9154::spi_clk_div_read_write(16);
csr::ad9154::spi_xfer_len_write_write(24);
csr::ad9154::spi_xfer_len_read_write(0);
csr::ad9154::spi_cs_write(csr::CONFIG_AD9154_DAC_CS);
csr::ad9154::spi_offline_write(0);
}
}
const AD9_READ: u16 = 1 << 15;
pub extern fn dac_write(addr: u16, data: u8) {
unsafe {
csr::ad9154::spi_data_write_write(
((addr as u32) << 16) | ((data as u32) << 8));
while csr::ad9154::spi_pending_read() != 0 {}
while csr::ad9154::spi_active_read() != 0 {}
}
}
pub extern fn dac_read(addr: u16) -> u8 {
unsafe {
dac_write(AD9_READ | addr, 0);
csr::ad9154::spi_data_read_read() as u8
}
}
pub extern fn clk_write(addr: u16, data: u8) {
unsafe {
csr::ad9154::spi_cs_write(csr::CONFIG_AD9154_CLK_CS);
dac_write(addr, data);
csr::ad9154::spi_cs_write(csr::CONFIG_AD9154_DAC_CS);
}
}
pub extern fn clk_read(addr: u16) -> u8 {
unsafe {
clk_write(AD9_READ | addr, 0);
csr::ad9154::spi_data_read_read() as u8
}
}
pub extern fn jesd_enable(en: u32) {
unsafe {
csr::ad9154::jesd_control_enable_write(en);
}
}
pub extern fn jesd_ready() {
unsafe {
csr::ad9154::jesd_control_ready_read();
}
}
pub extern fn jesd_prbs(p: u32) {
unsafe {
csr::ad9154::jesd_control_prbs_config_write(p);
}
}
pub extern fn jesd_stpl(en: u32) {
unsafe {
csr::ad9154::jesd_control_stpl_enable_write(en);
}
}

View File

@ -117,17 +117,22 @@ static mut API: &'static [(&'static str, *const ())] = &[
#[cfg(has_i2c)]
api!(i2c_read = ::i2c::read),
// #if (defined CONFIG_AD9154_CS)
api!(ad9154_init),
api!(ad9154_write),
api!(ad9154_read),
api!(ad9516_write),
api!(ad9516_read),
api!(ad9154_jesd_enable),
api!(ad9154_jesd_ready),
api!(ad9154_jesd_prbs),
api!(ad9154_jesd_stpl),
// #endif
#[cfg(has_ad9154)]
api!(ad9154_init = ::ad9154::init),
#[cfg(has_ad9154)]
api!(ad9154_write = ::ad9154::dac_write),
#[cfg(has_ad9154)]
api!(ad9154_read = ::ad9154::dac_read),
#[cfg(has_ad9154)]
api!(ad9516_write = ::ad9154::clk_write),
#[cfg(has_ad9154)]
api!(ad9516_read = ::ad9154::clk_read),
#[cfg(has_ad9154)]
api!(ad9154_jesd_enable = ::ad9154::jesd_enable),
#[cfg(has_ad9154)]
api!(ad9154_jesd_ready = ::ad9154::jesd_ready),
#[cfg(has_ad9154)]
api!(ad9154_jesd_prbs = ::ad9154::jesd_prbs),
#[cfg(has_ad9154)]
api!(ad9154_jesd_stpl = ::ad9154::jesd_stpl),
];

View File

@ -52,6 +52,8 @@ macro_rules! artiq_raise {
mod rtio;
#[cfg(has_i2c)]
mod i2c;
#[cfg(has_ad9154)]
mod ad9154;
use core::{mem, ptr, slice, str};
use std::io::Cursor;

View File

@ -4,7 +4,7 @@ include $(MISOC_DIRECTORY)/software/common.mak
PYTHON ?= python3.5
OBJECTS := flash_storage.o main.o
OBJECTS_KSUPPORT := ksupport_glue.o artiq_personality.o ad9154.o
OBJECTS_KSUPPORT := ksupport_glue.o artiq_personality.o
RUSTOUT_DIRECTORY := cargo/or1k-unknown-none/debug
CORE_IO_COMMIT := d40c593f42fafbac1ff3d827f6df96338b5b7d8b

View File

@ -1,77 +0,0 @@
#include <generated/csr.h>
#include <stdint.h>
#include <stddef.h>
#include "artiq_personality.h"
#include "ad9154.h"
#ifdef CONFIG_AD9154_DAC_CS
void ad9154_init(void)
{
ad9154_spi_offline_write(1);
ad9154_spi_cs_polarity_write(0);
ad9154_spi_clk_polarity_write(0);
ad9154_spi_clk_phase_write(0);
ad9154_spi_lsb_first_write(0);
ad9154_spi_half_duplex_write(0);
ad9154_spi_clk_div_write_write(16);
ad9154_spi_clk_div_read_write(16);
ad9154_spi_xfer_len_write_write(24);
ad9154_spi_xfer_len_read_write(0);
ad9154_spi_cs_write(CONFIG_AD9154_DAC_CS);
ad9154_spi_offline_write(0);
}
#define AD9_READ (1 << 15)
#define AD9_XFER(w) ((w) << 13)
void ad9154_write(uint16_t addr, uint8_t data)
{
ad9154_spi_data_write_write(
((AD9_XFER(0) | addr) << 16) | (data << 8));
while (ad9154_spi_pending_read());
while (ad9154_spi_active_read());
}
uint8_t ad9154_read(uint16_t addr)
{
ad9154_write(AD9_READ | addr, 0);
return ad9154_spi_data_read_read();
}
void ad9516_write(uint16_t addr, uint8_t data)
{
ad9154_spi_cs_write(CONFIG_AD9154_CLK_CS);
ad9154_write(addr, data);
ad9154_spi_cs_write(CONFIG_AD9154_DAC_CS);
}
uint8_t ad9516_read(uint16_t addr)
{
ad9516_write(AD9_READ | addr, 0);
return ad9154_spi_data_read_read();
}
void ad9154_jesd_enable(int en)
{
ad9154_jesd_control_enable_write(en);
}
int ad9154_jesd_ready(void)
{
return ad9154_jesd_control_ready_read();
}
void ad9154_jesd_prbs(int p)
{
ad9154_jesd_control_prbs_config_write(p);
}
void ad9154_jesd_stpl(int en)
{
ad9154_jesd_control_stpl_enable_write(en);
}
#endif /* CONFIG_AD9154_DAC_CS */

View File

@ -1,19 +0,0 @@
#ifndef __AD9154_H
#define __AD9154_H
#ifdef CONFIG_AD9154_DAC_CS
void ad9154_init(void);
void ad9154_write(uint16_t addr, uint8_t data);
uint8_t ad9154_read(uint16_t addr);
void ad9516_write(uint16_t addr, uint8_t data);
uint8_t ad9516_read(uint16_t addr);
void ad9154_jesd_enable(int en);
int ad9154_jesd_ready(void);
void ad9154_jesd_prbs(int p);
void ad9154_jesd_stpl(int en);
#endif
#endif