Commit f2c0e7ea authored by Andreas Werner's avatar Andreas Werner
Browse files

add code

parent 80406fe9
#ifndef HAL_SENSOR_H_
#define HAL_SENSOR_H_
void halSensor_init(void);
#endif
obj-y = motorcontoller.o nxp/
obj-y = motorcontoller.o hal.o nxp/
#include <gpio.h>
#include <devs.h>
#include <iomux.h>
#include <halSensor.h>
#include <stdbool.h>
struct halSensor {
bool value;
struct gpio_pin *pin;
};
struct halSensor hal[4] = {
{
.value = false,
.pin = NULL,
},
{
.value = false,
.pin = NULL,
},
{
.value = false,
.pin = NULL,
},
{
.value = false,
.pin = NULL,
},
};
static bool hal_irqHandler(struct gpio_pin *pin, uint32_t pinID, void *d) {
struct halSensor *data = d;
data->value = gpioPin_getValue(data->pin);
return false;
}
void halSensor_init(void) {
int i;
int32_t ret;
uint32_t pins[4] = {PTE0, PTE1, PTE16, PTE17};
struct gpio *gpio = gpio_init(GPIO_ID);
CONFIG_ASSERT(gpio);
for (i = 0; i < 4; i++) {
hal[i].pin = gpioPin_init(gpio, pins[i], GPIO_INPUT, GPIO_PULL_UP);
CONFIG_ASSERT(hal[i].pin);
ret = gpioPin_setCallback(hal[i].pin, hal_irqHandler, &hal[i], GPIO_EITHER);
CONFIG_ASSERT(ret >= 0);
ret = gpioPin_enableInterrupt(hal[i].pin);
CONFIG_ASSERT(ret >= 0);
hal[i].value = gpioPin_getValue(hal[i].pin);
}
}
......@@ -15,6 +15,7 @@
#ifdef CONFIG_USE_SBI_AS_STDOUT
# include <sbi_uart.h>
#endif
#include <halSensor.h>
void vApplicationMallocFailedHook() {
printf("Malloc Failed\n");
......@@ -29,6 +30,7 @@ void vApplicationStackOverflowHook( TaskHandle_t xTask, char * pcTaskName) {
void _startNXP();
void NXPMainTask(void *data) {
(void) data;
halSensor_init();
_startNXP();
vTaskDelete(NULL);
}
......
......@@ -36,7 +36,8 @@
#define M1_I_PH_NOM FRAC16(0.20875)
#define M1_U_PH_NOM FRAC16(0.661157024793)
// Mechanical Alignemnt
#define M1_ALIGN_CURRENT FRAC16(0.1875)
//#define M1_ALIGN_CURRENT FRAC16(0.1875)
#define M1_ALIGN_CURRENT FRAC16(0.0875)
#define M1_ALIGN_DURATION (500)
// Application counters
#define M1_CALIB_DURATION (200)
......
......@@ -100,9 +100,11 @@ int NXPmain(void)
//FMSTR_Poll(); // We remove FreeMaster
}*/
//TODO Start demo
#if 0
M1_SetAppSwitch(TRUE);
bDemoMode = TRUE;
ui32SpeedStimulatorCnt = 0;
#endif
return 0;
}
......@@ -217,7 +219,7 @@ void FTM3_isr(void)
*
*@return none
*/
void PDB0_IRQHandler(void)
void PDB0_isr(void)
{
if (PDB0->CH[0].S & PDB_S_ERR_MASK)
{
......@@ -289,6 +291,7 @@ void DemoSpeedStimulator(void)
if (bDemoMode)
{
#if 1
/* Increment speed stimulator counter */
ui32SpeedStimulatorCnt++;
switch (ui32SpeedStimulatorCnt)
......@@ -320,6 +323,9 @@ void DemoSpeedStimulator(void)
default:
break;
}
#else
M1_SetSpeed(FRAC16(2000.0 / M1_N_MAX));
#endif
}
else
{
......
......@@ -8,7 +8,6 @@
#include "mcdrv_twrkv46f150m.h"
#include "fsl_common.h"
#include <system.h>
/*******************************************************************************
* Definitions
......@@ -401,7 +400,10 @@ void InitADC12(void)
ADC->CTRL2 = (ADC_CTRL2_DIV0(5) | ADC_CTRL2_STOP1(1) | ADC_CTRL2_SYNC1(1) | ADC_CTRL2_SIMULT(1));
/* Enable samples 0, 1, 8, 9 */
ADC->SDIS = ADC_SDIS_DS(0xFCFC);
//ADC->SDIS = ADC_SDIS_DS(0xFCFC);
/* Enable samples 1, 2, 8, 9 */
#define BIT(x) (1 << (x))
ADC->SDIS = ADC_SDIS_DS(~(BIT(0) | BIT(1) | BIT(2) | BIT(8) | BIT(9) | BIT(10)));
/* Power-up ADCA and ADCB */
ADC->PWR &= ~(ADC_PWR_PD0_MASK | ADC_PWR_PD1_MASK);
......
......@@ -126,23 +126,23 @@ extern const char bldcCommutationTableComp[16];
#define ADC1_AUX ADC_NO_CHAN
#else
/* BEMF phase A */
#define ADC0_PH_A ADC_NO_CHAN
#define ADC1_PH_A (3)
#define ADC0_PH_A ADC_NO_CHAN // SAMPLE 0
#define ADC1_PH_A (3) // SAMPLE 8
/* BEMF phase B */
#define ADC0_PH_B ADC_NO_CHAN
#define ADC1_PH_B (5)
#define ADC0_PH_B ADC_NO_CHAN // SAMPLE 0
#define ADC1_PH_B (5) // SAMPLE 8
/* BEMF phase C */
#define ADC0_PH_C ADC_NO_CHAN
#define ADC1_PH_C (4)
#define ADC0_PH_C ADC_NO_CHAN // SAMPLE 0
#define ADC1_PH_C (4) // SAMPLE 8
/* DC-bus voltage */
#define ADC0_UDCB ADC_NO_CHAN
#define ADC1_UDCB (2)
#define ADC0_UDCB ADC_NO_CHAN // SAMPLE 1
#define ADC1_UDCB (2) // SAMPLE 9
/* DC-bus current */
#define ADC0_IDCB (4)
#define ADC1_IDCB ADC_NO_CHAN
#define ADC0_IDCB (4) // SAMPLE 2
#define ADC1_IDCB ADC_NO_CHAN // SAMPLE 8
/* Aux channel */
#define ADC0_AUX (2)
#define ADC1_AUX ADC_NO_CHAN
#define ADC0_AUX (2) // SAMPLE 1
#define ADC1_AUX ADC_NO_CHAN // SAMPLE 9
#endif
/******************************************************************************
......
......@@ -5,7 +5,6 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
//vim: ts=4 sw=4 expandtab
/***********************************************************************************************************************
* This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
......@@ -76,10 +75,11 @@ void BOARD_InitBootPins(void)
{
BOARD_InitPins();
PinTool_PWM();
PinTool_UART();
PinTool_OSC();
PinTool_Misc();
PinTool_SPI();
PinTool_ADC();
//PinTool_UART();
//PinTool_OSC();
//PinTool_Misc();
//PinTool_SPI();
}
/* clang-format off */
......@@ -436,3 +436,4 @@ void PinTool_SPI(void)
/***********************************************************************************************************************
* EOF
**********************************************************************************************************************/
//vim: ts=4 sw=4 expandtab
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment