5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include "shell.h"
21 |
22 | int shell_str_len(char *str)
23 | {
24 | int i = 0;
25 |
26 | while(str[i++] != 0);
27 |
28 | return i - 1;
29 | }
30 |
31 | int shell_str_cmp(char *str1, char *str2, int len1, int len2)
32 | {
33 | int i;
34 |
35 | if(len1 > len2) return 1;
36 |
37 | for(i = 0; i < len1; i++) {
38 | if(str1[i] != str2[i]) return 2;
39 | }
40 |
41 | // make sure we matched a whole command, and not only
42 | // a containing substring ...
43 | if(len2 > len1 && str2[i] != ' ') {
44 | return 2;
45 | }
46 |
47 | return 0;
48 | }
49 |
50 | int shell_parse_int(char *str)
51 | {
52 |
53 | int val = 0;
54 | int i = 0;
55 |
56 | char c;
57 |
58 | while((c = str[i++]) != 0) {
59 |
60 | if(c < '0' || c > '9') break;
61 |
62 | val = val * 10 + (c - '0');
63 | }
64 |
65 | return val;
66 | }
67 |
68 | int shell_arg_parser(char *cmd_line, int len, shell_cmd_args *args)
69 | {
70 | int i;
71 | int j;
72 | int spos = 0;
73 | int argc = 0;
74 |
75 | for(i = 0; i < len; i++) {
76 | // to many arguments
77 | if(argc > SHELL_MAX_ARGS) return 1;
78 |
79 | if(cmd_line[i] == ' ' || i == len - 1) {
80 | // catch last argument ...
81 | if(i == len - 1) i++;
82 |
83 | // ignore first since it is the cmd itself
84 | if(spos == 0) {
85 | spos = i;
86 | } else {
87 | // argument value to long
88 | if(i - spos > SHELL_MAX_ARG_LEN) return 2;
89 |
90 | for(j = 0; j < i - spos - 1; j++) {
91 | args->args[argc].val[j] = cmd_line[spos + 1 + j];
92 | }
93 | args->args[argc++].val[j] = 0;
94 | spos = i;
95 | }
96 | }
97 | }
98 |
99 | args->count = argc;
100 |
101 | return 0;
102 | }
103 |
104 | int shell_process_cmds(shell_cmds *cmds, char *cmd_line)
105 | {
106 | int i;
107 | int ret;
108 | int cmd_len;
109 | int cmd_line_len;
110 |
111 | shell_cmd_args args;
112 |
113 | for(i = 0; i < cmds->count; i++) {
114 |
115 | cmd_line_len = shell_str_len(cmd_line);
116 | cmd_len = shell_str_len((char *)(cmds->cmds[i].cmd));
117 |
118 | if(shell_str_cmp((char *)(cmds->cmds[i].cmd), cmd_line, cmd_len, cmd_line_len) == 0) {
119 | ret = shell_arg_parser(cmd_line, cmd_line_len, &args);
120 |
121 | if(ret == 1)
122 | return SHELL_PROCESS_ERR_ARGS_MAX;
123 | if(ret == 2)
124 | return SHELL_PROCESS_ERR_ARGS_LEN;
125 |
126 | return (cmds->cmds[i].func)(&args);
127 | }
128 | }
129 |
130 | return SHELL_PROCESS_ERR_CMD_UNKN;
131 | }
132 |
--------------------------------------------------------------------------------
/website/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
89 |
95 |
96 |
97 |
98 |
NB Hardware Demo
99 |
102 |
103 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/android/UDP_Simulation/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
20 |
25 |
26 |
31 |
36 |
41 |
45 |
46 |
47 |
48 |
53 |
58 |
59 |
64 |
65 |
66 |
67 |
74 |
75 |
76 |
80 |
81 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/stm32/StdPeriph/Objects/usbd_stm32f10x.d:
--------------------------------------------------------------------------------
1 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\RTE_Driver\USBD_STM32F10x.c
2 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\ARMCC\Bin\..\include\stdint.h
3 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\ARMCC\Bin\..\include\string.h
4 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\CMSIS\RTOS2\FreeRTOS\Include1\cmsis_os.h
5 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\RTOS2\Include\cmsis_os2.h
6 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\ARMCC\Bin\..\include\stddef.h
7 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\include\FreeRTOS.h
8 | .\objects\usbd_stm32f10x.o: .\RTE\RTOS\FreeRTOSConfig.h
9 | .\objects\usbd_stm32f10x.o: .\RTE\_Target\RTE_Components.h
10 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\Include\stm32f10x.h
11 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Include\core_cm3.h
12 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Include\cmsis_version.h
13 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Include\cmsis_compiler.h
14 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Include\cmsis_armcc.h
15 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\Include\system_stm32f10x.h
16 | .\objects\usbd_stm32f10x.o: .\RTE\Device\STM32F103ZE\stm32f10x_conf.h
17 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\StdPeriph_Driver\inc\stm32f10x_exti.h
18 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\Include\stm32f10x.h
19 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\StdPeriph_Driver\inc\stm32f10x_gpio.h
20 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\StdPeriph_Driver\inc\stm32f10x_rcc.h
21 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\StdPeriph_Driver\inc\stm32f10x_usart.h
22 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\Device\StdPeriph_Driver\inc\misc.h
23 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\RTOS2\Include\os_tick.h
24 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\CMSIS\RTOS2\FreeRTOS\Include\freertos_evr.h
25 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\include\projdefs.h
26 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\include\portable.h
27 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\include\deprecated_definitions.h
28 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\portable\RVDS\ARM_CM3\portmacro.h
29 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS-FreeRTOS\9.1.0\Source\include\mpu_wrappers.h
30 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\RTE_Driver\GPIO_STM32F10x.h
31 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\ARMCC\Bin\..\include\stdbool.h
32 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\Keil\STM32F1xx_DFP\2.2.0\RTE_Driver\USBD_STM32F10x.h
33 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Driver\Include\Driver_USBD.h
34 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Driver\Include\Driver_USB.h
35 | .\objects\usbd_stm32f10x.o: D:\Software\keil\install\ARM\PACK\ARM\CMSIS\5.1.0\CMSIS\Driver\Include\Driver_Common.h
36 | .\objects\usbd_stm32f10x.o: .\RTE\Device\STM32F103ZE\RTE_Device.h
37 |
--------------------------------------------------------------------------------
/stm32/StdPeriph/RTE/Device/STM32F103ZE/stm32f10x_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-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 __STM32F10x_CONF_H
24 | #define __STM32F10x_CONF_H
25 |
26 | /* Run Time Environment will set specific #define for each selected module below */
27 | #include "RTE_Components.h"
28 |
29 | #ifdef RTE_DEVICE_STDPERIPH_ADC
30 | #include "stm32f10x_adc.h"
31 | #endif
32 | #ifdef RTE_DEVICE_STDPERIPH_BKP
33 | #include "stm32f10x_bkp.h"
34 | #endif
35 | #ifdef RTE_DEVICE_STDPERIPH_CAN
36 | #include "stm32f10x_can.h"
37 | #endif
38 | #ifdef RTE_DEVICE_STDPERIPH_CEC
39 | #include "stm32f10x_cec.h"
40 | #endif
41 | #ifdef RTE_DEVICE_STDPERIPH_CRC
42 | #include "stm32f10x_crc.h"
43 | #endif
44 | #ifdef RTE_DEVICE_STDPERIPH_DAC
45 | #include "stm32f10x_dac.h"
46 | #endif
47 | #ifdef RTE_DEVICE_STDPERIPH_DBGMCU
48 | #include "stm32f10x_dbgmcu.h"
49 | #endif
50 | #ifdef RTE_DEVICE_STDPERIPH_DMA
51 | #include "stm32f10x_dma.h"
52 | #endif
53 | #ifdef RTE_DEVICE_STDPERIPH_EXTI
54 | #include "stm32f10x_exti.h"
55 | #endif
56 | #ifdef RTE_DEVICE_STDPERIPH_FLASH
57 | #include "stm32f10x_flash.h"
58 | #endif
59 | #ifdef RTE_DEVICE_STDPERIPH_FSMC
60 | #include "stm32f10x_fsmc.h"
61 | #endif
62 | #ifdef RTE_DEVICE_STDPERIPH_GPIO
63 | #include "stm32f10x_gpio.h"
64 | #endif
65 | #ifdef RTE_DEVICE_STDPERIPH_I2C
66 | #include "stm32f10x_i2c.h"
67 | #endif
68 | #ifdef RTE_DEVICE_STDPERIPH_IWDG
69 | #include "stm32f10x_iwdg.h"
70 | #endif
71 | #ifdef RTE_DEVICE_STDPERIPH_PWR
72 | #include "stm32f10x_pwr.h"
73 | #endif
74 | #ifdef RTE_DEVICE_STDPERIPH_RCC
75 | #include "stm32f10x_rcc.h"
76 | #endif
77 | #ifdef RTE_DEVICE_STDPERIPH_RTC
78 | #include "stm32f10x_rtc.h"
79 | #endif
80 | #ifdef RTE_DEVICE_STDPERIPH_SDIO
81 | #include "stm32f10x_sdio.h"
82 | #endif
83 | #ifdef RTE_DEVICE_STDPERIPH_SPI
84 | #include "stm32f10x_spi.h"
85 | #endif
86 | #ifdef RTE_DEVICE_STDPERIPH_TIM
87 | #include "stm32f10x_tim.h"
88 | #endif
89 | #ifdef RTE_DEVICE_STDPERIPH_USART
90 | #include "stm32f10x_usart.h"
91 | #endif
92 | #ifdef RTE_DEVICE_STDPERIPH_WWDG
93 | #include "stm32f10x_wwdg.h"
94 | #endif
95 | #ifdef RTE_DEVICE_STDPERIPH_FRAMEWORK
96 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
97 | #endif
98 |
99 | /* Exported types ------------------------------------------------------------*/
100 | /* Exported constants --------------------------------------------------------*/
101 | /* Uncomment the line below to expanse the "assert_param" macro in the
102 | Standard Peripheral Library drivers code */
103 | /* #define USE_FULL_ASSERT 1 */
104 |
105 | /* Exported macro ------------------------------------------------------------*/
106 | #ifdef USE_FULL_ASSERT
107 |
108 | /**
109 | * @brief The assert_param macro is used for function's parameters check.
110 | * @param expr: If expr is false, it calls assert_failed function which reports
111 | * the name of the source file and the source line number of the call
112 | * that failed. If expr is true, it returns no value.
113 | * @retval None
114 | */
115 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
116 | /* Exported functions ------------------------------------------------------- */
117 | void assert_failed(uint8_t* file, uint32_t line);
118 | #else
119 | #define assert_param(expr) ((void)0)
120 | #endif /* USE_FULL_ASSERT */
121 |
122 | #endif /* __STM32F10x_CONF_H */
123 |
124 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
125 |
--------------------------------------------------------------------------------
/stm32/StdPeriph/main.c:
--------------------------------------------------------------------------------
1 | #include "zengjf.h"
2 |
3 | osSemaphoreId_t sid_Thread_Semaphore;
4 | int count = 50;
5 | extern char* welcome_msg;
6 | char iot_send_buf[128] = {0};
7 | char iot_recev_buf[128] = {0};
8 |
9 | /* USART Driver */
10 | extern ARM_DRIVER_USART Driver_USART2;
11 |
12 | void myUSART_callback(uint32_t event) {
13 | uint32_t mask;
14 | mask = ARM_USART_EVENT_RECEIVE_COMPLETE |
15 | ARM_USART_EVENT_TRANSFER_COMPLETE |
16 | ARM_USART_EVENT_SEND_COMPLETE |
17 | ARM_USART_EVENT_TX_COMPLETE ;
18 | if (event & mask) {
19 | /* Success: Wakeup Thread */
20 | memset(iot_send_buf, 0, 128);
21 | }
22 | if (event & ARM_USART_EVENT_RX_TIMEOUT) {
23 | __breakpoint(0); /* Error: Call debugger or replace with custom error handling */
24 | }
25 | if (event & (ARM_USART_EVENT_RX_OVERFLOW | ARM_USART_EVENT_TX_UNDERFLOW)) {
26 | __breakpoint(0); /* Error: Call debugger or replace with custom error handling */
27 | }
28 | }
29 | static ARM_DRIVER_USART * USART2drv = &Driver_USART2;
30 |
31 | void vTaskLedRed(void *p)
32 | {
33 | for (;;)
34 | {
35 | led_toggle(GPIOE, GPIO_Pin_6);
36 | Delay(0x1FFFFF);
37 | }
38 | }
39 |
40 | void vTaskEXTILed(void *p)
41 | {
42 | USART2drv->Send("AT+NSOCR=DGRAM,17,4587,1\r\n", strlen("AT+NSOCR=DGRAM,17,4587,1\r\n"));
43 | printf("vTaskEXTILed.\r\n");
44 | for (;;)
45 | {
46 | osSemaphoreAcquire (sid_Thread_Semaphore, osWaitForever);
47 | led_toggle(GPIOE, GPIO_Pin_5);
48 | printf("EXTI Count Value: %d\r\n", count);
49 |
50 | strcpy(iot_send_buf, "AT+NSOST=0,120.24.184.124,8010,8,176A9B108A23");
51 | iot_send_buf[strlen(iot_send_buf)] = 3 + 0x30;
52 | iot_send_buf[strlen(iot_send_buf)] = (count / 10) + 0x30;
53 | iot_send_buf[strlen(iot_send_buf)] = 3 + 0x30;
54 | iot_send_buf[strlen(iot_send_buf)] = (count % 10) + 0x30;
55 | iot_send_buf[strlen(iot_send_buf)] = '\r';
56 | iot_send_buf[strlen(iot_send_buf)] = '\n';
57 | USART2drv->Send(iot_send_buf, strlen(iot_send_buf));
58 |
59 | // USART2drv->Send("AT+NSOST=0,120.24.184.124,8010,12,176A9B108A23303132333435\r\n", strlen("AT+NSOST=0,120.24.184.124,8010,12,176A9B108A23303132333435\r\n"));
60 | }
61 | }
62 |
63 | void vTaskDebugPort(void *p)
64 | {
65 | printf("%s", welcome_msg);
66 | printf("AplexOS # ");
67 | for (;;)
68 | {
69 | get_cmd_parser_char();
70 | led_toggle(GPIOE, GPIO_Pin_5);
71 | }
72 | }
73 |
74 | void vTaskI2C0(void *p)
75 | {
76 | i2c_data_transmission();
77 | }
78 |
79 |
80 | int main(void)
81 | {
82 | USART1_Config(115200);
83 | LED_GPIO_Config();
84 | EXTI_Config();
85 |
86 | /*Initialize the USART driver */
87 | USART2drv->Initialize(myUSART_callback);
88 | /*Power up the USART peripheral */
89 | USART2drv->PowerControl(ARM_POWER_FULL);
90 | /*Configure the USART to 115200 Bits/sec */
91 | USART2drv->Control(ARM_USART_MODE_ASYNCHRONOUS |
92 | ARM_USART_DATA_BITS_8 |
93 | ARM_USART_PARITY_NONE |
94 | ARM_USART_STOP_BITS_1 |
95 | ARM_USART_FLOW_CONTROL_NONE, 9600);
96 |
97 | /* Enable Receiver and Transmitter lines */
98 | USART2drv->Control (ARM_USART_CONTROL_TX, 1);
99 | USART2drv->Control (ARM_USART_CONTROL_RX, 1);
100 |
101 | // char* sendstr = "\r\nPress Enter to receive a message";
102 | // USART2drv->Send(sendstr, strlen(sendstr));
103 |
104 | // System Initialization
105 | SystemCoreClockUpdate();
106 | #ifdef RTE_Compiler_EventRecorder
107 | // Initialize and start Event Recorder
108 | EventRecorderInitialize(EventRecordError, 1U);
109 | #endif
110 |
111 | osKernelInitialize(); // Initialize CMSIS-RTOS
112 |
113 | osThreadNew(vTaskLedRed, NULL, NULL); // Create application thread
114 | osThreadNew(vTaskDebugPort, NULL, NULL); // Create application thread
115 | // osThreadNew(vTaskI2C0, NULL, NULL); // Create application thread
116 |
117 | // osThreadNew(vTaskSPI1, NULL, NULL); // Create application thread
118 |
119 | sid_Thread_Semaphore = osSemaphoreNew(1, 0, NULL);
120 | if (!sid_Thread_Semaphore) {
121 | printf("get sid_Thread_Semaphore error.\r\n"); // Semaphore object not created, handle failure
122 | }
123 | osThreadNew(vTaskEXTILed, NULL, NULL); // Create application thread
124 |
125 | osKernelStart(); // Start thread execution
126 | }
127 |
--------------------------------------------------------------------------------
/stm32/StdPeriph/zengjf/stm32f10x_it.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c
4 | * @author MCD Application Team
5 | * @version V3.5.0
6 | * @date 08-April-2011
7 | * @brief Main Interrupt Service Routines.
8 | * This file provides template for all exceptions handler and
9 | * peripherals interrupt service routine.
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
15 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
16 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
17 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
18 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 | *
20 | * © COPYRIGHT 2011 STMicroelectronics
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "zengjf.h"
26 |
27 | /** @addtogroup STM32F10x_StdPeriph_Template
28 | * @{
29 | */
30 |
31 | /* Private typedef -----------------------------------------------------------*/
32 | /* Private define ------------------------------------------------------------*/
33 | /* Private macro -------------------------------------------------------------*/
34 | /* Private variables ---------------------------------------------------------*/
35 | /* Private function prototypes -----------------------------------------------*/
36 | /* Private functions ---------------------------------------------------------*/
37 |
38 | /******************************************************************************/
39 | /* Cortex-M3 Processor Exceptions Handlers */
40 | /******************************************************************************/
41 |
42 | /**
43 | * @brief This function handles NMI exception.
44 | * @param None
45 | * @retval None
46 | */
47 | void NMI_Handler(void)
48 | {
49 | }
50 |
51 | /**
52 | * @brief This function handles Hard Fault exception.
53 | * @param None
54 | * @retval None
55 | */
56 | void HardFault_Handler(void)
57 | {
58 | /* Go to infinite loop when Hard Fault exception occurs */
59 | while (1)
60 | {
61 | }
62 | }
63 |
64 | /**
65 | * @brief This function handles Memory Manage exception.
66 | * @param None
67 | * @retval None
68 | */
69 | void MemManage_Handler(void)
70 | {
71 | /* Go to infinite loop when Memory Manage exception occurs */
72 | while (1)
73 | {
74 | }
75 | }
76 |
77 | /**
78 | * @brief This function handles Bus Fault exception.
79 | * @param None
80 | * @retval None
81 | */
82 | void BusFault_Handler(void)
83 | {
84 | /* Go to infinite loop when Bus Fault exception occurs */
85 | while (1)
86 | {
87 | }
88 | }
89 |
90 | /**
91 | * @brief This function handles Usage Fault exception.
92 | * @param None
93 | * @retval None
94 | */
95 | void UsageFault_Handler(void)
96 | {
97 | /* Go to infinite loop when Usage Fault exception occurs */
98 | while (1)
99 | {
100 | }
101 | }
102 |
103 | /**
104 | * @brief This function handles Debug Monitor exception.
105 | * @param None
106 | * @retval None
107 | */
108 | void DebugMon_Handler(void)
109 | {
110 | }
111 |
112 | /******************************************************************************/
113 | /* STM32F10x Peripherals Interrupt Handlers */
114 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
115 | /* available peripheral interrupt handler's name please refer to the startup */
116 | /* file (startup_stm32f10x_xx.s). */
117 | /******************************************************************************/
118 |
119 | /**
120 | * @brief This function handles PPP interrupt request.
121 | * @param None
122 | * @retval None
123 | */
124 | /*void PPP_IRQHandler(void)
125 | {
126 | }*/
127 |
128 | /**
129 | * @}
130 | */
131 |
132 |
133 | extern osSemaphoreId_t sid_Thread_Semaphore;
134 | extern int count;
135 |
136 | void EXTI0_IRQHandler(void)
137 | {
138 | osSemaphoreRelease (sid_Thread_Semaphore);
139 | if (--count < 0)
140 | count = 0;
141 |
142 | EXTI_ClearITPendingBit(EXTI_Line0);
143 | }
144 |
145 | void EXTI4_IRQHandler(void)
146 | {
147 | osSemaphoreRelease (sid_Thread_Semaphore);
148 | if (++count > 99)
149 | count = 99;
150 |
151 | EXTI_ClearITPendingBit(EXTI_Line4);
152 | }
153 |
154 |
155 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
156 |
--------------------------------------------------------------------------------
/stm32/StdPeriph/zengjf/include/shell.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the libemb project.
3 | *
4 | * Copyright (C) 2011 Stefan Wendler
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef __SHELL_H_
21 | #define __SHELL_H_
22 |
23 | /**
24 | * max number of character for a command line passed to the shell
25 | */
26 | #define SHELL_MAX_CMD_LINE 90
27 |
28 | /**
29 | * max number of arguments passed with one command to the shell
30 | */
31 | #define SHELL_MAX_ARGS 5
32 |
33 | /**
34 | * max number of character for a single argument form a command line passed to the shell
35 | */
36 | #define SHELL_MAX_ARG_LEN 15
37 |
38 | /**
39 | * return code given when processing of a command line was OK
40 | */
41 | #define SHELL_PROCESS_OK 0
42 |
43 | /**
44 | * ERROR maximum number of arguments was reached
45 | */
46 | #define SHELL_PROCESS_ERR_ARGS_MAX 0xfff0
47 |
48 | /**
49 | * ERROR maximum number of chars for an argument was reached
50 | */
51 | #define SHELL_PROCESS_ERR_ARGS_LEN 0xfff1
52 |
53 | /**
54 | * ERROR unknown command
55 | */
56 | #define SHELL_PROCESS_ERR_CMD_UNKN 0xfff2
57 |
58 | /**
59 | * Single command argument
60 | */
61 | typedef struct {
62 | /**
63 | * Value representing the argument
64 | */
65 | char val[SHELL_MAX_ARG_LEN];
66 | } shell_cmd_arg;
67 |
68 | /**
69 | * All arguments from a single command line
70 | */
71 | typedef struct {
72 | /**
73 | * Number of arguments
74 | */
75 | unsigned char count;
76 |
77 | /**
78 | * The arguments
79 | */
80 | shell_cmd_arg args[SHELL_MAX_ARGS];
81 | } shell_cmd_args;
82 |
83 | /**
84 | * Definition of a single shell command
85 | */
86 | typedef struct {
87 | /**
88 | * Name of the command
89 | */
90 | const char *cmd;
91 |
92 | /**
93 | * Description of the command
94 | */
95 | const char *desc;
96 |
97 | /**
98 | * Functino called when executing the commmand
99 | */
100 | int (*func)(shell_cmd_args *args);
101 | } shell_cmd;
102 |
103 | /**
104 | * All shell commands knwon by the shell
105 | */
106 | typedef struct {
107 | /**
108 | * Number of commands
109 | */
110 | unsigned char count;
111 |
112 | /**
113 | * The commands
114 | */
115 | shell_cmd cmds[];
116 | } shell_cmds;
117 |
118 | /**
119 | * Return the length of a given string.
120 | *
121 | * @param[in] str string for which to calculate the length
122 | * @return length of str
123 | */
124 | int shell_str_len(char *str);
125 |
126 | /**
127 | * Comapre str1 with given length len1 to str2 with given length len2.
128 | *
129 | * @param[in] str1 first string
130 | * @param[in] str2 second string
131 | * @param[in] len1 length of first string
132 | * @param[in] len2 length of second string
133 | * @return 0 if str1 euqals str2, 1 if len1 != len2, 2 if str1 != str2
134 | */
135 | int shell_str_cmp(char *str1, char *str2, int len1, int len2);
136 |
137 | /**
138 | * Parse the integer value from str and return it.
139 | *
140 | * @param[in] str from which to parse the integer value.
141 | * @return the integer value of str
142 | */
143 | int shell_parse_int(char *str);
144 |
145 | /**
146 | * Process a command line string given in cmd_line against the
147 | * commands given by cmds. If the command form cmd_line matches
148 | * against a command string defined in cmds, the function callback
149 | * for that command is executet.
150 | *
151 | * Note: the arguments form the command line are passed to the command
152 | * function, but the command function is responsible for checkeing the arguemts.
153 | *
154 | * @param[in] *cmds pointer to shell commands structure
155 | * @param[in] *cmd_line pointer to command line string
156 | * @return SHELL_PROCESS_OK if command and arguments where understood,
157 | * SHELL_PROCESS_ERR_ARGS_MAX if to many arguments are given,
158 | * SHELL_PROCESS_ERR_ARGS_LEN if an argument string was too long,
159 | * SHELL_PROCESS_ERR_CMD_UNK if the command was unknown
160 | */
161 | int shell_process_cmds(shell_cmds *cmds, char *cmd_line);
162 |
163 | /**
164 | * Process a command line. For details see {@link shell_process_cmds}.
165 | * This method has to be implemented by a specific shell. The implementation
166 | * must pass a valid {@link shell_cmds} struct to {@link shell_process_cmds}.
167 | *
168 | * @param[in] *cmd_line see {@link shell_process_cmds}
169 | * @return see {@link shell_process_cmds}
170 | */
171 | int shell_process(char *cmd_line);
172 |
173 | #endif
174 |
--------------------------------------------------------------------------------