284 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			284 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "os_task.h"
							 | 
						||
| 
								 | 
							
								#include "os_mem.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "dbg_io.h"
							 | 
						||
| 
								 | 
							
								#include "iot_diag.h"
							 | 
						||
| 
								 | 
							
								#include "iot_io.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//#include <stdlib.h>
							 | 
						||
| 
								 | 
							
								#include "iot_system_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//#include "iot_gptmr.h"
							 | 
						||
| 
								 | 
							
								#include "iot_system.h"
							 | 
						||
| 
								 | 
							
								//#include "os_mem.h"
							 | 
						||
| 
								 | 
							
								//#include "cpu.h"
							 | 
						||
| 
								 | 
							
								//#include "os_task.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "platform.h"
							 | 
						||
| 
								 | 
							
								#include "encoding.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//#include "sec_glb.h"
							 | 
						||
| 
								 | 
							
								//#include "ahb.h"
							 | 
						||
| 
								 | 
							
								//#include "intc.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "bits.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "iso7816_sim_rf.h"
							 | 
						||
| 
								 | 
							
								#include "apb_glb0_reg.h"
							 | 
						||
| 
								 | 
							
								#include "hw_reg_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "os_utils.h"
							 | 
						||
| 
								 | 
							
								#include "iso7816.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "gpio_mtx.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//#define RF0 0
							 | 
						||
| 
								 | 
							
								#define RF 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								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;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM0_DATA_in      57
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM1_DATA_in      58
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM1_DATA_out     90
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM1_CLK_out      91
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM1_RST_out      92
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM0_DATA_out     87
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM0_CLK_out      88
							 | 
						||
| 
								 | 
							
								#define  GMTX_SIM0_RST_out      89
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint8_t sim_gpio_sel(uint8_t port, uint8_t data, uint8_t clk, uint8_t rst)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    if(SIM_INVALID(port))
							 | 
						||
| 
								 | 
							
								        return 1;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    gpio_mtx_enable();
							 | 
						||
| 
								 | 
							
								    uint8_t data_func = 0;
							 | 
						||
| 
								 | 
							
								    uint8_t clk_func = 0;
							 | 
						||
| 
								 | 
							
								    uint8_t rst_func = 0;
							 | 
						||
| 
								 | 
							
								    gpio_sig_info_t info = {0};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    data_func = gpio_pin_func_get(data);
							 | 
						||
| 
								 | 
							
								    clk_func = gpio_pin_func_get(clk);
							 | 
						||
| 
								 | 
							
								    rst_func = gpio_pin_func_get(rst);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    info.CFG[0].type = IO_TYPE_IO;
							 | 
						||
| 
								 | 
							
								    info.CFG[0].func = data_func;
							 | 
						||
| 
								 | 
							
								    info.CFG[0].gpio = data;
							 | 
						||
| 
								 | 
							
								    info.CFG[1].type = IO_TYPE_OUT;
							 | 
						||
| 
								 | 
							
								    info.CFG[1].func = clk_func;
							 | 
						||
| 
								 | 
							
								    info.CFG[1].gpio = clk;
							 | 
						||
| 
								 | 
							
								    info.CFG[2].type = IO_TYPE_OUT;
							 | 
						||
| 
								 | 
							
								    info.CFG[2].func = rst_func;
							 | 
						||
