Phát triển hệ điều hành thời gian thực trên chip arm ứng dụng trong hệ thống lưu trữ thông minh

129 17 0
Phát triển hệ điều hành thời gian thực trên chip arm ứng dụng trong hệ thống lưu trữ thông minh

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI LUẬN VĂN THẠC SĨ Phát triển hệ điều hành thời gian thực chip ARM ứng dụng hệ thống lưu trữ thông minh ĐẶNG VĂN KHỞI Khoi.DVCB180120@sis.hust.edu.vn Ngành Kỹ thuật điều khiển tự động hóa Giảng viên hướng dẫn: PGS.TS Nguyễn Quang Địch Viện: Điện HÀ NỘI, 2020 TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI LUẬN VĂN THẠC SĨ Phát triển hệ điều hành thời gian thực chip ARM ứng dụng hệ thống lưu trữ thông minh ĐẶNG VĂN KHỞI Khoi.DVCB180120@sis.hust.edu.vn Ngành Kỹ thuật điều khiển tự động hóa Giảng viên hướng dẫn: PGS.TS Nguyễn Quang Địch Chữ ký GVHD Viện: Điện HÀ NỘI, 2020 CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh phúc BẢN XÁC NHẬN CHỈNH SỬA LUẬN VĂN THẠC SĨ Họ tên tác giả luận văn: Đặng Văn Khởi Đề tài luận văn: Phát triển hệ điều hành thời gian thực chip ARM ứng dụng hệ thống lưu trữ thông minh Chuyên ngành: Kỹ thuật điều khiển tự động hóa Mã số HV: CB180120 Tác giả, Người hướng dẫn khoa học Hội đồng chấm luận văn xác nhận tác giả sửa chữa, bổ sung luận văn theo biên họp Hội đồng ngày 30/10/2020 với nội dung sau: Chương 2: - Sửa lại câu từ bất hợp lý luận văn Chương 3: - Loại bỏ phần trình bày lan man Chương 4: - Sửa lại lưu đồ thuật tốn chưa xác - Làm rõ ý nghĩa, nhiệm vụ task Ngày 11 tháng 11 năm 2020 Tác giả luận văn Giáo viên hướng dẫn PGS.TS Nguyễn Quang Địch Đặng Văn Khởi CHỦ TỊCH HỘI ĐỒNG PGS.TS Nguyễn Phạm Thục Anh LỜI CẢM ƠN Trong trình thực luận văn “Phát triển hệ điều hành thời gian thực chip ARM ứng dụng hệ thống lưu trữ thông minh” nhận giúp đỡ tận tình thầy hướng dẫn tập thể cán làm việc Viện Kỹ thuật điều khiển tự động hóa, Đại học Bách Khoa Hà Nội Viện không tạo điều kiện việc hỗ trợ trang thiết bị, vật tư cần thiết đáp ứng định hướng phát triển mà luận văn hướng tới mà cịn tạo mơi trường học tập, nghiên cứu sơi nổi, hiệu chun nghiệp Chính yếu tố góp phần khơng nhỏ để tơi hồn thành luận văn Qua đây, xin gửi lời cám ơn đến Thầy hướng dẫn PGS.TS Nguyễn Quang Địch – Giám đốc viện Kỹ thuật điều khiển tự động hóa, tất cán làm việc Viện Là cán Viện, cảm thấy tự hào làm việc với tập thể đoàn kết có kiến thức chun mơn cao Hà Nội, ngày 11 tháng 11 năm 2020 Tác giả Đặng Văn Khởi MỤC LỤC DANH MỤC HÌNH VẼ I DANH MỤC BẢNG BIỂU III DANH MỤC TỪ VIẾT TẮT IV LỜI NÓI ĐẦU CHƯƠNG TỔNG QUAN VỀ HỆ THỐNG LƯU TRỮ THÔNG MINH 1.1 ĐẶT VẤN ĐỀ 1.2 TỔNG QUAN VỀ HỆ THỐNG LƯU TRỮ TÀI LIỆU 1.2.1 Tổng quan hệ thống lưu trữ tài liệu truyền thống 1.2.2 Tổng quan hệ thống lưu trữ tài liệu thông minh 1.2.3 Đánh giá 1.3 TỔNG QUAN CẤU TRÚC XÂY DỰNG HỆ THỐNG LƯU TRỮ THÔNG MINH 1.3.1 Tổng quan tính hệ thống lưu trữ thông minh 1.3.2 Cấu trúc thiết kế cho hệ thống lưu trữ thông minh 1.4 TỔNG KẾT CHƯƠNG 11 CHƯƠNG CƠ SỞ VÀ CẤU TRÚC THIẾT KẾ PHẦN CỨNG 12 2.1 ĐẶT VẤN ĐỀ 12 2.2 CƠ SỞ THIẾT KẾ MẠCH PHẦN CỨNG 12 2.3 THIẾT KẾ PHẦN CỨNG CHO HỆ THỐNG LƯU TRỮ THÔNG MINH 13 2.3.1 Thiết kế mạch đếm người thu 13 2.3.2 Thiết kế mạch điều khiển động 14 2.3.3 Thiết kế mạch điều khiển trung tâm 17 2.4 TỔNG KẾT CHƯƠNG 23 CHƯƠNG XÂY DỰNG MÔI TRƯỜNG NHÚNG HỆ ĐIỀU HÀNH THỜI GIAN THỰC TRÊN CHIP ARM 24 3.1 PHÂN TÍCH VÀ LỰA CHỌN HƯỚNG TIẾP CẬN 24 3.1.1 Phương pháp lập trình nhúng 24 3.2 CƠ SỞ PHÁT TRIỂN HỆ ĐIỀU HÀNH THỜI GIAN THỰC RTOS 28 3.2.1 Phân loại RTOS 28 3.2.2 Cơ sở lựa chọn Open Source RTOS phù hợp với chip ARM 29 3.3 XÂY DỰNG MÔI TRƯỜNG NHÚNG 34 3.3.1 Định hướng môi trường phát triển code nhúng 34 3.3.2 Xây dựng môi trường nhúng chip ARM 39 3.4 TỔNG KẾT CHƯƠNG 40 CHƯƠNG PHÁT TRIỂN THUẬT TOÁN TRÊN NỀN TẢNG HỆ ĐIỀU HÀNH THỜI GIAN THỰC CHO HỆ THỐNG LƯU TRỮ THÔNG MINH 41 4.1 PHƯƠNG PHÁP TIẾP CẬN 41 4.2 CƠ SỞ XÂY DỰNG THUẬT TOÁN CHO CÁC TASK 42 4.2.1 Cấu trúc thiết kế nhúng mạch điều khiển trung tâm tủ Slave …………………………………………………………………………… 42 4.2.2 Cở sở phát triển thuật toán mạch điều khiển trung tâm tủ Slave 44 4.3 XÂY DỰNG, PHÁT TRIỂN THUẬT TOÁN CHO CÁC TASK 46 4.3.1 Xây dựng task cho mạch điều khiển trung tâm tủ Slave 46 4.3.2 Xây dựng frame truyền nhận liệu task với ngoại vi 48 4.3.3 Phát triển thuật toán cho task 50 4.4 TỔNG KẾT CHƯƠNG 73 CHƯƠNG KẾT QUẢ ĐẠT ĐƯỢC 74 5.1 PHẦN CỨNG 74 5.2 PHẦN MỀM 77 5.3 TỔNG KẾT CHƯƠNG 79 KẾT LUẬN 80 TÀI LIỆU THAM KHẢO 81 PHỤ LỤC 83 DANH MỤC HÌNH VẼ Hình 1.1 Hình ảnh tủ lưu trữ tài liệu truyền thống Hình 1.2 Hình ảnh hệ thống lưu trữ tài liệu thơng minh Hình 1.3 Sơ đồ cấu trúc hệ thống lưu trữ thông minh 10 Hình 2.1 Sơ đồ kết nối mảng mạch tủ Slave Outmost Slave 13 Hình 2.2 Sơ đồ nguyên lý mạch đếm người thu 14 Hình 2.3 Động BLDC 120W có hộp số Driver động 15 Hình 2.4 Sơ đồ nguyên lý mạch điều khiển động BLDC 16 Hình 2.5 Nguồn cấp cho toàn mạch điều khiển trung tâm 19 Hình 2.6 Sơ đồ nguyên lý thiết kế chip ARM, truyền thơng CAN, RS485 dây 20 Hình 2.7 Sơ đồ nguyên lý kết nối với ngoại vi (1) 21 Hình 2.8 Sơ đồ nguyên lý kết nối với ngoại vi (2) 22 Hình 3.1 Pseudo code siêu vòng lặp (Super-loop) 25 Hình 3.2 Thành phần RTOS 26 Hình 3.3 Kiến trúc hệ điều hành thời gian thực FreeRTOS 29 Hình 3.4 Kiến trúc hệ điều hành ChibiOS/RT 31 Hình 3.5 Kiến trúc hệ điều hành thời gian thực TinyOS 32 Hình 3.6 Phát triển code nhúng chip ARM sử dụng IDE 35 Hình 3.7 Hệ điều hành Ubuntu 36 Hình 3.8 Phát triển code nhúng chip ARM khơng dùng IDE 37 Hình 4.1 Sơ đồ nhúng hệ điều hành FreeRTOS chip ARM (Nguồn Hình 3.11) 43 Hình 4.2 Phát triển Task FreeRTOS 45 Hình 4.3 Xây dựng task thực Timer Service Task 45 Hình 4.4 Kỹ thuật “Deferred Interrupt Processing” xử lý tín hiệu ngắt 46 Hình 4.5 Mơ hình task xây dựng cho chip ARM tủ Slave 47 Hình 4.6 Lưu đồ thuật tốn frame giao tiếp với mạch điều khiển động 52 Hình 4.7 Lưu đồ thuật tốn phát triển task "Xử lý truyền thơng Modbus RTU" 53 Hình 4.8 Lưu đồ thuật toán phát triển task "Đọc nhiệt độ, độ ẩm trong" 54 Hình 4.9 Lưu đồ thuật tốn xử lý "Sự kiện cháy trong" 55 Hình 4.10 Lưu đồ thuật tốn xử lý "Sự kiện CAN" 55 i Hình 4.11 Lưu đồ thuật tốn xử lý "Sự kiện USART1" 56 Hình 4.12 Lưu đồ thuật toán xử lý "Sự kiện USART2" 57 Hình 4.13 Lưu đồ thuật tốn xử lý "Sự kiện tài liệu nhơ" 58 Hình 4.14 Lưu đồ thuật tốn phát triển task "Xử lý truyền thông CAN" 60 Hình 4.15 Lưu đồ thuật tốn phát triển task "Dừng khẩn cấp" 61 Hình 4.16 Lưu đồ thuật tốn phát triển task "Xử lý tình cháy trong" 62 Hình 4.17 Lưu đồ thuật tốn phát triển task "Xử lý tình cháy ngồi" 63 Hình 4.18 Lưu đồ thuật tốn phát triển task "Đăng nhập hệ thống" 63 Hình 4.19 Lưu đồ thuật toán phát triển task "Đăng xuất hệ thống" 64 Hình 4.20 Lưu đồ thuật tốn phát triển task "Thơng gió hệ thống" 65 Hình 4.21 Lưu đồ thuật tốn phát triển task "Thơng gió hệ thống" (tiếp) 66 Hình 4.22 Lưu đồ thuật toán phát triển task "Điều khiển tủ xa Master" 67 Hình 4.23 Lưu đồ thuật tốn phát triển task "Điều khiển tủ lại gần Master" 68 Hình 4.24 Lưu đồ thuật tốn task "Đọc liệu từ mạch đếm người thu" 69 Hình 4.25 Lưu đồ thuật toán phát triển task "Tắt hiển thị cảnh báo" 70 Hình 4.26 Lưu đồ thuật toán phát triển task "Hiển thị số người tủ" 70 Hình 4.27 Lưu đồ thuật tốn phát triển task "Hiển thị khoảng cách tủ" 71 Hình 4.28 Lưu đồ thuật tốn phát triển task "Hiển thị nhiệt độ, độ ẩm trong" 72 Hình 4.29 Lưu đồ thuật toán phát triển task "Hiển thị nhiệt độ, độ ẩm ngồi" 72 Hình 4.30 Lưu đồ thuật toán phát triển task "Idle task" 73 Hình 5.1 Hình ảnh mạch điều khiển trung tâm tủ Slave 74 Hình 5.2 Các ngoại vi tủ Slave 75 Hình 5.3 Giao diện đăng nhập hệ thống 76 Hình 5.4 Giao diện hình điều khiển 76 Hình 5.5 Sơ đồ hình phát triển mã nguồn chip ARM cho tủ Slave 77 Hình 5.6 Tạo mơi trường debug chip OpenOCD 78 Hình 5.7 Nhúng mã nguồn (.elf extension) vào GDB Server phục vụ debug code 79 ii DANH MỤC BẢNG BIỂU Bảng 1.1 Bảng so sánh hệ thống lưu trữ truyền thống với hệ thống lưu trữ thông minh Bảng 3.1 Bảng so sánh Open Source RTOS Licensed RTOS 28 Bảng 3.2 Bảng so sánh hệ điều hành thời gian thực 33 Bảng 3.3 Bảng so sánh phát triển code nhúng dùng IDE không dùng IDE 37 Bảng 4.1 Ký hiệu quy ước biến khoảng cách 51 Bảng 4.2 Các trường hợp tủ thực task "Thơng gió hệ thống" 64 Bảng 4.3 Các trường hợp tủ thực task "Đk xa Master" 66 iii DANH MỤC TỪ VIẾT TẮT Viết tắt ADC API ARM Ý nghĩa Ghi Tiếng Anh Analog to Digital Convert Bộ chuyển đổi tương tự sang số Application Programming Giao diện lập trình ứng dụng Interface Application – Real-time – Microcontroller BLDC Brushless Direct Current CAN Controller Area Network CPU Central Processing Unit Bộ xử lý trung tâm CRC Cyclic Redundancy Check Mã check lỗi liệu Direct Current/ Direct Current Bộ chuyển đổi điện áp chiều sang chiều DSP Digital Signal Processor Bộ xử lý tín hiệu số GCC GNU Compiler Collection Trình biên dịch GNU GNU’s Not Unix GDB GNU Debugger Trình gỡ lỗi GUI Graphic User Interface Giao diện đồ họa người dùng HAL Hardware Abstraction Layer Lớp phần cứng trừu tượng HMI Human-Machine Interface Màn hình cơng nghiệp I2C Inter-Integrated Circuit Giao thức truyền tin nối tiếp đồng IC Integrated Circuit Chip IoT Internet of Things Kết nối vạn vật IPC Industrial Pannel PC Máy tính cơng nghiệp ISR Interrupt Service Routine Dịch vụ ngắt MCU Micro-Controller Unit Vi điều khiển MPU Micro-Processor Unit Vi xử lý MPU Memory Protection Unit Đơn vị bảo vệ nhớ nesC Network Embedded System C Ngôn ngữ C cho hệ thống mạng nhúng DC/DC Một chiều không chổi than iv void can_receive_data(uint32_t); END_DECLS #endif /* End of CAN_KD_H */ ✓ can_kd.c /* * File : CAN_KD.C (Source file) * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Desciption: - This file is source code of can_kd library * - This file is written for chip STM32F407xx families * - This file using libopencm3 library package */ #include "can_kd.h" uint8_t sdat[8] = {65, 66, 67, 68, 69, 70, 71, 72}; uint8_t rdat[8]; uint8_t len; uint8_t fmi; uint32_t id; bool ext, rtr; //static void can_enter_init_mode(uint32_t canport); static void can_enter_sleep_mode(uint32_t); static void can_enter_normal_mode(uint32_t); /*static void can_enter_init_mode(uint32_t canport) { CAN_MCR(canport) |= CAN_MCR_INRQ; CAN_MCR(canport) &= ~CAN_MCR_SLEEP; while(!(CAN_MSR(canport) & CAN_MSR_INAK)); }*/ 104 static void can_enter_sleep_mode(uint32_t canport) { CAN_MCR(canport) |= CAN_MCR_SLEEP; CAN_MCR(canport) &= ~CAN_MCR_INRQ; while((CAN_MSR(canport) & CAN_MSR_SLAK)); } static void can_enter_normal_mode(uint32_t canport) { CAN_MCR(canport) &= ~CAN_MCR_INRQ; CAN_MCR(canport) &= ~CAN_MCR_SLEEP; while(CAN_MSR(canport) & CAN_MSR_INAK); } /* Enable clock for PORT that contains CAN_TX and CAN_RX and clock for CAN interface */ void can_init_clock(void) { rcc_periph_clock_enable(CAN_RCC); rcc_periph_clock_enable(CAN_RCC_PORT); //rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CAN1EN); } /* Configure CAN_TX and CAN_RX pins */ void can_setup_gpio(void) { /* Config TX pin */ gpio_mode_setup(CAN_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, CAN_TX); gpio_set_af(CAN_PORT, GPIO_AF9, CAN_TX); /* Config RX pin */ gpio_mode_setup(CAN_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, CAN_RX); gpio_set_af(CAN_PORT, GPIO_AF9, CAN_RX); } /* Enable Interrupts that you need at here */ void can_enable_interrupt(uint32_t canport) { //nvic_enable_irq(CAN_IRQ_TX); nvic_enable_irq(CAN_IRQ_RX0); can_enable_irq(canport, CAN_IER_FMPIE0); } 105 /* Configure CAN Interface in initialization mode and filter type*/ void can_init_mode(uint32_t canport) { can_reset(canport); can_init(canport, TTCM, ABOM, AWUM, NART, RFLM, TXFP, SJW, TS1, TS2, BRP, LBKM, SILM); can_filter_id_list_32bit_init(NR, FR1, FR2, FIFO, ENA); } /* Run CAN in normal mode */ void can_normal_mode(uint32_t canport) { can_enter_normal_mode(canport); } /* Take CAN into sleep mode */ void can_sleep_mode(uint32_t canport) { can_enter_sleep_mode(canport); } /* Transmit data */ void can_transmit_data(uint32_t canport) { int val, yes; val = can_transmit(canport, ID, EXT, RTR, len, sdat); while(val == -1); if(val == 0) { while(!(CAN_TSR(canport) & CAN_TSR_RQCP0)); while(!(CAN_TSR(canport) & CAN_TSR_TXOK0)); while(!(CAN_TSR(canport) & CAN_TSR_TME0)); if(((CAN_TSR(canport) & CAN_TSR_ALST0)) || ((CAN_TSR(canport) & CAN_TSR_TERR0))) { yes = 0; } }else if(val == 1) { while(!(CAN_TSR(canport) & CAN_TSR_RQCP1)); while(!(CAN_TSR(canport) & CAN_TSR_TXOK1)); 106 while(!(CAN_TSR(canport) & CAN_TSR_TME1)); }else if(val == 2) { while(!(CAN_TSR(canport) & CAN_TSR_RQCP2)); while(!(CAN_TSR(canport) & CAN_TSR_TXOK2)); while(!(CAN_TSR(canport) & CAN_TSR_TME2)); } } /* Receive data */ void can_receive_data(uint32_t canport) { can_receive(canport, FIFO, RELEASE, &id, &ext, &rtr, &fmi, &len, rdat, NULL); } /* Interrupt Handler */ /*void can1_rx0_isr(void) { can_receive_data(CAN_INTERFACE); }*/ - Chương trình xây dựng, phát triển task ✓ Task_pre.h (phát triển Preemptive Task) /* * File : TASKS_PRE.H * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * Storage Project ! - This is a header file that is only used for Slave Storage in the Smart * - This file describes prototype of tasks that are constructed in Preemptive mode for Slave */ #ifndef TASKS_PRE_H #define TASKS_PRE_H 107 #include "Tasks_isr.h" #include "Vars_list.h" #include "gpio_kd.h" #include "usart_kd.h" #include #include /* Define Malloc() function if configUSE_MALLOC_FAILED_HOOK is set to */ #if (configUSE_MALLOC_FAILED_HOOK == 1) void vApplicationMallocFailedHook(void); #endif /* Define IdleHook() function if configUSE_IDLE_HOOK is set to */ #if (configUSE_IDLE_HOOK == 1) void vApplicationIdleHook(void); #endif /* Define TickHook() function if configUSE_TICK_HOOK is set to */ #if (configUSE_TICK_HOOK == 1) void vApplicationTickHook(void); // is used from within ISR #endif /* Define StackOverflowHook() function if configCHECK_FOR_STACK_OVERFLOW is set to */ #if (configCHECK_FOR_STACK_OVERFLOW ==1 ) void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName); #endif /* Define IdleTaskMemory() function if configSUPPORT_STATIC_ALLOCATION is set to */ #if (configSUPPORT_STATIC_ALLOCATION == 1) void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize); #endif /* Define TimerTaskMemory() function if configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to */ #if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configUSE_TIMERS == 1)) 108 void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ); #endif /* Define array holds Heap size if configAPPLICATION_ALLOCATED_HEAP is set to */ #if (configAPPLICATION_ALLOCATED_HEAP == 1) extern uint8_t ucHeap[configTOTAL_HEAP_SIZE]; #endif #define PRIORITY_TASK_CAN_HANDLER (UBaseType_t)(configMAX_PRIORITIES - 1) #define PRIORITY_TASK_MODBUS_HANDLER (UBaseType_t)(configMAX_PRIORITIES - 2) #define PRIORITY_TASK_PEO_CNT_HANDLER (UBaseType_t)(configMAX_PRIORITIES - 3) #define PRIORITY_TASK_EMER_STOP_SYS (UBaseType_t)(configMAX_PRIORITIES - 4) #define PRIORITY_TASK_FIRE_IN_HANDLER (UBaseType_t)(configMAX_PRIORITIES - 5) #define PRIORITY_TASK_FIRE_OUT_HANDLER (UBaseType_t)(configMAX_PRIORITIES - 6) #define PRIORITY_TASK_LOGIN_SYSTEM (UBaseType_t)(configMAX_PRIORITIES - 7) #define PRIORITY_TASK_LOGOUT_SYSTEM (UBaseType_t)(configMAX_PRIORITIES - 8) #define PRIORITY_TASK_VENTILATION (UBaseType_t)(configMAX_PRIORITIES - 9) #define PRIORITY_TASK_CHECK_MODE (UBaseType_t)(configMAX_PRIORITIES - 10) #define PRIORITY_TASK_CTRL_FAR_MASTER (UBaseType_t)(configMAX_PRIORITIES - 11) #define PRIORITY_TASK_CTRL_CLOSE_MASTER (UBaseType_t)(configMAX_PRIORITIES - 12) #define PRIORITY_TASK_READ_PEO_IN_DATA (UBaseType_t)(configMAX_PRIORITIES - 13) #define PRIORITY_TASK_TURN_OFF_WARNING (UBaseType_t)(configMAX_PRIORITIES - 15) #define PRIORITY_TASK_DISPLAY_PEO_IN (UBaseType_t)(configMAX_PRIORITIES - 16) #define PRIORITY_TASK_DISPLAY_DISTANCE (UBaseType_t)(configMAX_PRIORITIES - 17) 109 #define PRIORITY_TASK_DISPLAY_TEMP_HUMI_IN (UBaseType_t)(configMAX_PRIORITIES - 18) #define PRIORITY_TASK_DISPLAY_TEMP_HUMI_OUT (UBaseType_t)(configMAX_PRIORITIES - 19) #define PRIORITY_IDLE_TASK tskIDLE_PRIORITY #define BIT_TO_CLEAR_ON_ENTRY (uint32_t) 0x00 #define BIT_TO_CLEAR_ON_EXIT (uint32_t) 0xffffffff /* Define prototype of tasks running in Preemptive mode */ BEGIN_DECLS extern void vTaskCanHandler(void *); // Task handles CAN Protocol extern void vTaskModbusHandler(void *); Protocol // Task handles ModbusRTU extern void vTaskPeoCntHandler(void *); Interface connect with Receiver People Counting Circuit // Task handles UART extern void vTaskEmerStopSys(void *); // Task System Emergency Stop extern void vTaskFireInHandler(void *); // Task handles Fire Inside System extern void vTaskFireOutHandler(void *); // Task handles Fire Outside System extern void vTaskLoginSystem(void *); // Task logins system extern void vTaskLogoutSystem(void *); extern void vTaskVentilation(void *); extern void vTaskCheckMode(void *); and Peripherals in Slave Storage // Task logouts system // Task controls System Ventilation // Task checks entire Sensors extern void vTaskCtrlFarMaster(void *); // Task controls Slave far away Master extern void vTaskCtrlCloseMaster(void *); // Task controls Slave close to Master extern void vTaskReadPeoInData(void *); inside Slave // Task reads data of counting people extern void vTaskTurnOffWarning(void *); // Task turns off all of warnings extern void vTaskDisplaypPeoIn(void *); Slave // Task displays people inside extern void vTaskDisplayDistance(void *); Cabinets // Task displays distance between two extern void vTaskDisplayTempHumiIn(void *); Humidity inside Slave // Task displays Temperature and extern void vTaskDisplayTempHumiOut(void *); Humidity outside System // Task displays Temperature and extern void vIdleTask(void *); // Idle Task END_DECLS 110 #endif /* End of TASKS_PRE_H */ ✓ Task_tst.h (phát triển Timer Service Task) /* * File : TASKS_TST.H * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * Storage Project ! - This is a header file that is only used for Slave Storage in the Smart * - This file describes prototype of tasks that are contructed in Timer Service Task in FreeRTOS */ #ifndef TASKS_TST_H #define TASKS_TST_H #include "Vars_list.h" #include "sht3x.h" #define TIMER_PERIOD 2000 #define AUTO_RELOAD #define QUEUE_LENGTH // 2s with Tick freq = 1000 Hz pdTRUE (UBaseType_t) 10 BEGIN_DECLS void vQueueCreate(void); void vTimerCreate(void); void vTaskReadTempHumiIn(TimerHandle_t); END_DECLS #endif /* End of TASKS_TST_H */ ✓ Var_list.h /* * File : VARS_LIST.H * 111 * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * Storage Project ! - This is a header file that is only used for Slave Storage in the Smart * - This file define variables using in Slave Storage Source Code */ #ifndef VARS_LIST_H #define VARS_LIST_H #include #include "FreeRTOS.h" #include "task.h" #include "timers.h" #include "queue.h" #define TICKS_TO_WAIT /* Declare Variable indicating whether successful timer creating */ extern TimerHandle_t xTimerSuccess; /* Declare Variables to pass a handle to another created task (if needed) */ extern TaskHandle_t xTimerTask; extern TaskHandle_t xTaskCanHandler; extern TaskHandle_t xTaskModbusHandler; extern TaskHandle_t xTaskPeoCntHandler; extern TaskHandle_t xTaskEmerStopSys; extern TaskHandle_t xTaskFireInHandler; extern TaskHandle_t xTaskFireOutHandler; extern TaskHandle_t xTaskLoginSystem; extern TaskHandle_t xTaskLogoutSystem; extern TaskHandle_t xTaskVentilation; extern TaskHandle_t xTaskCheckMode; extern TaskHandle_t xTaskCtrlFarMaster; extern TaskHandle_t xTaskCtrlCloseMaster; extern TaskHandle_t xTaskReadPeoInData; 112 extern TaskHandle_t xTaskTurnOffWarning; extern TaskHandle_t xTaskDisplaypPeoIn; extern TaskHandle_t xTaskDisplayDistance; extern TaskHandle_t xTaskDisplayTempHumiIn; extern TaskHandle_t xTaskDisplayTempHumiOut; extern TaskHandle_t xTaskReadTempHumiIn; /* Declare Temperature and Humidity Variables */ extern float fTempIn; extern float fTempOut; extern float fHumiIn; extern float fHumiOut; extern float fTxTempHumiIn[2]; extern float fTxTempHumiOut[2]; extern float fRxTempHumiIn[2]; extern float fRxTempHumiOut[2]; extern QueueHandle_t xQueueHoldTempHumiIn; extern QueueHandle_t xQueueHoldTempHumiOut; /* Declare Distance Variables */ extern int32_t xDinit; // Distance Init extern int32_t xDsetup; // Distance setup extern int32_t xDoffset; // Distance offset extern int32_t xDmove; // Distance moving extern int32_t xDgone; // Distance has gone /* Declare People variable */ extern uint16_t uxPeoIn; /* Declare Warning variables */ extern enum Warning { PeopleInside = 1, FireInSys, FireOutSys, OverloadBLDC, Docs, CAN_frameERR, ModbusFrameERR, UART_BLDC_ERR, UART_Peo_ERR, I2C_SHT_ERR 113 }; #endif /* End of VARS_LIST_H */ - Source code (Main.c) /* * File : SourceCode(.c) * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * - This is a main function file that is only used for Slave Storage in the Smart Storage Project ! * - */ #include "main_kd.h" char cTaskWrite[10240]; /*#define STACK_SIZE 128 StackType_t xStack1[STACK_SIZE]; StackType_t xStack2[STACK_SIZE]; StaticTask_t xTaskBuffer1; StaticTask_t xTaskBuffer2; */ int main(void){ rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); Setup clock freq for chip Chip_init_clock(); // Peripheral clock init Chip_conf_gpio(); // Configure gpio Chip_conf_mode_periph(); vQueueCreate(); vTimerCreate(); // // Configure mode of peripherals // Create Queue // Create Timer /* Create all tasks for Slave */ xTimerCreateTimerTask(); 114 xTaskCreate(vTaskCanHandler, "Handling CAN RX", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_CAN_HANDLER, &xTaskCanHandler); xTaskCreate(vTaskPeoCntHandler, "Handling People Inside", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_PEO_CNT_HANDLER, &xTaskPeoCntHandler); xTaskCreate(vTaskEmerStopSys, "System has been stopped", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_EMER_STOP_SYS, &xTaskEmerStopSys); xTaskCreate(vTaskFireInHandler, "Occur fire inside system", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_FIRE_IN_HANDLER, &xTaskFireInHandler); xTaskCreate(vTaskFireOutHandler, "Occur fire outside system", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_FIRE_OUT_HANDLER, xTaskFireOutHandler); xTaskCreate(vTaskLoginSystem, "System Login", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_LOGIN_SYSTEM, &xTaskLoginSystem); xTaskCreate(vTaskLogoutSystem, "System Logout", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_LOGOUT_SYSTEM, &xTaskLogoutSystem); xTaskCreate(vTaskVentilation, "System ventilation", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_VENTILATION, &xTaskVentilation); xTaskCreate(vTaskCheckMode, "Check mode", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_CHECK_MODE, &xTaskCheckMode); xTaskCreate(vTaskCtrlFarMaster, "Control far away Master", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_CTRL_FAR_MASTER, &xTaskCtrlFarMaster); xTaskCreate(vTaskCtrlCloseMaster, "Control close to Master", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_CTRL_CLOSE_MASTER, &xTaskCtrlCloseMaster); xTaskCreate(vTaskReadPeoInData, "Read people inside system", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_READ_PEO_IN_DATA, &xTaskReadPeoInData); xTaskCreate(vTaskTurnOffWarning, "Turn off all Warning", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_TURN_OFF_WARNING, xTaskTurnOffWarning); xTaskCreate(vTaskDisplaypPeoIn, "Display People inside", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_DISPLAY_PEO_IN, &xTaskDisplaypPeoIn); xTaskCreate(vTaskDisplayDistance, "Display distance", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_DISPLAY_DISTANCE, &xTaskDisplayDistance); 115 xTaskCreate(vTaskDisplayTempHumiIn, "Display Temp & Humi Inside", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_DISPLAY_TEMP_HUMI_IN, &xTaskDisplayTempHumiIn); xTaskCreate(vTaskDisplayTempHumiOut, "Display Temp & Humi Outside", configMINIMAL_STACK_SIZE, (void *) 1, PRIORITY_TASK_DISPLAY_TEMP_HUMI_OUT, &xTaskDisplayTempHumiOut); vTaskList(cTaskWrite); /* Start Scheduler */ vTaskStartScheduler(); for(;;); } - TaskCode ✓ CHIPConfig.c /* * File : CHIPCONFIG.C * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * Storage Project ! - This is a header file that is only used for Slave Storage in the Smart * - This file is constructed to call functions to configurate CHIP */ #include "CHIPConfig.h" void Chip_init_clock(void) { rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOB); rcc_periph_clock_enable(RCC_GPIOC); rcc_periph_clock_enable(RCC_GPIOD); rcc_periph_clock_enable(RCC_GPIOE); i2c_init_clock(); usart_init_clock(); } 116 void Chip_conf_gpio(void) { gpio_setup_gpio(); i2c_setup_gpio(); irq_setup_gpio(); usart_setup_gpio(); } void Chip_conf_mode_periph(void) { i2c_conf_mode(); irq_conf_mode(); usart_conf_mode(); } ✓ Task_tst.c /* * File : TASKS_TST.C * * Author : Khoi Dora * Email : Khoidora@gmail.com * Institution : Institute for Control Engineering and Automation (Ha Noi * University of Science and Technology) * * Abstract: * - This is a executable functions file that is only used for Slave Storage in the Smart Storage Project ! * - */ /* Include FreeRTOS's Libraries that are used within Project */ #include "Tasks_tst.h" TaskHandle_t xTimerTask; TimerHandle_t xTimerSuccess = NULL; float fTempIn; float fTempOut; float fHumiIn; float fHumiOut; float fTxTempHumiIn[2]; QueueHandle_t xQueueHoldTempHumiIn = NULL; 117 void vQueueCreate(void) { UBaseType_t uxSize = (UBaseType_t) (sizeof(fTxTempHumiIn)/sizeof(fTxTempHumiIn[0])); xQueueHoldTempHumiIn = xQueueCreate(QUEUE_LENGTH, uxSize); } /* Function to create timer */ void vTimerCreate(void) { TickType_t xTime = pdMS_TO_TICKS(TIMER_PERIOD); xTimerSuccess = xTimerCreate("GetTempHumi", xTime, AUTO_RELOAD, (void *) 0, vTaskReadTempHumiIn); if(xTimerSuccess != NULL) { xTimerStart(xTimerSuccess, TICKS_TO_WAIT); } } /* Task Read temperature and humidity inside system TimerHandle_t xTimer */ void vTaskReadTempHumiIn(TimerHandle_t xTimer) { configASSERT(xTimer); SHT3X_GetTempAndHumiClkStretch(I2C_INTERFACE, I2C_SLAVE_ADDR, &fTempIn, &fHumiIn, REPEATAB_HIGH); //xTimerReset(xTimerSuccess, TICKS_TO_WAIT); fTxTempHumiIn[0] = fTempIn; fTxTempHumiIn[1] = fHumiIn; if(xQueueHoldTempHumiIn == pdTRUE) { xQueueSendToBack(xQueueHoldTempHumiIn, (void *) &fTempIn, TICKS_TO_WAIT); } //xQueueSendToBack(xQueueHoldTempHumiIn, (void *) fTxTempHumiIn, TICKS_TO_WAIT); //printf("Temp: %f\n", fTxTempHumiIn[0]); //printf("Humi: %f\n", fTxTempHumiIn[1]); //xTimerStart(xTimerSuccess, TICKS_TO_WAIT); } 118 ... tính hệ thống lưu trữ thông minh Hệ thống lưu trữ thông minh xây dựng gồm nhiều giá (tủ lưu trữ) đặt sát cạnh nhằm tối ưu không gian lưu trữ Hệ thống lưu trữ thông minh phục vụ cho công tác lưu trữ. .. thiết kế phần cứng Chương 3: Xây dựng môi trường nhúng hệ điều hành thời gian thực chip ARM Chương 4: Phát triển thuật toán tảng hệ điều hành thời gian thực cho hệ thống lưu trữ thông minh Chương... NHÚNG HỆ ĐIỀU HÀNH THỜI GIAN THỰC TRÊN CHIP ARM 3.1 Phân tích lựa chọn hướng tiếp cận Như trình bày phần trên, hệ thống lưu trữ thông minh xây dựng, phát triển thành hệ thống nhúng với chip điều

Ngày đăng: 07/12/2021, 23:18

Mục lục

    TÀI LIỆU THAM KHẢO

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan