1 /**
2 *
3 * \file
4 *
5 * \brief NMC1500 Peripherials Application Interface.
6 *
7 * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved.
8 *
9 * \asf_license_start
10 *
11 * \page License
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above copyright notice,
20 * this list of conditions and the following disclaimer in the documentation
21 * and/or other materials provided with the distribution.
22 *
23 * 3. The name of Atmel may not be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
29 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 * \asf_license_stop
39 *
40 */
41
42
43 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
44 INCLUDES
45 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
46
47 #include "driver/include/m2m_periph.h"
48 #include "driver/source/nmasic.h"
49 #include "m2m_hif.h"
50
51 #ifdef CONF_PERIPH
52
53 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
54 MACROS
55 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
56 #define GPIO_OP_DIR 0
57 #define GPIO_OP_SET 1
58 #define GPIO_OP_GET 2
59 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
60 DATA TYPES
61 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
62
63 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
64 STATIC FUNCTIONS
65 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
get_gpio_idx(uint8 u8GpioNum)66 static sint8 get_gpio_idx(uint8 u8GpioNum)
67 {
68 if(u8GpioNum >= M2M_PERIPH_GPIO_MAX) return -1;
69 if(u8GpioNum == M2M_PERIPH_GPIO15) { return 15;
70 } else if(u8GpioNum == M2M_PERIPH_GPIO16) { return 16;
71 } else if(u8GpioNum == M2M_PERIPH_GPIO18) { return 18;
72 } else if(u8GpioNum == M2M_PERIPH_GPIO3) { return 3;
73 } else if(u8GpioNum == M2M_PERIPH_GPIO4) { return 4;
74 } else if(u8GpioNum == M2M_PERIPH_GPIO5) { return 5;
75 } else if(u8GpioNum == M2M_PERIPH_GPIO6) { return 6;
76 } else {
77 return -2;
78 }
79 }
80 /*
81 * GPIO read/write skeleton with wakeup/sleep capability.
82 */
gpio_ioctl(uint8 op,uint8 u8GpioNum,uint8 u8InVal,uint8 * pu8OutVal)83 static sint8 gpio_ioctl(uint8 op, uint8 u8GpioNum, uint8 u8InVal, uint8 * pu8OutVal)
84 {
85 sint8 ret, gpio;
86
87 ret = hif_chip_wake();
88 if(ret != M2M_SUCCESS) goto _EXIT;
89
90 gpio = get_gpio_idx(u8GpioNum);
91 if(gpio < 0) goto _EXIT1;
92
93 if(op == GPIO_OP_DIR) {
94 ret = set_gpio_dir((uint8)gpio, u8InVal);
95 } else if(op == GPIO_OP_SET) {
96 ret = set_gpio_val((uint8)gpio, u8InVal);
97 } else if(op == GPIO_OP_GET) {
98 ret = get_gpio_val((uint8)gpio, pu8OutVal);
99 }
100 if(ret != M2M_SUCCESS) goto _EXIT1;
101
102 _EXIT1:
103 ret = hif_chip_sleep();
104 _EXIT:
105 return ret;
106 }
107 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
108 FUNCTION IMPLEMENTATION
109 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
110
111
m2m_periph_init(tstrPerphInitParam * param)112 sint8 m2m_periph_init(tstrPerphInitParam * param)
113 {
114 return M2M_SUCCESS;
115 }
116
m2m_periph_gpio_set_dir(uint8 u8GpioNum,uint8 u8GpioDir)117 sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir)
118 {
119 return gpio_ioctl(GPIO_OP_DIR, u8GpioNum, u8GpioDir, NULL);
120 }
121
m2m_periph_gpio_set_val(uint8 u8GpioNum,uint8 u8GpioVal)122 sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal)
123 {
124 return gpio_ioctl(GPIO_OP_SET, u8GpioNum, u8GpioVal, NULL);
125 }
126
m2m_periph_gpio_get_val(uint8 u8GpioNum,uint8 * pu8GpioVal)127 sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal)
128 {
129 return gpio_ioctl(GPIO_OP_GET, u8GpioNum, 0, pu8GpioVal);
130 }
131
m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum,uint8 u8PullupEn)132 sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn)
133 {
134 /* TBD */
135 return M2M_SUCCESS;
136 }
137
m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param)138 sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param)
139 {
140 /* TBD */
141 return M2M_SUCCESS;
142 }
143
m2m_periph_i2c_master_write(uint8 u8SlaveAddr,uint8 * pu8Buf,uint16 u16BufLen,uint8 flags)144 sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags)
145 {
146 /* TBD */
147 return M2M_SUCCESS;
148 }
149
m2m_periph_i2c_master_read(uint8 u8SlaveAddr,uint8 * pu8Buf,uint16 u16BufLen,uint16 * pu16ReadLen,uint8 flags)150 sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen, uint8 flags)
151 {
152 /* TBD */
153 return M2M_SUCCESS;
154 }
155
156
m2m_periph_pullup_ctrl(uint32 pinmask,uint8 enable)157 sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable)
158 {
159 return pullup_ctrl(pinmask, enable);
160 }
161 #endif /* CONF_PERIPH */