demo: 1wire GPIO access + reset

parent b1c504ad
...@@ -30,6 +30,7 @@ module system( ...@@ -30,6 +30,7 @@ module system(
// GPIO // GPIO
input btn, input btn,
output [3:0] led, output [3:0] led,
inout onewire,
// TDC // TDC
input tdc_signal input tdc_signal
...@@ -428,10 +429,11 @@ uart #( ...@@ -428,10 +429,11 @@ uart #(
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// System Controller // System Controller
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wire onewire_drivelow;
sysctl #( sysctl #(
.csr_addr(4'h1), .csr_addr(4'h1),
.ninputs(1), .ninputs(2),
.noutputs(4), .noutputs(5),
.systemid(32'h53504543) /* SPEC */ .systemid(32'h53504543) /* SPEC */
) sysctl ( ) sysctl (
.sys_clk(sys_clk), .sys_clk(sys_clk),
...@@ -446,11 +448,12 @@ sysctl #( ...@@ -446,11 +448,12 @@ sysctl #(
.csr_di(csr_dw), .csr_di(csr_dw),
.csr_do(csr_dr_sysctl), .csr_do(csr_dr_sysctl),
.gpio_inputs(btn), .gpio_inputs({onewire, btn}),
.gpio_outputs(led), .gpio_outputs({onewire_drivelow, led}),
.hard_reset(hard_reset) .hard_reset(hard_reset)
); );
assign onewire = onewire_drivelow ? 1'b0 : 1'bz;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// TDC // TDC
......
...@@ -19,8 +19,7 @@ NET "led[0]" LOC = G19 | IOSTANDARD = "LVCMOS18"; # AUX LEDs ...@@ -19,8 +19,7 @@ NET "led[0]" LOC = G19 | IOSTANDARD = "LVCMOS18"; # AUX LEDs
NET "led[1]" LOC = F20 | IOSTANDARD = "LVCMOS18"; NET "led[1]" LOC = F20 | IOSTANDARD = "LVCMOS18";
NET "led[2]" LOC = F18 | IOSTANDARD = "LVCMOS18"; NET "led[2]" LOC = F18 | IOSTANDARD = "LVCMOS18";
NET "led[3]" LOC = C20 | IOSTANDARD = "LVCMOS18"; NET "led[3]" LOC = C20 | IOSTANDARD = "LVCMOS18";
NET "onewire" LOC = D4 | IOSTANDARD = "LVCMOS25";
# TODO: temperature probe
# ==== TDC inputs ==== # ==== TDC inputs ====
# FIXME # FIXME
......
MMDIR=../.. MMDIR=../..
include $(MMDIR)/software/include.mak include $(MMDIR)/software/include.mak
OBJECTS=crt0.o main.o tdc.o OBJECTS=crt0.o main.o tdc.o temperature.o
SEGMENTS=-j .text -j .data -j .rodata SEGMENTS=-j .text -j .data -j .rodata
all: demo.bin demo.h0 demo.h1 demo.h2 demo.h3 all: demo.bin demo.h0 demo.h1 demo.h2 demo.h3
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <hw/uart.h> #include <hw/uart.h>
#include "tdc.h" #include "tdc.h"
#include "temperature.h"
/* General address space functions */ /* General address space functions */
...@@ -222,6 +223,7 @@ static void do_command(char *c) ...@@ -222,6 +223,7 @@ static void do_command(char *c)
else if(strcmp(token, "rofreq") == 0) rofreq(); else if(strcmp(token, "rofreq") == 0) rofreq();
else if(strcmp(token, "calinfo") == 0) calinfo(); else if(strcmp(token, "calinfo") == 0) calinfo();
else if(strcmp(token, "mraw") == 0) mraw(); else if(strcmp(token, "mraw") == 0) mraw();
else if(strcmp(token, "temp") == 0) temp();
else if(strcmp(token, "") != 0) else if(strcmp(token, "") != 0)
printf("Command not found\n"); printf("Command not found\n");
......
/*
* 1-wire temperature sensor access
*
* Copyright (C) 2011 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <hw/sysctl.h>
#include <hw/gpio.h>
#include "temperature.h"
static void udelay(int usec)
{
int limit;
limit = usec*125;
CSR_TIMER0_CONTROL = 0;
CSR_TIMER0_COUNTER = 0;
CSR_TIMER0_CONTROL = TIMER_ENABLE;
while(CSR_TIMER0_COUNTER < limit);
}
static int reset_1w()
{
int ok;
CSR_GPIO_OUT |= GPIO_1W_DRIVELOW;
udelay(500);
CSR_GPIO_OUT &= ~GPIO_1W_DRIVELOW;
udelay(65);
ok = !(CSR_GPIO_IN & GPIO_1W);
udelay(500);
return ok;
}
void temp()
{
if(reset_1w())
printf("1W reset OK\n");
else
printf("1W reset failed\n");
}
/*
* 1-wire temperature sensor access
*
* Copyright (C) 2011 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TEMPERATURE_H
#define __TEMPERATURE_H
void temp();
#endif /* __TEMPERATURE_H */
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
#define __HW_GPIO_H #define __HW_GPIO_H
/* Inputs */ /* Inputs */
#define GPIO_PB2 (0x00000001) #define GPIO_PB2 (0x00000001)
#define GPIO_1W (0x00000002)
/* Outputs */ /* Outputs */
#define GPIO_LD2 (0x00000001) #define GPIO_LD2 (0x00000001)
#define GPIO_LD3 (0x00000002) #define GPIO_LD3 (0x00000002)
#define GPIO_LD4 (0x00000004) #define GPIO_LD4 (0x00000004)
#define GPIO_LD5 (0x00000008) #define GPIO_LD5 (0x00000008)
#define GPIO_1W_DRIVELOW (0x00000010)
#endif /* __HW_GPIO_H */ #endif /* __HW_GPIO_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment