source: ReferenceDesigns/w3_802.11/c/wlan_w3_common/w3_userio_util.c

Last change on this file was 6319, checked in by chunter, 6 years ago

1.8.0 release wlan-mac-se

File size: 12.2 KB
Line 
1/** @file wlan_mac_misc_util.c
2 *  @brief Miscellaneous Utilities
3 *
4 *  This contains code common to both CPU_LOW and CPU_HIGH that allows them
5 *  to interact with the MAC Time and User IO cores.
6 *
7 *  @copyright Copyright 2013-2019, Mango Communications. All rights reserved.
8 *          Distributed under the Mango Communications Reference Design License
9 *              See LICENSE.txt included in the design archive or
10 *              at http://mangocomm.com/802.11/license
11 *
12 *  This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11)
13 */
14
15/***************************** Include Files *********************************/
16
17#include "w3_userio.h"
18#include "include/w3_userio_util.h"
19#include "wlan_platform_common.h"
20#include "xparameters.h"
21
22
23/*********************** Global Variable Definitions *************************/
24
25
26/*************************** Variable Definitions ****************************/
27
28
29/*************************** Functions Prototypes ****************************/
30
31
32/******************************** Functions **********************************/
33
34
35/*****************************************************************************/
36/**
37 * @brief Mapping of hexadecimal values to the 7-segment display
38 *
39 * @param   hex_value        - Hexadecimal value to be converted (between 0 and 15)
40 * @return  u8               - LED map value of the 7-segment display
41 */
42u8 hex_to_seven_segment(u8 hex_value) {
43    switch(hex_value) {
44        case(0x0) : return 0x3F;
45        case(0x1) : return 0x06;
46        case(0x2) : return 0x5B;
47        case(0x3) : return 0x4F;
48        case(0x4) : return 0x66;
49        case(0x5) : return 0x6D;
50        case(0x6) : return 0x7D;
51        case(0x7) : return 0x07;
52        case(0x8) : return 0x7F;
53        case(0x9) : return 0x6F;
54
55        case(0xA) : return 0x77;
56        case(0xB) : return 0x7C;
57        case(0xC) : return 0x39;
58        case(0xD) : return 0x5E;
59        case(0xE) : return 0x79;
60        case(0xF) : return 0x71;
61        default   : return 0x00;
62    }
63}
64
65
66
67/*****************************************************************************/
68/**
69 * @brief Enable the PWM functionality of the hex display
70 *
71 * This function will tell the User I/O to enable the PWM to pulse the hex display.
72 *
73 * @param   None
74 * @return  None
75 */
76void enable_hex_pwm() {
77    userio_set_pwm_ramp_en(USERIO_BASEADDR, 1);
78}
79
80
81
82/*****************************************************************************/
83/**
84 * @brief Disable the PWM functionality of the hex display
85 *
86 * This function will tell the User I/O to disable the PWM to pulse the hex display.
87 *
88 * @param   None
89 * @return  None
90 */
91void disable_hex_pwm() {
92    userio_set_pwm_ramp_en(USERIO_BASEADDR, 0);
93}
94
95
96
97/*****************************************************************************/
98/**
99 * @brief Set the PWM period for the Hex display
100 *
101 * This function will set the period used to pulse the hex display
102 *
103 * @param   period           - Period of the PWM ramp (u16)
104 * @return  None
105 */
106void set_hex_pwm_period(u16 period) {
107    userio_set_pwm_period(USERIO_BASEADDR, period);
108}
109
110
111
112/*****************************************************************************/
113/**
114 * @brief Set the Min / Max timing for the PWM ramp
115 *
116 * This function will set the Min / Max timing parameters for the PWM pulse of
117 * the hex display.  The values should be less that the period set by
118 * set_hex_pwm_period(), but that condition is not enforced.
119 *
120 * @param   min              - Timing parameter for when the PWM reaches minimum value (u16)
121 * @param   max              - Timing parameter for when the PWM reaches maximum value (u16)
122 * @return  None
123 *
124 * @note   This function will disable the PWM.  Therefore, the PWM must be enabled
125 *     after calling this function.
126 */
127void set_hex_pwm_min_max(u16 min, u16 max) {
128    // Ramp must be disabled when changing ramp params
129    userio_set_pwm_ramp_en(USERIO_BASEADDR, 0);
130    userio_set_pwm_ramp_min(USERIO_BASEADDR, min);
131    userio_set_pwm_ramp_max(USERIO_BASEADDR, max);
132}
133
134
135
136/*****************************************************************************/
137/**
138 * @brief Write a Decimal Value to the Hex Display
139 *
140 * This function will write a decimal value to the board's two-digit hex displays.
141 * The display is right justified; WLAN Exp will indicate its connection state
142 * using the right decimal point.
143 *
144 * @param   val              - Value to be displayed
145 *                                 0 -  99: Displayed normally
146 *                                99 - 254: "00" displayed
147 *                                     255: "--" displayed
148 * @return  None
149 */
150void write_hex_display(u8 val) {
151    u32 right_dp;
152    u8 left_val;
153    u8 right_val;
154
155    // Need to retain the value of the right decimal point
156    right_dp = userio_read_hexdisp_right(USERIO_BASEADDR) & W3_USERIO_HEXDISP_DP;
157
158    userio_write_control(USERIO_BASEADDR, (userio_read_control(USERIO_BASEADDR) & (~(W3_USERIO_HEXDISP_L_MAPMODE | W3_USERIO_HEXDISP_R_MAPMODE))));
159
160    if (val < 10) {
161        left_val  = 0;
162        right_val = hex_to_seven_segment(val);
163    } else {
164        if (val < 100) {
165            left_val  = hex_to_seven_segment(((val / 10) % 10));
166            right_val = hex_to_seven_segment((val % 10));
167        } else {
168            if (val != 255) {
169                left_val  = hex_to_seven_segment(0x00);
170                right_val = hex_to_seven_segment(0x00);
171            } else {
172                left_val  = 0x40;
173                right_val = 0x40;
174            }
175        }
176    }
177
178    userio_write_hexdisp_left(USERIO_BASEADDR, left_val);
179    userio_write_hexdisp_right(USERIO_BASEADDR, (right_val | right_dp));
180}
181
182
183
184/*****************************************************************************/
185/**
186 * @brief Write a Decimal Value to the Hex Display with PWM pulsing
187 *
188 * This function will write a decimal value to the board's two-digit hex displays.
189 * The display is right justified and will pulse using the pwms; WLAN Exp will
190 * indicate its connection state using the right decimal point.
191 *
192 * @param   val              - Value to be displayed
193 *                                 0 -  99: Displayed normally
194 *                                99 - 254: "00" displayed
195 *                                     255: "--" displayed
196 * @return  None
197 */
198void write_hex_display_with_pwm(u8 val) {
199    u32 hw_control;
200    u32 temp_control;
201    u32 right_dp;
202    u8 left_val;
203    u8 right_val;
204    u32 pwm_val;
205
206    // Need to retain the value of the right decimal point
207    right_dp = userio_read_hexdisp_right(USERIO_BASEADDR) & W3_USERIO_HEXDISP_DP;
208
209    if (val < 10) {
210        left_val  = 0;
211        right_val = hex_to_seven_segment(val);
212    } else {
213        if (val < 100) {
214            left_val  = hex_to_seven_segment(((val / 10) % 10));
215            right_val = hex_to_seven_segment((val % 10));
216        } else {
217            if (val != 255) {
218                left_val  = hex_to_seven_segment(0x00);
219                right_val = hex_to_seven_segment(0x00);
220            } else {
221                left_val  = 0x40;
222                right_val = 0x40;
223            }
224        }
225    }
226
227    // Store the original value of what is under HW control
228    hw_control   = userio_read_control(USERIO_BASEADDR);
229
230    // Need to zero out all of the HW control of the hex displays; Change to raw hex mode
231    temp_control = (hw_control & (~(W3_USERIO_HEXDISP_L_MAPMODE | W3_USERIO_HEXDISP_R_MAPMODE | W3_USERIO_CTRLSRC_HEXDISP_R | W3_USERIO_CTRLSRC_HEXDISP_L)));
232
233    // Set the hex display mode to raw bits
234    userio_write_control(USERIO_BASEADDR, temp_control);
235
236    // Write the display
237    userio_write_hexdisp_left(USERIO_BASEADDR, left_val);
238    userio_write_hexdisp_right(USERIO_BASEADDR, (right_val | right_dp));
239
240    pwm_val   = (right_val << 8) + left_val;
241
242    // Set the HW / SW control of the user io (raw mode w/ the new display value)
243    userio_write_control(USERIO_BASEADDR, (temp_control | pwm_val));
244
245    // Set the pins that are using PWM mode
246    userio_set_hw_ctrl_mode_pwm(USERIO_BASEADDR, pwm_val);
247}
248
249
250
251/*****************************************************************************/
252/**
253 * @brief Set Error Status for Node
254 *
255 * Function will set the hex display to be "Ex", where x is the value of the
256 * status error
257 *
258 * @param   status           - Number from 0 - 0xF to indicate status error
259 * @return  None
260 */
261void set_hex_display_error_status(u8 status) {
262    u32 right_dp;
263
264    // Need to retain the value of the right decimal point
265    right_dp = userio_read_hexdisp_right(USERIO_BASEADDR) & W3_USERIO_HEXDISP_DP;
266
267    userio_write_control(USERIO_BASEADDR, (userio_read_control(USERIO_BASEADDR) & (~(W3_USERIO_HEXDISP_L_MAPMODE | W3_USERIO_HEXDISP_R_MAPMODE))));
268
269    userio_write_hexdisp_left(USERIO_BASEADDR,  hex_to_seven_segment(0xE));
270    userio_write_hexdisp_right(USERIO_BASEADDR, (hex_to_seven_segment(status % 16) | right_dp));
271}
272
273
274
275/*****************************************************************************/
276/**
277 * @brief Blink LEDs
278 *
279 * For WARP v3 Hardware, this function will blink the hex display.
280 *
281 * @param   num_blinks       - Number of blinks (0 means blink forever)
282 * @param   blink_time       - Time in microseconds between blinks
283 *
284 * @return  None
285 */
286void blink_hex_display(u32 num_blinks, u32 blink_time) {
287    u32 i;
288    u32 hw_control;
289    u32 temp_control;
290    u8 right_val;
291    u8 left_val;
292
293    // Get left / right values
294    left_val  = userio_read_hexdisp_left(USERIO_BASEADDR);
295    right_val = userio_read_hexdisp_right(USERIO_BASEADDR);
296
297    // Store the original value of what is under HW control
298    hw_control   = userio_read_control(USERIO_BASEADDR);
299
300    // Need to zero out all of the HW control of the hex displays; Change to raw hex mode
301    temp_control = (hw_control & (~(W3_USERIO_HEXDISP_L_MAPMODE | W3_USERIO_HEXDISP_R_MAPMODE | W3_USERIO_CTRLSRC_HEXDISP_R | W3_USERIO_CTRLSRC_HEXDISP_L)));
302
303    // Set the hex display mode to raw bits
304    userio_write_control(USERIO_BASEADDR, temp_control);
305
306    // Use wlan_usleep to blink the display
307    if (num_blinks > 0) {
308        // Perform standard blink
309        for (i = 0; i < num_blinks; i++) {
310            userio_write_hexdisp_left(USERIO_BASEADDR,  (((i % 2) == 0) ? left_val  : 0x00));
311            userio_write_hexdisp_right(USERIO_BASEADDR, (((i % 2) == 0) ? right_val : 0x00));
312            wlan_usleep(blink_time);
313        }
314    } else {
315        // Perform an infinite blink
316        i = 0;
317        while (1) {
318            userio_write_hexdisp_left(USERIO_BASEADDR,  (((i % 2) == 0) ? left_val  : 0x00));
319            userio_write_hexdisp_right(USERIO_BASEADDR, (((i % 2) == 0) ? right_val : 0x00));
320            wlan_usleep(blink_time);
321            i++;
322        }
323    }
324
325    // Set control back to original value
326    userio_write_control( USERIO_BASEADDR, hw_control );
327}
328
329
330
331/*****************************************************************************/
332/**
333 * @brief Set Right Decimal Point on the Hex Display
334 *
335 * This function will set the right decimal point on the hex display
336 *
337 * @param   val              - 0 - Clear decimal point; 1 - Set decimal point
338 * @return  None
339 */
340void set_hex_display_right_dp(u8 val) {
341    if (val) {
342        userio_write_hexdisp_right(USERIO_BASEADDR, (userio_read_hexdisp_right(USERIO_BASEADDR) | W3_USERIO_HEXDISP_DP));
343    } else {
344        userio_write_hexdisp_right(USERIO_BASEADDR, (userio_read_hexdisp_right(USERIO_BASEADDR) & ~W3_USERIO_HEXDISP_DP));
345    }
346}
347
348
349
350/*****************************************************************************/
351/**
352 * @brief Set Left Decimal Point on the Hex Display
353 *
354 * This function will set the left decimal point on the hex display
355 *
356 * @param   val              - 0 - Clear decimal point; 1 - Set decimal point
357 * @return  None
358 */
359void set_hex_display_left_dp(u8 val) {
360    if (val) {
361        userio_write_hexdisp_left(USERIO_BASEADDR, (userio_read_hexdisp_left(USERIO_BASEADDR) | W3_USERIO_HEXDISP_DP));
362    } else {
363        userio_write_hexdisp_left(USERIO_BASEADDR, (userio_read_hexdisp_left(USERIO_BASEADDR) & ~W3_USERIO_HEXDISP_DP));
364    }
365}
366
367
Note: See TracBrowser for help on using the repository browser.