OpenNSL API Guide and Reference Manual
example_led.c
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * (C) Copyright Broadcom Corporation 2013-2017
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **********************************************************************
18  *
19  * \file example_led.c
20  *
21  * \brief OpenNSL example application for LED programming
22  *
23  * \details Example program for demonstrating the programmability of
24  * LED processor using OpenNSL APIs
25  *
26  **********************************************************************/
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sal/driver.h>
32 #include <sal/pci.h>
33 #include <opennsl/port.h>
34 #include <opennsl/error.h>
35 #include <examples/util.h>
36 
37 #define DEFAULT_UNIT 0
38 
39 char example_usage[] =
40 "Syntax: example_led \n\r"
41 " \n\r"
42 "Paramaters: None \n\r"
43 " \n\r"
44 "Example: The following command is used to run the led programming \n\r"
45 " application. \n\r"
46 " example_led \n\r"
47 " \n\r";
48 
49 
50 #define EXAMPLE_LED0_PROGRAM_RAM_SIZE 112
51 #define EXAMPLE_LED1_PROGRAM_RAM_SIZE 176
52 
53 typedef struct led_info_s {
58 } led_info_t;
59 /* __doxy_func_body_end__ */
60 
61 static led_info_t led_info_cmicm[] = {
66 };
67 /* __doxy_func_body_end__ */
68 
70  0x06,0xFE,0x80,0xD2,0x19,0x71,0x08,0xE0,0x60,0xFE,0xE9,0xD2,0x0F,0x75,0x10,0x81,\
71  0x61,0xFD,0x02,0x3F,0x60,0xFF,0x28,0x32,0x0F,0x87,0x67,0x4A,0x96,0xFF,0x06,0xFF,\
72  0xD2,0x2B,0x74,0x16,0x02,0x1F,0x60,0xFF,0x28,0x32,0x0F,0x87,0x67,0x4A,0x96,0xFF,\
73  0x06,0xFF,0xD2,0x13,0x74,0x28,0x02,0x0F,0x60,0xFF,0x28,0x32,0x0F,0x87,0x67,0x4A,\
74  0x96,0xFF,0x06,0xFF,0xD2,0x0B,0x74,0x3A,0x3A,0x48,0x32,0x07,0x32,0x08,0xC7,0x32,\
75  0x04,0xC7,0x97,0x71,0x57,0x77,0x69,0x32,0x00,0x32,0x01,0xB7,0x97,0x71,0x63,0x32,\
76  0x0E,0x77,0x6B,0x26,0xFD,0x97,0x27,0x77,0x6B,0x32,0x0F,0x87,0x57,0x00,0x00,0x00};
77 /* __doxy_func_body_end__ */
78 
80  0x06,0xFE,0x80,0xD2,0x19,0x71,0x08,0xE0,0x60,0xFE,0xE9,0xD2,0x0F,0x75,0x10,0x81,\
81  0x61,0xFD,0x02,0x20,0x67,0x89,0x02,0x24,0x67,0x89,0x02,0x10,0x67,0x89,0x02,0x28,\
82  0x67,0x89,0x02,0x2C,0x67,0x89,0x02,0x0C,0x67,0x89,0x02,0x2C,0x67,0x79,0x02,0x28,\
83  0x67,0x79,0x02,0x24,0x67,0x79,0x02,0x20,0x67,0x79,0x02,0x10,0x67,0x79,0x02,0x0C,\
84  0x67,0x79,0x02,0x0B,0x60,0xFF,0x28,0x32,0x0F,0x87,0x67,0x56,0x96,0xFF,0x06,0xFF,\
85  0xD2,0xFF,0x74,0x46,0x3A,0x36,0x32,0x07,0x32,0x08,0xC7,0x32,0x04,0xC7,0x97,0x71,\
86  0x63,0x77,0x75,0x32,0x00,0x32,0x01,0xB7,0x97,0x71,0x6F,0x32,0x0E,0x77,0x77,0x26,\
87  0xFD,0x97,0x27,0x77,0x77,0x32,0x0F,0x87,0x57,0x12,0xA0,0xF8,0x15,0x1A,0x01,0x75,\
88  0x85,0x28,0x67,0x56,0x57,0x32,0x0F,0x87,0x57,0x12,0xA0,0xF8,0x15,0x1A,0x01,0x71,\
89  0xA1,0x28,0x67,0x56,0x80,0x28,0x67,0x56,0x80,0x28,0x67,0x56,0x80,0x28,0x67,0x56,\
90  0x57,0x32,0x0F,0x87,0x32,0x0F,0x87,0x32,0x0F,0x87,0x32,0x0F,0x87,0x57,0x00,0x00};
91 /* __doxy_func_body_end__ */
92 
93 /*****************************************************************/
100 int main(int argc, char *argv[])
101 {
102  int rv = OPENNSL_E_NONE;
103  int unit = DEFAULT_UNIT;
104  int choice, led_max, ix;
105  led_info_t *led_info_cur, *led_info;
106  uint32 led_ctrl;
107  int offset;
108 
109 
110  if((argc != 1) || ((argc > 1) && (strcmp(argv[1], "--help") == 0))) {
111  printf("%s\n\r", example_usage);
112  return OPENNSL_E_PARAM;
113  }
114 
115  /* Initialize the system. */
117  if(rv != OPENNSL_E_NONE)
118  {
119  printf("\r\nFailed to initialize the system. Error: %s\r\n",
120  opennsl_errmsg(rv));
121  return rv;
122  }
123 
124  /* cold boot initialization commands */
125  rv = example_port_default_config(unit);
126  if (rv != OPENNSL_E_NONE)
127  {
128  printf("\r\nFailed to apply default config on ports, rc = %d (%s).\r\n",
129  rv, opennsl_errmsg(rv));
130  }
131 
132  /* Add ports to default vlan. */
133  printf("Adding ports to default vlan.\r\n");
135  if(rv != OPENNSL_E_NONE)
136  {
137  printf("\r\nFailed to add default ports. Error: %s\r\n",
138  opennsl_errmsg(rv));
139 
140  return rv;
141  }
142 
143  while(1) {
144  printf("\r\nUser menu: Select one of the following options\r\n");
145  printf("1. Program the LED processor\r\n");
146 #ifdef INCLUDE_DIAG_SHELL
147  printf("9. Launch diagnostic shell\n");
148 #endif
149  printf("0. Quit the application.\r\n");
150 
152  {
153  printf("Invalid option entered. Please re-enter.\n");
154  continue;
155  }
156  switch(choice)
157  {
158  case 1:
159  {
160  led_info = led_info_cmicm;
161  led_max = 2;
162 
163  for(ix = 0; ix < led_max; ix++)
164  {
165  led_info_cur = led_info+ix;
166  led_ctrl = opennsl_pci_read(unit, led_info_cur->ctrl);
167 
168  led_ctrl &= ~OPENNSL_LC_LED_ENABLE;
169  if(OPENNSL_E_NONE != opennsl_pci_write(unit, led_info_cur->ctrl, led_ctrl))
170  {
171  printf("opennsl_pci_write returns failure:%d\n",rv);
172  }
173 
174  for (offset = 0; offset < OPENNSL_CMIC_LED_PROGRAM_RAM_SIZE; offset++)
175  {
176  if(ix == 0)
177  {
178  opennsl_pci_write(unit,
179  led_info_cur->pram_base + OPENNSL_CMIC_LED_REG_SIZE * offset,
180  (offset < EXAMPLE_LED0_PROGRAM_RAM_SIZE) ? (uint32) led0_program[offset] : 0);
181  }
182  else
183  {
184  opennsl_pci_write(unit,
185  led_info_cur->pram_base + OPENNSL_CMIC_LED_REG_SIZE * offset,
186  (offset < EXAMPLE_LED1_PROGRAM_RAM_SIZE) ? (uint32) led1_program[offset] : 0);
187  }
188  }
189 
190  for (offset = 0x80; offset < OPENNSL_CMIC_LED_DATA_RAM_SIZE; offset++)
191  {
192  opennsl_pci_write(unit,
193  led_info_cur->dram_base + OPENNSL_CMIC_LED_REG_SIZE * offset,
194  0);
195  }
196 
197  /* The LED data area should be clear whenever program starts */
198  led_ctrl = opennsl_pci_read(unit, led_info_cur->ctrl);
199  opennsl_pci_write(unit, led_info_cur->ctrl, led_ctrl & ~OPENNSL_LC_LED_ENABLE);
200 
201  for (offset = 0x80; offset < OPENNSL_CMIC_LED_DATA_RAM_SIZE; offset++) {
202  opennsl_pci_write(unit,
203  led_info_cur->dram_base + OPENNSL_CMIC_LED_REG_SIZE * offset,
204  0);
205  }
206 
207  led_ctrl |= OPENNSL_LC_LED_ENABLE;
208  opennsl_pci_write(unit, led_info_cur->ctrl, led_ctrl);
209  }
210 
211  break;
212  }
213 
214 #ifdef INCLUDE_DIAG_SHELL
215  case 9:
216  {
217  opennsl_driver_shell();
218  break;
219  }
220 #endif
221 
222  case 0:
223  {
224  printf("Exiting the application.\n");
225  rv = opennsl_driver_exit();
226  return rv;
227  }
228  default:
229  break;
230  } /* End of switch */
231  } /* End of while */
232 
233  return rv;
234 }
235 /* __doxy_func_body_end__ */