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

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [HAL/] [src/] [sockit_owm.c] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 iztok
/******************************************************************************
2
*                                                                             *
3 3 iztok
* Minimalistic 1-wire (onewire) master with Avalon MM bus interface           *
4
* Copyright (C) 2010  Iztok Jeras                                             *
5
* Since the code is based on an Altera app note, I kept their license.        *
6
*                                                                             *
7 2 iztok
* License Agreement                                                           *
8
*                                                                             *
9
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA.           *
10
* All rights reserved.                                                        *
11
*                                                                             *
12
* Permission is hereby granted, free of charge, to any person obtaining a     *
13
* copy of this software and associated documentation files (the "Software"),  *
14
* to deal in the Software without restriction, including without limitation   *
15
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
16
* and/or sell copies of the Software, and to permit persons to whom the       *
17
* Software is furnished to do so, subject to the following conditions:        *
18
*                                                                             *
19
* The above copyright notice and this permission notice shall be included in  *
20
* all copies or substantial portions of the Software.                         *
21
*                                                                             *
22
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
23
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
24
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
25
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
26
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
27
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
28
* DEALINGS IN THE SOFTWARE.                                                   *
29
*                                                                             *
30
* This agreement shall be governed in all respects by the laws of the State   *
31
* of California and by the laws of the United States of America.              *
32
*                                                                             *
33
******************************************************************************/
34
 
35
 
36
#include <fcntl.h>
37
 
38
#include "sys/alt_dev.h"
39
#include "sys/alt_irq.h"
40
#include "sys/ioctl.h"
41
#include "sys/alt_errno.h"
42
 
43
#include "sockit_owm_regs.h"
44
#include "sockit_owm.h"
45
 
46
extern sockit_owm_state sockit_owm;
47
 
48
#ifndef SOCKIT_OWM_POLLING
49
 
50
//////////////////////////////////////////////////////////////////////////////
51
// interrupt implementation
52
//////////////////////////////////////////////////////////////////////////////
53
 
54
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
55
static void sockit_owm_irq ();
56
#else
57
static void sockit_owm_irq (alt_u32 id);
58
#endif
59
 
60
void sockit_owm_init (alt_u32 irq)
61
{
62
  int error;
63 3 iztok
  // initialize semaphore for 1-wire cycle locking
64 2 iztok
  error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
65 3 iztok
          ALT_SEM_CREATE  (sockit_owm.cyc, 1);
66 2 iztok
 
67
  if (!error) {
68 3 iztok
    // enable interrupt
69
    sockit_owm.ien = 0x1;
70 2 iztok
    // register the interrupt handler
71
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
72
    alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
73
#else
74
    alt_irq_register (irq, NULL, sockit_owm_irq);
75
#endif
76
  }
77
}
78
 
79
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
80
static void sockit_owm_irq(void * state)
81
#else
82
static void sockit_owm_irq(void * state, alt_u32 id)
83
#endif
84
{
85
  // clear onewire interrupts
86
  IORD_SOCKIT_OWM (sockit_owm.base);
87 3 iztok
  // set the flag indicating a completed 1-wire cycle
88 2 iztok
  ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
89
}
90
#else
91
 
92
//////////////////////////////////////////////////////////////////////////////
93
// polling implementation
94
//////////////////////////////////////////////////////////////////////////////
95
 
96
#endif

powered by: WebSVN 2.1.0

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