262 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			262 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | ||
| 
 | ||
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | ||
| 
 | ||
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | ||
| be copied by any method or incorporated into another program without
 | ||
| the express written consent of Aerospace C.Power. This Information or any portion
 | ||
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | ||
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | ||
| liability for its use in any way and conveys no license or title under
 | ||
| any patent or copyright and makes no representation or warranty that this
 | ||
| Information is free from patent or copyright infringement.
 | ||
| 
 | ||
| ****************************************************************************/
 | ||
| /* os shim includes */
 | ||
| #include "os_types.h"
 | ||
| #include "os_task.h"
 | ||
| #include "os_utils.h"
 | ||
| 
 | ||
| /* common includes */
 | ||
| #include "iot_io.h"
 | ||
| #include "iot_bitops.h"
 | ||
| #include "iot_pkt.h"
 | ||
| #include "iot_ipc.h"
 | ||
| #include "iot_plc_lib.h"
 | ||
| #include "iot_dbglog_api.h"
 | ||
| #include "iot_config.h"
 | ||
| 
 | ||
| /* driver includes */
 | ||
| #include "iot_clock.h"
 | ||
| #include "iot_uart.h"
 | ||
| #include "iot_led.h"
 | ||
| #include "iot_uart_h.h"
 | ||
| #include "iot_dma.h"
 | ||
| /* debug includes*/
 | ||
| #include "dbg_io.h"
 | ||
| 
 | ||
| /* plc public includes */
 | ||
| #include "uart.h"
 | ||
| #include "rtc.h"
 | ||
| 
 | ||
| #include "apb_dma.h"
 | ||
| #include "osif_dma_uart.h"
 | ||
| #include "apb.h"
 | ||
| #include "pin_rf.h"
 | ||
| #include "hw_reg_api.h"
 | ||
| #include "gpio_mtx_reg.h"
 | ||
| 
 | ||
| extern int platform_init();
 | ||
| 
 | ||
| static const iot_pkt_config_t test_pkt_config =
 | ||
| {
 | ||
|     {
 | ||
|         {
 | ||
|             256,
 | ||
|             25,
 | ||
|             PKT_OWNER_ALL,
 | ||
|         },
 | ||
|         {
 | ||
|             600,
 | ||
|             25,
 | ||
|             PKT_OWNER_ALL,
 | ||
|             },
 | ||
|         {
 | ||
|             1100,
 | ||
|             10,
 | ||
|             PKT_OWNER_ALL,
 | ||
|         },
 | ||
|         {
 | ||
|             2200,
 | ||
|             3,
 | ||
|             PKT_OWNER_ALL,
 | ||
|         },
 | ||
|         {
 | ||
|             0,
 | ||
|             0,
 | ||
|             PKT_OWNER_NONE,
 | ||
|         },
 | ||
|         {
 | ||
|             0,
 | ||
|             0,
 | ||
|             PKT_OWNER_NONE,
 | ||
|         },
 | ||
|         {
 | ||
|             0,
 | ||
|             0,
 | ||
|             PKT_OWNER_NONE,
 | ||
|         },
 | ||
|         {
 | ||
|             0,
 | ||
|             0,
 | ||
|             PKT_OWNER_NONE,
 | ||
|         },
 | ||
|     }
 | ||
| };
 | ||
| 
 | ||
| #define DMA_TRACE(s) iot_printf("\r\n%s@LINE:%d - %s", __FUNCTION__ , __LINE__, s)
 | ||
| #define TEST_UPORT  2
 | ||
| 
 | ||
| static iot_uart_h test_uart_dma_h;
 | ||
| static os_task_h test_init_handle;
 | ||
| 
 | ||
| static void iot_data_dump(uint8_t *p_buf, uint32_t plen, char *p_str)
 | ||
| {
 | ||
|     iot_printf("[%s]len=%d:", p_str, plen);
 | ||
|     for (uint32_t i = 0; i < plen; ++i) {
 | ||
|         iot_printf("%02X ", p_buf[i]);
 | ||
|     }
 | ||
|     iot_printf("\r\n");
 | ||
| 
 | ||
|     return;
 | ||
| }
 | ||
| 
 | ||
| static int test_uart_recieve(int pt, iot_pkt_t* pkt)
 | ||
