Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / PCA9544A_v1 / aos_test_PCA9544A.c @ f606f432

History | View | Annotate | Download (6.672 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 84f0ce9e Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 ddf34c3d Thomas Schöpping
#include <amiroos.h>
20 4c72a54c Thomas Schöpping
#include <aos_test_PCA9544A.h>
21 e545e620 Thomas Schöpping
22 4c72a54c Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23 ddf34c3d Thomas Schöpping
24 f3ac1c96 Thomas Schöpping
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/******************************************************************************/
47 e545e620 Thomas Schöpping
48 4c72a54c Thomas Schöpping
aos_testresult_t aosTestPca9544aFunc(BaseSequentialStream* stream, const aos_test_t* test)
49 e545e620 Thomas Schöpping
{
50 4c72a54c Thomas Schöpping
  aosDbgCheck(test->data != NULL && ((aos_test_pca9544adata_t*)test->data)->driver != NULL);
51 e545e620 Thomas Schöpping
52
  // local variables
53 ce12e797 Thomas Schöpping
  aos_testresult_t result;
54 4c72a54c Thomas Schöpping
  int32_t status;
55 e545e620 Thomas Schöpping
  uint8_t ctrlreg;
56
  pca9544a_lld_intstatus_t interrupt;
57
  pca9544a_lld_chid_t channel;
58
  uint8_t test_mask = 0x00u;
59
60 ce12e797 Thomas Schöpping
  aosTestResultInit(&result);
61
62 e545e620 Thomas Schöpping
  chprintf(stream, "reading control register...\n");
63 4c72a54c Thomas Schöpping
  status = pca9544a_lld_read(((aos_test_pca9544adata_t*)test->data)->driver, &ctrlreg, ((aos_test_pca9544adata_t*)test->data)->timeout);
64 e545e620 Thomas Schöpping
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
65 4c72a54c Thomas Schöpping
    aosTestPassed(stream, &result);
66 e545e620 Thomas Schöpping
  } else {
67 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X\n", status);
68 e545e620 Thomas Schöpping
  }
69
70
  chprintf(stream, "writing control register...\n");
71
  status = APAL_STATUS_OK;
72 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_write(((aos_test_pca9544adata_t*)test->data)->driver, (uint8_t)(PCA9544A_LLD_CTRLREG_EN), ((aos_test_pca9544adata_t*)test->data)->timeout);
73
  status |= pca9544a_lld_read(((aos_test_pca9544adata_t*)test->data)->driver, &ctrlreg, ((aos_test_pca9544adata_t*)test->data)->timeout);
74 e545e620 Thomas Schöpping
  if ((status == APAL_STATUS_OK  || status == APAL_STATUS_WARNING) && ctrlreg == PCA9544A_LLD_CTRLREG_EN) {
75 4c72a54c Thomas Schöpping
    aosTestPassed(stream, &result);
76 e545e620 Thomas Schöpping
  } else {
77 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, ctrlreg);
78 e545e620 Thomas Schöpping
  }
79
80
  chprintf(stream, "reading interrupt status...\n");
81 4c72a54c Thomas Schöpping
  status = pca9544a_lld_getintstatus(((aos_test_pca9544adata_t*)test->data)->driver, &interrupt, ((aos_test_pca9544adata_t*)test->data)->timeout);
82 e545e620 Thomas Schöpping
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
83 4c72a54c Thomas Schöpping
    aosTestPassedMsg(stream, &result, "0x%08X\n", interrupt);
84 e545e620 Thomas Schöpping
  } else {
85 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X\n", status);
86 e545e620 Thomas Schöpping
  }
87
88
  chprintf(stream, "reading current channel...\n");
89 4c72a54c Thomas Schöpping
  status = pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
90 e545e620 Thomas Schöpping
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
91 4c72a54c Thomas Schöpping
    aosTestPassedMsg(stream, &result, "0x%08X\n", channel);
92 e545e620 Thomas Schöpping
  } else {
93 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X\n", status);
94 e545e620 Thomas Schöpping
  }
95
96
  chprintf(stream, "setting current channel...\n");
97
  status = APAL_STATUS_OK;
98 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_setchannel(((aos_test_pca9544adata_t*)test->data)->driver, PCA9544A_LLD_CH0, ((aos_test_pca9544adata_t*)test->data)->timeout);
99
  status |= pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
100 e545e620 Thomas Schöpping
  test_mask |= (channel != PCA9544A_LLD_CH0) ? 0x01u : 0x00u;
101 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_setchannel(((aos_test_pca9544adata_t*)test->data)->driver, PCA9544A_LLD_CH1, ((aos_test_pca9544adata_t*)test->data)->timeout);
102
  status |= pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
103 e545e620 Thomas Schöpping
  test_mask |= (channel != PCA9544A_LLD_CH1) ? 0x02u : 0x00u;
104 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_setchannel(((aos_test_pca9544adata_t*)test->data)->driver, PCA9544A_LLD_CH2, ((aos_test_pca9544adata_t*)test->data)->timeout);
105
  status |= pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
106 e545e620 Thomas Schöpping
  test_mask |= (channel != PCA9544A_LLD_CH2) ? 0x04u : 0x00u;
107 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_setchannel(((aos_test_pca9544adata_t*)test->data)->driver, PCA9544A_LLD_CH3, ((aos_test_pca9544adata_t*)test->data)->timeout);
108
  status |= pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
109 e545e620 Thomas Schöpping
  test_mask |= (channel != PCA9544A_LLD_CH3) ? 0x08u : 0x00u;
110 4c72a54c Thomas Schöpping
  status |= pca9544a_lld_setchannel(((aos_test_pca9544adata_t*)test->data)->driver, PCA9544A_LLD_CH_NONE, ((aos_test_pca9544adata_t*)test->data)->timeout);
111
  status |= pca9544a_lld_getcurrentchannel(((aos_test_pca9544adata_t*)test->data)->driver, &channel, ((aos_test_pca9544adata_t*)test->data)->timeout);
112 e545e620 Thomas Schöpping
  test_mask |= (channel != PCA9544A_LLD_CH_NONE) ? 0x10u : 0x00u;
113
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && test_mask == 0x00u) {
114 4c72a54c Thomas Schöpping
    aosTestPassed(stream, &result);
115 e545e620 Thomas Schöpping
  } else {
116 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, test_mask);
117 e545e620 Thomas Schöpping
  }
118
119 4c72a54c Thomas Schöpping
  aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(PCA9544ADriver));
120 e545e620 Thomas Schöpping
121
  return result;
122
}
123
124 4c72a54c Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */