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 2

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

Line No. Rev Author Line
1 2 iztok
/******************************************************************************
2
*                                                                             *
3
* License Agreement                                                           *
4
*                                                                             *
5
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA.           *
6
* All rights reserved.                                                        *
7
*                                                                             *
8
* Permission is hereby granted, free of charge, to any person obtaining a     *
9
* copy of this software and associated documentation files (the "Software"),  *
10
* to deal in the Software without restriction, including without limitation   *
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
12
* and/or sell copies of the Software, and to permit persons to whom the       *
13
* Software is furnished to do so, subject to the following conditions:        *
14
*                                                                             *
15
* The above copyright notice and this permission notice shall be included in  *
16
* all copies or substantial portions of the Software.                         *
17
*                                                                             *
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
24
* DEALINGS IN THE SOFTWARE.                                                   *
25
*                                                                             *
26
* This agreement shall be governed in all respects by the laws of the State   *
27
* of California and by the laws of the United States of America.              *
28
*                                                                             *
29
******************************************************************************/
30
 
31
 
32
//////////////////////////////////////////////////////////////////////////////
33
//                                                                          //
34
//  Minimalistic 1-wire (onewire) master with Avalon MM bus interface       //
35
//                                                                          //
36
//  Copyright (C) 2010  Iztok Jeras                                         //
37
//                                                                          //
38
//////////////////////////////////////////////////////////////////////////////
39
//                                                                          //
40
//  This program is free software: you can redistribute it and/or modify    //
41
//  it under the terms of the GNU Lesser General Public License             //
42
//  as published by the Free Software Foundation, either                    //
43
//  version 3 of the License, or (at your option) any later version.        //
44
//                                                                          //
45
//  This program is distributed in the hope that it will be useful,         //
46
//  but WITHOUT ANY WARRANTY; without even the implied warranty of          //
47
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
48
//  GNU General Public License for more details.                            //
49
//                                                                          //
50
//  You should have received a copy of the GNU General Public License       //
51
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
52
//                                                                          //
53
//////////////////////////////////////////////////////////////////////////////
54
 
55
 
56
#include <fcntl.h>
57
 
58
#include "sys/alt_dev.h"
59
#include "sys/alt_irq.h"
60
#include "sys/ioctl.h"
61
#include "sys/alt_errno.h"
62
 
63
#include "sockit_owm_regs.h"
64
#include "sockit_owm.h"
65
 
66
extern sockit_owm_state sockit_owm;
67
 
68
#ifndef SOCKIT_OWM_POLLING
69
 
70
//////////////////////////////////////////////////////////////////////////////
71
// interrupt implementation
72
//////////////////////////////////////////////////////////////////////////////
73
 
74
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
75
static void sockit_owm_irq ();
76
#else
77
static void sockit_owm_irq (alt_u32 id);
78
#endif
79
 
80
void sockit_owm_init (alt_u32 irq)
81
{
82
  int error;
83
  // initialize semaphore for transfer locking
84
  // TODO there is a warning to fix here
85
  error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
86
          ALT_SEM_CREATE  (sockit_owm.trn, 1);
87
 
88
  if (!error) {
89
    // enable TX interrupt, RX is unused
90
    sockit_owm.ena = 0x1;
91
    // register the interrupt handler
92
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
93
    alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
94
#else
95
    alt_irq_register (irq, NULL, sockit_owm_irq);
96
#endif
97
  }
98
}
99
 
100
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
101
static void sockit_owm_irq(void * state)
102
#else
103
static void sockit_owm_irq(void * state, alt_u32 id)
104
#endif
105
{
106
  // clear onewire interrupts
107
  IORD_SOCKIT_OWM (sockit_owm.base);
108
  // set the flag indicating a completed transfer
109
  ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
110
}
111
#else
112
 
113
//////////////////////////////////////////////////////////////////////////////
114
// polling implementation
115
//////////////////////////////////////////////////////////////////////////////
116
 
117
#endif

powered by: WebSVN 2.1.0

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