IoT Wireless

WizFi250-CSI(C Scripting Interpreter) Header File 본문

IoT Platform(Script)

WizFi250-CSI(C Scripting Interpreter) Header File

DH0815 2015. 5. 29. 11:16

WizFi250-CSI(C Scripting Interpreter)에 대한 헤더 파일을 작성하였다.

현재까지 작업된 WizFi250-CSI가 지원하는 함수들을 포함하고 있다.


/*
 * This file is part of the WizFi250-CSI(C Script Interpreter) project
 * By referring to this header file, you can write a C-Script-file of WizFi250-CSI.
 * 
 * This is published under the "New BSD License".
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Copyright (C) 2015 Steve Kim (ssekim@gmail.com)
 *
 * The WizFi250-CSI is based on picoc project.
 * https://github.com/zsaleeba/picoc
 * Copyright (c) 2009-2011, Zik Saleeba
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are 
 * met:
 * 
 *     * Redistributions of source code must retain the above copyright 
 *       notice, this list of conditions and the following disclaimer.
 *       
 *     * Redistributions in binary form must reproduce the above copyright 
 *       notice, this list of conditions and the following disclaimer in 
 *       the documentation and/or other materials provided with the 
 *       distribution.
 *       
 *     * Neither the name of the Zik Saleeba nor the names of its 
 *       contributors may be used to endorse or promote products derived 
 *       from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
*/

// WizFi250-CSI(C Script Interpreter) Header File for All

// Based on "ctype.h" of C standard library
int isalnum(int);
int isalpha(int);
int isblank(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);

// Based on "stdbool.h" of C standard library
typedef int bool;
#define true 1
#define false 0

// Based on "stdio.h"
int puts(char *);
char *gets(char *);
int getchar();
int printf(char *, ...);
int sprintf(char *, char *, ...);
int snprintf(char *, int, char *, ...);
int scanf(char *, ...);
int sscanf(char *, char *, ...);
int vprintf(char *, va_list);
int vsprintf(char *, char *, va_list);
int vsnprintf(char *, int, char *, va_list);
int vscanf(char *, va_list);
int vsscanf(char *, char *, va_list);


// Based on "stdlib.h" of C standard library
#define NULL 0

int atoi(char *);
int atol(char *);
int strtol(char *,char **,int);
int strtoul(char *,char **,int);
void *malloc(int);
void *calloc(int,int);
void *realloc(void *,int);
void free(void *);
int rand();
void srand(int);
void abort();
void exit(int);
char *getenv(char *);
int abs(int);
int labs(int);

// Based on "string.h" of C standard library
void *memcpy(void *,void *,int);
void *memmove(void *,void *,int);
void *memchr(char *,int,int);
int memcmp(void *,void *,int);
void *memset(void *,int,int);
char *strcat(char *,char *);
char *strncat(char *,char *,int);
char *strchr(char *,int);
char *strrchr(char *,int);
int strcmp(char *,char *);
int strncmp(char *,char *,int);
int strcoll(char *,char *);
char *strcpy(char *,char *);
char *strncpy(char *,char *,int);
char *strerror(int);
int strlen(char *);
int strspn(char *,char *);
int strcspn(char *,char *);
char *strpbrk(char *,char *);
char *strstr(char *,char *);
char *strtok(char *,char *);
int strxfrm(char *,char *,int);


// Based on "time.h" of C standard library
typedef int time_t;
typedef int clock_t;

struct tm
{
  int	tm_sec;
  int	tm_min;
  int	tm_hour;
  int	tm_mday;
  int	tm_mon;
  int	tm_year;
  int	tm_wday;
  int	tm_yday;
  int	tm_isdst;
};

char *asctime(struct tm *);
char *ctime(int *);
struct tm *gmtime(int *);
struct tm *localtime(int *);
int mktime(struct tm *ptm);
int strftime(char *, int, char *, struct tm *);


// Based on "sockets.h" of lwIP
#define AF_UNSPEC_networkLibrary       0
#define AF_INET_networkLibrary         2
#define SOCK_STREAM_networkLibrary     1
#define SOCK_DGRAM_networkLibrary      2
#define SOCK_RAW_networkLibrary        3
#define IPPROTO_IP_networkLibrary      0
#define IPPROTO_TCP_networkLibrary     6
#define IPPROTO_UDP_networkLibrary     17

#define O_NONBLOCK_networkLibrary      1
#define F_GETFL_networkLibrary         3
#define F_SETFL_networkLibrary         4

#define EAGAIN_networkLibrary          11

#define MSG_PEEK_networkLibrary        0x01
#define MSG_DONTWAIT_networkLibrary    0x08

struct in_addr {
	unsigned long s_addr;
};

struct sockaddr_in {
	unsigned char sin_len;
	unsigned char sin_family;
	unsigned short sin_port;
	struct in_addr sin_addr;
	char sin_zero[8];
} sockaddr_in;

