OpenCores
URL https://opencores.org/ocsvn/sockit_owm/sockit_owm/trunk

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [HAL/] [src/] [sockit_owm.c] - Diff between revs 2 and 3

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 3
/******************************************************************************
/******************************************************************************
*                                                                             *
*                                                                             *
 
* 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.                                                        *
*                                                                             *
*                                                                             *
* Permission is hereby granted, free of charge, to any person obtaining a     *
* Permission is hereby granted, free of charge, to any person obtaining a     *
* copy of this software and associated documentation files (the "Software"),  *
* copy of this software and associated documentation files (the "Software"),  *
* to deal in the Software without restriction, including without limitation   *
* to deal in the Software without restriction, including without limitation   *
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
* and/or sell copies of the Software, and to permit persons to whom the       *
* and/or sell copies of the Software, and to permit persons to whom the       *
* Software is furnished to do so, subject to the following conditions:        *
* Software is furnished to do so, subject to the following conditions:        *
*                                                                             *
*                                                                             *
* The above copyright notice and this permission notice shall be included in  *
* The above copyright notice and this permission notice shall be included in  *
* all copies or substantial portions of the Software.                         *
* all copies or substantial portions of the Software.                         *
*                                                                             *
*                                                                             *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
* DEALINGS IN THE SOFTWARE.                                                   *
* DEALINGS IN THE SOFTWARE.                                                   *
*                                                                             *
*                                                                             *
* This agreement shall be governed in all respects by the laws of the State   *
* This agreement shall be governed in all respects by the laws of the State   *
* 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"
#include "sys/alt_errno.h"
#include "sys/alt_errno.h"
 
 
#include "sockit_owm_regs.h"
#include "sockit_owm_regs.h"
#include "sockit_owm.h"
#include "sockit_owm.h"
 
 
extern sockit_owm_state sockit_owm;
extern sockit_owm_state sockit_owm;
 
 
#ifndef SOCKIT_OWM_POLLING
#ifndef SOCKIT_OWM_POLLING
 
 
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// interrupt implementation
// interrupt implementation
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 
 
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void sockit_owm_irq ();
static void sockit_owm_irq ();
#else
#else
static void sockit_owm_irq (alt_u32 id);
static void sockit_owm_irq (alt_u32 id);
#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);
#endif
#endif
  }
  }
}
}
 
 
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void sockit_owm_irq(void * state)
static void sockit_owm_irq(void * state)
#else
#else
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
 
 
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// polling implementation
// polling implementation
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.