Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_PCA9544A_v1.c @ ddf34c3d

History | View | Annotate | Download (6.51 KB)

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

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
#include <amiroos.h>
20

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1)) || defined(__DOXYGEN__)
22

    
23
#include <ut_alld_PCA9544A_v1.h>
24

    
25
/******************************************************************************/
26
/* LOCAL DEFINITIONS                                                          */
27
/******************************************************************************/
28

    
29
/******************************************************************************/
30
/* EXPORTED VARIABLES                                                         */
31
/******************************************************************************/
32

    
33
/******************************************************************************/
34
/* LOCAL TYPES                                                                */
35
/******************************************************************************/
36

    
37
/******************************************************************************/
38
/* LOCAL VARIABLES                                                            */
39
/******************************************************************************/
40

    
41
/******************************************************************************/
42
/* LOCAL FUNCTIONS                                                            */
43
/******************************************************************************/
44

    
45
/******************************************************************************/
46
/* EXPORTED FUNCTIONS                                                         */
47
/******************************************************************************/
48

    
49
aos_utresult_t utAlldPca9544aFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
50
{
51
  aosDbgCheck(ut->data != NULL && ((ut_pca9544adata_t*)ut->data)->driver != NULL);
52

    
53
  // local variables
54
  aos_utresult_t result = {0,0};
55
  uint32_t status;
56
  uint8_t ctrlreg;
57
  pca9544a_lld_intstatus_t interrupt;
58
  pca9544a_lld_chid_t channel;
59
  uint8_t test_mask = 0x00u;
60

    
61
  chprintf(stream, "reading control register...\n");
62
  status = pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout);
63
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
64
    aosUtPassed(stream, &result);
65
  } else {
66
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
67
  }
68

    
69
  chprintf(stream, "writing control register...\n");
70
  status = APAL_STATUS_OK;
71
  status |= pca9544a_lld_write(((ut_pca9544adata_t*)ut->data)->driver, (uint8_t)(PCA9544A_LLD_CTRLREG_EN), ((ut_pca9544adata_t*)ut->data)->timeout);
72
  status |= pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout);
73
  if ((status == APAL_STATUS_OK  || status == APAL_STATUS_WARNING) && ctrlreg == PCA9544A_LLD_CTRLREG_EN) {
74
    aosUtPassed(stream, &result);
75
  } else {
76
    aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, ctrlreg);
77
  }
78

    
79
  chprintf(stream, "reading interrupt status...\n");
80
  status = pca9544a_lld_getintstatus(((ut_pca9544adata_t*)ut->data)->driver, &interrupt, ((ut_pca9544adata_t*)ut->data)->timeout);
81
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
82
    aosUtPassedMsg(stream, &result, "0x%08X\n", interrupt);
83
  } else {
84
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
85
  }
86

    
87
  chprintf(stream, "reading current channel...\n");
88
  status = pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
89
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
90
    aosUtPassedMsg(stream, &result, "0x%08X\n", channel);
91
  } else {
92
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
93
  }
94

    
95
  chprintf(stream, "setting current channel...\n");
96
  status = APAL_STATUS_OK;
97
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH0, ((ut_pca9544adata_t*)ut->data)->timeout);
98
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
99
  test_mask |= (channel != PCA9544A_LLD_CH0) ? 0x01u : 0x00u;
100
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH1, ((ut_pca9544adata_t*)ut->data)->timeout);
101
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
102
  test_mask |= (channel != PCA9544A_LLD_CH1) ? 0x02u : 0x00u;
103
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH2, ((ut_pca9544adata_t*)ut->data)->timeout);
104
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
105
  test_mask |= (channel != PCA9544A_LLD_CH2) ? 0x04u : 0x00u;
106
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH3, ((ut_pca9544adata_t*)ut->data)->timeout);
107
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
108
  test_mask |= (channel != PCA9544A_LLD_CH3) ? 0x08u : 0x00u;
109
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH_NONE, ((ut_pca9544adata_t*)ut->data)->timeout);
110
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
111
  test_mask |= (channel != PCA9544A_LLD_CH_NONE) ? 0x10u : 0x00u;
112
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && test_mask == 0x00u) {
113
    aosUtPassed(stream, &result);
114
  } else {
115
    aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, test_mask);
116
  }
117

    
118
  aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(PCA9544ADriver));
119

    
120
  return result;
121
}
122

    
123
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_PCA9544A) && (AMIROLLD_CFG_PCA9544A == 1) */
124