int main(void)
{
	DO_TEST_HARNESS_SETUP();
	
	WD_DISABLE();
	
	setupIO();
	readTestMode();
		
	setupTimers();
	
	smIndex = setupStateMachine();
	
	TS_Setup();
	
	Threshold_Init();
	
	Filter_Init();
	
	Flush_Reset();
		
	COMMS_Init();
		
	sei();
	
	runNormalApplication();
}	
Example #2
0
int main(void)
{
	SysTick_init();
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	
	uart_init(115200);
	
	Struct_Init();
	Pid_Init();
	
	MotoPwm_Init();
	
	OLED_Init();
	Key_Init();
	
	I2cMaster_Init();
  mpu_dmp_init();	
	GPIO_Config();
	
	Filter_Init();
	
//	NRF_Usart_Pin_Init();//无线初始化
//	NRF_Read_Live_Init();//无线在线传输	
//  ReadData_Init();
	
	Scheduler_Init();
	
  while(1)
	{
		Scheduler_Loop();
	}
}
Example #3
0
int main(int argc, char *argv[]) {
        IBhandle_t      fd;
        Mai_t           in_mai;
        Filter_t        filter;
        Status_t        status;
    uint32_t    port;
	uint32_t	dev=0;

    if (argc != 2)
    {
        fprintf(stderr, "usage: qp1sink <port>\n");
        exit(-1);
    }
    port = strtoul(argv[1], NULL, 0);

//
//      Initialize the MAI subsystem and open the port.
//
        mai_init();
        status=ib_init_devport(&dev, &port, NULL);
        if (status)
          {
            printf("ib_init_devport failed, %d\n",status);
            exit(1);
          }
        status = mai_open(1, 0, port, &fd);
        if (status != VSTATUS_OK) {
                fprintf(stderr, "Can't open MAI (%d)\n", status);
                exit(0);
        }

//
//      Create the filter so we can receive the reply to our request.
//
        Filter_Init(&filter, MAI_ACT_FMASK, MAI_TYPE_EXTERNAL);
        filter.value.tid = 0xF002030405060708ull;
        filter.mask.tid = 0xF000000000000000ull;

        status = mai_filter_create(fd, &filter, VFILTER_SHARE);
        if (status != VSTATUS_OK) {
                fprintf(stderr, "Can't create a filter (%d)\n", status);
                mai_close(fd);
                exit(1);
        }

        while (1)
    {

        //
        //      Wait five second for an answer.
        //
            status = mai_recv(fd, &in_mai, 1000000);
            if (status != VSTATUS_OK) {
                    fprintf(stderr, "Didn't receive a MAD (%d)\n", status);
            continue;
            }

        //
        //      Display the MAD that came in.
        //
        dumpit(&in_mai);
        }

//
//      Delete the filter.
//
        status = mai_filter_delete(fd, &filter, VFILTER_SHARE);
        if (status != VSTATUS_OK) {
                fprintf(stderr, "Can't delete a filter (%d)\n", status);
                mai_close(fd);
                exit(1);
        }

        mai_close(fd);
        exit(0);
}
Example #4
0
File: mai.c Project: 01org/opa-fm
static
Status_t
stl_get_portinfo(IBhandle_t handle, STL_PORT_INFO * pip, uint8_t user_port,
                int16_t dev, uint8_t port, uint32_t qpn)
{
	Status_t rc, saved_rc;
	Filter_t filter;
	int i;
	uint64_t tid;
    uint32_t datalen;
	uint8_t  path[2];
    DRStlSmp_t *drp;
	Mai_t out_mad, in_mad;
	
	IB_ENTER(__func__, handle, pip, user_port, 0);

	rc = mai_init_portinfo(dev, port);
	if (rc != VSTATUS_OK) {
		IB_LOG_WARNRC("Error in mai_init_portinfo; rc:", rc);
		return(VSTATUS_BAD);
	}
	
	memset(path, 0, sizeof(path));
	mai_alloc_tid(mai_portinfo_fd, MAD_CV_SUBN_DR, &tid);
	
	// create MAD
	Mai_Init(&out_mad);
	out_mad.dev     = dev;
	out_mad.port    = port;
	out_mad.qp      = 0;
	out_mad.active |= (MAI_ACT_DEV | MAI_ACT_PORT | MAI_ACT_QP);
	
	AddrInfo_Init(&out_mad, PERMISSIVE_LID, PERMISSIVE_LID, SMI_MAD_SL, mai_get_default_pkey(), MAI_SMI_QP, MAI_SMI_QP, 0);
	DRStlMad_Init(&out_mad, MAD_CM_GET, tid, STL_MCLASS_ATTRIB_ID_PORT_INFO, 0x01000000 | user_port, 0, path);
    datalen = STL_SMP_DR_HDR_LEN;
	
	// create MAI filter
	Filter_Init(&filter, 0, 0);
	
	filter.active |= MAI_ACT_ADDRINFO;
	filter.active |= MAI_ACT_BASE;
	filter.active |= MAI_ACT_TYPE;
	filter.active |= MAI_ACT_DATA;
	filter.active |= MAI_ACT_DEV;
	filter.active |= MAI_ACT_PORT;
	filter.active |= MAI_ACT_QP;
	filter.active |= MAI_ACT_FMASK;
	filter.type    = MAI_TYPE_EXTERNAL;
	filter.dev     = dev;
	filter.port    = (port == 0) ? MAI_TYPE_ANY : port;
	filter.qp      = 0;

	filter.value.bversion = STL_BASE_VERSION;
	filter.value.cversion = STL_SM_CLASS_VERSION;
	filter.value.mclass   = MAD_CV_SUBN_DR;
	filter.value.method   = MAD_CM_GET_RESP;
	filter.value.aid      = STL_MCLASS_ATTRIB_ID_PORT_INFO;
	filter.value.amod     = 0x01000000 | user_port;
	filter.value.tid      = tid;

	filter.mask.bversion  = 0xff;
	filter.mask.cversion  = 0xff;
	filter.mask.mclass	  = 0xff;
	filter.mask.method    = 0xff;
	filter.mask.aid       = 0xffff;
	filter.mask.amod      = 0xffffffff;
	filter.mask.tid       = 0xffffffffffffffffull;
	
	MAI_SET_FILTER_NAME(&filter, "stl_get_portinfo");
	
	rc = mai_filter_create(mai_portinfo_fd, &filter, VFILTER_SHARE | VFILTER_PURGE);
	if (rc != VSTATUS_OK) {
		IB_LOG_WARNRC("Error creating MAI filter; rc:", rc);
		return VSTATUS_BAD;
	}
	
	// do send/recv
	for (i = 0; i < MAD_RETRIES; i++) {
		rc = mai_send_stl_timeout(mai_portinfo_fd, &out_mad, &datalen, VTIMER_1S/4);
		if (rc != VSTATUS_OK) {
			IB_LOG_WARNRC("Error on send; rc:", rc);
			break;
		}
		rc = mai_recv(mai_portinfo_fd, &in_mad, VTIMER_1S/4);
		if (rc == VSTATUS_OK) {
			break;
		} else if (rc != VSTATUS_TIMEOUT) {
			IB_LOG_WARNRC("Error on receive; rc:", rc);
			break;
		}
	}
	
	// remove the MAI filter
	saved_rc = rc;
	rc = mai_filter_delete(mai_portinfo_fd, &filter, VFILTER_SHARE | VFILTER_PURGE);
	if (rc != VSTATUS_OK) {
		IB_LOG_WARNRC("Error deleting MAI filter; rc:", rc);
		IB_EXIT(__func__, VSTATUS_BAD);
		return VSTATUS_BAD;
	}
	
	// did send/receive work?
	if (saved_rc != VSTATUS_OK) {
		IB_EXIT(__func__, saved_rc);
		return saved_rc;
	}
	
	// confirm MAD status
	if ((in_mad.base.status & MAD_STATUS_MASK) != 0) {
		IB_LOG_WARN("Bad MAD status:", in_mad.base.status);
		IB_EXIT(__func__, VSTATUS_BAD);
		return VSTATUS_BAD;
	}
	
	// extract the PortInfo record
     drp = (DRStlSmp_t *)in_mad.data;
     (void)memcpy((void *)pip, (void *)drp->SMPData, sizeof(STL_PORT_INFO)); 
     (void)BSWAP_STL_PORT_INFO(pip); 
	IB_EXIT(__func__, VSTATUS_OK);
	return VSTATUS_OK;
}