Skip to content

Commit 42ea90f

Browse files
Merge pull request #243 from Telecominfraproject/UT_led
UT for led device
2 parents e424790 + 0c2403c commit 42ea90f

6 files changed

Lines changed: 714 additions & 26 deletions

File tree

firmware/ec/inc/devices/led.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* MACRO DEFINITIONS
2424
*****************************************************************************/
2525
#define LED_OFF 0xFF
26+
#define LED_RED 0xAA
27+
#define LED_GREEN 0x55
2628

2729
/* ClkX = fOSC/(2^(RegMisc[6:4]-1); 0x50-125kHz, 0x40-250KHz, 0x30-500KHz,
2830
* 0x20-1MHz, 0x10-2MHz; Fading - Linear */
@@ -84,5 +86,8 @@ ReturnStatus hci_led_system_boot(const HciLedCfg *driver);
8486
ReturnStatus led_init(const HciLedCfg *driver);
8587
ePostCode led_probe(const HciLedCfg *driver, POSTData *postData);
8688
void led_configure(HciLedCfg *driver);
87-
89+
ReturnStatus hci_led_backhaul_failure(const HciLedCfg *driver);
90+
ReturnStatus hci_led_radio_failure(const HciLedCfg *driver);
91+
ReturnStatus hci_led_system_failure(const HciLedCfg *driver);
92+
ReturnStatus hci_led_system_running(const HciLedCfg *driver);
8893
#endif /* INA226_H_ */

firmware/ec/src/devices/led.c