| 
								 | 
							
								    info.CFG[2].gpio = rst;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (port == 0) {
							 | 
						||
| 
								 | 
							
								        info.sig_type = 3;
							 | 
						||
| 
								 | 
							
								        info.CFG[0].inid = GMTX_SIM0_DATA_in;
							 | 
						||
| 
								 | 
							
								        info.CFG[0].outid = GMTX_SIM0_DATA_out;
							 | 
						||
| 
								 | 
							
								        info.CFG[1].inid = 0xff;
							 | 
						||
| 
								 | 
							
								        info.CFG[1].outid = GMTX_SIM0_CLK_out;
							 | 
						||
| 
								 | 
							
								        info.CFG[2].inid = 0xff;
							 | 
						||
| 
								 | 
							
								        info.CFG[2].outid = GMTX_SIM0_RST_out;
							 | 
						||
| 
								 | 
							
								    } else if (port == 1){
							 | 
						||
| 
								 | 
							
								        info.sig_type = 3;
							 | 
						||
| 
								 | 
							
								        info.CFG[0].inid = GMTX_SIM1_DATA_in;
							 | 
						||
| 
								 | 
							
								        info.CFG[0].outid = GMTX_SIM1_DATA_out;
							 | 
						||
| 
								 | 
							
								        info.CFG[1].inid = 0xff;
							 | 
						||
| 
								 | 
							
								        info.CFG[1].outid = GMTX_SIM1_CLK_out;
							 | 
						||
| 
								 | 
							
								        info.CFG[2].inid = 0xff;
							 | 
						||
| 
								 | 
							
								        info.CFG[2].outid = GMTX_SIM1_RST_out;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    gpio_module_pin_select(&info);
							 | 
						||
| 
								 | 
							
								    gpio_module_sig_select(&info, GPIO_MTX_MODE_MATRIX);
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void user_task_1()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint32_t value=0;
							 | 
						||
| 
								 | 
							
								    uint8_t i =0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    sim_gpio_sel(1, 3, 4, 5);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //tmode0 tx test
							 | 
						||
| 
								 | 
							
								//    iso7816_controller_reset(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_tmode_init(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_tmode_set_mode0(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_cold_reset(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_set_tx_mode(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//    iso7816_tx(RF1,0x68660055);
							 | 
						||
| 
								 | 
							
								//    iso7816_tx(RF1,0x686600aa);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//    os_delay(400);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //tmode1 tx test
							 | 
						||
| 
								 | 
							
								//    iso7816_controller_reset(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_tmode_init(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//    iso7816_tmode_set_mode1(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_cold_reset(RF);
							 | 
						||
| 
								 | 
							
								//    iso7816_set_tx_mode(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//    iso7816_tx(RF1,0x68660055);
							 | 
						||
| 
								 | 
							
								//    iso7816_tx(RF1,0x686600aa);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//    os_delay(400);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //tmode0 atr test
							 | 
						||
| 
								 | 
							
								    iso7816_controller_reset(RF);
							 | 
						||
| 
								 | 
							
								    iso7816_tmode_init(RF);
							 | 
						||
| 
								 | 
							
								    iso7816_cold_reset(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								     iso7816_set_rx_mode(RF);
							 | 
						||
| 
								 | 
							
								    if(0==iso7816_rx_fifo_empty_check(RF)){
							 | 
						||
| 
								 | 
							
								        i =0;
							 | 
						||
| 
								 | 
							
								        while(0==iso7816_rx_fifo_empty_check(RF)){
							 | 
						||
| 
								 | 
							
								            value = iso7816_rx(RF);
							 | 
						||
| 
								 | 
							
								            iot_printf("recieve data %d = %x \n",i,value);
							 | 
						||
| 
								 | 
							
								            i++;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //tmode1 9bit tx and rx test
							 | 
						||
| 
								 | 
							
								    iso7816_rx_fifo_clear(RF);
							 | 
						||
| 
								 | 
							
								    os_delay(400);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    iso7816_tmode_set_mode1(RF);
							 | 
						||
| 
								 | 
							
								    iso7816_set_tx_mode(RF);
							 | 
						||
| 
								 | 
							
								    iso7816_tx(RF,0x68660000);
							 | 
						||
| 
								 | 
							
								    iso7816_tx(RF,0x686600A4);
							 | 
						||
| 
								 | 
							
								    iso7816_tx(RF,0x68660004);
							 | 
						||
| 
								 | 
							
								    iso7816_tx(RF,0x68660000);
							 | 
						||
| 
								 | 
							
								    iso7816_tx(RF,0x6866000E);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    iso7816_wait_for_tx_done(RF);
							 | 
						||
| 
								 | 
							
								    iso7816_set_rx_mode(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    os_delay(400);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if(0==iso7816_rx_fifo_empty_check(RF)){
							 | 
						||
| 
								 | 
							
								        value = iso7816_rx(RF);
							 | 
						||
| 
								 | 
							
								        iot_printf("data received data = %x!\n",value);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    else{
							 | 
						||
| 
								 | 
							
								        iot_printf("no data received\n");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //de-active test
							 | 
						||
| 
								 | 
							
								    iso7816_rx_fifo_clear(RF);
							 | 
						||
| 
								 | 
							
								    os_delay(400);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    iso7816_card_release(RF);
							 | 
						||
| 
								 | 
							
								    os_delay(400);
							 | 
						||
| 
								 | 
							
								    iso7816_cold_reset(RF);
							 | 
						||
| 
								 | 
							
								    //iso7816_warm_reset(RF);
							 | 
						||
| 
								 | 
							
								    if(0==iso7816_rx_fifo_empty_check(RF)){
							 | 
						||
| 
								 | 
							
								        iot_printf("iso7816 rf%d card release successfully !\n",RF);
							 | 
						||
| 
								 | 
							
								        iso7816_set_rx_mode(RF);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        i =0;
							 | 
						||
| 
								 | 
							
								        while(0==iso7816_rx_fifo_empty_check(RF)){
							 | 
						||
| 
								 | 
							
								            value = iso7816_rx(RF);
							 | 
						||
| 
								 | 
							
								            iot_printf("recieve data %d = %x \n",i,value);
							 | 
						||
| 
								 | 
							
								            i++;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    else{
							 | 
						||
| 
								 | 
							
								        iot_printf("iso7816 rf%d card release failed !\n",RF);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    while(1)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        iot_printf("user_task_1....\n");
							 | 
						||
| 
								 | 
							
								        os_delay(400);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int32_t iot__task_init()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    os_task_h handle;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    handle = os_create_task(user_task_1, NULL, 9);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //create the tasks;
							 | 
						||
| 
								 | 
							
								    if(handle != NULL) {
							 | 
						||
| 
								 | 
							
								        iot_printf("task 1 init successfully...\n");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    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__task_start()
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    //start the tasks;
							 | 
						||
| 
								 | 
							
								    os_start_kernel();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int32_t iot__module_start(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    int32_t res = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    res = iot__task_start();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return res;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								int main(void)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    //module init;
							 | 
						||
| 
								 | 
							
								    iot__module_init();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    //module start;
							 | 
						||
| 
								 | 
							
								    iot__module_start();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return 0;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 |