Line 1... |
Line 1... |
/******************************************************************************
|
/******************************************************************************
|
* *
|
* *
|
|
* Minimalistic 1-wire (onewire) master with Avalon MM bus interface *
|
|
* Copyright (C) 2010 Iztok Jeras *
|
|
* Since the code is based on an Altera app note, I kept their license. *
|
|
* *
|
* License Agreement *
|
* License Agreement *
|
* *
|
* *
|
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
|
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
|
* All rights reserved. *
|
* All rights reserved. *
|
* *
|
* *
|
Line 27... |
Line 31... |
* of California and by the laws of the United States of America. *
|
* of California and by the laws of the United States of America. *
|
* *
|
* *
|
******************************************************************************/
|
******************************************************************************/
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// //
|
|
// Minimalistic 1-wire (onewire) master with Avalon MM bus interface //
|
|
// //
|
|
// Copyright (C) 2010 Iztok Jeras //
|
|
// //
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// //
|
|
// 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, either //
|
|
// version 3 of the License, or (at your option) any later version. //
|
|
// //
|
|
// 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 General Public License //
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
// //
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#include <fcntl.h>
|
#include <fcntl.h>
|
|
|
#include "sys/alt_dev.h"
|
#include "sys/alt_dev.h"
|
#include "sys/alt_irq.h"
|
#include "sys/alt_irq.h"
|
#include "sys/ioctl.h"
|
#include "sys/ioctl.h"
|
Line 78... |
Line 58... |
#endif
|
#endif
|
|
|
void sockit_owm_init (alt_u32 irq)
|
void sockit_owm_init (alt_u32 irq)
|
{
|
{
|
int error;
|
int error;
|
// initialize semaphore for transfer locking
|
// initialize semaphore for 1-wire cycle locking
|
// TODO there is a warning to fix here
|
|
error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
|
error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
|
ALT_SEM_CREATE (sockit_owm.trn, 1);
|
ALT_SEM_CREATE (sockit_owm.cyc, 1);
|
|
|
if (!error) {
|
if (!error) {
|
// enable TX interrupt, RX is unused
|
// enable interrupt
|
sockit_owm.ena = 0x1;
|
sockit_owm.ien = 0x1;
|
// register the interrupt handler
|
// register the interrupt handler
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
|
alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
|
#else
|
#else
|
alt_irq_register (irq, NULL, sockit_owm_irq);
|
alt_irq_register (irq, NULL, sockit_owm_irq);
|
Line 103... |
Line 82... |
static void sockit_owm_irq(void * state, alt_u32 id)
|
static void sockit_owm_irq(void * state, alt_u32 id)
|
#endif
|
#endif
|
{
|
{
|
// clear onewire interrupts
|
// clear onewire interrupts
|
IORD_SOCKIT_OWM (sockit_owm.base);
|
IORD_SOCKIT_OWM (sockit_owm.base);
|
// set the flag indicating a completed transfer
|
// set the flag indicating a completed 1-wire cycle
|
ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
|
ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
|
}
|
}
|
#else
|
#else
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|