//initialize routine
void Initialize(void) 
{ 
	InitializeIO(); //set up IO (directions and functions)
//	OpenSPI(SPI_FOSC_16, MODE_00, SMPMID); //open SPI1 
	spi1_open(); //open SPI1
	nrf24l01_initialize_debug(true, 1, false); //initialize the 24L01 to the debug configuration as TX, 1 data byte, and auto-ack disabled
} 
Example #2
0
void init_task(uint_32 initial_data)
{
  _task_id task_id;

  printf("\n Initialize IO \n");
  InitializeIO();

  task_id = _task_create(0, LED1_TASK, 0);
  if (task_id == MQX_NULL_TASK_ID)
    {
      printf("\n Could not create LED1_TASK\n");
    }
  else
    {
      printf("\n LED1_TASK created \n");
    }

  task_id = _task_create(0, LED2_TASK, 0);
  if (task_id == MQX_NULL_TASK_ID)
    {
      printf("\n Could not create LED2_TASK\n");
    }
  else
    {
      printf("\n LED2_TASK created \n");
    }

  task_id = _task_create(0, LED3_TASK, 0);
  if (task_id == MQX_NULL_TASK_ID)
    {
      printf("\n Could not create LED3_TASK\n");
    }
  else
    {
      printf("\n LED3_TASK created \n");
    }

  task_id = _task_create(0, LED4_TASK, 0);
  if (task_id == MQX_NULL_TASK_ID)
    {
      printf("\n Could not create LED4_TASK\n");
    }
  else
    {
      printf("\n LED4_TASK created \n");
    }
  
  task_id = task_create(0,RTC_TASK,0);
  if (task_id == MQX_NULL_TASK_ID)
    {
      printf("\n Could not create RTC_TASK\n");
    }
  else
    {
      printf("\n RTC_TASK created \n");
    }
}
Example #3
0
void Initialize()
{
    int pbClk = SYSTEMConfigPerformance(SYS_FREQ);
    InitializeIO(); //set up IO (directions and functions)
    initUART1(pbClk);
    SpiInitDevice(1, 1, 0, 0);
    nrf24l01_initialize_debug(true, width, false); //initialize the 24L01 to the debug configuration as RX, 1 data byte, and auto-ack disabled

}
int CVxParamArray::Initialize(vx_context context, vx_graph graph, const char * desc)
{
	// get object parameters and create object
	char objType[64];
	const char * ioParams = ScanParameters(desc, "array|virtual-array:", "s:", objType);
	if (!_stricmp(objType, "array") || !_stricmp(objType, "virtual-array") ||
		!_stricmp(objType, "array-virtual"))
	{
		// syntax: [virtual-]array:<format>,<capacity>[:<io-params>]
		char itemType[64];
		ioParams = ScanParameters(ioParams, "<format>,<capacity>", "s,D", &itemType, &m_capacity);
		bool found_userStruct = false;
		for (auto it = m_userStructMap->begin(); it != m_userStructMap->end(); ++it){
			if (strcmp(itemType, it->first.c_str()) == 0){
				found_userStruct = true;
				m_format = it->second;
			}
		}
		if (found_userStruct == false){
			m_format = ovxName2Enum(itemType);
			if (m_format == 0) {
				ReportError("ERROR: invalid array item type specified: %s\n", itemType);
			}
		}
		// create array object
		if (!_stricmp(objType, "virtual-array") || !_stricmp(objType, "array-virtual")) {
			m_array = vxCreateVirtualArray(graph, m_format, m_capacity);
			m_isVirtualObject = true;
		}
		else {
			m_array = vxCreateArray(context, m_format, m_capacity);
		}
	}
	else ReportError("ERROR: unsupported array type: %s\n", desc);
	vx_status ovxStatus = vxGetStatus((vx_reference)m_array);
	if (ovxStatus != VX_SUCCESS){
		printf("ERROR: array creation failed => %d (%s)\n", ovxStatus, ovxEnum2Name(ovxStatus));
		if (m_array) vxReleaseArray(&m_array);
		throw - 1;
	}
	m_vxObjRef = (vx_reference)m_array;

	// io initialize
	return InitializeIO(context, graph, m_vxObjRef, ioParams);
}
Example #5
0
int CVxParamDistribution::Initialize(vx_context context, vx_graph graph, const char * desc)
{
	// get object parameters and create object
	char objType[64];
	const char * ioParams = ScanParameters(desc, "distribution:<numBins>,<offset>,<range>", "s:D,d,d", objType, &m_numBins, &m_offset, &m_range);
	if (!_stricmp(objType, "distribution")) {
		m_distribution = vxCreateDistribution(context, m_numBins, m_offset, m_range);
	}
	else ReportError("ERROR: unsupported distribution type: %s\n", desc);
	vx_status ovxStatus = vxGetStatus((vx_reference)m_distribution);
	if (ovxStatus != VX_SUCCESS){
		printf("ERROR: distribution creation failed => %d (%s)\n", ovxStatus, ovxEnum2Name(ovxStatus));
		if (m_distribution) vxReleaseDistribution(&m_distribution);
		throw - 1;
	}
	m_vxObjRef = (vx_reference)m_distribution;

	// io initialize
	return InitializeIO(context, graph, m_vxObjRef, ioParams);
}
int CVxParamRemap::Initialize(vx_context context, vx_graph graph, const char * desc)
{
	// get object parameters and create object
	//   syntax: remap:<srcWidth>,<srcHeight>,<dstWidth>,<dstHeight>[:<io-params>]
	char objType[64];
	const char * ioParams = ScanParameters(desc, "remap:<srcWidth>,<srcHeight>,<dstWidth>,<dstHeight>", "s:d,d,d,d", objType, &m_srcWidth, &m_srcHeight, &m_dstWidth, &m_dstHeight);
	if (!_stricmp(objType, "remap")) {
		m_remap = vxCreateRemap(context, m_srcWidth, m_srcHeight, m_dstWidth, m_dstHeight);
	}
	else ReportError("ERROR: invalid remap type: %s\n", objType);
	vx_status ovxStatus = vxGetStatus((vx_reference)m_remap);
	if (ovxStatus != VX_SUCCESS){
		printf("ERROR: pyramid creation failed => %d (%s)\n", ovxStatus, ovxEnum2Name(ovxStatus));
		if (m_remap) vxReleaseRemap(&m_remap);
		throw - 1;
	}

	// io initialize
	return InitializeIO(context, graph, (vx_reference)m_remap, ioParams);
}
Example #7
0
int CVxParamMatrix::Initialize(vx_context context, vx_graph graph, const char * desc)
{
	// get object parameters and create object
	char objType[64], data_type[64];
	const char * ioParams = ScanParameters(desc, "matrix:<data-type>,<columns>,<rows>", "s:s,D,D", objType, data_type, &m_columns, &m_rows);
	if (!_stricmp(objType, "matrix")) {
		m_data_type = ovxName2Enum(data_type);
		m_matrix = vxCreateMatrix(context, m_data_type, m_columns, m_rows);
	}
	else ReportError("ERROR: unsupported matrix type: %s\n", desc);
	vx_status ovxStatus = vxGetStatus((vx_reference)m_matrix);
	if (ovxStatus != VX_SUCCESS){
		printf("ERROR: matrix creation failed => %d (%s)\n", ovxStatus, ovxEnum2Name(ovxStatus));
		if (m_matrix) vxReleaseMatrix(&m_matrix);
		throw - 1;
	}
	m_vxObjRef = (vx_reference)m_matrix;

	// io initialize
	return InitializeIO(context, graph, m_vxObjRef, ioParams);
}
Example #8
0
c4_FileStrategy::c4_FileStrategy(FILE *file_): _file(file_), _cleanup(0)
{
    InitializeIO();
    ResetFileMapping();
}
Example #9
0
/* Main loop */
void main() 
{
	static unsigned char value;
	static unsigned char oldValue;
	static unsigned char i;
	static unsigned char j;
	
	// Initialize
	InitializeIO();  

	// Initialialy turn everything off
	PORTA = 0xFF;
	PORTB = 0xFF;
	
	// Wait a while for the 136 to become stable
	for (i = 0; i != 0xFF; i++) {
		for (j = 0; j != 0xFF; j++) {
			// Do nothing
		}
	}
	
	// Main loop
	oldValue = 0;
	// Enable reception
	CREN = 1;
	while (1) 
	{
		if (RCIF)
		{
			if (FERR) 
			{
				// Framing error, just read, but do not process
				i = RCREG;
			}
			else 
			{
				// Read data
				value = RCREG;
			}
			if (value == oldValue) 
			{
				// Only update relays if we've received the same result twice
				SET(RA0, 0x01);
				SET(RB4, 0x02);
				SET(RA3, 0x04);
				SET(RB0, 0x08);
				SET(RA1, 0x10);
				SET(RB3, 0x20);
				SET(RA2, 0x40);
				SET(RB5, 0x80);
			}
			oldValue = value;

			if (OERR)
			{
				// Overrun error
				// Reset 
				CREN = 0;
				// Now re-activate
				CREN = 1;
			}
		}
	}
}
Example #10
0
void main(void) {
    // Enable UART for serial output display
    Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);

