463 lines
		
	
	
		
			8.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			463 lines
		
	
	
		
			8.0 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"
							 | 
						||
| 
								 | 
							
								#include "iot_errno.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* driver includes */
							 | 
						||
| 
								 | 
							
								#include "iot_clock.h"
							 | 
						||
| 
								 | 
							
								#include "iot_uart.h"
							 | 
						||
| 
								 | 
							
								#include "iot_led.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* cli includes */
							 | 
						||
| 
								 | 
							
								#include "iot_cli.h"
							 | 
						||
| 
								 | 
							
								#include "iot_uart_h.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* debug includes*/
							 | 
						||
| 
								 | 
							
								#include "dbg_io.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "uart.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								extern int platform_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								static const iot_pkt_config_t test_pkt_config =
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            256,
							 | 
						||
| 
								 | 
							
								            50,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_ALL,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            600,
							 | 
						||
| 
								 | 
							
								            50,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_ALL,
							 | 
						||
| 
								 | 
							
								            },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            1100,
							 | 
						||
| 
								 | 
							
								            15,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_ALL,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            2200,
							 | 
						||
| 
								 | 
							
								            6,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_ALL,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_NONE,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_NONE,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_NONE,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            0,
							 | 
						||
| 
								 | 
							
								            PKT_OWNER_NONE,
							 | 
						||
| 
								 | 
							
								        },
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define TX_HW_FLOW_EN 1
							 | 
						||
| 
								 | 
							
								#define RX_HW_FLOW_EN 2
							 | 
						||
| 
								 | 
							
								#define TX_HW_RX_FLOW_EN 3
							 | 
						||
| 
								 | 
							
								#define HW_FLOW_DISABLE 0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define TEST_UART_FLOW_CTRL 0
							 | 
						||
| 
								 | 
							
								#define DEBUG_UART_TASK_ENABLE 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if DEBUG_UART_TASK_ENABLE
							 | 
						||
| 
								 | 
							
								iot_uart_h_t  *g_test_uart_h;
							 | 
						||
| 
								 | 
							
								static void test_uart_recv_func(uint8_t* buffer, uint32_t buffer_len, bool_t is_full_frame, uint32_t invalid_data_len);
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								os_task_h test_init_handle;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if TEST_UART_FLOW_CTRL
							 | 
						||
| 
								 | 
							
								extern struct uart_ctrl uart_e_ctrl;
							 | 
						||
| 
								 | 
							
								int glb_port, tx_cnt = 1000, c_cnt;
							 | 
						||
| 
								 | 
							
								char tx_ch = 'U'; /* U = 01010101b */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int glb_port = 0; //hardware flow control on UART0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_flowctrl(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								//    int do_tx, do_rx, ret, rx_cnt;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    int ret = 0;
							 | 
						||
| 
								 | 
							
								    uint32_t tt = 0;
							 | 
						||
| 
								 | 
							
								    int rx_thrd = 1;
							 | 
						||
| 
								 | 
							
								    glb_port = 0;
							 | 
						||
| 
								 | 
							
								    char tx_char = 0;
							 | 
						||
| 
								 | 
							
								    char rx_char = 0;
							 | 
						||
| 
								 | 
							
								    uart_e_ctrl.init(glb_port);
							 | 
						||
