Verfasst am: 21.05.2016, 22:38
Titel: UART Treiber für Raspberry Pi mit Hilfe eines Matlab System
Hallo,
ich bin gerade dabei mir einen UART Treiber für den Pi zu schreiben. Dafür benutze ich ein Matlab System um dann einen Simulink Block erstellen zu können, der als Read und Send Block dient. Zum Testen habe ich Sende und Empfangspin miteinander verbunden.
Das Senden der Daten funktioniert soweit gut und es werden auch die richtigen Werte empfgangen. Das Problem ist nur die empfangenen Daten in den Outout des Matlab System zu bekommen.
Hier einmal das Matlab System:
Code:
classdef UART_read_send < matlab.System...
& coder.ExternalDependency...
& matlab.system.mixin.Propagates...
& matlab.system.mixin.CustomIcon
%
% System object template for a sink block. % % This template includes most, but not all, possible properties, % attributes, and methods that you can implement for a System object in % Simulink.
%
% NOTE: When renaming the class name Sink, the file name and % constructor name must be updated to use the class name.
%
% Copyright 2014 The MathWorks, Inc.
%#codegen
%#ok<*EMCA>
%Include der Struct Definition im C-Code und abgleichen der Namen
coder.cinclude('piData.h');
coder.cstructname(send_struct, 'piData_toFluco_t', 'extern');
%Senden des struct
coder.ceval('pidata_send', obj.fd, obj.packetID, coder.ref(send_struct), obj.size);
function releaseImpl(obj) if coder.target('Rtw') % Call C-function implementing device termination
coder.ceval('uart_close', obj.fd);
else % Place simulation termination code here end end end
methods(Static) function name = getDescriptiveName()
name = 'UART_read_send';
end
function b = isSupportedContext(context)
b = context.isCodeGenTarget('rtw');
end
function updateBuildInfo(buildInfo, context) if context.isCodeGenTarget('rtw') % Update buildInfo
rootDir = fullfile(fileparts(mfilename('fullpath')),'src');
buildInfo.addIncludePaths(rootDir);
% Use the following API's to add include files, sources and % linker flags
addIncludeFiles(buildInfo,'piData.h','uart.h');
addSourceFiles(buildInfo,'piData.c',rootDir);
addSourceFiles(buildInfo,'uart.c',rootDir);
%addLinkFlags(buildInfo,{'-llibSink'});
end end end end
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: piData.h
* Author: Michael
*
* Created on 19. Mai2016, 16:04
*/
#ifndef PIDATA_H
#define PIDATA_H
#include <stdint.h>
#pragma once
// Einstellen, dass die Paket-Structs dicht (ohne Byte-Lücken) gepackt sind
#pragma pack(push, 1)
Die Funktion pidata_parse gibt einen Buffer, welcher ebenfalls dem Struct piData_fromFluco_t entspricht zurück und soll die Werte in den rcv_struct schreiben, der im System intialisiert wird. Wenn ich dann mittels ou1 = rcv_struct.velocity_RCV die ouput zuweisen will kommt folgende Fehlermeldung beim Überspielen auf den Pi:
Code:
The build process will terminate as a result.
Error executing SSH command: make: Entering directory '/home/pi/Test_rtt'
"gcc" -I"./" -O3 -D"MODEL=Test" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ON_TARGET_WAIT_FOR_START=1" -D"ONESTEPFCN=0" -D"EXT_MODE=1" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"ALLOCATIONFCN=0" -D"TID01EQ=0" -D"_USE_TARGET_UDP_=" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"EXIT_FAILURE=1" -D"EXTMODE_DISABLETESTING=" -c ./linuxUDP.c ./ext_svr.c ./ext_work.c ./rtiostream_interface.c ./updown.c ./rtiostream_tcpip.c ./rtiostream_utils.c ./Test.c ./Test_data.c ./ert_main.c ./piData.c ./uart.c
./Test.c: In function âTest_outputâ:
./Test.c:43:20: error: expected â;â before âexpl_tempâ
./Test.c:73:3: error: âexpl_tempâ undeclared (first use in this function)
./Test.c:73:3: note: each undeclared identifier is reported only once for each function it appears in
_Test.mk:125: recipe for target 'linuxUDP.o' failed
make: *** [linuxUDP.o]Error1
make: Leaving directory '/home/pi/Test_rtt'
Es handelt sich dabei um ein Matlab System. Um den Code auszuführen, muss man in Simulink einen Matlab System Block einfügen und das UART_read_send File darin "laden".
Der Code ist so natürlich nicht vollständig. Aber ja, dann wird in jedem Zeitschritt die UART Schnittstelle so lange ausgelesen, bis keine Daten mehr im Puffer sind und dann wird der letzte gültige Wert an Simulink übergeben.
Einstellungen und Berechtigungen
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.