Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_pca9544a.c @ f3ac1c96

History | View | Annotate | Download (6.52 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 <ut_alld_pca9544a.h>
20

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

    
23
/******************************************************************************/
24
/* LOCAL DEFINITIONS                                                          */
25
/******************************************************************************/
26

    
27
/******************************************************************************/
28
/* EXPORTED VARIABLES                                                         */
29
/******************************************************************************/
30

    
31
/******************************************************************************/
32
/* LOCAL TYPES                                                                */
33
/******************************************************************************/
34

    
35
/******************************************************************************/
36
/* LOCAL VARIABLES                                                            */
37
/******************************************************************************/
38

    
39
/******************************************************************************/
40
/* LOCAL FUNCTIONS                                                            */
41
/******************************************************************************/
42

    
43
/******************************************************************************/
44
/* EXPORTED FUNCTIONS                                                         */
45
/******************************************************************************/
46
#include <aos_debug.h>
47
#include <chprintf.h>
48
#include <aos_thread.h>
49
#include <alld_pca9544a.h>
50

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

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

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

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

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

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

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

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

    
122
  return result;
123
}
124

    
125
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCA9544A) */
126