247 lines
15 KiB
TeX
247 lines
15 KiB
TeX
\doxysection{core0.\+h File Reference}
|
|
\hypertarget{core0_8h}{}\label{core0_8h}\index{core0.h@{core0.h}}
|
|
{\ttfamily \#include "{}shared.\+h"{}}\newline
|
|
{\ttfamily \#include "{}CV.\+h"{}}\newline
|
|
\doxysubsubsection*{Macros}
|
|
\begin{DoxyCompactItemize}
|
|
\item
|
|
\Hypertarget{core0_8h_a8cbe85a94beae30d747e6a6e85d1ae77}\label{core0_8h_a8cbe85a94beae30d747e6a6e85d1ae77}
|
|
\#define {\bfseries SIZE\+\_\+\+BYTE\+\_\+\+ARRAY}~5
|
|
\item
|
|
\Hypertarget{core0_8h_a8a9a8f8772123235b03debb48fa8a973}\label{core0_8h_a8a9a8f8772123235b03debb48fa8a973}
|
|
\#define {\bfseries MESSAGE\+\_\+3\+\_\+\+BYTES}~0b11111111110000000000000000000000000001
|
|
\item
|
|
\Hypertarget{core0_8h_acf2f95404177396e3c93496d3b1d709d}\label{core0_8h_acf2f95404177396e3c93496d3b1d709d}
|
|
\#define {\bfseries MESSAGE\+\_\+\+MASK\+\_\+3\+\_\+\+BYTES}~0b11111111111000000001000000001000000001
|
|
\item
|
|
\Hypertarget{core0_8h_a884ecc75183e104a60d283a494d163b6}\label{core0_8h_a884ecc75183e104a60d283a494d163b6}
|
|
\#define {\bfseries MESSAGE\+\_\+4\+\_\+\+BYTES}~0b11111111110000000000000000000000000000000000001
|
|
\item
|
|
\Hypertarget{core0_8h_adf19b4efd2b349355d55755444620350}\label{core0_8h_adf19b4efd2b349355d55755444620350}
|
|
\#define {\bfseries MESSAGE\+\_\+\+MASK\+\_\+4\+\_\+\+BYTES}~0b11111111111000000001000000001000000001000000001
|
|
\item
|
|
\Hypertarget{core0_8h_a1ea7db2e0ad13e6cd1cf221d72d86bb1}\label{core0_8h_a1ea7db2e0ad13e6cd1cf221d72d86bb1}
|
|
\#define {\bfseries MESSAGE\+\_\+5\+\_\+\+BYTES}~0b11111111110000000000000000000000000000000000000000000001
|
|
\item
|
|
\Hypertarget{core0_8h_acdd45d7e2d818186f88953c361831b55}\label{core0_8h_acdd45d7e2d818186f88953c361831b55}
|
|
\#define {\bfseries MESSAGE\+\_\+\+MASK\+\_\+5\+\_\+\+BYTES}~0b11111111111000000001000000001000000001000000001000000001
|
|
\item
|
|
\Hypertarget{core0_8h_ad7e019af7c87ab5b4921a34a69a492e4}\label{core0_8h_ad7e019af7c87ab5b4921a34a69a492e4}
|
|
\#define {\bfseries Program\+Instr\+Verify\+Bit}~0b10
|
|
\item
|
|
\Hypertarget{core0_8h_abc11566d5e50efd3460af5f3d44e1b55}\label{core0_8h_abc11566d5e50efd3460af5f3d44e1b55}
|
|
\#define {\bfseries Program\+Instr\+Verify\+Byte}~0b01
|
|
\item
|
|
\Hypertarget{core0_8h_a53dc68777633668edaa727468e284957}\label{core0_8h_a53dc68777633668edaa727468e284957}
|
|
\#define {\bfseries Program\+Instr\+Write\+Byte}~0b11
|
|
\item
|
|
\Hypertarget{core0_8h_aec939c48b644ea5430553e2aa14966f9}\label{core0_8h_aec939c48b644ea5430553e2aa14966f9}
|
|
\#define {\bfseries Program\+Cmd}(instr, adrmsbits)~((instr$<$$<$2) \texorpdfstring{$\vert$}{|} (adrmsbits))
|
|
\end{DoxyCompactItemize}
|
|
\doxysubsubsection*{Functions}
|
|
\begin{DoxyCompactItemize}
|
|
\item
|
|
\Hypertarget{core0_8h_a8db7b95e52c5a24409a057b5354aacac}\label{core0_8h_a8db7b95e52c5a24409a057b5354aacac}
|
|
float {\bfseries two\+\_\+std\+\_\+dev} (const float arr\mbox{[}$\,$\mbox{]}, uint32\+\_\+t length)
|
|
\item
|
|
\Hypertarget{core0_8h_a051fb7971eec35125457b7b6ff5d0c59}\label{core0_8h_a051fb7971eec35125457b7b6ff5d0c59}
|
|
void {\bfseries adc\+\_\+offset\+\_\+adjustment} (uint32\+\_\+t length)
|
|
\item
|
|
\Hypertarget{core0_8h_ac87bd6623f47a32e08278afe923477fd}\label{core0_8h_ac87bd6623f47a32e08278afe923477fd}
|
|
void {\bfseries acknowledge} ()
|
|
\item
|
|
\Hypertarget{core0_8h_afc9694833148886687130bfc41c0278b}\label{core0_8h_afc9694833148886687130bfc41c0278b}
|
|
void {\bfseries verify\+\_\+cv\+\_\+bit} (uint16\+\_\+t cv\+\_\+address, bool bit\+\_\+val, uint8\+\_\+t bit\+\_\+pos)
|
|
\item
|
|
\Hypertarget{core0_8h_a28319b022b8ee5ff0a38ef2581a4967e}\label{core0_8h_a28319b022b8ee5ff0a38ef2581a4967e}
|
|
void {\bfseries verify\+\_\+cv\+\_\+byte} (uint16\+\_\+t cv\+\_\+address, uint8\+\_\+t cv\+\_\+data)
|
|
\item
|
|
\Hypertarget{core0_8h_a48e55d64ba5153b8e12190e3a85c7d94}\label{core0_8h_a48e55d64ba5153b8e12190e3a85c7d94}
|
|
void {\bfseries regular\+\_\+cv\+\_\+write} (uint16\+\_\+t cv\+\_\+index, uint8\+\_\+t cv\+\_\+data)
|
|
\item
|
|
void \mbox{\hyperlink{core0_8h_a5036684f11eb837835390659f9e0c4a9}{program\+\_\+mode}} (uint8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t byte\+\_\+array\mbox{[}$\,$\mbox{]})
|
|
\begin{DoxyCompactList}\small\item\em CV Programming mode function Used on entering programming mode in order to write CV values to persistent flash memory or verify/read bits/bytes from flash. ~\newline
|
|
Refers to NMRA Standard 9.\+2.\+3 ("{}\+Service Mode Programming"{}) or RCN-\/216~\newline
|
|
\end{DoxyCompactList}\item
|
|
\Hypertarget{core0_8h_a278792ebcab284a57b088283d570957e}\label{core0_8h_a278792ebcab284a57b088283d570957e}
|
|
void {\bfseries set\+\_\+outputs} (uint32\+\_\+t functions\+\_\+to\+\_\+set\+\_\+bitmask)
|
|
\item
|
|
\Hypertarget{core0_8h_a38173806a6d7c084467c72ce23cc47a2}\label{core0_8h_a38173806a6d7c084467c72ce23cc47a2}
|
|
void {\bfseries update\+\_\+active\+\_\+functions} (uint32\+\_\+t new\+\_\+function\+\_\+bitmask, uint8\+\_\+t clr\+\_\+bit\+\_\+ind, bool direction\+\_\+change)
|
|
\item
|
|
\Hypertarget{core0_8h_a9ac1fe49e3a7374fa60cdf3996138b2c}\label{core0_8h_a9ac1fe49e3a7374fa60cdf3996138b2c}
|
|
bool {\bfseries error\+\_\+detection} (int8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t \texorpdfstring{$\ast$}{*}byte\+\_\+array)
|
|
\item
|
|
\Hypertarget{core0_8h_a0c3523e21bb4baefbe045caa9e35c2d7}\label{core0_8h_a0c3523e21bb4baefbe045caa9e35c2d7}
|
|
bool {\bfseries is\+\_\+long\+\_\+address} (uint8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t byte\+\_\+array\mbox{[}$\,$\mbox{]})
|
|
\item
|
|
\Hypertarget{core0_8h_a88ebfc9c05785e606880d290dee9216d}\label{core0_8h_a88ebfc9c05785e606880d290dee9216d}
|
|
bool {\bfseries address\+\_\+evaluation} (uint8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t byte\+\_\+array\mbox{[}$\,$\mbox{]})
|
|
\item
|
|
\Hypertarget{core0_8h_ab7c4b425f063f7945344c8209a097eca}\label{core0_8h_ab7c4b425f063f7945344c8209a097eca}
|
|
void {\bfseries instruction\+\_\+evaluation} (uint8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t byte\+\_\+array\mbox{[}$\,$\mbox{]})
|
|
\item
|
|
\Hypertarget{core0_8h_a0ba04419ee6b760e8a19868d3fffc0be}\label{core0_8h_a0ba04419ee6b760e8a19868d3fffc0be}
|
|
bool {\bfseries reset\+\_\+message\+\_\+check} (uint8\+\_\+t number\+\_\+of\+\_\+bytes, const uint8\+\_\+t \texorpdfstring{$\ast$}{*}const byte\+\_\+array)
|
|
\item
|
|
\Hypertarget{core0_8h_afe010c2c968965623f9a7409a997b1a8}\label{core0_8h_afe010c2c968965623f9a7409a997b1a8}
|
|
int8\+\_\+t {\bfseries verify\+\_\+dcc\+\_\+message} ()
|
|
\item
|
|
\Hypertarget{core0_8h_ac801d52a750572fda6908c63ab265571}\label{core0_8h_ac801d52a750572fda6908c63ab265571}
|
|
void {\bfseries bits\+\_\+to\+\_\+byte\+\_\+array} (int8\+\_\+t number\+\_\+of\+\_\+bytes, uint8\+\_\+t byte\+\_\+array\mbox{[}$\,$\mbox{]})
|
|
\item
|
|
\Hypertarget{core0_8h_a0fc8afa31d573a86427f7e73bdb8a07c}\label{core0_8h_a0fc8afa31d573a86427f7e73bdb8a07c}
|
|
void {\bfseries evaluate\+\_\+message} ()
|
|
\item
|
|
\Hypertarget{core0_8h_a9e63f26cc0e48c67410c6729a3798126}\label{core0_8h_a9e63f26cc0e48c67410c6729a3798126}
|
|
void {\bfseries track\+\_\+signal\+\_\+rise} (unsigned int gpio, long unsigned int events)
|
|
\item
|
|
\Hypertarget{core0_8h_aa8ee69201d93bb812e1fe4f5feadbfdf}\label{core0_8h_aa8ee69201d93bb812e1fe4f5feadbfdf}
|
|
void {\bfseries track\+\_\+signal\+\_\+fall} (unsigned int gpio, long unsigned int events)
|
|
\item
|
|
void \mbox{\hyperlink{core0_8h_a10e6b83317f9b22b5264200049a77138}{init\+\_\+outputs}} ()
|
|
\begin{DoxyCompactList}\small\item\em Output initialization function. \end{DoxyCompactList}\item
|
|
uint16\+\_\+t \mbox{\hyperlink{core0_8h_a6682cbc69c5c3fa424609b6f15f3a9fa}{measure\+\_\+base\+\_\+pwm}} (bool direction, uint8\+\_\+t iterations)
|
|
\begin{DoxyCompactList}\small\item\em Measures base pwm duty cycles at which the motor barely starts moving. \end{DoxyCompactList}\item
|
|
void \mbox{\hyperlink{core0_8h_afdf05cec06f673d2763ab0631cbe62f8}{cv\+\_\+setup\+\_\+check}} ()
|
|
\begin{DoxyCompactList}\small\item\em Checks various CV values in order to detect factory condition or pending calibrations. \end{DoxyCompactList}\item
|
|
void \mbox{\hyperlink{core0_8h_aebc81e473ba119c0ce42cacb4efeec69}{init\+\_\+motor\+\_\+pwm}} (uint8\+\_\+t gpio)
|
|
\begin{DoxyCompactList}\small\item\em Function initializes motor PWM for pin specified. \end{DoxyCompactList}\item
|
|
void \mbox{\hyperlink{core0_8h_a2d55adaff96e84bf99460f7c9d24f7a4}{init\+\_\+adc}} ()
|
|
\begin{DoxyCompactList}\small\item\em Initializes ADC. \end{DoxyCompactList}\end{DoxyCompactItemize}
|
|
\doxysubsubsection*{Variables}
|
|
\begin{DoxyCompactItemize}
|
|
\item
|
|
const uint32\+\_\+t \mbox{\hyperlink{core0_8h_a3cb7d222f559f6157b67e5b778b3752d}{clr\+\_\+bit\+\_\+arr}} \mbox{[}6\mbox{]}
|
|
\end{DoxyCompactItemize}
|
|
|
|
|
|
\doxysubsection{Detailed Description}
|
|
Used exclusively by core0
|
|
|
|
\doxysubsection{Function Documentation}
|
|
\Hypertarget{core0_8h_afdf05cec06f673d2763ab0631cbe62f8}\label{core0_8h_afdf05cec06f673d2763ab0631cbe62f8}
|
|
\index{core0.h@{core0.h}!cv\_setup\_check@{cv\_setup\_check}}
|
|
\index{cv\_setup\_check@{cv\_setup\_check}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{cv\_setup\_check()}{cv\_setup\_check()}}
|
|
{\footnotesize\ttfamily void cv\+\_\+setup\+\_\+check (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
Checks various CV values in order to detect factory condition or pending calibrations.
|
|
|
|
Procedure\+:
|
|
\begin{DoxyEnumerate}
|
|
\item Check for flash memory factory condition when found write default values specified in \doxylink{CV_8h_source}{CV.\+h} to flash memory
|
|
\item Check for existing ADC offset setup when not found write 7 to read-\/only CV\+\_\+7 in order to trigger a ADC offset measurement/calibration
|
|
\item Check for base PWM configuration/calibration, run calibration when none is found
|
|
\end{DoxyEnumerate}\Hypertarget{core0_8h_a2d55adaff96e84bf99460f7c9d24f7a4}\label{core0_8h_a2d55adaff96e84bf99460f7c9d24f7a4}
|
|
\index{core0.h@{core0.h}!init\_adc@{init\_adc}}
|
|
\index{init\_adc@{init\_adc}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{init\_adc()}{init\_adc()}}
|
|
{\footnotesize\ttfamily void init\+\_\+adc (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
Initializes ADC.
|
|
|
|
Function initializes ADC, corresponding GPIO pins and ADC FIFO \Hypertarget{core0_8h_aebc81e473ba119c0ce42cacb4efeec69}\label{core0_8h_aebc81e473ba119c0ce42cacb4efeec69}
|
|
\index{core0.h@{core0.h}!init\_motor\_pwm@{init\_motor\_pwm}}
|
|
\index{init\_motor\_pwm@{init\_motor\_pwm}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{init\_motor\_pwm()}{init\_motor\_pwm()}}
|
|
{\footnotesize\ttfamily void init\+\_\+motor\+\_\+pwm (\begin{DoxyParamCaption}\item[{uint8\+\_\+t}]{gpio }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
Function initializes motor PWM for pin specified.
|
|
|
|
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em gpio} & GPIO pin \\
|
|
\hline
|
|
\end{DoxyParams}
|
|
\Hypertarget{core0_8h_a10e6b83317f9b22b5264200049a77138}\label{core0_8h_a10e6b83317f9b22b5264200049a77138}
|
|
\index{core0.h@{core0.h}!init\_outputs@{init\_outputs}}
|
|
\index{init\_outputs@{init\_outputs}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{init\_outputs()}{init\_outputs()}}
|
|
{\footnotesize\ttfamily void init\+\_\+outputs (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
Output initialization function.
|
|
|
|
Initializes all allowed GPIO outputs as outputs ~\newline
|
|
Sets PWM functionality for GPIOs configured as PWM pins CV\+\_\+112 -\/ CV\+\_\+115 (see \doxylink{CV_8h_source}{CV.\+h} for reference) ~\newline
|
|
PWM frequency and clock divider are configured according to CV\+\_\+116 -\/ CV\+\_\+171 (see \doxylink{CV_8h_source}{CV.\+h} for reference) ~\newline
|
|
\Hypertarget{core0_8h_a6682cbc69c5c3fa424609b6f15f3a9fa}\label{core0_8h_a6682cbc69c5c3fa424609b6f15f3a9fa}
|
|
\index{core0.h@{core0.h}!measure\_base\_pwm@{measure\_base\_pwm}}
|
|
\index{measure\_base\_pwm@{measure\_base\_pwm}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{measure\_base\_pwm()}{measure\_base\_pwm()}}
|
|
{\footnotesize\ttfamily uint16\+\_\+t measure\+\_\+base\+\_\+pwm (\begin{DoxyParamCaption}\item[{bool}]{direction, }\item[{uint8\+\_\+t}]{iterations }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
Measures base pwm duty cycles at which the motor barely starts moving.
|
|
|
|
Function starts with 1/20 of the maximum duty cycle then increases the duty cycle by 1/500 of the maximum until the motor movement can be measured. This is done for the specified amount of iterations. The array with raw measurements values is then passed to two\+\_\+std\+\_\+dev() in order to detect outliers and calculate the average.\+An additional correction factor is applied and the overall measurement result is then returned. In case no motor movement could be measured a value of 0 is returned and normally written to flash, indicating a pending calibration next time the decoder starts, rerunning the calibration.
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em direction} & Specifies direction which is to be measured \\
|
|
\hline
|
|
{\em iterations} & Specifies the amount of iterations the measurement is to be repeated and averaged out over \\
|
|
\hline
|
|
\end{DoxyParams}
|
|
\begin{DoxyReturn}{Returns}
|
|
Measurement
|
|
\end{DoxyReturn}
|
|
\Hypertarget{core0_8h_a5036684f11eb837835390659f9e0c4a9}\label{core0_8h_a5036684f11eb837835390659f9e0c4a9}
|
|
\index{core0.h@{core0.h}!program\_mode@{program\_mode}}
|
|
\index{program\_mode@{program\_mode}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{program\_mode()}{program\_mode()}}
|
|
{\footnotesize\ttfamily void program\+\_\+mode (\begin{DoxyParamCaption}\item[{uint8\+\_\+t}]{number\+\_\+of\+\_\+bytes, }\item[{const uint8\+\_\+t}]{byte\+\_\+array\mbox{[}$\,$\mbox{]} }\end{DoxyParamCaption})}
|
|
|
|
|
|
|
|
CV Programming mode function Used on entering programming mode in order to write CV values to persistent flash memory or verify/read bits/bytes from flash. ~\newline
|
|
Refers to NMRA Standard 9.\+2.\+3 ("{}\+Service Mode Programming"{}) or RCN-\/216~\newline
|
|
|
|
|
|
Procedure\+:
|
|
\begin{DoxyEnumerate}
|
|
\item Checks for valid programming command
|
|
\item Disables core1 timers
|
|
\item Resets core1
|
|
\item Saves interrupts
|
|
\item Evaluates the type of programming instruction Write byte / Verify byte / Verify bit and runs corresponding function
|
|
\item Restores interrupts
|
|
\item Launch core1
|
|
\end{DoxyEnumerate}
|
|
|
|
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em number\+\_\+of\+\_\+bytes} & Number of bytes in byte\+\_\+array\mbox{[}\mbox{]} \\
|
|
\hline
|
|
{\em byte\+\_\+array} & Pointer to byte\+\_\+array\mbox{[}\mbox{]} \\
|
|
\hline
|
|
\end{DoxyParams}
|
|
|
|
|
|
\doxysubsection{Variable Documentation}
|
|
\Hypertarget{core0_8h_a3cb7d222f559f6157b67e5b778b3752d}\label{core0_8h_a3cb7d222f559f6157b67e5b778b3752d}
|
|
\index{core0.h@{core0.h}!clr\_bit\_arr@{clr\_bit\_arr}}
|
|
\index{clr\_bit\_arr@{clr\_bit\_arr}!core0.h@{core0.h}}
|
|
\doxysubsubsection{\texorpdfstring{clr\_bit\_arr}{clr\_bit\_arr}}
|
|
{\footnotesize\ttfamily const uint32\+\_\+t clr\+\_\+bit\+\_\+arr\mbox{[}6\mbox{]}}
|
|
|
|
{\bfseries Initial value\+:}
|
|
\begin{DoxyCode}{0}
|
|
\DoxyCodeLine{=\ \{}
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b11111111111111111111111111100000,\ }
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b11111111111111111111111000011111,\ }
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b11111111111111111110000111111111,\ }
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b11111111111000000001111111111111,\ }
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b11100000000111111111111111111111,\ }
|
|
\DoxyCodeLine{\ \ \ \ \ \ \ \ 0b00011111111111111111111111111111,\ }
|
|
\DoxyCodeLine{\}}
|
|
|
|
\end{DoxyCode}
|