#ifdef INVERT_UART
    baud1USART(BAUD_IDLE_TX_PIN_STATE_LOW & BAUD_IDLE_RX_PIN_STATE_LOW & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_ON);
#else
    baud1USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_ON);
#endif

    // I/O states will be held until DSCONL.RELEASE = 0, but we must still initialize
    // to what we want before clearing the RELEASE bit.
    InitializeIO();

#ifdef USE_32KHZ_CRYSTAL
    // Enable the Secondary Oscillator for RTCC use.
    OpenTimer1(TIMER_INT_OFF & T1_SOURCE_PINOSC & T1_PS_1_1 & T1_OSC1EN_ON & T1_SYNC_EXT_OFF, 0);
#endif

    // Did we wake up from Deep Sleep? Or is this the first initial power on?
    if (WDTCONbits.DS) {
        // woke up from Deep Sleep
        DSCONLbits.RELEASE = 0; // release control and data bits for all I/Os

        wait(); // allow time for INTOSC to stablize before using UART
        printf("Woke from Deep Sleep via ");
        if (DSWAKEHbits.DSINT0 != 0) {
            printf("RB0/INT0\r\n");
        } else if (DSWAKELbits.DSMCLR != 0) {
            printf("MCLR\r\n");
        } else if (DSWAKELbits.DSFLT != 0) {
            printf("DSFLT\n");
        } else if (DSWAKELbits.DSWDT != 0) {
            printf("DSWDT\n");
        } else if (DSWAKELbits.DSRTC != 0) {
            printf("RTCC Alarm\n");
        }
    } else {
        // first initial power up of the device.
        // unlock the RTCC registers so that we can write to them
        EECON2 = 0x55;
        EECON2 = 0xAA;
        RTCCFGbits.RTCWREN = 1;

        // reset RTCC date/time (only on first power on)
        RTCCFGbits.RTCPTR1 = 1;
        RTCCFGbits.RTCPTR0 = 1;
        RTCVALL = 0x09; // reserved | year
        RTCVALH = 0xFF;

        RTCVALL = 0x01; // month | day
        RTCVALH = 0x01;

        RTCVALL = 0x12; // weekday | hours
        RTCVALH = 0x01;

        RTCVALL = 0x00; // minutes | seconds
        RTCVALH = 0x00;

        RTCCFGbits.RTCEN = 1; // enable RTCC module
        RTCCAL = RTCCALIBRATION;

        wait(); // allow time for INTOSC to stablize before using UART
    }

    // Application Tasks
    DoApplicationTasks();

    // Power down into Deep Sleep mode.
    printf("Powering down into deep sleep, push RB0/INT0 down to wake...\r\n");
    Flush1USART();
    Close1USART();
    RB0ReleasedWait(); // wait for user to release INT0 so we don't get spurious wake up