Lines changed: 117 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,18 @@ static const hciLedData ledData[HCI_LED_TOTAL_NOS] =
189189
*****************************************************************************/
190190
ReturnStatus hci_led_turnon_green(const HciLedCfg *driver)
191191
{
192-
ReturnStatus status = RETURN_OK;
192+
ReturnStatus status = RETURN_NOTOK;
193193

194+
if (!driver) {
195+
return status;
196+
}
194197
/* Turn On Left side Green LEDs */
195198
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_LEFT],
196-
SX1509_REG_AB, 0x55, 0x55);
199+
SX1509_REG_AB, LED_GREEN, LED_GREEN);
197200
if (status == RETURN_OK) {
198201
/* Turn On Right side Green LEDs */
199202
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_RIGHT],
200-
SX1509_REG_AB, 0x55, 0x55);
203+
SX1509_REG_AB, LED_GREEN, 0x55);
201204
}
202205
return status;
203206
}
@@ -214,15 +217,18 @@ ReturnStatus hci_led_turnon_green(const HciLedCfg *driver)
214217
*****************************************************************************/
215218
ReturnStatus hci_led_turnon_red(const HciLedCfg *driver)
216219
{
217-
ReturnStatus status = RETURN_OK;
220+
ReturnStatus status = RETURN_NOTOK;
218221

222+
if (!driver) {
223+
return status;
224+
}
219225
/* Turn On Left side Red LEDs */
220226
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_LEFT],
221-
SX1509_REG_AB, 0xAA, 0xAA);
227+
SX1509_REG_AB, LED_RED, LED_RED);
222228
if (status == RETURN_OK) {
223229
/* Turn On Right side Red LEDs */
224230
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_RIGHT],
225-
SX1509_REG_AB, 0xAA, 0xAA);
231+
SX1509_REG_AB, LED_RED, LED_RED);
226232
}
227233
return status;
228234
}
@@ -239,8 +245,11 @@ ReturnStatus hci_led_turnon_red(const HciLedCfg *driver)
239245
*****************************************************************************/
240246
ReturnStatus hci_led_turnoff_all(const HciLedCfg *driver)
241247
{
242-
ReturnStatus status = RETURN_OK;
248+
ReturnStatus status = RETURN_NOTOK;
243249

250+
if (!driver) {
251+
return status;
252+
}
244253
/* Turn Off Left side LEDs */
245254
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_LEFT],
246255
SX1509_REG_AB, LED_OFF, LED_OFF);
@@ -264,9 +273,12 @@ ReturnStatus hci_led_turnoff_all(const HciLedCfg *driver)
264273
*****************************************************************************/
265274
static ReturnStatus hci_led_configure_sx1509_onofftime(const I2C_Dev *ioexpDev)
266275
{
267-
ReturnStatus status = RETURN_OK;
268276
uint8_t index;
277+
ReturnStatus status = RETURN_NOTOK;
269278

279+
if (!ioexpDev) {
280+
return status;
281+
}
270282
for (index = 0; index < 14; index++) {
271283
/* Configure RegTOn time of LEDs */
272284
status = ioexp_led_set_on_time(ioexpDev, index, REG_T_ON_VALUE);
@@ -282,7 +294,54 @@ static ReturnStatus hci_led_configure_sx1509_onofftime(const I2C_Dev *ioexpDev)
282294
}
283295
return status;
284296
}
297+
/*****************************************************************************
298+
** FUNCTION NAME : hci_led_configure_onofftime_left
299+
**
300+
** DESCRIPTION : Configure On and Off time of left LEDs on the LED
301+
*board.
302+
**
303+
** ARGUMENTS : None
304+
**
305+
** RETURN TYPE : Success or Failure
306+
**
307+
*****************************************************************************/
308+
static ReturnStatus hci_led_configure_onofftime_left(const HciLedCfg *driver)
309+
{
310+
ReturnStatus status = RETURN_NOTOK;
311+
312+
if (!driver) {
313+
return status;
314+
}
315+
/* Configure LED driver parameters(RegTOn, RegOff) for Left side LEDs */
316+
status = hci_led_configure_sx1509_onofftime(
317+
&driver->sx1509_dev[HCI_LED_DRIVER_LEFT]);
318+
319+
return status;
320+
}
321+
/*****************************************************************************
322+
** FUNCTION NAME : hci_led_configure_onofftime_right
323+
**
324+
** DESCRIPTION : Configure On and Off time of right LEDs on the LED
325+
*board.
326+
**
327+
** ARGUMENTS : None
328+
**
329+
** RETURN TYPE : Success or Failure
330+
**
331+
*****************************************************************************/
332+
static ReturnStatus hci_led_configure_onofftime_right(const HciLedCfg *driver)
333+
{
334+
ReturnStatus status = RETURN_NOTOK;
335+
336+
if (!driver) {
337+
return status;
338+
}
339+
/* Configure LED driver parameters(RegTOn, RegOff) for Left side LEDs */
340+
status = hci_led_configure_sx1509_onofftime(
341+
&driver->sx1509_dev[HCI_LED_DRIVER_RIGHT]);
285342

343+
return status;
344+
}
286345
/*****************************************************************************
287346
** FUNCTION NAME : hci_led_configure_onofftime
288347
**
@@ -295,16 +354,17 @@ static ReturnStatus hci_led_configure_sx1509_onofftime(const I2C_Dev *ioexpDev)
295354
*****************************************************************************/
296355
static ReturnStatus hci_led_configure_onofftime(const HciLedCfg *driver)
297356
{
298-
ReturnStatus status = RETURN_OK;
357+
ReturnStatus status = RETURN_NOTOK;
299358

359+
if (!driver) {
360+
return status;
361+
}
300362
/* Configure LED driver parameters(RegTOn, RegOff) for Left side LEDs */
301-
status = hci_led_configure_sx1509_onofftime(
302-
&driver->sx1509_dev[HCI_LED_DRIVER_LEFT]);
363+
status = hci_led_configure_onofftime_left(driver);
303364
if (status == RETURN_OK) {
304365
/* Configure LED driver parameters(RegTOn, RegOff) for Right side LEDs
305366
*/
306-
hci_led_configure_sx1509_onofftime(
307-
&driver->sx1509_dev[HCI_LED_DRIVER_RIGHT]);
367+
status = hci_led_configure_onofftime_right(driver);
308368
}
309369
return status;
310370
}
@@ -322,10 +382,13 @@ static ReturnStatus hci_led_configure_onofftime(const HciLedCfg *driver)
322382
*****************************************************************************/
323383
ReturnStatus hci_led_system_boot(const HciLedCfg *driver)
324384
{
325-
ReturnStatus status = RETURN_OK;
326385
uint8_t index = 0;
327386
uint8_t regValue = 0;
387+
ReturnStatus status = RETURN_NOTOK;
328388

389+
if (!driver) {
390+
return status;
391+
}
329392
/* Turn off all LEDs */
330393
status = hci_led_turnoff_all(driver);
331394
if (status != RETURN_OK) {
@@ -364,8 +427,11 @@ ReturnStatus hci_led_system_boot(const HciLedCfg *driver)
364427
*****************************************************************************/
365428
ReturnStatus hci_led_system_running(const HciLedCfg *driver)
366429
{
367-
ReturnStatus status = RETURN_OK;
430+
ReturnStatus status = RETURN_NOTOK;
368431

432+
if (!driver) {
433+
return status;
434+
}
369435
/* Turn off all LEDs */
370436
status = hci_led_turnoff_all(driver);
371437
if (status != RETURN_OK) {
@@ -397,8 +463,11 @@ ReturnStatus hci_led_system_running(const HciLedCfg *driver)
397463
*****************************************************************************/
398464
ReturnStatus hci_led_system_failure(const HciLedCfg *driver)
399465
{
400-
ReturnStatus status = RETURN_OK;
466+
ReturnStatus status = RETURN_NOTOK;
401467

468+
if (!driver) {
469+
return status;
470+
}
402471
/* Turn off all LEDs */
403472
status = hci_led_turnoff_all(driver);
404473
if (status != RETURN_OK) {
@@ -430,14 +499,21 @@ ReturnStatus hci_led_system_failure(const HciLedCfg *driver)
430499
*****************************************************************************/
431500
ReturnStatus hci_led_radio_failure(const HciLedCfg *driver)
432501
{
433-
ReturnStatus status = RETURN_OK;
502+
ReturnStatus status = RETURN_NOTOK;
434503

504+
if (!driver) {
505+
return status;
506+
}
435507
/* Turn off all LEDs */
436508
status = hci_led_turnoff_all(driver);
509+
/* Enable blink for the left LEDs */
510+
if (status == RETURN_OK) {
511+
status = hci_led_configure_onofftime_left(driver);
512+
}
437513
if (status == RETURN_OK) {
438514
/* Turn On Left side Red LEDs */
439-
status =
440-
ioexp_led_set_data(HCI_LED_DRIVER_LEFT, SX1509_REG_AB, 0xAA, 0xAA);
515+
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_LEFT],
516+
SX1509_REG_AB, LED_RED, LED_RED);
441517
}
442518

443519
return status;
@@ -456,14 +532,21 @@ ReturnStatus hci_led_radio_failure(const HciLedCfg *driver)
456532
*****************************************************************************/
457533
ReturnStatus hci_led_backhaul_failure(const HciLedCfg *driver)
458534
{
459-
ReturnStatus status = RETURN_OK;
535+
ReturnStatus status = RETURN_NOTOK;
460536

537+
if (!driver) {
538+
return status;
539+
}
461540
/* Turn off all LEDs */
462541
status = hci_led_turnoff_all(driver);
542+
/* Enable blink for all Right LEDs */
543+
if (status == RETURN_OK) {
544+
status = hci_led_configure_onofftime_right(driver);
545+
}
463546
if (status == RETURN_OK) {
464547
/* Turn On Right side Red LEDs */
465548
status = ioexp_led_set_data(&driver->sx1509_dev[HCI_LED_DRIVER_RIGHT],
466-
SX1509_REG_AB, 0xAA, 0xAA);
549+
SX1509_REG_AB, LED_RED, LED_RED);
467550
}
468551
return status;
469552
}
@@ -481,15 +564,18 @@ ReturnStatus hci_led_backhaul_failure(const HciLedCfg *driver)
481564
*****************************************************************************/
482565
ReturnStatus led_init(const HciLedCfg *driver)
483566
{
484-
ReturnStatus status = RETURN_OK;
485567
uint8_t index;
568+
ReturnStatus status = RETURN_NOTOK;
486569

570+
if (!driver) {
571+
return status;
572+
}
487573
/* Steps required to use the LED driver
488574
- Disable input buffer (RegInputDisable)
489575
- Disable pull-up (RegPullUp)
490576
- Enable open drain (RegOpenDrain)
491-
- Set direction to output (RegDir) by default RegData is set high => LED
492-
OFF
577+
- Set direction to output (RegDir) \96 by default RegData is set high =>
578+
LED OFF
493579
- Enable oscillator (RegClock)
494580
- Configure LED driver clock and mode if relevant (RegMisc)
495581
- Enable LED driver operation (RegLEDDriverEnable)
@@ -569,6 +655,9 @@ ReturnStatus led_init(const HciLedCfg *driver)
569655
void led_configure(HciLedCfg *driver)
570656
{
571657
/* Initialize IO pins */
658+
if (!driver) {
659+
return;
660+
}
572661
OcGpio_configure(&driver->pin_ec_gpio,
573662
OCGPIO_CFG_OUTPUT | OCGPIO_CFG_OUT_HIGH);
574663
}
@@ -585,9 +674,12 @@ void led_configure(HciLedCfg *driver)
585674
*****************************************************************************/
586675
ePostCode led_probe(const HciLedCfg *driver, POSTData *postData)
587676
{
588-
ReturnStatus status = RETURN_NOTOK;
677+
ReturnStatus status = POST_DEV_MISSING;
589678
uint8_t regValue = 0x00;
590679

680+
if (!(driver && postData)) {
681+
return status;
682+
}
591683
/* Read Test Register 1 of LED driver SX1509 of Left LED Module(RegTest1) */
592684
status = ioexp_led_read_testregister_1(
593685
&driver->sx1509_dev[HCI_LED_DRIVER_LEFT], &regValue);

firmware/ec/test/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ $(PATHB)Test_ocmp_debugocgpio$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DEBUG
196196
TEST_OCMP_DATXXR5A_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_dat-xxr5a-pp.c $(OCWARE_ROOT)/src/drivers/PinGroup.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_dat.c fake/fake_PCA9557.c $(OCWARE_ROOT)/src/helpers/memory.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/drivers/GpioPCA9557.c $(OCWARE_ROOT)/src/devices/pca9557.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_FE.c
197197
$(PATHB)Test_ocmp_dat-xxr5a$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_DATXXR5A_SRC)
198198

199+
200+
TEST_LED_SRC=$(OCWARE_ROOT)/src/devices/led.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c fake/fake_SX1509_register.c fake/fake_led.c stub/stub_GateMutex.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_LED.c
201+
$(PATHB)Test_led$(TARGET_EXTENSION): $(STD_FILES) $(TEST_LED_SRC)
202+
199203
$(PATHB)%$(TARGET_EXTENSION):
200204
$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@
201205
$(COV_CMDS)

firmware/ec/test/fake/fake_led.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
#include "include/test_led.h"
10+
11+
const I2C_Dev s_sx1509_left_dev = {
12+
.bus = OC_CONNECT1_I2C8,
13+
.slave_addr = LED_SX1509_LEFT_ADDRESS,
14+
};
15+
16+
const I2C_Dev s_sx1509_right_dev = {
17+
.bus = OC_CONNECT1_I2C8,
18+
.slave_addr = LED_SX1509_RIGHT_ADDRESS,
19+
};
20+
21+
OcGpio_Port ec_io = {
22+
.fn_table = &FakeGpio_fnTable,
23+
.object_data = &(FakeGpio_Obj){},
24+
};
25+
26+
uint8_t SX1509_right_regs[] = {
27+
[SX1509_REG_TEST_2] = 0x00,
28+
};
29+
30+
uint8_t LED_GpioPins[] = {
31+
[INPUT_BUFFER_DISABLE] = 0x00,
32+
[OC_EC_HCI_LED_RESET] = 0x00,
33+
};
34+
35+
uint32_t LED_GpioConfig[] = {
36+
[INPUT_BUFFER_DISABLE] = 0x00,
37+
[OC_EC_HCI_LED_RESET] = 0x00,
38+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
#ifndef _TEST_LED_H
10+
#define _TEST_LED_H
11+
12+
#include "fake/fake_GPIO.h"
13+
#include "fake/fake_I2C.h"
14+
#include "inc/devices/led.h"
15+
#include "inc/devices/sx1509.h"
16+
#include "include/test_sx1509.h"
17+
#include <string.h>
18+
#include <ti/sysbios/knl/Task.h>
19+
#include "unity.h"
20+
21+
#define LED_CLOCK_VALUE 0x40
22+
#define LED_DEFAULT_VALUE 0x00
23+
#define LED_DRIVER_ENABLE_B_VALUE 0xFF
24+
#define LED_INVALID_PARAM 3
25+
#define LED_POST_DATA_NULL 0x00
26+
#define LED_POST_DEVID 0xFF
27+
#define LED_POST_MANID 0xFF
28+
#define LED_REG_INPUT_DISABLE_B_VALUE 0xFF
29+
#define LED_REG_OPEN_DRAIN_B_VALUE 0xFF
30+
#define LED_REG_PULL_UP_B_VALUE 0x00
31+
#define LED_SYSTEM_BOOT_DATAB 0xD5
32+
#define INPUT_BUFFER_DISABLE 0x01
33+
#define OC_CONNECT1_I2C8 7
34+
#define OC_EC_HCI_LED_RESET 89
35+
#define SX1509_SOFT_RESET_REG_VALUE_2 0x34
36+
#define REG_T_ON_14_15_VALUE 0x00
37+
#endif

0 commit comments

Comments
 (0)