Initial commit

This commit is contained in:
2026-03-31 13:10:37 +02:00
commit 03325b9502
566 changed files with 351758 additions and 0 deletions

58
.gitignore vendored Normal file
View File

@@ -0,0 +1,58 @@
# ── Compilation C / C++ ──────────────────────────────────────────────────────
*.o
*.a
*.so
*.so.*
*.dylib
*.dll
*.exe
*.out
*.elf
*.bin
*.hex
*.map
*.lst
# ── CMake ─────────────────────────────────────────────────────────────────────
build/
cmake-build-*/
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
_deps/
install_manifest.txt
# ── PlatformIO ────────────────────────────────────────────────────────────────
.pio/
.pioenvs/
.piolibdeps/
# ── Raspberry Pi Pico / SDK ───────────────────────────────────────────────────
pico-sdk/
pico-examples/
# (déjà disponibles sur GitHub officiel, inutile de les dupliquer)
# ── Fichiers générés ─────────────────────────────────────────────────────────
*.d
*.dep
generated/
# ── Secrets / Config ──────────────────────────────────────────────────────────
.env
secret.env
secrets.h
config_secret.h
# ── IDE ───────────────────────────────────────────────────────────────────────
.vscode/
.idea/
*.swp
.DS_Store
Thumbs.db
*.user
*.suo
# ── Logs / Debug ─────────────────────────────────────────────────────────────
*.log
*.trace

1
AS5600 Submodule

Submodule AS5600 added at 513463364f

93
AS5600L/AS5600L.c Normal file
View File

@@ -0,0 +1,93 @@
#include "AS5600L.h"
void as560x_init(AS5600L* as5600l, i2c_inst_t *I2C_ID, int frq , int sda, int scl ) {
i2c_init(I2C_ID, frq);
gpio_set_function(sda, GPIO_FUNC_I2C);
gpio_set_function(scl, GPIO_FUNC_I2C);
gpio_pull_up(sda);
gpio_pull_up(scl);
AS5600L_I2C instance_i2c;
instance_i2c.I2C_PORT = I2C_ID;
instance_i2c.FREQUENCE = frq;
instance_i2c.I2C_SDA_PIN = sda;
instance_i2c.I2C_SCL_PIN = scl;
as5600l->serial_instance = instance_i2c;
as5600l->abs_pos = 0;
as5600l->curr_angle = 0;
as5600l->last_angle = 0;
as5600l->start_pos = 0;
as5600l->start_pos = as560xReadAngle(as5600l);
as5600l->abs_pos = 0 - as5600l->start_pos;
}
int update_pos(AS5600L* as5600l){
// sensorData();
as5600l->curr_angle = as560xReadAngle(as5600l);
if(as5600l->last_angle > ENCODER_RESOLUTION/2 & as5600l->curr_angle < (as5600l->last_angle - ENCODER_RESOLUTION/2)){
as5600l->abs_pos = as5600l->abs_pos + ENCODER_RESOLUTION - as5600l->last_angle + as5600l->curr_angle;
}else if(as5600l->curr_angle > ENCODER_RESOLUTION/2 & as5600l->last_angle < (as5600l->curr_angle - ENCODER_RESOLUTION/2) ){
as5600l->abs_pos = as5600l->abs_pos -ENCODER_RESOLUTION - as5600l->last_angle + as5600l->curr_angle;
}else{
as5600l->abs_pos = as5600l->abs_pos - as5600l->last_angle + as5600l->curr_angle;
}
as5600l->last_angle = as5600l->curr_angle;
return as5600l->abs_pos;
}
int __bswap16(int value) {
return (value >> 8) | (value << 8);
}
void i2cError() {
printf("I2C Error\n");
}
int as560xReadReg(AS5600L* as5600l,int addr, bool wide, int mask) {
int buf;
int result = i2c_write_timeout_us(as5600l->serial_instance.I2C_PORT, AS5600L_ADDRESS, (uint8_t *)&addr, 1, true, I2C_TIMEOUT_US);
if (result <= 0) {
i2cError();
}
result = i2c_read_timeout_us(as5600l->serial_instance.I2C_PORT, AS5600L_ADDRESS, (uint8_t *)&buf, (wide ? 2 : 1), false, I2C_TIMEOUT_US);
if (result <= 0) {
i2cError();
}
if (wide) {
return __bswap16(buf) & mask;
} else {
return buf & mask;
}
}
void AS560x_print_reg16(AS5600L* as5600l,const char *formatStr, int addr, int mask) {
int result = as560xReadReg(as5600l,addr, true, mask);
printf(formatStr, result & mask);
}
void AS560x_print_reg8(AS5600L* as5600l,const char *formatStr, int addr, uint8_t mask) {
uint8_t result = (uint8_t)as560xReadReg(as5600l,addr, false, mask);
printf(formatStr, result & mask);
}
int as560xReadAngle(AS5600L* as5600l) {
return as560xReadReg(as5600l,AS560x_RAW_ANGLE_REG, true, 0xFFF) ;
}
uint8_t as560xGetStatus(AS5600L* as5600l) {
return (uint8_t)as560xReadReg(as5600l,AS560x_STATUS_REG, false, 0x38);
}
void sensorData(AS5600L* as5600l) {
AS560x_print_reg8(as5600l,"Status: %02x; ", AS560x_STATUS_REG, 0x38);
AS560x_print_reg8(as5600l,"AGC: %3x; ", 0x1a, 0xff);
AS560x_print_reg16(as5600l,"Angle: %d\n\r", AS560x_RAW_ANGLE_REG, 0xFFF);
}

47
AS5600L/AS5600L.h Normal file
View File

@@ -0,0 +1,47 @@
#ifndef AS5600L_H
#define AS5600L_H
#include "hardware/i2c.h"
#include "pico/stdlib.h"
#include "pico/time.h"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#define I2C_TIMEOUT_US (100000)
#define AS560x_STATUS_REG (0x0B)
#define AS560x_RAW_ANGLE_REG (0x0C)
#define AS5600L_ADDRESS 0x40
#define ENCODER_RESOLUTION 4096
typedef struct {
i2c_inst_t *I2C_PORT;
int FREQUENCE;
int I2C_SDA_PIN;
int I2C_SCL_PIN;
} AS5600L_I2C;
typedef struct {
AS5600L_I2C serial_instance;
int last_angle;
int curr_angle ;
int abs_pos ;
int start_pos;
} AS5600L;
void as560x_init(AS5600L* as5600l, i2c_inst_t *I2C_ID, int frq , int sda, int scl);
int update_pos(AS5600L* as5600l);
int __bswap16(int value);
void i2cError();
int as560xReadReg(AS5600L* as5600l,int addr, bool wide, int mask);
void AS560x_print_reg16(AS5600L* as5600l,const char *formatStr, int addr, int mask);
void AS560x_print_reg8(AS5600L* as5600l,const char *formatStr, int addr, uint8_t mask);
int as560xReadAngle(AS5600L* as5600l);
uint8_t as560xGetStatus(AS5600L* as5600l);
void sensorData(AS5600L* as5600l);
#endif /* AS5600L_H */

32
AS5600L/CMakeLists.txt Normal file
View File

@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.12)
#cmake -G "MinGW Makefiles" ..
set(PROJECT_NAME "AS5600L_test")
set(PICO_SDK_PATH "E:/Beyon_Motion/pico-sdk")
set(PICO_TOOLCHAIN_PATH "C:/Users/spide/scoop/apps/gcc-arm-none-eabi/current/bin")
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(${PROJECT_NAME} C CXX ASM)
pico_sdk_init()
add_executable(${PROJECT_NAME}
main.c
AS5600L.c
AS5600L.h
)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
hardware_i2c
hardware_dma
)
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
pico_add_extra_outputs(${PROJECT_NAME})

28
AS5600L/main.c Normal file
View File

@@ -0,0 +1,28 @@
#include "pico/stdlib.h"
#include "pico/time.h"
#include "hardware/i2c.h"
#include <stdio.h>
#include "AS5600L.h"
#define I2C_PORT i2c0
#define I2C_SDA_PIN 8
#define I2C_SCL_PIN 9
int main() {
stdio_init_all();
sleep_ms(1000);
AS5600L as5600l;
as560x_init(&as5600l,I2C_PORT,100000,I2C_SDA_PIN,I2C_SCL_PIN);
int abs = 0;
abs = update_pos;
while (true) {
// abs = update_pos(&as5600l);
// printf("Position absolue : %d\n",abs);
sensorData(&as5600l);
}
return 0;
}

151
BM/as5600l.py Normal file
View File

@@ -0,0 +1,151 @@
import time
import setenv
from machine import I2C, Pin
ADDRESS = 0x40
ZMCO = 0x00
ZPOS = 0x01
MPOS = 0x03
MANG = 0x05
CONF_REG = 0x07
STATUS_REG = 0x0B
RAWANGLE = 0x0c
ANGLE_REG = 0x0E
AGC_REG = 0x1A
MAGNITUDE = 0x1b
BURN = 0xff
class AS5600L:
def __init__(self,
i2c_id = setenv.ENCODER_NUMBER,
sda = setenv.ENCODER_SDA_PIN,
scl = setenv.ENCODER_SCL_PIN,
i2c_freq = setenv.ENCODER_I2C_FREQUENCE,
hyst = setenv.ENCODER_HYST,
power_mode = 0,
watchdog = 0,
fast_filter_threshold = 0,
slow_filter = 0,
pwm_freq = 0,
output_stage = 0):
"""Init
Args:
i2c_id (int, optional): ID of the I2C bus. Defaults to 0.
sda (int, optional) : gpio of the I2C bus. Defaults to 0.
scl (int, optional) : gpio of clock for I2C bus. Defaults to 1.
i2c_freq (int, optional): I2C Ferequency. Default is max. Defaults to 1000000.
hyst (int, optional): Hysteresis: 0->3. Defaults to 0.
power_mode (int, optional): Power Mode: 0->3. Defaults to 0.
watchdog (int, optional): Enable the watchdog. Defaults to 0.
fast_filter_threshold (int, optional): Threshold value for the fast filter: 0->7. Defaults to 0.
slow_filter (int, optional): Slow filter mode: 0->3. Defaults to 0.
pwm_freq (int, optional): Output PWM frequency: 0->3. Defaults to 0.
output_stage (int, optional): Output mode (see datasheet): 0->2. Defaults to 0.
"""
self.i2c = I2C(i2c_id, scl=Pin(scl), sda=Pin(sda), freq=i2c_freq)
print(self.i2c.scan())
time.sleep_ms(100)
c1 = 0x00
c2 = 0x00
# # set watchdog 0,1
# if watchdog in range(0,2):
# c1 = c1 | (watchdog << 5)
# # set fast filter threshold 0->7
# if fast_filter_threshold in range(0,8):
# c1 = c1 | (fast_filter_threshold << 2)
# # set the slow filter 0->3
# if slow_filter in range(0,4):
# c1 = c1 | slow_filter
# # set PWM frequency 0->3
# if pwm_freq in range(0,4):
# c2 = c2 | (pwm_freq << 6)
# # set output stage 0->2
# if output_stage in range(0,2):
# c2 = c2 | (output_stage << 4)
# # set power_mode 0->3
# if power_mode in range(0, 4):
# c2 = c2 | power_mode
# # set Hysteresis 0->3
# if hyst in range(0, 4):
# c2 = c2 | (hyst << 2)
self.i2c.writeto(ADDRESS, bytes([CONF_REG, c1, c2]))
def get_status(self):
"""Get the status of the ASL560L
Returns:
Dict: Dictionary of the different statuses
"""
self.i2c.writeto(ADDRESS, bytes([STATUS_REG]))
status = int.from_bytes(self.i2c.readfrom(ADDRESS, 1), 'big')
mh = bool(status & 0b00001000)
ml = bool(status & 0b00010000)
md = bool(status & 0b00100000)
self.i2c.writeto(ADDRESS, bytes([AGC_REG]))
agc = int.from_bytes(self.i2c.readfrom(ADDRESS, 1), 'big')
return {
"magnetDetected": md,
"magnetTooWeak": ml,
"magnetTooStrong": mh,
"agc": agc
}
def is_ok(self) -> bool:
"""Reads the status values to determine if the magnet is able to be read.
Returns:
bool: True if the magnet can be detercted accurately
"""
self.i2c.writeto(ADDRESS, bytes([STATUS_REG]))
status = int.from_bytes(self.i2c.readfrom(ADDRESS, 1), 'big')
mh = bool(status & 0b00001000)
ml = bool(status & 0b00010000)
md = bool(status & 0b00100000)
if md and not mh and not ml:
return True
else:
return False
def get_angle(self) -> int:
"""Get the raw 12bit angle value
Returns:
int: 0->4095
"""
self.i2c.writeto(ADDRESS, bytes([ANGLE_REG]))
return int.from_bytes(self.i2c.readfrom(ADDRESS, 2), 'big')
def get_angle_degrees(self):
"""Get the angle in degrees, IF the magnet can be read
Returns:
float: Degrees (0->359) if magnet can be read otherwise None.
"""
if self.is_ok():
return (float(self.get_angle()))
else:
# if the magnet cannot be read then the angle is unreliable, so return None.
return None
def get_angle_degrees_fast(self):
"""Get the angle in degrees
Returns:
float: Degrees (0->359) if magnet can be read otherwise None.
"""
self.i2c.writeto(ADDRESS, b'\x0c')
return (float(int.from_bytes(self.i2c.readfrom(ADDRESS, 2), 'big')))
def get_conf(self):
"""Internal healper function to read the raw config value
Returns:
int: raw value
"""
self.i2c.writeto(ADDRESS, bytes([CONF_REG]))
return int.from_bytes(self.i2c.readfrom(ADDRESS, 2), 'big')

27
BM/main.py Normal file
View File

@@ -0,0 +1,27 @@
from smart_motor import SmartMotor
import time
tmc = SmartMotor()
print("########")
#tmc.driver_status()
#tmc.general_config()
print("########")
#tmc.init_encoder()
#tmc.rotate(5,degrees=18000,acceleration=1000,deceleration=1000)
print("begin1",tmc.get_microstepping_resolution());
time.sleep(2)
tmc.set_microstepping_resolution(256)
time.sleep(2)
print("begin",tmc.get_microstepping_resolution());
#print("encoder : ")
#print(tmc.get_encoder_position(0))
#0x55 0x00 0x6C 0x4D

39
BM/setenv.py Normal file
View File

@@ -0,0 +1,39 @@
SID = '#6'
BOARD_NAME = 'PICO'
PACKAGE_NAME = 'Prodigy'
VERSION = 0.1
#-----------------------------------------------------------------------
# Setup Pin Motor TMC2209
#-----------------------------------------------------------------------
MOTOR_NUMBER = 1
MOTOR_TX_PIN = 4
MOTOR_RX_PIN = 5
MOTOR_EN_PIN = 7
MOTOR_STEP_PIN = 10
MOTOR_DIR_PIN = 11
MOTOR_BAUDRATE = 115200
MOTOR_SENSOR_BEGIN_PIN = -1
MOTOR_SENSOR_END_PIN = -1
MOTOR_SENSOR_BEGIN_VALUE = 1
MOTOR_SENSOR_END_VALUE = 1
MOTOR_SOFT_UART = False
#-----------------------------------------------------------------------
# Setup Motor TMC2209
#-----------------------------------------------------------------------
MOTOR_STEP_MOTOR = 48
MOTOR_SCREW_THREAD = 1.22
MOTOR_MICROSTEP = 1
MOTOR_VREF = 5.4
MOTOR_AMP = 1800
#-----------------------------------------------------------------------
# Setup Pin I2C encoder AS5600L
#-----------------------------------------------------------------------
ENCODER_NUMBER = 0
ENCODER_SDA_PIN = 8
ENCODER_SCL_PIN = 9
ENCODER_I2C_FREQUENCE = 400000
ENCODER_HYST = 1

325
BM/smart_motor.py Normal file
View File

@@ -0,0 +1,325 @@
import time
from as5600l import AS5600L
from tmc_2209 import TMC2209
import setenv
from machine import Pin
import gc
#-----------------------------------------------------------------------
# sets the register bit "VACTUAL" to to a given value
# VACTUAL allows moving the motor by UART control.
# It gives the motor velocity in +-(2^23)-1 [μsteps / t]
# 0: Normal operation. Driver reacts to STEP input
#-----------------------------------------------------------------------
class SmartMotor(TMC2209):
status = False
position = 0
if setenv.MOTOR_SENSOR_END_PIN != -1 :
init_home_end =setenv.MOTOR_SENSOR_END_VALUE
pin_home_end = Pin(setenv.MOTOR_SENSOR_END_PIN, Pin.IN)
if setenv.MOTOR_SENSOR_BEGIN_PIN != -1 :
init_home_begin =setenv.MOTOR_SENSOR_BEGIN_VALUE
pin_home_begin = Pin(setenv.MOTOR_SENSOR_BEGIN_PIN, Pin.IN)
def get_encoder_position(self,encoder):
if self.encoder is not None:
self.actual = self.encoder.get_angle_degrees()
if self.actual != None and self.actual != self.last:
self.calc = self.actual-self.last
if self.actual < self.last :
if self.calc<-3800:
self.calc = abs((4096 - self.last + self.actual))
self.posreal+=self.calc
elif self.actual > self.last :
if self.calc>3800:
self.calc = abs((4096 - self.actual + self.last))
self.posreal+=self.calc
self.last = self.actual
return(self.posreal)
def init_encoder(self):
self.encoder = AS5600L()
self.actual = 0
self.last = 0
print(self.encoder.get_status())
self.posbegin = self.encoder.get_angle_degrees_fast()
print("posbegin",self.posbegin)
self.posreal = 0
self.last=self.posbegin
def reset_position(self):
self.position = 0
# def set_home_pins(self, start = -1, end = -1):
def set_encoder(self, encoder):
self.encoder = encoder
def init_vactual(self):
self.clear_general_stat()
time.sleep_us(10)
self.set_voltage_sense(False)#ok
self.set_current_flow(setenv.MOTOR_AMP)
self.set_iscale_analog(False)#ok
self.set_interpolation(True)
self.set_internal_resistor_sense(False)
self.set_spread_cycle(True)
self.set_microstepping_resolution(setenv.MOTOR_MICROSTEP)
self.set_microstep_resolution_regselect(True)
self.set_pin_enable(True)
return True
def rotate(self,
vactual,
degrees = 0,
acceleration = 0,
deceleration = 0,
KP = 1.0,
KI = 0,
KD = 0,
counter = False,
show_stallguard_result = False,
show_tstep = False,
absrel = True):
self.init_vactual()
liste_vitesse = [0]
liste_time = [0]
liste_distance = [0]
if(absrel):
if degrees - self.position < 0:
print(degrees - self.position)
self.set_direction_shart(False)
degrees = abs(degrees - self.position)
sense = False
else:
degrees = degrees - self.position
sense = True
self.set_direction_shart(True)
vactual = int(round((vactual/0.715)*self.get_steps_per_resolution())) # not tested!
self._stop = False
current_vactual = 0
last_error = 0
integral = 0
if self.debugmode == True:
if(degrees != 0):
print("vactual: "+str(vactual)+" for "+str(degrees)+" degrees")
if (degrees != 0):
start_time = time.ticks_ms()
end_time = start_time
current_degrees = 0
timespan = 0
error= 0
self.set_pin_enable(True)
while((current_degrees <= degrees)):
print(current_degrees)
error = degrees - current_degrees
integral = integral + error
derivative = error - last_error
speed_adjustment = KP * error + KI * integral + KD * derivative
last_error = error
start_time= time.ticks_ms()
gap_time = (start_time-end_time)/1000
rps = current_vactual/self.get_steps_per_resolution()*0.715
angle = rps*gap_time*360
current_degrees = current_degrees+angle
timespan +=gap_time
if(sense):
self.position += angle
else:
self.position -= angle
if ((current_vactual==0) or (error/current_vactual > current_vactual/deceleration)):
if(acceleration != 0 and abs(current_vactual)<abs(vactual)):
current_vactual += acceleration*gap_time
if current_vactual>vactual:
current_vactual=vactual
else:
current_vactual -= deceleration*gap_time
# liste_vitesse.append(current_vactual*setenv.MOTOR_MICROSTEP)
# liste_time.append(liste_time[len(liste_time)-1] + gap_time)
# liste_distance.append(current_degrees)
print(current_vactual*setenv.MOTOR_MICROSTEP)
self.set_vactual(current_vactual*setenv.MOTOR_MICROSTEP)
gc.collect()
end_time=start_time
self.set_pin_enable(False)
self.set_vactual(0)
# print("============vitesse==========")
# print(liste_vitesse)
# print("============temps============")
# print(liste_time)
# print("============distance============")
# print(liste_distance)
# print("=============================")
return ('fin de position a : ' + str(self.position) + ' degres')
def rotate_Closed_Loop(self,
vactual,
degrees = 0,
acceleration = 0,
deceleration = 0,
KP = 1.0,
KI = 0,
KD = 0,
counter = False,
show_stallguard_result = False,
show_tstep = False,
absrel = True):
self.init_vactual()
print(self.get_encoder_position(self.encoder))
if(absrel):
print(self.get_encoder_position(self.encoder))
if (degrees - self.get_encoder_position(self.encoder)) < 0:
self.set_direction_shart(False)
sense = False
else:
self.set_direction_shart(True)
sense = True
vactual = int(round((vactual/0.715)*self.get_steps_per_resolution())) # not tested!
self._stop = False
current_vactual = 0
last_error = 0
integral = 0
if (vactual<0):
acceleration = -acceleration
if self.debugmode == True:
if(degrees != 0):
print("vactual: "+str(vactual)+" for "+str(degrees)+" degrees")
if (degrees != 0):
current_degrees = self.get_encoder_position(0)
self.set_pin_enable(True)
start_time = time.ticks_ms()
end_time = start_time
current_degrees = 0
timespan = 0
if(degrees - current_degrees < 0):
self.set_set_direction_shart_shart(False)
while((not self._stop) and (current_degrees <= degrees)):
current_degrees = self.get_encoder_position(0)
error = degrees - current_degrees
integral = integral + error
derivative = error - last_error
speed_adjustment = KP * error + KI * integral + KD * derivative
last_error = error
start_time= time.ticks_ms()
gap_time = (start_time-end_time)/1000
rps = current_vactual/self.get_steps_per_resolution()*0.715
angle = rps*gap_time*360
current_degrees = current_degrees+angle
timespan +=gap_time
if(sense):
self.position += angle
else:
self.position -= angle
if ((current_vactual==0) or (error/current_vactual > current_vactual/deceleration)):
if(acceleration != 0 and abs(current_vactual)<abs(vactual)):
current_vactual += acceleration*gap_time
if current_vactual>vactual:
current_vactual=vactual
self.set_vactual(current_vactual)
else:
current_vactual -= deceleration*gap_time
self.set_vactual(current_vactual)
self.set_pin_enable(False)
self.set_vactual(0)
return ('fin de position a : ' + str(self.position) + ' degres')
def stop(self):
self.set_vactual(0)
time.sleep(1)
self.set_pin_enable(False)
self.p_pin_enable.off()
#-----------------------------------------------------------------------
# This function is for doing Home
# Setup "mode" to 'begin' for Home 0 and 'end' for go to max range
#For uses absolute position
#-----------------------------------------------------------------------
def go_home(self,mode=False):
self.run_vactual()
if(mode!=False):
if(mode == "begin"):
current_vactual = 0
if self.pin_home_begin != -1:
self.set_pin_enable(True)
self.set_direction_shart(False)
vactual = int(round((1/0.715)*self.get_steps_per_resolution()))
while self.pin_home_begin.value() == self.init_home_begin:
if(abs(current_vactual)<abs(vactual)):
current_vactual += 50*0.05
if current_vactual>vactual:
current_vactual=vactual
self.set_vactual(current_vactual)
self.set_vactual(0)
time.sleep(0.2)
self.set_direction_shart(True)
current_vactual = 0
while self.pin_home_begin.value() != self.init_home_begin:
if(abs(current_vactual)<abs(vactual)):
current_vactual += 50*0.05
if current_vactual>vactual:
current_vactual=vactual
self.set_vactual(current_vactual)
else :
print("Any begin sensor setup")
return False
if(mode == "end"):
if self.pin_home_end != -1:
self.set_pin_enable(True)
self.set_direction_shart(True)
vactual = int(round((1.5/0.715)*self.get_steps_per_resolution()))
while self.pin_home_end.value() == self.init_home_end:
if(abs(current_vactual)<abs(vactual)):
current_vactual += 100*0.05
if current_vactual>vactual:
current_vactual=vactual
self.set_vactual(current_vactual)
self.set_vactual(0)
time.sleep(0.2)
self.set_direction_shart(False)
current_vactual = 0
while self.pin_home_end.value() != self.init_home_end:
if(abs(current_vactual)<abs(vactual)):
current_vactual += 100*0.05
if current_vactual>vactual:
current_vactual=vactual
self.set_vactual(int(round(current_vactual)))
else :
print("Any end sensor setup")
return False
else:
self.set_voltage_sense(True)
self.set_current_flow(1800)
self.set_iscale_analog(True)
self.set_interpolation(True)
self.set_spread_cycle(True)
self.set_microstepping_resolution(setenv.MOTOR_MICROSTEP)
self.set_internal_resistor_sense(False)
self.set_microstep_resolution_regselect(True)
print(self.rotation(500,degrees=-self.position,acceleration=1000,deceleration=1000))
self.set_vactual(0)
self.position = 0
return True
#-----------------------------------------------------------------------
# return the current position result
#-----------------------------------------------------------------------
def get_position_degrees(self):
return self.position

56
BM/softuart.py Normal file
View File

@@ -0,0 +1,56 @@
from machine import Pin
from rp2 import PIO, StateMachine, asm_pio
## ASM
@asm_pio(autopush=True, push_thresh=8, in_shiftdir=PIO.SHIFT_RIGHT, fifo_join=PIO.JOIN_RX)
def uart_rx_mini():
wait(0, pin, 0)
set(x, 7) [10]
label("bitloop")
in_(pins, 1)
jmp(x_dec, "bitloop") [6]
@asm_pio(sideset_init=PIO.OUT_HIGH, out_init=PIO.OUT_HIGH, out_shiftdir=PIO.SHIFT_RIGHT)
def uart_tx():
pull()
set(x, 7) .side(0) [7]
label("bitloop")
out(pins, 1) [6]
jmp(x_dec, "bitloop")
nop() .side(1) [6]
class UART:
def __init__(self, rx, tx, baudrate, id):
self.UART_BAUD = baudrate
self.PIO_RX_PIN = Pin(rx, Pin.IN, Pin.PULL_UP)
self.PIO_TX_PIN = Pin(tx, Pin.OUT, value=1)
self.smrx = StateMachine(id, uart_rx_mini, freq=8*self.UART_BAUD, in_base=self.PIO_RX_PIN, jmp_pin=self.PIO_RX_PIN)
self.smrx.active(1)
self.smtx = StateMachine(id + 1, uart_tx, freq=8*self.UART_BAUD, sideset_base=self.PIO_TX_PIN, out_base=self.PIO_TX_PIN)
self.smtx.active(1)
def deinit(self):
self.smrx.active(0)
self.smtx.active(0)
def write(self,s):
#self.smtx.put(bytes(s))
self.smtx.put(s)
return len(s)
def read(self):
z = []
for i in range(100):
buflen = self.smrx.rx_fifo()
if buflen:
for c in range(buflen):
z.append(self.smrx.get() >> 24)
return bytes(z)

952
BM/tmc_2209.py Normal file
View File

@@ -0,0 +1,952 @@
import sys
import time
import math
import setenv
from machine import Pin
if setenv.MOTOR_SOFT_UART == True:
from softuart import UART
else:
from machine import UART
#-----------------------------------------------------------------------
# this file contains:
# 1. hexadecimal address of the different registers
# 2. bitposition and bitmasks of the different values of each register
#
# Example:
# the register IOIN has the address 0x06 and the first bit shows
# whether the ENABLE (EN/ENN) Pin is currently HIGH or LOW
#-----------------------------------------------------------------------
#addresses
GCONF = 0x00
GSTAT = 0x01
IFCNT = 0x02
IOIN = 0x06
IHOLD_IRUN = 0x10
TSTEP = 0x12
TCOOLTHRS = 0x14
SGTHRS = 0x40
SG_RESULT = 0x41
MSCNT = 0x6A
CHOPCONF = 0x6C
DRVSTATUS = 0x6F
VACTUAL = 0x22
#GCONF
i_scale_analog = 1<<0
internal_rsense = 1<<1
en_spreadcycle = 1<<2
shaft = 1<<3
index_otpw = 1<<4
index_step = 1<<5
mstep_reg_select = 1<<7
#GSTAT
reset = 1<<0
drv_err = 1<<1
uv_cp = 1<<2
#CHOPCONF
vsense = 1<<17
msres0 = 1<<24
msres1 = 1<<25
msres2 = 1<<26
msres3 = 1<<27
intpol = 1<<28
#IOIN
io_enn = 1<<0
io_step = 1<<7
io_spread = 1<<8
io_dir = 1<<9
#DRVSTATUS
stst = 1<<31
stealth = 1<<30
cs_actual = 31<<16
t157 = 1<<11
t150 = 1<<10
t143 = 1<<9
t120 = 1<<8
olb = 1<<7
ola = 1<<6
s2vsb = 1<<5
s2vsa = 1<<4
s2gb = 1<<3
s2ga = 1<<2
ot = 1<<1
otpw = 1<<0
#IHOLD_IRUN
ihold = 31<<0
irun = 31<<8
iholddelay = 15<<16
#SGTHRS
sgthrs = 255<<0
#others
mres_256 = 0
mres_128 = 1
mres_64 = 2
mres_32 = 3
mres_16 = 4
mres_8 = 5
mres_4 = 6
mres_2 = 7
mres_1 = 8
#-----------------------------------------------------------------------
# TMC_UART LogLevl
#-----------------------------------------------------------------------
class Loglevel():
none = 0
error = 10
info = 20
debug = 30
all = 100
#-----------------------------------------------------------------------
# TMC_UART
#
# this class is used to communicate with the TMC via UART
# it can be used to change the settings of the TMC.
# like the current or the microsteppingmode
#-----------------------------------------------------------------------
class TMC_UART:
mtr_id = 0
ser = None
rFrame = [0x55, 0, 0, 0]
wFrame = [0x55, 0, 0, 0 , 0, 0, 0, 0]
communication_pause = 0
#-----------------------------------------------------------------------
# constructor
#-----------------------------------------------------------------------
def __init__(self, rx, tx, serialport, baudrate):
if setenv.MOTOR_SOFT_UART == True:
self.ser = UART(rx=rx, tx=tx, baudrate=baudrate, id=serialport)
print("soft_tmc")
else:
self.ser = UART(serialport,baudrate,rx=Pin(rx), tx=Pin(tx))
print("hard_tmc",serialport,baudrate,rx ,tx)
self.mtr_id = 0
#self.ser.timeout = 20000/baudrate # adjust per baud and hardware. Sequential reads without some delay fail.
self.communication_pause = 500 / baudrate # adjust per baud and hardware. Sequential reads without some delay fail.
#-----------------------------------------------------------------------
# destructor
#-----------------------------------------------------------------------
def deinit(self):
self.ser.deinit()
#-----------------------------------------------------------------------
# this function calculates the crc8 parity bit
#-----------------------------------------------------------------------
def compute_crc8_atm(self, datagram, initial_value=0):
crc = initial_value
for byte in datagram: # Iterate bytes in data
for _ in range(0, 8): # Iterate bits in byte
if (crc >> 7) ^ (byte & 0x01):
crc = ((crc << 1) ^ 0x07) & 0xFF
else:
crc = (crc << 1) & 0xFF
byte = byte >> 1 # Shift to next bit
return crc
#-----------------------------------------------------------------------
# reads the registry on the TMC with a given address.
# returns the binary value of that register
#-----------------------------------------------------------------------
def read_reg(self, reg):
self.rFrame[1] = self.mtr_id
self.rFrame[2] = reg
self.rFrame[3] = self.compute_crc8_atm(self.rFrame[:-1])
rt = self.ser.write(bytes(self.rFrame))
if rt != len(self.rFrame):
# print(f"TMC2209: Err in write", file=sys.stderr)
return False
# time.sleep(self.communication_pause) # adjust per baud and hardware. Sequential reads without some delay fail.
rtn = self.ser.read() #read what it self
if rtn == None:
# print("TMC2209: Err in read")
return ""
print("rtn[7:11] :",rtn[7:11] , rtn[7] ,rtn[8] , rtn[9] , rtn[10] , " , reg : ",reg)
return rtn[7:11]
#-----------------------------------------------------------------------
# this function tries to read the registry of the TMC 10 times
# if a valid answer is returned, this function returns it as an integer
#-----------------------------------------------------------------------
def read_int(self, reg):
tries = 0
while True:
rtn = self.read_reg(reg)
tries += 1
if len(rtn) >= 4:
break
else:
pass
print(f"TMC2209: did not get the expected 4 data bytes. Instead got {str(len(rtn))} Bytes")
if tries >= 10:
print("TMC2209: after 10 tries not valid answer. exiting")
print("TMC2209: is Stepper Powersupply switched on ?")
raise SystemExit
return int.from_bytes(rtn, 'big', False)
#-----------------------------------------------------------------------
# this function can write a value to the register of the tmc
# 1. use read_int to get the current setting of the TMC
# 2. then modify the settings as wished
# 3. write them back to the driver with this function
#-----------------------------------------------------------------------
def write_reg(self, reg, val):
#self.ser.reset_output_buffer()
#self.ser.reset_input_buffer()
self.wFrame[1] = self.mtr_id
self.wFrame[2] = reg | 0x80; # set write bit
self.wFrame[3] = 0xFF & (val>>24)
self.wFrame[4] = 0xFF & (val>>16)
self.wFrame[5] = 0xFF & (val>>8)
self.wFrame[6] = 0xFF & val
self.wFrame[7] = self.compute_crc8_atm(self.wFrame[:-1])
print("x" ,bytes(self.wFrame),self.wFrame)
rtn = self.ser.write(bytes(self.wFrame))
if rtn != len(self.wFrame):
# print(f"TMC2209: Err in write", file=sys.stderr)
return False
time.sleep(self.communication_pause)
return True
#-----------------------------------------------------------------------
# this function als writes a value to the register of the TMC
# but it also checks if the writing process was successfully by checking
# the InterfaceTransmissionCounter before and after writing
#-----------------------------------------------------------------------
def write_reg_check(self, reg, val):
ifcnt1 = self.read_int(IFCNT)
self.write_reg(reg, val)
ifcnt2 = self.read_int(IFCNT)
if ifcnt1 >= ifcnt2:
print("TMC2209: writing not successful!")
print(f"reg: {reg} val: {val}")
print(f"ifcnt: {ifcnt1} {ifcnt2}")
return False
return True
#-----------------------------------------------------------------------
# this sets a specific bit to 1
#-----------------------------------------------------------------------
def set_bit(self, value, bit):
return value | (bit)
#-----------------------------------------------------------------------
# this sets a specific bit to 0
#-----------------------------------------------------------------------
def clear_bit(self, value, bit):
return value & ~(bit)
#-----------------------------------------------------------------------
# TMC_2209
#
# this class has two different functions:
# 1. change setting in the TMC-driver via UART
# 2. move the motor via STEP/DIR pins
#-----------------------------------------------------------------------
class TMC2209:
tmc_uart = None
pin_step = 1
p_pin_step = -1
p_pin_direction = -1
p_pin_enable = -1
debugmode = False
_micro_stepping_resolution = -1
_loglevel = Loglevel.info
#-----------------------------------------------------------------------
# constructor
#-----------------------------------------------------------------------
def __init__(self,
rx=setenv.MOTOR_RX_PIN,
tx=setenv.MOTOR_TX_PIN,
pin_step=setenv.MOTOR_STEP_PIN,
pin_direction=setenv.MOTOR_DIR_PIN,
pin_enable=setenv.MOTOR_EN_PIN,
baudrate=setenv.MOTOR_BAUDRATE,
serialport=setenv.MOTOR_NUMBER,
ms_resolution=setenv.MOTOR_MICROSTEP):
self.tmc_uart = TMC_UART(rx, tx, serialport, baudrate)
self.pin_step = pin_step
self.p_pin_step = Pin(pin_step, Pin.OUT)
self.p_pin_direction = Pin(pin_direction, Pin.OUT)
self.p_pin_enable = Pin(pin_enable, Pin.OUT)
#self.set_microstepping_resolution(setenv.MOTOR_MICROSTEP)
#self.clear_general_stat()
#-----------------------------------------------------------------------
# destructor
#-----------------------------------------------------------------------
def __del__(self):
if(self.debugmode == True):
print("TMC2209: Deinit")
self.set_pin_enable(False)
self.tmc_uart.deinit()
#-----------------------------------------------------------------------
# read the register Adress "DRVSTATUS" and prints all current setting
#-----------------------------------------------------------------------
def driver_status(self):
print("TMC2209: ---")
print("TMC2209: DRIVER STATUS:")
drvstatus = self.tmc_uart.read_int(DRVSTATUS)
if self.debugmode == True:
print("TMC2209:", bin(drvstatus))
if drvstatus & stst:
print("TMC2209: Info: motor is standing still")
else:
print("TMC2209: Info: motor is running")
if drvstatus & stealth:
print("TMC2209: Info: motor is running on StealthChop")
else:
print("TMC2209: Info: motor is running on SpreadCycle")
cs_act = drvstatus & cs_actual
cs_act = cs_act >> 16
print(f"TMC2209: CS actual: {str(cs_act)}")
if drvstatus & olb:
print("TMC2209: Warning: Open load detected on phase B")
if drvstatus & ola:
print("TMC2209: Warning: Open load detected on phase A")
if drvstatus & s2vsb:
print("TMC2209: Error: Short on low-side MOSFET detected on phase B. The driver becomes disabled")
if drvstatus & s2vsa:
print("TMC2209: Error: Short on low-side MOSFET detected on phase A. The driver becomes disabled")
if drvstatus & s2gb:
print("TMC2209: Error: Short to GND detected on phase B. The driver becomes disabled. ")
if drvstatus & s2ga:
print("TMC2209: Error: Short to GND detected on phase A. The driver becomes disabled. ")
if drvstatus & ot:
print("TMC2209: Error: Driver Overheating!")
if drvstatus & otpw:
print("TMC2209: Warning: Driver Overheating Prewarning!")
#-----------------------------------------------------------------------
# read the register Adress "GCONF" and prints all current setting
#-----------------------------------------------------------------------
def general_config(self):
print("TMC2209: ---")
print("TMC2209: GENERAL CONFIG")
gconf = self.tmc_uart.read_int(GCONF)
if self.debugmode == True:
print("TMC2209:", bin(gconf))
if gconf & i_scale_analog:
print("TMC2209: Driver is using voltage supplied to VREF as current reference")
else:
print("TMC2209: Driver is using internal reference derived from 5VOUT")
if gconf & internal_rsense:
print("TMC2209: Internal sense resistors. Use current supplied into VREF as reference.")
print("TMC2209: VREF pin internally is driven to GND in this mode.")
print("TMC2209: This will most likely destroy your driver!!!")
raise SystemExit
else:
print("TMC2209: Operation with external sense resistors")
if gconf & en_spreadcycle:
print("TMC2209: SpreadCycle mode enabled")
else:
print("TMC2209: StealthChop PWM mode enabled")
if gconf & shaft:
print("TMC2209: Inverse motor direction")
else:
print("TMC2209: normal motor direction")
if gconf & index_otpw:
print("TMC2209: INDEX pin outputs overtemperature prewarning flag")
else:
print("TMC2209: INDEX shows the first microstep position of sequencer")
if gconf & index_step:
print("TMC2209: INDEX output shows step pulses from internal pulse generator")
else:
print("TMC2209: INDEX output as selected by index_otpw")
if gconf & mstep_reg_select:
print("TMC2209: Microstep resolution selected by MSTEP register")
else:
print("TMC2209: Microstep resolution selected by pins MS1, MS2")
#-----------------------------------------------------------------------
# read the register Adress "GSTAT" and prints all current setting
#-----------------------------------------------------------------------
def general_stat(self):
print("TMC2209: ---")
print("TMC2209: GENERAL STAT")
gstat = self.tmc_uart.read_int(GSTAT)
if self.debugmode == True:
print("TMC2209:", bin(gstat))
if gstat & reset:
print("TMC2209: The Driver has been reset since the last read access to GSTAT")
if gstat & drv_err:
print("TMC2209: The driver has been shut down due to overtemperature or short circuit detection since the last read access")
if gstat & uv_cp:
print("TMC2209: Undervoltage on the charge pump. The driver is disabled in this case")
#-----------------------------------------------------------------------
# read the register Adress "GSTAT" and prints all current setting
#-----------------------------------------------------------------------
def clear_general_stat(self):
gstat = self.tmc_uart.read_int(GSTAT)
gstat = self.tmc_uart.set_bit(gstat, reset)
gstat = self.tmc_uart.set_bit(gstat, drv_err)
self.tmc_uart.write_reg_check(GSTAT, gstat)
#-----------------------------------------------------------------------
# read the register Adress "IOIN" and prints all current setting
#-----------------------------------------------------------------------
def ioin(self):
print("TMC2209: ---")
print("TMC2209: INPUTS")
ioin = self.tmc_uart.read_int(IOIN)
if self.debugmode == True:
print("TMC2209:", bin(ioin))
if ioin & io_spread:
print("TMC2209: spread is high")
else:
print("TMC2209: spread is low")
if ioin & io_dir:
print("TMC2209: dir is high")
else:
print("TMC2209: dir is low")
if ioin & io_step:
print("TMC2209: step is high")
else:
print("TMC2209: step is low")
if ioin & io_enn:
print("TMC2209: en is high")
else:
print("TMC2209: en is low")
#-----------------------------------------------------------------------
# read the register Adress "CHOPCONF" and prints all current setting
#-----------------------------------------------------------------------
def chopper_control(self):
print("TMC2209: ---")
print("TMC2209: CHOPPER CONTROL")
chopconf = self.tmc_uart.read_int(CHOPCONF)
if self.debugmode == True:
print("TMC2209:", bin(chopconf))
print(f"TMC2209: native {str(self.get_microstepping_resolution())} microstep setting")
if chopconf & intpol:
print("TMC2209: interpolation to 256 microsteps")
if chopconf & vsense:
print("TMC2209: 1: High sensitivity, low sense resistor voltage")
else:
print("TMC2209: 0: Low sensitivity, high sense resistor voltage")
#-----------------------------------------------------------------------
# enables or disables the motor current output
#-----------------------------------------------------------------------
def set_pin_enable(self, enabled):
if enabled:
self.p_pin_enable.off()
# print(f"TMC2209: Motor output active = {enabled}")
else:
self.p_pin_enable.on()
# print("en",self.p_pin_enable.value(),enabled)
# print(f"TMC2209: Motor output active = {enabled}")
#-----------------------------------------------------------------------
# sets the motor shaft direction to the given value: 0 = CCW; 1 = CW
#-----------------------------------------------------------------------
def set_pin_direction(self, direction):
if (self.p_pin_direction.value() != direction):
# print("change",self.p_pin_direction.value() , direction)
if direction:
self.p_pin_direction.on()
else:
self.p_pin_direction.off()
# print("value",self.p_pin_direction.value() )
#-----------------------------------------------------------------------
# enables or disables the motor step output
#-----------------------------------------------------------------------
def set_pin_step(self, enabled):
if enabled:
self.p_pin_step.on()
else:
self.p_pin_step.off()
#-----------------------------------------------------------------------
# returns the motor shaft direction: 0 = CCW; 1 = CW
#-----------------------------------------------------------------------
def get_direction_shart(self):
return self.tmc_uart.read_int(GCONF) & shaft
#-----------------------------------------------------------------------
# sets the motor shaft direction to the given value: 0 = CCW; 1 = CW
#-----------------------------------------------------------------------
def set_direction_shart(self, direction):
gconf = self.tmc_uart.read_int(GCONF)
if (self.get_direction_shart()/8!=direction):
if direction:
if self.debugmode == True:
print("TMC2209: write inverse motor direction")
gconf = self.tmc_uart.set_bit(gconf, shaft)
else:
if self.debugmode == True:
print("TMC2209: write normal motor direction")
gconf = self.tmc_uart.clear_bit(gconf, shaft)
# print(direction)
self.tmc_uart.write_reg_check(GCONF, gconf)
time.sleep_us(100)
#-----------------------------------------------------------------------
# return whether the tmc inbuilt interpolation is active
#-----------------------------------------------------------------------
def get_interpolation(self):
return self.tmc_uart.read_int(CHOPCONF) & intpol
#-----------------------------------------------------------------------
# enables the tmc inbuilt interpolation of the steps to 256 microsteps
#-----------------------------------------------------------------------
def set_interpolation(self, enabled):
chopconf = self.tmc_uart.read_int(CHOPCONF)
if enabled:
chopconf = self.tmc_uart.set_bit(chopconf, intpol)
else:
chopconf = self.tmc_uart.clear_bit(chopconf, intpol)
if self.debugmode == True:
print(f"TMC2209: writing microstep interpolation setting =", enabled)
self.tmc_uart.write_reg_check(CHOPCONF, chopconf)
#-----------------------------------------------------------------------
# return whether spreadcycle (1) is active or stealthchop (0)
#-----------------------------------------------------------------------
def get_spread_cycle(self):
return self.tmc_uart.read_int(GCONF) & en_spreadcycle
#-----------------------------------------------------------------------
# enables spreadcycle (1) or stealthchop (0)
#-----------------------------------------------------------------------
def set_spread_cycle(self, enabled):
gconf = self.tmc_uart.read_int(GCONF)
if enabled:
if self.debugmode == True:
print("TMC2209: Spreadcycle = activated")
gconf = self.tmc_uart.set_bit(gconf, en_spreadcycle)
else:
if self.debugmode == True:
print("TMC2209: Stealthchop = deactivated")
gconf = self.tmc_uart.clear_bit(gconf, en_spreadcycle)
self.tmc_uart.write_reg_check(GCONF, gconf)
#-----------------------------------------------------------------------
# returns the current native microstep resolution (1-256)
#-----------------------------------------------------------------------
def get_microstepping_resolution(self):
chopconf = self.tmc_uart.read_int(CHOPCONF)
print("chopconf : ", chopconf)
msresdezimal = chopconf & (msres0 | msres1 | msres2 | msres3)
msresdezimal = msresdezimal >> 24
msresdezimal = 8 - msresdezimal
self._micro_stepping_resolution = int(math.pow(2, msresdezimal))
return self._micro_stepping_resolution
#-----------------------------------------------------------------------
# sets the current native microstep resolution (1,2,4,8,16,32,64,128,256)
#-----------------------------------------------------------------------
def set_microstepping_resolution(self, msres):
chopconf = self.tmc_uart.read_int(CHOPCONF)
chopconf = chopconf & (~msres0 | ~msres1 | ~msres2 | ~msres3) #setting all bits to zero
print("chopconf 1 :",chopconf)
msresdezimal = int(math.log(msres, 2))
msresdezimal = 8 - msresdezimal
print("msresdezimal 2 :",msresdezimal)
chopconf = int(chopconf) & int(4043309055)
print("chopconf 2 :",chopconf)
chopconf = chopconf | msresdezimal << 24
print("chopconf 3 :",chopconf)
if self.debugmode == True:
print(f"TMC2209: writing {str(msres)} microstep setting")
self.tmc_uart.write_reg_check(CHOPCONF, chopconf)
self.set_microstep_resolution_regselect(True)
#-----------------------------------------------------------------------
# sets the register bit "mstep_reg_select" to 1 or 0 depending to the given value.
# this is needed to set the microstep resolution via UART
# this method is called by "setMicrosteppingResolution"
#-----------------------------------------------------------------------
def set_microstep_resolution_regselect(self, enabled):
gconf = self.tmc_uart.read_int(GCONF)
print("gconf1 :",gconf)
if enabled:
gconf = self.tmc_uart.set_bit(gconf, mstep_reg_select)
else:
gconf = self.tmc_uart.clear_bit(gconf, mstep_reg_select)
if self.debugmode == True:
print(f"TMC2209: writing MStep Reg Select = {enabled}")
print("gconf2 :",gconf)
self.tmc_uart.write_reg_check(GCONF, gconf)
#-----------------------------------------------------------------------
# returns how many steps are needed for one revolution
#-----------------------------------------------------------------------
def get_steps_per_resolution(self):
return 200 * self.get_microstepping_resolution()
#-----------------------------------------------------------------------
# returns the current Microstep counter.
# Indicates actual position in the microstep table for CUR_A
#-----------------------------------------------------------------------
def get_microstep_counter(self, in_steps = False, offset = 0):
mscnt = self.tmc_uart.read_int(MSCNT)
if not in_steps:
return mscnt
return round((4 * self._micro_stepping_resolution) - ((mscnt - 64) * (self._micro_stepping_resolution * 4) / 1024) - 1) + offset
#-----------------------------------------------------------------------
# returns how many steps are needed for one rotation
#-----------------------------------------------------------------------
def get_steps_per_rotation(self):
return self.get_steps_per_resolution() * 21
#-----------------------------------------------------------------------
# return the current stallguard result
# its will be calculated with every fullstep
# higher values means a lower motor load
#-----------------------------------------------------------------------
def get_tstep(self):
return self.tmc_uart.read_int(TSTEP)
ehyfbzeyfeunz,ujefz
#-----------------------------------------------------------------------
# sets the register bit "VACTUAL" to to a given value
# VACTUAL allows moving the motor by UART control.
# It gives the motor velocity in +-(2^23)-1 [μsteps / t]
# 0: Normal operation. Driver reacts to STEP input
#-----------------------------------------------------------------------
def set_vactual(self, value):
self.tmc_uart.write_reg_check(VACTUAL, int(round(value)))
#-----------------------------------------------------------------------
# return the current stallguard result
# its will be calculated with every fullstep
# higher values means a lower motor load
#-----------------------------------------------------------------------
def get_stallguard(self):
return self.tmc_uart.read_int(SG_RESULT)
#-----------------------------------------------------------------------
# sets the register bit "SGTHRS" to to a given value
# this is needed for the stallguard interrupt callback
# SG_RESULT becomes compared to the double of this threshold.
# SG_RESULT ≤ SGTHRS*2
#-----------------------------------------------------------------------
def set_stallguard_threshold(self, threshold):
if self.debugmode == True:
print("TMC2209: sgthrs =", bin(threshold))
self.tmc_uart.write_reg_check(SGTHRS, threshold)
#-----------------------------------------------------------------------
# This is the lower threshold velocity for switching
# on smart energy CoolStep and StallGuard to DIAG output. (unsigned)
#-----------------------------------------------------------------------
def set_coolstep_threshold(self, threshold):
if self.debugmode == True:
print("TMC2209: tcoolthrs =", bin(threshold))
self.tmc_uart.write_reg_check(TCOOLTHRS, threshold)
#-----------------------------------------------------------------------
# set a function to call back, when the driver detects a stall
# via stallguard
# high value on the diag pin can also mean a driver error
#-----------------------------------------------------------------------
def set_stallguard_callback(self, stallguard_pin, threshold, callback, min_speed = 2000):
self.set_stallguard_threshold(threshold)
self.set_coolstep_threshold(min_speed)
if self.debugmode == True:
print("TMC2209: setup stallguard callback")
p25 = Pin(stallguard_pin, Pin.IN, Pin.PULL_DOWN)
p25.irq(trigger=Pin.IRQ_RISING, handler=callback)
#-----------------------------------------------------------------------
# return whether Vref (1) or 5V (0) is used for current scale
#-----------------------------------------------------------------------
def get_iscale_analog(self):
return self.tmc_uart.read_int(GCONF) & i_scale_analog
#-----------------------------------------------------------------------
# sets Vref (1) or 5V (0) for current scale
#-----------------------------------------------------------------------
def set_iscale_analog(self, enabled):
gconf = self.tmc_uart.read_int(GCONF)
if enabled:
if self.debugmode == True:
print("TMC2209: activated Vref for current scale")
gconf = self.tmc_uart.set_bit(gconf, i_scale_analog)
else:
if self.debugmode == True:
print("TMC2209: activated 5V-out for current scale")
gconf = self.tmc_uart.clear_bit(gconf, i_scale_analog)
self.tmc_uart.write_reg_check(GCONF, gconf)
#-----------------------------------------------------------------------
# returns which sense resistor voltage is used for current scaling
# 0: Low sensitivity, high sense resistor voltage
# 1: High sensitivity, low sense resistor voltage
#-----------------------------------------------------------------------
def get_voltage_sense(self):
return self.tmc_uart.read_int(CHOPCONF) & vsense
#-----------------------------------------------------------------------
# sets which sense resistor voltage is used for current scaling
# 0: Low sensitivity, high sense resistor voltage
# 1: High sensitivity, low sense resistor voltage
#-----------------------------------------------------------------------
def set_voltage_sense(self, enabled):
chopconf = self.tmc_uart.read_int(CHOPCONF)
if enabled:
if self.debugmode == True:
print("TMC2209: activated High sensitivity, low sense resistor voltage")
chopconf = self.tmc_uart.set_bit(chopconf, vsense)
else:
if self.debugmode == True:
print("TMC2209: activated Low sensitivity, high sense resistor voltage")
chopconf = self.tmc_uart.clear_bit(chopconf, vsense)
self.tmc_uart.write_reg_check(CHOPCONF, chopconf)
#-----------------------------------------------------------------------
# returns which sense resistor voltage is used for current scaling
# 0: Low sensitivity, high sense resistor voltage
# 1: High sensitivity, low sense resistor voltage
#-----------------------------------------------------------------------
def get_internal_resistor_sense(self):
return self.tmc_uart.read_int(GCONF) & internal_rsense
#-----------------------------------------------------------------------
# sets which sense resistor voltage is used for current scaling
# 0: Low sensitivity, high sense resistor voltage
# 1: High sensitivity, low sense resistor voltage
#-----------------------------------------------------------------------
def set_internal_resistor_sense(self, enabled):
gconf = self.tmc_uart.read_int(GCONF)
if enabled:
if self.debugmode == True:
print("TMC2209: activated internal sense resistors.")
gconf = self.tmc_uart.set_bit(gconf, internal_rsense)
else:
if self.debugmode == True:
print("TMC2209: activated operation with external sense resistors")
gconf = self.tmc_uart.clear_bit(gconf, internal_rsense)
self.tmc_uart.write_reg_check(GCONF, gconf)
#-----------------------------------------------------------------------
# sets the current scale (CS) for Running and Holding
# and the delay, when to be switched to Holding current
# IHold = 0-31; IRun = 0-31; IHoldDelay = 0-15
#-----------------------------------------------------------------------
def set_irun_ihold(self, IHold, IRun, IHoldDelay):
ihold_irun = 0
ihold_irun = ihold_irun | IHold << 0
ihold_irun = ihold_irun | IRun << 8
ihold_irun = ihold_irun | IHoldDelay << 16
if self.debugmode == True:
print("TMC2209: ihold_irun =", bin(ihold_irun))
self.tmc_uart.write_reg_check(IHOLD_IRUN, ihold_irun)
#-----------------------------------------------------------------------
# sets the current flow for the motor
# run_current in mA
# check whether Vref is actually 1.2V
#-----------------------------------------------------------------------
def set_current_flow(self, run_current, hold_current_multiplier = 0.5, hold_current_delay = 10, Vref = setenv.MOTOR_VREF):
CS_IRun = 0
Rsense = 0.11
Vfs = 0
if self.get_voltage_sense():
if self.debugmode == True:
print("TMC2209: Vsense: 1")
Vfs = 0.180 * Vref / 2.5
else:
if self.debugmode == True:
print("TMC2209: Vsense: 0")
Vfs = 0.325 * Vref / 2.5
CS_IRun = 32.0 * 1.41421 * run_current / 1000.0 * (Rsense + 0.02) / Vfs - 1
CS_IRun = min(CS_IRun, 31)
CS_IRun = max(CS_IRun, 0)
CS_IHold = hold_current_multiplier * CS_IRun
CS_IRun = round(CS_IRun)
CS_IHold = round(CS_IHold)
hold_current_delay = round(hold_current_delay)
if self.debugmode == True:
print("TMC2209: CS_IRun =", CS_IRun)
print("TMC2209: CS_IHold =", CS_IHold)
print("TMC2209: Delay =", hold_current_delay)
self.set_irun_ihold(CS_IHold, CS_IRun, hold_current_delay)
#-----------------------------------------------------------------------
# tests the EN, DIR and STEP pin
# this sets the EN, DIR and STEP pin to HIGH, LOW and HIGH
# and checks the IOIN Register of the TMC meanwhile
#-----------------------------------------------------------------------
def test_pins(self):
pin_dir_ok = pin_step_ok = pin_en_ok = True
self.p_pin_step.on()
self.p_pin_direction.on()
self.p_pin_enable.on()
time.sleep(0.1)
ioin = self.tmc_uart.read_int(IOIN)
if not(ioin & io_dir):
pin_dir_ok = False
if not(ioin & io_step):
pin_step_ok = False
if not(ioin & io_enn):
pin_en_ok = False
self.p_pin_step.off()
self.p_pin_direction.off()
self.p_pin_enable.off()
time.sleep(0.1)
ioin = self.tmc_uart.read_int(IOIN)
if ioin & io_dir:
pin_dir_ok = False
if ioin & io_step:
pin_step_ok = False
if ioin & io_enn:
pin_en_ok = False
self.p_pin_step.on()
self.p_pin_direction.on()
self.p_pin_enable.on()
time.sleep(0.1)
ioin = self.tmc_uart.read_int(IOIN)
if not(ioin & io_dir):
pin_dir_ok = False
if not(ioin & io_step):
pin_step_ok = False
if not(ioin & io_enn):
pin_en_ok = False
self.set_pin_enable(False)
print("---")
print(f"Pin STEP: \t{pin_step_ok}")
print(f"Pin DIRECTION: \t{pin_dir_ok}")
print(f"Pin ENABLE: \t{pin_en_ok}")
print("---")

View File

@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.12)
set(PROJECT_NAME "Uart_TMC2209_test")
set(PICO_SDK_PATH "E:/Beyon_Motion/pico-sdk")
set(PICO_TOOLCHAIN_PATH "C:/Users/spide/scoop/apps/gcc-arm-none-eabi/current/bin")
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(${PROJECT_NAME} C CXX ASM) # Ajout de CXX ici
pico_sdk_init()
add_executable(${PROJECT_NAME}
main.c
Tmc2209.c
Tmc_uart.c
)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
hardware_i2c
hardware_uart
hardware_dma
# TMC2209
)
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
pico_add_extra_outputs(${PROJECT_NAME})

830
Clean_TMC2209/Tmc2209.c Normal file
View File

@@ -0,0 +1,830 @@
// Tmc2209.c
#include "Tmc2209.h"
#define portMAX_DELAY 10
#define UART_BUFFER_SIZE 64 // Taille du tampon UART, à ajuster selon vos besoins
// Adresses des registres
#define GCONF 0x00
#define GSTAT 0x01
#define IFCNT 0x02
#define IOIN 0x06
#define IHOLD_IRUN 0x10
#define TSTEP 0x12
#define TCOOLTHRS 0x14
#define SGTHRS 0x40
#define SG_RESULT 0x41
#define MSCNT 0x6A
#define CHOPCONF 0x6C
#define DRVSTATUS 0x6F
#define VACTUAL 0x22
// Bits associés à GCONF
#define I_SCALE_ANALOG (1 << 0)
#define INTERNAL_RSENSE (1 << 1)
#define EN_SPREADCYCLE (1 << 2)
#define SHAFT (1 << 3)
#define INDEX_OTPW (1 << 4)
#define INDEX_STEP (1 << 5)
#define MSTEP_REG_SELECT (1 << 7)
// Bits associés à GSTAT
#define RESET (1 << 0)
#define DRV_ERR (1 << 1)
#define UV_CP (1 << 2)
// Bits associés à CHOPCONF
#define VSENSE (1 << 17)
#define MSRES0 (1 << 24)
#define MSRES1 (1 << 25)
#define MSRES2 (1 << 26)
#define MSRES3 (1 << 27)
#define INTPOL (1 << 28)
// Bits associés à IOIN
#define IO_ENN (1 << 0)
#define IO_STEP (1 << 7)
#define IO_SPREAD (1 << 8)
#define IO_DIR (1 << 9)
// Bits associés à DRVSTATUS
#define STST (1U << 31)
#define STEALTH (1U << 30)
#define CS_ACTUAL (31U << 16)
#define T157 (1 << 11)
#define T150 (1 << 10)
#define T143 (1 << 9)
#define T120 (1 << 8)
#define OLB (1 << 7)
#define OLA (1 << 6)
#define S2VSB (1 << 5)
#define S2VSA (1 << 4)
#define S2GB (1 << 3)
#define S2GA (1 << 2)
#define OT (1 << 1)
#define OTPW (1 << 0)
// Bits associés à IHOLD_IRUN
#define IHOLD (31 << 0)
#define IRUN (31 << 8)
#define IHOLDDELAY (15 << 16)
// Bits associés à SGTHRS
#define SGTHRS_VAL (255 << 0)
// Autres constantes
#define MRES_256 0
#define MRES_128 1
#define MRES_64 2
#define MRES_32 3
#define MRES_16 4
#define MRES_8 5
#define MRES_4 6
#define MRES_2 7
#define MRES_1 8
void TMC2209_Init(TMC2209* tmc2209,TMC_UART* serial_instance) {
tmc2209->serial_instance = serial_instance;
tmc2209->mtr_id = 0x00;
tmc2209->rFrame[0] = 0x55;
tmc2209->rFrame[1] = 0x00;
tmc2209->rFrame[2] = 0x00;
tmc2209->rFrame[3] = 0x00;
tmc2209->wFrame[0] = 0x55;
tmc2209->wFrame[1] = 0x00;
tmc2209->wFrame[2] = 0x00;
tmc2209->wFrame[3] = 0x00;
tmc2209->wFrame[4] = 0x00;
tmc2209->wFrame[5] = 0x00;
tmc2209->wFrame[6] = 0x00;
tmc2209->wFrame[7] = 0x00;
tmc2209->result[0] = 0x00;
tmc2209->result[1] = 0x00;
tmc2209->result[2] = 0x00;
tmc2209->result[3] = 0x00;
// return true;
}
uint8_t compute_crc8_atm(const uint8_t *datagram, size_t length, uint8_t initial_value) {
uint8_t crc = initial_value;
size_t i;
int j;
for (i = 0; i < length; i++) {
uint8_t byte = datagram[i];
for (j = 0; j < 8; j++) {
if ((crc >> 7) ^ (byte & 0x01)) {
crc = ((crc << 1) ^ 0x07) & 0xFF;
} else {
crc = (crc << 1) & 0xFF;
}
byte >>= 1;
}
}
return crc;
}
uint64_t *read_reg(TMC2209* tmc2209, int reg) {
tmc2209->rFrame[0] = 0x55;
tmc2209->rFrame[1] = tmc2209->mtr_id;
tmc2209->rFrame[2] = reg;
tmc2209->rFrame[3] = compute_crc8_atm(tmc2209->rFrame, 3, 0);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->rFrame[0]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->rFrame[1]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->rFrame[2]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->rFrame[3]);
uint64_t temp_result[12] = {0x00};
int i = 0;
uint32_t start_time = time_us_32(); // Temps de départ en microsecondes
while (time_us_32() - start_time < 2000 && i < 12) { // Lire pendant 2 ms
if (uart_is_readable(tmc2209->serial_instance->UART_ID)) {
uint64_t tempchar = uart_getc(tmc2209->serial_instance->UART_ID);
temp_result[i] = tempchar;
i++;
}
}
if (temp_result[11] == 0 ){
tmc2209->result[0] = temp_result[6];
tmc2209->result[1] = temp_result[7];
tmc2209->result[2] = temp_result[8];
tmc2209->result[3] = temp_result[9];
}else{
tmc2209->result[0] = temp_result[7];
tmc2209->result[1] = temp_result[8];
tmc2209->result[2] = temp_result[9];
tmc2209->result[3] = temp_result[10];
}
sleep_ms(3);
return tmc2209->result;
}
uint32_t read_int(TMC2209* tmc2209, int reg) {
uint8_t data[4]; // Array to store the 4-byte response
for (int tries = 0; tries < 10; tries++) {
uint64_t* rtn = read_reg(tmc2209, reg);
if (rtn == NULL) {
printf("TMC2209: read_reg failed to return data\n");
continue;
}
if (sizeof(*rtn) >= sizeof(data)) {
for (int i = 0; i < sizeof(data); i++) {
data[i] = (uint8_t)(*rtn >> (8 * (sizeof(*rtn) - i - 1)));
}
} else {
printf("TMC2209: expected at least 4 bytes, got %zu Bytes\n", sizeof(*rtn));
continue;
}
uint32_t result_int = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
if (!(result_int & 0x80000000)) {
return result_int;
} else {
printf("TMC2209: error in register response: 0x%08X\n", result_int);
}
}
printf("TMC2209: failed to read register after 10 tries\n");
printf("TMC2209: is Stepper Powersupply switched on?\n");
exit(EXIT_FAILURE);
}
bool write_reg(TMC2209* tmc2209, int reg, int val) {
tmc2209->wFrame[0] = 0x55;
tmc2209->wFrame[1] = tmc2209->mtr_id;
tmc2209->wFrame[2] = reg | 0x80;
tmc2209->wFrame[3] = (val >> 24) & 0xFF;
tmc2209->wFrame[4] = (val >> 16) & 0xFF;
tmc2209->wFrame[5] = (val >> 8) & 0xFF;
tmc2209->wFrame[6] = val & 0xFF;
tmc2209->wFrame[7] = compute_crc8_atm(tmc2209->wFrame, sizeof(tmc2209->wFrame) - 1, 0);
// printf("val : %d\n",val);
// printf("Frames :");
// for (int i = 0; i < 8; i++) {
// printf("%X ", tmc2209->wFrame[i]);
// }
// printf("\n");
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[0]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[1]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[2]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[3]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[4]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[5]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[6]);
uart_putc(tmc2209->serial_instance->UART_ID, tmc2209->wFrame[7]);
sleep_ms(3);
return true;
}
bool write_reg_check(TMC2209* tmc2209, int reg, int val) {
int ifcnt12 = read_int(tmc2209, IFCNT);
unsigned int ifcnt1 = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
write_reg(tmc2209, reg, val);
int ifcnt22 = read_int(tmc2209, IFCNT);
unsigned int ifcnt2 = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (ifcnt1 >= ifcnt2) {
printf("TMC2209: writing not successful!\n");
printf("reg: %X val: %d\n", reg, val);
printf("ifcnt: %d %d\n", ifcnt1, ifcnt2);
return false;
}
return true;
}
void TMC2209_destroy(TMC2209* tmc2209) {
// free(tmc2209);
}
void driver_status(TMC2209* tmc2209) {
printf("TMC2209: ---\n");
printf("TMC2209: DRIVER STATUS:\n");
read_int(tmc2209, DRVSTATUS);
unsigned int drvstatus = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
printf("Drvstatus : %d \n",drvstatus);
if (drvstatus & STST) {
printf("TMC2209: Info: motor is standing still\n");
} else {
printf("TMC2209: Info: motor is running\n");
}
if (drvstatus & STEALTH) {
printf("TMC2209: Info: motor is running on StealthChop\n");
} else {
printf("TMC2209: Info: motor is running on SpreadCycle\n");
}
int cs_act = drvstatus & CS_ACTUAL;
cs_act >>= 16;
printf("TMC2209: CS actual: %d\n", cs_act);
if (drvstatus & OLB) {
printf("TMC2209: Warning: Open load detected on phase B\n");
}
if (drvstatus & OLA) {
printf("TMC2209: Warning: Open load detected on phase A\n");
}
if (drvstatus & S2VSB) {
printf("TMC2209: Error: Short on low-side MOSFET detected on phase B. The driver becomes disabled\n");
}
if (drvstatus & S2GA) {
printf("TMC2209: Error: Short on low-side MOSFET detected on phase A. The driver becomes disabled\n");
}
if (drvstatus & S2GB) {
printf("TMC2209: Error: Short to GND detected on phase B. The driver becomes disabled.\n");
}
if (drvstatus & S2GA) {
printf("TMC2209: Error: Short to GND detected on phase A. The driver becomes disabled.\n");
}
if (drvstatus & OT) {
printf("TMC2209: Error: Driver Overheating!\n");
}
if (drvstatus & OTPW) {
printf("TMC2209: Warning: Driver Overheating Prewarning!\n");
}
}
// Fonction general_config
void general_config(TMC2209* tmc2209) {
printf("TMC2209: ---\n");
printf("TMC2209: GENERAL CONFIG\n");
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
printf("Gconf : %d \n",gconf);
if (gconf & I_SCALE_ANALOG) {
printf("TMC2209: Driver is using voltage supplied to VREF as current reference\n");
} else {
printf("TMC2209: Driver is using internal reference derived from 5VOUT\n");
}
if (gconf & INTERNAL_RSENSE) {
printf("TMC2209: Internal sense resistors. Use current supplied into VREF as reference.\n");
printf("TMC2209: VREF pin internally is driven to GND in this mode.\n");
printf("TMC2209: This will most likely destroy your driver!!!\n");
exit(EXIT_FAILURE);
} else {
printf("TMC2209: Operation with external sense resistors\n");
}
if (gconf & EN_SPREADCYCLE) {
printf("TMC2209: SpreadCycle mode enabled\n");
} else {
printf("TMC2209: StealthChop PWM mode enabled\n");
}
if (gconf & SHAFT) {
printf("TMC2209: Inverse motor direction\n");
} else {
printf("TMC2209: normal motor direction\n");
}
if (gconf & INDEX_OTPW) {
printf("TMC2209: INDEX pin outputs overtemperature prewarning flag\n");
} else {
printf("TMC2209: INDEX shows the first microstep position of sequencer\n");
}
if (gconf & INDEX_STEP) {
printf("TMC2209: INDEX output shows step pulses from internal pulse generator\n");
} else {
printf("TMC2209: INDEX output as selected by index_otpw\n");
}
}
// Fonction general_stat
void general_stat(TMC2209* tmc2209) {
printf("TMC2209: ---\n");
printf("TMC2209: GENERAL STAT\n");
read_int(tmc2209, GSTAT);
unsigned int gstat = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
printf("Gstat : %d \n",gstat);
if (gstat & RESET) {
printf("TMC2209: The driver has been reset since the last read access to GSTAT\n");
} else {
printf("TMC2209: The driver has not been reset since the last read access to GSTAT\n");
}
if (gstat & DRV_ERR) {
printf("TMC2209: The driver has been shut down due to overtemperature or short circuit detection since the last read access\n");
} else {
printf("TMC2209: The driver has not been shut down due to overtemperature or short circuit detection since the last read access\n");
}
if (gstat & UV_CP) {
printf("TMC2209: Undervoltage detected on the charge pump. The driver is disabled in this case\n");
} else {
printf("TMC2209: No undervoltage detected on the charge pump. The driver is not disabled in this case\n");
}
printf("end Gstat\n");
}
bool set_vactual(TMC2209* tmc2209, int value) {
return write_reg_check(tmc2209, VACTUAL, value);
}
unsigned int set_bit(unsigned int value, unsigned int bit) {
unsigned int temp = value | bit;
// printf("value %d ,set_bit temp : %d\n" ,value,temp);
return temp;
}
// Fonction pour définir un bit spécifique à 0
unsigned int clear_bit(unsigned int value, unsigned int bit) {
unsigned int temp = value & ~(bit);
// printf("value %d ,clear_bit temp : %d\n" ,value,temp);
return temp;
}
void clear_general_stat(TMC2209* tmc2209) {
read_int(tmc2209, GSTAT);
unsigned int gstat= (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
gstat = set_bit(gstat, RESET);
gstat = set_bit(gstat, DRV_ERR);
write_reg_check(tmc2209, GSTAT, gstat);
}
void set_voltage_sense(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, CHOPCONF); // Lire la valeur actuelle du registre CHOPCONF
unsigned int chopconf= (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
chopconf |= VSENSE;
} else {
chopconf &= ~VSENSE;
}
if (!write_reg_check(tmc2209, CHOPCONF, chopconf)) {
printf("Erreur lors de l'écriture de la valeur dans le registre CHOPCONF\n");
}
}
bool get_voltage_sense(TMC2209* tmc2209) {
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (chopconf & VSENSE) != 0;
}
void set_current_flow(TMC2209* tmc2209,double run_current, double hold_current_multiplier, int hold_current_delay, double Vref) {
double CS_IRun = 0.0;
double Rsense = 0.11;
double Vfs = 0.0;
Vref = 5.4;
hold_current_multiplier = 0.5;
hold_current_delay = 10;
run_current = 1800;
int voltage_sense = get_voltage_sense(tmc2209);
if (voltage_sense) {
Vfs = 0.180 * Vref / 2.5;
} else {
Vfs = 0.325 * Vref / 2.5;
}
CS_IRun = 32.0 * 1.41421 * run_current / 1000.0 * (Rsense + 0.02) / Vfs - 1;
CS_IRun = fmin(CS_IRun, 31);
CS_IRun = fmax(CS_IRun, 0);
double CS_IHold = hold_current_multiplier * CS_IRun;
CS_IRun = round(CS_IRun);
CS_IHold = round(CS_IHold);
// printf("CS_IHold_rounded %.3f, CS_IRun_rounded %.3f, hold_current_delay %d\n" , CS_IHold, CS_IRun, hold_current_delay);
set_irun_ihold(tmc2209,CS_IHold, CS_IRun, hold_current_delay);
}
int get_iscale_analog(TMC2209* tmc2209) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (gconf & I_SCALE_ANALOG) ;
}
void set_iscale_analog(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
gconf = set_bit(gconf, I_SCALE_ANALOG);
} else {
gconf = clear_bit(gconf, I_SCALE_ANALOG);
}
write_reg_check(tmc2209, GCONF, gconf);
}
int get_interpolation(TMC2209* tmc2209) {
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (chopconf & INTPOL) ;
}
void set_interpolation(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
chopconf = set_bit(chopconf, INTPOL);
} else {
chopconf = clear_bit(chopconf, INTPOL);
}
write_reg_check(tmc2209, CHOPCONF, chopconf);
}
int get_internal_resistor_sense(TMC2209* tmc2209) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (gconf & INTERNAL_RSENSE) ;
}
void set_internal_resistor_sense(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
gconf = set_bit(gconf, INTERNAL_RSENSE);
} else {
gconf = clear_bit(gconf, INTERNAL_RSENSE);
}
write_reg_check(tmc2209, GCONF, gconf);
}
int get_spread_cycle(TMC2209* tmc2209) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (gconf & EN_SPREADCYCLE) ;
}
void set_spread_cycle(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
gconf = set_bit(gconf, EN_SPREADCYCLE);
} else {
gconf = clear_bit(gconf, EN_SPREADCYCLE);
}
write_reg_check(tmc2209, GCONF, gconf);
}
void set_microstepping_resolution(TMC2209* tmc2209, int msres) {
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
// printf("chopconf %d \n",chopconf);
int msresdezimal = 8 - (int)log2(msres);
chopconf &= 4043309055;
chopconf |= msresdezimal << 24;
write_reg_check(tmc2209, CHOPCONF, chopconf);
set_microstep_resolution_regselect(tmc2209, true);
}
int get_microstepping_resolution(TMC2209* tmc2209) {
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
// printf("chopconf : %d\n", chopconf);
int msresdezimal = chopconf & (MSRES0 | MSRES1 | MSRES2 | MSRES3);
msresdezimal = msresdezimal >> 24;
msresdezimal = 8 - msresdezimal;
int micro_stepping_resolution = (int)pow(2, msresdezimal);
return micro_stepping_resolution;
}
void set_microstep_resolution_regselect(TMC2209* tmc2209, bool enabled) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (enabled) {
gconf = set_bit(gconf, MSTEP_REG_SELECT);
} else {
gconf = clear_bit(gconf, MSTEP_REG_SELECT);
}
// printf("gconf : %d \n",gconf);
write_reg_check(tmc2209, GCONF, gconf);
}
void set_irun_ihold(TMC2209* tmc2209, double IHold, double IRun, int IHoldDelay) {
// Convertir les valeurs doubles en entiers
int ihold_irun = 0;
int ih = (int)IHold;
int ir = (int)IRun;
ihold_irun |= ih << 0;
// printf("ihold_irun1 : %d\n",ihold_irun);
ihold_irun |= ir << 8;
// printf("ihold_irun2 : %d\n",ihold_irun);
ihold_irun |= IHoldDelay << 16;
// printf("ihold_irun3 : %d\n",ihold_irun);
write_reg_check(tmc2209, IHOLD_IRUN, ihold_irun);
}
int get_direction_shart(TMC2209* tmc2209) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return (gconf & SHAFT) ;
}
void ioin(TMC2209* tmc2209) {
printf("TMC2209: ---\n");
printf("TMC2209: INPUTS\n");
read_int(tmc2209, IOIN);
unsigned int ioin = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (ioin & IO_SPREAD) {
printf("TMC2209: spread is high\n");
} else {
printf("TMC2209: spread is low\n");
}
if (ioin & IO_DIR) {
printf("TMC2209: dir is high\n");
} else {
printf("TMC2209: dir is low\n");
}
if (ioin & IO_STEP) {
printf("TMC2209: step is high\n");
} else {
printf("TMC2209: step is low\n");
}
if (ioin & IO_ENN) {
printf("TMC2209: en is high\n");
} else {
printf("TMC2209: en is low\n");
}
}
void chopper_control(TMC2209* tmc2209, int direction) {
printf("TMC2209: ---\n");
printf("TMC2209: CHOPPER CONTROL\n");
read_int(tmc2209, CHOPCONF);
unsigned int chopconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (chopconf & INTPOL) {
printf("TMC2209: interpolation to 256 microsteps\n");
}
if (chopconf & VSENSE) {
printf("TMC2209: 1: High sensitivity, low sense resistor voltage\n");
} else {
printf("TMC2209: 0: Low sensitivity, high sense resistor voltage\n");
}
}
void set_direction_shart(TMC2209* tmc2209, int direction) {
read_int(tmc2209, GCONF);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
int dir = get_direction_shart(tmc2209);
// printf("dir : %d , dir 8 : %d\n",dir,dir / 8);
if ((dir / 8) != direction) {
if (direction) {
gconf = set_bit(gconf, SHAFT);
} else {
gconf = clear_bit(gconf, SHAFT);
}
// printf("gconf : %d \n",gconf);
write_reg_check(tmc2209, GCONF, gconf);
sleep_us(100);
}
}
int get_stallguard(TMC2209* tmc2209) {
read_int(tmc2209, SG_RESULT);
unsigned int stg = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return stg ;
}
void set_stallguard_threshold(TMC2209* tmc2209, int threshold){
write_reg_check(tmc2209,SGTHRS, threshold);
}
void set_coolstep_threshold(TMC2209* tmc2209, int threshold){
write_reg_check(tmc2209,TCOOLTHRS, threshold);
}
void set_stallguard_callback(TMC2209* tmc2209, int stallguard_pin, int threshold, int callback, int min_speed){
set_stallguard_threshold(tmc2209,threshold);
set_coolstep_threshold(tmc2209,min_speed);
gpio_set_function(stallguard_pin, GPIO_FUNC_SIO);
gpio_pull_up(stallguard_pin);
gpio_set_irq_enabled_with_callback(stallguard_pin, GPIO_IRQ_EDGE_RISE, true, callback);
}
int get_tstep(TMC2209* tmc2209) {
read_int(tmc2209, TSTEP);
unsigned int gconf = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
return gconf ;
}
int get_microstep_counter(TMC2209* tmc2209, bool in_steps, int offset) {
read_int(tmc2209, MSCNT);
unsigned int mscnt = (unsigned int)tmc2209->result[0] << 24 |
(unsigned int)tmc2209->result[1] << 16 |
(unsigned int)tmc2209->result[2] << 8 |
(unsigned int)tmc2209->result[3];
if (!in_steps) {
return mscnt;
}
int micro_stepping_resolution = get_microstepping_resolution(tmc2209); // Remplacez par la résolution réelle du micro-pas
return round((4 * micro_stepping_resolution) - ((mscnt - 64) * (micro_stepping_resolution * 4) / 1024) - 1) + offset;
}

66
Clean_TMC2209/Tmc2209.h Normal file
View File

@@ -0,0 +1,66 @@
// Tmc2209.h
#ifndef TMC2209_H
#define TMC2209_H
#include "pico/stdlib.h"
#include "Tmc_uart.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <math.h>
#include <string.h>
typedef struct {
TMC_UART* serial_instance;
int mtr_id;
uint8_t rFrame[4];
uint8_t wFrame[8];
uint64_t result[4];
} TMC2209;
void TMC2209_Init(TMC2209* tmc2209, TMC_UART* serial_instance); //ok
void TMC2209_destroy(TMC2209* tmc2209); //TODO
uint8_t compute_crc8_atm(const uint8_t *datagram, size_t length, uint8_t initial_value); //ok
uint64_t* read_reg(TMC2209* tmc2209, int reg) ; //ok
uint32_t read_int(TMC2209* tmc2209, int reg); //ok
bool write_reg(TMC2209* tmc2209, int reg, int val); //ok
bool write_reg_check(TMC2209* tmc2209, int reg, int val) ; //ok
void driver_status(TMC2209* tmc2209); //NotWork
void general_config(TMC2209* tmc2209); //NotWork
void general_stat(TMC2209* tmc2209); //NotWork
bool set_vactual(TMC2209* tmc2209, int value); //ok
void set_voltage_sense(TMC2209* tmc2209, bool enabled); //ok
bool get_voltage_sense(TMC2209* tmc2209); //ok
void set_current_flow(TMC2209* tmc2209, double run_current, double hold_current_multiplier, int hold_current_delay, double Vref);//averif NotWork
int get_iscale_analog(TMC2209* tmc2209); //ok
void set_iscale_analog(TMC2209* tmc2209, bool enabled); //ok
int get_interpolation(TMC2209* tmc2209); //ok
void set_interpolation(TMC2209* tmc2209, bool enabled); //ok
int get_internal_resistor_sense(TMC2209* tmc2209); //ok
void set_internal_resistor_sense(TMC2209* tmc2209, bool enabled); //ok
int get_spread_cycle(TMC2209* tmc2209); //NotWork
void set_spread_cycle(TMC2209* tmc2209, bool enabled); //NotWork
void set_microstepping_resolution(TMC2209* tmc2209, int msres); //ok
int get_microstepping_resolution(TMC2209* tmc2209); //ok
void set_microstep_resolution_regselect(TMC2209* tmc2209, bool enabled); //ok
void set_irun_ihold(TMC2209* tmc2209, double IHold, double IRun, int IHoldDelay); //ok
int get_direction_shart(TMC2209* tmc2209); //ok
void ioin(TMC2209* tmc2209);
void clear_general_stat(TMC2209* tmc2209); //ok
void set_direction_shart(TMC2209* tmc2209, int direction); //ok
int get_stallguard(TMC2209* tmc2209);
void set_stallguard_threshold(TMC2209* tmc2209, int threshold);
void set_coolstep_threshold(TMC2209* tmc2209, int threshold);
void set_stallguard_callback(TMC2209* tmc2209, int stallguard_pin, int threshold, int callback, int min_speed);
int get_tstep(TMC2209* tmc2209);
int get_microstep_counter(TMC2209* tmc2209, bool in_steps, int offset);
#endif

36
Clean_TMC2209/Tmc_uart.c Normal file
View File

@@ -0,0 +1,36 @@
// TMC_UART.c
#include "TMC_uart.h"
#define DEFAULT_UART_ID uart1
#define DEFAULT_BAUD_RATE 115200
#define DEFAULT_MOTOR_TX_PIN 4
#define DEFAULT_MOTOR_RX_PIN 5
TMC_UART* tmc_Uart_Init(TMC_UART* tmc_uart, uart_inst_t *UART_ID, int BAUD_RATE, int MOTOR_TX_PIN, int MOTOR_RX_PIN) {
if (BAUD_RATE == -1) BAUD_RATE = DEFAULT_BAUD_RATE;
if (MOTOR_TX_PIN == -1) MOTOR_TX_PIN = DEFAULT_MOTOR_TX_PIN;
if (MOTOR_RX_PIN == -1) MOTOR_RX_PIN = DEFAULT_MOTOR_RX_PIN;
uart_init(UART_ID, BAUD_RATE);
gpio_set_function(MOTOR_TX_PIN, GPIO_FUNC_UART);
gpio_set_function(MOTOR_RX_PIN, GPIO_FUNC_UART);
uart_set_hw_flow(UART_ID, false, false);
uart_set_format(UART_ID, 8, 1, UART_PARITY_NONE);
uart_set_fifo_enabled(UART_ID, false);
tmc_uart->UART_ID = UART_ID;
tmc_uart->BAUD_RATE = BAUD_RATE;
tmc_uart->MOTOR_TX_PIN = MOTOR_TX_PIN;
tmc_uart->MOTOR_RX_PIN = MOTOR_RX_PIN;
return tmc_uart;
}
void TMC_UART_Write(TMC_UART* tmc_uart, int data) {
uart_putc(tmc_uart->UART_ID, data);
}
void TMC_UART_Destroy(TMC_UART* tmc_uart) {
// Aucune opération nécessaire
}

18
Clean_TMC2209/Tmc_uart.h Normal file
View File

@@ -0,0 +1,18 @@
// TMC_UART.h
#ifndef TMC_UART_H
#define TMC_UART_H
#include <stdio.h>
#include "pico/stdlib.h"
typedef struct {
uart_inst_t *UART_ID;
int BAUD_RATE;
int MOTOR_TX_PIN;
int MOTOR_RX_PIN;
} TMC_UART;
TMC_UART* tmc_Uart_Init(TMC_UART* tmc_uart, uart_inst_t *UART_ID, int BAUD_RATE, int MOTOR_TX_PIN, int MOTOR_RX_PIN);
void tmc_Uart_Destroy(TMC_UART* TMC_UART);
#endif

View File

@@ -0,0 +1,172 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#include "Board.h"
MotionControllerBoards motionControllerBoards;
DriverBoards driverBoards;
static void deInit(void) {}
// Evalboard channel function dummies
static uint32_t dummy_Motor(uint8_t motor)
{
UNUSED(motor);
return TMC_ERROR_FUNCTION;
}
static uint32_t dummy_MotorValue(uint8_t motor, int32_t value)
{
UNUSED(motor);
UNUSED(value);
return TMC_ERROR_FUNCTION;
}
static void dummy_AddressRef(uint8_t motor, uint16_t address, int32_t *value)
{
UNUSED(motor);
UNUSED(address);
UNUSED(value);
}
static void dummy_AddressValue(uint8_t motor, uint16_t address, int32_t value)
{
UNUSED(motor);
UNUSED(address);
UNUSED(value);
}
static uint32_t dummy_MotorRef(uint8_t motor, int32_t *value)
{
UNUSED(motor);
UNUSED(value);
return TMC_ERROR_FUNCTION;
}
static uint32_t dummy_TypeMotorValue(uint8_t type, uint8_t motor, int32_t value)
{
UNUSED(type);
UNUSED(motor);
UNUSED(value);
return TMC_ERROR_FUNCTION;
}
static uint32_t dummy_TypeMotorRef(uint8_t type, uint8_t motor, int32_t *value)
{
UNUSED(type);
UNUSED(motor);
UNUSED(value);
return TMC_ERROR_FUNCTION;
}
static uint32_t dummy_getLimit(uint8_t type, uint8_t motor, int32_t *value)
{
UNUSED(type);
UNUSED(motor);
UNUSED(value);
return TMC_ERROR_FUNCTION;
}
static uint8_t dummy_onPinChange(IOPinTypeDef *pin, IO_States state)
{
UNUSED(pin);
UNUSED(state);
return 1;
}
static void dummy_OTP_init(void)
{
return;
}
static void dummy_OTP_address(uint32_t address)
{
UNUSED(address);
return;
}
static void dummy_OTP_value(uint32_t value)
{
UNUSED(value);
return;
}
static void dummy_OTP_program(void)
{
return;
}
static void dummy_OTP_lock(void)
{
return;
}
static OTP_Status dummy_OTP_status(void)
{
return OTP_STATUS_IDLE;
}
static uint8_t delegationReturn(void)
{
return 1;
}
static void enableDriver(DriverState state)
{
UNUSED(state);
}
static void periodicJob(uint32_t tick)
{
UNUSED(tick);
}
void board_setDummyFunctions(EvalboardFunctionsTypeDef *channel)
{
channel->config->reset = delegationReturn;
channel->config->restore = delegationReturn;
channel->deInit = deInit;
channel->periodicJob = periodicJob;
channel->left = dummy_MotorValue;
channel->stop = dummy_Motor;
channel->moveTo = dummy_MotorValue;
channel->moveBy = dummy_MotorRef;
channel->moveProfile = dummy_MotorValue;
channel->right = dummy_MotorValue;
channel->GAP = dummy_TypeMotorRef;
channel->readRegister = dummy_AddressRef;
channel->writeRegister = dummy_AddressValue;
channel->SAP = dummy_TypeMotorValue;
channel->SIO = dummy_TypeMotorValue;
channel->GIO = dummy_TypeMotorRef;
channel->STAP = dummy_TypeMotorValue;
channel->RSAP = dummy_TypeMotorValue;
channel->userFunction = dummy_TypeMotorRef;
channel->getMeasuredSpeed = dummy_MotorRef;
channel->checkErrors = periodicJob;
channel->enableDriver = enableDriver;
channel->fullCover = NULL;
channel->getMin = dummy_getLimit;
channel->getMax = dummy_getLimit;
channel->onPinChange = dummy_onPinChange;
channel->OTP_init = dummy_OTP_init;
channel->OTP_address = dummy_OTP_address;
channel->OTP_value = dummy_OTP_value;
channel->OTP_program = dummy_OTP_program;
channel->OTP_status = dummy_OTP_status;
channel->OTP_lock = dummy_OTP_lock;
}
void periodicJobDummy(uint32_t tick)
{
UNUSED(tick);
}

View File

@@ -0,0 +1,197 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef BOARD_H
#define BOARD_H
#include "tmc/helpers/API_Header.h"
#include "hal/derivative.h"
#include "hal/HAL.h"
#include "tmc/VitalSignsMonitor.h"
#include "tmc/ic/TMC2130/TMC2130.h"
#include "tmc/ic/TMC2160/TMC2160.h"
#include "tmc/ic/TMC2208/TMC2208.h"
#include "tmc/ic/TMC2224/TMC2224.h"
#include "tmc/ic/TMC2590/TMC2590.h"
#include "tmc/ic/TMC2660/TMC2660.h"
#include "tmc/ic/TMC6100/TMC6100.h"
#include "tmc/ic/TMC6200/TMC6200.h"
#include "tmc/ic/TMC7300/TMC7300.h"
#include "tmc/ic/TMC2209/TMC2209.h"
#include "tmc/ic/TMC2225/TMC2225.h"
#include "tmc/ic/TMC2226/TMC2226.h"
#include "tmc/ic/TMC2300/TMC2300.h"
#include "tmc/ic/MAX22216/MAX22216.h"
#include "tmc/ic/TMC4361A/TMC4361A.h"
#include "tmc/ic/TMC5031/TMC5031.h"
#include "tmc/ic/TMC5041/TMC5041.h"
#include "tmc/ic/TMC5062/TMC5062.h"
#include "tmc/ic/TMC5072/TMC5072.h"
#include "tmc/ic/TMC5130/TMC5130.h"
#include "tmc/ic/TMC5160/TMC5160.h"
#include "tmc/ic/TMC8461/TMC8461.h"
#include "tmc/ic/TMC8462/TMC8462.h"
// parameter access (for axis parameters)
#define READ 0
#define WRITE 1
typedef enum {
LIMIT_MIN,
LIMIT_MAX
} AxisParameterLimit;
typedef enum {
DRIVER_DISABLE,
DRIVER_ENABLE,
DRIVER_USE_GLOBAL_ENABLE
} DriverState;
typedef enum {
OTP_STATUS_IDLE = 0,
OTP_STATUS_PROGRAMMING = 1,
OTP_STATUS_DONE = 2,
OTP_STATUS_FAILED = 3
} OTP_Status;
// Evalboard channel struct
typedef struct
{
void *type;
uint8_t id;
uint32_t errors;
int32_t VMMax;
int32_t VMMin;
unsigned char numberOfMotors;
ConfigurationTypeDef *config;
uint32_t (*left) (uint8_t motor, int32_t velocity); // move left with velocity <velocity>
uint32_t (*right) (uint8_t motor, int32_t velocity); // move right with velocity <velocity>
uint32_t (*rotate) (uint8_t motor, int32_t velocity); // move right with velocity <velocity>
uint32_t (*stop) (uint8_t motor); // stop motor
uint32_t (*moveTo) (uint8_t motor, int32_t position); // move to position <position>
uint32_t (*moveBy) (uint8_t motor, int32_t *ticks); // move by <ticks>, changes ticks to absolute target
uint32_t (*moveProfile) (uint8_t motor, int32_t position); // move profile <position>
uint32_t (*SAP) (uint8_t type, uint8_t motor, int32_t value); // set axis parameter -> TMCL conformance
uint32_t (*GAP) (uint8_t type, uint8_t motor, int32_t *value); // get axis parameter -> TMCL conformance
uint32_t (*STAP) (uint8_t type, uint8_t motor, int32_t value); // store axis parameter -> TMCL conformance
uint32_t (*RSAP) (uint8_t type, uint8_t motor, int32_t value); // restore axis parameter -> TMCL conformance
uint32_t (*SIO) (uint8_t type, uint8_t motor, int32_t value);
uint32_t (*GIO) (uint8_t type, uint8_t motor, int32_t *value);
void (*readRegister) (uint8_t motor, uint16_t address, int32_t *value); // Motor needed since some chips utilize it as a switch between low and high values
void (*writeRegister) (uint8_t motor, uint16_t address, int32_t value); // Motor needed since some chips utilize it as a switch between low and high values
uint32_t (*getMeasuredSpeed) (uint8_t motor, int32_t *value);
uint32_t (*userFunction) (uint8_t type, uint8_t motor, int32_t *value);
void (*periodicJob) (uint32_t tick);
void (*deInit) (void);
void (*checkErrors) (uint32_t tick);
void (*enableDriver) (DriverState state);
uint8_t (*cover) (uint8_t data, uint8_t lastTransfer);
void (*fullCover) (uint8_t *data, size_t length);
uint32_t (*getMin) (uint8_t type, uint8_t motor, int32_t *value);
uint32_t (*getMax) (uint8_t type, uint8_t motor, int32_t *value);
uint8_t (*onPinChange)(IOPinTypeDef *pin, IO_States state);
void (*OTP_init)(void);
void (*OTP_address)(uint32_t address);
void (*OTP_value)(uint32_t value);
void (*OTP_program)(void);
void (*OTP_lock)(void);
OTP_Status (*OTP_status)(void);
} EvalboardFunctionsTypeDef;
// "hash" function to resolve API error <=> Map index
inline uint8_t error_index(uint8_t error)
{
uint8_t i = 0;
for(; error != 1; i++)
error >>= 1;
return i;
}
// Evalboard errors
// TODO: Extends API Error bits. For more information, see comment in TMCError typedef.
typedef enum {
TMC_ERROR_TYPE = 0x04,
TMC_ERROR_ADDRESS = 0x04,
TMC_ERROR_NOT_DONE = 0x20
} EvalboardErrorBit;
// Channel identifiers required to switch between channels in readWrite
typedef enum {
CHANNEL_1,
CHANNEL_2
} EvalboardChannels;
// struct for our Evalsystem, with two available Evalboard channels
typedef struct
{
EvalboardFunctionsTypeDef ch1;
EvalboardFunctionsTypeDef ch2;
DriverState driverEnable; // global driver status
} EvalboardsTypeDef;
extern EvalboardsTypeDef Evalboards;
typedef enum {
TMC_BOARD_COMM_DEFAULT,
TMC_BOARD_COMM_SPI,
TMC_BOARD_COMM_UART,
TMC_BOARD_COMM_WLAN
} TMC_Board_Comm_Mode;
// Group all the motion controller chip objects into a single union to save memory,
// since we will only ever use one driver at a time
typedef union {
TMC4361ATypeDef tmc4361A;
TMC5031TypeDef tmc5031;
TMC5041TypeDef tmc5041;
TMC5062TypeDef tmc5062;
TMC5072TypeDef tmc5072;
TMC5130TypeDef tmc5130;
TMC5160TypeDef tmc5160;
TMC8461TypeDef tmc8461;
TMC8462TypeDef tmc8462;
} MotionControllerBoards;
extern MotionControllerBoards motionControllerBoards;
// Group all the driver chip objects into a single union to save memory,
// since we will only ever use one motion controller at a time
typedef union {
TMC2130TypeDef tmc2130;
TMC2160TypeDef tmc2160;
TMC2208TypeDef tmc2208;
TMC2224TypeDef tmc2224;
TMC2590TypeDef tmc2590;
TMC2660TypeDef tmc2660;
TMC7300TypeDef tmc7300;
TMC2209TypeDef tmc2209;
TMC2225TypeDef tmc2225;
TMC2226TypeDef tmc2226;
TMC2300TypeDef tmc2300;
MAX22216TypeDef max22216;
} DriverBoards;
extern DriverBoards driverBoards;
void periodicJobDummy(uint32_t tick);
void board_setDummyFunctions(EvalboardFunctionsTypeDef *channel);
#include "TMCDriver.h"
#include "TMCMotionController.h"
#endif /* BOARD_H */

View File

@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef SELF_TEST_H
#define SELF_TEST_H
#define SELF_TEST_PINS_PER_GROUP 17
#define SELF_TEST_LEAVE 1
#define SELF_TEST_A_OUT_B_IN 2
#define SELF_TEST_A_IN_B_OUT 3
#define SELF_TEST_READ_AN 4
#define SELF_TEST_SET_AN 5
#define SELF_TEST_SET_AN_2 6
#define SELF_TEST_SET_MIXED 7
#define SELF_TEST_SET_EXTIO 8
#endif /* SELF_TEST_H */

View File

@@ -0,0 +1,790 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#include "Board.h"
#include "tmc/ic/TMC2209/TMC2209.h"
#include "tmc/StepDir.h"
#undef TMC2209_MAX_VELOCITY
#define TMC2209_MAX_VELOCITY STEPDIR_MAX_VELOCITY
// Stepdir precision: 2^17 -> 17 digits of precision
#define STEPDIR_PRECISION 131072
#define ERRORS_VM (1<<0)
#define ERRORS_VM_UNDER (1<<1)
#define ERRORS_VM_OVER (1<<2)
#define VM_MIN 50 // VM[V/10] min
#define VM_MAX 390 // VM[V/10] max
#define MOTORS 1
#define VREF_FULLSCALE 2100 // mV // with R308 achievable Vref_max is ~2100mV
//#define VREF_FULLSCALE 3300 // mV // without R308 achievable Vref_max is ~2500mV
static uint32_t right(uint8_t motor, int32_t velocity);
static uint32_t left(uint8_t motor, int32_t velocity);
static uint32_t rotate(uint8_t motor, int32_t velocity);
static uint32_t stop(uint8_t motor);
static uint32_t moveTo(uint8_t motor, int32_t position);
static uint32_t moveBy(uint8_t motor, int32_t *ticks);
static uint32_t GAP(uint8_t type, uint8_t motor, int32_t *value);
static uint32_t SAP(uint8_t type, uint8_t motor, int32_t value);
static void checkErrors (uint32_t tick);
static void deInit(void);
static uint32_t userFunction(uint8_t type, uint8_t motor, int32_t *value);
static void periodicJob(uint32_t tick);
static uint8_t reset(void);
static uint8_t restore(void);
static void enableDriver(DriverState state);
static UART_Config *TMC2209_UARTChannel;
static ConfigurationTypeDef *TMC2209_config;
static uint16_t vref; // mV
static int32_t thigh;
static timer_channel timerChannel;
// Helper macro - Access the chip object in the driver boards union
#define TMC2209 (driverBoards.tmc2209)
// Helper macro - index is always 1 here (channel 1 <-> index 0, channel 2 <-> index 1)
#define TMC2209_CRC(data, length) tmc_CRC8(data, length, 1)
typedef struct
{
IOPinTypeDef *ENN;
IOPinTypeDef *SPREAD;
IOPinTypeDef *STEP;
IOPinTypeDef *DIR;
IOPinTypeDef *MS1_AD0;
IOPinTypeDef *MS2_AD1;
IOPinTypeDef *DIAG;
IOPinTypeDef *INDEX;
IOPinTypeDef *UC_PWM;
IOPinTypeDef *STDBY;
} PinsTypeDef;
static PinsTypeDef Pins;
static inline TMC2209TypeDef *motorToIC(uint8_t motor)
{
UNUSED(motor);
return &TMC2209;
}
static inline UART_Config *channelToUART(uint8_t channel)
{
UNUSED(channel);
return TMC2209_UARTChannel;
}
// => UART wrapper
// Write [writeLength] bytes from the [data] array.
// If [readLength] is greater than zero, read [readLength] bytes from the
// [data] array.
void tmc2209_readWriteArray(uint8_t channel, uint8_t *data, size_t writeLength, size_t readLength)
{
UART_readWrite(channelToUART(channel), data, writeLength, readLength);
}
// <= UART wrapper
// => CRC wrapper
// Return the CRC8 of [length] bytes of data stored in the [data] array.
uint8_t tmc2209_CRC8(uint8_t *data, size_t length)
{
return TMC2209_CRC(data, length);
}
// <= CRC wrapper
void tmc2209_writeRegister(uint8_t motor, uint16_t address, int32_t value)
{
tmc2209_writeInt(motorToIC(motor), (uint8_t) address, value);
}
void tmc2209_readRegister(uint8_t motor, uint16_t address, int32_t *value)
{
*value = tmc2209_readInt(motorToIC(motor), (uint8_t) address);
}
static uint32_t rotate(uint8_t motor, int32_t velocity)
{
if(motor >= MOTORS)
return TMC_ERROR_MOTOR;
StepDir_rotate(motor, velocity);
return TMC_ERROR_NONE;
}
static uint32_t right(uint8_t motor, int32_t velocity)
{
return rotate(motor, velocity);
}
static uint32_t left(uint8_t motor, int32_t velocity)
{
return rotate(motor, -velocity);
}
static uint32_t stop(uint8_t motor)
{
return rotate(motor, 0);
}
static uint32_t moveTo(uint8_t motor, int32_t position)
{
if(motor >= MOTORS)
return TMC_ERROR_MOTOR;
StepDir_moveTo(motor, position);
return TMC_ERROR_NONE;
}
static uint32_t moveBy(uint8_t motor, int32_t *ticks)
{
if(motor >= MOTORS)
return TMC_ERROR_MOTOR;
// determine actual position and add numbers of ticks to move
*ticks += StepDir_getActualPosition(motor);
return moveTo(motor, *ticks);
}
static uint32_t handleParameter(uint8_t readWrite, uint8_t motor, uint8_t type, int32_t *value)
{
uint32_t errors = TMC_ERROR_NONE;
int32_t buffer = 0;
if(motor >= MOTORS)
return TMC_ERROR_MOTOR;
switch(type)
{
case 0:
// Target position
if(readWrite == READ) {
*value = StepDir_getTargetPosition(motor);
} else if(readWrite == WRITE) {
StepDir_moveTo(motor, *value);
}
break;
case 1:
// Actual position
if(readWrite == READ) {
*value = StepDir_getActualPosition(motor);
} else if(readWrite == WRITE) {
StepDir_setActualPosition(motor, *value);
}
break;
case 2:
// Target speed
if(readWrite == READ) {
*value = StepDir_getTargetVelocity(motor);
} else if(readWrite == WRITE) {
StepDir_rotate(motor, *value);
}
break;
case 3:
// Actual speed
if(readWrite == READ) {
*value = StepDir_getActualVelocity(motor);
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
case 4:
// Maximum speed
if(readWrite == READ) {
*value = StepDir_getVelocityMax(motor);
} else if(readWrite == WRITE) {
StepDir_setVelocityMax(motor, abs(*value));
}
break;
case 5:
// Maximum acceleration
if(readWrite == READ) {
*value = StepDir_getAcceleration(motor);
} else if(readWrite == WRITE) {
StepDir_setAcceleration(motor, *value);
}
break;
case 6:
// Maximum current
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_IHOLD_IRUN, TMC2209_IRUN_MASK, TMC2209_IRUN_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_IHOLD_IRUN, TMC2209_IRUN_MASK, TMC2209_IRUN_SHIFT, *value);
}
break;
case 7:
// Standby current
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_IHOLD_IRUN, TMC2209_IHOLD_MASK, TMC2209_IHOLD_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_IHOLD_IRUN, TMC2209_IHOLD_MASK, TMC2209_IHOLD_SHIFT, *value);
}
break;
case 8:
// Position reached flag
if(readWrite == READ) {
*value = (StepDir_getStatus(motor) & STATUS_TARGET_REACHED)? 1:0;
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
case 9:
// VREF
if (readWrite == READ) {
*value = vref;
} else {
if ((uint32_t) *value < VREF_FULLSCALE) {
vref = *value;
Timer.setDuty(timerChannel, ((float)vref) / VREF_FULLSCALE);
} else {
errors |= TMC_ERROR_VALUE;
}
}
break;
case 23:
// Speed threshold for high speed mode
if(readWrite == READ) {
buffer = thigh;
*value = MIN(0xFFFFF, (1<<24) / ((buffer) ? buffer : 1));
} else if(readWrite == WRITE) {
*value = MIN(0xFFFFF, (1<<24) / ((*value) ? *value : 1));
thigh = *value;
}
break;
case 28:
// Internal RSense
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_GCONF, TMC2209_INTERNAL_RSENSE_MASK, TMC2209_INTERNAL_RSENSE_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_GCONF, TMC2209_INTERNAL_RSENSE_MASK, TMC2209_INTERNAL_RSENSE_SHIFT, *value);
}
break;
case 29:
// Measured Speed
if(readWrite == READ) {
buffer = (int32_t)(((int64_t)StepDir_getFrequency(motor) * (int64_t)122) / (int64_t)TMC2209_FIELD_READ(motorToIC(motor), TMC2209_TSTEP, TMC2209_TSTEP_MASK, TMC2209_TSTEP_SHIFT));
*value = (abs(buffer) < 20) ? 0 : buffer;
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
case 50: // StepDir internal(0)/external(1)
if(readWrite == READ) {
*value = StepDir_getMode(motor);
} else if(readWrite == WRITE) {
StepDir_setMode(motor, *value);
}
break;
case 51: // StepDir interrupt frequency
if(readWrite == READ) {
*value = StepDir_getFrequency(motor);
} else if(readWrite == WRITE) {
StepDir_setFrequency(motor, *value);
}
break;
case 140:
// Microstep Resolution
if(readWrite == READ) {
*value = 256 >> TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_MRES_MASK, TMC2209_MRES_SHIFT);
} else if(readWrite == WRITE) {
switch(*value)
{
case 1: *value = 8; break;
case 2: *value = 7; break;
case 4: *value = 6; break;
case 8: *value = 5; break;
case 16: *value = 4; break;
case 32: *value = 3; break;
case 64: *value = 2; break;
case 128: *value = 1; break;
case 256: *value = 0; break;
default: *value = -1; break;
}
if(*value != -1)
{
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_MRES_MASK, TMC2209_MRES_SHIFT, *value);
}
else
{
errors |= TMC_ERROR_VALUE;
}
}
break;
case 162:
// Chopper blank time
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_TBL_MASK, TMC2209_TBL_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_TBL_MASK, TMC2209_TBL_SHIFT, *value);
}
break;
case 165:
// Chopper hysteresis end / fast decay time
if(readWrite == READ) {
if(tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF) & (1<<14))
{
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_HEND_MASK, TMC2209_HEND_SHIFT);
}
else
{
buffer = tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF);
*value = (tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF) >> 4) & 0x07;
if(buffer & (1<<11))
*value |= 1<<3;
}
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
case 166:
// Chopper hysteresis start / sine wave offset
if(readWrite == READ) {
if(tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF) & (1<<14))
{
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_HSTRT_MASK, TMC2209_HSTRT_SHIFT);
}
else
{
buffer = tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF);
*value = (tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF) >> 7) & 0x0F;
if(buffer & (1<<11))
*value |= 1<<3;
}
} else if(readWrite == WRITE) {
if(tmc2209_readInt(motorToIC(motor), TMC2209_CHOPCONF) & (1<<14))
{
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_HSTRT_MASK, TMC2209_HSTRT_SHIFT, *value);
}
else
{
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_HEND_MASK, TMC2209_HEND_SHIFT, *value);
}
}
break;
case 167:
// Chopper off time
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_TOFF_MASK, TMC2209_TOFF_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_TOFF_MASK, TMC2209_TOFF_SHIFT, *value);
}
break;
case 168:
// smartEnergy current minimum (SEIMIN)
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEIMIN_MASK, TMC2209_SEIMIN_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEIMIN_MASK, TMC2209_SEIMIN_SHIFT, *value);
}
break;
case 169:
// smartEnergy current down step
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEDN_MASK, TMC2209_SEDN_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEDN_MASK, TMC2209_SEDN_SHIFT, *value);
}
break;
case 170:
// smartEnergy hysteresis
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEMAX_MASK, TMC2209_SEMAX_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEMAX_MASK, TMC2209_SEMAX_SHIFT, *value);
}
break;
case 171:
// smartEnergy current up step
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEUP_MASK, TMC2209_SEUP_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEUP_MASK, TMC2209_SEUP_SHIFT, *value);
}
break;
case 172:
// smartEnergy hysteresis start
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEMIN_MASK, TMC2209_SEMIN_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_COOLCONF, TMC2209_SEMIN_MASK, TMC2209_SEMIN_SHIFT, *value);
}
break;
case 174:
// stallGuard2 threshold
if(readWrite == READ) {
*value = tmc2209_readInt(motorToIC(motor), TMC2209_SGTHRS);
} else if(readWrite == WRITE) {
tmc2209_writeInt(motorToIC(motor), TMC2209_SGTHRS, *value);
}
break;
case 179:
// VSense
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_VSENSE_MASK, TMC2209_VSENSE_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_CHOPCONF, TMC2209_VSENSE_MASK, TMC2209_VSENSE_SHIFT, *value);
}
break;
case 180:
// smartEnergy actual current
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_DRVSTATUS, TMC2209_CS_ACTUAL_MASK, TMC2209_CS_ACTUAL_SHIFT);
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
case 181:
// smartEnergy stall velocity
if(readWrite == READ) {
*value = StepDir_getStallGuardThreshold(motor);
} else if(readWrite == WRITE) {
// Store the threshold value in the internal StepDir generator
StepDir_setStallGuardThreshold(motor, *value);
// Convert the value for the TCOOLTHRS register
// The IC only sends out Stallguard errors while TCOOLTHRS >= TSTEP >= TPWMTHRS
// The TSTEP value is measured. To prevent measurement inaccuracies hiding
// a stall signal, we decrease the needed velocity by roughly 12% before converting it.
*value -= (*value) >> 3;
if (*value)
{
*value = MIN(0x000FFFFF, (1<<24) / (*value));
}
else
{
*value = 0x000FFFFF;
}
tmc2209_writeInt(motorToIC(motor), TMC2209_TCOOLTHRS, *value);
}
break;
case 182:
// smartEnergy threshold speed
if(readWrite == READ) {
buffer = tmc2209_readInt(motorToIC(motor), TMC2209_TCOOLTHRS);
*value = MIN(0xFFFFF, (1<<24) / ((buffer) ? buffer : 1));
} else if(readWrite == WRITE) {
*value = MIN(0xFFFFF, (1<<24) / ((*value) ? *value : 1));
tmc2209_writeInt(motorToIC(motor), TMC2209_TCOOLTHRS, *value);
}
break;
case 186:
// PWM threshold speed
if(readWrite == READ) {
buffer = tmc2209_readInt(motorToIC(motor), TMC2209_TPWMTHRS);
*value = MIN(0xFFFFF, (1<<24) / ((buffer) ? buffer : 1));
} else if(readWrite == WRITE) {
*value = MIN(0xFFFFF, (1<<24) / ((*value) ? *value : 1));
tmc2209_writeInt(motorToIC(motor), TMC2209_TPWMTHRS, *value);
}
break;
case 187:
// PWM gradient
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_GRAD_MASK, TMC2209_PWM_GRAD_SHIFT);
} else if(readWrite == WRITE) {
// Set gradient
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_GRAD_MASK, TMC2209_PWM_GRAD_SHIFT, *value);
// Enable/disable stealthChop accordingly
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_GCONF, TMC2209_EN_SPREADCYCLE_MASK, TMC2209_EN_SPREADCYCLE_SHIFT, (*value > 0) ? 0 : 1);
}
break;
case 191:
// PWM frequency
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_FREQ_MASK, TMC2209_PWM_FREQ_SHIFT);
} else if(readWrite == WRITE) {
if(*value >= 0 && *value < 4)
{
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_FREQ_MASK, TMC2209_PWM_FREQ_SHIFT, *value);
}
else
{
errors |= TMC_ERROR_VALUE;
}
}
break;
case 192:
// PWM autoscale
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_AUTOSCALE_MASK, TMC2209_PWM_AUTOSCALE_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_PWMCONF, TMC2209_PWM_AUTOSCALE_MASK, TMC2209_PWM_AUTOSCALE_SHIFT, (*value)? 1:0);
}
break;
case 204:
// Freewheeling mode
if(readWrite == READ) {
*value = TMC2209_FIELD_READ(motorToIC(motor), TMC2209_PWMCONF, TMC2209_FREEWHEEL_MASK, TMC2209_FREEWHEEL_SHIFT);
} else if(readWrite == WRITE) {
TMC2209_FIELD_UPDATE(motorToIC(motor), TMC2209_PWMCONF, TMC2209_FREEWHEEL_MASK, TMC2209_FREEWHEEL_SHIFT, *value);
}
break;
case 206:
// Load value
if(readWrite == READ) {
*value = tmc2209_readInt(motorToIC(motor), TMC2209_SG_RESULT);
} else if(readWrite == WRITE) {
errors |= TMC_ERROR_TYPE;
}
break;
default:
errors |= TMC_ERROR_TYPE;
break;
}
return errors;
}
static uint32_t SAP(uint8_t type, uint8_t motor, int32_t value)
{
return handleParameter(WRITE, motor, type, &value);
}
static uint32_t GAP(uint8_t type, uint8_t motor, int32_t *value)
{
return handleParameter(READ, motor, type, value);
}
static void checkErrors(uint32_t tick)
{
UNUSED(tick);
Evalboards.ch2.errors = 0;
}
static uint32_t userFunction(uint8_t type, uint8_t motor, int32_t *value)
{
uint32_t errors = 0;
uint8_t state;
IOPinTypeDef *pin;
switch(type)
{
case 0: // Read StepDir status bits
*value = StepDir_getStatus(motor);
break;
case 1:
tmc2209_set_slave(motorToIC(motor), (*value) & 0xFF);
break;
case 2:
*value = tmc2209_get_slave(motorToIC(motor));
break;
case 3:
*value = Timer.getDuty(timerChannel) * 100 / TIMER_MAX;
break;
case 4:
Timer.setDuty(timerChannel, ((float)*value) / 100);
break;
case 5: // Set pin state
state = (*value) & 0x03;
pin = Pins.ENN;
switch(motor) {
case 0:
pin = Pins.ENN;
break;
case 1:
pin = Pins.SPREAD;
break;
case 2:
pin = Pins.MS1_AD0;
break;
case 3:
pin = Pins.MS2_AD1;
break;
case 4:
pin = Pins.UC_PWM;
break;
case 5:
pin = Pins.STDBY;
break;
}
HAL.IOs->config->setToState(pin, state);
break;
case 6: // Get pin state
pin = Pins.ENN;
switch(motor) {
case 0:
pin = Pins.ENN;
break;
case 1:
pin = Pins.SPREAD;
break;
case 2:
pin = Pins.MS1_AD0;
break;
case 3:
pin = Pins.MS2_AD1;
break;
case 4:
pin = Pins.UC_PWM;
break;
case 5:
pin = Pins.STDBY;
break;
}
*value = (uint32_t) HAL.IOs->config->getState(pin);
break;
default:
errors |= TMC_ERROR_TYPE;
break;
}
return errors;
}
static void deInit(void)
{
enableDriver(DRIVER_DISABLE);
HAL.IOs->config->reset(Pins.ENN);
HAL.IOs->config->reset(Pins.SPREAD);
HAL.IOs->config->reset(Pins.STEP);
HAL.IOs->config->reset(Pins.DIR);
HAL.IOs->config->reset(Pins.MS1_AD0);
HAL.IOs->config->reset(Pins.MS2_AD1);
HAL.IOs->config->reset(Pins.DIAG);
HAL.IOs->config->reset(Pins.INDEX);
HAL.IOs->config->reset(Pins.STDBY);
HAL.IOs->config->reset(Pins.UC_PWM);
StepDir_deInit();
Timer.deInit();
}
static uint8_t reset()
{
StepDir_init(STEPDIR_PRECISION);
StepDir_setPins(0, Pins.STEP, Pins.DIR, Pins.DIAG);
return tmc2209_reset(&TMC2209);
}
static uint8_t restore()
{
return tmc2209_restore(&TMC2209);
}
static void enableDriver(DriverState state)
{
if(state == DRIVER_USE_GLOBAL_ENABLE)
state = Evalboards.driverEnable;
if(state == DRIVER_DISABLE)
HAL.IOs->config->setHigh(Pins.ENN);
else if((state == DRIVER_ENABLE) && (Evalboards.driverEnable == DRIVER_ENABLE))
HAL.IOs->config->setLow(Pins.ENN);
}
static void periodicJob(uint32_t tick)
{
tmc2209_periodicJob(&TMC2209, tick);
StepDir_periodicJob(0);
}
void TMC2209_init(void)
{
#if defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
timerChannel = TIMER_CHANNEL_3;
#elif defined(LandungsbrueckeV3)
timerChannel = TIMER_CHANNEL_4;
#endif
tmc_fillCRC8Table(0x07, true, 1);
thigh = 0;
Pins.ENN = &HAL.IOs->pins->DIO0;
Pins.SPREAD = &HAL.IOs->pins->DIO8;
Pins.STEP = &HAL.IOs->pins->DIO6;
Pins.DIR = &HAL.IOs->pins->DIO7;
Pins.MS1_AD0 = &HAL.IOs->pins->DIO3;
Pins.MS2_AD1 = &HAL.IOs->pins->DIO4;
Pins.DIAG = &HAL.IOs->pins->DIO1;
Pins.INDEX = &HAL.IOs->pins->DIO2;
Pins.UC_PWM = &HAL.IOs->pins->DIO9;
Pins.STDBY = &HAL.IOs->pins->DIO0;
HAL.IOs->config->toOutput(Pins.ENN);
HAL.IOs->config->toOutput(Pins.SPREAD);
HAL.IOs->config->toOutput(Pins.STEP);
HAL.IOs->config->toOutput(Pins.DIR);
HAL.IOs->config->toOutput(Pins.MS1_AD0);
HAL.IOs->config->toOutput(Pins.MS2_AD1);
HAL.IOs->config->toInput(Pins.DIAG);
HAL.IOs->config->toInput(Pins.INDEX);
HAL.IOs->config->setLow(Pins.MS1_AD0);
HAL.IOs->config->setLow(Pins.MS2_AD1);
TMC2209_UARTChannel = HAL.UART;
TMC2209_UARTChannel->pinout = UART_PINS_2;
TMC2209_UARTChannel->rxtx.init();
TMC2209_config = Evalboards.ch2.config;
Evalboards.ch2.config->reset = reset;
Evalboards.ch2.config->restore = restore;
Evalboards.ch2.rotate = rotate;
Evalboards.ch2.right = right;
Evalboards.ch2.left = left;
Evalboards.ch2.stop = stop;
Evalboards.ch2.GAP = GAP;
Evalboards.ch2.SAP = SAP;
Evalboards.ch2.moveTo = moveTo;
Evalboards.ch2.moveBy = moveBy;
Evalboards.ch2.writeRegister = tmc2209_writeRegister;
Evalboards.ch2.readRegister = tmc2209_readRegister;
Evalboards.ch2.userFunction = userFunction;
Evalboards.ch2.enableDriver = enableDriver;
Evalboards.ch2.checkErrors = checkErrors;
Evalboards.ch2.numberOfMotors = MOTORS;
Evalboards.ch2.VMMin = VM_MIN;
Evalboards.ch2.VMMax = VM_MAX;
Evalboards.ch2.deInit = deInit;
Evalboards.ch2.periodicJob = periodicJob;
tmc2209_init(&TMC2209, 0, 0, TMC2209_config, &tmc2209_defaultRegisterResetState[0]);
StepDir_init(STEPDIR_PRECISION);
StepDir_setPins(0, Pins.STEP, Pins.DIR, Pins.DIAG);
StepDir_setVelocityMax(0, 51200);
StepDir_setAcceleration(0, 51200);
HAL.IOs->config->toOutput(Pins.UC_PWM);
#if defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
Pins.UC_PWM->configuration.GPIO_Mode = GPIO_Mode_AF4;
#elif defined(LandungsbrueckeV3)
Pins.UC_PWM->configuration.GPIO_Mode = GPIO_MODE_AF;
gpio_af_set(Pins.UC_PWM->port, GPIO_AF_1, Pins.UC_PWM->bitWeight);
#endif
vref = 2000;
HAL.IOs->config->set(Pins.UC_PWM);
Timer.init();
Timer.setDuty(timerChannel, ((float)vref) / VREF_FULLSCALE);
enableDriver(DRIVER_ENABLE);
};

View File

@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#include "TMCDriver.h"
EvalBoardDriverTypeDef TMCDriver =
{
.config =
{
.state = CONFIG_READY,
.configIndex = 0,
.shadowRegister = { 0 }
}
};
void tmcdriver_init()
{
Evalboards.ch2.config = &TMCDriver.config;
Evalboards.ch2.config->state = CONFIG_READY;
Evalboards.ch2.config->configIndex = 0;
// A value of 0 indicates the Evalboard not connecting the VM line,
// resulting in skipped global minimum voltage checks.
// A negative value indicates no board being connected, which skips the
// minimum voltage check for that channel
Evalboards.ch2.VMMin = -1;
Evalboards.ch2.VMMax = s32_MAX;
Evalboards.ch2.numberOfMotors = 0;
Evalboards.ch2.errors = 0;
Evalboards.ch2.config->channel = CHANNEL_2;
board_setDummyFunctions(&Evalboards.ch2);
}

View File

@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef TMCDRIVER_H_
#define TMCDRIVER_H_
#include "Board.h"
typedef struct
{
ConfigurationTypeDef config;
} EvalBoardDriverTypeDef;
extern EvalBoardDriverTypeDef TMCDriver;
void tmcdriver_init();
#endif /* TMCDRIVER_H_ */

View File

@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#include "TMCMotionController.h"
EvalBoardMotionControllerTypeDef TMCMotionController =
{
.config =
{
.state = CONFIG_READY,
.configIndex = 0,
.shadowRegister = { 0 }
}
};
void tmcmotioncontroller_init()
{
Evalboards.ch1.config = &TMCMotionController.config;
Evalboards.ch1.config->state = CONFIG_READY;
Evalboards.ch1.config->configIndex = 0;
// A value of 0 indicates the Evalboard not connecting the VM line,
// resulting in skipped global minimum voltage checks.
// A negative value indicates no board being connected, which skips the
// minimum voltage check for that channel
Evalboards.ch1.VMMin = -1;
Evalboards.ch1.VMMax = s32_MAX;
Evalboards.ch1.numberOfMotors = 0;
Evalboards.ch1.errors = 0;
Evalboards.ch1.config->channel = CHANNEL_1;
board_setDummyFunctions(&Evalboards.ch1);
}

View File

@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef TMCMOTIONCONTROLLER_H_
#define TMCMOTIONCONTROLLER_H_
#include "Board.h"
typedef struct
{
ConfigurationTypeDef config;
} EvalBoardMotionControllerTypeDef;
extern EvalBoardMotionControllerTypeDef TMCMotionController;
void tmcmotioncontroller_init();
#endif /* TMCMOTIONCONTROLLER_H_ */

View File

@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef ADC_H
#define ADC_H
#include <stdint.h>
#define N_O_ADC_CHANNELS 7
static volatile uint16_t ADCValue[N_O_ADC_CHANNELS];
typedef struct
{
volatile uint16_t *AIN0;
volatile uint16_t *AIN1;
volatile uint16_t *AIN2;
volatile uint16_t *DIO4;
volatile uint16_t *DIO5;
volatile uint16_t *VM;
volatile uint16_t *AIN_EXT; // Only LB_V3
void (*init)();
void (*deInit)();
} ADCTypeDef;
extern ADCTypeDef ADCs;
#endif /* ADC_H */

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef _HAL_H_
#define _HAL_H_
#include "derivative.h"
#include "IOs.h"
#include "IOMap.h"
#include "SPI.h"
#include "ADCs.h"
#include "USB.h"
#include "LEDs.h"
#include "RS232.h"
#include "WLAN.h"
#include "Timer.h"
#include "SysTick.h"
#include "UART.h"
typedef struct
{
IOsTypeDef *config;
IOPinMapTypeDef *pins;
} IOsFunctionsTypeDef;
typedef struct
{
void (*init) (void);
void (*reset) (uint8_t ResetPeripherals);
void (*NVIC_DeInit)(void);
const IOsFunctionsTypeDef *IOs;
SPITypeDef *SPI;
RXTXTypeDef *USB;
LEDsTypeDef *LEDs;
ADCTypeDef *ADCs;
RXTXTypeDef *RS232;
RXTXTypeDef *WLAN;
TimerTypeDef *Timer;
UART_Config *UART;
} HALTypeDef;
extern const HALTypeDef HAL;
extern uint8_t hwid;
#endif /* _HAL_H_ */

View File

@@ -0,0 +1,124 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef _IO_PIN_MAP_H_
#define _IO_PIN_MAP_H_
#include "IOs.h"
typedef struct
{
void (*init) (void);
IOPinTypeDef **pins; // Map Pin ID <=> Pin
IOPinTypeDef ID_CLK;
IOPinTypeDef ID_CH0;
IOPinTypeDef ID_CH1;
IOPinTypeDef DIO0;
IOPinTypeDef DIO1;
IOPinTypeDef DIO2;
IOPinTypeDef DIO3;
IOPinTypeDef DIO4;
IOPinTypeDef DIO5;
IOPinTypeDef DIO6;
IOPinTypeDef DIO7;
IOPinTypeDef DIO8;
IOPinTypeDef DIO9;
IOPinTypeDef DIO10;
IOPinTypeDef DIO11;
IOPinTypeDef CLK16;
IOPinTypeDef SPI2_CSN0;
IOPinTypeDef SPI2_CSN1;
IOPinTypeDef SPI2_CSN2;
IOPinTypeDef SPI2_SCK;
IOPinTypeDef SPI2_SDO;
IOPinTypeDef SPI2_SDI;
IOPinTypeDef SPI1_CSN;
IOPinTypeDef SPI1_SCK;
IOPinTypeDef SPI1_SDI;
IOPinTypeDef SPI1_SDO;
IOPinTypeDef DIO12;
IOPinTypeDef DIO13;
IOPinTypeDef DIO14;
IOPinTypeDef DIO15;
IOPinTypeDef DIO16;
IOPinTypeDef DIO17;
IOPinTypeDef DIO18;
IOPinTypeDef DIO19;
IOPinTypeDef RS232_TX;
IOPinTypeDef RS232_RX;
IOPinTypeDef USB_V_BUS;
IOPinTypeDef USB_V_DM;
IOPinTypeDef USB_V_DP;
IOPinTypeDef LED_STAT;
IOPinTypeDef LED_ERROR;
IOPinTypeDef EEPROM_SCK;
IOPinTypeDef EEPROM_SI;
IOPinTypeDef EEPROM_SO;
IOPinTypeDef EEPROM_NCS;
#if defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
IOPinTypeDef WIRELESS_TX;
IOPinTypeDef WIRELESS_RX;
IOPinTypeDef WIRELESS_NRST;
IOPinTypeDef MIXED0;
IOPinTypeDef MIXED1;
IOPinTypeDef MIXED2;
IOPinTypeDef MIXED3;
IOPinTypeDef MIXED4;
IOPinTypeDef MIXED5;
IOPinTypeDef MIXED6;
IOPinTypeDef ID_HW_0;
IOPinTypeDef ID_HW_1;
IOPinTypeDef ID_HW_2;
IOPinTypeDef EXTIO_2;
IOPinTypeDef EXTIO_3;
IOPinTypeDef EXTIO_4;
IOPinTypeDef EXTIO_5;
IOPinTypeDef EXTIO_6;
IOPinTypeDef EXTIO_7;
#endif
#if defined(LandungsbrueckeV3)
IOPinTypeDef DIO10_PWM_WL;
IOPinTypeDef DIO10_UART_TX;
IOPinTypeDef DIO11_PWM_WH;
IOPinTypeDef DIO11_UART_RX;
IOPinTypeDef SW_UART_PWM;
IOPinTypeDef EXT0;
IOPinTypeDef EXT1;
IOPinTypeDef EXT2;
IOPinTypeDef EXT3;
IOPinTypeDef EXT4;
IOPinTypeDef ADC_VM;
IOPinTypeDef AIN0;
IOPinTypeDef AIN1;
IOPinTypeDef AIN2;
IOPinTypeDef AIN_EXT;
IOPinTypeDef WIFI_EN;
IOPinTypeDef WIFI_RST;
IOPinTypeDef WIFI_TX;
IOPinTypeDef WIFI_RX;
IOPinTypeDef BUTTON;
#endif
IOPinTypeDef DUMMY;
} IOPinMapTypeDef;
extern IOPinMapTypeDef IOMap;
#endif /* _IO_PIN_MAP_H_ */

View File

@@ -0,0 +1,164 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef _IO_H_
#define _IO_H_
// #include "derivative.h"
typedef enum { // Give bits explicitly, because IDE relies on it.
IOS_LOW = 0b00,
IOS_HIGH = 0b01,
IOS_OPEN = 0b10,
IOS_NOCHANGE = 0b11
} IO_States;
#if defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
// use ST like configuration structures also for Landungsbruecke
typedef enum
{
GPIO_Mode_AN = 0x00, /*!< GPIO Analog Mode, Pin disabled */
GPIO_Mode_AF1 = 0x01, /*!< GPIO Alternate function Mode GPIO*/
GPIO_Mode_AF2 = 0x02, /*!< GPIO Alternate function Mode*/
GPIO_Mode_AF3 = 0x03, /*!< GPIO Alternate function Mode*/
GPIO_Mode_AF4 = 0x04, /*!< GPIO Alternate function Mode*/
GPIO_Mode_AF5 = 0x05, /*!< GPIO Alternate function Mode*/
GPIO_Mode_AF6 = 0x06, /*!< GPIO Alternate function Mode*/
GPIO_Mode_AF7 = 0x07, /*!< GPIO Alternate function Mode*/
GPIO_Mode_IN = 0x08, /*!< GPIO Input Mode */
GPIO_Mode_OUT = 0x09 /*!< GPIO Output Mode */
} GPIOMode_TypeDef;
typedef enum
{
GPIO_OType_PP = 0x00,
GPIO_OType_OD = 0x01
} GPIOOType_TypeDef;
typedef enum
{
GPIO_PuPd_NOPULL = 0x00,
GPIO_PuPd_UP = 0x01,
GPIO_PuPd_DOWN = 0x02
} GPIOPuPd_TypeDef;
typedef enum
{
GPIO_Speed_2MHz = 0x00, /*!< Low speed */
GPIO_Speed_25MHz = 0x01, /*!< Medium speed */
GPIO_Speed_50MHz = 0x02, /*!< Fast speed */
GPIO_Speed_100MHz = 0x03 /*!< High speed on 30 pF (80 MHz Output max speed on 15 pF) */
} GPIOSpeed_TypeDef;
#include "hal/Landungsbruecke/freescale/PDD/GPIO_PDD.h"
#elif defined(LandungsbrueckeV3)
// typedef enum
// {
// GPIO_MODE_INPUT = 0x00, /*!< GPIO Input Mode */
// GPIO_MODE_OUTPUT = 0x01, /*!< GPIO Output Mode */
// GPIO_MODE_AF = 0x02, /*!< GPIO Alternate function Mode*/
// GPIO_MODE_ANALOG = 0x03, /*!< GPIO Analog Mode*/
// } GPIOMode_TypeDef;
//
// typedef enum
// {
// GPIO_OTYPE_PP = 0x00,
// GPIO_OTYPE_OD = 0x01
// } GPIOOType_TypeDef;
//
// typedef enum
// {
// GPIO_PUPD_NONE = 0x00,
// GPIO_PUPD_PULLUP = 0x01,
// GPIO_PUPD_PULLDOWN = 0x02
// } GPIOPuPd_TypeDef;
//
// typedef enum
// {
// GPIO_OSPEED_2MHZ = 0x00, /*!< Low speed */
// GPIO_OSPEED_25MHZ = 0x01, /*!< Medium speed */
// GPIO_OSPEED_50MHZ = 0x02, /*!< Fast speed */
// GPIO_OSPEED_MAX = 0x03 /*!< GPIO very high output speed, max speed more than 50MHz */
// } GPIOSpeed_TypeDef;
typedef uint32_t GPIOMode_TypeDef;
typedef uint32_t GPIOOType_TypeDef;
typedef uint32_t GPIOPuPd_TypeDef;
typedef uint32_t GPIOSpeed_TypeDef;
#endif
enum IOsHighLevelFunctions { IO_DEFAULT, IO_DI, IO_AI, IO_DO, IO_PWM, IO_SD, IO_CLK16, IO_SPI };
typedef struct
{
const uint8_t DEFAULT;
const uint8_t DI;
const uint8_t AI;
const uint8_t DO;
const uint8_t PWM;
const uint8_t SD;
const uint8_t CLK16;
const uint8_t SPI;
} IOsHighLevelFunctionTypeDef;
typedef struct
{
GPIOMode_TypeDef GPIO_Mode;
GPIOSpeed_TypeDef GPIO_Speed;
GPIOOType_TypeDef GPIO_OType;
GPIOPuPd_TypeDef GPIO_PuPd;
} IOPinInitTypeDef;
typedef struct
{
#if defined(LandungsbrueckeV3)
uint32_t port;
volatile uint32_t *setBitRegister;
volatile uint32_t *resetBitRegister;
#elif defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
PORT_MemMapPtr portBase;
GPIO_MemMapPtr GPIOBase;
volatile uint32_t *setBitRegister;
volatile uint32_t *resetBitRegister;
#endif
uint32_t bitWeight;
unsigned char bit;
IOPinInitTypeDef configuration;
IOPinInitTypeDef resetConfiguration;
enum IOsHighLevelFunctions highLevelFunction;
IO_States state;
} IOPinTypeDef;
typedef struct
{
void (*set)(IOPinTypeDef *pin);
void (*copy)(IOPinInitTypeDef *from, IOPinTypeDef*to);
void (*reset)(IOPinTypeDef *pin);
void (*toOutput)(IOPinTypeDef *pin);
void (*toInput)(IOPinTypeDef *pin);
void (*setHigh)(IOPinTypeDef *pin);
void (*setLow)(IOPinTypeDef *pin);
void (*setToState)(IOPinTypeDef *pin, IO_States state);
IO_States (*getState)(IOPinTypeDef *pin);
unsigned char (*isHigh)(IOPinTypeDef *pin);
void (*init)(void);
IOsHighLevelFunctionTypeDef HIGH_LEVEL_FUNCTIONS;
} IOsTypeDef;
extern IOsTypeDef IOs;
// A bit weight of 0 is used to indicate a nonexistent pin
#define DUMMY_BITWEIGHT 0
#define IS_DUMMY_PIN(pin) (pin->bitWeight == DUMMY_BITWEIGHT)
#endif /* _IO_H_ */

View File

@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright © 2019 TRINAMIC Motion Control GmbH & Co. KG
* (now owned by Analog Devices Inc.),
*
* Copyright © 2023 Analog Devices Inc. All Rights Reserved. This software is
* proprietary & confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************/
#ifndef LEDS_H_
#define LEDS_H_
#if defined(Landungsbruecke) || defined(LandungsbrueckeSmall)
#define LED_ON() *HAL.IOs->pins->LED_STAT.resetBitRegister = HAL.IOs->pins->LED_STAT.bitWeight
#define LED_OFF() *HAL.IOs->pins->LED_STAT.setBitRegister = HAL.IOs->pins->LED_STAT.bitWeight
#define LED_TOGGLE() HAL.IOs->pins->LED_STAT.GPIOBase->PTOR ^= GPIO_PTOR_PTTO(HAL.IOs->pins->LED_STAT.bitWeight)
#define LED_ERROR_ON() *HAL.IOs->pins->LED_ERROR.resetBitRegister = HAL.IOs->pins->LED_ERROR.bitWeight
#define LED_ERROR_OFF() *HAL.IOs->pins->LED_ERROR.setBitRegister = HAL.IOs->pins->LED_ERROR.bitWeight
#define LED_ERROR_TOGGLE() HAL.IOs->pins->LED_ERROR.GPIOBase->PTOR ^= GPIO_PTOR_PTTO(HAL.IOs->pins->LED_ERROR.bitWeight)
#elif defined(LandungsbrueckeV3)
#define LED_ON() *HAL.IOs->pins->LED_STAT.resetBitRegister = HAL.IOs->pins->LED_STAT.bitWeight
#define LED_OFF() *HAL.IOs->pins->LED_STAT.setBitRegister = HAL.IOs->pins->LED_STAT.bitWeight
#define LED_TOGGLE() GPIO_TG(HAL.IOs->pins->LED_STAT.port) = HAL.IOs->pins->LED_STAT.bitWeight
#define LED_ERROR_ON() *HAL.IOs->pins->LED_ERROR.resetBitRegister = HAL.IOs->pins->LED_ERROR.bitWeight
#define LED_ERROR_OFF() *HAL.IOs->pins->LED_ERROR.setBitRegister = HAL.IOs->pins->LED_ERROR.bitWeight
#define LED_ERROR_TOGGLE() GPIO_TG(HAL.IOs->pins->LED_ERROR.port) = HAL.IOs->pins->LED_ERROR.bitWeight
#endif
#include "IOs.h"
typedef struct
{
void (*on)(void);
void (*off)(void);
void (*toggle)(void);
} LEDTypeDef;
typedef struct
{
void (*init)(void);
LEDTypeDef stat;
LEDTypeDef error;
} LEDsTypeDef;
extern LEDsTypeDef LEDs;
#endif /* LEDS_H_ */

View File

@@ -0,0 +1,295 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Cpu.c
** Project : FS_TC_Test
** Processor : MK20DN512VLL10
** Component : MK20DN512LL10
** Version : Component 01.000, Driver 01.04, CPU db: 3.00.000
** Datasheet : K20P144M100SF2V2RM Rev. 2, Jun 2012
** Compiler : GNU C Compiler
** Date/Time : 2014-12-22, 13:39, # CodeGen: 7
** Abstract :
**
** Settings :
**
** Contents :
** No public methods
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file Cpu.c
** @version 01.04
** @brief
**
*/
/*!
** @addtogroup Cpu_module Cpu module documentation
** @{
*/
/* MODULE Cpu. */
/* {Default RTOS Adapter} No RTOS includes */
#include "hal/derivative.h"
#include "Cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Global variables */
volatile uint8 SR_reg; /* Current value of the FAULTMASK register */
volatile uint8 SR_lock = 0x00U; /* Lock */
void LowLevelInit(void);
void InitClocks(void);
CpuTypeDef Cpu =
{
.initClocks = InitClocks,
.initLowLevel = LowLevelInit,
};
/*
** ===================================================================
** Method : Cpu_SetBASEPRI (component MK20DN512LL10)
**
** Description :
** This method sets the BASEPRI core register.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void Cpu_SetBASEPRI(uint32 Level);
/*
** ===================================================================
** Method : Cpu_INT_NMIInterrupt (component MK20DN512LL10)
**
** Description :
** This ISR services the Non Maskable Interrupt interrupt.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void __attribute__ ((interrupt)) Cpu_INT_NMIInterrupt(void)
{
}
/*
** ===================================================================
** Method : Cpu_Cpu_Interrupt (component MK20DN512LL10)
**
** Description :
** This ISR services an unused interrupt/exception vector.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void __attribute__ ((interrupt)) Cpu_Interrupt(void)
{
/* This code can be changed using the CPU component property "Build Options / Unhandled int code" */
PE_DEBUGHALT();
}
/***************************************************************//**
\fn InitClocks(void)
\brief Initialize the clock PLL
This function inializes the PLL to 96MHz (with 16MHz crystal
freqeuncy) and then switches to PLL clock.
So the following frequencies are used:
Core: 96MHz
Bus: 48MHz
FlexBus: 48MHz
Flash: 24MHz
This routine has been generated by ProcessorExpert and cleaned
up manually.
********************************************************************/
void InitClocks(void)
{
//Turn on clocking for all ports to enable pin routing
SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK
| SIM_SCGC5_PORTB_MASK
| SIM_SCGC5_PORTC_MASK
| SIM_SCGC5_PORTD_MASK
| SIM_SCGC5_PORTE_MASK );
//PLL already selected by bootloader? => exit
if((MCG_S & 0x0C)==0x0C) return;
SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0x00) |
SIM_CLKDIV1_OUTDIV2(0x01) |
SIM_CLKDIV1_OUTDIV3(0x03) |
SIM_CLKDIV1_OUTDIV4(0x03); /* Set the system prescalers to safe value */
if((PMC_REGSC & PMC_REGSC_ACKISO_MASK) != 0x0U)
{
/* PMC_REGSC: ACKISO=1 */
PMC_REGSC |= PMC_REGSC_ACKISO_MASK; /* Release IO pads after wakeup from VLLS mode. */
}
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=1,OUTDIV3=1,OUTDIV4=3,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0x00) |
SIM_CLKDIV1_OUTDIV2(0x01) |
SIM_CLKDIV1_OUTDIV3(0x01) |
SIM_CLKDIV1_OUTDIV4(0x03); /* Update system prescalers */
/* SIM_SOPT2: PLLFLLSEL=1 */
SIM_SOPT2 |= SIM_SOPT2_PLLFLLSEL_MASK|SIM_SOPT2_CLKOUTSEL(6); /* Select PLL as a clock source for various peripherals */
/* SIM_SOPT1: OSC32KSEL=3 */
SIM_SOPT1 |= SIM_SOPT1_OSC32KSEL(0x03); /* LPO 1kHz oscillator drives 32 kHz clock for various peripherals */
/* Switch to FBE Mode */
/* MCG_C2: LOCRE0=0,??=0,RANGE0=2,HGO0=0,EREFS0=1,LP=0,IRCS=0 */
MCG_C2 = (MCG_C2_RANGE0(0x02) | MCG_C2_EREFS0_MASK);
/* OSC_CR: ERCLKEN=1,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
OSC_CR = OSC_CR_ERCLKEN_MASK;
/* MCG_C1: CLKS=2,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
MCG_C1 = (MCG_C1_CLKS(0x02) | MCG_C1_FRDIV(0x04) | MCG_C1_IRCLKEN_MASK);
/* MCG_C4: DMX32=0,DRST_DRS=0 */
MCG_C4 &= (uint8)~(uint8)((MCG_C4_DMX32_MASK | MCG_C4_DRST_DRS(0x03)));
/* MCG_C5: ??=0,PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=3 */
MCG_C5 = MCG_C5_PRDIV0(0x03);
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=0 */
MCG_C6 = MCG_C6_VDIV0(0x00);
while((MCG_S & MCG_S_OSCINIT0_MASK) == 0x00U); /* Check that the oscillator is running */
while((MCG_S & MCG_S_IREFST_MASK) != 0x00U); /* Check that the source of the FLL reference clock is the external reference clock. */
while((MCG_S & 0x0CU) != 0x08U); /* Wait until external reference clock is selected as MCG output */
/* Switch to PBE Mode */
/* MCG_C6: LOLIE0=0,PLLS=1,CME0=0,VDIV0=0 */
MCG_C6 = (MCG_C6_PLLS_MASK | MCG_C6_VDIV0(0x00));
while((MCG_S & 0x0CU) != 0x08U); /* Wait until external reference clock is selected as MCG output */
while((MCG_S & MCG_S_LOCK0_MASK) == 0x00U); /* Wait until locked */
/* Switch to PEE Mode */
/* MCG_C1: CLKS=0,FRDIV=4,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
MCG_C1 = (MCG_C1_CLKS(0x00) | MCG_C1_FRDIV(0x04) | MCG_C1_IRCLKEN_MASK);
while((MCG_S & 0x0CU) != 0x0CU); /* Wait until output of the PLL is selected */
}
/*
** ===================================================================
** Method : Cpu_SetBASEPRI (component MK20DN512LL10)
**
** Description :
** This method sets the BASEPRI core register.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/*lint -save -e586 -e950 Disable MISRA rule (2.1,1.1) checking. */
#ifdef _lint
#define Cpu_SetBASEPRI(Level) /* empty */
#else
void Cpu_SetBASEPRI(uint32 Level) {
__asm ("msr basepri, %[input]"::[input] "r" (Level):);
}
#endif
/*lint -restore Enable MISRA rule (2.1,1.1) checking. */
/***************************************************************//**
\fn LowLevelInit(void)
\brief Low level initialization of the MCU
This function does some low level initialization of the MCU.
Generated by ProcessorExpert and then cleaned up manually.
********************************************************************/
void LowLevelInit(void)
{
/* Initialization of the RCM module */ //***TEST_OK: Kann je nach Beschaltung des Reset-Pins zum Absturz führen
/* RCM_RPFW: RSTFLTSEL=0 */
RCM_RPFW &= (uint8)~(uint8)(RCM_RPFW_RSTFLTSEL(0x1F));
/* RCM_RPFC: RSTFLTSS=0,RSTFLTSRW=0 */
RCM_RPFC &= (uint8)~(uint8)(
RCM_RPFC_RSTFLTSS_MASK |
RCM_RPFC_RSTFLTSRW(0x03)
);
/* Initialization of the FTFL_FlashConfig module */
/* SIM_SCGC7: MPU=1 */
SIM_SCGC7 |= SIM_SCGC7_MPU_MASK;
/* Initialization of the MPU module */
//Turn off MPU (important e.g. for the USB stack to work properly)
/* MPU_CESR: SPERR=0,VLD=0 */
MPU_CESR &= (uint32)~(uint32)((MPU_CESR_SPERR(0x1F) | MPU_CESR_VLD_MASK));
/* Initialization of the PMC module */
/* PMC_LVDSC1: LVDACK=1,LVDIE=0,LVDRE=1,LVDV=0 */
PMC_LVDSC1 = (uint8)((PMC_LVDSC1 & (uint8)~(uint8)(
PMC_LVDSC1_LVDIE_MASK |
PMC_LVDSC1_LVDV(0x03)
)) | (uint8)(
PMC_LVDSC1_LVDACK_MASK |
PMC_LVDSC1_LVDRE_MASK
));
/* PMC_LVDSC2: LVWACK=1,LVWIE=0,LVWV=0 */
PMC_LVDSC2 = (uint8)((PMC_LVDSC2 & (uint8)~(uint8)(
PMC_LVDSC2_LVWIE_MASK |
PMC_LVDSC2_LVWV(0x03)
)) | (uint8)(
PMC_LVDSC2_LVWACK_MASK
));
/* PMC_REGSC: BGEN=0,ACKISO=0,BGBE=0 */
PMC_REGSC &= (uint8)~(uint8)(
PMC_REGSC_BGEN_MASK |
PMC_REGSC_ACKISO_MASK |
PMC_REGSC_BGBE_MASK
);
/* SMC_PMPROT: ??=0,??=0,AVLP=0,??=0,ALLS=0,??=0,AVLLS=0,??=0 */
SMC_PMPROT = 0x00U; /* Setup Power mode protection register */
//Interrupt priority base setting
Cpu_SetBASEPRI(0);
}
/* END Cpu. */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,202 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Cpu.h
** Project : FS_TC_Test
** Processor : MK20DN512VLL10
** Component : MK20DN512LL10
** Version : Component 01.000, Driver 01.04, CPU db: 3.00.000
** Datasheet : K20P144M100SF2V2RM Rev. 2, Jun 2012
** Compiler : GNU C Compiler
** Date/Time : 2014-12-17, 14:57, # CodeGen: 6
** Abstract :
**
** Settings :
**
** Contents :
** No public methods
**
** (c) Freescale Semiconductor, Inc.
** 2004 All Rights Reserved
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file Cpu.h
** @version 01.04
** @brief
**
*/
/*!
** @addtogroup Cpu_module Cpu module documentation
** @{
*/
#ifndef __Cpu_H
#define __Cpu_H
/* MODULE Cpu. */
/*Include shared modules, which are used for whole project*/
#include "USB_CDC/PE_Types.h"
#include "USB_CDC/PE_Error.h"
#include "USB_CDC/PE_Const.h"
#include "hal/derivative.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Active configuration define symbol */
#define PEcfg_FLASH 1U
/* Methods configuration constants - generated for all enabled component's methods */
/* Events configuration constants - generated for all enabled component's events */
#define Cpu_OnNMIINT_EVENT_ENABLED
#define CPU_BUS_CLK_HZ 48000000U /* Initial value of the bus clock frequency in Hz */
#define CPU_CORE_CLK_HZ 96000000U /* Initial value of the core/system clock frequency in Hz. */
#define CPU_CLOCK_CONFIG_NUMBER 0x01U /* Specifies number of defined clock configurations. */
#define CPU_BUS_CLK_HZ_CLOCK_CONFIG0 48000000U /* Value of the bus clock frequency in the clock configuration 0 in Hz. */
#define CPU_CORE_CLK_HZ_CLOCK_CONFIG0 96000000U /* Value of the core/system clock frequency in the clock configuration 0 in Hz. */
#define CPU_XTAL_CLK_HZ 16000000U /* Value of the external crystal or oscillator clock frequency in Hz */
#define CPU_INT_SLOW_CLK_HZ 32768U /* Value of the slow internal oscillator clock frequency in Hz */
#define CPU_INT_FAST_CLK_HZ 4000000U /* Value of the fast internal oscillator clock frequency in Hz */
#define CPU_FAMILY_Kinetis /* Specification of the core type of the selected cpu */
#define CPU_DERIVATIVE_MK20DN512LL10 /* Name of the selected cpu derivative */
#define CPU_PARTNUM_MK20DN512VLL10 /* Part number of the selected cpu */
#define CPU_LITTLE_ENDIAN /* The selected cpu uses little endian */
/* CPU frequencies in clock configuration 0 */
#define CPU_CLOCK_CONFIG_0 0x00U /* Clock configuration 0 identifier */
#define CPU_CORE_CLK_HZ_CONFIG_0 96000000UL /* Core clock frequency in clock configuration 0 */
#define CPU_BUS_CLK_HZ_CONFIG_0 48000000UL /* Bus clock frequency in clock configuration 0 */
#define CPU_FLEXBUS_CLK_HZ_CONFIG_0 48000000UL /* Flexbus clock frequency in clock configuration 0 */
#define CPU_FLASH_CLK_HZ_CONFIG_0 24000000UL /* FLASH clock frequency in clock configuration 0 */
#define CPU_USB_CLK_HZ_CONFIG_0 0UL /* USB clock frequency in clock configuration 0 */
#define CPU_PLL_FLL_CLK_HZ_CONFIG_0 96000000UL /* PLL/FLL clock frequency in clock configuration 0 */
#define CPU_MCGIR_CLK_HZ_CONFIG_0 32768UL /* MCG internal reference clock frequency in clock configuration 0 */
#define CPU_OSCER_CLK_HZ_CONFIG_0 16000000UL /* System OSC external reference clock frequency in clock configuration 0 */
#define CPU_ERCLK32K_CLK_HZ_CONFIG_0 1000UL /* External reference clock 32k frequency in clock configuration 0 */
#define CPU_MCGFF_CLK_HZ_CONFIG_0 31250UL /* MCG fixed frequency clock */
typedef struct {
uint32 cpu_core_clk_hz; /* Core clock frequency in clock configuration */
uint32 cpu_bus_clk_hz; /* Bus clock frequency in clock configuration */
uint32 cpu_flexbus_clk_hz; /* Flexbus clock frequency in clock configuration */
uint32 cpu_flash_clk_hz; /* FLASH clock frequency in clock configuration */
uint32 cpu_usb_clk_hz; /* USB clock frequency in clock configuration */
uint32 cpu_pll_fll_clk_hz; /* PLL/FLL clock frequency in clock configuration */
uint32 cpu_mcgir_clk_hz; /* MCG internal reference clock frequency in clock configuration */
uint32 cpu_oscer_clk_hz; /* System OSC external reference clock frequency in clock configuration */
uint32 cpu_erclk32k_clk_hz; /* External reference clock 32k frequency in clock configuration */
uint32 cpu_mcgff_clk_hz; /* MCG fixed frequency clock */
} TCpuClockConfiguration;
/* The array of clock frequencies in configured clock configurations */
extern const TCpuClockConfiguration PE_CpuClockConfigurations[CPU_CLOCK_CONFIG_NUMBER];
/* Interrupt vector table type definition */
typedef void (*const tIsrFunc)(void);
typedef struct {
void * __ptr;
tIsrFunc __fun[0x77];
} tVectorTable;
extern const tVectorTable __vect_table;
/* Global variables */
/*lint -esym(765,SR_reg) Disable MISRA rule (8.10) checking for symbols (SR_reg). The SR_reg is used in inline assembler. */
extern volatile uint8 SR_reg; /* Current FAULTMASK register */
/*lint -esym(765,SR_lock) Disable MISRA rule (8.10) checking for symbols (SR_lock). The SR_reg is used in inline assembler. */
extern volatile uint8 SR_lock;
typedef struct
{
void (*initClocks)(void);
void (*initLowLevel)(void);
} CpuTypeDef;
extern CpuTypeDef Cpu;
/* {Default RTOS Adapter} ISR function prototype */
void __attribute__ ((interrupt)) Cpu_INT_NMIInterrupt(void);
/*
** ===================================================================
** Method : Cpu_INT_NMIInterrupt (component MK20DN512LL10)
**
** Description :
** This ISR services the Non Maskable Interrupt interrupt.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void __attribute__ ((interrupt)) Cpu_Interrupt(void);
/*
** ===================================================================
** Method : Cpu_Cpu_Interrupt (component MK20DN512LL10)
**
** Description :
** This ISR services an unused interrupt/exception vector.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/* END Cpu. */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
/* __Cpu_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,205 @@
/*
*****************************************************************************
**
** File : MK20DN512.ld
**
** Default linker command file for Flash targets
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(__thumb_startup)
/* Highest address of the user mode stack */
_estack = 0x20010000; /* end of SRAM */
__SP_INIT = _estack;
/* Generate a link error if heap and stack don't fit into RAM */
__heap_size = 0x400; /* required amount of heap */
__stack_size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
m_interrupts (rx) : ORIGIN = 0x00008000, LENGTH = 0x1BC
m_cfmprotrom (rx) : ORIGIN = 0x00008400, LENGTH = 0x10
m_text (rx) : ORIGIN = 0x00008410, LENGTH = 512K-32K-0x410
m_data (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 128K /* SRAM */
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into Flash */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.cfmprotect :
{
. = ALIGN(4);
KEEP(*(.cfmconfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_cfmprotrom
/* The program code and other data goes into Flash */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > m_text
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > m_text
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
___ROM_AT = .;
} > m_text
/* special area for data exchange between boot loader and application
at the beginning of the RAM*/
.bldata (NOLOAD) :
{
. = ALIGN(4);
KEEP(*(.bldata))
. = ALIGN(4);
} > m_data
/* reserve MTB memory at the beginning of m_data */
.mtb : /* MTB buffer address as defined by the hardware */
{
. = ALIGN(8);
_mtb_start = .;
KEEP(*(.mtb_buf)) /* need to KEEP Micro Trace Buffer as not referenced by application */
. = ALIGN(8);
_mtb_end = .;
} > m_data
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT(___ROM_AT)
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} > m_data
___data_size = _edata - _sdata;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
__START_BSS = .;
PROVIDE ( __bss_start__ = __START_BSS );
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__END_BSS = .;
PROVIDE ( __bss_end__ = __END_BSS );
} > m_data
_romp_at = ___ROM_AT + SIZEOF(.data);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(___ROM_AT);
LONG(_sdata);
LONG(___data_size);
LONG(0);
LONG(0);
LONG(0);
} > m_data
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__heap_addr = .;
. = . + __heap_size;
. = . + __stack_size;
. = ALIGN(4);
} > m_data
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@@ -0,0 +1,205 @@
/*
*****************************************************************************
**
** File : MK20DN512.ld
**
** Default linker command file for Flash targets
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(__thumb_startup)
/* Highest address of the user mode stack */
_estack = 0x20010000; /* end of SRAM */
__SP_INIT = _estack;
/* Generate a link error if heap and stack don't fit into RAM */
__heap_size = 0x400; /* required amount of heap */
__stack_size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
m_interrupts (rx) : ORIGIN = 0x00000000, LENGTH = 0x1BC
m_cfmprotrom (rx) : ORIGIN = 0x00000400, LENGTH = 0x10
m_text (rx) : ORIGIN = 0x00000410, LENGTH = 512K-0x410
m_data (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 128K /* SRAM */
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into Flash */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.cfmprotect :
{
. = ALIGN(4);
KEEP(*(.cfmconfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_cfmprotrom
/* The program code and other data goes into Flash */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > m_text
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > m_text
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
___ROM_AT = .;
} > m_text
/* special area for data exchange between boot loader and application
at the beginning of the RAM*/
.bldata (NOLOAD) :
{
. = ALIGN(4);
KEEP(*(.bldata))
. = ALIGN(4);
} > m_data
/* reserve MTB memory at the beginning of m_data */
.mtb : /* MTB buffer address as defined by the hardware */
{
. = ALIGN(8);
_mtb_start = .;
KEEP(*(.mtb_buf)) /* need to KEEP Micro Trace Buffer as not referenced by application */
. = ALIGN(8);
_mtb_end = .;
} > m_data
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT(___ROM_AT)
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.ramcode) /* .ramcode section for code to be executed in SRAM */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} > m_data
___data_size = _edata - _sdata;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
__START_BSS = .;
PROVIDE ( __bss_start__ = __START_BSS );
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__END_BSS = .;
PROVIDE ( __bss_end__ = __END_BSS );
} > m_data
_romp_at = ___ROM_AT + SIZEOF(.data);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(___ROM_AT);
LONG(_sdata);
LONG(___data_size);
LONG(0);
LONG(0);
LONG(0);
} > m_data
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__heap_addr = .;
. = . + __heap_size;
. = . + __stack_size;
. = ALIGN(4);
} > m_data
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@@ -0,0 +1,205 @@
/*
*****************************************************************************
**
** File : MK20DX256-TMCM.ld
**
** Default linker command file for Flash targets
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(__thumb_startup)
/* Highest address of the user mode stack */
_estack = 0x20008000; /* end of SRAM */
__SP_INIT = _estack;
/* Generate a link error if heap and stack don't fit into RAM */
__heap_size = 0x400; /* required amount of heap */
__stack_size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
m_interrupts (rx) : ORIGIN = 0x00008000, LENGTH = 0x1BC
m_cfmprotrom (rx) : ORIGIN = 0x00008400, LENGTH = 0x10
m_text (rx) : ORIGIN = 0x00008410, LENGTH = 512K-32K-0x410
m_data (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K /* SRAM */
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into Flash */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.cfmprotect :
{
. = ALIGN(4);
KEEP(*(.cfmconfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_cfmprotrom
/* The program code and other data goes into Flash */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > m_text
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > m_text
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
___ROM_AT = .;
} > m_text
/* special area for data exchange between boot loader and application
at the beginning of the RAM*/
.bldata (NOLOAD) :
{
. = ALIGN(4);
KEEP(*(.bldata))
. = ALIGN(4);
} > m_data
/* reserve MTB memory at the beginning of m_data */
.mtb : /* MTB buffer address as defined by the hardware */
{
. = ALIGN(8);
_mtb_start = .;
KEEP(*(.mtb_buf)) /* need to KEEP Micro Trace Buffer as not referenced by application */
. = ALIGN(8);
_mtb_end = .;
} > m_data
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT(___ROM_AT)
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} > m_data
___data_size = _edata - _sdata;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
__START_BSS = .;
PROVIDE ( __bss_start__ = __START_BSS );
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__END_BSS = .;
PROVIDE ( __bss_end__ = __END_BSS );
} > m_data
_romp_at = ___ROM_AT + SIZEOF(.data);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(___ROM_AT);
LONG(_sdata);
LONG(___data_size);
LONG(0);
LONG(0);
LONG(0);
} > m_data
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__heap_addr = .;
. = . + __heap_size;
. = . + __stack_size;
. = ALIGN(4);
} > m_data
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@@ -0,0 +1,205 @@
/*
*****************************************************************************
**
** File : MK20DN512.ld
**
** Default linker command file for Flash targets
**
*****************************************************************************
*/
/* Entry Point */
ENTRY(__thumb_startup)
/* Highest address of the user mode stack */
_estack = 0x20008000; /* end of SRAM */
__SP_INIT = _estack;
/* Generate a link error if heap and stack don't fit into RAM */
__heap_size = 0x400; /* required amount of heap */
__stack_size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
m_interrupts (rx) : ORIGIN = 0x00000000, LENGTH = 0x1BC
m_cfmprotrom (rx) : ORIGIN = 0x00000400, LENGTH = 0x10
m_text (rx) : ORIGIN = 0x00000410, LENGTH = 512K-0x410
m_data (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K /* SRAM */
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into Flash */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.cfmprotect :
{
. = ALIGN(4);
KEEP(*(.cfmconfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_cfmprotrom
/* The program code and other data goes into Flash */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > m_text
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > m_text
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
___ROM_AT = .;
} > m_text
/* special area for data exchange between boot loader and application
at the beginning of the RAM*/
.bldata (NOLOAD) :
{
. = ALIGN(4);
KEEP(*(.bldata))
. = ALIGN(4);
} > m_data
/* reserve MTB memory at the beginning of m_data */
.mtb : /* MTB buffer address as defined by the hardware */
{
. = ALIGN(8);
_mtb_start = .;
KEEP(*(.mtb_buf)) /* need to KEEP Micro Trace Buffer as not referenced by application */
. = ALIGN(8);
_mtb_end = .;
} > m_data
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT(___ROM_AT)
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.ramcode) /* .ramcode section for code to be executed in SRAM */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} > m_data
___data_size = _edata - _sdata;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
__START_BSS = .;
PROVIDE ( __bss_start__ = __START_BSS );
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__END_BSS = .;
PROVIDE ( __bss_end__ = __END_BSS );
} > m_data
_romp_at = ___ROM_AT + SIZEOF(.data);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(___ROM_AT);
LONG(_sdata);
LONG(___data_size);
LONG(0);
LONG(0);
LONG(0);
} > m_data
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__heap_addr = .;
. = . + __heap_size;
. = . + __stack_size;
. = ALIGN(4);
} > m_data
.ARM.attributes 0 : { *(.ARM.attributes) }
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,402 @@
/*
PDD layer implementation for peripheral type DMAMUX
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(DMAMUX_PDD_H_)
#define DMAMUX_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error DMAMUX PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* DMAMUX */ && \
!defined(MCU_MK10D5) /* DMAMUX */ && \
!defined(MCU_MK10D7) /* DMAMUX */ && \
!defined(MCU_MK10F12) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK10DZ10) /* DMAMUX */ && \
!defined(MCU_MK11D5) /* DMAMUX */ && \
!defined(MCU_MK11D5WS) /* DMAMUX */ && \
!defined(MCU_MK12D5) /* DMAMUX */ && \
!defined(MCU_MK20D10) /* DMAMUX */ && \
!defined(MCU_MK20D5) /* DMAMUX */ && \
!defined(MCU_MK20D7) /* DMAMUX */ && \
!defined(MCU_MK20F12) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK20DZ10) /* DMAMUX */ && \
!defined(MCU_MK21D5) /* DMAMUX */ && \
!defined(MCU_MK21D5WS) /* DMAMUX */ && \
!defined(MCU_MK21F12) /* DMAMUX */ && \
!defined(MCU_MK21F12WS) /* DMAMUX */ && \
!defined(MCU_MK22D5) /* DMAMUX */ && \
!defined(MCU_MK22F12810) /* DMAMUX */ && \
!defined(MCU_MK22F12) /* DMAMUX */ && \
!defined(MCU_MK22F25612) /* DMAMUX */ && \
!defined(MCU_MK22F51212) /* DMAMUX */ && \
!defined(MCU_MK24F12) /* DMAMUX */ && \
!defined(MCU_MK30D10) /* DMAMUX */ && \
!defined(MCU_MK30D7) /* DMAMUX */ && \
!defined(MCU_MK30DZ10) /* DMAMUX */ && \
!defined(MCU_MK40D10) /* DMAMUX */ && \
!defined(MCU_MK40D7) /* DMAMUX */ && \
!defined(MCU_MK40DZ10) /* DMAMUX */ && \
!defined(MCU_MK40X256VMD100) /* DMAMUX */ && \
!defined(MCU_MK50D10) /* DMAMUX */ && \
!defined(MCU_MK50D7) /* DMAMUX */ && \
!defined(MCU_MK50DZ10) /* DMAMUX */ && \
!defined(MCU_MK51D10) /* DMAMUX */ && \
!defined(MCU_MK51D7) /* DMAMUX */ && \
!defined(MCU_MK51DZ10) /* DMAMUX */ && \
!defined(MCU_MK52D10) /* DMAMUX */ && \
!defined(MCU_MK52DZ10) /* DMAMUX */ && \
!defined(MCU_MK53D10) /* DMAMUX */ && \
!defined(MCU_MK53DZ10) /* DMAMUX */ && \
!defined(MCU_MK60D10) /* DMAMUX */ && \
!defined(MCU_MK60F12) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK60F15) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK60DZ10) /* DMAMUX */ && \
!defined(MCU_MK60N512VMD100) /* DMAMUX */ && \
!defined(MCU_MK61F12) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK61F15) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK61F12WS) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK61F15WS) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK63F12) /* DMAMUX */ && \
!defined(MCU_MK63F12WS) /* DMAMUX */ && \
!defined(MCU_MK64F12) /* DMAMUX */ && \
!defined(MCU_MK65F18) /* DMAMUX */ && \
!defined(MCU_MK65F18WS) /* DMAMUX */ && \
!defined(MCU_MK66F18) /* DMAMUX */ && \
!defined(MCU_MK70F12) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK70F15) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK70F12WS) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MK70F15WS) /* DMAMUX0, DMAMUX1 */ && \
!defined(MCU_MKL04Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL05Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL14Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL15Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL16Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL24Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL25Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL26Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL34Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL36Z4) /* DMAMUX0 */ && \
!defined(MCU_MKL46Z4) /* DMAMUX0 */ && \
!defined(MCU_MKV10Z7) /* DMAMUX */ && \
!defined(MCU_MKV31F12810) /* DMAMUX */ && \
!defined(MCU_MKV31F25612) /* DMAMUX */ && \
!defined(MCU_MKV31F51212) /* DMAMUX */ && \
!defined(MCU_MKW01Z4) /* DMAMUX0 */ && \
!defined(MCU_MKW21D5) /* DMAMUX */ && \
!defined(MCU_MKW21D5WS) /* DMAMUX */ && \
!defined(MCU_MKW22D5) /* DMAMUX */ && \
!defined(MCU_MKW22D5WS) /* DMAMUX */ && \
!defined(MCU_MKW24D5) /* DMAMUX */ && \
!defined(MCU_MKW24D5WS) /* DMAMUX */ && \
!defined(MCU_PCK20L4) /* DMAMUX */
// Unsupported MCU is active
#error DMAMUX PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Channel request source constants. */
#define DMAMUX_PDD_CHANNEL_SOURCE_0 0U /**< Channel request source 0. */
#define DMAMUX_PDD_CHANNEL_SOURCE_1 0x1U /**< Channel request source 1. */
#define DMAMUX_PDD_CHANNEL_SOURCE_2 0x2U /**< Channel request source 2. */
#define DMAMUX_PDD_CHANNEL_SOURCE_3 0x3U /**< Channel request source 3. */
#define DMAMUX_PDD_CHANNEL_SOURCE_4 0x4U /**< Channel request source 4. */
#define DMAMUX_PDD_CHANNEL_SOURCE_5 0x5U /**< Channel request source 5. */
#define DMAMUX_PDD_CHANNEL_SOURCE_6 0x6U /**< Channel request source 6. */
#define DMAMUX_PDD_CHANNEL_SOURCE_7 0x7U /**< Channel request source 7. */
#define DMAMUX_PDD_CHANNEL_SOURCE_8 0x8U /**< Channel request source 8. */
#define DMAMUX_PDD_CHANNEL_SOURCE_9 0x9U /**< Channel request source 9. */
#define DMAMUX_PDD_CHANNEL_SOURCE_10 0xAU /**< Channel request source 10. */
#define DMAMUX_PDD_CHANNEL_SOURCE_11 0xBU /**< Channel request source 11. */
#define DMAMUX_PDD_CHANNEL_SOURCE_12 0xCU /**< Channel request source 12. */
#define DMAMUX_PDD_CHANNEL_SOURCE_13 0xDU /**< Channel request source 13. */
#define DMAMUX_PDD_CHANNEL_SOURCE_14 0xEU /**< Channel request source 14. */
#define DMAMUX_PDD_CHANNEL_SOURCE_15 0xFU /**< Channel request source 15. */
#define DMAMUX_PDD_CHANNEL_SOURCE_16 0x10U /**< Channel request source 16. */
#define DMAMUX_PDD_CHANNEL_SOURCE_17 0x11U /**< Channel request source 17. */
#define DMAMUX_PDD_CHANNEL_SOURCE_18 0x12U /**< Channel request source 18. */
#define DMAMUX_PDD_CHANNEL_SOURCE_19 0x13U /**< Channel request source 19. */
#define DMAMUX_PDD_CHANNEL_SOURCE_20 0x14U /**< Channel request source 20. */
#define DMAMUX_PDD_CHANNEL_SOURCE_21 0x15U /**< Channel request source 21. */
#define DMAMUX_PDD_CHANNEL_SOURCE_22 0x16U /**< Channel request source 22. */
#define DMAMUX_PDD_CHANNEL_SOURCE_23 0x17U /**< Channel request source 23. */
#define DMAMUX_PDD_CHANNEL_SOURCE_24 0x18U /**< Channel request source 24. */
#define DMAMUX_PDD_CHANNEL_SOURCE_25 0x19U /**< Channel request source 25. */
#define DMAMUX_PDD_CHANNEL_SOURCE_26 0x1AU /**< Channel request source 26. */
#define DMAMUX_PDD_CHANNEL_SOURCE_27 0x1BU /**< Channel request source 27. */
#define DMAMUX_PDD_CHANNEL_SOURCE_28 0x1CU /**< Channel request source 28. */
#define DMAMUX_PDD_CHANNEL_SOURCE_29 0x1DU /**< Channel request source 29. */
#define DMAMUX_PDD_CHANNEL_SOURCE_30 0x1EU /**< Channel request source 30. */
#define DMAMUX_PDD_CHANNEL_SOURCE_31 0x1FU /**< Channel request source 31. */
#define DMAMUX_PDD_CHANNEL_SOURCE_32 0x20U /**< Channel request source 32. */
#define DMAMUX_PDD_CHANNEL_SOURCE_33 0x21U /**< Channel request source 33. */
#define DMAMUX_PDD_CHANNEL_SOURCE_34 0x22U /**< Channel request source 34. */
#define DMAMUX_PDD_CHANNEL_SOURCE_35 0x23U /**< Channel request source 35. */
#define DMAMUX_PDD_CHANNEL_SOURCE_36 0x24U /**< Channel request source 36. */
#define DMAMUX_PDD_CHANNEL_SOURCE_37 0x25U /**< Channel request source 37. */
#define DMAMUX_PDD_CHANNEL_SOURCE_38 0x26U /**< Channel request source 38. */
#define DMAMUX_PDD_CHANNEL_SOURCE_39 0x27U /**< Channel request source 39. */
#define DMAMUX_PDD_CHANNEL_SOURCE_40 0x28U /**< Channel request source 40. */
#define DMAMUX_PDD_CHANNEL_SOURCE_41 0x29U /**< Channel request source 41. */
#define DMAMUX_PDD_CHANNEL_SOURCE_42 0x2AU /**< Channel request source 42. */
#define DMAMUX_PDD_CHANNEL_SOURCE_43 0x2BU /**< Channel request source 43. */
#define DMAMUX_PDD_CHANNEL_SOURCE_44 0x2CU /**< Channel request source 44. */
#define DMAMUX_PDD_CHANNEL_SOURCE_45 0x2DU /**< Channel request source 45. */
#define DMAMUX_PDD_CHANNEL_SOURCE_46 0x2EU /**< Channel request source 46. */
#define DMAMUX_PDD_CHANNEL_SOURCE_47 0x2FU /**< Channel request source 47. */
#define DMAMUX_PDD_CHANNEL_SOURCE_48 0x30U /**< Channel request source 48. */
#define DMAMUX_PDD_CHANNEL_SOURCE_49 0x31U /**< Channel request source 49. */
#define DMAMUX_PDD_CHANNEL_SOURCE_50 0x32U /**< Channel request source 50. */
#define DMAMUX_PDD_CHANNEL_SOURCE_51 0x33U /**< Channel request source 51. */
#define DMAMUX_PDD_CHANNEL_SOURCE_52 0x34U /**< Channel request source 52. */
#define DMAMUX_PDD_CHANNEL_SOURCE_53 0x35U /**< Channel request source 53. */
#define DMAMUX_PDD_CHANNEL_SOURCE_54 0x36U /**< Channel request source 54. */
#define DMAMUX_PDD_CHANNEL_SOURCE_55 0x37U /**< Channel request source 55. */
#define DMAMUX_PDD_CHANNEL_SOURCE_56 0x38U /**< Channel request source 56. */
#define DMAMUX_PDD_CHANNEL_SOURCE_57 0x39U /**< Channel request source 57. */
#define DMAMUX_PDD_CHANNEL_SOURCE_58 0x3AU /**< Channel request source 58. */
#define DMAMUX_PDD_CHANNEL_SOURCE_59 0x3BU /**< Channel request source 59. */
#define DMAMUX_PDD_CHANNEL_SOURCE_60 0x3CU /**< Channel request source 60. */
#define DMAMUX_PDD_CHANNEL_SOURCE_61 0x3DU /**< Channel request source 61. */
#define DMAMUX_PDD_CHANNEL_SOURCE_62 0x3EU /**< Channel request source 62. */
#define DMAMUX_PDD_CHANNEL_SOURCE_63 0x3FU /**< Channel request source 63. */
/* Channel enabled bit mask */
#define DMAMUX_PDD_CHANNEL_ENABLED DMAMUX_CHCFG_ENBL_MASK /**< Channel enabled bit mask */
/* Trigger enabled bit mask */
#define DMAMUX_PDD_TRIGGER_ENABLED DMAMUX_CHCFG_TRIG_MASK /**< Trigger enabled bit mask */
/* ----------------------------------------------------------------------------
-- WriteChannelConfigurationReg
---------------------------------------------------------------------------- */
/**
* @brief Writes to DMA MUX channel configuration register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @param Value DMA MUX channel configuration register value. This parameter is
* a 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* DMAMUX_PDD_WriteChannelConfigurationReg(<peripheral>_BASE_PTR,
* periphID, 1);
* @endcode
*/
#define DMAMUX_PDD_WriteChannelConfigurationReg(PeripheralBase, Channel, Value) ( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadChannelConfigurationReg
---------------------------------------------------------------------------- */
/**
* @brief Returns DMA MUX channel configuration register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* uint8 result =
* DMAMUX_PDD_ReadChannelConfigurationReg(<peripheral>_BASE_PTR, periphID);
* @endcode
*/
#define DMAMUX_PDD_ReadChannelConfigurationReg(PeripheralBase, Channel) ( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) \
)
/* ----------------------------------------------------------------------------
-- EnableChannel
---------------------------------------------------------------------------- */
/**
* @brief Enables or disables DMA MUX channel.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @param State Parameter specifying if DMA MUX channel will be enabled or
* disabled. This parameter is of "Global enumeration used for specifying
* general enable/disable states (PDD_DISABLE and PDD_ENABLE defined in
* PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* DMAMUX_PDD_EnableChannel(<peripheral>_BASE_PTR, periphID, PDD_DISABLE);
* @endcode
*/
#define DMAMUX_PDD_EnableChannel(PeripheralBase, Channel, State) ( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) = \
(uint8)(( \
(uint8)(( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel))) & ( \
(uint8)(~(uint8)DMAMUX_CHCFG_ENBL_MASK)))) | ( \
(uint8)((uint8)(State) << DMAMUX_CHCFG_ENBL_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- GetChannelEnabled
---------------------------------------------------------------------------- */
/**
* @brief Returns DMA MUX channel state.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* uint8 result = DMAMUX_PDD_GetChannelEnabled(<peripheral>_BASE_PTR,
* periphID);
* @endcode
*/
#define DMAMUX_PDD_GetChannelEnabled(PeripheralBase, Channel) ( \
(uint8)(DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) & DMAMUX_CHCFG_ENBL_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableTrigger
---------------------------------------------------------------------------- */
/**
* @brief Enables or disables DMA MUX channel triggering.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @param State Parameter specifying if DMA MUX channel triggering will be
* enabled or disabled. This parameter is of "Global enumeration used for
* specifying general enable/disable states (PDD_DISABLE and PDD_ENABLE defined
* in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* DMAMUX_PDD_EnableTrigger(<peripheral>_BASE_PTR, periphID, PDD_DISABLE);
* @endcode
*/
#define DMAMUX_PDD_EnableTrigger(PeripheralBase, Channel, State) ( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) = \
(uint8)(( \
(uint8)(( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel))) & ( \
(uint8)(~(uint8)DMAMUX_CHCFG_TRIG_MASK)))) | ( \
(uint8)((uint8)(State) << DMAMUX_CHCFG_TRIG_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- GetTriggerEnabled
---------------------------------------------------------------------------- */
/**
* @brief Returns DMA MUX channel triggering state.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* uint8 result = DMAMUX_PDD_GetTriggerEnabled(<peripheral>_BASE_PTR,
* periphID);
* @endcode
*/
#define DMAMUX_PDD_GetTriggerEnabled(PeripheralBase, Channel) ( \
(uint8)(DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) & DMAMUX_CHCFG_TRIG_MASK) \
)
/* ----------------------------------------------------------------------------
-- SetChannelSource
---------------------------------------------------------------------------- */
/**
* @brief Sets DMA channels source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @param ChannelSource DMA channel source number. This parameter is a 6-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* DMAMUX_PDD_SetChannelSource(<peripheral>_BASE_PTR, periphID, 1);
* @endcode
*/
#define DMAMUX_PDD_SetChannelSource(PeripheralBase, Channel, ChannelSource) ( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) = \
(uint8)(( \
(uint8)(( \
DMAMUX_CHCFG_REG(PeripheralBase,(Channel))) & ( \
(uint8)(~(uint8)DMAMUX_CHCFG_SOURCE_MASK)))) | ( \
(uint8)(ChannelSource))) \
)
/* ----------------------------------------------------------------------------
-- GetChannelSource
---------------------------------------------------------------------------- */
/**
* @brief Returns mask of enabled DMA channels requests.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Channel DMA channel number. This parameter is of index type.
* @return Returns a 6-bit value. The value is cast to "uint8".
* @remarks The macro accesses the following registers: CHCFG[Channel].
* @par Example:
* @code
* uint8 result = DMAMUX_PDD_GetChannelSource(<peripheral>_BASE_PTR,
* periphID);
* @endcode
*/
#define DMAMUX_PDD_GetChannelSource(PeripheralBase, Channel) ( \
(uint8)(DMAMUX_CHCFG_REG(PeripheralBase,(Channel)) & DMAMUX_CHCFG_SOURCE_MASK) \
)
#endif /* #if defined(DMAMUX_PDD_H_) */
/* DMAMUX_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,490 @@
/*
PDD layer implementation for peripheral type EWM
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(EWM_PDD_H_)
#define EWM_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error EWM PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* EWM */ && \
!defined(MCU_MK10D5) /* EWM */ && \
!defined(MCU_MK10D7) /* EWM */ && \
!defined(MCU_MK10F12) /* EWM */ && \
!defined(MCU_MK10DZ10) /* EWM */ && \
!defined(MCU_MK11D5) /* EWM */ && \
!defined(MCU_MK11D5WS) /* EWM */ && \
!defined(MCU_MK12D5) /* EWM */ && \
!defined(MCU_MK20D10) /* EWM */ && \
!defined(MCU_MK20D5) /* EWM */ && \
!defined(MCU_MK20D7) /* EWM */ && \
!defined(MCU_MK20F12) /* EWM */ && \
!defined(MCU_MK20DZ10) /* EWM */ && \
!defined(MCU_MK21D5) /* EWM */ && \
!defined(MCU_MK21D5WS) /* EWM */ && \
!defined(MCU_MK21F12) /* EWM */ && \
!defined(MCU_MK21F12WS) /* EWM */ && \
!defined(MCU_MK22D5) /* EWM */ && \
!defined(MCU_MK22F12810) /* EWM */ && \
!defined(MCU_MK22F12) /* EWM */ && \
!defined(MCU_MK22F25612) /* EWM */ && \
!defined(MCU_MK22F51212) /* EWM */ && \
!defined(MCU_MK24F12) /* EWM */ && \
!defined(MCU_MK30D10) /* EWM */ && \
!defined(MCU_MK30D7) /* EWM */ && \
!defined(MCU_MK30DZ10) /* EWM */ && \
!defined(MCU_MK40D10) /* EWM */ && \
!defined(MCU_MK40D7) /* EWM */ && \
!defined(MCU_MK40DZ10) /* EWM */ && \
!defined(MCU_MK40X256VMD100) /* EWM */ && \
!defined(MCU_MK50D10) /* EWM */ && \
!defined(MCU_MK50D7) /* EWM */ && \
!defined(MCU_MK50DZ10) /* EWM */ && \
!defined(MCU_MK51D10) /* EWM */ && \
!defined(MCU_MK51D7) /* EWM */ && \
!defined(MCU_MK51DZ10) /* EWM */ && \
!defined(MCU_MK52D10) /* EWM */ && \
!defined(MCU_MK52DZ10) /* EWM */ && \
!defined(MCU_MK53D10) /* EWM */ && \
!defined(MCU_MK53DZ10) /* EWM */ && \
!defined(MCU_MK60D10) /* EWM */ && \
!defined(MCU_MK60F12) /* EWM */ && \
!defined(MCU_MK60F15) /* EWM */ && \
!defined(MCU_MK60DZ10) /* EWM */ && \
!defined(MCU_MK60N512VMD100) /* EWM */ && \
!defined(MCU_MK61F12) /* EWM */ && \
!defined(MCU_MK61F15) /* EWM */ && \
!defined(MCU_MK61F12WS) /* EWM */ && \
!defined(MCU_MK61F15WS) /* EWM */ && \
!defined(MCU_MK63F12) /* EWM */ && \
!defined(MCU_MK63F12WS) /* EWM */ && \
!defined(MCU_MK64F12) /* EWM */ && \
!defined(MCU_MK65F18) /* EWM */ && \
!defined(MCU_MK65F18WS) /* EWM */ && \
!defined(MCU_MK66F18) /* EWM */ && \
!defined(MCU_MK70F12) /* EWM */ && \
!defined(MCU_MK70F15) /* EWM */ && \
!defined(MCU_MK70F12WS) /* EWM */ && \
!defined(MCU_MK70F15WS) /* EWM */ && \
!defined(MCU_MKV10Z7) /* EWM */ && \
!defined(MCU_MKV31F12810) /* EWM */ && \
!defined(MCU_MKV31F25612) /* EWM */ && \
!defined(MCU_MKV31F51212) /* EWM */ && \
!defined(MCU_MKW21D5) /* EWM */ && \
!defined(MCU_MKW21D5WS) /* EWM */ && \
!defined(MCU_MKW22D5) /* EWM */ && \
!defined(MCU_MKW22D5WS) /* EWM */ && \
!defined(MCU_MKW24D5) /* EWM */ && \
!defined(MCU_MKW24D5WS) /* EWM */ && \
!defined(MCU_PCK20L4) /* EWM */
// Unsupported MCU is active
#error EWM PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Service constants */
#define EWM_PDD_KEY_1 0xB4U /**< First key */
#define EWM_PDD_KEY_2 0x2CU /**< Second key */
/* Clock source constants. */
#define EWM_PDD_SOURCE_ROSC_8M 0U /**< Relaxation oscillator clock */
#define EWM_PDD_SOURCE_XTAL_OSC 0x1U /**< Crystal oscillator clock */
#define EWM_PDD_SOURCE_BUS_CLK 0x2U /**< IP bus clock */
#define EWM_PDD_SOURCE_ROSC_200K 0x3U /**< Low speed oscillator clock */
/* ----------------------------------------------------------------------------
-- WriteControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the control register. This parameter is a 8-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CTRL.
* @par Example:
* @code
* EWM_PDD_WriteControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteControlReg(PeripheralBase, Value) ( \
EWM_CTRL_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- GetEnableDeviceStatus
---------------------------------------------------------------------------- */
/**
* @brief Returns current state of EWM device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CTRL.
* @par Example:
* @code
* uint8 result = EWM_PDD_GetEnableDeviceStatus(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_GetEnableDeviceStatus(PeripheralBase) ( \
(uint8)(EWM_CTRL_REG(PeripheralBase) & EWM_CTRL_EWMEN_MASK) \
)
/* ----------------------------------------------------------------------------
-- WriteCompareLowReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the compare low register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the compare low register. This parameter is a
* 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CMPL.
* @par Example:
* @code
* EWM_PDD_WriteCompareLowReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteCompareLowReg(PeripheralBase, Value) ( \
EWM_CMPL_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadCompareLowReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the compare low register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CMPL.
* @par Example:
* @code
* uint8 result = EWM_PDD_ReadCompareLowReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_ReadCompareLowReg(PeripheralBase) ( \
EWM_CMPL_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteCompareHighReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the compare high register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the compare high register. This parameter is a
* 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CMPH.
* @par Example:
* @code
* EWM_PDD_WriteCompareHighReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteCompareHighReg(PeripheralBase, Value) ( \
EWM_CMPH_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadCompareHighReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the compare high register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CMPH.
* @par Example:
* @code
* uint8 result = EWM_PDD_ReadCompareHighReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_ReadCompareHighReg(PeripheralBase) ( \
EWM_CMPH_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteServiceReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the service register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Service constant. This parameter is a 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_SERV.
* @par Example:
* @code
* EWM_PDD_WriteServiceReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteServiceReg(PeripheralBase, Value) ( \
EWM_SERV_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- DisableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Disables the EWM interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CTRL.
* @par Example:
* @code
* EWM_PDD_DisableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_DisableInterrupt(PeripheralBase) ( \
EWM_CTRL_REG(PeripheralBase) &= \
(uint8)(~(uint8)EWM_CTRL_INTEN_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enables the EWM interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CTRL.
* @par Example:
* @code
* EWM_PDD_EnableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_EnableInterrupt(PeripheralBase) ( \
EWM_CTRL_REG(PeripheralBase) |= \
EWM_CTRL_INTEN_MASK \
)
/* ----------------------------------------------------------------------------
-- SelectClockSource
---------------------------------------------------------------------------- */
/**
* @brief Selects clock source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Source New value of the source. This parameter is of "Clock source
* constants." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CLKCTRL.
* @par Example:
* @code
* EWM_PDD_SelectClockSource(<peripheral>_BASE_PTR,
* EWM_PDD_SOURCE_ROSC_8M);
* @endcode
*/
#define EWM_PDD_SelectClockSource(PeripheralBase, Source) ( \
EWM_CLKCTRL_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(EWM_CLKCTRL_REG(PeripheralBase) & (uint8)(~(uint8)EWM_CLKCTRL_CLKSEL_MASK))) | ( \
(uint8)(Source))) \
)
/* ----------------------------------------------------------------------------
-- SetPrescaler
---------------------------------------------------------------------------- */
/**
* @brief Sets prescale value.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New value of the prescaler. This parameter is a 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CLKPRESCALER.
* @par Example:
* @code
* EWM_PDD_SetPrescaler(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_SetPrescaler(PeripheralBase, Value) ( \
EWM_CLKPRESCALER_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadControlReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CTRL.
* @par Example:
* @code
* uint8 result = EWM_PDD_ReadControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_ReadControlReg(PeripheralBase) ( \
EWM_CTRL_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteClockControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the clock control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the clock control register. This parameter is a
* 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CLKCTRL.
* @par Example:
* @code
* EWM_PDD_WriteClockControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteClockControlReg(PeripheralBase, Value) ( \
EWM_CLKCTRL_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadClockControlReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the clock control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CLKCTRL.
* @par Example:
* @code
* uint8 result = EWM_PDD_ReadClockControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_ReadClockControlReg(PeripheralBase) ( \
EWM_CLKCTRL_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteClockPrescalerReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the clock prescaler register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the clock prescaler register. This parameter is a
* 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: EWM_CLKPRESCALER.
* @par Example:
* @code
* EWM_PDD_WriteClockPrescalerReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define EWM_PDD_WriteClockPrescalerReg(PeripheralBase, Value) ( \
EWM_CLKPRESCALER_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadClockPrescalerReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the clock prescaler register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: EWM_CLKPRESCALER.
* @par Example:
* @code
* uint8 result = EWM_PDD_ReadClockPrescalerReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define EWM_PDD_ReadClockPrescalerReg(PeripheralBase) ( \
EWM_CLKPRESCALER_REG(PeripheralBase) \
)
#endif /* #if defined(EWM_PDD_H_) */
/* EWM_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,516 @@
/*
PDD layer implementation for peripheral type GPIO
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(GPIO_PDD_H_)
#define GPIO_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error GPIO PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK10D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK10D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK10F12) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK10DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK11D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK11D5WS) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK12D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK20D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK20D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK20D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK20F12) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK20DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK21D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK21D5WS) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK21F12) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK21F12WS) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK22D5) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK22F12810) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK22F12) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK22F25612) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK22F51212) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK24F12) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK30D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK30D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK30DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK40D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK40D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK40DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK40X256VMD100) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK50D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK50D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK50DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK51D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK51D7) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK51DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK52D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK52DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK53D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK53DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK60D10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK60F12) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK60F15) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK60DZ10) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK60N512VMD100) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK61F12) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK61F15) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK61F12WS) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK61F15WS) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK63F12) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK63F12WS) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK64F12) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK65F18) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK65F18WS) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK66F18) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MK70F12) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK70F15) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK70F12WS) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MK70F15WS) /* PTA, PTB, PTC, PTD, PTE, PTF */ && \
!defined(MCU_MKE02Z2) /* GPIOA, GPIOB */ && \
!defined(MCU_MKE02Z4) /* GPIOA, GPIOB */ && \
!defined(MCU_SKEAZN642) /* GPIOA, GPIOB */ && \
!defined(MCU_MKE04Z1284) /* GPIOA, GPIOB, GPIOC */ && \
!defined(MCU_MKE04Z4) /* GPIOA */ && \
!defined(MCU_SKEAZN84) /* GPIOA */ && \
!defined(MCU_MKE06Z4) /* GPIOA, GPIOB, GPIOC */ && \
!defined(MCU_MKL02Z4) /* PTA, PTB */ && \
!defined(MCU_MKL03Z4) /* PTA, PTB */ && \
!defined(MCU_MKL04Z4) /* PTA, PTB */ && \
!defined(MCU_MKL05Z4) /* PTA, PTB */ && \
!defined(MCU_MKL14Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL15Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL16Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL24Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL25Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL26Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL34Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL36Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKL46Z4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKV10Z7) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKV31F12810) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKV31F25612) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKV31F51212) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_MKW01Z4) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW21D5) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW21D5WS) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW22D5) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW22D5WS) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW24D5) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_MKW24D5WS) /* GPIOA, GPIOB, GPIOC, GPIOD, GPIOE */ && \
!defined(MCU_PCK20L4) /* PTA, PTB, PTC, PTD, PTE */ && \
!defined(MCU_SKEAZ1284) /* GPIOA, GPIOB, GPIOC */
// Unsupported MCU is active
#error GPIO PDD library: Unsupported derivative is active.
#endif
//#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Pin masks */
#define GPIO_PDD_PIN_0 0x1U /**< Pin 0 mask */
#define GPIO_PDD_PIN_1 0x2U /**< Pin 1 mask */
#define GPIO_PDD_PIN_2 0x4U /**< Pin 2 mask */
#define GPIO_PDD_PIN_3 0x8U /**< Pin 3 mask */
#define GPIO_PDD_PIN_4 0x10U /**< Pin 4 mask */
#define GPIO_PDD_PIN_5 0x20U /**< Pin 5 mask */
#define GPIO_PDD_PIN_6 0x40U /**< Pin 6 mask */
#define GPIO_PDD_PIN_7 0x80U /**< Pin 7 mask */
#define GPIO_PDD_PIN_8 0x100U /**< Pin 8 mask */
#define GPIO_PDD_PIN_9 0x200U /**< Pin 9 mask */
#define GPIO_PDD_PIN_10 0x400U /**< Pin 10 mask */
#define GPIO_PDD_PIN_11 0x800U /**< Pin 11 mask */
#define GPIO_PDD_PIN_12 0x1000U /**< Pin 12 mask */
#define GPIO_PDD_PIN_13 0x2000U /**< Pin 13 mask */
#define GPIO_PDD_PIN_14 0x4000U /**< Pin 14 mask */
#define GPIO_PDD_PIN_15 0x8000U /**< Pin 15 mask */
#define GPIO_PDD_PIN_16 0x10000U /**< Pin 16 mask */
#define GPIO_PDD_PIN_17 0x20000U /**< Pin 17 mask */
#define GPIO_PDD_PIN_18 0x40000U /**< Pin 18 mask */
#define GPIO_PDD_PIN_19 0x80000U /**< Pin 19 mask */
#define GPIO_PDD_PIN_20 0x100000U /**< Pin 20 mask */
#define GPIO_PDD_PIN_21 0x200000U /**< Pin 21 mask */
#define GPIO_PDD_PIN_22 0x400000U /**< Pin 22 mask */
#define GPIO_PDD_PIN_23 0x800000U /**< Pin 23 mask */
#define GPIO_PDD_PIN_24 0x1000000U /**< Pin 24 mask */
#define GPIO_PDD_PIN_25 0x2000000U /**< Pin 25 mask */
#define GPIO_PDD_PIN_26 0x4000000U /**< Pin 26 mask */
#define GPIO_PDD_PIN_27 0x8000000U /**< Pin 27 mask */
#define GPIO_PDD_PIN_28 0x10000000U /**< Pin 28 mask */
#define GPIO_PDD_PIN_29 0x20000000U /**< Pin 29 mask */
#define GPIO_PDD_PIN_30 0x40000000U /**< Pin 30 mask */
#define GPIO_PDD_PIN_31 0x80000000U /**< Pin 31 mask */
/* ----------------------------------------------------------------------------
-- GetPortDataInput
---------------------------------------------------------------------------- */
/**
* @brief Gets port data input independently of current direction setting nor
* pin usage. It returns zeros for pins which are not configured for a digital
* function.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: GPIOA_PDIR, GPIOB_PDIR,
* GPIOC_PDIR, GPIOD_PDIR, GPIOE_PDIR, GPIOF_PDIR (depending on the
* peripheral).
* @par Example:
* @code
* uint32 result = GPIO_PDD_GetPortDataInput(<peripheral>_BASE_PTR);
* @endcode
*/
#define GPIO_PDD_GetPortDataInput(PeripheralBase) ( \
(uint32)GPIO_PDIR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- SetPortDataOutput
---------------------------------------------------------------------------- */
/**
* @brief Sets port data output. The value is driven out to the corresponding
* pin if direction of the pin is set to output.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Parameter specifying new data output value. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDOR, GPIOB_PDOR,
* GPIOC_PDOR, GPIOD_PDOR, GPIOE_PDOR, GPIOF_PDOR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortDataOutput(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define GPIO_PDD_SetPortDataOutput(PeripheralBase, Value) ( \
GPIO_PDOR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- GetPortDataOutput
---------------------------------------------------------------------------- */
/**
* @brief Gets port data output independently of current direction setting.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: GPIOA_PDOR, GPIOB_PDOR,
* GPIOC_PDOR, GPIOD_PDOR, GPIOE_PDOR, GPIOF_PDOR (depending on the
* peripheral).
* @par Example:
* @code
* uint32 result = GPIO_PDD_GetPortDataOutput(<peripheral>_BASE_PTR);
* @endcode
*/
#define GPIO_PDD_GetPortDataOutput(PeripheralBase) ( \
(uint32)GPIO_PDOR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- ClearPortDataOutputMask
---------------------------------------------------------------------------- */
/**
* @brief Clears required bits of port data output.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be cleared. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PCOR, GPIOB_PCOR,
* GPIOC_PCOR, GPIOD_PCOR, GPIOE_PCOR, GPIOF_PCOR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_ClearPortDataOutputMask(<peripheral>_BASE_PTR, GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_ClearPortDataOutputMask(PeripheralBase, Mask) ( \
GPIO_PCOR_REG(PeripheralBase) = \
(uint32)(Mask) \
)
/* ----------------------------------------------------------------------------
-- SetPortDataOutputMask
---------------------------------------------------------------------------- */
/**
* @brief Sets required bits of port data output.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be set. Use constants
* from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PSOR, GPIOB_PSOR,
* GPIOC_PSOR, GPIOD_PSOR, GPIOE_PSOR, GPIOF_PSOR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortDataOutputMask(<peripheral>_BASE_PTR, GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortDataOutputMask(PeripheralBase, Mask) ( \
GPIO_PSOR_REG(PeripheralBase) = \
(uint32)(Mask) \
)
/* ----------------------------------------------------------------------------
-- TogglePortDataOutputMask
---------------------------------------------------------------------------- */
/**
* @brief Toggles required bits of port data output.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be inverted. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PTOR, GPIOB_PTOR,
* GPIOC_PTOR, GPIOD_PTOR, GPIOE_PTOR, GPIOF_PTOR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_TogglePortDataOutputMask(<peripheral>_BASE_PTR,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_TogglePortDataOutputMask(PeripheralBase, Mask) ( \
GPIO_PTOR_REG(PeripheralBase) = \
(uint32)(Mask) \
)
/* ----------------------------------------------------------------------------
-- SetPortInputDirectionMask
---------------------------------------------------------------------------- */
#if ((defined(MCU_MKE02Z2)) || (defined(MCU_MKE02Z4)) || (defined(MCU_MKE04Z1284)) || (defined(MCU_MKE04Z4)) || (defined(MCU_MKE06Z4)) || (defined(MCU_SKEAZ1284)) || (defined(MCU_SKEAZN642)) || (defined(MCU_SKEAZN84)))
/**
* @brief Sets required pins as input.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be set as input. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR, GPIOA_PIDR,
* GPIOB_PIDR, GPIOC_PIDR (depending on the peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortInputDirectionMask(<peripheral>_BASE_PTR,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortInputDirectionMask(PeripheralBase, Mask) ( \
(GPIO_PDDR_REG(PeripheralBase) &= \
(uint32)(~(uint32)(Mask))), \
(GPIO_PIDR_REG(PeripheralBase) &= \
(uint32)(~(uint32)(Mask))) \
)
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/**
* @brief Sets required pins as input.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be set as input. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR, GPIOA_PIDR,
* GPIOB_PIDR, GPIOC_PIDR (depending on the peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortInputDirectionMask(<peripheral>_BASE_PTR,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortInputDirectionMask(PeripheralBase, Mask) ( \
GPIO_PDDR_REG(PeripheralBase) &= \
(uint32)(~(uint32)(Mask)) \
)
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* ----------------------------------------------------------------------------
-- SetPortOutputDirectionMask
---------------------------------------------------------------------------- */
/**
* @brief Sets required pins as output.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mask Parameter specifying port pins which should be set as output. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortOutputDirectionMask(<peripheral>_BASE_PTR,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortOutputDirectionMask(PeripheralBase, Mask) ( \
GPIO_PDDR_REG(PeripheralBase) |= \
(uint32)(Mask) \
)
/* ----------------------------------------------------------------------------
-- SetPortDirectionMask
---------------------------------------------------------------------------- */
#if ((defined(MCU_MKE02Z2)) || (defined(MCU_MKE02Z4)) || (defined(MCU_MKE04Z1284)) || (defined(MCU_MKE04Z4)) || (defined(MCU_MKE06Z4)) || (defined(MCU_SKEAZ1284)) || (defined(MCU_SKEAZN642)) || (defined(MCU_SKEAZN84)))
/**
* @brief Sets direction on pins specified by mask parameters.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param InputMask Mask of port pins defining which should be set as input. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @param OutputMask Mask of port pins defining which should be set as output.
* Use constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR, GPIOA_PIDR,
* GPIOB_PIDR, GPIOC_PIDR (depending on the peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortDirectionMask(<peripheral>_BASE_PTR, GPIO_PDD_PIN_0,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortDirectionMask(PeripheralBase, InputMask, OutputMask) ( \
(GPIO_PDDR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(GPIO_PDDR_REG(PeripheralBase) & (uint32)(~(uint32)(InputMask)))) | ( \
(uint32)(OutputMask)))), \
(GPIO_PIDR_REG(PeripheralBase) &= \
(uint32)(~(uint32)(InputMask))) \
)
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/**
* @brief Sets direction on pins specified by mask parameters.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param InputMask Mask of port pins defining which should be set as input. Use
* constants from group "Pin masks". This parameter is 32 bits wide.
* @param OutputMask Mask of port pins defining which should be set as output.
* Use constants from group "Pin masks". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR, GPIOA_PIDR,
* GPIOB_PIDR, GPIOC_PIDR (depending on the peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortDirectionMask(<peripheral>_BASE_PTR, GPIO_PDD_PIN_0,
* GPIO_PDD_PIN_0);
* @endcode
*/
#define GPIO_PDD_SetPortDirectionMask(PeripheralBase, InputMask, OutputMask) ( \
GPIO_PDDR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(GPIO_PDDR_REG(PeripheralBase) & (uint32)(~(uint32)(InputMask)))) | ( \
(uint32)(OutputMask))) \
)
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* ----------------------------------------------------------------------------
-- SetPortDirection
---------------------------------------------------------------------------- */
/**
* @brief Sets direction of every pin in the port.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Parameter specifying new direction for port pins. This parameter
* is a 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR (depending on the
* peripheral).
* @par Example:
* @code
* GPIO_PDD_SetPortDirection(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define GPIO_PDD_SetPortDirection(PeripheralBase, Value) ( \
GPIO_PDDR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- GetPortDirection
---------------------------------------------------------------------------- */
/**
* @brief Gets direction of every pin in the port.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: GPIOA_PDDR, GPIOB_PDDR,
* GPIOC_PDDR, GPIOD_PDDR, GPIOE_PDDR, GPIOF_PDDR (depending on the
* peripheral).
* @par Example:
* @code
* uint32 result = GPIO_PDD_GetPortDirection(<peripheral>_BASE_PTR);
* @endcode
*/
#define GPIO_PDD_GetPortDirection(PeripheralBase) ( \
(uint32)GPIO_PDDR_REG(PeripheralBase) \
)
#endif /* #if defined(GPIO_PDD_H_) */
/* GPIO_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,788 @@
/*
PDD layer implementation for peripheral type LPTMR
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(LPTMR_PDD_H_)
#define LPTMR_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error LPTMR PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* LPTMR0 */ && \
!defined(MCU_MK10D5) /* LPTMR0 */ && \
!defined(MCU_MK10D7) /* LPTMR0 */ && \
!defined(MCU_MK10F12) /* LPTMR0 */ && \
!defined(MCU_MK10DZ10) /* LPTMR0 */ && \
!defined(MCU_MK11D5) /* LPTMR0 */ && \
!defined(MCU_MK11D5WS) /* LPTMR0 */ && \
!defined(MCU_MK12D5) /* LPTMR0 */ && \
!defined(MCU_MK20D10) /* LPTMR0 */ && \
!defined(MCU_MK20D5) /* LPTMR0 */ && \
!defined(MCU_MK20D7) /* LPTMR0 */ && \
!defined(MCU_MK20F12) /* LPTMR0 */ && \
!defined(MCU_MK20DZ10) /* LPTMR0 */ && \
!defined(MCU_MK21D5) /* LPTMR0 */ && \
!defined(MCU_MK21D5WS) /* LPTMR0 */ && \
!defined(MCU_MK21F12) /* LPTMR0 */ && \
!defined(MCU_MK21F12WS) /* LPTMR0 */ && \
!defined(MCU_MK22D5) /* LPTMR0 */ && \
!defined(MCU_MK22F12810) /* LPTMR0 */ && \
!defined(MCU_MK22F12) /* LPTMR0 */ && \
!defined(MCU_MK22F25612) /* LPTMR0 */ && \
!defined(MCU_MK22F51212) /* LPTMR0 */ && \
!defined(MCU_MK24F12) /* LPTMR0 */ && \
!defined(MCU_MK30D10) /* LPTMR0 */ && \
!defined(MCU_MK30D7) /* LPTMR0 */ && \
!defined(MCU_MK30DZ10) /* LPTMR0 */ && \
!defined(MCU_MK40D10) /* LPTMR0 */ && \
!defined(MCU_MK40D7) /* LPTMR0 */ && \
!defined(MCU_MK40DZ10) /* LPTMR0 */ && \
!defined(MCU_MK40X256VMD100) /* LPTMR0 */ && \
!defined(MCU_MK50D10) /* LPTMR0 */ && \
!defined(MCU_MK50D7) /* LPTMR0 */ && \
!defined(MCU_MK50DZ10) /* LPTMR0 */ && \
!defined(MCU_MK51D10) /* LPTMR0 */ && \
!defined(MCU_MK51D7) /* LPTMR0 */ && \
!defined(MCU_MK51DZ10) /* LPTMR0 */ && \
!defined(MCU_MK52D10) /* LPTMR0 */ && \
!defined(MCU_MK52DZ10) /* LPTMR0 */ && \
!defined(MCU_MK53D10) /* LPTMR0 */ && \
!defined(MCU_MK53DZ10) /* LPTMR0 */ && \
!defined(MCU_MK60D10) /* LPTMR0 */ && \
!defined(MCU_MK60F12) /* LPTMR0 */ && \
!defined(MCU_MK60F15) /* LPTMR0 */ && \
!defined(MCU_MK60DZ10) /* LPTMR0 */ && \
!defined(MCU_MK60N512VMD100) /* LPTMR0 */ && \
!defined(MCU_MK61F12) /* LPTMR0 */ && \
!defined(MCU_MK61F15) /* LPTMR0 */ && \
!defined(MCU_MK61F12WS) /* LPTMR0 */ && \
!defined(MCU_MK61F15WS) /* LPTMR0 */ && \
!defined(MCU_MK63F12) /* LPTMR0 */ && \
!defined(MCU_MK63F12WS) /* LPTMR0 */ && \
!defined(MCU_MK64F12) /* LPTMR0 */ && \
!defined(MCU_MK65F18) /* LPTMR0 */ && \
!defined(MCU_MK65F18WS) /* LPTMR0 */ && \
!defined(MCU_MK66F18) /* LPTMR0 */ && \
!defined(MCU_MK70F12) /* LPTMR0 */ && \
!defined(MCU_MK70F15) /* LPTMR0 */ && \
!defined(MCU_MK70F12WS) /* LPTMR0 */ && \
!defined(MCU_MK70F15WS) /* LPTMR0 */ && \
!defined(MCU_MKL02Z4) /* LPTMR0 */ && \
!defined(MCU_MKL03Z4) /* LPTMR0 */ && \
!defined(MCU_MKL04Z4) /* LPTMR0 */ && \
!defined(MCU_MKL05Z4) /* LPTMR0 */ && \
!defined(MCU_MKL14Z4) /* LPTMR0 */ && \
!defined(MCU_MKL15Z4) /* LPTMR0 */ && \
!defined(MCU_MKL16Z4) /* LPTMR0 */ && \
!defined(MCU_MKL24Z4) /* LPTMR0 */ && \
!defined(MCU_MKL25Z4) /* LPTMR0 */ && \
!defined(MCU_MKL26Z4) /* LPTMR0 */ && \
!defined(MCU_MKL34Z4) /* LPTMR0 */ && \
!defined(MCU_MKL36Z4) /* LPTMR0 */ && \
!defined(MCU_MKL46Z4) /* LPTMR0 */ && \
!defined(MCU_MKV10Z7) /* LPTMR0 */ && \
!defined(MCU_MKV31F12810) /* LPTMR0 */ && \
!defined(MCU_MKV31F25612) /* LPTMR0 */ && \
!defined(MCU_MKV31F51212) /* LPTMR0 */ && \
!defined(MCU_MKW01Z4) /* LPTMR0 */ && \
!defined(MCU_MKW21D5) /* LPTMR0 */ && \
!defined(MCU_MKW21D5WS) /* LPTMR0 */ && \
!defined(MCU_MKW22D5) /* LPTMR0 */ && \
!defined(MCU_MKW22D5WS) /* LPTMR0 */ && \
!defined(MCU_MKW24D5) /* LPTMR0 */ && \
!defined(MCU_MKW24D5WS) /* LPTMR0 */ && \
!defined(MCU_PCK20L4) /* LPTMR0 */
// Unsupported MCU is active
#error LPTMR PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Enable freerun constants */
#define LPTMR_PDD_RESTART_ENABLED 0U /**< Enabled */
#define LPTMR_PDD_RESTART_DISABLED LPTMR_CSR_TFC_MASK /**< Disabled */
/* Timer mode constants */
#define LPTMR_PDD_SOURCE_INTERNAL 0U /**< Internal */
#define LPTMR_PDD_SOURCE_EXTERNAL LPTMR_CSR_TMS_MASK /**< External */
/* Prescaler/Filter constants */
#define LPTMR_PDD_PRESCALER_2 0U /**< 2 */
#define LPTMR_PDD_PRESCALER_4 0x1U /**< 4 */
#define LPTMR_PDD_PRESCALER_8 0x2U /**< 8 */
#define LPTMR_PDD_PRESCALER_16 0x3U /**< 16 */
#define LPTMR_PDD_PRESCALER_32 0x4U /**< 32 */
#define LPTMR_PDD_PRESCALER_64 0x5U /**< 64 */
#define LPTMR_PDD_PRESCALER_128 0x6U /**< 128 */
#define LPTMR_PDD_PRESCALER_256 0x7U /**< 256 */
#define LPTMR_PDD_PRESCALER_512 0x8U /**< 512 */
#define LPTMR_PDD_PRESCALER_1024 0x9U /**< 1024 */
#define LPTMR_PDD_PRESCALER_2048 0xAU /**< 2048 */
#define LPTMR_PDD_PRESCALER_4096 0xBU /**< 4096 */
#define LPTMR_PDD_PRESCALER_8192 0xCU /**< 8192 */
#define LPTMR_PDD_PRESCALER_16384 0xDU /**< 16384 */
#define LPTMR_PDD_PRESCALER_32768 0xEU /**< 32768 */
#define LPTMR_PDD_PRESCALER_65536 0xFU /**< 65536 */
#define LPTMR_PDD_FILTER_2 0x1U /**< 2 */
#define LPTMR_PDD_FILTER_4 0x2U /**< 4 */
#define LPTMR_PDD_FILTER_8 0x3U /**< 8 */
#define LPTMR_PDD_FILTER_16 0x4U /**< 16 */
#define LPTMR_PDD_FILTER_32 0x5U /**< 32 */
#define LPTMR_PDD_FILTER_64 0x6U /**< 64 */
#define LPTMR_PDD_FILTER_128 0x7U /**< 128 */
#define LPTMR_PDD_FILTER_256 0x8U /**< 256 */
#define LPTMR_PDD_FILTER_512 0x9U /**< 512 */
#define LPTMR_PDD_FILTER_1024 0xAU /**< 1024 */
#define LPTMR_PDD_FILTER_2048 0xBU /**< 2048 */
#define LPTMR_PDD_FILTER_4096 0xCU /**< 4096 */
#define LPTMR_PDD_FILTER_8192 0xDU /**< 8192 */
#define LPTMR_PDD_FILTER_16384 0xEU /**< 16384 */
#define LPTMR_PDD_FILTER_32768 0xFU /**< 32768 */
/* Divider constants */
#define LPTMR_PDD_DIVIDER_1 0x1U /**< 1 */
#define LPTMR_PDD_DIVIDER_2 0U /**< 2 */
#define LPTMR_PDD_DIVIDER_4 0x2U /**< 4 */
#define LPTMR_PDD_DIVIDER_8 0x4U /**< 8 */
#define LPTMR_PDD_DIVIDER_16 0x6U /**< 16 */
#define LPTMR_PDD_DIVIDER_32 0x8U /**< 32 */
#define LPTMR_PDD_DIVIDER_64 0xAU /**< 64 */
#define LPTMR_PDD_DIVIDER_128 0xCU /**< 128 */
#define LPTMR_PDD_DIVIDER_256 0xEU /**< 256 */
#define LPTMR_PDD_DIVIDER_512 0x10U /**< 512 */
#define LPTMR_PDD_DIVIDER_1024 0x12U /**< 1024 */
#define LPTMR_PDD_DIVIDER_2048 0x14U /**< 2048 */
#define LPTMR_PDD_DIVIDER_4096 0x16U /**< 4096 */
#define LPTMR_PDD_DIVIDER_8192 0x18U /**< 8192 */
#define LPTMR_PDD_DIVIDER_16384 0x1AU /**< 16384 */
#define LPTMR_PDD_DIVIDER_32768 0x1CU /**< 32768 */
#define LPTMR_PDD_DIVIDER_65536 0x1EU /**< 65536 */
/* Timer Pin Select constants. */
#define LPTMR_PDD_HSCMP 0U /**< Alt 0 */
#define LPTMR_PDD_PIN_1 0x10U /**< Alt 1 */
#define LPTMR_PDD_PIN_2 0x20U /**< Alt 2 */
#define LPTMR_PDD_PIN_3 0x30U /**< Alt 3 */
/* Timer Pin Polarity constants. */
#define LPTMR_PDD_POLARITY_RISING 0U /**< Rising */
#define LPTMR_PDD_POLARITY_FALLING 0x8U /**< Falling */
/* Prescaler bypass constants. */
#define LPTMR_PDD_BYPASS_DISABLED 0U /**< Disabled */
#define LPTMR_PDD_BYPASS_ENABLED 0x4U /**< Enabled */
/* Clock source constants. */
#define LPTMR_PDD_SOURCE_INTREF 0U /**< Internal reference clock */
#define LPTMR_PDD_SOURCE_LPO1KHZ 0x1U /**< Low power oscillator clock */
#define LPTMR_PDD_SOURCE_EXT32KHZ 0x2U /**< External 32 kHz clock */
#define LPTMR_PDD_SOURCE_EXTREF 0x3U /**< External reference clock */
/* ----------------------------------------------------------------------------
-- GetInterruptMask
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt mask.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_GetInterruptMask(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_GetInterruptMask(PeripheralBase) ( \
(uint32)(LPTMR_CSR_REG(PeripheralBase) & LPTMR_CSR_TIE_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt flag bit.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_GetInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_GetInterruptFlag(PeripheralBase) ( \
(uint32)(LPTMR_CSR_REG(PeripheralBase) & LPTMR_CSR_TCF_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enables the LPT interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_EnableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_EnableInterrupt(PeripheralBase) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(LPTMR_CSR_REG(PeripheralBase) | LPTMR_CSR_TIE_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))) \
)
/* ----------------------------------------------------------------------------
-- DisableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Disables the LPT interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_DisableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_DisableInterrupt(PeripheralBase) ( \
LPTMR_CSR_REG(PeripheralBase) &= \
(uint32)(( \
(uint32)(~(uint32)LPTMR_CSR_TIE_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))) \
)
/* ----------------------------------------------------------------------------
-- ClearInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Clears LPT interrupt flag.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_ClearInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ClearInterruptFlag(PeripheralBase) ( \
LPTMR_CSR_REG(PeripheralBase) |= \
LPTMR_CSR_TCF_MASK \
)
/* ----------------------------------------------------------------------------
-- SelectPin
---------------------------------------------------------------------------- */
/**
* @brief Sets Timer Pin Select bits.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param TPS_val New value of the TPS. This parameter is of "Timer Pin Select
* constants." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_SelectPin(<peripheral>_BASE_PTR, LPTMR_PDD_HSCMP);
* @endcode
*/
#define LPTMR_PDD_SelectPin(PeripheralBase, TPS_val) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_CSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_CSR_TPS_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))))) | ( \
(uint32)(TPS_val))) \
)
/* ----------------------------------------------------------------------------
-- SetPinPolarity
---------------------------------------------------------------------------- */
/**
* @brief Configures the polarity of the input source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Edge New value of the polarity. This parameter is of "Timer Pin
* Polarity constants." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_SetPinPolarity(<peripheral>_BASE_PTR,
* LPTMR_PDD_POLARITY_RISING);
* @endcode
*/
#define LPTMR_PDD_SetPinPolarity(PeripheralBase, Edge) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_CSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_CSR_TPP_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))))) | ( \
(uint32)(Edge))) \
)
/* ----------------------------------------------------------------------------
-- EnableFreerun
---------------------------------------------------------------------------- */
/**
* @brief Configures the freerun mode.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Restart New value of the restart. Use constants from group "Enable
* freerun constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_EnableFreerun(<peripheral>_BASE_PTR,
* LPTMR_PDD_RESTART_ENABLED);
* @endcode
*/
#define LPTMR_PDD_EnableFreerun(PeripheralBase, Restart) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_CSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_CSR_TFC_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))))) | ( \
(uint32)(Restart))) \
)
/* ----------------------------------------------------------------------------
-- SetTimerMode
---------------------------------------------------------------------------- */
/**
* @brief Selects timer mode.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Source New value of the source. Use constants from group "Timer mode
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_SetTimerMode(<peripheral>_BASE_PTR,
* LPTMR_PDD_SOURCE_INTERNAL);
* @endcode
*/
#define LPTMR_PDD_SetTimerMode(PeripheralBase, Source) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_CSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_CSR_TMS_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))))) | ( \
(uint32)(Source))) \
)
/* ----------------------------------------------------------------------------
-- EnableDevice
---------------------------------------------------------------------------- */
/**
* @brief Enables the LPT device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Requested state of LPT device. This parameter is of "Global
* enumeration used for specifying general enable/disable states (PDD_DISABLE
* and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_EnableDevice(<peripheral>_BASE_PTR, PDD_DISABLE);
* @endcode
*/
#define LPTMR_PDD_EnableDevice(PeripheralBase, State) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_CSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_CSR_TEN_MASK)) & ( \
(uint32)(~(uint32)LPTMR_CSR_TCF_MASK))))) | ( \
(uint32)(State))) \
)
/* ----------------------------------------------------------------------------
-- GetEnableDeviceStatus
---------------------------------------------------------------------------- */
/**
* @brief Returns current state of LPT device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* uint32 result =
* LPTMR_PDD_GetEnableDeviceStatus(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_GetEnableDeviceStatus(PeripheralBase) ( \
(uint32)(LPTMR_CSR_REG(PeripheralBase) & LPTMR_CSR_TEN_MASK) \
)
/* ----------------------------------------------------------------------------
-- SetPrescaler
---------------------------------------------------------------------------- */
/**
* @brief Sets prescale value.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Prescaler New value of the prescaler. Use constants from group
* "Prescaler/Filter constants". This parameter is 4 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* LPTMR_PDD_SetPrescaler(<peripheral>_BASE_PTR, LPTMR_PDD_PRESCALER_2);
* @endcode
*/
#define LPTMR_PDD_SetPrescaler(PeripheralBase, Prescaler) ( \
LPTMR_PSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(LPTMR_PSR_REG(PeripheralBase) & (uint32)(~(uint32)LPTMR_PSR_PRESCALE_MASK))) | ( \
(uint32)((uint32)(Prescaler) << LPTMR_PSR_PRESCALE_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- EnablePrescalerBypass
---------------------------------------------------------------------------- */
/**
* @brief Sets prescaler bypass.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Bypass New value of the bypass. This parameter is of "Prescaler bypass
* constants." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* LPTMR_PDD_EnablePrescalerBypass(<peripheral>_BASE_PTR,
* LPTMR_PDD_BYPASS_DISABLED);
* @endcode
*/
#define LPTMR_PDD_EnablePrescalerBypass(PeripheralBase, Bypass) ( \
LPTMR_PSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(LPTMR_PSR_REG(PeripheralBase) & (uint32)(~(uint32)LPTMR_PSR_PBYP_MASK))) | ( \
(uint32)(Bypass))) \
)
/* ----------------------------------------------------------------------------
-- SetDivider
---------------------------------------------------------------------------- */
/**
* @brief Sets both prescale value and bypass value.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Divider New value of the divider. Use constants from group "Divider
* constants". This parameter is 5 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* LPTMR_PDD_SetDivider(<peripheral>_BASE_PTR, LPTMR_PDD_DIVIDER_1);
* @endcode
*/
#define LPTMR_PDD_SetDivider(PeripheralBase, Divider) ( \
LPTMR_PSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
LPTMR_PSR_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)LPTMR_PSR_PRESCALE_MASK)) & ( \
(uint32)(~(uint32)LPTMR_PSR_PBYP_MASK))))) | (( \
(uint32)((uint32)((uint32)(Divider) >> 1U) << LPTMR_PSR_PRESCALE_SHIFT)) | ( \
(uint32)((uint32)((uint32)(Divider) & 0x1U) << LPTMR_PSR_PBYP_SHIFT)))) \
)
/* ----------------------------------------------------------------------------
-- SelectPrescalerSource
---------------------------------------------------------------------------- */
/**
* @brief Selects clock source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Source New value of the source. This parameter is of "Clock source
* constants." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* LPTMR_PDD_SelectPrescalerSource(<peripheral>_BASE_PTR,
* LPTMR_PDD_SOURCE_INTREF);
* @endcode
*/
#define LPTMR_PDD_SelectPrescalerSource(PeripheralBase, Source) ( \
LPTMR_PSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(LPTMR_PSR_REG(PeripheralBase) & (uint32)(~(uint32)LPTMR_PSR_PCS_MASK))) | ( \
(uint32)(Source))) \
)
/* ----------------------------------------------------------------------------
-- WriteCompareReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the compare register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the compare register. This parameter is a 32-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CMR.
* @par Example:
* @code
* LPTMR_PDD_WriteCompareReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define LPTMR_PDD_WriteCompareReg(PeripheralBase, Value) ( \
LPTMR_CMR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadCompareReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the compare register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CMR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_ReadCompareReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ReadCompareReg(PeripheralBase) ( \
LPTMR_CMR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- ReadCounterReg
---------------------------------------------------------------------------- */
#if ((defined(MCU_MK10DZ10)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60N512VMD100)))
/**
* @brief Returns the content of the counter register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CNR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_ReadCounterReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ReadCounterReg(PeripheralBase) ( \
LPTMR_CNR_REG(PeripheralBase) \
)
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK52D10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/**
* @brief Returns the content of the counter register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CNR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_ReadCounterReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ReadCounterReg(PeripheralBase) ( \
(LPTMR_CNR_REG(PeripheralBase) = \
0U), \
LPTMR_CNR_REG(PeripheralBase) \
)
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK52D10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* ----------------------------------------------------------------------------
-- WriteControlStatusReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the control status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the control status register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* LPTMR_PDD_WriteControlStatusReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define LPTMR_PDD_WriteControlStatusReg(PeripheralBase, Value) ( \
LPTMR_CSR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadControlStatusReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the control status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_CSR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_ReadControlStatusReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ReadControlStatusReg(PeripheralBase) ( \
LPTMR_CSR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WritePrescaleReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the prescale register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the prescale register. This parameter is a 32-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* LPTMR_PDD_WritePrescaleReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define LPTMR_PDD_WritePrescaleReg(PeripheralBase, Value) ( \
LPTMR_PSR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadPrescaleReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the prescale register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LPTMR0_PSR.
* @par Example:
* @code
* uint32 result = LPTMR_PDD_ReadPrescaleReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define LPTMR_PDD_ReadPrescaleReg(PeripheralBase) ( \
LPTMR_PSR_REG(PeripheralBase) \
)
#endif /* #if defined(LPTMR_PDD_H_) */
/* LPTMR_PDD.h, eof. */

View File

@@ -0,0 +1,787 @@
/*
PDD layer implementation for peripheral type MCM
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(MCM_PDD_H_)
#define MCM_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error MCM PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* MCM */ && \
!defined(MCU_MK10D7) /* MCM */ && \
!defined(MCU_MK10F12) /* MCM */ && \
!defined(MCU_MK10DZ10) /* MCM */ && \
!defined(MCU_MK11D5) /* MCM */ && \
!defined(MCU_MK11D5WS) /* MCM */ && \
!defined(MCU_MK12D5) /* MCM */ && \
!defined(MCU_MK20D10) /* MCM */ && \
!defined(MCU_MK20D7) /* MCM */ && \
!defined(MCU_MK20F12) /* MCM */ && \
!defined(MCU_MK20DZ10) /* MCM */ && \
!defined(MCU_MK21D5) /* MCM */ && \
!defined(MCU_MK21D5WS) /* MCM */ && \
!defined(MCU_MK21F12) /* MCM */ && \
!defined(MCU_MK21F12WS) /* MCM */ && \
!defined(MCU_MK22D5) /* MCM */ && \
!defined(MCU_MK22F12810) /* MCM */ && \
!defined(MCU_MK22F12) /* MCM */ && \
!defined(MCU_MK22F25612) /* MCM */ && \
!defined(MCU_MK22F51212) /* MCM */ && \
!defined(MCU_MK24F12) /* MCM */ && \
!defined(MCU_MK30D10) /* MCM */ && \
!defined(MCU_MK30D7) /* MCM */ && \
!defined(MCU_MK30DZ10) /* MCM */ && \
!defined(MCU_MK40D10) /* MCM */ && \
!defined(MCU_MK40D7) /* MCM */ && \
!defined(MCU_MK40DZ10) /* MCM */ && \
!defined(MCU_MK40X256VMD100) /* MCM */ && \
!defined(MCU_MK50D10) /* MCM */ && \
!defined(MCU_MK50D7) /* MCM */ && \
!defined(MCU_MK50DZ10) /* MCM */ && \
!defined(MCU_MK51D10) /* MCM */ && \
!defined(MCU_MK51D7) /* MCM */ && \
!defined(MCU_MK51DZ10) /* MCM */ && \
!defined(MCU_MK52D10) /* MCM */ && \
!defined(MCU_MK52DZ10) /* MCM */ && \
!defined(MCU_MK53D10) /* MCM */ && \
!defined(MCU_MK53DZ10) /* MCM */ && \
!defined(MCU_MK60D10) /* MCM */ && \
!defined(MCU_MK60F12) /* MCM */ && \
!defined(MCU_MK60F15) /* MCM */ && \
!defined(MCU_MK60DZ10) /* MCM */ && \
!defined(MCU_MK60N512VMD100) /* MCM */ && \
!defined(MCU_MK61F12) /* MCM */ && \
!defined(MCU_MK61F15) /* MCM */ && \
!defined(MCU_MK61F12WS) /* MCM */ && \
!defined(MCU_MK61F15WS) /* MCM */ && \
!defined(MCU_MK63F12) /* MCM */ && \
!defined(MCU_MK63F12WS) /* MCM */ && \
!defined(MCU_MK64F12) /* MCM */ && \
!defined(MCU_MK65F18) /* MCM */ && \
!defined(MCU_MK65F18WS) /* MCM */ && \
!defined(MCU_MK66F18) /* MCM */ && \
!defined(MCU_MK70F12) /* MCM */ && \
!defined(MCU_MK70F15) /* MCM */ && \
!defined(MCU_MK70F12WS) /* MCM */ && \
!defined(MCU_MK70F15WS) /* MCM */ && \
!defined(MCU_MKE02Z2) /* MCM */ && \
!defined(MCU_MKE02Z4) /* MCM */ && \
!defined(MCU_SKEAZN642) /* MCM */ && \
!defined(MCU_MKE04Z1284) /* MCM */ && \
!defined(MCU_MKE04Z4) /* MCM */ && \
!defined(MCU_SKEAZN84) /* MCM */ && \
!defined(MCU_MKE06Z4) /* MCM */ && \
!defined(MCU_MKL02Z4) /* MCM */ && \
!defined(MCU_MKL03Z4) /* MCM */ && \
!defined(MCU_MKL04Z4) /* MCM */ && \
!defined(MCU_MKL05Z4) /* MCM */ && \
!defined(MCU_MKL14Z4) /* MCM */ && \
!defined(MCU_MKL15Z4) /* MCM */ && \
!defined(MCU_MKL16Z4) /* MCM */ && \
!defined(MCU_MKL24Z4) /* MCM */ && \
!defined(MCU_MKL25Z4) /* MCM */ && \
!defined(MCU_MKL26Z4) /* MCM */ && \
!defined(MCU_MKL34Z4) /* MCM */ && \
!defined(MCU_MKL36Z4) /* MCM */ && \
!defined(MCU_MKL46Z4) /* MCM */ && \
!defined(MCU_MKV10Z7) /* MCM */ && \
!defined(MCU_MKV31F12810) /* MCM */ && \
!defined(MCU_MKV31F25612) /* MCM */ && \
!defined(MCU_MKV31F51212) /* MCM */ && \
!defined(MCU_MKW01Z4) /* MCM */ && \
!defined(MCU_MKW21D5) /* MCM */ && \
!defined(MCU_MKW21D5WS) /* MCM */ && \
!defined(MCU_MKW22D5) /* MCM */ && \
!defined(MCU_MKW22D5WS) /* MCM */ && \
!defined(MCU_MKW24D5) /* MCM */ && \
!defined(MCU_MKW24D5WS) /* MCM */ && \
!defined(MCU_SKEAZ1284) /* MCM */
// Unsupported MCU is active
#error MCM PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Slave bus connection to AXBS input port masks constants (for
GetSlaveBusConnectionToAxbsInputPort macro). */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_0 0x1U /**< A bus slave connection to AXBS input port 0 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_1 0x2U /**< A bus slave connection to AXBS input port 1 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_2 0x4U /**< A bus slave connection to AXBS input port 2 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_3 0x8U /**< A bus slave connection to AXBS input port 3 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_4 0x10U /**< A bus slave connection to AXBS input port 4 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_5 0x20U /**< A bus slave connection to AXBS input port 5 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_6 0x40U /**< A bus slave connection to AXBS input port 6 is present */
#define MCM_PDD_SLAVE_BUS_CONNECTION_TO_AXBS_INPUT_PORT_7 0x80U /**< A bus slave connection to AXBS input port 7 is present */
/* Master bus connection to AXBS input port masks constants (for
GetMasterBusConnectionToAxbsInputPortMask macro). */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_0 0x1U /**< A bus master connection to AXBS input port 0 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_1 0x2U /**< A bus master connection to AXBS input port 1 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_2 0x4U /**< A bus master connection to AXBS input port 2 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_3 0x8U /**< A bus master connection to AXBS input port 3 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_4 0x10U /**< A bus master connection to AXBS input port 4 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_5 0x20U /**< A bus master connection to AXBS input port 5 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_6 0x40U /**< A bus master connection to AXBS input port 6 is present */
#define MCM_PDD_MASTER_BUS_CONNECTION_TO_AXBS_INPUT_PORT_7 0x80U /**< A bus master connection to AXBS input port 7 is present */
#if ((defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW01Z4)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)))
/* Crossbar master arbitration type */
#define MCM_PDD_FIXED_PRIORITY 0U /**< Fixed-priority arbitration for the crossbar masters */
#define MCM_PDD_ROUND_ROBIN 0x200U /**< Round-robin arbitration for the crossbar masters */
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) */
/* Crossbar master arbitration type */
#define MCM_PDD_FIXED_PRIORITY 0U /**< Fixed-priority arbitration for the crossbar masters */
#define MCM_PDD_ROUND_ROBIN 0x1U /**< Round-robin arbitration for the crossbar masters */
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) */
/* ----------------------------------------------------------------------------
-- GetSlaveBusConnectionToAxbsInputPortMask
---------------------------------------------------------------------------- */
/**
* @brief Returns present mask value of a corresponding connection to the
* crossbar switch's slave input port.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: MCM_PLASC.
* @par Example:
* @code
* uint8 result =
* MCM_PDD_GetSlaveBusConnectionToAxbsInputPortMask(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_GetSlaveBusConnectionToAxbsInputPortMask(PeripheralBase) ( \
(uint8)(MCM_PLASC_REG(PeripheralBase) & MCM_PLASC_ASC_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadCrossbarSwitchSlaveConfigurationReg
---------------------------------------------------------------------------- */
/**
* @brief Reads crossbar switch (AXBS) slave configuration register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 16-bit value.
* @remarks The macro accesses the following registers: MCM_PLASC.
* @par Example:
* @code
* uint16 result =
* MCM_PDD_ReadCrossbarSwitchSlaveConfigurationReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_ReadCrossbarSwitchSlaveConfigurationReg(PeripheralBase) ( \
MCM_PLASC_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- GetMasterBusConnectionToAxbsInputPortMask
---------------------------------------------------------------------------- */
/**
* @brief Returns present mask value of a corresponding connection to the
* crossbar switch's master input port.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: MCM_PLAMC.
* @par Example:
* @code
* uint8 result =
* MCM_PDD_GetMasterBusConnectionToAxbsInputPortMask(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_GetMasterBusConnectionToAxbsInputPortMask(PeripheralBase) ( \
(uint8)(MCM_PLAMC_REG(PeripheralBase) & MCM_PLAMC_AMC_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadCrossbarSwitchMasterConfigurationReg
---------------------------------------------------------------------------- */
/**
* @brief Reads crossbar switch (AXBS) master configuration register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 16-bit value.
* @remarks The macro accesses the following registers: MCM_PLAMC.
* @par Example:
* @code
* uint16 result =
* MCM_PDD_ReadCrossbarSwitchMasterConfigurationReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_ReadCrossbarSwitchMasterConfigurationReg(PeripheralBase) ( \
MCM_PLAMC_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- SetCrossbarMastersArbitrationType
---------------------------------------------------------------------------- */
/**
* @brief Selects arbitration type for crossbar masters.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Crossbar masters arbitration type. This parameter is of
* "Crossbar master arbitration type" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_SetCrossbarMastersArbitrationType(<peripheral>_BASE_PTR,
* MCM_PDD_FIXED_PRIORITY);
* @endcode
*/
#define MCM_PDD_SetCrossbarMastersArbitrationType(PeripheralBase, State) ( \
MCM_PLACR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(MCM_PLACR_REG(PeripheralBase) & (uint32)(~(uint32)MCM_PLACR_ARB_MASK))) | ( \
(uint32)(State))) \
)
/* ----------------------------------------------------------------------------
-- ReadPlatformControlReg
---------------------------------------------------------------------------- */
/**
* @brief Reads platform control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* uint32 result = MCM_PDD_ReadPlatformControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_ReadPlatformControlReg(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WritePlatformControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into platform control
* register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the platform control register. This
* parameter is a 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_WritePlatformControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define MCM_PDD_WritePlatformControlReg(PeripheralBase, Value) ( \
MCM_PLACR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- DisableStallingFlashController
---------------------------------------------------------------------------- */
/**
* @brief Disable stalling flash controller.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableStallingFlashController(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableStallingFlashController(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_ESFC_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableStallingFlashController
---------------------------------------------------------------------------- */
/**
* @brief Enable stalling flash controller.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableStallingFlashController(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableStallingFlashController(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_ESFC_MASK \
)
/* ----------------------------------------------------------------------------
-- DisableFlashControllerSpeculation
---------------------------------------------------------------------------- */
/**
* @brief Disable flash controller speculation.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableFlashControllerSpeculation(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableFlashControllerSpeculation(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_DFCS_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableFlashControllerSpeculation
---------------------------------------------------------------------------- */
/**
* @brief Enable flash controller speculation.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableFlashControllerSpeculation(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableFlashControllerSpeculation(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_DFCS_MASK) \
)
/* ----------------------------------------------------------------------------
-- DisableFlashDataSpeculation
---------------------------------------------------------------------------- */
/**
* @brief Disable flash data speculation.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableFlashDataSpeculation(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableFlashDataSpeculation(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_EFDS_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableFlashDataSpeculation
---------------------------------------------------------------------------- */
/**
* @brief Enable flash data speculation.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableFlashDataSpeculation(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableFlashDataSpeculation(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_EFDS_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableFlashControllerCache
---------------------------------------------------------------------------- */
/**
* @brief Enable flash controllerCache.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableFlashControllerCache(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableFlashControllerCache(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_DFCC_MASK) \
)
/* ----------------------------------------------------------------------------
-- DisableFlashControllerCache
---------------------------------------------------------------------------- */
/**
* @brief Disable flash controllerCache.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableFlashControllerCache(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableFlashControllerCache(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_DFCC_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableFlashControllerInstructionCaching
---------------------------------------------------------------------------- */
/**
* @brief Enable flash controller instruction caching.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableFlashControllerInstructionCaching(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableFlashControllerInstructionCaching(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_DFCIC_MASK) \
)
/* ----------------------------------------------------------------------------
-- DisableFlashControllerInstructionCaching
---------------------------------------------------------------------------- */
/**
* @brief Disable flash controller instruction caching.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableFlashControllerInstructionCaching(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableFlashControllerInstructionCaching(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_DFCIC_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableFlashControllerDataCaching
---------------------------------------------------------------------------- */
/**
* @brief Enable flash controller data caching.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_EnableFlashControllerDataCaching(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableFlashControllerDataCaching(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_PLACR_DFCDA_MASK) \
)
/* ----------------------------------------------------------------------------
-- DisableFlashControllerDataCaching
---------------------------------------------------------------------------- */
/**
* @brief Disable flash controller data caching.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_DisableFlashControllerDataCaching(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_DisableFlashControllerDataCaching(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_DFCDA_MASK \
)
/* ----------------------------------------------------------------------------
-- InvalidateFlashCache
---------------------------------------------------------------------------- */
/**
* @brief Invalidates flash cache.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_PLACR.
* @par Example:
* @code
* MCM_PDD_InvalidateFlashCache(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_InvalidateFlashCache(PeripheralBase) ( \
MCM_PLACR_REG(PeripheralBase) |= \
MCM_PLACR_CFCC_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableComputeOperationWakeupOnInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enable compute operation wakeup on interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* MCM_PDD_EnableComputeOperationWakeupOnInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_EnableComputeOperationWakeupOnInterrupt(PeripheralBase) ( \
MCM_CPO_REG(PeripheralBase) |= \
MCM_CPO_CPOWOI_MASK \
)
/* ----------------------------------------------------------------------------
-- GetComputeOperationState
---------------------------------------------------------------------------- */
/**
* @brief Returns non zero value if compute operation entry has completed or
* compute operation exit has not completed.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* uint32 result =
* MCM_PDD_GetComputeOperationState(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_GetComputeOperationState(PeripheralBase) ( \
(uint32)(MCM_CPO_REG(PeripheralBase) & MCM_CPO_CPOACK_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetComputeOperationRequest
---------------------------------------------------------------------------- */
/**
* @brief Returns non zero value if compute operation request is active.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* uint32 result =
* MCM_PDD_GetComputeOperationRequest(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_GetComputeOperationRequest(PeripheralBase) ( \
(uint32)(MCM_CPO_REG(PeripheralBase) & MCM_CPO_CPOREQ_MASK) \
)
/* ----------------------------------------------------------------------------
-- SetComputeOperationRequest
---------------------------------------------------------------------------- */
/**
* @brief Set compute operation request.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* MCM_PDD_SetComputeOperationRequest(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_SetComputeOperationRequest(PeripheralBase) ( \
MCM_CPO_REG(PeripheralBase) |= \
MCM_CPO_CPOREQ_MASK \
)
/* ----------------------------------------------------------------------------
-- ClearComputeOperationRequest
---------------------------------------------------------------------------- */
/**
* @brief Clear compute operation request.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* MCM_PDD_ClearComputeOperationRequest(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_ClearComputeOperationRequest(PeripheralBase) ( \
MCM_CPO_REG(PeripheralBase) &= \
(uint32)(~(uint32)MCM_CPO_CPOREQ_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadComputeOperationControlReg
---------------------------------------------------------------------------- */
/**
* @brief Reads compute operation control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* uint32 result =
* MCM_PDD_ReadComputeOperationControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define MCM_PDD_ReadComputeOperationControlReg(PeripheralBase) ( \
MCM_CPO_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteComputeOperationControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into compute operation
* control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the compute operation control register.
* This parameter is a 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: MCM_CPO.
* @par Example:
* @code
* MCM_PDD_WriteComputeOperationControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define MCM_PDD_WriteComputeOperationControlReg(PeripheralBase, Value) ( \
MCM_CPO_REG(PeripheralBase) = \
(uint32)(Value) \
)
#endif /* #if defined(MCM_PDD_H_) */
/* MCM_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
/* Common type declarations for PDD layer */
/* This file is static and it is generated from API-Factory */
#ifndef PDD_TYPES_H_
#define PDD_TYPES_H_
/* --------------------------------------------------------------- */
/* --------- PDD_TBool */
/* --------------------------------------------------------------- */
/* Implementation note for boolean type: */
/* Native "bool" type should be used for boolean values */
/* because the compiler provides optimization and best type representation. */
/* If the compiler does not support native "bool" type, common "Bool" */
/* at each place there should be used the most suitable integer type */
/* and no explicit conversion to 0 and 1 values should be used. */
/* Common "TBool" typedef could have possible performance issue */
/* (there is a problem how wide type to select). It is good to avoid using */
/* explicit "!= 0" because of performance penalty, but without such */
/* explicit conversion to 0/1 the resulting type may be too wide. */
/* Every bool type (native or replaced by integer value) should be always */
/* treated as zero-equal or non-zero (see below for examples). */
/* E.g.: This compiler supports boolean type only in C++ mode. */
/* Out of the C++ mode the boolean type must be simulated. */
#ifndef __cplusplus
typedef uint16 PDD_TBool;
#else
typedef bool PDD_TBool;
#endif
/* ============================================================================
================== General PDD macros ======================================
============================================================================ */
#define PDD_DISABLE 0u
#define PDD_ENABLE 1u
/* ============================================================================
================== General register manipulating routines ==================
============================================================================ */
#define setReg8(Reg, val) ((Reg) = (uint8)(val))
#define getReg8(Reg) (Reg)
#define testReg8Bits(Reg, GetMask) ((Reg) & (uint8)(GetMask))
#define clrReg8Bits(Reg, ClrMask) ((Reg) &= (uint8)((uint8)(~(uint8)(ClrMask))))
#define setReg8Bits(Reg, SetMask) ((Reg) |= (uint8)(SetMask))
#define invertReg8Bits(Reg, InvMask) ((Reg) ^= (uint8)(InvMask))
#define clrSetReg8Bits(Reg, ClrMask, SetMask) ((Reg) = (uint8)(((Reg) & (uint8)(~(uint8)(ClrMask))) | (uint8)(SetMask)))
#define setReg16(Reg, val) ((Reg) = (uint16)(val))
#define getReg16(Reg) (Reg)
#define testReg16Bits(Reg, GetMask) ((Reg) & (uint16)(GetMask))
#define clrReg16Bits(Reg, ClrMask) ((Reg) &= (uint16)(~(uint16)(ClrMask)))
#define setReg16Bits(Reg, SetMask) ((Reg) |= (uint16)(SetMask))
#define invertReg16Bits(Reg, InvMask) ((Reg) ^= (uint16)(InvMask))
#define clrSetReg16Bits(Reg, ClrMask, SetMask) ((Reg) = (uint16)(((Reg) & (uint16)(~(uint16)(ClrMask))) | (uint16)(SetMask)))
#define setReg32(Reg, val) ((Reg) = (uint32)(val))
#define getReg32(Reg) (Reg)
#define testReg32Bits(Reg, GetMask) ((Reg) & (uint32)(GetMask))
#define clrReg32Bits(Reg, ClrMask) ((Reg) &= (uint32)(~(uint32)(ClrMask)))
#define setReg32Bits(Reg, SetMask) ((Reg) |= (uint32)(SetMask))
#define invertReg32Bits(Reg, InvMask) ((Reg) ^= (uint32)(InvMask))
#define clrSetReg32Bits(Reg, ClrMask, SetMask) ((Reg) = (uint32)(((Reg) & (uint32)(~(uint32)(ClrMask))) | (uint32)(SetMask)))
#endif /* #if !defined(PDD_TYPES_H_) */

View File

@@ -0,0 +1,602 @@
/*
PDD layer implementation for peripheral type PIT
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(PIT_PDD_H_)
#define PIT_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error PIT PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* PIT */ && \
!defined(MCU_MK10D5) /* PIT */ && \
!defined(MCU_MK10D7) /* PIT */ && \
!defined(MCU_MK10F12) /* PIT */ && \
!defined(MCU_MK10DZ10) /* PIT */ && \
!defined(MCU_MK11D5) /* PIT */ && \
!defined(MCU_MK11D5WS) /* PIT */ && \
!defined(MCU_MK12D5) /* PIT */ && \
!defined(MCU_MK20D10) /* PIT */ && \
!defined(MCU_MK20D5) /* PIT */ && \
!defined(MCU_MK20D7) /* PIT */ && \
!defined(MCU_MK20F12) /* PIT */ && \
!defined(MCU_MK20DZ10) /* PIT */ && \
!defined(MCU_MK21D5) /* PIT */ && \
!defined(MCU_MK21D5WS) /* PIT */ && \
!defined(MCU_MK21F12) /* PIT */ && \
!defined(MCU_MK21F12WS) /* PIT */ && \
!defined(MCU_MK22D5) /* PIT */ && \
!defined(MCU_MK22F12810) /* PIT */ && \
!defined(MCU_MK22F12) /* PIT */ && \
!defined(MCU_MK22F25612) /* PIT */ && \
!defined(MCU_MK22F51212) /* PIT */ && \
!defined(MCU_MK24F12) /* PIT */ && \
!defined(MCU_MK30D10) /* PIT */ && \
!defined(MCU_MK30D7) /* PIT */ && \
!defined(MCU_MK30DZ10) /* PIT */ && \
!defined(MCU_MK40D10) /* PIT */ && \
!defined(MCU_MK40D7) /* PIT */ && \
!defined(MCU_MK40DZ10) /* PIT */ && \
!defined(MCU_MK40X256VMD100) /* PIT */ && \
!defined(MCU_MK50D10) /* PIT */ && \
!defined(MCU_MK50D7) /* PIT */ && \
!defined(MCU_MK50DZ10) /* PIT */ && \
!defined(MCU_MK51D10) /* PIT */ && \
!defined(MCU_MK51D7) /* PIT */ && \
!defined(MCU_MK51DZ10) /* PIT */ && \
!defined(MCU_MK52D10) /* PIT */ && \
!defined(MCU_MK52DZ10) /* PIT */ && \
!defined(MCU_MK53D10) /* PIT */ && \
!defined(MCU_MK53DZ10) /* PIT */ && \
!defined(MCU_MK60D10) /* PIT */ && \
!defined(MCU_MK60F12) /* PIT */ && \
!defined(MCU_MK60F15) /* PIT */ && \
!defined(MCU_MK60DZ10) /* PIT */ && \
!defined(MCU_MK60N512VMD100) /* PIT */ && \
!defined(MCU_MK61F12) /* PIT */ && \
!defined(MCU_MK61F15) /* PIT */ && \
!defined(MCU_MK61F12WS) /* PIT */ && \
!defined(MCU_MK61F15WS) /* PIT */ && \
!defined(MCU_MK63F12) /* PIT */ && \
!defined(MCU_MK63F12WS) /* PIT */ && \
!defined(MCU_MK64F12) /* PIT */ && \
!defined(MCU_MK65F18) /* PIT */ && \
!defined(MCU_MK65F18WS) /* PIT */ && \
!defined(MCU_MK66F18) /* PIT */ && \
!defined(MCU_MK70F12) /* PIT */ && \
!defined(MCU_MK70F15) /* PIT */ && \
!defined(MCU_MK70F12WS) /* PIT */ && \
!defined(MCU_MK70F15WS) /* PIT */ && \
!defined(MCU_MKE02Z2) /* PIT */ && \
!defined(MCU_MKE02Z4) /* PIT */ && \
!defined(MCU_SKEAZN642) /* PIT */ && \
!defined(MCU_MKE04Z1284) /* PIT */ && \
!defined(MCU_MKE04Z4) /* PIT */ && \
!defined(MCU_SKEAZN84) /* PIT */ && \
!defined(MCU_MKE06Z4) /* PIT */ && \
!defined(MCU_MKL04Z4) /* PIT */ && \
!defined(MCU_MKL05Z4) /* PIT */ && \
!defined(MCU_MKL14Z4) /* PIT */ && \
!defined(MCU_MKL15Z4) /* PIT */ && \
!defined(MCU_MKL16Z4) /* PIT */ && \
!defined(MCU_MKL24Z4) /* PIT */ && \
!defined(MCU_MKL25Z4) /* PIT */ && \
!defined(MCU_MKL26Z4) /* PIT */ && \
!defined(MCU_MKL34Z4) /* PIT */ && \
!defined(MCU_MKL36Z4) /* PIT */ && \
!defined(MCU_MKL46Z4) /* PIT */ && \
!defined(MCU_MKV31F12810) /* PIT */ && \
!defined(MCU_MKV31F25612) /* PIT */ && \
!defined(MCU_MKV31F51212) /* PIT */ && \
!defined(MCU_MKW01Z4) /* PIT */ && \
!defined(MCU_MKW21D5) /* PIT */ && \
!defined(MCU_MKW21D5WS) /* PIT */ && \
!defined(MCU_MKW22D5) /* PIT */ && \
!defined(MCU_MKW22D5WS) /* PIT */ && \
!defined(MCU_MKW24D5) /* PIT */ && \
!defined(MCU_MKW24D5WS) /* PIT */ && \
!defined(MCU_PCK20L4) /* PIT */ && \
!defined(MCU_SKEAZ1284) /* PIT */
// Unsupported MCU is active
#error PIT PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* PIT channel constants */
#define PIT_PDD_CHANNEL_0 0U /**< 0 */
#define PIT_PDD_CHANNEL_1 0x1U /**< 1 */
#define PIT_PDD_CHANNEL_2 0x2U /**< 2 */
#define PIT_PDD_CHANNEL_3 0x3U /**< 3 */
/* Module clock constants */
#define PIT_PDD_CLOCK_ENABLED 0U /**< Enabled */
#define PIT_PDD_CLOCK_DISABLED PIT_MCR_MDIS_MASK /**< Disabled */
/* Freeze constants */
#define PIT_PDD_TIMERS_RUN 0U /**< Run */
#define PIT_PDD_TIMERS_STOPPED PIT_MCR_FRZ_MASK /**< Stopped */
/* ----------------------------------------------------------------------------
-- GetInterruptMask
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt mask.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_GetInterruptMask(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_GetInterruptMask(PeripheralBase, ChannelIdx) ( \
(uint32)(PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) & PIT_TCTRL_TIE_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt flag bit.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: TFLG[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_GetInterruptFlag(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_GetInterruptFlag(PeripheralBase, ChannelIdx) ( \
(uint32)(PIT_TFLG_REG(PeripheralBase,(ChannelIdx)) & PIT_TFLG_TIF_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enables the PIT interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_EnableInterrupt(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_EnableInterrupt(PeripheralBase, ChannelIdx) ( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) |= \
PIT_TCTRL_TIE_MASK \
)
/* ----------------------------------------------------------------------------
-- DisableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Disables the PIT interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_DisableInterrupt(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_DisableInterrupt(PeripheralBase, ChannelIdx) ( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) &= \
(uint32)(~(uint32)PIT_TCTRL_TIE_MASK) \
)
/* ----------------------------------------------------------------------------
-- ClearInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Clears PIT interrupt flag.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TFLG[ChannelIdx],
* LDVAL[ChannelIdx] (depending on the peripheral).
* @par Example:
* @code
* PIT_PDD_ClearInterruptFlag(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_ClearInterruptFlag(PeripheralBase, ChannelIdx) ( \
(PIT_TFLG_REG(PeripheralBase,(ChannelIdx)) = \
PIT_TFLG_TIF_MASK), \
(void)PIT_LDVAL_REG(PeripheralBase,(ChannelIdx)) \
)
/* ----------------------------------------------------------------------------
-- ModuleClock
---------------------------------------------------------------------------- */
/**
* @brief Enables/disables PIT module clock.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Clock New value of the clock. Use constants from group "Module clock
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: PIT_MCR.
* @par Example:
* @code
* PIT_PDD_ModuleClock(<peripheral>_BASE_PTR, PIT_PDD_CLOCK_ENABLED);
* @endcode
*/
#define PIT_PDD_ModuleClock(PeripheralBase, Clock) ( \
PIT_MCR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(PIT_MCR_REG(PeripheralBase) & (uint32)(~(uint32)PIT_MCR_MDIS_MASK))) | ( \
(uint32)(Clock))) \
)
/* ----------------------------------------------------------------------------
-- ModuleFreeze
---------------------------------------------------------------------------- */
/**
* @brief Allows the timers to be stopped when the device enters debug mode.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Freeze New value of the freeze. Use constants from group "Freeze
* constants". This parameter is 32 bits wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: PIT_MCR.
* @par Example:
* @code
* PIT_PDD_ModuleFreeze(<peripheral>_BASE_PTR, PIT_PDD_TIMERS_RUN);
* @endcode
*/
#define PIT_PDD_ModuleFreeze(PeripheralBase, Freeze) ( \
PIT_MCR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(PIT_MCR_REG(PeripheralBase) & (uint32)(~(uint32)PIT_MCR_FRZ_MASK))) | ( \
(uint32)(Freeze))) \
)
/* ----------------------------------------------------------------------------
-- WriteLoadReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the load register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @param Value New content of the load register. This parameter is a 32-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: LDVAL[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_WriteLoadReg(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0, 1);
* @endcode
*/
#define PIT_PDD_WriteLoadReg(PeripheralBase, ChannelIdx, Value) ( \
PIT_LDVAL_REG(PeripheralBase,(ChannelIdx)) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadLoadReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the load register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: LDVAL[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_ReadLoadReg(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_ReadLoadReg(PeripheralBase, ChannelIdx) ( \
PIT_LDVAL_REG(PeripheralBase,(ChannelIdx)) \
)
/* ----------------------------------------------------------------------------
-- ReadTimerValueReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the current timer value register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: CVAL[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_ReadTimerValueReg(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_ReadTimerValueReg(PeripheralBase, ChannelIdx) ( \
PIT_CVAL_REG(PeripheralBase,(ChannelIdx)) \
)
/* ----------------------------------------------------------------------------
-- EnableDevice
---------------------------------------------------------------------------- */
/**
* @brief Enables the PIT channel device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @param State Requested state of PIT channel. This parameter is of "Global
* enumeration used for specifying general enable/disable states (PDD_DISABLE
* and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_EnableDevice(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0,
* PDD_DISABLE);
* @endcode
*/
#define PIT_PDD_EnableDevice(PeripheralBase, ChannelIdx, State) ( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) = \
(uint32)(( \
(uint32)(( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx))) & ( \
(uint32)(~(uint32)PIT_TCTRL_TEN_MASK)))) | ( \
(uint32)(State))) \
)
/* ----------------------------------------------------------------------------
-- GetEnableDeviceStatus
---------------------------------------------------------------------------- */
/**
* @brief Returns current state of PIT channel device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_GetEnableDeviceStatus(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_GetEnableDeviceStatus(PeripheralBase, ChannelIdx) ( \
(uint32)(PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) & PIT_TCTRL_TEN_MASK) \
)
/* ----------------------------------------------------------------------------
-- WriteModuleControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the module control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the module control register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: PIT_MCR.
* @par Example:
* @code
* PIT_PDD_WriteModuleControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define PIT_PDD_WriteModuleControlReg(PeripheralBase, Value) ( \
PIT_MCR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadModuleControlReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the module control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: PIT_MCR.
* @par Example:
* @code
* uint32 result = PIT_PDD_ReadModuleControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define PIT_PDD_ReadModuleControlReg(PeripheralBase) ( \
PIT_MCR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteTimerControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the timer control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @param Value New content of the timer control register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_WriteTimerControlReg(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0,
* 1);
* @endcode
*/
#define PIT_PDD_WriteTimerControlReg(PeripheralBase, ChannelIdx, Value) ( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadTimerControlReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the timer control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: TCTRL[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_ReadTimerControlReg(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_ReadTimerControlReg(PeripheralBase, ChannelIdx) ( \
PIT_TCTRL_REG(PeripheralBase,(ChannelIdx)) \
)
/* ----------------------------------------------------------------------------
-- WriteTimerFlagReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the timer flag register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @param Value New content of the timer flag register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: TFLG[ChannelIdx].
* @par Example:
* @code
* PIT_PDD_WriteTimerFlagReg(<peripheral>_BASE_PTR, PIT_PDD_CHANNEL_0, 1);
* @endcode
*/
#define PIT_PDD_WriteTimerFlagReg(PeripheralBase, ChannelIdx, Value) ( \
PIT_TFLG_REG(PeripheralBase,(ChannelIdx)) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadTimerFlagReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the timer flag register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ChannelIdx PIT channel index. Use constants from group "PIT channel
* constants". This parameter is 32 bits wide.
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: TFLG[ChannelIdx].
* @par Example:
* @code
* uint32 result = PIT_PDD_ReadTimerFlagReg(<peripheral>_BASE_PTR,
* PIT_PDD_CHANNEL_0);
* @endcode
*/
#define PIT_PDD_ReadTimerFlagReg(PeripheralBase, ChannelIdx) ( \
PIT_TFLG_REG(PeripheralBase,(ChannelIdx)) \
)
#endif /* #if defined(PIT_PDD_H_) */
/* PIT_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,539 @@
/*
PDD layer implementation for peripheral type SysTick
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(SysTick_PDD_H_)
#define SysTick_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error SysTick PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* SysTick */ && \
!defined(MCU_MK10D5) /* SysTick */ && \
!defined(MCU_MK10D7) /* SysTick */ && \
!defined(MCU_MK10F12) /* SysTick */ && \
!defined(MCU_MK10DZ10) /* SysTick */ && \
!defined(MCU_MK11D5) /* SysTick */ && \
!defined(MCU_MK11D5WS) /* SysTick */ && \
!defined(MCU_MK12D5) /* SysTick */ && \
!defined(MCU_MK20D10) /* SysTick */ && \
!defined(MCU_MK20D5) /* SysTick */ && \
!defined(MCU_MK20D7) /* SysTick */ && \
!defined(MCU_MK20F12) /* SysTick */ && \
!defined(MCU_MK20DZ10) /* SysTick */ && \
!defined(MCU_MK21D5) /* SysTick */ && \
!defined(MCU_MK21D5WS) /* SysTick */ && \
!defined(MCU_MK21F12) /* SysTick */ && \
!defined(MCU_MK21F12WS) /* SysTick */ && \
!defined(MCU_MK22D5) /* SysTick */ && \
!defined(MCU_MK22F12810) /* SysTick */ && \
!defined(MCU_MK22F12) /* SysTick */ && \
!defined(MCU_MK22F25612) /* SysTick */ && \
!defined(MCU_MK22F51212) /* SysTick */ && \
!defined(MCU_MK24F12) /* SysTick */ && \
!defined(MCU_MK30D10) /* SysTick */ && \
!defined(MCU_MK30D7) /* SysTick */ && \
!defined(MCU_MK30DZ10) /* SysTick */ && \
!defined(MCU_MK40D10) /* SysTick */ && \
!defined(MCU_MK40D7) /* SysTick */ && \
!defined(MCU_MK40DZ10) /* SysTick */ && \
!defined(MCU_MK40X256VMD100) /* SysTick */ && \
!defined(MCU_MK50D10) /* SysTick */ && \
!defined(MCU_MK50D7) /* SysTick */ && \
!defined(MCU_MK50DZ10) /* SysTick */ && \
!defined(MCU_MK51D10) /* SysTick */ && \
!defined(MCU_MK51D7) /* SysTick */ && \
!defined(MCU_MK51DZ10) /* SysTick */ && \
!defined(MCU_MK52D10) /* SysTick */ && \
!defined(MCU_MK52DZ10) /* SysTick */ && \
!defined(MCU_MK53D10) /* SysTick */ && \
!defined(MCU_MK53DZ10) /* SysTick */ && \
!defined(MCU_MK60D10) /* SysTick */ && \
!defined(MCU_MK60F12) /* SysTick */ && \
!defined(MCU_MK60F15) /* SysTick */ && \
!defined(MCU_MK60DZ10) /* SysTick */ && \
!defined(MCU_MK60N512VMD100) /* SysTick */ && \
!defined(MCU_MK61F12) /* SysTick */ && \
!defined(MCU_MK61F15) /* SysTick */ && \
!defined(MCU_MK61F12WS) /* SysTick */ && \
!defined(MCU_MK61F15WS) /* SysTick */ && \
!defined(MCU_MK63F12) /* SysTick */ && \
!defined(MCU_MK63F12WS) /* SysTick */ && \
!defined(MCU_MK64F12) /* SysTick */ && \
!defined(MCU_MK65F18) /* SysTick */ && \
!defined(MCU_MK65F18WS) /* SysTick */ && \
!defined(MCU_MK66F18) /* SysTick */ && \
!defined(MCU_MK70F12) /* SysTick */ && \
!defined(MCU_MK70F15) /* SysTick */ && \
!defined(MCU_MK70F12WS) /* SysTick */ && \
!defined(MCU_MK70F15WS) /* SysTick */ && \
!defined(MCU_MKE02Z2) /* SysTick */ && \
!defined(MCU_MKE02Z4) /* SysTick */ && \
!defined(MCU_SKEAZN642) /* SysTick */ && \
!defined(MCU_MKE04Z1284) /* SysTick */ && \
!defined(MCU_MKE04Z4) /* SysTick */ && \
!defined(MCU_SKEAZN84) /* SysTick */ && \
!defined(MCU_MKE06Z4) /* SysTick */ && \
!defined(MCU_MKL02Z4) /* SysTick */ && \
!defined(MCU_MKL03Z4) /* SysTick */ && \
!defined(MCU_MKL04Z4) /* SysTick */ && \
!defined(MCU_MKL05Z4) /* SysTick */ && \
!defined(MCU_MKL14Z4) /* SysTick */ && \
!defined(MCU_MKL15Z4) /* SysTick */ && \
!defined(MCU_MKL16Z4) /* SysTick */ && \
!defined(MCU_MKL24Z4) /* SysTick */ && \
!defined(MCU_MKL25Z4) /* SysTick */ && \
!defined(MCU_MKL26Z4) /* SysTick */ && \
!defined(MCU_MKL34Z4) /* SysTick */ && \
!defined(MCU_MKL36Z4) /* SysTick */ && \
!defined(MCU_MKL46Z4) /* SysTick */ && \
!defined(MCU_MKV10Z7) /* SysTick */ && \
!defined(MCU_MKV31F12810) /* SysTick */ && \
!defined(MCU_MKV31F25612) /* SysTick */ && \
!defined(MCU_MKV31F51212) /* SysTick */ && \
!defined(MCU_MKW01Z4) /* SysTick */ && \
!defined(MCU_MKW21D5) /* SysTick */ && \
!defined(MCU_MKW21D5WS) /* SysTick */ && \
!defined(MCU_MKW22D5) /* SysTick */ && \
!defined(MCU_MKW22D5WS) /* SysTick */ && \
!defined(MCU_MKW24D5) /* SysTick */ && \
!defined(MCU_MKW24D5WS) /* SysTick */ && \
!defined(MCU_PCK20L4) /* SysTick */ && \
!defined(MCU_SKEAZ1284) /* SysTick */
// Unsupported MCU is active
#error SysTick PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
#if ((defined(MCU_MKE02Z2)) || (defined(MCU_MKE02Z4)) || (defined(MCU_MKE04Z1284)) || (defined(MCU_MKE04Z4)) || (defined(MCU_MKE06Z4)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKW01Z4)) || (defined(MCU_SKEAZ1284)) || (defined(MCU_SKEAZN642)) || (defined(MCU_SKEAZN84)))
/* Clock source constants. */
#define SysTick_PDD_CORE_CLOCK 0x1U /**< 1 */
#define SysTick_PDD_CORE_CLOCK_DIV16 0U /**< 1 */
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* Clock source constants. */
#define SysTick_PDD_CORE_CLOCK 0x1U /**< 1 */
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* ----------------------------------------------------------------------------
-- GetInterruptMask
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt mask.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint32 result = SysTick_PDD_GetInterruptMask(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_GetInterruptMask(PeripheralBase) ( \
(uint32)(SysTick_CSR_REG(PeripheralBase) & SysTick_CSR_TICKINT_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Returns interrupt flag bit.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint32 result = SysTick_PDD_GetInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_GetInterruptFlag(PeripheralBase) ( \
(uint32)(SysTick_CSR_REG(PeripheralBase) & SysTick_CSR_COUNTFLAG_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enables the SysTick interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_EnableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_EnableInterrupt(PeripheralBase) ( \
SysTick_CSR_REG(PeripheralBase) |= \
SysTick_CSR_TICKINT_MASK \
)
/* ----------------------------------------------------------------------------
-- DisableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Disables the SysTick interrupt.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_DisableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_DisableInterrupt(PeripheralBase) ( \
SysTick_CSR_REG(PeripheralBase) &= \
(uint32)(~(uint32)SysTick_CSR_TICKINT_MASK) \
)
/* ----------------------------------------------------------------------------
-- ClearInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Clears SysTick interrupt flag.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_ClearInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_ClearInterruptFlag(PeripheralBase) ( \
SysTick_CSR_REG(PeripheralBase) &= \
(uint32)(~(uint32)SysTick_CSR_COUNTFLAG_MASK) \
)
/* ----------------------------------------------------------------------------
-- EnableDevice
---------------------------------------------------------------------------- */
/**
* @brief Enables the SysTick device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Requested state of SysTick device. This parameter is of "Global
* enumeration used for specifying general enable/disable states
* (PDD_DISABLE and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_EnableDevice(<peripheral>_BASE_PTR, PDD_DISABLE);
* @endcode
*/
#define SysTick_PDD_EnableDevice(PeripheralBase, State) ( \
SysTick_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
SysTick_CSR_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)SysTick_CSR_ENABLE_MASK)))) | ( \
(uint32)(State))) \
)
/* ----------------------------------------------------------------------------
-- GetEnableDeviceStatus
---------------------------------------------------------------------------- */
/**
* @brief Returns current state of SysTick device.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint32 result =
* SysTick_PDD_GetEnableDeviceStatus(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_GetEnableDeviceStatus(PeripheralBase) ( \
(uint32)(SysTick_CSR_REG(PeripheralBase) & SysTick_CSR_ENABLE_MASK) \
)
/* ----------------------------------------------------------------------------
-- SetClkSource
---------------------------------------------------------------------------- */
/**
* @brief Sets clock source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param ClkSource New value of the clock source. Use constants from group
* "Clock source constants.". This parameter is 1 bit wide.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_SetClkSource(<peripheral>_BASE_PTR, SysTick_PDD_CORE_CLOCK);
* @endcode
*/
#define SysTick_PDD_SetClkSource(PeripheralBase, ClkSource) ( \
SysTick_CSR_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
SysTick_CSR_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)SysTick_CSR_CLKSOURCE_MASK)))) | ( \
(uint32)((uint32)(ClkSource) << SysTick_CSR_CLKSOURCE_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- GetClkSource
---------------------------------------------------------------------------- */
#if ((defined(MCU_MKE02Z2)) || (defined(MCU_MKE02Z4)) || (defined(MCU_MKE04Z1284)) || (defined(MCU_MKE04Z4)) || (defined(MCU_MKE06Z4)) || (defined(MCU_MKL02Z4)) || (defined(MCU_MKL03Z4)) || (defined(MCU_MKL04Z4)) || (defined(MCU_MKL05Z4)) || (defined(MCU_MKL14Z4)) || (defined(MCU_MKL15Z4)) || (defined(MCU_MKL16Z4)) || (defined(MCU_MKL24Z4)) || (defined(MCU_MKL25Z4)) || (defined(MCU_MKL26Z4)) || (defined(MCU_MKL34Z4)) || (defined(MCU_MKL36Z4)) || (defined(MCU_MKL46Z4)) || (defined(MCU_MKV10Z7)) || (defined(MCU_MKW01Z4)) || (defined(MCU_SKEAZ1284)) || (defined(MCU_SKEAZN642)) || (defined(MCU_SKEAZN84)))
/**
* @brief Gets clock source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Use constants from group "Clock source constants." for processing
* return value. The value is cast to "uint8".
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint8 result = SysTick_PDD_GetClkSource(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_GetClkSource(PeripheralBase) ( \
(uint8)(( \
(uint32)(SysTick_CSR_REG(PeripheralBase) & SysTick_CSR_CLKSOURCE_MASK)) >> ( \
SysTick_CSR_CLKSOURCE_SHIFT)) \
)
#else /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/**
* @brief Gets clock source.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Use constants from group "Clock source constants." for processing
* return value. The value is cast to "uint8".
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint8 result = SysTick_PDD_GetClkSource(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_GetClkSource(PeripheralBase) ( \
0x1U \
)
#endif /* (defined(MCU_MK10D10)) || (defined(MCU_MK10D5)) || (defined(MCU_MK10D7)) || (defined(MCU_MK10DZ10)) || (defined(MCU_MK10F12)) || (defined(MCU_MK11D5)) || (defined(MCU_MK11D5WS)) || (defined(MCU_MK12D5)) || (defined(MCU_MK20D10)) || (defined(MCU_MK20D5)) || (defined(MCU_MK20D7)) || (defined(MCU_MK20DZ10)) || (defined(MCU_MK20F12)) || (defined(MCU_MK21D5)) || (defined(MCU_MK21D5WS)) || (defined(MCU_MK21F12)) || (defined(MCU_MK21F12WS)) || (defined(MCU_MK22D5)) || (defined(MCU_MK22F12)) || (defined(MCU_MK22F12810)) || (defined(MCU_MK22F25612)) || (defined(MCU_MK22F51212)) || (defined(MCU_MK24F12)) || (defined(MCU_MK30D10)) || (defined(MCU_MK30D7)) || (defined(MCU_MK30DZ10)) || (defined(MCU_MK40D10)) || (defined(MCU_MK40D7)) || (defined(MCU_MK40DZ10)) || (defined(MCU_MK40X256VMD100)) || (defined(MCU_MK50D10)) || (defined(MCU_MK50D7)) || (defined(MCU_MK50DZ10)) || (defined(MCU_MK51D10)) || (defined(MCU_MK51D7)) || (defined(MCU_MK51DZ10)) || (defined(MCU_MK52D10)) || (defined(MCU_MK52DZ10)) || (defined(MCU_MK53D10)) || (defined(MCU_MK53DZ10)) || (defined(MCU_MK60D10)) || (defined(MCU_MK60DZ10)) || (defined(MCU_MK60F12)) || (defined(MCU_MK60F15)) || (defined(MCU_MK60N512VMD100)) || (defined(MCU_MK61F12)) || (defined(MCU_MK61F12WS)) || (defined(MCU_MK61F15)) || (defined(MCU_MK61F15WS)) || (defined(MCU_MK63F12)) || (defined(MCU_MK63F12WS)) || (defined(MCU_MK64F12)) || (defined(MCU_MK65F18)) || (defined(MCU_MK65F18WS)) || (defined(MCU_MK66F18)) || (defined(MCU_MK70F12)) || (defined(MCU_MK70F12WS)) || (defined(MCU_MK70F15)) || (defined(MCU_MK70F15WS)) || (defined(MCU_MKV31F12810)) || (defined(MCU_MKV31F25612)) || (defined(MCU_MKV31F51212)) || (defined(MCU_MKW21D5)) || (defined(MCU_MKW21D5WS)) || (defined(MCU_MKW22D5)) || (defined(MCU_MKW22D5WS)) || (defined(MCU_MKW24D5)) || (defined(MCU_MKW24D5WS)) || (defined(MCU_PCK20L4)) */
/* ----------------------------------------------------------------------------
-- WriteControlStatusReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the control and status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the control and status register. This parameter
* is a 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* SysTick_PDD_WriteControlStatusReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define SysTick_PDD_WriteControlStatusReg(PeripheralBase, Value) ( \
SysTick_CSR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadControlStatusReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the control and status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CSR.
* @par Example:
* @code
* uint32 result =
* SysTick_PDD_ReadControlStatusReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_ReadControlStatusReg(PeripheralBase) ( \
SysTick_CSR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteReloadValueReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the reload register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the reload register. This parameter is a 32-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_RVR.
* @par Example:
* @code
* SysTick_PDD_WriteReloadValueReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define SysTick_PDD_WriteReloadValueReg(PeripheralBase, Value) ( \
SysTick_RVR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadReloadValueReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the reload register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_RVR.
* @par Example:
* @code
* uint32 result = SysTick_PDD_ReadReloadValueReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_ReadReloadValueReg(PeripheralBase) ( \
SysTick_RVR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteCurrentValueReg
---------------------------------------------------------------------------- */
/**
* @brief Writes value to the current value register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value New content of the current value register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: SYST_CVR.
* @par Example:
* @code
* SysTick_PDD_WriteCurrentValueReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define SysTick_PDD_WriteCurrentValueReg(PeripheralBase, Value) ( \
SysTick_CVR_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- ReadCurrentValueReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the current value register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CVR.
* @par Example:
* @code
* uint32 result =
* SysTick_PDD_ReadCurrentValueReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_ReadCurrentValueReg(PeripheralBase) ( \
SysTick_CVR_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- ReadCalibrationReg
---------------------------------------------------------------------------- */
/**
* @brief Returns the content of the calibration register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: SYST_CALIB.
* @par Example:
* @code
* uint32 result = SysTick_PDD_ReadCalibrationReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define SysTick_PDD_ReadCalibrationReg(PeripheralBase) ( \
SysTick_CALIB_REG(PeripheralBase) \
)
#endif /* #if defined(SysTick_PDD_H_) */
/* SysTick_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,816 @@
/*
PDD layer implementation for peripheral type USBDCD
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(USBDCD_PDD_H_)
#define USBDCD_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error USBDCD PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK20D10) /* USBDCD */ && \
!defined(MCU_MK20D5) /* USBDCD */ && \
!defined(MCU_MK20D7) /* USBDCD */ && \
!defined(MCU_MK20F12) /* USBDCD */ && \
!defined(MCU_MK20DZ10) /* USBDCD */ && \
!defined(MCU_MK21D5) /* USBDCD */ && \
!defined(MCU_MK21D5WS) /* USBDCD */ && \
!defined(MCU_MK21F12) /* USBDCD */ && \
!defined(MCU_MK21F12WS) /* USBDCD */ && \
!defined(MCU_MK22D5) /* USBDCD */ && \
!defined(MCU_MK22F12) /* USBDCD */ && \
!defined(MCU_MK24F12) /* USBDCD */ && \
!defined(MCU_MK40D10) /* USBDCD */ && \
!defined(MCU_MK40D7) /* USBDCD */ && \
!defined(MCU_MK40DZ10) /* USBDCD */ && \
!defined(MCU_MK40X256VMD100) /* USBDCD */ && \
!defined(MCU_MK50D10) /* USBDCD */ && \
!defined(MCU_MK50D7) /* USBDCD */ && \
!defined(MCU_MK50DZ10) /* USBDCD */ && \
!defined(MCU_MK51D10) /* USBDCD */ && \
!defined(MCU_MK51D7) /* USBDCD */ && \
!defined(MCU_MK51DZ10) /* USBDCD */ && \
!defined(MCU_MK52D10) /* USBDCD */ && \
!defined(MCU_MK52DZ10) /* USBDCD */ && \
!defined(MCU_MK53D10) /* USBDCD */ && \
!defined(MCU_MK53DZ10) /* USBDCD */ && \
!defined(MCU_MK60D10) /* USBDCD */ && \
!defined(MCU_MK60F12) /* USBDCD */ && \
!defined(MCU_MK60F15) /* USBDCD */ && \
!defined(MCU_MK60DZ10) /* USBDCD */ && \
!defined(MCU_MK60N512VMD100) /* USBDCD */ && \
!defined(MCU_MK61F12) /* USBDCD */ && \
!defined(MCU_MK61F15) /* USBDCD */ && \
!defined(MCU_MK61F12WS) /* USBDCD */ && \
!defined(MCU_MK61F15WS) /* USBDCD */ && \
!defined(MCU_MK63F12) /* USBDCD */ && \
!defined(MCU_MK63F12WS) /* USBDCD */ && \
!defined(MCU_MK64F12) /* USBDCD */ && \
!defined(MCU_MK65F18) /* USBDCD, USBHSDCD */ && \
!defined(MCU_MK65F18WS) /* USBDCD, USBHSDCD */ && \
!defined(MCU_MK66F18) /* USBDCD, USBHSDCD */ && \
!defined(MCU_MK70F12) /* USBDCD */ && \
!defined(MCU_MK70F15) /* USBDCD */ && \
!defined(MCU_MK70F12WS) /* USBDCD */ && \
!defined(MCU_MK70F15WS) /* USBDCD */ && \
!defined(MCU_MKW22D5) /* USBDCD */ && \
!defined(MCU_MKW22D5WS) /* USBDCD */ && \
!defined(MCU_MKW24D5) /* USBDCD */ && \
!defined(MCU_MKW24D5WS) /* USBDCD */ && \
!defined(MCU_PCK20L4) /* USBDCD */
// Unsupported MCU is active
#error USBDCD PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Status flags constants (for ReadStatusReg macro). */
#define USBDCD_PDD_ACTIVE_STATUS_INDICATOR USBDCD_STATUS_ACTIVE_MASK /**< Active status indicator - indicates whether the sequence is running */
#define USBDCD_PDD_TIMEOUT_FLAG USBDCD_STATUS_TO_MASK /**< Timeout flag */
#define USBDCD_PDD_ERROR_FLAG USBDCD_STATUS_ERR_MASK /**< Error flag */
/* Receiver status bits constants */
#define USBDCD_PDD_DATA_PIN_NOT_DETECTED 0U /**< The module is either not enabled, or the module is enabled but the data pins have not yet been detected */
#define USBDCD_PDD_DATA_PIN_CONTACT_COMPLETE 0x40000U /**< Data pin contact detection complete */
#define USBDCD_PDD_CHARGER_PORT_COMPLETE 0x80000U /**< Charger port detection complete */
#define USBDCD_PDD_CHARGER_TYPE_COMPLETE 0xC0000U /**< Charger type detection complete */
/* Receiver status bits constants */
#define USBDCD_PDD_NO_RESULTS_REPORTED 0U /**< No results to report */
#define USBDCD_PDD_ATTACHED_TO_HOST 0x10000U /**< Attached to a standard host */
#define USBDCD_PDD_ATTACHED_TO_CHARGING_PORT 0x20000U /**< Attached to a charging port */
#define USBDCD_PDD_ATTACHED_TO_DEDICATED_CHARGER 0x30000U /**< Attached to a dedicated charger. */
/* ----------------------------------------------------------------------------
-- PerformSoftwareReset
---------------------------------------------------------------------------- */
/**
* @brief Perform a software reset.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_PerformSoftwareReset(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_PerformSoftwareReset(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) |= \
USBDCD_CONTROL_SR_MASK \
)
/* ----------------------------------------------------------------------------
-- StartChangeDetectionSequence
---------------------------------------------------------------------------- */
/**
* @brief Initiate the charger detection sequence.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_StartChangeDetectionSequence(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_StartChangeDetectionSequence(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) |= \
USBDCD_CONTROL_START_MASK \
)
/* ----------------------------------------------------------------------------
-- EnableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Enables interrupts to the system.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_EnableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_EnableInterrupt(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) |= \
USBDCD_CONTROL_IE_MASK \
)
/* ----------------------------------------------------------------------------
-- DisableInterrupt
---------------------------------------------------------------------------- */
/**
* @brief Disable interrupts to the system.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_DisableInterrupt(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_DisableInterrupt(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) &= \
(uint32)(~(uint32)USBDCD_CONTROL_IE_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Gets the status of the interrupt flag bit.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_GetInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_GetInterruptFlag(PeripheralBase) ( \
(uint32)(USBDCD_CONTROL_REG(PeripheralBase) & USBDCD_CONTROL_IF_MASK) \
)
/* ----------------------------------------------------------------------------
-- ClearInterruptFlag
---------------------------------------------------------------------------- */
/**
* @brief Clears interrupt flag.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_ClearInterruptFlag(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ClearInterruptFlag(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) |= \
USBDCD_CONTROL_IACK_MASK \
)
/* ----------------------------------------------------------------------------
-- ReadControlReg
---------------------------------------------------------------------------- */
/**
* @brief Reads control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadControlReg(PeripheralBase) ( \
USBDCD_CONTROL_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the control register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CONTROL,
* USBHSDCD_CONTROL (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_WriteControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_WriteControlReg(PeripheralBase, Value) ( \
USBDCD_CONTROL_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- SetClockSpeedInKhz
---------------------------------------------------------------------------- */
/**
* @brief Sets the numerical value of clock speed in kHz.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Clock speed in kHz, value[1..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CLOCK,
* USBHSDCD_CLOCK (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_SetClockSpeedInKhz(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetClockSpeedInKhz(PeripheralBase, Value) ( \
USBDCD_CLOCK_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_CLOCK_REG(PeripheralBase)) & (( \
(uint32)(~(uint32)USBDCD_CLOCK_CLOCK_SPEED_MASK)) & ( \
(uint32)(~(uint32)USBDCD_CLOCK_CLOCK_UNIT_MASK))))) | ( \
(uint32)((uint32)(Value) << USBDCD_CLOCK_CLOCK_SPEED_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- SetClockSpeedInMhz
---------------------------------------------------------------------------- */
/**
* @brief Sets the numerical value of clock speed in MHz.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Clock speed in MHz, value[1..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CLOCK,
* USBHSDCD_CLOCK (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_SetClockSpeedInMhz(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetClockSpeedInMhz(PeripheralBase, Value) ( \
USBDCD_CLOCK_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_CLOCK_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_CLOCK_CLOCK_SPEED_MASK)))) | (( \
(uint32)((uint32)(Value) << USBDCD_CLOCK_CLOCK_SPEED_SHIFT)) | ( \
USBDCD_CLOCK_CLOCK_UNIT_MASK))) \
)
/* ----------------------------------------------------------------------------
-- ReadClockReg
---------------------------------------------------------------------------- */
/**
* @brief Reads clock register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_CLOCK,
* USBHSDCD_CLOCK (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadClockReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadClockReg(PeripheralBase) ( \
USBDCD_CLOCK_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteClockReg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into clock register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the clock register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_CLOCK,
* USBHSDCD_CLOCK (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_WriteClockReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_WriteClockReg(PeripheralBase, Value) ( \
USBDCD_CLOCK_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- GetStatusFlags
---------------------------------------------------------------------------- */
/**
* @brief Returns the value of the status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_STATUS,
* USBHSDCD_STATUS (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_GetStatusFlags(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_GetStatusFlags(PeripheralBase) ( \
USBDCD_STATUS_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- GetChargerDetectionSequenceStatus
---------------------------------------------------------------------------- */
/**
* @brief Returns charger detection sequence status.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of "Receiver status bits constants" type. The value
* is cast to "uint32".
* @remarks The macro accesses the following registers: USBDCD_STATUS,
* USBHSDCD_STATUS (depending on the peripheral).
* @par Example:
* @code
* uint32 result =
* USBDCD_PDD_GetChargerDetectionSequenceStatus(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_GetChargerDetectionSequenceStatus(PeripheralBase) ( \
(uint32)(USBDCD_STATUS_REG(PeripheralBase) & USBDCD_STATUS_SEQ_STAT_MASK) \
)
/* ----------------------------------------------------------------------------
-- GetChargerDetectionSequenceResults
---------------------------------------------------------------------------- */
/**
* @brief Returns charger detection sequence status.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of "Receiver status bits constants" type. The value
* is cast to "uint32".
* @remarks The macro accesses the following registers: USBDCD_STATUS,
* USBHSDCD_STATUS (depending on the peripheral).
* @par Example:
* @code
* uint32 result =
* USBDCD_PDD_GetChargerDetectionSequenceResults(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_GetChargerDetectionSequenceResults(PeripheralBase) ( \
(uint32)(USBDCD_STATUS_REG(PeripheralBase) & USBDCD_STATUS_SEQ_RES_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadStatusReg
---------------------------------------------------------------------------- */
/**
* @brief Reads status register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Use constants from group "Status flags constants (for ReadStatusReg
* macro)." for processing return value.
* @remarks The macro accesses the following registers: USBDCD_STATUS,
* USBHSDCD_STATUS (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadStatusReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadStatusReg(PeripheralBase) ( \
USBDCD_STATUS_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- SetSequenceInitiationTime
---------------------------------------------------------------------------- */
/**
* @brief Sets the system latency (in ms).
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Time System latency (in ms) value[0..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER0,
* USBHSDCD_TIMER0 (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_SetSequenceInitiationTime(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetSequenceInitiationTime(PeripheralBase, Time) ( \
USBDCD_TIMER0_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_TIMER0_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_TIMER0_TSEQ_INIT_MASK)))) | ( \
(uint32)((uint32)(Time) << USBDCD_TIMER0_TSEQ_INIT_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- GetUnitConnectionTimerElapse
---------------------------------------------------------------------------- */
/**
* @brief Returns unit connection timer elapse value (in ms).
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 12-bit value. The value is cast to "uint16".
* @remarks The macro accesses the following registers: USBDCD_TIMER0,
* USBHSDCD_TIMER0 (depending on the peripheral).
* @par Example:
* @code
* uint16 result =
* USBDCD_PDD_GetUnitConnectionTimerElapse(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_GetUnitConnectionTimerElapse(PeripheralBase) ( \
(uint16)(USBDCD_TIMER0_REG(PeripheralBase) & USBDCD_TIMER0_TUNITCON_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadTimer0Reg
---------------------------------------------------------------------------- */
/**
* @brief Reads timer 0 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_TIMER0,
* USBHSDCD_TIMER0 (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadTimer0Reg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadTimer0Reg(PeripheralBase) ( \
USBDCD_TIMER0_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteTimer0Reg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into timer 0 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the timer 0 register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER0,
* USBHSDCD_TIMER0 (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_WriteTimer0Reg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_WriteTimer0Reg(PeripheralBase, Value) ( \
USBDCD_TIMER0_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- SetTimePeriodToDebounceDpSignal
---------------------------------------------------------------------------- */
/**
* @brief Sets the time period (ms) to debounce the D+ signal during the data
* pin contact detection phase.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Period Time period (in ms) value[1..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER1,
* USBHSDCD_TIMER1 (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_SetTimePeriodToDebounceDpSignal(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetTimePeriodToDebounceDpSignal(PeripheralBase, Period) ( \
USBDCD_TIMER1_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_TIMER1_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_TIMER1_TDCD_DBNC_MASK)))) | ( \
(uint32)((uint32)(Period) << USBDCD_TIMER1_TDCD_DBNC_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- SetTimePeriodComparator
---------------------------------------------------------------------------- */
/**
* @brief Sets the time period (ms) comparator enabled.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Period Time period (in ms) value[1..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER1,
* USBHSDCD_TIMER1 (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_SetTimePeriodComparator(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetTimePeriodComparator(PeripheralBase, Period) ( \
USBDCD_TIMER1_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_TIMER1_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_TIMER1_TVDPSRC_ON_MASK)))) | ( \
(uint32)(Period))) \
)
/* ----------------------------------------------------------------------------
-- ReadTimer1Reg
---------------------------------------------------------------------------- */
/**
* @brief Reads timer 1 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_TIMER1,
* USBHSDCD_TIMER1 (depending on the peripheral).
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadTimer1Reg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadTimer1Reg(PeripheralBase) ( \
USBDCD_TIMER1_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteTimer1Reg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into timer 1 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the timer 1 register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER1,
* USBHSDCD_TIMER1 (depending on the peripheral).
* @par Example:
* @code
* USBDCD_PDD_WriteTimer1Reg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_WriteTimer1Reg(PeripheralBase, Value) ( \
USBDCD_TIMER1_REG(PeripheralBase) = \
(uint32)(Value) \
)
/* ----------------------------------------------------------------------------
-- SetTimePeriodBeforeEnablingDpPullup
---------------------------------------------------------------------------- */
/**
* @brief Sets the time period (ms) before enabling D+ pullup.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Period Time period (in ms) value[1..1023]. This parameter is a 10-bit
* value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER2.
* @par Example:
* @code
* USBDCD_PDD_SetTimePeriodBeforeEnablingDpPullup(<peripheral>_BASE_PTR,
* 1);
* @endcode
*/
#define USBDCD_PDD_SetTimePeriodBeforeEnablingDpPullup(PeripheralBase, Period) ( \
USBDCD_TIMER2_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_TIMER2_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_TIMER2_TVDPSRC_CON_MASK)))) | ( \
(uint32)((uint32)(Period) << USBDCD_TIMER2_TVDPSRC_CON_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- SetTimeBeforeCheckDmLine
---------------------------------------------------------------------------- */
/**
* @brief Sets the time period (ms) before check D- line.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Time (in ms) value[1..15]. This parameter is a 4-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER2.
* @par Example:
* @code
* USBDCD_PDD_SetTimeBeforeCheckDmLine(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_SetTimeBeforeCheckDmLine(PeripheralBase, Value) ( \
USBDCD_TIMER2_REG(PeripheralBase) = \
(uint32)(( \
(uint32)(( \
USBDCD_TIMER2_REG(PeripheralBase)) & ( \
(uint32)(~(uint32)USBDCD_TIMER2_CHECK_DM_MASK)))) | ( \
(uint32)(Value))) \
)
/* ----------------------------------------------------------------------------
-- ReadTimer2Reg
---------------------------------------------------------------------------- */
/**
* @brief Reads timer 2 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 32-bit value.
* @remarks The macro accesses the following registers: USBDCD_TIMER2.
* @par Example:
* @code
* uint32 result = USBDCD_PDD_ReadTimer2Reg(<peripheral>_BASE_PTR);
* @endcode
*/
#define USBDCD_PDD_ReadTimer2Reg(PeripheralBase) ( \
USBDCD_TIMER2_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteTimer2Reg
---------------------------------------------------------------------------- */
/**
* @brief Writes data specified by the Value parameter into timer 2 register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the timer 2 register. This parameter is a
* 32-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: USBDCD_TIMER2.
* @par Example:
* @code
* USBDCD_PDD_WriteTimer2Reg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define USBDCD_PDD_WriteTimer2Reg(PeripheralBase, Value) ( \
USBDCD_TIMER2_REG(PeripheralBase) = \
(uint32)(Value) \
)
#endif /* #if defined(USBDCD_PDD_H_) */
/* USBDCD_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,413 @@
/*
PDD layer implementation for peripheral type VREF
(C) 2013 Freescale, Inc. All rights reserved.
This file is static and it is generated from API-Factory
*/
#if !defined(VREF_PDD_H_)
#define VREF_PDD_H_
/* ----------------------------------------------------------------------------
-- Test if supported MCU is active
---------------------------------------------------------------------------- */
#if !defined(MCU_ACTIVE)
// No MCU is active
#error VREF PDD library: No derivative is active. Place proper #include with PDD memory map before including PDD library.
#elif \
!defined(MCU_MK10D10) /* VREF */ && \
!defined(MCU_MK10D5) /* VREF */ && \
!defined(MCU_MK10D7) /* VREF */ && \
!defined(MCU_MK10F12) /* VREF */ && \
!defined(MCU_MK10DZ10) /* VREF */ && \
!defined(MCU_MK11D5) /* VREF */ && \
!defined(MCU_MK11D5WS) /* VREF */ && \
!defined(MCU_MK12D5) /* VREF */ && \
!defined(MCU_MK20D10) /* VREF */ && \
!defined(MCU_MK20D5) /* VREF */ && \
!defined(MCU_MK20D7) /* VREF */ && \
!defined(MCU_MK20F12) /* VREF */ && \
!defined(MCU_MK20DZ10) /* VREF */ && \
!defined(MCU_MK21D5) /* VREF */ && \
!defined(MCU_MK21D5WS) /* VREF */ && \
!defined(MCU_MK21F12) /* VREF */ && \
!defined(MCU_MK21F12WS) /* VREF */ && \
!defined(MCU_MK22D5) /* VREF */ && \
!defined(MCU_MK22F12810) /* VREF */ && \
!defined(MCU_MK22F12) /* VREF */ && \
!defined(MCU_MK22F25612) /* VREF */ && \
!defined(MCU_MK22F51212) /* VREF */ && \
!defined(MCU_MK24F12) /* VREF */ && \
!defined(MCU_MK30D10) /* VREF */ && \
!defined(MCU_MK30D7) /* VREF */ && \
!defined(MCU_MK30DZ10) /* VREF */ && \
!defined(MCU_MK40D10) /* VREF */ && \
!defined(MCU_MK40D7) /* VREF */ && \
!defined(MCU_MK40DZ10) /* VREF */ && \
!defined(MCU_MK40X256VMD100) /* VREF */ && \
!defined(MCU_MK50D10) /* VREF */ && \
!defined(MCU_MK50D7) /* VREF */ && \
!defined(MCU_MK50DZ10) /* VREF */ && \
!defined(MCU_MK51D10) /* VREF */ && \
!defined(MCU_MK51D7) /* VREF */ && \
!defined(MCU_MK51DZ10) /* VREF */ && \
!defined(MCU_MK52D10) /* VREF */ && \
!defined(MCU_MK52DZ10) /* VREF */ && \
!defined(MCU_MK53D10) /* VREF */ && \
!defined(MCU_MK53DZ10) /* VREF */ && \
!defined(MCU_MK60D10) /* VREF */ && \
!defined(MCU_MK60F12) /* VREF */ && \
!defined(MCU_MK60F15) /* VREF */ && \
!defined(MCU_MK60DZ10) /* VREF */ && \
!defined(MCU_MK60N512VMD100) /* VREF */ && \
!defined(MCU_MK61F12) /* VREF */ && \
!defined(MCU_MK61F15) /* VREF */ && \
!defined(MCU_MK61F12WS) /* VREF */ && \
!defined(MCU_MK61F15WS) /* VREF */ && \
!defined(MCU_MK63F12) /* VREF */ && \
!defined(MCU_MK63F12WS) /* VREF */ && \
!defined(MCU_MK64F12) /* VREF */ && \
!defined(MCU_MK65F18) /* VREF */ && \
!defined(MCU_MK65F18WS) /* VREF */ && \
!defined(MCU_MK66F18) /* VREF */ && \
!defined(MCU_MK70F12) /* VREF */ && \
!defined(MCU_MK70F15) /* VREF */ && \
!defined(MCU_MK70F12WS) /* VREF */ && \
!defined(MCU_MK70F15WS) /* VREF */ && \
!defined(MCU_MKL03Z4) /* VREF */ && \
!defined(MCU_MKV31F12810) /* VREF */ && \
!defined(MCU_MKV31F25612) /* VREF */ && \
!defined(MCU_MKV31F51212) /* VREF */ && \
!defined(MCU_PCK20L4) /* VREF */
// Unsupported MCU is active
#error VREF PDD library: Unsupported derivative is active.
#endif
#include "PDD_Types.h"
/* ----------------------------------------------------------------------------
-- Method symbol definitions
---------------------------------------------------------------------------- */
/* Position of a parity bit */
#define VREF_PDD_DISABLED_OR_NOT_STABLE 0U /**< The module is disabled or not stable. */
#define VREF_PDD_STABLE 0x4U /**< The module is stable. */
/* Type of the buffer mode. */
#define VREF_PDD_BANDGAP_ON_ONLY 0U /**< Bandgap on only, for stabilization and startup. */
#define VREF_PDD_HIGH_POWER_BUFFER 0x1U /**< High power buffer mode enabled. */
#define VREF_PDD_LOW_POWER_BUFFER 0x2U /**< Low power buffer mode enabled. */
/* ----------------------------------------------------------------------------
-- EnableChopOscillator
---------------------------------------------------------------------------- */
/**
* @brief Enables chop oscillator.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Enables or disables chop oscillator. This parameter is of
* "Global enumeration used for specifying general enable/disable states
* (PDD_DISABLE and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_TRM.
* @par Example:
* @code
* VREF_PDD_EnableChopOscillator(<peripheral>_BASE_PTR, PDD_DISABLE);
* @endcode
*/
#define VREF_PDD_EnableChopOscillator(PeripheralBase, State) ( \
VREF_TRM_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_TRM_REG(PeripheralBase) & (uint8)(~(uint8)VREF_TRM_CHOPEN_MASK))) | ( \
(uint8)((uint8)(State) << VREF_TRM_CHOPEN_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- SetTrimValue
---------------------------------------------------------------------------- */
/**
* @brief Set trim value for voltage reference correction.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Trim value. This parameter is a 6-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_TRM.
* @par Example:
* @code
* VREF_PDD_SetTrimValue(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define VREF_PDD_SetTrimValue(PeripheralBase, Value) ( \
VREF_TRM_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_TRM_REG(PeripheralBase) & (uint8)(~(uint8)VREF_TRM_TRIM_MASK))) | ( \
(uint8)(Value))) \
)
/* ----------------------------------------------------------------------------
-- GetTrimValue
---------------------------------------------------------------------------- */
/**
* @brief Returns trim value for voltage reference correction.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 6-bit value. The value is cast to "uint8".
* @remarks The macro accesses the following registers: VREF_TRM.
* @par Example:
* @code
* uint8 result = VREF_PDD_GetTrimValue(<peripheral>_BASE_PTR);
* @endcode
*/
#define VREF_PDD_GetTrimValue(PeripheralBase) ( \
(uint8)(VREF_TRM_REG(PeripheralBase) & VREF_TRM_TRIM_MASK) \
)
/* ----------------------------------------------------------------------------
-- ReadTrimReg
---------------------------------------------------------------------------- */
/**
* @brief Reads trim register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: VREF_TRM.
* @par Example:
* @code
* uint8 result = VREF_PDD_ReadTrimReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define VREF_PDD_ReadTrimReg(PeripheralBase) ( \
VREF_TRM_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteTrimReg
---------------------------------------------------------------------------- */
/**
* @brief Writes new value specified by the Value parameter into trim register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the trim register. This parameter is a
* 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_TRM.
* @par Example:
* @code
* VREF_PDD_WriteTrimReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define VREF_PDD_WriteTrimReg(PeripheralBase, Value) ( \
VREF_TRM_REG(PeripheralBase) = \
(uint8)(Value) \
)
/* ----------------------------------------------------------------------------
-- EnableInternalVoltageReference
---------------------------------------------------------------------------- */
/**
* @brief Enables internal voltage reference.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Enables or disables internal voltage reference. This parameter
* is of "Global enumeration used for specifying general enable/disable
* states (PDD_DISABLE and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* VREF_PDD_EnableInternalVoltageReference(<peripheral>_BASE_PTR,
* PDD_DISABLE);
* @endcode
*/
#define VREF_PDD_EnableInternalVoltageReference(PeripheralBase, State) ( \
VREF_SC_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_SC_REG(PeripheralBase) & (uint8)(~(uint8)VREF_SC_VREFEN_MASK))) | ( \
(uint8)((uint8)(State) << VREF_SC_VREFEN_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- EnableRegulator
---------------------------------------------------------------------------- */
/**
* @brief Enables regulator.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Enables or disables regulator. This parameter is of "Global
* enumeration used for specifying general enable/disable states (PDD_DISABLE
* and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* VREF_PDD_EnableRegulator(<peripheral>_BASE_PTR, PDD_DISABLE);
* @endcode
*/
#define VREF_PDD_EnableRegulator(PeripheralBase, State) ( \
VREF_SC_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_SC_REG(PeripheralBase) & (uint8)(~(uint8)VREF_SC_REGEN_MASK))) | ( \
(uint8)((uint8)(State) << VREF_SC_REGEN_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- EnableSecondOrderCurvatureCompensation
---------------------------------------------------------------------------- */
/**
* @brief Enables second order curvature compensation.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param State Enables or disables second order curvature compensation. This
* parameter is of "Global enumeration used for specifying general
* enable/disable states (PDD_DISABLE and PDD_ENABLE defined in PDD_Types.h)" type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* VREF_PDD_EnableSecondOrderCurvatureCompensation(<peripheral>_BASE_PTR,
* PDD_DISABLE);
* @endcode
*/
#define VREF_PDD_EnableSecondOrderCurvatureCompensation(PeripheralBase, State) ( \
VREF_SC_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_SC_REG(PeripheralBase) & (uint8)(~(uint8)VREF_SC_ICOMPEN_MASK))) | ( \
(uint8)((uint8)(State) << VREF_SC_ICOMPEN_SHIFT))) \
)
/* ----------------------------------------------------------------------------
-- GetInternalVoltageReferenceState
---------------------------------------------------------------------------- */
/**
* @brief Returns state of the internal voltage reference.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a value of "Position of a parity bit" type. The value is cast
* to "uint8".
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* uint8 result =
* VREF_PDD_GetInternalVoltageReferenceState(<peripheral>_BASE_PTR);
* @endcode
*/
#define VREF_PDD_GetInternalVoltageReferenceState(PeripheralBase) ( \
(uint8)(VREF_SC_REG(PeripheralBase) & VREF_SC_VREFST_MASK) \
)
/* ----------------------------------------------------------------------------
-- SelectBufferMode
---------------------------------------------------------------------------- */
/**
* @brief Selects buffer mode.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Mode Type of the match operation. This parameter is of "Type of the
* buffer mode." type.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* VREF_PDD_SelectBufferMode(<peripheral>_BASE_PTR,
* VREF_PDD_BANDGAP_ON_ONLY);
* @endcode
*/
#define VREF_PDD_SelectBufferMode(PeripheralBase, Mode) ( \
VREF_SC_REG(PeripheralBase) = \
(uint8)(( \
(uint8)(VREF_SC_REG(PeripheralBase) & (uint8)(~(uint8)VREF_SC_MODE_LV_MASK))) | ( \
(uint8)(Mode))) \
)
/* ----------------------------------------------------------------------------
-- ReadStatusControlReg
---------------------------------------------------------------------------- */
/**
* @brief Reads status and control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @return Returns a 8-bit value.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* uint8 result = VREF_PDD_ReadStatusControlReg(<peripheral>_BASE_PTR);
* @endcode
*/
#define VREF_PDD_ReadStatusControlReg(PeripheralBase) ( \
VREF_SC_REG(PeripheralBase) \
)
/* ----------------------------------------------------------------------------
-- WriteStatusControlReg
---------------------------------------------------------------------------- */
/**
* @brief Writes new value specified by the Value parameter into status and
* control register.
* @param PeripheralBase Pointer to a peripheral registers structure (peripheral
* base address). You can use the constant defined in the registers
* definition header file (<peripheral>_BASE_PTR) or the constant defined in
* the peripheral initialization component header file
* (<component_name>_DEVICE).
* @param Value Value to be written to the status and control register. This
* parameter is a 8-bit value.
* @return Returns a value of void type.
* @remarks The macro accesses the following registers: VREF_SC.
* @par Example:
* @code
* VREF_PDD_WriteStatusControlReg(<peripheral>_BASE_PTR, 1);
* @endcode
*/
#define VREF_PDD_WriteStatusControlReg(PeripheralBase, Value) ( \
VREF_SC_REG(PeripheralBase) = \
(uint8)(Value) \
)
#endif /* #if defined(VREF_PDD_H_) */
/* VREF_PDD.h, eof. */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,556 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : CDC1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : FSL_USB_CDC_Device
** Version : Component 01.031, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
**
** Settings :
** Component name : CDC1
** CPU : Kinetis K20D72
** CDC Settings : Enabled
** .inf ClassGuid : 4D36E978-E325-11CE-BFC1-08002BE10318
** .inf VID : 2504
** .inf PID : 0300
** .inf PRVDR : Freescale
** .inf MFGNAME : My Company
** .inf DESCRIPTION : Freescale CDC Device
** .inf SERVICE : Virtual Com Driver
** Bus reported device : FSL CDC DEVICE
** Bus reported vendor : FREESCALE INC.
** Send Buffer : RingBuffer
** Receive Buffer : RingBuffer
** Use Timeout : Disabled
** Contents :
** ClearRxBuffer - void CDC1_ClearRxBuffer(void);
** ClearTxBuffer - void CDC1_ClearTxBuffer(void);
** GetFreeInTxBuf - word CDC1_GetFreeInTxBuf(void);
** GetCharsInTxBuf - word CDC1_GetCharsInTxBuf(void);
** GetCharsInRxBuf - word CDC1_GetCharsInRxBuf(void);
** GetChar - byte CDC1_GetChar(CDC1_TComData *Chr);
** RecvChar - byte CDC1_RecvChar(CDC1_TComData *Chr);
** SendChar - byte CDC1_SendChar(CDC1_TComData Chr);
** SendString - byte CDC1_SendString(CDC1_TComData *Chr);
** SendBlock - byte CDC1_SendBlock(byte *data, word dataSize);
** PutBufferChecked - byte CDC1_PutBufferChecked(byte *buf, size_t bufSize);
** App_Callback - void CDC1_App_Callback(byte controller_ID, byte event_type, void *val);
** Notify_Callback - void CDC1_Notify_Callback(byte controller_ID, byte event_type, void *val);
** App_Task - byte CDC1_App_Task(byte *txBuf, size_t txBufSize);
** Init - byte CDC1_Init(void);
**
** (c) Copyright Freescale, all rights reserved, 2013
** Ported as Processor Expert component: Erich Styger
** http: www.mcuoneclipse.com
** ###################################################################*/
/*!
** @file CDC1.c
** @version 01.00
** @brief
**
*/
/*!
** @addtogroup CDC1_module CDC1 module documentation
** @{
*/
/* MODULE CDC1. */
#include "CDC1.h"
#include "hidef.h" /* for EnableInterrupts; macro */
#include "hal/derivative.h" /* include peripheral declarations */
#include "usb_cdc.h" /* USB CDC Class Header File */
#include <stdio.h>
/* skip the inclusion in dependency state */
#ifndef __NO_SETJMP
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#define CONTROLLER_ID (0) /* ID to identify USB CONTROLLER */
#if HIGH_SPEED_DEVICE
static uint_32 g_cdcBuffer[DIC_BULK_OUT_ENDP_PACKET_SIZE>>1];
#endif
/* Virtual COM Application start Init Flag */
static volatile boolean start_app = FALSE;
/* Virtual COM Application Carrier Activate Flag */
static volatile boolean start_transactions = FALSE;
static volatile boolean transactionOngoing = FALSE;
/*
** ===================================================================
** Method : CDC1_GetFreeInTxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of free character in the send buffer
** Parameters : None
** Returns :
** --- - Number of free character in the receive
** buffer.
** ===================================================================
*/
/*
word CDC1_GetFreeInTxBuf(void)
{
*** Implemented as macro in the header file
}
*/
/*
** ===================================================================
** Method : CDC1_GetCharsInTxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of character in the send buffer
** Parameters : None
** Returns :
** --- - Number of character in the receive buffer.
** ===================================================================
*/
/*
word CDC1_GetCharsInTxBuf(void)
{
*** implemented as macro in the header file
return (word)Tx1_NofElements();
}
*/
/*
** ===================================================================
** Method : CDC1_GetCharsInRxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of character in the receive buffer
** Parameters : None
** Returns :
** --- - Number of character in the receive buffer.
** ===================================================================
*/
word CDC1_GetCharsInRxBuf(void)
{
static uint8 txBuf[CDC1_DATA_BUFF_SIZE];
if(CDC1_App_Task(txBuf, sizeof(txBuf))!=ERR_OK) { /* call USB handler: if active, then this will empty the buffer */
}
return (word)Rx1_NofElements();
}
/*
** ===================================================================
** Method : CDC1_GetChar (component FSL_USB_CDC_Device)
** Description :
** Receives a character from the USB interface. Function is not
** blocking if there is no character in the input buffer.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to where to store the character
** received
** Returns :
** --- - Error code, ERR_OK for success,
** ERR_RXEMPTY if nothing is in RX buffer.
** ===================================================================
*/
/**
byte CDC1_GetChar(CDC1_TComData *Chr)
{
*** implemented as macro in the header file
return Rx1_Get(Chr);
}
*/
/*
** ===================================================================
** Method : CDC1_RecvChar (component FSL_USB_CDC_Device)
** Description :
** Receives a character from the USB interface. Function is
** blocking if there is no character in the input buffer.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to where to store the character
** received
** Returns :
** --- - Error code, ERR_OK for success,
** ERR_RXEMPTY if nothing is in RX buffer.
** ===================================================================
*/
byte CDC1_RecvChar(CDC1_TComData *Chr)
{
while(Rx1_Get(Chr)!=ERR_OK) {
/* retry receiving until success */
}
return ERR_OK;
}
/*
** ===================================================================
** Method : CDC1_SendChar (component FSL_USB_CDC_Device)
** Description :
** Method to send a character to the USB interface. Method is
** non-blocking: If the output buffer is full, it tries to send
** it over USB. If this fails or buffer is still full, the
** character will be lost. If OnError() event is enabled, the
** error event will be called in case of error.
** Parameters :
** NAME - DESCRIPTION
** Chr - Character to send.
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
byte CDC1_SendChar(CDC1_TComData Chr)
{
static uint8 txBuf[CDC1_DATA_BUFF_SIZE];
if(Tx1_Put(Chr)==ERR_TXFULL) { /* retry once, otherwise throw it away */
if(CDC1_App_Task(txBuf, sizeof(txBuf))!=ERR_OK) { /* call USB handler: if active, then this will empty the buffer */
return ERR_TXFULL;
} else { /* retry, as USB App_Task() should have sent the buffer */
return Tx1_Put(Chr); /* retry. If buffer is still full, we will lose the character */
}
}
return ERR_OK;
}
/*
** ===================================================================
** Method : CDC1_SendBlock (component FSL_USB_CDC_Device)
** Description :
** Method to send a data block to the USB interface. Method is
** non-blocking: if data cannot be sent, it will be lost. If
** OnError() event is enabled, the error event will be called
** in case of error.
** Parameters :
** NAME - DESCRIPTION
** * data - Pointer to data to send.
** dataSize - Size of data in bytes
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
byte CDC1_SendBlock(byte *data, word dataSize)
{
byte res = ERR_OK;
while(dataSize > 0) {
if(CDC1_SendChar(*data)!=ERR_OK) {
res = ERR_TXFULL;
}
dataSize--; data++;
}
return res;
}
/*
** ===================================================================
** Method : CDC1_SendString (component FSL_USB_CDC_Device)
** Description :
** Method to send a string to the USB interface. Method is
** non-blocking: if string cannot be sent, it will be lost. If
** OnError() event is enabled, the error event will be called
** in case of error.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to string to send.
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
byte CDC1_SendString(CDC1_TComData *Chr)
{
byte res = ERR_OK;
while(*Chr != '\0') {
if(CDC1_SendChar(*Chr)!=ERR_OK) {
res = ERR_TXFULL;
}
Chr++;
}
return res;
}
/*
** ===================================================================
** Method : CDC1_App_Callback (component FSL_USB_CDC_Device)
** Description :
** Method to handle class callbacks from USB
** Parameters :
** NAME - DESCRIPTION
** controller_ID - controller ID
** event_type - value of the event
** val - gives the configuration value
** Returns : Nothing
** ===================================================================
*/
void CDC1_App_Callback(byte controller_ID, byte event_type, void *val)
{
UNUSED(controller_ID);
UNUSED(val);
if(event_type == USB_APP_BUS_RESET) {
start_app = FALSE;
} else if(event_type == USB_APP_ENUM_COMPLETE) {
#if HIGH_SPEED_DEVICE
/* prepare for the next receive event */
USB_Class_CDC_Interface_DIC_Recv_Data(&controller_ID,
(uint_8_ptr)g_cdcBuffer,
DIC_BULK_OUT_ENDP_PACKET_SIZE);
#endif
start_app = TRUE;
} else if((event_type == USB_APP_DATA_RECEIVED)&&(start_transactions==TRUE)) {
/* Copy Received Data buffer to Application Buffer */
USB_PACKET_SIZE BytesToBeCopied;
APP_DATA_STRUCT *dp_rcv = (APP_DATA_STRUCT*)val;
uint_8 index;
BytesToBeCopied = (USB_PACKET_SIZE)((dp_rcv->data_size > CDC1_DATA_BUFF_SIZE) ? CDC1_DATA_BUFF_SIZE:dp_rcv->data_size);
for(index = 0; index<BytesToBeCopied ; index++) {
if(Rx1_Put(dp_rcv->data_ptr[index])!=ERR_OK) {
/* Failed to put byte into buffer. Is the buffer to small? Then increase the Rx buffer.
Otherwise not much we could do here, so we are loosing byte here.
*/
/* Enable OnError() event so this event will be called here */
}
}
(void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0); /* see http://eprints.utar.edu.my/143/1/BI-2011-0708672-1.pdf, page 131 */
} else if((event_type == USB_APP_SEND_COMPLETE)&&(start_transactions==TRUE)) {
transactionOngoing = FALSE;
/* Previous Send is complete. Queue next receive */
#if HIGH_SPEED_DEVICE
//(void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, g_cdcBuffer, 0);
#else
(void)USB_Class_CDC_Interface_DIC_Recv_Data(CONTROLLER_ID, NULL, 0);
#endif
} else if(event_type == USB_APP_ERROR) { /* detach? */
start_app = FALSE;
start_transactions = FALSE;
}
}
/*
** ===================================================================
** Method : CDC1_Notify_Callback (component FSL_USB_CDC_Device)
** Description :
** Method to handle PSTN Sub Class callbacks
** Parameters :
** NAME - DESCRIPTION
** controller_ID - controller ID
** event_type - value of the event
** val -
** Returns : Nothing
** ===================================================================
*/
void CDC1_Notify_Callback(byte controller_ID, byte event_type, void *val)
{
UNUSED(controller_ID);
UNUSED(val);
if(start_app == TRUE) {
if(event_type == USB_APP_CDC_CARRIER_ACTIVATED) {
start_transactions = TRUE;
} else if(event_type == USB_APP_CDC_CARRIER_DEACTIVATED) {
start_transactions = FALSE;
}
}
start_transactions = TRUE; /* ??? see http://forums.freescale.com/t5/Freescale-MQX-trade-USB-Host/Cant-get-CDC-virtual-com-demo-to-work-with-VB2005-on-xp-sp3/m-p/92713#M302 */
}
/*
** ===================================================================
** Method : CDC1_RunUsbEngine (component FSL_USB_CDC_Device)
**
** Description :
** Runs the USB polling engine
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void CDC1_RunUsbEngine(void)
{
/* not needed */
}
/*
** ===================================================================
** Method : CDC1_SendDataBlock (component FSL_USB_CDC_Device)
**
** Description :
** Sends a USB data block
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
byte CDC1_SendDataBlock(byte *data, word dataSize)
{
uint8 res = ERR_OK;
transactionOngoing = TRUE;
if(USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, data, dataSize)!=USB_OK) {
transactionOngoing = FALSE;
return ERR_FAULT;
}
/* wait for transaction finish */
while(transactionOngoing) { /* wait until transaction is finished */
CDC1_RunUsbEngine();
}
return res;
}
/*
** ===================================================================
** Method : CDC1_App_Task (component FSL_USB_CDC_Device)
** Description :
** Application task to be called periodically from the main
** task.
** Parameters :
** NAME - DESCRIPTION
** * txBuf - Pointer to temporary buffer used to
** transmit data over USB. Should be equal or
** greater than the endpoint buffer size. Data
** will be sent in an asynchronous way, so
** make sure the buffer is *not* on the stack.
** This buffer must be available until the
** next transmission.
** txBufSize - Size of the buffer in bytes
** Returns :
** --- - Error code, returns ERR_OK if USB
** enumeration has been finished, error code
** otherwise.
** ===================================================================
*/
byte CDC1_App_Task(byte *txBuf, size_t txBufSize)
{
uint8 i, res;
/* device is Kinetis K20D72 */
CDC1_RunUsbEngine();
/* call the periodic task function */
USB_Class_CDC_Periodic_Task();
/* check whether enumeration is complete or not */
if((start_app==TRUE) && (start_transactions==TRUE)) {
if(Tx1_NofElements()!=0) {
i = 0;
while(i<txBufSize && Tx1_Get(&txBuf[i])==ERR_OK) {
i++;
}
res = CDC1_SendDataBlock(txBuf, i);
if(res!=ERR_OK) {
return res;
}
#if 0 /* workaround for problem in USB stack v3.1.1: if last block is 8, 16, 32, 40, 48, ... bytes, it does not get out until the next transfer? */
if((i%8)==0) {
/* workaround: sending a dummy block of zero bytes */
res = CDC1_SendDataBlock(txBuf, 0);
if(res!=ERR_OK) {
return res;
}
}
#endif
} /* if */
return ERR_OK;
} else {
return ERR_BUSOFF; /* USB bus not available yet */
}
}
/*
** ===================================================================
** Method : CDC1_Init (component FSL_USB_CDC_Device)
** Description :
** Initializes the driver
** Parameters : None
** Returns :
** --- - Error code
** ===================================================================
*/
byte CDC1_Init(void)
{
uint_8 err;
err = USB_Class_CDC_Init(CONTROLLER_ID, CDC1_App_Callback, NULL, CDC1_Notify_Callback, TRUE);
if(err != USB_OK) {
/* Error initializing USB-CDC Class */
return ERR_FAILED;
}
return ERR_OK;
}
/*
** ===================================================================
** Method : CDC1_PutBufferChecked (component FSL_USB_CDC_Device)
** Description :
** Puts a data block into the output buffer, but does not send
** it. If there is not enough size available, then ERR_TXFULL
** is returned, otherwise ERR_OK. The application then needs to
** call USB_App_Callback() to actually send the buffer.
** Parameters :
** NAME - DESCRIPTION
** * buf - Pointer to buffer to be sent
** bufsize - Buffer size in bytes
** Returns :
** --- - Error code
** ===================================================================
*/
byte CDC1_PutBufferChecked(byte *buf, size_t bufSize)
{
byte res;
if(bufSize>CDC1_GetFreeInTxBuf()) { /* no room at the Inn... */
res = ERR_TXFULL;
} else {
res = ERR_OK;
while(bufSize>0 && res==ERR_OK) {
res = Tx1_Put(*buf);
bufSize--;
buf++;
}
}
return res;
}
/*
** ===================================================================
** Method : CDC1_ClearRxBuffer (component FSL_USB_CDC_Device)
** Description :
** Clears the receiver buffer content
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/**
void CDC1_ClearRxBuffer(void)
{
Implemented as macro in the header file
}
*/
/*
** ===================================================================
** Method : CDC1_ClearTxBuffer (component FSL_USB_CDC_Device)
** Description :
** Clears the transmit buffer content
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/**
void CDC1_ClearTxBuffer(void)
{
Implemented as macro in the header file
}
*/
/* END CDC1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,379 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : CDC1.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : FSL_USB_CDC_Device
** Version : Component 01.031, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
**
** Settings :
** Component name : CDC1
** CPU : Kinetis K20D72
** CDC Settings : Enabled
** .inf ClassGuid : 4D36E978-E325-11CE-BFC1-08002BE10318
** .inf VID : 2504
** .inf PID : 0300
** .inf PRVDR : Freescale
** .inf MFGNAME : My Company
** .inf DESCRIPTION : Freescale CDC Device
** .inf SERVICE : Virtual Com Driver
** Bus reported device : FSL CDC DEVICE
** Bus reported vendor : FREESCALE INC.
** Send Buffer : RingBuffer
** Receive Buffer : RingBuffer
** Use Timeout : Disabled
** Contents :
** ClearRxBuffer - void CDC1_ClearRxBuffer(void);
** ClearTxBuffer - void CDC1_ClearTxBuffer(void);
** GetFreeInTxBuf - word CDC1_GetFreeInTxBuf(void);
** GetCharsInTxBuf - word CDC1_GetCharsInTxBuf(void);
** GetCharsInRxBuf - word CDC1_GetCharsInRxBuf(void);
** GetChar - byte CDC1_GetChar(CDC1_TComData *Chr);
** RecvChar - byte CDC1_RecvChar(CDC1_TComData *Chr);
** SendChar - byte CDC1_SendChar(CDC1_TComData Chr);
** SendString - byte CDC1_SendString(CDC1_TComData *Chr);
** SendBlock - byte CDC1_SendBlock(byte *data, word dataSize);
** PutBufferChecked - byte CDC1_PutBufferChecked(byte *buf, size_t bufSize);
** App_Callback - void CDC1_App_Callback(byte controller_ID, byte event_type, void *val);
** Notify_Callback - void CDC1_Notify_Callback(byte controller_ID, byte event_type, void *val);
** App_Task - byte CDC1_App_Task(byte *txBuf, size_t txBufSize);
** Init - byte CDC1_Init(void);
**
** (c) Copyright Freescale, all rights reserved, 2013
** Ported as Processor Expert component: Erich Styger
** http: www.mcuoneclipse.com
** ###################################################################*/
/*!
** @file CDC1.h
** @version 01.00
** @brief
**
*/
/*!
** @addtogroup CDC1_module CDC1 module documentation
** @{
*/
#ifndef __CDC1_H
#define __CDC1_H
/* MODULE CDC1. */
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
#include "MK20D10.h"
/* Include inherited beans */
#include "Tx1.h"
#include "Rx1.h"
#include <stddef.h> /* for size_t */
//#include "Cpu.h"
#ifndef __BWUserType_CDC1_TComData
#define __BWUserType_CDC1_TComData
typedef byte CDC1_TComData ; /* User type for communication data type. */
#endif
/*
DATA_BUFF_SIZE should be greater than or equal to the endpoint buffer size,
otherwise there will be data loss. For MC9S08JS16, maximum DATA_BUFF_SIZE
supported is 16 Bytes
*/
#define CDC1_DATA_BUFF_SIZE 64
#define CDC1_USB_ERR_SEND 1 /* Error while sending */
#define CDC1_USB_ERR_BUSOFF 2 /* Bus not ready */
#define CDC1_USB_ERR_INIT 3 /* USB initialization error */
#define CDC1_USB_ERR_TX_CHAR 4 /* Error sending character */
#define CDC1_USB_ERR_TX_STRING 5 /* Error sending string */
#define CDC1_USB_ERR_CHECKED_TXFULL 6 /* Error during sending a checked block */
#define CDC1_USB_ERR_RECEIVE 7 /* Error while starting an receive transaction */
#define CDC1_USB_ERR_RX_PUT 8 /* Error while putting RX byte into buffer */
#define CDC1_USB_ERR_TX_BLOCK 9 /* Error sending data block */
#define CDC1_USB_TIMEOUT_SEND 10 /* Timeout while sending */
#define CDC1_GetFreeInTxBuf() \
Tx1_NofFreeElements()
/*
** ===================================================================
** Method : CDC1_GetFreeInTxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of free character in the send buffer
** Parameters : None
** Returns :
** --- - Number of free character in the receive
** buffer.
** ===================================================================
*/
byte CDC1_RecvChar(CDC1_TComData *Chr);
/*
** ===================================================================
** Method : CDC1_RecvChar (component FSL_USB_CDC_Device)
** Description :
** Receives a character from the USB interface. Function is
** blocking if there is no character in the input buffer.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to where to store the character
** received
** Returns :
** --- - Error code, ERR_OK for success,
** ERR_RXEMPTY if nothing is in RX buffer.
** ===================================================================
*/
byte CDC1_SendChar(CDC1_TComData Chr);
/*
** ===================================================================
** Method : CDC1_SendChar (component FSL_USB_CDC_Device)
** Description :
** Method to send a character to the USB interface. Method is
** non-blocking: If the output buffer is full, it tries to send
** it over USB. If this fails or buffer is still full, the
** character will be lost. If OnError() event is enabled, the
** error event will be called in case of error.
** Parameters :
** NAME - DESCRIPTION
** Chr - Character to send.
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
#define CDC1_GetCharsInTxBuf() \
Tx1_NofElements()
/*
** ===================================================================
** Method : CDC1_GetCharsInTxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of character in the send buffer
** Parameters : None
** Returns :
** --- - Number of character in the receive buffer.
** ===================================================================
*/
word CDC1_GetCharsInRxBuf(void);
/*
** ===================================================================
** Method : CDC1_GetCharsInRxBuf (component FSL_USB_CDC_Device)
** Description :
** Returns the number of character in the receive buffer
** Parameters : None
** Returns :
** --- - Number of character in the receive buffer.
** ===================================================================
*/
byte CDC1_Init(void);
/*
** ===================================================================
** Method : CDC1_Init (component FSL_USB_CDC_Device)
** Description :
** Initializes the driver
** Parameters : None
** Returns :
** --- - Error code
** ===================================================================
*/
byte CDC1_App_Task(byte *txBuf, size_t txBufSize);
/*
** ===================================================================
** Method : CDC1_App_Task (component FSL_USB_CDC_Device)
** Description :
** Application task to be called periodically from the main
** task.
** Parameters :
** NAME - DESCRIPTION
** * txBuf - Pointer to temporary buffer used to
** transmit data over USB. Should be equal or
** greater than the endpoint buffer size. Data
** will be sent in an asynchronous way, so
** make sure the buffer is *not* on the stack.
** This buffer must be available until the
** next transmission.
** txBufSize - Size of the buffer in bytes
** Returns :
** --- - Error code, returns ERR_OK if USB
** enumeration has been finished, error code
** otherwise.
** ===================================================================
*/
byte CDC1_SendString(CDC1_TComData *Chr);
/*
** ===================================================================
** Method : CDC1_SendString (component FSL_USB_CDC_Device)
** Description :
** Method to send a string to the USB interface. Method is
** non-blocking: if string cannot be sent, it will be lost. If
** OnError() event is enabled, the error event will be called
** in case of error.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to string to send.
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
#define CDC1_GetChar(Chr) \
Rx1_Get(Chr)
/*
** ===================================================================
** Method : CDC1_GetChar (component FSL_USB_CDC_Device)
** Description :
** Receives a character from the USB interface. Function is not
** blocking if there is no character in the input buffer.
** Parameters :
** NAME - DESCRIPTION
** * Chr - Pointer to where to store the character
** received
** Returns :
** --- - Error code, ERR_OK for success,
** ERR_RXEMPTY if nothing is in RX buffer.
** ===================================================================
*/
byte CDC1_PutBufferChecked(byte *buf, size_t bufSize);
/*
** ===================================================================
** Method : CDC1_PutBufferChecked (component FSL_USB_CDC_Device)
** Description :
** Puts a data block into the output buffer, but does not send
** it. If there is not enough size available, then ERR_TXFULL
** is returned, otherwise ERR_OK. The application then needs to
** call USB_App_Callback() to actually send the buffer.
** Parameters :
** NAME - DESCRIPTION
** * buf - Pointer to buffer to be sent
** bufsize - Buffer size in bytes
** Returns :
** --- - Error code
** ===================================================================
*/
void CDC1_App_Callback(byte controller_ID, byte event_type, void *val);
/*
** ===================================================================
** Method : CDC1_App_Callback (component FSL_USB_CDC_Device)
** Description :
** Method to handle class callbacks from USB
** Parameters :
** NAME - DESCRIPTION
** controller_ID - controller ID
** event_type - value of the event
** val - gives the configuration value
** Returns : Nothing
** ===================================================================
*/
void CDC1_Notify_Callback(byte controller_ID, byte event_type, void *val);
/*
** ===================================================================
** Method : CDC1_Notify_Callback (component FSL_USB_CDC_Device)
** Description :
** Method to handle PSTN Sub Class callbacks
** Parameters :
** NAME - DESCRIPTION
** controller_ID - controller ID
** event_type - value of the event
** val -
** Returns : Nothing
** ===================================================================
*/
#define CDC1_ClearRxBuffer() \
Rx1_Clear()
/*
** ===================================================================
** Method : CDC1_ClearRxBuffer (component FSL_USB_CDC_Device)
** Description :
** Clears the receiver buffer content
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
#define CDC1_ClearTxBuffer() \
Tx1_Clear()
/*
** ===================================================================
** Method : CDC1_ClearTxBuffer (component FSL_USB_CDC_Device)
** Description :
** Clears the transmit buffer content
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void CDC1_RunUsbEngine(void);
/*
** ===================================================================
** Method : CDC1_RunUsbEngine (component FSL_USB_CDC_Device)
**
** Description :
** Runs the USB polling engine
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
byte CDC1_SendBlock(byte *data, word dataSize);
/*
** ===================================================================
** Method : CDC1_SendBlock (component FSL_USB_CDC_Device)
** Description :
** Method to send a data block to the USB interface. Method is
** non-blocking: if data cannot be sent, it will be lost. If
** OnError() event is enabled, the error event will be called
** in case of error.
** Parameters :
** NAME - DESCRIPTION
** * data - Pointer to data to send.
** dataSize - Size of data in bytes
** Returns :
** --- - Error code. ERR_OK for success and
** ERR_FAILED otherwise.
** ===================================================================
*/
byte CDC1_SendDataBlock(byte *data, word dataSize);
/*
** ===================================================================
** Method : CDC1_SendDataBlock (component FSL_USB_CDC_Device)
**
** Description :
** Sends a USB data block
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/* END CDC1. */
#endif
/* ifndef __CDC1_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,103 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : CS1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : CriticalSection
** Version : Component 01.006, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
**
** Settings :
**
** Contents :
** CriticalVariable - void CS1_CriticalVariable(void);
** EnterCritical - void CS1_EnterCritical(void);
** ExitCritical - void CS1_ExitCritical(void);
**
** License : Open Source (LGPL)
** Copyright : Erich Styger, 2014, all rights reserved.
** Web : www.mcuoneclipse.com
** This an open source software implementing a driver using Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file CS1.c
** @version 01.00
** @brief
**
*/
/*!
** @addtogroup CS1_module CS1 module documentation
** @{
*/
/* MODULE CS1. */
#include "CS1.h"
/*
** ===================================================================
** Method : CS1_CriticalVariable (component CriticalSection)
** Description :
** Defines a variable if necessary. This is a macro.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void CS1_CriticalVariable(void)
{
*** Implemented as macro in the header file CS1.h
}
*/
/*
** ===================================================================
** Method : CS1_EnterCritical (component CriticalSection)
** Description :
** Enters a critical section
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void CS1_EnterCritical(void)
{
*** Implemented as macro in the header file CS1.h
}
*/
/*
** ===================================================================
** Method : CS1_ExitCritical (component CriticalSection)
** Description :
** Exits a critical section
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/*
void CS1_ExitCritical(void)
{
*** Implemented as macro in the header file CS1.h
}
*/
/* END CS1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,126 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : CS1.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : CriticalSection
** Version : Component 01.006, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
**
** Settings :
**
** Contents :
** CriticalVariable - void CS1_CriticalVariable(void);
** EnterCritical - void CS1_EnterCritical(void);
** ExitCritical - void CS1_ExitCritical(void);
**
** License : Open Source (LGPL)
** Copyright : Erich Styger, 2014, all rights reserved.
** Web : www.mcuoneclipse.com
** This an open source software implementing a driver using Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file CS1.h
** @version 01.00
** @brief
**
*/
/*!
** @addtogroup CS1_module CS1 module documentation
** @{
*/
#ifndef __CS1_H
#define __CS1_H
/* MODULE CS1. */
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
/* Include inherited beans */
//#include "Cpu.h"
/* workaround macros for wrong EnterCritical()/ExitCritical() in the low level drivers. Will be removed once PEx is fixed */
#define CS1_CriticalVariableDrv() \
CS1_CriticalVariable()
#define CS1_EnterCriticalDrv() \
CS1_EnterCritical()
#define CS1_ExitCriticalDrv() \
CS1_ExitCritical()
#define CS1_CriticalVariable() \
uint8 cpuSR; /* variable to store current status */
/*
** ===================================================================
** Method : CS1_CriticalVariable (component CriticalSection)
** Description :
** Defines a variable if necessary. This is a macro.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
#define CS1_EnterCritical() \
do { \
asm ( \
"MRS R0, PRIMASK\n\t" \
"CPSID I\n\t" \
"STRB R0, %[output]" \
: [output] "=m" (cpuSR) :: "r0"); \
} while(0)
/*
** ===================================================================
** Method : CS1_EnterCritical (component CriticalSection)
** Description :
** Enters a critical section
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
#define CS1_ExitCritical() \
do{ \
asm ( \
"ldrb r0, %[input]\n\t" \
"msr PRIMASK,r0;\n\t" \
::[input] "m" (cpuSR) : "r0"); \
} while(0)
/*
** ===================================================================
** Method : CS1_ExitCritical (component CriticalSection)
** Description :
** Exits a critical section
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/* END CS1. */
#endif
/* ifndef __CS1_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,12 @@
/******************************************************************************
* Configuration file for the FSL USB stack created with Processor Expert.
*****************************************************************************/
#ifndef __FSL_USB_STACK_CONFIG_
#define __FSL_USB_STACK_CONFIG_
/* Overwrite initialization values from Processor Expert Init() component. These are 'known working values'.
* Otherwise you have to setup the bits (e.g. Pull-up/pull-down resistors!
* */
#define USB_USER_CONFIG_USE_STACK_INIT 1 /* value set by component property 'Use USB Stack Initialization' */
#endif /* __FSL_USB_STACK_CONFIG_ */

View File

@@ -0,0 +1,96 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : PE_Const.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : PE_Const
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component "PE_Const" contains internal definitions
** of the constants.
** Settings :
** Contents :
** No public methods
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file PE_Const.h
** @version 01.00
** @brief
** This component "PE_Const" contains internal definitions
** of the constants.
*/
/*!
** @addtogroup PE_Const_module PE_Const module documentation
** @{
*/
#ifndef __PE_Const_H
#define __PE_Const_H
/* Reset cause constants */
#define RSTSRC_WAKEUP 0x01U /*!< LLWU module wakeup reset */
#define RSTSRC_LVD 0x02U /*!< Low-voltage detect reset */
#define RSTSRC_LOC 0x04U /*!< Loss-of-clock reset */
#define RSTSRC_LOL 0x08U /*!< Loss-of-lock reset */
#define RSTSRC_COP 0x20U /*!< Watchdog reset */
#define RSTSRC_WDOG 0x20U /*!< Watchdog reset */
#define RSTSRC_PIN 0x40U /*!< External pin reset */
#define RSTSRC_POR 0x80U /*!< Power-on reset */
#define RSTSRC_JTAG 0x0100U /*!< JTAG reset pin */
#define RSTSRC_LOCKUP 0x0200U /*!< Core Lock-up reset */
#define RSTSRC_SW 0x0400U /*!< Software reset */
#define RSTSRC_MDM_AP 0x0800U /*!< Reset caused by host debugger system */
#define RSTSRC_EZPT 0x1000U /*!< EzPort reset */
#define RSTSRC_SACKERR 0x2000U /*!< Stop Mode Acknowledge Error Reset */
/* Low voltage interrupt cause constants */
#define LVDSRC_LVD 0x01U /*!< Low voltage detect */
#define LVDSRC_LVW 0x02U /*!< Low-voltage warning */
#endif /* _PE_Const_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,128 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : PE_Error.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : PE_Error
** Version : Driver 01.00
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component "PE_Error" contains internal definitions
** of the error constants.
** Contents :
** No public methods
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file PE_Error.h
** @version 01.00
** @brief
** This component "PE_Error" contains internal definitions
** of the error constants.
*/
/*!
** @addtogroup PE_Error_module PE_Error module documentation
** @{
*/
#ifndef __PE_Error_H
#define __PE_Error_H
#define ERR_OK 0x00U /*!< OK */
#define ERR_SPEED 0x01U /*!< This device does not work in the active speed mode. */
#define ERR_RANGE 0x02U /*!< Parameter out of range. */
#define ERR_VALUE 0x03U /*!< Parameter of incorrect value. */
#define ERR_OVERFLOW 0x04U /*!< Timer overflow. */
#define ERR_MATH 0x05U /*!< Overflow during evaluation. */
#define ERR_ENABLED 0x06U /*!< Device is enabled. */
#define ERR_DISABLED 0x07U /*!< Device is disabled. */
#define ERR_BUSY 0x08U /*!< Device is busy. */
#define ERR_NOTAVAIL 0x09U /*!< Requested value or method not available. */
#define ERR_RXEMPTY 0x0AU /*!< No data in receiver. */
#define ERR_TXFULL 0x0BU /*!< Transmitter is full. */
#define ERR_BUSOFF 0x0CU /*!< Bus not available. */
#define ERR_OVERRUN 0x0DU /*!< Overrun error is detected. */
#define ERR_FRAMING 0x0EU /*!< Framing error is detected. */
#define ERR_PARITY 0x0FU /*!< Parity error is detected. */
#define ERR_NOISE 0x10U /*!< Noise error is detected. */
#define ERR_IDLE 0x11U /*!< Idle error is detected. */
#define ERR_FAULT 0x12U /*!< Fault error is detected. */
#define ERR_BREAK 0x13U /*!< Break char is received during communication. */
#define ERR_CRC 0x14U /*!< CRC error is detected. */
#define ERR_ARBITR 0x15U /*!< A node losts arbitration. This error occurs if two nodes start transmission at the same time. */
#define ERR_PROTECT 0x16U /*!< Protection error is detected. */
#define ERR_UNDERFLOW 0x17U /*!< Underflow error is detected. */
#define ERR_UNDERRUN 0x18U /*!< Underrun error is detected. */
#define ERR_COMMON 0x19U /*!< Common error of a device. */
#define ERR_LINSYNC 0x1AU /*!< LIN synchronization error is detected. */
#define ERR_FAILED 0x1BU /*!< Requested functionality or process failed. */
#define ERR_QFULL 0x1CU /*!< Queue is full. */
#define ERR_PARAM_MASK 0x80U /*!< Invalid mask. */
#define ERR_PARAM_MODE 0x81U /*!< Invalid mode. */
#define ERR_PARAM_INDEX 0x82U /*!< Invalid index. */
#define ERR_PARAM_DATA 0x83U /*!< Invalid data. */
#define ERR_PARAM_SIZE 0x84U /*!< Invalid size. */
#define ERR_PARAM_VALUE 0x85U /*!< Invalid value. */
#define ERR_PARAM_RANGE 0x86U /*!< Invalid parameter's range or parameters' combination. */
#define ERR_PARAM_LOW_VALUE 0x87U /*!< Invalid value (LOW part). */
#define ERR_PARAM_HIGH_VALUE 0x88U /*!< Invalid value (HIGH part). */
#define ERR_PARAM_ADDRESS 0x89U /*!< Invalid address. */
#define ERR_PARAM_PARITY 0x8AU /*!< Invalid parity. */
#define ERR_PARAM_WIDTH 0x8BU /*!< Invalid width. */
#define ERR_PARAM_LENGTH 0x8CU /*!< Invalid length. */
#define ERR_PARAM_ADDRESS_TYPE 0x8DU /*!< Invalid address type. */
#define ERR_PARAM_COMMAND_TYPE 0x8EU /*!< Invalid command type. */
#define ERR_PARAM_COMMAND 0x8FU /*!< Invalid command. */
#define ERR_PARAM_RECIPIENT 0x90U /*!< Invalid recipient. */
#define ERR_PARAM_BUFFER_COUNT 0x91U /*!< Invalid buffer count. */
#define ERR_PARAM_ID 0x92U /*!< Invalid ID. */
#define ERR_PARAM_GROUP 0x93U /*!< Invalid group. */
#define ERR_PARAM_CHIP_SELECT 0x94U /*!< Invalid chip select. */
#define ERR_PARAM_ATTRIBUTE_SET 0x95U /*!< Invalid set of attributes. */
#define ERR_PARAM_SAMPLE_COUNT 0x96U /*!< Invalid sample count. */
#define ERR_PARAM_CONDITION 0x97U /*!< Invalid condition. */
#define ERR_PARAM_TICKS 0x98U /*!< Invalid ticks parameter. */
#endif /* __PE_Error_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
/* ################################################################### */
/*##
/*## This component module is generated by Processor Expert. Do not modify it. */
/*## */
/*## Filename : ProcessorExpert.ld */
/*## */
/*## Project : Landungsbruecke_KDS_v2.0.0 */
/*## */
/*## Processor : MK20DN512VLL10 */
/*## */
/*## Compiler : GNU C Compiler */
/*## */
/*## Date/Time : 2015-01-09, 16:27, # CodeGen: 0 */
/*## */
/*## Abstract : */
/*## */
/*## This file is used by the linker. It describes files to be linked, */
/*## memory ranges, stack size, etc. For detailed description about linker */
/*## command files see compiler documentation. This file is generated by default. */
/*## You can switch off generation by setting the property "Generate linker file = no" */
/*## in the "Build options" tab of the CPU component and then modify this file as needed. */
/*##
/*## */
/*## ###################################################################*/
/* Entry Point */
ENTRY(__thumb_startup)
/* Highest address of the user mode stack */
_estack = 0x20000000; /* end of m_data */
__SP_INIT = _estack;
/* Generate a link error if heap and stack don't fit into RAM */
__heap_size = 0x00; /* required amount of heap */
__stack_size = 0x0400; /* required amount of stack */
MEMORY {
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x000001E0
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_20000000 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
m_cfmprotrom (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into INTERNAL_FLASH */
.interrupts :
{
__vector_table = .;
. = ALIGN(4);
KEEP(*(.vectortable)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
.cfmprotect :
{
. = ALIGN(4);
KEEP(*(.cfmconfig)) /* Flash Configuration Field (FCF) */
. = ALIGN(4);
} > m_cfmprotrom
/* The program code and other data goes into INTERNAL_FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > m_text
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > m_text
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
___ROM_AT = .;
} > m_text
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT(___ROM_AT)
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} > m_data
___data_size = _edata - _sdata;
___m_data_20000000_ROMStart = ___ROM_AT + SIZEOF(.data);
.m_data_20000000 : AT(___m_data_20000000_ROMStart)
{
. = ALIGN(4);
___m_data_20000000_RAMStart = .;
*(.m_data_20000000) /* This is an User defined section */
___m_data_20000000_RAMEnd = .;
. = ALIGN(4);
} > m_data_20000000
___m_data_20000000_ROMSize = ___m_data_20000000_RAMEnd - ___m_data_20000000_RAMStart;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
__START_BSS = .;
PROVIDE ( __bss_start__ = __START_BSS );
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__END_BSS = .;
PROVIDE ( __bss_end__ = __END_BSS );
} > m_data
_romp_at = ___ROM_AT + SIZEOF(.data) +SIZEOF(.m_data_20000000);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(___ROM_AT);
LONG(_sdata);
LONG(___data_size);
LONG(___m_data_20000000_ROMStart);
LONG(___m_data_20000000_RAMStart);
LONG(___m_data_20000000_ROMSize);
LONG(0);
LONG(0);
LONG(0);
} > m_data
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
__heap_addr = .;
__HeapBase = .;
. = . + __heap_size;
__HeapLimit = .;
. = . + __stack_size;
. = ALIGN(4);
} > m_data
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@@ -0,0 +1,202 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Rx1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : RingBuffer
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a ring buffer for different integer data type.
** Settings :
** Component name : Rx1
** Buffer Size : 1
** Contents :
** Clear - void Rx1_Clear(void);
** Put - byte Rx1_Put(Rx1_ElementType elem);
** Get - byte Rx1_Get(Rx1_ElementType *elemP);
** NofElements - Rx1_BufSizeType Rx1_NofElements(void);
** NofFreeElements - Rx1_BufSizeType Rx1_NofFreeElements(void);
** Init - void Rx1_Init(void);
**
** License : Open Source (LGPL)
** Copyright : (c) Copyright Erich Styger, 2014, all rights reserved.
** Web: http://www.mcuoneclipse.com
** This an open source software of an embedded component for Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file Rx1.c
** @version 01.00
** @brief
** This component implements a ring buffer for different integer data type.
*/
/*!
** @addtogroup Rx1_module Rx1 module documentation
** @{
*/
/* MODULE Rx1. */
#include "Rx1.h"
#if Rx1_IS_REENTRANT
#define Rx1_DEFINE_CRITICAL() CS1_CriticalVariable()
#define Rx1_ENTER_CRITICAL() CS1_EnterCritical()
#define Rx1_EXIT_CRITICAL() CS1_ExitCritical()
#else
#define Rx1_DEFINE_CRITICAL() /* nothing */
#define Rx1_ENTER_CRITICAL() /* nothing */
#define Rx1_EXIT_CRITICAL() /* nothing */
#endif
static Rx1_ElementType Rx1_buffer[Rx1_BUF_SIZE]; /* ring buffer */
static Rx1_BufSizeType Rx1_inIdx; /* input index */
static Rx1_BufSizeType Rx1_outIdx; /* output index */
static Rx1_BufSizeType Rx1_inSize; /* size data in buffer */
/*
** ===================================================================
** Method : Rx1_Put (component RingBuffer)
** Description :
** Puts a new element into the buffer
** Parameters :
** NAME - DESCRIPTION
** elem - New element to be put into the buffer
** Returns :
** --- - Error code
** ===================================================================
*/
byte Rx1_Put(Rx1_ElementType elem)
{
byte res = ERR_OK;
Rx1_DEFINE_CRITICAL();
Rx1_ENTER_CRITICAL();
if(Rx1_inSize==Rx1_BUF_SIZE) {
res = ERR_TXFULL;
} else {
Rx1_buffer[Rx1_inIdx] = elem;
Rx1_inSize++;
Rx1_inIdx++;
if(Rx1_inIdx==Rx1_BUF_SIZE) {
Rx1_inIdx = 0;
}
}
Rx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Rx1_Get (component RingBuffer)
** Description :
** Removes an element from the buffer
** Parameters :
** NAME - DESCRIPTION
** * elemP - Pointer to where to store the received
** element
** Returns :
** --- - Error code
** ===================================================================
*/
byte Rx1_Get(Rx1_ElementType *elemP)
{
byte res = ERR_OK;
Rx1_DEFINE_CRITICAL();
Rx1_ENTER_CRITICAL();
if(Rx1_inSize==0) {
res = ERR_RXEMPTY;
} else {
*elemP = Rx1_buffer[Rx1_outIdx];
Rx1_inSize--;
Rx1_outIdx++;
if(Rx1_outIdx==Rx1_BUF_SIZE) {
Rx1_outIdx = 0;
}
}
Rx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Rx1_NofElements (component RingBuffer)
** Description :
** Returns the actual number of elements in the buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Rx1_BufSizeType Rx1_NofElements(void)
{
return Rx1_inSize;
}
/*
** ===================================================================
** Method : Rx1_NofFreeElements (component RingBuffer)
** Description :
** Returns the actual number of free elements/space in the
** buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Rx1_BufSizeType Rx1_NofFreeElements(void)
{
return (Rx1_BufSizeType)(Rx1_BUF_SIZE-Rx1_inSize);
}
/*
** ===================================================================
** Method : Rx1_Init (component RingBuffer)
** Description :
** Initializes the data structure
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Rx1_Init(void)
{
Rx1_inIdx = 0;
Rx1_outIdx = 0;
Rx1_inSize = 0;
}
/*
** ===================================================================
** Method : Rx1_Clear (component RingBuffer)
** Description :
** Clear (empty) the ring buffer.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Rx1_Clear(void)
{
Rx1_DEFINE_CRITICAL();
Rx1_ENTER_CRITICAL();
Rx1_Init();
Rx1_EXIT_CRITICAL();
}
/* END Rx1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,167 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Rx1.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : RingBuffer
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a ring buffer for different integer data type.
** Settings :
** Component name : Rx1
** Buffer Size : 1
** Contents :
** Clear - void Rx1_Clear(void);
** Put - byte Rx1_Put(Rx1_ElementType elem);
** Get - byte Rx1_Get(Rx1_ElementType *elemP);
** NofElements - Rx1_BufSizeType Rx1_NofElements(void);
** NofFreeElements - Rx1_BufSizeType Rx1_NofFreeElements(void);
** Init - void Rx1_Init(void);
**
** License : Open Source (LGPL)
** Copyright : (c) Copyright Erich Styger, 2014, all rights reserved.
** Web: http://www.mcuoneclipse.com
** This an open source software of an embedded component for Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file Rx1.h
** @version 01.00
** @brief
** This component implements a ring buffer for different integer data type.
*/
/*!
** @addtogroup Rx1_module Rx1 module documentation
** @{
*/
#ifndef __Rx1_H
#define __Rx1_H
/* MODULE Rx1. */
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
/* Include inherited beans */
#include "CS1.h"
//#include "Cpu.h"
#define Rx1_BUF_SIZE 64 /* number of elements in the buffer */
#define Rx1_ELEM_SIZE 1 /* size of a single element in bytes */
#define Rx1_IS_REENTRANT 0 /* 0: Critical section NOT used for accessing shared data, 1 otherwise */
#if Rx1_ELEM_SIZE==1
typedef uint8 Rx1_ElementType; /* type of single element */
#elif Rx1_ELEM_SIZE==2
typedef uint16 Rx1_ElementType; /* type of single element */
#elif Rx1_ELEM_SIZE==4
typedef uint32 Rx1_ElementType; /* type of single element */
#else
#error "illegal element type size in properties"
#endif
#if Rx1_BUF_SIZE<=256
typedef uint8 Rx1_BufSizeType; /* up to 256 elements (index 0x00..0xFF) */
#else
typedef uint16 Rx1_BufSizeType; /* more than 256 elements, up to 2^16 */
#endif
byte Rx1_Put(Rx1_ElementType elem);
/*
** ===================================================================
** Method : Rx1_Put (component RingBuffer)
** Description :
** Puts a new element into the buffer
** Parameters :
** NAME - DESCRIPTION
** elem - New element to be put into the buffer
** Returns :
** --- - Error code
** ===================================================================
*/
byte Rx1_Get(Rx1_ElementType *elemP);
/*
** ===================================================================
** Method : Rx1_Get (component RingBuffer)
** Description :
** Removes an element from the buffer
** Parameters :
** NAME - DESCRIPTION
** * elemP - Pointer to where to store the received
** element
** Returns :
** --- - Error code
** ===================================================================
*/
Rx1_BufSizeType Rx1_NofElements(void);
/*
** ===================================================================
** Method : Rx1_NofElements (component RingBuffer)
** Description :
** Returns the actual number of elements in the buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
void Rx1_Init(void);
/*
** ===================================================================
** Method : Rx1_Init (component RingBuffer)
** Description :
** Initializes the data structure
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
Rx1_BufSizeType Rx1_NofFreeElements(void);
/*
** ===================================================================
** Method : Rx1_NofFreeElements (component RingBuffer)
** Description :
** Returns the actual number of free elements/space in the
** buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
void Rx1_Clear(void);
/*
** ===================================================================
** Method : Rx1_Clear (component RingBuffer)
** Description :
** Clear (empty) the ring buffer.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/* END Rx1. */
#endif
/* ifndef __Rx1_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,202 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Tx1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : RingBuffer
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a ring buffer for different integer data type.
** Settings :
** Component name : Tx1
** Buffer Size : 1
** Contents :
** Clear - void Tx1_Clear(void);
** Put - byte Tx1_Put(Tx1_ElementType elem);
** Get - byte Tx1_Get(Tx1_ElementType *elemP);
** NofElements - Tx1_BufSizeType Tx1_NofElements(void);
** NofFreeElements - Tx1_BufSizeType Tx1_NofFreeElements(void);
** Init - void Tx1_Init(void);
**
** License : Open Source (LGPL)
** Copyright : (c) Copyright Erich Styger, 2014, all rights reserved.
** Web: http://www.mcuoneclipse.com
** This an open source software of an embedded component for Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file Tx1.c
** @version 01.00
** @brief
** This component implements a ring buffer for different integer data type.
*/
/*!
** @addtogroup Tx1_module Tx1 module documentation
** @{
*/
/* MODULE Tx1. */
#include "Tx1.h"
#if Tx1_IS_REENTRANT
#define Tx1_DEFINE_CRITICAL() CS1_CriticalVariable()
#define Tx1_ENTER_CRITICAL() CS1_EnterCritical()
#define Tx1_EXIT_CRITICAL() CS1_ExitCritical()
#else
#define Tx1_DEFINE_CRITICAL() /* nothing */
#define Tx1_ENTER_CRITICAL() /* nothing */
#define Tx1_EXIT_CRITICAL() /* nothing */
#endif
static Tx1_ElementType Tx1_buffer[Tx1_BUF_SIZE]; /* ring buffer */
static Tx1_BufSizeType Tx1_inIdx; /* input index */
static Tx1_BufSizeType Tx1_outIdx; /* output index */
static Tx1_BufSizeType Tx1_inSize; /* size data in buffer */
/*
** ===================================================================
** Method : Tx1_Put (component RingBuffer)
** Description :
** Puts a new element into the buffer
** Parameters :
** NAME - DESCRIPTION
** elem - New element to be put into the buffer
** Returns :
** --- - Error code
** ===================================================================
*/
byte Tx1_Put(Tx1_ElementType elem)
{
byte res = ERR_OK;
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
if(Tx1_inSize==Tx1_BUF_SIZE) {
res = ERR_TXFULL;
} else {
Tx1_buffer[Tx1_inIdx] = elem;
Tx1_inSize++;
Tx1_inIdx++;
if(Tx1_inIdx==Tx1_BUF_SIZE) {
Tx1_inIdx = 0;
}
}
Tx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Tx1_Get (component RingBuffer)
** Description :
** Removes an element from the buffer
** Parameters :
** NAME - DESCRIPTION
** * elemP - Pointer to where to store the received
** element
** Returns :
** --- - Error code
** ===================================================================
*/
byte Tx1_Get(Tx1_ElementType *elemP)
{
byte res = ERR_OK;
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
if(Tx1_inSize==0) {
res = ERR_RXEMPTY;
} else {
*elemP = Tx1_buffer[Tx1_outIdx];
Tx1_inSize--;
Tx1_outIdx++;
if(Tx1_outIdx==Tx1_BUF_SIZE) {
Tx1_outIdx = 0;
}
}
Tx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Tx1_NofElements (component RingBuffer)
** Description :
** Returns the actual number of elements in the buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofElements(void)
{
return Tx1_inSize;
}
/*
** ===================================================================
** Method : Tx1_NofFreeElements (component RingBuffer)
** Description :
** Returns the actual number of free elements/space in the
** buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofFreeElements(void)
{
return (Tx1_BufSizeType)(Tx1_BUF_SIZE-Tx1_inSize);
}
/*
** ===================================================================
** Method : Tx1_Init (component RingBuffer)
** Description :
** Initializes the data structure
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Tx1_Init(void)
{
Tx1_inIdx = 0;
Tx1_outIdx = 0;
Tx1_inSize = 0;
}
/*
** ===================================================================
** Method : Tx1_Clear (component RingBuffer)
** Description :
** Clear (empty) the ring buffer.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Tx1_Clear(void)
{
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
Tx1_Init();
Tx1_EXIT_CRITICAL();
}
/* END Tx1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,167 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Tx1.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : RingBuffer
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a ring buffer for different integer data type.
** Settings :
** Component name : Tx1
** Buffer Size : 1
** Contents :
** Clear - void Tx1_Clear(void);
** Put - byte Tx1_Put(Tx1_ElementType elem);
** Get - byte Tx1_Get(Tx1_ElementType *elemP);
** NofElements - Tx1_BufSizeType Tx1_NofElements(void);
** NofFreeElements - Tx1_BufSizeType Tx1_NofFreeElements(void);
** Init - void Tx1_Init(void);
**
** License : Open Source (LGPL)
** Copyright : (c) Copyright Erich Styger, 2014, all rights reserved.
** Web: http://www.mcuoneclipse.com
** This an open source software of an embedded component for Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file Tx1.h
** @version 01.00
** @brief
** This component implements a ring buffer for different integer data type.
*/
/*!
** @addtogroup Tx1_module Tx1 module documentation
** @{
*/
#ifndef __Tx1_H
#define __Tx1_H
/* MODULE Tx1. */
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
/* Include inherited beans */
#include "CS1.h"
//#include "Cpu.h"
#define Tx1_BUF_SIZE 64 /* number of elements in the buffer */
#define Tx1_ELEM_SIZE 1 /* size of a single element in bytes */
#define Tx1_IS_REENTRANT 0 /* 0: Critical section NOT used for accessing shared data, 1 otherwise */
#if Tx1_ELEM_SIZE==1
typedef uint8 Tx1_ElementType; /* type of single element */
#elif Tx1_ELEM_SIZE==2
typedef uint16 Tx1_ElementType; /* type of single element */
#elif Tx1_ELEM_SIZE==4
typedef uint32 Tx1_ElementType; /* type of single element */
#else
#error "illegal element type size in properties"
#endif
#if Tx1_BUF_SIZE<=256
typedef uint8 Tx1_BufSizeType; /* up to 256 elements (index 0x00..0xFF) */
#else
typedef uint16 Tx1_BufSizeType; /* more than 256 elements, up to 2^16 */
#endif
byte Tx1_Put(Tx1_ElementType elem);
/*
** ===================================================================
** Method : Tx1_Put (component RingBuffer)
** Description :
** Puts a new element into the buffer
** Parameters :
** NAME - DESCRIPTION
** elem - New element to be put into the buffer
** Returns :
** --- - Error code
** ===================================================================
*/
byte Tx1_Get(Tx1_ElementType *elemP);
/*
** ===================================================================
** Method : Tx1_Get (component RingBuffer)
** Description :
** Removes an element from the buffer
** Parameters :
** NAME - DESCRIPTION
** * elemP - Pointer to where to store the received
** element
** Returns :
** --- - Error code
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofElements(void);
/*
** ===================================================================
** Method : Tx1_NofElements (component RingBuffer)
** Description :
** Returns the actual number of elements in the buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
void Tx1_Init(void);
/*
** ===================================================================
** Method : Tx1_Init (component RingBuffer)
** Description :
** Initializes the data structure
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofFreeElements(void);
/*
** ===================================================================
** Method : Tx1_NofFreeElements (component RingBuffer)
** Description :
** Returns the actual number of free elements/space in the
** buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
void Tx1_Clear(void);
/*
** ===================================================================
** Method : Tx1_Clear (component RingBuffer)
** Description :
** Clear (empty) the ring buffer.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/* END Tx1. */
#endif
/* ifndef __Tx1_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,396 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : USB0.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : Init_USB_OTG
** Version : Component 01.004, Driver 01.04, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This file implements the USB_OTG (USB0) module initialization
** according to the Peripheral Initialization settings, and
** defines interrupt service routines prototypes.
** Settings :
** Component name : USB0
** Device : USB0
** Settings :
** Clock gate : Enabled
** Clock settings :
** Clock divider :
** Clock divider source : PLL/FLL clock
** Clock divider input frequency : 96 MHz
** Clock divider fraction : multiply by 1
** Clock divider divisor : divide by 2
** Module clock source : Clock divider output
** Module clock frequency : 48 MHz
** Pull-up/pull-down settings :
** Weak pulldowns : Enabled
** Pull-up/pull-down control : Mode dependent
** D+ pull-up : Disabled
** D+ pull-down : Disabled
** D- pull-down : Disabled
** D+ pull-up for non-OTG mode : Disabled
** Endpoints :
** EP0 : Disabled
** Direct low speed : Disabled
** Retry : Enabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP1 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP2 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP3 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP4 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP5 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP6 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP7 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP8 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP9 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP10 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP11 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP12 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP13 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP14 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP15 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** Buffer descriptor table :
** External object declaration : extern uint8 g_Mem[];
** Address : ((uint32)&g_Mem[0])
** SOF threshold : 0
** Pins :
** Alternate clock source : Disabled
** SOF output : Disabled
** Data plus : Enabled
** Pin : USB0_DP
** Pin signal :
** Data minus : Enabled
** Pin : USB0_DM
** Pin signal :
** Interrupts :
** USB :
** Interrupt : INT_USB0
** Interrupt request : Disabled
** Interrupt priority : 0 (Highest)
** ISR Name : USB_ISR
** Stall : Enabled
** Attach : Enabled
** Resume : Enabled
** Sleep : Enabled
** Token OK : Enabled
** Start of frame : Enabled
** Error interrupt : Enabled
** USB reset : Enabled
** Asynchronous Resume interrupt : Enabled
** Error interrupts :
** Bit stuff error : Disabled
** DMA error : Disabled
** Bus turnaround timeout : Disabled
** Data length error : Disabled
** CRC16 error : Disabled
** CRC5 or EOF : Disabled
** PID error : Disabled
** OTG interrupts :
** ID pin changed : Disabled
** 1 ms interrupt : Disabled
** Line stage change : Disabled
** Session valid : Disabled
** "B" session end : Disabled
** "A" bus valid : Disabled
** Initialization :
** Mode : Device
** USB transceiver suspend state : Enabled
** Call Init method : yes
** Contents :
** Init - void USB0_Init(void);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file USB0.c
** @version 01.04
** @brief
** This file implements the USB_OTG (USB0) module initialization
** according to the Peripheral Initialization settings, and
** defines interrupt service routines prototypes.
*/
/*!
** @addtogroup USB0_module USB0 module documentation
** @{
*/
/* MODULE USB0. */
#include "USB0.h"
/* Including shared modules, which are used in the whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "hal/derivative.h"
/*
** ===================================================================
** Method : USB0_Init (component Init_USB_OTG)
** Description :
** This method initializes registers of the USB_OTG module
** according to the Peripheral Initialization settings.
** Call this method in user code to initialize the module. By
** default, the method is called by PE automatically; see "Call
** Init method" property of the component for more details.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
extern uint8 g_Mem[];
void USB0_Init(void)
{
/* SIM_CLKDIV2: USBDIV=1,USBFRAC=0 */
SIM_CLKDIV2 = (uint32)((SIM_CLKDIV2 & (uint32)~(uint32)(
SIM_CLKDIV2_USBDIV(0x06) |
SIM_CLKDIV2_USBFRAC_MASK
)) | (uint32)(
SIM_CLKDIV2_USBDIV(0x01)
));
/* SIM_SOPT2: USBSRC=1 */
SIM_SOPT2 |= SIM_SOPT2_USBSRC_MASK;
/* SIM_SCGC4: USBOTG=1 */
SIM_SCGC4 |= SIM_SCGC4_USBOTG_MASK;
/* USB0_CTL: ODDRST=1 */
USB0_CTL |= USB_CTL_ODDRST_MASK;
/* USB0_USBCTRL: SUSP=1,PDE=1,??=0,??=0,??=0,??=0,??=0,??=0 */
USB0_USBCTRL = (USB_USBCTRL_SUSP_MASK | USB_USBCTRL_PDE_MASK);
/* USB0_OTGISTAT: IDCHG=1,ONEMSEC=1,LINE_STATE_CHG=1,??=1,SESSVLDCHG=1,B_SESS_CHG=1,??=1,AVBUSCHG=1 */
USB0_OTGISTAT = USB_OTGISTAT_IDCHG_MASK |
USB_OTGISTAT_ONEMSEC_MASK |
USB_OTGISTAT_LINE_STATE_CHG_MASK |
USB_OTGISTAT_SESSVLDCHG_MASK |
USB_OTGISTAT_B_SESS_CHG_MASK |
USB_OTGISTAT_AVBUSCHG_MASK |
0x12U;
/* USB0_ISTAT: STALL=1,ATTACH=1,RESUME=1,SLEEP=1,TOKDNE=1,SOFTOK=1,ERROR=1,USBRST=1 */
USB0_ISTAT = USB_ISTAT_STALL_MASK |
USB_ISTAT_ATTACH_MASK |
USB_ISTAT_RESUME_MASK |
USB_ISTAT_SLEEP_MASK |
USB_ISTAT_TOKDNE_MASK |
USB_ISTAT_SOFTOK_MASK |
USB_ISTAT_ERROR_MASK |
USB_ISTAT_USBRST_MASK;
/* USB0_ERRSTAT: BTSERR=1,??=1,DMAERR=1,BTOERR=1,DFN8=1,CRC16=1,CRC5EOF=1,PIDERR=1 */
USB0_ERRSTAT = USB_ERRSTAT_BTSERR_MASK |
USB_ERRSTAT_DMAERR_MASK |
USB_ERRSTAT_BTOERR_MASK |
USB_ERRSTAT_DFN8_MASK |
USB_ERRSTAT_CRC16_MASK |
USB_ERRSTAT_CRC5EOF_MASK |
USB_ERRSTAT_PIDERR_MASK |
0x40U;
/* USB0_INTEN: STALLEN=1,ATTACHEN=1,RESUMEEN=1,SLEEPEN=1,TOKDNEEN=1,SOFTOKEN=1,ERROREN=1,USBRSTEN=1 */
USB0_INTEN = USB_INTEN_STALLEN_MASK |
USB_INTEN_ATTACHEN_MASK |
USB_INTEN_RESUMEEN_MASK |
USB_INTEN_SLEEPEN_MASK |
USB_INTEN_TOKDNEEN_MASK |
USB_INTEN_SOFTOKEN_MASK |
USB_INTEN_ERROREN_MASK |
USB_INTEN_USBRSTEN_MASK;
/* USB0_ERREN: BTSERREN=0,??=0,DMAERREN=0,BTOERREN=0,DFN8EN=0,CRC16EN=0,CRC5EOFEN=0,PIDERREN=0 */
USB0_ERREN = 0x00U;
/* USB0_USBTRC0: USBRESET=0,??=1,USBRESMEN=1,??=0,??=0,??=0,SYNC_DET=0,USB_RESUME_INT=0 */
USB0_USBTRC0 = (USB_USBTRC0_USBRESMEN_MASK | 0x40U);
/* USB0_OTGICR: IDEN=0,ONEMSECEN=0,LINESTATEEN=0,??=0,SESSVLDEN=0,BSESSEN=0,??=0,AVBUSEN=0 */
USB0_OTGICR = 0x00U;
/* USB0_ADDR: LSEN=0,ADDR=0 */
USB0_ADDR = USB_ADDR_ADDR(0x00);
/* USB0_ENDPT0: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT0 = 0x00U;
/* USB0_ENDPT1: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT1 = 0x00U;
/* USB0_ENDPT2: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT2 = 0x00U;
/* USB0_ENDPT3: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT3 = 0x00U;
/* USB0_ENDPT4: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT4 = 0x00U;
/* USB0_ENDPT5: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT5 = 0x00U;
/* USB0_ENDPT6: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT6 = 0x00U;
/* USB0_ENDPT7: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT7 = 0x00U;
/* USB0_ENDPT8: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT8 = 0x00U;
/* USB0_ENDPT9: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT9 = 0x00U;
/* USB0_ENDPT10: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT10 = 0x00U;
/* USB0_ENDPT11: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT11 = 0x00U;
/* USB0_ENDPT12: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT12 = 0x00U;
/* USB0_ENDPT13: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT13 = 0x00U;
/* USB0_ENDPT14: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT14 = 0x00U;
/* USB0_ENDPT15: HOSTWOHUB=0,RETRYDIS=0,??=0,EPCTLDIS=0,EPRXEN=0,EPTXEN=0,EPSTALL=0,EPHSHK=0 */
USB0_ENDPT15 = 0x00U;
USB0_BDTPAGE1 = (uint8)((((uint32)((uint32)&g_Mem[0])) >> 0x08) & 0xFEU);
USB0_BDTPAGE2 = (uint8)((((uint32)((uint32)&g_Mem[0])) >> 0x10) & 0xFFU);
USB0_BDTPAGE3 = (uint8)((((uint32)((uint32)&g_Mem[0])) >> 0x18) & 0xFFU);
/* USB0_SOFTHLD: CNT=0 */
USB0_SOFTHLD = USB_SOFTHLD_CNT(0x00);
/* USB0_OTGCTL: DPHIGH=0,??=0,DPLOW=0,DMLOW=0,??=0,OTGEN=0,??=0,??=0 */
USB0_OTGCTL = 0x00U;
/* USB0_CONTROL: ??=0,??=0,??=0,DPPULLUPNONOTG=0,??=0,??=0,??=0,??=0 */
USB0_CONTROL = 0x00U;
/* USB0_CTL: TXSUSPENDTOKENBUSY=0,HOSTMODEEN=0,ODDRST=0,USBENSOFEN=1 */
USB0_CTL = (uint8)((USB0_CTL & (uint8)~(uint8)(
USB_CTL_TXSUSPENDTOKENBUSY_MASK |
USB_CTL_HOSTMODEEN_MASK |
USB_CTL_ODDRST_MASK
)) | (uint8)(
USB_CTL_USBENSOFEN_MASK
));
}
/*
** ###################################################################
**
** The interrupt service routine(s) must be implemented
** by user in one of the following user modules.
**
** If the "Generate ISR" option is enabled, Processor Expert generates
** ISR templates in the CPU event module.
**
** User modules:
** main.c
** Events.c
**
** ###################################################################
PE_ISR(USB_ISR)
{
// NOTE: The routine should include actions to clear the appropriate
// interrupt flags.
//
}
*/
/* END USB0. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,279 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : USB0.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : Init_USB_OTG
** Version : Component 01.004, Driver 01.04, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This file implements the USB_OTG (USB0) module initialization
** according to the Peripheral Initialization settings, and
** defines interrupt service routines prototypes.
** Settings :
** Component name : USB0
** Device : USB0
** Settings :
** Clock gate : Enabled
** Clock settings :
** Clock divider :
** Clock divider source : PLL/FLL clock
** Clock divider input frequency : 96 MHz
** Clock divider fraction : multiply by 1
** Clock divider divisor : divide by 2
** Module clock source : Clock divider output
** Module clock frequency : 48 MHz
** Pull-up/pull-down settings :
** Weak pulldowns : Enabled
** Pull-up/pull-down control : Mode dependent
** D+ pull-up : Disabled
** D+ pull-down : Disabled
** D- pull-down : Disabled
** D+ pull-up for non-OTG mode : Disabled
** Endpoints :
** EP0 : Disabled
** Direct low speed : Disabled
** Retry : Enabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP1 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP2 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP3 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP4 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP5 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP6 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP7 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP8 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP9 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP10 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP11 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP12 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP13 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP14 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** EP15 : Disabled
** Setup transfers : Enabled
** Handshake : Disabled
** Rx transfer : Disabled
** Tx transfer : Disabled
** Force stall : Disabled
** Buffer descriptor table :
** External object declaration : extern uint8 g_Mem[];
** Address : ((uint32)&g_Mem[0])
** SOF threshold : 0
** Pins :
** Alternate clock source : Disabled
** SOF output : Disabled
** Data plus : Enabled
** Pin : USB0_DP
** Pin signal :
** Data minus : Enabled
** Pin : USB0_DM
** Pin signal :
** Interrupts :
** USB :
** Interrupt : INT_USB0
** Interrupt request : Disabled
** Interrupt priority : 0 (Highest)
** ISR Name : USB_ISR
** Stall : Enabled
** Attach : Enabled
** Resume : Enabled
** Sleep : Enabled
** Token OK : Enabled
** Start of frame : Enabled
** Error interrupt : Enabled
** USB reset : Enabled
** Asynchronous Resume interrupt : Enabled
** Error interrupts :
** Bit stuff error : Disabled
** DMA error : Disabled
** Bus turnaround timeout : Disabled
** Data length error : Disabled
** CRC16 error : Disabled
** CRC5 or EOF : Disabled
** PID error : Disabled
** OTG interrupts :
** ID pin changed : Disabled
** 1 ms interrupt : Disabled
** Line stage change : Disabled
** Session valid : Disabled
** "B" session end : Disabled
** "A" bus valid : Disabled
** Initialization :
** Mode : Device
** USB transceiver suspend state : Enabled
** Call Init method : yes
** Contents :
** Init - void USB0_Init(void);
**
** Copyright : 1997 - 2014 Freescale Semiconductor, Inc.
** All Rights Reserved.
**
** Redistribution and use in source and binary forms, with or without modification,
** are permitted provided that the following conditions are met:
**
** o Redistributions of source code must retain the above copyright notice, this list
** of conditions and the following disclaimer.
**
** o Redistributions in binary form must reproduce the above copyright notice, this
** list of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution.
**
** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
** contributors may be used to endorse or promote products derived from this
** software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** http: www.freescale.com
** mail: support@freescale.com
** ###################################################################*/
/*!
** @file USB0.h
** @version 01.04
** @brief
** This file implements the USB_OTG (USB0) module initialization
** according to the Peripheral Initialization settings, and
** defines interrupt service routines prototypes.
*/
/*!
** @addtogroup USB0_module USB0 module documentation
** @{
*/
#ifndef USB0_H_
#define USB0_H_
/* MODULE USB0. */
/* Including shared modules, which are used in the whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
//#include "Cpu.h"
/* Peripheral base address parameter */
#define USB0_DEVICE USB0_BASE_PTR
/*
** ===================================================================
** Method : USB0_Init (component Init_USB_OTG)
** Description :
** This method initializes registers of the USB_OTG module
** according to the Peripheral Initialization settings.
** Call this method in user code to initialize the module. By
** default, the method is called by PE automatically; see "Call
** Init method" property of the component for more details.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void USB0_Init(void);
/*
** ===================================================================
** The interrupt service routine must be implemented by user in one
** of the user modules (see USB0.c file for more information).
** ===================================================================
*/
//PE_ISR(USB_ISR);
void __attribute((interrupt)) USB_ISR(void);
/* END USB0. */
#endif /* #ifndef __USB0_H_ */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,112 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : USB1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : FSL_USB_Stack
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a wrapper to the FSL USB Stack.
** Settings :
** Component name : USB1
** Freescale USB Stack Version : v4.1.1
** USB : Init_USB_OTG_VAR0
** Device Class : CDC Device
** CDC Device : Enabled
** CDCDevice : FSL_USB_CDC_Device
** HID Keyboard Device : Disabled
** MSD Host : Disabled
** Call Init Method : yes
** Contents :
** Init - byte USB1_Init(void);
**
** (c) Copyright Freescale, all rights reserved, 2013-2014.
** Ported as Processor Expert component: Erich Styger
** http: www.mcuoneclipse.com
** ###################################################################*/
/*!
** @file USB1.c
** @version 01.00
** @brief
** This component implements a wrapper to the FSL USB Stack.
*/
/*!
** @addtogroup USB1_module USB1 module documentation
** @{
*/
/* MODULE USB1. */
#include "USB1.h"
#include "hal/derivative.h" /* include peripheral declarations */
/*
** ===================================================================
** Method : USB1_usb_int_dis (component FSL_USB_Stack)
**
** Description :
** Disables USB interrupts (if supported)
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void USB1_usb_int_dis(void)
{
/* Kinetis K20D72 */
NVICISER1 = (1<<9); /* Disable interrupts from USB module (Interrupt Clear-Enable Register) */
}
/*
** ===================================================================
** Method : USB1_usb_int_en (component FSL_USB_Stack)
**
** Description :
** Enables USB interrupts (if supported).
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void USB1_usb_int_en(void)
{
/* Kinetis K20D72 */
NVICICPR2 = (1<<9); /* Clear any pending interrupts on USB (Interrupt Clear-Pending Register) */
NVICISER2 = (1<<9); /* Enable interrupts from USB module (Interrupt Set-Enable Register) */
}
/*
** ===================================================================
** Method : USB1_Init (component FSL_USB_Stack)
** Description :
** Initializes the driver
** Parameters : None
** Returns :
** --- - Error code
** ===================================================================
*/
byte USB1_Init(void)
{
byte err;
/* Initialize the USB interface */
err = CDC1_Init();
if(err != ERR_OK) {
/* Error initializing USB Class */
return ERR_FAILED;
}
USB1_usb_int_en();
return ERR_OK;
}
/* END USB1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,132 @@
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : USB1.h
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : FSL_USB_Stack
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a wrapper to the FSL USB Stack.
** Settings :
** Component name : USB1
** Freescale USB Stack Version : v4.1.1
** USB : Init_USB_OTG_VAR0
** Device Class : CDC Device
** CDC Device : Enabled
** CDCDevice : FSL_USB_CDC_Device
** HID Keyboard Device : Disabled
** MSD Host : Disabled
** Call Init Method : yes
** Contents :
** Init - byte USB1_Init(void);
**
** (c) Copyright Freescale, all rights reserved, 2013-2014.
** Ported as Processor Expert component: Erich Styger
** http: www.mcuoneclipse.com
** ###################################################################*/
/*!
** @file USB1.h
** @version 01.00
** @brief
** This component implements a wrapper to the FSL USB Stack.
*/
/*!
** @addtogroup USB1_module USB1 module documentation
** @{
*/
#ifndef __USB1_H
#define __USB1_H
/* MODULE USB1. */
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "MK20D10.h"
/* Include inherited beans */
#include "USB0.h"
#include "CDC1.h"
#include <stddef.h> /* for size_t */
/* Interfaces/wrappers to the CDC device class, needed by FSShell: */
#define USB1_SendString(str) CDC1_SendString(str)
#define USB1_RecvChar(chr) CDC1_GetChar(chr)
#define USB1_SendChar(chr) CDC1_SendChar(chr)
#define USB1_GetCharsInRxBuf() CDC1_GetCharsInRxBuf()
//#include "Cpu.h"
#ifndef __BWUserType_USB1_TComData
#define __BWUserType_USB1_TComData
typedef byte USB1_TComData ; /* User type for communication data type. */
#endif
/*
DATA_BUFF_SIZE should be greater than or equal to the endpoint buffer size,
otherwise there will be data loss. For MC9S08JS16, maximum DATA_BUFF_SIZE
supported is 16 Bytes
*/
#define USB1_DATA_BUFF_SIZE 64 /* data buffer size as specified in the properties */
#define USB1_USB_ERR_SEND 1 /* Error while sending */
#define USB1_USB_ERR_BUSOFF 2 /* Bus not ready */
#define USB1_USB_ERR_INIT 3 /* USB initialization error */
#define USB1_USB_ERR_TX_CHAR 4 /* Error sending character */
#define USB1_USB_ERR_TX_STRING 5 /* Error sending string */
#define USB1_USB_ERR_CHECKED_TXFULL 6 /* Error during sending a checked block */
#define USB1_USB_ERR_RECEIVE 7 /* Error while starting a receive transaction */
byte USB1_Init(void);
/*
** ===================================================================
** Method : USB1_Init (component FSL_USB_Stack)
** Description :
** Initializes the driver
** Parameters : None
** Returns :
** --- - Error code
** ===================================================================
*/
void USB1_usb_int_dis(void);
/*
** ===================================================================
** Method : USB1_usb_int_dis (component FSL_USB_Stack)
**
** Description :
** Disables USB interrupts (if supported)
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void USB1_usb_int_en(void);
/*
** ===================================================================
** Method : USB1_usb_int_en (component FSL_USB_Stack)
**
** Description :
** Enables USB interrupts (if supported).
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/* END USB1. */
#endif
/* ifndef __USB1_H */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/

View File

@@ -0,0 +1,211 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file USB_Config.h
*
* @author B14088
*
* @version
*
* @date Oct 31, 2010
*
* @brief
*****************************************************************************/
#ifndef USB_CONFIG_H_
#define USB_CONFIG_H_
/*****************************************************************************/
/* Includes Section */
/*****************************************************************************/
/*****************************************************************************/
/* Typedef Section */
/*****************************************************************************/
/*****************************************************************************/
/* Function's Prototypes */
/*****************************************************************************/
/* CDC class services */
extern void USB_Class_CDC_Service_Dic_Bulk_In (PTR_USB_DEV_EVENT_STRUCT event);
extern void USB_Class_CDC_Service_Dic_Bulk_Out(PTR_USB_DEV_EVENT_STRUCT event);
extern void USB_Class_CDC_Service_Cic_Notify(PTR_USB_DEV_EVENT_STRUCT event);
extern void USB_NULL_CALLBACK (PTR_USB_DEV_EVENT_STRUCT event);
/*****************************************************************************/
/* Defines & Macros Section */
/*****************************************************************************/
#define REMOTE_WAKEUP_SUPPORT (TRUE)
/* CDC specific configuration parameters */
#define DATA_CLASS_SUPPORT (TRUE)
#define CIC_NOTIF_ELEM_SUPPORT (TRUE) /* Mandatory */
#define DIC_ISOCHRONOUS_SETTING (FALSE)
#define IMPLEMENT_QUEUING (FALSE)
/* Hardware components configuration */
#define USB_HW_VREG_EN TRUE
#define USB_HW_PU_EN TRUE
/* Event callbacks assignation */
#define USB_EP0_CALLBACK USB_Control_Service
#if DIC_ISOCHRONOUS_SETTING
#define USB_EP1_CALLBACK USB_Class_CDC_Service_Dic_Iso_In
#define USB_EP2_CALLBACK USB_Class_CDC_Service_Dic_Iso_Out
#else
#define USB_EP1_CALLBACK USB_Class_CDC_Service_Dic_Bulk_In
#define USB_EP2_CALLBACK USB_Class_CDC_Service_Dic_Bulk_Out
#endif
#define USB_EP3_CALLBACK USB_Class_CDC_Service_Cic_Notify
#define USB_EP4_CALLBACK USB_NULL_CALLBACK
#define USB_EP5_CALLBACK USB_NULL_CALLBACK
#define USB_EP6_CALLBACK USB_NULL_CALLBACK
#define USB_EP7_CALLBACK USB_NULL_CALLBACK
#define USB_EP8_CALLBACK USB_NULL_CALLBACK
#define USB_EP9_CALLBACK USB_NULL_CALLBACK
#define USB_EP10_CALLBACK USB_NULL_CALLBACK
#define USB_EP11_CALLBACK USB_NULL_CALLBACK
#define USB_EP12_CALLBACK USB_NULL_CALLBACK
#define USB_EP13_CALLBACK USB_NULL_CALLBACK
#define USB_EP14_CALLBACK USB_NULL_CALLBACK
#define USB_EP15_CALLBACK USB_NULL_CALLBACK
#define USB_BUS_RESET_CALLBACK USB_Reset_Service
#define USB_SUSPEND_CALLBACK USB_Suspend_Service
#define USB_SOF_CALLBACK USB_Sof_Service
#define USB_RESUME_CALLBACK USB_Resume_Service
#define USB_SLEEP_CALLBACK USB_Suspend_Service
#define USB_SPEED_DETECTION_CALLBACK USB_NULL_CALLBACK
#define USB_ERROR_CALLBACK USB_Error_Service
#define USB_STALL_CALLBACK USB_Stall_Service
/* Endpoints configuration */
#define USB_EP0_ENABLE TRUE
#define USB_EP0_DIR EP_CTRL
#define USB_EP0_HSHK TRUE
#define USB_EP0_SIZE 32
#if DIC_ISOCHRONOUS_SETTING
#define USB_EP1_ENABLE TRUE
#define USB_EP1_DIR USB_DIR_IN
#define USB_EP1_HSHK FALSE
#define USB_EP1_SIZE 64
#define USB_EP2_ENABLE TRUE
#define USB_EP2_DIR EP_OUT
#define USB_EP2_HSHK FALSE
#define USB_EP2_SIZE 64
#else
#define USB_EP1_ENABLE TRUE
#define USB_EP1_DIR EP_IN
#define USB_EP1_HSHK TRUE
#define USB_EP1_SIZE 32
#define USB_EP2_ENABLE TRUE
#define USB_EP2_DIR EP_OUT
#define USB_EP2_HSHK TRUE
#define USB_EP2_SIZE 32
#endif
#define USB_EP3_ENABLE TRUE
#define USB_EP3_DIR EP_IN
#define USB_EP3_HSHK TRUE
#define USB_EP3_SIZE 32
#define USB_EP4_ENABLE FALSE
#define USB_EP4_DIR NA
#define USB_EP4_HSHK TRUE
#define USB_EP4_SIZE 0
#define USB_EP5_ENABLE FALSE
#define USB_EP5_DIR NA
#define USB_EP5_HSHK TRUE
#define USB_EP5_SIZE 0
#define USB_EP6_ENABLE FALSE
#define USB_EP6_DIR NA
#define USB_EP6_HSHK TRUE
#define USB_EP6_SIZE 0
#define USB_EP7_ENABLE FALSE
#define USB_EP7_DIR NA
#define USB_EP7_HSHK TRUE
#define USB_EP7_SIZE 0
#define USB_EP8_ENABLE FALSE
#define USB_EP8_DIR NA
#define USB_EP8_HSHK TRUE
#define USB_EP8_SIZE 0
#define USB_EP9_ENABLE FALSE
#define USB_EP9_DIR NA
#define USB_EP9_HSHK TRUE
#define USB_EP9_SIZE 0
#define USB_EP10_ENABLE FALSE
#define USB_EP10_DIR NA
#define USB_EP10_HSHK TRUE
#define USB_EP10_SIZE 0
#define USB_EP11_ENABLE FALSE
#define USB_EP11_DIR NA
#define USB_EP11_HSHK TRUE
#define USB_EP11_SIZE 0
#define USB_EP12_ENABLE FALSE
#define USB_EP12_DIR NA
#define USB_EP12_HSHK TRUE
#define USB_EP12_SIZE 0
#define USB_EP13_ENABLE FALSE
#define USB_EP13_DIR NA
#define USB_EP13_HSHK TRUE
#define USB_EP13_SIZE 0
#define USB_EP14_ENABLE FALSE
#define USB_EP14_DIR NA
#define USB_EP14_HSHK TRUE
#define USB_EP14_SIZE 0
#define USB_EP15_ENABLE FALSE
#define USB_EP15_DIR NA
#define USB_EP15_HSHK TRUE
#define USB_EP15_SIZE 0
/*****************************************************************************/
/* Extern Variables Section */
/*****************************************************************************/
/*****************************************************************************/
/* Function Prototypes Section */
/*****************************************************************************/
/*****************************************************************************/
#endif /* USB_CONFIG_H_ */

View File

@@ -0,0 +1,64 @@
/******************************************************/
/**
* @file hidef.h
* Machine/compiler dependent declarations.
*/
/*----------------------------------------------------
Copyright (c) Freescale DevTech
All rights reserved
Do not modify!
*****************************************************/
#ifndef _H_HIDEF_
#define _H_HIDEF_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef EnableInterrupts
#ifndef DisableInterrupts
#if defined(__CWCC__)
#pragma gcc_extensions on
/**** Version for ColFire V1 */
#include <stddef.h>
#include "types.h"
/*!< Macro to enable all interrupts. */
#define EnableInterrupts asm ("CPSIE i")
/*!< Macro to disable all interrupts. */
#define DisableInterrupts asm ("CPSID i")
#elif defined(__IAR_SYSTEMS_ICC__)
#include <intrinsics.h>
#define EnableInterrupts; __enable_interrupt()
#define DisableInterrupts __disable_interrupt()
#elif defined (__CC_ARM)
#define EnableInterrupts __enable_irq()
#define DisableInterrupts __disable_irq()
#elif defined (__GNUC__)
#include <stddef.h>
#include "types.h"
/*!< Macro to enable all interrupts. */
#define EnableInterrupts asm ("CPSIE i")
/*!< Macro to disable all interrupts. */
#define DisableInterrupts asm ("CPSID i")
#endif
#ifdef __cplusplus
}
#endif
#endif
#endif /* #ifdef DisableInterrupts */
#endif/* #ifdef EnableInterrupts */
/*****************************************************/
/* end hidef.h */

View File

@@ -0,0 +1,180 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file types.h
*
* @author
*
* @version
*
* @date
*
* @brief The file contains definitions of datatypes.
*
*****************************************************************************/
#ifndef _TYPES_H
#define _TYPES_H
/******************************************************************************
* Includes
*****************************************************************************/
#include <stddef.h>
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
#define LSB(a) ((a)._byte.byte0)
#define MSB(a) ((a)._byte.byte1)
#define LOWER_LSB(a) ((a)._byte.byte0)
#define LOWER_MSB(a) ((a)._byte.byte1)
#define UPPER_LSB(a) ((a)._byte.byte2)
#define UPPER_MSB(a) ((a)._byte.byte3)
#define _PTR_ *
#define _CODE_PTR_ *
#ifndef TRUE
#define FALSE 0
#define TRUE 1
#endif
#define BYTESWAP16(x) (uint_16)((((x) & 0xFF00) >> 0x8) | (((x) & 0xFF) << 0x8))
#define BYTESWAP32(val) (uint_32)((BYTESWAP16((uint_32)(val) & (uint_32)0xFFFF) << 0x10) | \
(BYTESWAP16((uint_32)((val) >> 0x10))))
#ifdef CPU_LITTLE_ENDIAN /* << EST: defined by Processor Expert CPU.h for Kinetis devices */
#ifndef LITTLE_ENDIAN /* might be defined already on the compiler command line? */
#define LITTLE_ENDIAN
#endif
#endif
#ifndef LITTLE_ENDIAN
#define ieee_htons(x) (uint_16)(x)
#define ieee_htonl(x) (uint_32)(x)
#define ieee_ntohs(x) (uint_16)(x)
#define ieee_ntohl(x) (uint_32)(x)
#else
#define ieee_htons(x) BYTESWAP16(x)
#define ieee_htonl(x) BYTESWAP32(x)
#define ieee_ntohs(x) BYTESWAP16(x)
#define ieee_ntohl(x) BYTESWAP32(x)
#endif
#ifndef UNUSED
#define UNUSED(x) (void)(x);
#endif
/******************************************************************************
* Types
*****************************************************************************/
typedef void _PTR_ pointer; /* Machine representation of a pointer */
typedef unsigned char uint_8; /* 8-bit*/
typedef signed char int_8; /* 8-bit*/
typedef unsigned short uint_16; /* 16-bit*/
typedef signed short int_16; /* 16-bit*/
typedef unsigned long uint_32; /* 32-bit*/
typedef signed long int_32; /* 32-bit*/
typedef unsigned char boolean; /* 8-bit*/
typedef uint_8* uint_8_ptr; /* ptr to 8-bit*/
typedef uint_16* uint_16_ptr; /* ptr to 16-bit */
typedef uint_32* uint_32_ptr; /* ptr to 32-bit*/
typedef uint_8_ptr uint8_ptr; /* ptr to 8-bit*/
/* definition of 8 bit word */
typedef union _BYTE
{
uint_8 _byte;
struct
{
unsigned b0:1;
unsigned b1:1;
unsigned b2:1;
unsigned b3:1;
unsigned b4:1;
unsigned b5:1;
unsigned b6:1;
unsigned b7:1;
}Bit;
} BYTE;
/* definition of 16 bit word */
typedef union _WORD
{
uint_16 _word;
struct
{
uint_8 byte1;
uint_8 byte0;
}_byte;
struct
{
BYTE HighB;
BYTE LowB;
}_Byte;
} WORD;
/* definition of 32 bit word */
typedef union _DWORD
{
uint_32 _dword;
struct
{
uint_8 byte3;
uint_8 byte2;
uint_8 byte1;
uint_8 byte0;
}_byte;
struct
{
uint_16 word1;
uint_16 word0;
}_word;
struct
{
BYTE Byte3;
BYTE Byte2;
BYTE Byte1;
BYTE Byte0;
}_Byte;
struct
{
WORD Word1;
WORD Word0;
}_Word;
} DWORD;
/******************************************************************************
* Global Functions - None
*****************************************************************************/
#endif

View File

@@ -0,0 +1,140 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_bdt_kinetis.h
*
* @author
*
* @version
*
* @date Jun-05-2009
*
* @brief The file contains definitions of Buffer Descriptor Table.
*
*****************************************************************************/
#ifndef _USBBDT_H
#define _USBBDT_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
/* Buffer Descriptor Status Register Initialization Parameters */
#define _BDTSTALL (0x04) /* Buffer Stall enable */
#define _DATA0 (0x00) /* DATA0 packet expected next */
#define _DATA1 (0x40) /* DATA1 packet expected next */
#define _DTS (0x08) /* DTS Mask */
#define _SIE (0x80) /* SIE owns buffer */
#define _CPU (0x00) /* CPU owns buffer */
#define _KEEP (0x20) /* keep bit */
#define MAX_BDT_INDEX (64) /* Maximum BDT Indexes */
/******************************************************************************
* Types
*****************************************************************************/
/* This structure is an exact replica of the BDT MAP in the USB RAM
The BDT_STAT defines the stat byte of the buffer descriptor vector.
McuCtlBit structure defines the bits that have a meaning from CPU
point of view.SieCtlBit structure defines the bits that have a
meaning from USB controller point of view.
*/
#if defined(__CWCC__)
#pragma align_array_members on
#endif
/* << EST pushing current packing */
#pragma pack(push)
#pragma pack(1)
typedef struct _MCU_CTL_BIT{
uint_8 :1;
uint_8 :1;
uint_8 bdtstall:1; /* Buffer Stall Enable */
uint_8 dts:1; /* Data Toggle Synch Enable */
uint_8 keep:1; /* Address Increment Disable */
uint_8 ninc:1; /* BD Keep Enable */
uint_8 data:1; /* Data Toggle Synch Value */
uint_8 own:1; /* USB Ownership */
}MCU_CTL_BIT; /* read Stat */
typedef struct _SIE_CTL_BIT{
uint_8 :1;
uint_8 :1;
uint_8 pid0:1; /* Packet Identifier bit 0 */
uint_8 pid1:1; /* Packet Identifier bit 1 */
uint_8 pid2:1; /* Packet Identifier bit 2 */
uint_8 pid3:1; /* Packet Identifier bit 3 */
uint_8 :1;
uint_8 own:1;
}SIE_CTL_BIT; /* write Stat */
typedef struct _REC_PID{
uint_8 :2;
uint_8 pid:4; /* Packet Identifier */
uint_8 :2;
}REC_PID;
typedef union _BD_STAT
{
uint_8 _byte;
MCU_CTL_BIT McuCtlBit;
SIE_CTL_BIT SieCtlBit;
REC_PID RecPid;
} BD_STAT; /* Buffer Descriptor Status Register */
typedef struct _BUFF_DSC
{
BD_STAT Stat;
uint_8 reserved1;
uint_16 cnt; /* Count of bytes receieved or sent */
/* six MSB bits are reserved ones */
uint_32 addr; /* Buffer Address */
} BUFF_DSC, *P_BUFF_DSC; /* Buffer Descriptor Table */
typedef struct _g_bdtmap {
BUFF_DSC ep_dsc[MAX_BDT_INDEX]; /* Endpoint Descriptor */
}BDTMAP;
#if defined(__CWCC__)
#pragma align_array_members off
#pragma options align=reset
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma pack()
#else /* e.g. gcc */
/* << EST restoring previous packing */
#pragma pack(pop)
#endif
/******************************************************************************
* Global Functions - None
*****************************************************************************/
#endif

View File

@@ -0,0 +1,809 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_cdc.c
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file contains USB stack CDC layer implementation.
*
*****************************************************************************/
/******************************************************************************
* Includes
*****************************************************************************/
#include "usb_cdc.h" /* USB CDC Class Header File */
/*****************************************************************************
* Constant and Macro's
*****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
#ifdef _MC9S08JS16_H
#pragma DATA_SEG APP_DATA
#endif
/* CDC Class Callback Function Pointer */
static USB_CLASS_CALLBACK g_cdc_class_callback = NULL;
/* CDC Class Vendor Callback Function Pointer */
static USB_REQ_FUNC g_vendor_req_callback = NULL;
/* CDC endpoint info array */
#ifndef COMPOSITE_DEV
static USB_CLASS_CDC_ENDPOINT g_cdc_ep[CDC_DESC_ENDPOINT_COUNT];
#else
static USB_CLASS_CDC_ENDPOINT g_cdc_ep[COMPOSITE_DESC_ENDPOINT_COUNT];
#endif
/*****************************************************************************
* Local Types - None
*****************************************************************************/
/*****************************************************************************
* Local Functions Prototypes
*****************************************************************************/
#if CIC_NOTIF_ELEM_SUPPORT
void USB_Class_CDC_Service_Cic_Notify(PTR_USB_DEV_EVENT_STRUCT event);
#endif
#if !DIC_ISOCHRONOUS_SETTING
void USB_Class_CDC_Service_Dic_Bulk_In(PTR_USB_DEV_EVENT_STRUCT event);
void USB_Class_CDC_Service_Dic_Bulk_Out(PTR_USB_DEV_EVENT_STRUCT event);
#else
static void USB_Class_CDC_Service_Dic_Iso_In(PTR_USB_DEV_EVENT_STRUCT event);
static void USB_Class_CDC_Service_Dic_Iso_Out(PTR_USB_DEV_EVENT_STRUCT event);
#endif
#ifndef COMPOSITE_DEV
static uint_8 USB_Other_Requests(
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
#endif
void USB_Class_CDC_Event(
uint_8 controller_ID,
uint_8 event,
void* val);
/*****************************************************************************
* Local Variables - None
*****************************************************************************/
/*****************************************************************************
* Local Functions
*****************************************************************************/
#if CIC_NOTIF_ELEM_SUPPORT
/**************************************************************************//*!
*
* @name USB_Class_CDC_Service_Cic_Notify
*
* @brief The function is callback function of CIC Notification endpoint
*
* @param event : Pointer to USB Event Structure
*
* @return None
*
******************************************************************************
* Called by Lower layer when data on CIC Endpoint is sent
*****************************************************************************/
void USB_Class_CDC_Service_Cic_Notify (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
#if IMPLEMENT_QUEUING
uint_8 index;
uint_8 producer, consumer;
USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
USB_Desc_Get_Endpoints(event->controller_ID);
USB_CLASS_CDC_QUEUE queue;
/* map the endpoint num to the index of the endpoint structure */
for(index = 0; index < usb_ep_data->count; index++)
{
if(usb_ep_data->ep[index].ep_num == event->ep_num)
break;
}
producer = g_cdc_ep[index].bin_producer;
/* if there are no errors de-queue the queue and decrement the no. of
transfers left, else send the same data again */
if(event->errors == 0)
{
g_cdc_ep[index].bin_consumer++;
}
consumer = g_cdc_ep[index].bin_consumer;
if(consumer != producer)
{/*if bin is not empty */
queue = g_cdc_ep[index].queue[consumer%MAX_QUEUE_ELEMS];
(void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
queue.app_data.data_ptr, queue.app_data.data_size);
}
#endif
if(g_cdc_class_callback != NULL)
{
uint_8 event_type = USB_APP_SEND_COMPLETE;
if(event->errors != 0)
{
event_type = USB_APP_ERROR;
}
g_cdc_class_callback(event->controller_ID, event_type,
(uint_8*)(&(event->errors)));
}
}
#endif
#if !DIC_ISOCHRONOUS_SETTING
/**************************************************************************//*!
*
* @name USB_Class_CDC_Service_Dic_Bulk_In
*
* @brief The function is callback function of DIC Bulk In Endpoint
*
* @param event : Pointer to USB Event Structure
*
* @return None
*
******************************************************************************
* Called by Lower Layer when Data on DIC SEND Interface is sent
*****************************************************************************/
void USB_Class_CDC_Service_Dic_Bulk_In (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
APP_DATA_STRUCT bulk_in_recv;
#if IMPLEMENT_QUEUING
uint_8 index;
uint_8 producer, consumer;
USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
USB_Desc_Get_Endpoints(event->controller_ID);
USB_CLASS_CDC_QUEUE queue;
bulk_in_recv.data_ptr = event->buffer_ptr;
bulk_in_recv.data_size = event->len;
/* map the endpoint num to the index of the endpoint structure */
for(index = 0; index < usb_ep_data->count; index++)
{
if(usb_ep_data->ep[index].ep_num == event->ep_num)
break;
}
producer = g_cdc_ep[index].bin_producer;
/* if there are no errors de-queue the queue and decrement the no. of
transfers left, else send the same data again */
if(event->errors == 0)
{
g_cdc_ep[index].bin_consumer++;
}
consumer = g_cdc_ep[index].bin_consumer;
if(consumer != producer)
{/*if bin is not empty */
queue = g_cdc_ep[index].queue[consumer%MAX_QUEUE_ELEMS];
(void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
queue.app_data.data_ptr, queue.app_data.data_size);
}
#endif
if(g_cdc_class_callback != NULL)
{
if(event->errors != 0)
{
g_cdc_class_callback(event->controller_ID, USB_APP_ERROR,
(uint_8*)(&(event->errors)));
}
else
{
g_cdc_class_callback(event->controller_ID, USB_APP_SEND_COMPLETE,
(void*)&bulk_in_recv);
}
}
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_Service_Dic_Bulk_Out
*
* @brief The function is callback function of DIC Bulk Out Endpoint
*
* @param event : Pointer to USB Event Structure
*
* @return None
*
******************************************************************************
* Called by Lower Layer when Data on DIC RECV Interface is received
*****************************************************************************/
void USB_Class_CDC_Service_Dic_Bulk_Out (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{ APP_DATA_STRUCT bulk_out_recv;
bulk_out_recv.data_ptr = event->buffer_ptr;
bulk_out_recv.data_size = event->len;
if(g_cdc_class_callback != NULL)
{
if(event->errors != 0)
{
g_cdc_class_callback(event->controller_ID, USB_APP_ERROR,
(uint_8*)(&(event->errors)));
}
else
{
g_cdc_class_callback(event->controller_ID, USB_APP_DATA_RECEIVED,
(void*)&bulk_out_recv);
}
}
}
#else
/**************************************************************************//*!
*
* @name USB_Class_CDC_Service_Dic_Iso_In
*
* @brief The function is callback function of DIC Isochronous In Endpoint
*
* @param event : Pointer to USB Event Structure
*
* @return None
*
******************************************************************************
* Called by Lower Layer when Data on DIC SEND Interface is sent
*****************************************************************************/
static void USB_Class_CDC_Service_Dic_Iso_In (
PTR_USB_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
APP_DATA_STRUCT iso_in_recv;
#if IMPLEMENT_QUEUING
uint_8 index;
uint_8 producer, consumer;
USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
USB_Desc_Get_Endpoints(event->controller_ID);
USB_CLASS_CDC_QUEUE queue;
/* map the endpoint num to the index of the endpoint structure */
for(index = 0; index < usb_ep_data->count; index++)
{
if(usb_ep_data->ep[index].ep_num == event->ep_num)
{
break;
}
}
producer = g_cdc_ep[index].bin_producer;
/* if there are no errors de-queue the queue and decrement the no. of
transfers left, else send the same data again */
if(event->errors == 0)
{
g_cdc_ep[index].bin_consumer++;
}
consumer = g_cdc_ep[index].bin_consumer;
if(consumer != producer)
{/*if bin is not empty */
queue = g_cdc_ep[index].queue[consumer%MAX_QUEUE_ELEMS];
(void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
queue.app_data.data_ptr, queue.app_data.data_size);
}
#endif
iso_in_recv.data_ptr = event->buffer_ptr;
iso_in_recv.data_size = event->len;
if(g_cdc_class_callback != NULL)
{
if(event->errors != 0)
{
g_cdc_class_callback(event->controller_ID, USB_APP_ERROR,
(uint_8*)(&(event->errors)));
}
else
{
g_cdc_class_callback(event->controller_ID, USB_APP_SEND_COMPLETE,
(void*)&iso_in_recv);
}
}
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_Service_Dic_Iso_Out
*
* @brief This is a callback function of DIC Isochronous Out Endpoint
*
* @param event : Pointer to USB Event Structure
*
* @return None
*
******************************************************************************
* Called by Lower Layer when Data on DIC RECV Interface is received
*****************************************************************************/
static void USB_Class_CDC_Service_Dic_Iso_Out (
PTR_USB_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
APP_DATA_STRUCT iso_out_recv;
iso_out_recv.data_ptr = event->buffer_ptr;
iso_out_recv.data_size = event->len;
if(g_cdc_class_callback != NULL)
{
if(event->errors != 0)
{
g_cdc_class_callback(event->controller_ID, USB_APP_ERROR,
(uint_8*)(&(event->errors)));
}
else
{
g_cdc_class_callback(event->controller_ID, USB_APP_DATA_RECEIVED,
(void*)&iso_out_recv);
}
}
}
#endif
/**************************************************************************//*!
*
* @name USB_Class_CDC_Event
*
* @brief The function initializes CDC endpoints
*
* @param controller_ID : Controller ID
* @param event : Event Type
* @param val : Pointer to configuration Value
*
* @return None
*
******************************************************************************
*
*****************************************************************************/
void USB_Class_CDC_Event (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 event, /* [IN] Event Type */
void* val /* [OUT] Pointer to configuration Value */
)
{
uint_8 index;
USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
USB_Desc_Get_Endpoints(controller_ID);
if(event == USB_APP_ENUM_COMPLETE)
{
uint_8 count = 0,ep_count = 0;
uint_8 index_num = 0;
#ifdef COMPOSITE_DEV
DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
CLASS_ARC_STRUCT_PTR dev_class_ptr;
dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
for(count = 0; count < dev_arc_ptr->cl_count; count++)
{
dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
/* Initializes sub_classes */
ep_count = dev_class_ptr->value[0];
if(dev_class_ptr->class_type == 0x02/*CDC_CC*/)
break;
index_num +=dev_class_ptr->value[0];
}
#else
ep_count = usb_ep_data->count;
#endif
for(count=index_num; count<ep_count+index_num; count++)
{
USB_EP_STRUCT_PTR ep_struct_ptr=
(USB_EP_STRUCT_PTR) (unsigned long) (&usb_ep_data->ep[count]); // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
(void)_usb_device_deinit_endpoint(&controller_ID,
ep_struct_ptr->ep_num, ep_struct_ptr->direction);
}
/* intialize all non control endpoints */
for(count=index_num; count<ep_count+index_num; count++)
{
USB_EP_STRUCT_PTR ep_struct=
(USB_EP_STRUCT_PTR) (unsigned long) (&usb_ep_data->ep[count]); // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
(void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
ep_struct->size, ep_struct->direction, ep_struct->type, FALSE);
/* register callback service for Non Control EndPoints */
switch(ep_struct->type)
{
#if CIC_NOTIF_ELEM_SUPPORT
case USB_INTERRUPT_PIPE :
(void)_usb_device_register_service(controller_ID,
(uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
USB_Class_CDC_Service_Cic_Notify);
break;
#endif
#if !DIC_ISOCHRONOUS_SETTING
case USB_BULK_PIPE :
#ifdef MULTIPLE_DEVICES
if(ep_struct->direction == USB_RECV)
{
(void)_usb_device_register_service(controller_ID,
(uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
USB_Class_CDC_Service_Dic_Bulk_Out);
}
else
{
(void)_usb_device_register_service(controller_ID,
(uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
USB_Class_CDC_Service_Dic_Bulk_In);
}
#endif
break;
#else
case USB_ISOCHRONOUS_PIPE :
if(ep_struct->direction == USB_RECV)
{
(void)_usb_device_register_service(controller_ID,
(uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
USB_Class_CDC_Service_Dic_Iso_Out);
}
else
{
(void)_usb_device_register_service(controller_ID,
(uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
USB_Class_CDC_Service_Dic_Iso_In);
}
break;
#endif
default:
break;
}
/* set the EndPoint Status as Idle in the device layer */
(void)_usb_device_set_status(&controller_ID,
(uint_8)(USB_STATUS_ENDPOINT | ep_struct->ep_num |
(ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
(uint_8)USB_STATUS_IDLE);
}
}
else if(event == USB_APP_BUS_RESET)
{
#if IMPLEMENT_QUEUING
for(index = 0; index < usb_ep_data->count; index++)
{
g_cdc_ep[index].bin_consumer = 0x00;
g_cdc_ep[index].bin_producer = 0x00;
}
#endif
}
if(g_cdc_class_callback != NULL)
{
g_cdc_class_callback(controller_ID, event, val);
}
}
/**************************************************************************//*!
*
* @name USB_Other_Requests
*
* @brief The function provides flexibilty to add class and vendor specific
* requests
*
* @param controller_ID : Controller ID
* @param setup_packet : Setup packet received
* @param data: : Data to be send back
* @param size: : Size to be returned
*
* @return status:
* USB_OK : When Successfull
* Others : When Error
*
******************************************************************************
* Handles CDC Class requests and forwards vendor specific request to the
* application
*****************************************************************************/
#ifndef COMPOSITE_DEV
static uint_8 USB_Other_Requests
#else
uint_8 USB_CDC_Other_Requests
#endif
(
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet,/* [IN] Pointer to Setup Packet Received */
uint_8_ptr *data, /* [OUT] Pointer to Data Buffer to be sent */
USB_PACKET_SIZE *size /* [OUT] Size of Data buffer */
)
{
uint_8 status = USBERR_INVALID_REQ_TYPE;
if((setup_packet->request_type & USB_REQUEST_CLASS_MASK) ==
USB_REQUEST_CLASS_CLASS)
{
/* class request so handle it here */
status=USB_OK;
/* call for class/subclass specific requests */
switch(setup_packet->request)
{
case SEND_ENCAPSULATED_COMMAND :
/* Add code to transfer Request and Acknowledgement */
*size=0;
break;
case GET_ENCAPSULATED_RESPONSE :
/*
Add code for handling Transfer Response/Requests and
Notification
*/
*size=0;
break;
case SET_COMM_FEATURE :
status = USB_Class_CDC_PSTN_Set_Comm_Feature(controller_ID,
setup_packet, data, size);
break;
case GET_COMM_FEATURE :
status = USB_Class_CDC_PSTN_Get_Comm_Feature(controller_ID,
setup_packet, data, size);
break;
case CLEAR_COMM_FEATURE : /* Verify this implementation */
*size = COMM_FEATURE_DATA_SIZE;
**data = 0x00; *(++(*data)) = 0x00;/* clear both feature bytes */
status = USB_Class_CDC_PSTN_Set_Comm_Feature(controller_ID,
setup_packet, data, size);
break;
case GET_LINE_CODING :
status = USB_Class_CDC_PSTN_Get_Line_Coding(controller_ID,
setup_packet, data, size);
break;
case SET_LINE_CODING :
status = USB_Class_CDC_PSTN_Set_Line_Coding(controller_ID,
setup_packet, data, size);
break;
case SET_CONTROL_LINE_STATE :
status = USB_Class_CDC_PSTN_Set_Ctrl_Line_State(controller_ID,
setup_packet, data, size);
break;
case SEND_BREAK :
status = USB_Class_CDC_PSTN_Send_Break(controller_ID,
setup_packet, data, size);
break;
default:
*size=0;
break;
}
}
else if((setup_packet->request_type & USB_REQUEST_CLASS_MASK) ==
USB_REQUEST_CLASS_VENDOR)
{
/* vendor specific request */
if(g_vendor_req_callback != NULL)
{
status = g_vendor_req_callback(controller_ID, setup_packet, data,
size);
}
}
return status;
}
/*****************************************************************************
* Global Functions
*****************************************************************************/
/**************************************************************************//*!
*
* @name USB_Class_CDC_Init
*
* @brief The function initializes the Device and Controller layer
*
* @param controller_ID: Controller ID
* @param cdc_class_callback: CDC Class Callback
* @param vendor_req_callback: vendor specific class request callback
* @param param_callback: PSTN Callback
*
* @return status
* USB_OK : When Successfull
* Others : Errors
******************************************************************************
* This function initializes the CDC Class layer and layers it is dependent upon
*****************************************************************************/
uint_8 USB_Class_CDC_Init (
uint_8 controller_ID, /* [IN] Controller ID */
USB_CLASS_CALLBACK cdc_class_callback, /* [IN] CDC Class Callback */
USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */
USB_CLASS_CALLBACK pstn_callback, /* [IN] PSTN Callback */
uint_8 bVregEn /* Enables or disables internal regulator */
)
{
uint_8 index,status = USB_OK;
USB_ENDPOINTS *usb_ep_data =
(USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
#ifndef COMPOSITE_DEV
/* Initialize the device layer*/
status = _usb_device_init(controller_ID, NULL,
(uint_8)(usb_ep_data->count+1), bVregEn);
/* +1 is for Control Endpoint */
if(status == USB_OK)
{
/* Initialize the generic class functions */
status = USB_Class_Init(controller_ID,USB_Class_CDC_Event,
USB_Other_Requests);
#endif
#if IMPLEMENT_QUEUING
for(index = 0; index < usb_ep_data->count; index++)
{
g_cdc_ep[index].endpoint = usb_ep_data->ep[index].ep_num;
g_cdc_ep[index].type = usb_ep_data->ep[index].type;
g_cdc_ep[index].bin_consumer = 0x00;
g_cdc_ep[index].bin_producer = 0x00;
}
#endif
#if PSTN_SUBCLASS_NOTIF_SUPPORT
/* Initialize the pstn subclass functions */
status = USB_Class_CDC_Pstn_Init(controller_ID,pstn_callback);
#endif
if(status == USB_OK)
{
/* save the callback pointer */
g_cdc_class_callback = cdc_class_callback;
/* save the callback pointer */
g_vendor_req_callback = vendor_req_callback;
}
#ifndef COMPOSITE_DEV
}
#endif
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_DeInit
*
* @brief The function de-initializes the Device and Controller layer
*
* @param controller_ID : Controller ID
*
* @return status:
* USB_OK : When Successfull
* Others : When Error
*
******************************************************************************
*This function de-initializes the CDC Class layer
*****************************************************************************/
uint_8 USB_Class_CDC_DeInit
(
uint_8 controller_ID /* [IN] Controller ID */
)
{
uint_8 status = USB_OK;
#ifdef COMPOSITE_DEV
UNUSED(controller_ID);
#endif
/* save the callback pointer */
g_cdc_class_callback = NULL;
/* free the vendor request callback pointer */
g_vendor_req_callback = NULL;
#ifndef COMPOSITE_DEV
/* call common class deinit function */
status = USB_Class_DeInit(controller_ID);
if(status == USB_OK)
/* Call device deinit function */
status = _usb_device_deinit();
#endif
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_Send_Data
*
* @brief This function is used to send data from CDC Class over send endpoints
*
* @param controller_ID : Controller ID
* @param ep_num : Endpoint number
* @param app_buff : Buffer to send
* @param size : Length of the transfer
*
* @return status
* USB_OK : When Successfull
* Others : Errors
******************************************************************************
* Helper function. Sends DATA over CIC and DIC Interfaces to Host
*****************************************************************************/
uint_8 USB_Class_CDC_Send_Data (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 ep_num, /* [IN] Endpoint Number */
uint_8_ptr app_buff, /* Pointer to Application Buffer */
USB_PACKET_SIZE size /* Size of Application Buffer */
)
{
uint_8 status = USB_OK;
#if IMPLEMENT_QUEUING
uint_8 index;
uint_8 producer, consumer;
USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
USB_Desc_Get_Endpoints(controller_ID);
/* map the endpoint num to the index of the endpoint structure */
for(index = 0; index < usb_ep_data->count; index++)
{
if(usb_ep_data->ep[index].ep_num == ep_num)
{
break;
}
}
producer = g_cdc_ep[index].bin_producer;
consumer = g_cdc_ep[index].bin_consumer;
if(((uint_8)(producer - consumer)) != (uint_8)(MAX_QUEUE_ELEMS))
{
/* the bin is not full*/
uint_8 queue_num = (uint_8)(producer % MAX_QUEUE_ELEMS);
/* put all send request parameters in the endpoint data structure */
g_cdc_ep[index].queue[queue_num].controller_ID = controller_ID;
g_cdc_ep[index].queue[queue_num].channel = ep_num;
g_cdc_ep[index].queue[queue_num].app_data.data_ptr = app_buff;
g_cdc_ep[index].queue[queue_num].app_data.data_size = size;
/* increment producer bin by 1*/
g_cdc_ep[index].bin_producer = ++producer;
if((uint_8)(producer - consumer) == (uint_8)1)
{
#endif
status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
#if IMPLEMENT_QUEUING
}
}
else /* bin is full */
{
status = USBERR_DEVICE_BUSY;
}
#endif
return status;
}
/* EOF */

View File

@@ -0,0 +1,202 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_cdc.h
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file contains USB stack CDC class layer API header function.
*
*****************************************************************************/
#ifndef _USB_CDC_H
#define _USB_CDC_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
#include "usb_descriptor.h"
#include "usb_class.h"
#include "usb_cdc_pstn.h"
#include "usb_devapi.h"
#ifdef COMPOSITE_DEV
#include "usb_composite.h"
#endif
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
/* Class specific request Codes */
#define SEND_ENCAPSULATED_COMMAND (0x00)
#define GET_ENCAPSULATED_RESPONSE (0x01)
#define SET_COMM_FEATURE (0x02)
#define GET_COMM_FEATURE (0x03)
#define CLEAR_COMM_FEATURE (0x04)
#define SET_AUX_LINE_STATE (0x10)
#define SET_HOOK_STATE (0x11)
#define PULSE_SETUP (0x12)
#define SEND_PULSE (0x13)
#define SET_PULSE_TIME (0x14)
#define RING_AUX_JACK (0x15)
#define SET_LINE_CODING (0x20)
#define GET_LINE_CODING (0x21)
#define SET_CONTROL_LINE_STATE (0x22)
#define SEND_BREAK (0x23)
#define SET_RINGER_PARAMS (0x30)
#define GET_RINGER_PARAMS (0x31)
#define SET_OPERATION_PARAM (0x32)
#define GET_OPERATION_PARAM (0x33)
#define SET_LINE_PARAMS (0x34)
#define GET_LINE_PARAMS (0x35)
#define DIAL_DIGITS (0x36)
#define SET_UNIT_PARAMETER (0x37)
#define GET_UNIT_PARAMETER (0x38)
#define CLEAR_UNIT_PARAMETER (0x39)
#define GET_PROFILE (0x3A)
#define SET_ETHERNET_MULTICAST_FILTERS (0x40)
#define SET_ETHERNET_POW_PATTER_FILTER (0x41)
#define GET_ETHERNET_POW_PATTER_FILTER (0x42)
#define SET_ETHERNET_PACKET_FILTER (0x43)
#define GET_ETHERNET_STATISTIC (0x44)
#define SET_ATM_DATA_FORMAT (0x50)
#define GET_ATM_DEVICE_STATISTICS (0x51)
#define SET_ATM_DEFAULT_VC (0x52)
#define GET_ATM_VC_STATISTICS (0x53)
#define MDLM_SPECIFIC_REQUESTS_MASK (0x7F)
/* Class Specific Notification Codes */
#define NETWORK_CONNECTION_NOTIF (0x00)
#define RESPONSE_AVAIL_NOTIF (0x01)
#define AUX_JACK_HOOK_STATE_NOTIF (0x08)
#define RING_DETECT_NOTIF (0x09)
#define SERIAL_STATE_NOTIF (0x20)
#define CALL_STATE_CHANGE_NOTIF (0x28)
#define LINE_STATE_CHANGE_NOTIF (0x29)
#define CONNECTION_SPEED_CHANGE_NOTIF (0x2A)
#define MDLM_SPECIFIC_NOTIF_MASK (0x5F)
/* Events to the Application */ /* 0 to 4 are reserved for class events */
#define USB_APP_CDC_CARRIER_DEACTIVATED (0x21)
#define USB_APP_CDC_CARRIER_ACTIVATED (0x22)
/* other macros */
#define NOTIF_PACKET_SIZE (0x08)
#define NOTIF_REQUEST_TYPE (0xA1)
/* macros for queuing */
#define MAX_QUEUE_ELEMS (4)
#if CIC_NOTIF_ELEM_SUPPORT
#define CIC_SEND_ENDPOINT CIC_NOTIF_ENDPOINT
#endif
#if DIC_ISOCHRONOUS_SETTING
#define DIC_SEND_ENDPOINT DIC_ISO_IN_ENDPOINT
#define DIC_RECV_ENDPOINT DIC_ISO_OUT_ENDPOINT
#else
#define DIC_SEND_ENDPOINT DIC_BULK_IN_ENDPOINT
#define DIC_RECV_ENDPOINT DIC_BULK_OUT_ENDPOINT
#endif
/******************************************************************************
* Types
*****************************************************************************/
#ifndef COMPOSITE_DEV
typedef struct _app_data_struct
{
uint_8_ptr data_ptr; /* pointer to buffer */
USB_PACKET_SIZE data_size; /* buffer size of endpoint */
}APP_DATA_STRUCT;
#endif
/* structure to hold a request in the endpoint queue */
typedef struct _usb_class_cdc_queue
{
uint_8 controller_ID; /* Controller ID */
uint_8 channel; /* Endpoint Number */
APP_DATA_STRUCT app_data; /* Application Data Structure */
}USB_CLASS_CDC_QUEUE, *PTR_USB_CLASS_CDC_QUEUE;
/* USB class cdc endpoint data */
typedef struct _usb_class_cdc_endpoint
{
uint_8 endpoint; /* endpoint num */
uint_8 type; /* type of endpoint (interrupt, bulk or isochronous) */
uint_8 bin_consumer;/* the num of queued elements */
uint_8 bin_producer;/* the num of de-queued elements */
USB_CLASS_CDC_QUEUE queue[MAX_QUEUE_ELEMS]; /* queue data */
}USB_CLASS_CDC_ENDPOINT;
/******************************************************************************
* Global Functions
*****************************************************************************/
extern uint_8 USB_Class_CDC_Init (
uint_8 controller_ID, /* [IN] Controller ID */
USB_CLASS_CALLBACK cdc_class_callback, /* [IN] CDC Class Callback */
USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */
USB_CLASS_CALLBACK pstn_callback, /* [IN] PSTN Callback */
uint_8 bVregEn /* Enables or disables internal regulator */
);
#ifdef COMPOSITE_DEV
extern uint_8 USB_CDC_Other_Requests(uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
#endif
extern uint_8 USB_Class_CDC_DeInit
(
uint_8 controller_ID
);
extern uint_8 USB_Class_CDC_Send_Data (
uint_8 controller_ID,
uint_8 ep_num,
uint_8_ptr buff_ptr,
USB_PACKET_SIZE size
);
#if CIC_NOTIF_ELEM_SUPPORT
#define USB_Class_CDC_Interface_CIC_Send_Data(a,b,c) \
USB_Class_CDC_Send_Data(a,CIC_SEND_ENDPOINT,b,c)
#endif
#define USB_Class_CDC_Interface_DIC_Send_Data(a,b,c) \
USB_Class_CDC_Send_Data(a,DIC_SEND_ENDPOINT,b,c)
#define USB_Class_CDC_Interface_DIC_Recv_Data(a,b,c) \
_usb_device_recv_data(a,DIC_RECV_ENDPOINT,b,c)
#define USB_Class_CDC_Interface_DIC_Get_Send_Buffer(a,b,c) \
_usb_device_get_send_buffer(a,DIC_SEND_ENDPOINT,b,c)
#define USB_Class_CDC_Periodic_Task USB_Class_Periodic_Task
#endif

View File

@@ -0,0 +1,398 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_cdc_pstn.c
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file contains USB CDC_PSTN Sub Class implementation.
*
*****************************************************************************/
/******************************************************************************
* Includes
*****************************************************************************/
#include "usb_cdc_pstn.h" /* USB CDC PSTN Sub Class Header File */
/*****************************************************************************
* Constant and Macro's
*****************************************************************************/
/*****************************************************************************
* Global Functions Prototypes
*****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/*****************************************************************************
* Local Types - None
*****************************************************************************/
/*****************************************************************************
* Local Functions Prototypes
*****************************************************************************/
/*****************************************************************************
* Local Variables
*****************************************************************************/
/* PSTN subclass callback pointer */
static USB_CLASS_CALLBACK g_pstn_callback = NULL;
/* data terminal equipment present or not */
static boolean g_dte_present = FALSE;
static uint_8 g_dte_status = 0; /* Status of DATA TERMINAL EQUIPMENT */
static uint_16 g_break_duration = 0; /* Length of time in milliseconds of the
break signal */
static uint_8 g_current_interface = 0;
static UART_BITMAP g_uart_bitmap;
#if CIC_NOTIF_ELEM_SUPPORT
static uint_8 g_serial_state_buf[NOTIF_PACKET_SIZE+UART_BITMAP_SIZE] =
{
NOTIF_REQUEST_TYPE,SERIAL_STATE_NOTIF,
0x00,0x00,/*wValue*/
0x00,0x00,/*interface - modifies*/
UART_BITMAP_SIZE,0x00,/* wlength*/
0x00,0x00 /*data initialized - modifies*/
};/*uart bitmap*/
#endif
/*****************************************************************************
* Local Functions
*****************************************************************************/
/*****************************************************************************
* Global Functions
*****************************************************************************/
/**************************************************************************//*!
*
* @name USB_Class_CDC_Pstn_Init
*
* @brief The function initializes the PSTN Module
*
* @param controller_ID : Controller ID
* @param callback : PSTN Callback
*
* @return error
* USB_OK : Always
******************************************************************************
* PSTN Sub Class Initialization routine
*****************************************************************************/
uint_8 USB_Class_CDC_Pstn_Init (
uint_8 controller_ID, /* [IN] Controller ID */
USB_CLASS_CALLBACK callback /* [IN] PSTN Callback */
)
{
uint_8 error = USB_OK;
UNUSED (controller_ID);
/* save input parameters */
g_pstn_callback = callback;
return error;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Get_Line_Coding
*
* @brief This function is called in response to GetLineCoding request
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data to be send
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : When Successfull
* USBERR_INVALID_REQ_TYPE: When request for
* invalid Interface is presented
******************************************************************************
* Calls application to receive Line Coding Information
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Get_Line_Coding (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data to be send */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{
uint_8 status;
UNUSED (size);
g_current_interface = (uint_8)setup_packet->index ;
status = USB_Desc_Get_Line_Coding(controller_ID, g_current_interface,
data);
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Set_Line_Coding
*
* @brief This function is called in response to SetLineCoding request
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : When Successfull
* USBERR_INVALID_REQ_TYPE : When request for invalid
* Interface is presented
******************************************************************************
* Calls Applciation to update Line Coding Information
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Set_Line_Coding (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{
uint_8 status;
UNUSED(data);
*size = 0;
g_current_interface = (uint_8)setup_packet->index ;
status = USB_Desc_Set_Line_Coding(controller_ID, g_current_interface,
(uint_8_ptr *)&setup_packet);
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Set_Ctrl_Line_State
*
* @brief This function is called in response to Set Control Line State
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : Always
******************************************************************************
* Updates Control Line State
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Set_Ctrl_Line_State (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{
UNUSED(data);
*size = 0;
g_dte_status = (uint_8)setup_packet->value ;
g_uart_bitmap._byte = 0x00; /* initialize */
/* activate/deactivate Tx carrier */
g_uart_bitmap.Bitmap_Uart.bTxCarrier = (g_dte_status &
CARRIER_ACTIVATION_CHECK) ? 1 : 0 ;
/* activate carrier and DTE */
g_uart_bitmap.Bitmap_Uart.bRxCarrier = (g_dte_status &
CARRIER_ACTIVATION_CHECK) ? 1 : 0 ;
/* Indicates to DCE if DTE is present or not */
g_dte_present = (boolean)((g_dte_status & DTE_PRESENCE_CHECK) ?
TRUE : FALSE);
UNUSED(g_dte_present);
#if CIC_NOTIF_ELEM_SUPPORT
/* Send Notification to Host - Parameter on Device side has changed */
USB_Class_CDC_PSTN_Send_Serial_State(controller_ID);
#endif
if(g_pstn_callback != NULL)
{
if(g_dte_status & CARRIER_ACTIVATION_CHECK)
{
g_pstn_callback(controller_ID, USB_APP_CDC_CARRIER_ACTIVATED,
NULL);
}
else
{
g_pstn_callback(controller_ID, USB_APP_CDC_CARRIER_DEACTIVATED,
NULL);
}
}
return USB_OK;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Send_Break
*
* @brief This function is called in response to Set Config request
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : Always
******************************************************************************
* Updates Break Duration Information from Host
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Send_Break (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{
UNUSED (controller_ID);
UNUSED (data);
*size = 0;
g_break_duration = setup_packet->value;
UNUSED(g_break_duration);
return USB_OK;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Get_Comm_Feature
*
* @brief This function is called in response to GetCommFeature request
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data to be send
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : When Successfull
* USBERR_INVALID_REQ_TYPE : When request for invalid
* Interface is presented
******************************************************************************
* Returns the status of the get comm feature request
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Get_Comm_Feature (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data to send */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{ uint_8 status;
status = USB_OK;
*size = COMM_FEATURE_DATA_SIZE;
g_current_interface = (uint_8)setup_packet->index ;
if(setup_packet->value == ABSTRACT_STATE_FEATURE)
{
status = USB_Desc_Get_Abstract_State(controller_ID,
g_current_interface, data);
}
else if(setup_packet->value == COUNTRY_SETTING_FEATURE)
{
status = USB_Desc_Get_Country_Setting(controller_ID,
g_current_interface, data);
}
else
{
*size = 0; /* for Reserved/Invalid Feature Selector Value */
}
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Set_Comm_Feature
*
* @brief This function is called in response to SetCommFeature request
*
* @param controller_ID : Controller ID
* @param setup_packet : Pointer to setup packet
* @param data : Pointer to Data
* @param size : Pointer to Size of Data
*
* @return status:
* USB_OK : When Successfull
* USBERR_INVALID_REQ_TYPE : When request for invalid
* Interface is presented
******************************************************************************
* Sets the comm feature specified by Host
*****************************************************************************/
uint_8 USB_Class_CDC_PSTN_Set_Comm_Feature (
uint_8 controller_ID, /* [IN] Controller ID */
USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
uint_8_ptr *data, /* [OUT] Pointer to Data */
USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
)
{
uint_8 status;
status = USB_OK;
*size = COMM_FEATURE_DATA_SIZE;
g_current_interface = (uint_8)setup_packet->index ;
if(setup_packet->value == ABSTRACT_STATE_FEATURE)
{
status = USB_Desc_Set_Abstract_State(controller_ID,
g_current_interface, data);
}
else if(setup_packet->value == COUNTRY_SETTING_FEATURE)
{
status = USB_Desc_Set_Country_Setting(controller_ID,
g_current_interface, data);
}
else
{
*size = 0; /* for Reserved/Invalid Feature Selector Value */
}
return status;
}
#if CIC_NOTIF_ELEM_SUPPORT
/**************************************************************************//*!
*
* @name USB_Class_CDC_PSTN_Send_Serial_State
*
* @brief This function is called to send serial state notification
*
* @param controller_ID : Controller ID
*
* @return NONE
******************************************************************************
* Returns the Serial State
*****************************************************************************/
void USB_Class_CDC_PSTN_Send_Serial_State (
uint_8 controller_ID /* [IN] Controller ID */
)
{
/* update array for current interface */
g_serial_state_buf[4] = g_current_interface;
/* Lower byte of UART BITMAP */
g_serial_state_buf[NOTIF_PACKET_SIZE+UART_BITMAP_SIZE-2] =
g_uart_bitmap._byte;
(void)USB_Class_CDC_Interface_CIC_Send_Data(controller_ID,
g_serial_state_buf, (NOTIF_PACKET_SIZE + UART_BITMAP_SIZE));
}
#endif

View File

@@ -0,0 +1,125 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_cdc_pstn.h
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file contains USB CDC_PSTN Sub Class API header function
*
*****************************************************************************/
#ifndef _USB_CDC_PSTN_H
#define _USB_CDC_PSTN_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "usb_cdc.h" /* USB CDC Class Header File */
/******************************************************************************
* Constants - None
*****************************************************************************/
#ifdef __MCF52xxx_H__
#pragma reverse_bitfields on
#endif
typedef struct _BITMAP_UART
{
uint_8 bRxCarrier : 1; /* Receive Carrier Activation Flag */
uint_8 bTxCarrier : 1; /* Transmit Carrier Activation Flag */
uint_8 bBreak : 1; /* Break Flag */
uint_8 bRingSignal : 1; /* Ring Signal Flag */
uint_8 bFraming : 1; /* Frame Flag */
uint_8 bParity : 1; /* Parity Flag */
uint_8 bOverRun : 1; /* OverRun Flag */
uint_8 reserved1 : 1; /* Reserved */
}BITMAP_UART;
#ifdef __MCF52xxx_H__
#pragma reverse_bitfields off
#endif
typedef union _UART_BITMAP
{
uint_8 _byte;
BITMAP_UART Bitmap_Uart;
}UART_BITMAP; /* UART STATE BITMAP */
/******************************************************************************
* Macro's
*****************************************************************************/
#define UART_BITMAP_SIZE (0x02)
#define ABSTRACT_STATE_FEATURE (0x01)
#define COUNTRY_SETTING_FEATURE (0x02)
#define CARRIER_ACTIVATION_CHECK (0x02)
#define DTE_PRESENCE_CHECK (0x01)
extern uint_8 USB_Class_CDC_Pstn_Init (
uint_8 controller_ID,
USB_CLASS_CALLBACK callback
);
extern uint_8 USB_Class_CDC_PSTN_Get_Line_Coding (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
extern uint_8 USB_Class_CDC_PSTN_Set_Line_Coding (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
extern uint_8 USB_Class_CDC_PSTN_Set_Ctrl_Line_State (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
extern uint_8 USB_Class_CDC_PSTN_Send_Break (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
extern uint_8 USB_Class_CDC_PSTN_Get_Comm_Feature (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
extern uint_8 USB_Class_CDC_PSTN_Set_Comm_Feature (
uint_8 controller_ID,
USB_SETUP_STRUCT * setup_packet,
uint_8_ptr *data,
USB_PACKET_SIZE *size);
#if CIC_NOTIF_ELEM_SUPPORT
extern void USB_Class_CDC_PSTN_Send_Serial_State (uint_8 controller_ID);
#endif
#endif

View File

@@ -0,0 +1,493 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_class.c
*
* @author
*
* @version
*
* @date
*
* @brief The file contains USB stack Class module implementation.
*
*****************************************************************************/
/******************************************************************************
* Includes
*****************************************************************************/
#include "usb_class.h" /* USB class Header File */
#include "usb_devapi.h" /* USB device Header file */
#include "usb_framework.h" /* USB framework module header file */
#include "hidef.h" /* for EnableInterrupts; macro */
#if 0 /* << EST */
#if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
#include "exceptions.h"
#endif
#else
/* device is Kinetis K20D72 << EST */
#endif
/*****************************************************************************
* Constant and Macro's
*****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/* Class callback pointer */
static USB_CLASS_CALLBACK g_class_callback = NULL;
/* save the device state before device goes to suspend state */
static uint_8 g_device_state_before_suspend;
/*****************************************************************************
* Local Types - None
*****************************************************************************/
/*****************************************************************************
* Local Functions Prototypes
*****************************************************************************/
void USB_Suspend_Service (PTR_USB_DEV_EVENT_STRUCT event );
void USB_Resume_Service (PTR_USB_DEV_EVENT_STRUCT event );
void USB_Stall_Service (PTR_USB_DEV_EVENT_STRUCT event );
void USB_Sof_Service (PTR_USB_DEV_EVENT_STRUCT event );
void USB_Reset_Service (PTR_USB_DEV_EVENT_STRUCT event );
void USB_Error_Service (PTR_USB_DEV_EVENT_STRUCT event );
/*****************************************************************************
* Local Variables
*****************************************************************************/
/*****************************************************************************
* Local Functions - None
*****************************************************************************/
/*****************************************************************************
* Global Functions
*****************************************************************************/
#if 0 /* << EST */
#if (defined(_MC9S08MM128_H) || defined(_MC9S08JE128_H))
#pragma CODE_SEG DEFAULT
#endif
#else
/* device is Kinetis K20D72 << EST */
#endif
/**************************************************************************//*!
*
* @name USB_Suspend_Service
*
* @brief The function is called when host suspends the USB port
*
* @param event : Pointer to USB Event Structure
*
* @return None
******************************************************************************
* Sets the device state as USB_STATE_SUSPEND
*****************************************************************************/
void USB_Suspend_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
/* Get the status of the device before suspend, so that on resume we
can get back to the same state */
(void)_usb_device_get_status(&(event->controller_ID),
USB_STATUS_DEVICE_STATE, &g_device_state_before_suspend);
/* Set the device state in the Device Layer to SUSPEND */
(void)_usb_device_set_status(&(event->controller_ID), USB_STATUS_DEVICE_STATE,
USB_STATE_SUSPEND);
/* let the application know that bus suspend has taken place */
g_class_callback(event->controller_ID, USB_APP_BUS_SUSPEND, NULL);
return;
}
/**************************************************************************//*!
*
* @name USB_Resume_Service
*
* @brief The function is called when host resumes the USB port
*
* @param event : Pointer to USB Event Structure
*
* @return None
******************************************************************************
* Restore the state of the device before suspend
*****************************************************************************/
void USB_Resume_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
uint_8 device_state;
(void)_usb_device_get_status(&(event->controller_ID), USB_STATUS_DEVICE_STATE,
&device_state);
if(device_state == USB_STATE_SUSPEND)
{
/*
Set the device state in the Device Layer to the state
before suspend
*/
(void)_usb_device_set_status(&(event->controller_ID),
USB_STATUS_DEVICE_STATE, g_device_state_before_suspend);
}
/* let the application know that bus resume has taken place */
g_class_callback(event->controller_ID, USB_APP_BUS_RESUME, NULL);
return;
}
/**************************************************************************//*!
*
* @name USB_Stall_Service
*
* @brief The function is called when endpoint is stalled
*
* @param event: Pointer to USB Event Structure
*
* @return None
******************************************************************************
* This function sends STALL Packet for the endpoint to be stalled. Also, sets
* the status of Endpoint as STALLED
*****************************************************************************/
void USB_Stall_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
if(event->ep_num == CONTROL_ENDPOINT)
{
/* Update the Endpoint Status in the Device Layer to Idle */
(void)_usb_device_set_status(&(event->controller_ID),
(uint_8)(USB_STATUS_ENDPOINT | CONTROL_ENDPOINT |
(event->direction << USB_COMPONENT_DIRECTION_SHIFT)),
(uint_16)USB_STATUS_IDLE);
}
return;
}
/**************************************************************************//*!
*
* @name USB_Sof_Service
*
* @brief The function is called when SOF flag is set (from ISR)
*
* @param event: Pointer to USB Event Structure
*
* @return None
******************************************************************************
* This function is called when SOF token is received by controller. Updates
* SOF Count status.
*****************************************************************************/
void USB_Sof_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
uint_16 sof_count;
/* update SOF */
sof_count = event->buffer_ptr[0];
sof_count <<= SOF_HIGH_BYTE_SHIFT;
sof_count |= event->buffer_ptr[1];
/* write SOF to status */
(void)_usb_device_set_status(&(event->controller_ID), USB_STATUS_SOF_COUNT,
(uint_8)sof_count);
return;
}
/**************************************************************************//*!
*
* @name USB_Reset_Service
*
* @brief The function is called upon a bus reset event.
Initializes the control endpoint.
*
* @param event: Pointer to USB Event Structure
*
* @return None
******************************************************************************
* Reset Callback function. This function re-initializes CONTROL Endpoint
*****************************************************************************/
void USB_Reset_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
USB_EP_STRUCT ep_struct;
uint_8 err;
/* Initialize the endpoint 0 in both directions */
ep_struct.direction = USB_SEND;
ep_struct.ep_num = CONTROL_ENDPOINT;
ep_struct.size = CONTROL_MAX_PACKET_SIZE;
ep_struct.type = USB_CONTROL_PIPE;
/* Deinit Endpoint in case its already initialized */
err = _usb_device_deinit_endpoint(&(event->controller_ID),
ep_struct.ep_num, ep_struct.direction);
/* now initialize the endpoint */
err = _usb_device_init_endpoint(&(event->controller_ID),
ep_struct.ep_num, (uint_16)ep_struct.size, ep_struct.direction, ep_struct.type, TRUE);
ep_struct.direction = USB_RECV;
/* Deinit Endpoint in case its already initialized */
(void)_usb_device_deinit_endpoint(&(event->controller_ID),
ep_struct.ep_num, ep_struct.direction);
/* now initialize the endpoint */
(void)_usb_device_init_endpoint(&(event->controller_ID),
ep_struct.ep_num, (uint_16)ep_struct.size, ep_struct.direction, ep_struct.type, TRUE);
/* set the default device state */
(void)_usb_device_set_status(&(event->controller_ID), USB_STATUS_DEVICE_STATE,
USB_STATE_DEFAULT);
/* set the default device state */
(void)_usb_device_set_status(&(event->controller_ID), USB_STATUS_DEVICE,
SELF_POWERED >> SELF_POWER_BIT_SHIFT);
/* set the EndPoint Status as Idle in the device layer */
(void)_usb_device_set_status(&(event->controller_ID),
(uint_8)(USB_STATUS_ENDPOINT | CONTROL_ENDPOINT |
(USB_SEND << USB_COMPONENT_DIRECTION_SHIFT)),
USB_STATUS_IDLE);
/* let the application know that bus reset has taken place */
g_class_callback(event->controller_ID, USB_APP_BUS_RESET, NULL);
UNUSED(err);
return;
}
/**************************************************************************//*!
*
* @name USB_Error_Service
*
* @brief The function is called when an error has been detected
*
* @param event: Pointer to USB Event Structure
*
* @return None
******************************************************************************
* Calls application with the error code received from the lower layer
*****************************************************************************/
void USB_Error_Service (
PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
)
{
/* notify the application of the error */
g_class_callback(event->controller_ID, USB_APP_ERROR,
(uint_8*)(&(event->errors)));
return;
}
/**************************************************************************//*!
*
* @name USB_Class_Init
*
* @brief The function initializes the Class Module
*
* @param controller_ID : Controller ID
* @param class_callback : Class callback
* @param other_req_callback : Other Requests Callback
*
* @return status
* USB_OK : When Successfull
* Others : Errors
******************************************************************************
* Initializes USB Class Module
*****************************************************************************/
uint_8 USB_Class_Init (
uint_8 controller_ID, /* [IN] Controller ID */
USB_CLASS_CALLBACK class_callback, /* [IN] Class Callback */
USB_REQ_FUNC other_req_callback /* [IN] Other Requests Callback */
)
{
uint_8 status = USB_Framework_Init(controller_ID,class_callback,
other_req_callback);
/* save callback address */
g_class_callback = class_callback;
if(status == USB_OK)
{
/* Register all the services here */
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_BUS_RESET, USB_Reset_Service);
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_SOF,USB_Sof_Service);
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_SLEEP,USB_Suspend_Service);
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_RESUME,USB_Resume_Service);
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_STALL,USB_Stall_Service);
status |= _usb_device_register_service(controller_ID,
USB_SERVICE_ERROR,USB_Error_Service);
/* set the device state as powered */
(void)_usb_device_set_status(&controller_ID,
USB_STATUS_DEVICE_STATE,USB_STATE_POWERED);
g_device_state_before_suspend = USB_STATE_POWERED;
}
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_DeInit
*
* @brief The function De-initializes the Class Module
*
* @param controller_ID : Controller ID
*
* @return status
* USB_OK : When Successfull
* Others : Errors
******************************************************************************
* De-initializes USB Class Module
*****************************************************************************/
uint_8 USB_Class_DeInit
(
uint_8 controller_ID /* [IN] Controller ID */
)
{
uint_8 status = USB_OK;
/* Free class_callback */
g_class_callback = NULL;
/* Unegister all the services here */
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_BUS_RESET);
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_SOF);
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_SLEEP);
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_RESUME);
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_STALL);
status |= _usb_device_unregister_service(&controller_ID,USB_SERVICE_ERROR);
if(status == USB_OK)
/* Call Framework deinit function */
status = USB_Framework_DeInit(controller_ID);
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_Initiate_Resume
*
* @brief The function initiates resume procedure
*
* @param controller_ID : Controller ID
*
* @return device_state
******************************************************************************/
uint_8 USB_Class_Initiate_Resume(
uint_8 controller_ID /* [IN] Controller ID */
)
{
uint_8 device_state, state;
(void)_usb_device_get_status(&controller_ID, USB_STATUS_DEVICE_STATE,
&device_state);
(void)_usb_device_get_status(&controller_ID, USB_STATUS_DEVICE, &state);
if((device_state == USB_STATE_SUSPEND) &&
(state & REMOTE_WAKEUP_STATUS_MASK ) &&
(USB_Frame_Remote_Wakeup(controller_ID) == TRUE))
{
DisableInterrupts;
#if 0
#if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
usb_int_dis();
#endif
#else /* << EST */
/* device is Kinetis K20D72 << EST */
#endif
/* Resume the bus */
_usb_device_assert_resume(&controller_ID);
device_state = USB_STATE_CONFIG;
/* Set the device state in the Device Layer to DEFAULT */
(void)_usb_device_set_status(&controller_ID, USB_STATUS_DEVICE_STATE,
USB_STATE_CONFIG);
EnableInterrupts;;
#if (defined _MCF51MM256_H) || (defined _MCF51JE256_H)
usb_int_en();
#endif
}
return device_state;
}
/**************************************************************************//*!
*
* @name USB_Class_Send_Data
*
* @brief The function calls the device to send data upon receiving an IN token
*
* @param controller_ID : Controller ID
* @param ep_num : Endpoint number
* @param buff_ptr : Buffer to send
* @param size : Length of transfer
*
* @return status
* USB_OK : When Successfull
* Others : Errors
******************************************************************************
* Used by Application to send Data on USB Bus if not suspended
*****************************************************************************/
uint_8 USB_Class_Send_Data (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 ep_num, /* [IN] Endpoint number */
uint_8_ptr buff_ptr, /* [IN] Buffer to send */
USB_PACKET_SIZE size /* [IN] Length of the transfer */
)
{
uint_8 status = USB_OK;
uint_8 device_state;
device_state = USB_Class_Initiate_Resume(controller_ID);
if(device_state != USB_STATE_SUSPEND)
{ /* if not suspended */
status = _usb_device_send_data(&controller_ID, ep_num, buff_ptr, size);
}
return status;
}
/**************************************************************************//*!
*
* @name USB_Class_Periodic_Task
*
* @brief The function calls for periodic tasks
*
* @param None
*
* @return None
******************************************************************************
* Called to check for any pending requests
*****************************************************************************/
void USB_Class_Periodic_Task (void)
{
#ifdef DELAYED_PROCESSING
USB_Framework_Periodic_Task();
#endif
}

View File

@@ -0,0 +1,151 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_class.h
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file contains USB stack class layer API header function.
*
*****************************************************************************/
#ifndef _USB_CLASS_H
#define _USB_CLASS_H
/*#define DELAYED_PROCESSING 1 This define is used to delay the control
processing and not have it executed as part
of the interrupt routine */
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
#include "usb_devapi.h"
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
#define SOF_HIGH_BYTE_SHIFT (8)
#define GET_STATUS_DEVICE_MASK (0x0003)
#ifdef OTG_BUILD
#define GET_STATUS_OTG_MASK (0x0001)
#endif
#define REMOTE_WAKEUP_STATUS_MASK (0x0002)
#define BUS_POWERED (0x80)
#define SELF_POWERED (0x40)
#define SELF_POWER_BIT_SHIFT (6)
/* Events to the Application */
#define USB_APP_BUS_RESET (0)
#define USB_APP_CONFIG_CHANGED (1)
#define USB_APP_ENUM_COMPLETE (2)
#define USB_APP_SEND_COMPLETE (3)
#define USB_APP_DATA_RECEIVED (4)
#define USB_APP_ERROR (5)
#define USB_APP_GET_DATA_BUFF (6)
#define USB_APP_EP_STALLED (7)
#define USB_APP_EP_UNSTALLED (8)
#define USB_APP_GET_TRANSFER_SIZE (9)
#define USB_APP_BUS_SUSPEND (0x0A)
#define USB_APP_BUS_RESUME (0x0B)
/* max packet size for the control endpoint */
/* USB Specs define CONTROL_MAX_PACKET_SIZE for High Speed device as only 64,
whereas for FS its allowed to be 8, 16, 32 or 64 */
#if HIGH_SPEED_DEVICE
#define CONTROL_MAX_PACKET_SIZE (64) /* max supported value is 64*/
#else
#define CONTROL_MAX_PACKET_SIZE (16) /* max supported value is 16*/
#endif
/* identification values and masks to identify request types */
#define USB_REQUEST_CLASS_MASK (0x60)
#define USB_REQUEST_CLASS_STRD (0x00)
#define USB_REQUEST_CLASS_CLASS (0x20)
#define USB_REQUEST_CLASS_VENDOR (0x40)
/******************************************************************************
* Types
*****************************************************************************/
/* eight byte usb setup packet structure */
typedef struct _USB_SETUP_STRUCT {
uint_8 request_type; /* bmRequestType */
uint_8 request; /* Request code */
uint_16 value; /* wValue */
uint_16 index; /* wIndex */
uint_16 length; /* Length of the data */
} USB_SETUP_STRUCT;
/* callback function pointer structure for Application to handle events */
typedef void(_CODE_PTR_ USB_CLASS_CALLBACK)(uint_8, uint_8, void*);
/* callback function pointer structure to handle USB framework request */
typedef uint_8 (_CODE_PTR_ USB_REQ_FUNC)(uint_8, USB_SETUP_STRUCT *,
uint_8_ptr*,
USB_PACKET_SIZE*);
/*callback function pointer structure for application to provide class params*/
typedef uint_8 (_CODE_PTR_ USB_CLASS_SPECIFIC_HANDLER_FUNC)(
uint_8,
uint_16,
uint_16, // Application needs to know which Interface is being communicated with
uint_8_ptr*,
USB_PACKET_SIZE*);
/******************************************************************************
* Global Functions
*****************************************************************************/
extern uint_8 USB_Class_Init (
uint_8 controller_ID,
USB_CLASS_CALLBACK class_callback,
USB_REQ_FUNC other_req_callback
);
extern uint_8 USB_Class_DeInit
(
uint_8 controller_ID
);
extern uint_8 USB_Class_Initiate_Resume(
uint_8 controller_ID
);
extern uint_8 USB_Class_Send_Data (
uint_8 controller_ID,
uint_8 ep_num,
uint_8_ptr buff_ptr,
USB_PACKET_SIZE size
);
extern void USB_Class_Periodic_Task(void);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,311 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_dci_kinetis.h
*
* @author
*
* @version
*
* @date
*
* @brief The file contains Macro's and functions needed by the DCI layer.
*
*****************************************************************************/
#ifndef _USB_DCI_H
#define _USB_DCI_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
#include "hal/derivative.h"
#include "usb_devapi.h"
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
#define BYTES_1024 (1024)
#define BYTES_512 (512)
#define ENDPT_EP_STALL_MASK (0x02)
#define FRAME_HIGH_BYTE_SHIFT (8)
#ifdef USB_LOWPOWERMODE
typedef enum _stopmode
{
STOP_MODE1 = 1, /* STOP MODE 1 */
STOP_MODE2 = 2, /* STOP MODE 2 */
STOP_MODE3 = 3, /* STOP MODE 3 */
STOP_MODE4 = 4 /* STOP MODE 4 */
}STOP_MODE;
#endif
/* USBTRC0 Initialization Parameters */
#define _USBPHYEN (0x01) /* Use internal transceiver */
#define _USBPUEN (0x40) /* Use internal pull-up resistor */
#define _USBREGEN (0x04) /* Use the internal regulator */
#define _USBRESET (0x80)
#define UCFG_VAL (_USBPUEN|_USBREGEN)
#define CTL_RESET_VAL (0) /* value programmed to the CTL
register in RESET */
#define EP_CTRL (0x0C) /* Cfg Control pipe for this endpoint */
// HIGH_SPEED_DEVICE
#if !HIGH_SPEED_DEVICE
#define EP_OUT (0x08) /* Cfg OUT only pipe for this endpoint*/
#define EP_IN (0x04) /* Cfg IN only pipe for this endpoint */
#endif
#define HSHK_EN (0x01) /* Enable handshake packet */
/* Handshake should be disable for
isochorous transfer */
#define EP_CTL_DIS (0x10)
#define EP_DISABLE (0)
#define TRANSFER_INDEX(x) (x>>1)
#define MAX_EP_BUFFER_SIZE USB_MAX_EP_BUFFER_SIZE /*Max Endpoint Buffer Size*/
/* Macro's to check whether corresponding INT_STAT bit is set */
#define BUS_RESET_FLAG(x) ((x) & 1)
#define ERROR_FLAG(x) ((x) & 2)
#define SOF_TOKEN_FLAG(x) ((x) & 4)
#define SLEEP_FLAG(x) ((x) & 0x10)
#define RESUME_FLAG(x) ((x) & 0x20)
#define STALL_FLAG(x) ((x) & 0x80)
#define TOKEN_COMPL_FLAG(x) ((x) & 8)
/* Setup the controller for Remote Wakeup */
#define USB_DCI_WAKEUP \
{ \
USB0_ISTAT |= USB_ISTAT_RESUME_MASK; \
USB0_INTEN &= ~USB_INTEN_RESUMEEN_MASK; \
USB0_CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK; \
}
/* control endpoint transfer types */
#define USB_TRF_UNKNOWN (0xFF)
#define BDT_MIN_BUFFER_SIZE (16) /* space occupied by smallest
buffer in BDT */
#define BDT_MIN_BUFFER_ADDR_INC (4) /* min offset increment
correspoding to min buffer
size */
#define BDT_OFFSET_SHIFT (4) /* bdt offset shift */
#define INVALID_BDT_INDEX (0xFF)/* invalid bdt index */
#define ENDPOINT_NUMBER_SHIFT (4) /* endpoint shift & mask to */
#define ENDPOINT_NUMBER_MASK (0xF0)/* use in setting and getting
status */
#define ENDPOINT_DIRECTION_SHIFT (3) /* direction shift & mask to */
#define ENDPOINT_DIRECTION_MASK (0x08)/* be used for STAT byte
in BDT */
#define SEND_CONTROL_ENDPOINT_BDT_INDEX (2) /* BDT Index for Control Endpoint
SEND direction */
#define RECV_CONTROL_ENDPOINT_BDT_INDEX (0) /* BDT Index for Control Endpoint
RECV direction */
#define EPCTL_STALL (0x02)/* Stall bit in Endpoint
Control Reg */
#define USB_SETUP_TOKEN (0x0d)/* Setup Token PID */
#define USB_SETUP_DIRECTION (0x80)/* Data xfer direction
for Setup packet */
#define INT_STAT_CLEAR_ALL (0xBF)/* Value to clear
all Interrupts */
#define ERR_STAT_CLEAR_ALL (0xBF)/* Value to clear
all Errors */
#define ERR_ENB_ENABLE_ALL (0xBF)/* Value to enable
all Error Interrupts */
#define INTENB_BUS_RESET_VAL (0x9F)/* Value to enable
Interrupts in Bus Reset */
#define INTENB_DISABLE_ALL_VAL (0x00)/* Value to disable all
Interrupts */
#define MAX_USB_RAM_BUFFER_INDEX (14) /* MAX possible RAM buffer
Index */
#define EP_START_BUFFER_ADDR (0x08)/* First USB_RAM buffer offset*/
#define ASSERT_RESUME_DELAY_COUNT (20000)/* Delay for assert resume, 48MHz clock */
#define NO_ERRORS (0) /* Init value for error */
#define USB_RAM_EVEN_BUFFER (0)
#define USB_RAM_ODD_BUFFER (1)
#define SWAP16(val) (val)
#define SWAP32(val) (val)
/******************************************************************************
* Types
*****************************************************************************/
#ifdef LONG_SEND_TRANSACTION
#define LONG_TRANSACTION
#endif
#ifdef LONG_RECEIVE_TRANSACTION
#define LONG_TRANSACTION
#endif
typedef union {
uint_8 Byte;
struct {
uint_8 EP_HSHK :1; /* When set this bet enables an endpoint to perform handshaking during a transaction to this endpoint. This bit will generally be set unless the endpoint is Isochronous */
uint_8 EP_STALL :1; /* When set this bit indicates that the endpoint is stalled */
uint_8 EP_TX_EN :1; /* This bit, when set, enables the endpoint for TX transfers */
uint_8 EP_RX_EN :1; /* This bit, when set, enables the endpoint for RX transfers */
uint_8 EP_CTRL_DIS :1; /* This bit, when set, disables control (SETUP) transfers. When cleared, control transfers are enabled. This applies if and only if the EP_RX_EN and EP_TX_EN bits are also set */
uint_8 :1;
uint_8 RETRY_DIS :1; /* This is a Host mode only bit and is only present in the control register for endpoint 0 (ENDPT0) */
uint_8 HOST_WO_HUB :1; /* This is a Host mode only bit and is only present in the control register for endpoint 0 (ENDPT0) */
} Bits;
} ENDPT0STR;
/* << EST pushing current packing */
#pragma pack(push)
#pragma pack(1)
/* This structure is used to hold endpoint paramaetes and the
transaction parameters on the IO's happening on them */
typedef struct _BDT_ELEM
{
uint_16 len; /* endpoint max buffer len */
uint_32 addr; /* endpoint buffer addr in USB_RAM */
#ifdef LONG_TRANSACTION
uint_8_ptr app_buffer; /* application buffer pointer */
USB_PACKET_SIZE app_len; /* application buffer len */
USB_PACKET_SIZE curr_offset; /* current offset for long transactions */
#endif
uint_8 flag; /* zero termination flag */
uint_8 bdtmap_index; /* Corresponding to the buffer */
uint_8 direction; /* Direction (Send/Receive) */
uint_8 type; /* Type of Endpoint */
} BDT_ELEM, *P_BDT_ELEM;
#if defined(__CWCC__)
#pragma options align = reset
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma pack()
#else /* gcc */
/* << EST restoring previous packing */
#pragma pack(pop)
#endif
uint_8 USB_DCI_DeInit(void);
/*****************************************************************************
* Global Functions
*****************************************************************************/
//extern uint_8 USB_Device_Call_Service(
// uint_8 type,
// PTR_USB_DEV_EVENT_STRUCT event
//);
#ifndef OTG_BUILD
void USB_ISR(void);
#endif
#if HIGH_SPEED_DEVICE
/* Device Queue Head and Device Transfer Descriptor Related Defination */
#define SIZE_OF_QHD 0x40
#define SIZE_OF_DTD0 0x20
#define SIZE_OF_DTD1 0x20
#define dTD_SIZE_EPIN (SIZE_OF_DTD0 + SIZE_OF_DTD1) //0x40
#define dTD_SIZE_EPOUT (SIZE_OF_DTD0 + SIZE_OF_DTD1) //0x40
#define BUFFER_USED_PER_EP ((SIZE_OF_QHD + dTD_SIZE_EPIN) +(SIZE_OF_QHD + dTD_SIZE_EPOUT)) //0x100
#define ZLT_ENABLE 0
#define ZLT_DISABLE 1
#define IOS_NOTSET 0
#define IOS_SET 1
#define IOC_NOTSET 0
#define IOC_SET 1
#define TERMINATE 1
#define NOT_TERMINATE 0
#define NO_STATUS 0
#define ACTIVE 0x00000080
#define EPOUT_COMPLETE 0x00000001
#define EPIN_COMPLETE 0x00010000
#define EPOUT_PRIME 0x00000001
#define EPIN_PRIME 0x00010000
#define EPOUT_ENABLE 0x00000080
#define EPIN_ENABLE 0x00800000
#define STALL_RX 0x00000001
#define STALL_TX 0x00010000
/* Maximum packet size defination */
#define MPS_8 8
#define MPS_64 64
/* enum for endpoint numbers */
enum {
EP0,
EP1,
EP2,
EP3,
EP4,
EP5
};
enum {
OUT,
IN
};
/* enum for data transfer type on endpoints */
enum {
CONTROL,
ISOCHRONOUS,
BULK,
INTERRUPT
};
/* Status of all transaction on USB */
typedef enum {
USB_SUCCESS,
USB_FAILURE,
USB_INVALID = -1 /* Always Keep this entry in last */
} usb_status_t;
/* USB Device State which are handled by DCD */
typedef enum {
USB_DEV_DUMMY_STATE,
USB_DEV_DEFAULT_STATE,
USB_DEV_ADDRESSED_STATE,
USB_DEV_CONFIGURED_STATE
} usb_state_t;
#endif // HIGH_SPEED_DEVICE
#endif

View File

@@ -0,0 +1,262 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
******************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************//*!
*
* @file usb_dciapi.h
*
* @author
*
* @version
*
* @date Jun-05-2009
*
* @brief The file contains DCI api function definetions .
*
*****************************************************************************/
#ifndef _USB_DCIAPI_H
#define _USB_DCIAPI_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
#include "usb_devapi.h"
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
#define MAX_SUPPORTED_ENDPOINTS (USB_SERVICE_MAX_EP + 1)
/* Maximum endpoints supported */
#define MIN_SUPPORTED_ENDPOINTS (1) /* Minimum endpoints supported */
#define DOUBLE_BUFFERED_ENPOINT_NUMBER (0) /* First double buffered endpoint */
#ifdef MCU_MK70F12
#define NUM_USB_CONTROLLERS (2)
#else
#define NUM_USB_CONTROLLERS (1)
#endif
/******************************************************************************
* Types
*****************************************************************************/
typedef enum USB_Controllers_t
{
MAX3353,
ULPI
}USB_Controllers_t;
#if HIGH_SPEED_DEVICE
typedef struct dqh_setup_t {
unsigned int dqh_word0;
unsigned int dqh_word1;
unsigned int dqh_word2;
unsigned int dqh_word3;
unsigned int dqh_word4;
unsigned int dqh_word5;
unsigned int dqh_word6;
unsigned int dqh_word7;
unsigned int dqh_word8;
unsigned int dqh_word9;
unsigned int dqh_word10;
unsigned int dqh_word11;
} dqh_setup_t;
typedef struct dtd_setup_t {
unsigned int dtd_word0;
unsigned int dtd_word1;
unsigned int dtd_word2;
unsigned int dtd_word3;
unsigned int dtd_word4;
unsigned int dtd_word5;
unsigned int dtd_word6;
unsigned int dtd_word7;
} dtd_setup_t;
typedef struct dqh_t {
unsigned int dqh_base;
unsigned int next_link_ptr;
unsigned int buffer_ptr0;
unsigned int buffer_ptr1;
unsigned int buffer_ptr2;
unsigned int buffer_ptr3;
unsigned int buffer_ptr4;
unsigned short total_bytes;
unsigned short mps;
unsigned short current_offset;
unsigned char zlt;
unsigned char ios;
unsigned char terminate;
unsigned char ioc;
unsigned char status;
unsigned char mult;
} dqh_t;
typedef struct dtd_t {
unsigned int dtd_base;
unsigned int next_link_ptr;
unsigned int buffer_ptr0;
unsigned int buffer_ptr1;
unsigned int buffer_ptr2;
unsigned int buffer_ptr3;
unsigned int buffer_ptr4;
unsigned short total_bytes;
unsigned short current_offset;
unsigned char terminate;
unsigned char ioc;
unsigned char status;
} dtd_t;
typedef struct {
unsigned int ep_dqh_base_addrs; /* Base Address of Queue Header */
unsigned int ep_dtd_base_addrs; /* Base Address of Transfer Descriptor */
unsigned int ep0_buffer_addrs; /* Buffer Addres for EP0 IN */
unsigned int buffer1_address; /* Buffer1 address for bulk transfer */
unsigned int buffer1_status; /* Status of Buffer1 */
unsigned int buffer2_address; /* Buffer2 address for bulk transfer */
unsigned int buffer2_status; /* Status of Buffer2 */
} buffer_map_t;
/* USB standard device request*/
typedef struct usb_standrd_device_request {
unsigned char bmRequestType;
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} usb_standard_device_request_t;
#endif // HIGH_SPEED_DEVICE
/*****************************************************************************
* Global Functions
*****************************************************************************/
extern uint_8 USB_DCI_Init(
uint_8 controller_ID,
uint_8 bVregEn
);
extern uint_8 USB_DCI_Init_EndPoint(
uint_8 controller_ID,
USB_EP_STRUCT_PTR ep_ptr,
boolean flag
);
extern uint_8 USB_DCI_Cancel_Transfer(
uint_8 controller_ID,
uint_8 ep_num,
uint_8 direction
);
extern uint_8 USB_DCI_Deinit_EndPoint(
uint_8 controller_ID,
uint_8 ep_num,
uint_8 direction
);
extern void USB_DCI_Stall_EndPoint(
uint_8 controller_ID,
uint_8 ep_num,
uint_8 direction
);
extern void USB_DCI_Unstall_EndPoint(
uint_8 controller_ID,
uint_8 ep_num,
uint_8 direction
);
extern void USB_DCI_Get_Setup_Data(
uint_8 controller_ID,
uint_8 ep_num,
uint8_ptr buff_ptr
);
extern uint_8 USB_DCI_Get_Transfer_Status(
uint_8 controller_ID,
uint_8 ep_num,
uint_8 direction
);
extern void USB_DCI_Clear_DATA0_Endpoint(
uint_8 ep_num,
uint_8 direction
);
extern uint_8 USB_DCI_Recv_Data(
uint_8 controller_ID,
uint_8 ep_num,
uint8_ptr buff_ptr,
USB_PACKET_SIZE size
);
extern uint_8 USB_DCI_Send_Data(
uint_8 controller_ID,
uint_8 ep_num,
uint8_ptr buff_ptr,
USB_PACKET_SIZE size
);
extern void USB_DCI_Set_Address(
uint_8 controller_ID,
uint_8 address
);
extern void USB_DCI_Shutdown(
uint_8 controller_ID
);
extern void USB_DCI_Assert_Resume(
uint_8 controller_ID
);
extern void Clear_Mem(uint_8* start_addr,uint_32 count, uint_8 val);
#define USB_DCI_Cancel_Transfer _usb_device_cancel_transfer
#define USB_DCI_Recv_Data _usb_device_recv_data
#define USB_DCI_Send_Data _usb_device_send_data
#define USB_DCI_Shutdown _usb_device_shutdown
#define USB_DCI_Stall_EndPoint _usb_device_stall_endpoint
#define USB_DCI_Unstall_EndPoint _usb_device_unstall_endpoint
#define USB_DCI_Get_Transfer_Status _usb_device_get_transfer_status
#define USB_DCI_Clear_DATA0_Endpoint _usb_device_clear_data0_endpoint
#define USB_DCI_Get_Setup_Data _usb_device_read_setup_data
#define USB_DCI_Set_Address _usb_device_set_address
#define USB_DCI_Assert_Resume _usb_device_assert_resume
#endif

View File

@@ -0,0 +1,889 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
**************************************************************************//*!
*
* @file usb_descriptor.c
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief This file contains USB descriptors for Virtual COM Loopback
* Application
*****************************************************************************/
/******************************************************************************
* Includes
*****************************************************************************/
#include "hal/derivative.h"
#include "types.h"
#include "usb_class.h"
#include "usb_descriptor.h"
#if (defined __MCF52xxx_H__)||(defined __MK_xxx_H__)
/* Put CFV2 descriptors in RAM */
#define USB_DESC_CONST
#else
#define USB_DESC_CONST const
#endif
/*****************************************************************************
* Constant and Macro's
*****************************************************************************/
/* structure containing details of all the endpoints used by this device */
USB_DESC_CONST USB_ENDPOINTS usb_desc_ep =
{
CDC_DESC_ENDPOINT_COUNT,
{
#if DATA_CLASS_SUPPORT
#if DIC_ISOCHRONOUS_SETTING
{
DIC_ISO_IN_ENDPOINT,
USB_ISOCHRONOUS_PIPE,
USB_SEND,
DIC_ISO_IN_ENDP_PACKET_SIZE
},
{
DIC_ISO_OUT_ENDPOINT,
USB_ISOCHRONOUS_PIPE,
USB_RECV,
DIC_ISO_OUT_ENDP_PACKET_SIZE
}
#else
{
DIC_BULK_IN_ENDPOINT,
USB_BULK_PIPE,
USB_SEND,
DIC_BULK_IN_ENDP_PACKET_SIZE
},
{
DIC_BULK_OUT_ENDPOINT,
USB_BULK_PIPE,
USB_RECV,
DIC_BULK_OUT_ENDP_PACKET_SIZE
}
#endif
#endif
#if CIC_NOTIF_ELEM_SUPPORT
,
{
CIC_NOTIF_ENDPOINT,
USB_INTERRUPT_PIPE,
USB_SEND,
CIC_NOTIF_ENDP_PACKET_SIZE
}
#endif
}
};
uint_8 USB_DESC_CONST g_device_descriptor[DEVICE_DESCRIPTOR_SIZE] =
{
DEVICE_DESCRIPTOR_SIZE, /* Device Descriptor Size */
USB_DEVICE_DESCRIPTOR, /* Device Type of descriptor */
0x00, 0x02, /* BCD USB version */
0x02, /* Device Class is indicated in
the interface descriptors */
0x00, /* Device Subclass is indicated
in the interface descriptors */
0x00, /* Device Protocol */
CONTROL_MAX_PACKET_SIZE, /* Max Packet size */
(0x2A3C&0xFF),((0x2A3C>>8)&0xFF), /* Vendor ID "Trinamic" */
(0x0700&0xFF),((0x0700>>8)&0xFF), /* "TRINAMIC Evaluation Device" */
0x02,0x00, /* BCD Device version */
0x01, /* Manufacturer string index */
0x02, /* Product string index */
0x00, /* Serial number string index */
0x01 /* Number of configurations */
};
uint_8 USB_DESC_CONST g_config_descriptor[CONFIG_DESC_SIZE] =
{
CONFIG_ONLY_DESC_SIZE, /* Configuration Descriptor Size */
USB_CONFIG_DESCRIPTOR, /* "Configuration" type of descriptor */
CONFIG_DESC_SIZE, 0x00, /* Total length of the Configuration descriptor */
(uint_8)(1+DATA_CLASS_SUPPORT),/*NumInterfaces*/
0x01, /* Configuration Value */
0x00, /* Configuration Description String Index*/
BUS_POWERED|SELF_POWERED|(REMOTE_WAKEUP_SUPPORT<<REMOTE_WAKEUP_SHIFT),
/* Attributes.support RemoteWakeup and self power*/
0x32, /* Current draw from bus -- 100mA*/
/* CIC INTERFACE DESCRIPTOR */
IFACE_ONLY_DESC_SIZE,
USB_IFACE_DESCRIPTOR,
0x00, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
CIC_ENDP_COUNT, /* management and notification(optional)element present */
0x02, /* Communication Interface Class */
CIC_SUBCLASS_CODE,
CIC_PROTOCOL_CODE,
0x00, /* Interface Description String Index*/
/* CDC Class-Specific descriptor */
0x05, /* size of Functional Desc in bytes */
USB_CS_INTERFACE, /* descriptor type*/
HEADER_FUNC_DESC,
0x10, 0x01, /* USB Class Definitions for CDC spec release number in BCD */
0x05, /* Size of this descriptor */
USB_CS_INTERFACE, /* descriptor type*/
CALL_MANAGEMENT_FUNC_DESC,
0x01,/*may use 0x03 */ /* device handales call management itself(D0 set)
and will process commands multiplexed over the data interface */
0x01, /* Indicates multiplexed commands are
handled via data interface */
0x04, /* Size of this descriptor */
USB_CS_INTERFACE, /* descriptor type*/
ABSTRACT_CONTROL_FUNC_DESC,
0x06, /*may use 0x0F */ /* Device Supports all commands for ACM - CDC
PSTN SubClass bmCapabilities */
0x05, /* size of Functional Desc in bytes */
USB_CS_INTERFACE, /* descriptor type*/
UNION_FUNC_DESC,
0x00, /* Interface Number of Control */
0x01 /* Interface Number of Subordinate (Data Class) Interface */
#if CIC_NOTIF_ELEM_SUPPORT /*Endpoint descriptor */
, /* Comma Added if NOTIF ELEM IS TO BE ADDED */
ENDP_ONLY_DESC_SIZE,
USB_ENDPOINT_DESCRIPTOR,
CIC_NOTIF_ENDPOINT|(USB_SEND << 7),
USB_INTERRUPT_PIPE,
CIC_NOTIF_ENDP_PACKET_SIZE, 0x00,
0x0A
#endif
#if DATA_CLASS_SUPPORT
, /* Comma Added if DATA_CLASS_DESC IS TO BE ADDED */
IFACE_ONLY_DESC_SIZE,
USB_IFACE_DESCRIPTOR,
(uint_8)(0x00+DATA_CLASS_SUPPORT), /* bInterfaceNumber */
0x00, /* bAlternateSetting */
DIC_ENDP_COUNT, /* notification element included */
0x0A, /* DATA Interface Class */
0x00, /* Data Interface SubClass Code */
DIC_PROTOCOL_CODE,
0x00, /* Interface Description String Index*/
#if ! DIC_ISOCHRONOUS_SETTING
/*Endpoint descriptor */
ENDP_ONLY_DESC_SIZE,
USB_ENDPOINT_DESCRIPTOR,
DIC_BULK_IN_ENDPOINT|(USB_SEND << 7),
USB_BULK_PIPE,
DIC_BULK_IN_ENDP_PACKET_SIZE, 0x00,
0x00,/* This value is ignored for Bulk ENDPOINT */
/*Endpoint descriptor */
ENDP_ONLY_DESC_SIZE,
USB_ENDPOINT_DESCRIPTOR,
DIC_BULK_OUT_ENDPOINT|(USB_RECV << 7),
USB_BULK_PIPE,
DIC_BULK_OUT_ENDP_PACKET_SIZE, 0x00,
0x00 /* This value is ignored for Bulk ENDPOINT */
#else
/*Endpoint descriptor */
ENDP_ONLY_DESC_SIZE,
USB_ENDPOINT_DESCRIPTOR,
DIC_ISO_IN_ENDPOINT|(USB_SEND << 7),
USB_ISOCHRONOUS_PIPE,
DIC_ISO_IN_ENDP_PACKET_SIZE, 0x00,
0x01,/* This value is for Iso ENDPOINT */
/*Endpoint descriptor */
ENDP_ONLY_DESC_SIZE,
USB_ENDPOINT_DESCRIPTOR,
DIC_ISO_OUT_ENDPOINT|(USB_RECV << 7),
USB_ISOCHRONOUS_PIPE,
DIC_ISO_OUT_ENDP_PACKET_SIZE, 0x00,
0x01 /* This value is for Iso ENDPOINT */
#endif
#endif
};
uint_8 USB_DESC_CONST USB_STR_0[USB_STR_0_SIZE+USB_STR_DESC_SIZE] =
{sizeof(USB_STR_0),
USB_STRING_DESCRIPTOR,
0x09,
0x04/*equiavlent to 0x0409*/
};
uint_8 USB_DESC_CONST USB_STR_1[USB_STR_1_SIZE+USB_STR_DESC_SIZE]
= { sizeof(USB_STR_1),
USB_STRING_DESCRIPTOR,
'T',0,
'R',0,
'I',0,
'N',0,
'A',0,
'M',0,
'I',0,
'C',0,
' ',0,
'M',0,
'o',0,
't',0,
'i',0,
'o',0,
'n',0,
' ',0,
'C',0,
'o',0,
'n',0,
't',0,
'r',0,
'o',0,
'l',0,
' ',0,
' ',0,
' ',0,
' ',0,
' ',0
};
uint_8 USB_DESC_CONST USB_STR_2[USB_STR_2_SIZE+USB_STR_DESC_SIZE]
= { sizeof(USB_STR_2),
USB_STRING_DESCRIPTOR,
'E',0,
'v',0,
'a',0,
'l',0,
'u',0,
'a',0,
't',0,
'i',0,
'o',0,
'n',0,
' ',0,
'D',0,
'e',0,
'v',0,
'i',0,
'c',0,
'e',0,
' ',0
};
uint_8 USB_DESC_CONST USB_STR_n[USB_STR_n_SIZE+USB_STR_DESC_SIZE]
= { sizeof(USB_STR_n),
USB_STRING_DESCRIPTOR,
'B',0,
'A',0,
'D',0,
' ',0,
'S',0,
'T',0,
'R',0,
'I',0,
'N',0,
'G',0,
' ',0,
'I',0,
'N',0,
'D',0,
'E',0,
'X',0
};
USB_PACKET_SIZE const g_std_desc_size[USB_MAX_STD_DESCRIPTORS+1] =
{0,
DEVICE_DESCRIPTOR_SIZE,
CONFIG_DESC_SIZE,
0, /* string */
0, /* Interface */
0, /* Endpoint */
0, /* Device Qualifier */
0 /* other speed config */
};
uint_8_ptr const g_std_descriptors[USB_MAX_STD_DESCRIPTORS+1] =
{
NULL,
(uint_8_ptr)g_device_descriptor,
(uint_8_ptr)g_config_descriptor,
NULL, /* string */
NULL, /* Interface */
NULL, /* Endpoint */
NULL, /* Device Qualifier */
NULL /* other speed config*/
};
uint_8 const g_string_desc_size[USB_MAX_STRING_DESCRIPTORS+1] =
{
sizeof(USB_STR_0),
sizeof(USB_STR_1),
sizeof(USB_STR_2),
sizeof(USB_STR_n)
};
uint_8_ptr const g_string_descriptors[USB_MAX_STRING_DESCRIPTORS+1] =
{
(uint_8_ptr)USB_STR_0,
(uint_8_ptr)USB_STR_1,
(uint_8_ptr)USB_STR_2,
(uint_8_ptr)USB_STR_n
};
#ifdef __HC08__ /* << EST */
#pragma MESSAGE DISABLE C4800 /* implicit cast in assignment */
#endif
USB_ALL_LANGUAGES g_languages = { USB_STR_0, sizeof(USB_STR_0),
{
{
(uint_16)0x0409,
(const uint_8 **) (unsigned long) g_string_descriptors, // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
g_string_desc_size
}
}
};
#ifdef __HC08__ /* << EST */
#pragma MESSAGE DEFAULT C4800
#endif
uint_8 const g_valid_config_values[USB_MAX_CONFIG_SUPPORTED+1]={0,1};
/****************************************************************************
* Global Variables
****************************************************************************/
#ifdef _MC9S08JS16_H
#pragma DATA_SEG APP_DATA
#endif
static uint_8 g_line_coding[USB_MAX_SUPPORTED_INTERFACES][LINE_CODING_SIZE] =
{
{ (LINE_CODE_DTERATE_IFACE0>> 0) & 0x000000FF,
(LINE_CODE_DTERATE_IFACE0>> 8) & 0x000000FF,
(LINE_CODE_DTERATE_IFACE0>>16) & 0x000000FF,
(LINE_CODE_DTERATE_IFACE0>>24) & 0x000000FF,
/*e.g. 0x00,0xC2,0x01,0x00 : 0x0001C200 is 115200 bits per second */
LINE_CODE_CHARFORMAT_IFACE0,
LINE_CODE_PARITYTYPE_IFACE0,
LINE_CODE_DATABITS_IFACE0
}
};
static uint_8 g_abstract_state[USB_MAX_SUPPORTED_INTERFACES][COMM_FEATURE_DATA_SIZE] =
{
{ (STATUS_ABSTRACT_STATE_IFACE0>>0) & 0x00FF,
(STATUS_ABSTRACT_STATE_IFACE0>>8) & 0x00FF
}
};
static uint_8 g_country_code[USB_MAX_SUPPORTED_INTERFACES][COMM_FEATURE_DATA_SIZE] =
{
{ (COUNTRY_SETTING_IFACE0>>0) & 0x00FF,
(COUNTRY_SETTING_IFACE0>>8) & 0x00FF
}
};
static uint_8 g_alternate_interface[USB_MAX_SUPPORTED_INTERFACES];
/*****************************************************************************
* Local Types - None
*****************************************************************************/
/*****************************************************************************
* Local Functions Prototypes
*****************************************************************************/
/*****************************************************************************
* Local Variables - None
*****************************************************************************/
/*****************************************************************************
* Local Functions - None
*****************************************************************************/
/*****************************************************************************
* Global Functions
*****************************************************************************/
/**************************************************************************//*!
*
* @name USB_Desc_Get_Descriptor
*
* @brief The function returns the correponding descriptor
*
* @param controller_ID : Controller ID
* @param type : type of descriptor requested
* @param sub_type : string index for string descriptor
* @param index : string descriptor language Id
* @param descriptor : output descriptor pointer
* @param size : size of descriptor returned
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* This function is used to pass the pointer to the requested descriptor
*****************************************************************************/
uint_8 USB_Desc_Get_Descriptor (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 type, /* [IN] type of descriptor requested */
uint_8 str_num, /* [IN] string index for string descriptor */
uint_16 index, /* [IN] string descriptor language Id */
uint_8_ptr *descriptor, /* [OUT] output descriptor pointer */
USB_PACKET_SIZE *size /* [OUT] size of descriptor returned */
)
{
UNUSED (controller_ID);
/* string descriptors are handled saperately */
if(type == USB_STRING_DESCRIPTOR)
{
if(index == 0)
{
/* return the string and size of all languages */
*descriptor = (uint_8_ptr) (unsigned long) g_languages.languages_supported_string; // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
*size = g_languages.languages_supported_size;
} else
{
uint_8 lang_id=0;
uint_8 lang_index=USB_MAX_LANGUAGES_SUPPORTED;
for(;lang_id< USB_MAX_LANGUAGES_SUPPORTED;lang_id++)
{
/* check whether we have a string for this language */
if(index == g_languages.usb_language[lang_id].language_id)
{ /* check for max descriptors */
if(str_num < USB_MAX_STRING_DESCRIPTORS)
{ /* setup index for the string to be returned */
lang_index=str_num;
}
break;
}
}
/* set return val for descriptor and size */
*descriptor = (uint_8_ptr) (unsigned long) g_languages.usb_language[lang_id]. // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
lang_desc[lang_index];
*size = g_languages.usb_language[lang_id].
lang_desc_size[lang_index];
}
}
else if(type < USB_MAX_STD_DESCRIPTORS+1)
{
/* Set return val for descriptor and size */
*descriptor = (uint_8_ptr) (unsigned long) g_std_descriptors [type]; // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
/* if there is no descriptor then return error */
if(*descriptor == NULL)
{
return USBERR_INVALID_REQ_TYPE;
}
*size = g_std_desc_size[type];
}
else /* invalid descriptor */
{
return USBERR_INVALID_REQ_TYPE;
}
return USB_OK;
}
/**************************************************************************//*!
*
* @name USB_Desc_Get_Interface
*
* @brief The function returns the alternate interface
*
* @param controller_ID : Controller Id
* @param interface : Interface number
* @param alt_interface : Output alternate interface
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* This function is called by the framework module to get the current interface
*****************************************************************************/
uint_8 USB_Desc_Get_Interface (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] interface number */
uint_8_ptr alt_interface /* [OUT] output alternate interface */
)
{
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* get alternate interface*/
*alt_interface = g_alternate_interface[interface];
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Set_Interface
*
* @brief The function sets the alternate interface
*
* @param controller_ID : Controller Id
* @param interface : Interface number
* @param alt_interface : Input alternate interface
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* This function is called by the framework module to set the interface
*****************************************************************************/
uint_8 USB_Desc_Set_Interface (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] interface number */
uint_8 alt_interface /* [IN] input alternate interface */
)
{
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* set alternate interface*/
g_alternate_interface[interface]=alt_interface;
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Valid_Configation
*
* @brief The function checks whether the configuration parameter
* input is valid or not
*
* @param controller_ID : Controller Id
* @param config_val : Configuration value
*
* @return TRUE When Valid
* FALSE When Error
*****************************************************************************
* This function checks whether the configuration is valid or not
*****************************************************************************/
boolean USB_Desc_Valid_Configation (
uint_8 controller_ID,/*[IN] Controller ID */
uint_16 config_val /*[IN] configuration value */
)
{
uint_8 loop_index=0;
UNUSED (controller_ID);
/* check with only supported val right now */
while(loop_index < (USB_MAX_CONFIG_SUPPORTED+1))
{
if(config_val == g_valid_config_values[loop_index])
{
return TRUE;
}
loop_index++;
}
return FALSE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Valid_Interface
*
* @brief The function checks whether the interface parameter
* input is valid or not
*
* @param controller_ID : Controller Id
* @param interface : Target interface
*
* @return TRUE When Valid
* FALSE When Error
*****************************************************************************
* This function checks whether the interface is valid or not
*****************************************************************************/
boolean USB_Desc_Valid_Interface (
uint_8 controller_ID, /*[IN] Controller ID */
uint_8 interface /*[IN] target interface */
)
{
uint_8 loop_index=0;
UNUSED (controller_ID);
/* check with only supported val right now */
while(loop_index < USB_MAX_SUPPORTED_INTERFACES)
{
if(interface == g_alternate_interface[loop_index])
{
return TRUE;
}
loop_index++;
}
return FALSE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Remote_Wakeup
*
* @brief The function checks whether the remote wakeup is supported or not
*
* @param controller_ID : Controller ID
*
* @return REMOTE_WAKEUP_SUPPORT (TRUE) - if remote wakeup supported
*****************************************************************************
* This function returns remote wakeup is supported or not
*****************************************************************************/
boolean USB_Desc_Remote_Wakeup (
uint_8 controller_ID /* [IN] Controller ID */
)
{
UNUSED (controller_ID);
return REMOTE_WAKEUP_SUPPORT;
}
/**************************************************************************//*!
*
* @name USB_Desc_Get_Endpoints
*
* @brief The function returns with the list of all non control endpoints used
*
* @param controller_ID : Controller ID
*
* @return pointer to USB_ENDPOINTS
*****************************************************************************
* This function returns the information about all the non control endpoints
* implemented
*****************************************************************************/
void* USB_Desc_Get_Endpoints (
uint_8 controller_ID /* [IN] Controller ID */
)
{
UNUSED (controller_ID);
return (void*) (unsigned long) &usb_desc_ep; // cast to unsigned long before properly casting to prevent gcc from complaining about cast from const to non-const
}
/**************************************************************************//*!
*
* @name USB_Desc_Get_Line_Coding
*
* @brief The function returns the Line Coding/Configuraion
*
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param coding_data : Output line coding data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Returns current Line Coding Parameters
*****************************************************************************/
uint_8 USB_Desc_Get_Line_Coding (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *coding_data /* [OUT] Line Coding Data */
)
{
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* get line coding data*/
*coding_data = g_line_coding[interface];
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Set_Line_Coding
*
* @brief The function sets the Line Coding/Configuraion
*
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param coding_data : Output line coding data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Sets Line Coding Structure with the HOST specified values
*****************************************************************************/
uint_8 USB_Desc_Set_Line_Coding (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *coding_data /* [IN] Line Coding Data */
)
{
uint_8 count;
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* set line coding data*/
for(count = 0; count < LINE_CODING_SIZE; count++)
{
g_line_coding[interface][count] = *((*coding_data +
USB_SETUP_PKT_SIZE) + count);
}
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Get_Abstract_State
*
* @brief The function gets the current setting for communication feature
* (ABSTRACT_STATE)
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param feature_data : Output comm feature data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Returns ABSTRACT STATE Communication Feature to the Host
*****************************************************************************/
uint_8 USB_Desc_Get_Abstract_State (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *feature_data /* [OUT] Output Comm Feature Data */
)
{
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* get line coding data*/
*feature_data = g_abstract_state[interface];
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Get_Country_Setting
*
* @brief The function gets the current setting for communication feature
* (COUNTRY_CODE)
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param feature_data : Output comm feature data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Returns the country Code to the Host
*****************************************************************************/
uint_8 USB_Desc_Get_Country_Setting (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *feature_data /* [OUT] Output Comm Feature Data */
)
{
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* get line coding data*/
*feature_data = g_country_code[interface];
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Set_Abstract_State
*
* @brief The function gets the current setting for communication feature
* (ABSTRACT_STATE)
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param feature_data : Output comm feature data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Sets the ABSTRACT State specified by the Host
*****************************************************************************/
uint_8 USB_Desc_Set_Abstract_State (
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *feature_data /* [OUT] Output Comm Feature Data */
)
{
uint_8 count;
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
/* set Abstract State Feature*/
for(count = 0; count < COMM_FEATURE_DATA_SIZE; count++)
{
g_abstract_state[interface][count] = *(*feature_data + count);
}
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}
/**************************************************************************//*!
*
* @name USB_Desc_Set_Country_Setting
*
* @brief The function gets the current setting for communication feature
* (COUNTRY_CODE)
* @param controller_ID : Controller ID
* @param interface : Interface number
* @param feature_data : Output comm feature data
*
* @return USB_OK When Successfull
* USBERR_INVALID_REQ_TYPE when Error
*****************************************************************************
* Sets the country code specified by the HOST
*****************************************************************************/
uint_8 USB_Desc_Set_Country_Setting(
uint_8 controller_ID, /* [IN] Controller ID */
uint_8 interface, /* [IN] Interface Number */
uint_8_ptr *feature_data /* [OUT] Output Comm Feature Data */
)
{
uint_8 count;
UNUSED (controller_ID);
/* if interface valid */
if(interface < USB_MAX_SUPPORTED_INTERFACES)
{
for(count = 0; count < COMM_FEATURE_DATA_SIZE; count++)
{
g_country_code[interface][count] = *(*feature_data + count);
}
return USB_OK;
}
return USBERR_INVALID_REQ_TYPE;
}

View File

@@ -0,0 +1,301 @@
/******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
**************************************************************************//*!
*
* @file usb_descriptor.h
*
* @author
*
* @version
*
* @date May-28-2009
*
* @brief The file is a header file for USB Descriptors required for Virtual
* COM Loopback Application
*****************************************************************************/
#ifndef _USB_DESCRIPTOR_H
#define _USB_DESCRIPTOR_H
/******************************************************************************
* Includes
*****************************************************************************/
#include "types.h"
#include "usb_class.h"
/******************************************************************************
* Constants - None
*****************************************************************************/
/******************************************************************************
* Macro's
*****************************************************************************/
#define REMOTE_WAKEUP_SUPPORT (FALSE)
#define DATA_CLASS_SUPPORT (TRUE)
#define CIC_NOTIF_ELEM_SUPPORT (TRUE) /* Mandatory */
#define DIC_ISOCHRONOUS_SETTING (FALSE)
#define IMPLEMENT_QUEUING (TRUE)
/* Communication Class SubClass Codes */
#define DIRECT_LINE_CONTROL_MODEL (0x01)
#define ABSTRACT_CONTROL_MODEL (0x02)
#define TELEPHONE_CONTROL_MODEL (0x03)
#define MULTI_CHANNEL_CONTROL_MODEL (0x04)
#define CAPI_CONTROL_MOPDEL (0x05)
#define ETHERNET_NETWORKING_CONTROL_MODEL (0x06)
#define ATM_NETWORKING_CONTROL_MODEL (0x07)
#define WIRELESS_HANDSET_CONTROL_MODEL (0x08)
#define DEVICE_MANAGEMENT (0x09)
#define MOBILE_DIRECT_LINE_MODEL (0x0A)
#define OBEX (0x0B)
#define ETHERNET_EMULATION_MODEL (0x0C)
/* Communication Class Protocol Codes */
#define NO_CLASS_SPECIFIC_PROTOCOL (0x00)
#define AT_250_PROTOCOL (0x01)
#define AT_PCCA_101_PROTOCOL (0x02)
#define AT_PCCA_101_ANNEX_O (0x03)
#define AT_GSM_7_07 (0x04)
#define AT_3GPP_27_007 (0x05)
#define AT_TIA_CDMA (0x06)
#define ETHERNET_EMULATION_PROTOCOL (0x07)
#define EXTERNAL_PROTOCOL (0xFE)
#define VENDOR_SPECIFIC (0xFF)
/* Data Class Protocol Codes */
/* #define NO_CLASS_SPECIFIC_PROTOCOL (0x00) */
#define PYHSICAL_INTERFACE_PROTOCOL (0x30)
#define HDLC_PROTOCOL (0x31)
#define TRANSPARENT_PROTOCOL (0x32)
#define MANAGEMENT_PROTOCOL (0x50)
#define DATA_LINK_Q931_PROTOCOL (0x51)
#define DATA_LINK_Q921_PROTOCOL (0x52)
#define DATA_COMPRESSION_V42BIS (0x90)
#define EURO_ISDN_PROTOCOL (0x91)
#define RATE_ADAPTION_ISDN_V24 (0x92)
#define CAPI_COMMANDS (0x93)
#define HOST_BASED_DRIVER (0xFD)
#define CDC_UNIT_FUNCTIONAL (0xFE)
/* #define VENDOR_SPECIFIC (0xFF) */
/* Descriptor SubType in Communications Class Functional Descriptors */
#define HEADER_FUNC_DESC (0x00)
#define CALL_MANAGEMENT_FUNC_DESC (0x01)
#define ABSTRACT_CONTROL_FUNC_DESC (0x02)
#define DIRECT_LINE_FUNC_DESC (0x03)
#define TELEPHONE_RINGER_FUNC_DESC (0x04)
#define TELEPHONE_REPORT_FUNC_DESC (0x05)
#define UNION_FUNC_DESC (0x06)
#define COUNTRY_SELECT_FUNC_DESC (0x07)
#define TELEPHONE_MODES_FUNC_DESC (0x08)
#define USB_TERMINAL_FUNC_DESC (0x09)
#define NETWORK_CHANNEL_FUNC_DESC (0x0A)
#define PROTOCOL_UNIT_FUNC_DESC (0x0B)
#define EXTENSION_UNIT_FUNC_DESC (0x0C)
#define MULTI_CHANNEL_FUNC_DESC (0x0D)
#define CAPI_CONTROL_FUNC_DESC (0x0E)
#define ETHERNET_NETWORKING_FUNC_DESC (0x0F)
#define ATM_NETWORKING_FUNC_DESC (0x10)
#define WIRELESS_CONTROL_FUNC_DESC (0x11)
#define MOBILE_DIRECT_LINE_FUNC_DESC (0x12)
#define MDLM_DETAIL_FUNC_DESC (0x13)
#define DEVICE_MANAGEMENT_FUNC_DESC (0x14)
#define OBEX_FUNC_DESC (0x15)
#define COMMAND_SET_FUNC_DESC (0x16)
#define COMMAND_SET_DETAIL_FUNC_DESC (0x17)
#define TELEPHONE_CONTROL_FUNC_DESC (0x18)
#define OBEX_SERVICE_ID_FUNC_DESC (0x19)
#define CIC_SUBCLASS_CODE ABSTRACT_CONTROL_MODEL
#define CIC_PROTOCOL_CODE NO_CLASS_SPECIFIC_PROTOCOL
#define DIC_PROTOCOL_CODE NO_CLASS_SPECIFIC_PROTOCOL
#define CIC_ENDP_COUNT (0+(CIC_NOTIF_ELEM_SUPPORT & 0x01) * 1)
#define DIC_ENDP_COUNT (2)
#define CIC_NOTIF_ENDPOINT (3)
#define CIC_NOTIF_ENDP_PACKET_SIZE (16)
#define DIC_BULK_IN_ENDPOINT (1)
#define DIC_BULK_IN_ENDP_PACKET_SIZE (16)/* max supported is 64 */
#define DIC_BULK_OUT_ENDPOINT (2)
#define DIC_BULK_OUT_ENDP_PACKET_SIZE (16)/* max supported is 64*/
#if DIC_ISOCHRONOUS_SETTING
#define DIC_ISO_IN_ENDPOINT (1)
#define DIC_ISO_IN_ENDP_PACKET_SIZE (64)
#define DIC_ISO_OUT_ENDPOINT (2)
#define DIC_ISO_OUT_ENDP_PACKET_SIZE (64)
#endif
#define REMOTE_WAKEUP_SHIFT (5)
/* Various descriptor sizes */
#define DEVICE_DESCRIPTOR_SIZE (18)
#define CONFIG_ONLY_DESC_SIZE (9)
#define CONFIG_DESC_SIZE (CONFIG_ONLY_DESC_SIZE + 28 + \
(CIC_NOTIF_ELEM_SUPPORT & 0x01) \
* 7 + DATA_CLASS_SUPPORT * 23)
#define DEVICE_QUALIFIER_DESCRIPTOR_SIZE (10)
#define IFACE_ONLY_DESC_SIZE (9)
#define ENDP_ONLY_DESC_SIZE (7)
/* Max descriptors provided by the Application */
#define USB_MAX_STD_DESCRIPTORS (7)
/* Max configuration supported by the Application */
#define USB_MAX_CONFIG_SUPPORTED (1)
/* Max string descriptors supported by the Application */
#define USB_MAX_STRING_DESCRIPTORS (3)
/* Max language codes supported by the USB */
#define USB_MAX_LANGUAGES_SUPPORTED (1)
/* string descriptors sizes */
#define USB_STR_DESC_SIZE (2)
#define USB_STR_0_SIZE (2)
#define USB_STR_1_SIZE (56)
#define USB_STR_2_SIZE (36)
#define USB_STR_n_SIZE (32)
/* descriptors codes */
#define USB_DEVICE_DESCRIPTOR (1)
#define USB_CONFIG_DESCRIPTOR (2)
#define USB_STRING_DESCRIPTOR (3)
#define USB_IFACE_DESCRIPTOR (4)
#define USB_ENDPOINT_DESCRIPTOR (5)
#define USB_DEVQUAL_DESCRIPTOR (6)
#define USB_CS_INTERFACE (0x24)
#define USB_CS_ENDPOINT (0x25)
#define USB_MAX_SUPPORTED_INTERFACES (2)
/* Implementation Specific Macros */
#define LINE_CODING_SIZE (0x07)
#define COMM_FEATURE_DATA_SIZE (0x02)
#define LINE_CODE_DTERATE_IFACE0 (115200) /*e.g 9600 is 0x00002580 */
#define LINE_CODE_CHARFORMAT_IFACE0 (0x00) /* 1 stop bit */
#define LINE_CODE_PARITYTYPE_IFACE0 (0x00) /* No Parity */
#define LINE_CODE_DATABITS_IFACE0 (0x08) /* Data Bits Format */
#define LINE_CODE_DTERATE_IFACE1 (9600) /*e.g. 115200 is 0x0001C200*/
#define LINE_CODE_CHARFORMAT_IFACE1 (0x00) /* 1 stop bit */
#define LINE_CODE_PARITYTYPE_IFACE1 (0x00) /* No Parity */
#define LINE_CODE_DATABITS_IFACE1 (0x08) /* Data Bits Format */
#define STATUS_ABSTRACT_STATE_IFACE0 (0x0000) /* Disable Multiplexing
ENDP in this interface will
continue to accept/offer data*/
#define STATUS_ABSTRACT_STATE_IFACE1 (0x0000) /* Disable Multiplexing
ENDP in this interface will
continue to accept/offer data*/
#define COUNTRY_SETTING_IFACE0 (0x0000) /* Country Code in the format as
defined in [ISO3166] */
#define COUNTRY_SETTING_IFACE1 (0x0000) /* Country Code in the format as
defined in [ISO3166] */
/* Notifications Support */
#define PSTN_SUBCLASS_NOTIF_SUPPORT (TRUE)
#define WMC_SUBCLASS_NOTIF_SUPPORT (FALSE)
#define CDC_CLASS_NOTIF_SUPPORT (FALSE)
#define CDC_DESC_ENDPOINT_COUNT (CIC_ENDP_COUNT+(DATA_CLASS_SUPPORT & 0x01) \
*DIC_ENDP_COUNT)
/******************************************************************************
* Types
*****************************************************************************/
typedef const struct _USB_LANGUAGE
{
uint_16 const language_id; /* Language ID */
uint_8 const ** lang_desc; /* Language Descriptor String */
uint_8 const * lang_desc_size; /* Language Descriptor Size */
} USB_LANGUAGE;
typedef const struct _USB_ALL_LANGUAGES
{
/* Pointer to Supported Language String */
uint_8 const *languages_supported_string;
/* Size of Supported Language String */
uint_8 const languages_supported_size;
/* Array of Supported Languages */
USB_LANGUAGE usb_language[USB_MAX_SUPPORTED_INTERFACES];
}USB_ALL_LANGUAGES;
typedef const struct _USB_ENDPOINTS
{
/* Number of non control Endpoints */
uint_8 count;
/* Array of Endpoints Structures */
USB_EP_STRUCT ep[CDC_DESC_ENDPOINT_COUNT];
}USB_ENDPOINTS;
/******************************************************************************
* Global Functions
*****************************************************************************/
extern uint_8 USB_Desc_Get_Descriptor(
uint_8 controller_ID,
uint_8 type,
uint_8 str_num,
uint_16 index,
uint_8_ptr *descriptor,
USB_PACKET_SIZE *size);
extern uint_8 USB_Desc_Get_Interface(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr alt_interface);
extern uint_8 USB_Desc_Set_Interface(
uint_8 controller_ID,
uint_8 interface,
uint_8 alt_interface);
extern boolean USB_Desc_Valid_Configation(
uint_8 controller_ID,
uint_16 config_val);
extern boolean USB_Desc_Valid_Interface(
uint_8 controller_ID,
uint_8 interface);
extern boolean USB_Desc_Remote_Wakeup(uint_8 controller_ID);
extern void* USB_Desc_Get_Endpoints(uint_8 controller_ID);
extern uint_8 USB_Desc_Get_Line_Coding(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *coding_data);
extern uint_8 USB_Desc_Set_Line_Coding(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *coding_data);
extern uint_8 USB_Desc_Get_Abstract_State(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *feature_data);
extern uint_8 USB_Desc_Get_Country_Setting(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *feature_data);
extern uint_8 USB_Desc_Set_Abstract_State(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *feature_data);
extern uint_8 USB_Desc_Set_Country_Setting(
uint_8 controller_ID,
uint_8 interface,
uint_8_ptr *feature_data);
#endif

Some files were not shown because too many files have changed in this diff Show More