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 |
5 |
iztok |
// this header would be used if a proper file handler could be assidned,
|
36 |
|
|
// but due to global variables in the public domain kit, this is not possible
|
37 |
|
|
//#include <fcntl.h>
|
38 |
2 |
iztok |
|
39 |
|
|
#include "sys/alt_dev.h"
|
40 |
|
|
#include "sys/alt_irq.h"
|
41 |
|
|
#include "sys/ioctl.h"
|
42 |
|
|
#include "sys/alt_errno.h"
|
43 |
|
|
|
44 |
|
|
#include "sockit_owm_regs.h"
|
45 |
|
|
#include "sockit_owm.h"
|
46 |
|
|
|
47 |
|
|
extern sockit_owm_state sockit_owm;
|
48 |
|
|
|
49 |
|
|
#ifndef SOCKIT_OWM_POLLING
|
50 |
|
|
|
51 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
52 |
|
|
// interrupt implementation
|
53 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
|
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
56 |
|
|
static void sockit_owm_irq ();
|
57 |
|
|
#else
|
58 |
|
|
static void sockit_owm_irq (alt_u32 id);
|
59 |
|
|
#endif
|
60 |
|
|
|
61 |
|
|
void sockit_owm_init (alt_u32 irq)
|
62 |
|
|
{
|
63 |
|
|
int error;
|
64 |
3 |
iztok |
// initialize semaphore for 1-wire cycle locking
|
65 |
2 |
iztok |
error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
|
66 |
3 |
iztok |
ALT_SEM_CREATE (sockit_owm.cyc, 1);
|
67 |
2 |
iztok |
|
68 |
|
|
if (!error) {
|
69 |
3 |
iztok |
// enable interrupt
|
70 |
|
|
sockit_owm.ien = 0x1;
|
71 |
2 |
iztok |
// register the interrupt handler
|
72 |
|
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
73 |
|
|
alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
|
74 |
|
|
#else
|
75 |
|
|
alt_irq_register (irq, NULL, sockit_owm_irq);
|
76 |
|
|
#endif
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
|
81 |
|
|
static void sockit_owm_irq(void * state)
|
82 |
|
|
#else
|
83 |
|
|
static void sockit_owm_irq(void * state, alt_u32 id)
|
84 |
|
|
#endif
|
85 |
|
|
{
|
86 |
|
|
// clear onewire interrupts
|
87 |
5 |
iztok |
IORD_SOCKIT_OWM_CTL (sockit_owm.base);
|
88 |
3 |
iztok |
// set the flag indicating a completed 1-wire cycle
|
89 |
2 |
iztok |
ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
|
90 |
|
|
}
|
91 |
|
|
#else
|
92 |
|
|
|
93 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
// polling implementation
|
95 |
|
|
//////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
|
|
#endif
|