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

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [HAL/] [inc/] [sockit_owm.h] - Blame information for rev 3

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
#ifndef __SOCKIT_OWM_H__
37
#define __SOCKIT_OWM_H__
38
 
39
#include <stddef.h>
40
 
41
#include "sys/alt_warning.h"
42
 
43
#include "os/alt_sem.h"
44
#include "os/alt_flag.h"
45
#include "alt_types.h"
46
 
47
#ifdef __cplusplus
48
extern "C"
49
{
50 3 iztok
#endif // __cplusplus
51 2 iztok
 
52 3 iztok
//////////////////////////////////////////////////////////////////////////////
53
// global structure containing the current state of the sockit_owm driver
54
//////////////////////////////////////////////////////////////////////////////
55 2 iztok
 
56
typedef struct sockit_owm_state_s
57
{
58 3 iztok
  void*            base;            // The base address of the device
59 2 iztok
  // constants
60 3 iztok
  alt_u32          ovd_e;           // Overdrive mode               implementation enable
61
  alt_u32          cdr_e;           // Clock divider ratio register implementation enable
62 2 iztok
  alt_u32          own;             // Number of onewire ports
63 3 iztok
  char             btp_n[3];        // base time period for normal    mode
64
  char             btp_o[3];        // base time period for overdrive mode
65
  // clock divider ratio
66
  alt_u32          cdr_n;           // cdr for normal    mode
67
  alt_u32          cdr_o;           // cdr for overdrive mode
68
  alt_u32          f_dly;           // u16.16 1/ms (inverse of delay time)
69 2 iztok
  // status
70 3 iztok
  alt_u32          ien;             // interrupt enable status
71 2 iztok
  alt_u32          use;             // Aquire status
72
  alt_u32          ovd;             // Overdrive status
73
  alt_u32          pwr;             // Power status
74
  // OS multitasking features
75 3 iztok
  ALT_FLAG_GRP    (irq)             // interrupt event flag
76
  ALT_SEM         (cyc)             // transfer lock semaphore
77 2 iztok
} sockit_owm_state;
78
 
79 3 iztok
//////////////////////////////////////////////////////////////////////////////
80
// instantiation macro
81
// can be used oly once, since the driver is based on global variables
82
//////////////////////////////////////////////////////////////////////////////
83 2 iztok
 
84
#define SOCKIT_OWM_INSTANCE(name, state) \
85 3 iztok
  sockit_owm_state sockit_owm = { (void*) name##_BASE,  \
86
                                          name##_OVD_E, \
87
                                          name##_CDR_E, \
88
                                          name##_OWN,   \
89
                                          name##_BTP_N, \
90
                                          name##_BTP_O, \
91
                                          name##_CDR_N, \
92
                                          name##_CDR_O, \
93
                                          name##_F_DLY, \
94
                                          0, 0, 0, 0};  \
95 2 iztok
  void* state = (void*) name##_BASE
96
 
97 3 iztok
//////////////////////////////////////////////////////////////////////////////
98
// initialization function, registers the interrupt handler
99
//////////////////////////////////////////////////////////////////////////////
100
 
101 2 iztok
extern void sockit_owm_init(alt_u32 irq);
102
 
103 3 iztok
//////////////////////////////////////////////////////////////////////////////
104
// initialization macro
105
//////////////////////////////////////////////////////////////////////////////
106
 
107 2 iztok
#ifndef SOCKIT_OWM_POLLING
108
#define SOCKIT_OWM_INIT(name, state)                                       \
109
  if (name##_IRQ == ALT_IRQ_NOT_CONNECTED)                                 \
110
  {                                                                        \
111
    ALT_LINK_ERROR ("Error: Interrupt not connected for " #name ". "       \
112
                    "You have selected the interrupt driven version of "   \
113 3 iztok
                    "the sockit_owm (SoCkit 1-wire master) driver, but "   \
114 2 iztok
                    "the interrupt is not connected for this device. You " \
115
                    "can select a polled mode driver by checking the "     \
116
                    "'small driver' option in the HAL configuration "      \
117 3 iztok
                    "window, or by using the -DSOCKIT_OWM_POLLING "        \
118 2 iztok
                    "preprocessor flag.");                                 \
119
  }                                                                        \
120
  else                                                                     \
121
  {                                                                        \
122
    sockit_owm_init(name##_IRQ);                                           \
123
  }
124
#else
125
#define SOCKIT_OWM_INIT(name, state)
126
#endif
127
 
128
#ifdef __cplusplus
129
}
130 3 iztok
#endif // __cplusplus
131 2 iztok
 
132 3 iztok
#endif // __SOCKIT_OWM_H__

powered by: WebSVN 2.1.0

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