Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2m_periph.c Source File

m2m_periph.c

Go to the documentation of this file.
00001 /**
00002  *
00003  * \file
00004  *
00005  * \brief NMC1500 Peripherials Application Interface.
00006  *
00007  * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved.
00008  *
00009  * \asf_license_start
00010  *
00011  * \page License
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. The name of Atmel may not be used to endorse or promote products derived
00024  *    from this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00027  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00028  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00029  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
00030  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00032  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00033  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00034  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * \asf_license_stop
00039  *
00040  */
00041 
00042 
00043 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00044 INCLUDES
00045 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00046 
00047 #include "driver/include/m2m_periph.h"
00048 #include "driver/source/nmasic.h"
00049 #include "m2m_hif.h"
00050 
00051 #ifdef CONF_PERIPH
00052 
00053 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00054 MACROS
00055 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00056 #define GPIO_OP_DIR     0
00057 #define GPIO_OP_SET     1
00058 #define GPIO_OP_GET     2
00059 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00060 DATA TYPES
00061 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00062 
00063 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00064 STATIC FUNCTIONS
00065 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00066 static sint8 get_gpio_idx(uint8 u8GpioNum)
00067 {
00068     if(u8GpioNum >= M2M_PERIPH_GPIO_MAX) return -1;
00069     if(u8GpioNum == M2M_PERIPH_GPIO15 ) { return 15;
00070     } else if(u8GpioNum == M2M_PERIPH_GPIO16 ) { return 16;
00071     } else if(u8GpioNum == M2M_PERIPH_GPIO18 ) { return 18;
00072     } else if(u8GpioNum == M2M_PERIPH_GPIO3 ) { return 3;
00073     } else if(u8GpioNum == M2M_PERIPH_GPIO4 ) { return 4;
00074     } else if(u8GpioNum == M2M_PERIPH_GPIO5 ) { return 5;
00075     } else if(u8GpioNum == M2M_PERIPH_GPIO6 ) { return 6;
00076     } else {
00077         return -2;
00078     }
00079 }
00080 /*
00081  * GPIO read/write skeleton with wakeup/sleep capability.
00082  */
00083 static sint8 gpio_ioctl(uint8 op, uint8 u8GpioNum, uint8 u8InVal, uint8 * pu8OutVal)
00084 {
00085     sint8 ret, gpio;
00086 
00087     ret = hif_chip_wake();
00088     if(ret != M2M_SUCCESS) goto _EXIT;
00089 
00090     gpio = get_gpio_idx(u8GpioNum);
00091     if(gpio < 0) goto _EXIT1;
00092 
00093     if(op == GPIO_OP_DIR) {
00094         ret = set_gpio_dir((uint8)gpio, u8InVal);
00095     } else if(op == GPIO_OP_SET) {
00096         ret = set_gpio_val((uint8)gpio, u8InVal);
00097     } else if(op == GPIO_OP_GET) {
00098         ret = get_gpio_val((uint8)gpio, pu8OutVal);
00099     }
00100     if(ret != M2M_SUCCESS) goto _EXIT1;
00101 
00102 _EXIT1:
00103     ret = hif_chip_sleep();
00104 _EXIT:
00105     return ret;
00106 }
00107 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
00108 FUNCTION IMPLEMENTATION
00109 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
00110 
00111 
00112 sint8 m2m_periph_init(tstrPerphInitParam * param)
00113 {
00114     return M2M_SUCCESS;
00115 }
00116 
00117 sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir)
00118 {
00119     return gpio_ioctl(GPIO_OP_DIR, u8GpioNum, u8GpioDir, NULL);
00120 }
00121 
00122 sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal)
00123 {
00124     return gpio_ioctl(GPIO_OP_SET, u8GpioNum, u8GpioVal, NULL);
00125 }
00126 
00127 sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal)
00128 {
00129     return gpio_ioctl(GPIO_OP_GET, u8GpioNum, 0, pu8GpioVal);
00130 }
00131 
00132 sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn)
00133 {
00134     /* TBD */
00135     return M2M_SUCCESS;
00136 }
00137 
00138 sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param)
00139 {
00140     /* TBD */
00141     return M2M_SUCCESS;
00142 }
00143 
00144 sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags)
00145 {
00146     /* TBD */
00147     return M2M_SUCCESS;
00148 }
00149 
00150 sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen, uint8 flags)
00151 {
00152     /* TBD */
00153     return M2M_SUCCESS;
00154 }
00155 
00156 
00157 sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable)
00158 {
00159     return pullup_ctrl(pinmask, enable);
00160 }
00161 #endif /* CONF_PERIPH */
00162