| 
								 | 
							
								    uart_e_ctrl.flow_ctrl(glb_port, TX_HW_RX_FLOW_EN,rx_thrd);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    while(1){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								       while(tt<0x0F0000){
							 | 
						||
| 
								 | 
							
								        tt++;
							 | 
						||
| 
								 | 
							
								                __asm volatile("nop\n");
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        tt=0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        ret = uart_e_ctrl.getc(glb_port);
							 | 
						||
| 
								 | 
							
								        if(ret>0){
							 | 
						||
| 
								 | 
							
								                rx_char = (char)ret;
							 | 
						||
| 
								 | 
							
								                uart_e_ctrl.putc(glb_port,rx_char);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        else{
							 | 
						||
| 
								 | 
							
								                tx_char = 'B';
							 | 
						||
| 
								 | 
							
								        uart_e_ctrl.putc(glb_port,tx_char);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return ;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void iot_test_hook(char ch)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								#if 0
							 | 
						||
| 
								 | 
							
								    int k;
							 | 
						||
| 
								 | 
							
								    char *buf;
							 | 
						||
| 
								 | 
							
								    iot_pkt_t *pkt;
							 | 
						||
| 
								 | 
							
								   pkt =  iot_pkt_alloc(1024, IOT_DRIVER_MID);
							 | 
						||
| 
								 | 
							
								   buf = (char*)(pkt->data);
							 | 
						||
| 
								 | 
							
								   for(k=0; k<256; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = ch +0;
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<512; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = ch +1;
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<768; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = ch +2;
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<1024; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = ch +3;
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   pkt->tail += 1024;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   iot_uart_send(g_test_uart_h, pkt, NULL);
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_task_1(){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for(;;) {
							 | 
						||
| 
								 | 
							
								        //iot_printf("test task 1111111111111....\n");
							 | 
						||
| 
								 | 
							
								        os_delay(1000);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_task_2(){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for(;;) {
							 | 
						||
| 
								 | 
							
								        //iot_printf("test task 22222222222....\n");
							 | 
						||
| 
								 | 
							
								        iot_test_hook('A');
							 | 
						||
| 
								 | 
							
								        os_delay(2000);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_task_3(){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for(;;) {
							 | 
						||
| 
								 | 
							
								        //iot_printf("test task 333333....\n");
							 | 
						||
| 
								 | 
							
								        iot_test_hook('0');
							 | 
						||
| 
								 | 
							
								        os_delay(3000);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_task_4(){
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for(;;) {
							 | 
						||
| 
								 | 
							
								        //iot_printf("test task 4....\n");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        os_delay(4000);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_task_init()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								   os_task_h handle;
							 | 
						||
| 
								 | 
							
								   handle = os_create_task(test_task_1, NULL, 6);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   //create the tasks;
							 | 
						||
| 
								 | 
							
								   if(handle != NULL) {
							 | 
						||
| 
								 | 
							
								       iot_printf("task 1 init successfully...\n");
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   handle = os_create_task(test_task_2, NULL, 7);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   //create the tasks;
							 | 
						||
| 
								 | 
							
								   if(handle != NULL) {
							 | 
						||
| 
								 | 
							
								        iot_printf("task 2 init successfully...\n");
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    handle = os_create_task(test_task_3, NULL, 8);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //create the tasks;
							 | 
						||
| 
								 | 
							
								    if(handle != NULL) {
							 | 
						||
| 
								 | 
							
								        iot_printf("task 3 init successfully...\n");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    handle = os_create_task(test_task_4, NULL, 9);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //create the tasks;
							 | 
						||
| 
								 | 
							
								    if(handle != NULL) {
							 | 
						||
| 
								 | 
							
								        iot_printf("task 2 init successfully...\n");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void test_init()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /* init common modules */
							 | 
						||
| 
								 | 
							
								    iot_bitops_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /* init os related modules and utilities */
							 | 
						||
| 
								 | 
							
								    os_utils_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /* init dbglog module */
							 | 
						||
| 
								 | 
							
								    iot_dbglog_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /* init pkt module */
							 | 
						||
| 
								 | 
							
								    iot_pkt_init(&test_pkt_config);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /* init ipc module */
							 | 
						||
| 
								 | 
							
								    //iot_ipc_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /*init uart module*/
							 | 
						||
| 
								 | 
							
								    iot_uart_init(1);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    test_task_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   /*dbg uart stage 2 init*/
							 | 
						||
| 
								 | 
							
								    //dbg_uart_stage2_init();
							 | 
						||
| 
								 | 
							
								#if DEBUG_UART_TASK_ENABLE
							 | 
						||
| 
								 | 
							
								    g_test_uart_h = iot_uart_open(3, test_uart_recv_func, 1024, NULL);
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if DEBUG_UART_TASK_ENABLE
							 | 
						||
| 
								 | 
							
								#include "os_mem.h"
							 | 
						||
| 
								 | 
							
								static void test_uart_recv_func(uint8_t* buffer, uint32_t buffer_len, bool_t is_full_frame,
							 | 
						||
| 
								 | 
							
								        uint32_t invalid_data_len)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    char *buf;
							 | 
						||
| 
								 | 
							
								    iot_pkt_t *pkt;
							 | 
						||
| 
								 | 
							
								    (void)invalid_data_len;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   pkt =  iot_pkt_alloc(buffer_len, IOT_DRIVER_MID);
							 | 
						||
| 
								 | 
							
								   buf = (char*)(pkt->data);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   os_mem_cpy(buf, buffer, buffer_len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   pkt->tail += buffer_len;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   iot_uart_send(g_test_uart_h, pkt, NULL);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void iot_task_1(void *arg)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    iot_printf("task 1 entry....\n");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for(;;) {
							 | 
						||
| 
								 | 
							
								       test_init();
							 | 
						||
| 
								 | 
							
								       //iot_test_hook();
							 | 
						||
| 
								 | 
							
								       os_delete_task(test_init_handle);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								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("task 1 init successfully...\n");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int32_t iot_task_start()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    //start the tasks;
							 | 
						||
| 
								 | 
							
								    os_start_kernel();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    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();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    iot_led_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int32_t iot_module_init(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    //platform intialization;
							 | 
						||
| 
								 | 
							
								    iot_platform_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //create all the tasks;
							 | 
						||
| 
								 | 
							
								    iot_task_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    iot_printf("starting...\n");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int32_t iot_module_start(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    int32_t res = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    res = iot_task_start();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return res;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								extern struct uart_ctrl uart_e_ctrl;
							 | 
						||
| 
								 | 
							
								int raw_uart_write(int pt, char* buf, size_t count)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    int i = 0;
							 | 
						||
| 
								 | 
							
								    uint8_t* p = (uint8_t*)buf;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    while(i < count) {
							 | 
						||
| 
								 | 
							
								        if(uart_e_ctrl.putc(pt, *p) == -ERR_AGAIN)
							 | 
						||
| 
								 | 
							
								            break;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        p++;
							 | 
						||
| 
								 | 
							
								        i++;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return i;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								char tst_tmp[1032];
							 | 
						||
| 
								 | 
							
								int do_continue = 1;
							 | 
						||
| 
								 | 
							
								void uart_raw_test(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    int k;
							 | 
						||
| 
								 | 
							
								    char *buf = tst_tmp, *p;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   uart_e_ctrl.init(0);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(k=0; k<256; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = 'A';
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<512; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = 'B';
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<768; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = 'C';
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   for(; k<1024; k++)
							 | 
						||
| 
								 | 
							
								   {
							 | 
						||
| 
								 | 
							
								    buf[k] = 'D';
							 | 
						||
| 
								 | 
							
								   }
							 | 
						||
| 
								 | 
							
								    do
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								       k = 0;
							 | 
						||
| 
								 | 
							
								       while(k < 1024)
							 | 
						||
| 
								 | 
							
								       {
							 | 
						||
| 
								 | 
							
								        p = tst_tmp + k;
							 | 
						||
| 
								 | 
							
								        k += raw_uart_write(0, p, 1024-k);
							 | 
						||
| 
								 | 
							
								       }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								       __asm volatile("nop\n");
							 | 
						||
| 
								 | 
							
								       k = 40000;
							 | 
						||
| 
								 | 
							
								       __asm volatile("nop\n");
							 | 
						||
| 
								 | 
							
								       while(k-- > 0) __asm volatile("nop\n");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    }while(do_continue);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    while(1);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int main(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    //uart_raw_test();
							 | 
						||
| 
								 | 
							
								#if TEST_UART_FLOW_CTRL
							 | 
						||
| 
								 | 
							
								    test_flowctrl();
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   //module init;
							 | 
						||
| 
								 | 
							
								    iot_module_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   //module start;
							 | 
						||
| 
								 | 
							
								    iot_module_start();
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 |