Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# --- 빌드 결과물 및 임시 파일만 철저히 무시 ---
# 위치와 상관없이 아래 이름의 폴더나 확장자는 무시합니다.
**/TriCore\ Debug\ (TASKING)/**
**/Debug/**
**/.ads/**

*.o
*.d
*.elf
*.hex
*.map
*.src
*.lst
*.pre
*.err
*.launch
*.tmp

# 개인 설정 파일
.settings/
.project
.cproject
97 changes: 97 additions & 0 deletions ACT/Servo_driver/Cpu0_Main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**********************************************************************************************************************
* \file Cpu0_Main.c
*********************************************************************************************************************/
#include "Ifx_Types.h"
#include "IfxScuWdt.h"
#include "IfxPort.h"
#include "IfxStm.h"
#include "IfxCpu.h"
#include "uart_msg.h"
#include "servo.h"
#include "Bsp.h"
#include <time.h>
#include <stdlib.h>

IfxCpu_syncEvent cpuSyncEvent = 0;

#define BTN_PORT &MODULE_P02
#define BTN_PIN 1

void send_random(void)
{
int warning = rand() % 4;
int brake = rand() % 4;
int gear = rand() % 4;
int door = rand() % 2;
int driver = rand() % 4;
int speed = rand() % 10;
sendData(warning, brake, gear, door, driver, speed);
}

void core0_main(void)
{
IfxCpu_enableInterrupts();

IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

IfxCpu_emitEvent(&cpuSyncEvent);
IfxCpu_waitEvent(&cpuSyncEvent, 1);

Driver_Asc0_Init();
srand((unsigned int)IfxStm_getLower(&MODULE_STM0));

uint8 prevState = 0;
IfxPort_setPinModeInput(
BTN_PORT,
BTN_PIN,
IfxPort_InputMode_pullUp
);

Servo_Init();

while (1)
{
/*
// UART
uint8 currState = IfxPort_getPinState(BTN_PORT, BTN_PIN);

if (prevState == 1 && currState == 0)
{
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 20));

if (IfxPort_getPinState(BTN_PORT, BTN_PIN) == 0)
{
send_random();

while (IfxPort_getPinState(BTN_PORT, BTN_PIN) == 0)
{
}
}
}

prevState = currState;
*/
// Servo
uint8 currState = IfxPort_getPinState(BTN_PORT, BTN_PIN);
if (prevState == 1 && currState == 0)
{
if (IfxPort_getPinState(BTN_PORT, BTN_PIN) == 0)
{
if (get_break_state() == 1){
break_off();
}
else{
break_on();
}
while (IfxPort_getPinState(BTN_PORT, BTN_PIN) == 0)
{
}
}
}

break_update();

prevState = currState;
}
}
21 changes: 21 additions & 0 deletions ACT/Servo_driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Servo Driver 사용법

1. 시작할 때 Servo_Init() 호출
2. 브레이크를 걸 때 break_on() 호출
3. 브레이크를 해제할 때 break_off() 호출
4. 메인 루프나 주기 함수에서 break_update()를 계속 호출
5. 현재 상태 확인이 필요하면 get_break_state() 사용

```
Servo_Init();

while (1)
{
if (조건)
break_on();
else
break_off();

break_update();
}
```
122 changes: 122 additions & 0 deletions ACT/Servo_driver/servo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**********************************************************************************************************************
* \file servo.c
* \copyright Copyright (C) Infineon Technologies AG 2019
*
* Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of
* business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
* are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and
* accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
* and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
* Software is furnished to do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including the above license grant, this restriction
* and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are solely in the form of
* machine-executable object code generated by a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*********************************************************************************************************************/


/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "servo.h"

#include "IfxPort.h"
#include "IfxStm.h"
#include "Bsp.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define SERVO_PORT &MODULE_P10
#define SERVO_PIN 2

#define SERVO_PERIOD_US 20000U
#define SERVO_RIGHT_PULSE_US 750U
#define SERVO_CENTER_PULSE_US 1500U
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
static int break_state; // 1 = on, 0 = off
/*********************************************************************************************************************/
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
static void Servo_DelayUs(uint32 us)
{
waitTime(IfxStm_getTicksFromMicroseconds(BSP_DEFAULT_TIMER, us));
}

static void Servo_Hold(uint32 pulseUs, uint32 holdMs)
{
uint32 repeat = holdMs / 20U;

for (uint32 i = 0; i < repeat; i++)
{
uint32 lowUs = SERVO_PERIOD_US - pulseUs;

IfxPort_setPinHigh(SERVO_PORT, SERVO_PIN);
Servo_DelayUs(pulseUs);

IfxPort_setPinLow(SERVO_PORT, SERVO_PIN);
Servo_DelayUs(lowUs);
}
}

void Servo_Init(void)
{
break_state = 0;
IfxPort_setPinModeOutput(
SERVO_PORT,
SERVO_PIN,
IfxPort_OutputMode_pushPull,
IfxPort_OutputIdx_general
);

IfxPort_setPinLow(SERVO_PORT, SERVO_PIN);

Servo_Hold(SERVO_CENTER_PULSE_US, 500);
}

void break_update(void)
{
if (break_state == 1)
{
Servo_Hold(SERVO_CENTER_PULSE_US, 20);
}
else
{
Servo_Hold(SERVO_RIGHT_PULSE_US, 20);
}
}

int get_break_state(void)
{
return break_state;
}

void break_on(void)
{
break_state = 1;
}

void break_off(void)
{
break_state = 0;
}
55 changes: 55 additions & 0 deletions ACT/Servo_driver/servo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**********************************************************************************************************************
* \file servo.h
* \copyright Copyright (C) Infineon Technologies AG 2019
*
* Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of
* business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
* are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and
* accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
* and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
* Software is furnished to do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including the above license grant, this restriction
* and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are solely in the form of
* machine-executable object code generated by a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*********************************************************************************************************************/


/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "Ifx_Types.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/
/*********************************************************************************************************************/

/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
void Servo_Init(void);
void Servo_Run(void);
void break_on(void);
void break_off(void);
int get_break_state(void);
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
Loading