Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
hardwareAccess.h
Go to the documentation of this file.
1 /**
2  *****************************************************************************
3  * @file hardwareAccess.h
4  * @author Michael Riedel
5  * @author Marc Kossmann
6  * @version v1.0.0
7  * @date 11.11.2014
8  * @brief Functions for accessing hardware connected through pio´s and
9  * registers
10  *****************************************************************************
11  * @par History:
12  * @details v0.1.0 21.10.2014 Riedel & Kossmann
13  * - first draft for milestone 1b
14  * @details v0.1.1 29.10.2014 Kossmann
15  * - renewed complete pio access concept
16  * @details v0.1.2 31.10.2014 Riedel & Kossmann
17  * - added missing var type in hex functions
18  * @details v1.0.0 31.10.2014 Kossmann
19  * - added function to clear edgecapture of switches
20  *****************************************************************************
21  */
22 
23 #ifndef __HARDWAREACCESS_H__
24 #define __HARDWAREACCESS_H__
25 
26 #include <stdint.h>
27 #include <system.h>
28 #include <altera_avalon_pio_regs.h>
29 
30 #define PIO_KEY_RS_IR0_MSK (0b0001) //!< Run/Stop mask for PIO-Key
31 #define PIO_KEY_MINUS_IR2_MSK (0b0100) //!< Increase steps mask for PIO-Key
32 #define PIO_KEY_PLUS_IR3_MSK (0b1000) //!< Decreses steps mask for PIO-Key
33 #define PIO_SW_LR_MSK (0b0000000001) //!< Left/Right mask for PIO-Switches
34 #define PIO_SW_MODE_MSK (0b0000011110) //!< Mode mask for PIO-Switches
35 #define PIO_SW_DEBUG_MSK (0b1000000000) //!< Debug mask for PIO-Switches
36 
37 /**
38  * @name keys
39  */
40 
41 /**
42  * @brief Function to enable interrupts for pio key
43  * @param enablebits : set bits to `1` for enable interrupt
44  * @retval None
45  */
46 static __inline__ void PIO_KEY_SetIRMsk(uint32_t enablebits) {
47  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_KEY_BASE, enablebits);
48 }
49 
50 /**
51  * @brief Function to clear bits of keys edgecapture register
52  * @param clearbits : set bits to `1` for enable interrupt
53  * @retval none
54  */
55 static __inline__ void PIO_KEY_ClearEdgeCptBits(uint32_t clearbits) {
56  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_BASE, clearbits);
57 }
58 
59 /**
60  * @brief Function to read content of keys edgecapture register
61  * @retval pressedKeys : When edge was detected, bit is `1`
62  */
63 static __inline__ uint32_t PIO_KEY_GetEdgeCpt(void) {
64  return (IORD_ALTERA_AVALON_PIO_EDGE_CAP(PIO_KEY_BASE));
65 }
66 
67 /**
68  * @name sliding switches
69  */
70 
71 /**
72  * @brief Function to enable interrupts for pio sw
73  * @param enablebits : set bits to `1` for enable interrupt
74  * @retval None
75  */
76 static __inline__ void PIO_SW_SetIRMsk(uint32_t enablebits) {
77  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_SW_BASE, enablebits);
78 }
79 
80 /**
81  * @brief Function to clear bits of switches edgecapture register
82  * @param clearbits : set bits to `1` for clearing interrupt
83  * @retval none
84  */
85 static __inline__ void PIO_SW_ClearEdgeCptBits(uint32_t clearbits) {
86  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_SW_BASE, clearbits);
87 }
88 
89 /**
90  * @brief Function to read content of switches data register
91  * @retval switchesValues : Values of all switches
92  * @arg 0 = Switch OFF
93  * @arg 1 = Switch ON
94  */
95 static __inline__ uint32_t PIO_SW_GetValues(void) {
96  return (IORD_ALTERA_AVALON_PIO_DATA(PIO_SW_BASE));
97 }
98 
99 /**
100  * @name red LED_9 (heartbeat)
101  */
102 
103 /**
104  * @brief Function to set led9 for heartbeat
105  * @param ledValue : Value for LED9
106  * @arg 0 = LED OFF
107  * @arg 1 = LED ON
108  * @retval none
109  */
110 static __inline__ void PIO_LED9_Set(uint32_t ledValue) {
111  IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED9_BASE, ledValue);
112 }
113 
114 /**
115  * @name 7-segment hex displays
116  */
117 
118 /**
119  * @brief Function to set segments on hex0 display
120  * @param segmentValues : Values for all seven segments
121  * @arg 0 = segment OFF
122  * @arg 1 = segment ON
123  * @retval none
124  */
125 static __inline__ void PIO_HEX0_Set(uint32_t segmentValues) {
126  IOWR_ALTERA_AVALON_PIO_DATA(PIO_HEX0_BASE, ~segmentValues);
127 }
128 
129 /**
130  * @brief Function to set segments on hex1 display
131  * @param segmentValues : Values for all seven segments
132  * @arg 0 = segment OFF
133  * @arg 1 = segment ON
134  * @retval none
135  */
136 static __inline__ void PIO_HEX1_Set(uint32_t segmentValues) {
137  IOWR_ALTERA_AVALON_PIO_DATA(PIO_HEX1_BASE, ~segmentValues);
138 }
139 
140 /**
141  * @brief Function to set segments on hex2 display
142  * @param segmentValues : Values for all seven segments
143  * @arg 0 = segment OFF
144  * @arg 1 = segment ON
145  * @retval none
146  */
147 static __inline__ void PIO_HEX2_Set(uint32_t segmentValues) {
148  IOWR_ALTERA_AVALON_PIO_DATA(PIO_HEX2_BASE, ~segmentValues);
149 }
150 
151 /**
152  * @brief Function to set segments on hex3 display
153  * @param segmentValues : Values for all seven segments
154  * @arg 0 = segment OFF
155  * @arg 1 = segment ON
156  * @retval none
157  */
158 static __inline__ void PIO_HEX3_Set(uint32_t segmentValues) {
159  IOWR_ALTERA_AVALON_PIO_DATA(PIO_HEX3_BASE, ~segmentValues);
160 }
161 
162 #endif // __HARDWAREACCESS_H__
static __inline__ void PIO_KEY_SetIRMsk(uint32_t enablebits)
Function to enable interrupts for pio key.
static __inline__ void PIO_HEX1_Set(uint32_t segmentValues)
Function to set segments on hex1 display.
static __inline__ void PIO_HEX2_Set(uint32_t segmentValues)
Function to set segments on hex2 display.
static __inline__ void PIO_KEY_ClearEdgeCptBits(uint32_t clearbits)
Function to clear bits of keys edgecapture register.
static __inline__ void PIO_HEX3_Set(uint32_t segmentValues)
Function to set segments on hex3 display.
static __inline__ void PIO_LED9_Set(uint32_t ledValue)
Function to set led9 for heartbeat.
static __inline__ void PIO_SW_SetIRMsk(uint32_t enablebits)
Function to enable interrupts for pio sw.
static __inline__ uint32_t PIO_SW_GetValues(void)
Function to read content of switches data register.
static __inline__ uint32_t PIO_KEY_GetEdgeCpt(void)
Function to read content of keys edgecapture register.
static __inline__ void PIO_SW_ClearEdgeCptBits(uint32_t clearbits)
Function to clear bits of switches edgecapture register.
static __inline__ void PIO_HEX0_Set(uint32_t segmentValues)
Function to set segments on hex0 display.