Exemplo n.º 1
0
		void sendMemLoc(uint32_t * ptr) {

			printLF();

			printser_string("Address [0x");

			printser_uint32ToHex((uint32_t) ptr);

			printser_string("] = Value 0x");

			printser_uint32ToHex(&ptr);

		}
Exemplo n.º 2
0
		void sendCPUInfo() {

			printLF();

			printser_string("CPU ID: 0x");

			printser_uint32ToHex(SCB->CPUID);

		}
Exemplo n.º 3
0
void odp_canraw_printParam(UBaseType_t msgType, void *data,
			   printChar_cbf printchar)
{
    param_data *args = data;
    extern bus_paramPrint actBus_paramPrint;
    if (args->args[ARG_CMD] == PARAM_INFO
	&& args->args[ARG_VALUE_1] == VALUE_PARAM_INFO_VERSION) {
	printser_string("0 - Raw CAN");
	printLF();
	printEOT();
    } else {
	createCommandResultMsg(FBID_PROTOCOL_GENERIC,
			       FBID_PROTOCOL_GENERIC, 0,
			       ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);
    }
}
Exemplo n.º 4
0
void print_telegram(UBaseType_t msgType, void *data,
		    printChar_cbf printchar)
{
    static data_packet *dp;
    dp = data;
    printser_string("# ");
    printser_int(dp->timestamp * portTICK_PERIOD_MS, 10);
    printser_string(" 0x");
    printser_int(dp->recv, 16);
    printser_string(" 0x");
    printser_int(dp->err, 16);
    printser_string(" ");
    printser_int(dp->len, 10);
    printser_string(" ");
    int i;
    for (i = 0; i < dp->len; i++) {
	printser_uint8ToHex(dp->data[i]);
	printser_string(" ");
    }
    printLF();
}
Exemplo n.º 5
0
void obp_canraw(void *pvParameters)
{
//>>>> oobdtemple protocol initmain  >>>>
    int keeprunning = 1;
    data_packet *dp;
    data_packet actDataPacket;
    UBaseType_t busToUse = *(UBaseType_t *) pvParameters;
/* function pointers to the bus interface */
    extern bus_init actBus_init;
    extern bus_send actBus_send;
    extern bus_flush actBus_flush;
    extern bus_param actBus_param;
    extern bus_close actBus_close;
    extern QueueHandle_t protocolQueue;
    extern QueueHandle_t outputQueue;
    extern QueueHandle_t inputQueue;
    MsgData *msg;
    MsgData *ownMsg;
    param_data *args;
    extern SemaphoreHandle_t protocollBinarySemaphore;
    UBaseType_t msgType;
    UBaseType_t timeout = 0;
    int i;
    //catch the "Protocoll is running" Semaphore
    xSemaphoreTake(protocollBinarySemaphore, portMAX_DELAY);
    /* activate the bus... */
    odbarr[busToUse] ();
    actBus_init();
    ODPBuffer *protocolBuffer;
    protocolBuffer = NULL;
    // start with the protocol specific initalisation
//<<<< oobdtemple protocol initmain <<<<
    extern print_cbf printdata_CAN;
    UBaseType_t stateMachine_state = 0;
    UBaseType_t actBufferPos = 0;
    /* tell the Rx-ISR about the function to use for received data */
    busControl(ODB_CMD_RECV, odp_canraw_recvdata);
    protocolBuffer = createODPBuffer(CANRAWBUFFERSIZE);
    if (protocolBuffer == NULL) {
	keeprunning = 0;
    } else {
	protocolBuffer->len = 0;
    }
    extern protocolConfigPtr actProtConfigPtr;
    struct CanRawConfig *protocolConfig;
    protocolConfig = pvPortMalloc(sizeof(struct CanRawConfig));
    if (protocolConfig == NULL) {
	keeprunning = 0;
    } else {
	actProtConfigPtr = protocolConfig;
	protocolConfig->recvID = 0x7DF;
	protocolConfig->separationTime = 0;
	protocolConfig->showBusTransfer = 0;
    }
//>>>> oobdtemple protocol mainloop_start  >>>>    
    for (; keeprunning;) {

	if (MSG_NONE != (msgType = waitMsg(protocolQueue, &msg, portMAX_DELAY)))	// portMAX_DELAY
	    /* handle message */
	{
	    switch (msgType) {
//<<<< oobdtemple protocol mainloop_start <<<<
//>>>> oobdtemple protocol MSG_BUS_RECV  >>>>    
	    case MSG_BUS_RECV:
		dp = msg->addr;
//<<<< oobdtemple protocol MSG_BUS_RECV <<<<
		if (protocolConfig->showBusTransfer > 0) {
		    odp_canraw_dumpFrame(dp, printdata_CAN);
		}
		// no more action, Raw CAN does not manage any answers from the bus
//>>>> oobdtemple protocol MSG_SERIAL_DATA  >>>>    
		break;
	    case MSG_SERIAL_DATA:
//<<<< oobdtemple protocol MSG_SERIAL_DATA <<<<
		if (stateMachine_state == SM_CANRAW_STANDBY) {	/* only if just nothing to do */
		    dp = (data_packet *) msg->addr;
		    // data block received from serial input which need to be handled now
		    if (((protocolBuffer->len) + dp->len) <=
			CANRAWBUFFERSIZE) {
			/* copy the data into the uds- buffer */
			for (i = 0; i < dp->len; i++) {
			    protocolBuffer->data[protocolBuffer->len++] =
				dp->data[i];
			}
		    } else {
			createCommandResultMsg
			    (FBID_PROTOCOL_GENERIC,
			     ERR_CODE_CANRAW_DATA_TOO_LONG_ERR,
			     (protocolBuffer->len) + dp->len,
			     ERR_CODE_CANRAW_DATA_TOO_LONG_ERR_TEXT);
		    }
		}
//>>>> oobdtemple protocol MSG_SERIAL_PARAM_1 >>>>    
		break;
	    case MSG_SERIAL_PARAM:
		args = (UBaseType_t *) msg->addr;
		/*
		 * DEBUGPRINT("protocol parameter received %ld %ld %ld\n",
		 args->args[ARG_RECV], args->args[ARG_CMD],
		 args->args[ARG_VALUE_1]);
		 */
		switch (args->args[ARG_RECV]) {
		case FBID_PROTOCOL_GENERIC:
		    /*
		     *    DEBUGPRINT
		     ("generic protocol parameter received %ld %ld\n",
		     args->args[ARG_CMD], args->args[ARG_VALUE_1]);
		     */
		    switch (args->args[ARG_CMD]) {
		    case PARAM_INFO:
//<<<< oobdtemple protocol MSG_SERIAL_PARAM_1 <<<<
			CreateParamOutputMsg(args, odp_canraw_printParam);
//>>>> oobdtemple protocol MSG_SERIAL_PARAM_2 >>>>    
			break;
			// and here we proceed all command parameters
		    case PARAM_LISTEN:
			xTickCurrent = 0;	// set current Timestamp to "0" if Listen mode ist activated
			protocolConfig->showBusTransfer =
			    args->args[ARG_VALUE_1];
			createCommandResultMsg(FBID_PROTOCOL_GENERIC,
					       ERR_CODE_NO_ERR, 0, NULL);
			break;
		    default:
			createCommandResultMsg
			    (FBID_PROTOCOL_GENERIC,
			     ERR_CODE_OS_UNKNOWN_COMMAND, 0,
			     ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);
			break;
		    }
		    break;
//<<<< oobdtemple protocol MSG_SERIAL_PARAM_2 <<<<
		case FBID_PROTOCOL_SPEC:
		    //DEBUGPRINT ("can raw protocol parameter received %ld %ld\n", args->args[ARG_CMD], args->args[ARG_VALUE_1]);
		    switch (args->args[ARG_CMD]) {
			// first we commend out all parameters  which are not used to generate the right "unknown parameter" message in the default - area
			/*
			   case PARAM_ECHO:
			   break;
			   case PARAM_TIMEOUT_PENDING:
			   break;
			   case PARAM_BLOCKSIZE:
			   break;
			 */
		    case PARAM_CANRAW_FRAME_DELAY:
			protocolConfig->separationTime =
			    args->args[ARG_VALUE_1] + 1;
			createCommandResultMsg(FBID_PROTOCOL_SPEC,
					       ERR_CODE_NO_ERR, 0, NULL);
			break;
		    case PARAM_CANRAW_SENDID:
			protocolConfig->recvID = args->args[ARG_VALUE_1];
			createCommandResultMsg(FBID_PROTOCOL_SPEC,
					       ERR_CODE_NO_ERR, 0, NULL);
			break;
		    default:
			createCommandResultMsg(FBID_PROTOCOL_SPEC,
					       ERR_CODE_OS_UNKNOWN_COMMAND,
					       0,
					       ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);
			break;
		    }
		    break;
//>>>> oobdtemple protocol MSG_OTHERS >>>>    
		case FBID_BUS_GENERIC:
		case FBID_BUS_SPEC:
		    actBus_param(args);	/* forward the received params to the underlying bus. */
		    break;
		default:
		    createCommandResultMsg(FBID_PROTOCOL_SPEC,
					   ERR_CODE_OS_UNKNOWN_COMMAND,
					   0,
					   ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);
		    break;
		}
//<<<< oobdtemple protocol MSG_OTHERS <<<<
//>>>> oobdtemple protocol MSG_INIT >>>>    
	    case MSG_INIT:
		if (protocolBuffer != NULL) {
		    protocolBuffer->len = 0;
		}
//<<<< oobdtemple protocol MSG_INIT <<<<
//>>>> oobdtemple protocol MSG_PROTOCOL_STOP >>>>    
		break;
	    case MSG_PROTOCOL_STOP:
		keeprunning = 0;
		break;
//<<<< oobdtemple protocol MSG_PROTOCOL_STOP <<<<
//>>>> oobdtemple protocol MSG_SEND_BUFFER >>>>    
	    case MSG_SEND_BUFFER:
		/* let's Dance: Starting the transfer protocol */
//<<<< oobdtemple protocol MSG_SEND_BUFFER <<<<
		if (protocolBuffer->len > 0) {
		    actBufferPos = 0;
		    for (; sendMoreFrames(protocolBuffer, &actBufferPos, &protocolConfig->showBusTransfer, &stateMachine_state, &timeout, printdata_CAN, actBus_send););	// fire all in one shot.
//>>>> oobdtemple protocol MSG_SEND_BUFFER_2 >>>>    
		} else {	/* no data to send? */
		    createCommandResultMsg
			(FBID_PROTOCOL_GENERIC, ERR_CODE_NO_ERR, 0, NULL);
		    /* just release the input again */
		    if (pdPASS !=
			sendMsg(MSG_SERIAL_RELEASE, inputQueue, NULL)) {
			printser_string("Input queue is full!");
			DEBUGPRINT
			    ("FATAL ERROR: input queue is full!\n", 'a');
		    }
		}
		break;
//<<<< oobdtemple protocol MSG_SEND_BUFFER_2 <<<<
//>>>> oobdtemple protocol MSG_TICK >>>>    
	    case MSG_TICK:
//<<<< oobdtemple protocol MSG_TICK <<<<
		if (timeout > 0) {	/* we just waiting for the next frame to send */
		    if (timeout == 1) {	/* time's gone... */
			for (; sendMoreFrames(protocolBuffer, &actBufferPos, &protocolConfig->showBusTransfer, &stateMachine_state, &timeout, printdata_CAN, actBus_send););	// fire all in one shot.
			if (timeout < 2) {	//
			    protocolBuffer->len = 0;
			    createCommandResultMsg
				(FBID_PROTOCOL_GENERIC,
				 ERR_CODE_NO_ERR, 0, NULL);
			    stateMachine_state = SM_CANRAW_STANDBY;
			    if (pdPASS !=
				sendMsg(MSG_SERIAL_RELEASE, inputQueue,
					NULL)) {
				printser_string("INPQUE_FULL");
				DEBUGPRINT
				    ("FATAL ERROR: input queue is full!\n",
				     'a');
			    }
			}
		    }
		    timeout--;
		}
//>>>> oobdtemple protocol final >>>>    
		break;
	    }
	    disposeMsg(msg);
	}
	/* vTaskDelay (5000 / portTICK_PERIOD_MS); */

    }

    /* Do all cleanup here to finish task */
    actBus_close();
    vPortFree(protocolConfig);
    freeODPBuffer(protocolBuffer);
    xSemaphoreGive(protocollBinarySemaphore);
    vTaskDelete(NULL);
}
Exemplo n.º 6
0
void odp_canraw_recvdata(data_packet * p, UBaseType_t callFromISR)
{
    extern print_cbf printdata_CAN;
    extern printChar_cbf printChar;
    extern protocolConfigPtr actProtConfigPtr;
    struct CanRawConfig *protocolConfig;
    short ByteCnt;

    if (callFromISR)
	xTickNew = (uint16_t) xTaskGetTickCountFromISR();
    else
	xTickNew = (uint16_t) xTaskGetTickCount();

    if (xTickNew < xTickOld)	// check for xTick overflow
	xTickOld = 0;

    if (xTickCurrent >= 59999)	// limit timestamp to 0-59999 tick (ms)
	xTickCurrent = 0;

    xTickCurrent = xTickCurrent + (xTickNew - xTickOld);
    xTickOld = xTickNew;	// set latest value to xTickOld for next duration
    p->timestamp = xTickCurrent;

    protocolConfig = actProtConfigPtr;
    if (protocolConfig != NULL) {
	if (protocolConfig->showBusTransfer == 1) {	//normal output
	    MsgData *msg;
	    extern QueueHandle_t protocolQueue;
	    if (NULL != (msg = createDataMsg(p))) {
		UBaseType_t res = 0;
		if (callFromISR) {
		    res = sendMsgFromISR(MSG_BUS_RECV, protocolQueue, msg);
		} else {
		    res = sendMsg(MSG_BUS_RECV, protocolQueue, msg);
		}
		if (res != pdPASS) {
		    disposeMsg(msg);
		    DEBUGPRINT("FATAL ERROR: protocol queue is full!\n",
			       'a');
		}
	    } else {
		DEBUGPRINT("FATAL ERROR: Out of Heap space!l\n", 'a');
	    }
	}
	if (protocolConfig->showBusTransfer == 2) {	//normal output, but straight from the ISR
	    printdata_CAN(MSG_BUS_RECV, p, printChar);
	}
	if (protocolConfig->showBusTransfer == 3) {
	    // Lawicel format: Estimated out of http://lxr.free-electrons.com/source/drivers/net/can/slcan.c line 110 cc.
	    if (p->recv & 0x80000000) {	// Bit 32 set, so it's an extended CAN ID
		printser_string("T");
		printser_uint32ToHex(p->recv & 0x1FFFFFFF);
	    } else {
		printser_string("t");
		printser_int((p->recv & 0x700) >> 8, 10);
		printser_uint8ToHex(p->recv & 0x00FF);
	    }
	    printser_int(p->len, 10);
	    ByteCnt = 0;
	    while (ByteCnt != p->len) {
		printser_uint8ToHex(p->data[ByteCnt]);
		ByteCnt++;
	    }
	    if (p->err == 0x01)
		printser_string("FFFF");	// if error occurs set timestamp to 0xFFFF
	    else
		printser_uint16ToHex(p->timestamp * portTICK_PERIOD_MS & 0xFFFF);	//reduce down to 16 bit = 65536 ms = ~ 1 min
	    printLF();
	}
	if (protocolConfig->showBusTransfer == 4) {
	    printser_uint8ToRaw(255);	//startbyte
	    printser_uint8ToRaw((p->len & 0xF) |	// bit 0-3: DLC
				((p->err & 3) << 4) |	//bit 4-5 : Error flag
				(((p->recv & 0x80000000) ? 1 : 0) << 5)	//bit 6: Extended CAN ID
		);		//Status flag
	    printser_uint16ToRawCoded(p->timestamp * portTICK_PERIOD_MS & 0xFFFF);	//reduce down to 16 bit = 65536 ms = ~ 1 min
	    if ((p->recv & 0x80000000)) {	// Bit 32 set, so it's an exended CAN ID
		printser_uint32ToRawCoded(p->recv & 0x1FFFFFFF);
	    } else {
		printser_uint16ToRawCoded(p->recv & 0x1FFFFFFF);
	    }
	    int i;

	    for (i = 0; i < p->len; i++) {
		printser_uint8ToRawCoded(p->data[i]);
	    }
	}
    }
}
Exemplo n.º 7
0
/*-----------------------------------------------------------*/
void bus_param_can_generic_Print(UBaseType_t msgType, void *data,
				 printChar_cbf printchar)
{
    param_data *args = data;
    uint8_t FiltCntr;
    DEBUGPRINT("can Parameter receiced %ld-%ld\n", args->args[ARG_RECV],
	       args->args[ARG_CMD]);
    if (args->args[ARG_CMD] == PARAM_INFO) {
	CAN_GetCanConfig(canConfig);
	switch (args->args[ARG_VALUE_1]) {
	case VALUE_PARAM_INFO_VERSION:
	    printser_string("CAN Bus");
	    printLF();
	    printEOT();
	    break;
	case VALUE_PARAM_INFO_BUS_MODE:
	    switch (canConfig->mode) {
	    case VALUE_BUS_MODE_SILENT:
		printser_string("0 - CAN Transceiver in 'Silent Mode'");
		printLF();
		break;
	    case VALUE_BUS_MODE_LOOP_BACK:
		printser_string("1 - CAN Transceiver in 'Loop Back Mode'");
		printLF();
		break;
	    case VALUE_BUS_MODE_LOOP_BACK_WITH_SILENT:
		printser_string
		    ("2 - CAN Transceiver in 'Loop Back combined with Silent Mode'");
		printLF();
		break;
	    case VALUE_BUS_MODE_NORMAL:
		printser_string("3 - CAN Transceiver in 'Normal Mode'");
		printLF();
		break;
	    }

	    switch (canConfig->state) {
	    case STATE_REQUEST_CAN_ERROR_ACTIVE:
		printser_string("0 - Bus Active");
		printLF();
		break;
	    case STATE_REQUEST_CAN_ERROR_WARNING:
		printser_string("1 - Bus Active, a few errors");
		printLF();
		break;
	    case STATE_REQUEST_CAN_ERROR_PASSIVE:
		printser_string("2 - Bus Passive, many errors");
		printLF();
		break;
	    case STATE_REQUEST_CAN_BUS_OFF:
		printser_string("3 - Bus Off, too many errors");
		printLF();
		break;
	    case STATE_REQUEST_CAN_STOPPED:
		printser_string("4 - Bus offline");
		printLF();
		break;
	    case STATE_REQUEST_CAN_SLEEPING:
		printser_string("5 - Bus sleeping");
		printLF();
		break;
	    case STATE_REQUEST_CAN_UNKNOWN:
		printser_string("6 - no feedback from device");
		printLF();
		break;
	    }
	    printEOT();
	    break;
	case VALUE_PARAM_INFO_BUS_CONFIG:
	    switch (canConfig->busConfig) {
	    case VALUE_BUS_CONFIG_11bit_125kbit:
		printser_string("1 = ISO 15765-4, CAN 11bit ID/125kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_11bit_250kbit:
		printser_string("2 = ISO 15765-4, CAN 11bit ID/250kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_11bit_500kbit:
		printser_string("3 = ISO 15765-4, CAN 11bit ID/500kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_11bit_1000kbit:
		printser_string("4 - ISO 15765-4, CAN 11bit ID/1000kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_29bit_125kbit:
		printser_string("5 - ISO 15765-4, CAN 29bit ID/125kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_29bit_250kbit:
		printser_string("6 - ISO 15765-4, CAN 29bit ID/250kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_29bit_500kbit:
		printser_string("7 - ISO 15765-4, CAN 29bit ID/500kBaud");
		printLF();
		printEOT();
		break;
	    case VALUE_BUS_CONFIG_29bit_1000kbit:
		printser_string("8 - ISO 15765-4, CAN 29bit ID/1000kBaud");
		printLF();
		printEOT();
		break;
	    }
	    break;
	case VALUE_PARAM_INFO_BUS_ERROR:
	    if (VALUE_PARAM_INFO_BUS_ERROR_READ == args->args[ARG_VALUE_2]) {
		printser_int(bus_rx_count_can(), 10);
		printser_string(" ");
		printser_int(bus_rx_error_can(), 10);
		printser_string(" ");
		printser_int(bus_rec_can(), 10);
		printser_string(" ");
		printser_int(bus_tx_count_can(), 10);
		printser_string(" ");
		printser_int(bus_tx_error_can(), 10);
		printser_string(" ");
		printser_int(bus_rec_can(), 10);
		printser_string(" ");
		printser_int(bus_tec_can(), 10);
		printser_string(" ");
		printser_int(bus_busoff_error_can(), 10);
		printser_string(" ");
		printser_int(bus_warning_error_can(), 10);
		printser_string(" ");
		printser_int(bus_passive_error_can(), 10);
	    } else if (VALUE_PARAM_INFO_BUS_ERROR_DEL ==
		       args->args[ARG_VALUE_2]) {
		/* delete counters if parameter is requested with option "1" */
		bus_clear_rx_error_can();
		bus_clear_tx_error_can();
		bus_clear_rx_count_can();
		bus_clear_tx_count_can();
	    } else
		printser_string("Missing parameter!");

	    printLF();
	    printEOT();
	    break;

	case VALUE_PARAM_INFO_Can11FilterID:
	    for (FiltCntr = 0; FiltCntr < MAXCANFILTER; FiltCntr++) {
		printser_string("0x");
		printser_int(CAN_GetFilterReg16(FiltCntr, 1, 0), 16);
		printser_string(" 0x");
		printser_int(CAN_GetFilterReg16(FiltCntr, 1, 1), 16);
		printser_string(" 0x");
		printser_int(CAN_GetFilterReg16(FiltCntr, 2, 0), 16);
		printser_string(" 0x");
		printser_int(CAN_GetFilterReg16(FiltCntr, 2, 1), 16);
		printLF();
	    }
	    printLF();
	    printEOT();
	    break;

	case VALUE_PARAM_INFO_Can29FilterID:
	    for (FiltCntr = 0; FiltCntr < MAXCANFILTER; FiltCntr++) {
		printser_string("0x");
		printser_int(CAN_GetFilterReg32(FiltCntr, 1), 16);
		printser_string(" 0x");
		printser_int(CAN_GetFilterReg32(FiltCntr, 2), 16);
		printLF();
	    }
	    printLF();
	    printEOT();
	    break;

	default:
	    evalResult(FBID_BUS_GENERIC, ERR_CODE_OS_UNKNOWN_COMMAND, 0,
		       ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);

	    break;
	}
    } else {
	evalResult(FBID_BUS_GENERIC, ERR_CODE_OS_UNKNOWN_COMMAND, 0,
		   ERR_CODE_OS_UNKNOWN_COMMAND_TEXT);

    }
}