typedef struct fd_set {
	unsigned char fd_bits [(8+7)/8];
} fd_set;

int accept(int, struct sockaddr *, unsigned long *);
int bind(int, struct sockaddr *, unsigned long);
int shutdown(int, int);
int getpeername(int, struct sockaddr *, unsigned long *);
int getsockname(int, struct sockaddr *, unsigned long *);
int getsockopt(int, int, int, void *, unsigned long *);
int setsockopt(int, int, int, void *, unsigned long);
int close(int);
int connect(int, struct sockaddr *, unsigned long);
int listen(int, int);
int recv(int, void *, unsigned long, int);
int recvfrom(int, void *, unsigned long, int, struct sockaddr *, unsigned long *);
int send(int, void *, unsigned long, int);        
int sendto(int, void *, unsigned long, int, struct sockaddr *, unsigned long);
int socket(int, int, int);
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
int fcntl(int, int, int);
int inet_addr(char *);
unsigned short htons(unsigned short);

// Regarding WizFi250-WiFi 
/** 
  * @brief  Joins a Wi-Fi network
  * @param  ssid       : A null terminated string containing the SSID name of the network to join
  * @param  auth_type  : Authentication type:
  *                       open       - Open Security
  *                       wep        - WEP Security
  *                       wpa2_tkip  - WPA2 Security using TKIP cipher
  *                       wpa2_aes   - WPA2 Security using AES cipher
  *                       wpa2       - WPA2 Security using AES and/or TKIP ciphers
  *                       wpa_aes    - WPA Security using AES cipher
  *                       wpa_tkip   - WPA Security using TKIP ciphers
  * @param  key        : Security key
  * @param  ip         : String of IP address string (if 0, DHCP will be applied.)
  * @param  netmask    : String of netamsk string
  * @param  gateway    : String of gateway address string
  * @return 0(Success), the others(Fail)
  */
int wifi_join(char* ssid, char* auth_type, char* key, char* ip, char* netmask, char* gateway);

/** 
  * @brief  Disassociates from a Wi-Fi network.
  * @return None
  */
int wifi_leave();

// Regarding WizFi250-Hardware
/**
  * @brief  Initialises a GPIO pin
  * @param  gpio : the gpio pin which should be initialised
  *                GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12(LED), GPIO13(LED), GPIO14
  * @param  type : A structure containing the required gpio configuration
                   0 : INPUT_PULL_UP              : Input with an internal pull-up resistor - use with devices that actively drive the signal low - e.g. button connected to ground
                   1 : INPUT_PULL_DOWN            : Input with an internal pull-down resistor - use with devices that actively drive the signal high - e.g. button connected to a power rail
                   2 : INPUT_HIGH_IMPEDANCE       : Input - must always be driven, either actively or by an external pullup resistor
                   3 : OUTPUT_PUSH_PULL           : Output actively driven high and actively driven low - must not be connected to other active outputs - e.g. LED output
                   4 : OUTPUT_OPEN_DRAIN_NO_PULL  : Output actively driven low but is high-impedance when set high - can be connected to other open-drain/open-collector outputs. Needs an external pull-up resistor
                   5 : OUTPUT_OPEN_DRAIN_PULL_UP  : Output actively driven low and is pulled high with an internal resistor when set high - can be connected to other open-drain/open-collector outputs.
  * @retval None
  */
void pinMode(int gpio, int type);

/**
  * @brief  Sets an output GPIO pin low or hign
  * @param  gpio  : the gpio pin which should be set
  *                 GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12, GPIO13, GPIO14
  * @param  value : 0(low) or 1(high)
  * @retval None
  */
void pinOut(int gpio, int value);

/**
  * @brief  Get the state of an input GPIO pin
  * @param  gpio  : the gpio pin which should be read
  *                 GPIO1, GPIO6, GPIO7, GPIO8, GPIO9, GPIO12, GPIO13, GPIO14
  * @retval 0(low) or 1(high)
  */
int pinIn(int);

/** 
  * @brief  Transmit data on a UART interface
  * @param  uart : the UART interface. UART1, UART2.
  * @param  data : pointer to the start of data
  * @param  size : number of bytes to transmit
  * @return None
  */
void uart_tx(int uart, unsigned char* data, int size);

/** 
  * @brief  Takes a single sample from an ADC interface
  * @param  adc : the interface which should be sampled 
                  AD1(Currently, WizFi250-CSI support one ADC)
  * @return a variable which will receive the sample
  */
int analogRead(int adc);

/** 
  * @brief  Receive data on a UART interface
  * @param  uart : the UART interface. UART1, UART2.
  * @param  data : pointer to the buffer which will store incoming data
  * @param  size : number of bytes to receive
  * @return number of received bytes
  */
int uart_rx(int uart, unsigned char* data, int size);

/** 
  * @brief  Sleep for a given period
  * @param  milliseconds : the time to sleep in milliseconds
  * @return None
  */
void delay_ms(unsigned long milliseconds);