diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/ARC.code-workspace b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/ARC.code-workspace new file mode 100644 index 00000000..2c8c72de --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/ARC.code-workspace @@ -0,0 +1,31 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "D:\\embarc_osp-master" + }, + { + "path": "mbedtls_ssl_client2" + }, + { + "path": "Vending_Machine" + } + ], + "settings": { + "files.associations": { + "embarc_debug.h": "c", + "embarc.h": "c", + "emsk_gpio.c": "cpp", + "config.h": "c", + "openthread.h": "c", + "cli.h": "c", + "ssd1306_app_config.h": "c", + "u8g.h": "c", + "adt7420.h": "c", + "iosfwd": "c", + "xutility": "c" + } + } +} \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/StartVSCode.bat b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/StartVSCode.bat new file mode 100644 index 00000000..356f9314 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/StartVSCode.bat @@ -0,0 +1,6 @@ +@ECHO OFF +SETLOCAL +SET ARC_ToolChain=D:/arc_gnu +SET ARC_BSP_SRC=D:/embarc_osp-master +start "" "C:\Program Files\Microsoft VS Code\Code.exe" %* +ENDLOCAL \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/Source/main.c b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/Source/main.c new file mode 100644 index 00000000..5c80162b --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/Source/main.c @@ -0,0 +1,385 @@ +/* embARC HAL */ + +#include "embARC.h" +#include "embARC_debug.h" + +#include "vm_task.h" +#include "communication_task.h" + +extern SemaphoreHandle_t xSemaphore; + +enum main_status_type +{ + main_init_1, + main_init_2, + main_init_3, + main_init_4, + main_user_input_1, + main_user_input_2, + main_user_input_3, + main_user_input_4, + main_balance_check, + main_recommand, + main_purchase_choice, + main_purchase_confirm +}; + +void _Main_Enqueue (int target_id, vm_data _data) +{ + _data.source_id = id_main; + _data.target_id = target_id; + enQueue(_data); +} + + +// 有問題,待改 沒有這個型態的 queue +void _Wifi_Main_Enqueue (WIFI_data _wifi_data) +{ + vm_data _data; + _data.source_id = id_main; + _data.target_id = id_wifi; + strncpy(_data.user, _wifi_data.user, 4); + _data.target_item = _wifi_data.target_item; + + for ( int i = 0; i < 4; i++ ) + _data.body[i].i = _wifi_data.body[i].i; + + for ( int i = 0; i < 4; i++ ) + { + strncpy(_data.type, _wifi_data.type[i], 6); + strncpy(_data.name, _wifi_data.name[i], 6); + _Main_Enqueue(id_wifi, _data); + } +} + +int main(int argc, char **argv) +{ + EMBARC_PRINTF("entering main function\r\n"); + + vm_data data = {0}; // data for receiveing + WIFI_data local_data = {0}; // local database + // int main_status = main_init_1; + int main_status = main_init_1; + char output = 'Z'; + + while (1) + { + if (main_status == main_init_1) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + strncpy(local_data.type[data.target_item - 1], data.type, 6); + strncpy(local_data.name[data.target_item - 1], data.name, 6); + local_data.body[data.target_item - 1].i = data.body[data.target_item - 1].i; + local_data.source_id = id_main; + main_status = main_init_2; + } + } + } + } + if (main_status == main_init_2) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + strncpy(local_data.type[data.target_item - 1], data.type, 6); + strncpy(local_data.name[data.target_item - 1], data.name, 6); + local_data.body[data.target_item - 1].i = data.body[data.target_item - 1].i; + local_data.source_id = id_main; + main_status = main_init_3; + } + } + } + } + if (main_status == main_init_3) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + strncpy(local_data.type[data.target_item - 1], data.type, 6); + strncpy(local_data.name[data.target_item - 1], data.name, 6); + local_data.body[data.target_item - 1].i = data.body[data.target_item - 1].i; + local_data.source_id = id_main; + main_status = main_init_4; + } + } + } + } + if (main_status == main_init_4) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + strncpy(local_data.type[data.target_item - 1], data.type, 6); + strncpy(local_data.name[data.target_item - 1], data.name, 6); + local_data.body[data.target_item - 1].i = data.body[data.target_item - 1].i; + local_data.source_id = id_main; + main_status = main_user_input_1; + + EMBARC_PRINTF("\r\n\r\n####### initial value stored in main function #######\r\n\r\n"); + EMBARC_PRINTF("\t target item: %d\r\n", local_data.target_item); + EMBARC_PRINTF("\t status : %d\r\n", local_data.status); + EMBARC_PRINTF("\t user : %s\r\n", local_data.user); + EMBARC_PRINTF("\t name 1: %s, type 1: %s, #: %d\r\n", local_data.name[0], local_data.type[0], local_data.body[0].i); + EMBARC_PRINTF("\t name 2: %s, type 2: %s, #: %d\r\n", local_data.name[1], local_data.type[1], local_data.body[1].i); + EMBARC_PRINTF("\t name 3: %s, type 3: %s, #: %d\r\n", local_data.name[2], local_data.type[2], local_data.body[2].i); + EMBARC_PRINTF("\t name 4: %s, type 4: %s, #: %d\r\n", local_data.name[3], local_data.type[3], local_data.body[3].i); + EMBARC_PRINTF("\r\n#####################################################\r\n\r\n"); + } + EMBARC_PRINTF(" -> main initial success\r\n"); + } + } + } + if (main_status == main_user_input_1) + { + // EMBARC_PRINTF("Reading from numpad in main function started. \r\n"); + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_numpad) + { + data.user[0] = (char) data.body[0].i; + data.status = user_input_1; + data.target_id = no_item; + _Main_Enqueue(id_oled, data); + local_data.user[0] = (char) data.body[0].i; + main_status = main_user_input_2; + } + } + } + } + if (main_status == main_user_input_2) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_numpad) + { + data.user[1] = (char) data.body[0].i; + data.status = user_input_2; + data.target_id = no_item; + _Main_Enqueue(id_oled, data); + local_data.user[1] = (char) data.body[0].i; + main_status = main_user_input_3; + } + } + } + } + if (main_status == main_user_input_3) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_numpad) + { + data.user[2] = (char) data.body[0].i; + data.status = user_input_3; + data.target_id = no_item; + _Main_Enqueue(id_oled, data); + local_data.user[2] = (char) data.body[0].i; + main_status = main_user_input_4; + } + } + } + } + if (main_status == main_user_input_4) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_numpad) + { + EMBARC_PRINTF("receive char: %c\n", (char) data.body[0].i); + data.user[3] = (char) data.body[0].i; + data.status = user_input_4; + data.target_id = no_item; + _Main_Enqueue(id_oled, data); + + + data.status = balance_check; + local_data.user[3] = (char) data.body[0].i; + + for (int i = 0; i < 4; i++) + data.user[i] = local_data.user[i]; + for (int i = 0; i < 4; i++) + data.body[i].i = local_data.body[i].i; + _Main_Enqueue(id_wifi, data); + + local_data.target_item = no_item; + // local_data.status = balance_check; + // _Wifi_Main_Enqueue(local_data); + + // check balance just once + local_data.status = server_do_nothing; + // _Wifi_Main_Enqueue(local_data); + + EMBARC_PRINTF("\r\n\r\n -> user id recognize as: %s\r\n\r\n", data.user); + + EMBARC_PRINTF("\r\n\r\n####### value after user inputted #######\r\n\r\n"); + EMBARC_PRINTF("\t target item: %d\r\n", local_data.target_item); + EMBARC_PRINTF("\t status : %d\r\n", local_data.status); + EMBARC_PRINTF("\t user : %s\r\n", local_data.user); + EMBARC_PRINTF("\t name 1: %s, type 1: %s, #: %d\r\n", local_data.name[0], local_data.type[0], local_data.body[0].i); + EMBARC_PRINTF("\t name 2: %s, type 2: %s, #: %d\r\n", local_data.name[1], local_data.type[1], local_data.body[1].i); + EMBARC_PRINTF("\t name 3: %s, type 3: %s, #: %d\r\n", local_data.name[2], local_data.type[2], local_data.body[2].i); + EMBARC_PRINTF("\t name 4: %s, type 4: %s, #: %d\r\n", local_data.name[3], local_data.type[3], local_data.body[3].i); + EMBARC_PRINTF("\r\n#####################################################\r\n\r\n"); + + main_status = main_balance_check; + } + EMBARC_PRINTF(" -> main user input 4 success\r\n"); + } + } + } + if (main_status == main_balance_check) + { + + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + EMBARC_PRINTF(" -> main balance check wwith Wi-Fi\r\n"); + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + EMBARC_PRINTF(" -> server balance check is %s.\r\n", (data.status == sell_recommand) ? "PASSED" : (data.status = reject_balance) ? "REJECTED" : "UNDEFINED"); + EMBARC_PRINTF(" => target_item is %d\r\n", data.target_item); + EMBARC_PRINTF(" => balance check is %d\r\n", data.status); + + if (data.status == sell_recommand) + { + main_status = main_purchase_choice; + _Main_Enqueue(id_oled, data); + } + else if (data.status == reject_balance) + { + data.target_item = 5; // judgement in oled_task() + data.status = purchase_confirm; + main_status = main_user_input_1; + _Main_Enqueue(id_oled, data); + } + } + } + } + } + /* + if (main_status == main_recommand) + { + EMBARC_PRINTF("\r\n -> enter recommand state.\r\n"); + + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_wifi) + { + data.status = sell_recommand; + _Main_Enqueue(id_oled, data); + main_status = main_purchase_choice; + } + } + } + } + */ + if (main_status == main_purchase_choice) + { + EMBARC_PRINTF(" -> enter choice state.\r\n"); + + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + EMBARC_PRINTF(" -> numpad input: %c\r\n", (char)data.body[0].i); + if (data.source_id == id_numpad) + { + if (data.body[0].i == '1' || data.body[0].i == '2') + { + data.status = purchase_check; + data.target_item = (int)data.body[0].i - 48; + local_data.target_item = (int)data.body[0].i - 48; + strncpy(data.name, local_data.name[data.target_item - 1], 6); + strncpy(data.type, local_data.type[data.target_item - 1], 6); + _Main_Enqueue(id_oled, data); + main_status = main_purchase_confirm; + } + } + } + } + } + if (main_status == main_purchase_confirm) + { + if( xMainQueue != NULL ) + { + if( xQueueReceive( xMainQueue, &data, portMAX_DELAY ) ) + { + EMBARC_PRINTF(" -> main purchase_confirm\r\n"); + // EMBARC_PRINTF("receive data, source_id and target_id: %d, %d\r\n", data.source_id, data.target_id); + if (data.source_id == id_numpad) + { + if ((char) data.body[0].i == '#') + { + data.target_item = local_data.target_item; + + for ( int i = 0; i < 4; i++ ) + data.body[i].i = 0; + + data.body[0].i = local_data.target_item; + + data.status = purchase_confirm; + local_data.status = purchase_confirm; + local_data.body[local_data.target_item - 1].i--; + + _Main_Enqueue(id_dcmotor, data); + + for ( int i = 0; i < 4; i++ ) + data.body[i].i = local_data.body[i].i; + + strncpy(data.user, local_data.user, 4); + + _Main_Enqueue(id_oled, data); + _Main_Enqueue(id_wifi, data); + + // _Wifi_Main_Enqueue(local_data); + } + + local_data.user[0] = 0; + local_data.user[1] = 0; + local_data.user[2] = 0; + local_data.user[3] = 0; + main_status = main_user_input_1; + } + } + } + } + vTaskDelay(20); + } + + return E_SYS; +} diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/makefile b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/makefile new file mode 100644 index 00000000..bec5ba4c --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/ARC_VSCODE/Vending_Machine/makefile @@ -0,0 +1,35 @@ +# Application name +APPL ?= ${workspaceFolderBasename} + +EXT_DEV_LIST += wifi/rw009 sensor/temperature/adt7420 + +# Heap Size Settings +HEAPSZ ?= 1048576 +STACKSZ ?= 1048576 + +# +# root dir of embARC +# +EMBARC_ROOT = ${ARC_BSP_SRC} + +OS_SEL = freertos + +MID_SEL = vending-machine common u8glib mbedtls fatfs lwip lwip-contrib + +APPL_DEFINES += -DEMSK_PMWIFI_USE_J6 + +# application source dirs +APPL_CSRC_DIR = ./Source +APPL_ASMSRC_DIR = ./Source + +# application include dirs +APPL_INC_DIR = ./Include + + +# include current project makefile +COMMON_COMPILE_PREREQUISITES += makefile + +### Options above must be added before include options.mk ### +# include key embARC build system makefile +override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) +include $(EMBARC_ROOT)/options/options.mk \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/README.md b/arc_design_contest/2018/NCKU_Vending_Machine/README.md new file mode 100644 index 00000000..66401c9c --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/README.md @@ -0,0 +1,159 @@ +# ARC team 5 vending machine + +## Table of Content + +* [Introduction](#introduction) +* [Video](#video) +* [Document](#doc) +* [hardware](#hardware) + * [EMSK Board firmware used in this application](#firmware) + * [The peripheral devices used in this application](#peripheral) + * [The hardware setup](#setup) +* [Software](#software) + * [Makefile settings](#makefile) + * [IDE settings](#ide) +* [User Manual](#usermanual) + * [Before Running This Application](#before) + * [Launch Server side code](#server) + * [Launch VSCode IDE](#vscode) + * [Wi-Fi hotspot connnection settings](#wifi) + * [Entering Main](#main) +* [Source code directory](#sourcecode) + +## Introduction
+We use ARC as our user terminal and connect to the server, which is implemented with cloud data management and smart selling system. Peripheral devices and sensors are added to the ARC exp. WiFi, temperature sensor, OLED and many more. + +Our vending machine system provides maintainance issue related to vending machine, such as auto-checking for food expired date, temperature overheat detecting. Other than that, vending machine is connected to database which users are allow to use their id for payment without physical bills or coins, and the machine will recommend what to buy depending on the purchase records of that user. The reason why our machine is different from others, the system administrator can get the information by signing in far away from the vending machine; the costomer can pay cashlessly. With e-payment, according to the purchase record of customer or other information, our machine can easily give some recommand after some operation, which can effectively decrease the time for customer making decision and interact with interest. + +## Video
+http://v.youku.com/v_show/id_XMzYzMDE0MTg1Mg==.html?spm=a2h0k.8191407.0.0&from=s1.8-1-1.2 + +## Document
+For the documentation, please refer to https://drive.google.com/drive/folders/1Ae3eZAxOxhwls43yeXHgO07RQz1IF__S?usp=sharing + +For the presentation slides, please refer to https://prezi.com/p/hvdr4jdcaljk/arc/ + +## hardware connection
+### EMSK Board firmware used in this application
+* emsk ver2.2 + +### The peripheral devices used in this application
+ +| peripheral | module | +| :--------------: | ------: | +| Wi-Fi | EMW3162 | +| OLED | SSD1306 | +| temperture | adt7420 | +| DC motor | 6V 1:1000 | +| Infrared ray led | 940nm | + +### The hardware setup
+ +| port | interface | peripheral | +| :--: | :-------: | :----------: | +| J1 | GPIO | DC motor & Infrared ray | +| J2 | I2C | temperature | +| J3 | GPIO | Number pad | +| J5 | SPI | OLED | +| J6 | SPI | Wi-Fi | + +## Software
+sofware requirement +* Visual Studio code IDE +* ARC GNU Toolchain +* serial port terminal eg. putty +* Apache server , phpmysql + +### visual Studio IDE settings
+edit `/ARC_VSCODE/StartVSCode.bat` to set your ARC toolchain path, library path, vscode program path. +example: +``` + SET ARC_ToolChain=C:/arc_gnu + SET ARC_BSP_SRC=C:/embarc_osp-master + start "" "C:/Program Files/Microsoft VS Code/Code.exe" %* +``` + +### Makefile settings
+Target options about EMSK and toolchain: + +BOARD ?= emsk +BD_VER ?= 22 +CUR_CORE ?= arcem7d +TOOLCHAIN ?= gnu + +## User Manual
+### Before Running This Application
+Firstly, download source code of vending machine from GitHub. +- For whole new application + * Source code download link: https://github.com/cstandy/ARC_team_5_vending_machine.git + +- For who already have embARC_osp-master + * Source code download link: +https://github.com/cstandy/embarc_applications + * Paste your `embarc_osp-master` to `embarc_applications/arc_design_contest/2018/vending_machine/embarc_osp-master/` for additional files + +### Run the server_side code
+1. open the Apache HTTP server . +2. Secure your site with HTTPS(openssl etc...), you should also put the certificae file into the arc board so that it can update data via HTTPS. + - in file `embarc_osp-master/middleware/mbedtls/library/certs.c` + - change the content of `const char mbedtls_test_cli_crt_rsa[]` +3. import projectarc.sql into phpmysql(Data Base) +4. register a new user account from our website. + * register link: https://127.0.0.1/../server_side/sign_up.php + +4. change the value 'Authority' in the table 'sign_data' to 1. +5. sign in to enter the main website. +* register link: https://127.0.0.1/../server_side/sign_in.php + + +### Launch VSCode IDE
+```../ARC_VSCODE/StartVSCode.bat``` +Launch StartVSCode.bat to run this vending machine application. After launching VScode, right click on the workspace and choose add Folder in the path ```../ARC_VSCODE/vending-machine``` to workspace. + +### Wi-Fi hotspot connnection settings
+Modify the ssid and password of Wi-Fi AP in ``` ../embarc_osp-master/board/emsk/emsk.h``` to connect Wi-Fi module to the hotspot + +```clike=137 +#define WF_HOTSPOT_NAME "EMBARC" +#define WF_HOTSPOT_PASSWD "12345678" +``` + +### Entering Main
+After Wi-Fi connected, FREERTOS rises all tasks including communication, oled, temperature, blinky, number pad and DC motor. + +## Source code directory
+ +* main function directory ```src\arc_osp-master\middleware\vending-machine``` + * Include + * Source + * Readme.md + +* ```src\arc_osp-master\middleware\vending-machine\Source``` + +| FILE | description | +| -------------------: | :--------------------- | +| vm_task.c | main queue | +| communication_task.c | mbedtls ssl client | +| oled_task.c | oled display | +| adt7420.c | temperature sensor | +| dcmotor_task.c | dc_motor controller | +| numpad_task.c | user input | +| LED_task.c | make the board blinky | +| FreeRTOSConfig.c | Freertos configuration | + + + +* ```..\server_side\``` + +| FILE | description | +| -------------------: | :--------------------- | +| item.php | change vending machine's data | +| item.css | to typeset item.php | +| logout.php | logout | +| read.php | updata both side server and arc | +| sign_in.php | sign into the item.php | +| sign_up.php | create an account | +| arc2php.txt | exchange data from arc to server | +| com2arc.txt | exchange data from server to arc | +| projectarc.sql | initialize the data in the data base| + diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/arc/arc_exception.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/arc/arc_exception.c new file mode 100644 index 00000000..62210fe0 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/arc/arc_exception.c @@ -0,0 +1,519 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ + +/** + * \file + * \ingroup ARC_HAL_EXCEPTION_CPU ARC_HAL_EXCEPTION_INTERRUPT + * \brief C Implementation of exception and interrupt management + */ +#undef LIB_SECURESHIELD_OVERRIDES +#include "arc_exception.h" +#include "arc_cache.h" + +#define DBG_LESS +#include "embARC_debug.h" + +/** + * \addtogroup ARC_HAL_EXCEPTION_CPU + * @{ + * \var exc_entry_table + * \brief exception entry table + * + * install exception entry table to ARC_AUX_INT_VECT_BASE in startup. + * According to ARCv2 ISA, vectors are fetched in instruction space and thus + * may be present in ICCM, Instruction Cache, or + * main memory accessed by instruction fetch logic. + * So it is put into a specific section .vector. + * + * Please note that the exc_entry_table maybe cached in ARC. Some functions is + * defined in .s files. + * + */ + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU + * \brief default cpu exception handler + * \param p_excinf pointer to the exception frame + */ +static void exc_handler_default(void *p_excinf) +{ + uint32_t excpt_cause_reg = 0; + uint32_t excpt_ret_reg = 0; + uint32_t exc_no = 0; + uint32_t excpt_addr = 0; + + excpt_cause_reg = _arc_aux_read(AUX_ECR); + excpt_ret_reg = _arc_aux_read(AUX_ERRET); + exc_no = (excpt_cause_reg >> 16) & 0xff; + excpt_addr = _arc_aux_read(AUX_EFA); + + dbg_printf(DBG_LESS_INFO, "\r\ndefault cpu exception handler\r\n"); + dbg_printf(DBG_LESS_INFO, "exc_no:%d, last sp:0x%08x, ecr:0x%08x, eret:0x%08x, efa:0x%08x\r\n", + exc_no, (uint32_t)p_excinf, excpt_cause_reg, excpt_ret_reg, excpt_addr); +#if SECURESHIELD_VERSION == 2 + while (1); +#else + Asm("kflag 1"); +#endif +} + + +/** + * \ingroup ARC_HAL_EXCEPTION_INTERRUPT + * \brief default interrupt handler + * \param[in] p_excinf information for interrupt handler + */ +static void int_handler_default(void *p_excinf) +{ + uint32_t int_cause_reg = 0; + + int_cause_reg = _arc_aux_read(AUX_IRQ_CAUSE); + dbg_printf(DBG_LESS_INFO, "default interrupt handler\r\n"); + dbg_printf(DBG_LESS_INFO, "last sp:0x%08x, icause:0x%08x\r\n", (uint32_t)p_excinf, int_cause_reg); +#if SECURESHIELD_VERSION == 2 + while (1); +#else + Asm("kflag 1"); +#endif +} + +__attribute__ ((aligned(1024), section(".vector"))) +EXC_ENTRY exc_entry_table[NUM_EXC_ALL] = { + [0] = _arc_reset, + [1 ... NUM_EXC_CPU-1] = exc_entry_cpu, + [NUM_EXC_CPU ... NUM_EXC_ALL-1] = exc_entry_int + }; +/** + * \var exc_int_handler_table + * \brief the cpu exception and interrupt exception handler table + * called in exc_entry_default and exc_entry_int + */ +EXC_HANDLER exc_int_handler_table[NUM_EXC_ALL] = { + [0 ... NUM_EXC_CPU-1] = exc_handler_default, + [NUM_EXC_CPU ... NUM_EXC_ALL-1] = int_handler_default +}; + +/** + * \var exc_nest_count + * \brief the counter for exc/int processing, =0 no int/exc + * >1 in int/exc processing + * @} + */ +uint32_t exc_nest_count; + +typedef struct aux_irq_ctrl_field { + /* note: little endian */ + uint32_t save_nr_gpr_pairs: 5; /** Indicates number of general-purpose register pairs saved, from 0 to 8/16 */ + uint32_t res: 4; /** Reserved */ + uint32_t save_blink: 1; /** Indicates whether to save and restore BLINK */ + uint32_t save_lp_regs: 1; /** Indicates whether to save and restore loop registers (LP_COUNT, LP_START, LP_END) */ + uint32_t save_u_to_u: 1; /** Indicates if user context is saved to user stack */ + uint32_t res2: 1; /** Reserved */ + uint32_t save_idx_regs: 1; /** Indicates whether to save and restore code-density registers (EI_BASE, JLI_BASE, LDI_BASE) */ + uint32_t res3: 18; /** Reserved */ +} aux_irq_ctrl_field_t; + +typedef union { + aux_irq_ctrl_field_t bits; + uint32_t value; +} aux_irq_ctrl_t; + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU ARC_HAL_EXCEPTION_INTERRUPT + * \brief initialize the exception and interrupt handling + */ +void exc_int_init(void) +{ + uint32_t i; + uint32_t status; + aux_irq_ctrl_t ictrl; + + ictrl.value = 0; + +#ifndef ARC_FEATURE_RF16 + ictrl.bits.save_nr_gpr_pairs = 6; /* r0 to r11 (r12 saved manually) */ +#else + ictrl.bits.save_nr_gpr_pairs = 3; /* r0 to r3, r10, r11 */ +#endif + ictrl.bits.save_blink = 1; + ictrl.bits.save_lp_regs = 1; /* LP_COUNT, LP_START, LP_END */ + ictrl.bits.save_u_to_u = 0; /* user ctxt saved on kernel stack */ + ictrl.bits.save_idx_regs = 1; /* JLI, LDI, EI */ + + status = arc_lock_save(); + for (i = NUM_EXC_CPU; i < NUM_EXC_ALL; i++) { + /* interrupt level triggered, disabled, priority is the lowest */ + _arc_aux_write(AUX_IRQ_SELECT, i); + _arc_aux_write(AUX_IRQ_ENABLE, 0); + _arc_aux_write(AUX_IRQ_TRIGGER, 0); +#if defined(ARC_FEATURE_SEC_PRESENT) && (SECURESHIELD_VERSION < 2) + _arc_aux_write(AUX_IRQ_PRIORITY, (1 << AUX_IRQ_PRIORITY_BIT_S)|(INT_PRI_MAX - INT_PRI_MIN)); +#else + _arc_aux_write(AUX_IRQ_PRIORITY, INT_PRI_MAX - INT_PRI_MIN); +#endif + } + _arc_aux_write(AUX_IRQ_CTRL, ictrl.value); + + arc_unlock_restore(status); + + /** ipm should be set after cpu unlock restore to avoid reset of the status32 value */ + arc_int_ipm_set((INT_PRI_MAX - INT_PRI_MIN)); +} + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU + * \brief install a CPU exception entry + * \param[in] excno exception number + * \param[in] entry the entry of exception to install + */ +int32_t exc_entry_install(const uint32_t excno, EXC_ENTRY entry) +{ + uint32_t status; + EXC_ENTRY *table; + +#if defined(ARC_FEATURE_SEC_PRESENT) && (SECURESHIELD_VERSION < 2) + table = (EXC_ENTRY *)_arc_aux_read(AUX_INT_VECT_BASE_S); +#else + table = (EXC_ENTRY *)_arc_aux_read(AUX_INT_VECT_BASE); +#endif + + if (excno < NUM_EXC_ALL && entry != NULL + && table[excno] != entry) { + status = cpu_lock_save(); + /* directly write to mem, as arc gets exception handler from mem not from cache */ + /* FIXME, here maybe icache is dirty, need to be invalidated */ + table[excno] = entry; + + if (_arc_aux_read(AUX_BCR_D_CACHE) > 0x2) { + /* dcache is available */ + dcache_flush_line((uint32_t)&table[excno]); + } + + if (_arc_aux_read(AUX_BCR_D_CACHE) > 0x2) { + /* icache is available */ + icache_invalidate_line((uint32_t)&table[excno]); + } + cpu_unlock_restore(status); + return 0; + } + return -1; +} + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU + * \brief get the installed CPU exception entry + * \param[in] excno exception number + * \return the installed CPU exception entry + */ +EXC_ENTRY exc_entry_get(const uint32_t excno) +{ + if (excno < NUM_EXC_ALL) { + return exc_entry_table[excno]; + } + return NULL; +} + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU + * \brief install an exception handler + * \param[in] excno exception number + * \param[in] handler the handler of exception to install + */ +int32_t exc_handler_install(const uint32_t excno, EXC_HANDLER handler) +{ + if (excno < NUM_EXC_ALL && handler != NULL) { + exc_int_handler_table[excno] = handler; + return 0; + } + + return -1; +} + +/** + * \ingroup ARC_HAL_EXCEPTION_CPU + * \brief get the installed exception handler + * \param[in] excno exception number + * \return the installed exception handler or NULL + */ +EXC_HANDLER exc_handler_get(const uint32_t excno) +{ + if (excno < NUM_EXC_ALL) { + return exc_int_handler_table[excno]; + } + + return NULL; +} + + +#ifndef EMBARC_OVERRIDE_ARC_INTERRUPT_MANAGEMENT +/** + * \brief disable the specific interrupt + * + * \param[in] intno interrupt number + */ +int32_t int_disable(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + arc_int_disable(intno); + return 0; + } + + return -1; +} + +/** + * \brief enable the specific int + * + * \param[in] intno interrupt number + */ +int32_t int_enable(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + arc_int_enable(intno); + return 0; + } + + return -1; +} + +/** + * \brief check whether the specific int is enabled + * + * \param[in] intno interrupt number + * \return 0 disabled, 1 enabled, < 0 error + */ +int32_t int_enabled(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + _arc_aux_write(AUX_IRQ_SELECT, intno); + return _arc_aux_read(AUX_IRQ_ENABLE); + } + + return -1; +} + +/** + * \brief get the interrupt priority mask + * + * \returns interrupt priority mask, negative num + */ +int32_t int_ipm_get(void) +{ + return ((int32_t)arc_int_ipm_get() + INT_PRI_MIN); +} + + +/** + * \brief set the interrupt priority mask + * + * \param[in] intpri interrupt priority + */ +int32_t int_ipm_set(int32_t intpri) +{ + if (intpri >= INT_PRI_MIN && intpri <= INT_PRI_MAX) { + intpri = intpri - INT_PRI_MIN; + arc_int_ipm_set(intpri); + return 0; + } + + return -1; +} + + +/** + * \brief get current interrupt priority mask + * + * \param[in] intno interrupt number + * \return <0 interrupt priority, 0 error + */ +int32_t int_pri_get(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + return (int32_t)arc_int_pri_get(intno) + INT_PRI_MIN; + } + + return 0; +} + + +/** + * \brief set interrupt priority + * + * \param[in] intno interrupt number + * \param[in] intpri interrupt priority + * \return <0 error, 0 ok + */ +int32_t int_pri_set(const uint32_t intno, int32_t intpri) +{ + uint32_t status; + + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + status = cpu_lock_save(); + intpri = intpri - INT_PRI_MIN; + arc_int_pri_set(intno,(uint32_t)intpri); + cpu_unlock_restore(status); + return 0; + } + return -1; +} + +/** + * \brief set interrupt secure or not secure + * This function is valid in secureshield v2 + * \param[in] intno interrupt number + * \param[in] secure, 0 for normal, >0 for secure + * \return <0 error, 0 ok + */ +int32_t int_secure_set(const uint32_t intno, uint32_t secure) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + arc_int_secure_set(intno, secure); + return 0; + } + return -1; + +} + + +/** + * \brief probe the pending status of interrupt + * + * \param[in] intno interrupt number + * + * \returns 1 pending, 0 no pending, -1 error + */ +int32_t int_probe(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + return arc_int_probe(intno); + } + return -1; +} + + +/** + * \brief trigger the interrupt in software + * + * \param[in] intno interrupt number + * \return 0 ok, -1 error + */ +int32_t int_sw_trigger(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + arc_int_sw_trigger(intno); + return 0; + } + return -1; +} + +/** + * \brief config the interrupt level triggered or pulse triggered + * + * \param[in] intno interrupt number + * \param[in] level, 0-level trigger, 1-pulse triggered + * \return 0 ok, -1 error + */ +int32_t int_level_config(const uint32_t intno, const uint32_t level) +{ + if (intno >= NUM_EXC_CPU && intno < NUM_EXC_ALL) { + arc_int_level_config(intno, level); + return 0; + } + return -1; +} + + +/** + * \brief lock cpu, disable interrupts + */ +void cpu_lock(void) +{ + arc_lock(); +} + +/** + * \brief unlock cpu, enable interrupts to happen + */ +void cpu_unlock(void) +{ + arc_unlock(); +} + +/** + * \brief lock cpu and return status + * + * \returns cpu status + */ +uint32_t cpu_lock_save(void) +{ + return arc_lock_save(); +} + +/** + * \brief unlock cpu with the specific status + * + * \param[in] status cpu status saved by cpu_lock_save + */ +void cpu_unlock_restore(const uint32_t status) +{ + arc_unlock_restore(status); +} + +/** + * \ingroup ARC_HAL_EXCEPTION_INTERRUPT + * \brief install an interrupt handler + * \param[in] intno interrupt number + * \param[in] handler interrupt handler to install + */ +int32_t int_handler_install(const uint32_t intno, INT_HANDLER handler) +{ + /*!< \todo parameter check ? */ + if (intno >= NUM_EXC_CPU) { + return exc_handler_install(intno, handler); + } + + return -1; +} + +/** + * \ingroup ARC_HAL_EXCEPTION_INTERRUPT + * \brief get the installed an interrupt handler + * \param[in] intno interrupt number + * \return the installed interrupt handler or NULL + */ +INT_HANDLER int_handler_get(const uint32_t intno) +{ + if (intno >= NUM_EXC_CPU) { + return exc_handler_get(intno); + } + + return NULL; +} +#endif /* EMBARC_OVERRIDE_ARC_INTERRUPT_MANAGEMENT */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.c new file mode 100644 index 00000000..39ed46e3 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.c @@ -0,0 +1,390 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +#include "embARC.h" +#include "embARC_debug.h" + +typedef struct main_args { + int argc; + char *argv[]; +} MAIN_ARGS; + +/** Change this to pass your own arguments to main functions */ +MAIN_ARGS s_main_args = {1, {"main"}}; + +#if defined(MID_FATFS) +static FATFS sd_card_fs; /* File system object for each logical drive */ +#endif /* MID_FATFS */ + +#if defined(EMBARC_USE_BOARD_MAIN) +/*--- When new embARC Startup process is used----*/ +#define MIN_CALC(x, y) (((x)<(y))?(x):(y)) +#define MAX_CALC(x, y) (((x)>(y))?(x):(y)) + +#ifdef OS_FREERTOS + +SemaphoreHandle_t spi_mutex; // for more device to connect to spi (pmod 5) +SemaphoreHandle_t vm_queue_mutex; + +/* Note: Task size in unit of StackType_t */ +/* Note: Stack size should be small than 65536, since the stack size unit is uint16_t */ +#define MIN_STACKSZ(size) (MIN_CALC((size)*sizeof(StackType_t), configTOTAL_HEAP_SIZE>>3)/sizeof(StackType_t)) + +#ifdef MID_LWIP + +#include "lwip_pmwifi.h" + +#ifndef TASK_WIFI_PERIOD +#define TASK_WIFI_PERIOD 50 /* WiFi connection task polling period, unit: kernel ticks */ +#endif + +#ifndef TASK_STACK_SIZE_WIFI +/* WiFi task stack size */ +#define TASK_STACK_SIZE_WIFI MIN_STACKSZ(65535) +#endif + +#ifndef TASK_PRI_WIFI +#define TASK_PRI_WIFI (configMAX_PRIORITIES-1) /* WiFi task priority */ +#endif + +static DEV_WNIC *pmwifi_wnic; +static TaskHandle_t task_handle_wifi; + +#endif /* MID_LWIP */ + + +/* the pre-define for vending machine application*/ +#ifdef MID_VM +#include "vm_task.h" + +#ifndef TASK_STACK_SIZE_VM +#define TASK_STACK_SIZE_VM MIN_STACKSZ(1024) +#endif +#ifndef TASK_STACK_SIZE_LED +#define TASK_STACK_SIZE_LED MIN_STACKSZ(256) +#endif +#ifndef TASK_STACK_SIZE_OLED +#define TASK_STACK_SIZE_OLED MIN_STACKSZ(1024) +#endif +#ifndef TASK_STACK_SIZE_COMMUNICATION +#define TASK_STACK_SIZE_COMMUNICATION MIN_STACKSZ(65535) +#endif +#ifndef TASK_STACK_SIZE_TEMP +#define TASK_STACK_SIZE_TEMP MIN_STACKSZ(256) +#endif +#ifndef TASK_STACK_SIZE_NUMPAD +#define TASK_STACK_SIZE_NUMPAD MIN_STACKSZ(256) +#endif +#ifndef TASK_STACK_SIZE_DCMOTOR +#define TASK_STACK_SIZE_DCMOTOR MIN_STACKSZ(256) +#endif + +// the priority is higher for larger # +#ifndef TASK_PRI_VM +#define TASK_PRI_VM 2 +#endif +#ifndef TASK_PRI_LED +#define TASK_PRI_LED 2 +#endif +#ifndef TASK_PRI_OLED +#define TASK_PRI_OLED 2 +#endif +#ifndef TASK_PRI_COMMUNICATION +#define TASK_PRI_COMMUNICATION 2 +#endif +#ifndef TASK_PRI_TEMP +#define TASK_PRI_TEMP 2 +#endif +#ifndef TASK_PRI_NUMPAD +#define TASK_PRI_NUMPAD 2 +#endif +#ifndef TASK_PRI_DCMOTOR +#define TASK_PRI_DCMOTOR 2 +#endif + +static TaskHandle_t task_handle_vm; +static TaskHandle_t task_handle_led; +static TaskHandle_t task_handle_oled; +TaskHandle_t task_handle_communication; +static TaskHandle_t task_handle_temp; +static TaskHandle_t task_handle_numpad; +static TaskHandle_t task_handle_dcmotor; +QueueHandle_t xVMQueue; +QueueHandle_t xMainQueue; +QueueHandle_t xOledQueue; +QueueHandle_t xCommunicationQueue; +QueueHandle_t xTempQueue; +QueueHandle_t xNumPadQueue; +QueueHandle_t xDCmotorQueue; + +#endif +/* MID_VM, vending machine */ + + +#ifdef MID_NTSHELL + +#ifndef TASK_STACK_SIZE_NTSHELL +#define TASK_STACK_SIZE_NTSHELL MIN_STACKSZ(65535) +#endif + +#ifndef TASK_PRI_NTSHELL +#define TASK_PRI_NTSHELL 1 /* NTSHELL task priority */ +#endif +static TaskHandle_t task_handle_ntshell; + +#else /* No middleware ntshell,will activate main task */ + +#ifndef TASK_STACK_SIZE_MAIN +#define TASK_STACK_SIZE_MAIN MIN_STACKSZ(1024) +#endif + +#ifndef TASK_PRI_MAIN +#define TASK_PRI_MAIN 1 /* Main task priority */ +#endif +static TaskHandle_t task_handle_main; + +#endif /* MID_NTSHELL */ + +#endif /* OS_FREERTOS */ + +#if defined(OS_FREERTOS) && defined(MID_LWIP) +static void task_wifi(void *par) +{ + WNIC_AUTH_KEY auth_key; + int flag=0; + + pmwifi_wnic = wnic_get_dev(BOARD_PMWIFI_0_ID); + +#if WF_HOTSPOT_IS_OPEN + auth_key.key = NULL; + auth_key.key_len = 0; + auth_key.key_idx = 0; +#else + auth_key.key = (const uint8_t *)WF_HOTSPOT_PASSWD; + auth_key.key_len = sizeof(WF_HOTSPOT_PASSWD); + auth_key.key_idx = 0; +#endif + lwip_pmwifi_init(); + EMBARC_PRINTF("\r\nNow trying to connect to WIFI hotspot, please wait about 30s!\r\n"); + + while (1) { + pmwifi_wnic->period_process(par); +#if WF_HOTSPOT_IS_OPEN + pmwifi_wnic->wnic_connect(AUTH_SECURITY_OPEN, (const uint8_t *)WF_HOTSPOT_NAME, &auth_key); +#else + pmwifi_wnic->wnic_connect(AUTH_SECURITY_WPA_AUTO_WITH_PASS_PHRASE, (const uint8_t *)WF_HOTSPOT_NAME, &auth_key); +#endif + if ((flag == 0) && lwip_pmwifi_isup()) { + flag = 1; + EMBARC_PRINTF("WiFi connected \r\n"); +#ifndef MID_NTSHELL /* resume main task when ntshell task is not defined */ +#ifdef MID_VM + + //if (communication_task) communication_task (NULL); + //flag = 0; + +#ifdef OS_FREERTOS + if(task_handle_communication) vTaskResume(task_handle_communication); + //vTaskResume(task_handle_wifi); +#else + if (communication_task) communication_task (NULL); + flag = 0; +#endif +#else + if (task_handle_main) vTaskResume(task_handle_main); +#endif +#else + EMBARC_PRINTF("Please run NT-Shell command(main) to start your application.\r\n"); + EMBARC_PRINTF("main command may required some arguments, please refer to example's document.\r\n"); +#endif + /* consider to generate a event to notify network is ready */ + } else if ((flag == 1) && !lwip_pmwifi_isup()){// Wifi Lost connection + if(task_handle_communication) vTaskSuspend(task_handle_communication); + flag = 0; + } + vTaskDelay(TASK_WIFI_PERIOD); + } +} +#endif + +static void task_main(void *par) +{ + int ercd; + EMBARC_PRINTF("Enter to main function....\r\n"); +#if defined(OS_FREERTOS) && defined(MID_LWIP) && !defined(MID_NTSHELL) && !defined(MID_VM) + EMBARC_PRINTF("Wait until WiFi connected...\r\n"); + vTaskSuspend(NULL); +#endif + + if ((par == NULL) || (((int)par) & 0x3)) { + /* null or aligned not to 4 bytes */ + ercd = _arc_goto_main(0, NULL); + } else { + MAIN_ARGS *main_arg = (MAIN_ARGS *)par; + ercd = _arc_goto_main(main_arg->argc, main_arg->argv); + } + +#if defined(OS_FREERTOS) + EMBARC_PRINTF("Exit from main function, error code:%d....\r\n", ercd); + while (1) { + vTaskSuspend(NULL); + } +#else + while (1); +#endif +} + +void board_main(void) +{ +/* board level hardware init */ + board_init(); + +// spi swmaphore: declare lock for spi ifdef FREERTOS +#ifdef OS_FREERTOS +#ifdef MID_VM + spi_mutex = xSemaphoreCreateBinary(); + xSemaphoreGive(spi_mutex); + vm_queue_mutex = xSemaphoreCreateBinary(); + xSemaphoreGive(vm_queue_mutex); +#endif +#endif + +/* board level middlware init */ + +#ifdef MID_COMMON + xprintf_setup(); +#endif + +#ifdef MID_FATFS + if(f_mount(&sd_card_fs, "", 0) != FR_OK) { + EMBARC_PRINTF("FatFS failed to initialize!\r\n"); + } else { + EMBARC_PRINTF("FatFS initialized successfully!\r\n"); + } +#endif + +#ifdef ENABLE_OS + os_hal_exc_init(); +#endif + +// try if the makefile is normal +#ifdef MID_VM +#ifdef OS_FREERTOS + + /* create common-use queue for inter-communication */ + xVMQueue = xQueueCreate(48, sizeof(vm_data)); + + /* create 5 queues for specific usage and device */ + xMainQueue = xQueueCreate(12, sizeof(vm_data)); + xOledQueue = xQueueCreate(12, sizeof(vm_data)); + xCommunicationQueue = xQueueCreate(12, sizeof(vm_data)); + xTempQueue = xQueueCreate(12, sizeof(vm_data)); + xNumPadQueue = xQueueCreate(12, sizeof(vm_data)); + xDCmotorQueue = xQueueCreate(12, sizeof(vm_data)); + + /* create 5 tasks */ + xTaskCreate((TaskFunction_t)vm_task, "vending machine", TASK_STACK_SIZE_VM, NULL, TASK_PRI_VM, &task_handle_vm); + xTaskCreate((TaskFunction_t)LED_task, "led blinky", TASK_STACK_SIZE_LED, NULL, TASK_PRI_LED, &task_handle_led); + xTaskCreate((TaskFunction_t)communication_task, "wifi communication", TASK_STACK_SIZE_COMMUNICATION, NULL, TASK_PRI_COMMUNICATION, &task_handle_communication); + xTaskCreate((TaskFunction_t)temp_task, "temperature", TASK_STACK_SIZE_TEMP, NULL, TASK_PRI_TEMP, &task_handle_temp); + xTaskCreate((TaskFunction_t)numpad_task, "number pad", TASK_STACK_SIZE_NUMPAD, NULL, TASK_PRI_NUMPAD, &task_handle_numpad); + xTaskCreate((TaskFunction_t)dcmotor_task, "DC motor", TASK_STACK_SIZE_DCMOTOR, NULL, TASK_PRI_DCMOTOR, &task_handle_dcmotor); + xTaskCreate((TaskFunction_t)oled_task, "oled", TASK_STACK_SIZE_OLED, NULL, TASK_PRI_OLED, &task_handle_oled); +#endif +#endif + +/* NTSHELL related initialization */ +/* For OS situation, ntshell task will be created; for baremetal ntshell_task will be executed */ +#ifdef MID_NTSHELL + NTSHELL_IO *nt_io; + nt_io = get_ntshell_io(BOARD_ONBOARD_NTSHELL_ID); + +#ifdef OS_FREERTOS + xTaskCreate((TaskFunction_t)ntshell_task, "ntshell-console", TASK_STACK_SIZE_NTSHELL, + (void *)nt_io, TASK_PRI_NTSHELL, &task_handle_ntshell); +#else + cpu_unlock(); /* unlock cpu to let interrupt work */ + /** enter ntshell command routine no return */ + ntshell_task((void *)nt_io); +#endif + +#else /* No ntshell */ +#ifdef OS_FREERTOS + xTaskCreate((TaskFunction_t)task_main, "main_function", TASK_STACK_SIZE_MAIN, + (void *)(&s_main_args), TASK_PRI_MAIN, &task_handle_main); +#else /* No os and ntshell */ + cpu_unlock(); /* unlock cpu to let interrupt work */ +#endif + +#endif /* MID_NTSHELL */ + + +#if defined(OS_FREERTOS) && defined (MID_LWIP) + xTaskCreate((TaskFunction_t)task_wifi, "wifi-conn", TASK_STACK_SIZE_WIFI, + (void *)1, TASK_PRI_WIFI, &task_handle_wifi); +#endif + + + +#ifdef OS_FREERTOS + vTaskStartScheduler(); +#else + task_main((void *)(&s_main_args)); +#endif + +/* board level exit */ +} + +#else /*-- Old embARC Startup process */ + +static void enter_to_main(MAIN_ARGS *main_arg) +{ + if (main_arg == NULL) { + /* null or aligned not to 4 bytes */ + _arc_goto_main(0, NULL); + } else { + _arc_goto_main(main_arg->argc, main_arg->argv); + } +} + +void board_main(void) +{ +#ifdef MID_COMMON + xprintf_setup(); +#endif +#ifdef MID_FATFS + if(f_mount(&sd_card_fs, "", 0) != FR_OK) { + EMBARC_PRINTF("FatFS failed to initialize!\r\n"); + } else { + EMBARC_PRINTF("FatFS initialized successfully!\r\n"); + } +#endif + enter_to_main(&s_main_args); +} +#endif /* EMBARC_USE_BOARD_MAIN */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.mk new file mode 100644 index 00000000..667c2100 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/board.mk @@ -0,0 +1,74 @@ +## +# \defgroup MK_BOARD Board Makefile Configurations +# \brief makefile related to board configurations +## + +# boards root declaration +BOARDS_ROOT = $(EMBARC_ROOT)/board + +## +# BOARD +# select the target board +# scan the sub-dirs of board to get the supported boards +SUPPORTED_BOARDS = $(basename $(notdir $(wildcard $(BOARDS_ROOT)/*/*.mk))) +BOARD ?= emsk +USE_BOARD_MAIN ?= 1 + +override BOARD := $(strip $(BOARD)) +override USE_BOARD_MAIN := $(strip $(USE_BOARD_MAIN)) +override WIFI_SEL := $(strip $(WIFI_SEL)) + +BOARD_CSRCDIR += $(BOARDS_ROOT) +BOARD_ASMSRCDIR += $(BOARDS_ROOT) +BOARD_INCDIR += $(BOARDS_ROOT) + +ifeq ($(USE_BOARD_MAIN), 1) +BOARD_MAIN_DEFINES = -DEMBARC_USE_BOARD_MAIN +else +BOARD_MAIN_DEFINES = +endif + +EXTRA_BOARD_DEFINES += $(BOARD_MAIN_DEFINES) + +ifeq ($(VALID_TOOLCHAIN), mw) +LINKER_SCRIPT_FILE ?= $(BOARDS_ROOT)/linker_template_mw.ld +else +LINKER_SCRIPT_FILE ?= $(BOARDS_ROOT)/linker_template_gnu.ld +endif + +## CPU_FREQ & DEV_FREQ defined in each board support file ## + +## Set Valid Board +VALID_BOARD = $(call check_item_exist, $(BOARD), $(SUPPORTED_BOARDS)) + +## Try Check BOARD is valid +ifeq ($(VALID_BOARD), ) +$(info BOARD - $(SUPPORTED_BOARDS) are supported) +$(error BOARD $(BOARD) is not supported, please check it!) +endif + +#board definition +BOARD_ID = $(call uc,BOARD_$(VALID_BOARD)) +#device usage settings +#must be before include +COMMON_COMPILE_PREREQUISITES += $(BOARDS_ROOT)/$(VALID_BOARD)/$(VALID_BOARD).mk +include $(BOARDS_ROOT)/$(VALID_BOARD)/$(VALID_BOARD).mk + +## +# \brief add defines for board +## +BOARD_DEFINES += $(EXTRA_BOARD_DEFINES) -D$(BOARD_ID) -DHW_VERSION=$(BD_VER) +ifneq ($(CPU_FREQ), ) +BOARD_DEFINES += -DBOARD_CPU_FREQ=$(CPU_FREQ) +endif +ifneq ($(DEV_FREQ), ) +BOARD_DEFINES += -DBOARD_DEV_FREQ=$(DEV_FREQ) +endif + +# extra directories need to be compiled +EXTRA_CSRCDIR += $(BOARDS_ROOT) + +# include dependency files +ifneq ($(MAKECMDGOALS),clean) +-include $(BOARD_DEPS) +endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/common/emsk_init.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/common/emsk_init.c new file mode 100644 index 00000000..d3c9eb87 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/common/emsk_init.c @@ -0,0 +1,70 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +/** + * \defgroup BOARD_EMSK_COMMON_INIT EMSK Common Init Module + * \ingroup BOARD_EMSK_COMMON + * \brief EMSK Board Common Init Module + * \details + * EMSK timer/gpio/interrupt init process. Device-driver installation is done while + * getting the device object for the first time. + */ + +/** + * \file + * \ingroup BOARD_EMSK_COMMON_INIT + * \brief common emsk init module + */ + +/** + * \addtogroup BOARD_EMSK_COMMON_INIT + * @{ + */ +#include "arc_timer.h" +#include "board.h" +#include "emsk_timer.h" +#include "dev_pinmux.h" + + +/** + * \brief Board init routine MUST be called in each application + * \note It is better to disable interrupts when calling this function + * remember to enable interrupt when you want to use them + */ +void board_init(void) +{ + timer_init(); + io_mux_init(); + emsk_gpio_init(); +#ifndef OS_FREERTOS + emsk_timer_init(); +#endif +} + +/** @} end of group BOARD_EMSK_COMMON_INIT */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/drivers/mux/mux.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/drivers/mux/mux.c new file mode 100644 index 00000000..4ced6aa4 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/drivers/mux/mux.c @@ -0,0 +1,216 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +/** + * \defgroup BOARD_EMSK_DRV_MUX EMSK Mux Driver + * \ingroup BOARD_EMSK_DRIVER + * \brief EMSK Mux Controller Driver + * \details + * Mux controller is the hardware external PMOD port pin connection + * controller, it can distribute the external port pins into different + * functions like general input/output, spi, iic, uart and so on. + */ + +/** + * \file + * \ingroup BOARD_EMSK_DRV_MUX + * \brief emsk mux controller driver + */ + +/** + * \addtogroup BOARD_EMSK_DRV_MUX + * @{ + */ +#include "dev_pinmux.h" +#include "mux_hal.h" +#include "mux.h" +#include "embARC_error.h" +#include "arc.h" +#include "arc_builtin.h" +#include "../../emsk.h" + +static MUX_REG *mux_regs; + +/** set PMOD muxer scheme */ +void set_pmod_mux(uint32_t val) +{ + mux_regs[PMOD_MUX_CTRL] = val; +} + +/** get PMOD muxer scheme */ +uint32_t get_pmod_mux(void) +{ + return (uint32_t) mux_regs[PMOD_MUX_CTRL]; +} + +/** set SPI connection scheme */ +void set_spi_map(uint32_t val) +{ + mux_regs[SPI_MAP_CTRL] = val; +} + +/** set UART connection scheme */ +void set_uart_map(uint32_t val) +{ + mux_regs[UART_MAP_CTRL] = val; +} + +int32_t io_mikro_config(uint32_t config) +{ + /* no mikro interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_spi(uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_uart(uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_i2c(uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_ad(uint32_t num, uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_pwm(uint32_t num, uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + +int32_t io_arduino_config_gpio(uint32_t num, uint32_t config) +{ + /* no arduino interface */ + return E_NOSPT; +} + + +int32_t io_pmod_config(uint32_t pmod, uint32_t type, uint32_t config) +{ + uint32_t val = get_pmod_mux(); + switch (pmod) { + case PMOD_1: /* PMOD GPIO, PMOD_UART */ + if (type == PMOD_GPIO) { + val &= ~(PM1_UR_UART_0 | PM1_LR_SPI_S); + } else if (type == PMOD_UART) { + val |= PM1_UR_UART_0; + } else { + return E_NOSPT; + } + break; + case PMOD_2: /* PMOD GPIO, PMOD_I2C */ + case PMOD_3: + case PMOD_4: + pmod--; + pmod <<= 2; /* (pmode - 1) * 4*/ + if (type == PMOD_GPIO) { + val &= ~(1 << pmod); + } else if (type == PMOD_I2C) { + val |= (1 << pmod); + } else { + return E_NOSPT; + } + break; + case PMOD_5: /* PMOD GPIO, PMOD_SPI */ + if (type == PMOD_GPIO) { + val &= ~(PM5_UR_SPI_M1); + } else if (type == PMOD_SPI) { + val |= PM5_UR_SPI_M1; + } else { + return E_NOSPT; + } + break; + case PMOD_6: /* PMOD GPIO, PMOD_SPI */ + if (type == PMOD_GPIO) { + val &= ~(PM6_UR_SPI_M0); + } else if (type == PMOD_SPI) { + val |= PM6_UR_SPI_M0; + } else { + return E_NOSPT; + } + break; + default: + return E_PAR; + } + + set_pmod_mux(val); + + return E_OK; +} + +void io_mux_init(void) +{ + mux_regs = (MUX_REG *)(PERIPHERAL_BASE | REL_REGBASE_PINMUX); + // Initialize Mux controller registers by default values + mux_regs[PMOD_MUX_CTRL] = PMOD_MUX_CTRL_DEFAULT; + mux_regs[SPI_MAP_CTRL] = SPI_MAP_CTRL_DEFAULT; + mux_regs[UART_MAP_CTRL] = UART_MAP_CTRL_DEFAULT; + + /** + * + Please refer to corresponding EMSK User Guide for detailed information + * -> Appendix: A Hardware Functional Description + * -> Pmods Configuration summary + * + Set up pin-multiplexer of all PMOD connections + * - PM1 J1: Upper row as UART 0, lower row as SPI Slave + * - PM2 J2: IIC 0 and run/halt signals + * - PM3 J3: GPIO Port A and Port C + * - PM4 J4: IIC 1 and Port D + * - PM5 J5: Upper row as SPI Master, lower row as Port A + * - PM6 J6: Upper row as SPI Master, lower row as Port A + */ + set_pmod_mux(PM1_UR_GPIO_C | PM1_LR_GPIO_A \ + | PM2_I2C_HRI \ + | PM3_GPIO_AC \ + | PM4_I2C_GPIO_D \ + | PM5_UR_SPI_M1 | PM5_LR_GPIO_A \ + | PM6_UR_SPI_M0 | PM6_LR_GPIO_A ); + + /** + * PM1 upper row as UART + * UM4:RXD, UM3:TXD + * UM2:RTS_N, UM1:CTS_N + */ + set_uart_map(0xe4); +} + +/** @} end of group BOARD_EMSK_DRV_MUX */ + diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/emsk.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/emsk.h new file mode 100644 index 00000000..9164ea66 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/board/emsk/emsk.h @@ -0,0 +1,183 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +/** + * + * \file + * \ingroup BOARD_EMSK_COMMON_INIT + * \brief emsk resource definitions + */ + +/** + * \addtogroup BOARD_EMSK_COMMON_INIT + * @{ + */ +#ifndef _EMSK_H_ +#define _EMSK_H_ + +#include "arc_em.h" +#include "arc_builtin.h" + +#include "drivers/ip/designware/iic/dw_iic_obj.h" +#include "drivers/ip/designware/spi/dw_spi_obj.h" +#include "drivers/ip/designware/uart/dw_uart_obj.h" +#include "drivers/ip/designware/gpio/dw_gpio_obj.h" +#include "drivers/ntshell/ntshell_io.h" +#include "drivers/sdcard/emsk_sdcard.h" +#include "drivers/pmwifi/pmwifi.h" +#include "dev_pinmux.h" + +#include "common/emsk_timer.h" +#include "common/emsk_gpio.h" + +#include "emsk_hardware.h" + +#ifdef ARC_FEATURE_DMP_PERIPHERAL +#define PERIPHERAL_BASE ARC_FEATURE_DMP_PERIPHERAL +#else +#define PERIPHERAL_BASE _arc_aux_read(AUX_DMP_PERIPHERAL) +#endif + +/* common macros must be defined by all boards */ + +#define BOARD_CONSOLE_UART_ID DW_UART_1_ID +#define BOARD_CONSOLE_UART_BAUD UART_BAUDRATE_115200 +#define BOARD_ADC_IIC_ID DW_IIC_0_ID +#define BOARD_TEMP_SENSOR_IIC_ID DW_IIC_0_ID + +#define BOARD_TEMP_IIC_SLVADDR TEMP_I2C_SLAVE_ADDRESS + +#define BOARD_SDCARD_SPI_ID DW_SPI_0_ID +#define BOARD_WIFI_SPI_ID DW_SPI_0_ID +#define BOARD_SFLASH_SPI_ID DW_SPI_0_ID + +#define BOARD_SDCARD_SPI_LINE EMSK_SPI_LINE_SDCARD +#define BOARD_WIFI_SPI_LINE EMSK_SPI_LINE_1 +#define BOARD_SFLASH_SPI_LIN EMSK_SPI_LINE_SFLASH + +#ifndef BOARD_SPI_FREQ +#define BOARD_SPI_FREQ (1000000) +#endif + + +#define BOARD_SYS_TIMER_ID TIMER_0 +#define BOARD_SYS_TIMER_INTNO INTNO_TIMER0 +#define BOARD_SYS_TIMER_HZ (1000) + +/** board timer count frequency (HZ) */ +#define BOARD_SYS_TIMER_MS_HZ (1000) +/** board timer count frequency convention based on the global timer counter */ +#define BOARD_SYS_TIMER_MS_CONV (BOARD_SYS_TIMER_MS_HZ/BOARD_SYS_TIMER_HZ) + +#define BOARD_OS_TIMER_ID TIMER_0 +#define BOARD_OS_TIMER_INTNO INTNO_TIMER0 + +#define BOARD_CPU_CLOCK CLK_CPU +#define BOARD_DEV_CLOCK CLK_BUS_APB + +#define BOARD_LED_MASK (0x1ff) +#define BOARD_LED_CNT (9) +#define BOARD_BTN_MASK (0x7) +#define BOARD_BTN_CNT (3) +#define BOARD_SWT_MASK (0xf) +#define BOARD_SWT_CNT (4) + +#define BOARD_ONBOARD_NTSHELL_ID (EMSK_NTSHELL_0_ID) +#define NTSHELL_CONSOLE_ID (EMSK_NTSHELL_0_ID) +#define NTSHELL_NETWORK_ID (EMSK_NTSHELL_1_ID) + +#define OSP_DELAY_OS_COMPAT_ENABLE (1) +#define OSP_DELAY_OS_COMPAT_DISABLE (0) + +#define WF_IPADDR_1 (192) +#define WF_IPADDR_2 (168) +#define WF_IPADDR_3 (43) +#define WF_IPADDR_4 (102) + +#define WF_NETMASK_1 (255) +#define WF_NETMASK_2 (255) +#define WF_NETMASK_3 (255) +#define WF_NETMASK_4 (0) + +#define WF_GATEWAY_1 (192) +#define WF_GATEWAY_2 (168) +#define WF_GATEWAY_3 (43) +#define WF_GATEWAY_4 (1) + +#define WF_HOTSPOT_IS_OPEN (0) + +#define WF_IPADDR_DHCP (1) + +//#define WF_HOTSPOT_NAME "Big big dictionary" +//#define WF_HOTSPOT_PASSWD "12345678" +//#define WF_HOTSPOT_NAME "KF_0520_wifi" +//#define WF_HOTSPOT_PASSWD "kf0520kf" +//#define WF_HOTSPOT_NAME "JIZZ" +//#define WF_HOTSPOT_PASSWD "71222217" +#define WF_HOTSPOT_NAME "Kai iPhone" +#define WF_HOTSPOT_PASSWD "chuahdeekai" +//#define WF_HOTSPOT_NAME "Andy iPhone" +//#define WF_HOTSPOT_PASSWD "smalldeer" +//#define WF_HOTSPOT_NAME "need password" +//#define WF_HOTSPOT_PASSWD "password" + +#define WF_ENABLE_MANUAL_SET_MAC (0) + +#define WF_MAC_ADDR0 (EMSK_PMWIFI_0_MAC_ADDR0) +#define WF_MAC_ADDR1 (EMSK_PMWIFI_0_MAC_ADDR1) +#define WF_MAC_ADDR2 (EMSK_PMWIFI_0_MAC_ADDR2) +#define WF_MAC_ADDR3 (EMSK_PMWIFI_0_MAC_ADDR3) +#define WF_MAC_ADDR4 (EMSK_PMWIFI_0_MAC_ADDR4) +#define WF_MAC_ADDR5 (EMSK_PMWIFI_0_MAC_ADDR5) + +#define BOARD_PMWIFI_0_ID EMSK_PMWIFI_0_ID +#define BOARD_PMWIFI_ID_MAX EMSK_PMWIFI_0_ID + +#define OSP_GET_CUR_SYSHZ() (gl_emsk_sys_hz_cnt) +#define OSP_GET_CUR_MS() (gl_emsk_ms_cnt) +#define OSP_GET_CUR_US() board_get_cur_us() +#define OSP_GET_CUR_HWTICKS() board_get_hwticks() + +#ifdef __cplusplus +extern "C" { +#endif + +extern void board_init(void); +extern void board_timer_update(uint32_t precision); +extern void board_delay_ms(uint32_t ms, uint8_t os_compat); +extern uint64_t board_get_hwticks(void); +extern uint64_t board_get_cur_us(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _EMSK_H_ */ + +/** @} end of group BOARD_EMSK_COMMON_INIT */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/ip/designware/spi/dw_spi.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/ip/designware/spi/dw_spi.c new file mode 100644 index 00000000..b48a5396 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/ip/designware/spi/dw_spi.c @@ -0,0 +1,1371 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ + +/** + * \defgroup DEVICE_DW_SPI Designware SPI Driver + * \ingroup DEVICE_DW + * \brief Designware SPI Driver Implementation + */ + +/** + * \file + * \brief DesignWare SPI driver implementation based on device hal layer definition (\ref dev_spi.h) + * \ingroup DEVICE_DW_SPI + */ +#include + +#ifdef OS_FREERTOS +#include "embARC.h" +#include "embARC_debug.h" +#endif + +#include "embARC_toolchain.h" +#include "embARC_error.h" + +#include "arc_exception.h" + +#include "dw_spi_hal.h" +#include "dw_spi.h" + +// spi semaphore notice: ifdef FREERTOS, extern the lock here +#ifdef OS_FREERTOS +extern SemaphoreHandle_t spi_mutex; +#endif + +/** + * \defgroup DEVICE_DW_SPI_DEFINES DesignWare SPI Driver Macros + * \ingroup DEVICE_DW_SPI + * \brief DesignWare SPI driver macros used in spi driver + * @{ + */ +/** check expressions used in DesignWare SPI driver implementation */ +#define DW_SPI_CHECK_EXP(EXPR, ERROR_CODE) CHECK_EXP(EXPR, ercd, ERROR_CODE, error_exit) + +/** convert DesignWare frequence to divisor */ +#define DW_SPI_FREQ2DV(perifreq, spifreq) ((perifreq) / (spifreq)) + +#ifndef DISABLE_DEVICE_OBJECT_VALID_CHECK +/** valid check of spi info object */ +#define VALID_CHK_SPI_INFO_OBJECT(spiinfo_obj_ptr) { \ + DW_SPI_CHECK_EXP((spiinfo_obj_ptr)!=NULL, E_OBJ); \ + DW_SPI_CHECK_EXP(((spiinfo_obj_ptr)->spi_ctrl)!=NULL, E_OBJ); \ + } +#endif + +/** + * \defgroup DEVICE_DW_SPI_DEF_CBR DesignWare SPI Interrupt Callback Routine Select Marcos + * \ingroup DEVICE_DW_SPI_DEFINES + * \brief DesignWare SPI interrupt callback routines select macros definitions + * @{ + */ +#define DW_SPI_RDY_SND (1U) /*!< ready to send callback */ +#define DW_SPI_RDY_RCV (2U) /*!< ready to receive callback */ +#define DW_SPI_RDY_XFER (3U) /*!< ready to transfer callback */ +/** @} */ + +/** @} */ + +/** + * \defgroup DEVICE_DW_SPI_STATIC DesignWare SPI Driver Static Functions + * \ingroup DEVICE_DW_SPI + * \brief Static or inline functions, variables for DesignWare SPI handle spi operations, + * only used in this file. + * @{ + */ + +/** Disable designware spi device */ +Inline void dw_spi_disable(DW_SPI_REG *spi_reg_ptr) +{ +/** disable spi operations, then program spi control regs is possible */ + spi_reg_ptr->SSIENR = DW_SPI_SSI_DISABLE; +} +/** Enable designware spi device */ +Inline void dw_spi_enable(DW_SPI_REG *spi_reg_ptr) +{ + spi_reg_ptr->SSIENR = DW_SPI_SSI_ENABLE; +} + +/** Clear all designware spi interrupt */ +Inline void dw_spi_clear_interrupt_all(DW_SPI_REG *spi_reg_ptr) +{ + (void)spi_reg_ptr->ICR; +} + +/** test whether spi is busy, busy return 1, else 0 */ +Inline int32_t dw_spi_busy(DW_SPI_REG *spi_reg_ptr) +{ + return ((spi_reg_ptr->SR & DW_SPI_SR_BUSY) != 0); +} +/** test whether spi is ready to send, 1 ready, 0 not ready */ +Inline int32_t dw_spi_putready(DW_SPI_REG *spi_reg_ptr) +{ + return ((spi_reg_ptr->SR & DW_SPI_SR_TFNF) != 0); +} +/** test whether spi is read to receive, 1 ready, 0 not ready */ +Inline int32_t dw_spi_getready(DW_SPI_REG *spi_reg_ptr) +{ + return ((spi_reg_ptr->SR & DW_SPI_SR_RFNE) != 0); +} +/** write data to spi send fifo */ +Inline void dw_spi_putdata(DW_SPI_REG *spi_reg_ptr, int32_t data) +{ + spi_reg_ptr->DATAREG = (uint32_t)data; +} +/** read data from spi receive fifo, return data received */ +Inline int32_t dw_spi_getdata(DW_SPI_REG *spi_reg_ptr) +{ + return (int32_t)spi_reg_ptr->DATAREG; +} +/** + * \brief send data by spi when available, + * mostly used in interrupt method, non-blocked function + * \param[in] spi_reg_ptr spi register structure pointer + * \param[in] data data to be sent + * \retval E_OK send successfully + * \retval E_OBJ not ready to send data + */ +Inline int32_t dw_spi_snd_dat(DW_SPI_REG *spi_reg_ptr, int32_t data) +{ + if (dw_spi_putready(spi_reg_ptr)) { + dw_spi_putdata(spi_reg_ptr, data); + return E_OK; + } + return E_OBJ; +} +/** + * \brief receive one char from spi, + * mostly used in interrupt routine, non-blocked function + * \param[in] spi_reg_ptr spi register structure pointer + * \return data received by the spi + */ +Inline int32_t dw_spi_rcv_dat(DW_SPI_REG *spi_reg_ptr) +{ + return dw_spi_getdata(spi_reg_ptr); +} +/** + * \brief send char by spi in poll method, blocked function + * \param[in] spi_reg_ptr spi register structure pointer + * \param[in] data data to be sent + */ +Inline void dw_spi_psnd_dat(DW_SPI_REG *spi_reg_ptr, int32_t data) +{ + /** wait until spi is ready to send */ + while (!dw_spi_putready(spi_reg_ptr)); /* blocked */ + /** send char */ + dw_spi_putdata(spi_reg_ptr, data); +} +/** + * \brief receive one char from spi in poll method, blocked function + * \param[in] spi_reg_ptr spi register structure pointer + * \return data received by the spi + */ +Inline int32_t dw_spi_prcv_dat(DW_SPI_REG *spi_reg_ptr) +{ + /** wait until spi is ready to receive */ + while (!dw_spi_getready(spi_reg_ptr)); /* blocked */ + /** receive data */ + return dw_spi_getdata(spi_reg_ptr); +} + +/** Reset designware FIFO by disable spi device, then enable device */ +Inline void dw_spi_reset_fifo(DW_SPI_REG *spi_reg_ptr) +{ + dw_spi_disable(spi_reg_ptr); + dw_spi_enable(spi_reg_ptr); +} + +/** Enable designware spi bit interrupt with mask */ +Inline void dw_spi_unmask_interrupt(DW_SPI_REG *spi_reg_ptr, uint32_t mask) +{ + spi_reg_ptr->IMR |= mask; +} + +/** Disable designware spi bit interrupt with mask */ +Inline void dw_spi_mask_interrupt(DW_SPI_REG *spi_reg_ptr, uint32_t mask) +{ + spi_reg_ptr->IMR &= ~mask; +} + +/** Set designware spi device frequency */ +Inline void dw_spi_set_freq(DW_SPI_CTRL *spi_ctrl_ptr, uint32_t freq) +{ + uint32_t sck_divisor; + DW_SPI_REG *spi_reg_ptr = spi_ctrl_ptr->dw_spi_regs; + + dw_spi_disable(spi_reg_ptr); + + sck_divisor = DW_SPI_FREQ2DV(spi_ctrl_ptr->dw_apb_bus_freq, freq); + spi_reg_ptr->BAUDR = sck_divisor; + dw_spi_enable(spi_reg_ptr); +} + +/** Set designware spi device data frame size */ +static int32_t dw_spi_set_dfs(DW_SPI_REG *spi_reg_ptr, uint32_t dfs) +{ + uint32_t ctrl0_reg; + if ((dfs <= 3) || (dfs > 16)) return -1; + + dw_spi_disable(spi_reg_ptr); + ctrl0_reg = spi_reg_ptr->CTRLR0; + ctrl0_reg &= ~(DW_SPI_CTRLR0_DFS_MASK); + spi_reg_ptr->CTRLR0 = ctrl0_reg | (dfs-1); + dw_spi_enable(spi_reg_ptr); + + return 0; +} + +/** Choose proper designware spi clock mode setting value */ +Inline uint32_t dw_spi_select_clockmode(uint32_t clk_mode) +{ + return (clk_mode << DW_SPI_CTRLR0_SC_OFS); +} + +/** Set designware spi clock mode */ +Inline int32_t dw_spi_set_clockmode(DW_SPI_REG *spi_reg_ptr, uint32_t clk_mode) +{ + if (clk_mode > SPI_CPOL_1_CPHA_1) { + return -1; + } + dw_spi_disable(spi_reg_ptr); + spi_reg_ptr->CTRLR0 &= ~(DW_SPI_CTRLR0_SC_MASK); + spi_reg_ptr->CTRLR0 |= dw_spi_select_clockmode(clk_mode); + dw_spi_enable(spi_reg_ptr); + return 0; +} + +/** Select a spi slave with slv_line */ +Inline int32_t dw_spi_select_slave(DW_SPI_REG *spi_reg_ptr, uint32_t slv_line) +{ + /* check if spi busy */ + if (dw_spi_busy(spi_reg_ptr)) return -1; + + spi_reg_ptr->SER = 1<SER = 0; + return 0; +} + +Inline void dw_spi_flush_tx(DW_SPI_REG *spi_reg_ptr) +{ + dw_spi_reset_fifo(spi_reg_ptr); +} + +Inline void dw_spi_flush_rx(DW_SPI_REG *spi_reg_ptr) +{ + dw_spi_reset_fifo(spi_reg_ptr); +} + +/** Get TX FIFO Length. + * calculate spi fifo length using fifo threshold method + * If you attempt to set bits [7:0] of this register to + * a value greater than or equal to the depth of the FIFO, + * this field is not written and retains its current value. + */ +static uint32_t dw_spi_get_txfifo_len(DW_SPI_REG *spi_reg_ptr) +{ + uint32_t fifo_thr_lev_tmp, left, right, i; + + fifo_thr_lev_tmp = spi_reg_ptr->TXFTLR; + + if (fifo_thr_lev_tmp != 0) { + left = fifo_thr_lev_tmp; + } else { + left = DW_SPI_MIN_FIFO_LENGTH; + } + right = DW_SPI_MAX_FIFO_LENGTH + 1; + + for (i = left; i <= right; i++) { + spi_reg_ptr->TXFTLR = i; + if (spi_reg_ptr->TXFTLR != i) { + break; + } + } + spi_reg_ptr->TXFTLR = fifo_thr_lev_tmp; /* restore old fifo threshold */ + + return (i); +} + +/** Get RX FIFO Length */ +static uint32_t dw_spi_get_rxfifo_len(DW_SPI_REG *spi_reg_ptr) +{ + uint32_t fifo_thr_lev_tmp, left, right, i; + + fifo_thr_lev_tmp = spi_reg_ptr->RXFTLR; + + if (fifo_thr_lev_tmp != 0) { + left = fifo_thr_lev_tmp; + } else { + left = DW_SPI_MIN_FIFO_LENGTH; + } + right = DW_SPI_MAX_FIFO_LENGTH + 1; + + for (i = left; i <= right; i++) { + spi_reg_ptr->RXFTLR = i; + if (spi_reg_ptr->RXFTLR != i) { + break; + } + } + spi_reg_ptr->RXFTLR = fifo_thr_lev_tmp; /* restore old fifo threshold */ + + return (i); +} + +/** Init Designware SPI Hardware */ +static void dw_spi_hw_init(DW_SPI_CTRL *spi_ctrl_ptr, uint32_t clk_mode, uint32_t dfs) +{ + uint32_t ctrl0_reg = 0; + DW_SPI_REG *spi_reg_ptr = spi_ctrl_ptr->dw_spi_regs; + + dw_spi_disable(spi_reg_ptr); + + /* Clear interrupts */ + ctrl0_reg = spi_reg_ptr->ICR; + /* Mask all interrupts */ + spi_reg_ptr->IMR = 0; + + ctrl0_reg = DW_SPI_CTRLR0_FRF_MOTOROLA | DW_SPI_TMOD_TRANSMIT_RECEIVE \ + | dw_spi_select_clockmode(clk_mode) | (dfs - 1) | DW_SPI_CTRLR0_SLV_OE_ENABLE; + spi_reg_ptr->CTRLR0 = ctrl0_reg; + spi_reg_ptr->CTRLR1 = 0; + + /* deselect slaves */ + spi_reg_ptr->SER = 0; + + /* Set threshold values for both tx and rx */ + spi_reg_ptr->TXFTLR = 0; + spi_reg_ptr->RXFTLR = 0; + + spi_reg_ptr->RX_SAMPLE_DLY = spi_ctrl_ptr->rx_sampledly; + + dw_spi_enable(spi_reg_ptr); +} + +/** enable designware spi */ +static void dw_spi_enable_device(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + + if ((spi_info_ptr->status & DEV_ENABLED) == 0) { + dw_spi_enable(spi_reg_ptr); + spi_info_ptr->status |= DEV_ENABLED; + } +} + +/** disable designware spi */ +static void dw_spi_disable_device(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + + dw_spi_disable(spi_reg_ptr); + spi_info_ptr->status &= ~DEV_ENABLED; +} + + +/** + * \brief disable designware spi send or receive interrupt + * \param[in] DEV_SPI_INFO *spi_info_ptr + * \param[in] cbrtn control code of callback routine of send or receive + */ +static int32_t dw_spi_dis_cbr(DEV_SPI_INFO *spi_info_ptr, uint32_t cbrtn) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + int32_t ercd = E_OK; + + if ((spi_info_ptr->status & DW_SPI_IN_XFER) != 0) { /* only in transfer need do check */ + switch (cbrtn) { + case DW_SPI_RDY_SND: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_TX, E_CTX); + spi_info_ptr->status &= ~(DW_SPI_IN_TX); + break; + case DW_SPI_RDY_RCV: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_RX, E_CTX); + spi_info_ptr->status &= ~(DW_SPI_IN_RX); + break; + case DW_SPI_RDY_XFER: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_XFER, E_CTX); + spi_info_ptr->status &= ~(DW_SPI_IN_XFER); + break; + default: + break; + } + } + + dw_spi_mask_interrupt(spi_ctrl_ptr->dw_spi_regs, DW_SPI_IMR_XFER); + + if (spi_ctrl_ptr->int_status & DW_SPI_GINT_ENABLE) { + if (spi_ctrl_ptr->intno != DW_SPI_INVALID_INTNO) { + int_disable(spi_ctrl_ptr->intno); + } + spi_ctrl_ptr->int_status &= ~DW_SPI_GINT_ENABLE; + } + +error_exit: + return ercd; +} + +/** + * \brief enable DesignWare SPI send or receive interrupt + * \param[in] DEV_SPI_INFO *spi_info_ptr + * \param[in] cbrtn control code of callback routine of send or receive + */ +static int32_t dw_spi_ena_cbr(DEV_SPI_INFO *spi_info_ptr, uint32_t cbrtn) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + int32_t ercd = E_OK; + + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == 0, E_CTX); + switch (cbrtn) { + case DW_SPI_RDY_SND: + spi_info_ptr->status |= DW_SPI_IN_TX; + break; + case DW_SPI_RDY_RCV: + spi_info_ptr->status |= DW_SPI_IN_RX; + break; + case DW_SPI_RDY_XFER: + spi_info_ptr->status |= DW_SPI_IN_XFER; + break; + default: + break; + } + dw_spi_unmask_interrupt(spi_ctrl_ptr->dw_spi_regs, DW_SPI_IMR_XFER); + + if ((spi_ctrl_ptr->int_status & DW_SPI_GINT_ENABLE) == 0) { + spi_ctrl_ptr->int_status |= DW_SPI_GINT_ENABLE; + if (spi_ctrl_ptr->intno != DW_SPI_INVALID_INTNO) { + int_enable(spi_ctrl_ptr->intno); + } + } + +error_exit: + return ercd; +} + +/** + * \brief enable designware spi interrupt + * \param spi_info_ptr spi information structure pointer + */ +static void dw_spi_enable_interrupt(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + + if (spi_ctrl_ptr->intno != DW_SPI_INVALID_INTNO) { + int_handler_install(spi_ctrl_ptr->intno, spi_ctrl_ptr->dw_spi_int_handler); + spi_ctrl_ptr->int_status |= DW_SPI_GINT_ENABLE; + /** enable spi interrupt */ + int_enable(spi_ctrl_ptr->intno); + } else { + spi_ctrl_ptr->int_status |= DW_SPI_GINT_ENABLE; + } +} +/** + * \brief disable designware spi interrupt + * \param spi_info_ptr spi information structure pointer + */ +static void dw_spi_disable_interrupt(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + + /** disable spi send&receive interrupt after disable spi interrupt */ + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_SND); + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_RCV); + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_XFER); + /* disable spi interrupt */ + dw_spi_mask_interrupt(spi_ctrl_ptr->dw_spi_regs, DW_SPI_IMR_XFER); + spi_info_ptr->status &= ~DW_SPI_IN_XFER; + if (spi_ctrl_ptr->intno != DW_SPI_INVALID_INTNO) { + int_disable(spi_ctrl_ptr->intno); + } + spi_ctrl_ptr->int_status &= ~(DW_SPI_GINT_ENABLE); +} + +static void dw_spi_reset_device(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + + dw_spi_disable_device(spi_info_ptr); + dw_spi_disable_interrupt(spi_info_ptr); + dw_spi_clear_interrupt_all(spi_reg_ptr); + dw_spi_enable_device(spi_info_ptr); +} + +/** abort current interrupt transmit transfer */ +static int32_t dw_spi_abort_tx(DEV_SPI *spi_obj) +{ + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + int32_t ercd = E_OK; + + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) != 0, E_OK); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_TX, E_CTX); + + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_SND); + spi_info_ptr->status |= DEV_IN_TX_ABRT; + if (spi_info_ptr->spi_cbs.tx_cb != NULL) { + spi_info_ptr->spi_cbs.tx_cb(spi_obj); + } + spi_info_ptr->status &= ~(DEV_IN_TX_ABRT); + +error_exit: + return ercd; +} + +/** abort current interrupt receive transfer */ +static int32_t dw_spi_abort_rx(DEV_SPI *spi_obj) +{ + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + int32_t ercd = E_OK; + + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) != 0, E_OK); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_RX, E_CTX); + + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_RCV); + spi_info_ptr->status |= DEV_IN_RX_ABRT; + if (spi_info_ptr->spi_cbs.rx_cb != NULL) { + spi_info_ptr->spi_cbs.rx_cb(spi_obj); + } + spi_info_ptr->status &= ~(DEV_IN_RX_ABRT); + +error_exit: + return ercd; +} + +/** abort current interrupt transfer */ +static int32_t dw_spi_abort_xfer(DEV_SPI *spi_obj) +{ + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + int32_t ercd = E_OK; + + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) != 0, E_OK); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_XFER, E_CTX); + + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_XFER); + spi_info_ptr->status |= DEV_IN_XFER_ABRT; + if (spi_info_ptr->spi_cbs.xfer_cb != NULL) { + spi_info_ptr->spi_cbs.xfer_cb(spi_obj); + } + spi_info_ptr->status &= ~(DEV_IN_XFER_ABRT); + +error_exit: + return ercd; +} + +/** Get available transmit fifo count */ +static int32_t dw_spi_get_txavail(DW_SPI_CTRL *spi_ctrl_ptr) +{ + int32_t tx_avail = 0; + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + +#if DW_SPI_CALC_FIFO_LEN_ENABLE + if (spi_ctrl_ptr->tx_fifo_len <= 1) { + if (dw_spi_putready(spi_reg_ptr) == 1) { + tx_avail = 1; + } else { + tx_avail = 0; + } + } else +#endif + { + tx_avail = spi_ctrl_ptr->tx_fifo_len - spi_reg_ptr->TXFLR; + } + return tx_avail; +} + +/** Get available receive fifo count */ +static int32_t dw_spi_get_rxavail(DW_SPI_CTRL *spi_ctrl_ptr) +{ + int32_t rx_avail = 0; + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + +#if DW_SPI_CALC_FIFO_LEN_ENABLE + if (spi_ctrl_ptr->rx_fifo_len <= 1) { + if (dw_spi_getready(spi_reg_ptr) == 1) { + rx_avail = 1; + } else { + rx_avail = 0; + } + } else +#endif + { + rx_avail = spi_reg_ptr->RXFLR; + } + return rx_avail; +} + +static uint32_t dw_spi_tx_max(DW_SPI_CTRL *spi_ctrl_ptr) +{ + uint32_t tx_left, tx_room; + DW_SPI_TRANSFER *xfer = &(spi_ctrl_ptr->dw_xfer); + + tx_left = (xfer->xfer_len - xfer->tx_idx) / xfer->nbytes; + tx_room = dw_spi_get_txavail(spi_ctrl_ptr); + + return (tx_left < tx_room) ? tx_left : tx_room; +} + +static uint32_t dw_spi_rx_max(DW_SPI_CTRL *spi_ctrl_ptr) +{ + uint32_t rx_left, rx_room; + DW_SPI_TRANSFER *xfer = &(spi_ctrl_ptr->dw_xfer); + + rx_left = (xfer->xfer_len - xfer->rx_idx) / xfer->nbytes; + rx_room = dw_spi_get_rxavail(spi_ctrl_ptr); + + return (rx_left < rx_room) ? rx_left : rx_room; +} + +Inline int32_t dw_spi_rx_end(DW_SPI_CTRL *spi_ctrl_ptr) +{ + DW_SPI_TRANSFER *xfer = &(spi_ctrl_ptr->dw_xfer); + + return (xfer->rx_idx >= xfer->xfer_len); +} + +Inline int32_t dw_spi_tx_end(DW_SPI_CTRL *spi_ctrl_ptr) +{ + DW_SPI_TRANSFER *xfer = &(spi_ctrl_ptr->dw_xfer); + + return (xfer->tx_idx >= xfer->xfer_len); +} + +/** 1 for end, 0 for not end */ +Inline int32_t dw_spi_xfer_end(DW_SPI_CTRL *spi_ctrl_ptr) +{ + return (dw_spi_tx_end(spi_ctrl_ptr) && dw_spi_rx_end(spi_ctrl_ptr)); +} + +static int32_t dw_spi_writer(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + DW_SPI_TRANSFER *dw_xfer = &(spi_ctrl_ptr->dw_xfer); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + uint32_t tx_max = dw_spi_tx_max(spi_ctrl_ptr); + int32_t tx_w; + uint32_t tx_cnt = tx_max; + + if (dw_xfer->tx_xfer == NULL) { + return 0; + } + while (tx_max) { + if (dw_xfer->tx_xfer->tx_idx >= dw_xfer->tx_xfer->tot_len) { + dw_xfer->tx_xfer = dw_xfer->tx_xfer->next; + if (dw_xfer->tx_xfer == NULL) { + break; + } + } + if ( (dw_xfer->tx_xfer->tx_idx >= dw_xfer->tx_xfer->tx_ofs) \ + && (dw_xfer->tx_xfer->tx_idx < dw_xfer->tx_xfer->tx_totlen)) { + if (dw_xfer->nbytes == 1) { + tx_w = (int32_t)(*(int8_t *)(dw_xfer->tx_xfer->tx_buf)); + } else { + tx_w = (int32_t)(*(int16_t *)(dw_xfer->tx_xfer->tx_buf)); + } + dw_xfer->tx_xfer->tx_buf += dw_xfer->nbytes; + } else { + tx_w = spi_info_ptr->dummy; + } + dw_spi_putdata(spi_reg_ptr, tx_w); + dw_xfer->tx_xfer->tx_idx += dw_xfer->nbytes; + dw_xfer->tx_idx += dw_xfer->nbytes; + tx_max --; + } + return ((tx_cnt-tx_max) * dw_xfer->nbytes); +} + +static int32_t dw_spi_reader(DEV_SPI_INFO *spi_info_ptr) +{ + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + DW_SPI_TRANSFER *dw_xfer = &(spi_ctrl_ptr->dw_xfer); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + uint32_t rx_max = dw_spi_rx_max(spi_ctrl_ptr); + int32_t rx_w; + uint32_t rx_cnt = rx_max; + + if (dw_xfer->rx_xfer == NULL) { + return 0; + } + while (rx_max) { + if (dw_xfer->rx_xfer->rx_idx >= dw_xfer->rx_xfer->tot_len) { + dw_xfer->rx_xfer = dw_xfer->rx_xfer->next; + if (dw_xfer->rx_xfer == NULL) { + break; + } + } + rx_w = dw_spi_getdata(spi_reg_ptr); + if ( (dw_xfer->rx_xfer->rx_idx >= dw_xfer->rx_xfer->rx_ofs) \ + && (dw_xfer->rx_xfer->rx_idx < dw_xfer->rx_xfer->rx_totlen) ) { + if (dw_xfer->nbytes == 1) { + *(int8_t *)(dw_xfer->rx_xfer->rx_buf) = rx_w; + } else { + *(int16_t *)(dw_xfer->rx_xfer->rx_buf) = rx_w; + } + dw_xfer->rx_xfer->rx_buf += dw_xfer->nbytes; + } + dw_xfer->rx_xfer->rx_idx += dw_xfer->nbytes; + dw_xfer->rx_idx += dw_xfer->nbytes; + rx_max --; + } + return ((rx_cnt-rx_max) * dw_xfer->nbytes); +} + +Inline uint32_t dw_spi_nbytes(uint32_t dfs) +{ + uint32_t nbytes = 1; + + if (dfs > 8) nbytes = 2; + return nbytes; +} + +static void dw_spi_init_transfer(DW_SPI_CTRL *spi_ctrl_ptr, DEV_SPI_TRANSFER *xfer, uint32_t dfs) +{ + DW_SPI_TRANSFER *dw_xfer= &(spi_ctrl_ptr->dw_xfer); + uint32_t tot_len = 0; + + dw_xfer->tx_xfer = xfer; + dw_xfer->rx_xfer = xfer; + dw_xfer->tx_idx = 0; + dw_xfer->rx_idx = 0; + dw_xfer->nbytes = dw_spi_nbytes(dfs); + + /** Calculate all transfer length */ + while (xfer) { + DEV_SPI_XFER_INIT(xfer); + tot_len += xfer->tot_len; + xfer = xfer->next; + } + dw_xfer->xfer_len = tot_len; +} + +/* Check buffer align status, 0 for aligned, -1 for not-aligned */ +static int32_t dw_spi_chk_xfer_aligned(DEV_SPI_TRANSFER *xfer, uint32_t dfs) +{ + uint32_t align_bytes = 1; + if (xfer == NULL) return -1; + + if (dfs > 8) { + align_bytes = 2; + } else { + return 0; + } + + while (xfer) { + /* check tx buffer align status */ + if (xfer->tx_len != 0) { + if (xfer->tx_len % align_bytes) return -1; + if (xfer->tx_ofs % align_bytes) return -1; + if (!CHECK_ALIGN_BYTES(xfer->tx_buf, align_bytes)) return -1; + } + /* check tx buffer align status */ + if (xfer->rx_len != 0) { + if (xfer->rx_len % align_bytes) return -1; + if (xfer->rx_ofs % align_bytes) return -1; + if (!CHECK_ALIGN_BYTES(xfer->rx_buf, align_bytes)) return -1; + } + xfer = xfer->next; + } + return 0; +} + +static uint32_t dw_spi_poll_transfer(DEV_SPI_INFO *spi_info_ptr) +{ + uint32_t len = 0; + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + + spi_info_ptr->status |= DEV_IN_XFER; + while (!dw_spi_xfer_end(spi_ctrl_ptr)) { + len += dw_spi_writer(spi_info_ptr); + len += dw_spi_reader(spi_info_ptr); + } + spi_info_ptr->status &= ~DEV_IN_XFER; + + return len>>1; +} + +/** @} */ + +/** + * \brief open a designware spi device + * \param[in] spi_obj spi object pointer + * \param[in] mode spi working mode (master or slave) + * \param[in] param parameter, for master, param is the freq, for slave, param is dfs + * \retval E_OK Open successfully without any issues + * \retval E_OPNED If device was opened before with different parameters, + * then just increase the \ref dev_spi_info::opn_cnt "opn_cnt" and return \ref E_OPNED + * \retval E_OBJ Device object is not valid + * \retval E_SYS Device is opened for different mode before, if you want to open it with different mode, you need to fully close it first. + * \retval E_PAR Parameter is not valid + * \retval E_NOSPT Open settings are not supported + */ +int32_t dw_spi_open (DEV_SPI *spi_obj, uint32_t mode, uint32_t param) +{ + int32_t ercd = E_OK; + uint32_t param2check; + uint32_t clk_mode, dfs_val; + uint32_t support_modes; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + DW_SPI_CHECK_EXP((mode==DEV_MASTER_MODE)||(mode==DEV_SLAVE_MODE), E_PAR); + if (mode == DEV_SLAVE_MODE) { /* clock mode should be in the enum structure */ + DW_SPI_CHECK_EXP((param>=SPI_CPOL_0_CPHA_0) && (param<=SPI_CPOL_1_CPHA_1), E_PAR); + } else { /* frequence should > 0 */ + DW_SPI_CHECK_EXP(param>0, E_PAR); + } + /* END OF ERROR CHECK */ + + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + + /* Check supported modes, master or slave */ + support_modes = spi_ctrl_ptr->support_modes; + DW_SPI_CHECK_EXP( (((support_modes)&DW_SPI_MASTER_SUPPORTED)&&(mode == DEV_MASTER_MODE)) || \ + (((support_modes)&DW_SPI_SLAVE_SUPPORTED)&&(mode == DEV_SLAVE_MODE)), E_NOSPT); + + /** Check opened before use case */ + if (spi_info_ptr->opn_cnt > 0) { + if (mode != spi_info_ptr->mode) { + /* current working mode is different from passing mode */ + return E_SYS; + } + if (mode == DEV_MASTER_MODE) { /* param is freq when as master */ + param2check = spi_info_ptr->freq; + } else { /* param is clk_mode when as slave */ + param2check = spi_info_ptr->clk_mode; + } + spi_info_ptr->opn_cnt ++; + if (param != param2check) { /* open with different speed mode */ + return E_OPNED; + } else { + return E_OK; + } + } + /* auto increase open count */ + spi_info_ptr->opn_cnt ++; + + /* Do FIFO Length get before init */ +#if DW_SPI_CALC_FIFO_LEN_ENABLE + spi_ctrl_ptr->tx_fifo_len = dw_spi_get_txfifo_len(spi_ctrl_ptr->dw_spi_regs); + spi_ctrl_ptr->rx_fifo_len = dw_spi_get_rxfifo_len(spi_ctrl_ptr->dw_spi_regs); +#endif + /* hardware init */ + spi_info_ptr->mode = mode; + clk_mode = SPI_CLK_MODE_DEFAULT; + dfs_val = SPI_DFS_DEFAULT; + if (mode == DEV_SLAVE_MODE) { + clk_mode = param; + } + spi_info_ptr->dfs = dfs_val; + spi_info_ptr->clk_mode = clk_mode; + dw_spi_hw_init(spi_ctrl_ptr, clk_mode, dfs_val); + if (mode == DEV_MASTER_MODE) { /* Deselect all slaves, and set frequence */ + dw_spi_deselect_slave(spi_ctrl_ptr->dw_spi_regs, 0); + dw_spi_set_freq(spi_ctrl_ptr, param); + spi_info_ptr->freq = param; + } + + spi_info_ptr->status = DEV_ENABLED; + spi_info_ptr->extra = NULL; + spi_info_ptr->slave = SPI_SLAVE_NOT_SELECTED; + spi_info_ptr->dummy = 0xff; + + spi_ctrl_ptr->int_status = 0; + dw_spi_init_transfer(spi_ctrl_ptr, NULL, dfs_val); + + /** install spi interrupt into system */ + dw_spi_disable_interrupt(spi_info_ptr); + if (spi_ctrl_ptr->intno != DW_SPI_INVALID_INTNO) { + int_handler_install(spi_ctrl_ptr->intno, spi_ctrl_ptr->dw_spi_int_handler); + } + memset(&(spi_info_ptr->xfer), 0, sizeof(DEV_SPI_TRANSFER)); + memset(&(spi_info_ptr->spi_cbs), 0, sizeof(DEV_SPI_CBS)); + +error_exit: + return ercd; +} + +/** + * \brief close a DesignWare SPI device + * \param[in] spi_obj spi object pointer + * \retval E_OK Close successfully without any issues(including scenario that device is already closed) + * \retval E_OPNED Device is still opened, the device \ref dev_spi_info::opn_cnt "opn_cnt" decreased by 1 + * \retval E_OBJ Device object is not valid + */ +int32_t dw_spi_close (DEV_SPI *spi_obj) +{ + int32_t ercd = E_OK; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + DW_SPI_CHECK_EXP(spi_info_ptr->opn_cnt > 0, E_OK); + /* END OF ERROR CHECK */ + + spi_info_ptr->opn_cnt --; + if (spi_info_ptr->opn_cnt == 0) { + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + + dw_spi_disable_interrupt(spi_info_ptr); + dw_spi_abort_tx(spi_obj); + dw_spi_abort_rx(spi_obj); + memset(&(spi_info_ptr->xfer), 0, sizeof(DEV_SPI_TRANSFER)); + memset(&(spi_info_ptr->spi_cbs), 0, sizeof(DEV_SPI_CBS)); + memset(&(spi_ctrl_ptr->dw_xfer), 0, sizeof(DW_SPI_TRANSFER)); + dw_spi_disable_device(spi_info_ptr); + spi_info_ptr->status = DEV_DISABLED; + spi_info_ptr->extra = NULL; + } else { + ercd = E_OPNED; + } + +error_exit: + return ercd; +} + +/** + * \brief control spi by ctrl command + * \param[in] spi_obj spi object pointer + * \param[in] ctrl_cmd control command code to do specific spi work + * \param[in,out] param parameters used to control spi or return something + * \retval E_OK Control device successfully + * \retval E_CLSED Device is not opened + * \retval E_OBJ Device object is not valid or not exists + * \retval E_PAR Parameter is not valid for current control command + * \retval E_SYS Control device failed, due to hardware issues, such as device is disabled + * \retval E_CTX Control device failed, due to different reasons like in transfer state + * \retval E_NOSPT Control command is not supported or not valid + */ +int32_t dw_spi_control (DEV_SPI *spi_obj, uint32_t ctrl_cmd, void *param) +{ + int32_t ercd = E_OK; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + DW_SPI_CHECK_EXP(spi_info_ptr->opn_cnt > 0, E_CLSED); + /* END OF ERROR CHECK */ + + uint32_t val32; /** to receive unsigned int value */ + DEV_BUFFER *devbuf; + + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL *)(spi_info_ptr->spi_ctrl); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + DEV_SPI_TRANSFER *spi_xfer = &(spi_info_ptr->xfer); + + /* check whether current device is disabled */ + if ((spi_info_ptr->status & DEV_ENABLED) == 0) { + /** When device is disabled, + * only SPI_CMD_ENA_DEV, SPI_CMD_DIS_DEV, SPI_CMD_GET_STATUS, SPI_CMD_RESET + * are available, other commands will return E_SYS + */ + if ((ctrl_cmd != SPI_CMD_ENA_DEV) && \ + (ctrl_cmd != SPI_CMD_DIS_DEV) && \ + (ctrl_cmd != SPI_CMD_GET_STATUS) && \ + (ctrl_cmd != SPI_CMD_RESET) ) { + return E_SYS; + } + } + + switch (ctrl_cmd) { + /* Commmon commands for both master and slave mode */ + case SPI_CMD_GET_STATUS: + DW_SPI_CHECK_EXP((param!=NULL) && CHECK_ALIGN_4BYTES(param), E_PAR); + *((int32_t *)param) = spi_info_ptr->status; + break; + case SPI_CMD_SET_CLK_MODE: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + val32 = (uint32_t)param; + DW_SPI_CHECK_EXP((val32>=SPI_CPOL_0_CPHA_0) && (val32<=SPI_CPOL_1_CPHA_1), E_PAR); + if (dw_spi_set_clockmode(spi_reg_ptr, val32) == 0) { + spi_info_ptr->clk_mode = val32; + } else { + ercd = E_SYS; + } + break; + case SPI_CMD_ENA_DEV: + dw_spi_enable_device(spi_info_ptr); + break; + case SPI_CMD_DIS_DEV: + dw_spi_disable_device(spi_info_ptr); + break; + case SPI_CMD_RESET: + dw_spi_reset_device(spi_info_ptr); + break; + case SPI_CMD_FLUSH_TX: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + dw_spi_flush_tx(spi_reg_ptr); + break; + case SPI_CMD_FLUSH_RX: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + dw_spi_flush_rx(spi_reg_ptr); + break; + case SPI_CMD_SET_DFS: + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + val32 = (uint32_t)param; + DW_SPI_CHECK_EXP(val32>0, E_PAR); + if (dw_spi_set_dfs(spi_reg_ptr, val32) == 0) { + spi_info_ptr->dfs = val32; + } else { + ercd = E_SYS; + } + break; + case SPI_CMD_SET_DUMMY_DATA: + val32 = (uint32_t)param; + spi_info_ptr->dummy = val32; + break; + case SPI_CMD_GET_RXAVAIL: /* Notice in bytes unit */ + DW_SPI_CHECK_EXP((param!=NULL) && CHECK_ALIGN_4BYTES(param), E_PAR); + *((int32_t *)param) = dw_spi_get_rxavail(spi_ctrl_ptr) * dw_spi_nbytes(spi_info_ptr->dfs); + break; + case SPI_CMD_GET_TXAVAIL: /* Notice in bytes unit */ + DW_SPI_CHECK_EXP((param!=NULL) && CHECK_ALIGN_4BYTES(param), E_PAR); + *((int32_t *)param) = dw_spi_get_txavail(spi_ctrl_ptr) * dw_spi_nbytes(spi_info_ptr->dfs); + break; + case SPI_CMD_SET_TXCB: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + spi_info_ptr->spi_cbs.tx_cb = param; + break; + case SPI_CMD_SET_RXCB: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + spi_info_ptr->spi_cbs.rx_cb = param; + break; + case SPI_CMD_SET_XFERCB: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + spi_info_ptr->spi_cbs.xfer_cb = param; + break; + case SPI_CMD_SET_ERRCB: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + spi_info_ptr->spi_cbs.err_cb = param; + break; + case SPI_CMD_ABORT_TX: + ercd = dw_spi_abort_tx(spi_obj); + break; + case SPI_CMD_ABORT_RX: + ercd = dw_spi_abort_rx(spi_obj); + break; + case SPI_CMD_ABORT_XFER: + ercd = dw_spi_abort_xfer(spi_obj); + break; + case SPI_CMD_SET_TXINT: + val32 = (uint32_t)param; + if (val32 == 0) { + ercd = dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_SND); + } else { + ercd = dw_spi_ena_cbr(spi_info_ptr, DW_SPI_RDY_SND); + } + break; + case SPI_CMD_SET_RXINT: + val32 = (uint32_t)param; + if (val32 == 0) { + ercd = dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_RCV); + } else { + ercd = dw_spi_ena_cbr(spi_info_ptr, DW_SPI_RDY_RCV); + } + break; + case SPI_CMD_SET_TXINT_BUF: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + if (param != NULL) { + devbuf = (DEV_BUFFER *)param; + DEV_SPI_XFER_SET_TXBUF(spi_xfer, devbuf->buf, 0, devbuf->len); + DEV_SPI_XFER_SET_RXBUF(spi_xfer, NULL, devbuf->len, 0); + DEV_SPI_XFER_SET_NEXT(spi_xfer, NULL); + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned(spi_xfer, spi_info_ptr->dfs) == 0, E_PAR); + dw_spi_init_transfer(spi_ctrl_ptr, spi_xfer, spi_info_ptr->dfs); + } else { + DEV_SPI_XFER_SET_TXBUF(spi_xfer, NULL, 0, 0); + DEV_SPI_XFER_SET_RXBUF(spi_xfer, NULL, 0, 0); + DEV_SPI_XFER_SET_NEXT(spi_xfer, NULL); + dw_spi_init_transfer(spi_ctrl_ptr, NULL, spi_info_ptr->dfs); + } + break; + case SPI_CMD_SET_RXINT_BUF: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + if (param != NULL) { + devbuf = (DEV_BUFFER *)param; + DEV_SPI_XFER_SET_TXBUF(spi_xfer, NULL, devbuf->len, 0); + DEV_SPI_XFER_SET_RXBUF(spi_xfer, devbuf->buf, 0, devbuf->len); + DEV_SPI_XFER_SET_NEXT(spi_xfer, NULL); + /* Check transfer align */ + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned(spi_xfer, spi_info_ptr->dfs) == 0, E_PAR); + dw_spi_init_transfer(spi_ctrl_ptr, spi_xfer, spi_info_ptr->dfs); + } else { + DEV_SPI_XFER_SET_TXBUF(spi_xfer, NULL, 0, 0); + DEV_SPI_XFER_SET_RXBUF(spi_xfer, NULL, 0, 0); + DEV_SPI_XFER_SET_NEXT(spi_xfer, NULL); + dw_spi_init_transfer(spi_ctrl_ptr, NULL, spi_info_ptr->dfs); + } + break; + case SPI_CMD_TRANSFER_POLLING: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + if (param != NULL) { + /* Check transfer align */ + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned((DEV_SPI_TRANSFER *)param, spi_info_ptr->dfs) == 0, E_PAR); + *spi_xfer = *((DEV_SPI_TRANSFER *)param); + dw_spi_init_transfer(spi_ctrl_ptr, spi_xfer, spi_info_ptr->dfs); + /* Transfer data by poll */ + dw_spi_poll_transfer(spi_info_ptr); + } else { + ercd = E_PAR; + } + break; + case SPI_CMD_TRANSFER_INT: + DW_SPI_CHECK_EXP(CHECK_ALIGN_4BYTES(param), E_PAR); + if (param != NULL) { + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + /* Check transfer align */ + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned((DEV_SPI_TRANSFER *)param, spi_info_ptr->dfs) == 0, E_PAR); + *spi_xfer = *((DEV_SPI_TRANSFER *)param); + dw_spi_init_transfer(spi_ctrl_ptr, spi_xfer, spi_info_ptr->dfs); + /* Transfer data by interrupt */ + ercd = dw_spi_ena_cbr(spi_info_ptr, DW_SPI_RDY_XFER); + } else { + ercd = dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_XFER); + } + break; + + /* Master mode only commands */ + case SPI_CMD_MST_SET_FREQ: + DW_SPI_CHECK_EXP(spi_info_ptr->mode == DEV_MASTER_MODE, E_NOSPT); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + val32 = (uint32_t)param; + DW_SPI_CHECK_EXP(val32>0, E_PAR); + dw_spi_set_freq(spi_ctrl_ptr, val32); + spi_info_ptr->freq = val32; + break; + case SPI_CMD_MST_SEL_DEV: + DW_SPI_CHECK_EXP(spi_info_ptr->mode == DEV_MASTER_MODE, E_NOSPT); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + val32 = (uint32_t)param; +// spi semaphore notice: lock, use mutex with judgement if OS_FREERTOS is defined +#ifdef OS_FREERTOS + //xSemaphoreTake( spi_mutex, 10 ); +#endif + if (dw_spi_select_slave(spi_reg_ptr, val32) == 0) { + spi_info_ptr->slave = val32; + } else { + ercd = E_SYS; +// spi semaphore notice: unlock if OS_FREERTOS is defined +#ifdef OS_FREERTOS + //xSemaphoreGive( spi_mutex ); +#endif + } + break; + case SPI_CMD_MST_DSEL_DEV: + DW_SPI_CHECK_EXP(spi_info_ptr->mode == DEV_MASTER_MODE, E_NOSPT); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + val32 = (uint32_t)param; + if (dw_spi_deselect_slave(spi_reg_ptr, val32) == 0) { + spi_info_ptr->slave = SPI_SLAVE_NOT_SELECTED; + } else { + ercd = E_SYS; + } +// caslab notice: unlock here if OS_FREERTOS is defined +#ifdef OS_FREERTOS + //xSemaphoreGive( spi_mutex ); +#endif + break; + + /* Slave mode only commands */ + + + default: + ercd = E_NOSPT; + break; + } + +error_exit: + return ercd; +} + +/** + * \brief send data through DesignWare SPI + * \param[in] spi_obj spi object pointer + * \param[in] data pointer to data need to send by spi + * \param[in] len length of data to be sent + * \retval >0 Byte count that was successfully sent for poll method + * \retval E_OBJ Device object is not valid or not exists + * \retval E_PAR Parameter is not valid + * \retval E_CTX Device is still in transfer state + * \retval E_SYS Can't write data to hardware due to hardware issues, such as device is disabled + */ +int32_t dw_spi_write (DEV_SPI *spi_obj, const void *data, uint32_t len) +{ + int32_t ercd = E_OK; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + DW_SPI_CHECK_EXP(spi_info_ptr->opn_cnt > 0, E_CLSED); + DW_SPI_CHECK_EXP(spi_info_ptr->status & DEV_ENABLED, E_SYS); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + DW_SPI_CHECK_EXP(data!=NULL, E_PAR); + DW_SPI_CHECK_EXP(len>0, E_PAR); + /* END OF ERROR CHECK */ + + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + DEV_SPI_TRANSFER spi_xfer; + + /* Master and Slave transmit */ + DEV_SPI_XFER_SET_TXBUF(&spi_xfer, data, 0, len); + DEV_SPI_XFER_SET_RXBUF(&spi_xfer, NULL, len, 0); + DEV_SPI_XFER_SET_NEXT(&spi_xfer, NULL); + + /* Check transfer align */ + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned(&spi_xfer, spi_info_ptr->dfs) == 0, E_PAR); + + dw_spi_init_transfer(spi_ctrl_ptr, &spi_xfer, spi_info_ptr->dfs); + + ercd = dw_spi_poll_transfer(spi_info_ptr); + +error_exit: + return ercd; +} + +/** + * \brief read data through DesignWare SPI + * \param[in] spi_info_ptr spi information structure pointer + * \param[out] data data that need to read (data must be char type) + * \param[in] len data count need to read + * \retval >=0 data have been read + * \retval E_PAR arguments passed was wrong + * \retval E_OBJ spi has something error, nothing can be done + * \retval E_CLSED spi was closed, not available for control + * \retval <0 other error code not defined here + */ +int32_t dw_spi_read (DEV_SPI *spi_obj, void *data, uint32_t len) +{ + int32_t ercd = E_OK; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + DW_SPI_CHECK_EXP(spi_info_ptr->opn_cnt > 0, E_CLSED); + DW_SPI_CHECK_EXP(spi_info_ptr->status & DEV_ENABLED, E_SYS); + DW_SPI_CHECK_EXP((spi_info_ptr->status & DEV_IN_XFER) == 0, E_CTX); + DW_SPI_CHECK_EXP(data!=NULL, E_PAR); + DW_SPI_CHECK_EXP(len>0, E_PAR); + /* END OF ERROR CHECK */ + + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + DEV_SPI_TRANSFER spi_xfer; + + /* Master and Slave transmit */ + DEV_SPI_XFER_SET_TXBUF(&spi_xfer, NULL, len, 0); + DEV_SPI_XFER_SET_RXBUF(&spi_xfer, data, 0, len); + DEV_SPI_XFER_SET_NEXT(&spi_xfer, NULL); + + /* Check transfer align */ + DW_SPI_CHECK_EXP(dw_spi_chk_xfer_aligned(&spi_xfer, spi_info_ptr->dfs) == 0, E_PAR); + + dw_spi_init_transfer(spi_ctrl_ptr, &spi_xfer, spi_info_ptr->dfs); + + ercd = dw_spi_poll_transfer(spi_info_ptr); + +error_exit: + return ercd; +} + +/** + * \brief DesignWare SPI interrupt processing routine + * \param[in] spi_info_ptr DEV_SPI_INFO *spi_info_ptr + * \param[in] ptr extra information + */ +void dw_spi_isr(DEV_SPI *spi_obj, void *ptr) +{ + int32_t ercd = E_OK; + DEV_SPI_INFO *spi_info_ptr = &(spi_obj->spi_info); + + /* START ERROR CHECK */ + VALID_CHK_SPI_INFO_OBJECT(spi_info_ptr); + /* END OF ERROR CHECK */ + + DW_SPI_CTRL *spi_ctrl_ptr = (DW_SPI_CTRL_PTR)(spi_info_ptr->spi_ctrl); + DW_SPI_REG *spi_reg_ptr = (DW_SPI_REG *)(spi_ctrl_ptr->dw_spi_regs); + + uint32_t isr_status; + + isr_status = spi_reg_ptr->ISR; + + if (!isr_status) return; + if (spi_ctrl_ptr->dw_xfer.xfer_len == 0) { + dw_spi_disable_interrupt(spi_info_ptr); + } else { + if (isr_status & (DW_SPI_IMR_TXOIM|DW_SPI_IMR_RXOIM|DW_SPI_IMR_RXUIM)) { + dw_spi_clear_interrupt_all(spi_reg_ptr); + dw_spi_disable_interrupt(spi_info_ptr); + if (spi_info_ptr->spi_cbs.err_cb) { + spi_info_ptr->spi_cbs.err_cb(spi_obj); + } + memset(&(spi_ctrl_ptr->dw_xfer), 0, sizeof(DW_SPI_TRANSFER)); + } + dw_spi_reader(spi_info_ptr); + if (isr_status & DW_SPI_IMR_TXEIM) { + dw_spi_writer(spi_info_ptr); + } + if (dw_spi_xfer_end(spi_ctrl_ptr)) { + if ((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_TX) { + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_SND); + if (spi_info_ptr->spi_cbs.tx_cb) { + spi_info_ptr->spi_cbs.tx_cb(spi_obj); + } + } else if ((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_RX) { + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_RCV); + if (spi_info_ptr->spi_cbs.rx_cb) { + spi_info_ptr->spi_cbs.rx_cb(spi_obj); + } + } else if ((spi_info_ptr->status & DW_SPI_IN_XFER) == DW_SPI_IN_XFER) { + dw_spi_dis_cbr(spi_info_ptr, DW_SPI_RDY_XFER); + if (spi_info_ptr->spi_cbs.xfer_cb) { + spi_info_ptr->spi_cbs.xfer_cb(spi_obj); + } + } else { + dw_spi_disable_interrupt(spi_info_ptr); + } + memset(&(spi_ctrl_ptr->dw_xfer), 0, sizeof(DW_SPI_TRANSFER)); + } + } + +error_exit: + return; +} +/** @} */ /* DEVICE_DW_SPI_IMPLEMENT */ + +/** @} */ /* DEVICE_DW_SPI */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/peripheral/wifi/rw009/rw009.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/peripheral/wifi/rw009/rw009.c new file mode 100644 index 00000000..414a33a7 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/device/peripheral/wifi/rw009/rw009.c @@ -0,0 +1,1281 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ + +/** + * \file + * \ingroup BOARD_EMSK_DRV_RW009 + * \brief rw009 wifi module driver + */ + +#include +#include "embARC.h" +#include "rw009.h" + +#define DEBUG +#include "embARC_debug.h" + + +/* data format of rw009 */ +/* + * + * Master: REQ(16bytes) + DUMMY + DATA to transfer + * RW009: DUMMY + RESP(16 bytes)+ DATA to transfer + * + * DATA: len(4bytes) + type(4bytes) + buffer + * type: eth_data, cmd, resp, status + * eth_data: ethernet datapacket to IP stack + * cmd & resp:cmd(4bytes) + len(4bytes) + params + * + */ + +/* Note: all the following data structures are for little-endian */ +/* Master starts the transfer with a request, rw009 will response */ +#define RW009_CHECK_EXP(EXPR, ERROR_CODE) CHECK_EXP(EXPR, ercd, ERROR_CODE, error_exit) + +struct rw009_spi_request { + uint32_t flag; + uint32_t len; // master to slave data len. + uint32_t magic1; + uint32_t magic2; +}; + +#define RW009_REQ_MAGIC1 (0x67452301) +#define RW009_REQ_MAGIC2 (0xEFCDAB89) +#define RW009_REQ_FLAG_MRDY (0x01) /* master ready to transfer */ + +struct rw009_spi_response { + uint32_t flag; + uint32_t len; // slave to master data len. + uint32_t magic1; + uint32_t magic2; +}; + +#define RW009_RESP_FLAG_SRDY (0x01) /* rw009 ready to transfer */ +#define RW009_RESP_MAGIC1 (0x98BADCFE) +#define RW009_RESP_MAGIC2 (0x10325476) + +#define RW009_CMD_PACKET_HRD_LEN (8) + +#define RW009_PASSWORD_LENGTH_MAX (64) + +#define RW009_CMD_INIT (128) +#define RW009_CMD_SCAN (129) +#define RW009_CMD_JOIN (130) +#define RW009_CMD_EASY_JOIN (131) +#define RW009_CMD_RSSI (132) +#define RW009_CMD_SOFTAP (133) +#define RW009_CMD_NULL (0xff) + +#define RW009_DATA_PACKET_HDR_LEN (8) +#define RW009_CMD_PACKET_HDR_LEN (8) + +typedef enum { + RW009_TYPE_ETH_DATA = 0, + RW009_TYPE_CMD, + RW009_TYPE_RESP, + RW009_TYPE_STATUS +} RW009_DATA_TYPE_DEF; + +typedef struct _rw009_cmd_init { + uint32_t mode; +} RW009_CMD_INIT_DEF; + +typedef struct _rw009_resp_init { + uint8_t mac[8]; /* 6byte + 2byte PAD. */ + uint8_t sn[24]; /* serial no. of rw 009 */ + char version[16]; /* firmware version */ +} RW009_RESP_INIT_DEF; + +typedef struct _rw009_cmd_easy_join { + char ssid[RW009_SSID_NAME_LENGTH_MAX]; + char passwd[RW009_PASSWORD_LENGTH_MAX]; +} RW009_CMD_EASY_JOIN_DEF; + +typedef struct _rw009_cmd_join { + uint8_t bssid[8]; /* 6byte + 2byte PAD. */ + char passwd[RW009_PASSWORD_LENGTH_MAX]; +} RW009_CMD_JOIN_DEF; + +typedef struct _rw009_cmd_rssi { + uint8_t bssid[8]; /* 6byte + 2byte PAD. */ +} RW009_CMD_RSSI_DEF; + +typedef struct _rw009_cmd_softap { + char ssid[RW009_SSID_NAME_LENGTH_MAX]; + char passwd[RW009_PASSWORD_LENGTH_MAX]; + + uint32_t security; /* Security type. */ + uint32_t channel; /* Radio channel that the AP beacon was received on */ +} RW009_CMD_SOFTAP_DEF; + +typedef struct _rw009_resp_join { + RW009_AP_INFO_DEF ap_info; +} RW009_RESP_JOIN_DEF; + +typedef struct rw009_cmd { + uint32_t cmd; + uint32_t len; + + /** command body */ + union { + RW009_CMD_INIT_DEF init; + RW009_CMD_EASY_JOIN_DEF easy_join; + RW009_CMD_JOIN_DEF join; + RW009_CMD_RSSI_DEF rssi; + RW009_CMD_SOFTAP_DEF softap; + } params; +} RW009_CMD_DEF, * RW009_CMD_DEF_PTR; + +struct rw009_resp { + uint32_t cmd; + uint32_t len; + + int32_t result; /* result for CMD */ + + /** resp Body */ + union { + RW009_RESP_INIT_DEF init; + RW009_AP_INFO_DEF ap_info; + } resp; +}; + +/** + * @brief get current system time in millisecond + * @return millisecond + */ +static uint32_t rw009_timer_read_ms(void) +{ + return OSP_GET_CUR_MS(); +} + +static void rw009_timer_delay(uint32_t ms) +{ +#if defined(OS_FREERTOS) + vTaskDelay(ms); +#else + board_delay_ms(ms, OSP_DELAY_OS_COMPAT_ENABLE); +#endif +} + +static int32_t rw009_spi_open(RW009_DEF_PTR rw009) +{ + DEV_SPI_PTR spi; + int32_t ercd = E_OK; + + spi = spi_get_dev(rw009->spi_master); + RW009_CHECK_EXP(spi != NULL, E_OBJ); + + ercd = spi->spi_open(DEV_MASTER_MODE, rw009->spi_freq); + + if (ercd == E_OPNED) { + ercd = E_OK; + } + +error_exit: + return ercd; +} + +static int32_t rw009_gpio_open(RW009_DEF_PTR rw009) +{ + int32_t ercd = E_OK; + uint32_t mask; + DEV_GPIO_BIT_ISR bit_isr; + DEV_GPIO_INT_CFG int_cfg; + DEV_GPIO_PTR gpio; + + gpio = gpio_get_dev(rw009->gpio_rst); + RW009_CHECK_EXP(gpio != NULL, E_OBJ); + + ercd = gpio->gpio_open(1 << rw009->pin_rst); + + if (ercd == E_OPNED) { + mask = 1 << rw009->pin_rst; + gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)mask); + } + + gpio = gpio_get_dev(rw009->gpio_cs); + RW009_CHECK_EXP(gpio != NULL, E_OBJ); + + ercd = gpio->gpio_open(1 << rw009->pin_cs); + + if (ercd == E_OPNED) { + mask = 1 << rw009->pin_cs; + gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)mask); + } + + gpio = gpio_get_dev(rw009->gpio_int_busy); + RW009_CHECK_EXP(gpio != NULL, E_OBJ); + + /* pin_int_busy is input */ + ercd = gpio->gpio_open(0); + + mask = 1 << rw009->pin_int_busy; + if (ercd == E_OPNED) { + gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)mask); + } + + int_cfg.int_bit_mask = mask; + int_cfg.int_bit_type = GPIO_INT_BITS_EDGE_TRIG(mask); + int_cfg.int_bit_polarity = GPIO_INT_BITS_POL_FALL_EDGE(mask); + int_cfg.int_bit_debounce = GPIO_INT_BITS_DIS_DEBOUNCE(mask); + gpio->gpio_control(GPIO_CMD_SET_BIT_INT_CFG, (void *)(&int_cfg)); + bit_isr.int_bit_ofs = rw009->pin_int_busy; + bit_isr.int_bit_handler = rw009->gpio_int_handler; + gpio->gpio_control(GPIO_CMD_SET_BIT_ISR, (void *)(&bit_isr)); + + ercd = gpio->gpio_control(GPIO_CMD_ENA_BIT_INT, (void *)(mask)); + +error_exit: + return ercd; +} + +/** + * @brief enable rw009 interrupt + */ +static void rw009_int_enable(RW009_DEF_PTR rw009) +{ + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_int_busy); + + gpio->gpio_control(GPIO_CMD_ENA_BIT_INT, (void *)(1 << rw009->pin_int_busy)); +} + +/** + * @brief disable rw009 interrupt + */ +static void rw009_int_disable(RW009_DEF_PTR rw009) +{ + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_int_busy); + + gpio->gpio_control(GPIO_CMD_DIS_BIT_INT, (void *)(1 << rw009->pin_int_busy)); +} + +/** + * @brief poll rw009 whether is busy + * @return 1 busy, 0 idle + */ +static int32_t rw009_is_busy(RW009_DEF_PTR rw009) +{ + uint32_t val; + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_int_busy); + + gpio->gpio_read(&val, 1 << rw009->pin_int_busy); + + if (val) { + return 0; + } + + return 1; +} + +/** + * @brief reset rw009 + */ +static void rw009_reset(RW009_DEF_PTR rw009) +{ +#define RW009_RESET_ASSERT_MS 100 +#define RW009_RESET_DELAY_MS 200 + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_rst); + + gpio->gpio_write(~(1 << rw009->pin_rst), 1 << rw009->pin_rst); + rw009_timer_delay(RW009_RESET_ASSERT_MS); + gpio->gpio_write(1 << rw009->pin_rst, 1 << rw009->pin_rst); + rw009_timer_delay(RW009_RESET_DELAY_MS); +} + +/** + * @brief chip select rw009 + */ +static void rw009_select(RW009_DEF_PTR rw009) +{ + DEV_SPI_PTR spi = spi_get_dev(rw009->spi_master); + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_cs); + do { + if( spi->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID((uint32_t)rw009->spi_cs)) == E_OK) { + gpio->gpio_write(~(1 << rw009->pin_cs), 1 << rw009->pin_cs); + break; + } else { +#if defined(OS_FREERTOS) + vTaskDelay(0); +#else + Sleep(1); +#endif + } + } while(1); +} + +/** + * @brief chip de-select rw009 + */ +static void rw009_deselect(RW009_DEF_PTR rw009) +{ + uint32_t val; + DEV_SPI_PTR spi = spi_get_dev(rw009->spi_master); + DEV_GPIO_PTR gpio = gpio_get_dev(rw009->gpio_cs); + gpio->gpio_read(&val, 1 << rw009->pin_cs); + if(val == 0) { + gpio->gpio_write(1 << rw009->pin_cs, 1 << rw009->pin_cs); + spi->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID((uint32_t)rw009->spi_cs)); + taskEXIT_CRITICAL(); + } +} + +/** + * @brief cmd response handler + * + * @param rw009_wnic rw009 object + * @param rw009_resp response from rw009 + + * @return error code + */ +static int32_t cmd_resp_handler(DEV_WNIC *rw009_wnic, struct rw009_resp* resp) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + DEV_WNIC_ON_OPS_PTR rw009_on_ops; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + rw009_on_ops = &(rw009_wnic->wnic_on_ops); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + if (resp->cmd != rw009->last_cmd) { + DBG("current command is %d, cmd and response do not match!\r\n", resp->cmd); + } + + switch (resp->cmd) { + case RW009_CMD_INIT: + RW009_CHECK_EXP((rw009_info->init_status == WNIC_DURING_INITIALIZATION), E_PAR); + + DBG("response for RW009_CMD_INIT\r\n"); + DBG("sn:%s\r\n", resp->resp.init.sn); + DBG("ver:%s\r\n", resp->resp.init.version); + memcpy(rw009_info->mac_addr, resp->resp.init.mac, WNIC_HDR_LEN); + rw009_info->init_status = WNIC_INIT_SUCCESSFUL; + rw009->init_try = 0; + + if (rw009_on_ops->on_init_success != NULL) { + rw009_on_ops->on_init_success(rw009_wnic); + } + break; + case RW009_CMD_SCAN: + RW009_CHECK_EXP((rw009_info->scan_status == WNIC_DURING_SCAN), E_PAR); + DBG("response for rw009_cmd_scan\n"); + if (rw009->scan_cnt < RW009_SCAN_AP_NUM) { + memcpy(&(rw009->scanned_ap[rw009->scan_cnt++]), &resp->resp.ap_info, sizeof(RW009_AP_INFO_DEF)); + } + break; + case RW009_CMD_JOIN: + if (rw009_info->conn_status != WNIC_CONNECTED) { + break; + } + case RW009_CMD_EASY_JOIN: + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_PAR); + RW009_CHECK_EXP((rw009_info->conn_status == WNIC_DURING_CONNECTION) || \ + (rw009_info->conn_status == WNIC_CONNECTED), E_CLS); + rw009_info->busy_status = WNIC_IS_FREE; + DBG("response for RW009_CMD_JOIN or easy_join(cmd:%d, resp:%d)\r\n", resp->cmd, resp->result); + if (resp->result == 0) { + /* connected */ + DBG("rw009 connection success\r\n"); + if (rw009_info->conn_status != WNIC_CONNECTED) { + rw009_info->conn_status = WNIC_CONNECTED; + if (rw009_on_ops->on_connected != NULL) { + rw009_on_ops->on_connected(rw009_wnic); + } + } + } else { + if (! (((resp->cmd == RW009_CMD_JOIN) && (resp->result == 12)) || \ + (resp->cmd == RW009_CMD_EASY_JOIN)) ) { + break; + } + if ((rw009_info->conn_status == WNIC_CONNECTED) && \ + (resp->cmd == RW009_CMD_EASY_JOIN)) { + break; + } + DBG("rw009 connection failure\r\n"); + if (rw009_info->conn_status == WNIC_CONNECTED) { + rw009_info->conn_status = WNIC_NOT_CONNECTED; + if (rw009_on_ops->on_disconnected != NULL) { + rw009_on_ops->on_disconnected(rw009_wnic); + } + } else { + rw009_info->conn_status = WNIC_NOT_CONNECTED; + } + } + break; + case RW009_CMD_RSSI: + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_PAR); + DBG("response for RW009_CMD_RSSI\r\n"); + /* \todo use to poll the status of connection ? */ + break; + default: + DBG("unknown cmd response\r\n"); + ercd = E_PAR; + break; + } + +error_exit: + return ercd; +} + +/** + * @brief transfer function between rw009 and host + * + * @param rw009_wnic rw009 object + * @param out output packet + * @param rw009_spi_data_packet input packet + * @return < 0 error + */ +static int32_t rw009_xfer(DEV_WNIC *rw009_wnic, struct rw009_spi_data_packet* out, struct rw009_spi_data_packet* in) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + DEV_WNIC_ON_OPS_PTR rw009_on_ops; + RW009_DEF_PTR rw009; + DEV_SPI_PTR spi; + + struct rw009_spi_request req; + struct rw009_spi_response resp; + struct dev_spi_transfer xfer; + uint32_t to_send = 0; + + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + rw009_on_ops = &(rw009_wnic->wnic_on_ops); + + if (out == NULL || in == NULL) { + return -1; + } + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + spi = spi_get_dev(rw009->spi_master); + + rw009_int_disable(rw009); + + while (rw009_is_busy(rw009)); /* wait if rw009 is busy */ + + req.magic1 = RW009_REQ_MAGIC1; + req.magic2 = RW009_REQ_MAGIC2; + req.flag = RW009_REQ_FLAG_MRDY; + if (out->len) { + req.len = out->len + RW009_DATA_PACKET_HDR_LEN; + } else { + req.len = 0; + } + + spi->spi_control(SPI_CMD_MST_SET_FREQ, CONV2VOID(rw009->spi_freq)); + spi->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CLK_MODE_0)); + + /* send cmd request */ + rw009_select(rw009); + spi->spi_write(&req, sizeof(req)); + rw009_deselect(rw009); + + while (rw009_is_busy(rw009)); + + rw009_select(rw009); + + /* receive cmd request response */ + spi->spi_read(&resp, sizeof(resp)); + + if ((resp.magic1 != RW009_RESP_MAGIC1) || (resp.magic2 != RW009_RESP_MAGIC2)) { + DBG("bad resp magic, abort!\r\n"); + return E_SYS; + } + + if (resp.flag & RW009_RESP_FLAG_SRDY) { + //DBG("slave is ready to receive\n"); + to_send = req.len; + } + + if (resp.len > RW009_SPI_MAX_DATA_LEN) { + resp.len = 0; + } + + DEV_SPI_XFER_SET_TXBUF(&xfer, out, 0, to_send); + DEV_SPI_XFER_SET_RXBUF(&xfer, in, 0, resp.len); + DEV_SPI_XFER_SET_NEXT(&xfer, NULL); + + spi->spi_control(SPI_CMD_TRANSFER_POLLING, &xfer); + + rw009_deselect(rw009); + + if (resp.len > 0) { + if (in->type == RW009_TYPE_ETH_DATA) { + //DBG("eth data:%d\n", resp.len); + /* ethernet data */ + if (rw009_info->init_status == WNIC_INIT_SUCCESSFUL) { + if (rw009_on_ops->on_rxdata_comes != NULL) { + rw009_on_ops->on_rxdata_comes(rw009_wnic); + } + } + /* eth packet it recevied */ + } else if (in->type == RW009_TYPE_RESP) { + /* cmd respone received */ + cmd_resp_handler(rw009_wnic, (struct rw009_resp *)in->buffer); + } else { + DBG("unsupported data type\r\n"); + ercd = E_SYS; + } + } + rw009_int_enable(rw009); + //DBG("master send %d bytes, rw009 send %d bytes\r\n", to_send, resp.len); +error_exit: + return ercd; +} + +/** + * @brief send cmd to rw009 + * + * @param rw009_wnic rw009 object + * @param cmd command for rw009 + * @param args arguments of command + * @return < 0 failed + */ +static int32_t rw009_cmd(DEV_WNIC *rw009_wnic, uint32_t cmd, void *args) +{ + uint32_t cmd_len; +#ifdef RW009_SPI_CPULOCK_ENABLE + uint32_t cpu_status; +#endif + RW009_CMD_DEF_PTR cmd_packet; + struct rw009_spi_data_packet* out; + RW009_DEF_PTR rw009; + + cmd_len = 0; + rw009 = (RW009_DEF_PTR)(rw009_wnic->wnic_info.ctrl); + + switch (cmd) { + case RW009_CMD_INIT: + cmd_len = sizeof(RW009_CMD_INIT_DEF); + rw009->init_timer = rw009_timer_read_ms() + RW009_INIT_TIME_MS; + break; + case RW009_CMD_SCAN: + cmd_len = 0; + break; + case RW009_CMD_JOIN: + cmd_len = sizeof(RW009_CMD_JOIN_DEF); + rw009->conn_timer = rw009_timer_read_ms() + RW009_CON_TIME_MS; + break; + case RW009_CMD_EASY_JOIN: + cmd_len = sizeof(RW009_CMD_EASY_JOIN_DEF); + rw009->conn_timer = rw009_timer_read_ms() + RW009_CON_TIME_MS; + break; + case RW009_CMD_SOFTAP: + cmd_len = sizeof(RW009_CMD_SOFTAP_DEF); + break; + case RW009_CMD_RSSI: + cmd_len = sizeof(RW009_CMD_RSSI_DEF); + break; + default: + cmd_len = 0xff; + break; + } + + if (cmd_len == 0xff) { + DBG("cmd type error\r\n"); + return -1; + } + +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_status = cpu_lock_save(); +#endif + + out = &rw009->snd_packet; + cmd_packet = (RW009_CMD_DEF_PTR)out->buffer; + + cmd_packet->cmd = cmd; + cmd_packet->len = cmd_len; + memcpy(&cmd_packet->params, args, cmd_len); + rw009->last_cmd = cmd; + out->type = RW009_TYPE_CMD; + out->len = RW009_CMD_PACKET_HDR_LEN + cmd_len; + rw009_xfer(rw009_wnic, out, &rw009->rcv_packet); + out->len = 0; + out->type = 0; + +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_unlock_restore(cpu_status); +#endif + return 0; +} + +/* the following is rw009 implementation for WNIC interface */ +int32_t rw009_wnic_get_info(DEV_WNIC *rw009_wnic, uint32_t cmd, void *rinfo) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + +error_exit: + return ercd; +} + +int32_t rw009_wnic_control(DEV_WNIC *rw009_wnic, uint32_t ctrl_cmd, void *param) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + +error_exit: + return ercd; +} + +int32_t rw009_wnic_init(DEV_WNIC *rw009_wnic, uint32_t network_type) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_CMD_INIT_DEF cmd; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_NOT_INITIALIZED) \ + || (rw009_info->init_status == WNIC_INIT_FAILED), E_OPNED); + + RW009_CHECK_EXP((network_type == WNIC_NETWORK_TYPE_INFRASTRUCTURE) \ + || (network_type == WNIC_NETWORK_TYPE_ADHOC), E_PAR); + + rw009_info->init_status = WNIC_DURING_INITIALIZATION; /* start initialization process */ + rw009_info->network_type = network_type; /* set network type used next */ + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + DBG("init rw009\r\n"); + + if ((ercd = rw009_gpio_open(rw009)) != E_OK) { + DBG("rw009 gpio open failed\r\n"); + return ercd; + } + + if ((ercd = rw009_spi_open(rw009)) != E_OK) { + DBG("rw009 spi open failed\r\n"); + return ercd; + } + + rw009_reset(rw009); + rw009_deselect(rw009); + + cmd.mode = RW009_MODE_STATION; + rw009_cmd(rw009_wnic, RW009_CMD_INIT, (void *)&cmd); + + + rw009_info->power_status = WNIC_POWER_NORMAL; + +error_exit: + return ercd; +} + +int32_t rw009_poll_init_status(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + + ercd = rw009_info->init_status; + +error_exit: + return ercd; +} + +int32_t rw009_poll_busy_status(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + ercd = rw009_info->busy_status; + +error_exit: + return ercd; +} + +int32_t rw009_set_network_type(DEV_WNIC *rw009_wnic, uint32_t type) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((type == WNIC_NETWORK_TYPE_INFRASTRUCTURE) \ + || (type == WNIC_NETWORK_TYPE_ADHOC), E_PAR); + + /* \todo: set network type: SoftAP is supported in rw009 */ + rw009_info->network_type = type; + +error_exit: + return ercd; +} + +int32_t rw009_set_macaddr(DEV_WNIC *rw009_wnic, uint8_t *mac) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + DEV_WNIC_ON_OPS_PTR rw009_on_ops; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((mac != NULL), E_PAR); + + /* Note: the mac of rw009 can not be set */ + rw009_on_ops = &(rw009_wnic->wnic_on_ops); + if (rw009_on_ops->on_mac_updated != NULL) { + rw009_on_ops->on_mac_updated(rw009_wnic); + } + +error_exit: + return ercd; +} + +int32_t rw009_get_macaddr(DEV_WNIC *rw009_wnic, uint8_t *mac) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((mac != NULL), E_PAR); + + memcpy(mac, rw009_info->mac_addr, WNIC_HDR_LEN); +error_exit: + return ercd; +} + +int32_t rw009_start_scan(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((rw009_info->scan_status != WNIC_DURING_SCAN), E_CLS); + RW009_CHECK_EXP((rw009_info->conn_status == WNIC_NOT_CONNECTED) \ + || (rw009_info->conn_status == WNIC_CONNECTED), E_CLS); + RW009_CHECK_EXP((rw009_info->busy_status == WNIC_IS_FREE), E_CLS); + + + rw009_info->scan_status = WNIC_DURING_SCAN; + rw009_info->busy_status = WNIC_IS_BUSY; + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + rw009->scan_timer = rw009_timer_read_ms() + RW009_SCAN_TIME_MS; + rw009_cmd(rw009_wnic, RW009_CMD_SCAN, NULL); + +error_exit: + return ercd; +} + +int32_t rw009_stop_scan(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009_info->scan_status = WNIC_NOT_SCANED; + rw009_info->busy_status = WNIC_IS_FREE; + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + rw009->scan_cnt = 0; + rw009->scan_timer = 0; + + /* \todo cannot stop the scan of rw009 */ + +error_exit: + return ercd; +} + +int32_t rw009_poll_scan_status(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + ercd = rw009_info->scan_status; + +error_exit: + return ercd; +} + +int32_t rw009_get_scan_result_cnt(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + if (rw009_info->scan_status == WNIC_SCAN_FINISHED) { + ercd = rw009_info->scan_results; + } else { + ercd = 0; + } + +error_exit: + return ercd; +} + +int32_t rw009_get_scan_result(DEV_WNIC *rw009_wnic, uint32_t index, WNIC_SCAN_RESULT *result) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_AP_INFO_DEF_PTR ap; + RW009_DEF_PTR rw009; + + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + RW009_CHECK_EXP(result != NULL, E_PAR); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((rw009_info->scan_status == WNIC_SCAN_FINISHED), E_CLS); + RW009_CHECK_EXP((index < rw009_info->scan_results), E_PAR); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + ap = &rw009->scanned_ap[index]; + + memcpy(result->bssid, ap->bssid, WNIC_BSSID_MAX_LEN); + memcpy(result->ssid, ap->ssid, WNIC_SSID_MAX_LEN); + result->ssidlen = strlen(ap->ssid); + result->ap_config.apConfig = 0; + result->rssi = ap->rssi; + result->bsstype = 0; + result->channel = ap->channel; + +error_exit: + return ercd; +} + +int32_t rw009_wnic_connect(DEV_WNIC *rw009_wnic, uint32_t security, const uint8_t *ssid, WNIC_AUTH_KEY *key) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + int32_t ssid_len; + RW009_CMD_EASY_JOIN_DEF easy_join; + + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + RW009_CHECK_EXP((ssid != NULL), E_PAR); + RW009_CHECK_EXP(!((key == NULL) && (security != AUTH_SECURITY_OPEN)), E_PAR); + + ssid_len = strlen((const char *)ssid); + RW009_CHECK_EXP((ssid_len <= WNIC_SSID_MAX_LEN), E_PAR); /* check ssid len */ + + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((rw009_info->busy_status == WNIC_IS_FREE), E_CLS); + RW009_CHECK_EXP((rw009_info->conn_status == WNIC_NOT_CONNECTED) \ + || (rw009_info->conn_status == WNIC_CONNECTED), E_CLS); + + if (rw009_info->conn_status == WNIC_CONNECTED) { + /* if connected to a different ssid, just disconnect it */ + if (strcmp((const char *)ssid, (const char *)(rw009_info->ssid.ssid)) == 0) { + ercd = E_OK; + goto error_exit; + } else { + if (rw009_wnic_disconnect(rw009_wnic) != E_OK) { /* if disconnect failed just return failed */ + ercd = E_SYS; + } + } + } + + rw009_info->busy_status = WNIC_IS_BUSY; + rw009_info->conn_status = WNIC_DURING_CONNECTION; + + memcpy(rw009_info->ssid.ssid, ssid, ssid_len); + strncpy(easy_join.ssid, (const char *)ssid, sizeof(easy_join.ssid) ); + strncpy(easy_join.passwd, (const char *)key->key, sizeof(easy_join.passwd)); + + ercd = rw009_cmd(rw009_wnic, RW009_CMD_EASY_JOIN, (void *)&easy_join); + +error_exit: + return ercd; +} + +int32_t rw009_poll_conn_status(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + if (rw009_info->busy_status == WNIC_IS_BUSY) { + ercd = rw009_info->conn_status; + goto error_exit; + } + if (rw009_info->conn_status == WNIC_CONNECTED) { + ercd = WNIC_CONNECTED; + goto error_exit; + } + rw009_info->conn_status = ercd; + +error_exit: + return ercd; +} + +int32_t rw009_wnic_disconnect(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + DEV_WNIC_ON_OPS_PTR rw009_on_ops; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + RW009_CHECK_EXP((rw009_info->conn_status != WNIC_DURING_DISCONNECTION), E_CLS); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + if (rw009_poll_conn_status(rw009_wnic) == WNIC_CONNECTED) { + rw009_info->conn_status = WNIC_DURING_DISCONNECTION; + rw009_reset(rw009); + rw009_info->conn_status = WNIC_NOT_CONNECTED; + rw009_on_ops = &(rw009_wnic->wnic_on_ops); + if (rw009_on_ops->on_disconnected != NULL) { + rw009_on_ops->on_disconnected(rw009_wnic); + } + } + +error_exit: + return ercd; +} + +int32_t rw009_prepare_tx(DEV_WNIC *rw009_wnic, uint32_t tx_len) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + rw009->snd_cnt = 0; + +error_exit: + return ercd; +} + +int32_t rw009_add_tx_data(DEV_WNIC *rw009_wnic, uint8_t *p_buf, uint32_t len) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + RW009_CHECK_EXP(p_buf != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + memcpy(rw009->snd_packet.buffer + rw009->snd_cnt, p_buf, len); + rw009->snd_cnt += len; + /* copy data into tx buffer */ + + ercd = len; + +error_exit: + return ercd; +} + +int32_t rw009_commit_tx(DEV_WNIC *rw009_wnic, uint32_t len) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + +#ifdef RW009_SPI_CPULOCK_ENABLE + uint32_t cpu_status; +#endif + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_status = cpu_lock_save(); +#endif + + rw009->snd_packet.len = rw009->snd_cnt; + rw009->snd_packet.type = RW009_TYPE_ETH_DATA; + rw009_xfer(rw009_wnic, &rw009->snd_packet, &rw009->rcv_packet); + rw009->snd_packet.len = 0; + rw009->snd_cnt = 0; + +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_unlock_restore(cpu_status); +#endif + +error_exit: + return ercd; +} + +int32_t rw009_prepare_rx(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + rw009->rcv_cnt = 0; + return rw009->rcv_packet.len; + /* get received data length in rx buffer */ + +error_exit: + return ercd; +} + +int32_t rw009_get_rx_data(DEV_WNIC *rw009_wnic, uint8_t *p_buf, uint32_t len) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + RW009_CHECK_EXP(p_buf != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + memcpy(p_buf, rw009->rcv_packet.buffer + rw009->rcv_cnt, len); + rw009->rcv_cnt += len; + /* copy received data */ + /* just copy data in rx buffer */ + +error_exit: + return ercd; +} + +int32_t rw009_accept_rx(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + rw009->rcv_cnt = 0; + rw009->rcv_packet.len = 0; + + /* Note: nothing to do in rw009 */ + +error_exit: + return ercd; +} + +int32_t rw009_config_power_mode(DEV_WNIC *rw009_wnic, int32_t power_mode) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + /* \todo no support in rw009 */ + +error_exit: + return ercd; +} + +int32_t rw009_poll_power_mode(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + /* \todo no support in rw009 */ + ercd = rw009_info->power_status; +error_exit: + return ercd; +} + +int32_t rw009_wnic_reset(DEV_WNIC *rw009_wnic) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->init_status == WNIC_INIT_SUCCESSFUL), E_CLSED); + + rw009_info->init_status = WNIC_NOT_INITIALIZED; + rw009_info->power_status = WNIC_POWER_OFF; + + rw009_reset((RW009_DEF_PTR)rw009_info->ctrl); + ercd = rw009_wnic_init(rw009_wnic, rw009_info->network_type); + +error_exit: + return ercd; +} + +void rw009_period_process(DEV_WNIC *rw009_wnic, void *ptr) +{ + int32_t ercd = E_OK; + DEV_WNIC_INFO_PTR rw009_info; + RW009_DEF_PTR rw009; +#ifdef RW009_SPI_CPULOCK_ENABLE + uint32_t cpu_status; +#endif + DEV_WNIC_ON_OPS_PTR rw009_on_ops; + + RW009_CHECK_EXP(rw009_wnic != NULL, E_OBJ); + rw009_info = &(rw009_wnic->wnic_info); + RW009_CHECK_EXP((rw009_info->power_status == WNIC_POWER_NORMAL), E_CLSED); + rw009_on_ops = &(rw009_wnic->wnic_on_ops); + + rw009 = (RW009_DEF_PTR)rw009_info->ctrl; + + if (rw009->rw009_to_send) { +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_status = cpu_lock_save(); +#endif + rw009->rw009_to_send = 0; + rw009_xfer(rw009_wnic, &rw009->snd_packet, &rw009->rcv_packet); + +#ifdef RW009_SPI_CPULOCK_ENABLE + cpu_unlock_restore(cpu_status); +#endif + } + + if (rw009_info->scan_status == WNIC_DURING_SCAN) { + if (rw009_timer_read_ms() > rw009->scan_timer) { + //DBG("rw009 scan finished\n"); + rw009_info->scan_results = rw009->scan_cnt; + rw009_info->scan_status = WNIC_SCAN_FINISHED; + rw009_info->busy_status = WNIC_IS_FREE; + rw009->scan_timer = 0; + if (rw009_on_ops->on_scan_finished != NULL) { + rw009_on_ops->on_scan_finished(rw009_wnic); + } + } + } + + if (rw009_info->init_status == WNIC_DURING_INITIALIZATION) { + if (rw009_timer_read_ms() > rw009->init_timer) { + if (rw009->init_try < RW009_INIT_RETRY) { + DBG("rw009 re-init\r\n"); + RW009_CMD_INIT_DEF cmd; + rw009_reset(rw009); + rw009_deselect(rw009); + cmd.mode = RW009_MODE_STATION; + rw009_cmd(rw009_wnic, RW009_CMD_INIT, (void *)&cmd); + rw009->init_try++; + } else { + DBG("rw009 init failed\r\n"); + rw009->init_try = 0; + rw009_info->init_status = WNIC_INIT_FAILED; + if (rw009_on_ops->on_init_fail != NULL) { + rw009_on_ops->on_init_fail(rw009_wnic); + } + } + } + } + + if (rw009_info->conn_status == WNIC_DURING_CONNECTION) { + if (rw009_timer_read_ms() > rw009->conn_timer) { + DBG("rw009 connection time out\r\n"); + rw009_info->conn_status = WNIC_NOT_CONNECTED; + if (rw009_on_ops->on_disconnected != NULL) { + rw009_on_ops->on_disconnected(rw009_wnic); + } + } + } + +error_exit: + return; +} + +/** + * @brief interrupt service routine for rw009 + * + * @param ptr parameter to isr + */ +void rw009_isr(DEV_WNIC_PTR rw009_wnic) +{ + RW009_DEF_PTR rw009; + + rw009 = (RW009_DEF_PTR)rw009_wnic->wnic_info.ctrl; + //DBG("interrupt from rw009\r\n"); + /* rw009 has data to send */ + if (rw009->rw009_to_send == 0) { + rw009->rw009_to_send = 1; + } else { + DBG("rw009 interrupt missed\r\n"); + } + rw009_int_disable(rw009); +} \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/baremetal/blinky/main.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/baremetal/blinky/main.c new file mode 100644 index 00000000..8a66c4be --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/baremetal/blinky/main.c @@ -0,0 +1,84 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ + +/** + * \defgroup EMBARC_APP_BAREMETAL_BLINKY embARC Blinky Example + * \ingroup EMBARC_APPS_TOTAL + * \ingroup EMBARC_APPS_BAREMETAL + * \brief embARC example for toggle leds on board + * + * \details + * ### Extra Required Tools + * + * ### Extra Required Peripherals + * + * ### Design Concept + * This example is designed to test board without any extra peripheral + * + * ### Usage Manual + * Toggle all leds on board in 1s period + * + * ### Extra Comments + * + */ + +/** + * \file + * \ingroup EMBARC_APP_BAREMETAL_BLINKY + * \brief main source file for blinky example + */ + +/** + * \addtogroup EMBARC_APP_BAREMETAL_BLINKY + * @{ + */ +/* embARC HAL */ +#include "../../../inc/embARC.h" +#include "../../../inc/embARC_debug.h" + +#define LED_TOGGLE_MASK BOARD_LED_MASK + +/** + * \brief Test hardware board without any peripheral + */ +int main(void) +{ + uint16_t led_toggle_val = LED_TOGGLE_MASK; + + while (1) { + led_write(led_toggle_val, BOARD_LED_MASK); + led_toggle_val = ~led_toggle_val; + board_delay_ms(500, 1); + } + + return E_SYS; +} + +/** @} */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/freertos/kernel/FreeRTOSConfig.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/freertos/kernel/FreeRTOSConfig.h new file mode 100644 index 00000000..6b4ff326 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/example/freertos/kernel/FreeRTOSConfig.h @@ -0,0 +1,113 @@ +/* + FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 4 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 18 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 10 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/inc/embARC.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/inc/embARC.h new file mode 100644 index 00000000..8886d722 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/inc/embARC.h @@ -0,0 +1,99 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ + +/** + * \file + * \ingroup CORE_ERROR + * \brief header files wrapper + */ +#ifndef _EMBARC_H_ +#define _EMBARC_H_ + +/* toolchain definition */ +#include "embARC_toolchain.h" + +/* error code related definitions */ +#include "embARC_error.h" + +/* ARC HAL */ +#include "arc_builtin.h" +#include "arc_timer.h" +#include "arc_exception.h" +#include "arc_cache.h" +#include "arc_udma.h" + +#include "board.h" + +#ifdef ENABLE_OS +#include "os_hal_inc.h" +#endif + +#ifdef MID_COMMON +#include "console_io.h" +#include "xprintf.h" +#endif + +/* FatFS header files */ +#ifdef MID_FATFS +#include "ff.h" +#include "diskio.h" +#endif + +/* ntshell header files */ +#ifdef MID_NTSHELL +#include "ntshell_task.h" +#endif + +/* vending machine header files */ +#ifdef MID_VM +#include "vm_task.h" +#include "LED_task.h" +#include "communication_task.h" +#include "temp_task.h" +#include "oled_task.h" +#include "numpad_task.h" +#include "dcmotor_task.h" +#endif + +/* \todo: lwIP header files */ +#ifdef MID_LWIP +#endif + +#ifdef LIB_CLIB +#include "embARC_syscalls.h" +#endif + + +/* LIB_SECURESHIELD should be at the end */ +#ifdef LIB_SECURESHIELD +#include "secureshield_lib.h" +#endif + +#endif /* _EMBARC_H_ */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g.h new file mode 100644 index 00000000..9eb18f31 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g.h @@ -0,0 +1,2052 @@ +/* + + u8g.h + + Universal 8bit Graphics Library + + Copyright (c) 2011, olikraus@gmail.com + 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. + + 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 HOLDER 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. + +*/ + +#ifndef _U8G_H +#define _U8G_H + +/* uncomment the following line to support displays larger than 240x240 */ +//#define U8G_16BIT 1 + +/* comment the following line to generate more compact but interrupt unsafe code */ +#define U8G_INTERRUPT_SAFE 1 + + +#include + +#ifdef __18CXX +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +#else +#include +#endif + +#if defined(__AVR__) +#include +#endif + +/* + use the com interface directly on any systems which are not AVR or ARDUINO +*/ +#if defined(__AVR__) || defined(ARDUINO) || defined(__MSP430__) +#define U8G_WITH_PINLIST +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*===============================================================*/ +#ifdef __GNUC__ +# define U8G_NOINLINE __attribute__((noinline)) +# define U8G_PURE __attribute__ ((pure)) +# define U8G_NOCOMMON __attribute__ ((nocommon)) +# define U8G_SECTION(name) __attribute__ ((section (name))) +# if defined(__MSPGCC__) +/* mspgcc does not have .progmem sections. Use -fdata-sections. */ +# define U8G_FONT_SECTION(name) +# endif +# if defined(__AVR__) +# define U8G_FONT_SECTION(name) U8G_SECTION(".progmem." name) +# endif +#else +# define U8G_NOINLINE +# define U8G_PURE +# define U8G_NOCOMMON +# define U8G_SECTION(name) +# define U8G_FONT_SECTION(name) +#endif + +#ifdef __MSP430__ +/* + Specifying a section will cause the MSP-GCC to put even const data to RAM + at least for the fonts. But as the fonts are consts we don't need to specify + it manually - the MSP-GCC seems to be smart enough to put it into the + flash memory. +*/ +# undef U8G_SECTION +# define U8G_SECTION(name) +#endif + +/*===============================================================*/ + +#ifndef U8G_FONT_SECTION +# define U8G_FONT_SECTION(name) +#endif + + +/*===============================================================*/ +/* flash memory access */ + +#if defined(__AVR__) +/* U8G_PROGMEM is used by the XBM example */ +#define U8G_PROGMEM U8G_SECTION(".progmem.data") +typedef uint8_t PROGMEM u8g_pgm_uint8_t; +typedef uint8_t u8g_fntpgm_uint8_t; +#define u8g_pgm_read(adr) pgm_read_byte_near(adr) +#define U8G_PSTR(s) ((u8g_pgm_uint8_t *)PSTR(s)) + +#else + +#define U8G_PROGMEM +#define PROGMEM +typedef uint8_t u8g_pgm_uint8_t; +typedef uint8_t u8g_fntpgm_uint8_t; +#define u8g_pgm_read(adr) (*(const u8g_pgm_uint8_t *)(adr)) +#define U8G_PSTR(s) ((u8g_pgm_uint8_t *)(s)) + +#endif + +/*===============================================================*/ +/* interrupt safe code */ +#if defined(U8G_INTERRUPT_SAFE) +# if defined(__AVR__) +extern uint8_t global_SREG_backup; /* u8g_state.c */ +# define U8G_ATOMIC_START() do { global_SREG_backup = SREG; cli(); } while(0) +# define U8G_ATOMIC_END() SREG = global_SREG_backup +# define U8G_ATOMIC_OR(ptr, val) do { uint8_t tmpSREG = SREG; cli(); (*(ptr) |= (val)); SREG = tmpSREG; } while(0) +# define U8G_ATOMIC_AND(ptr, val) do { uint8_t tmpSREG = SREG; cli(); (*(ptr) &= (val)); SREG = tmpSREG; } while(0) +# else +# define U8G_ATOMIC_OR(ptr, val) (*(ptr) |= (val)) +# define U8G_ATOMIC_AND(ptr, val) (*(ptr) &= (val)) +# define U8G_ATOMIC_START() +# define U8G_ATOMIC_END() +# endif /* __AVR__ */ +#else +# define U8G_ATOMIC_OR(ptr, val) (*(ptr) |= (val)) +# define U8G_ATOMIC_AND(ptr, val) (*(ptr) &= (val)) +# define U8G_ATOMIC_START() +# define U8G_ATOMIC_END() +#endif /* U8G_INTERRUPT_SAFE */ + + +/*===============================================================*/ +/* forward */ +typedef struct _u8g_t u8g_t; +typedef struct _u8g_dev_t u8g_dev_t; + +typedef struct _u8g_dev_arg_pixel_t u8g_dev_arg_pixel_t; +typedef struct _u8g_dev_arg_bbx_t u8g_dev_arg_bbx_t; +typedef struct _u8g_box_t u8g_box_t; +typedef struct _u8g_dev_arg_irgb_t u8g_dev_arg_irgb_t; + + +/*===============================================================*/ +/* generic */ +#if defined(U8G_16BIT) +typedef uint16_t u8g_uint_t; +typedef int16_t u8g_int_t; +#else +typedef uint8_t u8g_uint_t; +typedef int8_t u8g_int_t; +#endif + +#ifdef OBSOLETE +struct _u8g_box_t +{ + u8g_uint_t x0, y0, x1, y1; +}; +typedef struct _u8g_box_t u8g_box_t; +#endif /* OBSOLETE */ + + +/*===============================================================*/ +/* device structure */ + +#ifdef __XC8 +/* device prototype */ +typedef uint8_t (*u8g_dev_fnptr)(void *u8g, void *dev, uint8_t msg, void *arg); + +/* com prototype */ +typedef uint8_t (*u8g_com_fnptr)(void *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); +#else +/* device prototype */ +typedef uint8_t (*u8g_dev_fnptr)(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* com prototype */ +typedef uint8_t (*u8g_com_fnptr)(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); +#endif + + + +struct _u8g_dev_t +{ + u8g_dev_fnptr dev_fn; /* device procedure */ + void *dev_mem; /* device memory */ + u8g_com_fnptr com_fn; /* communication procedure */ +}; + + +/*===============================================================*/ +/* device list */ + +/* Size: 128x64 SDL, u8g_dev_sdl.c */ +extern u8g_dev_t u8g_dev_sdl_1bit; +extern u8g_dev_t u8g_dev_sdl_1bit_h; +extern u8g_dev_t u8g_dev_sdl_2bit; +extern u8g_dev_t u8g_dev_sdl_2bit_double_mem; +extern u8g_dev_t u8g_dev_sdl_8bit; +extern u8g_dev_t u8g_dev_sdl_hicolor; +extern u8g_dev_t u8g_dev_sdl_fullcolor; +int u8g_sdl_get_key(void); + +/* Size: 70x30 monochrom, stdout */ +extern u8g_dev_t u8g_dev_stdout; + +/* Size: monochrom, writes "u8g.pbm" */ +extern u8g_dev_t u8g_dev_pbm; +extern u8g_dev_t u8g_dev_pbm_8h1; +extern u8g_dev_t u8g_dev_pbm_8h2; /* grayscale simulation */ + +/* Size: 128x64 monochrom, no output, used for performance measure */ +extern u8g_dev_t u8g_dev_gprof; + +/* Display: EA DOGS102, Size: 102x64 monochrom */ +extern u8g_dev_t u8g_dev_uc1701_dogs102_sw_spi; +extern u8g_dev_t u8g_dev_uc1701_dogs102_hw_spi; + +extern u8g_dev_t u8g_dev_uc1701_dogs102_2x_sw_spi; +extern u8g_dev_t u8g_dev_uc1701_dogs102_2x_hw_spi; + +/* Display: Mini12864 (dealextreme), Size: 128x64 monochrom */ +extern u8g_dev_t u8g_dev_uc1701_mini12864_sw_spi; +extern u8g_dev_t u8g_dev_uc1701_mini12864_hw_spi; + +extern u8g_dev_t u8g_dev_uc1701_mini12864_2x_sw_spi; +extern u8g_dev_t u8g_dev_uc1701_mini12864_2x_hw_spi; + +/* Display: EA DOGM132, Size: 128x32 monochrom */ +extern u8g_dev_t u8g_dev_st7565_dogm132_sw_spi; +extern u8g_dev_t u8g_dev_st7565_dogm132_hw_spi; + +/* Display: EA DOGM128, Size: 128x64 monochrom */ +extern u8g_dev_t u8g_dev_st7565_dogm128_sw_spi; +extern u8g_dev_t u8g_dev_st7565_dogm128_hw_spi; +extern u8g_dev_t u8g_dev_st7565_dogm128_parallel; + +extern u8g_dev_t u8g_dev_st7565_dogm128_2x_sw_spi; +extern u8g_dev_t u8g_dev_st7565_dogm128_2x_hw_spi; +extern u8g_dev_t u8g_dev_st7565_dogm128_2x_parallel; + +/* EA DOGM 240-6 */ +extern u8g_dev_t u8g_dev_uc1611_dogm240_i2c; +extern u8g_dev_t u8g_dev_uc1611_dogm240_hw_spi; +extern u8g_dev_t u8g_dev_uc1611_dogm240_sw_spi; +extern u8g_dev_t u8g_dev_uc1611_dogm240_8bit; + +/* EA DOGXL 240 */ +extern u8g_dev_t u8g_dev_uc1611_dogxl240_i2c; +extern u8g_dev_t u8g_dev_uc1611_dogxl240_hw_spi; +extern u8g_dev_t u8g_dev_uc1611_dogxl240_sw_spi; +extern u8g_dev_t u8g_dev_uc1611_dogxl240_8bit; + +/* Display: Topway LM6059 128x64 (Adafruit) */ +extern u8g_dev_t u8g_dev_st7565_lm6059_sw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6059_hw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6059_2x_sw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6059_2x_hw_spi; +/* Display: Topway LM6063 128x64 */ +extern u8g_dev_t u8g_dev_st7565_lm6063_sw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6063_hw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6063_2x_sw_spi; +extern u8g_dev_t u8g_dev_st7565_lm6063_2x_hw_spi; +/* Display: Newhaven NHD-C12864 */ +extern u8g_dev_t u8g_dev_st7565_nhd_c12864_sw_spi; +extern u8g_dev_t u8g_dev_st7565_nhd_c12864_hw_spi; +extern u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_sw_spi; +extern u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_hw_spi; + +/* Display: Newhaven NHD-C12832 */ +extern u8g_dev_t u8g_dev_st7565_nhd_c12832_sw_spi; +extern u8g_dev_t u8g_dev_st7565_nhd_c12832_hw_spi; +extern u8g_dev_t u8g_dev_st7565_nhd_c12832_parallel; +extern u8g_dev_t u8g_dev_st7565_nhd_c12832_hw_usart_spi; + +/* Display: Displaytech 64128N */ +extern u8g_dev_t u8g_dev_st7565_64128n_sw_spi; +extern u8g_dev_t u8g_dev_st7565_64128n_hw_spi; +extern u8g_dev_t u8g_dev_st7565_64128n_parallel; + +extern u8g_dev_t u8g_dev_st7565_64128n_2x_sw_spi; +extern u8g_dev_t u8g_dev_st7565_64128n_2x_hw_spi; +extern u8g_dev_t u8g_dev_st7565_64128n_2x_parallel; + +/* Display: LCD-AG-C128032R-DIW W/KK E6 PBF */ +extern u8g_dev_t u8g_dev_uc1601_c128032_sw_spi; +extern u8g_dev_t u8g_dev_uc1601_c128032_hw_spi; + +extern u8g_dev_t u8g_dev_uc1601_c128032_2x_sw_spi; +extern u8g_dev_t u8g_dev_uc1601_c128032_2x_hw_spi; + +/* East Rising/buy-display.com ERC24064-1 */ +extern u8g_dev_t u8g_dev_uc1608_240x64_sw_spi; +extern u8g_dev_t u8g_dev_uc1608_240x64_hw_spi; + +extern u8g_dev_t u8g_dev_uc1608_240x64_2x_sw_spi; +extern u8g_dev_t u8g_dev_uc1608_240x64_2x_hw_spi; + +/* UC1608 240x128 */ +extern u8g_dev_t u8g_dev_uc1608_240x128_sw_spi; +extern u8g_dev_t u8g_dev_uc1608_240x128_hw_spi; + +extern u8g_dev_t u8g_dev_uc1608_240x128_2x_sw_spi; +extern u8g_dev_t u8g_dev_uc1608_240x128_2x_hw_spi; + +/* dfrobot 128x64 Graphic LCD (SKU:FIT0021) */ +extern u8g_dev_t u8g_dev_st7920_128x64_sw_spi; +extern u8g_dev_t u8g_dev_st7920_128x64_hw_spi; +extern u8g_dev_t u8g_dev_st7920_128x64_8bit; +extern u8g_dev_t u8g_dev_st7920_128x64_custom; + +extern u8g_dev_t u8g_dev_st7920_128x64_4x_sw_spi; +extern u8g_dev_t u8g_dev_st7920_128x64_4x_hw_spi; +extern u8g_dev_t u8g_dev_st7920_128x64_4x_8bit; +extern u8g_dev_t u8g_dev_st7920_128x64_4x_custom; + +/* NHD-19232WG */ +extern u8g_dev_t u8g_dev_st7920_192x32_sw_spi; +extern u8g_dev_t u8g_dev_st7920_192x32_hw_spi; +extern u8g_dev_t u8g_dev_st7920_192x32_8bit; + +extern u8g_dev_t u8g_dev_st7920_192x32_4x_sw_spi; +extern u8g_dev_t u8g_dev_st7920_192x32_4x_hw_spi; +extern u8g_dev_t u8g_dev_st7920_192x32_4x_8bit; + +/* CrystalFontz CFAG20232 */ +extern u8g_dev_t u8g_dev_st7920_202x32_sw_spi; +extern u8g_dev_t u8g_dev_st7920_202x32_hw_spi; +extern u8g_dev_t u8g_dev_st7920_202x32_8bit; + +extern u8g_dev_t u8g_dev_st7920_202x32_4x_sw_spi; +extern u8g_dev_t u8g_dev_st7920_202x32_4x_hw_spi; +extern u8g_dev_t u8g_dev_st7920_202x32_4x_8bit; + +/* LC7981 160x80 display */ +extern u8g_dev_t u8g_dev_lc7981_160x80_8bit; +/* LC7981 240x64 display */ +extern u8g_dev_t u8g_dev_lc7981_240x64_8bit; +/* LC7981 240x128 display */ +extern u8g_dev_t u8g_dev_lc7981_240x128_8bit; +/* LC7981 320x64 display */ +extern u8g_dev_t u8g_dev_lc7981_320x64_8bit; + +/* T6963, all t6963 devices have double page (2x) */ +extern u8g_dev_t u8g_dev_t6963_240x128_8bit; +extern u8g_dev_t u8g_dev_t6963_128x128_8bit; +extern u8g_dev_t u8g_dev_t6963_240x64_8bit; +extern u8g_dev_t u8g_dev_t6963_128x64_8bit; + +/* Display: EA DOGXL160, Size: 160x104 monochrom & gray level */ +extern u8g_dev_t u8g_dev_uc1610_dogxl160_bw_sw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_bw_hw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_gr_sw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_gr_hw_spi; + +extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_bw_sw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_bw_hw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_gr_sw_spi; +extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_gr_hw_spi; + +/* Display: Generic KS0108b, Size: 128x64 monochrom */ +extern u8g_dev_t u8g_dev_ks0108_128x64; /* official Arduino Library interface */ +extern u8g_dev_t u8g_dev_ks0108_128x64_fast; /* faster, but uses private tables from the Arduino Library */ + +/* Nokia 84x48 Display with PCD8544 */ +extern u8g_dev_t u8g_dev_pcd8544_84x48_sw_spi; +extern u8g_dev_t u8g_dev_pcd8544_84x48_hw_spi; +extern u8g_dev_t u8g_dev_tls8204_84x48_sw_spi; + +/* Nokia 96x65 Display with PCF8812 */ +extern u8g_dev_t u8g_dev_pcf8812_96x65_sw_spi; +extern u8g_dev_t u8g_dev_pcf8812_96x65_hw_spi; + +/* NHD-2.7-12864UCY3 OLED Display with SSD1325 Controller */ +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_sw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_hw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_parallel; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_gr_hw_spi; + +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_sw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_hw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_parallel; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_hw_spi; + +/* LY120 OLED with SSD1327 Controller (tested with Seeedstudio module) */ +extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_hw_spi; +extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_i2c; + +extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_hw_spi; +extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_i2c; + +/* NHD-3.12-25664 OLED Display with SSD1322 Controller */ +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_sw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_hw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_parallel; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_sw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_hw_spi; + +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_hw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_parallel; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_sw_spi; +extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_hw_spi; + +/* OLED 128x64 Display with SSD1306 Controller */ +extern u8g_dev_t u8g_dev_ssd1306_128x64_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x64_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x64_i2c; + +extern u8g_dev_t u8g_dev_ssd1306_adafruit_128x64_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_adafruit_128x64_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_adafruit_128x64_i2c; + +extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c; +extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c0; +extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c1; + +/* OLED 128x64 Display with SH1106 Controller */ +extern u8g_dev_t u8g_dev_sh1106_128x64_sw_spi; +extern u8g_dev_t u8g_dev_sh1106_128x64_hw_spi; +extern u8g_dev_t u8g_dev_sh1106_128x64_i2c; + +extern u8g_dev_t u8g_dev_sh1106_128x64_2x_sw_spi; +extern u8g_dev_t u8g_dev_sh1106_128x64_2x_hw_spi; +extern u8g_dev_t u8g_dev_sh1106_128x64_2x_i2c; + +/* OLED 128x64 Display with SSD1309 Controller */ +extern u8g_dev_t u8g_dev_ssd1309_128x64_sw_spi; +extern u8g_dev_t u8g_dev_ssd1309_128x64_hw_spi; +extern u8g_dev_t u8g_dev_ssd1309_128x64_i2c; + +/* OLED 128x32 Display with SSD1306 Controller */ +extern u8g_dev_t u8g_dev_ssd1306_128x32_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x32_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x32_i2c; + +extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_i2c; + +/* OLED 64x48 Display with SSD1306 Controller */ +extern u8g_dev_t u8g_dev_ssd1306_64x48_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_64x48_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_64x48_i2c; + +extern u8g_dev_t u8g_dev_ssd1306_64x48_2x_sw_spi; +extern u8g_dev_t u8g_dev_ssd1306_64x48_2x_hw_spi; +extern u8g_dev_t u8g_dev_ssd1306_64x48_2x_i2c; + +/* OLED 60x32 Display with LD7032 Controller */ +extern u8g_dev_t u8g_dev_ld7032_60x32_sw_spi; +extern u8g_dev_t u8g_dev_ld7032_60x32_hw_spi; +extern u8g_dev_t u8g_dev_ld7032_60x32_parallel; + +/* experimental 65K TFT with st7687 controller */ +extern u8g_dev_t u8g_dev_st7687_c144mvgd_sw_spi; +extern u8g_dev_t u8g_dev_st7687_c144mvgd_8bit; + +/* SBN1661/SED1520 display with 122x32 */ +extern u8g_dev_t u8g_dev_sbn1661_122x32; + +/* flip disc matrix */ +extern u8g_dev_t u8g_dev_flipdisc_2x7; +void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)); + +/* ILI9325D based TFT */ +extern u8g_dev_t u8g_dev_ili9325d_320x240_8bit; + + +/* SSD1351 OLED (breakout board from http://www.kickstarter.com/projects/ilsoftltd/colour-oled-breakout-board) */ +extern u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi; + +/* SSD1351 OLED (Freetronics, GPIOs set to high level) */ +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi; +extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi; + + +/* SSD1353 OLED Palmtronics */ +extern u8g_dev_t u8g_dev_ssd1353_160x128_332_hw_spi; +extern u8g_dev_t u8g_dev_ssd1353_160x128_hicolor_hw_spi; + +/* HT1632 */ +extern u8g_dev_t u8g_dev_ht1632_24x16; + +/* A2 Micro Printer */ +extern u8g_dev_t u8g_dev_a2_micro_printer_384x240; +extern u8g_dev_t u8g_dev_a2_micro_printer_192x120_ds; +extern u8g_dev_t u8g_dev_a2_micro_printer_192x360_ds; +extern u8g_dev_t u8g_dev_a2_micro_printer_192x720_ds; + +/* u8g_virtual_screen.c */ +extern u8g_dev_t u8g_dev_vs; + + +/*===============================================================*/ +/* device messages */ + +struct _u8g_dev_arg_pixel_t +{ + u8g_uint_t x, y; /* will be modified */ + uint8_t pixel; /* will be modified, pixel sequence or transparency value */ + uint8_t dir; + uint8_t color; /* color or index value, red value for true color mode */ + uint8_t hi_color; /* high byte for 64K color mode, low byte is in "color", green value for true color mode */ + uint8_t blue; /* blue value in true color mode */ +}; +/* typedef struct _u8g_dev_arg_pixel_t u8g_dev_arg_pixel_t; */ /* forward decl */ + +/* range for r,g,b: 0..255 */ +#define U8G_GET_HICOLOR_BY_RGB(r,g,b) (((uint16_t)((r)&0x0f8))<<8)|(((uint16_t)((g)&0x0fc))<<3)|(((uint16_t)((b)>>3))) + +struct _u8g_dev_arg_bbx_t +{ + u8g_uint_t x, y, w, h; +}; +/* typedef struct _u8g_dev_arg_bbx_t u8g_dev_arg_bbx_t; */ /* forward decl */ + +struct _u8g_box_t +{ + u8g_uint_t x0, y0, x1, y1; +}; +/* typedef struct _u8g_box_t u8g_box_t; */ /* forward decl */ + +struct _u8g_dev_arg_irgb_t +{ + u8g_uint_t idx, r, g, b; /* index with rgb value */ +}; +/* typedef struct _u8g_dev_arg_irgb_t u8g_dev_arg_irgb_t; */ /* forward decl */ + + + +#define U8G_DEV_MSG_INIT 10 +#define U8G_DEV_MSG_STOP 11 + +/* arg: pointer to uint8_t, contranst value between 0 and 255 */ +#define U8G_DEV_MSG_CONTRAST 15 + +#define U8G_DEV_MSG_SLEEP_ON 16 +#define U8G_DEV_MSG_SLEEP_OFF 17 + +#define U8G_DEV_MSG_PAGE_FIRST 20 +#define U8G_DEV_MSG_PAGE_NEXT 21 + +/* arg: u8g_dev_arg_bbx_t * */ +/* new algorithm with U8G_DEV_MSG_GET_PAGE_BOX makes this msg obsolete */ +/* #define U8G_DEV_MSG_IS_BBX_INTERSECTION 22 */ + +/* arg: u8g_box_t *, fill structure with current page properties */ +#define U8G_DEV_MSG_GET_PAGE_BOX 23 + +/* +#define U8G_DEV_MSG_PRIMITIVE_START 30 +#define U8G_DEV_MSG_PRIMITIVE_END 31 +*/ + +/* arg: u8g_dev_arg_pixel_t * */ +#define U8G_DEV_MSG_SET_TPIXEL 44 +#define U8G_DEV_MSG_SET_4TPIXEL 45 + +#define U8G_DEV_MSG_SET_PIXEL 50 +#define U8G_DEV_MSG_SET_8PIXEL 59 + +#define U8G_DEV_MSG_SET_COLOR_ENTRY 60 + +#define U8G_DEV_MSG_SET_XY_CB 61 + +#define U8G_DEV_MSG_GET_WIDTH 70 +#define U8G_DEV_MSG_GET_HEIGHT 71 +#define U8G_DEV_MSG_GET_MODE 72 + +/*===============================================================*/ +/* device modes */ +#define U8G_MODE(is_index_mode, is_color, bits_per_pixel) (((is_index_mode)<<6) | ((is_color)<<5)|(bits_per_pixel)) + +#define U8G_MODE_UNKNOWN 0 +#define U8G_MODE_BW U8G_MODE(0, 0, 1) +#define U8G_MODE_GRAY2BIT U8G_MODE(0, 0, 2) +#define U8G_MODE_R3G3B2 U8G_MODE(0, 1, 8) +#define U8G_MODE_INDEX U8G_MODE(1, 1, 8) +/* hicolor is R5G6B5 */ +#define U8G_MODE_HICOLOR U8G_MODE(0, 1, 16) +/* truecolor */ +#define U8G_MODE_TRUECOLOR U8G_MODE(0, 1, 24) + + +#define U8G_MODE_GET_BITS_PER_PIXEL(mode) ((mode)&31) +#define U8G_MODE_IS_COLOR(mode) (((mode)&32)==0?0:1) +#define U8G_MODE_IS_INDEX_MODE(mode) (((mode)&64)==0?0:1) + + +/*===============================================================*/ +/* com options */ + +/* uncomment the following line for Atmega HW SPI double speed, issue 89 */ +/* #define U8G_HW_SPI_2X 1 */ + +/* com messages */ + +#define U8G_COM_MSG_STOP 0 +#define U8G_COM_MSG_INIT 1 + +#define U8G_COM_MSG_ADDRESS 2 + +/* CHIP_SELECT argument: number of the chip which needs to be activated, so this is more like high active */ +#define U8G_COM_MSG_CHIP_SELECT 3 + +#define U8G_COM_MSG_RESET 4 + +#define U8G_COM_MSG_WRITE_BYTE 5 +#define U8G_COM_MSG_WRITE_SEQ 6 +#define U8G_COM_MSG_WRITE_SEQ_P 7 + + +/* com driver */ + +uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_null.c */ + +uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* requires U8G_WITH_PINLIST */ + + +uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_std_sw_spi.c */ +uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_atmega_hw_usart_spi.c */ +uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_sw_spi.c */ +uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_hw_spi.c */ +uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_arduino_ATTiny85_std_hw_spi.c */ +uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_st7920_spi.c */ +uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_st7920_custom.c */ +uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_st7920_hw_spi.c */ +uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_parallel.c */ +uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_fast_parallel.c */ +uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_port_d_wr.c */ +uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_no_en_parallel.c */ +uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_ssd_i2c.c */ +uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); +uint8_t u8g_com_arduino_t6963_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_t6963.c */ + + +uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_atmega_hw_spi.c */ +uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_atmega_sw_spi.c */ +uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_atmega_st7920_spi.c */ +uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); +uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_atmega_parallel.c */ + +uint8_t u8g_com_msp430_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_msp430_hw_spi.c */ + +uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_rasperrypi_hw_spi.c */ +uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_raspberrypi_ssd_i2c.c */ + +uint8_t u8g_com_embarc_ssd_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); +uint8_t u8g_com_embarc_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); + + +/* + Translation of system specific com drives to generic com names + At the moment, the following generic com drives are available + U8G_COM_HW_SPI + U8G_COM_SW_SPI + U8G_COM_PARALLEL + U8G_COM_T6963 + U8G_COM_FAST_PARALLEL + U8G_COM_SSD_I2C + U8G_COM_SSD_SPI + U8G_COM_UC_I2C + +defined(__18CXX) || defined(__PIC32MX) + +*/ + +/* ==== HW SPI, msp430 ====*/ +#if defined(__MSP430__) +#define U8G_COM_HW_SPI u8g_com_msp430_hw_spi_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#endif + +/* ==== HW SPI, Raspberry PI ====*/ +#if defined(U8G_RASPBERRY_PI) +#define U8G_COM_HW_SPI u8g_com_raspberrypi_hw_spi_fn +#define U8G_COM_SW_SPI u8g_com_null_fn + +/* I'm sure there must be some mad reason for needing this */ +#define U8G_COM_ST7920_SW_SPI u8g_com_null_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#endif + +/* ==== HW SPI, Arduino ====*/ +#if defined(ARDUINO) +#if defined(__AVR__) + +#if defined(__AVR_ATtiny85__) +#define U8G_COM_HW_SPI u8g_com_arduino_ATtiny85_std_hw_spi_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#else + +#define U8G_COM_HW_SPI u8g_com_arduino_hw_spi_fn +#if defined(__AVR_ATmega32U4__) +#define U8G_COM_HW_USART_SPI u8g_com_arduino_hw_usart_spi_fn +#endif /* __AVR_ATmega32U4__ */ +#define U8G_COM_ST7920_HW_SPI u8g_com_arduino_st7920_hw_spi_fn +#endif /* __AVR_ATtiny85__ */ + +#elif defined(__18CXX) || defined(__PIC32MX) +#define U8G_COM_HW_SPI u8g_com_null_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#elif defined(__SAM3X8E__) /* Arduino Due */ +#define U8G_COM_HW_SPI u8g_com_arduino_hw_spi_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#endif +#endif +/* ==== HW SPI, not Arduino ====*/ +#ifndef U8G_COM_HW_SPI +#if defined(__AVR__) +#define U8G_COM_HW_SPI u8g_com_atmega_hw_spi_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_atmega_st7920_hw_spi_fn +#endif +#endif +#ifndef U8G_COM_HW_SPI +#define U8G_COM_HW_SPI u8g_com_null_fn +#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn +#endif +#ifndef U8G_COM_HW_USART_SPI +#define U8G_COM_HW_USART_SPI u8g_com_null_fn +#endif + + +/* ==== SW SPI, Arduino ====*/ +#if defined(ARDUINO) +#if defined(__AVR__) +#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn +#elif defined(__18CXX) || defined(__PIC32MX) +#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn +#elif defined(__SAM3X8E__) /* Arduino Due */ +//#define U8G_COM_SW_SPI u8g_com_arduino_std_sw_spi_fn +#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn +#elif defined(__arm__) /* Teensy */ +#define U8G_COM_SW_SPI u8g_com_arduino_std_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn +#endif +#endif + +#ifndef U8G_COM_SW_SPI +/* ==== SW SPI, not Arduino ====*/ + +/* ==== SW SPI, msp430 ====*/ +#if defined(__MSP430__) +#define U8G_COM_SW_SPI u8g_com_std_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_null_fn +#endif + +#if defined(__AVR__) +#define U8G_COM_SW_SPI u8g_com_atmega_sw_spi_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_atmega_st7920_sw_spi_fn +#endif +#endif +#ifndef U8G_COM_SW_SPI +#define U8G_COM_SW_SPI u8g_com_null_fn +#define U8G_COM_ST7920_SW_SPI u8g_com_null_fn +#endif + +/* ==== Parallel interface, Arduino ====*/ +#if defined(ARDUINO) +#if defined(__AVR__) +#define U8G_COM_PARALLEL u8g_com_arduino_parallel_fn +#define U8G_COM_FAST_PARALLEL u8g_com_arduino_fast_parallel_fn +#define U8G_COM_T6963 u8g_com_arduino_t6963_fn +#else /* Arduino Due, Chipkit PIC32 */ +#define U8G_COM_PARALLEL u8g_com_arduino_parallel_fn +#define U8G_COM_FAST_PARALLEL u8g_com_arduino_parallel_fn +#define U8G_COM_T6963 u8g_com_null_fn +#endif +#endif +#ifndef U8G_COM_PARALLEL +#if defined(__AVR__) +#define U8G_COM_PARALLEL u8g_com_atmega_parallel_fn +#define U8G_COM_FAST_PARALLEL u8g_com_atmega_parallel_fn +#define U8G_COM_T6963 u8g_com_null_fn +#endif +#endif +#ifndef U8G_COM_PARALLEL +#define U8G_COM_PARALLEL u8g_com_null_fn +#define U8G_COM_FAST_PARALLEL u8g_com_null_fn +#define U8G_COM_T6963 u8g_com_null_fn +#endif + +#if defined(ARDUINO) +#if defined(__AVR__) +#define U8G_COM_SSD_I2C u8g_com_arduino_ssd_i2c_fn +#define U8G_COM_UC_I2C u8g_com_arduino_uc_i2c_fn +#endif +#endif + +#ifndef U8G_COM_SSD_I2C +#if defined(__AVR__) || defined(__SAM3X8E__) +/* AVR variant and also DUE can use the arduino version at the moment */ +#define U8G_COM_SSD_I2C u8g_com_arduino_ssd_i2c_fn +#endif +#endif + +#ifndef U8G_COM_SSD_I2C +#if defined(U8G_RASPBERRY_PI) +#define U8G_COM_SSD_I2C u8g_com_raspberrypi_ssd_i2c_fn +#endif +#endif + +/* ==== HW I2C, embARC ====*/ +#if defined(PLATFORM_EMBARC) +#define U8G_COM_SSD_I2C u8g_com_embarc_ssd_i2c_fn + +#ifndef U8G_COM_SSD_I2C +#define U8G_COM_SSD_I2C u8g_com_null_fn +#endif +#endif + +/* ==== HW SPI, embARC ====*/ +#if defined(PLATFORM_EMBARC) +#define U8G_COM_SSD_SPI u8g_com_embarc_ssd_spi_fn + +#ifndef U8G_COM_SSD_SPI +#define U8G_COM_SSD_SPI u8g_com_null_fn +#endif + +#endif + + +#ifndef U8G_COM_UC_I2C +#if defined(__AVR__) +/* AVR variant can use the arduino version at the moment */ +#define U8G_COM_UC_I2C u8g_com_arduino_uc_i2c_fn +#endif +#endif +#ifndef U8G_COM_UC_I2C +#define U8G_COM_UC_I2C u8g_com_null_fn +#endif + + +/*===============================================================*/ +/* com api */ + +#define U8G_SPI_CLK_CYCLE_50NS 1 +#define U8G_SPI_CLK_CYCLE_300NS 2 +#define U8G_SPI_CLK_CYCLE_400NS 3 +#define U8G_SPI_CLK_CYCLE_NONE 255 + +uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time); +void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev); +void u8g_EnableCom(u8g_t *u8g, u8g_dev_t *dev); /* obsolete */ +void u8g_DisableCom(u8g_t *u8g, u8g_dev_t *dev); /* obsolete */ +void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs); +void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev); +void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev); +void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address); +uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val); +uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq); +uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq); + + + +#define U8G_ESC_DLY(x) 255, ((x) & 0x7f) +#define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) +#define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) +#define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) +#define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) +#define U8G_ESC_END 255, 254 +#define U8G_ESC_255 255, 255 +//uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, u8g_pgm_uint8_t *esc_seq); +uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq); + + +/* u8g_com_api_16gr.c */ +uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b); +uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr); +uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b); +uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr); + + +/*===============================================================*/ +/* u8g_arduino_common.c */ +void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value); +void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g); + +/*===============================================================*/ +/* u8g_com_io.c */ + +/* create internal number from port and pin */ +uint8_t u8g_Pin(uint8_t port, uint8_t bitpos); +#define PN(port,bitpos) u8g_Pin(port,bitpos) + +/* low level procedures */ +void u8g_SetPinOutput(uint8_t internal_pin_number); +void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level); +void u8g_SetPinInput(uint8_t internal_pin_number); +uint8_t u8g_GetPinLevel(uint8_t internal_pin_number); + +/* u8g level procedures, expect U8G_PI_xxx macro */ +void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi); +void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level); + + +/*===============================================================*/ +/* page */ +struct _u8g_page_t +{ + u8g_uint_t page_height; + u8g_uint_t total_height; + u8g_uint_t page_y0; + u8g_uint_t page_y1; + uint8_t page; +}; +typedef struct _u8g_page_t u8g_page_t; + +void u8g_page_First(u8g_page_t *p) U8G_NOINLINE; /* u8g_page.c */ +void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) U8G_NOINLINE; /* u8g_page.c */ +uint8_t u8g_page_Next(u8g_page_t *p) U8G_NOINLINE; /* u8g_page.c */ + +/*===============================================================*/ +/* page buffer (pb) */ + +struct _u8g_pb_t +{ + u8g_page_t p; + u8g_uint_t width; /* pixel width */ + void *buf; +}; +typedef struct _u8g_pb_t u8g_pb_t; + + +/* u8g_pb.c */ +void u8g_pb_Clear(u8g_pb_t *b); +uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1); +uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1); +uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx); +void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box); +uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel); +uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev); + +/* + note on __attribute__ ((nocommon)) + AVR scripts often use --gc-sections on the linker to remove unused section. + This works fine for initialed data and text sections. In principle .bss is also + handled, but the name##_pb definition is not removed. Reason is, that + array definitions are placed in the COMMON section, by default + The attribute "nocommon" removes this automatic assignment to the + COMMON section and directly puts it into .bss. As a result, if more + than one buffer is defined in one file, then it will be removed with --gc-sections + + .. not sure if Arduino IDE uses -fno-common... if yes, then the attribute is + redundant. +*/ +#define U8G_PB_DEV(name, width, height, page_height, dev_fn, com_fn) \ +uint8_t name##_buf[width] U8G_NOCOMMON ; \ +u8g_pb_t name##_pb = { {page_height, height, 0, 0, 0}, width, name##_buf}; \ +u8g_dev_t name = { dev_fn, &name##_pb, com_fn } + + +void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; +void u8g_pb8v1_Clear(u8g_pb_t *b) U8G_NOINLINE; + +uint8_t u8g_pb8v1_IsYIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1); +uint8_t u8g_pb8v1_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1); +uint8_t u8g_pb8v1_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev); + +uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb16v1.c */ +uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb14v1.c */ +uint8_t u8g_dev_pb14v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb8v2.c */ +uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb16v2.c (double memory of pb8v2) */ +uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + + +/* u8g_pb8h1.c */ +uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb16h1.c */ +uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb32h1.c */ +uint8_t u8g_dev_pb32h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + + +/* u8g_pb8h2.c 8 pixel rows, byte has horzontal orientation */ +uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb16h2.c */ +uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + + + +/* u8g_pb8h1f.c */ +uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pb8h8.c */ +uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pbxh16.c */ +uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +/* u8g_pbxh24.c */ +uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + + +/*===============================================================*/ +/* u8g_ll_api.c */ + +/* cursor draw callback */ +typedef void (*u8g_draw_cursor_fn)(u8g_t *u8g); + +/* vertical reference point calculation callback */ +typedef u8g_uint_t (*u8g_font_calc_vref_fnptr)(u8g_t *u8g); + +/* state backup and restore procedure */ +typedef void (*u8g_state_cb)(uint8_t msg); + + +/* PI = Pin Index */ + +/* reset pin, usually optional */ +#define U8G_PI_RESET 0 + +/* address / data or instruction */ +#define U8G_PI_A0 1 +#define U8G_PI_DI 1 + +/* chip select line */ +#define U8G_PI_CS 2 +#define U8G_PI_CS1 2 +#define U8G_PI_CS2 3 +/* Feb 2013: A0 state moved from 7 to 3 for t6963 controller*/ +#define U8G_PI_A0_STATE 3 + +/* enable / clock signal */ +#define U8G_PI_EN 4 +#define U8G_PI_CS_STATE 4 +#define U8G_PI_SCK 4 +#define U8G_PI_SCL 4 +#define U8G_PI_RD 4 + + +/* data pins, shared with SPI and I2C pins */ +#define U8G_PI_D0 5 +#define U8G_PI_MOSI 5 +#define U8G_PI_SDA 5 +#define U8G_PI_D1 6 +#define U8G_PI_MISO 6 +#define U8G_PI_D2 7 +#define U8G_PI_D3 8 +#define U8G_PI_SET_A0 8 +#define U8G_PI_D4 9 +#define U8G_PI_D5 10 +#define U8G_PI_I2C_OPTION 11 +#define U8G_PI_D6 11 +#define U8G_PI_D7 12 + +/* read/write pin, must be the last pin in the list, this means U8G_PIN_LIST_LEN = U8G_PI_RW + 1*/ +#define U8G_PI_WR 13 +#define U8G_PI_RW 13 + +#define U8G_PIN_LIST_LEN 14 + + +#define U8G_PIN_DUMMY 254 +#define U8G_PIN_NONE 255 + +#define U8G_FONT_HEIGHT_MODE_TEXT 0 +#define U8G_FONT_HEIGHT_MODE_XTEXT 1 +#define U8G_FONT_HEIGHT_MODE_ALL 2 + +struct _u8g_t +{ + u8g_uint_t width; + u8g_uint_t height; + + + u8g_dev_t *dev; /* first device in the device chain */ + const u8g_pgm_uint8_t *font; /* regular font for all text procedures */ + const u8g_pgm_uint8_t *cursor_font; /* special font for cursor procedures */ + uint8_t cursor_fg_color, cursor_bg_color; + uint8_t cursor_encoding; + uint8_t mode; /* display mode, one of U8G_MODE_xxx */ + u8g_uint_t cursor_x; + u8g_uint_t cursor_y; + u8g_draw_cursor_fn cursor_fn; + + int8_t glyph_dx; + int8_t glyph_x; + int8_t glyph_y; + uint8_t glyph_width; + uint8_t glyph_height; + + u8g_font_calc_vref_fnptr font_calc_vref; + uint8_t font_height_mode; + int8_t font_ref_ascent; + int8_t font_ref_descent; + uint8_t font_line_spacing_factor; /* line_spacing = factor * (ascent - descent) / 64 */ + uint8_t line_spacing; + + u8g_dev_arg_pixel_t arg_pixel; + /* uint8_t color_index; */ + +#ifdef U8G_WITH_PINLIST + uint8_t pin_list[U8G_PIN_LIST_LEN]; +#endif + + u8g_state_cb state_cb; + + u8g_box_t current_page; /* current box of the visible page */ + +}; + +#define u8g_GetFontAscent(u8g) ((u8g)->font_ref_ascent) +#define u8g_GetFontDescent(u8g) ((u8g)->font_ref_descent) +#define u8g_GetFontLineSpacing(u8g) ((u8g)->line_spacing) + +uint8_t u8g_call_dev_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); + +uint8_t u8g_InitLL(u8g_t *u8g, u8g_dev_t *dev); +void u8g_FirstPageLL(u8g_t *u8g, u8g_dev_t *dev); +uint8_t u8g_NextPageLL(u8g_t *u8g, u8g_dev_t *dev); +uint8_t u8g_SetContrastLL(u8g_t *u8g, u8g_dev_t *dev, uint8_t contrast); +void u8g_DrawPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y); +void u8g_Draw8PixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel); +void u8g_Draw4TPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel); +uint8_t u8g_IsBBXIntersectionLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h); /* obsolete */ +u8g_uint_t u8g_GetWidthLL(u8g_t *u8g, u8g_dev_t *dev); +u8g_uint_t u8g_GetHeightLL(u8g_t *u8g, u8g_dev_t *dev); + +void u8g_UpdateDimension(u8g_t *u8g); +uint8_t u8g_Begin(u8g_t *u8g); /* reset device, put it into default state and call u8g_UpdateDimension() */ +uint8_t u8g_Init(u8g_t *u8g, u8g_dev_t *dev); /* only usefull if the device only as hardcoded ports */ +uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn); /* Init procedure for anything which is not Arduino or AVR (e.g. ARM, but not Due, which is Arduino) */ + +#if defined(U8G_WITH_PINLIST) +uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset); +uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset); +uint8_t u8g_InitI2C(u8g_t *u8g, u8g_dev_t *dev, uint8_t options); /* use U8G_I2C_OPT_NONE as options */ +uint8_t u8g_Init8BitFixedPort(u8g_t *u8g, u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset); +uint8_t u8g_Init8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, + uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset); +uint8_t u8g_InitRW8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, + uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset); +#endif + +void u8g_FirstPage(u8g_t *u8g); +uint8_t u8g_NextPage(u8g_t *u8g); +uint8_t u8g_SetContrast(u8g_t *u8g, uint8_t contrast); +void u8g_SleepOn(u8g_t *u8g); +void u8g_SleepOff(u8g_t *u8g); +void u8g_DrawPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y); +void u8g_Draw8Pixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel); +void u8g_Draw4TPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel); +void u8g_Draw8ColorPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t colpixel); + +uint8_t u8g_Stop(u8g_t *u8g); +void u8g_SetColorEntry(u8g_t *u8g, uint8_t idx, uint8_t r, uint8_t g, uint8_t b); +void u8g_SetColorIndex(u8g_t *u8g, uint8_t idx); +void u8g_SetHiColor(u8g_t *u8g, uint16_t rgb); +void u8g_SetHiColorByRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b); +void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b); +uint8_t u8g_GetColorIndex(u8g_t *u8g); + +uint8_t u8g_GetDefaultForegroundColor(u8g_t *u8g); +void u8g_SetDefaultForegroundColor(u8g_t *u8g); + +uint8_t u8g_GetDefaultBackgroundColor(u8g_t *u8g); +void u8g_SetDefaultBackgroundColor(u8g_t *u8g); + +uint8_t u8g_GetDefaultMidColor(u8g_t *u8g); +void u8g_SetDefaultMidColor(u8g_t *u8g); + +#define u8g_GetWidth(u8g) ((u8g)->width) +#define u8g_GetHeight(u8g) ((u8g)->height) +#define u8g_GetMode(u8g) ((u8g)->mode) +/* + U8G_MODE_GET_BITS_PER_PIXEL(u8g_GetMode(u8g)) + U8G_MODE_IS_COLOR(u8g_GetMode(u8g)) +*/ + +/* u8g_state.c */ +#define U8G_STATE_ENV_IDX 0 +#define U8G_STATE_U8G_IDX 1 +#define U8G_STATE_RESTORE 0 +#define U8G_STATE_BACKUP 1 +#define U8G_STATE_MSG_COMPOSE(cmd,idx) (((cmd)<<1) | (idx)) + +#define U8G_STATE_MSG_RESTORE_ENV U8G_STATE_MSG_COMPOSE(U8G_STATE_RESTORE,U8G_STATE_ENV_IDX) +#define U8G_STATE_MSG_BACKUP_ENV U8G_STATE_MSG_COMPOSE(U8G_STATE_BACKUP,U8G_STATE_ENV_IDX) +#define U8G_STATE_MSG_RESTORE_U8G U8G_STATE_MSG_COMPOSE(U8G_STATE_RESTORE,U8G_STATE_U8G_IDX) +#define U8G_STATE_MSG_BACKUP_U8G U8G_STATE_MSG_COMPOSE(U8G_STATE_BACKUP,U8G_STATE_U8G_IDX) + +#define U8G_STATE_MSG_GET_IDX(msg) ((msg)&1) +#define U8G_STATE_MSG_IS_BACKUP(msg) ((msg)&2) + + + +void u8g_state_dummy_cb(uint8_t msg); +void u8g_backup_spi(uint8_t msg); /* backup SPI state controller */ +/* backward compatible definition */ +#define u8g_backup_avr_spi u8g_backup_spi + +void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb); + +/* u8g_clip.c */ + +uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h); + + +/* u8g_rot.c */ + +void u8g_UndoRotation(u8g_t *u8g); +void u8g_SetRot90(u8g_t *u8g); +void u8g_SetRot180(u8g_t *u8g); +void u8g_SetRot270(u8g_t *u8g); + +/* u8g_scale.c */ + +void u8g_UndoScale(u8g_t *u8g); +void u8g_SetScale2x2(u8g_t *u8g); + + +/* u8g_font.c */ + +size_t u8g_font_GetSize(const void *font); +uint8_t u8g_font_GetFontStartEncoding(const void *font) U8G_NOINLINE; +uint8_t u8g_font_GetFontEndEncoding(const void *font) U8G_NOINLINE; + +void u8g_SetFont(u8g_t *u8g, const u8g_fntpgm_uint8_t *font); + +uint8_t u8g_GetFontBBXWidth(u8g_t *u8g); +uint8_t u8g_GetFontBBXHeight(u8g_t *u8g); +int8_t u8g_GetFontBBXOffX(u8g_t *u8g); +int8_t u8g_GetFontBBXOffY(u8g_t *u8g); +uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g); + +uint8_t u8g_IsGlyph(u8g_t *u8g, uint8_t requested_encoding); +int8_t u8g_GetGlyphDeltaX(u8g_t *u8g, uint8_t requested_encoding); + +int8_t u8g_draw_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); /* used by u8g_cursor.c */ + +int8_t u8g_DrawGlyphDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding); +int8_t u8g_DrawGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); +int8_t u8g_DrawGlyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); +int8_t u8g_DrawGlyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); +int8_t u8g_DrawGlyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); +int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding); + +u8g_uint_t u8g_DrawStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s); +u8g_uint_t u8g_DrawStr90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s); +u8g_uint_t u8g_DrawStr180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s); +u8g_uint_t u8g_DrawStr270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s); + +u8g_uint_t u8g_DrawStrDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s); + + +u8g_uint_t u8g_DrawStrP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s); +u8g_uint_t u8g_DrawStr90P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s); +u8g_uint_t u8g_DrawStr180P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s); +u8g_uint_t u8g_DrawStr270P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s); + + +void u8g_SetFontRefHeightText(u8g_t *u8g); +void u8g_SetFontRefHeightExtendedText(u8g_t *u8g); +void u8g_SetFontRefHeightAll(u8g_t *u8g); +void u8g_SetFontLineSpacingFactor(u8g_t *u8g, uint8_t factor); + +u8g_uint_t u8g_font_calc_vref_font(u8g_t *u8g); +u8g_uint_t u8g_font_calc_vref_bottom(u8g_t *u8g); +u8g_uint_t u8g_font_calc_vref_top(u8g_t *u8g); +u8g_uint_t u8g_font_calc_vref_center(u8g_t *u8g); + +void u8g_SetFontPosBaseline(u8g_t *u8g); +void u8g_SetFontPosBottom(u8g_t *u8g); +void u8g_SetFontPosCenter(u8g_t *u8g); +void u8g_SetFontPosTop(u8g_t *u8g); + + +u8g_uint_t u8g_GetStrPixelWidth(u8g_t *u8g, const char *s); +u8g_uint_t u8g_GetStrPixelWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s); +int8_t u8g_GetStrX(u8g_t *u8g, const char *s); +int8_t u8g_GetStrXP(u8g_t *u8g, const u8g_pgm_uint8_t *s); +u8g_uint_t u8g_GetStrWidth(u8g_t *u8g, const char *s) U8G_NOINLINE; +u8g_uint_t u8g_GetStrWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s); + +u8g_uint_t u8g_DrawStrFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s); + +void u8g_GetStrMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height); +void u8g_GetStrAMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height); + + +u8g_uint_t u8g_DrawAAStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s); + +/* u8g_rect.c */ + +void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE; + +void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w) U8G_NOINLINE; +void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w) U8G_NOINLINE; +void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE; +void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE; + +void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r) U8G_NOINLINE; +void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r) U8G_NOINLINE; + +/* u8g_bitmap.c */ + +void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap); +void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap); +void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap); +void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap); + +void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap); +void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap); + + +/* u8g_line.c */ +void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2); + + +/* u8g_circle.c */ + +/* the following, commented code has been rewritten or is not yet finished +#define U8G_CIRC_UPPER_RIGHT 0x01 +#define U8G_CIRC_UPPER_LEFT 0x02 +#define U8G_CIRC_LOWER_LEFT 0x04 +#define U8G_CIRC_LOWER_RIGHT 0x08 +#define U8G_CIRC_ALL (U8G_CIRC_UPPER_RIGHT|U8G_CIRC_UPPER_LEFT|U8G_CIRC_LOWER_RIGHT|U8G_CIRC_LOWER_LEFT) +void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option); +void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option); +void u8g_DrawEllipseRect(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t x1, u8g_uint_t y1); +*/ + +#define U8G_DRAW_UPPER_RIGHT 0x01 +#define U8G_DRAW_UPPER_LEFT 0x02 +#define U8G_DRAW_LOWER_LEFT 0x04 +#define U8G_DRAW_LOWER_RIGHT 0x08 +#define U8G_DRAW_ALL (U8G_DRAW_UPPER_RIGHT|U8G_DRAW_UPPER_LEFT|U8G_DRAW_LOWER_RIGHT|U8G_DRAW_LOWER_LEFT) + +void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) U8G_NOINLINE; +void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) U8G_NOINLINE; + +void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option); +void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option); + +/* u8g_ellipse.c */ +void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option); +void u8g_DrawFilledEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option); + +/* u8g_clip.c */ +uint8_t u8g_is_box_bbx_intersection(u8g_box_t *box, u8g_dev_arg_bbx_t *bbx); + + +/* u8g_cursor.c */ +void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font); +void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding); +void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y); +void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg); +void u8g_EnableCursor(u8g_t *u8g); +void u8g_DisableCursor(u8g_t *u8g); +void u8g_DrawCursor(u8g_t *u8g); + +/* u8g_polygon.c */ + +typedef int16_t pg_word_t; + +#define PG_NOINLINE U8G_NOINLINE + +struct pg_point_struct +{ + pg_word_t x; + pg_word_t y; +}; + +typedef struct _pg_struct pg_struct; /* forward declaration */ + +struct pg_edge_struct +{ + pg_word_t x_direction; /* 1, if x2 is greater than x1, -1 otherwise */ + pg_word_t height; + pg_word_t current_x_offset; + pg_word_t error_offset; + + /* --- line loop --- */ + pg_word_t current_y; + pg_word_t max_y; + pg_word_t current_x; + pg_word_t error; + + /* --- outer loop --- */ + uint8_t (*next_idx_fn)(pg_struct *pg, uint8_t i); + uint8_t curr_idx; +}; + +/* maximum number of points in the polygon */ +/* can be redefined, but highest possible value is 254 */ +#define PG_MAX_POINTS 6 + +/* index numbers for the pge structures below */ +#define PG_LEFT 0 +#define PG_RIGHT 1 + + +struct _pg_struct +{ + struct pg_point_struct list[PG_MAX_POINTS]; + uint8_t cnt; + uint8_t is_min_y_not_flat; + pg_word_t total_scan_line_cnt; + struct pg_edge_struct pge[2]; /* left and right line draw structures */ +}; + +void pg_ClearPolygonXY(pg_struct *pg); +void pg_AddPolygonXY(pg_struct *pg, u8g_t *u8g, int16_t x, int16_t y); +void pg_DrawPolygon(pg_struct *pg, u8g_t *u8g); +void u8g_ClearPolygonXY(void); +void u8g_AddPolygonXY(u8g_t *u8g, int16_t x, int16_t y); +void u8g_DrawPolygon(u8g_t *u8g); +void u8g_DrawTriangle(u8g_t *u8g, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2); + + +/*===============================================================*/ +/* u8g_virtual_screen.c */ +void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height); +uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g); + +/*===============================================================*/ +void st_Draw(uint8_t fps); +void st_Step(uint8_t player_pos, uint8_t is_auto_fire, uint8_t is_fire); + +/*===============================================================*/ +/* u8g_com_i2c.c */ + +/* options for u8g_i2c_init() */ +#define U8G_I2C_OPT_NONE 0 +#define U8G_I2C_OPT_NO_ACK 2 +#define U8G_I2C_OPT_DEV_0 0 +#define U8G_I2C_OPT_DEV_1 4 +#define U8G_I2C_OPT_FAST 16 + +/* retrun values from u8g_twi_get_error() */ +#define U8G_I2C_ERR_NONE 0x00 +/* the following values are bit masks */ +#define U8G_I2C_ERR_TIMEOUT 0x01 +#define U8G_I2C_ERR_BUS 0x02 + +void u8g_i2c_clear_error(void) U8G_NOINLINE; +uint8_t u8g_i2c_get_error(void) U8G_NOINLINE; +uint8_t u8g_i2c_get_err_pos(void) U8G_NOINLINE; +void u8g_i2c_init(uint8_t options) U8G_NOINLINE; /* use U8G_I2C_OPT_NONE as options */ +uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos) U8G_NOINLINE; +uint8_t u8g_i2c_start(uint8_t sla) U8G_NOINLINE; +uint8_t u8g_i2c_send_byte(uint8_t data) U8G_NOINLINE; +uint8_t u8g_i2c_send_mode(uint8_t mode) U8G_NOINLINE; +void u8g_i2c_stop(void) U8G_NOINLINE; + + +/*===============================================================*/ +/* u8g_u8toa.c */ +/* v = value, d = number of digits */ +const char *u8g_u8toa(uint8_t v, uint8_t d); + +/* u8g_u8toa.c */ +/* v = value, d = number of digits */ +const char *u8g_u16toa(uint16_t v, uint8_t d); + +/*===============================================================*/ +/* u8g_delay.c */ + +/* delay by the specified number of milliseconds */ +void u8g_Delay(uint16_t val); + +/* delay by one microsecond */ +void u8g_MicroDelay(void); + +/* delay by 10 microseconds */ +void u8g_10MicroDelay(void); + +/*===============================================================*/ +/* chessengine.c */ +#define CHESS_KEY_NONE 0 +#define CHESS_KEY_NEXT 1 +#define CHESS_KEY_PREV 2 +#define CHESS_KEY_SELECT 3 +#define CHESS_KEY_BACK 4 + +void chess_Init(u8g_t *u8g, uint8_t empty_body_color); +void chess_Draw(void); +void chess_Step(uint8_t keycode); + +/*===============================================================*/ +/* font definitions */ +extern const u8g_fntpgm_uint8_t u8g_font_m2icon_5[] U8G_FONT_SECTION("u8g_font_m2icon_5"); +extern const u8g_fntpgm_uint8_t u8g_font_m2icon_7[] U8G_FONT_SECTION("u8g_font_m2icon_7"); +extern const u8g_fntpgm_uint8_t u8g_font_m2icon_9[] U8G_FONT_SECTION("u8g_font_m2icon_9"); + +extern const u8g_fntpgm_uint8_t u8g_font_u8glib_4[] U8G_FONT_SECTION("u8g_font_u8glib_4"); +extern const u8g_fntpgm_uint8_t u8g_font_u8glib_4r[] U8G_FONT_SECTION("u8g_font_u8glib_4r"); + + +extern const u8g_fntpgm_uint8_t u8g_font_6x12_75r[] U8G_FONT_SECTION("u8g_font_6x12_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13_75r[] U8G_FONT_SECTION("u8g_font_6x13_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13_75r[] U8G_FONT_SECTION("u8g_font_7x13_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13_75r[] U8G_FONT_SECTION("u8g_font_8x13_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15_75r[] U8G_FONT_SECTION("u8g_font_9x15_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18_75r[] U8G_FONT_SECTION("u8g_font_9x18_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_cu12_75r[] U8G_FONT_SECTION("u8g_font_cu12_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_75r[] U8G_FONT_SECTION("u8g_font_unifont_75r"); +extern const u8g_fntpgm_uint8_t u8g_font_10x20_75r[] U8G_FONT_SECTION("u8g_font_10x20_75r"); + +extern const u8g_fntpgm_uint8_t u8g_font_10x20_67_75[] U8G_FONT_SECTION("u8g_font_10x20_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_10x20_78_79[] U8G_FONT_SECTION("u8g_font_10x20_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_10x20[] U8G_FONT_SECTION("u8g_font_10x20"); +extern const u8g_fntpgm_uint8_t u8g_font_10x20r[] U8G_FONT_SECTION("u8g_font_10x20r"); +extern const u8g_fntpgm_uint8_t u8g_font_4x6[] U8G_FONT_SECTION("u8g_font_4x6"); +extern const u8g_fntpgm_uint8_t u8g_font_4x6r[] U8G_FONT_SECTION("u8g_font_4x6r"); +//extern const u8g_fntpgm_uint8_t u8g_font_4x6n[] U8G_FONT_SECTION("u8g_font_4x6n"); +extern const u8g_fntpgm_uint8_t u8g_font_5x7[] U8G_FONT_SECTION("u8g_font_5x7"); +extern const u8g_fntpgm_uint8_t u8g_font_5x7r[] U8G_FONT_SECTION("u8g_font_5x7r"); +extern const u8g_fntpgm_uint8_t u8g_font_5x8[] U8G_FONT_SECTION("u8g_font_5x8"); +extern const u8g_fntpgm_uint8_t u8g_font_5x8r[] U8G_FONT_SECTION("u8g_font_5x8r"); +extern const u8g_fntpgm_uint8_t u8g_font_6x10[] U8G_FONT_SECTION("u8g_font_6x10"); +extern const u8g_fntpgm_uint8_t u8g_font_6x10r[] U8G_FONT_SECTION("u8g_font_6x10r"); +extern const u8g_fntpgm_uint8_t u8g_font_6x12_67_75[] U8G_FONT_SECTION("u8g_font_6x12_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_6x12_78_79[] U8G_FONT_SECTION("u8g_font_6x12_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_6x12[] U8G_FONT_SECTION("u8g_font_6x12"); +extern const u8g_fntpgm_uint8_t u8g_font_6x12r[] U8G_FONT_SECTION("u8g_font_6x12r"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13_67_75[] U8G_FONT_SECTION("u8g_font_6x13_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13_78_79[] U8G_FONT_SECTION("u8g_font_6x13_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13B[] U8G_FONT_SECTION("u8g_font_6x13B"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13Br[] U8G_FONT_SECTION("u8g_font_6x13Br"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13[] U8G_FONT_SECTION("u8g_font_6x13"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13r[] U8G_FONT_SECTION("u8g_font_6x13r"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13O[] U8G_FONT_SECTION("u8g_font_6x13O"); +extern const u8g_fntpgm_uint8_t u8g_font_6x13Or[] U8G_FONT_SECTION("u8g_font_6x13Or"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13_67_75[] U8G_FONT_SECTION("u8g_font_7x13_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13_78_79[] U8G_FONT_SECTION("u8g_font_7x13_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13B[] U8G_FONT_SECTION("u8g_font_7x13B"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13Br[] U8G_FONT_SECTION("u8g_font_7x13Br"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13[] U8G_FONT_SECTION("u8g_font_7x13"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13r[] U8G_FONT_SECTION("u8g_font_7x13r"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13O[] U8G_FONT_SECTION("u8g_font_7x13O"); +extern const u8g_fntpgm_uint8_t u8g_font_7x13Or[] U8G_FONT_SECTION("u8g_font_7x13Or"); +extern const u8g_fntpgm_uint8_t u8g_font_7x14B[] U8G_FONT_SECTION("u8g_font_7x14B"); +extern const u8g_fntpgm_uint8_t u8g_font_7x14Br[] U8G_FONT_SECTION("u8g_font_7x14Br"); +extern const u8g_fntpgm_uint8_t u8g_font_7x14[] U8G_FONT_SECTION("u8g_font_7x14"); +extern const u8g_fntpgm_uint8_t u8g_font_7x14r[] U8G_FONT_SECTION("u8g_font_7x14r"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13_67_75[] U8G_FONT_SECTION("u8g_font_8x13_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13B[] U8G_FONT_SECTION("u8g_font_8x13B"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13Br[] U8G_FONT_SECTION("u8g_font_8x13Br"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13[] U8G_FONT_SECTION("u8g_font_8x13"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13r[] U8G_FONT_SECTION("u8g_font_8x13r"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13O[] U8G_FONT_SECTION("u8g_font_8x13O"); +extern const u8g_fntpgm_uint8_t u8g_font_8x13Or[] U8G_FONT_SECTION("u8g_font_8x13Or"); + +extern const u8g_fntpgm_uint8_t u8g_font_9x15_67_75[] U8G_FONT_SECTION("u8g_font_9x15_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15_78_79[] U8G_FONT_SECTION("u8g_font_9x15_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15B[] U8G_FONT_SECTION("u8g_font_9x15B"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15Br[] U8G_FONT_SECTION("u8g_font_9x15Br"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15[] U8G_FONT_SECTION("u8g_font_9x15"); +extern const u8g_fntpgm_uint8_t u8g_font_9x15r[] U8G_FONT_SECTION("u8g_font_9x15r"); + +extern const u8g_fntpgm_uint8_t u8g_font_9x18_67_75[] U8G_FONT_SECTION("u8g_font_9x18_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18_78_79[] U8G_FONT_SECTION("u8g_font_9x18_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18B[] U8G_FONT_SECTION("u8g_font_9x18B"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18[] U8G_FONT_SECTION("u8g_font_9x18"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18Br[] U8G_FONT_SECTION("u8g_font_9x18Br"); +extern const u8g_fntpgm_uint8_t u8g_font_9x18r[] U8G_FONT_SECTION("u8g_font_9x18r"); + +extern const u8g_fntpgm_uint8_t u8g_font_cursor[] U8G_FONT_SECTION("u8g_font_cursor"); +extern const u8g_fntpgm_uint8_t u8g_font_cursorr[] U8G_FONT_SECTION("u8g_font_cursorr"); +extern const u8g_fntpgm_uint8_t u8g_font_micro[] U8G_FONT_SECTION("u8g_font_micro"); + +extern const u8g_fntpgm_uint8_t u8g_font_cu12_67_75[] U8G_FONT_SECTION("u8g_font_cu12_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_cu12_78_79[] U8G_FONT_SECTION("u8g_font_cu12_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_cu12[] U8G_FONT_SECTION("u8g_font_cu12"); + +/* + Free-Universal Bold + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_fub11[] U8G_FONT_SECTION("u8g_font_fub11"); +extern const u8g_fntpgm_uint8_t u8g_font_fub11r[] U8G_FONT_SECTION("u8g_font_fub11r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub11n[] U8G_FONT_SECTION("u8g_font_fub11n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub14[] U8G_FONT_SECTION("u8g_font_fub14"); +extern const u8g_fntpgm_uint8_t u8g_font_fub14r[] U8G_FONT_SECTION("u8g_font_fub14r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub14n[] U8G_FONT_SECTION("u8g_font_fub14n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub17[] U8G_FONT_SECTION("u8g_font_fub17"); +extern const u8g_fntpgm_uint8_t u8g_font_fub17r[] U8G_FONT_SECTION("u8g_font_fub17r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub17n[] U8G_FONT_SECTION("u8g_font_fub17n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub20[] U8G_FONT_SECTION("u8g_font_fub20"); +extern const u8g_fntpgm_uint8_t u8g_font_fub20r[] U8G_FONT_SECTION("u8g_font_fub20r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub20n[] U8G_FONT_SECTION("u8g_font_fub20n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub25[] U8G_FONT_SECTION("u8g_font_fub25"); +extern const u8g_fntpgm_uint8_t u8g_font_fub25r[] U8G_FONT_SECTION("u8g_font_fub25r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub25n[] U8G_FONT_SECTION("u8g_font_fub25n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub30[] U8G_FONT_SECTION("u8g_font_fub30"); +extern const u8g_fntpgm_uint8_t u8g_font_fub30r[] U8G_FONT_SECTION("u8g_font_fub30r"); +extern const u8g_fntpgm_uint8_t u8g_font_fub30n[] U8G_FONT_SECTION("u8g_font_fub30n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub35n[] U8G_FONT_SECTION("u8g_font_fub35n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub42n[] U8G_FONT_SECTION("u8g_font_fub42n"); +extern const u8g_fntpgm_uint8_t u8g_font_fub49n[] U8G_FONT_SECTION("u8g_font_fub49n"); + +/* + Free-Universal Regular + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_fur11[] U8G_FONT_SECTION("u8g_font_fur11"); +extern const u8g_fntpgm_uint8_t u8g_font_fur11r[] U8G_FONT_SECTION("u8g_font_fur11r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur11n[] U8G_FONT_SECTION("u8g_font_fur11n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur14[] U8G_FONT_SECTION("u8g_font_fur14"); +extern const u8g_fntpgm_uint8_t u8g_font_fur14r[] U8G_FONT_SECTION("u8g_font_fur14r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur14n[] U8G_FONT_SECTION("u8g_font_fur14n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur17[] U8G_FONT_SECTION("u8g_font_fur17"); +extern const u8g_fntpgm_uint8_t u8g_font_fur17r[] U8G_FONT_SECTION("u8g_font_fur17r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur17n[] U8G_FONT_SECTION("u8g_font_fur17n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur20[] U8G_FONT_SECTION("u8g_font_fur20"); +extern const u8g_fntpgm_uint8_t u8g_font_fur20r[] U8G_FONT_SECTION("u8g_font_fur20r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur20n[] U8G_FONT_SECTION("u8g_font_fur20n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur25[] U8G_FONT_SECTION("u8g_font_fur25"); +extern const u8g_fntpgm_uint8_t u8g_font_fur25r[] U8G_FONT_SECTION("u8g_font_fur25r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur25n[] U8G_FONT_SECTION("u8g_font_fur25n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur30[] U8G_FONT_SECTION("u8g_font_fur30"); +extern const u8g_fntpgm_uint8_t u8g_font_fur30r[] U8G_FONT_SECTION("u8g_font_fur30r"); +extern const u8g_fntpgm_uint8_t u8g_font_fur30n[] U8G_FONT_SECTION("u8g_font_fur30n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur35n[] U8G_FONT_SECTION("u8g_font_fur35n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur42n[] U8G_FONT_SECTION("u8g_font_fur42n"); +extern const u8g_fntpgm_uint8_t u8g_font_fur49n[] U8G_FONT_SECTION("u8g_font_fur49n"); + +/* + Gentium Bold + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_gdb11[] U8G_FONT_SECTION("u8g_font_gdb11"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb12[] U8G_FONT_SECTION("u8g_font_gdb12"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb14[] U8G_FONT_SECTION("u8g_font_gdb14"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb17[] U8G_FONT_SECTION("u8g_font_gdb17"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb20[] U8G_FONT_SECTION("u8g_font_gdb20"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb25[] U8G_FONT_SECTION("u8g_font_gdb25"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb30[] U8G_FONT_SECTION("u8g_font_gdb30"); + +extern const u8g_fntpgm_uint8_t u8g_font_gdb11r[] U8G_FONT_SECTION("u8g_font_gdb11r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb12r[] U8G_FONT_SECTION("u8g_font_gdb12r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb14r[] U8G_FONT_SECTION("u8g_font_gdb14r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb17r[] U8G_FONT_SECTION("u8g_font_gdb17r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb20r[] U8G_FONT_SECTION("u8g_font_gdb20r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb25r[] U8G_FONT_SECTION("u8g_font_gdb25r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb30r[] U8G_FONT_SECTION("u8g_font_gdb30r"); + +extern const u8g_fntpgm_uint8_t u8g_font_gdb11n[] U8G_FONT_SECTION("u8g_font_gdb11n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb12n[] U8G_FONT_SECTION("u8g_font_gdb12n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb14n[] U8G_FONT_SECTION("u8g_font_gdb14n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb17n[] U8G_FONT_SECTION("u8g_font_gdb17n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb20n[] U8G_FONT_SECTION("u8g_font_gdb20n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb25n[] U8G_FONT_SECTION("u8g_font_gdb25n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdb30n[] U8G_FONT_SECTION("u8g_font_gdb30n"); + +/* + Gentium Regular + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_gdr9[] U8G_FONT_SECTION("u8g_font_gdr9"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr10[] U8G_FONT_SECTION("u8g_font_gdr10"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr11[] U8G_FONT_SECTION("u8g_font_gdr11"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr12[] U8G_FONT_SECTION("u8g_font_gdr12"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr14[] U8G_FONT_SECTION("u8g_font_gdr14"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr17[] U8G_FONT_SECTION("u8g_font_gdr17"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr20[] U8G_FONT_SECTION("u8g_font_gdr20"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr25[] U8G_FONT_SECTION("u8g_font_gdr25"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr30[] U8G_FONT_SECTION("u8g_font_gdr30"); + +extern const u8g_fntpgm_uint8_t u8g_font_gdr9r[] U8G_FONT_SECTION("u8g_font_gdr9r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr10r[] U8G_FONT_SECTION("u8g_font_gdr10r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr11r[] U8G_FONT_SECTION("u8g_font_gdr11r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr12r[] U8G_FONT_SECTION("u8g_font_gdr12r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr14r[] U8G_FONT_SECTION("u8g_font_gdr14r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr17r[] U8G_FONT_SECTION("u8g_font_gdr17r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr20r[] U8G_FONT_SECTION("u8g_font_gdr20r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr25r[] U8G_FONT_SECTION("u8g_font_gdr25r"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr30r[] U8G_FONT_SECTION("u8g_font_gdr30r"); + +extern const u8g_fntpgm_uint8_t u8g_font_gdr9n[] U8G_FONT_SECTION("u8g_font_gdr9n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr10n[] U8G_FONT_SECTION("u8g_font_gdr10n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr11n[] U8G_FONT_SECTION("u8g_font_gdr11n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr12n[] U8G_FONT_SECTION("u8g_font_gdr12n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr14n[] U8G_FONT_SECTION("u8g_font_gdr14n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr17n[] U8G_FONT_SECTION("u8g_font_gdr17n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr20n[] U8G_FONT_SECTION("u8g_font_gdr20n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr25n[] U8G_FONT_SECTION("u8g_font_gdr25n"); +extern const u8g_fntpgm_uint8_t u8g_font_gdr30n[] U8G_FONT_SECTION("u8g_font_gdr30n"); + +/* + Old-Standard Bold + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_osb18[] U8G_FONT_SECTION("u8g_font_osb18"); +extern const u8g_fntpgm_uint8_t u8g_font_osb21[] U8G_FONT_SECTION("u8g_font_osb21"); +extern const u8g_fntpgm_uint8_t u8g_font_osb26[] U8G_FONT_SECTION("u8g_font_osb26"); +extern const u8g_fntpgm_uint8_t u8g_font_osb29[] U8G_FONT_SECTION("u8g_font_osb29"); +extern const u8g_fntpgm_uint8_t u8g_font_osb35[] U8G_FONT_SECTION("u8g_font_osb35"); + +extern const u8g_fntpgm_uint8_t u8g_font_osb18r[] U8G_FONT_SECTION("u8g_font_osb18r"); +extern const u8g_fntpgm_uint8_t u8g_font_osb21r[] U8G_FONT_SECTION("u8g_font_osb21r"); +extern const u8g_fntpgm_uint8_t u8g_font_osb26r[] U8G_FONT_SECTION("u8g_font_osb26r"); +extern const u8g_fntpgm_uint8_t u8g_font_osb29r[] U8G_FONT_SECTION("u8g_font_osb29r"); +extern const u8g_fntpgm_uint8_t u8g_font_osb35r[] U8G_FONT_SECTION("u8g_font_osb35r"); + +extern const u8g_fntpgm_uint8_t u8g_font_osb18n[] U8G_FONT_SECTION("u8g_font_osb18n"); +extern const u8g_fntpgm_uint8_t u8g_font_osb21n[] U8G_FONT_SECTION("u8g_font_osb21n"); +extern const u8g_fntpgm_uint8_t u8g_font_osb26n[] U8G_FONT_SECTION("u8g_font_osb26n"); +extern const u8g_fntpgm_uint8_t u8g_font_osb29n[] U8G_FONT_SECTION("u8g_font_osb29n"); +extern const u8g_fntpgm_uint8_t u8g_font_osb35n[] U8G_FONT_SECTION("u8g_font_osb35n"); + +/* + Old-Standard Regular + r: Reduced char set (codes 32 - 128) + n: Numbers (codes 42 - 57) + no char: Full set (codes 32 - 255) +*/ + +extern const u8g_fntpgm_uint8_t u8g_font_osr18[] U8G_FONT_SECTION("u8g_font_osr18"); +extern const u8g_fntpgm_uint8_t u8g_font_osr21[] U8G_FONT_SECTION("u8g_font_osr21"); +extern const u8g_fntpgm_uint8_t u8g_font_osr26[] U8G_FONT_SECTION("u8g_font_osr26"); +extern const u8g_fntpgm_uint8_t u8g_font_osr29[] U8G_FONT_SECTION("u8g_font_osr29"); +extern const u8g_fntpgm_uint8_t u8g_font_osr35[] U8G_FONT_SECTION("u8g_font_osr35"); + +extern const u8g_fntpgm_uint8_t u8g_font_osr18r[] U8G_FONT_SECTION("u8g_font_osr18r"); +extern const u8g_fntpgm_uint8_t u8g_font_osr21r[] U8G_FONT_SECTION("u8g_font_osr21r"); +extern const u8g_fntpgm_uint8_t u8g_font_osr26r[] U8G_FONT_SECTION("u8g_font_osr26r"); +extern const u8g_fntpgm_uint8_t u8g_font_osr29r[] U8G_FONT_SECTION("u8g_font_osr29r"); +extern const u8g_fntpgm_uint8_t u8g_font_osr35r[] U8G_FONT_SECTION("u8g_font_osr35r"); + +extern const u8g_fntpgm_uint8_t u8g_font_osr18n[] U8G_FONT_SECTION("u8g_font_osr18n"); +extern const u8g_fntpgm_uint8_t u8g_font_osr21n[] U8G_FONT_SECTION("u8g_font_osr21n"); +extern const u8g_fntpgm_uint8_t u8g_font_osr26n[] U8G_FONT_SECTION("u8g_font_osr26n"); +extern const u8g_fntpgm_uint8_t u8g_font_osr29n[] U8G_FONT_SECTION("u8g_font_osr29n"); +extern const u8g_fntpgm_uint8_t u8g_font_osr35n[] U8G_FONT_SECTION("u8g_font_osr35n"); + +//extern const u8g_fntpgm_uint8_t u8g_font_osr41[] U8G_FONT_SECTION("u8g_font_osr41"); + +/* GNU unifont */ + +extern const u8g_fntpgm_uint8_t u8g_font_unifont_18_19[] U8G_FONT_SECTION("u8g_font_unifont_18_19"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_72_73[] U8G_FONT_SECTION("u8g_font_unifont_72_73"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_67_75[] U8G_FONT_SECTION("u8g_font_unifont_67_75"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_76[] U8G_FONT_SECTION("u8g_font_unifont_76"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_77[] U8G_FONT_SECTION("u8g_font_unifont_77"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_78_79[] U8G_FONT_SECTION("u8g_font_unifont_78_79"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_86[] U8G_FONT_SECTION("u8g_font_unifont_86"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont[] U8G_FONT_SECTION("u8g_font_unifont"); +extern const u8g_fntpgm_uint8_t u8g_font_unifontr[] U8G_FONT_SECTION("u8g_font_unifontr"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_0_8[] U8G_FONT_SECTION("u8g_font_unifont_0_8"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_2_3[] U8G_FONT_SECTION("u8g_font_unifont_2_3"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_4_5[] U8G_FONT_SECTION("u8g_font_unifont_4_5"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_8_9[] U8G_FONT_SECTION("u8g_font_unifont_8_9"); +extern const u8g_fntpgm_uint8_t u8g_font_unifont_12_13[] U8G_FONT_SECTION("u8g_font_unifont_12_13"); + + +/* 04b fonts */ + +extern const u8g_fntpgm_uint8_t u8g_font_04b_03b[] U8G_FONT_SECTION("u8g_font_04b_03b"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_03bn[] U8G_FONT_SECTION("u8g_font_04b_03bn"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_03br[] U8G_FONT_SECTION("u8g_font_04b_03br"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_03[] U8G_FONT_SECTION("u8g_font_04b_03"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_03n[] U8G_FONT_SECTION("u8g_font_04b_03n"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_03r[] U8G_FONT_SECTION("u8g_font_04b_03r"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_24[] U8G_FONT_SECTION("u8g_font_04b_24"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_24n[] U8G_FONT_SECTION("u8g_font_04b_24n"); +extern const u8g_fntpgm_uint8_t u8g_font_04b_24r[] U8G_FONT_SECTION("u8g_font_04b_24r"); + +/* orgdot fonts */ + +extern const u8g_fntpgm_uint8_t u8g_font_orgv01[] U8G_FONT_SECTION("u8g_font_orgv01"); +extern const u8g_fntpgm_uint8_t u8g_font_orgv01r[] U8G_FONT_SECTION("u8g_font_orgv01r"); +extern const u8g_fntpgm_uint8_t u8g_font_orgv01n[] U8G_FONT_SECTION("u8g_font_orgv01n"); + +extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0[] U8G_FONT_SECTION("u8g_font_fixed_v0"); +extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0r[] U8G_FONT_SECTION("u8g_font_fixed_v0r"); +extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0n[] U8G_FONT_SECTION("u8g_font_fixed_v0n"); + +extern const u8g_fntpgm_uint8_t u8g_font_tpssb[] U8G_FONT_SECTION("u8g_font_tpssb"); +extern const u8g_fntpgm_uint8_t u8g_font_tpssbr[] U8G_FONT_SECTION("u8g_font_tpssbr"); +extern const u8g_fntpgm_uint8_t u8g_font_tpssbn[] U8G_FONT_SECTION("u8g_font_tpssbn"); + +extern const u8g_fntpgm_uint8_t u8g_font_tpss[] U8G_FONT_SECTION("u8g_font_tpss"); +extern const u8g_fntpgm_uint8_t u8g_font_tpssr[] U8G_FONT_SECTION("u8g_font_tpssr"); +extern const u8g_fntpgm_uint8_t u8g_font_tpssn[] U8G_FONT_SECTION("u8g_font_tpssn"); + +/* contributed */ + +extern const u8g_fntpgm_uint8_t u8g_font_freedoomr25n[] U8G_FONT_SECTION("u8g_font_freedoomr25n"); +extern const u8g_fntpgm_uint8_t u8g_font_freedoomr10r[] U8G_FONT_SECTION("u8g_font_freedoomr10r"); + +/* adobe X11 */ +extern const u8g_fntpgm_uint8_t u8g_font_courB08[] U8G_FONT_SECTION("u8g_font_courB08"); +extern const u8g_fntpgm_uint8_t u8g_font_courB08r[] U8G_FONT_SECTION("u8g_font_courB08r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB10[] U8G_FONT_SECTION("u8g_font_courB10"); +extern const u8g_fntpgm_uint8_t u8g_font_courB10r[] U8G_FONT_SECTION("u8g_font_courB10r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB12[] U8G_FONT_SECTION("u8g_font_courB12"); +extern const u8g_fntpgm_uint8_t u8g_font_courB12r[] U8G_FONT_SECTION("u8g_font_courB12r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB14[] U8G_FONT_SECTION("u8g_font_courB14"); +extern const u8g_fntpgm_uint8_t u8g_font_courB14r[] U8G_FONT_SECTION("u8g_font_courB14r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB18[] U8G_FONT_SECTION("u8g_font_courB18"); +extern const u8g_fntpgm_uint8_t u8g_font_courB18r[] U8G_FONT_SECTION("u8g_font_courB18r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB24[] U8G_FONT_SECTION("u8g_font_courB24"); +extern const u8g_fntpgm_uint8_t u8g_font_courB24r[] U8G_FONT_SECTION("u8g_font_courB24r"); +extern const u8g_fntpgm_uint8_t u8g_font_courB24n[] U8G_FONT_SECTION("u8g_font_courB24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_courR08[] U8G_FONT_SECTION("u8g_font_courR08"); +extern const u8g_fntpgm_uint8_t u8g_font_courR08r[] U8G_FONT_SECTION("u8g_font_courR08r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR10[] U8G_FONT_SECTION("u8g_font_courR10"); +extern const u8g_fntpgm_uint8_t u8g_font_courR10r[] U8G_FONT_SECTION("u8g_font_courR10r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR12[] U8G_FONT_SECTION("u8g_font_courR12"); +extern const u8g_fntpgm_uint8_t u8g_font_courR12r[] U8G_FONT_SECTION("u8g_font_courR12r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR14[] U8G_FONT_SECTION("u8g_font_courR14"); +extern const u8g_fntpgm_uint8_t u8g_font_courR14r[] U8G_FONT_SECTION("u8g_font_courR14r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR18[] U8G_FONT_SECTION("u8g_font_courR18"); +extern const u8g_fntpgm_uint8_t u8g_font_courR18r[] U8G_FONT_SECTION("u8g_font_courR18r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR24[] U8G_FONT_SECTION("u8g_font_courR24"); +extern const u8g_fntpgm_uint8_t u8g_font_courR24r[] U8G_FONT_SECTION("u8g_font_courR24r"); +extern const u8g_fntpgm_uint8_t u8g_font_courR24n[] U8G_FONT_SECTION("u8g_font_courR24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_helvB08[] U8G_FONT_SECTION("u8g_font_helvB08"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB08r[] U8G_FONT_SECTION("u8g_font_helvB08r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB08n[] U8G_FONT_SECTION("u8g_font_helvB08n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB10[] U8G_FONT_SECTION("u8g_font_helvB10"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB10r[] U8G_FONT_SECTION("u8g_font_helvB10r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB10n[] U8G_FONT_SECTION("u8g_font_helvB10n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB12[] U8G_FONT_SECTION("u8g_font_helvB12"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB12r[] U8G_FONT_SECTION("u8g_font_helvB12r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB12n[] U8G_FONT_SECTION("u8g_font_helvB12n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB14[] U8G_FONT_SECTION("u8g_font_helvB14"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB14r[] U8G_FONT_SECTION("u8g_font_helvB14r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB14n[] U8G_FONT_SECTION("u8g_font_helvB14n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB18[] U8G_FONT_SECTION("u8g_font_helvB18"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB18r[] U8G_FONT_SECTION("u8g_font_helvB18r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB18n[] U8G_FONT_SECTION("u8g_font_helvB18n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB24[] U8G_FONT_SECTION("u8g_font_helvB24"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB24r[] U8G_FONT_SECTION("u8g_font_helvB24r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvB24n[] U8G_FONT_SECTION("u8g_font_helvB24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_helvR08[] U8G_FONT_SECTION("u8g_font_helvR08"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR08r[] U8G_FONT_SECTION("u8g_font_helvR08r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR08n[] U8G_FONT_SECTION("u8g_font_helvR08n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR10[] U8G_FONT_SECTION("u8g_font_helvR10"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR10r[] U8G_FONT_SECTION("u8g_font_helvR10r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR10n[] U8G_FONT_SECTION("u8g_font_helvR10n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR12[] U8G_FONT_SECTION("u8g_font_helvR12"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR12r[] U8G_FONT_SECTION("u8g_font_helvR12r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR12n[] U8G_FONT_SECTION("u8g_font_helvR12n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR14[] U8G_FONT_SECTION("u8g_font_helvR14"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR14r[] U8G_FONT_SECTION("u8g_font_helvR14r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR14n[] U8G_FONT_SECTION("u8g_font_helvR14n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR18[] U8G_FONT_SECTION("u8g_font_helvR18"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR18r[] U8G_FONT_SECTION("u8g_font_helvR18r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR18n[] U8G_FONT_SECTION("u8g_font_helvR18n"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR24[] U8G_FONT_SECTION("u8g_font_helvR24"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR24r[] U8G_FONT_SECTION("u8g_font_helvR24r"); +extern const u8g_fntpgm_uint8_t u8g_font_helvR24n[] U8G_FONT_SECTION("u8g_font_helvR24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_ncenB08[] U8G_FONT_SECTION("u8g_font_ncenB08"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB08r[] U8G_FONT_SECTION("u8g_font_ncenB08r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB10[] U8G_FONT_SECTION("u8g_font_ncenB10"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB10r[] U8G_FONT_SECTION("u8g_font_ncenB10r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB12[] U8G_FONT_SECTION("u8g_font_ncenB12"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB12r[] U8G_FONT_SECTION("u8g_font_ncenB12r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB14[] U8G_FONT_SECTION("u8g_font_ncenB14"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB14r[] U8G_FONT_SECTION("u8g_font_ncenB14r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB18[] U8G_FONT_SECTION("u8g_font_ncenB18"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB18r[] U8G_FONT_SECTION("u8g_font_ncenB18r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB24[] U8G_FONT_SECTION("u8g_font_ncenB24"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB24r[] U8G_FONT_SECTION("u8g_font_ncenB24r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenB24n[] U8G_FONT_SECTION("u8g_font_ncenB24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_ncenR08[] U8G_FONT_SECTION("u8g_font_ncenR08"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR08r[] U8G_FONT_SECTION("u8g_font_ncenR08r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR10[] U8G_FONT_SECTION("u8g_font_ncenR10"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR10r[] U8G_FONT_SECTION("u8g_font_ncenR10r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR12[] U8G_FONT_SECTION("u8g_font_ncenR12"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR12r[] U8G_FONT_SECTION("u8g_font_ncenR12r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR14[] U8G_FONT_SECTION("u8g_font_ncenR14"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR14r[] U8G_FONT_SECTION("u8g_font_ncenR14r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR18[] U8G_FONT_SECTION("u8g_font_ncenR18"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR18r[] U8G_FONT_SECTION("u8g_font_ncenR18r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR24[] U8G_FONT_SECTION("u8g_font_ncenR24"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR24r[] U8G_FONT_SECTION("u8g_font_ncenR24r"); +extern const u8g_fntpgm_uint8_t u8g_font_ncenR24n[] U8G_FONT_SECTION("u8g_font_ncenR24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_symb08[] U8G_FONT_SECTION("u8g_font_symb08"); +extern const u8g_fntpgm_uint8_t u8g_font_symb08r[] U8G_FONT_SECTION("u8g_font_symb08r"); +extern const u8g_fntpgm_uint8_t u8g_font_symb10[] U8G_FONT_SECTION("u8g_font_symb10"); +extern const u8g_fntpgm_uint8_t u8g_font_symb10r[] U8G_FONT_SECTION("u8g_font_symb10r"); +extern const u8g_fntpgm_uint8_t u8g_font_symb12[] U8G_FONT_SECTION("u8g_font_symb12"); +extern const u8g_fntpgm_uint8_t u8g_font_symb12r[] U8G_FONT_SECTION("u8g_font_symb12r"); +extern const u8g_fntpgm_uint8_t u8g_font_symb14[] U8G_FONT_SECTION("u8g_font_symb14"); +extern const u8g_fntpgm_uint8_t u8g_font_symb14r[] U8G_FONT_SECTION("u8g_font_symb14r"); +extern const u8g_fntpgm_uint8_t u8g_font_symb18[] U8G_FONT_SECTION("u8g_font_symb18"); +extern const u8g_fntpgm_uint8_t u8g_font_symb18r[] U8G_FONT_SECTION("u8g_font_symb18r"); +extern const u8g_fntpgm_uint8_t u8g_font_symb24[] U8G_FONT_SECTION("u8g_font_symb24"); +extern const u8g_fntpgm_uint8_t u8g_font_symb24r[] U8G_FONT_SECTION("u8g_font_symb24r"); + +extern const u8g_fntpgm_uint8_t u8g_font_timB08[] U8G_FONT_SECTION("u8g_font_timB08"); +extern const u8g_fntpgm_uint8_t u8g_font_timB08r[] U8G_FONT_SECTION("u8g_font_timB08r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB10[] U8G_FONT_SECTION("u8g_font_timB10"); +extern const u8g_fntpgm_uint8_t u8g_font_timB10r[] U8G_FONT_SECTION("u8g_font_timB10r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB12[] U8G_FONT_SECTION("u8g_font_timB12"); +extern const u8g_fntpgm_uint8_t u8g_font_timB12r[] U8G_FONT_SECTION("u8g_font_timB12r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB14[] U8G_FONT_SECTION("u8g_font_timB14"); +extern const u8g_fntpgm_uint8_t u8g_font_timB14r[] U8G_FONT_SECTION("u8g_font_timB14r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB18[] U8G_FONT_SECTION("u8g_font_timB18"); +extern const u8g_fntpgm_uint8_t u8g_font_timB18r[] U8G_FONT_SECTION("u8g_font_timB18r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB24[] U8G_FONT_SECTION("u8g_font_timB24"); +extern const u8g_fntpgm_uint8_t u8g_font_timB24r[] U8G_FONT_SECTION("u8g_font_timB24r"); +extern const u8g_fntpgm_uint8_t u8g_font_timB24n[] U8G_FONT_SECTION("u8g_font_timB24n"); + +extern const u8g_fntpgm_uint8_t u8g_font_timR08[] U8G_FONT_SECTION("u8g_font_timR08"); +extern const u8g_fntpgm_uint8_t u8g_font_timR08r[] U8G_FONT_SECTION("u8g_font_timR08r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR10[] U8G_FONT_SECTION("u8g_font_timR10"); +extern const u8g_fntpgm_uint8_t u8g_font_timR10r[] U8G_FONT_SECTION("u8g_font_timR10r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR12[] U8G_FONT_SECTION("u8g_font_timR12"); +extern const u8g_fntpgm_uint8_t u8g_font_timR12r[] U8G_FONT_SECTION("u8g_font_timR12r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR14[] U8G_FONT_SECTION("u8g_font_timR14"); +extern const u8g_fntpgm_uint8_t u8g_font_timR14r[] U8G_FONT_SECTION("u8g_font_timR14r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR18[] U8G_FONT_SECTION("u8g_font_timR18"); +extern const u8g_fntpgm_uint8_t u8g_font_timR18r[] U8G_FONT_SECTION("u8g_font_timR18r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR24[] U8G_FONT_SECTION("u8g_font_timR24"); +extern const u8g_fntpgm_uint8_t u8g_font_timR24r[] U8G_FONT_SECTION("u8g_font_timR24r"); +extern const u8g_fntpgm_uint8_t u8g_font_timR24n[] U8G_FONT_SECTION("u8g_font_timR24n"); + +/* fontstruct */ + +extern const u8g_fntpgm_uint8_t u8g_font_p01type[] U8G_FONT_SECTION("u8g_font_p01type"); +extern const u8g_fntpgm_uint8_t u8g_font_p01typer[] U8G_FONT_SECTION("u8g_font_p01typer"); +extern const u8g_fntpgm_uint8_t u8g_font_p01typen[] U8G_FONT_SECTION("u8g_font_p01typen"); + +extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternate[] U8G_FONT_SECTION("u8g_font_lucasfont_alternate"); +extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternater[] U8G_FONT_SECTION("u8g_font_lucasfont_alternater"); +extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternaten[] U8G_FONT_SECTION("u8g_font_lucasfont_alternaten"); + +extern const u8g_fntpgm_uint8_t u8g_font_chikita[] U8G_FONT_SECTION("u8g_font_chikita"); +extern const u8g_fntpgm_uint8_t u8g_font_chikitar[] U8G_FONT_SECTION("u8g_font_chikitar"); +extern const u8g_fntpgm_uint8_t u8g_font_chikitan[] U8G_FONT_SECTION("u8g_font_chikitan"); + +extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micro[] U8G_FONT_SECTION("u8g_font_pixelle_micro"); +extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micror[] U8G_FONT_SECTION("u8g_font_pixelle_micror"); +extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micron[] U8G_FONT_SECTION("u8g_font_pixelle_micron"); + +extern const u8g_fntpgm_uint8_t u8g_font_trixel_square[] U8G_FONT_SECTION("u8g_font_trixel_square"); +extern const u8g_fntpgm_uint8_t u8g_font_trixel_squarer[] U8G_FONT_SECTION("u8g_font_trixel_squarer"); +extern const u8g_fntpgm_uint8_t u8g_font_trixel_squaren[] U8G_FONT_SECTION("u8g_font_trixel_squaren"); + +extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niro[] U8G_FONT_SECTION("u8g_font_robot_de_niro"); +extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niror[] U8G_FONT_SECTION("u8g_font_robot_de_niror"); +extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niron[] U8G_FONT_SECTION("u8g_font_robot_de_niron"); + +extern const u8g_fntpgm_uint8_t u8g_font_baby[] U8G_FONT_SECTION("u8g_font_baby"); +extern const u8g_fntpgm_uint8_t u8g_font_babyr[] U8G_FONT_SECTION("u8g_font_babyr"); +extern const u8g_fntpgm_uint8_t u8g_font_babyn[] U8G_FONT_SECTION("u8g_font_babyn"); + +extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07[] U8G_FONT_SECTION("u8g_font_blipfest_07"); +extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07r[] U8G_FONT_SECTION("u8g_font_blipfest_07r"); +extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07n[] U8G_FONT_SECTION("u8g_font_blipfest_07n"); + +/* profont */ + +extern const u8g_fntpgm_uint8_t u8g_font_profont10[] U8G_FONT_SECTION("u8g_font_profont10"); +extern const u8g_fntpgm_uint8_t u8g_font_profont10r[] U8G_FONT_SECTION("u8g_font_profont10r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont11[] U8G_FONT_SECTION("u8g_font_profont11"); +extern const u8g_fntpgm_uint8_t u8g_font_profont11r[] U8G_FONT_SECTION("u8g_font_profont11r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont12[] U8G_FONT_SECTION("u8g_font_profont12"); +extern const u8g_fntpgm_uint8_t u8g_font_profont12r[] U8G_FONT_SECTION("u8g_font_profont12r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont15[] U8G_FONT_SECTION("u8g_font_profont15"); +extern const u8g_fntpgm_uint8_t u8g_font_profont15r[] U8G_FONT_SECTION("u8g_font_profont15r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont17[] U8G_FONT_SECTION("u8g_font_profont17"); +extern const u8g_fntpgm_uint8_t u8g_font_profont17r[] U8G_FONT_SECTION("u8g_font_profont17r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont22[] U8G_FONT_SECTION("u8g_font_profont22"); +extern const u8g_fntpgm_uint8_t u8g_font_profont22r[] U8G_FONT_SECTION("u8g_font_profont22r"); +extern const u8g_fntpgm_uint8_t u8g_font_profont29[] U8G_FONT_SECTION("u8g_font_profont29"); +extern const u8g_fntpgm_uint8_t u8g_font_profont29r[] U8G_FONT_SECTION("u8g_font_profont29r"); + + +#ifdef __cplusplus +} +#endif + +#endif /* _U8G_H */ + diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g_com_embarc_ssd1306_spi.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g_com_embarc_ssd1306_spi.c new file mode 100644 index 00000000..22cbc591 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/u8glib/csrc/u8g_com_embarc_ssd1306_spi.c @@ -0,0 +1,275 @@ +/* + + u8g.h + + Universal 8bit Graphics Library + + Copyright (c) 2011, olikraus@gmail.com + 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. + + 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 HOLDER 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. + +*/ +/* + * Modified for port to ARC embARC platform + * by Wayne Ren wei.ren@synopsys.com, Synopsys, Inc. + */ + +#include "u8g.h" +#include "embARC.h" +#include "dev_gpio.h" +#include "ssd1306_app_config.h" + +#ifndef SSD1306_SPI_ID +#define SSD1306_SPI_ID 0 +#endif + +#ifndef SSD1306_SPI_CS +#define SSD1306_SPI_CS EMSK_SPI_LINE_1 +#endif + +#ifndef SSD1306_USE_CS_PIN + #define SSD1306_USE_CS_PIN 1 +#endif + +#if SSD1306_USE_CS_PIN +# ifndef SSD1306_CS_GPIO + #define SSD1306_CS_GPIO (DEV_GPIO_PORT_A) +# endif + +# ifndef SSD1306_CS_PIN + #define SSD1306_CS_PIN 24 +# endif +static void oled_ssd1306_chip_select(DEV_SPI* _oled_spi, bool select) +{ + static DEV_GPIO *oled_gpio_cs; + if(!oled_gpio_cs) { + oled_gpio_cs = gpio_get_dev(SSD1306_CS_GPIO); + if(oled_gpio_cs) { + oled_gpio_cs->gpio_open(1<gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(1<gpio_write(1<spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(SSD1306_SPI_CS)) == E_OK) { + oled_gpio_cs->gpio_write(0, 1<spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(SSD1306_SPI_CS)); + oled_gpio_cs->gpio_write(1<spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(SSD1306_SPI_CS)) == E_OK) { +#if defined(OS_FREERTOS) + taskENTER_CRITICAL(); +#endif + break; + } else { +#if defined(OS_FREERTOS) + vTaskDelay(0); +#else + Sleep(1); +#endif + } + } while(1); + } else { + _oled_spi->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(SSD1306_SPI_CS)); +#if defined(OS_FREERTOS) + taskEXIT_CRITICAL(); +#endif + } +} +#endif + +#ifndef SSD1306_SPI_FREQ +#define SSD1306_SPI_FREQ 250000ul +#endif + +/* Use RESET pin or not */ +#ifndef SSD1306_USE_RST_PIN + #define SSD1306_USE_RST_PIN 1 +#endif + +#ifndef SSD1306_CD_GPIO + #define SSD1306_CD_GPIO (DEV_GPIO_PORT_A) +#endif + +#ifndef SSD1306_CD_PIN + #define SSD1306_CD_PIN 26 +#endif + +#if SSD1306_USE_RST_PIN +# ifndef SSD1306_RST_GPIO + #define SSD1306_RST_GPIO (DEV_GPIO_PORT_A) +# endif + +# ifndef SSD1306_RST_PIN + #define SSD1306_RST_PIN 25 +# endif +static DEV_GPIO *oled_gpio; +static void oled_ssd1306_hw_reset(void) +{ + oled_gpio = gpio_get_dev(SSD1306_RST_GPIO); + if (oled_gpio) { + oled_gpio->gpio_open(1<gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(1<gpio_write(0, 1<gpio_write(1<gpio_write(1<gpio_write(0, 1<spi_write(buf, cnt); +} + +Inline int32_t oled_ssd1306_write_cmd(uint8_t cmd) +{ + return oled_ssd1306_write(&cmd, 1); +} + +Inline int32_t oled_ssd1306_write_data(uint8_t data) +{ + return oled_ssd1306_write(&data, 1); +} + +Inline int32_t oled_ssd1306_write_buf(uint8_t *buf, uint8_t cnt) +{ + return oled_ssd1306_write(buf, cnt); +} + +uint8_t u8g_com_embarc_ssd_spi_fn_sel(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr, int32_t devid) +{ + //uint8_t *ptr; + int32_t ercd; + + switch(msg) { + case U8G_COM_MSG_INIT: + OLED_HW_RESET(); + oled_ssd1306 = spi_get_dev(devid); + + oled_gpio_cd = gpio_get_dev(SSD1306_CD_GPIO); + if (oled_gpio_cd) { + oled_gpio_cd->gpio_open(1<gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(1<gpio_write(0, 1<spi_open(DEV_MASTER_MODE, oled_ssd1306_freq); + if ((ercd != E_OK) && (ercd != E_OPNED)) { + return 0; + } + oled_ssd1306->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CPOL_1_CPHA_1)); + //oled_ssd1306->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CPOL_0_CPHA_0)); + break; + + case U8G_COM_MSG_STOP: + break; + + case U8G_COM_MSG_RESET: +#if SSD1306_USE_RST_PIN + if(oled_gpio) { + if(arg_val) + oled_gpio->gpio_write(1<gpio_write(0, 1<dev_mem); + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start); + u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */ + u8g_SetAddress(u8g, dev, 1); /* data mode */ + if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) + return 0; + u8g_SetChipSelect(u8g, dev, 0); + } + break; + case U8G_DEV_MSG_SLEEP_ON: + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on); + return 1; + case U8G_DEV_MSG_SLEEP_OFF: + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off); + return 1; + } + return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); +} + + +uint8_t u8g_dev_ssd1306_128x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) +{ + switch(msg) + { + case U8G_DEV_MSG_INIT: + u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS); + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_emsk_init_seq); + break; + case U8G_DEV_MSG_STOP: + break; + case U8G_DEV_MSG_PAGE_NEXT: + { + u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start); + u8g_WriteByte(u8g, dev, 0x0b0 | (pb->p.page*2)); //select current page (SSD1306) + u8g_SetAddress(u8g, dev, 1); //data mode + u8g_WriteSequence(u8g, dev, pb->width, pb->buf); + u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width); + u8g_SetChipSelect(u8g, dev, 0); + } + break; + case U8G_DEV_MSG_SLEEP_ON: + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on); + return 1; + case U8G_DEV_MSG_SLEEP_OFF: + u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off); + return 1; + } + return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg); +} + +//U8G_PB_DEV(u8g_dev_ssd1306_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1306_128x64_fn, U8G_COM_SSD_I2C); + +uint8_t u8g_dev_ssd1306_128x64_2x_buf[WIDTH*2] U8G_NOCOMMON ; +u8g_pb_t u8g_dev_ssd1306_128x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x64_2x_buf}; +u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_I2C }; +u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi = { u8g_dev_ssd1306_128x64_2x_fn, &u8g_dev_ssd1306_128x64_2x_pb, U8G_COM_SSD_SPI }; + +u8g_pb_t u8g_dev_ssd1306_128x64_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1306_128x64_2x_buf}; +u8g_dev_t u8g_dev_ssd1306_128x64_hw_spi = { u8g_dev_ssd1306_128x64_fn, &u8g_dev_ssd1306_128x64_pb, U8G_COM_SSD_SPI }; \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/FreeRTOSConfig.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/FreeRTOSConfig.h new file mode 100644 index 00000000..10c38763 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/FreeRTOSConfig.h @@ -0,0 +1,114 @@ +/* + FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 10 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1024 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 20 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configUSE_COUNTING_SEMAPHORES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/LED_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/LED_task.h new file mode 100644 index 00000000..2fceeec1 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/LED_task.h @@ -0,0 +1,8 @@ +#ifndef LED_TASK_H +#define LED_TASK_H + +#include "stdint.h" + +void LED_task(void *p_arg); + +#endif \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/adt7420.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/adt7420.h new file mode 100644 index 00000000..b327e3ab --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/adt7420.h @@ -0,0 +1,94 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +/** + * \file + * \brief header file of adt7420 pmod temperature sensor driver + */ + +#ifndef _ADT7420_H_ +#define _ADT7420_H_ + +#include "dev_iic.h" + +/** + * I2C address of PmodTmp2 (ADT7420) can be selected via jumpers: 0x48, 0x49, 0x4A, 0x4B + * Default (all jumpers removed) is 0x4B + */ +#define ADT7420_A0_PIN 1 /*!< I2C Serial Bus Address Selection Pin */ +#define ADT7420_A1_PIN 1 /*!< I2C Serial Bus Address Selection Pin */ +#define ADT7420_IIC_ADDRESS (0x48 + (ADT7420_A1_PIN << 1) + ADT7420_A0_PIN) + +#define TEMP_I2C_SLAVE_ADDRESS ADT7420_IIC_ADDRESS + +#ifdef __cplusplus +extern "C" { +#endif + +/* options for mode parameter of temp_sensor_mode() */ +typedef enum { + ADT7420_OP_MODE_CONT_CONV = 0, + ADT7420_OP_MODE_ONE_SHOT = 1, + ADT7420_OP_MODE_1_SPS = 2, + ADT7420_OP_MODE_SHUTDOWN = 3 +} ADT7420_OP_MODE; + +/* options for resolution parameter of temp_sensor_resolution() */ +typedef enum { + ADT7420_RESOLUTION_13BIT, + ADT7420_RESOLUTION_16BIT +} ADT7420_RESOLUTION; + +/* temperature sensor object type*/ +typedef struct { + uint32_t i2c_id; + uint32_t slvaddr; + + int32_t resolution; + int32_t op_mode; +} ADT7420_DEF, *ADT7420_DEF_PTR; + +#define ADT7420_DEFINE(NAME, I2C_ID, SLAVE_ADDRESS) \ + ADT7420_DEF __ ## NAME = { \ + .i2c_id = I2C_ID, \ + .slvaddr = SLAVE_ADDRESS, \ + }; \ + ADT7420_DEF_PTR NAME = &__ ## NAME + +extern int32_t adt7420_sensor_init(ADT7420_DEF_PTR obj); +extern int32_t adt7420_sensor_deinit(ADT7420_DEF_PTR obj); +extern int32_t adt7420_sensor_mode(ADT7420_DEF_PTR obj, int32_t mode); +extern int32_t adt7420_sensor_resolution(ADT7420_DEF_PTR obj, int32_t resolution); +extern int32_t adt7420_sensor_read(ADT7420_DEF_PTR obj, float *val); + +#ifdef __cplusplus +} +#endif + +#endif /* _ADT7420_H_ */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/communication_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/communication_task.h new file mode 100644 index 00000000..69bd154f --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/communication_task.h @@ -0,0 +1,32 @@ +#ifndef COMMUNICATION_TASK_H +#define COMMUNICATION_TASK_H + +#include "stdint.h" + +void communication_task(void *p_arg); + +typedef struct _wifi_data +{ + int source_id; + int target_id; + + int status; + int target_item; + + char user[5]; + char type[4][7]; + char name[4][7]; + + data_union body[4]; + // number name type + // item 1: body[0].i name[0] type[0] + // item 2: body[1].i name[1] type[1] + // item 3: body[2].i name[2] type[2] + // item 4: body[3].i name[3] type[3] + // + // temp: body[0].f + // other integer data: body[0].i + +} WIFI_data; + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/dcmotor_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/dcmotor_task.h new file mode 100644 index 00000000..7417cced --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/dcmotor_task.h @@ -0,0 +1,8 @@ +#ifndef DCMOTOR_TASK_H +#define DCMOTOR_TASK_H + +#include "stdint.h" + +void dcmotor_task(void *p_arg); + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/lwipopts.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/lwipopts.h new file mode 100644 index 00000000..b42cf97b --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/lwipopts.h @@ -0,0 +1,455 @@ +/** + * @file + * + * lwIP Options Configuration + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_LWIPOPTS_H +#define LWIP_LWIPOPTS_H + +/* + ----------------------------------------------- + ---------- Platform specific locking ---------- + ----------------------------------------------- +*/ + +/** + * NO_SYS==1: Provides VERY minimal functionality. Otherwise, + * use lwIP facilities. + */ +#ifdef ENABLE_OS +#define NO_SYS 0 +#else +#define NO_SYS 1 +#endif + + +/* + ------------------------------------ + ---------- Memory options ---------- + ------------------------------------ +*/ +/** + * MEM_ALIGNMENT: should be set to the alignment of the CPU + * 4 byte alignment -> #define MEM_ALIGNMENT 4 + * 2 byte alignment -> #define MEM_ALIGNMENT 2 + */ +#define MEM_ALIGNMENT 4 + +/** + * MEM_SIZE: the size of the heap memory. If the application will send + * a lot of data that needs to be copied, this should be set high. + */ +#define MEM_SIZE (8*1024) + + +/* + ------------------------------------------------ + ---------- Internal Memory Pool Sizes ---------- + ------------------------------------------------ +*/ +/** + * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). + * If the application sends a lot of data out of ROM (or other static memory), + * this should be set high. + */ +#define MEMP_NUM_PBUF 30 + +/** + * MEMP_NUM_RAW_PCB: Number of raw connection PCBs + * (requires the LWIP_RAW option) + */ +#define MEMP_NUM_RAW_PCB 4 + +/** + * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + * per active UDP "connection". + * (requires the LWIP_UDP option) + */ +#define MEMP_NUM_UDP_PCB 4 + +/** + * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. + * (requires the LWIP_TCP option) + */ +#define MEMP_NUM_TCP_PCB 5 + +/** + * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. + * (requires the LWIP_TCP option) + */ +#define MEMP_NUM_TCP_PCB_LISTEN 8 + +/** + * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. + * (requires the LWIP_TCP option) + */ +#define MEMP_NUM_TCP_SEG 16 + +/** + * MEMP_NUM_ARP_QUEUE: the number of simulateously queued outgoing + * packets (pbufs) that are waiting for an ARP request (to resolve + * their destination address) to finish. + * (requires the ARP_QUEUEING option) + */ +#define MEMP_NUM_ARP_QUEUE 2 + +/** + * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. + */ +#define MEMP_NUM_SYS_TIMEOUT 20 + +/** + * MEMP_NUM_NETBUF: the number of struct netbufs. + * (only needed if you use the sequential API, like api_lib.c) + */ +#define MEMP_NUM_NETBUF 2 + +/** + * MEMP_NUM_NETCONN: the number of struct netconns. + * (only needed if you use the sequential API, like api_lib.c) + */ +#define MEMP_NUM_NETCONN 10 + +/** + * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used + * for callback/timeout API communication. + * (only needed if you use tcpip.c) + */ +#define MEMP_NUM_TCPIP_MSG_API 16 + +/** + * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used + * for incoming packets. + * (only needed if you use tcpip.c) + */ +#define MEMP_NUM_TCPIP_MSG_INPKT 16 + +/** + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + */ +#define PBUF_POOL_SIZE 120 + +/* + --------------------------------- + ---------- ARP options ---------- + --------------------------------- +*/ +/** + * LWIP_ARP==1: Enable ARP functionality. + */ +#define LWIP_ARP 1 + +/* + -------------------------------- + ---------- IP options ---------- + -------------------------------- +*/ +/** + * IP_FORWARD==1: Enables the ability to forward IP packets across network + * interfaces. If you are going to run lwIP on a device with only one network + * interface, define this to 0. + */ +#define IP_FORWARD 0 + +/** + * IP_OPTIONS: Defines the behavior for IP options. + * IP_OPTIONS==0_ALLOWED: All packets with IP options are dropped. + * IP_OPTIONS==1_ALLOWED: IP options are allowed (but not parsed). + */ +#define IP_OPTIONS_ALLOWED 1 + +/** + * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that + * this option does not affect outgoing packet sizes, which can be controlled + * via IP_FRAG. + */ +#define IP_REASSEMBLY 1 + +/** + * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note + * that this option does not affect incoming packet sizes, which can be + * controlled via IP_REASSEMBLY. + */ +#define IP_FRAG 1 + +/** + * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) + * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived + * in this time, the whole packet is discarded. + */ +#define IP_REASS_MAXAGE 3 + +/** + * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. + * Since the received pbufs are enqueued, be sure to configure + * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive + * packets even if the maximum amount of fragments is enqueued for reassembly! + */ +#define IP_REASS_MAX_PBUFS 10 + +/** + * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP + * fragmentation. Otherwise pbufs are allocated and reference the original + * packet data to be fragmented. + */ +#define IP_FRAG_USES_STATIC_BUF 0 + +/** + * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. + */ +#define IP_DEFAULT_TTL 255 + +/* + ---------------------------------- + ---------- ICMP options ---------- + ---------------------------------- +*/ +/** + * LWIP_ICMP==1: Enable ICMP module inside the IP stack. + * Be careful, disable that make your product non-compliant to RFC1122 + */ +#define LWIP_ICMP 1 + +/** + * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. + */ +#define ICMP_TTL (IP_DEFAULT_TTL) + +/* + --------------------------------- + ---------- RAW options ---------- + --------------------------------- +*/ +/** + * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. + */ +#define LWIP_RAW 1 + +/* + ---------------------------------- + ---------- DHCP options ---------- + ---------------------------------- +*/ +/** + * LWIP_DHCP==1: Enable DHCP module. + */ +#define LWIP_DHCP 1 + +/* + ------------------------------------ + ---------- AUTOIP options ---------- + ------------------------------------ +*/ +/** + * LWIP_AUTOIP==1: Enable AUTOIP module. + */ +#define LWIP_AUTOIP 0 + +/* + ---------------------------------- + ---------- SNMP options ---------- + ---------------------------------- +*/ +/** + * LWIP_SNMP==1: Turn on SNMP module. UDP must be available for SNMP + * transport. + */ +#define LWIP_SNMP 0 +#define SNMP_PRIVATE_MIB 0 + +/* + ---------------------------------- + ---------- IGMP options ---------- + ---------------------------------- +*/ +/** + * LWIP_IGMP==1: Turn on IGMP module. + */ +#define LWIP_IGMP 0 + +/* + ---------------------------------- + ---------- DNS options ----------- + ---------------------------------- +*/ +/** + * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS + * transport. + */ +#define LWIP_DNS 1 + +/* + --------------------------------- + ---------- UDP options ---------- + --------------------------------- +*/ +/** + * LWIP_UDP==1: Turn on UDP. + */ +#define LWIP_UDP 1 + +/** + * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) + */ +#define LWIP_UDPLITE 0 + +/** + * UDP_TTL: Default Time-To-Live value. + */ +#define UDP_TTL (IP_DEFAULT_TTL) + +/* + --------------------------------- + ---------- TCP options ---------- + --------------------------------- +*/ +/** + * LWIP_TCP==1: Turn on TCP. + */ +#define LWIP_TCP 1 +/* MBox sizes cannot be zer, which is their default. */ +#define TCPIP_MBOX_SIZE 10 + +#define DEFAULT_RAW_RECVMBOX_SIZE 5 + +#define DEFAULT_UDP_RECVMBOX_SIZE 5 +#define DEFAULT_TCP_RECVMBOX_SIZE 5 + +#define DEFAULT_ACCEPTMBOX_SIZE 5 +/* + ---------------------------------- + ---------- Pbuf options ---------- + ---------------------------------- +*/ +/** + * PBUF_LINK_HLEN: the number of bytes that should be allocated for a + * link level header. The default is 14, the standard value for + * Ethernet. + */ +#define PBUF_LINK_HLEN 16 + +/* + ------------------------------------ + ---------- LOOPIF options ---------- + ------------------------------------ +*/ +/** + * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c + */ +#define LWIP_HAVE_LOOPIF 0 + + +/* + ---------------------------------------------- + ---------- Sequential layer options ---------- + ---------------------------------------------- +*/ + +/** + * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) + */ +#define LWIP_NETCONN 1 +#define LWIP_SO_SNDTIMEO 1 +#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_SNDRCVTIMEO_NONSTANDARD 1 + +#define SO_REUSE 1 +#define SO_REUSE_RXTOALL 1 +/* + ------------------------------------ + ---------- Socket options ---------- + ------------------------------------ +*/ +/** + * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) + */ +#define LWIP_SOCKET 1 + +/* + ---------------------------------------- + ---------- Statistics options ---------- + ---------------------------------------- +*/ +/** + * LWIP_STATS==1: Enable statistics collection in lwip_stats. + */ +#define LWIP_STATS 0 + +#define TCPIP_THREAD_PRIO 3 // Relatively low priority + +#define DEFAULT_THREAD_PRIO 2 + +#define TCPIP_THREAD_STACKSIZE 512 +#define DEFAULT_THREAD_STACKSIZE 512 + +#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("8.8.8.8"))) + +/* Misc */ + +#define LWIP_DEBUG +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define PPP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF +#define HTTPD_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF + +#define LWIP_NETIF_STATUS_CALLBACK 1 + +#endif /* LWIP_LWIPOPTS_H */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/mbedtls_config.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/mbedtls_config.h new file mode 100644 index 00000000..d768e135 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/mbedtls_config.h @@ -0,0 +1,2495 @@ +/** + * \file config.h + * + * \brief Configuration options (set of defines) + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +/* + * This set of compile-time options may be used to enable + * or disable features selectively, and reduce the global + * memory footprint. + */ +#ifndef MBEDTLS_CONFIG_H +#define MBEDTLS_CONFIG_H + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif + +/** + * \name SECTION: System support + * + * This section sets system specific settings. + * \{ + */ + +/** + * \def MBEDTLS_HAVE_ASM + * + * The compiler has support for asm(). + * + * Requires support for asm() in compiler. + * + * Used in: + * library/timing.c + * library/padlock.c + * include/mbedtls/bn_mul.h + * + * Comment to disable the use of assembly code. + */ +//#define MBEDTLS_HAVE_ASM + +/** + * \def MBEDTLS_HAVE_SSE2 + * + * CPU supports SSE2 instruction set. + * + * Uncomment if the CPU supports SSE2 (IA-32 specific). + */ +//#define MBEDTLS_HAVE_SSE2 + +/** + * \def MBEDTLS_HAVE_TIME + * + * System has time.h and time(). + * The time does not need to be correct, only time differences are used, + * by contrast with MBEDTLS_HAVE_TIME_DATE + * + * Comment if your system does not support time functions + */ +#define MBEDTLS_HAVE_TIME + +/** + * \def MBEDTLS_HAVE_TIME_DATE + * + * System has time.h and time(), gmtime() and the clock is correct. + * The time needs to be correct (not necesarily very accurate, but at least + * the date should be correct). This is used to verify the validity period of + * X.509 certificates. + * + * Comment if your system does not have a correct clock. + */ +#define MBEDTLS_HAVE_TIME_DATE + +/** + * \def MBEDTLS_PLATFORM_MEMORY + * + * Enable the memory allocation layer. + * + * By default mbed TLS uses the system-provided calloc() and free(). + * This allows different allocators (self-implemented or provided) to be + * provided to the platform abstraction layer. + * + * Enabling MBEDTLS_PLATFORM_MEMORY without the + * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide + * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and + * free() function pointer at runtime. + * + * Enabling MBEDTLS_PLATFORM_MEMORY and specifying + * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the + * alternate function at compile time. + * + * Requires: MBEDTLS_PLATFORM_C + * + * Enable this layer to allow use of alternative memory allocators. + */ +//#define MBEDTLS_PLATFORM_MEMORY + +/** + * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS + * + * Do not assign standard functions in the platform layer (e.g. calloc() to + * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF) + * + * This makes sure there are no linking errors on platforms that do not support + * these functions. You will HAVE to provide alternatives, either at runtime + * via the platform_set_xxx() functions or at compile time by setting + * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a + * MBEDTLS_PLATFORM_XXX_MACRO. + * + * Requires: MBEDTLS_PLATFORM_C + * + * Uncomment to prevent default assignment of standard functions in the + * platform layer. + */ +//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS + +/** + * \def MBEDTLS_PLATFORM_XXX_ALT + * + * Uncomment a macro to let mbed TLS support the function in the platform + * abstraction layer. + * + * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will + * provide a function "mbedtls_platform_set_printf()" that allows you to set an + * alternative printf function pointer. + * + * All these define require MBEDTLS_PLATFORM_C to be defined! + * + * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows; + * it will be enabled automatically by check_config.h + * + * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as + * MBEDTLS_PLATFORM_XXX_MACRO! + * + * Uncomment a macro to enable alternate implementation of specific base + * platform function + */ +//#define MBEDTLS_PLATFORM_EXIT_ALT +//#define MBEDTLS_PLATFORM_FPRINTF_ALT +//#define MBEDTLS_PLATFORM_PRINTF_ALT +//#define MBEDTLS_PLATFORM_SNPRINTF_ALT + +/** + * \def MBEDTLS_DEPRECATED_WARNING + * + * Mark deprecated functions so that they generate a warning if used. + * Functions deprecated in one version will usually be removed in the next + * version. You can enable this to help you prepare the transition to a new + * major version by making sure your code is not using these functions. + * + * This only works with GCC and Clang. With other compilers, you may want to + * use MBEDTLS_DEPRECATED_REMOVED + * + * Uncomment to get warnings on using deprecated functions. + */ +//#define MBEDTLS_DEPRECATED_WARNING + +/** + * \def MBEDTLS_DEPRECATED_REMOVED + * + * Remove deprecated functions so that they generate an error if used. + * Functions deprecated in one version will usually be removed in the next + * version. You can enable this to help you prepare the transition to a new + * major version by making sure your code is not using these functions. + * + * Uncomment to get errors on using deprecated functions. + */ +//#define MBEDTLS_DEPRECATED_REMOVED + +/* \} name SECTION: System support */ + +/** + * \name SECTION: mbed TLS feature support + * + * This section sets support for features that are or are not needed + * within the modules that are enabled. + * \{ + */ + +/** + * \def MBEDTLS_TIMING_ALT + * + * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(), + * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay() + * + * Only works if you have MBEDTLS_TIMING_C enabled. + * + * You will need to provide a header "timing_alt.h" and an implementation at + * compile time. + */ +#define MBEDTLS_TIMING_ALT + +/** + * \def MBEDTLS__MODULE_NAME__ALT + * + * Uncomment a macro to let mbed TLS use your alternate core implementation of + * a symmetric crypto or hash module (e.g. platform specific assembly + * optimized implementations). Keep in mind that the function prototypes + * should remain the same. + * + * This replaces the whole module. If you only want to replace one of the + * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags. + * + * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer + * provide the "struct mbedtls_aes_context" definition and omit the base function + * declarations and implementations. "aes_alt.h" will be included from + * "aes.h" to include the new function definitions. + * + * Uncomment a macro to enable alternate implementation of the corresponding + * module. + */ +//#define MBEDTLS_AES_ALT +//#define MBEDTLS_ARC4_ALT +//#define MBEDTLS_BLOWFISH_ALT +//#define MBEDTLS_CAMELLIA_ALT +//#define MBEDTLS_DES_ALT +//#define MBEDTLS_XTEA_ALT +//#define MBEDTLS_MD2_ALT +//#define MBEDTLS_MD4_ALT +//#define MBEDTLS_MD5_ALT +//#define MBEDTLS_RIPEMD160_ALT +//#define MBEDTLS_SHA1_ALT +//#define MBEDTLS_SHA256_ALT +//#define MBEDTLS_SHA512_ALT + +/** + * \def MBEDTLS__FUNCTION_NAME__ALT + * + * Uncomment a macro to let mbed TLS use you alternate core implementation of + * symmetric crypto or hash function. Keep in mind that function prototypes + * should remain the same. + * + * This replaces only one function. The header file from mbed TLS is still + * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags. + * + * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will + * no longer provide the mbedtls_sha1_process() function, but it will still provide + * the other function (using your mbedtls_sha1_process() function) and the definition + * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible + * with this definition. + * + * Note: if you use the AES_xxx_ALT macros, then is is recommended to also set + * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES + * tables. + * + * Uncomment a macro to enable alternate implementation of the corresponding + * function. + */ +//#define MBEDTLS_MD2_PROCESS_ALT +//#define MBEDTLS_MD4_PROCESS_ALT +//#define MBEDTLS_MD5_PROCESS_ALT +//#define MBEDTLS_RIPEMD160_PROCESS_ALT +//#define MBEDTLS_SHA1_PROCESS_ALT +//#define MBEDTLS_SHA256_PROCESS_ALT +//#define MBEDTLS_SHA512_PROCESS_ALT +//#define MBEDTLS_DES_SETKEY_ALT +//#define MBEDTLS_DES_CRYPT_ECB_ALT +//#define MBEDTLS_DES3_CRYPT_ECB_ALT +//#define MBEDTLS_AES_SETKEY_ENC_ALT +//#define MBEDTLS_AES_SETKEY_DEC_ALT +//#define MBEDTLS_AES_ENCRYPT_ALT +//#define MBEDTLS_AES_DECRYPT_ALT + +/** + * \def MBEDTLS_ENTROPY_HARDWARE_ALT + * + * Uncomment this macro to let mbed TLS use your own implementation of a + * hardware entropy collector. + * + * Your function must be called \c mbedtls_hardware_poll(), have the same + * prototype as declared in entropy_poll.h, and accept NULL as first argument. + * + * Uncomment to use your own hardware entropy collector. + */ +//#define MBEDTLS_ENTROPY_HARDWARE_ALT + +/** + * \def MBEDTLS_AES_ROM_TABLES + * + * Store the AES tables in ROM. + * + * Uncomment this macro to store the AES tables in ROM. + */ +//#define MBEDTLS_AES_ROM_TABLES + +/** + * \def MBEDTLS_CAMELLIA_SMALL_MEMORY + * + * Use less ROM for the Camellia implementation (saves about 768 bytes). + * + * Uncomment this macro to use less memory for Camellia. + */ +//#define MBEDTLS_CAMELLIA_SMALL_MEMORY + +/** + * \def MBEDTLS_CIPHER_MODE_CBC + * + * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_CBC + +/** + * \def MBEDTLS_CIPHER_MODE_CFB + * + * Enable Cipher Feedback mode (CFB) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_CFB + +/** + * \def MBEDTLS_CIPHER_MODE_CTR + * + * Enable Counter Block Cipher mode (CTR) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_CTR + +/** + * \def MBEDTLS_CIPHER_NULL_CIPHER + * + * Enable NULL cipher. + * Warning: Only do so when you know what you are doing. This allows for + * encryption or channels without any security! + * + * Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable + * the following ciphersuites: + * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_RSA_WITH_NULL_SHA256 + * MBEDTLS_TLS_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_RSA_WITH_NULL_MD5 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_PSK_WITH_NULL_SHA + * + * Uncomment this macro to enable the NULL cipher and ciphersuites + */ +//#define MBEDTLS_CIPHER_NULL_CIPHER + +/** + * \def MBEDTLS_CIPHER_PADDING_XXX + * + * Uncomment or comment macros to add support for specific padding modes + * in the cipher layer with cipher modes that support padding (e.g. CBC) + * + * If you disable all padding modes, only full blocks can be used with CBC. + * + * Enable padding modes in the cipher layer. + */ +#define MBEDTLS_CIPHER_PADDING_PKCS7 +#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS +#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN +#define MBEDTLS_CIPHER_PADDING_ZEROS + +/** + * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES + * + * Enable weak ciphersuites in SSL / TLS. + * Warning: Only do so when you know what you are doing. This allows for + * channels with virtually no security at all! + * + * This enables the following ciphersuites: + * MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA + * + * Uncomment this macro to enable weak ciphersuites + */ +//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES + +/** + * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES + * + * Remove RC4 ciphersuites by default in SSL / TLS. + * This flag removes the ciphersuites based on RC4 from the default list as + * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to + * enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them + * explicitly. + * + * Uncomment this macro to remove RC4 ciphersuites by default. + */ +#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES + +/** + * \def MBEDTLS_ECP_XXXX_ENABLED + * + * Enables specific curves within the Elliptic Curve module. + * By default all supported curves are enabled. + * + * Comment macros to disable the curve and functions for it + */ +#define MBEDTLS_ECP_DP_SECP192R1_ENABLED +#define MBEDTLS_ECP_DP_SECP224R1_ENABLED +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_ECP_DP_SECP384R1_ENABLED +#define MBEDTLS_ECP_DP_SECP521R1_ENABLED +#define MBEDTLS_ECP_DP_SECP192K1_ENABLED +#define MBEDTLS_ECP_DP_SECP224K1_ENABLED +#define MBEDTLS_ECP_DP_SECP256K1_ENABLED +#define MBEDTLS_ECP_DP_BP256R1_ENABLED +#define MBEDTLS_ECP_DP_BP384R1_ENABLED +#define MBEDTLS_ECP_DP_BP512R1_ENABLED +#define MBEDTLS_ECP_DP_CURVE25519_ENABLED + +/** + * \def MBEDTLS_ECP_NIST_OPTIM + * + * Enable specific 'modulo p' routines for each NIST prime. + * Depending on the prime and architecture, makes operations 4 to 8 times + * faster on the corresponding curve. + * + * Comment this macro to disable NIST curves optimisation. + */ +#define MBEDTLS_ECP_NIST_OPTIM + +/** + * \def MBEDTLS_ECDSA_DETERMINISTIC + * + * Enable deterministic ECDSA (RFC 6979). + * Standard ECDSA is "fragile" in the sense that lack of entropy when signing + * may result in a compromise of the long-term signing key. This is avoided by + * the deterministic variant. + * + * Requires: MBEDTLS_HMAC_DRBG_C + * + * Comment this macro to disable deterministic ECDSA. + */ +#define MBEDTLS_ECDSA_DETERMINISTIC + +/** + * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED + * + * Enable the PSK based ciphersuite modes in SSL / TLS. + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED + * + * Enable the DHE-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_DHM_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED + * + * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED + * + * Enable the RSA-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED + * + * Enable the RSA-only based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 + */ +#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED + * + * Enable the DHE-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED + * + * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + * + * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C, + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED + * + * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + */ +#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED + * + * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 + */ +#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED + * + * Enable the ECJPAKE based ciphersuite modes in SSL / TLS. + * + * \warning This is currently experimental. EC J-PAKE support is based on the + * Thread v1.0.0 specification; incompatible changes to the specification + * might still happen. For this reason, this is disabled by default. + * + * Requires: MBEDTLS_ECJPAKE_C + * MBEDTLS_SHA256_C + * MBEDTLS_ECP_DP_SECP256R1_ENABLED + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 + */ +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED + +/** + * \def MBEDTLS_PK_PARSE_EC_EXTENDED + * + * Enhance support for reading EC keys using variants of SEC1 not allowed by + * RFC 5915 and RFC 5480. + * + * Currently this means parsing the SpecifiedECDomain choice of EC + * parameters (only known groups are supported, not arbitrary domains, to + * avoid validation issues). + * + * Disable if you only need to support RFC 5915 + 5480 key formats. + */ +#define MBEDTLS_PK_PARSE_EC_EXTENDED + +/** + * \def MBEDTLS_ERROR_STRERROR_DUMMY + * + * Enable a dummy error function to make use of mbedtls_strerror() in + * third party libraries easier when MBEDTLS_ERROR_C is disabled + * (no effect when MBEDTLS_ERROR_C is enabled). + * + * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're + * not using mbedtls_strerror() or error_strerror() in your application. + * + * Disable if you run into name conflicts and want to really remove the + * mbedtls_strerror() + */ +#define MBEDTLS_ERROR_STRERROR_DUMMY + +/** + * \def MBEDTLS_GENPRIME + * + * Enable the prime-number generation code. + * + * Requires: MBEDTLS_BIGNUM_C + */ +#define MBEDTLS_GENPRIME + +/** + * \def MBEDTLS_FS_IO + * + * Enable functions that use the filesystem. + */ +// #define MBEDTLS_FS_IO + +/** + * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + * + * Do not add default entropy sources. These are the platform specific, + * mbedtls_timing_hardclock and HAVEGE based poll functions. + * + * This is useful to have more control over the added entropy sources in an + * application. + * + * Uncomment this macro to prevent loading of default entropy functions. + */ +//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + +/** + * \def MBEDTLS_NO_PLATFORM_ENTROPY + * + * Do not use built-in platform entropy functions. + * This is useful if your platform does not support + * standards like the /dev/urandom or Windows CryptoAPI. + * + * Uncomment this macro to disable the built-in platform entropy functions. + */ +#define MBEDTLS_NO_PLATFORM_ENTROPY + +/** + * \def MBEDTLS_ENTROPY_FORCE_SHA256 + * + * Force the entropy accumulator to use a SHA-256 accumulator instead of the + * default SHA-512 based one (if both are available). + * + * Requires: MBEDTLS_SHA256_C + * + * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option + * if you have performance concerns. + * + * This option is only useful if both MBEDTLS_SHA256_C and + * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used. + */ +//#define MBEDTLS_ENTROPY_FORCE_SHA256 + +/** + * \def MBEDTLS_MEMORY_DEBUG + * + * Enable debugging of buffer allocator memory issues. Automatically prints + * (to stderr) all (fatal) messages on memory allocation issues. Enables + * function for 'debug output' of allocated memory. + * + * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C + * + * Uncomment this macro to let the buffer allocator print out error messages. + */ +//#define MBEDTLS_MEMORY_DEBUG + +/** + * \def MBEDTLS_MEMORY_BACKTRACE + * + * Include backtrace information with each allocated block. + * + * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C + * GLIBC-compatible backtrace() an backtrace_symbols() support + * + * Uncomment this macro to include backtrace information + */ +//#define MBEDTLS_MEMORY_BACKTRACE + +/** + * \def MBEDTLS_PK_RSA_ALT_SUPPORT + * + * Support external private RSA keys (eg from a HSM) in the PK layer. + * + * Comment this macro to disable support for external private RSA keys. + */ +#define MBEDTLS_PK_RSA_ALT_SUPPORT + +/** + * \def MBEDTLS_PKCS1_V15 + * + * Enable support for PKCS#1 v1.5 encoding. + * + * Requires: MBEDTLS_RSA_C + * + * This enables support for PKCS#1 v1.5 operations. + */ +#define MBEDTLS_PKCS1_V15 + +/** + * \def MBEDTLS_PKCS1_V21 + * + * Enable support for PKCS#1 v2.1 encoding. + * + * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C + * + * This enables support for RSAES-OAEP and RSASSA-PSS operations. + */ +#define MBEDTLS_PKCS1_V21 + +/** + * \def MBEDTLS_RSA_NO_CRT + * + * Do not use the Chinese Remainder Theorem for the RSA private operation. + * + * Uncomment this macro to disable the use of CRT in RSA. + * + */ +//#define MBEDTLS_RSA_NO_CRT + +/** + * \def MBEDTLS_SELF_TEST + * + * Enable the checkup functions (*_self_test). + */ +#define MBEDTLS_SELF_TEST + +/** + * \def MBEDTLS_SHA256_SMALLER + * + * Enable an implementation of SHA-256 that has lower ROM footprint but also + * lower performance. + * + * The default implementation is meant to be a reasonnable compromise between + * performance and size. This version optimizes more aggressively for size at + * the expense of performance. Eg on Cortex-M4 it reduces the size of + * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about + * 30%. + * + * Uncomment to enable the smaller implementation of SHA256. + */ +//#define MBEDTLS_SHA256_SMALLER + +/** + * \def MBEDTLS_SSL_AEAD_RANDOM_IV + * + * Generate a random IV rather than using the record sequence number as a + * nonce for ciphersuites using and AEAD algorithm (GCM or CCM). + * + * Using the sequence number is generally recommended. + * + * Uncomment this macro to always use random IVs with AEAD ciphersuites. + */ +//#define MBEDTLS_SSL_AEAD_RANDOM_IV + +/** + * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES + * + * Enable sending of alert messages in case of encountered errors as per RFC. + * If you choose not to send the alert messages, mbed TLS can still communicate + * with other servers, only debugging of failures is harder. + * + * The advantage of not sending alert messages, is that no information is given + * about reasons for failures thus preventing adversaries of gaining intel. + * + * Enable sending of all alert messages + */ +#define MBEDTLS_SSL_ALL_ALERT_MESSAGES + +/** + * \def MBEDTLS_SSL_DEBUG_ALL + * + * Enable the debug messages in SSL module for all issues. + * Debug messages have been disabled in some places to prevent timing + * attacks due to (unbalanced) debugging function calls. + * + * If you need all error reporting you should enable this during debugging, + * but remove this for production servers that should log as well. + * + * Uncomment this macro to report all debug messages on errors introducing + * a timing side-channel. + * + */ +//#define MBEDTLS_SSL_DEBUG_ALL + +/** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC + * + * Enable support for Encrypt-then-MAC, RFC 7366. + * + * This allows peers that both support it to use a more robust protection for + * ciphersuites using CBC, providing deep resistance against timing attacks + * on the padding or underlying cipher. + * + * This only affects CBC ciphersuites, and is useless if none is defined. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1 or + * MBEDTLS_SSL_PROTO_TLS1_1 or + * MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for Encrypt-then-MAC + */ +#define MBEDTLS_SSL_ENCRYPT_THEN_MAC + +/** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET + * + * Enable support for Extended Master Secret, aka Session Hash + * (draft-ietf-tls-session-hash-02). + * + * This was introduced as "the proper fix" to the Triple Handshake familiy of + * attacks, but it is recommended to always use it (even if you disable + * renegotiation), since it actually fixes a more fundamental issue in the + * original SSL/TLS design, and has implications beyond Triple Handshake. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1 or + * MBEDTLS_SSL_PROTO_TLS1_1 or + * MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for Extended Master Secret. + */ +#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET + +/** + * \def MBEDTLS_SSL_FALLBACK_SCSV + * + * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00). + * + * For servers, it is recommended to always enable this, unless you support + * only one version of TLS, or know for sure that none of your clients + * implements a fallback strategy. + * + * For clients, you only need this if you're using a fallback strategy, which + * is not recommended in the first place, unless you absolutely need it to + * interoperate with buggy (version-intolerant) servers. + * + * Comment this macro to disable support for FALLBACK_SCSV + */ +#define MBEDTLS_SSL_FALLBACK_SCSV + +/** + * \def MBEDTLS_SSL_HW_RECORD_ACCEL + * + * Enable hooking functions in SSL module for hardware acceleration of + * individual records. + * + * Uncomment this macro to enable hooking functions. + */ +//#define MBEDTLS_SSL_HW_RECORD_ACCEL + +/** + * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING + * + * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0. + * + * This is a countermeasure to the BEAST attack, which also minimizes the risk + * of interoperability issues compared to sending 0-length records. + * + * Comment this macro to disable 1/n-1 record splitting. + */ +#define MBEDTLS_SSL_CBC_RECORD_SPLITTING + +/** + * \def MBEDTLS_SSL_RENEGOTIATION + * + * Disable support for TLS renegotiation. + * + * The two main uses of renegotiation are (1) refresh keys on long-lived + * connections and (2) client authentication after the initial handshake. + * If you don't need renegotiation, it's probably better to disable it, since + * it has been associated with security issues in the past and is easy to + * misuse/misunderstand. + * + * Comment this to disable support for renegotiation. + */ +#define MBEDTLS_SSL_RENEGOTIATION + +/** + * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO + * + * Enable support for receiving and parsing SSLv2 Client Hello messages for the + * SSL Server module (MBEDTLS_SSL_SRV_C). + * + * Uncomment this macro to enable support for SSLv2 Client Hello messages. + */ +//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO + +/** + * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE + * + * Pick the ciphersuite according to the client's preferences rather than ours + * in the SSL Server module (MBEDTLS_SSL_SRV_C). + * + * Uncomment this macro to respect client's ciphersuite order + */ +//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE + +/** + * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + * + * Enable support for RFC 6066 max_fragment_length extension in SSL. + * + * Comment this macro to disable support for the max_fragment_length extension + */ +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + +/** + * \def MBEDTLS_SSL_PROTO_SSL3 + * + * Enable support for SSL 3.0. + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for SSL 3.0 + */ +#define MBEDTLS_SSL_PROTO_SSL3 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1 + * + * Enable support for TLS 1.0. + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for TLS 1.0 + */ +#define MBEDTLS_SSL_PROTO_TLS1 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1_1 + * + * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled). + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for TLS 1.1 / DTLS 1.0 + */ +#define MBEDTLS_SSL_PROTO_TLS1_1 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1_2 + * + * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled). + * + * Requires: MBEDTLS_SHA1_C or MBEDTLS_SHA256_C or MBEDTLS_SHA512_C + * (Depends on ciphersuites) + * + * Comment this macro to disable support for TLS 1.2 / DTLS 1.2 + */ +#define MBEDTLS_SSL_PROTO_TLS1_2 + +/** + * \def MBEDTLS_SSL_PROTO_DTLS + * + * Enable support for DTLS (all available versions). + * + * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0, + * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1_1 + * or MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for DTLS + */ +#define MBEDTLS_SSL_PROTO_DTLS + +/** + * \def MBEDTLS_SSL_ALPN + * + * Enable support for RFC 7301 Application Layer Protocol Negotiation. + * + * Comment this macro to disable support for ALPN. + */ +#define MBEDTLS_SSL_ALPN + +/** + * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY + * + * Enable support for the anti-replay mechanism in DTLS. + * + * Requires: MBEDTLS_SSL_TLS_C + * MBEDTLS_SSL_PROTO_DTLS + * + * \warning Disabling this is often a security risk! + * See mbedtls_ssl_conf_dtls_anti_replay() for details. + * + * Comment this to disable anti-replay in DTLS. + */ +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY + +/** + * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY + * + * Enable support for HelloVerifyRequest on DTLS servers. + * + * This feature is highly recommended to prevent DTLS servers being used as + * amplifiers in DoS attacks against other hosts. It should always be enabled + * unless you know for sure amplification cannot be a problem in the + * environment in which your server operates. + * + * \warning Disabling this can ba a security risk! (see above) + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Comment this to disable support for HelloVerifyRequest. + */ +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY + +/** + * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE + * + * Enable server-side support for clients that reconnect from the same port. + * + * Some clients unexpectedly close the connection and try to reconnect using the + * same source port. This needs special support from the server to handle the + * new connection securely, as described in section 4.2.8 of RFC 6347. This + * flag enables that support. + * + * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY + * + * Comment this to disable support for clients reusing the source port. + */ +#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE + +/** + * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT + * + * Enable support for a limit of records with bad MAC. + * + * See mbedtls_ssl_conf_dtls_badmac_limit(). + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + */ +#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT + +/** + * \def MBEDTLS_SSL_SESSION_TICKETS + * + * Enable support for RFC 5077 session tickets in SSL. + * Client-side, provides full support for session tickets (maintainance of a + * session store remains the responsibility of the application, though). + * Server-side, you also need to provide callbacks for writing and parsing + * tickets, including authenticated encryption and key management. Example + * callbacks are provided by MBEDTLS_SSL_TICKET_C. + * + * Comment this macro to disable support for SSL session tickets + */ +#define MBEDTLS_SSL_SESSION_TICKETS + +/** + * \def MBEDTLS_SSL_EXPORT_KEYS + * + * Enable support for exporting key block and master secret. + * This is required for certain users of TLS, e.g. EAP-TLS. + * + * Comment this macro to disable support for key export + */ +#define MBEDTLS_SSL_EXPORT_KEYS + +/** + * \def MBEDTLS_SSL_SERVER_NAME_INDICATION + * + * Enable support for RFC 6066 server name indication (SNI) in SSL. + * + * Requires: MBEDTLS_X509_CRT_PARSE_C + * + * Comment this macro to disable support for server name indication in SSL + */ +#define MBEDTLS_SSL_SERVER_NAME_INDICATION + +/** + * \def MBEDTLS_SSL_TRUNCATED_HMAC + * + * Enable support for RFC 6066 truncated HMAC in SSL. + * + * Comment this macro to disable support for truncated HMAC in SSL + */ +#define MBEDTLS_SSL_TRUNCATED_HMAC + +/** + * \def MBEDTLS_THREADING_ALT + * + * Provide your own alternate threading implementation. + * + * Requires: MBEDTLS_THREADING_C + * + * Uncomment this to allow your own alternate threading implementation. + */ +#define MBEDTLS_THREADING_ALT + +/** + * \def MBEDTLS_THREADING_PTHREAD + * + * Enable the pthread wrapper layer for the threading layer. + * + * Requires: MBEDTLS_THREADING_C + * + * Uncomment this to enable pthread mutexes. + */ +//#define MBEDTLS_THREADING_PTHREAD + +/** + * \def MBEDTLS_VERSION_FEATURES + * + * Allow run-time checking of compile-time enabled features. Thus allowing users + * to check at run-time if the library is for instance compiled with threading + * support via mbedtls_version_check_feature(). + * + * Requires: MBEDTLS_VERSION_C + * + * Comment this to disable run-time checking and save ROM space + */ +#define MBEDTLS_VERSION_FEATURES + +/** + * \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 + * + * If set, the X509 parser will not break-off when parsing an X509 certificate + * and encountering an extension in a v1 or v2 certificate. + * + * Uncomment to prevent an error. + */ +//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 + +/** + * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION + * + * If set, the X509 parser will not break-off when parsing an X509 certificate + * and encountering an unknown critical extension. + * + * \warning Depending on your PKI use, enabling this can be a security risk! + * + * Uncomment to prevent an error. + */ +//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION + +/** + * \def MBEDTLS_X509_CHECK_KEY_USAGE + * + * Enable verification of the keyUsage extension (CA and leaf certificates). + * + * Disabling this avoids problems with mis-issued and/or misused + * (intermediate) CA and leaf certificates. + * + * \warning Depending on your PKI use, disabling this can be a security risk! + * + * Comment to skip keyUsage checking for both CA and leaf certificates. + */ +#define MBEDTLS_X509_CHECK_KEY_USAGE + +/** + * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE + * + * Enable verification of the extendedKeyUsage extension (leaf certificates). + * + * Disabling this avoids problems with mis-issued and/or misused certificates. + * + * \warning Depending on your PKI use, disabling this can be a security risk! + * + * Comment to skip extendedKeyUsage checking for certificates. + */ +#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE + +/** + * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT + * + * Enable parsing and verification of X.509 certificates, CRLs and CSRS + * signed with RSASSA-PSS (aka PKCS#1 v2.1). + * + * Comment this macro to disallow using RSASSA-PSS in certificates. + */ +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT + +/** + * \def MBEDTLS_ZLIB_SUPPORT + * + * If set, the SSL/TLS module uses ZLIB to support compression and + * decompression of packet data. + * + * \warning TLS-level compression MAY REDUCE SECURITY! See for example the + * CRIME attack. Before enabling this option, you should examine with care if + * CRIME or similar exploits may be a applicable to your use case. + * + * \note Currently compression can't be used with DTLS. + * + * Used in: library/ssl_tls.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * This feature requires zlib library and headers to be present. + * + * Uncomment to enable use of ZLIB + */ +//#define MBEDTLS_ZLIB_SUPPORT +/* \} name SECTION: mbed TLS feature support */ + +/** + * \name SECTION: mbed TLS modules + * + * This section enables or disables entire modules in mbed TLS + * \{ + */ + +/** + * \def MBEDTLS_AESNI_C + * + * Enable AES-NI support on x86-64. + * + * Module: library/aesni.c + * Caller: library/aes.c + * + * Requires: MBEDTLS_HAVE_ASM + * + * This modules adds support for the AES-NI instructions on x86-64 + */ +//#define MBEDTLS_AESNI_C + +/** + * \def MBEDTLS_AES_C + * + * Enable the AES block cipher. + * + * Module: library/aes.c + * Caller: library/ssl_tls.c + * library/pem.c + * library/ctr_drbg.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA + * + * PEM_PARSE uses AES for decrypting encrypted keys. + */ +#define MBEDTLS_AES_C + +/** + * \def MBEDTLS_ARC4_C + * + * Enable the ARCFOUR stream cipher. + * + * Module: library/arc4.c + * Caller: library/ssl_tls.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 + * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA + */ +#define MBEDTLS_ARC4_C + +/** + * \def MBEDTLS_ASN1_PARSE_C + * + * Enable the generic ASN1 parser. + * + * Module: library/asn1.c + * Caller: library/x509.c + * library/dhm.c + * library/pkcs12.c + * library/pkcs5.c + * library/pkparse.c + */ +#define MBEDTLS_ASN1_PARSE_C + +/** + * \def MBEDTLS_ASN1_WRITE_C + * + * Enable the generic ASN1 writer. + * + * Module: library/asn1write.c + * Caller: library/ecdsa.c + * library/pkwrite.c + * library/x509_create.c + * library/x509write_crt.c + * library/mbedtls_x509write_csr.c + */ +#define MBEDTLS_ASN1_WRITE_C + +/** + * \def MBEDTLS_BASE64_C + * + * Enable the Base64 module. + * + * Module: library/base64.c + * Caller: library/pem.c + * + * This module is required for PEM support (required by X.509). + */ +#define MBEDTLS_BASE64_C + +/** + * \def MBEDTLS_BIGNUM_C + * + * Enable the multi-precision integer library. + * + * Module: library/bignum.c + * Caller: library/dhm.c + * library/ecp.c + * library/ecdsa.c + * library/rsa.c + * library/ssl_tls.c + * + * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support. + */ +#define MBEDTLS_BIGNUM_C + +/** + * \def MBEDTLS_BLOWFISH_C + * + * Enable the Blowfish block cipher. + * + * Module: library/blowfish.c + */ +#define MBEDTLS_BLOWFISH_C + +/** + * \def MBEDTLS_CAMELLIA_C + * + * Enable the Camellia block cipher. + * + * Module: library/camellia.c + * Caller: library/ssl_tls.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 + */ +#define MBEDTLS_CAMELLIA_C + +/** + * \def MBEDTLS_CCM_C + * + * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher. + * + * Module: library/ccm.c + * + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * + * This module enables the AES-CCM ciphersuites, if other requisites are + * enabled as well. + */ +#define MBEDTLS_CCM_C + +/** + * \def MBEDTLS_CERTS_C + * + * Enable the test certificates. + * + * Module: library/certs.c + * Caller: + * + * This module is used for testing (ssl_client/server). + */ +#define MBEDTLS_CERTS_C + +/** + * \def MBEDTLS_CIPHER_C + * + * Enable the generic cipher layer. + * + * Module: library/cipher.c + * Caller: library/ssl_tls.c + * + * Uncomment to enable generic cipher wrappers. + */ +#define MBEDTLS_CIPHER_C + +/** + * \def MBEDTLS_CTR_DRBG_C + * + * Enable the CTR_DRBG AES-256-based random generator. + * + * Module: library/ctr_drbg.c + * Caller: + * + * Requires: MBEDTLS_AES_C + * + * This module provides the CTR_DRBG AES-256 random number generator. + */ +#define MBEDTLS_CTR_DRBG_C + +/** + * \def MBEDTLS_DEBUG_C + * + * Enable the debug functions. + * + * Module: library/debug.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * This module provides debugging functions. + */ +#define MBEDTLS_DEBUG_C + +/** + * \def MBEDTLS_DES_C + * + * Enable the DES block cipher. + * + * Module: library/des.c + * Caller: library/pem.c + * library/ssl_tls.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA + * + * PEM_PARSE uses DES/3DES for decrypting encrypted keys. + */ +#define MBEDTLS_DES_C + +/** + * \def MBEDTLS_DHM_C + * + * Enable the Diffie-Hellman-Merkle module. + * + * Module: library/dhm.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * This module is used by the following key exchanges: + * DHE-RSA, DHE-PSK + */ +#define MBEDTLS_DHM_C + +/** + * \def MBEDTLS_ECDH_C + * + * Enable the elliptic curve Diffie-Hellman library. + * + * Module: library/ecdh.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * This module is used by the following key exchanges: + * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK + * + * Requires: MBEDTLS_ECP_C + */ +#define MBEDTLS_ECDH_C + +/** + * \def MBEDTLS_ECDSA_C + * + * Enable the elliptic curve DSA library. + * + * Module: library/ecdsa.c + * Caller: + * + * This module is used by the following key exchanges: + * ECDHE-ECDSA + * + * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C + */ +#define MBEDTLS_ECDSA_C + +/** + * \def MBEDTLS_ECJPAKE_C + * + * Enable the elliptic curve J-PAKE library. + * + * \warning This is currently experimental. EC J-PAKE support is based on the + * Thread v1.0.0 specification; incompatible changes to the specification + * might still happen. For this reason, this is disabled by default. + * + * Module: library/ecjpake.c + * Caller: + * + * This module is used by the following key exchanges: + * ECJPAKE + * + * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C + */ +//#define MBEDTLS_ECJPAKE_C + +/** + * \def MBEDTLS_ECP_C + * + * Enable the elliptic curve over GF(p) library. + * + * Module: library/ecp.c + * Caller: library/ecdh.c + * library/ecdsa.c + * library/ecjpake.c + * + * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED + */ +#define MBEDTLS_ECP_C + +/** + * \def MBEDTLS_ENTROPY_C + * + * Enable the platform-specific entropy code. + * + * Module: library/entropy.c + * Caller: + * + * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C + * + * This module provides a generic entropy pool + */ +#define MBEDTLS_ENTROPY_C + +/** + * \def MBEDTLS_ERROR_C + * + * Enable error code to error string conversion. + * + * Module: library/error.c + * Caller: + * + * This module enables mbedtls_strerror(). + */ +#define MBEDTLS_ERROR_C + +/** + * \def MBEDTLS_GCM_C + * + * Enable the Galois/Counter Mode (GCM) for AES. + * + * Module: library/gcm.c + * + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * + * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other + * requisites are enabled as well. + */ +#define MBEDTLS_GCM_C + +/** + * \def MBEDTLS_HAVEGE_C + * + * Enable the HAVEGE random generator. + * + * Warning: the HAVEGE random generator is not suitable for virtualized + * environments + * + * Warning: the HAVEGE random generator is dependent on timing and specific + * processor traits. It is therefore not advised to use HAVEGE as + * your applications primary random generator or primary entropy pool + * input. As a secondary input to your entropy pool, it IS able add + * the (limited) extra entropy it provides. + * + * Module: library/havege.c + * Caller: + * + * Requires: MBEDTLS_TIMING_C + * + * Uncomment to enable the HAVEGE random generator. + */ +#define MBEDTLS_HAVEGE_C + +/** + * \def MBEDTLS_HMAC_DRBG_C + * + * Enable the HMAC_DRBG random generator. + * + * Module: library/hmac_drbg.c + * Caller: + * + * Requires: MBEDTLS_MD_C + * + * Uncomment to enable the HMAC_DRBG random number geerator. + */ +#define MBEDTLS_HMAC_DRBG_C + +/** + * \def MBEDTLS_MD_C + * + * Enable the generic message digest layer. + * + * Module: library/mbedtls_md.c + * Caller: + * + * Uncomment to enable generic message digest wrappers. + */ +#define MBEDTLS_MD_C + +/** + * \def MBEDTLS_MD2_C + * + * Enable the MD2 hash algorithm. + * + * Module: library/mbedtls_md2.c + * Caller: + * + * Uncomment to enable support for (rare) MD2-signed X.509 certs. + */ +//#define MBEDTLS_MD2_C + +/** + * \def MBEDTLS_MD4_C + * + * Enable the MD4 hash algorithm. + * + * Module: library/mbedtls_md4.c + * Caller: + * + * Uncomment to enable support for (rare) MD4-signed X.509 certs. + */ +//#define MBEDTLS_MD4_C + +/** + * \def MBEDTLS_MD5_C + * + * Enable the MD5 hash algorithm. + * + * Module: library/mbedtls_md5.c + * Caller: library/mbedtls_md.c + * library/pem.c + * library/ssl_tls.c + * + * This module is required for SSL/TLS and X.509. + * PEM_PARSE uses MD5 for decrypting encrypted keys. + */ +#define MBEDTLS_MD5_C + +/** + * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C + * + * Enable the buffer allocator implementation that makes use of a (stack) + * based buffer to 'allocate' dynamic memory. (replaces calloc() and free() + * calls) + * + * Module: library/memory_buffer_alloc.c + * + * Requires: MBEDTLS_PLATFORM_C + * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS) + * + * Enable this module to enable the buffer memory allocator. + */ +//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C + +/** + * \def MBEDTLS_NET_C + * + * Enable the TCP/IP networking routines. + * + * Module: library/net.c + * + * This module provides TCP/IP networking routines. + */ +#define MBEDTLS_NET_C + +/** + * \def MBEDTLS_OID_C + * + * Enable the OID database. + * + * Module: library/oid.c + * Caller: library/asn1write.c + * library/pkcs5.c + * library/pkparse.c + * library/pkwrite.c + * library/rsa.c + * library/x509.c + * library/x509_create.c + * library/mbedtls_x509_crl.c + * library/mbedtls_x509_crt.c + * library/mbedtls_x509_csr.c + * library/x509write_crt.c + * library/mbedtls_x509write_csr.c + * + * This modules translates between OIDs and internal values. + */ +#define MBEDTLS_OID_C + +/** + * \def MBEDTLS_PADLOCK_C + * + * Enable VIA Padlock support on x86. + * + * Module: library/padlock.c + * Caller: library/aes.c + * + * Requires: MBEDTLS_HAVE_ASM + * + * This modules adds support for the VIA PadLock on x86. + */ +//#define MBEDTLS_PADLOCK_C + +/** + * \def MBEDTLS_PEM_PARSE_C + * + * Enable PEM decoding / parsing. + * + * Module: library/pem.c + * Caller: library/dhm.c + * library/pkparse.c + * library/mbedtls_x509_crl.c + * library/mbedtls_x509_crt.c + * library/mbedtls_x509_csr.c + * + * Requires: MBEDTLS_BASE64_C + * + * This modules adds support for decoding / parsing PEM files. + */ +#define MBEDTLS_PEM_PARSE_C + +/** + * \def MBEDTLS_PEM_WRITE_C + * + * Enable PEM encoding / writing. + * + * Module: library/pem.c + * Caller: library/pkwrite.c + * library/x509write_crt.c + * library/mbedtls_x509write_csr.c + * + * Requires: MBEDTLS_BASE64_C + * + * This modules adds support for encoding / writing PEM files. + */ +#define MBEDTLS_PEM_WRITE_C + +/** + * \def MBEDTLS_PK_C + * + * Enable the generic public (asymetric) key layer. + * + * Module: library/pk.c + * Caller: library/ssl_tls.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * Requires: MBEDTLS_RSA_C or MBEDTLS_ECP_C + * + * Uncomment to enable generic public key wrappers. + */ +#define MBEDTLS_PK_C + +/** + * \def MBEDTLS_PK_PARSE_C + * + * Enable the generic public (asymetric) key parser. + * + * Module: library/pkparse.c + * Caller: library/mbedtls_x509_crt.c + * library/mbedtls_x509_csr.c + * + * Requires: MBEDTLS_PK_C + * + * Uncomment to enable generic public key parse functions. + */ +#define MBEDTLS_PK_PARSE_C + +/** + * \def MBEDTLS_PK_WRITE_C + * + * Enable the generic public (asymetric) key writer. + * + * Module: library/pkwrite.c + * Caller: library/x509write.c + * + * Requires: MBEDTLS_PK_C + * + * Uncomment to enable generic public key write functions. + */ +#define MBEDTLS_PK_WRITE_C + +/** + * \def MBEDTLS_PKCS5_C + * + * Enable PKCS#5 functions. + * + * Module: library/pkcs5.c + * + * Requires: MBEDTLS_MD_C + * + * This module adds support for the PKCS#5 functions. + */ +#define MBEDTLS_PKCS5_C + +/** + * \def MBEDTLS_PKCS11_C + * + * Enable wrapper for PKCS#11 smartcard support. + * + * Module: library/pkcs11.c + * Caller: library/pk.c + * + * Requires: MBEDTLS_PK_C + * + * This module enables SSL/TLS PKCS #11 smartcard support. + * Requires the presence of the PKCS#11 helper library (libpkcs11-helper) + */ +//#define MBEDTLS_PKCS11_C + +/** + * \def MBEDTLS_PKCS12_C + * + * Enable PKCS#12 PBE functions. + * Adds algorithms for parsing PKCS#8 encrypted private keys + * + * Module: library/pkcs12.c + * Caller: library/pkparse.c + * + * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C + * Can use: MBEDTLS_ARC4_C + * + * This module enables PKCS#12 functions. + */ +#define MBEDTLS_PKCS12_C + +/** + * \def MBEDTLS_PLATFORM_C + * + * Enable the platform abstraction layer that allows you to re-assign + * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit(). + * + * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT + * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned + * above to be specified at runtime or compile time respectively. + * + * \note This abstraction layer must be enabled on Windows (including MSYS2) + * as other module rely on it for a fixed snprintf implementation. + * + * Module: library/platform.c + * Caller: Most other .c files + * + * This module enables abstraction of common (libc) functions. + */ +#define MBEDTLS_PLATFORM_C + +/** + * \def MBEDTLS_RIPEMD160_C + * + * Enable the RIPEMD-160 hash algorithm. + * + * Module: library/mbedtls_ripemd160.c + * Caller: library/mbedtls_md.c + * + */ +#define MBEDTLS_RIPEMD160_C + +/** + * \def MBEDTLS_RSA_C + * + * Enable the RSA public-key cryptosystem. + * + * Module: library/rsa.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * library/x509.c + * + * This module is used by the following key exchanges: + * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK + * + * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C + */ +#define MBEDTLS_RSA_C + +/** + * \def MBEDTLS_SHA1_C + * + * Enable the SHA1 cryptographic hash algorithm. + * + * Module: library/mbedtls_sha1.c + * Caller: library/mbedtls_md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * library/x509write_crt.c + * + * This module is required for SSL/TLS and SHA1-signed certificates. + */ +#define MBEDTLS_SHA1_C + +/** + * \def MBEDTLS_SHA256_C + * + * Enable the SHA-224 and SHA-256 cryptographic hash algorithms. + * + * Module: library/mbedtls_sha256.c + * Caller: library/entropy.c + * library/mbedtls_md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * This module adds support for SHA-224 and SHA-256. + * This module is required for the SSL/TLS 1.2 PRF function. + */ +#define MBEDTLS_SHA256_C + +/** + * \def MBEDTLS_SHA512_C + * + * Enable the SHA-384 and SHA-512 cryptographic hash algorithms. + * + * Module: library/mbedtls_sha512.c + * Caller: library/entropy.c + * library/mbedtls_md.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * This module adds support for SHA-384 and SHA-512. + */ +#define MBEDTLS_SHA512_C + +/** + * \def MBEDTLS_SSL_CACHE_C + * + * Enable simple SSL cache implementation. + * + * Module: library/ssl_cache.c + * Caller: + * + * Requires: MBEDTLS_SSL_CACHE_C + */ +#define MBEDTLS_SSL_CACHE_C + +/** + * \def MBEDTLS_SSL_COOKIE_C + * + * Enable basic implementation of DTLS cookies for hello verification. + * + * Module: library/ssl_cookie.c + * Caller: + */ +#define MBEDTLS_SSL_COOKIE_C + +/** + * \def MBEDTLS_SSL_TICKET_C + * + * Enable an implementation of TLS server-side callbacks for session tickets. + * + * Module: library/ssl_ticket.c + * Caller: + * + * Requires: MBEDTLS_CIPHER_C + */ +#define MBEDTLS_SSL_TICKET_C + +/** + * \def MBEDTLS_SSL_CLI_C + * + * Enable the SSL/TLS client code. + * + * Module: library/ssl_cli.c + * Caller: + * + * Requires: MBEDTLS_SSL_TLS_C + * + * This module is required for SSL/TLS client support. + */ +#define MBEDTLS_SSL_CLI_C + +/** + * \def MBEDTLS_SSL_SRV_C + * + * Enable the SSL/TLS server code. + * + * Module: library/ssl_srv.c + * Caller: + * + * Requires: MBEDTLS_SSL_TLS_C + * + * This module is required for SSL/TLS server support. + */ +#define MBEDTLS_SSL_SRV_C + +/** + * \def MBEDTLS_SSL_TLS_C + * + * Enable the generic SSL/TLS code. + * + * Module: library/ssl_tls.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C + * and at least one of the MBEDTLS_SSL_PROTO_XXX defines + * + * This module is required for SSL/TLS. + */ +#define MBEDTLS_SSL_TLS_C + +/** + * \def MBEDTLS_THREADING_C + * + * Enable the threading abstraction layer. + * By default mbed TLS assumes it is used in a non-threaded environment or that + * contexts are not shared between threads. If you do intend to use contexts + * between threads, you will need to enable this layer to prevent race + * conditions. + * + * Module: library/threading.c + * + * This allows different threading implementations (self-implemented or + * provided). + * + * You will have to enable either MBEDTLS_THREADING_ALT or + * MBEDTLS_THREADING_PTHREAD. + * + * Enable this layer to allow use of mutexes within mbed TLS + */ +#define MBEDTLS_THREADING_C + +/** + * \def MBEDTLS_TIMING_C + * + * Enable the portable timing interface. + * + * Module: library/timing.c + * Caller: library/havege.c + * + * This module is used by the HAVEGE random number generator. + */ +#define MBEDTLS_TIMING_C + +/** + * \def MBEDTLS_VERSION_C + * + * Enable run-time version information. + * + * Module: library/version.c + * + * This module provides run-time version information. + */ +#define MBEDTLS_VERSION_C + +/** + * \def MBEDTLS_X509_USE_C + * + * Enable X.509 core for using certificates. + * + * Module: library/x509.c + * Caller: library/mbedtls_x509_crl.c + * library/mbedtls_x509_crt.c + * library/mbedtls_x509_csr.c + * + * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, + * MBEDTLS_PK_PARSE_C + * + * This module is required for the X.509 parsing modules. + */ +#define MBEDTLS_X509_USE_C + +/** + * \def MBEDTLS_X509_CRT_PARSE_C + * + * Enable X.509 certificate parsing. + * + * Module: library/mbedtls_x509_crt.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is required for X.509 certificate parsing. + */ +#define MBEDTLS_X509_CRT_PARSE_C + +/** + * \def MBEDTLS_X509_CRL_PARSE_C + * + * Enable X.509 CRL parsing. + * + * Module: library/mbedtls_x509_crl.c + * Caller: library/mbedtls_x509_crt.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is required for X.509 CRL parsing. + */ +#define MBEDTLS_X509_CRL_PARSE_C + +/** + * \def MBEDTLS_X509_CSR_PARSE_C + * + * Enable X.509 Certificate Signing Request (CSR) parsing. + * + * Module: library/mbedtls_x509_csr.c + * Caller: library/x509_crt_write.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is used for reading X.509 certificate request. + */ +#define MBEDTLS_X509_CSR_PARSE_C + +/** + * \def MBEDTLS_X509_CREATE_C + * + * Enable X.509 core for creating certificates. + * + * Module: library/x509_create.c + * + * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C + * + * This module is the basis for creating X.509 certificates and CSRs. + */ +#define MBEDTLS_X509_CREATE_C + +/** + * \def MBEDTLS_X509_CRT_WRITE_C + * + * Enable creating X.509 certificates. + * + * Module: library/x509_crt_write.c + * + * Requires: MBEDTLS_X509_CREATE_C + * + * This module is required for X.509 certificate creation. + */ +#define MBEDTLS_X509_CRT_WRITE_C + +/** + * \def MBEDTLS_X509_CSR_WRITE_C + * + * Enable creating X.509 Certificate Signing Requests (CSR). + * + * Module: library/x509_csr_write.c + * + * Requires: MBEDTLS_X509_CREATE_C + * + * This module is required for X.509 certificate request writing. + */ +#define MBEDTLS_X509_CSR_WRITE_C + +/** + * \def MBEDTLS_XTEA_C + * + * Enable the XTEA block cipher. + * + * Module: library/xtea.c + * Caller: + */ +#define MBEDTLS_XTEA_C + +/* \} name SECTION: mbed TLS modules */ + +/** + * \name SECTION: Module configuration options + * + * This section allows for the setting of module specific sizes and + * configuration options. The default values are already present in the + * relevant header files and should suffice for the regular use cases. + * + * Our advice is to enable options and change their values here + * only if you have a good reason and know the consequences. + * + * Please check the respective header file for documentation on these + * parameters (to prevent duplicate documentation). + * \{ + */ + +/* MPI / BIGNUM options */ +//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ +//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */ + +/* CTR_DRBG options */ +//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */ +//#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ +//#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ +//#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ +//#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ + +/* HMAC_DRBG options */ +//#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ +//#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ +//#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ +//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ + +/* ECP options */ +//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ +//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ +//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ + +/* Entropy options */ +//#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */ +//#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */ + +/* Memory buffer allocator options */ +//#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ + +/* Platform options */ +//#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ +//#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */ +/* Note: your snprintf must correclty zero-terminate the buffer! */ +//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ + +/* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */ +/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */ +//#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */ +/* Note: your snprintf must correclty zero-terminate the buffer! */ +//#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */ + +/* SSL Cache options */ +//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ +//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ + +/* SSL options */ +//#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Maxium fragment length in bytes, determines the size of each of the two internal I/O buffers */ +//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */ +//#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */ +//#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ + +/** + * Complete list of ciphersuites to use, in order of preference. + * + * \warning No dependency checking is done on that field! This option can only + * be used to restrict the set of available ciphersuites. It is your + * responsibility to make sure the needed modules are active. + * + * Use this to save a few hundred bytes of ROM (default ordering of all + * available ciphersuites) and a few to a few hundred bytes of RAM. + * + * The value below is only an example, not the default. + */ +//#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + +/* X509 options */ +//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */ + +/* \} name SECTION: Module configuration options */ + + +#include "mbedtls/check_config.h" + +#endif /* MBEDTLS_CONFIG_H */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/numpad_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/numpad_task.h new file mode 100644 index 00000000..4741097d --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/numpad_task.h @@ -0,0 +1,8 @@ +#ifndef NUMPAD_TASK_H +#define NUMPAD_TASK_H + +#include "stdint.h" + +void numpad_task(void *p_arg); + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/oled_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/oled_task.h new file mode 100644 index 00000000..02eb16fe --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/oled_task.h @@ -0,0 +1,8 @@ +#ifndef OLED_TASK_H +#define OLED_TASK_H + +#include "stdint.h" + +void oled_task(void *p_arg); + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/ssd1306_app_config.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/ssd1306_app_config.h new file mode 100644 index 00000000..e0b60f16 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/ssd1306_app_config.h @@ -0,0 +1,46 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +#ifndef _SSD1306_APP_CONFIG_H_ +#define _SSD1306_APP_CONFIG_H_ +#include "dev_gpio.h" + +#define SSD1306_SPI_ID 0 +#define SSD1306_SPI_CS EMSK_SPI_LINE_1 +#define SSD1306_RST_PIN 25 // pmod J5 pin 8 +#define SSD1306_CD_GPIO (DEV_GPIO_PORT_A) +#define SSD1306_CD_PIN 26 // pmod J5 pin 9 + +#define SSD1306_CS_GPIO (DEV_GPIO_PORT_A) +#define SSD1306_CS_PIN 24 // pmod J5 pin 7 + +//#define SSD1306_SPI_FREQ 4000000ul +//#define SSD1306_SPI_FREQ 8000000ul +#define SSD1306_SPI_FREQ 10000000ul +#endif /* _SSD1306_APP_CONFIG_H_ */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/temp_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/temp_task.h new file mode 100644 index 00000000..fbde2cf7 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/temp_task.h @@ -0,0 +1,8 @@ +#ifndef TEMP_TASK_H +#define TEMP_TASK_H + +#include "stdint.h" + +void temp_task(void *p_arg); + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/vm_task.h b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/vm_task.h new file mode 100644 index 00000000..7db63413 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Include/vm_task.h @@ -0,0 +1,75 @@ +#ifndef VM_TASK_H +#define VM_TASK_H + +// define id +#define id_main 1 +#define id_wifi 2 +#define id_temp 3 +#define id_numpad 4 +#define id_dcmotor 5 +#define id_oled 6 + +// define target_item +#define no_item 0 +#define item_1 1 +#define item_2 2 +#define item_3 3 +#define item_4 4 + +// define status +#define server_do_nothing 0 +#define balance_check 1 +#define sell_request 2 +#define sell_recommand 3 +#define reject_balance 4 +#define reject_overdue 5 +#define reject_enough 6 +#define purchase_check 7 +#define temperature 8 +#define purchase_confirm 9 +#define user_input_1 10 +#define user_input_2 11 +#define user_input_3 12 +#define user_input_4 13 + +#include "stdint.h" +extern QueueHandle_t xVMQueue; +extern QueueHandle_t xMainQueue; +extern QueueHandle_t xOledQueue; +extern QueueHandle_t xCommunicationQueue; +extern QueueHandle_t xTempQueue; +extern QueueHandle_t xNumPadQueue; +extern QueueHandle_t xDCmotorQueue; + +typedef union u_data{ + int i; + float f; +} data_union; + +typedef struct _vm_data +{ + int source_id; + int target_id; + + int status; + int target_item; + + char user[4]; + char type[7]; + char name[7]; + + union u_data body[4]; + // number name type + // item 1: body[0].i name[0] type[0] + // + // temp: body[0].f + // other integer data: body[0].i + +} vm_data; + + +void vm_task(void *p_arg); + +void enQueue(vm_data); + +#endif diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/FreeRTOSConfig.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/FreeRTOSConfig.c new file mode 100644 index 00000000..88dac088 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/FreeRTOSConfig.c @@ -0,0 +1,113 @@ +/* + FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 10 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 1024 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 20 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/LED_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/LED_task.c new file mode 100644 index 00000000..e7addb4b --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/LED_task.c @@ -0,0 +1,21 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" + + +#define LED_TOGGLE_MASK BOARD_LED_MASK + +/** + * \brief Test hardware board without any peripheral + */ +void LED_task(void *p_arg) +{ + uint16_t led_toggle_val = LED_TOGGLE_MASK; + uint64_t Test = CLK_CPU; + while (1) { + led_write(led_toggle_val, BOARD_LED_MASK); + led_toggle_val = ~led_toggle_val; + board_delay_ms(500, 1); + } +} +/** @} */ \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/adt7420.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/adt7420.c new file mode 100644 index 00000000..14fb4f06 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/adt7420.c @@ -0,0 +1,274 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) 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. + + * 3) Neither the name of the Synopsys, Inc., 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 HOLDER 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. + * +--------------------------------------------- */ +/** + * \file + * \brief adt7420 pmod temperature sensor driver + */ +#include "arc.h" +#include "arc_builtin.h" +#include "embARC_toolchain.h" +#include "embARC_error.h" +#include "embARC_debug.h" + +#include "dev_iic.h" +#include "adt7420.h" +#include "board.h" + +/*! ADT7420 registers */ +enum registers { + ADT7420_REG_TEMP_MSB = 0x00, /*!< ADT7420 Temperature value MSB */ + ADT7420_REG_TEMP_LSB = 0x01, /*!< ADT7420 Temperature value LSB */ + ADT7420_REG_STATUS = 0x02, /*!< ADT7420 Status */ + ADT7420_REG_CONFIG = 0x03, /*!< ADT7420 Configuration */ + ADT7420_REG_T_HIGH_MSB = 0x04, /*!< ADT7420 Temperature HIGH set point MSB */ + ADT7420_REG_T_HIGH_LSB = 0x05, /*!< ADT7420 Temperature HIGH set point LSB */ + ADT7420_REG_T_LOW_MSB = 0x06, /*!< ADT7420 Temperature LOW set point MSB */ + ADT7420_REG_T_LOW_LSB = 0x07, /*!< ADT7420 Temperature LOW set point LSB */ + ADT7420_REG_T_CRIT_MSB = 0x08, /*!< ADT7420 Temperature CRIT set point MSB */ + ADT7420_REG_T_CRIT_LSB = 0x09, /*!< ADT7420 Temperature CRIT set point LSB */ + ADT7420_REG_HIST = 0x0A, /*!< ADT7420 Temperature HYST set point */ + ADT7420_REG_ID = 0x0B, /*!< ADT7420 ID */ + ADT7420_REG_RESET = 0x2F /*!< ADT7420 Software reset */ +}; + +/* ADT7420_REG_STATUS definition */ +#define STATUS_T_LOW (1 << 4) +#define STATUS_T_HIGH (1 << 5) +#define STATUS_T_CRIT (1 << 6) +#define STATUS_RDY (1 << 7) + +/* ADT7420_REG_CONFIG definition */ +#define ADT7420_CONFIG_FAULT_QUEUE(x) (x & 0x3) +#define ADT7420_CONFIG_CT_POL (1 << 2) +#define ADT7420_CONFIG_INT_POL (1 << 3) +#define ADT7420_CONFIG_INT_CT_MODE (1 << 4) +#define ADT7420_CONFIG_OP_MODE(x) ((x & 0x3) << 5) +#define ADT7420_CONFIG_RESOLUTION (1 << 7) + +/* ADT7420_CONFIG_FAULT_QUEUE(x) options */ +enum fault_queue { + FAULT_QUEUE_1 = 0, + FAULT_QUEUE_2 = 1, + FAULT_QUEUE_3 = 2, + FAULT_QUEUE_4 = 3 +}; + +/* ADT7420 default ID */ +#define ADT7420_DEFAULT_ID 0xCB + +#define ADT7420_CHECK_EXP_NORTN(EXPR) CHECK_EXP_NOERCD(EXPR, error_exit) + +/** + * \brief write adt7420 register + * \param[in] obj temperature sensor object + * \param[in] regaddr temperature sensor register address + * \param[in] val pointer to buffer to write + * \param[in] len length of data in buffer + * \retval >=0 write success, return bytes written + * \retval !E_OK write failed + */ +static int32_t _adt7420_reg_write(ADT7420_DEF_PTR obj, uint8_t regaddr, uint8_t *val, uint8_t len) +{ + int32_t ercd = E_PAR; + uint8_t data[1]; + DEV_IIC_PTR iic_obj = iic_get_dev(obj->i2c_id); + + dbg_printf(DBG_LESS_INFO, "[%s]%d: obj 0x%x, regaddr 0x%x, val 0x%x\r\n", __FUNCTION__, __LINE__, obj, regaddr, *val); + dbg_printf(DBG_MORE_INFO, "[%s]%d: iic_obj 0x%x -> 0x%x\r\n", __FUNCTION__, __LINE__, iic_obj, *iic_obj); + ADT7420_CHECK_EXP_NORTN(iic_obj!=NULL); + + data[0] = (uint8_t)(regaddr & 0xff); + + /** make sure set the temp sensor's slave address */ + iic_obj->iic_control(IIC_CMD_MST_SET_TAR_ADDR, CONV2VOID(obj->slvaddr)); + + ercd = iic_obj->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + ercd = iic_obj->iic_write(data, 1); + ercd = iic_obj->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); + ercd = iic_obj->iic_write(val, len); + +error_exit: + return ercd; +} + +/** + * \brief read adt7420 register + * \param[in] obj emperature sensor object + * \param[in] regaddr temperature sensor register address + * \param[in] val pointer to buffer to read + * \param[in] len length of data to read + * \retval >=0 read success, return bytes read + * \retval !E_OK read failed + */ +static int32_t _adt7420_reg_read(ADT7420_DEF_PTR obj, uint8_t regaddr, uint8_t *val, uint8_t len) +{ + int32_t ercd = E_PAR; + uint8_t data[1]; + DEV_IIC_PTR iic_obj = iic_get_dev(obj->i2c_id); + + dbg_printf(DBG_MORE_INFO, "[%s]%d: iic_obj 0x%x -> 0x%x\r\n", __FUNCTION__, __LINE__, iic_obj, *iic_obj); + ADT7420_CHECK_EXP_NORTN(iic_obj!=NULL); + + data[0] = (uint8_t)(regaddr & 0xff); + /** make sure set the temp sensor's slave address */ + iic_obj->iic_control(IIC_CMD_MST_SET_TAR_ADDR, CONV2VOID(obj->slvaddr)); + /** write register address then read register value */ + ercd = iic_obj->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + ercd = iic_obj->iic_write(data, 1); + ercd = iic_obj->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); + ercd = iic_obj->iic_read(val, len); + +error_exit: + return ercd; +} + +/** + * \brief adt7420 init + * \param[in] obj temperature sensor object + * \retval E_OK init success + * \retval !E_OK init failed + */ +int32_t adt7420_sensor_init(ADT7420_DEF_PTR obj) +{ + int32_t ercd = E_OK; + DEV_IIC_PTR iic_obj = iic_get_dev(obj->i2c_id); + + dbg_printf(DBG_MORE_INFO, "[%s]%d: iic_obj 0x%x -> 0x%x\r\n", __FUNCTION__, __LINE__, iic_obj, *iic_obj); + ADT7420_CHECK_EXP_NORTN(iic_obj!=NULL); + + ercd = iic_obj->iic_open(DEV_MASTER_MODE, IIC_SPEED_HIGH); + if ((ercd == E_OK) || (ercd == E_OPNED)) { + ercd = iic_obj->iic_control(IIC_CMD_MST_SET_TAR_ADDR, CONV2VOID(obj->slvaddr)); + /** Set to Default resolution and op_mode*/ + obj->resolution = ADT7420_RESOLUTION_13BIT; + adt7420_sensor_resolution(obj, obj->resolution); + obj->op_mode = ADT7420_OP_MODE_CONT_CONV; + adt7420_sensor_mode(obj, obj->op_mode); + } + +error_exit: + return ercd; +} + +/** + * \brief temperature sensor deinit + * \param[in] obj temperature sensor object + * \retval E_OK init success + * \retval !E_OK init failed + */ +int32_t adt7420_sensor_deinit(ADT7420_DEF_PTR obj) +{ + int32_t ercd = E_OK; + DEV_IIC_PTR iic_obj = iic_get_dev(obj->i2c_id); + ercd = iic_obj->iic_close(); + ADT7420_CHECK_EXP_NORTN(ercd == E_OK); + /*Set back to default value*/ + obj->resolution = ADT7420_RESOLUTION_13BIT; + obj->op_mode = ADT7420_OP_MODE_CONT_CONV; + +error_exit: + return ercd; +} + +/** + * \brief temperature sensor deinit + * \param[in] obj temperature sensor object + * \param[in] mode sensor working mode, choose from enum sensor_op_mode + * \retval E_OK always return E_OK + */ +int32_t adt7420_sensor_mode(ADT7420_DEF_PTR obj, int32_t mode){ + uint8_t config; + obj->op_mode = mode; + + _adt7420_reg_read(obj, ADT7420_REG_CONFIG, &config, 1); + /** set working mode bits: first clear bits to zero, then set bits to correct mode */ + config &= ~ADT7420_CONFIG_OP_MODE(0x03); + config |= ADT7420_CONFIG_OP_MODE(obj->op_mode); + _adt7420_reg_write(obj, ADT7420_REG_CONFIG, &config, 1); + return E_OK; +} + +/** + * \brief temperature sensor resolution setting + * \param[in] obj temperature sensor object + * \param[in] resolution resolution of temperature sensor + * \retval E_OK always return E_OK + */ +int32_t adt7420_sensor_resolution(ADT7420_DEF_PTR obj, int32_t resolution){ + uint8_t config; + + obj->resolution = resolution; + _adt7420_reg_read(obj, ADT7420_REG_CONFIG, &config, 1); + /** set ADT7420 resolution bit */ + if (obj->resolution == ADT7420_RESOLUTION_13BIT) { + config &= ~ADT7420_CONFIG_RESOLUTION; + } else { + config |= ADT7420_CONFIG_RESOLUTION; + } + _adt7420_reg_write(obj, ADT7420_REG_CONFIG, &config, 1); + return E_OK; +} + +/** + * \brief read temperature sensor value in 0.1c unit + * \param[in] obj temperature sensor object + * \param[out] val return temperature in degrees Celsius (°C) + * \retval E_OK read success + * \retval !E_OK read failed + */ +int32_t adt7420_sensor_read(ADT7420_DEF_PTR obj, float *val) +{ + int32_t ercd = E_OK; + uint8_t data[2]; + int16_t temp; + + ADT7420_CHECK_EXP_NORTN(val!=NULL); + + ercd = _adt7420_reg_read(obj, ADT7420_REG_TEMP_MSB, data, 2); + + if (ercd != 2) { + ercd = E_OBJ; + } else { + ercd = E_OK; + temp = ((int16_t)data[0] << 8) + ((int16_t)data[1]); + dbg_printf(DBG_MORE_INFO, "[%s]%d: data[0] 0x%x; data[1] 0x%x\r\n", __FUNCTION__, __LINE__, data[0], data[1]); + dbg_printf(DBG_LESS_INFO, "[%s]%d: temp %x\r\n", __FUNCTION__, __LINE__, temp); + /* conversion (val = temp*0.0625) for 13bits[15:3] resolution and (val = temp*0.0078) for 16bits resolution in Degrees Celsius */ + if (obj->resolution == ADT7420_RESOLUTION_13BIT) { + temp >>= 3; + *val = temp*0.0625; + } else { + *val = temp*0.0078; + } + } + +error_exit: + return ercd; +} diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/communication_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/communication_task.c new file mode 100644 index 00000000..cefdd1e8 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/communication_task.c @@ -0,0 +1,1599 @@ +#define USE_VENDINGSMACHINE2 +// alternative server choice: vendingsmachine/vendingsmachine2 + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#define mbedtls_printf printf +#define mbedtls_fprintf fprintf +#define mbedtls_snprintf snprintf +#endif + +#if !defined(MBEDTLS_ENTROPY_C) || \ + !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \ + !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_CTR_DRBG_C) +int main( void ) +{ + mbedtls_printf("MBEDTLS_ENTROPY_C and/or " + "MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or " + "MBEDTLS_NET_C and/or MBEDTLS_CTR_DRBG_C and/or not defined.\n"); + return( 0 ); +} +#else + +#include "mbedtls/net.h" +#include "mbedtls/ssl.h" +#include "mbedtls/entropy.h" +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/certs.h" +#include "mbedtls/x509.h" +#include "mbedtls/error.h" +#include "mbedtls/debug.h" +#include "mbedtls/timing.h" + +#include +#include +#include + + +#ifndef USE_VENDINGSMACHINE2 +#define DFL_SERVER_NAME "vendingsmachine.caslab.ee.ncku.edu.tw" +#define DFL_SERVER_ADDR "vendingsmachine.caslab.ee.ncku.edu.tw" +// #define DFL_SERVER_ADDR "192.168.43.4" +// #define DFL_SERVER_ADDR "140.116.164.239" +// #define DFL_REQUEST_PAGE "/arcproject/project-arc/com2arc.txt" +#define DFL_REQUEST_PAGE "/arcproject/project-arc/read.php" +//#define DFL_REQUEST_PAGE "/" +#define POST_REQUEST "POST %s HTTP/1.1\r\nHost: vendingsmachine.caslab.ee.ncku.edu.tw\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\npost=%s\t%d\t%d\t%s\t%d\t%d\t%d\t%d" +#else +#define DFL_SERVER_NAME "vendingsmachine2.caslab.ee.ncku.edu.tw" +#define DFL_SERVER_ADDR "vendingsmachine2.caslab.ee.ncku.edu.tw" +#define DFL_REQUEST_PAGE "/arc/read.php" +#define POST_REQUEST "POST %s HTTP/1.1\r\nHost: vendingsmachine2.caslab.ee.ncku.edu.tw\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\npost=%s\t%d\t%d\t%s\t%d\t%d\t%d\t%d" +#endif /* USE_VENDINGSMAHCINE2 */ + +#define POST_REQUEST_LENGTH 27 +// #define GET_REQUEST "GET %s HTTP/1.0\r\nHost: vendingsmachine.caslab.ee.ncku.edu.tw " +#define GET_REQUEST_END "\r\n\r\n" + +#define DFL_SERVER_PORT "443" + +#define DFL_REQUEST_SIZE 128 +#define DFL_DEBUG_LEVEL 0 +#define DFL_NBIO 0 +#define DFL_READ_TIMEOUT 0 +#define DFL_MAX_RESEND 0 +#define DFL_CA_FILE "" +#define DFL_CA_PATH "" +#define DFL_CRT_FILE "" +#define DFL_KEY_FILE "" +#define DFL_PSK "" +#define DFL_PSK_IDENTITY "Client_identity" +#define DFL_ECJPAKE_PW NULL +#define DFL_FORCE_CIPHER 0 +#define DFL_RENEGOTIATION MBEDTLS_SSL_RENEGOTIATION_DISABLED +#define DFL_ALLOW_LEGACY -2 +#define DFL_RENEGOTIATE 0 +#define DFL_EXCHANGES 1 +#define DFL_MIN_VERSION -1 +#define DFL_MAX_VERSION -1 +#define DFL_ARC4 -1 +#define DFL_AUTH_MODE MBEDTLS_SSL_VERIFY_OPTIONAL +#define DFL_MFL_CODE MBEDTLS_SSL_MAX_FRAG_LEN_NONE +#define DFL_TRUNC_HMAC -1 +#define DFL_RECSPLIT -1 +#define DFL_DHMLEN -1 +#define DFL_RECONNECT 1 +#define DFL_RECO_DELAY 0 +#define DFL_RECONNECT_HARD 0 +#define DFL_TICKETS MBEDTLS_SSL_SESSION_TICKETS_ENABLED +#define DFL_ALPN_STRING NULL +#define DFL_TRANSPORT MBEDTLS_SSL_TRANSPORT_STREAM +#define DFL_HS_TO_MIN 0 +#define DFL_HS_TO_MAX 0 +#define DFL_FALLBACK -1 +#define DFL_EXTENDED_MS -1 +#define DFL_ETM -1 + +#include "embARC.h" +#include "embARC_debug.h" +#include "vm_task.h" +#include "communication_task.h" + +void _Wifi_Enqueue(int target_id, WIFI_data _data) { + static int init = 1; + vm_data eq_data = {0}; + + _data.source_id = id_wifi; + _data.target_id = target_id; + + if (init == 1) + { + eq_data.source_id = id_wifi; + eq_data.target_id = _data.target_id; + strncpy(eq_data.name, _data.name[0], 6); + strncpy(eq_data.type, _data.type[0], 6); + eq_data.body[0].i = _data.body[0].i; + eq_data.target_item = 1; + enQueue(eq_data); + strncpy(eq_data.name, _data.name[1], 6); + strncpy(eq_data.type, _data.type[1], 6); + eq_data.body[1].i = _data.body[1].i; + eq_data.target_item = 2; + enQueue(eq_data); + strncpy(eq_data.name, _data.name[2], 6); + strncpy(eq_data.type, _data.type[2], 6); + eq_data.body[2].i = _data.body[2].i; + eq_data.target_item = 3; + enQueue(eq_data); + strncpy(eq_data.name, _data.name[3], 6); + strncpy(eq_data.type, _data.type[3], 6); + eq_data.body[3].i = _data.body[3].i; + eq_data.target_item = 4; + enQueue(eq_data); + + init = 0; + } + else + { + eq_data.source_id = id_wifi; + eq_data.target_id = _data.target_id; + eq_data.target_item = _data.target_item; + eq_data.status = _data.status; + strncpy(eq_data.name, _data.name[_data.target_item - 1], 6); + strncpy(eq_data.type, _data.type[_data.target_item - 1], 6); + eq_data.body[_data.target_item - 1].i = _data.body[_data.target_item - 1].i; + enQueue(eq_data); + } +} + +#if defined(MBEDTLS_X509_CRT_PARSE_C) +#if defined(MBEDTLS_FS_IO) +#define USAGE_IO \ + " ca_file=%%s The single file containing the top-level CA(s) you fully trust\n" \ + " default: \"\" (pre-loaded)\n" \ + " ca_path=%%s The path containing the top-level CA(s) you fully trust\n" \ + " default: \"\" (pre-loaded) (overrides ca_file)\n" \ + " crt_file=%%s Your own cert and chain (in bottom to top order, top may be omitted)\n" \ + " default: \"\" (pre-loaded)\n" \ + " key_file=%%s default: \"\" (pre-loaded)\n" +#else +#define USAGE_IO \ + " No file operations available (MBEDTLS_FS_IO not defined)\n" +#endif /* MBEDTLS_FS_IO */ +#else +#define USAGE_IO "" +#endif /* MBEDTLS_X509_CRT_PARSE_C */ + +#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) +#define USAGE_PSK \ + " psk=%%s default: \"\" (in hex, without 0x)\n" \ + " psk_identity=%%s default: \"Client_identity\"\n" +#else +#define USAGE_PSK "" +#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ + +#if defined(MBEDTLS_SSL_SESSION_TICKETS) +#define USAGE_TICKETS \ + " tickets=%%d default: 1 (enabled)\n" +#else +#define USAGE_TICKETS "" +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + +#if defined(MBEDTLS_SSL_TRUNCATED_HMAC) +#define USAGE_TRUNC_HMAC \ + " trunc_hmac=%%d default: library default\n" +#else +#define USAGE_TRUNC_HMAC "" +#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */ + +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) +#define USAGE_MAX_FRAG_LEN \ + " max_frag_len=%%d default: 16384 (tls default)\n" \ + " options: 512, 1024, 2048, 4096\n" +#else +#define USAGE_MAX_FRAG_LEN "" +#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ + +#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) +#define USAGE_RECSPLIT \ + " recsplit=0/1 default: (library default: on)\n" +#else +#define USAGE_RECSPLIT +#endif + +#if defined(MBEDTLS_DHM_C) +#define USAGE_DHMLEN \ + " dhmlen=%%d default: (library default: 1024 bits)\n" +#else +#define USAGE_DHMLEN +#endif + +#if defined(MBEDTLS_SSL_ALPN) +#define USAGE_ALPN \ + " alpn=%%s default: \"\" (disabled)\n" \ + " example: spdy/1,http/1.1\n" +#else +#define USAGE_ALPN "" +#endif /* MBEDTLS_SSL_ALPN */ + +#if defined(MBEDTLS_SSL_PROTO_DTLS) +#define USAGE_DTLS \ + " dtls=%%d default: 0 (TLS)\n" \ + " hs_timeout=%%d-%%d default: (library default: 1000-60000)\n" \ + " range of DTLS handshake timeouts in millisecs\n" +#else +#define USAGE_DTLS "" +#endif + +#if defined(MBEDTLS_SSL_FALLBACK_SCSV) +#define USAGE_FALLBACK \ + " fallback=0/1 default: (library default: off)\n" +#else +#define USAGE_FALLBACK "" +#endif + +#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) +#define USAGE_EMS \ + " extended_ms=0/1 default: (library default: on)\n" +#else +#define USAGE_EMS "" +#endif + +#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) +#define USAGE_ETM \ + " etm=0/1 default: (library default: on)\n" +#else +#define USAGE_ETM "" +#endif + +#if defined(MBEDTLS_SSL_RENEGOTIATION) +#define USAGE_RENEGO \ + " renegotiation=%%d default: 0 (disabled)\n" \ + " renegotiate=%%d default: 0 (disabled)\n" +#else +#define USAGE_RENEGO "" +#endif + +#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) +#define USAGE_ECJPAKE \ + " ecjpake_pw=%%s default: none (disabled)\n" +#else +#define USAGE_ECJPAKE "" +#endif + +#define USAGE \ + "\n usage: ssl_client2 param=<>...\n" \ + "\n acceptable parameters:\n" \ + " server_name=%%s default: localhost\n" \ + " server_addr=%%s default: given by name\n" \ + " server_port=%%d default: 4433\n" \ + " request_page=%%s default: \".\"\n" \ + " request_size=%%d default: about 34 (basic request)\n" \ + " (minimum: 0, max: 16384)\n" \ + " debug_level=%%d default: 0 (disabled)\n" \ + " nbio=%%d default: 0 (blocking I/O)\n" \ + " options: 1 (non-blocking), 2 (added delays)\n" \ + " read_timeout=%%d default: 0 ms (no timeout)\n" \ + " max_resend=%%d default: 0 (no resend on timeout)\n" \ + "\n" \ + USAGE_DTLS \ + "\n" \ + " auth_mode=%%s default: (library default: none)\n" \ + " options: none, optional, required\n" \ + USAGE_IO \ + "\n" \ + USAGE_PSK \ + USAGE_ECJPAKE \ + "\n" \ + " allow_legacy=%%d default: (library default: no)\n" \ + USAGE_RENEGO \ + " exchanges=%%d default: 1\n" \ + " reconnect=%%d default: 0 (disabled)\n" \ + " reco_delay=%%d default: 0 seconds\n" \ + " reconnect_hard=%%d default: 0 (disabled)\n" \ + USAGE_TICKETS \ + USAGE_MAX_FRAG_LEN \ + USAGE_TRUNC_HMAC \ + USAGE_ALPN \ + USAGE_FALLBACK \ + USAGE_EMS \ + USAGE_ETM \ + USAGE_RECSPLIT \ + USAGE_DHMLEN \ + "\n" \ + " arc4=%%d default: (library default: 0)\n" \ + " min_version=%%s default: (library default: tls1)\n" \ + " max_version=%%s default: (library default: tls1_2)\n" \ + " force_version=%%s default: \"\" (none)\n" \ + " options: ssl3, tls1, tls1_1, tls1_2, dtls1, dtls1_2\n" \ + "\n" \ + " force_ciphersuite= default: all enabled\n"\ + " acceptable ciphersuite names:\n" + +/* + * global options + */ +struct options +{ + const char *server_name; /* hostname of the server (client only) */ + const char *server_addr; /* address of the server (client only) */ + const char *server_port; /* port on which the ssl service runs */ + int debug_level; /* level of debugging */ + int nbio; /* should I/O be blocking? */ + uint32_t read_timeout; /* timeout on mbedtls_ssl_read() in milliseconds */ + int max_resend; /* DTLS times to resend on read timeout */ + const char *request_page; /* page on server to request */ + int request_size; /* pad request with header to requested size */ + const char *ca_file; /* the file with the CA certificate(s) */ + const char *ca_path; /* the path with the CA certificate(s) reside */ + const char *crt_file; /* the file with the client certificate */ + const char *key_file; /* the file with the client key */ + const char *psk; /* the pre-shared key */ + const char *psk_identity; /* the pre-shared key identity */ + const char *ecjpake_pw; /* the EC J-PAKE password */ + int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */ + int renegotiation; /* enable / disable renegotiation */ + int allow_legacy; /* allow legacy renegotiation */ + int renegotiate; /* attempt renegotiation? */ + int renego_delay; /* delay before enforcing renegotiation */ + int exchanges; /* number of data exchanges */ + int min_version; /* minimum protocol version accepted */ + int max_version; /* maximum protocol version accepted */ + int arc4; /* flag for arc4 suites support */ + int auth_mode; /* verify mode for connection */ + unsigned char mfl_code; /* code for maximum fragment length */ + int trunc_hmac; /* negotiate truncated hmac or not */ + int recsplit; /* enable record splitting? */ + int dhmlen; /* minimum DHM params len in bits */ + int reconnect; /* attempt to resume session */ + int reco_delay; /* delay in seconds before resuming session */ + int reconnect_hard; /* unexpectedly reconnect from the same port */ + int tickets; /* enable / disable session tickets */ + const char *alpn_string; /* ALPN supported protocols */ + int transport; /* TLS or DTLS? */ + uint32_t hs_to_min; /* Initial value of DTLS handshake timer */ + uint32_t hs_to_max; /* Max value of DTLS handshake timer */ + int fallback; /* is this a fallback connection? */ + int extended_ms; /* negotiate extended master secret? */ + int etm; /* negotiate encrypt then mac? */ +} opt; + +static void my_debug( void *ctx, int level, + const char *file, int line, + const char *str ) +{ + const char *p, *basename; + + /* Extract basename from file */ + for( p = basename = file; *p != '\0'; p++ ) + if( *p == '/' || *p == '\\' ) + basename = p + 1; + + mbedtls_fprintf( (FILE *) ctx, "%s:%04d: |%d| %s", basename, line, level, str ); + fflush( (FILE *) ctx ); +} + +/* + * Test recv/send functions that make sure each try returns + * WANT_READ/WANT_WRITE at least once before sucesseding + */ +static int my_recv( void *ctx, unsigned char *buf, size_t len ) +{ + static int first_try = 1; + int ret; + + if( first_try ) + { + first_try = 0; + return( MBEDTLS_ERR_SSL_WANT_READ ); + } + + ret = mbedtls_net_recv( ctx, buf, len ); + if( ret != MBEDTLS_ERR_SSL_WANT_READ ) + first_try = 1; /* Next call will be a new operation */ + return( ret ); +} + +static int my_send( void *ctx, const unsigned char *buf, size_t len ) +{ + static int first_try = 1; + int ret; + + if( first_try ) + { + first_try = 0; + return( MBEDTLS_ERR_SSL_WANT_WRITE ); + } + + ret = mbedtls_net_send( ctx, buf, len ); + if( ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + first_try = 1; /* Next call will be a new operation */ + return( ret ); +} + +#if defined(MBEDTLS_X509_CRT_PARSE_C) +/* + * Enabled if debug_level > 1 in code below + */ +static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *flags ) +{ + char buf[1024]; + ((void) data); + + mbedtls_printf( "\nVerify requested for (Depth %d):\n", depth ); + mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt ); + mbedtls_printf( "%s", buf ); + + if ( ( *flags ) == 0 ) + mbedtls_printf( " This certificate has no flags\n" ); + else + { + mbedtls_x509_crt_verify_info( buf, sizeof( buf ), " ! ", *flags ); + mbedtls_printf( "%s\n", buf ); + } + + return( 0 ); +} +#endif /* MBEDTLS_X509_CRT_PARSE_C */ + + +// for first time run, wait for wifi to up +int first = 1; + +void communication_task(void *p_arg) +// int main( int argc, char *argv[] ) +{ +while(1) +{ + EMBARC_PRINTF("entering wifi task\r\n"); + int argc = 1; + char *argv[] = {"main"}; + + // vending machine variables + char temp[6] = {'0','0','.','0','0'}; + int init = 1; + vm_data data_from_queue = {0}; + WIFI_data wifi_data = {0}; + wifi_data.user[0] = '0'; + wifi_data.user[1] = '0'; + wifi_data.user[2] = '0'; + wifi_data.user[3] = '0'; + wifi_data.user[4] = '\0'; + + + int ret = 0, len, tail_len, i, written, frags, retry_left; + mbedtls_net_context server_fd; + unsigned char buf[MBEDTLS_SSL_MAX_CONTENT_LEN + 1]; +#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) + unsigned char psk[MBEDTLS_PSK_MAX_LEN]; + size_t psk_len = 0; +#endif +#if defined(MBEDTLS_SSL_ALPN) + const char *alpn_list[10]; +#endif + const char *pers = "ssl_client2"; + + mbedtls_entropy_context entropy; + mbedtls_ctr_drbg_context ctr_drbg; + mbedtls_ssl_context ssl; + mbedtls_ssl_config conf; + mbedtls_ssl_session saved_session; +#if defined(MBEDTLS_TIMING_C) + mbedtls_timing_delay_context timer; +#endif +#if defined(MBEDTLS_X509_CRT_PARSE_C) + uint32_t flags; + mbedtls_x509_crt cacert; + mbedtls_x509_crt clicert; + mbedtls_pk_context pkey; +#endif + char *p, *q; + const int *list; + + /* + * Make sure memory references are valid. + */ + if (first == 1) + { + first = 0; + vTaskSuspend(NULL); + } + mbedtls_net_init( &server_fd ); + mbedtls_ssl_init( &ssl ); + mbedtls_ssl_config_init( &conf ); + memset( &saved_session, 0, sizeof( mbedtls_ssl_session ) ); + mbedtls_ctr_drbg_init( &ctr_drbg ); +#if defined(MBEDTLS_X509_CRT_PARSE_C) + mbedtls_x509_crt_init( &cacert ); + mbedtls_x509_crt_init( &clicert ); + mbedtls_pk_init( &pkey ); +#endif +#if defined(MBEDTLS_SSL_ALPN) + memset( (void * ) alpn_list, 0, sizeof( alpn_list ) ); +#endif + + + if( argc == 0 ) + { + usage: + if( ret == 0 ) + ret = 1; + + /* + mbedtls_printf( USAGE ); + + list = mbedtls_ssl_list_ciphersuites(); + while( *list ) + { + mbedtls_printf(" %-42s", mbedtls_ssl_get_ciphersuite_name( *list ) ); + list++; + if( !*list ) + break; + mbedtls_printf(" %s\n", mbedtls_ssl_get_ciphersuite_name( *list ) ); + list++; + } + mbedtls_printf("\n"); + + goto exit; + */ + } + + opt.server_name = DFL_SERVER_NAME; + opt.server_addr = DFL_SERVER_ADDR; + opt.server_port = DFL_SERVER_PORT; + opt.debug_level = DFL_DEBUG_LEVEL; + opt.nbio = DFL_NBIO; + opt.read_timeout = DFL_READ_TIMEOUT; + opt.max_resend = DFL_MAX_RESEND; + opt.request_page = DFL_REQUEST_PAGE; + opt.request_size = DFL_REQUEST_SIZE; + opt.ca_file = DFL_CA_FILE; + opt.ca_path = DFL_CA_PATH; + opt.crt_file = DFL_CRT_FILE; + opt.key_file = DFL_KEY_FILE; + opt.psk = DFL_PSK; + opt.psk_identity = DFL_PSK_IDENTITY; + opt.ecjpake_pw = DFL_ECJPAKE_PW; + opt.force_ciphersuite[0]= DFL_FORCE_CIPHER; + opt.renegotiation = DFL_RENEGOTIATION; + opt.allow_legacy = DFL_ALLOW_LEGACY; + opt.renegotiate = DFL_RENEGOTIATE; + opt.exchanges = DFL_EXCHANGES; + opt.min_version = DFL_MIN_VERSION; + opt.max_version = DFL_MAX_VERSION; + opt.arc4 = DFL_ARC4; + opt.auth_mode = DFL_AUTH_MODE; + opt.mfl_code = DFL_MFL_CODE; + opt.trunc_hmac = DFL_TRUNC_HMAC; + opt.recsplit = DFL_RECSPLIT; + opt.dhmlen = DFL_DHMLEN; + opt.reconnect = DFL_RECONNECT; + opt.reco_delay = DFL_RECO_DELAY; + opt.reconnect_hard = DFL_RECONNECT_HARD; + opt.tickets = DFL_TICKETS; + opt.alpn_string = DFL_ALPN_STRING; + opt.transport = DFL_TRANSPORT; + opt.hs_to_min = DFL_HS_TO_MIN; + opt.hs_to_max = DFL_HS_TO_MAX; + opt.fallback = DFL_FALLBACK; + opt.extended_ms = DFL_EXTENDED_MS; + opt.etm = DFL_ETM; + + +#if defined(MBEDTLS_DEBUG_C) + mbedtls_debug_set_threshold( opt.debug_level ); +#endif + + if( opt.force_ciphersuite[0] > 0 ) + { + const mbedtls_ssl_ciphersuite_t *ciphersuite_info; + ciphersuite_info = mbedtls_ssl_ciphersuite_from_id( opt.force_ciphersuite[0] ); + + if( opt.max_version != -1 && + ciphersuite_info->min_minor_ver > opt.max_version ) + { + mbedtls_printf("forced ciphersuite not allowed with this protocol version\n"); + ret = 2; + goto usage; + } + if( opt.min_version != -1 && + ciphersuite_info->max_minor_ver < opt.min_version ) + { + mbedtls_printf("forced ciphersuite not allowed with this protocol version\n"); + ret = 2; + goto usage; + } + + /* If the server selects a version that's not supported by + * this suite, then there will be no common ciphersuite... */ + if( opt.max_version == -1 || + opt.max_version > ciphersuite_info->max_minor_ver ) + { + opt.max_version = ciphersuite_info->max_minor_ver; + } + if( opt.min_version < ciphersuite_info->min_minor_ver ) + { + opt.min_version = ciphersuite_info->min_minor_ver; + /* DTLS starts with TLS 1.1 */ + if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && + opt.min_version < MBEDTLS_SSL_MINOR_VERSION_2 ) + opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2; + } + + /* Enable RC4 if needed and not explicitly disabled */ + if( ciphersuite_info->cipher == MBEDTLS_CIPHER_ARC4_128 ) + { + if( opt.arc4 == MBEDTLS_SSL_ARC4_DISABLED ) + { + mbedtls_printf("forced RC4 ciphersuite with RC4 disabled\n"); + ret = 2; + goto usage; + } + + opt.arc4 = MBEDTLS_SSL_ARC4_ENABLED; + } + } + +#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) + /* + * Unhexify the pre-shared key if any is given + */ + if( strlen( opt.psk ) ) + { + unsigned char c; + size_t j; + + if( strlen( opt.psk ) % 2 != 0 ) + { + mbedtls_printf("pre-shared key not valid hex\n"); + goto exit; + } + + psk_len = strlen( opt.psk ) / 2; + + for( j = 0; j < strlen( opt.psk ); j += 2 ) + { + c = opt.psk[j]; + if( c >= '0' && c <= '9' ) + c -= '0'; + else if( c >= 'a' && c <= 'f' ) + c -= 'a' - 10; + else if( c >= 'A' && c <= 'F' ) + c -= 'A' - 10; + else + { + mbedtls_printf("pre-shared key not valid hex\n"); + goto exit; + } + psk[ j / 2 ] = c << 4; + + c = opt.psk[j + 1]; + if( c >= '0' && c <= '9' ) + c -= '0'; + else if( c >= 'a' && c <= 'f' ) + c -= 'a' - 10; + else if( c >= 'A' && c <= 'F' ) + c -= 'A' - 10; + else + { + mbedtls_printf("pre-shared key not valid hex\n"); + goto exit; + } + psk[ j / 2 ] |= c; + } + } +#endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ + +#if defined(MBEDTLS_SSL_ALPN) + if( opt.alpn_string != NULL ) + { + p = (char *) opt.alpn_string; + i = 0; + + /* Leave room for a final NULL in alpn_list */ + while( i < (int) sizeof alpn_list - 1 && *p != '\0' ) + { + alpn_list[i++] = p; + + /* Terminate the current string and move on to next one */ + while( *p != ',' && *p != '\0' ) + p++; + if( *p == ',' ) + *p++ = '\0'; + } + } +#endif /* MBEDTLS_SSL_ALPN */ + + /* + * 0. Initialize the RNG and the session data + */ + mbedtls_printf( "\n . Seeding the random number generator..." ); + fflush( stdout ); + + mbedtls_entropy_init( &entropy ); + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, + (const unsigned char *) pers, + strlen( pers ) ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", -ret ); + goto exit; + } + + mbedtls_printf( " ok\n" ); + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + /* + * 1.1. Load the trusted CA + */ + mbedtls_printf( " . Loading the CA root certificate ..." ); + fflush( stdout ); + +#if defined(MBEDTLS_FS_IO) + if( strlen( opt.ca_path ) ) + if( strcmp( opt.ca_path, "none" ) == 0 ) + ret = 0; + else + ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); + else if( strlen( opt.ca_file ) ) + if( strcmp( opt.ca_file, "none" ) == 0 ) + ret = 0; + else + ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); + else +#endif +#if defined(MBEDTLS_CERTS_C) + for( i = 0; mbedtls_test_cas[i] != NULL; i++ ) + { + ret = mbedtls_x509_crt_parse( &cacert, + (const unsigned char *) mbedtls_test_cas[i], + mbedtls_test_cas_len[i] ); + if( ret != 0 ) + break; + } +#else + { + ret = 1; + mbedtls_printf("MBEDTLS_CERTS_C not defined."); + } +#endif + if( ret < 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); + goto exit; + } + + mbedtls_printf( " ok (%d skipped)\n", ret ); + + /* + * 1.2. Load own certificate and private key + * + * (can be skipped if client authentication is not required) + */ + mbedtls_printf( " . Loading the client cert. and key..." ); + fflush( stdout ); + +#if defined(MBEDTLS_FS_IO) + if( strlen( opt.crt_file ) ) + if( strcmp( opt.crt_file, "none" ) == 0 ) + ret = 0; + else + ret = mbedtls_x509_crt_parse_file( &clicert, opt.crt_file ); + else +#endif +#if defined(MBEDTLS_CERTS_C) + ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt, + mbedtls_test_cli_crt_len ); +#else + { + ret = 1; + mbedtls_printf("MBEDTLS_CERTS_C not defined."); + } +#endif + if( ret != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); + goto exit; + } + +#if defined(MBEDTLS_FS_IO) + if( strlen( opt.key_file ) ) + if( strcmp( opt.key_file, "none" ) == 0 ) + ret = 0; + else + ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file, "" ); + else +#endif +#if defined(MBEDTLS_CERTS_C) + ret = mbedtls_pk_parse_key( &pkey, (const unsigned char *) mbedtls_test_cli_key, + mbedtls_test_cli_key_len, NULL, 0 ); +#else + { + ret = 1; + mbedtls_printf("MBEDTLS_CERTS_C not defined."); + } +#endif + if( ret != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_pk_parse_key returned -0x%x\n\n", -ret ); + goto exit; + } + + mbedtls_printf( " ok\n" ); +#endif /* MBEDTLS_X509_CRT_PARSE_C */ + + /* + * 2. Start the connection + */ + if( opt.server_addr == NULL) + opt.server_addr = opt.server_name; + + mbedtls_printf( " . Connecting to %s/%s/%s...", + opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? "tcp" : "udp", + opt.server_addr, opt.server_port ); + fflush( stdout ); + + if( ( ret = mbedtls_net_connect( &server_fd, opt.server_addr, opt.server_port, + opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? + MBEDTLS_NET_PROTO_TCP : MBEDTLS_NET_PROTO_UDP ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_net_connect returned -0x%x\n\n", -ret ); + goto exit; + } + + if( opt.nbio > 0 ) + ret = mbedtls_net_set_nonblock( &server_fd ); + else + ret = mbedtls_net_set_block( &server_fd ); + if( ret != 0 ) + { + mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret ); + goto exit; + } + + mbedtls_printf( " ok\n" ); + + /* + * 3. Setup stuff + */ + mbedtls_printf( " . Setting up the SSL/TLS structure..." ); + fflush( stdout ); + + if( ( ret = mbedtls_ssl_config_defaults( &conf, + MBEDTLS_SSL_IS_CLIENT, + opt.transport, + MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned -0x%x\n\n", -ret ); + goto exit; + } + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + if( opt.debug_level > 0 ) + mbedtls_ssl_conf_verify( &conf, my_verify, NULL ); +#endif + + //if( opt.auth_mode != DFL_AUTH_MODE ) + if( opt.auth_mode != -1 ) + mbedtls_ssl_conf_authmode( &conf, opt.auth_mode ); + +#if defined(MBEDTLS_SSL_PROTO_DTLS) + if( opt.hs_to_min != DFL_HS_TO_MIN || opt.hs_to_max != DFL_HS_TO_MAX ) + mbedtls_ssl_conf_handshake_timeout( &conf, opt.hs_to_min, opt.hs_to_max ); +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) + if( ( ret = mbedtls_ssl_conf_max_frag_len( &conf, opt.mfl_code ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_conf_max_frag_len returned %d\n\n", ret ); + goto exit; + } +#endif + +#if defined(MBEDTLS_SSL_TRUNCATED_HMAC) + if( opt.trunc_hmac != DFL_TRUNC_HMAC ) + mbedtls_ssl_conf_truncated_hmac( &conf, opt.trunc_hmac ); +#endif + +#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) + if( opt.extended_ms != DFL_EXTENDED_MS ) + mbedtls_ssl_conf_extended_master_secret( &conf, opt.extended_ms ); +#endif + +#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) + if( opt.etm != DFL_ETM ) + mbedtls_ssl_conf_encrypt_then_mac( &conf, opt.etm ); +#endif + +#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) + if( opt.recsplit != DFL_RECSPLIT ) + mbedtls_ssl_conf_cbc_record_splitting( &conf, opt.recsplit + ? MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED + : MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED ); +#endif + +#if defined(MBEDTLS_DHM_C) + if( opt.dhmlen != DFL_DHMLEN ) + mbedtls_ssl_conf_dhm_min_bitlen( &conf, opt.dhmlen ); +#endif + +#if defined(MBEDTLS_SSL_ALPN) + if( opt.alpn_string != NULL ) + if( ( ret = mbedtls_ssl_conf_alpn_protocols( &conf, alpn_list ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_conf_alpn_protocols returned %d\n\n", ret ); + goto exit; + } +#endif + + mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); + mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); + + mbedtls_ssl_conf_read_timeout( &conf, opt.read_timeout ); + +#if defined(MBEDTLS_SSL_SESSION_TICKETS) + mbedtls_ssl_conf_session_tickets( &conf, opt.tickets ); +#endif + + if( opt.force_ciphersuite[0] != DFL_FORCE_CIPHER ) + mbedtls_ssl_conf_ciphersuites( &conf, opt.force_ciphersuite ); + +#if defined(MBEDTLS_ARC4_C) + if( opt.arc4 != DFL_ARC4 ) + mbedtls_ssl_conf_arc4_support( &conf, opt.arc4 ); +#endif + + if( opt.allow_legacy != DFL_ALLOW_LEGACY ) + mbedtls_ssl_conf_legacy_renegotiation( &conf, opt.allow_legacy ); +#if defined(MBEDTLS_SSL_RENEGOTIATION) + mbedtls_ssl_conf_renegotiation( &conf, opt.renegotiation ); +#endif + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + if( strcmp( opt.ca_path, "none" ) != 0 && + strcmp( opt.ca_file, "none" ) != 0 ) + { + mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL ); + } + if( strcmp( opt.crt_file, "none" ) != 0 && + strcmp( opt.key_file, "none" ) != 0 ) + { + if( ( ret = mbedtls_ssl_conf_own_cert( &conf, &clicert, &pkey ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_conf_own_cert returned %d\n\n", ret ); + goto exit; + } + } +#endif + +#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) + if( ( ret = mbedtls_ssl_conf_psk( &conf, psk, psk_len, + (const unsigned char *) opt.psk_identity, + strlen( opt.psk_identity ) ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_conf_psk returned %d\n\n", ret ); + goto exit; + } +#endif + + if( opt.min_version != DFL_MIN_VERSION ) + mbedtls_ssl_conf_min_version( &conf, MBEDTLS_SSL_MAJOR_VERSION_3, opt.min_version ); + + if( opt.max_version != DFL_MAX_VERSION ) + mbedtls_ssl_conf_max_version( &conf, MBEDTLS_SSL_MAJOR_VERSION_3, opt.max_version ); + +#if defined(MBEDTLS_SSL_FALLBACK_SCSV) + if( opt.fallback != DFL_FALLBACK ) + mbedtls_ssl_conf_fallback( &conf, opt.fallback ); +#endif + + if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", -ret ); + goto exit; + } + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + if( ( ret = mbedtls_ssl_set_hostname( &ssl, opt.server_name ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret ); + goto exit; + } +#endif + +#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) + if( opt.ecjpake_pw != DFL_ECJPAKE_PW ) + { + if( ( ret = mbedtls_ssl_set_hs_ecjpake_password( &ssl, + (const unsigned char *) opt.ecjpake_pw, + strlen( opt.ecjpake_pw ) ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_set_hs_ecjpake_password returned %d\n\n", ret ); + goto exit; + } + } +#endif + + if( opt.nbio == 2 ) + mbedtls_ssl_set_bio( &ssl, &server_fd, my_send, my_recv, NULL ); + else + mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, + opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL ); + +#if defined(MBEDTLS_TIMING_C) + mbedtls_ssl_set_timer_cb( &ssl, &timer, mbedtls_timing_set_delay, + mbedtls_timing_get_delay ); +#endif + + mbedtls_printf( " ok\n" ); + + /* + * 4. Handshake + */ + mbedtls_printf( " . Performing the SSL/TLS handshake..." ); + fflush( stdout ); + + while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 ) + { + if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n", -ret ); + if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) + mbedtls_printf( + " Unable to verify the server's certificate. " + "Either it is invalid,\n" + " or you didn't set ca_file or ca_path " + "to an appropriate value.\n" + " Alternatively, you may want to use " + "auth_mode=optional for testing purposes.\n" ); + mbedtls_printf( "\n" ); + goto exit; + } + } + + mbedtls_printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n", + mbedtls_ssl_get_version( &ssl ), mbedtls_ssl_get_ciphersuite( &ssl ) ); + + if( ( ret = mbedtls_ssl_get_record_expansion( &ssl ) ) >= 0 ) + mbedtls_printf( " [ Record expansion is %d ]\n", ret ); + else + mbedtls_printf( " [ Record expansion is unknown (compression) ]\n" ); + +#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) + mbedtls_printf( " [ Maximum fragment length is %u ]\n", + (unsigned int) mbedtls_ssl_get_max_frag_len( &ssl ) ); +#endif + +#if defined(MBEDTLS_SSL_ALPN) + if( opt.alpn_string != NULL ) + { + const char *alp = mbedtls_ssl_get_alpn_protocol( &ssl ); + mbedtls_printf( " [ Application Layer Protocol is %s ]\n", + alp ? alp : "(none)" ); + } +#endif + + if( opt.reconnect != 0 ) + { + mbedtls_printf(" . Saving session for reuse..." ); + fflush( stdout ); + + if( ( ret = mbedtls_ssl_get_session( &ssl, &saved_session ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_get_session returned -0x%x\n\n", -ret ); + goto exit; + } + + mbedtls_printf( " ok\n" ); + } + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + /* + * 5. Verify the server certificate + */ + mbedtls_printf( " . Verifying peer X.509 certificate..." ); + + if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 ) + { + char vrfy_buf[512]; + + mbedtls_printf( " failed\n" ); + + mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags ); + + mbedtls_printf( "%s\n", vrfy_buf ); + } + else + mbedtls_printf( " ok\n" ); + + if( mbedtls_ssl_get_peer_cert( &ssl ) != NULL ) + { + mbedtls_printf( " . Peer certificate information ...\n" ); + mbedtls_x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ", + mbedtls_ssl_get_peer_cert( &ssl ) ); + mbedtls_printf( "%s\n", buf ); + } +#endif /* MBEDTLS_X509_CRT_PARSE_C */ + +#if defined(MBEDTLS_SSL_RENEGOTIATION) + if( opt.renegotiate ) + { + /* + * Perform renegotiation (this must be done when the server is waiting + * for input from our side). + */ + mbedtls_printf( " . Performing renegotiation..." ); + fflush( stdout ); + while( ( ret = mbedtls_ssl_renegotiate( &ssl ) ) != 0 ) + { + if( ret != MBEDTLS_ERR_SSL_WANT_READ && + ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_renegotiate returned %d\n\n", ret ); + goto exit; + } + } + mbedtls_printf( " ok\n" ); + } +#endif /* MBEDTLS_SSL_RENEGOTIATION */ + + /* + * 6. Write the GET request or POST request + */ + retry_left = opt.max_resend; + + send_request: + mbedtls_printf( " > Write to server:" ); + fflush( stdout ); + + + if (xTempQueue != 0) + if( xQueueReceive( xTempQueue, &data_from_queue, 0 ) ) + { + if (data_from_queue.source_id == id_temp) + { + EMBARC_PRINTF("\r\n ## receive data from temp...\r\n"); + // strncpy(temp, "00.00", 5); + sprintf(temp, "%*.*lf", 2, 2, data_from_queue.body[0].f); + } + } + if (xCommunicationQueue != 0) + if( xQueueReceive( xCommunicationQueue, &data_from_queue, 0 ) ) + { + if (data_from_queue.source_id == id_main) + { + EMBARC_PRINTF("\r\n ## receive data from main...\r\n"); + /* + if (data_from_queue.target_item != no_item) + { + strncpy(wifi_data.type[data_from_queue.target_item - 1], data_from_queue.type, 6); + strncpy(wifi_data.name[data_from_queue.target_item - 1], data_from_queue.name, 6); + } + */ + wifi_data.status = data_from_queue.status; + wifi_data.target_item = data_from_queue.target_item; + strncpy(wifi_data.user, data_from_queue.user, 4); + + for ( int i = 0; i < 4; i++ ) + wifi_data.body[i].i = data_from_queue.body[i].i; + } + } + + if (init == 0) + { + len = mbedtls_snprintf( (char *) buf, MBEDTLS_SSL_MAX_CONTENT_LEN, POST_REQUEST, opt.request_page, POST_REQUEST_LENGTH, + temp, wifi_data.target_item, wifi_data.status, wifi_data.user, + wifi_data.body[0].i, wifi_data.body[1].i, wifi_data.body[2].i, wifi_data.body[3].i); + tail_len = (int) strlen( GET_REQUEST_END ); + } + else{ + len = mbedtls_snprintf( (char *) buf, MBEDTLS_SSL_MAX_CONTENT_LEN, POST_REQUEST, opt.request_page, POST_REQUEST_LENGTH, + "00.00", wifi_data.target_item, wifi_data.status, wifi_data.user, + wifi_data.body[0].i, wifi_data.body[1].i, wifi_data.body[2].i, wifi_data.body[3].i); + tail_len = (int) strlen( GET_REQUEST_END ); + } + + /* Add padding to GET request to reach opt.request_size in length */ + if( opt.request_size != DFL_REQUEST_SIZE && + len + tail_len < opt.request_size ) + { + memset( buf + len, 'A', opt.request_size - len - tail_len ); + len += opt.request_size - len - tail_len; + } + + strncpy( (char *) buf + len, GET_REQUEST_END, MBEDTLS_SSL_MAX_CONTENT_LEN - len ); + len += tail_len; + + /* Truncate if request size is smaller than the "natural" size */ + if( opt.request_size != DFL_REQUEST_SIZE && + len > opt.request_size ) + { + len = opt.request_size; + + /* Still end with \r\n unless that's really not possible */ + if( len >= 2 ) buf[len - 2] = '\r'; + if( len >= 1 ) buf[len - 1] = '\n'; + } + + if( opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ) + { + for( written = 0, frags = 0; written < len; written += ret, frags++ ) + { + while( ( ret = mbedtls_ssl_write( &ssl, buf + written, len - written ) ) + <= 0 ) + { + if( ret != MBEDTLS_ERR_SSL_WANT_READ && + ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_write returned -0x%x\n\n", -ret ); + goto exit; + } + } + } + } + else /* Not stream, so datagram */ + { + do ret = mbedtls_ssl_write( &ssl, buf, len ); + while( ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE ); + + if( ret < 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret ); + goto exit; + } + + frags = 1; + written = ret; + } + + buf[written] = '\0'; + mbedtls_printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf ); + + /* + * 7. Read the HTTP response + */ + mbedtls_printf( " < Read from server:" ); + fflush( stdout ); + + /* + * TLS and DTLS need different reading styles (stream vs datagram) + */ + if( opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ) + { + do + { + len = sizeof( buf ) - 1; + memset( buf, 0, sizeof( buf ) ); + ret = mbedtls_ssl_read( &ssl, buf, len ); + + if( ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE ) + continue; + + if( ret <= 0 ) + { + switch( ret ) + { + case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: + mbedtls_printf( " connection was closed gracefully\n" ); + ret = 0; + goto close_notify; + + case 0: + case MBEDTLS_ERR_NET_CONN_RESET: + mbedtls_printf( " connection was reset by peer\n" ); + ret = 0; + goto reconnect; + + default: + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + goto exit; + } + } + + len = ret; + buf[len] = '\0'; + mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf ); + + /* + * decode the information receive from the server + */ + // EMBARC_PRINTF("%c%c%c", buf[9], buf[10], buf[11]); + if (buf[9] == '2' && buf[10] == '0' && buf[11] == '0') // if response from server is "200 OK" + { + if (init == 1) + { + init = 0; + // wifi_data.status = 1; // test for balance check + // wifi_data.target_item = 1; // test for balance check +#ifndef USE_VENDINGSMACHINE2 + wifi_data.target_item = (int)buf[198] - 48; + wifi_data.status = (int)buf[200] - 48; + strncpy(wifi_data.user, buf + 202, 4); + strncpy(wifi_data.name[0], buf + 209, 6); + strncpy(wifi_data.type[0], buf + 219, 6); + wifi_data.body[0].i = buf[238] - 48; + strncpy(wifi_data.name[1], buf + 242, 6); + strncpy(wifi_data.type[1], buf + 252, 6); + wifi_data.body[1].i = buf[271] - 48; + strncpy(wifi_data.name[2], buf + 275, 6); + strncpy(wifi_data.type[2], buf + 285, 6); + wifi_data.body[2].i = buf[304] - 48; + strncpy(wifi_data.name[3], buf + 308, 6); + strncpy(wifi_data.type[3], buf + 318, 6); + wifi_data.body[3].i = buf[337] - 48; +#else + // wifi_data.target_item = (int)buf[200] - 48; + // wifi_data.status = (int)buf[202] - 48; + // strncpy(wifi_data.user, buf + 204, 4); + strncpy(wifi_data.name[0], buf + 211, 6); + strncpy(wifi_data.type[0], buf + 221, 6); + wifi_data.body[0].i = buf[240] - 48; + strncpy(wifi_data.name[1], buf + 244, 6); + strncpy(wifi_data.type[1], buf + 254, 6); + wifi_data.body[1].i = buf[273] - 48; + strncpy(wifi_data.name[2], buf + 277, 6); + strncpy(wifi_data.type[2], buf + 287, 6); + wifi_data.body[2].i = buf[306] - 48; + strncpy(wifi_data.name[3], buf + 310, 6); + strncpy(wifi_data.type[3], buf + 320, 6); + wifi_data.body[3].i = buf[339] - 48; +#endif /* USE_VENDINGSMACHINE2 */ + } + else{ +#ifndef USE_VENDINGSMACHINE2 + wifi_data.target_item = (int)buf[198] - 48; + wifi_data.status = (int)buf[200] - 48; + // strncpy(wifi_data.user, buf + 202, 4); +#else + wifi_data.target_item = (int)buf[200] - 48; + wifi_data.status = (int)buf[202] - 48; + // strncpy(wifi_data.user, buf + 204, 4); +#endif + } + //--wifi_data.body[wifi_data.target_item - 1].i; + // decrease the number of item if buying + } + + _Wifi_Enqueue(id_main, wifi_data); + + EMBARC_PRINTF("\r\n\r\n$$$$$$$ check the value reading from wifi connection $$$$$$$\r\n\r\n"); + EMBARC_PRINTF("\t target item: %d\r\n", wifi_data.target_item); + EMBARC_PRINTF("\t status : %d\r\n", wifi_data.status); + EMBARC_PRINTF("\t user : %s\r\n", wifi_data.user); + EMBARC_PRINTF("\t name 1: %s, type 1: %s, #: %d\r\n", wifi_data.name[0], wifi_data.type[0], wifi_data.body[0].i); + EMBARC_PRINTF("\t name 2: %s, type 2: %s, #: %d\r\n", wifi_data.name[1], wifi_data.type[1], wifi_data.body[1].i); + EMBARC_PRINTF("\t name 3: %s, type 3: %s, #: %d\r\n", wifi_data.name[2], wifi_data.type[2], wifi_data.body[2].i); + EMBARC_PRINTF("\t name 4: %s, type 4: %s, #: %d\r\n", wifi_data.name[3], wifi_data.type[3], wifi_data.body[3].i); + EMBARC_PRINTF("\r\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\r\n\r\n"); + vTaskSuspend(NULL); + + // just for pausing putty output + // console_getchar(); + + /* End of message should be detected according to the syntax of the + * application protocol (eg HTTP), just use a dummy test here. */ + if( ret > 0 && buf[len-1] == '\n' ) + { + ret = 0; + break; + } + } + while( 1 ); + } + else /* Not stream, so datagram */ + { + len = sizeof( buf ) - 1; + memset( buf, 0, sizeof( buf ) ); + + do ret = mbedtls_ssl_read( &ssl, buf, len ); + while( ret == MBEDTLS_ERR_SSL_WANT_READ || + ret == MBEDTLS_ERR_SSL_WANT_WRITE ); + + if( ret <= 0 ) + { + switch( ret ) + { + case MBEDTLS_ERR_SSL_TIMEOUT: + mbedtls_printf( " timeout\n" ); + if( retry_left-- > 0 ) + goto send_request; + goto exit; + + case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: + mbedtls_printf( " connection was closed gracefully\n" ); + ret = 0; + goto close_notify; + + default: + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + goto exit; + } + } + + len = ret; + buf[len] = '\0'; + mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf ); + ret = 0; + } + + /* + * 7b. Simulate hard reset and reconnect from same port? + */ + if( opt.reconnect_hard != 0 ) + { + opt.reconnect_hard = 0; + + mbedtls_printf( " . Restarting connection from same port..." ); + fflush( stdout ); + + if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n", -ret ); + goto exit; + } + + while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 ) + { + if( ret != MBEDTLS_ERR_SSL_WANT_READ && + ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + goto exit; + } + } + + mbedtls_printf( " ok\n" ); + + goto send_request; + } + + memset(buf, 0, MBEDTLS_SSL_MAX_CONTENT_LEN); +/* +#ifdef OS_FREERTOS + EMBARC_PRINTF(" . Waiting 1s for next data exchange...\r\n"); + vTaskDelay(1000); +#endif +*/ + + /* + * 7c. Continue doing data exchanges? + */ + if( opt.exchanges > 0 ) + goto send_request; + + /* + * 8. Done, cleanly close the connection + */ +close_notify: + mbedtls_printf( " . Closing the connection..." ); + fflush( stdout ); + + /* No error checking, the connection might be closed already */ + do ret = mbedtls_ssl_close_notify( &ssl ); + while( ret == MBEDTLS_ERR_SSL_WANT_WRITE ); + ret = 0; + + mbedtls_printf( " done\n" ); + + /* + * 9. Reconnect? + */ +reconnect: + if( opt.reconnect != 0 ) + { + // --opt.reconnect; + + mbedtls_net_free( &server_fd ); + +#if defined(MBEDTLS_TIMING_C) + if( opt.reco_delay > 0 ) + mbedtls_net_usleep( 1000000 * opt.reco_delay ); +#endif + + mbedtls_printf( " . Reconnecting with saved session..." ); + + if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n", -ret ); + goto exit; + } + + if( ( ret = mbedtls_ssl_set_session( &ssl, &saved_session ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_conf_session returned %d\n\n", ret ); + goto exit; + } + + if( ( ret = mbedtls_net_connect( &server_fd, opt.server_addr, opt.server_port, + opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? + MBEDTLS_NET_PROTO_TCP : MBEDTLS_NET_PROTO_UDP ) ) != 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_net_connect returned -0x%x\n\n", -ret ); + goto exit; + } + + if( opt.nbio > 0 ) + ret = mbedtls_net_set_nonblock( &server_fd ); + else + ret = mbedtls_net_set_block( &server_fd ); + if( ret != 0 ) + { + mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", + -ret ); + goto exit; + } + + while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 ) + { + if( ret != MBEDTLS_ERR_SSL_WANT_READ && + ret != MBEDTLS_ERR_SSL_WANT_WRITE ) + { + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + goto exit; + } + } + + mbedtls_printf( " ok\n" ); + + goto send_request; + } + + /* + * Cleanup and exit + */ +exit: +#ifdef MBEDTLS_ERROR_C + if( ret != 0 ) + { + char error_buf[100]; + mbedtls_strerror( ret, error_buf, 100 ); + mbedtls_printf("Last error was: -0x%X - %s\n\n", -ret, error_buf ); + } +#endif + + mbedtls_net_free( &server_fd ); + +#if defined(MBEDTLS_X509_CRT_PARSE_C) + mbedtls_x509_crt_free( &clicert ); + mbedtls_x509_crt_free( &cacert ); + mbedtls_pk_free( &pkey ); +#endif + mbedtls_ssl_session_free( &saved_session ); + mbedtls_ssl_free( &ssl ); + mbedtls_ssl_config_free( &conf ); + mbedtls_ctr_drbg_free( &ctr_drbg ); + mbedtls_entropy_free( &entropy ); + +#if defined(_WIN32) + mbedtls_printf( " + Press Enter to exit this program.\n" ); + fflush( stdout ); getchar(); +#endif + + // Shell can not handle large exit numbers -> 1 for errors + if( ret < 0 ) + ret = 1; + +// return( ret ); + + // for FREERTOS, it doesn't allow the task to exit itself + EMBARC_PRINTF("\r\n.........................................\r\n"); + EMBARC_PRINTF("\r\nProgram failed, restart the wifi connection.\r\n"); + EMBARC_PRINTF("\r\n.........................................\r\n\r\n"); +#ifdef OS_FREERTOS + EMBARC_PRINTF(" . Waiting 3s for next data exchange...\r\n"); + vTaskDelay(3000); +#endif +} +} +#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C && + MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C && + MBEDTLS_CTR_DRBG_C MBEDTLS_TIMING_C */ diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/dcmotor_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/dcmotor_task.c new file mode 100644 index 00000000..e0d8d009 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/dcmotor_task.c @@ -0,0 +1,63 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" + +#define OBJECT_NOT_DROP 0 +#define OBJECT_DROP 1 + +static DEV_GPIO *dc_motor; +static DEV_GPIO *infrared_ray; + + +void dcmotor_task(void *p_arg) +{ + vm_data dcmotor_data = {0}; + EMBARC_PRINTF("entering dc motor task\r\n"); + + dc_motor = gpio_get_dev(DW_GPIO_PORT_C); + //dc_motor->gpio_close(); /* opened before now close it */ + dc_motor->gpio_open(0x0f00); //only open pin1~4:motor1 portc[8] + dc_motor->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)(0x0f00)); + dc_motor->gpio_write(0x00, 0x0f00); + + infrared_ray = gpio_get_dev(DW_GPIO_PORT_A); + infrared_ray->gpio_open(0x0f00); + infrared_ray->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)(0x0f00)); + + int motor = 0; + bool product = OBJECT_NOT_DROP; + uint32_t motor_spining; + while(1){ + if( xDCmotorQueue != 0 ) + { + if( xQueueReceive( xDCmotorQueue, &dcmotor_data, portMAX_DELAY ) ) + { + motor = dcmotor_data.body[0].i; + // EMBARC_PRINTF("=========================> motor receive from numpad: %d\r\n", motor); + } + } + + + if(motor == 1) dc_motor->gpio_write(0x0100, 0x0f00); + else if(motor == 2) dc_motor->gpio_write(0x0200, 0x0f00); + //else if(motor == 3) dc_motor->gpio_write(0x0400, 0x0f00); + //else if(motor == 4) dc_motor->gpio_write(0x0800, 0x0f00); + else dc_motor->gpio_write(0x0000, 0x0f00); + + + while(1){ + vTaskDelay(1); + infrared_ray->gpio_read(&motor_spining, 0x0f00); + // EMBARC_PRINTF("object %d\r\n", motor_spining && 0x0100); + if(motor_spining && 0x0100) product = OBJECT_NOT_DROP; // no object drop + else product = OBJECT_DROP;// object drop + if (product == OBJECT_DROP) { + dc_motor->gpio_write(0x0000, 0x0f00); + motor = 5; + break; + } + } + + vTaskDelay(1000); + } +} diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/numpad_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/numpad_task.c new file mode 100644 index 00000000..e6d99e4b --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/numpad_task.c @@ -0,0 +1,100 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" + +#include "vm_task.h" + +#define J3_PIN7to10_MASK_A 0xf0000 +#define J3_PIN1to4_MASK_C 0xf0000 +#define false 0 +#define true 1 +#define debounce_start_on 2 +#define debounce_start_off 3 + +static inline void _Npad_Enqueue(int target_id, int user_input) { + vm_data _data = {0}; + + _data.source_id = id_numpad; + _data.target_id = target_id; + _data.body[0].i = user_input; + enQueue(_data); +} + +// 要設計讓使用者輸入 帳號 和 要買的物品 + +typedef struct _button_status{ + int ispress; + uint64_t press_time; + uint64_t release_time; +} button_status; + +const static char Numpad_Convert[] = { + '1', '2', '3', 'A', + '4', '5', '6', 'B', + '7', '8', '9', 'C', + '*', '0', '#', 'D' +}; + +static button_status Numpad_table[4][4] = {0}; +static DEV_GPIO_PTR numpad_row; +static DEV_GPIO_PTR numpad_col; + +void numpad_task(void *p_arg) +{ + EMBARC_PRINTF("enter num_pad task\r\n"); + + numpad_row = gpio_get_dev(DW_GPIO_PORT_C); + numpad_col = gpio_get_dev(DW_GPIO_PORT_A); + numpad_row->gpio_close(); /* opened before now close it */ + numpad_col->gpio_close(); /* opened before now close it */ + numpad_row->gpio_open(J3_PIN1to4_MASK_C); + numpad_col->gpio_open(J3_PIN7to10_MASK_A); + + numpad_row->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)(J3_PIN1to4_MASK_C)); + numpad_col->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)(J3_PIN7to10_MASK_A)); + + numpad_row->gpio_write(0x00000000, J3_PIN1to4_MASK_C); + numpad_col->gpio_write(0xf0000, J3_PIN7to10_MASK_A); + + uint32_t data; + uint32_t buffer; + + int i, j; + + while(1){ + for(i= 0; i < 4; i ++){ + //scan 4 rows + + numpad_row->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)(0x10000 << i)); + numpad_row->gpio_write(0x00000000, J3_PIN1to4_MASK_C); + vTaskDelay(1); + numpad_col->gpio_read(&data, J3_PIN7to10_MASK_A); + + for(j= 0; j < 4; j ++){ + //scan 4 rows + if(data & (0x10000 << j)) {//Not press + + if(Numpad_table[i][j].ispress == true){ + Numpad_table[i][j].release_time = board_get_cur_us(); + //EMBARC_PRINTF("%d,%d\r\n",i,j); + if((Numpad_table[i][j].release_time - Numpad_table[i][j].press_time) >= 100000ul) { + // EMBARC_PRINTF("%c\n", Numpad_Convert[i*4+j]); + _Npad_Enqueue(id_main, (int) Numpad_Convert[i*4+j]); + // _Npad_Enqueue(id_oled, (int) Numpad_Convert[i*4+j]); + // _Npad_Enqueue(id_dcmotor, (int) Numpad_Convert[i*4+j] - 48); + } + Numpad_table[i][j].ispress = false; + } + } else {//Press + if(Numpad_table[i][j].ispress == false) { + Numpad_table[i][j].press_time = board_get_cur_us(); + Numpad_table[i][j].ispress = true; + } + } + + } + numpad_row->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)(J3_PIN1to4_MASK_C)); + } + vTaskDelay(0); + } +} \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/oled_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/oled_task.c new file mode 100644 index 00000000..7dd6393b --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/oled_task.c @@ -0,0 +1,293 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" + +/* middleware level */ +#include "u8g.h" +#include "vm_task.h" + +u8g_t u8g; + +// ******************************************************************************** +// variables used for vending machine, indicate the info for all 4 items +char name[7] = "Chips"; +char type[7] = {0}; +char temp[5] = {"31.75"}; +char user[4] = {"5013"}; +int number[4] = {1, 2, 3, 4}; +int oled_status = 0; +int user_receive_status = 0; +vm_data oled_data = {0}; + +enum oled_status_list { + normal = 0, input_1, input_2, input_3, input_4, recommand, check, confirm +}; +// ******************************************************************************** + +void u8g_prepare(void) { + u8g_SetFont(&u8g, u8g_font_6x10); /* set the current font and reset the font reference position to "Baseline" */ + u8g_SetFontRefHeightExtendedText(&u8g); /* define the calculation method for the ascent and descent of the current font */ + u8g_SetDefaultForegroundColor(&u8g); /* assign one of the default colors as current color index */ + u8g_SetFontPosTop(&u8g); /* set the reference position for the character and string draw procedure */ +} + +/** first page in OLED */ +void u8g_box_frame(uint8_t a) { + u8g_DrawStr(&u8g, 0, 0, "embARC"); /* draws a string at the specified x/y position */ + u8g_DrawBox(&u8g, 5,10,20,10); /* draw a box (filled frame), starting at x/y position (upper left edge) */ + u8g_DrawBox(&u8g, 10+a,15,30,7); + u8g_DrawStr(&u8g, 0, 30, "drawFrame"); + u8g_DrawFrame(&u8g, 5,10+30,20,10); /* draw a frame, starting at x/y position (upper left edge) */ + u8g_DrawFrame(&u8g, 10+a,15+30,30,7); +} + +/** second page in OLED */ +void u8g_string(uint8_t a) { + u8g_DrawStr(&u8g, 30+a,31, " 0"); + u8g_DrawStr90(&u8g, 30,31+a, " 90"); /* rotate string output by 90 degree */ + u8g_DrawStr180(&u8g, 30-a,31, " 180"); /* rotate string output by 180 degree */ + u8g_DrawStr270(&u8g, 30,31-a, " 270"); /* rotate string output by 270 degree */ +} + +/** third page in OLED */ +void u8g_line(uint8_t a) { + u8g_DrawStr(&u8g, 0, 0, "drawLine"); + u8g_DrawLine(&u8g, 7+a, 10, 40, 55); /* draw a line from (x1, y1) to (x2, y2) */ + u8g_DrawLine(&u8g, 7+a*2, 10, 60, 55); + u8g_DrawLine(&u8g, 7+a*3, 10, 80, 55); + u8g_DrawLine(&u8g, 7+a*4, 10, 100, 55); +} + +/** forth page in OLED */ +void u8g_ascii_1(void) { + char s[2] = " "; + uint8_t x, y; + u8g_DrawStr(&u8g, 0, 0, "ASCII page 1"); + for( y = 0; y < 6; y++ ) { + for( x = 0; x < 16; x++ ) { + s[0] = y*16 + x + 32; + u8g_DrawStr(&u8g, x*7, y*10+10, s); + } + } +} + +/** fifth page in OLED */ +void u8g_ascii_2(void) { + char s[2] = " "; + uint8_t x, y; + u8g_DrawStr(&u8g, 0, 0, "ASCII page 2"); + for( y = 0; y < 6; y++ ) { + for( x = 0; x < 16; x++ ) { + s[0] = y*16 + x + 160; + u8g_DrawStr(&u8g, x*7, y*10+10, s); + } + } +} + +uint8_t draw_state = 0; + +/** test page in OLED +void u8g_test(int index) { + static char buffer[30]; + u8g_SetFont(&u8g, u8g_font_gdr30); + u8g_DrawStr(&u8g, 0, 35, name[index]); + u8g_SetFont(&u8g, u8g_font_6x10); + u8g_DrawStr(&u8g, 0, 50, strcat("type: ", type[index])); + xsprintf(buffer, "left: %d, temp: %s", number[index], temp); + u8g_DrawStr(&u8g, 0, 60, buffer); +} +*/ + +void u8g_cover(void) { + static char buffer[30]; + u8g_SetFont(&u8g, u8g_font_gdr20); + u8g_DrawStr(&u8g, 0, 25, "NCKUEE"); + u8g_SetFont(&u8g, u8g_font_6x10); + u8g_DrawStr(&u8g, 0, 40, "Vending Machine..."); + u8g_DrawStr(&u8g, 0, 50, "Please enter your"); + u8g_DrawStr(&u8g, 0, 60, "user account."); +} + +void u8g_recommand(void) { + static char buffer[30]; + u8g_SetFont(&u8g, u8g_font_gdr20); + u8g_DrawStr(&u8g, 0, 25, name); + u8g_SetFont(&u8g, u8g_font_6x10); + xsprintf(buffer, "(%s) recommanded.", type); + u8g_DrawStr(&u8g, 0, 40, buffer); + u8g_DrawStr(&u8g, 0, 50, "Please enter your"); + u8g_DrawStr(&u8g, 0, 60, "choice of item."); +} + +void u8g_check(void) { + static char buffer[30]; + u8g_SetFont(&u8g, u8g_font_gdr20); + u8g_DrawStr(&u8g, 0, 35, name); + u8g_SetFont(&u8g, u8g_font_6x10); + u8g_DrawStr(&u8g, 0, 50, "purchase?"); + u8g_DrawStr(&u8g, 0, 60, "Press # to confirm."); +} + +void u8g_confirm(void) { + static char buffer[30]; + u8g_SetFont(&u8g, u8g_font_gdr20); + u8g_DrawStr(&u8g, 0, 35, "Thanks"); + u8g_SetFont(&u8g, u8g_font_6x10); + u8g_DrawStr(&u8g, 0, 50, "Vielen Danke."); + xsprintf(buffer, "Terima kasih."); + u8g_DrawStr(&u8g, 0, 60, buffer); +} + +void u8g_input(int index) { + static char buffer[30]; + char output_user[4] = {0}; + for (int i = 0; i <= index; i++) + output_user[i] = user[i]; + u8g_SetFont(&u8g, u8g_font_gdr30); + u8g_DrawStr(&u8g, 0, 35, output_user); + u8g_SetFont(&u8g, u8g_font_6x10); + u8g_DrawStr(&u8g, 0, 50, "inputted."); + xsprintf(buffer, "welcome, temp: %s", temp); + u8g_DrawStr(&u8g, 0, 60, buffer); +} + +/** draw five pages in OLED */ +void draw(void) { + u8g_prepare(); + /* + switch(draw_state >> 3) { + case 0: u8g_box_frame(draw_state&7); break; + case 1: u8g_string(draw_state&7); break; + case 2: u8g_line(draw_state&7); break; + //case 3: u8g_ascii_1(); break; + //case 4: u8g_ascii_2(); break; + case 3: u8g_test_1(); break; + }*/ + switch (oled_status){ + case normal: u8g_cover(); break; + case input_1: u8g_input(0); break; + case input_2: u8g_input(1); break; + case input_3: u8g_input(2); break; + case input_4: u8g_input(3); break; + case recommand: u8g_recommand(); break; + case check: u8g_check(); break; + case confirm: + u8g_confirm(); + oled_status = normal; + vTaskDelay(5000); + break; + } +} + +void oled_task(void *p_arg) +{ + // decode the queue if there is new data receive + + /* + if( xOledQueue != 0 ) + { + if( xQueueReceive( xOledQueue, &oled_data, 0 ) ) + { + if (oled_data.source_id == id_temp) + sprintf(temp, "%*.*lf", 2, 2, oled_data.body[0].f); + } + } + */ + + + EMBARC_PRINTF("entering oled task\r\n"); + EMBARC_PRINTF("u8glib\r\n"); + + EMBARC_PRINTF("u8g_InitComFn\r\n"); + u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_2x_hw_spi, U8G_COM_SSD_SPI); /* create a new interface to a graphics display */ + + + EMBARC_PRINTF("Display Width: %u, Display Height: %u\r\n" , u8g_GetWidth(&u8g), u8g_GetHeight(&u8g)); + + u8g_Begin(&u8g); /* reset display and put it into default state */ + + + while(1) { + // EMBARC_PRINTF("Update frame [%d]\r\n", draw_state); + /* picture loop */ + u8g_FirstPage(&u8g); /* marks the beginning of the picture loop; it cannot be used inside the picture loop */ + do { + draw(); + } while (u8g_NextPage(&u8g)); /* marks the end of the body of the picture loop */ + + draw_state++; + if (draw_state >= 8*8) { /* refresh 8 times for every "draw_state" */ + draw_state = 0; + } + + // decode the queue if there is new data receive + + if (oled_status > 7) + oled_status = 0; + + if( xOledQueue != 0 ) + { + if( xQueueReceive( xOledQueue, &oled_data, 0 ) ) + { + if (oled_data.source_id == id_temp) + { + sprintf(temp, "%*.*lf", 2, 2, oled_data.body[0].f); + // EMBARC_PRINTF("oled receive temp: %s\r\n", temp); + } + // else if (oled_data.source_id == id_numpad) + else if (oled_data.source_id == id_main) + { + if (oled_data.target_item == no_item) + { + if (user_receive_status >= 4) user_receive_status = 0; + + user[user_receive_status] = (char)oled_data.body[0].i; + ++user_receive_status; + ++oled_status; + } else if (oled_data.status == sell_recommand) + // for merchandise recommand + { + oled_status = recommand; + strncpy(name, oled_data.name, 6); + strncpy(type, oled_data.type, 6); + } else if (oled_data.status == purchase_check) + // for user to select the item + { + oled_status = check; + strncpy(name, oled_data.name, 6); + strncpy(type, oled_data.type, 6); + } else if (oled_data.status == purchase_confirm) + // for user to confirm the deal + { + oled_status = confirm; + } + } + /* + else if (oled_data.source_id == id_wifi) + { + if (oled_data.status == sell_recommand) + oled_status = recommand; + else if (user_input_1 <= oled_data.status && oled_data.status <= user_input_4) + { + user[oled_data.status - user_input_1] = oled_data.user[oled_data.status - user_input_1]; + oled_status = oled_data.status - user_input_1 + 2; + } + else + { + oled_status = normal; + for (int i = 0; i <= 4; i++) + { + number[i] = oled_data.body[0].i; + sprintf(type[i], "%s", oled_data.type); + sprintf(name[i], "%s", oled_data.name); + EMBARC_PRINTF("oled receive data type: %s\r\n", oled_data.type); + EMBARC_PRINTF("oled receive data name: %s\r\n", oled_data.name); + } + } + } + */ + } + } + vTaskDelay(100); + } +} \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/temp_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/temp_task.c new file mode 100644 index 00000000..e73e1ff3 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/temp_task.c @@ -0,0 +1,46 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" +#include "adt7420.h" +#include "vm_task.h" + +static inline void _Temp_Enqueue(int target_id, float temp_receive) { + vm_data _data = {0}; + + _data.status = temperature; + _data.source_id = id_temp; + _data.target_id = target_id; + _data.body[0].f = temp_receive; + enQueue(_data); +} + +static ADT7420_DEF ADT7420_DEF_PTR_test = { + .i2c_id = BOARD_TEMP_SENSOR_IIC_ID, + .slvaddr = TEMP_I2C_SLAVE_ADDRESS +}; + +void temp_task(void *p_arg) +{ + EMBARC_PRINTF("entering temp task\r\n"); + + int32_t ercd = 1; + int cond = 0; + float temp_receive = 0; + char test[5] = {0}; + + //board_init(); /* board level init */ + + ercd = adt7420_sensor_init(&ADT7420_DEF_PTR_test); + if (ercd != E_OK) { + EMBARC_PRINTF("temperature sensor init failed. %d", ercd); + } + + while(1){ + cond = adt7420_sensor_read(&ADT7420_DEF_PTR_test, &temp_receive); + // EMBARC_PRINTF("temperature receive: %d \r\n", temp_receive); + _Temp_Enqueue(id_temp, temp_receive); + _Temp_Enqueue(id_oled, temp_receive); + // board_delay_ms(500, 1); + vTaskDelay(10000); + } +} \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/vm_task.c b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/vm_task.c new file mode 100644 index 00000000..a065227c --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/Source/vm_task.c @@ -0,0 +1,59 @@ +/* embARC HAL */ +#include "embARC.h" +#include "embARC_debug.h" + +#include "vm_task.h" + +extern SemaphoreHandle_t vm_queue_mutex; +extern TaskHandle_t task_handle_communication; + +void enQueue(vm_data data) +{ + BaseType_t ret; + do{ + xSemaphoreTake(vm_queue_mutex, portMAX_DELAY); + ret = xQueueSendToBack(xVMQueue, &data, 20); + xSemaphoreGive(vm_queue_mutex); + } while(ret != pdTRUE); +} + + +void vm_task(void *p_arg) +{ + BaseType_t ret; + EMBARC_PRINTF("entering vm task\r\n"); + vm_data data = {0}; + + // xVMQueue, xOledQueue, xCommunicationQueue, xTempQueue, xNumPadQueue, xDCmotorQueue + // all tasks push the data to xVMQueue + + while (1) + { + //xSemaphoreTake(vm_queue_mutex, portMAX_DELAY); + ret = xQueueReceive( xVMQueue, &data, portMAX_DELAY ); + //xSemaphoreGive(vm_queue_mutex); + if (ret == pdTRUE) + { + switch (data.target_id) + { + case id_main: + xQueueSend(xMainQueue, &data, portMAX_DELAY); + break; + case id_wifi: + xQueueSend(xCommunicationQueue, &data, portMAX_DELAY); + if (data.source_id == id_main) vTaskResume(task_handle_communication); + break; + case id_temp: + xQueueSend(xTempQueue, &data, portMAX_DELAY); + // for wifi accessing to temperature + break; + case id_dcmotor: + xQueueSend(xDCmotorQueue, &data, portMAX_DELAY); + break; + case id_oled: + xQueueSend(xOledQueue, &data, portMAX_DELAY); + break; + } + } + } +} diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/vending-machine.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/vending-machine.mk new file mode 100644 index 00000000..8c3a1969 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/middleware/vending-machine/vending-machine.mk @@ -0,0 +1,54 @@ +# dir declaration +MID_VM_DIR = $(MIDDLEWARES_ROOT)/vending-machine + +MID_VM_ASMSRCDIR = $(MID_VM_DIR) +MID_VM_CSRCDIR = $(MID_VM_DIR)/Source +MID_VM_INCDIR = $(MID_VM_DIR)/Include + +# find all the source files in the target directories +MID_VM_CSRCS = $(call get_csrcs, $(MID_VM_CSRCDIR)) +MID_VM_ASMSRCS = $(call get_asmsrcs, $(MID_VM_ASMSRCDIR)) + +APPL_DEFINES += -DNTCONF_EDITOR_MAXLEN=256 -DMBEDTLS_CONFIG_FILE=\"mbedtls_config.h\" + +# get object files +MID_VM_COBJS = $(call get_relobjs, $(MID_VM_CSRCS)) +MID_VM_ASMOBJS = $(call get_relobjs, $(MID_VM_ASMSRCS)) +MID_VM_OBJS = $(MID_VM_COBJS) $(MID_VM_ASMOBJS) + +# get dependency files +MID_VM_DEPS = $(call get_deps, $(MID_VM_OBJS)) + +# extra macros to be defined +MID_VM_DEFINES = -DMID_VM + +# genearte library +MID_LIB_VM = $(OUT_DIR)/libmidvm.a + +# library generation rule +$(MID_LIB_VM): $(MID_VM_OBJS) + $(TRACE_ARCHIVE) + $(Q)$(AR) $(AR_OPT) $@ $(MID_VM_OBJS) + +# specific compile rules +# user can add rules to compile this middleware +# if not rules specified to this middleware, it will use default compiling rules + +# Middleware Definitions +MID_INCDIR += $(MID_VM_INCDIR) +MID_CSRCDIR += $(MID_VM_CSRCDIR) +MID_ASMSRCDIR += $(MID_VM_ASMSRCDIR) + +MID_CSRCS += $(MID_VM_CSRCS) +MID_CXXSRCS += +MID_ASMSRCS += $(MID_VM_ASMSRCS) +MID_ALLSRCS += $(MID_VM_CSRCS) $(MID_VM_ASMSRCS) + +MID_COBJS += $(MID_VM_COBJS) +MID_CXXOBJS += +MID_ASMOBJS += $(MID_VM_ASMOBJS) +MID_ALLOBJS += $(MID_VM_OBJS) + +MID_DEFINES += $(MID_VM_DEFINES) +MID_DEPS += $(MID_VM_DEPS) +MID_LIBS += $(MID_LIB_VM) \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/options.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/options.mk new file mode 100644 index 00000000..2ce4f002 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/options.mk @@ -0,0 +1,249 @@ +## +# Special Default Make Goal to all +# so if no make goal specified, +# all will be the make goal, +# not the first target in the makefile +## +.DEFAULT_GOAL = all + +## Force convert windows path to linux format +override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) + +## Default options settings ## +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/options.mk + +## +# Output OBJS Root Directory +## +OUT_DIR_ROOT ?= + +## +# Compile Toolchain +# Refer to toolchain.mk +## +TOOLCHAIN ?= gnu + +# Optimization Level +# Please Refer to toolchain_xxx.mk for this option +OLEVEL ?= O2 + +## +# additional options +# compile link assembler +## +ADT_COPT ?= +ADT_CXXOPT ?= +ADT_LOPT ?= +ADT_AOPT ?= + +## +# Default HEAP SIZE & STACK SIZE +## +DEFAULT_HEAPSZ := 8192 +DEFAULT_STACKSZ := 8192 + +## +# HEAP SIZE Set +## +HEAPSZ ?= 8192 + +## +# STACK SIZE Set +## +STACKSZ ?= 8192 + +## +# Debugger Select +# Refer to debug.mk +## +JTAG ?= usb + +## +# Digilent JTAG Name Specify(Only for Metaware) +# This is especially useful if you have more than one +# Digilent device connected to your host. +# You can open digilent adept tool to see what digilent +# jtag is connected, leave this blank if don't know the name of digilent jtag +# I have see two digilent name: JtagHs1 TE0604-02 +# Simple wrapper of -prop=dig_device=name option of Metaware Debugger(mdb) +## +DIG_NAME ?= + +## +# Digilent JTAG Choice Select(Only for Metaware) +# Simple wrapper of -prop=dig_device_choice=N option of Metaware Debugger(mdb) +## +DIG_CHOICE ?= + +## +# Set Digilent JTAG frequency(in Hz)(Only for Metaware) +# This is especially useful when you want to specify +# the digilent JTAG frequency when your board freq is quite low. +# Simple wrapper of -prop=dig_speed=SSS option of Metaware Debugger(mdb) +## +DIG_SPEED ?= + +## +# DEBUG +# 1 for enable +# other for disable +## +DEBUG ?= 1 + +## +# generate map +# 1 for enable +# other for disable +## +MAP ?= 1 + +## +# Control Compiler Message Show +# 1: show compile total options +# 0: just show compile file info +## +V ?= 0 + +## +# Suppress All Messages +## +SILENT ?= 0 + +## +# Overwrite some configurations +# Never modify this if you don't know about it +## +override APPL := $(strip $(APPL)) +override OUT_DIR_ROOT := $(strip $(OUT_DIR_ROOT)) + +override ADT_COPT := $(strip $(ADT_COPT)) +override ADT_CXXOPT := $(strip $(ADT_CXXOPT)) +override ADT_LOPT := $(strip $(ADT_LOPT)) +override ADT_AOPT := $(strip $(ADT_AOPT)) +override HEAPSZ := $(strip $(HEAPSZ)) +override STACKSZ := $(strip $(STACKSZ)) + +GENE_TCF = arc.tcf +GENE_BCR_CONTENTS_TXT = bcr_contents.txt +## +# Argument files' filename generated from TCF +# Don't do any modification here +## +GENE_CCAC_ARG = ccac.arg +GENE_GCC_ARG = gcc.arg +GENE_NSIM_PROPS = nsim.props +GENE_MDB_ARG = mdb.arg +GENE_CORE_CONFIG_H = core_config.h +GENE_CORE_CONFIG_S = core_config.s +## +# Apex possiblely not generated +## +GENE_APEXEXTENSIONS_H = apexextensions.h +GENE_APEXEXTENSIONS_S = apexextensions.s + +## +# Argument files not generated +## +GENE_LINK_CMD_TXT = mw_linker.ld +GENE_MEMORY_X = gnu_linker.ld + +## File list which might need to be generated +GENE_FILE_LIST = $(GENE_TCF) $(GENE_CCAC_ARG) $(GENE_GCC_ARG) $(GENE_NSIM_PROPS) \ + $(GENE_MDB_ARG) $(GENE_CORE_CONFIG_H) $(GENE_CORE_CONFIG_S) + +## Include Scripts and Functions ## +include $(EMBARC_ROOT)/options/scripts.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/scripts.mk + +## +# Output Directory Set +## +ifeq ($(strip $(OUT_DIR_ROOT)), ) +OUT_DIR_PREFIX = obj_ +else +### Check Root Out Directory Doesn't contain whitespace ## +ifneq ($(words $(OUT_DIR_ROOT)),1) +$(error PATH '$(OUT_DIR_ROOT)' contains whitespace, not supported!) +else +OUT_DIR_ROOT_FIXPATH = $(subst \,/, $(strip $(OUT_DIR_ROOT))) +OUT_DIR_ROOT_FIXPATH_EXIST = $(realpath $(OUT_DIR_ROOT_FIXPATH)) +ifeq ($(OUT_DIR_ROOT_FIXPATH_EXIST),) +$(error PATH '$(OUT_DIR_ROOT)' doesn't exist, please check it!) +else +override OUT_DIR_ROOT := $(OUT_DIR_ROOT_FIXPATH) +OUT_DIR_PREFIX = $(strip $(OUT_DIR_ROOT))/obj_ +endif +endif +endif +## Board Infomation +BOARD_INFO = $(strip $(BOARD))_$(strip $(BD_VER)) +## Build Infomation +BUILD_INFO = $(strip $(TOOLCHAIN))_$(strip $(CUR_CORE)) +## Selected Configuration +SELECTED_CONFIG=$(BOARD_INFO)-$(BUILD_INFO) + +## Objects Output Directory +BOARD_OUT_DIR = $(OUT_DIR_PREFIX)$(BOARD_INFO) +OUT_DIR = $(BOARD_OUT_DIR)/$(BUILD_INFO) + +## +# Application Path and Name Setting +## +APPL_NAME = $(strip $(APPL)_$(BUILD_INFO)) +APPL_FULL_NAME = $(strip $(OUT_DIR)/$(APPL_NAME)) +APPL_OUT_DIR = $(OUT_DIR)/application + +## +# Generated directory - contains generated files +# Such as metaware, arc gnu, nsim argument files, generated link file +## +EMBARC_GENERATED_DIR = $(OUT_DIR)/embARC_generated + +## +# Application Link file definition +## +APPL_LINK_FILE = $(strip $(OUT_DIR)/linker_$(TOOLCHAIN).ldf) + +################## Pre processing ######################################### +# INCLUDE target specific configuration makefiles +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/rules.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/toolchain.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/debug.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/files.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/arc/arc.mk +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/board/board.mk + +# include toolchain settings +include $(EMBARC_ROOT)/options/toolchain.mk + +################# Components of embARC ################################### +# board specific settings +include $(EMBARC_ROOT)/board/board.mk + +# ARC HAL +include $(EMBARC_ROOT)/arc/arc.mk + +# os specific settings +ifdef OS_SEL +override OS_SEL := $(strip $(OS_SEL)) +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/os/os.mk +include $(EMBARC_ROOT)/os/os.mk +endif + +# middleware makefile +include $(EMBARC_ROOT)/middleware/middleware.mk + +# library makefile +include $(EMBARC_ROOT)/library/library.mk + +############## Post processing ############################################# +# source directories and include directories settings +include $(EMBARC_ROOT)/options/files.mk + +# include debug settings +include $(EMBARC_ROOT)/options/debug.mk + +## +# Include Compiler / Linker / Other Rules +# +include $(EMBARC_ROOT)/options/rules.mk diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/rules.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/rules.mk new file mode 100644 index 00000000..2f183541 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/rules.mk @@ -0,0 +1,396 @@ +## TCF Processing ## +VALID_TCF = $(wildcard $(TCF)) + +ifeq ($(VALID_TCF),) +CORE_ARG_FILES = +else +CORE_ARG_FILES_LIST = $(GENE_FILE_LIST) +CORE_ARG_FILES = $(addprefix $(EMBARC_GENERATED_DIR)/, $(CORE_ARG_FILES_LIST)) +COMMON_COMPILE_PREREQUISITES += $(CORE_ARG_FILES) +EXTRA_DEFINES += -DEMBARC_TCF_GENERATED +endif + + +## All defines ## +ALL_DEFINES += -DPLATFORM_EMBARC $(CPU_DEFINES) $(BOARD_DEFINES) \ + $(MID_DEFINES) $(LIB_DEFINES) $(OS_DEFINES) \ + $(TOOLCHAIN_DEFINES) $(EXTRA_DEFINES) $(APPL_DEFINES) + +## all includes conversion ## +ALL_INCLUDES = $(foreach dir,$(ALL_INC_DIRS),-I$(dir)) + +## +# All object sub-directories need to be created +## +ALL_OBJDIRS = $(sort $(dir $(ALL_ALLOBJS))) + +## +# Generated directories required to build this applications +## +ALL_GENERATED_DIRS += $(ALL_OBJDIRS) $(EMBARC_GENERATED_DIR)/ +ALL_GENERATED_DIRS_TMPFILES = $(sort $(call get_mkdir_tmps, $(ALL_GENERATED_DIRS))) + +## +# Collect all libraries +## +ALL_LIBS = $(BOARD_LIB) $(MID_LIBS) $(OS_LIBS) $(CPU_LIBS) $(LIB_LIBS) +EMBARC_LIB = $(OUT_DIR)/libembarc.a + +## +# Collect Dependency Files +## +APPL_DEPS = $(call get_deps, $(APPL_OBJS)) +EXTRA_DEPS = $(call get_deps, $(EXTRA_OBJS)) +ALL_DEPS = $(call get_deps, $(ALL_ALLOBJS)) + +# include dependency files of application +ifneq ($(MAKECMDGOALS),clean) + -include $(APPL_DEPS) + -include $(EXTRA_DEPS) +endif + + +## +# Clean Related +## +OUT_DIR_PREFIX_WILDCARD = $(subst \,/,$(OUT_DIR_PREFIX)) +OUT_DIRS_WILDCARD = $(sort $(wildcard $(OUT_DIR_PREFIX_WILDCARD)*)) +OUT_DIRS = $(subst /,$(PS), $(strip $(OUT_DIRS_WILDCARD))) + +ifeq ($(strip $(OUT_DIRS)), ) +DIST_DIR_CLEAN = +else +DIST_DIR_CLEAN = $(RMD) $(OUT_DIRS) +endif + +TEMP_FILES2CLEAN = $(sort $(wildcard *.o *.out *.bin *.dis *.elf *.a *.hex *.map *.bak *.dump *.d *.img *.dasm *.log)) +ifeq ($(strip $(TEMP_FILES2CLEAN)), ) +TEMPFILES_CLEAN = +else +TEMPFILES_CLEAN = $(RM) $(TEMP_FILES2CLEAN) +endif + +## +# Overwrite some variables +## +override ALL_DEFINES := $(sort $(ALL_DEFINES)) +override ALL_INCLUDES := $(sort $(ALL_INCLUDES)) + +# +# the definition of source file directory +# +vpath %.C $(ALL_CSRC_DIRS) +vpath %.c $(ALL_CSRC_DIRS) +vpath %.cpp $(ALL_CXXSRC_DIRS) +vpath %.S $(ALL_ASMSRC_DIRS) +vpath %.s $(ALL_ASMSRC_DIRS) + +.PHONY : all build dump dasm bin hex size clean boardclean distclean run gui cfg opt info spopt infodirs infosrcs infoobjs help + +all : $(APPL_FULL_NAME).elf + +build : clean all + +dump : $(APPL_FULL_NAME).dump + +dasm : $(APPL_FULL_NAME).dasm + +bin : $(APPL_FULL_NAME).bin + +hex : $(APPL_FULL_NAME).hex + +help : + @$(ECHO) 'Build Targets for selected configuration:' + @$(ECHO) ' all - Build example' + @$(ECHO) ' bin - Build and Generate binary for example' + @$(ECHO) ' hex - Build and Generate Intel Hex File for example' + @$(ECHO) ' build - Clean first then compile example' + @$(ECHO) ' dump - Generate dump information for example' + @$(ECHO) ' dasm - Disassemble object file' + @$(ECHO) ' size - Display size information of object file' + @$(ECHO) 'Clean Targets:' + @$(ECHO) ' clean - Remove object files of selected configuration' + @$(ECHO) ' boardclean - Remove object files of selected board' + @$(ECHO) ' distclean - Remove object files of all boards' + @$(ECHO) 'Debug & Run Targets for selected configuration:' + @$(ECHO) ' run - Use MDB & JTAG to download and run object elf file' + @$(ECHO) ' gui - Use MDB & JTAG to download and debug object elf file' + @$(ECHO) 'Other Targets:' + @$(ECHO) ' cfg - Display build target configuration' + @$(ECHO) ' opt - Display Current MAKE options' + @$(ECHO) ' spopt - Display Supported MAKE options' + @$(ECHO) 'Available Configurations:' + @$(ECHO) ' BOARD=emsk|nsim|axs - Build for which board(EMSK, NSIM, AXS)' + @$(ECHO) ' BD_VER=11|22|23|10|1506|103 - Board Version of development board' + @$(ECHO) ' OLEVEL=Os|O0|O1|O2|O3 - Optimization Level of examples to be built' + @$(ECHO) ' CUR_CORE=arcem4|arcem4cr16|arcem6|arcem6gp|arcem7d|arcem9d|arcem11d|arcem|archs|arcemfull|arcsem|archs36|...' + @$(ECHO) ' - Current core configuration' + @$(ECHO) ' TCF=path/to/yourtcf - Select your own tcf file to replace current used one' + @$(ECHO) ' TOOLCHAIN=mw|gnu - Current selected compiling toolchain' + @$(ECHO) ' JTAG=usb|opella - Current debug jtag(Digilent JTAG or Ashling Opella-XD JTAG)' + @$(ECHO) ' OUT_DIR_ROOT=.|xxx - Specify where to generate object files default current example makefile folder' + @$(ECHO) ' SILENT=0|1 - Disable or enable message output' + @$(ECHO) ' V=0|1 - Disable or enable verbose compiling information' + @$(ECHO) ' DIG_NAME=xxx - Specify Digilent JTAG which to be used, most useful when more than one Digilent USB-JTAG plugged in' + @$(ECHO) ' HEAPSZ=xxx - Specify heap size for program, xxx stands for size in bytes' + @$(ECHO) ' STACKSZ=xxx - Specify stack size for program, xxx stands for size in bytes' + @$(ECHO) 'Example Usage:' + @$(ECHO) ' make all - build example in current directory using default configuration' + @$(ECHO) ' make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d OLEVEL=O2 TOOLCHAIN=gnu all - build example using configuration (emsk, 22, arcem7d, O2, gnu)' + @$(ECHO) ' make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TCF=mytcfpath all - build example using configuration (emsk, 22, arcem7d) using the tcf defined in TCF option' + +cfg : + @$(ECHO) '=======Current Configuration=======' + @$(ECHO) 'Host OS : $(HOST_OS)' + @$(ECHO) 'Board : $(BOARD)' + @$(ECHO) 'Hardware Version : $(BD_VER)' + @$(ECHO) 'Core Configuration : $(CUR_CORE)' + @$(ECHO) 'CPU Clock HZ : $(CPU_FREQ)' + @$(ECHO) 'Peripheral Clock HZ: $(DEV_FREQ)' + @$(ECHO) 'Build Toolchain : $(TOOLCHAIN)' + @$(ECHO) 'Optimization Level : $(OLEVEL)' + @$(ECHO) 'Debug Jtag : $(JTAG)' + @$(ECHO) '======Supported Configurations of $(BOARD)-$(BD_VER)======' + @$(ECHO) 'Boards (BOARD) : $(SUPPORTED_BOARDS)' + @$(ECHO) 'Core Configurations (CUR_CORE) : $(SUPPORTED_CORES)' + @$(ECHO) 'Build Toolchains (TOOLCHAIN) : $(SUPPORTED_TOOLCHAINS)' + @$(ECHO) 'Debug Jtags (JTAG) : $(SUPPORTED_JTAGS)' + +opt : + @$(ECHO) ======CURRENT CONFIGURATION===== + @$(ECHO) BOARD : $(BOARD) + @$(ECHO) BD_VER : $(BD_VER) + @$(ECHO) CUR_CORE : $(CUR_CORE) + @$(ECHO) TOOLCHAIN : $(TOOLCHAIN) + @$(ECHO) OLEVEL : $(OLEVEL) + @$(ECHO) JTAG : $(JTAG) + @$(ECHO) EMBARC_ROOT : $(EMBARC_ROOT) + @$(ECHO) OUT_DIR_ROOT : $(OUT_DIR_ROOT) + @$(ECHO) APPL_DEFINES : $(APPL_DEFINES) + @$(ECHO) COMPILE_OPT : $(subst $(MKDEP_OPT), , $(COMPILE_OPT)) + @$(ECHO) CXX_COMPILE_OPT: $(subst $(MKDEP_OPT), , $(CXX_COMPILE_OPT)) + @$(ECHO) ASM_OPT : $(subst $(MKDEP_OPT), , $(ASM_OPT)) + @$(ECHO) AR_OPT : $(AR_OPT) + @$(ECHO) LINK_OPT : $(LINK_OPT) + @$(ECHO) DEBUGGER : $(DBG) + @$(ECHO) DBG_HW_FLAGS : $(DBG_HW_FLAGS) + @$(ECHO) MDB_NSIM_OPT : $(MDB_NSIM_OPT) + +info: + @$(ECHO) ======CURRENT BUILD INFORMATION===== + @$(ECHO) EMBARC_ROOT : $(realpath $(EMBARC_ROOT)) + @$(ECHO) OUT_DIR_ROOT : $(realpath $(OUT_DIR_ROOT)) + @$(ECHO) BUILD_OPTION : BOARD=$(BOARD) BD_VER=$(BD_VER) CUR_CORE=$(CUR_CORE) TOOLCHAIN=$(TOOLCHAIN) OLEVEL=$(OLEVEL) V=$(V) DEBUG=$(DEBUG) SILENT=$(SILENT) + @$(ECHO) APPLICATION_NAME : $(APPL_NAME) + @$(ECHO) APPLICATION_LINKSCRIPT : $(APPL_LINK_FILE) + @$(ECHO) APPLICATION_ELF : $(APPL_FULL_NAME).elf + @$(ECHO) APPLICATION_BIN : $(APPL_FULL_NAME).bin + @$(ECHO) APPLICATION_HEX : $(APPL_FULL_NAME).hex + @$(ECHO) APPLICATION_MAP : $(APPL_FULL_NAME).map + @$(ECHO) APPLICATION_DUMP : $(APPL_FULL_NAME).dump + @$(ECHO) APPLICATION_DASM : $(APPL_FULL_NAME).dasm + @$(ECHO) MIDDLEWARE : $(sort $(MID_SEL)) + @$(ECHO) PERIPHERAL : $(sort $(EXT_DEV_LIST)) + +spopt : + @$(ECHO) ======SUPPORTED CONFIGURATIONS===== + @$(ECHO) SUPPORTED_BOARDS : $(SUPPORTED_BOARDS) + @$(ECHO) SUPPORTED_BD_VERS : $(SUPPORTED_BD_VERS) + @$(ECHO) SUPPORTED_CORES : $(SUPPORTED_CORES) + @$(ECHO) SUPPORTED_OLEVELS : $(SUPPORTED_OLEVELS) + @$(ECHO) SUPPORTED_TOOLCHAINS : $(SUPPORTED_TOOLCHAINS) + @$(ECHO) SUPPORTED_JTAGS : $(SUPPORTED_JTAGS) + +infodirs : + @$(ECHO) ======ALL Directories Information===== + @$(ECHO) ALL_INC_DIRS : $(ALL_INC_DIRS) + @$(ECHO) ALL_CSRC_DIRS : $(ALL_CSRC_DIRS) + @$(ECHO) ALL_ASMSRC_DIRS : $(ALL_ASMSRC_DIRS) + @$(ECHO) ALL_CXXSRC_DIRS : $(ALL_CXXSRC_DIRS) + +infosrcs : + @$(ECHO) ======ALL Sources Information===== + @$(ECHO) ALL_CSRCS : $(ALL_CSRCS) + @$(ECHO) ALL_ASMSRCS : $(ALL_ASMSRCS) + @$(ECHO) ALL_CXXSRCS : $(ALL_CXXSRCS) + +infoobjs : + @$(ECHO) ======ALL Sources Information===== + @$(ECHO) ALL_COBJS : $(ALL_COBJS) + @$(ECHO) ALL_ASMOBJS : $(ALL_ASMOBJS) + @$(ECHO) ALL_CXXOBJS : $(ALL_CXXOBJS) + + +size : $(APPL_FULL_NAME).elf + @$(ECHO) "Print Application Program Size" + $(Q)$(SIZE) $(SIZE_OPT) $< + +clean : + @$(ECHO) "Clean Workspace For Selected Configuration : $(SELECTED_CONFIG)" + -$(IFEXISTDIR) $(subst /,$(PS),$(OUT_DIR)) $(ENDIFEXISTDIR) $(RMD) $(subst /,$(PS),$(OUT_DIR)) + -$(IFEXISTDIR) .sc.project $(ENDIFEXISTDIR) $(RMD) .sc.project + -$(TEMPFILES_CLEAN) + +boardclean : + @$(ECHO) "Clean Workspace For Selected Board : $(BOARD_INFO)" + -$(IFEXISTDIR) $(subst /,$(PS),$(BOARD_OUT_DIR)) $(ENDIFEXISTDIR) $(RMD) $(subst /,$(PS),$(BOARD_OUT_DIR)) + -$(IFEXISTDIR) .sc.project $(ENDIFEXISTDIR) $(RMD) .sc.project + -$(TEMPFILES_CLEAN) + +distclean : + @$(ECHO) "Clean All" + -$(IFEXISTDIR) .sc.project $(ENDIFEXISTDIR) $(RMD) .sc.project + -$(DIST_DIR_CLEAN) + -$(TEMPFILES_CLEAN) + +run : $(APPL_FULL_NAME).elf + @$(ECHO) "Download & Run $<" + $(DBG) $(DBG_HW_FLAGS) $< $(CMD_LINE) + +gui : $(APPL_FULL_NAME).elf + @$(ECHO) "Download & Debug $<" + $(DBG) $(DBG_HW_FLAGS) $< $(CMD_LINE) + +ifeq ($(BOARD), nsim) +ifeq ($(DBG), arc-elf32-gdb) +ifeq ($(VALID_TCF),) +nsim : +else +nsim : $(EMBARC_GENERATED_DIR)/$(GENE_NSIM_PROPS) +endif + @$(ECHO) "Start nSim Standalone" + $(NSIMDRV) -gdb -port 1234 -p nsim_emt=1 $(NSIMDRV_OPT) +endif +endif + +#####RULES FOR GENERATING ARGUMENT FILE USING TCF##### +$(EMBARC_GENERATED_DIR)/$(GENE_TCF): $(VALID_TCF) $(EMBARC_GENERATED_DIR)/.mkdir_done +ifeq ($(UPGRADE_TCF), 1) +## Upgrade TCF file needed. + @$(ECHO) "Upgrade to latest TCF file $@" + $(Q)$(TCFGEN) -q -i $< -o $@ -ob $(dir $@)/$(GENE_BCR_CONTENTS_TXT) +else +## No need to upgrade TCF file + @$(ECHO) "Copy TCF file $< to $@" +# $(Q)-$(IFEXISTFILE) $(subst /,$(PS),$@) $(ENDIFEXISTFILE) $(RM) $(subst /,$(PS),$@) +# $(Q)$(CP) $(subst /,$(PS),$<) $(subst /,$(PS),$@) + $(Q)$(TCFTOOL) -q -d IDE -o $@ $< +endif + +$(EMBARC_GENERATED_DIR)/$(GENE_CCAC_ARG): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate Metaware compiler argument file $@" + $(Q)$(TCFTOOL) -q -x mw_compiler,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_GCC_ARG): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC GNU compiler argument file $@" + $(Q)$(TCFTOOL) -q -x gcc_compiler,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_NSIM_PROPS): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate nSIM properties file $@" + $(Q)$(TCFTOOL) -q -x nSIM,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_MDB_ARG): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate Metaware Debugger argument file $@" + $(Q)$(TCFTOOL) -q -x mw_debugger,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_CORE_CONFIG_H): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC core config header file $@" + $(Q)$(TCFTOOL) -q -x C_defines,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_CORE_CONFIG_S): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC core config assembler file $@" + $(Q)$(TCFTOOL) -q -x assembler_defines,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_APEXEXTENSIONS_H): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC APEX externsion header file $@" + -$(Q)$(TCFTOOL) -q -x apex_header,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_APEXEXTENSIONS_S): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC APEX externsion assembler file $@" + -$(Q)$(TCFTOOL) -q -x apex_assembly,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_LINK_CMD_TXT): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate Metaware Linker file from TCF $@" + $(Q)$(TCFTOOL) -q -x linker_command_file,$@ $< + +$(EMBARC_GENERATED_DIR)/$(GENE_MEMORY_X): $(EMBARC_GENERATED_DIR)/$(GENE_TCF) + @$(ECHO) "Generate ARC GNU Linker file from TCF $@" + $(Q)$(TCFTOOL) -q -x gnu_linker_command_file,$@ $< + + +#####RULES FOR GENERATING LINK FILE FROM TEMPLATE##### +.SECONDEXPANSION: +$(APPL_LINK_FILE): $(LINKER_SCRIPT_FILE) $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_GEN_LINKFILE) + $(Q)$(CC) -c $(ALL_DEFINES) $(LINK_FILE_OPT) $< -o $@ + +#####RULES FOR GENERATING ELF FILE##### +.SECONDEXPANSION: +$(APPL_FULL_NAME).elf : $(ALL_GENERATED_DIRS_TMPFILES) $(CORE_ARG_FILES) $(APPL_LINK_FILE) $(APPL_OBJS) $(EXTRA_OBJS) $(EMBARC_LIB) $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_LINK) + $(Q)$(LD) $(LINK_OPT) $(APPL_OBJS) $(EXTRA_OBJS) $(LD_START_GROUPLIB) $(EMBARC_LIB) $(APPL_LIBS) $(LD_SYSTEMLIBS) $(LD_END_GROUPLIB) -o $@ + +#####RULES FOR ACHIEVING EMBARC WHOLE LIBRARY##### +$(EMBARC_LIB) : $(ALL_GENERATED_DIRS_TMPFILES) $(CORE_ARG_FILES) $(ALL_LIBS) $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_ARCHIVE) + $(Q)-$(IFEXISTFILE) $(subst /,$(PS),$(EMBARC_LIB)) $(ENDIFEXISTFILE) $(RM) $(subst /,$(PS),$(EMBARC_LIB)) + $(Q)$(AR) $(AR_OPT) $@ $(ALL_LIBS) + +#####APPLICATION C/ASM/CPP SOURCE FILE COMPILING RULES##### +.SECONDEXPANSION: +$(APPL_COBJS) :$(APPL_OUT_DIR)/%.o: %.c $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_COMPILE) + $(Q)$(CC) -c $(COMPILE_OPT) $< -o $@ + +.SECONDEXPANSION: +$(APPL_CXXOBJS) : $(APPL_OUT_DIR)/%.o: %.cpp $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_COMPILE) + $(Q)$(CXX) -c $(CXX_COMPILE_OPT) $< -o $@ + +.SECONDEXPANSION: +$(APPL_ASMOBJS): $(APPL_OUT_DIR)/%.o: %.s $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_ASSEMBLE) + $(Q)$(CC) -c $(ASM_OPT) $< -o $@ + +#####DEFAULT C/ASM/CPP SOURCE FILE COMPILING RULES FOR CPU/BOARD/LIBRARY/MIDDLEWARE/OS/EXTRA##### +.SECONDEXPANSION: +$(OUT_DIR)/%.o :$(EMBARC_ROOT)/%.c $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_COMPILE) + $(Q)$(CC) -c $(COMPILE_OPT) $< -o $@ + +.SECONDEXPANSION: +$(OUT_DIR)/%.o :$(EMBARC_ROOT)/%.cpp $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_COMPILE) + $(Q)$(CC) -c $(CXX_COMPILE_OPT) $< -o $@ + +.SECONDEXPANSION: +$(OUT_DIR)/%.o :$(EMBARC_ROOT)/%.s $$(COMMON_COMPILE_PREREQUISITES) + $(TRACE_ASSEMBLE) + $(Q)$(CC) -c $(ASM_OPT) $< -o $@ + +#####RULES FOR CREATING REQUIRED DIRECTORIES##### +%/.mkdir_done: + $(TRACE_CREATE_DIR) + $(TRY_MK_OBJDIR) + @$(ECHO) $(@D) > $@ + +#####RULES FOR GENERATING DUMP/DASM/BIN/HEX FILE##### +$(APPL_FULL_NAME).dump : $(APPL_FULL_NAME).elf + @$(ECHO) "Dumping $<" + $(Q)$(DMP) $(DMP_OPT) $< > $@ + +$(APPL_FULL_NAME).dasm : $(APPL_FULL_NAME).elf + @$(ECHO) "Disassembling $<" + $(Q)$(DMP) $(DASM_OPT) $< > $@ + +$(APPL_FULL_NAME).bin : $(APPL_FULL_NAME).elf + @$(ECHO) "Generating Binary $@" + $(Q)$(OBJCOPY) $(ELF2BIN_OPT) $< $@ + +$(APPL_FULL_NAME).hex : $(APPL_FULL_NAME).elf + @$(ECHO) "Generating Intel Hex File $@" + $(Q)$(ELF2HEX) $(ELF2HEX_INOPT) $< $(ELF2HEX_OUTOPT) $@ + +#####RULES FOR WORKAROUNDS##### + : + @$(ECHO) "Rules to fix built-in missing caused by metaware compiler 2014.12" diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain.mk new file mode 100644 index 00000000..523cbcd8 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain.mk @@ -0,0 +1,44 @@ +## +# TOOLCHAIN +# Select which TOOLCHAIN should be used +# Supported toolchains: +# +# mw -Metaware development tools +# gnu -ARC GNU Tool chain +## +SUPPORTED_TOOLCHAINS = gnu mw +## Another define in options.mk +TOOLCHAIN ?= gnu + +## +# Definition of Tool Paths +## +MW_TOOLPATH ?= +GNU_TOOLPATH ?= + +override TOOLCHAIN := $(strip $(TOOLCHAIN)) + +## Set Valid Toolchain +VALID_TOOLCHAIN = $(call check_item_exist, $(TOOLCHAIN), $(SUPPORTED_TOOLCHAINS)) + +## Try include toolchain makefile +ifneq ($(VALID_TOOLCHAIN), ) +COMMON_COMPILE_PREREQUISITES += $(EMBARC_ROOT)/options/toolchain/toolchain_$(VALID_TOOLCHAIN).mk +include $(EMBARC_ROOT)/options/toolchain/toolchain_$(VALID_TOOLCHAIN).mk +else +$(info TOOLCHAIN - $(SUPPORTED_TOOLCHAINS) are supported) +$(error Toolchain $(TOOLCHAIN) is not supported, please check it!) +endif + +ifeq ($(VALID_TOOLCHAIN), mw) +TOOLCHAIN_ID = METAWARE +else +ifeq ($(VALID_TOOLCHAIN), gnu) +TOOLCHAIN_ID = ARC_GNU +else +TOOLCHAIN_ID = NONE +endif +endif + +## TOOLCHAIN Defines, some defined in toolchain_xxx.mk +TOOLCHAIN_DEFINES += -DTOOLCHAIN=$(TOOLCHAIN_ID) diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain/toolchain_gnu.mk b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain/toolchain_gnu.mk new file mode 100644 index 00000000..74c50497 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/embarc_osp-master/options/toolchain/toolchain_gnu.mk @@ -0,0 +1,220 @@ +ifeq ($(DEBUG), 1) + CDEBUG_OPTION := -g +endif + +ifeq ($(MAP), 1) + LMAP_OPTION = -Wl,-M,-Map=$(APPL_FULL_NAME).map +endif + +ifdef HEAPSZ + HEAP_DEFINES := -D_HEAPSIZE=$(strip $(HEAPSZ)) +else + HEAP_DEFINES := -D_HEAPSIZE=$(strip $(DEFAULT_HEAPSZ)) +endif + +ifdef STACKSZ + STACK_DEFINES := -D_STACKSIZE=$(strip $(STACKSZ)) +else + STACK_DEFINES := -D_STACKSIZE=$(strip $(DEFAULT_STACKSZ)) +endif + +TOOLCHAIN_DEFINES += $(HEAP_DEFINES) $(STACK_DEFINES) -D__GNU__ + +SUPPORTED_OLEVELS = O O0 O1 O2 O3 Os Os1 Oz Ofast Og +## +# Optimization level settings +# GCC Version For ARC +# refer to Using the GNU Compiler Collection (GCC) +# 3.10 Options That Control Optimization +# You can invoke GCC with ‘-Q --help=optimizers’ +# to find out the exact set of optimizations +# that are enabled at each level. +## +## -O Set optimization level to +## -Ofast Optimize for speed disregarding exact standards compliance +## -Og Optimize for debugging experience rather than speed or size +## -Os Optimize for space rather than speed +ifeq ($(OLEVEL), O) + #Optimize. Optimizing compilation takes + #somewhat more time, and a lot more memory + #for a large function. + #equivalent to -O1 + OPT_OLEVEL = -O +else +ifeq ($(OLEVEL), O0) + #Reduce compilation time and + #make debugging produce the expected results + #This is the default. + OPT_OLEVEL = -O0 +else +ifeq ($(OLEVEL), O1) + #equivalent to -O + OPT_OLEVEL = -O1 +else +ifeq ($(OLEVEL), O2) + #Optimize even more. GCC performs nearly all + #supported optimizations that do not involve + #a space-speed tradeoff. As compared to ‘-O’, + #this option increases both compilation time + #and the performance of the generated code + OPT_OLEVEL = -O2 +else +ifeq ($(OLEVEL), O3) + #Optimize yet more. ‘-O3’ turns on all optimizations + #specified by ‘-O2’ and also turns on the ‘-finline-functions’, + #‘-funswitch-loops’, ‘-fpredictive-commoning’, ‘-fgcse-after-reload’, + #‘-ftree-vectorize’, ‘-fvect-cost-model’, + #‘-ftree-partial-pre’ and ‘-fipa-cp-clone’ options. + OPT_OLEVEL = -O3 +else +ifeq ($(OLEVEL), Os) + #Optimize for size. ‘-Os’ enables all ‘-O2’ optimizations + #that do not typically increase code size. It also performs + #further optimizations designed to reduce code size + OPT_OLEVEL = -Os +else +ifeq ($(OLEVEL), Os1) + #here equivalent to -Os + OPT_OLEVEL = -Os +else +ifeq ($(OLEVEL), Oz) + #here equivalent to -Os + OPT_OLEVEL = -Os +else +ifeq ($(OLEVEL), Ofast) + #Disregard strict standards compliance. + #‘-Ofast’ enables all ‘-O3’ optimizations. It also enables + #optimizations that are not valid for all standardcompliant programs. + OPT_OLEVEL = -Ofast +else +ifeq ($(OLEVEL), Og) + #Optimize debugging experience. ‘-Og’ enables optimizations + #that do not interfere with debugging. + OPT_OLEVEL = -Og +else + #no optimization option defined + OPT_OLEVEL = +endif +endif +endif +endif +endif +endif +endif +endif +endif +endif + +## +# define tools +## +GNU_TOOLCHAIN_PREFIX := $(strip $(GNU_TOOLPATH)) + +ifneq ($(GNU_TOOLCHAIN_PREFIX), ) +GNU_TOOLCHAIN_PREFIX := $(wildcard $(GNU_TOOLCHAIN_PREFIX)) +endif + +## GNU TOOLCHAIN TOOLS NAME DEFINITIONS ## + CC = arc-elf32-gcc + CXX = arc-elf32-g++ + AS = arc-elf32-as + DMP = arc-elf32-objdump + LD = arc-elf32-gcc + AR = arc-elf32-ar + NM = arc-elf32-nm + OBJCOPY = arc-elf32-objcopy + ELF2HEX = arc-elf32-objcopy + SIZE = arc-elf32-size + +## GNU TOOLCHAIN EXIST TESTING ## +GNU_TOOLCHAIN_PREFIX_TEST := $(wildcard $(GNU_TOOLCHAIN_PREFIX)/$(DMP)*) +ifneq ($(GNU_TOOLCHAIN_PREFIX_TEST), ) + CC := $(GNU_TOOLCHAIN_PREFIX)/$(CC) + CXX := $(GNU_TOOLCHAIN_PREFIX)/$(CXX) + AS := $(GNU_TOOLCHAIN_PREFIX)/$(AS) + DMP := $(GNU_TOOLCHAIN_PREFIX)/$(DMP) + LD := $(GNU_TOOLCHAIN_PREFIX)/$(LD) + AR := $(GNU_TOOLCHAIN_PREFIX)/$(AR) + NM := $(GNU_TOOLCHAIN_PREFIX)/$(NM) + OBJCOPY := $(GNU_TOOLCHAIN_PREFIX)/$(OBJCOPY) + ELF2HEX := $(GNU_TOOLCHAIN_PREFIX)/$(OBJCOPY) + SIZE := $(GNU_TOOLCHAIN_PREFIX)/$(SIZE) +endif + + MAKE = make + DBG ?= arc-elf32-gdb + + NSIMDRV = nsimdrv + TCFGEN = tcfgen + TCFTOOL = tcftool + +## +# Openocd script root location(OPENOCD_SCRIPT_ROOT) +# Please take care with letter case of the path +# Please use absolute path and linux slash(/) +## +## Set windows Path for Openocd script root +ifeq "$(HOST_OS)" "Msys" + OPENOCD_SCRIPT_ROOT = C:/arc_gnu/share/openocd/scripts +else +## Set Cygwin for windows Path for Openocd script root +ifeq "$(HOST_OS)" "Cygwin" + OPENOCD_SCRIPT_ROOT = C:/arc_gnu/share/openocd/scripts +else +## Set Linux Path for Openocd script root +ifeq "$(HOST_OS)" "GNU/Linux" + OPENOCD_SCRIPT_ROOT = ~/arc_gnu/share/openocd/scripts +else +## Set default Path for Openocd script root + OPENOCD_SCRIPT_ROOT = D:/arc_gnu/share/openocd/scripts +endif +endif +endif + +## Don't change this line +override OPENOCD_SCRIPT_ROOT := $(subst \,/, $(strip $(OPENOCD_SCRIPT_ROOT))) + +## +# toolchain flags +## +libnsim = $(shell $(CC) -print-file-name=libnsim.a) +ifeq ($(libnsim),libnsim.a) + # File doens't exists - old newlib. + TOOLCHAIN_DEFINES += -U_HAVE_LIBGLOSS_ +else + TOOLCHAIN_DEFINES += -D_HAVE_LIBGLOSS_ +endif + +## +# build options +## + ## Common Options + MKDEP_OPT = -MMD -MT $@ -MF $@.d + COMMON_COMPILE_OPT = -mno-sdata $(OPT_OLEVEL) $(CDEBUG_OPTION) $(ALL_DEFINES) $(ALL_INCLUDES) $(MKDEP_OPT) + + ## C/CPP/ASM/LINK Options + COMPILE_OPT += $(CCORE_OPT_GNU) $(ADT_COPT) $(COMMON_COMPILE_OPT) -std=gnu99 + CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) $(ADT_CXXOPT) $(COMMON_COMPILE_OPT) + ASM_OPT += $(ACORE_OPT_GNU) $(ADT_AOPT) $(COMMON_COMPILE_OPT) -x assembler-with-cpp + LINK_OPT += $(LCORE_OPT_GNU) $(ADT_LOPT) \ + -mno-sdata -nostartfiles $(LMAP_OPTION) -lm -Wl,--script=$(APPL_LINK_FILE) + + ## Link File Generation Options + LINK_FILE_OPT += -x assembler-with-cpp $(ALL_INCLUDES) -E -P -nostdinc -undef -D__GNU__ + LINK_FILE_DEPOPT = $(LINK_FILE_OPT) -DENABLE_GENERATE_DEPENDCY_FILE $(MKDEP_OPT) + + ## Other Options + AR_OPT += -rcsT + DMP_OPT += -x + DASM_OPT += -D + SIZE_OPT += + + LD_START_GROUPLIB = -Wl,--start-group + LD_SYSTEMLIBS = -lm -lc -lgcc + LD_END_GROUPLIB = -Wl,--end-group +## +# additional options +## + ELF2HEX_INOPT = -O ihex + ELF2HEX_OUTOPT = + ELF2BIN_OPT = -O binary \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/arc2php.txt b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/arc2php.txt new file mode 100644 index 00000000..f5e47e37 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/arc2php.txt @@ -0,0 +1 @@ +26.25 3 9 1234 2 5 4 6 \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/com2arc.txt b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/com2arc.txt new file mode 100644 index 00000000..f72b23a6 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/com2arc.txt @@ -0,0 +1,5 @@ +1 3 1234 +1 Soda 27 drinks 2018-06-23 2 +2 Water 25 drinks 2018-06-29 5 +3 Coffee 25 drinks 2018-07-31 4 +4 Chips 25 food 2018-07-03 6 diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.css b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.css new file mode 100644 index 00000000..e42d24f1 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.css @@ -0,0 +1,56 @@ +td +{ + text-align:center; +} +input +{ + text-align:left; +} +#record +{ + overflow: scroll; +} + +#state,#analysis,#record +{ + height: 100vh; +} +.grid-container { + display: grid; + grid-template-columns: 33% 33% 33% ; + grid-gap: 10px; + background-color: rgb(0, 3, 5); + padding: 10px; +} +.grid-container > div { + background-color: rgba(255, 255, 255, 0.8); + padding: 10px ; + font-size: 18px; +} +#user +{ + text-align: right; +} +label +{ + margin-right: 2em; + font-size: 19px; +} +.item5 { + grid-area: 1 / 3 / 4 / 4; +} +.item6 { + grid-area: 3 / 1 / 4 / 3; +} +input +{ + width: 4em; +} +.date +{ + width: 10em; +} +input.w3-button +{ + margin-left: 15vw; +} diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.php b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.php new file mode 100644 index 00000000..4c075b85 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/item.php @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + 饅丁蘑蕈倉儲系統 + + + + + + +
+
+ + +
+
+

販賣機狀態

+
"> +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+

通知

+

+
+ +
+

狀態
販賣機編號: 狀態: + 溫度: 時間:

+
+ +
+ + + + + + +
+
+
+
+
+
+ +
+

分析

+
+
+
+
+ + + 0, "Water" => 0, "Coffee" => 0, "Chips" => 0); + for ($i = 1; $i <= $size; $i++)//初始化,獲得資料庫數值 + { + $idaccount = "Buy_Time" . (string)$i; + $idRfid = "Rfid" . (string)$i; + $idItem = "Item" . (string)$i; + $idCost = "Cost" . (string)$i; + $idBalance = "Balance" . (string)$i; + $rs = mysqli_fetch_row($data); + $account[$idaccount] = $rs[1]; + $Rfid[$idRfid] = $rs[0]; + $Item[$idItem] = $rs[2]; + $Cost[$idCost] = $rs[3]; + $Balance[$idBalance] = $rs[4]; + if(isset($count[$rs[2]])) + $count[$rs[2]]++; + } + ?> + +
+

購買紀錄

+ + + + + + + + + + + + + + + + + + +
帳號 時間 商品 花費 餘額
+
+
+
+
+ + + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/logout.php b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/logout.php new file mode 100644 index 00000000..e67a4994 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/logout.php @@ -0,0 +1,19 @@ + + + + + + + 登出中... + + + + + + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/projectarc.sql b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/projectarc.sql new file mode 100644 index 00000000..3bbe4a80 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/projectarc.sql @@ -0,0 +1,193 @@ +-- phpMyAdmin SQL Dump +-- version 4.7.7 +-- https://www.phpmyadmin.net/ +-- +-- 主機: 127.0.0.1 +-- 產生時間: 2018 年 06 月 24 日 16:12 +-- 伺服器版本: 10.1.30-MariaDB +-- PHP 版本: 7.2.2 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET AUTOCOMMIT = 0; +START TRANSACTION; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- 資料庫: `projectarc` +-- + +-- -------------------------------------------------------- + +-- +-- 資料表結構 `costomer` +-- + +CREATE TABLE `costomer` ( + `Rfid` int(11) NOT NULL, + `Time` date DEFAULT NULL, + `like1` int(11) DEFAULT NULL, + `like2` int(11) DEFAULT NULL, + `like3` int(11) DEFAULT NULL, + `like4` int(11) DEFAULT NULL, + `Balance` int(11) DEFAULT NULL, + `State` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- 資料表的匯出資料 `costomer` +-- + +INSERT INTO `costomer` (`Rfid`, `Time`, `like1`, `like2`, `like3`, `like4`, `Balance`, `State`) VALUES +(1234, '2018-05-16', 9, 8, 12, 13, 1741, 0); + +-- -------------------------------------------------------- + +-- +-- 資料表結構 `item` +-- + +CREATE TABLE `item` ( + `序號` int(10) UNSIGNED NOT NULL, + `Name` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `Price` mediumint(9) DEFAULT NULL, + `Type` varchar(10) CHARACTER SET utf32 COLLATE utf32_unicode_ci DEFAULT NULL, + `Exp_Date` date DEFAULT NULL, + `Num` mediumint(9) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- 資料表的匯出資料 `item` +-- + +INSERT INTO `item` (`序號`, `Name`, `Price`, `Type`, `Exp_Date`, `Num`) VALUES +(1, 'Soda', 27, 'drinks', '2018-06-23', 2), +(2, 'Water', 25, 'drinks', '2018-06-29', 5), +(3, 'Coffee', 25, 'drinks', '2018-07-31', 4), +(4, 'Chips', 25, 'food', '2018-07-03', 6); + +-- -------------------------------------------------------- + +-- +-- 資料表結構 `record` +-- + +CREATE TABLE `record` ( + `Buy_Time` datetime NOT NULL, + `Rfid` int(11) NOT NULL, + `Item` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `Cost` int(11) NOT NULL, + `Balance` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- 資料表的匯出資料 `record` +-- + +INSERT INTO `record` (`Buy_Time`, `Rfid`, `Item`, `Cost`, `Balance`) VALUES +('2018-06-17 12:02:05', 1234, 'Chips', 25, 492), +('2018-06-17 12:03:08', 1234, 'Chips', 25, 467), +('2018-06-17 12:03:35', 1234, 'Chips', 25, 442), +('2018-06-17 12:03:53', 1234, 'Chips', 25, 417), +('2018-06-17 12:04:42', 1234, 'Chips', 25, 392), +('2018-06-17 12:08:12', 1234, 'Chips', 25, 367), +('2018-06-17 12:09:33', 1234, 'Chips', 25, 342), +('2018-06-17 12:14:47', 1234, 'Water', 25, 317), +('2018-06-17 12:15:37', 1234, 'Water', 25, 292), +('2018-06-17 12:27:51', 1234, 'Water', 25, 267), +('2018-06-17 12:31:18', 1234, 'Water', 25, 242), +('2018-06-17 12:31:58', 1234, 'Water', 25, 217), +('2018-06-17 12:59:15', 1234, 'Water', 25, 192), +('2018-06-17 18:06:18', 1234, 'Soda', 27, 1893), +('2018-06-17 18:06:36', 1234, 'Soda', 27, 1866), +('2018-06-17 18:07:08', 1234, 'Coffee', 25, 1841), +('2018-06-17 18:07:22', 1234, 'Coffee', 25, 1816), +('2018-06-20 15:49:43', 1234, 'Coffee', 25, 1791), +('2018-06-20 15:59:00', 1234, 'Coffee', 25, 1766), +('2018-06-20 15:59:35', 1234, 'Coffee', 25, 1741); + +-- -------------------------------------------------------- + +-- +-- 資料表結構 `sign_data` +-- + +CREATE TABLE `sign_data` ( + `account` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `Authority` int(5) DEFAULT NULL, + `password` varchar(65) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- 資料表的匯出資料 `sign_data` +-- + +INSERT INTO `sign_data` (`account`, `Authority`, `password`) VALUES +('joanne', 1, '9c64dcb56c7495e197add6833f310ce064da11ccfba07c53c3a17911b7d6cf19'), +('peter1719', 1, '02f6ce48da6a03ea57db8446f5d5a944b72e96859d8aa6577516503ad6f48859'); + +-- -------------------------------------------------------- + +-- +-- 資料表結構 `state` +-- + +CREATE TABLE `state` ( + `M_ID` int(11) NOT NULL, + `State` int(11) NOT NULL, + `Temperature` float NOT NULL, + `Time` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- +-- 資料表的匯出資料 `state` +-- + +INSERT INTO `state` (`M_ID`, `State`, `Temperature`, `Time`) VALUES +(1, 1, 26.25, '2018-06-20 15:59:35'); + +-- +-- 已匯出資料表的索引 +-- + +-- +-- 資料表索引 `costomer` +-- +ALTER TABLE `costomer` + ADD UNIQUE KEY `Rfid` (`Rfid`); + +-- +-- 資料表索引 `item` +-- +ALTER TABLE `item` + ADD PRIMARY KEY (`序號`), + ADD UNIQUE KEY `序號` (`序號`), + ADD KEY `序號_2` (`序號`); + +-- +-- 資料表索引 `record` +-- +ALTER TABLE `record` + ADD UNIQUE KEY `Buy_Time` (`Buy_Time`); + +-- +-- 資料表索引 `sign_data` +-- +ALTER TABLE `sign_data` + ADD UNIQUE KEY `account` (`account`); + +-- +-- 資料表索引 `state` +-- +ALTER TABLE `state` + ADD UNIQUE KEY `MID` (`M_ID`); +COMMIT; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/read.php b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/read.php new file mode 100644 index 00000000..fd057638 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/read.php @@ -0,0 +1,254 @@ +\n"; +// } +//fetch item data from mysql to the file +error_reporting(E_ALL & ~E_NOTICE);//取消notice顯示 +//$fp = fsockopen("127.0.0.1", 9527, $errno, $errstr, 5); +$con = mysqli_connect("127.0.0.1", "peter1719", "Good870216", "projectarc"); +if (!$con) { + echo "連接錯誤"; + die('Error, insert query failed'); +} else { + //echo"連接成功!!"; +} +mysqli_query($con, "set names utf8"); + +/*********************function*****************************/ +function make_string($data) +{//make string 6 bits + $size = strlen($data); + $space_num = 6 - $size; + $buffer = $data; + for ($i = 0; $i < $space_num; $i++) { + $buffer .= " "; + } + return $buffer; +} + +function test_input($data)//處理資料,防止錯誤 +{ + return $data; +} + +function update($user, $reject, $con)//update the data base +{ + if($reject == 2) + { + $data = mysqli_query($con, "select * from item"); + $size = mysqli_num_rows($data);//陣列大小 + $myfile = fopen("com2arc.txt", "w") or die("Unable to open file!"); + $txt = "0\t0\t" . "$user" . "\n"; + fwrite($myfile, $txt); + for ($i = 1; $i <= $size; $i++) { + $rs = mysqli_fetch_row($data); + $order = $rs[0]; + $name = make_string($rs[1]); + $Price = $rs[2]; + $Type = make_string($rs[3]); + $Exp_Date = $rs[4]; + $num = $rs[5]; + $txt = "$order" . "\t" . "$name" . "\t" . "$Price" . "\t" . "$Type" . "\t" . " $Exp_Date" . "\t" . "$num" . "\n"; + fwrite($myfile, $txt); + } + $fileData = file_get_contents("com2arc.txt"); + fclose($myfile); + return $fileData; + } + else if ($reject == 1) { + $data = mysqli_query($con, "select * from item"); + $size = mysqli_num_rows($data);//陣列大小 + $myfile = fopen("com2arc.txt", "w") or die("Unable to open file!"); + $txt = "0\t4\t" . "$user" . "\n"; + fwrite($myfile, $txt); + for ($i = 1; $i <= $size; $i++) { + $rs = mysqli_fetch_row($data); + $order = $rs[0]; + $name = make_string($rs[1]); + $Price = $rs[2]; + $Type = make_string($rs[3]); + $Exp_Date = $rs[4]; + $num = $rs[5]; + $txt = "$order" . "\t" . "$name" . "\t" . "$Price" . "\t" . "$Type" . "\t" . " $Exp_Date" . "\t" . "$num" . "\n"; + fwrite($myfile, $txt); + } + $fileData = file_get_contents("com2arc.txt"); + fclose($myfile); + return $fileData; + } else { + $sql = "SELECT * FROM `costomer` WHERE `Rfid` = \"" . $user . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_row($search); + $like1 = $result[2];//1 + $like2 = $result[3];//0 + $like3 = $result[4];//0 + $like4 = $result[5];//0 + $like = array($like1, $like2, $like3, $like4); + $array_size = $like1 + $like2 + $like3 + $like4 - 1 + 4;//4 + $recommand_weight = array(); + for ($i = 0; $i < 4; $i++) { + for ($j = 0; $j < $like[$i] + 1; $j++) {//2+1+1+1=5 + array_push($recommand_weight, $i + 1);//11234 + } + } + $recommand_item = $recommand_weight[rand(0, $array_size)]; + + $data = mysqli_query($con, "select * from item"); + $size = mysqli_num_rows($data);//陣列大小 + $myfile = fopen("com2arc.txt", "w") or die("Unable to open file!"); + $txt = "$recommand_item" . "\t3\t" . "$user" . "\n"; + fwrite($myfile, $txt); + for ($i = 1; $i <= $size; $i++) { + $rs = mysqli_fetch_row($data); + $order = $rs[0]; + $name = make_string($rs[1]); + $Price = $rs[2]; + $Type = make_string($rs[3]); + $Exp_Date = $rs[4]; + $num = $rs[5]; + $txt = "$order" . "\t" . "$name" . "\t" . "$Price" . "\t" . "$Type" . "\t" . "$Exp_Date" . "\t" . "$num" . "\n"; + fwrite($myfile, $txt); + } + $fileData = file_get_contents("com2arc.txt"); + fclose($myfile); + return $fileData; + //$recommand = rand(1,4); + } +} +/*********************************************************************************/ +//echo "Loading... \n"; + +if (isset($_POST["post"]))//獲得html form post過來的值 +{ + $read = $_POST["post"]; + // $read = "26.25\t1\t1\t1234\t2\t3\t4\t5"; + //echo $read; + $txt = test_input($read); + $myfile = fopen("arc2php.txt", "w") or die("Unable to open file!"); + fwrite($myfile, $txt); + fclose($myfile); + $myfile = fopen("arc2php.txt", "r"); + $value = fgets($myfile);//first line + $value = rtrim($value);//取消每個字元後的空白 + $value = explode("\t", $value);//用tab分開字串 + $temp = $value[0]; + if ($temp == 00.00) {//初始化 + $data = mysqli_query($con, "select * from item"); + $size = mysqli_num_rows($data);//陣列大小 + $myfile = fopen("com2arc.txt", "w") or die("Unable to open file!"); + $txt = "0\t0\t0000\n"; + fwrite($myfile, $txt); + for ($i = 1; $i <= $size; $i++) { + $rs = mysqli_fetch_row($data); + $order = $rs[0]; + $name = make_string($rs[1]); + $Price = $rs[2]; + $Type = make_string($rs[3]); + $Exp_Date = $rs[4]; + $num = $rs[5]; + $txt = "$order" . "\t" . "$name" . "\t" . "$Price" . "\t" . "$Type" . "\t" . " $Exp_Date" . "\t" . "$num" . "\n"; + fwrite($myfile, $txt); + } + $fileData = file_get_contents("com2arc.txt"); + echo $fileData; + fclose($myfile); + } else { + /* $read = $_POST["post"];////從arc傳上來儲存 + $txt = test_input($read); + $myfile = fopen("arc2php.txt", "w") or die("Unable to open file!"); + fwrite($myfile, $txt); + echo $myfile; + fclose($myfile); + echo $read; + echo "read done!!\n"; */ + + /*******************更新database*********************/ + date_default_timezone_set("Asia/Taipei");//設定時區 + $Time = date("Y-m-d H:i:s");//24-hours format + //echo $Time; + $file = fopen("arc2php.txt", "r"); + $value = fgets($file); + $value = rtrim($value);//取消每個字元後的空白 + $value = explode("\t", $value);//用tab分開字串 + //echo $ID . "\n"; + $Temp = $value[0]; + //echo $Temp . "\n"; + $target_item = $value[1]; + $state = $value[2]; + $user = $value[3]; + $num = array($value[4], $value[5], $value[6], $value[7]); + //顯示出文件內容 + //echo $value[0] . "\t" . $value[1] . "\t" . $value[2] . "\t" . $value[3] . "\t" . $value[4] . "\t" . $value[5] . "
"; + $data = mysqli_query($con, "SELECT * FROM `state`"); + $data = mysqli_query($con, "UPDATE `state` SET `Temperature` = '" . $Temp . "', `Time` = '" . $Time . "' WHERE `state`.`M_ID` = '1' ;"); + $data = mysqli_query($con, "SELECT * FROM `item`"); + for ($i = 1; $i <= 4; $i++) { + $data = mysqli_query($con, "UPDATE `item` SET `Num` = '" . $num[$i - 1] . "' WHERE `item`.`序號` = " . $i . ";"); + } + if($state == 0) + { + echo update($user, 2, $con); + } + /*****************判斷post的內容**************************** */ + /*temp target_item status user*/ + if ($state == 1)//1.uer exist? 2.判斷餘額是否足夠 + { + $sql = "SELECT * FROM `costomer` WHERE `Rfid` = \"" . $user . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_array($search); + if (empty($result)) {//since rfid not found ,return reject at status + echo update($user, 1, $con); + } else {//having found rfid, then check balance + //get balance from database + $sql = "SELECT * FROM `costomer` WHERE `Rfid` = \"" . $user . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_row($search); + + $sql2 = "SELECT * FROM `item` WHERE `序號` = \"" . $target_item . "\";"; + $search2 = mysqli_query($con, $sql2); + $result2 = mysqli_fetch_row($search2); + $cost = $result2[2];//get item cost + if ($result[6] < $cost)//have no enough, return reject at status + { + echo update($user, 1, $con); + } else {//return 3 at status and recomand item + echo update($user, 0, $con); + } + } + } else if ($state == 9)//update sell data + { + //get balance from database + //INSERT INTO `record` (`Buy_Time`, `Rfid`, `Item`, `Cost`, `Balance`) VALUES ('2018-05-31 10:27:26', '1234', 'Soda', '25', '50'); + //SELECT * FROM `item` WHERE `序號` = 1 + //UPDATE `costomer` SET `like2` = '0', `Balance` = '52' WHERE `costomer`.`Rfid` = 1234; + $sql = "SELECT * FROM `costomer` WHERE `Rfid` = \"" . $user . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_row($search); + $balance_old = $result[6]; + $liknum = $result[$target_item + 1] + 1;//get the old like counter + + $sql = "SELECT * FROM `item` WHERE `序號` = \"" . $target_item . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_row($search); + $cost = $result[2];//get item cost + $item = $result[1];//get name + + $balance_new = $balance_old - $cost; + $sql = "INSERT INTO `record` (`Buy_Time`, `Rfid`, `Item`, `Cost`, `Balance`) VALUES('" . $Time . "', '" . $user . "', '" . $item . "', " . $cost . ", '" . $balance_new . "');"; + $data = mysqli_query($con, $sql); + + $like = "like" . (string)$target_item; + $sql = "UPDATE `costomer` SET `" . $like . "` = '" . $liknum . "', `Balance` = '" . $balance_new . "' WHERE `costomer`.`Rfid` = " . $user . ";"; + $data = mysqli_query($con, $sql); + echo update($user, 0, $con); + } + + + //關閉文件 + fclose($file); + } +} +/* sleep(5); +header("Refresh:0");//重新整理 */ +?> \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_in.php b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_in.php new file mode 100644 index 00000000..93a15ad4 --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_in.php @@ -0,0 +1,94 @@ + + + +alert(\"登入失敗\")"; + header("Refresh:0");//重新整理 + } else { + //找到帳密 + $sql = "SELECT * FROM `sign_data` WHERE `account` LIKE \"" . $account . "\";"; + $search = mysqli_query($con, $sql); + $result = mysqli_fetch_row($search); + if ($result[2] == "$password")//密碼正確 + { + echo ""; + if ($result[1] == 1) { + $_SESSION['username'] = $account; + header("Refresh:0; url=item.php"); + } else { + echo ""; + header("Refresh:0");//重新整理 + } + } else { + echo ""; + header("Refresh:0");//重新整理 + } + } +} +?> + + + + + + 饅丁蘑蕈登入系統 + + + + + +
+
+

饅丁蘑蕈登入系統

+
"> + 帳號 : +
+ 密碼 : +
+ + +
+
+
+ + + diff --git a/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_up.php b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_up.php new file mode 100644 index 00000000..10643bcd --- /dev/null +++ b/arc_design_contest/2018/NCKU_Vending_Machine/server_side/sign_up.php @@ -0,0 +1,95 @@ + + + + + + + 饅丁蘑蕈註冊系統 + + + + +
"> +
+

饅丁蘑蕈註冊系統

+       + 帳號 : +
+       + 密碼 : +
+ 確認密碼 : + +
+
+                 + +       + +
+
+ + + alert("註冊成功!");'; + header("Refresh:0; url=sign_in.php"); + } + else { + //若符合顯示帳號、密碼資訊 + echo ''; + } + } + ?> + + + + \ No newline at end of file diff --git a/arc_design_contest/2018/README.md b/arc_design_contest/2018/README.md deleted file mode 100644 index e69de29b..00000000