Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.1 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
#include <aos_debug.h>
24
#include <chprintf.h>
25
#include <aos_thread.h>
26
#include <alld_pca9544a.h>
27
28
aos_utresult_t utAlldPca9544aFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
29
{
30
  aosDbgCheck(ut->data != NULL && ((ut_pca9544adata_t*)ut->data)->driver != NULL);
31
32
  // local variables
33
  aos_utresult_t result = {0,0};
34
  uint32_t status;
35
  uint8_t ctrlreg;
36
  pca9544a_lld_intstatus_t interrupt;
37
  pca9544a_lld_chid_t channel;
38
  uint8_t test_mask = 0x00u;
39
40
  chprintf(stream, "reading control register...\n");
41
  status = pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout);
42
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
43
    aosUtPassed(stream, &result);
44
  } else {
45
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
46
  }
47
48
  chprintf(stream, "writing control register...\n");
49
  status = APAL_STATUS_OK;
50
  status |= pca9544a_lld_write(((ut_pca9544adata_t*)ut->data)->driver, (uint8_t)(PCA9544A_LLD_CTRLREG_EN), ((ut_pca9544adata_t*)ut->data)->timeout);
51
  status |= pca9544a_lld_read(((ut_pca9544adata_t*)ut->data)->driver, &ctrlreg, ((ut_pca9544adata_t*)ut->data)->timeout);
52
  if ((status == APAL_STATUS_OK  || status == APAL_STATUS_WARNING) && ctrlreg == PCA9544A_LLD_CTRLREG_EN) {
53
    aosUtPassed(stream, &result);
54
  } else {
55
    aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, ctrlreg);
56
  }
57
58
  chprintf(stream, "reading interrupt status...\n");
59
  status = pca9544a_lld_getintstatus(((ut_pca9544adata_t*)ut->data)->driver, &interrupt, ((ut_pca9544adata_t*)ut->data)->timeout);
60
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
61
    aosUtPassedMsg(stream, &result, "0x%08X\n", interrupt);
62
  } else {
63
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
64
  }
65
66
  chprintf(stream, "reading current channel...\n");
67
  status = pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
68
  if (status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) {
69
    aosUtPassedMsg(stream, &result, "0x%08X\n", channel);
70
  } else {
71
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
72
  }
73
74
  chprintf(stream, "setting current channel...\n");
75
  status = APAL_STATUS_OK;
76
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH0, ((ut_pca9544adata_t*)ut->data)->timeout);
77
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
78
  test_mask |= (channel != PCA9544A_LLD_CH0) ? 0x01u : 0x00u;
79
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH1, ((ut_pca9544adata_t*)ut->data)->timeout);
80
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
81
  test_mask |= (channel != PCA9544A_LLD_CH1) ? 0x02u : 0x00u;
82
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH2, ((ut_pca9544adata_t*)ut->data)->timeout);
83
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
84
  test_mask |= (channel != PCA9544A_LLD_CH2) ? 0x04u : 0x00u;
85
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH3, ((ut_pca9544adata_t*)ut->data)->timeout);
86
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
87
  test_mask |= (channel != PCA9544A_LLD_CH3) ? 0x08u : 0x00u;
88
  status |= pca9544a_lld_setchannel(((ut_pca9544adata_t*)ut->data)->driver, PCA9544A_LLD_CH_NONE, ((ut_pca9544adata_t*)ut->data)->timeout);
89
  status |= pca9544a_lld_getcurrentchannel(((ut_pca9544adata_t*)ut->data)->driver, &channel, ((ut_pca9544adata_t*)ut->data)->timeout);
90
  test_mask |= (channel != PCA9544A_LLD_CH_NONE) ? 0x10u : 0x00u;
91
  if ((status == APAL_STATUS_OK || status == APAL_STATUS_WARNING) && test_mask == 0x00u) {
92
    aosUtPassed(stream, &result);
93
  } else {
94
    aosUtFailedMsg(stream, &result, "0x%08X, 0x%X\n", status, test_mask);
95
  }
96
97
  aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(PCA9544ADriver));
98
99
  return result;
100
}
101
102
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_PCA9544A) */