| {
 | ||
|     if (0) {
 | ||
|         iot_data_dump(iot_pkt_data(pkt), iot_pkt_data_len(pkt), "RX");
 | ||
|     } else {
 | ||
|         iot_printf("recv_len=%d\r\n", iot_pkt_data_len(pkt));
 | ||
|     }
 | ||
| 
 | ||
|     if (0) {
 | ||
|         iot_pkt_free(pkt);
 | ||
|     } else {
 | ||
|         iot_uart_dma_send(test_uart_dma_h, pkt);
 | ||
|     }
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 | ||
| static uint8_t test_uart_send_cnt;
 | ||
| static void test_uart_send_tmr_handle(timer_id_t tid, void *data)
 | ||
| {
 | ||
|     iot_pkt_t *p_pkt;
 | ||
|     uint8_t send_buf[8];
 | ||
| 
 | ||
|     if (NULL == (p_pkt = iot_pkt_alloc(sizeof(send_buf), UNKNOWN_MID))) {
 | ||
|         iot_printf("pkt alloc failed.\n");
 | ||
|         IOT_ASSERT(0);
 | ||
|     }
 | ||
|     for (uint8_t i = 0; i < sizeof(send_buf); i++) {
 | ||
|         send_buf[i] = test_uart_send_cnt++;
 | ||
|     }
 | ||
| 
 | ||
|     os_mem_cpy(iot_pkt_put(p_pkt, sizeof(send_buf)), send_buf, sizeof(send_buf));
 | ||
|     iot_uart_dma_send(test_uart_dma_h, p_pkt);
 | ||
| }
 | ||
| 
 | ||
| static void test_uart_dma_init(void)
 | ||
| {
 | ||
|     timer_id_t test_uart_send_tmr;
 | ||
| 
 | ||
|     apb_enable(APB_GMTX);
 | ||
| 
 | ||
|     iot_uart_dma_init();
 | ||
| 
 | ||
|     if((test_uart_dma_h = iot_uart_dma_open(TEST_UPORT, test_uart_recieve)) == NULL) {
 | ||
|         DMA_TRACE("test_uart_init created failed!\r\n");
 | ||
|         return ;
 | ||
|     }
 | ||
|     if (1) { // 不使用默认的GPIO口,在这里重新修改串口PIN
 | ||
|         iot_uart_set_pin(TEST_UPORT, 22, 23);
 | ||
|     }
 | ||
| 
 | ||
|     test_uart_send_tmr = os_create_timer(UNKNOWN_MID, 1,
 | ||
|         (os_timer_func_t)test_uart_send_tmr_handle, (void *)NULL);
 | ||
| 
 | ||
|     if (0) {
 | ||
|         /* Start the timer. */
 | ||
|         os_start_timer(test_uart_send_tmr, 1000);
 | ||
|     }
 | ||
| 
 | ||
|     DMA_TRACE("\r\nUart Dma Start!\r\n");
 | ||
| 
 | ||
|     return;
 | ||
| }
 | ||
| 
 | ||
| static void iot_sub_system_init()
 | ||
| {
 | ||
|     /* init common modules */
 | ||
|     iot_bitops_init();
 | ||
| 
 | ||
|     /* init os related modules and utilities */
 | ||
|     os_utils_init();
 | ||
| 
 | ||
|     /* init pkt module */
 | ||
|     iot_pkt_init(&test_pkt_config);
 | ||
| 
 | ||
|     /* init ipc module */
 | ||
|     iot_ipc_init();
 | ||
| 
 | ||
|     /* init dma module */
 | ||
|     iot_dma_init();
 | ||
| }
 | ||
| 
 | ||
| static void iot_task_1(void *arg)
 | ||
| {
 | ||
|     iot_sub_system_init();
 | ||
|     for(;;) {
 | ||
|        iot_printf("iot_task_1 running...\n");
 | ||
|        test_uart_dma_init();
 | ||
|        os_delete_task(test_init_handle);
 | ||
|     }
 | ||
| }
 | ||
| 
 | ||
| static int32_t iot_task_init()
 | ||
| {
 | ||
|     /* start plc lib task */
 | ||
|     test_init_handle = os_create_task(iot_task_1, NULL, 9);
 | ||
| 
 | ||
|     //create the tasks;
 | ||
|     if(test_init_handle != NULL) {
 | ||
|         iot_printf("iot_task_1 create successfully...\n");
 | ||
|     }
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 | ||
| static int32_t iot_platform_init()
 | ||
| {
 | ||
|     /* platform intialization */
 | ||
|     platform_init();
 | ||
| 
 | ||
|     /* resource initializations */
 | ||
|     system_clock_init();
 | ||
| 
 | ||
|     system_uart_init();
 | ||
| 
 | ||
|     dbg_uart_init();
 | ||
| 
 | ||
|     dbg_uart_stage1_init();
 | ||
| 
 | ||
|     /* rtc init, idle used rtc lock */
 | ||
|     iot_rtc_init();
 | ||
| 
 | ||
|     iot_printf("iot platform init successfully...\n");
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 | ||
| static int32_t iot_task_start()
 | ||
| {
 | ||
|     //start the tasks;
 | ||
|     os_start_kernel();
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 | ||
| int main(void)
 | ||
| {
 | ||
|     //platform intialization;
 | ||
|     iot_platform_init();
 | ||
| 
 | ||
|     //create all the tasks;
 | ||
|     iot_task_init();
 | ||
| 
 | ||
|     iot_task_start();
 | ||
| 
 | ||
|     return 0;
 | ||
| }
 | ||
| 
 |