├── .gitignore ├── LICENSE ├── README.md ├── def_config └── terminal_config.h ├── examples ├── Coocox_lcp1227 │ ├── global_inc.h │ ├── lib │ │ └── cmsis │ │ │ ├── cmsis_boot │ │ │ ├── LPC12xx.h │ │ │ ├── startup │ │ │ │ └── startup_lpc12xx.c │ │ │ ├── system_LPC12xx.c │ │ │ └── system_LPC12xx.h │ │ │ ├── cmsis_core │ │ │ ├── core_cm0.h │ │ │ ├── core_cmFunc.h │ │ │ └── core_cmInstr.h │ │ │ ├── cmsis_lib │ │ │ ├── lpc12xx_gpio.c │ │ │ ├── lpc12xx_gpio.h │ │ │ ├── lpc12xx_iocon.c │ │ │ ├── lpc12xx_iocon.h │ │ │ ├── lpc12xx_libcfig.h │ │ │ ├── lpc12xx_sysctrl.c │ │ │ ├── lpc12xx_sysctrl.h │ │ │ ├── lpc12xx_uart.c │ │ │ ├── lpc12xx_uart.h │ │ │ └── lpc_types.h │ │ │ └── syscalls │ │ │ └── syscalls.c │ ├── lpc1227.cogui │ ├── lpc1227.comarker │ ├── lpc1227.coproj │ ├── lpc1227 │ │ └── Debug │ │ │ └── bin │ │ │ └── lpc1227.bin │ ├── main.c │ ├── my_test_commands │ │ ├── my_test_commands.c │ │ └── my_test_commands.h │ └── terminal_config.h ├── Coocox_stm32f4 │ ├── cmsis │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ ├── core_cmFunc.h │ │ └── core_cmInstr.h │ ├── cmsis_boot │ │ ├── startup │ │ │ └── startup_stm32f4xx.c │ │ ├── stm32f4xx.h │ │ ├── stm32f4xx_conf.h │ │ ├── system_stm32f4xx.c │ │ └── system_stm32f4xx.h │ ├── cmsis_lib │ │ ├── include │ │ │ ├── stm32f4xx_gpio.h │ │ │ ├── stm32f4xx_rcc.h │ │ │ └── stm32f4xx_usart.h │ │ └── source │ │ │ ├── stm32f4xx_gpio.c │ │ │ ├── stm32f4xx_rcc.c │ │ │ └── stm32f4xx_usart.c │ ├── global_inc.h │ ├── main.c │ ├── my_test_commands │ │ ├── my_test_commands.c │ │ └── my_test_commands.h │ ├── stdio │ │ └── printf.c │ ├── stm32f4_terminal_example.cogui │ ├── stm32f4_terminal_example.comarker │ ├── stm32f4_terminal_example.coproj │ ├── stm32f4_terminal_example │ │ └── Debug │ │ │ └── bin │ │ │ ├── stm32f4_terminal_example.bin │ │ │ ├── stm32f4_terminal_example.elf │ │ │ └── stm32f4_terminal_example.hex │ ├── syscalls │ │ └── syscalls.c │ └── terminal_config.h ├── Proteus_emulate │ └── atmega32 │ │ ├── proteus_prj │ │ ├── Backup Of atmega32_terminal_prj.pdsbak │ │ ├── Last Loaded atmega32_terminal_prj.pdsbak │ │ ├── atmega32_terminal_prj.pdsprj │ │ └── atmega32_terminal_prj.pdsprj.PCi.Alexei.workspace │ │ └── src_prj │ │ ├── atmega32_terminal.aps │ │ ├── atmega32_terminal.aws │ │ ├── default │ │ ├── Makefile │ │ ├── atmega32_terminal.elf │ │ └── atmega32_terminal.hex │ │ ├── global_inc.h │ │ ├── lib │ │ ├── spi │ │ │ ├── spi.c │ │ │ └── spi.h │ │ ├── temp_sensor │ │ │ ├── temperature.c │ │ │ └── temperature.h │ │ ├── timer │ │ │ ├── timer1.c │ │ │ └── timer1.h │ │ └── uart │ │ │ ├── uart.c │ │ │ └── uart.h │ │ ├── main.c │ │ ├── terminal_config.h │ │ └── test_cmds │ │ ├── test_cmds.c │ │ └── test_cmds.h ├── dev_cpp │ ├── Makefile.win │ ├── com │ │ ├── com.c │ │ └── com.h │ ├── commands │ │ ├── test_commands.c │ │ └── test_commands.h │ ├── irq │ │ ├── irq.c │ │ └── irq.h │ ├── main.c │ ├── mcu_emulate.dev │ ├── mcu_emulate.exe │ ├── mcu_emulate.layout │ ├── systimer │ │ ├── systimer.c │ │ └── systimer.h │ └── terminal_config.h └── linux │ ├── Time.c │ ├── Time.h │ ├── main.c │ ├── makefile │ ├── terminal │ ├── terminal_config.h │ └── test_commands │ ├── test_commands.c │ └── test_commands.h ├── lib ├── cli_queue.c ├── cli_queue.h ├── cli_string.c └── cli_string.h ├── module ├── cli_input.c ├── cli_input.h ├── cli_log.c ├── cli_log.h ├── cli_time.c └── cli_time.h ├── terminal.c └── terminal.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/history.xml 3 | /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/stm32f4_terminal_example.map 4 | /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/obj/history.xml 5 | /examples/Coocox_stm32f4/stm32f4_terminal_example/stm32f4_terminal_example.elf.xcodeproj/*.pbxproj 6 | /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/obj/dependencies.xml 7 | /examples/Proteus_emulate/atmega32/src_prj/default/dep/*.d 8 | /examples/Proteus_emulate/atmega32/src_prj/default/atmega32_terminal.map 9 | /examples/Proteus_emulate/atmega32/src_prj/default/atmega32_terminal.lss 10 | /examples/Proteus_emulate/atmega32/src_prj/default/atmega32_terminal.eep 11 | /examples/Coocox_lcp1227/lpc1227/Debug/obj 12 | /examples/Coocox_lcp1227/lpc1227/Debug/bin/history.xml 13 | /examples/Coocox_lcp1227/lpc1227/Debug/bin/lpc1227.map 14 | /examples/Coocox_lcp1227/lpc1227/Debug/bin/lpc1227.elf 15 | /examples/Coocox_lcp1227/lpc1227/Debug/bin/lpc1227.hex 16 | /examples/Coocox_lcp1227/lpc1227/lpc1227.elf.xcodeproj/project.pbxproj 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Command Line Interface for microcontrollers 2 | =========================================== 3 | 4 | Flexible terminal settings allow you to integrate it with any microcontroller, without much effort. 5 | 6 | #### Features: 7 | + Flexible setup 8 | + Platform independent 9 | + Logging commands 10 | + The mechanism for aborting execution 11 | + Available keys KeyLeft, KeyRight, Delete, BackSpace, Home, End, Tab 12 | 13 | Required space in the program memory with a minimum working configuration of ~ 10 KB 14 | 15 | INSTALLATION 16 | ------------ 17 | All that is required to work with the terminal, copy all the sources to a shared folder: 18 | 19 | lib/ 20 | module/ 21 | terminal.h 22 | terminal.c 23 | 24 | Copy the configuration file to the project folder, configure the configuration file according to the required parameters: 25 | 26 | def_config/terminal_config.h 27 | 28 | CONFIG FILE 29 | ----------- 30 | 31 | In the configuration file, you must configure the terminal output: 32 | 33 | TERM_TX_RX_EN - the macro controls the inclusion of the terminal output 34 | 35 | Override output functions: 36 | 37 | CLI_Printf 38 | CLI_PutChar 39 | 40 | Next, you must specify the basic parameters of the terminal: 41 | 42 | TERM_SIZE_TASK 43 | TERM_CMD_BUF_SIZE 44 | TERM_CMD_LOG_SIZE 45 | TERM_ARGS_BUF_SIZE 46 | TERM_ARG_SIZE 47 | 48 | After the above, additional terminal components can be configured. 49 | 50 | QUICK START 51 | ----------- 52 | 53 | There are examples of working with a terminal for Windows (you need to install a bundle of virtual COM ports COM1 <-> COM2) and for microcontrollers. 54 | 55 | examples/ 56 | -------------------------------------------------------------------------------- /def_config/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | 18 | // ****************************** Code keys ******************************** 19 | 20 | #define _KEY_INIT(c) ((char)c) 21 | 22 | #define TERM_KEY_ENTER (_KEY_INIT(0x0D)) // Enter command symbol 23 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x08)) // Delete character before cursor position 24 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 25 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 26 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 27 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 28 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 29 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 30 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 31 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 32 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 33 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 34 | #define TERM_KEY_RESET '~' // Reset CPU 35 | 36 | // ************************************************************************** 37 | 38 | // ********************** Terminal Settings ********************************* 39 | 40 | extern void _reset_fcn(); 41 | #define _TERM_VER_ "v1.4" // Terminal version 42 | #define TERM_SIZE_TASK (20) // Max number of commands 43 | #define TERM_CMD_BUF_SIZE (60) // Max number of character buffer string command 44 | #define TERM_CMD_LOG_SIZE (10) // Max number of loging command 45 | #define TERM_ARGS_BUF_SIZE (10) // Max number of arguments in one command 46 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 47 | #define CHAR_INTERRUPT TERM_KEY_ESCAPE // Abort execute command key-code symbol 48 | #define CHAR_BACKSPACE '\x08' // Backspace char 49 | #define STRING_TERM_ENTER "\n\r" // String new line 50 | #define STRING_TERM_ARROW ">> " // String arrow enter 51 | #define RESET_FCN _reset_fcn // Reset CPU Function 52 | 53 | #define TERM_TIMELEFT_EN (1) // Calculate time 54 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 55 | #define TERM_TX_RX_DEB_EN (0) // Addition debug printf 56 | #define TERM_CMD_LOG_EN (1) // Command logging 57 | #define TERM_CMD_AUTOCMPLT_EN (1) // Command AutoComplete 58 | #define TERM_LR_KEY_EN (1) // Move cursor left-rigth 59 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 60 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 61 | #define TERM_PRINT_ERROR_EXEC_EN (1) // Print error after execute command 62 | #define TERM_PRINT_ERROR_ADD_CMD_EN (1) // Print error after added command 63 | #define ECHO_EN (1) // Enter echo enable 64 | 65 | // ************************************************************************** 66 | 67 | // ************************* IO Terminal Settings *************************** 68 | 69 | #if (TERM_TX_RX_EN == 1) 70 | #include 71 | extern void TUSART_Print(const char* str); 72 | extern void TUSART_PutChar(char c); 73 | extern char dbgbuffer[256]; 74 | #define COM_Printf(...) {sprintf(dbgbuffer,__VA_ARGS__);TUSART_Print(dbgbuffer);} 75 | #define CLI_Printf COM_Printf 76 | #if (ECHO_EN == 1) 77 | #define CLI_PutChar TUSART_PutChar 78 | #else // ECHO_EN != 1 79 | #define CLI_PutChar 80 | #endif // ECHO_EN == 1 81 | 82 | #else // TERM_TX_RX_EN != 1 83 | #define CLI_Printf 84 | #define CLI_PutChar 85 | #endif // TERM_TX_RX_EN == 1 86 | // ************************************************************************** 87 | 88 | // *********************** IO Debug Terminal Settings *********************** 89 | 90 | #if (TERM_TX_RX_DEB_EN == 1) 91 | #define CLI_DPrintf printf 92 | #else // TERM_TX_RX_DEB_EN != 1 93 | #define CLI_DPrintf 94 | #endif // TERM_TX_RX_DEB_EN == 1 95 | 96 | // ************************************************************************** 97 | 98 | // ************************ Time calculate Settings ************************* 99 | 100 | #if (TERM_TIMELEFT_EN == 1) 101 | 102 | // yout implementation 103 | extern volatile uint64_t SysTickCtr; // Variable tackts cntr 104 | 105 | #define CLI_GetUs() ((float)SysTickCtr * 10) // System time in us 106 | #define CLI_GetFastUs() (SysTickCtr << 3) // System time in us (not exact) 107 | #define CLI_GetFastMs() (SysTickCtr >> 7) // System time in ms (not exact) 108 | #define CLI_CounterReset() {SysTickCtr = 0;} 109 | 110 | #else // TERM_TIMELEFT_EN != 1 111 | 112 | #define CLI_GetUs() (0) // System time in us 113 | #define CLI_GetFastUs() (0) // System time in us (not exact) 114 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 115 | #define CLI_CounterReset() {} 116 | 117 | #endif // TERM_TIMELEFT_EN == 1 118 | 119 | // ************************************************************************** 120 | 121 | // ********************** memory allocate functions ************************* 122 | 123 | #if (TERM_DEFAULT_ALLOC_EN == 1) 124 | #include 125 | #define cli_malloc malloc 126 | #define cli_free free 127 | #else 128 | #define cli_malloc // your implementation 129 | #define cli_free // your implementation 130 | #endif 131 | 132 | // ************************************************************************** 133 | 134 | // *************************** string functions ***************************** 135 | 136 | #if (TERM_DEFAULT_STRING_EN == 1) 137 | #include 138 | #define cli_memcpy memcpy 139 | #else 140 | #define cli_memcpy // your implementation 141 | #endif 142 | 143 | // ************************************************************************** 144 | 145 | #endif // _TERMIANL_CONFIG_H_ 146 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/global_inc.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOBAL_INC_H_ 2 | #define _GLOBAL_INC_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define _SI_ static inline 10 | 11 | #endif // _GLOBAL_INC_H_0 12 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_boot/startup/startup_lpc12xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file startup_lpc11xx.c 4 | * @author Coocox 5 | * @version V1.0 6 | * @date 05/25/2011 7 | * @brief LPC12XX Devices Startup code. 8 | * This module performs: 9 | * - Set the initial SP 10 | * - Set the vector table entries with the exceptions ISR address 11 | * - Initialize data and bss 12 | * - Setup the microcontroller system. 13 | * - Call the application's entry point. 14 | ******************************************************************************* 15 | */ 16 | 17 | 18 | /*----------Stack Configuration-----------------------------------------------*/ 19 | #define STACK_SIZE 0x00000200 /*!< The Stack size suggest using even number */ 20 | __attribute__ ((section(".co_stack"))) 21 | unsigned long pulStack[STACK_SIZE]; 22 | 23 | unsigned long stack_size = STACK_SIZE; 24 | 25 | /*----------Macro definition--------------------------------------------------*/ 26 | #define WEAK __attribute__ ((weak)) 27 | 28 | 29 | /*----------Declaration of the default fault handlers-------------------------*/ 30 | /* System exception vector handler */ 31 | __attribute__ ((used)) 32 | void WEAK Reset_Handler(void); 33 | void WEAK NMI_Handler(void); 34 | void WEAK HardFault_Handler(void); 35 | void WEAK SVC_Handler(void); 36 | void WEAK PendSV_Handler(void); 37 | void WEAK SysTick_Handler(void); 38 | void WEAK WAKEUP_IRQHandler(void); 39 | void WEAK SSP_IRQHandler(void); 40 | void WEAK I2C_IRQHandler(void); 41 | void WEAK TIMER16_0_IRQHandler(void); 42 | void WEAK TIMER16_1_IRQHandler(void); 43 | void WEAK TIMER32_0_IRQHandler(void); 44 | void WEAK TIMER32_1_IRQHandler(void); 45 | void WEAK SSP0_IRQHandler(void); 46 | void WEAK UART0_IRQHandler(void); 47 | void WEAK UART1_IRQHandler(void); 48 | void WEAK ADC_IRQHandler(void); 49 | void WEAK COMP_IRQHandler(void); 50 | void WEAK WDT_IRQHandler(void); 51 | void WEAK BOD_IRQHandler(void); 52 | void WEAK FMC_IRQHandler(void); 53 | void WEAK PIOINT2_IRQHandler(void); 54 | void WEAK PIOINT1_IRQHandler(void); 55 | void WEAK PIOINT0_IRQHandler(void); 56 | void WEAK PMU_IRQHandler(void); 57 | void WEAK EDM_IRQHandler(void); 58 | void WEAK DMA_IRQHandler(void); 59 | void WEAK RTC_IRQHandler(void); 60 | 61 | 62 | /*----------Symbols defined in linker script----------------------------------*/ 63 | extern unsigned long _sidata; /*!< Start address for the initialization 64 | values of the .data section. */ 65 | extern unsigned long _sdata; /*!< Start address for the .data section */ 66 | extern unsigned long _edata; /*!< End address for the .data section */ 67 | extern unsigned long _sbss; /*!< Start address for the .bss section */ 68 | extern unsigned long _ebss; /*!< End address for the .bss section */ 69 | extern void _eram; /*!< End address for ram */ 70 | 71 | 72 | /*----------Function prototypes-----------------------------------------------*/ 73 | extern int main(void); /*!< The entry point for the application. */ 74 | extern void SystemInit(void); /*!< Setup the microcontroller system(CMSIS) */ 75 | void Default_Reset_Handler(void); /*!< Default reset handler */ 76 | static void Default_Handler(void); /*!< Default exception handler */ 77 | void HardFault_Handler(void); /*!< Default exception handler */ 78 | void BusFault_Handler(void); 79 | 80 | /** 81 | *@brief The minimal vector table for a Cortex M0. Note that the proper constructs 82 | * must be placed on this to ensure that it ends up at physical address 83 | * 0x00000000. 84 | */ 85 | __attribute__ ((used,section(".isr_vector"))) 86 | void (* const g_pfnVectors[])(void) = 87 | { 88 | /*----------Core Exceptions------------------------------------------------ */ 89 | (void *)&pulStack[STACK_SIZE], /*!< The initial stack pointer */ 90 | Default_Reset_Handler, /*!< Reset Handler */ 91 | NMI_Handler, /*!< NMI Handler */ 92 | HardFault_Handler, /*!< Hard Fault Handler */ 93 | 0, /*!< MPU Fault Handler */ 94 | BusFault_Handler, /*!< Bus Fault Handler */ 95 | 0, /*!< Usage Fault Handler */ 96 | 0,0,0,0, /*!< Reserved */ 97 | SVC_Handler, /*!< SVCall Handler */ 98 | 0, /*!< Debug Monitor Handler */ 99 | 0, /*!< Reserved */ 100 | PendSV_Handler, /*!< PendSV Handler */ 101 | SysTick_Handler, /*!< SysTick Handler */ 102 | 103 | /*----------External Exceptions---------------------------------------------*/ 104 | WAKEUP_IRQHandler, /*!< 16+ 0: Wakeup PIO0.0 */ 105 | WAKEUP_IRQHandler, /*!< 16+ 1: Wakeup PIO0.1 */ 106 | WAKEUP_IRQHandler, /*!< 16+ 2: Wakeup PIO0.2 */ 107 | WAKEUP_IRQHandler, /*!< 16+ 3: Wakeup PIO0.2 */ 108 | WAKEUP_IRQHandler, /*!< 16+ 4: Wakeup PIO0.2 */ 109 | WAKEUP_IRQHandler, /*!< 16+ 5: Wakeup PIO0.2 */ 110 | WAKEUP_IRQHandler, /*!< 16+ 6: Wakeup PIO0.2 */ 111 | WAKEUP_IRQHandler, /*!< 16+ 7: Wakeup PIO0.2 */ 112 | WAKEUP_IRQHandler, /*!< 16+ 8: Wakeup PIO0.2 */ 113 | WAKEUP_IRQHandler, /*!< 16+ 9: Wakeup PIO0.2 */ 114 | WAKEUP_IRQHandler, /*!< 16+ 10: Wakeup PIO0.2 */ 115 | WAKEUP_IRQHandler, /*!< 16+ 11: Wakeup PIO0.2 */ 116 | I2C_IRQHandler, /*!< 16+ 12: I2C */ 117 | TIMER16_0_IRQHandler, /*!< 16+ 13: 16-bit Timer0 */ 118 | TIMER16_1_IRQHandler, /*!< 16+ 14: 16-bit Timer1 */ 119 | TIMER32_0_IRQHandler, /*!< 16+ 15: 32-bit Timer0 */ 120 | TIMER32_1_IRQHandler, /*!< 16+ 16: 32-bit Timer1 */ 121 | SSP_IRQHandler, /*!< 16+ 17: SSP */ 122 | UART0_IRQHandler, /*!< 16+ 18: UART0 */ 123 | UART1_IRQHandler, /*!< 16+ 19: UART1 */ 124 | COMP_IRQHandler, /*!< 16+ 20: Comparator */ 125 | ADC_IRQHandler, /*!< 16+ 21: A/D Converter */ 126 | WDT_IRQHandler, /*!< 16+ 22: Watchdog timer */ 127 | BOD_IRQHandler, /*!< 16+ 23: Brown Out Detect */ 128 | FMC_IRQHandler, /*!< 16+ 24: IP2111 Flash Memory Controller */ 129 | PIOINT0_IRQHandler, /*!< 16+ 25: PIO INT0 */ 130 | PIOINT1_IRQHandler, /*!< 16+ 26: PIO INT1 */ 131 | PIOINT2_IRQHandler, /*!< 16+ 27: PIO INT2 */ 132 | PMU_IRQHandler, /*!< 16+ 28: PWU/Wakeup */ 133 | DMA_IRQHandler, /*!< 16+ 29: DMA */ 134 | RTC_IRQHandler, /*!< 16+ 30: RTC */ 135 | EDM_IRQHandler /*!< 16+ 31: Event Driver Micro */ 136 | }; 137 | 138 | 139 | /** 140 | * @brief This is the code that gets called when the processor first 141 | * starts execution following a reset event. Only the absolutely 142 | * necessary set is performed, after which the application 143 | * supplied main() routine is called. 144 | * @param None 145 | * @retval None 146 | */ 147 | void Default_Reset_Handler(void) 148 | { 149 | /* Initialize data and bss */ 150 | unsigned long *pulSrc, *pulDest; 151 | 152 | /* Copy the data segment initializers from flash to SRAM */ 153 | pulSrc = &_sidata; 154 | 155 | for(pulDest = &_sdata; pulDest < &_edata; ) 156 | { 157 | *(pulDest++) = *(pulSrc++); 158 | } 159 | 160 | /* Zero fill the bss segment. */ 161 | for(pulDest = &_sbss; pulDest < &_ebss; ) 162 | { 163 | *(pulDest++) = 0; 164 | } 165 | 166 | /* Setup the microcontroller system. */ 167 | SystemInit(); 168 | 169 | /* Call the application's entry point.*/ 170 | main(); 171 | } 172 | 173 | 174 | /** 175 | *@brief Provide weak aliases for each Exception handler to the Default_Handler. 176 | * As they are weak aliases, any function with the same name will override 177 | * this definition. 178 | */ 179 | #pragma weak Reset_Handler = Default_Reset_Handler 180 | #pragma weak NMI_Handler = Default_Handler 181 | #pragma weak SVC_Handler = Default_Handler 182 | #pragma weak PendSV_Handler = Default_Handler 183 | //#pragma weak SysTick_Handler = Default_Handler 184 | #pragma weak WAKEUP_IRQHandler = Default_Handler 185 | #pragma weak SSP_IRQHandler = Default_Handler 186 | #pragma weak I2C_IRQHandler = Default_Handler 187 | #pragma weak TIMER16_0_IRQHandler = Default_Handler 188 | #pragma weak TIMER16_1_IRQHandler = Default_Handler 189 | #pragma weak TIMER32_0_IRQHandler = Default_Handler 190 | #pragma weak TIMER32_1_IRQHandler = Default_Handler 191 | #pragma weak SSP0_IRQHandler = Default_Handler 192 | #pragma weak UART0_IRQHandler = Default_Handler 193 | #pragma weak UART1_IRQHandler = Default_Handler 194 | #pragma weak ADC_IRQHandler = Default_Handler 195 | #pragma weak COMP_IRQHandler = Default_Handler 196 | #pragma weak WDT_IRQHandler = Default_Handler 197 | #pragma weak BOD_IRQHandler = Default_Handler 198 | #pragma weak FMC_IRQHandler = Default_Handler 199 | #pragma weak PIOINT2_IRQHandler = Default_Handler 200 | #pragma weak PIOINT1_IRQHandler = Default_Handler 201 | #pragma weak PIOINT0_IRQHandler = Default_Handler 202 | #pragma weak PMU_IRQHandler = Default_Handler 203 | #pragma weak EDM_IRQHandler = Default_Handler 204 | #pragma weak DMA_IRQHandler = Default_Handler 205 | #pragma weak RTC_IRQHandler = Default_Handler 206 | 207 | /** 208 | * @brief This is the code that gets called when the processor receives an 209 | * unexpected interrupt. This simply enters an infinite loop, 210 | * preserving the system state for examination by a debugger. 211 | * @param None 212 | * @retval None 213 | */ 214 | static void Default_Handler(void) 215 | { 216 | /* Go into an infinite loop. */ 217 | while (1) 218 | { 219 | //rtt_printf("\nDefault Handler"); 220 | } 221 | } 222 | 223 | void BusFault_Handler(void) 224 | { 225 | while(1){} 226 | } 227 | 228 | /*********************** (C) COPYRIGHT 2010 Coocox ************END OF FILE*****/ 229 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_boot/system_LPC12xx.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * $Id: system_LPC12xx.h 360 2010-08-24 06:26:20Z cnh20509 $ 3 | * 4 | * @file system_LPC12xx.h 5 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer Header File 6 | * for the NXP LPC12xx Device Series 7 | * @version 1.0 8 | * @date 26. Sep. 2010 9 | * @author NXP MCU Team 10 | * 11 | * @note 12 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 13 | * 14 | * @par 15 | * Software that is described herein is for illustrative purposes only 16 | * which provides customers with programming information regarding the 17 | * products. This software is supplied "AS IS" without any warranties. 18 | * NXP Semiconductors assumes no responsibility or liability for the 19 | * use of the software, conveys no license or title under any patent, 20 | * copyright, or mask work right to the product. NXP Semiconductors 21 | * reserves the right to make changes in the software without 22 | * notification. NXP Semiconductors also make no representation or 23 | * warranty that such application will be suitable for the specified 24 | * use without further testing or modification. 25 | ******************************************************************************/ 26 | 27 | #ifndef __SYSTEM_LPC12xx_H 28 | #define __SYSTEM_LPC12xx_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include 35 | 36 | /** @addtogroup LPC12xx_System 37 | * @{ 38 | */ 39 | 40 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 41 | extern uint32_t MainClock; /*!< Main Clock Frequency (Main Clock) */ 42 | 43 | /** 44 | * Initialize the system 45 | * 46 | * @param none 47 | * @return none 48 | * 49 | * @brief Setup the microcontroller system. 50 | * Initialize the System and update the SystemCoreClock variable. 51 | */ 52 | extern void SystemInit (void); 53 | 54 | /** 55 | * Update SystemCoreClock variable 56 | * 57 | * @param none 58 | * @return none 59 | * 60 | * @brief Updates the SystemCoreClock with current core Clock 61 | * retrieved from cpu registers. 62 | */ 63 | extern void SystemCoreClockUpdate (void); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | #endif /* __SYSTEM_LPC12xx_H */ 74 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_lib/lpc12xx_gpio.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * $Id: lpc12xx_gpio.h 519 2010-09-15 01:46:38Z nxp21428 $ 3 | * 4 | * @file lpc12xx_gpio.h 5 | * @brief Contains all macro definitions and function prototypes 6 | * support for GPIO firmware library on lpc12xx. 7 | * @version 1.0 8 | * @date 26. Sep. 2010 9 | * @author NXP MCU Team 10 | * 11 | * @note 12 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 13 | * 14 | * @par 15 | * Software that is described herein is for illustrative purposes only 16 | * which provides customers with programming information regarding the 17 | * products. This software is supplied "AS IS" without any warranties. 18 | * NXP Semiconductors assumes no responsibility or liability for the 19 | * use of the software, conveys no license or title under any patent, 20 | * copyright, or mask work right to the product. NXP Semiconductors 21 | * reserves the right to make changes in the software without 22 | * notification. NXP Semiconductors also make no representation or 23 | * warranty that such application will be suitable for the specified 24 | * use without further testing or modification. 25 | ******************************************************************************/ 26 | 27 | /* Peripheral group ----------------------------------------------------------- */ 28 | /** @defgroup GPIO 29 | * @ingroup LPC1200CMSIS_FwLib_Drivers 30 | * @{ 31 | */ 32 | 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | 35 | #ifndef __LPC12xx_GPIO_H 36 | #define __LPC12xx_GPIO_H 37 | 38 | /* Includes ------------------------------------------------------------------- */ 39 | #include "LPC12xx.h" 40 | #include "lpc_types.h" 41 | 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | 49 | /* Public Macros --------------------------------------------------------------- */ 50 | /** @defgroup GPIO_Public_Types 51 | * @{ 52 | */ 53 | 54 | /** @defgroup GPIO_interrupt_type 55 | * @{ 56 | */ 57 | #define GPIO_INTERRUPT_FALLING ((uint8_t)(0)) 58 | #define GPIO_INTERRUPT_RISING ((uint8_t)(1)) 59 | #define GPIO_INTERRUPT_BOTH_EDGES ((uint8_t)(2)) 60 | #define GPIO_INTERRUPT_LOW ((uint8_t)(3)) 61 | #define GPIO_INTERRUPT_HIGH ((uint8_t)(4)) 62 | 63 | #define PARAM_GPIO_INTERRUPT(TYPE) (( TYPE == GPIO_INTERRUPT_FALLING) || \ 64 | ( TYPE == GPIO_INTERRUPT_RISING) || \ 65 | ( TYPE == GPIO_INTERRUPT_BOTH_EDGES)|| \ 66 | ( TYPE == GPIO_INTERRUPT_LOW) || \ 67 | ( TYPE == GPIO_INTERRUPT_HIGH)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /* Public Functions ----------------------------------------------------------- */ 78 | /** @defgroup GPIO_Public_Functions 79 | * @{ 80 | */ 81 | void GPIO_SetMask(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t mask); 82 | uint32_t GPIO_GetPinValue( LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi); 83 | void GPIO_SetOutValue(LPC_GPIO_TypeDef* pGPIO, uint32_t value); 84 | void GPIO_SetHighLevel(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t value); 85 | void GPIO_SetLowLevel(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t value); 86 | void GPIO_SetInvert(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t value); 87 | void GPIO_SetDir(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t value); 88 | uint32_t GPIO_GetDir( LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi); 89 | 90 | #ifdef _GPIO_INT 91 | void GPIO_IntSetType(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint8_t type ); 92 | uint32_t GPIO_IntGetRawStatus( LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi ); 93 | void GPIO_IntSetMask(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t mask); 94 | uint32_t GPIO_IntGetMaskStatus( LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi ); 95 | void GPIO_IntClear(LPC_GPIO_TypeDef* pGPIO, uint8_t bitPosi, uint32_t value); 96 | #endif 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | #endif /* __LPC12xx_GPIO_H */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /* --------------------------------- End Of File ------------------------------ */ 112 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_lib/lpc12xx_iocon.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * $Id: lpc12xx_iocon.c 377 2010-08-26 03:28:46Z nxp21428 $ 3 | * 4 | * @file lpc12xx_iocon.c 5 | * @brief Contains all functions support for IOCON firmware library on LPC12xx. 6 | * @version 1.0 7 | * @date 26. Sep. 2010 8 | * @author NXP MCU Team 9 | * 10 | * @note 11 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 12 | * 13 | * @par 14 | * Software that is described herein is for illustrative purposes only 15 | * which provides customers with programming information regarding the 16 | * products. This software is supplied "AS IS" without any warranties. 17 | * NXP Semiconductors assumes no responsibility or liability for the 18 | * use of the software, conveys no license or title under any patent, 19 | * copyright, or mask work right to the product. NXP Semiconductors 20 | * reserves the right to make changes in the software without 21 | * notification. NXP Semiconductors also make no representation or 22 | * warranty that such application will be suitable for the specified 23 | * use without further testing or modification. 24 | ******************************************************************************/ 25 | 26 | 27 | /* Peripheral group ----------------------------------------------------------- */ 28 | /** @addtogroup IOCON 29 | * @{ 30 | */ 31 | 32 | /* Includes ------------------------------------------------------------------- */ 33 | #include "lpc12xx_iocon.h" 34 | #include "lpc12xx_libcfig.h" 35 | 36 | #ifdef _IOCON 37 | 38 | /* Public Functions ----------------------------------------------------------- */ 39 | /** @addtogroup IOCON_Private_Functions 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @brief Setup the PIO port selection function 45 | * @param mode Pointer to a IOCON_PIO_CFG_Type structure 46 | * 47 | * @return None 48 | */ 49 | void IOCON_SetFunc ( IOCON_PIO_CFG_Type *mode) 50 | { 51 | uint32_t offset; 52 | uint32_t func; 53 | uint32_t tmp; 54 | uint32_t *p = (uint32_t *)&LPC_IOCON->PIO2_28; 55 | 56 | CHECK_PARAM( PARAM_IOCON_PIO_TYPE(mode->type) ); 57 | CHECK_PARAM( PARAM_IOCON_PIO_MODE(mode->pinmode)); 58 | CHECK_PARAM( PARAM_IOCON_PIO_DRV(mode->drive) ); 59 | CHECK_PARAM( PARAM_IOCON_PIO_AD(mode->ad) ); 60 | CHECK_PARAM( PARAM_IOCON_PIO_OD(mode->od)); 61 | CHECK_PARAM( PARAM_IOCON_PIO_INV(mode->invert) ); 62 | CHECK_PARAM( PARAM_IOCON_PIO_SMODE(mode->sm)); 63 | CHECK_PARAM( PARAM_IOCON_PIO_CLKDIV(mode->cd)); 64 | 65 | offset = (mode->type >> 6); 66 | func = (mode->type & 0xf); 67 | 68 | if(offset == 0x24 || offset == 0x25){ //0x90, 0x94 right shift 2 bit 69 | tmp = (uint32_t)(func|(mode->pmode)|(mode->od)|(mode->invert)|(mode->sm)|(mode->cd)); 70 | 71 | }else{ 72 | tmp = (uint32_t)(func|(mode->pinmode)|(mode->drive)|(mode->ad)|(mode->od)|(mode->invert)|(mode->sm)|(mode->cd)); 73 | } 74 | *(uint32_t *)(p + offset) = tmp; 75 | } 76 | 77 | /** 78 | * @brief Fills each IOCON_PIO_CFG_Type member with its default value. 79 | * 80 | * @param mode pointer to a IOCON_PIO_CFG_Type structure which will be initialized. 81 | * @retval None 82 | */ 83 | void IOCON_StructInit ( IOCON_PIO_CFG_Type *mode) 84 | { 85 | mode->type = 0x0; 86 | mode->pinmode = IOCON_PIO_MODE_PULLUP; 87 | mode->invert = IOCON_PIO_INV_NOT; 88 | mode->pmode = IOCON_PIO_PMODE_DISABLE; 89 | mode->od = IOCON_PIO_OD_DISABLE; 90 | mode->drive = IOCON_PIO_DRV_2MA_12MA; 91 | mode->ad = IOCON_PIO_AD_DIGITAL; 92 | mode->sm = IOCON_PIO_SMODE_BYPASS; 93 | mode->cd = IOCON_PIO_CLKDIV_0; 94 | } 95 | /** 96 | * @} 97 | */ 98 | 99 | #endif 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /* --------------------------------- End Of File ------------------------------ */ 106 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_lib/lpc12xx_libcfig.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************************* 2 | * $Id: lpc12xx_libcfg_default.h 550 2010-09-20 06:55:52Z cnh20509 $ 3 | * 4 | * @file lpc12xx_libcfg.h 5 | * @brief Default Library configuration header file 6 | * @version 1.0 7 | * @date 26. Sep. 2010 8 | * @author NXP MCU Team 9 | * 10 | * @note 11 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 12 | * 13 | * @par 14 | * Software that is described herein is for illustrative purposes only 15 | * which provides customers with programming information regarding the 16 | * products. This software is supplied "AS IS" without any warranties. 17 | * NXP Semiconductors assumes no responsibility or liability for the 18 | * use of the software, conveys no license or title under any patent, 19 | * copyright, or mask work right to the product. NXP Semiconductors 20 | * reserves the right to make changes in the software without 21 | * notification. NXP Semiconductors also make no representation or 22 | * warranty that such application will be suitable for the specified 23 | * use without further testing or modification. 24 | *******************************************************************************************/ 25 | 26 | /* Library Configuration group ------------------------------------------------------------*/ 27 | /** @defgroup LIBCFG_DEFAULT 28 | * @ingroup LPC1200CMSIS_FwLib_Drivers 29 | * @{ 30 | */ 31 | 32 | #ifndef __LPC12xx_LIBCFG_DEFAULT_H 33 | #define __LPC12xx_LIBCFG_DEFAULT_H 34 | 35 | /* Includes -------------------------------------------------------------------------------*/ 36 | #include "lpc_types.h" 37 | 38 | /* Public Macros --------------------------------------------------------------------------*/ 39 | /** @defgroup LIBCFG_DEFAULT_Public_Macros 40 | * @{ 41 | */ 42 | 43 | /************************** DEBUG MODE DEFINITIONS *****************************************/ 44 | /* Un-comment the line below to compile the library in DEBUG mode, this will expanse 45 | the "CHECK_PARAM" macro in the FW library code */ 46 | 47 | //#define DEBUG 48 | 49 | 50 | /******************* PERIPHERAL FW LIBRARY CONFIGURATION DEFINITIONS ***********************/ 51 | 52 | /* Comment the line below to disable the specific peripheral inclusion */ 53 | 54 | /* GPIO -------------------------------- */ 55 | #define _GPIO 56 | #define _GPIO_INT 57 | 58 | /* UART -------------------------------- */ 59 | #define _UART 60 | #define _UART_INT 61 | //#define _MODEM 62 | //#define _RS485 63 | //#define _IRDA 64 | 65 | /* IOCON ------------------------------- */ 66 | #define _IOCON 67 | 68 | /* CRC --------------------------------- */ 69 | #define _CRC 70 | 71 | /* SSP --------------------------------- */ 72 | #define _SSP 73 | 74 | /* FLASH ------------------------------- */ 75 | #define _FLASH 76 | 77 | /* RTC --------------------------------- */ 78 | #define _RTC 79 | 80 | /* I2C --------------------------------- */ 81 | #define _I2C 82 | 83 | /* PMU --------------------------------- */ 84 | #define _PMU 85 | 86 | /* TIMER32 ----------------------------- */ 87 | #define _TIMER32 88 | 89 | /* TIMER16 ----------------------------- */ 90 | #define _TIMER16 91 | 92 | /* WDT --------------------------------- */ 93 | #define _WDT 94 | 95 | /* DMA --------------------------------- */ 96 | #define _DMA 97 | 98 | /* SYSCTRL ----------------------------- */ 99 | #define _SYSCTRL 100 | 101 | /* ADC --------------------------------- */ 102 | #define _ADC 103 | 104 | /* comparator -------------------------- */ 105 | #define _COMP 106 | 107 | /************************** GLOBAL/PUBLIC MACRO DEFINITIONS *********************************/ 108 | 109 | #ifdef DEBUG 110 | /******************************************************************************* 111 | * @brief The CHECK_PARAM macro is used for function's parameters check. 112 | * It is used only if the library is compiled in DEBUG mode. 113 | * @param[in] expr - If expr is false, it calls check_failed() function 114 | * which reports the name of the source file and the source 115 | * line number of the call that failed. 116 | * - If expr is true, it returns no value. 117 | * @return None 118 | *******************************************************************************/ 119 | #define CHECK_PARAM(expr) ((expr) ? (void)0 : check_failed((uint8_t *)__FILE__, __LINE__)) 120 | #else 121 | #define CHECK_PARAM(expr) 122 | #endif /* DEBUG */ 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | 129 | /* Public Functions ----------------------------------------------------------- */ 130 | /** @defgroup LIBCFG_Public_Functions 131 | * @{ 132 | */ 133 | 134 | #ifdef DEBUG 135 | void check_failed(uint8_t *file, uint32_t line); 136 | #endif 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | #endif /* __LPC12xx_LIBCFG_H */ 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /* --------------------------------- End Of File ------------------------------ */ 149 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_lib/lpc12xx_sysctrl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * $Id: lpc12xx_sysctrl.h 457 2010-09-08 06:01:37Z cnh82208 $ 3 | * 4 | * @file lpc12xx_sysctrl.h 5 | * @brief Contains all macro definitions and function prototypes 6 | * support for SysCtrl firmware library on LPC12xx. 7 | * @version 1.0 8 | * @date 26. Sep. 2010 9 | * @author NXP MCU Team 10 | * 11 | * @note 12 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 13 | * 14 | * @par 15 | * Software that is described herein is for illustrative purposes only 16 | * which provides customers with programming information regarding the 17 | * products. This software is supplied "AS IS" without any warranties. 18 | * NXP Semiconductors assumes no responsibility or liability for the 19 | * use of the software, conveys no license or title under any patent, 20 | * copyright, or mask work right to the product. NXP Semiconductors 21 | * reserves the right to make changes in the software without 22 | * notification. NXP Semiconductors also make no representation or 23 | * warranty that such application will be suitable for the specified 24 | * use without further testing or modification. 25 | ******************************************************************************/ 26 | 27 | /* Peripheral group --------------------------------------------------------- */ 28 | /** @defgroup SYSCTRL 29 | * @ingroup LPC1200CMSIS_FwLib_Drivers 30 | * @{ 31 | */ 32 | 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | #ifndef __LPC12xx_SYSCTRL_H 35 | #define __LPC12xx_SYSCTRL_H 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ----------------------------------------------------------------- */ 42 | #include "LPC12xx.h" 43 | #include "lpc_types.h" 44 | 45 | 46 | /* Public Macros -------------------------------------------------------------- */ 47 | /** @defgroup SYSCTRL_Public_Macros 48 | * @{ 49 | */ 50 | 51 | /** @defgroup SYS_remap_mode 52 | * @{ 53 | */ 54 | 55 | #define SYS_BOOTLOADERMODE 0x00 /**< Interrupt vectors are re-mapped to Boot ROM */ 56 | #define SYS_USERRAMMODE 0x01 /**< Interrupt vectors are re-mapped to Static RAM */ 57 | #define SYS_USERFLASHMODE 0x02 /**< Interrupt vectors are not re-mapped and reside in Flash */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | 64 | /** @defgroup SYS_clock_source 65 | * @{ 66 | */ 67 | 68 | #define SYS_IRCOSC 0x00 /**< IRC oscillator */ 69 | #define SYS_SYSOSC 0x01 /**< System oscillator */ 70 | #define SYS_SYSPLLCLKIN 0x01 /**< Input clock to system PLL */ 71 | #define SYS_WDTOSC 0x02 /**< WDT oscillator */ 72 | #define SYS_SYSPLLCLKOUT 0x03 /**< System PLL clock out */ 73 | #define SYS_MAINCLK 0x01 /**< Main clock */ 74 | #define SYS_MAINCLKOUT 0x03 /**< Main clock */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | 81 | /** @defgroup SYS_RTCOSC_control 82 | * @{ 83 | */ 84 | #define SYS_RTC_1HZ 0x00 /**< 1 Hz clock */ 85 | #define SYS_RTC_DELAY1HZ 0x01 /**< delayed 1 Hz clock */ 86 | #define SYS_RTC_1KHZ 0x03 /**< 1 KHz clock */ 87 | #define SYS_RTC_PCLK 0x07 /**< RTC PCLK */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | 94 | /** @defgroup SYS_AHBCLK_control 95 | * @{ 96 | */ 97 | 98 | #define SYS_AHBCLKCTRL_SYS (1<<0) /**< Enables clock for AHB to APB bridge, to AHB matrix, 99 | to Cortex-M3 FCLK and HCLK, to SysCon, and to 100 | PMU. This bit is read only */ 101 | #define SYS_AHBCLKCTRL_ROM (1<<1) /**< Clock for ROM */ 102 | #define SYS_AHBCLKCTRL_RAM (1<<2) /**< Clock for RAM */ 103 | #define SYS_AHBCLKCTRL_FLASH1 (1<<3) /**< Clock for Flash 1 */ 104 | #define SYS_AHBCLKCTRL_FLASH2 (1<<4) /**< Clock for Flash 2 */ 105 | #define SYS_AHBCLKCTRL_I2C (1<<5) /**< Clock for I2C */ 106 | #define SYS_AHBCLKCTRL_CRC (1<<6) /**< Clock for CRC */ 107 | #define SYS_AHBCLKCTRL_CT16B0 (1<<7) /**< Clock for 16 bit counter/timer 0 */ 108 | #define SYS_AHBCLKCTRL_CT16B1 (1<<8) /**< Clock for 16 bit counter/timer 1 */ 109 | #define SYS_AHBCLKCTRL_CT32B0 (1<<9) /**< Clock for 32 bit counter/timer 0 */ 110 | #define SYS_AHBCLKCTRL_CT32B1 (1<<10) /**< Clock for 32 bit counter/timer 1 */ 111 | #define SYS_AHBCLKCTRL_SSP (1<<11) /**< Clock for SSP */ 112 | #define SYS_AHBCLKCTRL_UART0 (1<<12) /**< Clock for UART0 */ 113 | #define SYS_AHBCLKCTRL_UART1 (1<<13) /**< Clock for UART1 */ 114 | #define SYS_AHBCLKCTRL_ADC (1<<14) /**< Clock for ADC */ 115 | #define SYS_AHBCLKCTRL_WDT (1<<15) /**< Clock for WDT */ 116 | #define SYS_AHBCLKCTRL_IOCON (1<<16) /**< Clock for IO configuration block */ 117 | #define SYS_AHBCLKCTRL_DMA (1<<17) /**< Clock for DMA */ 118 | #define SYS_AHBCLKCTRL_EZH (1<<18) /**< Clock for EZH */ 119 | #define SYS_AHBCLKCTRL_RTC (1<<19) /**< Clock for RTC */ 120 | #define SYS_AHBCLKCTRL_CMP (1<<20) /**< Clock for CMP */ 121 | //#define SYS_AHBCLKCTRL_GPIO3 (1<<28) /**< Clock for GPIO3 */ 122 | #define SYS_AHBCLKCTRL_GPIO2 (1<<29) /**< Clock for GPIO2 */ 123 | #define SYS_AHBCLKCTRL_GPIO1 (1<<30) /**< Clock for GPIO1 */ 124 | #define SYS_AHBCLKCTRL_GPIO0 (1UL<<31) /**< Clock for GPIO0 */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | 131 | /** @defgroup SYS_peripheralRST_control 132 | * @{ 133 | */ 134 | /* Macro defines for Peripheral reset control register */ 135 | #define SYS_PRESETCTRL_SSP_RST (1<<0) /**< SSP reset disabled */ 136 | #define SYS_PRESETCTRL_I2C_RST (1<<1) /**< I2C reset disabled */ 137 | #define SYS_PRESETCTRL_UART0_RST (1<<2) /**< UART0 reset disabled */ 138 | #define SYS_PRESETCTRL_UART1_RST (1<<3) /**< UART1 reset disabled */ 139 | #define SYS_PRESETCTRL_CT16B0_RST (1<<4) /**< CT16B0 reset disabled */ 140 | #define SYS_PRESETCTRL_CT16B1_RST (1<<5) /**< CT16B1 reset disabled */ 141 | #define SYS_PRESETCTRL_CT32B0_RST (1<<6) /**< CT32B0 reset disabled */ 142 | #define SYS_PRESETCTRL_CT32B1_RST (1<<7) /**< CT32B1 reset disabled */ 143 | #define SYS_PRESETCTRL_CMP_RST (1<<8) /**< CMP reset disabled */ 144 | #define SYS_PRESETCTRL_CRC_RST (1<<9) /**< CRC reset disabled */ 145 | #define SYS_PRESETCTRL_DMA_RST (1<<10) /**< DMA reset disabled */ 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | 152 | /** @defgroup SYS_NMI_source_control 153 | * @{ 154 | */ 155 | 156 | #define SYS_NMI_I2C 0 /**< I2C interrupt */ 157 | #define SYS_NMI_CT16B1 1 /**< CT16B1 interrupt */ 158 | #define SYS_NMI_CT16B0 2 /**< CT16B0 interrupt */ 159 | #define SYS_NMI_CT32B0 3 /**< CT32B0 interrupt */ 160 | #define SYS_NMI_CT32B1 4 /**< CT32B1 interrupt */ 161 | #define SYS_NMI_SSP 5 /**< SSP interrupt */ 162 | #define SYS_NMI_UART0 6 /**< UART0 interrupt */ 163 | #define SYS_NMI_UART1 7 /**< UART1 interrupt */ 164 | #define SYS_NMI_COMP 8 /**< COMP interrupt */ 165 | #define SYS_NMI_ADC 9 /**< ADC interrupt */ 166 | #define SYS_NMI_WDT 10 /**< WDT interrupt */ 167 | #define SYS_NMI_BOD 11 /**< BOD interrupt */ 168 | #define SYS_NMI_FLASH 12 /**< FLASH interrupt */ 169 | #define SYS_NMI_EINT0 13 /**< EINT0 interrupt */ 170 | #define SYS_NMI_EINT1 14 /**< EINT1 interrupt */ 171 | #define SYS_NMI_EINT2 15 /**< EINT2 interrupt */ 172 | #define SYS_NMI_PMU 16 /**< PMU interrupt */ 173 | #define SYS_NMI_DMA 17 /**< DMA interrupt */ 174 | #define SYS_NMI_RTC 18 /**< RTC interrupt */ 175 | #define SYS_NMI_DISABLE 24 /**< NMI disabled */ 176 | 177 | /** 178 | * @} 179 | */ 180 | 181 | 182 | /** @defgroup SYS_startlogic0_control 183 | * @{ 184 | */ 185 | 186 | #define SYS_APR0_0 (1<<0) /**< PIO0_0 */ 187 | #define SYS_APR0_1 (1<<1) /**< PIO0_1 */ 188 | #define SYS_APR0_2 (1<<2) /**< PIO0_2 */ 189 | #define SYS_APR0_3 (1<<3) /**< PIO0_3 */ 190 | #define SYS_APR0_4 (1<<4) /**< PIO0_4 */ 191 | #define SYS_APR0_5 (1<<5) /**< PIO0_5 */ 192 | #define SYS_APR0_6 (1<<6) /**< PIO0_6 */ 193 | #define SYS_APR0_7 (1<<7) /**< PIO0_7 */ 194 | #define SYS_APR0_8 (1<<8) /**< PIO0_8 */ 195 | #define SYS_APR0_9 (1<<9) /**< PIO0_9 */ 196 | #define SYS_APR0_10 (1<<10) /**< PIO0_10 */ 197 | #define SYS_APR0_11 (1<<11) /**< PIO0_11 */ 198 | 199 | /** 200 | * @} 201 | */ 202 | 203 | /** @defgroup SYS_startlogic1_control 204 | * @{ 205 | */ 206 | 207 | #define SYS_APR1_I2C (1<<0) /**< I2C interrupt */ 208 | #define SYS_APR1_CT16B1 (1<<1) /**< CT16B1 interrupt */ 209 | #define SYS_APR1_CT16B0 (1<<2) /**< CT16B0 interrupt */ 210 | #define SYS_APR1_CT32B0 (1<<3) /**< CT32B0 interrupt */ 211 | #define SYS_APR1_CT32B1 (1<<4) /**< CT32B1 interrupt */ 212 | #define SYS_APR1_SSP (1<<5) /**< SSP interrupt */ 213 | #define SYS_APR1_UART0 (1<<6) /**< UART0 interrupt */ 214 | #define SYS_APR1_UART1 (1<<7) /**< UART1 interrupt */ 215 | #define SYS_APR1_COMP (1<<8) /**< COMP interrupt */ 216 | #define SYS_APR1_ADC (1<<9) /**< ADC interrupt */ 217 | #define SYS_APR1_WDT (1<<10) /**< WDT interrupt */ 218 | #define SYS_APR1_BOD (1<<11) /**< BOD interrupt */ 219 | #define SYS_APR1_FLASH (1<<12) /**< FLASH interrupt */ 220 | #define SYS_APR1_EINT0 (1<<13) /**< EINT0 interrupt */ 221 | #define SYS_APR1_EINT1 (1<<14) /**< EINT1 interrupt */ 222 | #define SYS_APR1_EINT2 (1<<15) /**< EINT2 interrupt */ 223 | #define SYS_APR1_PMU (1<<16) /**< PMU interrupt */ 224 | #define SYS_APR1_DMA (1<<17) /**< DMA interrupt */ 225 | #define SYS_APR1_RTC (1<<18) /**< RTC interrupt */ 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | 232 | /** @defgroup SYS_edge_control 233 | * @{ 234 | */ 235 | 236 | #define SYS_FALLINGEDGE 0x00 237 | #define SYS_RISINGEDGE 0x01 238 | 239 | /** 240 | * @} 241 | */ 242 | 243 | 244 | /** @defgroup SYS_power_control 245 | * @{ 246 | */ 247 | 248 | #define SYS_PDRUNCFG_IRCOUT (1<<0) /**< IRC OSC output */ 249 | #define SYS_PDRUNCFG_IRC (1<<1) /**< IRC OSC */ 250 | #define SYS_PDRUNCFG_FLASH (1<<2) /**< Flash */ 251 | #define SYS_PDRUNCFG_BOD (1<<3) /**< BOD */ 252 | #define SYS_PDRUNCFG_ADC (1<<4) /**< ADC */ 253 | #define SYS_PDRUNCFG_SYSOSC (1<<5) /**< System OSC */ 254 | #define SYS_PDRUNCFG_WDTOSC (1<<6) /**< WDT OSC */ 255 | #define SYS_PDRUNCFG_SYSPLL (1<<7) /**< System PLL */ 256 | 257 | /** 258 | * @} 259 | */ 260 | 261 | 262 | 263 | /** 264 | * @} 265 | */ 266 | 267 | /* Public Functions ----------------------------------------------------------- */ 268 | /** @defgroup SYSCTRL_Public_Functions 269 | * @{ 270 | */ 271 | 272 | uint32_t SYS_GetResetStatus(void); 273 | void SYS_SetMemMap(uint32_t MapValue); 274 | void SYS_SelectSystemPLLCLKSource(uint32_t ClkSrc); 275 | void SYS_ConfigSystemPLL(uint32_t M, uint32_t P, 276 | FunctionalState DirectState, FunctionalState BypassEn); 277 | void SYS_SelectMainCLKSource(uint32_t ClkSrc); 278 | void SYS_SetAHBClockDiv(uint32_t DivNum); 279 | void SYS_ConfigAHBCLK(uint32_t AHBClk_Type, FunctionalState CmdState); 280 | void SYS_ConfigWDTOSC(uint32_t DivNum, uint32_t FreqSel); 281 | void SYS_ResetPeripheral(uint32_t RSTBlock, FunctionalState CmdState); 282 | void SYS_SetSSPClockDiv(uint32_t DivNum); 283 | void SYS_SetUART0ClockDiv(uint32_t DivNum); 284 | void SYS_SetUART1ClockDiv(uint32_t DivNum); 285 | void SYS_SetGlitchFilter0ClockDiv(uint32_t DivNum); 286 | void SYS_SetGlitchFilter1ClockDiv(uint32_t DivNum); 287 | void SYS_SetGlitchFilter2ClockDiv(uint32_t DivNum); 288 | void SYS_SetGlitchFilter3ClockDiv(uint32_t DivNum); 289 | void SYS_SetGlitchFilter4ClockDiv(uint32_t DivNum); 290 | void SYS_SetGlitchFilter5ClockDiv(uint32_t DivNum); 291 | void SYS_SetGlitchFilter6ClockDiv(uint32_t DivNum); 292 | void SYS_SetSysTickClockDiv(uint32_t DivNum); 293 | void SYS_ConfigCLKOUTCLK(uint32_t ClkSrc, uint32_t DivNum); 294 | void SYS_ConfigDeepSleep(uint32_t DStype, FunctionalState CmdState); 295 | void SYS_ConfigPowerDown(uint32_t PDtype, FunctionalState CmdState); 296 | void SYS_ConfigWakeUp(uint32_t WUtype, FunctionalState CmdState); 297 | void SYS_NMIInterrupt(uint32_t Peripheral_int); 298 | void SYS_EnableStartLogic0(uint32_t Pin_x, FunctionalState CmdState); 299 | void SYS_SetStartLogic0Edge(uint32_t Pin_x, uint32_t Edge); 300 | void SYS_ResetStartLogic0(uint32_t Pin_x); 301 | void SYS_EnableStartLogic0(uint32_t Peripheral_int, FunctionalState CmdState); 302 | void SYS_SetStartLogic0Edge(uint32_t Peripheral_int, uint32_t Edge); 303 | void SYS_ResetStartLogic0(uint32_t Peripheral_int); 304 | uint32_t SYS_GetDeviceID(void); 305 | 306 | 307 | 308 | /** 309 | * @} 310 | */ 311 | 312 | #ifdef __cplusplus 313 | } 314 | #endif 315 | 316 | #endif /* __LPC12xx_SSP_H */ 317 | 318 | /** 319 | * @} 320 | */ 321 | 322 | /* --------------------------------- End Of File ------------------------------ */ 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/cmsis_lib/lpc_types.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * $Id$ 3 | * 4 | * @file lpc_types.h 5 | * @brief Contains the NXP ABL typedefs for C standard types. 6 | * It is intended to be used in ISO C conforming development 7 | * environments and checks for this insofar as it is possible 8 | * to do so. 9 | * @version 1.0 10 | * @date 23. June. 2010 11 | * @author NXP MCU Team 12 | * 13 | * @note 14 | * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved. 15 | * 16 | * @par 17 | * Software that is described herein is for illustrative purposes only 18 | * which provides customers with programming information regarding the 19 | * products. This software is supplied "AS IS" without any warranties. 20 | * NXP Semiconductors assumes no responsibility or liability for the 21 | * use of the software, conveys no license or title under any patent, 22 | * copyright, or mask work right to the product. NXP Semiconductors 23 | * reserves the right to make changes in the software without 24 | * notification. NXP Semiconductors also make no representation or 25 | * warranty that such application will be suitable for the specified 26 | * use without further testing or modification. 27 | ******************************************************************************/ 28 | 29 | /* Type group ----------------------------------------------------------- */ 30 | /** @defgroup LPC_Types 31 | * @ingroup LPC1200CMSIS_FwLib_Drivers 32 | * @{ 33 | */ 34 | 35 | #ifndef LPC_TYPES_H 36 | #define LPC_TYPES_H 37 | 38 | /* Includes ------------------------------------------------------------------- */ 39 | #include 40 | 41 | 42 | /* Public Types --------------------------------------------------------------- */ 43 | /** @defgroup LPC_Types_Public_Types 44 | * @{ 45 | */ 46 | 47 | /** 48 | * @brief Boolean Type definition 49 | */ 50 | typedef enum {FALSE = 0, TRUE = !FALSE} Bool; 51 | 52 | /** 53 | * @brief Flag Status and Interrupt Flag Status type definition 54 | */ 55 | typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState; 56 | #define PARAM_SETSTATE(State) ((State==RESET) || (State==SET)) 57 | 58 | /** 59 | * @brief Functional State Definition 60 | */ 61 | typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; 62 | #define PARAM_FUNCTIONALSTATE(State) ((State==DISABLE) || (State==ENABLE)) 63 | 64 | /** 65 | * @ Status type definition 66 | */ 67 | typedef enum {ERROR = 0, SUCCESS = !ERROR} Status; 68 | 69 | 70 | /** 71 | * Read/Write transfer type mode (Block or non-block) 72 | */ 73 | typedef enum 74 | { 75 | NONE_BLOCKING = 0, /**< None Blocking type */ 76 | BLOCKING, /**< Blocking type */ 77 | } TRANSFER_BLOCK_Type; 78 | 79 | 80 | /** Pointer to Function returning Void (any number of parameters) */ 81 | typedef void (*PFV)(); 82 | 83 | /** Pointer to Function returning int32_t (any number of parameters) */ 84 | typedef int32_t(*PFI)(); 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | 91 | /* Public Macros -------------------------------------------------------------- */ 92 | /** @defgroup LPC_Types_Public_Macros 93 | * @{ 94 | */ 95 | 96 | /* _BIT(n) sets the bit at position "n" 97 | * _BIT(n) is intended to be used in "OR" and "AND" expressions: 98 | * e.g., "(_BIT(3) | _BIT(7))". 99 | */ 100 | #undef _BIT 101 | /* Set bit macro */ 102 | #define _BIT(n) (1< = (any_expression) & _BITMASK(x), where 0 < x <= 32. 118 | * If "any_expression" results in a value that is larger than can be 119 | * contained in 'x' bits, the bits above 'x - 1' are masked off. When 120 | * used with the _SBF example above, the example would be written: 121 | * a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16)) 122 | * This ensures that the value written to a_reg is no wider than 123 | * 16 bits, and makes the code easier to read and understand. 124 | */ 125 | #undef _BITMASK 126 | /* Bitmask creation macro */ 127 | #define _BITMASK(field_width) ( _BIT(field_width) - 1) 128 | 129 | /* NULL pointer */ 130 | #ifndef NULL 131 | #define NULL ((void*) 0) 132 | #endif 133 | 134 | /* Number of elements in an array */ 135 | #define NELEMENTS(array) (sizeof (array) / sizeof (array[0])) 136 | 137 | /* Static data/function define */ 138 | #define STATIC static 139 | /* External data/function define */ 140 | #define EXTERN extern 141 | 142 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 143 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | 150 | /* Old Type Definition compatibility ------------------------------------------ */ 151 | /** @addtogroup LPC_Types_Public_Types 152 | * @{ 153 | */ 154 | 155 | /** SMA type for character type */ 156 | typedef char CHAR; 157 | 158 | /** SMA type for 8 bit unsigned value */ 159 | typedef uint8_t UNS_8; 160 | 161 | /** SMA type for 8 bit signed value */ 162 | typedef int8_t INT_8; 163 | 164 | /** SMA type for 16 bit unsigned value */ 165 | typedef uint16_t UNS_16; 166 | 167 | /** SMA type for 16 bit signed value */ 168 | typedef int16_t INT_16; 169 | 170 | /** SMA type for 32 bit unsigned value */ 171 | typedef uint32_t UNS_32; 172 | 173 | /** SMA type for 32 bit signed value */ 174 | typedef int32_t INT_32; 175 | 176 | /** SMA type for 64 bit signed value */ 177 | typedef int64_t INT_64; 178 | 179 | /** SMA type for 64 bit unsigned value */ 180 | typedef uint64_t UNS_64; 181 | 182 | /** 32 bit boolean type */ 183 | typedef Bool BOOL_32; 184 | 185 | /** 16 bit boolean type */ 186 | typedef Bool BOOL_16; 187 | 188 | /** 8 bit boolean type */ 189 | typedef Bool BOOL_8; 190 | 191 | /** 192 | * @} 193 | */ 194 | 195 | 196 | #endif /* LPC_TYPES_H */ 197 | 198 | /** 199 | * @} 200 | */ 201 | 202 | /* --------------------------------- End Of File ------------------------------ */ 203 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lib/cmsis/syscalls/syscalls.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//***** 2 | * @file stdio.c 3 | * @brief Implementation of newlib syscall 4 | ********************************************************************************/ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #undef errno 12 | extern int errno; 13 | extern int _end; 14 | 15 | /*This function is used for handle heap option*/ 16 | __attribute__ ((used)) 17 | caddr_t _sbrk ( int incr ) 18 | { 19 | static unsigned char *heap = NULL; 20 | unsigned char *prev_heap; 21 | 22 | if (heap == NULL) { 23 | heap = (unsigned char *)&_end; 24 | } 25 | prev_heap = heap; 26 | 27 | heap += incr; 28 | 29 | return (caddr_t) prev_heap; 30 | } 31 | 32 | __attribute__ ((used)) 33 | int link(char *old, char *new) 34 | { 35 | return -1; 36 | } 37 | 38 | __attribute__ ((used)) 39 | int _close(int file) 40 | { 41 | return -1; 42 | } 43 | 44 | __attribute__ ((used)) 45 | int _fstat(int file, struct stat *st) 46 | { 47 | st->st_mode = S_IFCHR; 48 | return 0; 49 | } 50 | 51 | __attribute__ ((used)) 52 | int _isatty(int file) 53 | { 54 | return 1; 55 | } 56 | 57 | __attribute__ ((used)) 58 | int _lseek(int file, int ptr, int dir) 59 | { 60 | return 0; 61 | } 62 | 63 | /*Low layer read(input) function*/ 64 | __attribute__ ((used)) 65 | int _read(int file, char *ptr, int len) 66 | { 67 | 68 | #if 0 69 | //user code example 70 | int i; 71 | (void)file; 72 | 73 | for(i = 0; i < len; i++) 74 | { 75 | // UART_GetChar is user's basic input function 76 | *ptr++ = UART_GetChar(); 77 | } 78 | 79 | #endif 80 | 81 | return len; 82 | } 83 | 84 | 85 | /*Low layer write(output) function*/ 86 | /* 87 | __attribute__ ((used)) 88 | int _write(int file, char *ptr, int len) 89 | { 90 | 91 | #if 0 92 | //user code example 93 | 94 | int i; 95 | (void)file; 96 | 97 | for(i = 0; i < len; i++) 98 | { 99 | // UART_PutChar is user's basic output function 100 | UART_PutChar(*ptr++); 101 | } 102 | #endif 103 | 104 | return len; 105 | } 106 | */ 107 | __attribute__ ((used)) 108 | void abort(void) 109 | { 110 | /* Abort called */ 111 | while(1); 112 | } 113 | 114 | /* --------------------------------- End Of File ------------------------------ */ 115 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lpc1227.comarker: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lpc1227.coproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 48 | 49 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/lpc1227/Debug/bin/lpc1227.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Coocox_lcp1227/lpc1227/Debug/bin/lpc1227.bin -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/main.c: -------------------------------------------------------------------------------- 1 | #include "global_inc.h" 2 | 3 | #include "lib/cmsis/cmsis_boot/LPC12xx.h" 4 | #include "cmsis_lib/lpc12xx_iocon.h" // AF 5 | #include "cmsis_lib/lpc12xx_sysctrl.h" // CLK 6 | #include "cmsis_lib/lpc12xx_uart.h" // UART 7 | 8 | #include "core_cm0.h" 9 | #include "core_cmFunc.h" 10 | 11 | #include "terminal_config.h" 12 | #include "terminal.h" 13 | 14 | #include "my_test_commands/my_test_commands.h" 15 | 16 | char dbgbuffer[256]; 17 | 18 | // GPIO0_8 , GPIO0_9 19 | #define TERMINAL_USART LPC_UART1 20 | 21 | void _reset_fcn() 22 | { 23 | NVIC_SystemReset(); 24 | } 25 | 26 | inline void TUSART_PutChar(char c) 27 | { 28 | while(!(TERMINAL_USART->LSR & (1 << 5))){}; 29 | TERMINAL_USART->THR = c; 30 | } 31 | 32 | void TUSART_Print(const char* str) 33 | { 34 | uint16_t co = 0; 35 | 36 | while(((str+co) != NULL) && ((*(str+co) != '\0'))) 37 | { 38 | TUSART_PutChar(str[co]); 39 | co++; 40 | } 41 | } 42 | 43 | void _InitHW() 44 | { 45 | SystemCoreClockUpdate(); 46 | 47 | LPC_WDT->MOD &= ~(1 << 0); // wdt disable 48 | SysTick->CTRL = 3; // start systick interrupt 49 | 50 | SysTick_Config(360); // [max 0x00ffffff], div for systick 51 | 52 | // uart init 53 | LPC_IOCON->PIO0_8 |= 0x2; // AF RXD1 54 | LPC_IOCON->PIO0_9 |= 0x2; // AF TXD1 55 | 56 | LPC_SYSCON->UART1CLKDIV = 1; 57 | 58 | LPC_SYSCON->SYSAHBCLKCTRL |= SYS_AHBCLKCTRL_UART1 | SYS_AHBCLKCTRL_GPIO0; 59 | 60 | UART_CFG_Type cfg; 61 | cfg.baudrate = 115200; 62 | cfg.databits = UART_CFG_DATABIT_8; 63 | cfg.stopbits = UART_CFG_STOPBIT_1; 64 | cfg.parity = UART_CFG_PARITY_NONE; 65 | cfg.fifodma = UART_CFG_DMAMODE_DISABLE; 66 | cfg.txdbreak = UART_CFG_TXDBREAK_DISABLE; 67 | cfg.fifolevel = UART_CFG_FIFOTRG_4; 68 | 69 | UART_SetConfig(TERMINAL_USART, &cfg); 70 | 71 | TERMINAL_USART->TER = 0x80; 72 | TERMINAL_USART->FCR |= 0x7; 73 | 74 | NVIC_EnableIRQ(UART1_IRQn); 75 | TERMINAL_USART->IER |= (UART_INTCFG_RBR); 76 | 77 | 78 | LPC_SYSCON->SYSAHBCLKCTRL |= SYS_AHBCLKCTRL_IOCON; 79 | 80 | __enable_irq(); 81 | } 82 | 83 | void _InitSW() 84 | { 85 | CLI_Init(TDC_Time); 86 | 87 | MyTestCmds_Init(); 88 | } 89 | 90 | int main(void) 91 | { 92 | _InitHW(); 93 | _InitSW(); 94 | 95 | while(1) 96 | { 97 | CLI_Execute(); 98 | } 99 | } 100 | 101 | void UART1_IRQHandler() 102 | { 103 | TC_Result_e result = CLI_EnterChar(TERMINAL_USART->RBR); 104 | if (result == TC_Reset) 105 | { 106 | RESET_FCN(); 107 | } 108 | } 109 | 110 | volatile uint64_t SysTickCtr = 0; 111 | void SysTick_Handler() 112 | { 113 | SysTickCtr++; 114 | } 115 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/my_test_commands/my_test_commands.c: -------------------------------------------------------------------------------- 1 | #include "my_test_commands.h" 2 | 3 | #include "terminal_config.h" 4 | #include "terminal.h" 5 | 6 | static uint8_t _t1_cmd(); 7 | static uint8_t _t2_cmd(); 8 | 9 | void MyTestCmds_Init() 10 | { 11 | CLI_AddCmd("t1", _t1_cmd, 1, TMC_PrintStartTime | TMC_PrintStopTime, "t1 - description command"); 12 | CLI_AddCmd("t2", _t2_cmd, 0, TMC_PrintDiffTime, "t2 - description command"); 13 | } 14 | 15 | // ***************** implementation commands **************** 16 | 17 | uint8_t _t1_cmd() 18 | { 19 | uint32_t a = 0x01; 20 | uint32_t b = 0x10; 21 | uint32_t c = 7; 22 | 23 | // be sure arguments 24 | c = CLI_GetArgDec(0); 25 | 26 | // optional arguments 27 | CLI_GetArgHexByFlag("-a", &a); 28 | CLI_GetArgHexByFlag("-b", &b); 29 | 30 | CLI_Printf("\r\na: 0x%08X\r\nb: 0x%08X\r\nc: %d", (int) a, (int) b, (int) c); 31 | 32 | return TE_OK; 33 | } 34 | 35 | uint8_t _t2_cmd() 36 | { 37 | CLI_Printf("\r\nPress ESC"); 38 | while(1) 39 | { 40 | CLI_CheckAbort(); 41 | } 42 | 43 | return TE_OK; 44 | } 45 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/my_test_commands/my_test_commands.h: -------------------------------------------------------------------------------- 1 | #ifndef _MY_TEST_COMMANDS_H_ 2 | #define _MY_TEST_COMMANDS_H_ 3 | 4 | void MyTestCmds_Init(); 5 | 6 | #endif // _MY_TEST_COMMANDS_H_ 7 | -------------------------------------------------------------------------------- /examples/Coocox_lcp1227/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | 18 | // ****************************** Code keys ******************************** 19 | 20 | #define _KEY_INIT(c) ((char)c) 21 | 22 | #define TERM_KEY_ENTER (_KEY_INIT(0x0D)) // Enter command symbol 23 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x08)) // Delete character before cursor position 24 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 25 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 26 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 27 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 28 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 29 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 30 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 31 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 32 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 33 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 34 | #define TERM_KEY_RESET '~' // Reset CPU 35 | 36 | // ************************************************************************** 37 | 38 | // ********************** Terminal Settings ********************************* 39 | 40 | extern void _reset_fcn(); 41 | #define _TERM_VER_ "v1.4" // Terminal version 42 | #define TERM_SIZE_TASK (20) // Max number of commands 43 | #define TERM_CMD_BUF_SIZE (60) // Max number of character buffer string command 44 | #define TERM_CMD_LOG_SIZE (10) // Max number of loging command 45 | #define TERM_ARGS_BUF_SIZE (10) // Max number of arguments in one command 46 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 47 | #define CHAR_INTERRUPT TERM_KEY_ESCAPE // Abort execute command key-code symbol 48 | #define CHAR_BACKSPACE '\x08' // Backspace char 49 | #define STRING_TERM_ENTER "\n\r" // String new line 50 | #define STRING_TERM_ARROW ">> " // String arrow enter 51 | #define RESET_FCN _reset_fcn // Reset CPU Function 52 | 53 | #define TERM_TIMELEFT_EN (1) // Calculate time 54 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 55 | #define TERM_TX_RX_DEB_EN (1) // Addition debug printf 56 | #define TERM_CMD_LOG_EN (1) // Command logging 57 | #define TERM_CMD_AUTOCMPLT_EN (1) // Command AutoComplete 58 | #define TERM_LR_KEY_EN (1) // Move cursor left-rigth 59 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 60 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 61 | #define TERM_PRINT_ERROR_EXEC_EN (1) // Print error after execute command 62 | #define TERM_PRINT_ERROR_ADD_CMD_EN (1) // Print error after added command 63 | #define ECHO_EN (1) // Enter echo enable 64 | 65 | // ************************************************************************** 66 | 67 | // ************************* IO Terminal Settings *************************** 68 | 69 | #if (TERM_TX_RX_EN == 1) 70 | #include 71 | extern void TUSART_Print(const char* str); 72 | extern void TUSART_PutChar(char c); 73 | extern char dbgbuffer[256]; 74 | #define COM_Printf(...) {sprintf(dbgbuffer,__VA_ARGS__);TUSART_Print(dbgbuffer);} 75 | #define CLI_Printf COM_Printf 76 | #if (ECHO_EN == 1) 77 | #define CLI_PutChar TUSART_PutChar 78 | #else // ECHO_EN != 1 79 | #define CLI_PutChar 80 | #endif // ECHO_EN == 1 81 | 82 | #else // TERM_TX_RX_EN != 1 83 | #define CLI_Printf 84 | #define CLI_PutChar 85 | #endif // TERM_TX_RX_EN == 1 86 | // ************************************************************************** 87 | 88 | // *********************** IO Debug Terminal Settings *********************** 89 | 90 | #if (TERM_TX_RX_DEB_EN == 1) 91 | #define CLI_DPrintf printf 92 | #else // TERM_TX_RX_DEB_EN != 1 93 | #define CLI_DPrintf 94 | #endif // TERM_TX_RX_DEB_EN == 1 95 | 96 | // ************************************************************************** 97 | 98 | // ************************ Time calculate Settings ************************* 99 | 100 | #if (TERM_TIMELEFT_EN == 1) 101 | 102 | // yout implementation 103 | extern volatile uint64_t SysTickCtr; // Variable tackts cntr 104 | 105 | #define CLI_GetUs() ((float)SysTickCtr * 10) // System time in us 106 | #define CLI_GetFastUs() (SysTickCtr << 3) // System time in us (not exact) 107 | #define CLI_GetFastMs() (SysTickCtr >> 7) // System time in ms (not exact) 108 | #define CLI_CounterReset() {SysTickCtr = 0;} 109 | 110 | #else // TERM_TIMELEFT_EN != 1 111 | 112 | #define CLI_GetUs() (0) // System time in us 113 | #define CLI_GetFastUs() (0) // System time in us (not exact) 114 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 115 | #define CLI_CounterReset() {} 116 | 117 | #endif // TERM_TIMELEFT_EN == 1 118 | 119 | // ************************************************************************** 120 | 121 | // ********************** memory allocate functions ************************* 122 | 123 | #if (TERM_DEFAULT_ALLOC_EN == 1) 124 | #include 125 | #define cli_malloc malloc 126 | #define cli_free free 127 | #else 128 | #define cli_malloc // your implementation 129 | #define cli_free // your implementation 130 | #endif 131 | 132 | // ************************************************************************** 133 | 134 | // *************************** string functions ***************************** 135 | 136 | #if (TERM_DEFAULT_STRING_EN == 1) 137 | #include 138 | #define cli_memcpy memcpy 139 | #else 140 | #define cli_memcpy // your implementation 141 | #endif 142 | 143 | // ************************************************************************** 144 | 145 | #endif // _TERMIANL_CONFIG_H_ 146 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/cmsis_boot/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Coocox_stm32f4/cmsis_boot/stm32f4xx.h -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/cmsis_boot/stm32f4xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 30-September-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F4xx_CONF_H 24 | #define __STM32F4xx_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment the line below to enable peripheral header file inclusion */ 28 | /*#include "stm32f4xx_adc.h" 29 | #include "stm32f4xx_can.h" 30 | #include "stm32f4xx_crc.h" 31 | #include "stm32f4xx_cryp.h" 32 | #include "stm32f4xx_dac.h" 33 | #include "stm32f4xx_dbgmcu.h" 34 | #include "stm32f4xx_dcmi.h" 35 | #include "stm32f4xx_dma.h" 36 | #include "stm32f4xx_exti.h" 37 | #include "stm32f4xx_flash.h" 38 | #include "stm32f4xx_fsmc.h" 39 | #include "stm32f4xx_hash.h" 40 | #include "stm32f4xx_gpio.h" 41 | #include "stm32f4xx_i2c.h" 42 | #include "stm32f4xx_iwdg.h" 43 | #include "stm32f4xx_pwr.h" 44 | #include "stm32f4xx_rcc.h" 45 | #include "stm32f4xx_rng.h" 46 | #include "stm32f4xx_rtc.h" 47 | #include "stm32f4xx_sdio.h" 48 | #include "stm32f4xx_spi.h" 49 | #include "stm32f4xx_syscfg.h" 50 | #include "stm32f4xx_tim.h" 51 | #include "stm32f4xx_usart.h" 52 | #include "stm32f4xx_wwdg.h" 53 | #include "misc.h"*/ 54 | /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 55 | 56 | /* Exported types ------------------------------------------------------------*/ 57 | /* Exported constants --------------------------------------------------------*/ 58 | 59 | /* If an external clock source is used, then the value of the following define 60 | should be set to the value of the external clock source, else, if no external 61 | clock is used, keep this define commented */ 62 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ 63 | 64 | 65 | /* Uncomment the line below to expanse the "assert_param" macro in the 66 | Standard Peripheral Library drivers code */ 67 | /* #define USE_FULL_ASSERT 1 */ 68 | 69 | /* Exported macro ------------------------------------------------------------*/ 70 | #ifdef USE_FULL_ASSERT 71 | 72 | /** 73 | * @brief The assert_param macro is used for function's parameters check. 74 | * @param expr: If expr is false, it calls assert_failed function 75 | * which reports the name of the source file and the source 76 | * line number of the call that failed. 77 | * If expr is true, it returns no value. 78 | * @retval None 79 | */ 80 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 81 | /* Exported functions ------------------------------------------------------- */ 82 | void assert_failed(uint8_t* file, uint32_t line); 83 | #else 84 | #define assert_param(expr) ((void)0) 85 | #endif /* USE_FULL_ASSERT */ 86 | 87 | #endif /* __STM32F4xx_CONF_H */ 88 | 89 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 90 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/cmsis_boot/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 30-September-2011 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f4xx_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F4XX_H 34 | #define __SYSTEM_STM32F4XX_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F4xx_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F4xx_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @addtogroup STM32F4xx_System_Exported_Constants 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @addtogroup STM32F4xx_System_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @addtogroup STM32F4xx_System_Exported_Functions 77 | * @{ 78 | */ 79 | 80 | extern void SystemInit(void); 81 | extern void SystemCoreClockUpdate(void); 82 | /** 83 | * @} 84 | */ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /*__SYSTEM_STM32F4XX_H */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 100 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/cmsis_lib/source/stm32f4xx_rcc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Coocox_stm32f4/cmsis_lib/source/stm32f4xx_rcc.c -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/global_inc.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOBAL_INC_H_ 2 | #define _GLOBAL_INC_H_ 3 | 4 | #include 5 | #include 6 | 7 | #endif // _GLOBAL_INC_H_ 8 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/main.c: -------------------------------------------------------------------------------- 1 | #include "global_inc.h" 2 | 3 | #include "stm32f4xx.h" 4 | 5 | #include "core_cm4.h" 6 | #include "core_cmFunc.h" 7 | 8 | #include "system_stm32f4xx.h" 9 | #include "stm32f4xx_gpio.h" 10 | #include "stm32f4xx_usart.h" 11 | #include "stm32f4xx_rcc.h" 12 | 13 | #include "terminal_config.h" 14 | #include "terminal/terminal.h" 15 | 16 | #include "my_test_commands/my_test_commands.h" 17 | 18 | char dbgbuffer[256]; 19 | 20 | #define TERMINAL_USART USART3 21 | #define TERMINAL_GPIO GPIOD 22 | 23 | void _reset_fcn() 24 | { 25 | NVIC_SystemReset(); 26 | } 27 | 28 | inline void TUSART_PutChar(char c) 29 | { 30 | while (!USART_GetFlagStatus(TERMINAL_USART, USART_FLAG_TXE)); 31 | USART_SendData(TERMINAL_USART, c); 32 | } 33 | 34 | void TUSART_Print(const char* str) 35 | { 36 | while(str != NULL) { 37 | TUSART_PutChar(*str); 38 | 39 | if (*str == '\0') 40 | break; 41 | 42 | str++; 43 | } 44 | } 45 | 46 | void _InitHW() 47 | { 48 | SystemCoreClockUpdate(); 49 | 50 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); 51 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); 52 | 53 | GPIO_InitTypeDef gpio; 54 | gpio.GPIO_Mode = GPIO_Mode_AF; 55 | gpio.GPIO_OType = GPIO_OType_PP; 56 | gpio.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; 57 | gpio.GPIO_PuPd = GPIO_PuPd_UP; 58 | gpio.GPIO_Speed = GPIO_Speed_100MHz; 59 | GPIO_Init(TERMINAL_GPIO, &gpio); 60 | 61 | GPIO_PinAFConfig(TERMINAL_GPIO, GPIO_PinSource8, GPIO_AF_USART3); 62 | GPIO_PinAFConfig(TERMINAL_GPIO, GPIO_PinSource9, GPIO_AF_USART3); 63 | 64 | USART_InitTypeDef usart; 65 | usart.USART_BaudRate = 115200; 66 | usart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; 67 | usart.USART_Parity = USART_Parity_No; 68 | usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 69 | usart.USART_StopBits = USART_StopBits_1; 70 | usart.USART_WordLength = USART_WordLength_8b; 71 | 72 | USART_Init(TERMINAL_USART, &usart); 73 | 74 | USART_Cmd(TERMINAL_USART, ENABLE); 75 | USART_ITConfig(TERMINAL_USART, USART_IT_RXNE, ENABLE); 76 | 77 | SysTick_Config(SystemCoreClock / 100000); 78 | 79 | NVIC_EnableIRQ(USART3_IRQn); 80 | NVIC_EnableIRQ(SysTick_IRQn); 81 | 82 | __enable_irq(); 83 | } 84 | 85 | void _InitSW() 86 | { 87 | CLI_Init(TDC_Time); 88 | 89 | MyTestCmds_Init(); 90 | } 91 | 92 | int main(void) 93 | { 94 | _InitHW(); 95 | _InitSW(); 96 | 97 | while(1) 98 | { 99 | CLI_Execute(); 100 | } 101 | } 102 | 103 | void USART3_IRQHandler() 104 | { 105 | USART_ClearITPendingBit(TERMINAL_USART, USART_IT_RXNE); 106 | CLI_EnterChar(USART_ReceiveData(TERMINAL_USART)); 107 | } 108 | 109 | volatile uint64_t SysTickCtr = 0; 110 | void SysTick_Handler() 111 | { 112 | SysTickCtr++; 113 | } 114 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/my_test_commands/my_test_commands.c: -------------------------------------------------------------------------------- 1 | #include "my_test_commands.h" 2 | 3 | #include "terminal_config.h" 4 | #include "terminal.h" 5 | 6 | static uint8_t _t1_cmd(); 7 | static uint8_t _t2_cmd(); 8 | 9 | void MyTestCmds_Init() 10 | { 11 | CLI_AddCmd("t1", _t1_cmd, 1, TMC_PrintStartTime | TMC_PrintStopTime, "t1 - description command"); 12 | CLI_AddCmd("t2", _t2_cmd, 0, TMC_PrintDiffTime, "t2 - description command"); 13 | } 14 | 15 | // ***************** implementation commands **************** 16 | 17 | uint8_t _t1_cmd() 18 | { 19 | uint32_t a = 0x01; 20 | uint32_t b = 0x10; 21 | uint32_t c = 7; 22 | 23 | // be sure arguments 24 | c = CLI_GetArgDec(0); 25 | 26 | // optional arguments 27 | CLI_GetArgHexByFlag("-a", &a); 28 | CLI_GetArgHexByFlag("-b", &b); 29 | 30 | CLI_Printf("\r\na: 0x%08X\r\nb: 0x%08X\r\nc: %d", (int) a, (int) b, (int) c); 31 | 32 | return TE_OK; 33 | } 34 | 35 | uint8_t _t2_cmd() 36 | { 37 | CLI_Printf("\r\nPress ESC"); 38 | while(1) 39 | { 40 | CLI_CheckAbort(); 41 | } 42 | 43 | return TE_OK; 44 | } 45 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/my_test_commands/my_test_commands.h: -------------------------------------------------------------------------------- 1 | #ifndef _MY_TEST_COMMANDS_H_ 2 | #define _MY_TEST_COMMANDS_H_ 3 | 4 | void MyTestCmds_Init(); 5 | 6 | #endif // _MY_TEST_COMMANDS_H_ 7 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/stm32f4_terminal_example.comarker: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/stm32f4_terminal_example.coproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 21 | 22 | 50 | 51 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/stm32f4_terminal_example.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/stm32f4_terminal_example.bin -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/stm32f4_terminal_example.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Coocox_stm32f4/stm32f4_terminal_example/Debug/bin/stm32f4_terminal_example.elf -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/syscalls/syscalls.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//***** 2 | * @file stdio.c 3 | * @brief Implementation of newlib syscall 4 | ********************************************************************************/ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #undef errno 12 | extern int errno; 13 | extern int _end; 14 | 15 | /*This function is used for handle heap option*/ 16 | __attribute__ ((used)) 17 | caddr_t _sbrk ( int incr ) 18 | { 19 | static unsigned char *heap = NULL; 20 | unsigned char *prev_heap; 21 | 22 | if (heap == NULL) { 23 | heap = (unsigned char *)&_end; 24 | } 25 | prev_heap = heap; 26 | 27 | heap += incr; 28 | 29 | return (caddr_t) prev_heap; 30 | } 31 | 32 | __attribute__ ((used)) 33 | int link(char *old, char *new) 34 | { 35 | return -1; 36 | } 37 | 38 | __attribute__ ((used)) 39 | int _close(int file) 40 | { 41 | return -1; 42 | } 43 | 44 | __attribute__ ((used)) 45 | int _fstat(int file, struct stat *st) 46 | { 47 | st->st_mode = S_IFCHR; 48 | return 0; 49 | } 50 | 51 | __attribute__ ((used)) 52 | int _isatty(int file) 53 | { 54 | return 1; 55 | } 56 | 57 | __attribute__ ((used)) 58 | int _lseek(int file, int ptr, int dir) 59 | { 60 | return 0; 61 | } 62 | 63 | /*Low layer read(input) function*/ 64 | __attribute__ ((used)) 65 | int _read(int file, char *ptr, int len) 66 | { 67 | 68 | #if 0 69 | //user code example 70 | int i; 71 | (void)file; 72 | 73 | for(i = 0; i < len; i++) 74 | { 75 | // UART_GetChar is user's basic input function 76 | *ptr++ = UART_GetChar(); 77 | } 78 | 79 | #endif 80 | 81 | return len; 82 | } 83 | 84 | 85 | /*Low layer write(output) function*/ 86 | __attribute__ ((used)) 87 | int _write(int file, char *ptr, int len) 88 | { 89 | 90 | #if 0 91 | //user code example 92 | 93 | int i; 94 | (void)file; 95 | 96 | for(i = 0; i < len; i++) 97 | { 98 | // UART_PutChar is user's basic output function 99 | UART_PutChar(*ptr++); 100 | } 101 | #endif 102 | 103 | return len; 104 | } 105 | 106 | __attribute__ ((used)) 107 | void abort(void) 108 | { 109 | /* Abort called */ 110 | while(1); 111 | } 112 | 113 | /* --------------------------------- End Of File ------------------------------ */ 114 | -------------------------------------------------------------------------------- /examples/Coocox_stm32f4/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | 18 | // ****************************** Code keys ******************************** 19 | 20 | #define _KEY_INIT(c) ((char)c) 21 | 22 | #define TERM_KEY_ENTER (_KEY_INIT(0x0D)) // Enter command symbol 23 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x08)) // Delete character before cursor position 24 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 25 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 26 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 27 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 28 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 29 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 30 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 31 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 32 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 33 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 34 | #define TERM_KEY_RESET '~' // Reset CPU 35 | 36 | // ************************************************************************** 37 | 38 | // ********************** Terminal Settings ********************************* 39 | 40 | extern void _reset_fcn(); 41 | #define _TERM_VER_ "v1.4" // Terminal version 42 | #define TERM_SIZE_TASK (20) // Max number of commands 43 | #define TERM_CMD_BUF_SIZE (60) // Max number of character buffer string command 44 | #define TERM_CMD_LOG_SIZE (10) // Max number of loging command 45 | #define TERM_ARGS_BUF_SIZE (10) // Max number of arguments in one command 46 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 47 | #define CHAR_INTERRUPT TERM_KEY_ESCAPE // Abort execute command key-code symbol 48 | #define CHAR_BACKSPACE '\x08' // Backspace char 49 | #define STRING_TERM_ENTER "\n\r" // String new line 50 | #define STRING_TERM_ARROW ">> " // String arrow enter 51 | #define RESET_FCN _reset_fcn // Reset CPU Function 52 | 53 | #define TERM_TIMELEFT_EN (1) // Calculate time 54 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 55 | #define TERM_TX_RX_DEB_EN (0) // Addition debug printf 56 | #define TERM_CMD_LOG_EN (1) // Command logging 57 | #define TERM_CMD_AUTOCMPLT_EN (1) // Command AutoComplete 58 | #define TERM_LR_KEY_EN (1) // Move cursor left-rigth 59 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 60 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 61 | #define TERM_PRINT_ERROR_EXEC_EN (1) // Print error after execute command 62 | #define TERM_PRINT_ERROR_ADD_CMD_EN (1) // Print error after added command 63 | #define ECHO_EN (1) // Enter echo enable 64 | 65 | // ************************************************************************** 66 | 67 | // ************************* IO Terminal Settings *************************** 68 | 69 | #if (TERM_TX_RX_EN == 1) 70 | #include 71 | extern void TUSART_Print(const char* str); 72 | extern void TUSART_PutChar(char c); 73 | extern char dbgbuffer[256]; 74 | #define COM_Printf(...) {sprintf(dbgbuffer,__VA_ARGS__);TUSART_Print(dbgbuffer);} 75 | #define CLI_Printf COM_Printf 76 | #if (ECHO_EN == 1) 77 | #define CLI_PutChar TUSART_PutChar 78 | #else // ECHO_EN != 1 79 | #define CLI_PutChar 80 | #endif // ECHO_EN == 1 81 | 82 | #else // TERM_TX_RX_EN != 1 83 | #define CLI_Printf 84 | #define CLI_PutChar 85 | #endif // TERM_TX_RX_EN == 1 86 | // ************************************************************************** 87 | 88 | // *********************** IO Debug Terminal Settings *********************** 89 | 90 | #if (TERM_TX_RX_DEB_EN == 1) 91 | #define CLI_DPrintf printf 92 | #else // TERM_TX_RX_DEB_EN != 1 93 | #define CLI_DPrintf 94 | #endif // TERM_TX_RX_DEB_EN == 1 95 | 96 | // ************************************************************************** 97 | 98 | // ************************ Time calculate Settings ************************* 99 | 100 | #if (TERM_TIMELEFT_EN == 1) 101 | 102 | // yout implementation 103 | extern volatile uint64_t SysTickCtr; // Variable tackts cntr 104 | 105 | #define CLI_GetUs() ((float)SysTickCtr * 10) // System time in us 106 | #define CLI_GetFastUs() (SysTickCtr << 3) // System time in us (not exact) 107 | #define CLI_GetFastMs() (SysTickCtr >> 7) // System time in ms (not exact) 108 | #define CLI_CounterReset() {SysTickCtr = 0;} 109 | 110 | #else // TERM_TIMELEFT_EN != 1 111 | 112 | #define CLI_GetUs() (0) // System time in us 113 | #define CLI_GetFastUs() (0) // System time in us (not exact) 114 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 115 | #define CLI_CounterReset() {} 116 | 117 | #endif // TERM_TIMELEFT_EN == 1 118 | 119 | // ************************************************************************** 120 | 121 | // ********************** memory allocate functions ************************* 122 | 123 | #if (TERM_DEFAULT_ALLOC_EN == 1) 124 | #include 125 | #define cli_malloc malloc 126 | #define cli_free free 127 | #else 128 | #define cli_malloc // your implementation 129 | #define cli_free // your implementation 130 | #endif 131 | 132 | // ************************************************************************** 133 | 134 | // *************************** string functions ***************************** 135 | 136 | #if (TERM_DEFAULT_STRING_EN == 1) 137 | #include 138 | #define cli_memcpy memcpy 139 | #else 140 | #define cli_memcpy // your implementation 141 | #endif 142 | 143 | // ************************************************************************** 144 | 145 | #endif // _TERMIANL_CONFIG_H_ 146 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/proteus_prj/Backup Of atmega32_terminal_prj.pdsbak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Proteus_emulate/atmega32/proteus_prj/Backup Of atmega32_terminal_prj.pdsbak -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/proteus_prj/Last Loaded atmega32_terminal_prj.pdsbak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Proteus_emulate/atmega32/proteus_prj/Last Loaded atmega32_terminal_prj.pdsbak -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/proteus_prj/atmega32_terminal_prj.pdsprj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Proteus_emulate/atmega32/proteus_prj/atmega32_terminal_prj.pdsprj -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/proteus_prj/atmega32_terminal_prj.pdsprj.PCi.Alexei.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2c0000000200000003000000ffffffffffffffffffffffffffffffff3c0000001c000000ca0400000a030000 5 | 6 | 7 | 8 | 9 | 10 | 11 | 552 12 | No 13 | 100 14 | 120 15 | 100 16 | 17 | 18 | 19 | 20 | 85 21 | No 22 | Yes 23 | "UCSRA","0x002B",00000002,0000000D,11,1,2,F0130000,1,00000000,00000000 24 | "UCSRB","0x002A",00000002,0000000D,10,1,2,436D0000,0,00000000,00000000 25 | "TCNT1H","0x004D",00000002,0000000D,45,1,2,32EE0000,0,00000000,00000000 26 | "TCNT1L","0x004C",00000002,0000000D,44,1,2,3A710000,0,00000000,00000000 27 | "TCCR1B","0x004E",00000002,0000000D,46,1,2,FDE00000,0,00000000,00000000 28 | "TCCR1A","0x004F",00000002,0000000D,47,1,2,CEC60000,0,00000000,00000000 29 | "TIFR","0x0058",00000002,0000000D,56,1,2,47E40000,0,00000000,00000000 30 | "TIMSK","0x0059",00000002,0000000D,57,1,2,5BD90000,0,00000000,00000000 31 | "secTmt","R17:R16",00000002,0000000E,16,2,2,00000003,0,00000000,00000000 32 | "SPSR","0x002E",00000002,0000000D,14,1,2,7E0C0000,0,00000000,00000000 33 | 85 34 | Yes 35 | No 36 | No 37 | Yes 38 | 0 39 | 85 40 | 100 41 | 130 42 | 1,0,00000000, 43 | 10 44 | 45 | 46 | 47 | 48 | 0 49 | 0 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 2 58 | Yes 59 | 2 60 | Yes 61 | Yes 62 | 00000000 63 | 64 | 65 | 66 | 67 | 2 68 | Yes 69 | 2 70 | Yes 71 | Yes 72 | 00000000 73 | 74 | 75 | 76 | 77 | 2 78 | Yes 79 | 2 80 | Yes 81 | Yes 82 | 00000000 83 | 84 | 85 | 86 | 87 | 2 88 | Yes 89 | 2 90 | Yes 91 | Yes 92 | 00000000 93 | 94 | 95 | 96 | 97 | 2 98 | Yes 99 | 2 100 | Yes 101 | Yes 102 | 00000060 103 | 104 | 105 | 106 | 107 | 2 108 | Yes 109 | 2 110 | Yes 111 | Yes 112 | 00000020 113 | 114 | 115 | 116 | 117 | "MainLoop",00CC,000A,C13B,1A33,-1 118 | 119 | No 120 | Yes 121 | No 122 | No 123 | Yes 124 | No 125 | 1 126 | 127 | 128 | 129 | 130 | 96 131 | No 132 | Yes 133 | 96 134 | Yes 135 | Yes 136 | No 137 | No 138 | No 139 | 0 140 | 153 141 | 100 142 | 0 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/atmega32_terminal.aps: -------------------------------------------------------------------------------- 1 | atmega32_terminal16-Aug-2017 18:29:1818-Aug-2017 22:15:27241016-Aug-2017 18:29:1844, 19, 0, 730AVR GCCdefault\atmega32_terminal.elfD:\gitclone\terminal\examples\Proteus_emulate\atmega32\src_prj\AVR SimulatorATmega32.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.clib\uart\uart.cD:\gitclone\terminal\terminal.cD:\gitclone\terminal\module\cli_log.cD:\gitclone\terminal\module\cli_time.cD:\gitclone\terminal\lib\cli_queue.cD:\gitclone\terminal\lib\cli_string.clib\spi\spi.clib\timer\timer1.ctest_cmds\test_cmds.clib\temp_sensor\temperature.cglobal_inc.hlib\uart\uart.hterminal_config.hD:\gitclone\terminal\terminal.hD:\gitclone\terminal\lib\cli_queue.hD:\gitclone\terminal\lib\cli_string.hD:\gitclone\terminal\module\cli_log.hD:\gitclone\terminal\module\cli_time.hlib\spi\spi.hlib\timer\timer1.htest_cmds\test_cmds.hlib\temp_sensor\temperature.hdefault\atmega32_terminal.lssdefault\atmega32_terminal.mapdefaultNOatmega32111atmega32_terminal.elfdefault\1.\..\..\..\..\..\..\..\..\lib\..\..\..\..\module\-Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files (x86)\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files (x86)\Atmel\AVR Tools\AVR Toolchain\bin\make.exe00000main.c100001test_cmds\test_cmds.c100002lib\timer\timer1.c100003lib\temp_sensor\temperature.c100004lib\spi\spi.c100005terminal_config.h100006D:\gitclone\terminal\lib\cli_queue.c100007D:\gitclone\terminal\lib\cli_queue.h1 2 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/atmega32_terminal.aws: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/default/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile for the project atmega32_terminal 3 | ############################################################################### 4 | 5 | ## General Flags 6 | PROJECT = atmega32_terminal 7 | MCU = atmega32 8 | TARGET = atmega32_terminal.elf 9 | CC = avr-gcc 10 | 11 | CPP = avr-g++ 12 | 13 | ## Options common to compile, link and assembly rules 14 | COMMON = -mmcu=$(MCU) 15 | 16 | ## Compile options common for all C compilation units. 17 | CFLAGS = $(COMMON) 18 | CFLAGS += -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums 19 | CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d 20 | 21 | ## Assembly specific flags 22 | ASMFLAGS = $(COMMON) 23 | ASMFLAGS += $(CFLAGS) 24 | ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 25 | 26 | ## Linker flags 27 | LDFLAGS = $(COMMON) 28 | LDFLAGS += -Wl,-Map=atmega32_terminal.map 29 | 30 | 31 | ## Intel Hex file production flags 32 | HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature 33 | 34 | HEX_EEPROM_FLAGS = -j .eeprom 35 | HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" 36 | HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings 37 | 38 | 39 | ## Include Directories 40 | INCLUDES = -I"D:\gitclone\terminal\examples\Proteus_emulate\atmega32\src_prj\." -I"D:\gitclone\terminal\examples\Proteus_emulate\atmega32\src_prj\..\..\..\.." -I"D:\gitclone\terminal\examples\Proteus_emulate\atmega32\src_prj\..\..\..\..\lib" -I"D:\gitclone\terminal\examples\Proteus_emulate\atmega32\src_prj\..\..\..\..\module" 41 | 42 | ## Objects that must be built in order to link 43 | OBJECTS = main.o uart.o terminal.o cli_log.o cli_time.o cli_queue.o cli_string.o spi.o timer1.o test_cmds.o temperature.o 44 | 45 | ## Objects explicitly added by the user 46 | LINKONLYOBJECTS = 47 | 48 | ## Build 49 | all: $(TARGET) atmega32_terminal.hex atmega32_terminal.eep atmega32_terminal.lss size 50 | 51 | ## Compile 52 | main.o: ../main.c 53 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 54 | 55 | uart.o: ../lib/uart/uart.c 56 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 57 | 58 | terminal.o: ../../../../../terminal.c 59 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 60 | 61 | cli_log.o: ../../../../../module/cli_log.c 62 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 63 | 64 | cli_time.o: ../../../../../module/cli_time.c 65 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 66 | 67 | cli_queue.o: ../../../../../lib/cli_queue.c 68 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 69 | 70 | cli_string.o: ../../../../../lib/cli_string.c 71 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 72 | 73 | spi.o: ../lib/spi/spi.c 74 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 75 | 76 | timer1.o: ../lib/timer/timer1.c 77 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 78 | 79 | test_cmds.o: ../test_cmds/test_cmds.c 80 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 81 | 82 | temperature.o: ../lib/temp_sensor/temperature.c 83 | $(CC) $(INCLUDES) $(CFLAGS) -c $< 84 | 85 | ##Link 86 | $(TARGET): $(OBJECTS) 87 | $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) 88 | 89 | %.hex: $(TARGET) 90 | avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ 91 | 92 | %.eep: $(TARGET) 93 | -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 94 | 95 | %.lss: $(TARGET) 96 | avr-objdump -h -S $< > $@ 97 | 98 | size: ${TARGET} 99 | @echo 100 | @avr-size -C --mcu=${MCU} ${TARGET} 101 | 102 | ## Clean target 103 | .PHONY: clean 104 | clean: 105 | -rm -rf $(OBJECTS) atmega32_terminal.elf dep/* atmega32_terminal.hex atmega32_terminal.eep atmega32_terminal.lss atmega32_terminal.map 106 | 107 | 108 | ## Other dependencies 109 | -include $(shell mkdir dep 2>NUL) $(wildcard dep/*) 110 | 111 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/default/atmega32_terminal.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/Proteus_emulate/atmega32/src_prj/default/atmega32_terminal.elf -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/global_inc.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBAL_INC_H_ 2 | #define GLOBAL_INC_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define FREQ ((uint32_t) 16000000) 10 | 11 | 12 | #endif /* GLOBAL_INC_H_ */ 13 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/spi/spi.c: -------------------------------------------------------------------------------- 1 | #include "spi.h" 2 | 3 | #include 4 | 5 | void SPI_Init() 6 | { 7 | DDRB = 0xB0; 8 | 9 | SPCR |= 0x50 | (1 << 2); 10 | } 11 | 12 | void SPI_SetData(uint8_t data) 13 | { 14 | SPDR = data; 15 | } 16 | 17 | uint8_t SPI_GetData() 18 | { 19 | return SPDR; 20 | } 21 | 22 | bool SPI_IsStatus(uint8_t status) 23 | { 24 | return ((SPSR & status) == status); 25 | } 26 | 27 | void SPI_SetCS() 28 | { 29 | PORTB |= 0x10; 30 | } 31 | 32 | void SPI_ClrCS() 33 | { 34 | PORTB &= ~0x10; 35 | } 36 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/spi/spi.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPI_H_ 2 | #define _SPI_H_ 3 | 4 | #include 5 | #include 6 | 7 | void SPI_Init(); 8 | 9 | void SPI_SetData(uint8_t data); 10 | uint8_t SPI_GetData(); 11 | 12 | bool SPI_IsStatus(uint8_t status); 13 | 14 | void SPI_SetCS(); 15 | void SPI_ClrCS(); 16 | 17 | #endif // _SPI_H_ 18 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/temp_sensor/temperature.c: -------------------------------------------------------------------------------- 1 | #include "temperature.h" 2 | 3 | #include "lib\spi\spi.h" 4 | 5 | void delay_t(uint16_t cntr) 6 | { 7 | volatile uint16_t c = cntr; 8 | while(c-- > 0){} 9 | } 10 | 11 | void TMP_Init() 12 | { 13 | 14 | } 15 | 16 | uint8_t TMP_ReadReg(uint8_t reg) 17 | { 18 | volatile uint8_t data = 0; 19 | SPI_SetCS(); 20 | 21 | SPI_SetData(reg); 22 | while(!SPI_IsStatus(0x80)){} 23 | 24 | SPI_SetData(0x00); 25 | while(!SPI_IsStatus(0x80)){} 26 | data = SPI_GetData(); 27 | 28 | SPI_ClrCS(); 29 | 30 | return data; 31 | } 32 | 33 | void TMP_WriteReg(uint8_t reg, uint8_t value) 34 | { 35 | SPI_SetCS(); 36 | 37 | SPI_SetData(reg); 38 | while(!SPI_IsStatus(0x80)){} 39 | 40 | SPI_SetData(value); 41 | while(!SPI_IsStatus(0x80)){} 42 | 43 | SPI_ClrCS(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/temp_sensor/temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEMPERATURE_H_ 2 | #define _TEMPERATURE_H_ 3 | 4 | #include 5 | 6 | void TMP_Init(); 7 | 8 | uint8_t TMP_ReadReg(uint8_t reg); 9 | void TMP_WriteReg(uint8_t reg, uint8_t value); 10 | 11 | #endif // _TEMPERATURE_H_ 12 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/timer/timer1.c: -------------------------------------------------------------------------------- 1 | #include "timer1.h" 2 | 3 | #include 4 | #include 5 | 6 | #define TMR_OVF_TOFS (65536-62439) 7 | 8 | volatile uint16_t sec_cntr = 0; 9 | 10 | void TMR1_Init() 11 | { 12 | TCCR1B = 0x04; 13 | TCNT1 = TMR_OVF_TOFS; 14 | TIMSK = 0x04; 15 | } 16 | 17 | uint16_t TMR1_GetSec() 18 | { 19 | return sec_cntr; 20 | } 21 | 22 | ISR(TIMER1_OVF_vect) 23 | { 24 | TCNT1 = TMR_OVF_TOFS; 25 | sec_cntr++; 26 | } 27 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/timer/timer1.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMER1_H_ 2 | #define _TIMER1_H_ 3 | 4 | #include 5 | 6 | void TMR1_Init(); 7 | 8 | uint16_t TMR1_GetSec(); 9 | 10 | #endif // _TIMER1_H_ 11 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/uart/uart.c: -------------------------------------------------------------------------------- 1 | #include "../../global_inc.h" 2 | 3 | #include "uart.h" 4 | 5 | #include 6 | 7 | void UART_Init(uint32_t baudrate) 8 | { 9 | DDRD = 0x02; 10 | 11 | uint16_t v = (FREQ) / (16 * baudrate) - 1; 12 | UBRRH = (v >> 8) & 0x0F; 13 | UBRRL = v; 14 | UCSRB = (1 << 4) | (1 << 3); 15 | UCSRC = (1 << 7) | (1 << 3) | (3 << 1); 16 | } 17 | 18 | void UART_PutChar(char c) 19 | { 20 | while(!(UCSRA & (1 << 5))){} 21 | UDR = c; 22 | } 23 | 24 | void UART_PutString(const char* str) 25 | { 26 | while(str != NULL) 27 | { 28 | if (*str == '\0') 29 | break; 30 | 31 | UART_PutChar(*str); 32 | str++; 33 | } 34 | } 35 | 36 | char UART_GetChar() 37 | { 38 | return UDR; 39 | } 40 | 41 | bool UART_IsStatus(uint8_t state) 42 | { 43 | return ((UCSRA & state) == state); 44 | } 45 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/lib/uart/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef UART_H_ 2 | #define UART_H_ 3 | 4 | #include "../../global_inc.h" 5 | 6 | void UART_Init(uint32_t baudrate); 7 | 8 | void UART_PutChar(char c); 9 | void UART_PutString(const char* str); 10 | 11 | char UART_GetChar(); 12 | 13 | bool UART_IsStatus(uint8_t state); 14 | 15 | #endif /* UART_H_ */ 16 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/main.c: -------------------------------------------------------------------------------- 1 | #include "global_inc.h" 2 | 3 | #include "lib\uart\uart.h" 4 | #include "lib\spi\spi.h" 5 | #include "lib\timer\timer1.h" 6 | 7 | #include "lib\temp_sensor\temperature.h" 8 | 9 | #include "test_cmds\test_cmds.h" 10 | 11 | #include 12 | #include 13 | 14 | #include "terminal_config.h" 15 | #include "terminal.h" 16 | 17 | char dbgbuffer[TERM_CMD_BUF_SIZE]; 18 | 19 | void HW_Init() 20 | { 21 | UART_Init(57600); 22 | SPI_Init(); 23 | 24 | DDRC |= 0x03; 25 | 26 | TMP_Init(); 27 | TMR1_Init(); 28 | 29 | sei(); 30 | } 31 | 32 | void SW_Init() 33 | { 34 | CLI_Init(TDC_None); 35 | TestCmds_Init(); 36 | } 37 | 38 | void MainLoop() 39 | { 40 | if (UART_IsStatus(1 << 7)) 41 | { 42 | CLI_EnterChar(UART_GetChar()); 43 | } 44 | 45 | CLI_Execute(); 46 | } 47 | 48 | int main (void) 49 | { 50 | HW_Init(); 51 | SW_Init(); 52 | 53 | while(1) 54 | { 55 | MainLoop(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | 18 | // ****************************** Code keys ******************************** 19 | 20 | #define _KEY_INIT(c) ((char)c) 21 | 22 | #define TERM_KEY_ENTER (_KEY_INIT(0x0D)) // Enter command symbol 23 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x08)) // Delete character before cursor 24 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 25 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 26 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 27 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 28 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 29 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 30 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 31 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 32 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 33 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 34 | #define TERM_KEY_RESET '~' // Reset CPU 35 | 36 | // ************************************************************************** 37 | 38 | // ********************** Terminal Settings ********************************* 39 | 40 | #define _TERM_VER_ "v1.4" // Terminal version 41 | #define TERM_SIZE_TASK (4) // Max number of commands 42 | #define TERM_CMD_BUF_SIZE (20) // Max number of character buffer string command 43 | #define TERM_CMD_LOG_SIZE (5) // Max number of loging command 44 | #define TERM_ARGS_BUF_SIZE (20) // Max number of arguments in one command 45 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 46 | #define CHAR_INTERRUPT TERM_KEY_ESCAPE // Abort execute command key-code symbol 47 | #define CHAR_BACKSPACE '\x08' // Backspace char 48 | #define STRING_TERM_ENTER "\n\r" // String new line 49 | #define STRING_TERM_ARROW ">> " // String arrow enter 50 | #define RESET_FCN() // Reset CPU Function 51 | 52 | #define TERM_TIMELEFT_EN (0) // Calculate time 53 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 54 | #define TERM_TX_RX_DEB_EN (0) // Addition debug printf 55 | #define TERM_CMD_LOG_EN (0) // Command logging 56 | #define TERM_CMD_AUTOCMPLT_EN (0) // Command AutoComplete 57 | #define TERM_LR_KEY_EN (0) // Move cursor left-rigth 58 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 59 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 60 | #define TERM_PRINT_ERROR_EXEC_EN (0) // Print error after execute command 61 | #define TERM_PRINT_ERROR_ADD_CMD_EN (0) // Print error after added command 62 | #define ECHO_EN (1) // Enter echo enable 63 | 64 | // ************************************************************************** 65 | 66 | // ************************* IO Terminal Settings *************************** 67 | 68 | #if (TERM_TX_RX_EN == 1) 69 | #include 70 | #include "lib\uart\uart.h" 71 | extern void UART_PutString(const char* str); 72 | extern char dbgbuffer[TERM_CMD_BUF_SIZE]; 73 | #define COM_Printf(...){sprintf(dbgbuffer,__VA_ARGS__);UART_PutString(dbgbuffer);} 74 | #define CLI_Printf COM_Printf 75 | extern void UART_PutChar(char c); 76 | #if (ECHO_EN == 1) 77 | #define CLI_PutChar UART_PutChar 78 | #else // ECHO_EN != 1 79 | #define CLI_PutChar 80 | #endif // ECHO_EN == 1 81 | 82 | #else // TERM_TX_RX_EN != 1 83 | #define CLI_Printf 84 | #define CLI_PutChar 85 | #endif // TERM_TX_RX_EN == 1 86 | // ************************************************************************** 87 | 88 | // *********************** IO Debug Terminal Settings *********************** 89 | 90 | #if (TERM_TX_RX_DEB_EN == 1) 91 | #define CLI_DPrintf printf 92 | #else // TERM_TX_RX_DEB_EN != 1 93 | #define CLI_DPrintf 94 | #endif // TERM_TX_RX_DEB_EN == 1 95 | 96 | // ************************************************************************** 97 | 98 | // ************************ Time calculate Settings ************************* 99 | 100 | #if (TERM_TIMELEFT_EN == 1) 101 | 102 | // yout implementation 103 | extern volatile uint64_t SysTickCtr; // Variable tackts cntr 104 | 105 | #define CLI_GetUs() ((float)SysTickCtr * 10) // System time in us 106 | #define CLI_GetFastUs() (SysTickCtr << 3) // System time in us (not exact) 107 | #define CLI_GetFastMs() (SysTickCtr >> 7) // System time in ms (not exact) 108 | #define CLI_CounterReset() {SysTickCtr = 0;} 109 | 110 | #else // TERM_TIMELEFT_EN != 1 111 | 112 | #define CLI_GetUs() (0) // System time in us 113 | #define CLI_GetFastUs() (0) // System time in us (not exact) 114 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 115 | #define CLI_CounterReset() {} 116 | 117 | #endif // TERM_TIMELEFT_EN == 1 118 | 119 | // ************************************************************************** 120 | 121 | // ********************** memory allocate functions ************************* 122 | 123 | #if (TERM_DEFAULT_ALLOC_EN == 1) 124 | 125 | #define cli_malloc malloc 126 | #define cli_free free 127 | #else 128 | #define cli_malloc // your implementation 129 | #define cli_free // your implementation 130 | #endif 131 | 132 | // ************************************************************************** 133 | 134 | // *************************** string functions ***************************** 135 | 136 | #if (TERM_DEFAULT_STRING_EN == 1) 137 | #include 138 | #define cli_memcpy memcpy 139 | #else 140 | #define cli_memcpy // your implementation 141 | #endif 142 | 143 | // ************************************************************************** 144 | 145 | #endif // _TERMIANL_CONFIG_H_ 146 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/test_cmds/test_cmds.c: -------------------------------------------------------------------------------- 1 | #include "test_cmds.h" 2 | 3 | #include "lib\temp_sensor\temperature.h" 4 | #include "lib\timer\timer1.h" 5 | 6 | #include "terminal_config.h" 7 | #include "terminal.h" 8 | 9 | uint8_t _t1_cmd(); 10 | uint8_t _t2_cmd(); 11 | 12 | void TestCmds_Init() 13 | { 14 | CLI_AddCmd("t1", _t1_cmd, 1, 0, ""); 15 | CLI_AddCmd("t2", _t2_cmd, 0, 0, ""); 16 | } 17 | 18 | uint8_t _t1_cmd() 19 | { 20 | uint32_t decVal = CLI_GetArgDec(0); 21 | uint32_t hexVal = 0; 22 | 23 | CLI_GetArgHexByFlag("-h", &hexVal); 24 | 25 | CLI_Printf("\r\nDec: %d\r\nHex: 0x%04X%04X", (int) decVal, 26 | (unsigned int) (hexVal >> 16), 27 | (unsigned int) hexVal); 28 | 29 | if (CLI_IsArgFlag("-f")) 30 | CLI_Printf("\r\n-f: TRUE") 31 | else 32 | CLI_Printf("\r\n-f: FALSE"); 33 | 34 | return TE_OK; 35 | } 36 | 37 | uint8_t _t2_cmd() 38 | { 39 | uint32_t cnt = 1; 40 | uint32_t i = 0; 41 | 42 | uint8_t id = TMP_ReadReg(0x03); 43 | uint8_t ctrl = TMP_ReadReg(0x00); 44 | 45 | CLI_Printf("\r\nTemp CTRL: 0x%02X", ctrl); 46 | TMP_WriteReg(0x80, 0x00); 47 | 48 | ctrl = TMP_ReadReg(0x00); 49 | 50 | CLI_Printf("\r\nTemp ID: 0x%02X", id); 51 | CLI_Printf("\r\nTemp CTRL: 0x%02X", ctrl); 52 | 53 | CLI_GetArgDecByFlag("-c", &cnt); 54 | 55 | uint16_t secTmt = TMR1_GetSec(); 56 | while(i < cnt) 57 | { 58 | CLI_CheckAbort(); 59 | 60 | uint16_t newSecTmt = TMR1_GetSec(); 61 | if (secTmt != newSecTmt) 62 | { 63 | uint8_t tl = TMP_ReadReg(0x01); 64 | uint8_t th = TMP_ReadReg(0x02); 65 | uint16_t t = ((uint16_t) th << 8) | tl; 66 | 67 | uint16_t s = t / 64; 68 | uint16_t temp = s * 0.25; 69 | CLI_Printf("\r\nTemperature: %d (0x%04X)", temp, t); 70 | 71 | secTmt = newSecTmt; 72 | i++; 73 | } 74 | 75 | } 76 | 77 | 78 | return TE_OK; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /examples/Proteus_emulate/atmega32/src_prj/test_cmds/test_cmds.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_CMDS_H_ 2 | #define _TEST_CMDS_H_ 3 | 4 | void TestCmds_Init(); 5 | 6 | #endif // _TEST_CMDS_H_ 7 | -------------------------------------------------------------------------------- /examples/dev_cpp/Makefile.win: -------------------------------------------------------------------------------- 1 | # Project: mcu_emulate 2 | # Makefile created by Dev-C++ 5.11 3 | 4 | CPP = g++.exe -D__DEBUG__ 5 | CC = gcc.exe -D__DEBUG__ 6 | WINDRES = windres.exe 7 | OBJ = main.o ../../lib/cli_queue.o ../../lib/cli_string.o ../../module/cli_log.o ../../module/cli_time.o ../../terminal.o com/com.o irq/irq.o systimer/systimer.o commands/test_commands.o ../../module/cli_input.o 8 | LINKOBJ = main.o ../../lib/cli_queue.o ../../lib/cli_string.o ../../module/cli_log.o ../../module/cli_time.o ../../terminal.o com/com.o irq/irq.o systimer/systimer.o commands/test_commands.o ../../module/cli_input.o 9 | LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc -g3 10 | INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"D:/gitclone/terminal" -I"D:/gitclone/terminal/examples/dev_cpp" 11 | CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"D:/gitclone/terminal" -I"D:/gitclone/terminal/examples/dev_cpp" 12 | BIN = mcu_emulate.exe 13 | CXXFLAGS = $(CXXINCS) -std=gnu99 -g3 14 | CFLAGS = $(INCS) -std=gnu99 -g3 15 | RM = rm.exe -f 16 | 17 | .PHONY: all all-before all-after clean clean-custom 18 | 19 | all: all-before $(BIN) all-after 20 | 21 | clean: clean-custom 22 | ${RM} $(OBJ) $(BIN) 23 | 24 | $(BIN): $(OBJ) 25 | $(CC) $(LINKOBJ) -o $(BIN) $(LIBS) 26 | 27 | main.o: main.c 28 | $(CC) -c main.c -o main.o $(CFLAGS) 29 | 30 | ../../lib/cli_queue.o: ../../lib/cli_queue.c 31 | $(CC) -c ../../lib/cli_queue.c -o ../../lib/cli_queue.o $(CFLAGS) 32 | 33 | ../../lib/cli_string.o: ../../lib/cli_string.c 34 | $(CC) -c ../../lib/cli_string.c -o ../../lib/cli_string.o $(CFLAGS) 35 | 36 | ../../module/cli_log.o: ../../module/cli_log.c 37 | $(CC) -c ../../module/cli_log.c -o ../../module/cli_log.o $(CFLAGS) 38 | 39 | ../../module/cli_time.o: ../../module/cli_time.c 40 | $(CC) -c ../../module/cli_time.c -o ../../module/cli_time.o $(CFLAGS) 41 | 42 | ../../terminal.o: ../../terminal.c 43 | $(CC) -c ../../terminal.c -o ../../terminal.o $(CFLAGS) 44 | 45 | com/com.o: com/com.c 46 | $(CC) -c com/com.c -o com/com.o $(CFLAGS) 47 | 48 | irq/irq.o: irq/irq.c 49 | $(CC) -c irq/irq.c -o irq/irq.o $(CFLAGS) 50 | 51 | systimer/systimer.o: systimer/systimer.c 52 | $(CC) -c systimer/systimer.c -o systimer/systimer.o $(CFLAGS) 53 | 54 | commands/test_commands.o: commands/test_commands.c 55 | $(CC) -c commands/test_commands.c -o commands/test_commands.o $(CFLAGS) 56 | 57 | ../../module/cli_input.o: ../../module/cli_input.c 58 | $(CC) -c ../../module/cli_input.c -o ../../module/cli_input.o $(CFLAGS) 59 | -------------------------------------------------------------------------------- /examples/dev_cpp/com/com.c: -------------------------------------------------------------------------------- 1 | #include "com.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define COM_BUFFER_SIZE 256 8 | 9 | struct 10 | { 11 | HANDLE handle; 12 | struct 13 | { 14 | char buffer[COM_BUFFER_SIZE]; 15 | int size; 16 | bool lock; 17 | }Fifo; 18 | }COM; 19 | 20 | static inline void _FIFO_Lock() { while(COM.Fifo.lock){} COM.Fifo.lock = true; } 21 | static inline void _FIFO_Unlock() { COM.Fifo.lock = false; } 22 | static inline bool _FIFO_IsFull() { return COM.Fifo.size == COM_BUFFER_SIZE; } 23 | static inline bool _FIFO_IsEmpty() { return COM.Fifo.size == 0; } 24 | static inline char _FIFO_Pop() 25 | { 26 | _FIFO_Lock(); 27 | char c = COM.Fifo.buffer[0]; 28 | for(int i = 0; i < COM.Fifo.size - 1; i++) 29 | COM.Fifo.buffer[i] = COM.Fifo.buffer[i + 1]; 30 | COM.Fifo.size--; 31 | _FIFO_Unlock(); 32 | return c; 33 | } 34 | 35 | static inline void _FIFO_Push(char c) 36 | { 37 | _FIFO_Lock(); 38 | COM.Fifo.buffer[COM.Fifo.size] = c; 39 | COM.Fifo.size++; 40 | _FIFO_Unlock(); 41 | } 42 | 43 | static void _COM_UpdateBuffer() 44 | { 45 | if (!_FIFO_IsFull()) 46 | { 47 | DWORD size = 0; 48 | char c; 49 | 50 | ReadFile(COM.handle, &c, 1, &size, 0); 51 | 52 | if (size > 0) 53 | _FIFO_Push(c); 54 | } 55 | } 56 | 57 | static DWORD WINAPI _threadReadComPort(CONST LPVOID lpParam) 58 | { 59 | while(true) 60 | _COM_UpdateBuffer(); 61 | 62 | CloseHandle(COM.handle); 63 | } 64 | 65 | inline bool COM_IsNotEmpty() { return !_FIFO_IsEmpty(); } 66 | 67 | inline char COM_GetChar() 68 | { 69 | if (!_FIFO_IsEmpty()) 70 | return _FIFO_Pop(); 71 | 72 | return 0; 73 | } 74 | 75 | bool COM_Init(const char* comName) 76 | { 77 | COM.handle = CreateFile(comName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); 78 | 79 | if(COM.handle != INVALID_HANDLE_VALUE) 80 | { 81 | DCB dcbSerialParams = {0}; 82 | dcbSerialParams.DCBlength = sizeof(dcbSerialParams); 83 | 84 | if (!GetCommState(COM.handle, &dcbSerialParams)) 85 | return false; 86 | 87 | dcbSerialParams.BaudRate = CBR_115200; 88 | dcbSerialParams.ByteSize = 8; 89 | dcbSerialParams.StopBits = ONESTOPBIT; 90 | dcbSerialParams.Parity = NOPARITY; 91 | 92 | if(!SetCommState(COM.handle, &dcbSerialParams)) 93 | return false; 94 | 95 | // without timeout mode settings 96 | COMMTIMEOUTS CommTimeOuts={0xFFFFFFFF,0,0,0,1500}; 97 | if (!SetCommTimeouts(COM.handle, &CommTimeOuts)) 98 | return false; 99 | 100 | printf("serial port \"COM1\"-115200-8-1 init\n"); 101 | 102 | COM.Fifo.size = 0; 103 | _FIFO_Unlock(); 104 | CreateThread(NULL, 0, &_threadReadComPort, NULL, 0, NULL); 105 | 106 | return true; 107 | } 108 | 109 | return false; 110 | } 111 | 112 | void COM_Putc(char c) 113 | { 114 | DWORD dwBytesWritten; 115 | WriteFile(COM.handle, &c, 1, &dwBytesWritten, NULL); 116 | } 117 | 118 | void COM_Print(const char* str) 119 | { 120 | uint16_t i = 0; 121 | while(str[i] != '\0') 122 | { 123 | COM_Putc(str[i]); 124 | i++; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /examples/dev_cpp/com/com.h: -------------------------------------------------------------------------------- 1 | #ifndef _COM_H_ 2 | #define _COM_H_ 3 | 4 | #include 5 | #include 6 | 7 | bool COM_Init(const char* comName); 8 | 9 | void COM_Putc(char c); 10 | void COM_Print(const char* str); 11 | 12 | bool COM_IsNotEmpty(); 13 | 14 | char COM_GetChar(); 15 | 16 | #endif // _COM_H_ 17 | -------------------------------------------------------------------------------- /examples/dev_cpp/commands/test_commands.c: -------------------------------------------------------------------------------- 1 | #include "test_commands.h" 2 | 3 | #include "terminal.h" 4 | 5 | uint8_t _to_cmd() 6 | { 7 | uint32_t count = 1; 8 | 9 | // be sure arguments 10 | count = CLI_GetArgDec(0); 11 | 12 | for(uint32_t i = 0; i < count; i++) 13 | { 14 | CLI_Printf("\r\n| Test%d | OK |", (int) i); 15 | } 16 | 17 | return TE_OK; 18 | } 19 | 20 | uint8_t _tf_cmd() 21 | { 22 | // be sure arguments 23 | uint32_t count = CLI_GetArgDec(0); 24 | 25 | for(uint32_t i = 0; i < count; i++) 26 | { 27 | if (i < 2) { 28 | CLI_Printf("\r\n| Test%d | OK |", (int) i); 29 | } 30 | else { 31 | CLI_Printf("\r\n| Test%d | FAIL |", (int) i); 32 | } 33 | } 34 | return TE_OK; 35 | } 36 | 37 | uint8_t _delay_cmd() 38 | { 39 | float delayMs = CLI_GetArgDec(0); 40 | 41 | float ms = CLI_GetFastMs(); 42 | while((CLI_GetFastMs() - ms) < delayMs) {} 43 | 44 | return TE_OK; 45 | } 46 | 47 | void TestCommands_Init() 48 | { 49 | CLI_AddCmd("test_ok", _to_cmd, 1, TMC_PrintDiffTime, "test ok"); 50 | CLI_AddCmd("test_fail", _tf_cmd, 1, TMC_PrintDiffTime, "test fail"); 51 | CLI_AddCmd("delay", _delay_cmd, 1, 52 | TMC_PrintDiffTime|TMC_PrintStartTime|TMC_PrintStopTime, "delay in ms"); 53 | } 54 | -------------------------------------------------------------------------------- /examples/dev_cpp/commands/test_commands.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEST_COMMANDS_H_ 2 | #define _TEST_COMMANDS_H_ 3 | 4 | void TestCommands_Init(); 5 | 6 | #endif // _TEST_COMMANDS_H_ 7 | -------------------------------------------------------------------------------- /examples/dev_cpp/irq/irq.c: -------------------------------------------------------------------------------- 1 | #include "irq.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define COUNT_VECTORS 2 10 | 11 | static struct 12 | { 13 | struct 14 | { 15 | void (*interrupt)(); 16 | bool (*check)(); 17 | }Handlers[COUNT_VECTORS]; 18 | bool enable; 19 | }IRQ; 20 | 21 | static DWORD WINAPI threadInterrupts(CONST LPVOID lpParam) 22 | { 23 | while(true) 24 | { 25 | if (IRQ.enable) 26 | { 27 | for(int i = 0; i < COUNT_VECTORS; i++) 28 | { 29 | if ((IRQ.Handlers[i].check != NULL) && (IRQ.Handlers[i].check())) 30 | { 31 | IRQ.Handlers[i].interrupt(); 32 | } 33 | } 34 | } 35 | 36 | Sleep(10); 37 | } 38 | } 39 | 40 | void IRQ_Enable() { IRQ.enable = true; } 41 | void IRQ_Disable() { IRQ.enable = false; } 42 | 43 | void IRQ_SetVector(int vector, void (*handler)(), bool (*check)()) 44 | { 45 | IRQ.Handlers[vector].interrupt = handler; 46 | IRQ.Handlers[vector].check = check; 47 | } 48 | 49 | void IRQ_Init() 50 | { 51 | IRQ_Disable(); 52 | CreateThread(NULL, 0, &threadInterrupts, NULL, 0, NULL); 53 | } 54 | -------------------------------------------------------------------------------- /examples/dev_cpp/irq/irq.h: -------------------------------------------------------------------------------- 1 | #ifndef _IRQ_H_ 2 | #define _IRQ_H_ 3 | 4 | #include 5 | 6 | void IRQ_Enable(); 7 | void IRQ_Disable(); 8 | 9 | void IRQ_SetVector(int vector, void (*handler)(), bool (*check)()); 10 | 11 | void IRQ_Init(); 12 | 13 | #endif // _IRQ_H_ 14 | -------------------------------------------------------------------------------- /examples/dev_cpp/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "com/com.h" 5 | #include "systimer/systimer.h" 6 | #include "irq/irq.h" 7 | 8 | #include "terminal_config.h" 9 | #include "terminal.h" 10 | 11 | #include "commands/test_commands.h" 12 | 13 | char dbgbuffer[256]; 14 | 15 | void IRQ_UartRxHandler() 16 | { 17 | CLI_EnterChar(COM_GetChar()); 18 | } 19 | 20 | void InitSW() 21 | { 22 | CLI_Init(TDC_Time); 23 | 24 | TestCommands_Init(); 25 | } 26 | 27 | void InitHW() 28 | { 29 | COM_Init("COM1"); 30 | STMR_Init(); 31 | 32 | IRQ_SetVector(0, IRQ_UartRxHandler, COM_IsNotEmpty); 33 | IRQ_Init(); 34 | } 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | InitHW(); 39 | InitSW(); 40 | 41 | IRQ_Enable(); 42 | 43 | while(1) 44 | CLI_Execute(); 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/dev_cpp/mcu_emulate.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=mcu_emulate.dev 3 | Name=mcu_emulate 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes=D:\gitclone\terminal;D:\gitclone\terminal\examples\dev_cpp 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=0 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName=mcu_emulate.exe 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders=com,commands,irq,systimer,terminal,terminal/lib,terminal/module 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings=00000000e0000000001000000 32 | UnitCount=22 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion=1.0.0.0 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion=1.0.0.0 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit1] 54 | FileName=main.c 55 | CompileCpp=0 56 | Folder= 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit4] 64 | FileName=..\..\lib\cli_string.c 65 | CompileCpp=0 66 | Folder=terminal/lib 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit5] 74 | FileName=..\..\lib\cli_string.h 75 | CompileCpp=0 76 | Folder=terminal/lib 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | [Unit6] 84 | FileName=..\..\module\cli_log.c 85 | CompileCpp=0 86 | Folder=terminal/module 87 | Compile=1 88 | Link=1 89 | Priority=1000 90 | OverrideBuildCmd=0 91 | BuildCmd= 92 | 93 | [Unit7] 94 | FileName=..\..\module\cli_log.h 95 | CompileCpp=0 96 | Folder=terminal/module 97 | Compile=1 98 | Link=1 99 | Priority=1000 100 | OverrideBuildCmd=0 101 | BuildCmd= 102 | 103 | [Unit8] 104 | FileName=..\..\module\cli_time.c 105 | CompileCpp=0 106 | Folder=terminal/module 107 | Compile=1 108 | Link=1 109 | Priority=1000 110 | OverrideBuildCmd=0 111 | BuildCmd= 112 | 113 | [Unit9] 114 | FileName=..\..\module\cli_time.h 115 | CompileCpp=0 116 | Folder=terminal/module 117 | Compile=1 118 | Link=1 119 | Priority=1000 120 | OverrideBuildCmd=0 121 | BuildCmd= 122 | 123 | [Unit10] 124 | FileName=..\..\terminal.c 125 | CompileCpp=0 126 | Folder=terminal 127 | Compile=1 128 | Link=1 129 | Priority=1000 130 | OverrideBuildCmd=0 131 | BuildCmd= 132 | 133 | [Unit11] 134 | FileName=..\..\terminal.h 135 | CompileCpp=0 136 | Folder=terminal 137 | Compile=1 138 | Link=1 139 | Priority=1000 140 | OverrideBuildCmd=0 141 | BuildCmd= 142 | 143 | [Unit12] 144 | FileName=com\com.c 145 | CompileCpp=0 146 | Folder=com 147 | Compile=1 148 | Link=1 149 | Priority=1000 150 | OverrideBuildCmd=0 151 | BuildCmd= 152 | 153 | [Unit13] 154 | FileName=com\com.h 155 | CompileCpp=0 156 | Folder=com 157 | Compile=1 158 | Link=1 159 | Priority=1000 160 | OverrideBuildCmd=0 161 | BuildCmd= 162 | 163 | [Unit14] 164 | FileName=terminal_config.h 165 | CompileCpp=0 166 | Folder=terminal 167 | Compile=1 168 | Link=1 169 | Priority=1000 170 | OverrideBuildCmd=0 171 | BuildCmd= 172 | 173 | [Unit2] 174 | FileName=..\..\lib\cli_queue.c 175 | CompileCpp=0 176 | Folder=terminal/lib 177 | Compile=1 178 | Link=1 179 | Priority=1000 180 | OverrideBuildCmd=0 181 | BuildCmd= 182 | 183 | [Unit3] 184 | FileName=..\..\lib\cli_queue.h 185 | CompileCpp=0 186 | Folder=terminal/lib 187 | Compile=1 188 | Link=1 189 | Priority=1000 190 | OverrideBuildCmd=0 191 | BuildCmd= 192 | 193 | [Unit15] 194 | FileName=irq\irq.c 195 | CompileCpp=0 196 | Folder=irq 197 | Compile=1 198 | Link=1 199 | Priority=1000 200 | OverrideBuildCmd=0 201 | BuildCmd= 202 | 203 | [Unit16] 204 | FileName=irq\irq.h 205 | CompileCpp=0 206 | Folder=irq 207 | Compile=1 208 | Link=1 209 | Priority=1000 210 | OverrideBuildCmd=0 211 | BuildCmd= 212 | 213 | [Unit17] 214 | FileName=systimer\systimer.c 215 | CompileCpp=0 216 | Folder=systimer 217 | Compile=1 218 | Link=1 219 | Priority=1000 220 | OverrideBuildCmd=0 221 | BuildCmd= 222 | 223 | [Unit18] 224 | FileName=systimer\systimer.h 225 | CompileCpp=0 226 | Folder=systimer 227 | Compile=1 228 | Link=1 229 | Priority=1000 230 | OverrideBuildCmd=0 231 | BuildCmd= 232 | 233 | [Unit19] 234 | FileName=commands\test_commands.c 235 | CompileCpp=0 236 | Folder=commands 237 | Compile=1 238 | Link=1 239 | Priority=1000 240 | OverrideBuildCmd=0 241 | BuildCmd= 242 | 243 | [Unit20] 244 | FileName=commands\test_commands.h 245 | CompileCpp=0 246 | Folder=commands 247 | Compile=1 248 | Link=1 249 | Priority=1000 250 | OverrideBuildCmd=0 251 | BuildCmd= 252 | 253 | [Unit21] 254 | FileName=..\..\module\cli_input.c 255 | CompileCpp=0 256 | Folder=terminal/module 257 | Compile=1 258 | Link=1 259 | Priority=1000 260 | OverrideBuildCmd=0 261 | BuildCmd= 262 | 263 | [Unit22] 264 | FileName=..\..\module\cli_input.h 265 | CompileCpp=0 266 | Folder=terminal/module 267 | Compile=1 268 | Link=1 269 | Priority=1000 270 | OverrideBuildCmd=0 271 | BuildCmd= 272 | 273 | -------------------------------------------------------------------------------- /examples/dev_cpp/mcu_emulate.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/dev_cpp/mcu_emulate.exe -------------------------------------------------------------------------------- /examples/dev_cpp/mcu_emulate.layout: -------------------------------------------------------------------------------- 1 | [Editor_8] 2 | CursorCol=2 3 | CursorRow=24 4 | TopLine=1 5 | LeftChar=1 6 | [Editor_3] 7 | CursorCol=1 8 | CursorRow=7 9 | TopLine=76 10 | LeftChar=1 11 | [Editor_7] 12 | CursorCol=1 13 | CursorRow=18 14 | TopLine=1 15 | LeftChar=1 16 | [Editor_9] 17 | CursorCol=2 18 | CursorRow=333 19 | TopLine=318 20 | LeftChar=1 21 | [Editor_6] 22 | CursorCol=1 23 | CursorRow=20 24 | TopLine=1 25 | LeftChar=1 26 | [Editor_13] 27 | CursorCol=32 28 | CursorRow=90 29 | TopLine=22 30 | LeftChar=1 31 | [Editor_12] 32 | CursorCol=6 33 | CursorRow=9 34 | TopLine=1 35 | LeftChar=1 36 | [Editor_1] 37 | CursorCol=23 38 | CursorRow=1 39 | TopLine=1 40 | LeftChar=1 41 | [Editors] 42 | Order=0,13,10,9,21,20 43 | Focused=9 44 | [Editor_0] 45 | CursorCol=15 46 | CursorRow=17 47 | TopLine=1 48 | LeftChar=1 49 | [Editor_15] 50 | CursorCol=20 51 | CursorRow=4 52 | TopLine=1 53 | LeftChar=1 54 | [Editor_14] 55 | CursorCol=6 56 | CursorRow=30 57 | TopLine=3 58 | LeftChar=1 59 | [Editor_2] 60 | CursorCol=13 61 | CursorRow=28 62 | TopLine=1 63 | LeftChar=1 64 | [Editor_4] 65 | CursorCol=1 66 | CursorRow=19 67 | TopLine=1 68 | LeftChar=1 69 | [Editor_5] 70 | CursorCol=1 71 | CursorRow=1 72 | TopLine=25 73 | LeftChar=1 74 | [Editor_10] 75 | CursorCol=3 76 | CursorRow=26 77 | TopLine=1 78 | LeftChar=1 79 | [Editor_11] 80 | CursorCol=32 81 | CursorRow=14 82 | TopLine=1 83 | LeftChar=1 84 | [Editor_16] 85 | CursorCol=17 86 | CursorRow=27 87 | TopLine=1 88 | LeftChar=1 89 | [Editor_17] 90 | CursorCol=16 91 | CursorRow=5 92 | TopLine=1 93 | LeftChar=1 94 | [Editor_18] 95 | CursorCol=4 96 | CursorRow=29 97 | TopLine=3 98 | LeftChar=1 99 | [Editor_19] 100 | CursorCol=26 101 | CursorRow=4 102 | TopLine=1 103 | LeftChar=1 104 | [Editor_20] 105 | CursorCol=29 106 | CursorRow=264 107 | TopLine=217 108 | LeftChar=1 109 | [Editor_21] 110 | CursorCol=1 111 | CursorRow=16 112 | TopLine=1 113 | LeftChar=1 114 | -------------------------------------------------------------------------------- /examples/dev_cpp/systimer/systimer.c: -------------------------------------------------------------------------------- 1 | #include "systimer.h" 2 | 3 | #include 4 | 5 | static struct 6 | { 7 | float startTimeMs; 8 | }STMR; 9 | 10 | float _GetCurrentMs() 11 | { 12 | SYSTEMTIME time; 13 | GetSystemTime(&time); 14 | return (time.wSecond * 1000) + time.wMilliseconds; 15 | } 16 | 17 | void STMR_Init() 18 | { 19 | STMR.startTimeMs = _GetCurrentMs(); 20 | } 21 | 22 | float STMR_GetMs() 23 | { 24 | return _GetCurrentMs() - STMR.startTimeMs; 25 | } 26 | 27 | float STMR_GetUs() 28 | { 29 | return STMR_GetMs() * 1000; 30 | } 31 | -------------------------------------------------------------------------------- /examples/dev_cpp/systimer/systimer.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSTIMER_H_ 2 | #define _SYSTIMER_H_ 3 | 4 | void STMR_Init(); 5 | float STMR_GetUs(); 6 | float STMR_GetMs(); 7 | 8 | #endif // _SYSTIMER_H_ 9 | -------------------------------------------------------------------------------- /examples/dev_cpp/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | 18 | // ****************************** Code keys ******************************** 19 | 20 | #define _KEY_INIT(c) ((char)c) 21 | 22 | #define TERM_KEY_ENTER (_KEY_INIT(0x0D)) // Enter command symbol 23 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x7F)) // Delete character before cursor 24 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 25 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 26 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 27 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 28 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 29 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 30 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 31 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 32 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 33 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 34 | #define TERM_KEY_RESET '~' // Reset CPU 35 | 36 | // ************************************************************************** 37 | 38 | // ********************** Terminal Settings ********************************* 39 | 40 | #define _TERM_VER_ "v1.4" // Terminal version 41 | #define TERM_SIZE_TASK (80) // Max number of commands 42 | #define TERM_CMD_BUF_SIZE (80) // Max number of character buffer string command 43 | #define TERM_CMD_LOG_SIZE (10) // Max number of loging command 44 | #define TERM_ARGS_BUF_SIZE (20) // Max number of arguments in one command 45 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 46 | #define CHAR_INTERRUPT TERM_KEY_ESCAPE // Abort execute command key-code symbol 47 | #define CHAR_BACKSPACE '\x08' // Backspace char 48 | #define STRING_TERM_ENTER "\n\r" // String new line 49 | #define STRING_TERM_ARROW ">> " // String arrow enter 50 | #define RESET_FCN() // Reset CPU Function 51 | 52 | #define TERM_TIMELEFT_EN (1) // Calculate time 53 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 54 | #define TERM_TX_RX_DEB_EN (1) // Addition debug printf 55 | #define TERM_CMD_LOG_EN (1) // Command logging 56 | #define TERM_CMD_AUTOCMPLT_EN (1) // Command AutoComplete 57 | #define TERM_LR_KEY_EN (1) // Move cursor left-rigth 58 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 59 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 60 | #define TERM_PRINT_ERROR_EXEC_EN (1) // Print error after execute command 61 | #define TERM_PRINT_ERROR_ADD_CMD_EN (1) // Print error after added command 62 | #define ECHO_EN (1) // Enter echo enable 63 | 64 | // ************************************************************************** 65 | 66 | // ************************* IO Terminal Settings *************************** 67 | 68 | #if (TERM_TX_RX_EN == 1) 69 | #include 70 | extern void COM_Print(const char* str); 71 | extern char dbgbuffer[256]; 72 | #define COM_Printf(...) {sprintf(dbgbuffer,__VA_ARGS__);COM_Print(dbgbuffer);} 73 | #define CLI_Printf COM_Printf 74 | extern void COM_Putc(char c); 75 | #if (ECHO_EN == 1) 76 | #define CLI_PutChar COM_Putc 77 | #else // ECHO_EN != 1 78 | #define CLI_PutChar 79 | #endif // ECHO_EN == 1 80 | 81 | #else // TERM_TX_RX_EN != 1 82 | #define CLI_Printf 83 | #define CLI_PutChar 84 | #endif // TERM_TX_RX_EN == 1 85 | // ************************************************************************** 86 | 87 | // *********************** IO Debug Terminal Settings *********************** 88 | 89 | #if (TERM_TX_RX_DEB_EN == 1) 90 | #define CLI_DPrintf printf 91 | #else // TERM_TX_RX_DEB_EN != 1 92 | #define CLI_DPrintf 93 | #endif // TERM_TX_RX_DEB_EN == 1 94 | 95 | // ************************************************************************** 96 | 97 | // ************************ Time calculate Settings ************************* 98 | 99 | #if (TERM_TIMELEFT_EN == 1) 100 | 101 | extern void STMR_Init(); 102 | extern float STMR_GetUs(); 103 | extern float STMR_GetMs(); 104 | 105 | #define CLI_GetUs() (STMR_GetUs()) // System time in us 106 | #define CLI_GetFastUs() (STMR_GetUs()) // System time in us (not exact) 107 | #define CLI_GetFastMs() (STMR_GetMs()) // System time in ms (not exact) 108 | #define CLI_CounterReset() {STMR_Init();} 109 | 110 | #else // TERM_TIMELEFT_EN != 1 111 | 112 | #define CLI_GetUs() (0) // System time in us 113 | #define CLI_GetFastUs() (0) // System time in us (not exact) 114 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 115 | #define CLI_CounterReset() {} 116 | 117 | #endif // TERM_TIMELEFT_EN == 1 118 | 119 | // ************************************************************************** 120 | 121 | // ********************** memory allocate functions ************************* 122 | 123 | #if (TERM_DEFAULT_ALLOC_EN == 1) 124 | #include 125 | #define cli_malloc malloc 126 | #define cli_free free 127 | #else 128 | #define cli_malloc // your implementation 129 | #define cli_free // your implementation 130 | #endif 131 | 132 | // ************************************************************************** 133 | 134 | // *************************** string functions ***************************** 135 | 136 | #if (TERM_DEFAULT_STRING_EN == 1) 137 | #include 138 | #define cli_memcpy memcpy 139 | #else 140 | #define cli_memcpy // your implementation 141 | #endif 142 | 143 | // ************************************************************************** 144 | 145 | #endif // _TERMIANL_CONFIG_H_ 146 | -------------------------------------------------------------------------------- /examples/linux/Time.c: -------------------------------------------------------------------------------- 1 | #define _POSIX_C_SOURCE 199309L 2 | #include "Time.h" 3 | #include 4 | #include 5 | 6 | long long TimeUs(void) { 7 | struct timespec t; 8 | clock_gettime(CLOCK_MONOTONIC, &t); 9 | 10 | long long t_us = t.tv_sec * 1000000LL + t.tv_nsec / 1000LL; 11 | return t_us; 12 | } 13 | 14 | long long TimeMs(void) { 15 | struct timespec t; 16 | clock_gettime(CLOCK_MONOTONIC, &t); 17 | 18 | long long t_ms = t.tv_sec * 1000LL + t.tv_nsec / 1000000LL; 19 | return t_ms; 20 | } 21 | -------------------------------------------------------------------------------- /examples/linux/Time.h: -------------------------------------------------------------------------------- 1 | #ifndef TERMINAL_LINUX_TIME_H 2 | #define TERMINAL_LINUX_TIME_H 3 | 4 | long long TimeUs(void); 5 | long long TimeMs(void); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /examples/linux/main.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "terminal_config.h" 11 | #include "terminal.h" 12 | 13 | #include "test_commands/test_commands.h" 14 | 15 | char dbgbuffer[256]; 16 | 17 | struct termios orig_termios; 18 | 19 | void reset_terminal_mode() 20 | { 21 | tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); 22 | } 23 | 24 | void set_raw_mode() 25 | { 26 | struct termios tattr; 27 | 28 | tcgetattr(STDIN_FILENO, &orig_termios); 29 | atexit(reset_terminal_mode); 30 | 31 | tcgetattr(STDIN_FILENO, &tattr); 32 | tattr.c_lflag &= ~(ICANON|ECHO); 33 | tattr.c_cc[VMIN] = 1; 34 | tattr.c_cc[VTIME] = 0; 35 | tcsetattr(STDIN_FILENO, TCSANOW, &tattr); 36 | } 37 | 38 | void sigio_handler(int signo) 39 | { 40 | char c; 41 | while (read(STDIN_FILENO, &c, 1) > 0) { 42 | CLI_EnterChar(c); 43 | } 44 | } 45 | 46 | void setup_keyboard_signal() 47 | { 48 | int flags = fcntl(STDIN_FILENO, F_GETFL, 0); 49 | if (flags == -1) perror("fcntl F_GETFL"); 50 | 51 | if (fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK | O_ASYNC) == -1) { 52 | perror("fcntl F_SETFL"); 53 | } 54 | 55 | if (fcntl(STDIN_FILENO, F_SETOWN, getpid()) == -1) { 56 | perror("fcntl F_SETOWN"); 57 | } 58 | 59 | signal(SIGIO, sigio_handler); 60 | } 61 | 62 | void InitSW() 63 | { 64 | set_raw_mode(); 65 | setup_keyboard_signal(); 66 | 67 | CLI_Init(TDC_Time); 68 | TestCmds_Init(); 69 | } 70 | 71 | int main() { 72 | InitSW(); 73 | 74 | while(1) { 75 | CLI_Execute(); 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /examples/linux/makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -c 2 | LD = gcc 3 | #OC = objcopy 4 | #OS = size 5 | 6 | TARGET = terminal 7 | 8 | OPT = -O0 9 | DIR_TEST_COMMANDS = ./test_commands 10 | DIR_TERMINAL = ../.. 11 | DIR_TERMINAL_lib = $(DIR_TERMINAL)/lib 12 | DIR_TERMINAL_module = $(DIR_TERMINAL)/module 13 | DIR_OBJ = ./.obj 14 | DEBUG = -g 15 | 16 | VPATH = $(DIR_TERMINAL) $(DIR_TERMINAL_lib) $(DIR_TERMINAL_module) $(DIR_TEST_COMMANDS) ./ 17 | 18 | DIR_FLAGS = -I. -I$(DIR_TERMINAL) -I$(DIR_TERMINAL_lib) -I$(DIR_TERMINAL_module) -I$(DIR_TEST_COMMANDS) 19 | 20 | CFLAGS += $(OPT) $(DEBUG) 21 | CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration 22 | CFLAGS += -Wredundant-decls 23 | CFLAGS += -fno-common -ffunction-sections -fdata-sections 24 | CFLAGS += -MMD -MP 25 | 26 | PREPFLAGS = -MD -Wall -Wundef $(DEFS) 27 | 28 | OBJS = $(DIR_OBJ)/main.o \ 29 | $(DIR_OBJ)/cli_queue.o \ 30 | $(DIR_OBJ)/cli_string.o \ 31 | $(DIR_OBJ)/cli_input.o \ 32 | $(DIR_OBJ)/cli_log.o \ 33 | $(DIR_OBJ)/cli_time.o \ 34 | $(DIR_OBJ)/terminal.o \ 35 | $(DIR_OBJ)/test_commands.o \ 36 | $(DIR_OBJ)/Time.o 37 | 38 | all : $(TARGET) 39 | 40 | $(TARGET) : $(OBJS) 41 | $(LD) $(CFLAGS) $(OBJS) -o $(TARGET) 42 | 43 | $(DIR_OBJ)/%.o : %.c 44 | mkdir -p $(DIR_OBJ) 45 | $(CC) $(CFLAGS) $(DIR_FLAGS) $(PREPFLAGS) $< -o $@ 46 | 47 | clean : 48 | rm -rf $(DIR_OBJ) $(TARGET) 49 | 50 | -include $(OBJS:.o=.d) 51 | -------------------------------------------------------------------------------- /examples/linux/terminal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/examples/linux/terminal -------------------------------------------------------------------------------- /examples/linux/terminal_config.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Terminal configure file 4 | * 5 | * --------------------------------------------------------------------- 6 | * 7 | * Examples in Readme.h file. 8 | * 9 | ************************************************************************/ 10 | 11 | #ifndef _TERMIANL_CONFIG_H_ 12 | #define _TERMIANL_CONFIG_H_ 13 | 14 | #include 15 | #include 16 | #include // strtol, itoa 17 | #include 18 | 19 | // ****************************** Code keys ******************************** 20 | 21 | #define _KEY_INIT(c) ((char)c) 22 | 23 | #define TERM_KEY_ENTER (_KEY_INIT(0x0A)) // Enter command symbol 24 | #define TERM_KEY_BACKSPACE (_KEY_INIT(0x7F)) // Delete character before cursor position 25 | #define TERM_KEY_LSHIFT (_KEY_INIT(0x08)) // Left shift symbol 26 | #define TERM_KEY_ESCAPE (_KEY_INIT(0xF0)) // Exception execute command symbol 27 | #define TERM_KEY_UP (_KEY_INIT(0xF1)) // KeyUp symbol 28 | #define TERM_KEY_RIGHT (_KEY_INIT(0xF2)) // KeyRight symbol 29 | #define TERM_KEY_DOWN (_KEY_INIT(0xF3)) // KeyDown symbol 30 | #define TERM_KEY_LEFT (_KEY_INIT(0xF4)) // KeyLeft symbol 31 | #define TERM_KEY_DEL (_KEY_INIT(0xF5)) // Delete character after cursor position 32 | #define TERM_KEY_HOME (_KEY_INIT(0xA0)) // Home key 33 | #define TERM_KEY_END (_KEY_INIT(0xA1)) // End key 34 | #define TERM_KEY_TAB (_KEY_INIT(0x09)) // 35 | #define TERM_KEY_CAN (_KEY_INIT(0x18)) 36 | #define TERM_KEY_RESET '~' // Reset CPU 37 | 38 | // ************************************************************************** 39 | 40 | // ********************** Terminal Settings ********************************* 41 | 42 | #define _TERM_VER_ "v1.4" // Terminal version 43 | #define TERM_SIZE_TASK (20) // Max number of commands 44 | #define TERM_CMD_BUF_SIZE (60) // Max number of character buffer string command 45 | #define TERM_CMD_LOG_SIZE (10) // Max number of loging command 46 | #define TERM_ARGS_BUF_SIZE (10) // Max number of arguments in one command 47 | #define TERM_ARG_SIZE (15) // Max number character of one arguments 48 | #define CHAR_INTERRUPT TERM_KEY_CAN // Abort execute command key-code symbol 49 | #define CHAR_BACKSPACE '\x08' // Backspace char 50 | #define STRING_TERM_ENTER "\n\r" // String new line 51 | #define STRING_TERM_ARROW ">> " // String arrow enter 52 | #define RESET_FCN() // Reset CPU Function 53 | 54 | #define TERM_TIMELEFT_EN (1) // Calculate time 55 | #define TERM_TX_RX_EN (1) // Terminal Printf (without this don,t work) 56 | #define TERM_TX_RX_DEB_EN (0) // Addition debug printf 57 | #define TERM_CMD_LOG_EN (1) // Command logging 58 | #define TERM_CMD_AUTOCMPLT_EN (1) // Command AutoComplete 59 | #define TERM_LR_KEY_EN (1) // Move cursor left-rigth 60 | #define TERM_DEFAULT_ALLOC_EN (1) // Default Memory Allocate functions 61 | #define TERM_DEFAULT_STRING_EN (1) // Default String functions 62 | #define TERM_PRINT_ERROR_EXEC_EN (1) // Print error after execute command 63 | #define TERM_PRINT_ERROR_ADD_CMD_EN (1) // Print error after added command 64 | #define ECHO_EN (1) // Enter echo enable 65 | 66 | // ************************************************************************** 67 | 68 | // ************************* IO Terminal Settings *************************** 69 | 70 | #if (TERM_TX_RX_EN == 1) 71 | #include 72 | extern char dbgbuffer[256]; 73 | #define COM_Printf(...) {sprintf(dbgbuffer,__VA_ARGS__); printf("%s", dbgbuffer); fflush(stdout);} 74 | #define CLI_Printf COM_Printf 75 | #if (ECHO_EN == 1) 76 | #define CLI_PutChar(c) { char ch = c; write(STDOUT_FILENO, &ch, 1); } 77 | #else // ECHO_EN != 1 78 | #define CLI_PutChar 79 | #endif // ECHO_EN == 1 80 | 81 | #else // TERM_TX_RX_EN != 1 82 | #define CLI_Printf 83 | #define CLI_PutChar 84 | #endif // TERM_TX_RX_EN == 1 85 | // ************************************************************************** 86 | 87 | // *********************** IO Debug Terminal Settings *********************** 88 | 89 | #if (TERM_TX_RX_DEB_EN == 1) 90 | #define CLI_DPrintf printf 91 | #else // TERM_TX_RX_DEB_EN != 1 92 | #define CLI_DPrintf 93 | #endif // TERM_TX_RX_DEB_EN == 1 94 | 95 | // ************************************************************************** 96 | 97 | // ************************ Time calculate Settings ************************* 98 | 99 | #if (TERM_TIMELEFT_EN == 1) 100 | 101 | // your implementation 102 | extern long long TimeUs(void); 103 | extern long long TimeMs(void); 104 | extern void TimeReset(void); 105 | 106 | #define CLI_GetUs() (TimeUs()) // System time in us 107 | #define CLI_GetFastUs() (TimeUs()) // System time in us (not exact) 108 | #define CLI_GetFastMs() (TimeMs()) // System time in ms (not exact) 109 | #define CLI_CounterReset() {} 110 | 111 | #else // TERM_TIMELEFT_EN != 1 112 | 113 | #define CLI_GetUs() (0) // System time in us 114 | #define CLI_GetFastUs() (0) // System time in us (not exact) 115 | #define CLI_GetFastMs() (0) // System time in ms (not exact) 116 | #define CLI_CounterReset() {} 117 | 118 | #endif // TERM_TIMELEFT_EN == 1 119 | 120 | // ************************************************************************** 121 | 122 | // ********************** memory allocate functions ************************* 123 | 124 | #if (TERM_DEFAULT_ALLOC_EN == 1) 125 | #include 126 | #define cli_malloc malloc 127 | #define cli_free free 128 | #else 129 | #define cli_malloc // your implementation 130 | #define cli_free // your implementation 131 | #endif 132 | 133 | // ************************************************************************** 134 | 135 | // *************************** string functions ***************************** 136 | 137 | #if (TERM_DEFAULT_STRING_EN == 1) 138 | #include 139 | #define cli_memcpy memcpy 140 | #else 141 | #define cli_memcpy // your implementation 142 | #endif 143 | 144 | // ************************************************************************** 145 | 146 | #endif // _TERMIANL_CONFIG_H_ 147 | -------------------------------------------------------------------------------- /examples/linux/test_commands/test_commands.c: -------------------------------------------------------------------------------- 1 | #include "test_commands.h" 2 | 3 | #include "terminal_config.h" 4 | #include "terminal.h" 5 | 6 | static uint8_t _t1_cmd() 7 | { 8 | uint32_t a = 0x01; 9 | uint32_t b = 0x10; 10 | uint32_t c = 7; 11 | 12 | // be sure arguments 13 | c = CLI_GetArgDec(0); 14 | 15 | // optional arguments 16 | CLI_GetArgHexByFlag("-a", &a); 17 | CLI_GetArgHexByFlag("-b", &b); 18 | 19 | CLI_Printf("\r\na: 0x%08X\r\nb: 0x%08X\r\nc: %d", (int) a, (int) b, (int) c); 20 | 21 | return TE_OK; 22 | } 23 | 24 | static uint8_t _t2_cmd() 25 | { 26 | CLI_Printf("\r\nPress ESC"); 27 | while(1) 28 | { 29 | CLI_CheckAbort(); 30 | } 31 | 32 | return TE_OK; 33 | } 34 | 35 | void TestCmds_Init(void) 36 | { 37 | CLI_AddCmd("t1", _t1_cmd, 1, TMC_PrintStartTime | TMC_PrintStopTime, "t1 - description command"); 38 | CLI_AddCmd("t2", _t2_cmd, 0, TMC_PrintDiffTime, "t2 - description command"); 39 | } 40 | -------------------------------------------------------------------------------- /examples/linux/test_commands/test_commands.h: -------------------------------------------------------------------------------- 1 | #ifndef _MY_TEST_COMMANDS_H_ 2 | #define _MY_TEST_COMMANDS_H_ 3 | 4 | void TestCmds_Init(void); 5 | 6 | #endif // _MY_TEST_COMMANDS_H_ 7 | -------------------------------------------------------------------------------- /lib/cli_queue.c: -------------------------------------------------------------------------------- 1 | #include "cli_queue.h" 2 | #include "terminal_config.h" 3 | 4 | #include "stdlib.h" 5 | #include "string.h" 6 | 7 | void Q_Free(QueueObj* qdObj) 8 | { 9 | Queue_s* qd = (Queue_s*) qdObj; 10 | cli_free(qd->ptrObj); 11 | } 12 | 13 | void Q_Init(QueueObj* qdObj, uint16_t sizeQueue, uint8_t sizeObj, uint32_t mode) 14 | { 15 | Queue_s* qd = (Queue_s*) qdObj; 16 | 17 | qd->ptrObj = (void*) cli_malloc(sizeObj * sizeQueue); 18 | 19 | if (qd->ptrObj == NULL) 20 | { 21 | } 22 | 23 | qd->size = sizeQueue; 24 | qd->_cntr = 0; 25 | qd->sizeObj = sizeObj; 26 | qd->mode = mode; 27 | } 28 | 29 | bool Q_Push(QueueObj* qdObj, const void* value) 30 | { 31 | Queue_s* qd = (Queue_s*) qdObj; 32 | 33 | if (qd->_cntr >= qd->size) 34 | { 35 | if ((qd->mode & QUEUE_FORCED_PUSH_POP_Msk) != 0) 36 | { 37 | memcpy(qd->ptrObj, qd->ptrObj + qd->sizeObj, qd->sizeObj * (qd->size - 1)); 38 | memcpy(qd->ptrObj + qd->sizeObj * (qd->_cntr - 1), value, qd->sizeObj); 39 | qd->_cntr = qd->size; 40 | } 41 | else 42 | return false; 43 | } 44 | else 45 | { 46 | memcpy(qd->ptrObj + qd->sizeObj * qd->_cntr, value, qd->sizeObj); 47 | qd->_cntr++; 48 | } 49 | 50 | return true; 51 | } 52 | 53 | bool Q_Pop(QueueObj* qdObj, void* value) 54 | { 55 | Queue_s* qd = (Queue_s*) qdObj; 56 | 57 | if (qd->_cntr == 0) 58 | return false; 59 | 60 | memcpy((uint8_t*)value, qd->ptrObj, qd->sizeObj); 61 | for(uint8_t i = 0; i < qd->_cntr; i++) 62 | { 63 | memcpy((uint8_t*)(qd->ptrObj + qd->sizeObj * i), (uint8_t*)(qd->ptrObj + qd->sizeObj * (i+1)), qd->sizeObj); 64 | } 65 | 66 | qd->_cntr--; 67 | return true; 68 | } 69 | 70 | bool Q_IsFull(QueueObj* qdObj) 71 | { 72 | Queue_s* qd = (Queue_s*) qdObj; 73 | 74 | return qd->_cntr >= qd->size; 75 | } 76 | 77 | bool Q_IsEmpty(QueueObj* qdObj) 78 | { 79 | Queue_s* qd = (Queue_s*) qdObj; 80 | 81 | return qd->_cntr == 0; 82 | } 83 | 84 | bool Q_IsEqual(QueueObj* qd, const void* items, uint32_t size) 85 | { 86 | if (size > qd->_cntr) 87 | return false; 88 | 89 | return (memcmp(qd->ptrObj, items, qd->sizeObj * size) == 0); 90 | } 91 | -------------------------------------------------------------------------------- /lib/cli_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUEUE_H_ 2 | #define _QUEUE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /// \brief Struct Queue 9 | typedef struct 10 | { 11 | void* ptrObj; // pointer on objects 12 | uint16_t size; // queue size 13 | uint16_t _cntr; // queue count added objects 14 | uint8_t sizeObj; // one object size 15 | uint32_t mode; // queue work mode 16 | } Queue_s; 17 | 18 | #define QUEUE_FORCED_PUSH_POP_Msk (0x01) // Forced queue filling 19 | 20 | typedef Queue_s QueueObj; 21 | 22 | void Q_Free(QueueObj* qd); 23 | void Q_Init(QueueObj* qd, uint16_t sizeQueue, uint8_t sizeObj, uint32_t mode); 24 | bool Q_Push(QueueObj* qd, const void* value); 25 | bool Q_Pop(QueueObj* qd, void* value); 26 | bool Q_IsFull(QueueObj* qd); 27 | bool Q_IsEmpty(QueueObj* qd); 28 | bool Q_IsEqual(QueueObj* qd, const void* items, uint32_t size); 29 | 30 | #endif // _QUEUE_H_ 31 | -------------------------------------------------------------------------------- /lib/cli_string.c: -------------------------------------------------------------------------------- 1 | #include "cli_string.h" 2 | #include "terminal_config.h" 3 | 4 | void _strcpy(const char* src, uint16_t offsetSrc, char* dst, uint16_t offsetDst, uint16_t length); 5 | char* _trim(const char* src); 6 | uint8_t _strcmp(const char* str1, const char* str2); 7 | uint32_t _strlen(const char* strSrc); 8 | uint16_t _getCountSeparator(const char* str, const char* separator); 9 | 10 | /// \brief Splitting a string by a given separator 11 | void split(char* strSrc, const char* separator, Params_s* dst) 12 | { 13 | uint8_t count_sep = _getCountSeparator(strSrc, separator); 14 | uint16_t lenSep = _strlen((char*)separator); 15 | 16 | //dst->argv = (char**) malloc(sizeof(char*) * count_sep); 17 | dst->argc = count_sep; 18 | 19 | int start_index = 0; 20 | int size_word = 0; 21 | 22 | int co = 0; 23 | int co_arg = 0; 24 | while(1) 25 | { 26 | 27 | uint16_t s = 0; 28 | 29 | for(; s < lenSep; s++){ 30 | if((strSrc[co] == separator[s]) || (strSrc[co] == '\0')) 31 | { 32 | size_word = co - start_index; 33 | 34 | //dst->argv[co_arg] = malloc(sizeof(char) * (size_word + 1)); 35 | dst->argv[co_arg][size_word] = '\0'; 36 | _strcpy(strSrc, start_index, dst->argv[co_arg], 0, size_word); 37 | 38 | start_index = co + 1; 39 | co_arg++; 40 | break; 41 | } 42 | } 43 | 44 | if (strSrc[co] == '\0') 45 | break; 46 | 47 | co++; 48 | } 49 | } 50 | 51 | /// \brief free memory 52 | /// \return none 53 | void ArgDestroy(Params_s* src) 54 | { 55 | /* 56 | for(int8_t i = src->argc - 1; i > 0; i--) 57 | { 58 | free((src->argv[i])); 59 | } 60 | 61 | free(src->argv); 62 | */ 63 | src->argc = 0; 64 | } 65 | 66 | // ****************** private methods ********************** 67 | 68 | void _strcpy(const char* src, uint16_t offsetSrc, char* dst, uint16_t offsetDst, uint16_t length) 69 | { 70 | uint16_t i = 0; 71 | for(; i < length; i++) 72 | dst[i + offsetDst] = src[i + offsetSrc]; 73 | } 74 | 75 | char* _trim(const char* src) 76 | { 77 | int16_t lengthDst; 78 | char* result; 79 | int16_t i = 0; 80 | int16_t len = _strlen(src); 81 | int16_t coStart = 0, coEnd = 0; 82 | 83 | for(; i < len; i++){ 84 | if (!((src[i] > 0x00) && (src[i] < 0x21))) 85 | break; 86 | coStart++; 87 | } 88 | 89 | if (coStart == len){ 90 | result = cli_malloc(sizeof(char)); 91 | result[0] = '\0'; 92 | return result; 93 | } 94 | 95 | for(i = len - 1; i >= 0; i++){ 96 | if (!((src[i] > 0x00) && (src[i] < 0x21))) 97 | break; 98 | coEnd++; 99 | } 100 | 101 | lengthDst = len - coStart - coEnd; 102 | result = cli_malloc(sizeof(char) * lengthDst); 103 | _strcpy(src, coStart, result, 0, lengthDst); 104 | return result; 105 | } 106 | 107 | uint32_t _strlen(const char* strSrc) 108 | { 109 | int32_t co = 0; 110 | while((strSrc != NULL) && (*strSrc != '\0')){ 111 | strSrc++; 112 | co++; 113 | } 114 | 115 | return co; 116 | } 117 | 118 | uint16_t _getCountSeparator(const char* strSrc, const char* separator) 119 | { 120 | uint8_t i = 0; 121 | uint16_t result = 0; 122 | uint16_t count_separator = _strlen((char*) separator); 123 | 124 | for(; strSrc[i] != '\0'; i++) 125 | { 126 | uint16_t j = 0; 127 | for(; j < count_separator; j++) 128 | if (strSrc[i] == separator[j]){ 129 | result++; 130 | break; 131 | } 132 | } 133 | 134 | return result + 1; 135 | } 136 | 137 | uint8_t _strPartCmp(const char* str1, const char* str2) 138 | { 139 | uint8_t co = 0; 140 | while(((str1 + co) != NULL) && (*(str1 + co) != '\0') && 141 | ((str2 + co) != NULL) && (*(str2 + co) != '\0')){ 142 | 143 | if (str1[co] != str2[co]) 144 | return 0; 145 | 146 | co++; 147 | } 148 | 149 | return 1; 150 | } 151 | 152 | uint8_t _strcmp(const char* str1, const char* str2) 153 | { 154 | uint16_t co = 0; 155 | 156 | if (_strlen(str1) != _strlen(str2)) 157 | return 0; 158 | 159 | while(((str1 + co) != NULL) && (*(str1 + co) != '\0') && 160 | ((str2 + co) != NULL) && (*(str2 + co) != '\0')){ 161 | 162 | if (str1[co] != str2[co]) 163 | return 0; 164 | 165 | co++; 166 | } 167 | 168 | if ( 169 | (((str1 + co) == NULL) && ((str2 + co) != NULL)) || 170 | (((str2 + co) == NULL) && ((str1 + co) != NULL)) || 171 | (((str1 + co) != NULL) && ((str2 + co) != NULL) && (*(str2 + co) != *(str1 + co))) 172 | ) 173 | return 0; 174 | 175 | 176 | return 1; 177 | } 178 | -------------------------------------------------------------------------------- /lib/cli_string.h: -------------------------------------------------------------------------------- 1 | #ifndef _CLI_STRING_A_H 2 | #define _CLI_STRING_A_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct{ 9 | uint8_t argc; 10 | char** argv; 11 | }Params_s; 12 | 13 | void ArgDestroy(Params_s* src); 14 | 15 | void split(char* strSrc, const char* separator, Params_s* dst); 16 | 17 | #endif // _CLI_STRING_A_H 18 | -------------------------------------------------------------------------------- /module/cli_input.c: -------------------------------------------------------------------------------- 1 | #include "cli_input.h" 2 | 3 | #include "lib/cli_queue.h" 4 | #include "lib/cli_string.h" 5 | 6 | extern uint32_t _strlen(const char* strSrc); 7 | 8 | #define INPUT_COUNT_BUFFER 2 9 | 10 | typedef struct 11 | { 12 | char Data[TERM_CMD_BUF_SIZE + 1]; // buffer 13 | int16_t CursorInBuffer; // cursos position 14 | int16_t BufferCount; // count entered symbols 15 | }Buffer_s; 16 | 17 | struct 18 | { 19 | Buffer_s Buffers[INPUT_COUNT_BUFFER]; // buffers commands 20 | Buffer_s* CurBuffer; 21 | Queue_s Symbols; // queue symbols input 22 | InputBufferType_e CurrentBuffer; // current proccesing buffer 23 | }Input; 24 | 25 | static void _AddChar(char c) 26 | { 27 | CLI_PutChar(c); 28 | 29 | Input.CurBuffer->Data[Input.CurBuffer->CursorInBuffer] = c; 30 | Input.CurBuffer->BufferCount++; 31 | Input.CurBuffer->CursorInBuffer++; 32 | Input.CurBuffer->Data[Input.CurBuffer->BufferCount] = '\0'; 33 | } 34 | 35 | static void _RemChar() 36 | { 37 | CLI_PutChar(CHAR_BACKSPACE); 38 | CLI_PutChar(' '); 39 | CLI_PutChar(CHAR_BACKSPACE); 40 | 41 | Input.CurBuffer->CursorInBuffer--; 42 | Input.CurBuffer->BufferCount--; 43 | Input.CurBuffer->Data[Input.CurBuffer->BufferCount] = '\0'; 44 | } 45 | 46 | void INPUT_Refresh(const char* newCmd) 47 | { 48 | CLI_PutChar('\r'); 49 | CLI_Printf(STRING_TERM_ARROW); 50 | 51 | if (Input.CurBuffer->Data != newCmd) 52 | { 53 | uint32_t lenNewCmd = _strlen(newCmd); 54 | uint32_t lenCurCmd = Input.CurBuffer->BufferCount; 55 | cli_memcpy(Input.CurBuffer->Data, newCmd, lenNewCmd); 56 | 57 | Input.CurBuffer->BufferCount = lenNewCmd; 58 | Input.CurBuffer->CursorInBuffer = lenNewCmd; 59 | 60 | for(uint8_t i = 0; i < lenNewCmd; i++) 61 | { 62 | CLI_PutChar(Input.CurBuffer->Data[i]); 63 | } 64 | 65 | uint8_t cntSpcChar = 0; 66 | for(uint8_t i = lenNewCmd; i < lenCurCmd; i++) 67 | { 68 | CLI_PutChar(' '); 69 | cntSpcChar++; 70 | } 71 | 72 | for(uint8_t i = 0; i < cntSpcChar; i++) 73 | {CLI_PutChar(CHAR_BACKSPACE);} 74 | 75 | #if 0 76 | CLI_DPrintf("\r\nNewCmd: %s", newCmd); 77 | CLI_DPrintf("\r\nlenNewCmd: %d", lenNewCmd); 78 | #endif 79 | 80 | } 81 | else 82 | { 83 | for(uint8_t i = 0; i < Input.CurBuffer->BufferCount; i++) 84 | { 85 | CLI_PutChar(Input.CurBuffer->Data[i]); 86 | } 87 | } 88 | } 89 | 90 | bool INPUT_IsEmpty() 91 | { 92 | return Input.CurBuffer->BufferCount == 0; 93 | } 94 | 95 | bool INPUT_IsFull() 96 | { 97 | return Input.CurBuffer->BufferCount >= TERM_CMD_BUF_SIZE; 98 | } 99 | 100 | void INPUT_RemChar() 101 | { 102 | #if (TERM_LR_KEY_EN == 1) 103 | 104 | if (Input.CurBuffer->CursorInBuffer != Input.CurBuffer->BufferCount) 105 | { 106 | // save current position cursor 107 | uint8_t tmpPos = Input.CurBuffer->CursorInBuffer - 1; 108 | 109 | cli_memcpy(Input.Buffers[TransitBuffer].Data, Input.CurBuffer->Data, tmpPos); 110 | cli_memcpy(Input.Buffers[TransitBuffer].Data + tmpPos, Input.CurBuffer->Data + tmpPos + 1, Input.CurBuffer->BufferCount - tmpPos); 111 | 112 | Input.Buffers[TransitBuffer].Data[Input.CurBuffer->BufferCount - 1] = '\0'; 113 | 114 | INPUT_Refresh(Input.Buffers[TransitBuffer].Data); 115 | 116 | for(uint8_t pos = 0; pos < Input.CurBuffer->BufferCount - tmpPos; pos++) 117 | { 118 | CLI_PutChar(CHAR_BACKSPACE); 119 | Input.CurBuffer->CursorInBuffer--; 120 | } 121 | } 122 | else 123 | { 124 | _RemChar(); 125 | } 126 | #else 127 | _RemChar(); 128 | #endif 129 | } 130 | 131 | void INPUT_AddChar(char c) 132 | { 133 | #if (TERM_LR_KEY_EN == 1) 134 | if (Input.CurBuffer->CursorInBuffer != Input.CurBuffer->BufferCount) 135 | { 136 | uint8_t tmpPos = Input.CurBuffer->CursorInBuffer; 137 | cli_memcpy(Input.Buffers[TransitBuffer].Data, Input.CurBuffer->Data, tmpPos); 138 | cli_memcpy(Input.Buffers[TransitBuffer].Data + tmpPos, &c, 1); 139 | cli_memcpy(Input.Buffers[TransitBuffer].Data + tmpPos + 1, Input.CurBuffer->Data + tmpPos, Input.CurBuffer->BufferCount - tmpPos); 140 | Input.Buffers[TransitBuffer].Data[Input.CurBuffer->BufferCount + 1] = '\0'; 141 | 142 | Input.CurBuffer->BufferCount++; 143 | Input.CurBuffer->CursorInBuffer++; 144 | Input.CurBuffer->Data[Input.CurBuffer->BufferCount] = '\0'; 145 | 146 | tmpPos++; 147 | INPUT_Refresh(Input.Buffers[TransitBuffer].Data); 148 | 149 | for(uint8_t pos = 0; pos < Input.CurBuffer->BufferCount - tmpPos; pos++) 150 | { 151 | CLI_PutChar(CHAR_BACKSPACE); 152 | Input.CurBuffer->CursorInBuffer--; 153 | } 154 | } 155 | else 156 | { 157 | _AddChar(c); 158 | } 159 | 160 | #else 161 | _AddChar(c); 162 | #endif 163 | } 164 | 165 | void INPUT_Init() 166 | { 167 | for(uint32_t i = 0; i < INPUT_COUNT_BUFFER; i++) 168 | { 169 | Input.Buffers[i].Data[0] = '\0'; 170 | Input.Buffers[i].BufferCount = 0; 171 | Input.Buffers[i].CursorInBuffer = 0; 172 | } 173 | 174 | Input.CurBuffer = &Input.Buffers[MainBuffer]; 175 | 176 | Q_Init(&Input.Symbols, 3, sizeof(char), QUEUE_FORCED_PUSH_POP_Msk); 177 | 178 | for(uint8_t i = 0; i < 3; i++) 179 | { 180 | char c = 0; 181 | Q_Push(&Input.Symbols, &c); 182 | } 183 | } 184 | 185 | uint8_t arr_up[] = {0x1B, 0x5B, 0x41}; 186 | uint8_t arr_down[] = {0x1B, 0x5B, 0x42}; 187 | uint8_t arr_right[] = {0x1B, 0x5B, 0x43}; 188 | uint8_t arr_left[] = {0x1B, 0x5B, 0x44}; 189 | uint8_t arr_esc[] = {0x1B, 0x1B, 0x1B}; 190 | uint8_t del[] = {0x1B, 0x5B, 0x33}; 191 | uint8_t home[] = {0x1B, 0x5B, 0x31}; 192 | uint8_t end[] = {0x1B, 0x5B, 0x34}; 193 | 194 | InputValue_s INPUT_PutChar(char c) 195 | { 196 | InputValue_s iv; 197 | 198 | Q_Push(&Input.Symbols, &c); 199 | 200 | if (Q_IsEqual(&Input.Symbols, arr_up, 3)) {c = TERM_KEY_UP;} 201 | else if (Q_IsEqual(&Input.Symbols, arr_down, 3)) {c = TERM_KEY_DOWN;} 202 | else if (Q_IsEqual(&Input.Symbols, arr_right, 3)) {c = TERM_KEY_RIGHT;} 203 | else if (Q_IsEqual(&Input.Symbols, arr_left, 3)) {c = TERM_KEY_LEFT;} 204 | else if (Q_IsEqual(&Input.Symbols, arr_esc, 3)) {c = TERM_KEY_ESCAPE;} 205 | else if (Q_IsEqual(&Input.Symbols, del, 3)) {c = TERM_KEY_DEL;} 206 | else if (Q_IsEqual(&Input.Symbols, home, 3)) {c = TERM_KEY_HOME;} 207 | else if (Q_IsEqual(&Input.Symbols, end, 3)) {c = TERM_KEY_END;} 208 | 209 | iv.isValid = ((Input.CurBuffer->BufferCount < TERM_CMD_BUF_SIZE) || 210 | (c == TERM_KEY_BACKSPACE) || 211 | (c == TERM_KEY_ENTER) || 212 | (c == CHAR_INTERRUPT)); 213 | 214 | iv.isAlphaBet = (((c >= '0') && (c <= '9')) || 215 | ((c >= 'a') && (c <= 'z')) || 216 | ((c >= 'A') && (c <= 'Z')) || 217 | (c == 0x20) || (c == '_') || (c == '-')); 218 | 219 | iv.keyCode = c; 220 | return iv; 221 | } 222 | 223 | void INPUT_Cache() 224 | { 225 | Input.CurBuffer->Data[Input.CurBuffer->BufferCount] = '\0'; 226 | cli_memcpy(Input.Buffers[TransitBuffer].Data, Input.CurBuffer->Data, Input.CurBuffer->BufferCount + 1); 227 | } 228 | 229 | void INPUT_Reset() 230 | { 231 | Input.CurBuffer->CursorInBuffer = Input.CurBuffer->BufferCount = 0; 232 | Input.CurBuffer->Data[Input.CurBuffer->BufferCount] = '\0'; 233 | } 234 | 235 | char INPUT_GetLastChar() { return Input.CurBuffer->Data[Input.CurBuffer->BufferCount - 1]; } 236 | 237 | void INPUT_CursorTo(uint16_t pos) { Input.CurBuffer->CursorInBuffer = pos; } 238 | 239 | void INPUT_CursorShift(int16_t shift) { Input.CurBuffer->CursorInBuffer += shift; } 240 | 241 | char* INPUT_GetBuffer(InputBufferType_e type) { return Input.Buffers[type].Data; } 242 | 243 | void INPUT_SetBuffer(InputBufferType_e type, char* buffer, uint32_t len) 244 | { 245 | cli_memcpy(Input.Buffers[type].Data, buffer, len); 246 | Input.CurBuffer->BufferCount = Input.CurBuffer->CursorInBuffer = len; 247 | } 248 | 249 | void INPUT_CursorToHome() 250 | { 251 | while(Input.CurBuffer->CursorInBuffer > 0) 252 | { 253 | CLI_PutChar(CHAR_BACKSPACE); 254 | INPUT_CursorShift(-1); 255 | } 256 | } 257 | 258 | void INPUT_CursorToEnd() 259 | { 260 | while(Input.CurBuffer->CursorInBuffer < Input.CurBuffer->BufferCount) 261 | { 262 | CLI_PutChar(Input.CurBuffer->Data[Input.CurBuffer->CursorInBuffer]); 263 | INPUT_CursorShift(1); 264 | } 265 | } 266 | 267 | void INPUT_CursorToLeft() 268 | { 269 | if (Input.CurBuffer->CursorInBuffer > 0) 270 | { 271 | INPUT_CursorShift(-1); 272 | CLI_PutChar(CHAR_BACKSPACE); 273 | } 274 | } 275 | 276 | void INPUT_CursorToRight() 277 | { 278 | if (Input.CurBuffer->CursorInBuffer < Input.CurBuffer->BufferCount) 279 | { 280 | CLI_PutChar(Input.CurBuffer->Data[Input.CurBuffer->CursorInBuffer]); 281 | INPUT_CursorShift(1); 282 | } 283 | } 284 | 285 | void INPUT_Delete() 286 | { 287 | if ((Input.CurBuffer->CursorInBuffer != Input.CurBuffer->BufferCount) && (!INPUT_IsEmpty())) 288 | { 289 | INPUT_CursorShift(1); 290 | if(Input.CurBuffer->CursorInBuffer != Input.CurBuffer->BufferCount) 291 | { 292 | CLI_PutChar(Input.CurBuffer->Data[Input.CurBuffer->CursorInBuffer - 1]); 293 | } 294 | CLI_PutChar(Input.CurBuffer->Data[Input.CurBuffer->CursorInBuffer - 1]); 295 | INPUT_RemChar(); 296 | } 297 | } 298 | 299 | void INPUT_Backspace() 300 | { 301 | if (!INPUT_IsEmpty() && (Input.CurBuffer->CursorInBuffer > 0)) 302 | INPUT_RemChar(); 303 | } 304 | -------------------------------------------------------------------------------- /module/cli_input.h: -------------------------------------------------------------------------------- 1 | #ifndef _CLI_INPUT_H_ 2 | #define _CLI_INPUT_H_ 3 | 4 | #include "terminal_config.h" 5 | 6 | typedef struct 7 | { 8 | char keyCode; 9 | bool isValid; 10 | bool isAlphaBet; 11 | }InputValue_s; 12 | 13 | typedef enum 14 | { 15 | MainBuffer = 0x00, 16 | TransitBuffer = 0x01 17 | }InputBufferType_e; 18 | 19 | void INPUT_Init(); 20 | 21 | char* INPUT_GetBuffer(InputBufferType_e type); 22 | void INPUT_SetBuffer(InputBufferType_e type, char* buffer, uint32_t len); 23 | 24 | bool INPUT_IsEmpty(); 25 | bool INPUT_IsFull(); 26 | 27 | void INPUT_RemChar(); 28 | void INPUT_AddChar(char c); 29 | 30 | void INPUT_Cache(); 31 | void INPUT_Reset(); 32 | 33 | char INPUT_GetLastChar(); 34 | 35 | void INPUT_Refresh(const char* newCmd); 36 | 37 | InputValue_s INPUT_PutChar(char c); 38 | 39 | void INPUT_Delete(); 40 | void INPUT_Backspace(); 41 | 42 | void INPUT_CursorToHome(); 43 | void INPUT_CursorToEnd(); 44 | void INPUT_CursorTo(uint16_t pos); 45 | void INPUT_CursorToLeft(); 46 | void INPUT_CursorToRight(); 47 | 48 | void INPUT_CursorShift(int16_t shift); 49 | 50 | #endif // _CLI_INPUT_H_ 51 | -------------------------------------------------------------------------------- /module/cli_log.c: -------------------------------------------------------------------------------- 1 | #include "cli_log.h" 2 | 3 | #include "../lib/cli_string.h" 4 | 5 | extern uint8_t _strcmp(const char* str1, const char* str2); 6 | 7 | struct{ 8 | char cmds[TERM_CMD_LOG_SIZE][TERM_CMD_BUF_SIZE]; 9 | int8_t _curCmd; 10 | int8_t _cntCmd; 11 | }TermLog; 12 | 13 | void CLI_LogInit() 14 | { 15 | TermLog._cntCmd = 0; 16 | CLI_CurReset(); 17 | 18 | for(uint8_t i = 0; i < TERM_CMD_LOG_SIZE; i++) 19 | { 20 | TermLog.cmds[i][0] = '\0'; 21 | } 22 | } 23 | 24 | void CLI_LogCmdPush(const char* cmd) 25 | { 26 | if (TermLog._cntCmd < TERM_CMD_LOG_SIZE) 27 | { 28 | if (TermLog._cntCmd > 0) 29 | { 30 | if (_strcmp(cmd, (const char*) TermLog.cmds[TermLog._cntCmd-1]) == 0) 31 | { 32 | cli_memcpy(TermLog.cmds[TermLog._cntCmd], cmd, TERM_CMD_BUF_SIZE); 33 | TermLog._cntCmd++; 34 | } 35 | } 36 | else 37 | { 38 | cli_memcpy(TermLog.cmds[TermLog._cntCmd], cmd, TERM_CMD_BUF_SIZE); 39 | TermLog._cntCmd++; 40 | } 41 | } 42 | else 43 | { 44 | if (_strcmp(cmd, (const char*) TermLog.cmds[TermLog._cntCmd-1]) == 0) 45 | { 46 | cli_memcpy(&TermLog.cmds[0][0], &TermLog.cmds[1][0], TERM_CMD_BUF_SIZE*(TERM_CMD_LOG_SIZE - 1)); 47 | cli_memcpy(&TermLog.cmds[TermLog._cntCmd-1][0], cmd, TERM_CMD_BUF_SIZE); 48 | TermLog._cntCmd = TERM_CMD_LOG_SIZE; 49 | } 50 | } 51 | } 52 | 53 | const char* CLI_LogCmdGet(uint8_t index) 54 | { 55 | if (index < TERM_CMD_LOG_SIZE) 56 | { 57 | return &TermLog.cmds[index][0]; 58 | } 59 | 60 | return NULL; 61 | } 62 | 63 | const char* CLI_GetNextCmd() 64 | { 65 | if (TermLog._curCmd < TermLog._cntCmd - 1) 66 | { 67 | TermLog._curCmd++; 68 | return &TermLog.cmds[TermLog._curCmd][0]; 69 | } 70 | 71 | return NULL; 72 | } 73 | 74 | const char* CLI_GetLastCmd() 75 | { 76 | if (TermLog._curCmd > 0) 77 | { 78 | TermLog._curCmd--; 79 | return &TermLog.cmds[TermLog._curCmd][0]; 80 | } 81 | 82 | return NULL; 83 | } 84 | 85 | void CLI_CurReset() 86 | { 87 | TermLog._curCmd = TermLog._cntCmd; 88 | } 89 | -------------------------------------------------------------------------------- /module/cli_log.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMINAL_LOG_H_ 2 | #define _TERMINAL_LOG_H_ 3 | 4 | #include "terminal_config.h" 5 | 6 | #include 7 | #include 8 | #include "../lib/cli_queue.h" 9 | 10 | void CLI_LogInit(); 11 | 12 | void CLI_LogCmdPush(const char* cmd); 13 | const char* CLI_LogCmdGet(uint8_t index); 14 | 15 | const char* CLI_GetNextCmd(); 16 | const char* CLI_GetLastCmd(); 17 | 18 | void CLI_CurReset(); 19 | 20 | #endif // _TERMINAL_LOG_H_ 21 | -------------------------------------------------------------------------------- /module/cli_time.c: -------------------------------------------------------------------------------- 1 | #include "cli_time.h" 2 | 3 | uint32_t _def_time_ms; 4 | 5 | /// \brief Generate CLI_Time_s struct from milliseconds 6 | CLI_Time_s CLI_GetFormatTimeByMs(uint32_t msec) 7 | { 8 | CLI_Time_s res; 9 | res.msec = msec % 1000; 10 | uint32_t s = msec / 1000; 11 | res.second = s % 60; 12 | uint32_t m = s / 60; 13 | res.minute = m % 60; 14 | uint32_t h = s / 3600; 15 | res.hour = h; 16 | 17 | return res; 18 | } 19 | 20 | inline void CLI_SetBaseTimeFromMs(uint32_t ms) 21 | { 22 | _def_time_ms = ms; 23 | } 24 | 25 | inline void CLI_SetBaseTimeFromHMS(uint32_t h, uint32_t m, uint32_t s) 26 | { 27 | _def_time_ms = h * 3600000 + m * 60000 + s * 1000; 28 | } 29 | 30 | inline CLI_Time_s CLI_GetFormatLastTimeByMs(uint32_t msec) 31 | { 32 | return CLI_GetFormatTimeByMs(msec + _def_time_ms); 33 | } 34 | 35 | void CLI_DelayMs(uint32_t ms) 36 | { 37 | uint32_t startMs = CLI_GetMs(); 38 | while(((uint32_t)CLI_GetMs() - startMs) < (ms)) {} 39 | } 40 | 41 | void CLI_DelayUs(uint32_t us) 42 | { 43 | uint32_t startUs = CLI_GetUs(); 44 | while(((uint32_t)CLI_GetUs() - startUs) < (us)) {} 45 | } 46 | -------------------------------------------------------------------------------- /module/cli_time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMINAL_TIME_H_ 2 | #define _TERMINAL_TIME_H_ 3 | 4 | #include "terminal_config.h" 5 | 6 | #define CLI_GetMs() ((float) CLI_GetUs() / 1000) // System time in ms 7 | 8 | void CLI_DelayMs(uint32_t ms); 9 | void CLI_DelayUs(uint32_t us); 10 | 11 | typedef struct{ 12 | uint32_t hour; 13 | uint8_t minute; 14 | uint8_t second; 15 | uint16_t msec; 16 | }CLI_Time_s; 17 | 18 | void CLI_SetBaseTimeFromMs(uint32_t ms); 19 | void CLI_SetBaseTimeFromHMS(uint32_t h, uint32_t m, uint32_t s); 20 | 21 | CLI_Time_s CLI_GetFormatTimeByMs(uint32_t msec); 22 | CLI_Time_s CLI_GetFormatLastTimeByMs(uint32_t msec); 23 | 24 | #endif // _TERMINAL_TIME_H_ 25 | -------------------------------------------------------------------------------- /terminal.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JingoC/terminal/127042551415b8ca25d52133211d1123be563e2c/terminal.c -------------------------------------------------------------------------------- /terminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMINAL_H 2 | #define _TERMINAL_H 3 | 4 | #include "terminal_config.h" 5 | 6 | /// \brief Terminal Error Result Execute 7 | typedef enum{ TE_OK = 0, TE_Err, TE_NotFound, TE_ArgErr, TE_ExecErr, TE_WorkInt, }TE_Result_e; 8 | 9 | /// \brief Terminal Add Command Result 10 | typedef enum{ TA_OK = 0, TA_MaxCmd, TA_FcnNull, TA_EmptyName, TA_RetryName, }TA_Result_e; 11 | 12 | /// \brief Terminal Char Append Result 13 | typedef enum{ TC_OK = 0, TC_Enter, TC_BufFull, TC_Reset, TC_Ignore,}TC_Result_e; 14 | 15 | /// \brief Terminal Default Init Command 16 | typedef enum{ 17 | TDC_None = 0x0000, 18 | TDC_Time = 0x0001, 19 | TDC_CPU = 0x0002, 20 | TDC_All = 0xFFFF 21 | }TypeDefaultCmd_e; 22 | 23 | /// \brief Terminal Mode Execute Command 24 | typedef enum{ 25 | TMC_None = 0x0000, 26 | TMC_PrintStartTime = 0x0001, 27 | TMC_PrintStopTime = 0x0002, 28 | TMC_PrintDiffTime = 0x0004, 29 | TMC_All = 0xFFFF, 30 | }TypeModeCmd_e; 31 | 32 | bool CLI_GetIntState(); 33 | #define CLI_CheckAbort() { if (CLI_GetIntState()){return TE_WorkInt;}} 34 | 35 | void CLI_Init(TypeDefaultCmd_e defCmd); 36 | TA_Result_e CLI_AddCmd(const char* name, 37 | uint8_t (*fcn)(), 38 | uint8_t argc, 39 | uint16_t mode, 40 | const char* descr); 41 | 42 | TC_Result_e CLI_EnterChar(char c); 43 | bool CLI_Execute(); 44 | 45 | bool CLI_IsArgFlag(const char* flag); 46 | 47 | bool CLI_GetArgDecByFlag(const char* flag, uint32_t* outValue); 48 | bool CLI_GetArgHexByFlag(const char* flag, uint32_t* outValue); 49 | 50 | uint32_t CLI_GetArgDec(uint8_t index); 51 | uint32_t CLI_GetArgHex(uint8_t index); 52 | 53 | #endif // _TERMINAL_H 54 | --------------------------------------------------------------------------------