EnterDeepSleepMode:
    EnableINT0();
    EnterDeepSleep();

    // Execution should normally never reach here, as Deep Sleep powers up
    // at the Reset Vector.
    //
    // However, there exists a small possibility an INT0 wake up is triggered
    // before the processor has fully enter Deep Sleep mode. As a result, gaurd
    // code is required here to handle re-initiating Deep Sleep entry.
    goto EnterDeepSleepMode;
}
int CVxParamTensor::Initialize(vx_context context, vx_graph graph, const char * desc)
{
	// get object parameters and create object
	const char * ioParams = desc;
	if (!_strnicmp(desc, "tensor:", 7) || !_strnicmp(desc, "virtual-tensor:", 15)) {
		bool isVirtual = false;
		if (!_strnicmp(desc, "virtual-tensor:", 15)) {
			isVirtual = true;
			desc += 8;
		}
		char objType[64], data_type[64];
		ioParams = ScanParameters(desc, "tensor:<num-of-dims>,{dims},<data-type>,<fixed-point-pos>", "s:D,L,s,d", objType, &m_num_of_dims, &m_num_of_dims, m_dims, data_type, &m_fixed_point_pos);
		m_data_type = ovxName2Enum(data_type);
		if (isVirtual) {
			m_tensor = vxCreateVirtualTensor(graph, m_num_of_dims, m_dims, m_data_type, m_fixed_point_pos);
		}
		else {
			m_tensor = vxCreateTensor(context, m_num_of_dims, m_dims, m_data_type, m_fixed_point_pos);
		}
	}
	else if (!_strnicmp(desc, "tensor-from-roi:", 16)) {
		char objType[64], masterName[64];
		ioParams = ScanParameters(desc, "tensor-from-view:<tensor>,<view>", "s:s,D,L,L", objType, masterName, &m_num_of_dims, &m_num_of_dims, m_start, &m_num_of_dims, m_end);
		auto itMaster = m_paramMap->find(masterName);
		if (itMaster == m_paramMap->end())
			ReportError("ERROR: tensor [%s] doesn't exist for %s\n", masterName, desc);
		vx_tensor masterTensor = (vx_tensor)itMaster->second->GetVxObject();
		m_tensor = vxCreateTensorFromView(masterTensor, m_num_of_dims, m_start, m_end);
	}
	else if (!_strnicmp(desc, "tensor-from-handle:", 19)) {
		char objType[64], data_type[64], memory_type_str[64];
		ioParams = ScanParameters(desc, "tensor-from-handle:<num-of-dims>,{dims},<data-type>,<fixed-point-pos>,{strides},<num-handles>,<memory-type>",
			"s:D,L,s,d,L,D,s", objType, &m_num_of_dims, &m_num_of_dims, m_dims, data_type, &m_fixed_point_pos, &m_num_of_dims, m_stride, &m_num_handles, memory_type_str);
		if(m_num_handles > MAX_BUFFER_HANDLES)
			ReportError("ERROR: num-handles is out of range: " VX_FMT_SIZE " (must be less than %d)\n", m_num_handles, MAX_BUFFER_HANDLES);
		m_data_type = ovxName2Enum(data_type);
		vx_uint64 memory_type = 0;
		if (GetScalarValueFromString(VX_TYPE_ENUM, memory_type_str, &memory_type) < 0)
			ReportError("ERROR: invalid memory type enum: %s\n", memory_type_str);
		m_memory_type = (vx_enum)memory_type;
		memset(m_memory_handle, 0, sizeof(m_memory_handle));
		if (m_memory_type == VX_MEMORY_TYPE_HOST) {
			// allocate all handles on host
			for (vx_size active_handle = 0; active_handle < m_num_handles; active_handle++) {
				vx_size size = m_dims[m_num_of_dims-1] * m_stride[m_num_of_dims-1];
				m_memory_handle[active_handle] = malloc(size);
				if (!m_memory_handle[active_handle])
					ReportError("ERROR: malloc(%d) failed\n", (int)size);
			}
		}
#if ENABLE_OPENCL
		else if (m_memory_type == VX_MEMORY_TYPE_OPENCL) {
			// allocate all handles on opencl
			cl_context opencl_context = nullptr;
			vx_status status = vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_AMD_OPENCL_CONTEXT, &opencl_context, sizeof(opencl_context));
			if (status)
				ReportError("ERROR: vxQueryContext(*,VX_CONTEXT_ATTRIBUTE_AMD_OPENCL_CONTEXT,...) failed (%d)\n", status);
			for (vx_size active_handle = 0; active_handle < m_num_handles; active_handle++) {
				vx_size size = m_dims[m_num_of_dims-1] * m_stride[m_num_of_dims-1];
				cl_int err = CL_SUCCESS;
				m_memory_handle[active_handle] = clCreateBuffer(opencl_context, CL_MEM_READ_WRITE, size, NULL, &err);
				if (!m_memory_handle[active_handle] || err)
					ReportError("ERROR: clCreateBuffer(*,CL_MEM_READ_WRITE,%d,NULL,*) failed (%d)\n", (int)size, err);
			}
		}
#endif
		else ReportError("ERROR: invalid memory-type enum: %s\n", memory_type_str);
		m_active_handle = 0;
		m_tensor = vxCreateTensorFromHandle(context, m_num_of_dims, m_dims, m_data_type, m_fixed_point_pos, m_stride, m_memory_handle[m_active_handle], m_memory_type);
	}
	else ReportError("ERROR: unsupported tensor type: %s\n", desc);
	vx_status ovxStatus = vxGetStatus((vx_reference)m_tensor);
	if (ovxStatus != VX_SUCCESS){
		printf("ERROR: tensor creation failed => %d (%s)\n", ovxStatus, ovxEnum2Name(ovxStatus));
		if (m_tensor) vxReleaseTensor(&m_tensor);
		throw - 1;
	}
	m_vxObjRef = (vx_reference)m_tensor;

	// io initialize
	return InitializeIO(context, graph, m_vxObjRef, ioParams);
}