初版
This commit is contained in:
commit
00ac229a6a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
QualityReport(BCZT,DefaultBuild).txt
|
||||
DefaultBuild
|
14
app/.vscode/c_cpp_properties.json
vendored
Normal file
14
app/.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"__near="
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
6
app/.vscode/settings.json
vendored
Normal file
6
app/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"motorctrl.h": "c",
|
||||
"r_cg_wdt.h": "c"
|
||||
}
|
||||
}
|
1045
app/BCZT.dm01.mtud
Normal file
1045
app/BCZT.dm01.mtud
Normal file
File diff suppressed because one or more lines are too long
5943
app/BCZT.mtpj
Normal file
5943
app/BCZT.mtpj
Normal file
File diff suppressed because it is too large
Load Diff
2447
app/BCZT.rcpe
Normal file
2447
app/BCZT.rcpe
Normal file
File diff suppressed because it is too large
Load Diff
144
app/DataFlash/pfdl.h
Normal file
144
app/DataFlash/pfdl.h
Normal file
@ -0,0 +1,144 @@
|
||||
/*******************************************************************************
|
||||
* Library : Flash Data Library T04 (PicoFDL)
|
||||
*
|
||||
* File Name : $Source: pfdl.h $
|
||||
* Lib. Version : $RL78_FDL_LIB_VERSION_T04_REN: V1.05 $
|
||||
* Mod. Revision : $Revision: 1.8 $
|
||||
* Mod. Date : $Date: 2013/06/10 22:04:41JST $
|
||||
* Device(s) : RL78
|
||||
* Description : C language API definition of the Flash Data Library
|
||||
*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2011-2013 Renesas Electronics Corporation. All rights reserved.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef __PFDL_H_INCLUDED
|
||||
#define __PFDL_H_INCLUDED
|
||||
|
||||
/*================================================================================================*/
|
||||
/* include files list */
|
||||
/*================================================================================================*/
|
||||
#include "pfdl_types.h"
|
||||
|
||||
#define FLASH_START_ADDRESS (0xF1000) /* Start address of data flash */
|
||||
#define TARGET_BLOCK (0) /* Block number of target(0 ~ 3) */
|
||||
#define BLOCK_SIZE (0x400) /* Block size */
|
||||
//#define WRITE_SIZE (1) /* Size of data to be written at once */
|
||||
#define MAX_VALUE (0xFF) /* Maximum value of writing */
|
||||
#define MAX_ADDRESS ((TARGET_BLOCK + 1) * BLOCK_SIZE - 1) /* Maximum address of writing */
|
||||
#define PFDL_NG (1) /* Failure to Data Flash */
|
||||
#define FDL_FRQ (32) /* Setting frequency (MHz) */
|
||||
#define FDL_VOL (0x00) /* Voltage mode */
|
||||
|
||||
uint8_t WriteDataflash(uint8_t* buffer,uint32_t Addr,uint16_t lenth);
|
||||
uint8_t WriteDataflash1(uint8_t* buffer,uint32_t Addr,uint16_t lenth);
|
||||
|
||||
void ReadFlashData(uint8_t* buffer,uint32_t Addr,uint16_t lenth);
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Block type: standard function */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Purpose: Unconditional activation of the Data Flash Library. */
|
||||
/* Based on the descriptor data: */
|
||||
/* - the flash firmware will be initialized for data-flash access only */
|
||||
/* - the internal timing and low-voltage capability will be configured according to the descriptor */
|
||||
/* After successful initialization the data flash clock is ON and the PFDL is ready to use. */
|
||||
/* */
|
||||
/* CAUTION: */
|
||||
/* Due to the code size minimization no plausibility checks are done by the PicoFDL. */
|
||||
/* Neither configuration, frequency range nor data flash size will be checked by the library. */
|
||||
/* */
|
||||
/* Input: address of the PFDL descriptor variable (RAM only) */
|
||||
/* Output: - */
|
||||
/* Return: PFDL status */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
extern pfdl_status_t __far PFDL_Open(__near pfdl_descriptor_t* descriptor_pstr);
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Block type: standard function */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Purpose: Disable data flash access unconditionally. */
|
||||
/* If any command is just executed, PFDL_Close will stop it immediately. */
|
||||
/* After return the data flash clock is switched OFF. */
|
||||
/* Input: - */
|
||||
/* Output: - */
|
||||
/* Return: - */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
extern void __far PFDL_Close(void);
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Block type: standard function */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Purpose: Initiating execution of the PFDL request related to the data flash. */
|
||||
/* The corresponding request variable has to be parametrized before. */
|
||||
/* */
|
||||
/* request_pstr->index_u16 : byte-index or block-number within PFDL-pool */
|
||||
/* request_pstr->data_pu08 : start address of the RAM data that should be read/written */
|
||||
/* request_pstr->bytecount_u16 : number of bytes has to be read/written */
|
||||
/* request_pstr->command_enu : command code */
|
||||
/* */
|
||||
/* CAUTION: */
|
||||
/* Due to the code size minimization no plausibility checks are done by the PFDL. */
|
||||
/* */
|
||||
/* Input: &request_pstr - pointer to PFDL request variable */
|
||||
/* Output: - */
|
||||
/* Return: status of the request */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
extern pfdl_status_t __far PFDL_Execute(__near pfdl_request_t* request_pstr);
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Block type: standard function */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Purpose: Continuation of command execution and status update of requests being under execution. */
|
||||
/* Input: - */
|
||||
/* Output: - */
|
||||
/* Return: PFDL status = */
|
||||
/* PFDL_IDLE - no request is processed by PFDL, PFDL is ready to receive new requests */
|
||||
/* PFDL_OK - processed request/command finished without problems */
|
||||
/* PFDL_BUSY - request/command is still being processed */
|
||||
/* other - flash or firmware related errors */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
extern pfdl_status_t __far PFDL_Handler(void);
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Block type: standard function */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
/* Purpose: Returns the start address of the library version string */
|
||||
/* */
|
||||
/* Input: - */
|
||||
/* Output: - */
|
||||
/* Return: starting address of the zero-terminated version string */
|
||||
/* ---------------------------------------------------------------------------------------------------------------*/
|
||||
extern __far pfdl_u08* __far PFDL_GetVersionString(void);
|
||||
|
||||
|
||||
|
||||
#endif
|
BIN
app/DataFlash/pfdl.lib
Normal file
BIN
app/DataFlash/pfdl.lib
Normal file
Binary file not shown.
146
app/DataFlash/pfdl_types.h
Normal file
146
app/DataFlash/pfdl_types.h
Normal file
@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
* Library : Flash Data Library T04 (PicoFDL)
|
||||
*
|
||||
* File Name : $Source: pfdl_types.h $
|
||||
* Lib. Version : $RL78_FDL_LIB_VERSION_T04_REN: V1.05 $
|
||||
* Mod. Revision : $Revision: 1.8 $
|
||||
* Mod. Date : $Date: 2013/06/10 22:28:01JST $
|
||||
* Device(s) : RL78
|
||||
* Description : Type definitions used by the library
|
||||
*******************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only
|
||||
* intended for use with Renesas products. No other uses are authorized. This
|
||||
* software is owned by Renesas Electronics Corporation and is protected under
|
||||
* all applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
|
||||
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
|
||||
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
|
||||
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
|
||||
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
|
||||
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software
|
||||
* and to discontinue the availability of this software. By using this software,
|
||||
* you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2011-2013 Renesas Electronics Corporation. All rights reserved.
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
#ifndef __PFDL_TYPES_H_INCLUDED
|
||||
#define __PFDL_TYPES_H_INCLUDED
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef __TYPEDEF__
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned short MD_STATUS;
|
||||
#define __TYPEDEF__
|
||||
#endif
|
||||
/*==============================================================================================*/
|
||||
/* unsigned type definitions */
|
||||
/*==============================================================================================*/
|
||||
typedef unsigned char pfdl_u08;
|
||||
typedef unsigned int pfdl_u16;
|
||||
typedef unsigned long int pfdl_u32;
|
||||
|
||||
|
||||
/*==============================================================================================*/
|
||||
/* global constant definitions */
|
||||
/*==============================================================================================*/
|
||||
|
||||
|
||||
|
||||
/*==============================================================================================*/
|
||||
/* global type definitions */
|
||||
/*==============================================================================================*/
|
||||
|
||||
|
||||
/* PFDL command code set */
|
||||
typedef enum
|
||||
{ /* ---------------------------------------------- */
|
||||
PFDL_CMD_READ_BYTES = (0x00), /* 0x00, reads data from flash memory */
|
||||
PFDL_CMD_IVERIFY_BYTES = (0x06), /* 0x06, verifies data if flash content is stable */
|
||||
PFDL_CMD_BLANKCHECK_BYTES = (0x08), /* 0x08, checks if flash content is blank */
|
||||
PFDL_CMD_WRITE_BYTES = (0x04), /* 0x04, writes data into flash memory */
|
||||
PFDL_CMD_ERASE_BLOCK = (0x03) /* 0x03, erases one flash block */
|
||||
} pfdl_command_t; /* ---------------------------------------------- */
|
||||
|
||||
|
||||
/* PFDL error code set */
|
||||
typedef enum
|
||||
{
|
||||
/* operation related status */ /* ---------------------------------------------- */
|
||||
PFDL_IDLE = (0x30), /* 0x30, PFDL ready to receive requests */
|
||||
PFDL_OK = (0x00), /* 0x00, command finished without problems */
|
||||
PFDL_BUSY = (0xFF), /* 0xFF, command is being processed */
|
||||
/* flash related status */ /* ---------------------------------------------- */
|
||||
PFDL_ERR_PROTECTION = (0x10), /* 0x10, protection error (access right conflict) */
|
||||
PFDL_ERR_ERASE = (0x1A), /* 0x1A, erase error */
|
||||
PFDL_ERR_MARGIN = (0x1B), /* 0x1B, blankcheck or verify margin violated */
|
||||
PFDL_ERR_WRITE = (0x1C), /* 0x1C, write error */
|
||||
PFDL_ERR_PARAMETER = (0x05) /* 0x05, parameter error */
|
||||
} pfdl_status_t; /* ---------------------------------------------- */
|
||||
|
||||
|
||||
/* PFDL request type (base type for any PFDL access) */
|
||||
typedef struct
|
||||
{ /* ---------------------------------------------- */
|
||||
pfdl_u16 index_u16; /* 2, W, virt. byte/block index inside PFDL-pool */
|
||||
__near pfdl_u08* data_pu08; /* 2, W, pointer to the 1'st byte of data buffer */
|
||||
pfdl_u16 bytecount_u16; /* 2, W, number of bytes to be transfered */
|
||||
pfdl_command_t command_enu; /* 1, W, command code */
|
||||
} pfdl_request_t; /*------------------------------------------------*/
|
||||
/* 7 bytes in total */
|
||||
/*------------------------------------------------*/
|
||||
|
||||
/* PFDL descriptor type */
|
||||
typedef struct
|
||||
{ /* ---------------------------------------------- */
|
||||
pfdl_u08 fx_MHz_u08; /* 1, system frequency expressed in MHz */
|
||||
pfdl_u08 wide_voltage_mode_u08; /* 1, programming voltage mode ( full/wide ) */
|
||||
} pfdl_descriptor_t; /*------------------------------------------------*/
|
||||
/* 2 bytes in total */
|
||||
|
||||
|
||||
/*==============================================================================================*/
|
||||
/* type definition plausibility check */
|
||||
/*==============================================================================================*/
|
||||
|
||||
/* The following checks are implemented in order to check the correct size of the FDL type */
|
||||
/* definitions at compile time. In case of a compilation error in the following lines, please */
|
||||
/* check your compiler options for enumeration types and structures and contact your local */
|
||||
/* support, if necessary. */
|
||||
|
||||
#define R_PFDLT04_ASSERT_CONCAT_(a, b) a##b
|
||||
#define R_PFDLT04_ASSERT_CONCAT(a, b) R_PFDLT04_ASSERT_CONCAT_(a, b)
|
||||
#define R_PFDLT04_STATIC_ASSERT(e) enum { R_PFDLT04_ASSERT_CONCAT(R_PFDLT04_ASSERT_LINE_, __LINE__) = 1/(!!(e)) }
|
||||
|
||||
|
||||
/* assertion if unsigned data type size is not correct, please evaluate compiler settings for integer types */
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_u08)==1);
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_u16)==2);
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_u32)==4);
|
||||
|
||||
/* assertion if unsigned data type size is not correct, please evaluate compiler settings for enumeration types */
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_command_t)==1);
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_status_t)==1);
|
||||
|
||||
/* assertion if structure type size is not correct, please evaluate compiler settings for structure types */
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_request_t)>=7); /* sizeof(pfdl_request_t) == 7 for packed structures */
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_request_t)<=8); /* sizeof(pfdl_request_t) == 8 for unpacked structures */
|
||||
R_PFDLT04_STATIC_ASSERT(sizeof(pfdl_descriptor_t)==2);
|
||||
|
||||
|
||||
#endif
|
303
app/DataFlash/r_pfdl.c
Normal file
303
app/DataFlash/r_pfdl.c
Normal file
@ -0,0 +1,303 @@
|
||||
|
||||
|
||||
#include "r_cg_macrodriver.h"
|
||||
|
||||
#include "pfdl.h"
|
||||
#include "pfdl_types.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: WriteDataflash
|
||||
* Description :
|
||||
* Arguments : buffer: to be writed data; Addr:Target absolute address,must be check for different mcu;lenth:to be writed number,<=1024
|
||||
* Return Value : PFDL_OK -
|
||||
Success
|
||||
PFDL_IDLE -
|
||||
Idling statement
|
||||
PFDL_ERR_MARGIN -
|
||||
Blank check error
|
||||
|
||||
other//if(Addr>=FLASH_START_ADDRESS&&Addr<FLASH_END_ADDRESS){
|
||||
***********************************************************************************************************************/
|
||||
uint8_t WriteDataflash(uint8_t* buffer,uint32_t Addr,uint16_t lenth)
|
||||
{
|
||||
static unsigned char Wr_Status;
|
||||
pfdl_status_t ret;
|
||||
pfdl_descriptor_t descriptor;
|
||||
pfdl_request_t requester;
|
||||
|
||||
if(Addr>=0x000F1000 && Addr<0x000F2000)
|
||||
{
|
||||
if(Wr_Status == 0)
|
||||
{
|
||||
/* ---- Setting for PFDL_Open ---- */
|
||||
descriptor.fx_MHz_u08 = FDL_FRQ;
|
||||
descriptor.wide_voltage_mode_u08 = FDL_VOL;
|
||||
PFDL_Open(&descriptor);
|
||||
|
||||
/* ---- Setting for blank check ---- */
|
||||
requester.command_enu = PFDL_CMD_BLANKCHECK_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000);//g_write_address;0x0F1000 according to MCU
|
||||
requester.bytecount_u16 = lenth;
|
||||
ret = PFDL_Execute(&requester); /* Blank check */
|
||||
Wr_Status = 1;
|
||||
}
|
||||
|
||||
if(Wr_Status == 1)
|
||||
{
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
}
|
||||
if(ret != PFDL_BUSY)
|
||||
{
|
||||
/* **** When blank check error **** */
|
||||
if(ret == PFDL_ERR_MARGIN)
|
||||
{
|
||||
|
||||
/* ---- Setting for erase ---- */
|
||||
requester.command_enu = PFDL_CMD_ERASE_BLOCK;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000)/0x400;//TARGET_BLOCK;
|
||||
ret = PFDL_Execute(&requester); /* Erase block data */
|
||||
Wr_Status = 2;
|
||||
/* Erase data of target block */
|
||||
}
|
||||
/* **** When other than blank check error **** */
|
||||
else
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
/******When blank no check error***/
|
||||
if(ret == PFDL_OK)
|
||||
{
|
||||
/* ---- Setting for write ---- */
|
||||
requester.command_enu = PFDL_CMD_WRITE_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000);//g_write_address;;
|
||||
requester.bytecount_u16 = lenth;
|
||||
requester.data_pu08 = buffer;//&g_write_value;
|
||||
ret = PFDL_Execute(&requester); /* Execute write */
|
||||
Wr_Status = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Wr_Status == 2)
|
||||
{
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
}
|
||||
if(ret != PFDL_BUSY)
|
||||
{
|
||||
if(ret == PFDL_OK)
|
||||
{
|
||||
/* ---- Setting for write ---- */
|
||||
requester.command_enu = PFDL_CMD_WRITE_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000);//g_write_address;;
|
||||
requester.bytecount_u16 = lenth;
|
||||
requester.data_pu08 = buffer;//&g_write_value;
|
||||
ret = PFDL_Execute(&requester); /* Execute write */
|
||||
Wr_Status = 3;
|
||||
}
|
||||
/* **** When blank check or data erase is failure **** */
|
||||
else
|
||||
{
|
||||
ret = PFDL_NG;
|
||||
//PFDL_Close(); /* Close FDL */
|
||||
//Wr_Status = 0;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Wr_Status == 3)
|
||||
{
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
}
|
||||
if(ret != PFDL_BUSY)
|
||||
{
|
||||
/* ==== When write data is success ==== */
|
||||
if(ret == PFDL_OK)
|
||||
{
|
||||
/* ---- Setting for verify ---- */
|
||||
requester.command_enu = PFDL_CMD_IVERIFY_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr- 0x0F1000);//g_write_address;;
|
||||
requester.bytecount_u16 = lenth;
|
||||
ret = PFDL_Execute(&requester); /* Execute internal verify */
|
||||
Wr_Status = 4;
|
||||
}
|
||||
/* ==== When writing data is failure ==== */
|
||||
else
|
||||
{
|
||||
ret = PFDL_NG;
|
||||
//PFDL_Close(); /* Close FDL */
|
||||
//Wr_Status = 0;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Wr_Status == 4)
|
||||
{
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
}
|
||||
if(ret != PFDL_BUSY)
|
||||
{
|
||||
PFDL_Close(); /* Close FDL */
|
||||
Wr_Status = 0;
|
||||
return 0x11;//write data flash finished
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = PFDL_NG;
|
||||
Wr_Status = 0;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t WriteDataflash1(uint8_t* buffer,uint32_t Addr,uint16_t lenth)
|
||||
{
|
||||
pfdl_status_t ret;
|
||||
pfdl_descriptor_t descriptor;
|
||||
pfdl_request_t requester;
|
||||
|
||||
if(Addr>=0x000F1000&&Addr<0x000F2000){
|
||||
/* ---- Setting for PFDL_Open ---- */
|
||||
descriptor.fx_MHz_u08 = FDL_FRQ;
|
||||
descriptor.wide_voltage_mode_u08 = FDL_VOL;
|
||||
PFDL_Open(&descriptor);
|
||||
|
||||
/* ---- Setting for blank check ---- */
|
||||
requester.command_enu = PFDL_CMD_BLANKCHECK_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000);//g_write_address;0x0F1000 according to MCU
|
||||
requester.bytecount_u16 = lenth;
|
||||
ret = PFDL_Execute(&requester); /* Blank check */
|
||||
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
}
|
||||
|
||||
/* **** When blank check error **** */
|
||||
if(ret == PFDL_ERR_MARGIN)
|
||||
{
|
||||
|
||||
/* ---- Setting for erase ---- */
|
||||
requester.command_enu = PFDL_CMD_ERASE_BLOCK;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000)/0x400;//TARGET_BLOCK;
|
||||
ret = PFDL_Execute(&requester); /* Erase block data */
|
||||
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
} /* Erase data of target block */
|
||||
}
|
||||
/* **** When other than blank check error **** */
|
||||
else
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
if(ret == PFDL_OK)
|
||||
{
|
||||
/* ---- Setting for write ---- */
|
||||
requester.command_enu = PFDL_CMD_WRITE_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr - 0x0F1000);//g_write_address;;
|
||||
requester.bytecount_u16 = lenth;
|
||||
requester.data_pu08 = buffer;//&g_write_value;
|
||||
ret = PFDL_Execute(&requester); /* Execute write */
|
||||
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler(); /* Status check process */
|
||||
} /* Write data process */
|
||||
/* ==== When write data is success ==== */
|
||||
|
||||
if(ret == PFDL_OK)
|
||||
{
|
||||
/* ---- Setting for verify ---- */
|
||||
requester.command_enu = PFDL_CMD_IVERIFY_BYTES;
|
||||
requester.index_u16 = (unsigned int)(Addr- 0x0F1000);//g_write_address;;
|
||||
requester.bytecount_u16 = lenth;
|
||||
ret = PFDL_Execute(&requester); /* Execute internal verify */
|
||||
|
||||
/* ---- Waiting for command finish ---- */
|
||||
while(ret == PFDL_BUSY)
|
||||
{
|
||||
ret = PFDL_Handler();/* Status check process */
|
||||
}
|
||||
|
||||
}
|
||||
/* ==== When writing data is failure ==== */
|
||||
else
|
||||
{
|
||||
ret = PFDL_NG;
|
||||
}
|
||||
}
|
||||
/* **** When blank check or data erase is failure **** */
|
||||
else
|
||||
{
|
||||
ret = PFDL_NG;
|
||||
}
|
||||
|
||||
PFDL_Close(); /* Close FDL */
|
||||
|
||||
return ret;
|
||||
}
|
||||
else{
|
||||
ret = PFDL_NG;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: ReadFlashData
|
||||
* Description :
|
||||
* Arguments : buffer: to be read data;
|
||||
Addr:Target absolute address,must be check for different mcu; Both codeflash & dataflash can be used
|
||||
lenth:to be read number
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
|
||||
void ReadFlashData(uint8_t* buffer,uint32_t Addr,uint16_t lenth)
|
||||
{
|
||||
uint8_t temp;
|
||||
volatile uint32_t w_count;
|
||||
volatile uint8_t * snnumber;
|
||||
/**** Only dataflash needed start*****/
|
||||
if(0 == DFLEN)
|
||||
{
|
||||
DFLEN = 1U; //允许存取数据闪存
|
||||
for (w_count = 0U; w_count < 15U; w_count++)//3U
|
||||
{
|
||||
NOP(); //延时,给硬件反应的时间
|
||||
}
|
||||
}
|
||||
/**** Only dataflash needed end******/
|
||||
snnumber = Addr;
|
||||
|
||||
for(temp = 0; temp < lenth; temp ++)
|
||||
{
|
||||
*buffer = *snnumber;
|
||||
buffer ++;
|
||||
snnumber ++;
|
||||
}
|
||||
//memcpy(buffer,snnumber,lenth);
|
||||
}
|
||||
|
||||
/* End user code. Do not edit comment generated here */
|
10
app/DataFlash/测试数据.txt
Normal file
10
app/DataFlash/测试数据.txt
Normal file
@ -0,0 +1,10 @@
|
||||
内振32MHz
|
||||
|
||||
擦除 64Bytes和1024Bytes个00H,时间一样,为5.7mS
|
||||
写入 1024Bytes个00H 需要46.8mS,写入时间和数据长度成线性关系
|
||||
|
||||
T04库的使用注意事项:
|
||||
1,栈,传参,DMA对应的RAM地址都不要放到高速RAM区,否则程序跑飞
|
||||
2,由于连续写入多个字节的时间较长,建议不要采用提供函数中的死等的办法,可以在主循环中查PFDL_Handler()
|
||||
3,读出可以直接用CPU指令,不需要库
|
||||
4,输入的地址超出范围,库的返回值有可能不报错,镜像区不报错,保留区跑飞
|
231
app/cstart.asm
Normal file
231
app/cstart.asm
Normal file
@ -0,0 +1,231 @@
|
||||
;/**********************************************************************************************************************
|
||||
; * DISCLAIMER
|
||||
; * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
|
||||
; * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
; * applicable laws, including copyright laws.
|
||||
; * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
; * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
||||
; * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
|
||||
; * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
|
||||
; * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO
|
||||
; * THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
; * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
|
||||
; * this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
; * following link:
|
||||
; * http://www.renesas.com/disclaimer
|
||||
; *
|
||||
; * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved.
|
||||
; *********************************************************************************************************************/
|
||||
; NOTE : THIS IS A TYPICAL EXAMPLE.
|
||||
|
||||
$IFNDEF __RENESAS_VERSION__
|
||||
__RENESAS_VERSION__ .EQU 0x01000000
|
||||
$ENDIF
|
||||
|
||||
.public _start
|
||||
.public _exit
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; RAM section
|
||||
;-----------------------------------------------------------------------------
|
||||
.SECTION .dataR, DATA
|
||||
.SECTION .sdataR, DATA
|
||||
; .SECTION .datafR, DATAF
|
||||
; .SECTION .textfR, TEXTF
|
||||
|
||||
$IF (__RENESAS_VERSION__ < 0x01010000) ; for CC-RL V1.00
|
||||
;-----------------------------------------------------------------------------
|
||||
; stack area
|
||||
;-----------------------------------------------------------------------------
|
||||
; !!! [CAUTION] !!!
|
||||
; Set up stack size suitable for a project.
|
||||
.SECTION .stack_bss, BSS
|
||||
_stackend:
|
||||
.DS 0x200
|
||||
_stacktop:
|
||||
$ENDIF
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; RESET vector
|
||||
;-----------------------------------------------------------------------------
|
||||
_start .VECTOR 0
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; startup
|
||||
;-----------------------------------------------------------------------------
|
||||
.SECTION .text, TEXT
|
||||
_start:
|
||||
;--------------------------------------------------
|
||||
; setting register bank
|
||||
;--------------------------------------------------
|
||||
; SEL RB0
|
||||
|
||||
;--------------------------------------------------
|
||||
; setting mirror area
|
||||
;--------------------------------------------------
|
||||
; ONEB !PMC ; mirror area = 10000-1FFFFH
|
||||
|
||||
;--------------------------------------------------
|
||||
; setting the stack pointer
|
||||
;--------------------------------------------------
|
||||
$IF (__RENESAS_VERSION__ >= 0x01010000)
|
||||
MOVW SP,#LOWW(__STACK_ADDR_START)
|
||||
$ELSE ; for CC-RL V1.00
|
||||
MOVW SP,#LOWW(_stacktop)
|
||||
$ENDIF
|
||||
|
||||
;--------------------------------------------------
|
||||
; initializing stack area
|
||||
;--------------------------------------------------
|
||||
$IF (__RENESAS_VERSION__ >= 0x01010000)
|
||||
MOVW AX,#LOWW(__STACK_ADDR_END)
|
||||
$ELSE ; for CC-RL V1.00
|
||||
MOVW AX,#LOWW(_stackend)
|
||||
$ENDIF
|
||||
CALL !!_stkinit
|
||||
|
||||
;--------------------------------------------------
|
||||
; hardware initialization
|
||||
;--------------------------------------------------
|
||||
CALL !!_hdwinit
|
||||
|
||||
;--------------------------------------------------
|
||||
; initializing BSS
|
||||
;--------------------------------------------------
|
||||
; clear external variables which doesn't have initial value (near)
|
||||
MOVW HL,#LOWW(STARTOF(.bss))
|
||||
MOVW AX,#LOWW(STARTOF(.bss) + SIZEOF(.bss))
|
||||
BR $.L2_BSS
|
||||
.L1_BSS:
|
||||
MOV [HL+0],#0
|
||||
INCW HL
|
||||
.L2_BSS:
|
||||
CMPW AX,HL
|
||||
BNZ $.L1_BSS
|
||||
|
||||
; clear saddr variables which doesn't have initial value
|
||||
MOVW HL,#LOWW(STARTOF(.sbss))
|
||||
MOVW AX,#LOWW(STARTOF(.sbss) + SIZEOF(.sbss))
|
||||
BR $.L2_SBSS
|
||||
.L1_SBSS:
|
||||
MOV [HL+0],#0
|
||||
INCW HL
|
||||
.L2_SBSS:
|
||||
CMPW AX,HL
|
||||
BNZ $.L1_SBSS
|
||||
|
||||
; clear external variables which doesn't have initial value (far)
|
||||
; MOV ES,#HIGHW(STARTOF(.bssf))
|
||||
; MOVW HL,#LOWW(STARTOF(.bssf))
|
||||
; MOVW AX,#LOWW(STARTOF(.bssf) + SIZEOF(.bssf))
|
||||
; BR $.L2_BSSF
|
||||
;.L1_BSSF:
|
||||
; MOV ES:[HL+0],#0
|
||||
; INCW HL
|
||||
;.L2_BSSF:
|
||||
; CMPW AX,HL
|
||||
; BNZ $.L1_BSSF
|
||||
|
||||
;--------------------------------------------------
|
||||
; ROM data copy
|
||||
;--------------------------------------------------
|
||||
; copy external variables having initial value (near)
|
||||
MOV ES,#HIGHW(STARTOF(.data))
|
||||
MOVW BC,#LOWW(SIZEOF(.data))
|
||||
BR $.L2_DATA
|
||||
.L1_DATA:
|
||||
DECW BC
|
||||
MOV A,ES:LOWW(STARTOF(.data))[BC]
|
||||
MOV LOWW(STARTOF(.dataR))[BC],A
|
||||
.L2_DATA:
|
||||
CLRW AX
|
||||
CMPW AX,BC
|
||||
BNZ $.L1_DATA
|
||||
|
||||
; copy saddr variables having initial value
|
||||
MOV ES,#HIGHW(STARTOF(.sdata))
|
||||
MOVW BC,#LOWW(SIZEOF(.sdata))
|
||||
BR $.L2_SDATA
|
||||
.L1_SDATA:
|
||||
DECW BC
|
||||
MOV A,ES:LOWW(STARTOF(.sdata))[BC]
|
||||
MOV LOWW(STARTOF(.sdataR))[BC],A
|
||||
.L2_SDATA:
|
||||
CLRW AX
|
||||
CMPW AX,BC
|
||||
BNZ $.L1_SDATA
|
||||
|
||||
; copy external variables having initial value (far)
|
||||
; MOVW BC,#LOWW(SIZEOF(.dataf))
|
||||
; BR $.L2_DATAF
|
||||
;.L1_DATAF:
|
||||
; DECW BC
|
||||
; MOV ES,#HIGHW(STARTOF(.dataf))
|
||||
; MOV A,ES:LOWW(STARTOF(.dataf))[BC]
|
||||
; MOV ES,#HIGHW(STARTOF(.datafR))
|
||||
; MOV ES:LOWW(STARTOF(.datafR))[BC],A
|
||||
;.L2_DATAF:
|
||||
; CLRW AX
|
||||
; CMPW AX,BC
|
||||
; BNZ $.L1_DATAF
|
||||
|
||||
; copy .text to RAM
|
||||
; MOV C,#HIGHW(STARTOF(.textf))
|
||||
; MOVW HL,#LOWW(STARTOF(.textf))
|
||||
; MOVW DE,#LOWW(STARTOF(.textfR))
|
||||
; BR $.L2_TEXT
|
||||
;.L1_TEXT:
|
||||
; MOV A,C
|
||||
; MOV ES,A
|
||||
; MOV A,ES:[HL]
|
||||
; MOV [DE],A
|
||||
; INCW DE
|
||||
; INCW HL
|
||||
; CLRW AX
|
||||
; CMPW AX,HL
|
||||
; SKNZ
|
||||
; INC C
|
||||
;.L2_TEXT:
|
||||
; MOVW AX,HL
|
||||
; CMPW AX,#LOWW(STARTOF(.text) + SIZEOF(.text))
|
||||
; BNZ $.L1_TEXT
|
||||
|
||||
;--------------------------------------------------
|
||||
; call main function
|
||||
;--------------------------------------------------
|
||||
CALL !!_main ; main();
|
||||
|
||||
;--------------------------------------------------
|
||||
; call exit function
|
||||
;--------------------------------------------------
|
||||
CLRW AX ; exit(0)
|
||||
_exit:
|
||||
BR $_exit
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; section
|
||||
;-----------------------------------------------------------------------------
|
||||
$IF (__RENESAS_VERSION__ >= 0x01010000)
|
||||
.SECTION .RLIB, TEXTF
|
||||
.L_section_RLIB:
|
||||
.SECTION .SLIB, TEXTF
|
||||
.L_section_SLIB:
|
||||
$ENDIF
|
||||
.SECTION .textf, TEXTF
|
||||
.L_section_textf:
|
||||
.SECTION .const, CONST
|
||||
.L_section_const:
|
||||
.SECTION .constf, CONSTF
|
||||
.L_section_constf:
|
||||
.SECTION .data, DATA
|
||||
.L_section_data:
|
||||
;.SECTION .dataf, DATAF
|
||||
;.L_section_dataf:
|
||||
.SECTION .sdata, SDATA
|
||||
.L_section_sdata:
|
||||
.SECTION .bss, BSS
|
||||
.L_section_bss:
|
||||
;.SECTION .bssf, BSSF
|
||||
;.L_section_bssf:
|
||||
.SECTION .sbss, SBSS
|
||||
.L_section_sbss:
|
35
app/hdwinit.asm
Normal file
35
app/hdwinit.asm
Normal file
@ -0,0 +1,35 @@
|
||||
;/**********************************************************************************************************************
|
||||
; * DISCLAIMER
|
||||
; * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
|
||||
; * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
; * applicable laws, including copyright laws.
|
||||
; * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
; * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
||||
; * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
|
||||
; * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
|
||||
; * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO
|
||||
; * THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
; * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
|
||||
; * this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
; * following link:
|
||||
; * http://www.renesas.com/disclaimer
|
||||
; *
|
||||
; * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved.
|
||||
; *********************************************************************************************************************/;---------------------------------------------------------------------
|
||||
; _hdwinit
|
||||
;
|
||||
; void _hdwinit(void);
|
||||
;
|
||||
; input:
|
||||
; NONE
|
||||
; output:
|
||||
; NONE
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
; NOTE : THIS IS A TYPICAL EXAMPLE.
|
||||
|
||||
.PUBLIC _hdwinit
|
||||
|
||||
.textf .CSEG TEXTF
|
||||
_hdwinit:
|
||||
RET
|
1108
app/iodefine.h
Normal file
1108
app/iodefine.h
Normal file
File diff suppressed because it is too large
Load Diff
35
app/main.c
Normal file
35
app/main.c
Normal file
@ -0,0 +1,35 @@
|
||||
/**********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
|
||||
* other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
|
||||
* EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
|
||||
* SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO
|
||||
* THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
|
||||
* this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved.
|
||||
*********************************************************************************************************************/
|
||||
/***********************************************************************/
|
||||
/* */
|
||||
/* FILE :Main.c */
|
||||
/* DATE : */
|
||||
/* DESCRIPTION :Main Program */
|
||||
/* CPU TYPE : */
|
||||
/* */
|
||||
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
void main(void);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
}
|
139
app/r_cg_adc.c
Normal file
139
app/r_cg_adc.c
Normal file
@ -0,0 +1,139 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_adc.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for ADC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_adc.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Create
|
||||
* Description : This function initializes the AD converter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Create(void)
|
||||
{
|
||||
ADCEN = 1U; /* supply AD clock */
|
||||
ADM0 = _00_AD_ADM0_INITIALVALUE; /* disable AD conversion and clear ADM0 register */
|
||||
ADMK = 1U; /* disable INTAD interrupt */
|
||||
ADIF = 0U; /* clear INTAD interrupt flag */
|
||||
/* Set INTAD low priority */
|
||||
ADPR1 = 1U;
|
||||
ADPR0 = 1U;
|
||||
/* The reset status of ADPC is analog input, so it's unnecessary to set. */
|
||||
/* Set ANI0 - ANI3 pin as analog input */
|
||||
PM8 |= 0x03U;
|
||||
PM3 |= 0x18U;
|
||||
ADM0 = _00_AD_CONVERSION_CLOCK_64 | _00_AD_TIME_MODE_NORMAL_1 | _00_AD_OPERMODE_SELECT;
|
||||
ADM1 = _80_AD_TRIGGER_HARDWARE_NOWAIT | _00_AD_CONVMODE_CONSELECT | _00_AD_TRIGGER_INTTM01;
|
||||
ADM2 = _00_AD_POSITIVE_VDD | _00_AD_NEGATIVE_VSS | _00_AD_AREA_MODE_1 | _00_AD_RESOLUTION_10BIT;
|
||||
ADUL = _FF_AD_ADUL_VALUE;
|
||||
ADLL = _00_AD_ADLL_VALUE;
|
||||
ADS = _00_AD_INPUT_CHANNEL_0;
|
||||
ADCE = 1U; /* enable AD comparator */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Start
|
||||
* Description : This function starts the AD converter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Start(void)
|
||||
{
|
||||
ADIF = 0U; /* clear INTAD interrupt flag */
|
||||
ADMK = 0U; /* enable INTAD interrupt */
|
||||
ADCS = 1U; /* enable AD conversion */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Stop
|
||||
* Description : This function stops the AD converter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Stop(void)
|
||||
{
|
||||
ADCS = 0U; /* disable AD conversion */
|
||||
ADMK = 1U; /* disable INTAD interrupt */
|
||||
ADIF = 0U; /* clear INTAD interrupt flag */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Set_OperationOn
|
||||
* Description : This function enables comparator operation.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Set_OperationOn(void)
|
||||
{
|
||||
ADCE = 1U; /* enable AD comparator */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Set_OperationOff
|
||||
* Description : This function stops comparator operation.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Set_OperationOff(void)
|
||||
{
|
||||
ADCE = 0U; /* disable AD comparator */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_ADC_Get_Result
|
||||
* Description : This function returns the conversion result in the buffer.
|
||||
* Arguments : buffer -
|
||||
* the address where to write the conversion result
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Get_Result(uint16_t * const buffer)
|
||||
{
|
||||
*buffer = (uint16_t)(ADCR >> 6U);
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
193
app/r_cg_adc.h
Normal file
193
app/r_cg_adc.h
Normal file
@ -0,0 +1,193 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_adc.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for ADC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef ADC_H
|
||||
#define ADC_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
/*
|
||||
Peripheral enable register 0 (PER0)
|
||||
*/
|
||||
/* Control of AD converter input clock (ADCEN) */
|
||||
#define _00_AD_CLOCK_STOP (0x00U) /* stop supply of input clock */
|
||||
#define _20_AD_CLOCK_SUPPLY (0x20U) /* supply input clock */
|
||||
|
||||
/*
|
||||
AD converter mode register 0 (ADM0)
|
||||
*/
|
||||
#define _00_AD_ADM0_INITIALVALUE (0x00U)
|
||||
/* AD conversion operation control (ADCS) */
|
||||
#define _80_AD_CONVERSION_ENABLE (0x80U) /* enable AD conversion operation control */
|
||||
#define _00_AD_CONVERSION_DISABLE (0x00U) /* disable AD conversion operation control */
|
||||
/* Specification of AD conversion operation mode (ADMD) */
|
||||
#define _00_AD_OPERMODE_SELECT (0x00U) /* select operation mode */
|
||||
#define _40_AD_OPERMODE_SCAN (0x40U) /* scan operation mode */
|
||||
/* AD conversion clock selection (FR2 - FR0) */
|
||||
#define _00_AD_CONVERSION_CLOCK_64 (0x00U) /* fCLK/64 */
|
||||
#define _08_AD_CONVERSION_CLOCK_32 (0x08U) /* fCLK/32 */
|
||||
#define _10_AD_CONVERSION_CLOCK_16 (0x10U) /* fCLK/16 */
|
||||
#define _18_AD_CONVERSION_CLOCK_8 (0x18U) /* fCLK/8 */
|
||||
#define _20_AD_CONVERSION_CLOCK_6 (0x20U) /* fCLK/6 */
|
||||
#define _28_AD_CONVERSION_CLOCK_5 (0x28U) /* fCLK/5 */
|
||||
#define _30_AD_CONVERSION_CLOCK_4 (0x30U) /* fCLK/4 */
|
||||
#define _38_AD_CONVERSION_CLOCK_2 (0x38U) /* fCLK/2 */
|
||||
/* Specification AD conversion time mode (LV1, LV0) */
|
||||
#define _00_AD_TIME_MODE_NORMAL_1 (0x00U) /* normal 1 mode */
|
||||
#define _02_AD_TIME_MODE_NORMAL_2 (0x02U) /* normal 2 mode */
|
||||
/* AD comparator operation control (ADCE) */
|
||||
#define _01_AD_COMPARATOR_ENABLE (0x01U) /* enable comparator operation control */
|
||||
#define _00_AD_COMPARATOR_DISABLE (0x00U) /* disable comparator operation control */
|
||||
|
||||
/*
|
||||
Analog input channel specification register (ADS)
|
||||
*/
|
||||
/* Specification of analog input channel (ADISS, ADS4 - ADS0) */
|
||||
/* Select mode */
|
||||
#define _00_AD_INPUT_CHANNEL_0 (0x00U) /* ANI0 */
|
||||
#define _01_AD_INPUT_CHANNEL_1 (0x01U) /* ANI1 */
|
||||
#define _02_AD_INPUT_CHANNEL_2 (0x02U) /* ANI2 */
|
||||
#define _03_AD_INPUT_CHANNEL_3 (0x03U) /* ANI3 */
|
||||
#define _04_AD_INPUT_CHANNEL_4 (0x04U) /* ANI4 */
|
||||
#define _05_AD_INPUT_CHANNEL_5 (0x05U) /* ANI5 */
|
||||
#define _06_AD_INPUT_CHANNEL_6 (0x06U) /* ANI6 */
|
||||
#define _07_AD_INPUT_CHANNEL_7 (0x07U) /* ANI7 */
|
||||
#define _08_AD_INPUT_CHANNEL_8 (0x08U) /* ANI8 */
|
||||
#define _09_AD_INPUT_CHANNEL_9 (0x09U) /* ANI9 */
|
||||
#define _0A_AD_INPUT_CHANNEL_10 (0x0AU) /* ANI10 */
|
||||
#define _0B_AD_INPUT_CHANNEL_11 (0x0BU) /* ANI11 */
|
||||
#define _0C_AD_INPUT_CHANNEL_12 (0x0CU) /* ANI12 */
|
||||
#define _18_AD_INPUT_CHANNEL_24 (0x18U) /* ANI24 */
|
||||
#define _19_AD_INPUT_CHANNEL_25 (0x19U) /* ANI25 */
|
||||
#define _80_AD_INPUT_TEMPERSENSOR_0 (0x80U) /* temperature sensor 0 output is used to be the input channel */
|
||||
#define _81_AD_INPUT_INTERREFVOLT (0x81U) /* internal reference voltage output is used to be the input channel */
|
||||
/* Scan mode */
|
||||
#define _00_AD_INPUT_CHANNEL_0_3 (0x00U) /* ANI0 - ANI3 */
|
||||
#define _01_AD_INPUT_CHANNEL_1_4 (0x01U) /* ANI1 - ANI4 */
|
||||
#define _02_AD_INPUT_CHANNEL_2_5 (0x02U) /* ANI2 - ANI5 */
|
||||
#define _03_AD_INPUT_CHANNEL_3_6 (0x03U) /* ANI3 - ANI6 */
|
||||
#define _04_AD_INPUT_CHANNEL_4_7 (0x04U) /* ANI4 - ANI7 */
|
||||
#define _05_AD_INPUT_CHANNEL_5_8 (0x05U) /* ANI5 - ANI8 */
|
||||
#define _06_AD_INPUT_CHANNEL_6_9 (0x06U) /* ANI6 - ANI9 */
|
||||
#define _07_AD_INPUT_CHANNEL_7_10 (0x07U) /* ANI7 - ANI10 */
|
||||
#define _08_AD_INPUT_CHANNEL_8_11 (0x08U) /* ANI8 - ANI11 */
|
||||
#define _09_AD_INPUT_CHANNEL_9_12 (0x09U) /* ANI9 - ANI12 */
|
||||
|
||||
/*
|
||||
AD converter mode register 1 (ADM1)
|
||||
*/
|
||||
/* AD trigger mode selection (ADTMD1, ADTMD0) */
|
||||
#define _00_AD_TRIGGER_SOFTWARE (0x00U) /* software trigger mode */
|
||||
#define _80_AD_TRIGGER_HARDWARE_NOWAIT (0x80U) /* hardware trigger mode (no wait) */
|
||||
#define _C0_AD_TRIGGER_HARDWARE_WAIT (0xC0U) /* hardware trigger mode (wait) */
|
||||
/* AD convertion mode selection (ADSCM) */
|
||||
#define _00_AD_CONVMODE_CONSELECT (0x00U) /* continuous convertion mode */
|
||||
#define _20_AD_CONVMODE_ONESELECT (0x20U) /* oneshot convertion mode */
|
||||
/* Trigger signal selection (ADTRS1, ADTRS0) */
|
||||
#define _00_AD_TRIGGER_INTTM01 (0x00U) /* INTTM01 */
|
||||
#define _01_AD_TRIGGER_ELC (0x01U) /* ELC */
|
||||
#define _01_AD_TRIGGER_TIMER (0x01U) /* INTTRD0,INTTRJ0 */
|
||||
#define _02_AD_TRIGGER_INTRTC (0x02U) /* INTRTC */
|
||||
/*
|
||||
AD converter mode register 2 (ADM2)
|
||||
*/
|
||||
/* AD VREF(+) selection (ADREFP1, ADREFP0) */
|
||||
#define _00_AD_POSITIVE_VDD (0x00U) /* use VDD as VREF(+) */
|
||||
#define _40_AD_POSITIVE_AVREFP (0x40U) /* use AVREFP as VREF(+) */
|
||||
#define _80_AD_POSITIVE_INTERVOLT (0x80U) /* use internal voltage as VREF(+) */
|
||||
/* AD VREF(-) selection (ADREFM) */
|
||||
#define _00_AD_NEGATIVE_VSS (0x00U) /* use VSS as VREF(-) */
|
||||
#define _20_AD_NEGATIVE_AVREFM (0x20U) /* use AVREFM as VREF(-) */
|
||||
/* AD conversion result upper/lower bound value selection (ADRCK) */
|
||||
#define _00_AD_AREA_MODE_1 (0x00U) /* generates INTAD when ADLL <= ADCRH <= ADUL */
|
||||
#define _08_AD_AREA_MODE_2_3 (0x08U) /* generates INTAD when ADUL < ADCRH or ADLL > ADCRH */
|
||||
/* AD wakeup function selection (AWC) */
|
||||
#define _00_AD_WAKEUP_OFF (0x00U) /* stop wakeup function */
|
||||
#define _04_AD_WAKEUP_ON (0x04U) /* use wakeup function */
|
||||
/* AD resolution selection (ADTYP) */
|
||||
#define _00_AD_RESOLUTION_10BIT (0x00U) /* 10 bits */
|
||||
#define _01_AD_RESOLUTION_8BIT (0x01U) /* 8 bits */
|
||||
|
||||
/*
|
||||
AD test function register (ADTES)
|
||||
*/
|
||||
/* AD test mode signal (ADTES2 - ADTES0) */
|
||||
#define _00_AD_NORMAL_INPUT (0x00U) /* normal mode */
|
||||
#define _02_AD_TEST_AVREFM (0x02U) /* use AVREFM as test signal */
|
||||
#define _03_AD_TEST_AVREFP (0x03U) /* use AVREFP as test signal */
|
||||
/*
|
||||
Format of A/D Converter Trigger Select Register 0 (ADTRGS0)(F13 only)
|
||||
*/
|
||||
/* Selection of the operation trigger of the A/D converter when the timer RD0 input capture B/compare match B
|
||||
interrupt request is generated (ADTRGS00) */
|
||||
#define _01_AD_TRIGGER_INTTRD0 (0x01U) /* A/D conversion is started when the interrupt request is generated */
|
||||
|
||||
/*
|
||||
Format of A/D Converter Trigger Select Register 1 (ADTRGS1)(F13 only)
|
||||
*/
|
||||
/* Selection of the operation trigger of the A/D converter when the timer RJ0 interrupt request is generated (ADTRGS10) */
|
||||
#define _01_AD_TRIGGER_INTTRJ0 (0x01U) /* A/D conversion is started when the interrupt request is generated */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
/* Upper bound (ADUL) value */
|
||||
#define _FF_AD_ADUL_VALUE (0xFFU)
|
||||
/* Upper bound (ADLL) value */
|
||||
#define _00_AD_ADLL_VALUE (0x00U)
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
ADCHANNEL0, ADCHANNEL1, ADCHANNEL2, ADCHANNEL3, ADCHANNEL4, ADCHANNEL5, ADCHANNEL6,
|
||||
ADCHANNEL7, ADCHANNEL8, ADCHANNEL9, ADCHANNEL10, ADCHANNEL11, ADCHANNEL12,
|
||||
ADCHANNEL24 = 24U, ADCHANNEL25, ADTEMPERSENSOR0 = 128U, ADINTERREFVOLT
|
||||
} ad_channel_t;
|
||||
typedef enum
|
||||
{
|
||||
ADNORMALINPUT,
|
||||
ADAVREFM = 2U,
|
||||
ADAVREFP
|
||||
} test_channel_t;
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
void R_ADC_Create(void);
|
||||
void R_ADC_Start(void);
|
||||
void R_ADC_Stop(void);
|
||||
void R_ADC_Set_OperationOn(void);
|
||||
void R_ADC_Set_OperationOff(void);
|
||||
void R_ADC_Get_Result(uint16_t * const buffer);
|
||||
|
||||
/* Start user code for function. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#endif
|
87
app/r_cg_adc_user.c
Normal file
87
app/r_cg_adc_user.c
Normal file
@ -0,0 +1,87 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_adc_user.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for ADC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_adc.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
#pragma interrupt r_adc_interrupt(vect=INTAD)
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
uint16_t g_adval[4];
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_adc_interrupt
|
||||
* Description : This function is INTAD interrupt service routine.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
static void __near r_adc_interrupt(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
switch (ADS)
|
||||
{
|
||||
case _00_AD_INPUT_CHANNEL_0:
|
||||
R_ADC_Get_Result(g_adval);
|
||||
ADS = _01_AD_INPUT_CHANNEL_1;
|
||||
break;
|
||||
case _01_AD_INPUT_CHANNEL_1:
|
||||
R_ADC_Get_Result(g_adval+1);
|
||||
ADS = _02_AD_INPUT_CHANNEL_2;
|
||||
break;
|
||||
case _02_AD_INPUT_CHANNEL_2:
|
||||
R_ADC_Get_Result(g_adval+2);
|
||||
ADS = _03_AD_INPUT_CHANNEL_3;
|
||||
break;
|
||||
case _03_AD_INPUT_CHANNEL_3:
|
||||
R_ADC_Get_Result(g_adval+3);
|
||||
ADS = _00_AD_INPUT_CHANNEL_0;
|
||||
break;
|
||||
default:
|
||||
ADS = _00_AD_INPUT_CHANNEL_0;
|
||||
break;
|
||||
}
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
82
app/r_cg_cgc.c
Normal file
82
app/r_cg_cgc.c
Normal file
@ -0,0 +1,82 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_cgc.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for CGC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_cgc.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_CGC_Create
|
||||
* Description : This function initializes the clock generator.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_CGC_Create(void)
|
||||
{
|
||||
/* Set fSL */
|
||||
SELLOSC = 1U;
|
||||
/* Set fMX */
|
||||
CMC = _00_CGC_HISYS_PORT | _00_CGC_SUB_PORT | _00_CGC_SYSOSC_DEFAULT | _00_CGC_SUBMODE_DEFAULT;
|
||||
MSTOP = 1U;
|
||||
/* Set fMAIN */
|
||||
MCM0 = 0U;
|
||||
MDIV = _01_CGC_FMP_DIV_1;
|
||||
/* Set fMP to clock through mode */
|
||||
SELPLL = 0U;
|
||||
/* Set fSUB */
|
||||
XTSTOP = 1U;
|
||||
/* Set fCLK */
|
||||
CSS = 0U;
|
||||
/* Set fIH */
|
||||
HIOSTOP = 0U;
|
||||
/* Set RTC clock source */
|
||||
RTCCL = _80_CGC_RTC_FIH;
|
||||
RTCCL |= _42_CGC_RTC_DIV122;
|
||||
/* Set Timer RD clock source to fCLK, fMP */
|
||||
TRD_CKSEL = 0U;
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
227
app/r_cg_cgc.h
Normal file
227
app/r_cg_cgc.h
Normal file
@ -0,0 +1,227 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_cgc.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for CGC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef CGC_H
|
||||
#define CGC_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
/*
|
||||
Clock operation mode control register (CMC)
|
||||
*/
|
||||
/* High-speed system clock pin operation mode (EXCLK, OSCSEL) */
|
||||
#define _C0_CGC_HISYS_PIN (0xC0U)
|
||||
#define _00_CGC_HISYS_PORT (0x00U) /* X1, X2 as I/O port */
|
||||
#define _40_CGC_HISYS_OSC (0x40U) /* X1, X2 as crystal/ceramic resonator connection */
|
||||
#define _80_CGC_HISYS_PORT1 (0x80U) /* X1, X2 as I/O port */
|
||||
#define _C0_CGC_HISYS_EXT (0xC0U) /* X1 as I/O port, X2 as external clock input */
|
||||
/* Subsystem clock pin operation mode (EXCLKS, OSCSELS) */
|
||||
#define _30_CGC_SUB_PIN (0x30U)
|
||||
#define _00_CGC_SUB_PORT (0x00U) /* XT1, XT2 as I/O port */
|
||||
#define _10_CGC_SUB_OSC (0x10U) /* XT1, XT2 as crystal connection */
|
||||
#define _20_CGC_SUB_PORT1 (0x20U) /* XT1, XT2 as I/O port */
|
||||
#define _30_CGC_SUB_EXT (0x30U) /* XT1 as I/O port, XT2 as external clock input */
|
||||
/* XT1 oscillator oscillation mode selection (AMPHS1, AMPHS0) */
|
||||
#define _00_CGC_SUBMODE_DEFAULT (0x00U)
|
||||
#define _00_CGC_SUBMODE_LOW (0x00U) /* low power consumption oscillation */
|
||||
#define _02_CGC_SUBMODE_NORMAL (0x02U) /* normal oscillation */
|
||||
#define _04_CGC_SUBMODE_ULOW (0x04U) /* ultra-low power consumption oscillation */
|
||||
/* Control of X1 high-speed system clock oscillation frequency (AMPH) */
|
||||
#define _00_CGC_SYSOSC_DEFAULT (0x00U)
|
||||
#define _00_CGC_SYSOSC_UNDER10M (0x00U) /* fX <= 10MHz */
|
||||
#define _01_CGC_SYSOSC_OVER10M (0x01U) /* fX > 10MHz */
|
||||
|
||||
/*
|
||||
Clock operation status control register (CSC)
|
||||
*/
|
||||
/* Control of high-speed system clock operation (MSTOP) */
|
||||
#define _00_CGC_HISYS_OPER (0x00U) /* X1 oscillator/external clock operating */
|
||||
#define _80_CGC_HISYS_STOP (0x80U) /* X1 oscillator/external clock stopped */
|
||||
/* Subsystem clock operation (XTSTOP) */
|
||||
#define _00_CGC_SUB_OPER (0x00U) /* XT1 oscillator operating */
|
||||
#define _40_CGC_SUB_STOP (0x40U) /* XT1 oscillator stopped */
|
||||
/* High-speed OCO operation (HIOSTOP) */
|
||||
#define _00_CGC_HIO_OPER (0x00U) /* high-speed OCO operating */
|
||||
#define _01_CGC_HIO_STOP (0x01U) /* high-speed OCO stopped */
|
||||
|
||||
/*
|
||||
Oscillation stabilization time counter status register (OSTC)
|
||||
*/
|
||||
/* Oscillation stabilization time status (MOST18 - MOST8) */
|
||||
#define _00_CGC_OSCSTAB_STA0 (0x00U) /* < 2^8/fX */
|
||||
#define _80_CGC_OSCSTAB_STA8 (0x80U) /* 2^8/fX */
|
||||
#define _C0_CGC_OSCSTAB_STA9 (0xC0U) /* 2^9/fX */
|
||||
#define _E0_CGC_OSCSTAB_STA10 (0xE0U) /* 2^10/fX */
|
||||
#define _F0_CGC_OSCSTAB_STA11 (0xF0U) /* 2^11/fX */
|
||||
#define _F8_CGC_OSCSTAB_STA13 (0xF8U) /* 2^13/fX */
|
||||
#define _FC_CGC_OSCSTAB_STA15 (0xFCU) /* 2^15/fX */
|
||||
#define _FE_CGC_OSCSTAB_STA17 (0xFEU) /* 2^17/fX */
|
||||
#define _FF_CGC_OSCSTAB_STA18 (0xFFU) /* 2^18/fX */
|
||||
|
||||
/*
|
||||
Oscillation stabilization time select register (OSTS)
|
||||
*/
|
||||
/* Oscillation stabilization time selection (OSTS2 - OSTS0) */
|
||||
#define _00_CGC_OSCSTAB_SEL8 (0x00U) /* 2^8/fX */
|
||||
#define _01_CGC_OSCSTAB_SEL9 (0x01U) /* 2^9/fX */
|
||||
#define _02_CGC_OSCSTAB_SEL10 (0x02U) /* 2^10/fX */
|
||||
#define _03_CGC_OSCSTAB_SEL11 (0x03U) /* 2^11/fX */
|
||||
#define _04_CGC_OSCSTAB_SEL13 (0x04U) /* 2^13/fX */
|
||||
#define _05_CGC_OSCSTAB_SEL15 (0x05U) /* 2^15/fX */
|
||||
#define _06_CGC_OSCSTAB_SEL17 (0x06U) /* 2^17/fX */
|
||||
#define _07_CGC_OSCSTAB_SEL18 (0x07U) /* 2^18/fX */
|
||||
|
||||
/*
|
||||
PLL control register (PLLCTL)
|
||||
*/
|
||||
/* Lockup wait counter setting value */
|
||||
#define _00_CGC_LOCKUP_WAIT_7 (0x00U) /* 2^7/fMAIN */
|
||||
#define _40_CGC_LOCKUP_WAIT_8 (0x40U) /* 2^8/fMAIN */
|
||||
#define _80_CGC_LOCKUP_WAIT_9 (0x80U) /* 2^9/fMAIN */
|
||||
/* PLL output clock selection (PLLDIV1) */
|
||||
#define _00_CGC_PLL_BELOW_32MHZ (0x00U) /* when fMAIN <= 32 MHz */
|
||||
#define _20_CGC_PLL_ABOVE_32MHZ (0x20U) /* when fMAIN > 32 MHz */
|
||||
/* PLL output clock division selection (PLLDIV0) */
|
||||
#define _00_CGC_PLL_DIVISION_2 (0x00U) /* divides the clock frequency by 2 */
|
||||
#define _10_CGC_PLL_DIVISION_4 (0x10U) /* divides the clock frequency by 4 */
|
||||
/* Clock mode selection (SELPLL) */
|
||||
#define _00_CGC_NOSEL_PLL (0x00U) /* clock through mode */
|
||||
#define _04_CGC_SEL_PLL (0x04U) /* PLL clock select mode */
|
||||
/* PLL output clock (fPLLO) multiplier selection (PLLMUL) */
|
||||
#define _00_CGC_PLL_MULTIPLY_X12 (0x00U) /* clock through mode */
|
||||
#define _02_CGC_PLL_MULTIPLY_X16 (0x02U) /* PLL clock select mode */
|
||||
/* Operating or stopping PLL function (PLLON) */
|
||||
#define _00_CGC_PLL_STOP (0x00U) /* PLL operating stopped */
|
||||
#define _01_CGC_PLL_ENABLE (0x01U) /* PLL operating */
|
||||
|
||||
/*
|
||||
PLL status register (PLLSTS)
|
||||
*/
|
||||
/* PLL lock state */
|
||||
#define _00_CGC_PLL_UNLOCKED (0x00U) /* Unlocked state */
|
||||
#define _80_CGC_PLL_LOCKED (0x80U) /* Locked state */
|
||||
|
||||
/*
|
||||
FMP clock selection division register (MDIV)
|
||||
*/
|
||||
/* Division of PLL clock (fMP) */
|
||||
#define _00_CGC_FMP_DIV_DEFAULT (0x00U) /* fMP (default) */
|
||||
#define _01_CGC_FMP_DIV_1 (0x01U) /* fMP/2^1 */
|
||||
#define _02_CGC_FMP_DIV_2 (0x02U) /* fMP/2^2 */
|
||||
#define _03_CGC_FMP_DIV_3 (0x03U) /* fMP/2^3 */
|
||||
#define _04_CGC_FMP_DIV_4 (0x04U) /* fMP/2^4 */
|
||||
#define _05_CGC_FMP_DIV_5 (0x05U) /* fMP/2^5 */
|
||||
#define _06_CGC_FMP_DIV_6 (0x06U) /* fMP/2^6 */
|
||||
|
||||
/*
|
||||
System clock control register (CKC)
|
||||
*/
|
||||
/* Status of CPU/peripheral hardware clock fCLK (CLS) */
|
||||
#define _00_CGC_CPUCLK_MAIN (0x00U) /* main system clock (fMAIN) */
|
||||
#define _80_CGC_CPUCLK_SUB (0x80U) /* subsystem clock (fSUB) */
|
||||
/* Selection of CPU/peripheral hardware clock fCLK (CSS) */
|
||||
#define _00_CGC_CPUCLK_SELMAIN (0x00U) /* main system clock (fMAIN) */
|
||||
#define _40_CGC_CPUCLK_SELSUB (0x40U) /* subsystem clock (fSUB) */
|
||||
/* Status of Main system clock fMAIN (MCS) */
|
||||
#define _00_CGC_MAINCLK_HIO (0x00U) /* high-speed OCO clock (fIH) */
|
||||
#define _20_CGC_MAINCLK_HISYS (0x20U) /* high-speed system clock (fMX) */
|
||||
/* Selection of Main system clock fMAIN (MCM0) */
|
||||
#define _00_CGC_MAINCLK_SELHIO (0x00U) /* high-speed OCO clock (fIH) */
|
||||
#define _10_CGC_MAINCLK_SELHISYS (0x10U) /* high-speed system clock (fMX) */
|
||||
|
||||
/*
|
||||
Operation speed mode control register (OSMC)
|
||||
*/
|
||||
/* Setting in subsystem clock HALT mode (RTCLPC) */
|
||||
#define _00_CGC_SUBINHALT_ON (0x00U) /* enables supply of subsystem clock to peripheral functions */
|
||||
#define _80_CGC_SUBINHALT_OFF (0x80U) /* stops supply to peripheral functions other than RTC and interval timer */
|
||||
/* RTC macro operation clock (WUTMMCK0) */
|
||||
#define _00_CGC_RTC_CLK_OTHER (0x00U) /* Other than fIL */
|
||||
#define _10_CGC_RTC_CLK_FIL (0x10U) /* use fIL clock */
|
||||
|
||||
/*
|
||||
Illegal memory access detection control register (IAWCTL)
|
||||
*/
|
||||
/* Illegal memory access detection control (IAWEN) */
|
||||
#define _00_CGC_ILLEGAL_ACCESS_OFF (0x00U) /* disables illegal memory access detection */
|
||||
#define _80_CGC_ILLEGAL_ACCESS_ON (0x80U) /* enables illegal memory access detection */
|
||||
/* RAM guard area (GRAM1, GRAM0) */
|
||||
#define _00_CGC_RAM_GUARD_OFF (0x00U) /* invalid, it is possible to write RAM */
|
||||
#define _10_CGC_RAM_GUARD_AREA0 (0x10U) /* 128 bytes from RAM bottom address */
|
||||
#define _20_CGC_RAM_GUARD_AREA1 (0x20U) /* 256 bytes from RAM bottom address */
|
||||
#define _30_CGC_RAM_GUARD_AREA2 (0x30U) /* 512 bytes from RAM bottom address */
|
||||
/* PORT register guard (GPORT) */
|
||||
#define _00_CGC_PORT_GUARD_OFF (0x00U) /* invalid, it is possible to write PORT register */
|
||||
#define _04_CGC_PORT_GUARD_ON (0x04U) /* valid, it is impossible to write PORT register, but possible for read */
|
||||
/* Interrupt register guard (GINT) */
|
||||
#define _00_CGC_INT_GUARD_OFF (0x00U) /* invalid, it is possible to write interrupt register */
|
||||
#define _02_CGC_INT_GUARD_ON (0x02U) /* valid, it is impossible to write , but possible for read */
|
||||
/* CSC register guard (GCSC) */
|
||||
#define _00_CGC_CSC_GUARD_OFF (0x00U) /* invalid, it is possible to write CSC register */
|
||||
#define _01_CGC_CSC_GUARD_ON (0x01U) /* valid, it is impossible to write CSC register, but possible for read */
|
||||
|
||||
/*
|
||||
RTC clock selection register (RTCCL)
|
||||
*/
|
||||
/* Operation clock source selection for RTC (RTCCL7) */
|
||||
#define _00_CGC_RTC_FMX (0x00U) /* RTC uses External Main clock (fMX) */
|
||||
#define _80_CGC_RTC_FIH (0x80U) /* RTC uses Internal high speed clock (fIH) */
|
||||
/* Operation selection of RTC macro (RTCCL6,RTCCKS1 - RTCCKS0) */
|
||||
#define _00_CGC_RTC_FSUB (0x00U) /* RTC uses sub clock */
|
||||
#define _02_CGC_RTC_DIV128 (0x02U) /* RTC uses high-speed clock / 128 */
|
||||
#define _03_CGC_RTC_DIV256 (0x03U) /* RTC uses high-speed clock / 256 */
|
||||
#define _42_CGC_RTC_DIV122 (0x42U) /* RTC uses high-speed clock / 122 */
|
||||
#define _43_CGC_RTC_DIV244 (0x43U) /* RTC uses high-speed clock / 244 */
|
||||
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
HIOCLK,
|
||||
SYSX1CLK,
|
||||
SYSEXTCLK,
|
||||
SUBXT1CLK,
|
||||
SUBEXTCLK
|
||||
} clock_mode_t;
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
void R_CGC_Create(void);
|
||||
void R_CGC_Get_ResetSource(void);
|
||||
|
||||
/* Start user code for function. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#endif
|
64
app/r_cg_cgc_user.c
Normal file
64
app/r_cg_cgc_user.c
Normal file
@ -0,0 +1,64 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_cgc_user.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for CGC module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_cgc.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_CGC_Get_ResetSource
|
||||
* Description : This function process of Reset.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_CGC_Get_ResetSource(void)
|
||||
{
|
||||
uint8_t reset_flag = RESF;
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
89
app/r_cg_macrodriver.h
Normal file
89
app/r_cg_macrodriver.h
Normal file
@ -0,0 +1,89 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_macrodriver.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements general head file.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef STATUS_H
|
||||
#define STATUS_H
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "iodefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
#ifndef __TYPEDEF__
|
||||
#define DI __DI
|
||||
#define EI __EI
|
||||
#define HALT __halt
|
||||
#define NOP __nop
|
||||
#define STOP __stop
|
||||
#define BRK __brk
|
||||
|
||||
/* Status list definition */
|
||||
#define MD_STATUSBASE 0x00U
|
||||
#define MD_OK (MD_STATUSBASE + 0x00U) /* register setting OK */
|
||||
#define MD_SPT (MD_STATUSBASE + 0x01U) /* IIC stop */
|
||||
#define MD_NACK (MD_STATUSBASE + 0x02U) /* IIC no ACK */
|
||||
#define MD_BUSY1 (MD_STATUSBASE + 0x03U) /* busy 1 */
|
||||
#define MD_BUSY2 (MD_STATUSBASE + 0x04U) /* busy 2 */
|
||||
#define MD_OVERRUN (MD_STATUSBASE + 0x05U) /* IIC OVERRUN occur */
|
||||
|
||||
/* Error list definition */
|
||||
#define MD_ERRORBASE 0x80U
|
||||
#define MD_ERROR (MD_ERRORBASE + 0x00U) /* error */
|
||||
#define MD_ARGERROR (MD_ERRORBASE + 0x01U) /* error agrument input error */
|
||||
#define MD_ERROR1 (MD_ERRORBASE + 0x02U) /* error 1 */
|
||||
#define MD_ERROR2 (MD_ERRORBASE + 0x03U) /* error 2 */
|
||||
#define MD_ERROR3 (MD_ERRORBASE + 0x04U) /* error 3 */
|
||||
#define MD_ERROR4 (MD_ERRORBASE + 0x05U) /* error 4 */
|
||||
#define MD_DATAEXISTS (MD_ERRORBASE + 0x06U) /* data to be transferred next exists in TXBn register */
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
#ifndef __TYPEDEF__
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned short MD_STATUS;
|
||||
#define __TYPEDEF__
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#endif
|
77
app/r_cg_port.c
Normal file
77
app/r_cg_port.c
Normal file
@ -0,0 +1,77 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_port.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for PORT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_port.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_PORT_Create
|
||||
* Description : This function initializes the Port I/O.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_PORT_Create(void)
|
||||
{
|
||||
P3 = _00_Pn0_OUTPUT_0 | _00_Pn2_OUTPUT_0;
|
||||
P7 = _00_Pn0_OUTPUT_0 | _00_Pn1_OUTPUT_0 | _00_Pn2_OUTPUT_0 | _00_Pn3_OUTPUT_0;
|
||||
P13 = _00_Pn0_OUTPUT_0;
|
||||
P14 = _00_Pn0_OUTPUT_0;
|
||||
PMC12 = _00_PMCn0_DI_ON | _00_PMCn5_DI_ON | _DE_PMC12_DEFAULT;
|
||||
PSRSEL = _00_PSR140_NORMAL | _00_PSR120_NORMAL | _00_PSR30_NORMAL;
|
||||
ADPC = _05_ADPC_DI_ON;
|
||||
PM3 = _00_PMn0_MODE_OUTPUT | _02_PMn1_NOT_USE | _00_PMn2_MODE_OUTPUT | _08_PMn3_NOT_USE | _10_PMn4_NOT_USE |
|
||||
_E0_PM3_DEFAULT;
|
||||
PM6 = _01_PMn0_MODE_INPUT | _02_PMn1_MODE_INPUT | _04_PMn2_MODE_INPUT | _08_PMn3_MODE_INPUT | _F0_PM6_DEFAULT;
|
||||
PM7 = _00_PMn0_MODE_OUTPUT | _00_PMn1_MODE_OUTPUT | _00_PMn2_MODE_OUTPUT | _00_PMn3_MODE_OUTPUT | _F0_PM7_DEFAULT;
|
||||
PM8 = _01_PMn0_NOT_USE | _02_PMn1_NOT_USE | _04_PMn2_MODE_INPUT | _08_PMn3_MODE_INPUT | _10_PMn4_MODE_INPUT |
|
||||
_20_PMn5_MODE_INPUT | _40_PMn6_MODE_INPUT | _80_PMn7_MODE_INPUT;
|
||||
PM9 = _01_PMn0_NOT_USE | _02_PMn1_MODE_INPUT | _04_PMn2_MODE_INPUT | _F8_PM9_DEFAULT;
|
||||
PM12 = _01_PMn0_MODE_INPUT | _20_PMn5_MODE_INPUT | _DE_PM12_DEFAULT;
|
||||
PM14 = _00_PMn0_MODE_OUTPUT | _FE_PM14_DEFAULT;
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
257
app/r_cg_port.h
Normal file
257
app/r_cg_port.h
Normal file
@ -0,0 +1,257 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_port.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for PORT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef PORT_H
|
||||
#define PORT_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
/*
|
||||
Port Mode Register (PMm)
|
||||
*/
|
||||
/* Pmn pin I/O mode selection (PMm7 - PMm0) */
|
||||
#define _01_PMn0_NOT_USE (0x01U) /* not use Pn0 as digital I/O */
|
||||
#define _01_PMn0_MODE_INPUT (0x01U) /* use Pn0 as input mode */
|
||||
#define _00_PMn0_MODE_OUTPUT (0x00U) /* use Pn0 as output mode */
|
||||
#define _02_PMn1_NOT_USE (0x02U) /* not use Pn1 as digital I/O */
|
||||
#define _02_PMn1_MODE_INPUT (0x02U) /* use Pn1 as input mode */
|
||||
#define _00_PMn1_MODE_OUTPUT (0x00U) /* use Pn1 as output mode */
|
||||
#define _04_PMn2_NOT_USE (0x04U) /* not use Pn2 as digital I/O */
|
||||
#define _04_PMn2_MODE_INPUT (0x04U) /* use Pn2 as input mode */
|
||||
#define _00_PMn2_MODE_OUTPUT (0x00U) /* use Pn2 as output mode */
|
||||
#define _08_PMn3_NOT_USE (0x08U) /* not use Pn3 as digital I/O */
|
||||
#define _08_PMn3_MODE_INPUT (0x08U) /* use Pn3 as input mode */
|
||||
#define _00_PMn3_MODE_OUTPUT (0x00U) /* use Pn3 as output mode */
|
||||
#define _10_PMn4_NOT_USE (0x10U) /* not use Pn4 as digital I/O */
|
||||
#define _10_PMn4_MODE_INPUT (0x10U) /* use Pn4 as input mode */
|
||||
#define _00_PMn4_MODE_OUTPUT (0x00U) /* use Pn4 as output mode */
|
||||
#define _20_PMn5_NOT_USE (0x20U) /* not use Pn5 as digital I/O */
|
||||
#define _20_PMn5_MODE_INPUT (0x20U) /* use Pn5 as input mode */
|
||||
#define _00_PMn5_MODE_OUTPUT (0x00U) /* use Pn5 as output mode */
|
||||
#define _40_PMn6_NOT_USE (0x40U) /* not use Pn6 as digital I/O */
|
||||
#define _40_PMn6_MODE_INPUT (0x40U) /* use Pn6 as input mode */
|
||||
#define _00_PMn6_MODE_OUTPUT (0x00U) /* use Pn6 as output mode */
|
||||
#define _80_PMn7_NOT_USE (0x80U) /* not use Pn7 as digital I/O */
|
||||
#define _80_PMn7_MODE_INPUT (0x80U) /* use Pn7 as input mode */
|
||||
#define _00_PMn7_MODE_OUTPUT (0x00U) /* use Pn7 as output mode */
|
||||
|
||||
/*
|
||||
Port Register (Pm)
|
||||
*/
|
||||
/* Pmn pin data (Pm0 to Pm7) */
|
||||
#define _00_Pn0_OUTPUT_0 (0x00U) /* Pn0 output 0 */
|
||||
#define _01_Pn0_OUTPUT_1 (0x01U) /* Pn0 output 1 */
|
||||
#define _00_Pn1_OUTPUT_0 (0x00U) /* Pn1 output 0 */
|
||||
#define _02_Pn1_OUTPUT_1 (0x02U) /* Pn1 output 1 */
|
||||
#define _00_Pn2_OUTPUT_0 (0x00U) /* Pn2 output 0 */
|
||||
#define _04_Pn2_OUTPUT_1 (0x04U) /* Pn2 output 1 */
|
||||
#define _00_Pn3_OUTPUT_0 (0x00U) /* Pn3 output 0 */
|
||||
#define _08_Pn3_OUTPUT_1 (0x08U) /* Pn3 output 1 */
|
||||
#define _00_Pn4_OUTPUT_0 (0x00U) /* Pn4 output 0 */
|
||||
#define _10_Pn4_OUTPUT_1 (0x10U) /* Pn4 output 1 */
|
||||
#define _00_Pn5_OUTPUT_0 (0x00U) /* Pn5 output 0 */
|
||||
#define _20_Pn5_OUTPUT_1 (0x20U) /* Pn5 output 1 */
|
||||
#define _00_Pn6_OUTPUT_0 (0x00U) /* Pn6 output 0 */
|
||||
#define _40_Pn6_OUTPUT_1 (0x40U) /* Pn6 output 1 */
|
||||
#define _00_Pn7_OUTPUT_0 (0x00U) /* Pn7 output 0 */
|
||||
#define _80_Pn7_OUTPUT_1 (0x80U) /* Pn7 output 1 */
|
||||
|
||||
/*
|
||||
Pull-up Resistor Option Register (PUm)
|
||||
*/
|
||||
/* Pmn pin on-chip pull-up resistor selection (PUmn) */
|
||||
#define _00_PUn0_PULLUP_OFF (0x00U) /* Pn0 pull-up resistor not connected */
|
||||
#define _01_PUn0_PULLUP_ON (0x01U) /* Pn0 pull-up resistor connected */
|
||||
#define _00_PUn1_PULLUP_OFF (0x00U) /* Pn1 pull-up resistor not connected */
|
||||
#define _02_PUn1_PULLUP_ON (0x02U) /* Pn1 pull-up resistor connected */
|
||||
#define _00_PUn2_PULLUP_OFF (0x00U) /* Pn2 Pull-up resistor not connected */
|
||||
#define _04_PUn2_PULLUP_ON (0x04U) /* Pn2 pull-up resistor connected */
|
||||
#define _00_PUn3_PULLUP_OFF (0x00U) /* Pn3 pull-up resistor not connected */
|
||||
#define _08_PUn3_PULLUP_ON (0x08U) /* Pn3 pull-up resistor connected */
|
||||
#define _00_PUn4_PULLUP_OFF (0x00U) /* Pn4 pull-up resistor not connected */
|
||||
#define _10_PUn4_PULLUP_ON (0x10U) /* Pn4 pull-up resistor connected */
|
||||
#define _00_PUn5_PULLUP_OFF (0x00U) /* Pn5 pull-up resistor not connected */
|
||||
#define _20_PUn5_PULLUP_ON (0x20U) /* Pn5 pull-up resistor connected */
|
||||
#define _00_PUn6_PULLUP_OFF (0x00U) /* Pn6 pull-up resistor not connected */
|
||||
#define _40_PUn6_PULLUP_ON (0x40U) /* Pn6 pull-up resistor connected */
|
||||
#define _00_PUn7_PULLUP_OFF (0x00U) /* Pn7 pull-up resistor not connected */
|
||||
#define _80_PUn7_PULLUP_ON (0x80U) /* Pn7 pull-up resistor connected */
|
||||
|
||||
/*
|
||||
Port Input Mode Register (PIMm)
|
||||
*/
|
||||
/* Pmn pin input buffer selection (PIMmn) */
|
||||
#define _00_PIMn0_TTL_OFF (0x00U) /* set Pn0 normal input buffer */
|
||||
#define _01_PIMn0_TTL_ON (0x01U) /* set Pn0 TTL input buffer */
|
||||
#define _00_PIMn1_TTL_OFF (0x00U) /* set Pn1 normal input buffer */
|
||||
#define _02_PIMn1_TTL_ON (0x02U) /* set Pn1 TTL input buffer */
|
||||
#define _00_PIMn2_TTL_OFF (0x00U) /* set Pn2 normal input buffer */
|
||||
#define _04_PIMn2_TTL_ON (0x04U) /* set Pn2 TTL input buffer */
|
||||
#define _00_PIMn3_TTL_OFF (0x00U) /* set Pn3 normal input buffer */
|
||||
#define _08_PIMn3_TTL_ON (0x08U) /* set Pn3 TTL input buffer */
|
||||
#define _00_PIMn4_TTL_OFF (0x00U) /* set Pn4 normal input buffer */
|
||||
#define _10_PIMn4_TTL_ON (0x10U) /* set Pn4 TTL input buffer */
|
||||
#define _00_PIMn5_TTL_OFF (0x00U) /* set Pn5 normal input buffer */
|
||||
#define _20_PIMn5_TTL_ON (0x20U) /* set Pn5 TTL input buffer */
|
||||
#define _00_PIMn6_TTL_OFF (0x00U) /* set Pn6 normal input buffer */
|
||||
#define _40_PIMn6_TTL_ON (0x40U) /* set Pn6 TTL input buffer */
|
||||
#define _00_PIMn7_TTL_OFF (0x00U) /* set Pn7 normal input buffer */
|
||||
#define _80_PIMn7_TTL_ON (0x80U) /* set Pn7 TTL input buffer */
|
||||
|
||||
/*
|
||||
Port Input Threshold Control Register (PITHLm)
|
||||
*/
|
||||
/* Pmn pin input threshold selection (PITHLmn) */
|
||||
#define _00_PITHLn0_SCHMITT3_OFF (0x00U) /* set Pn0 schmitt 1 input (default) */
|
||||
#define _01_PITHLn0_SCHMITT3_ON (0x01U) /* set Pn0 schmitt 3 input */
|
||||
#define _00_PITHLn1_SCHMITT3_OFF (0x00U) /* set Pn1 schmitt 1 input (default) */
|
||||
#define _02_PITHLn1_SCHMITT3_ON (0x02U) /* set Pn1 schmitt 3 input */
|
||||
#define _00_PITHLn2_SCHMITT3_OFF (0x00U) /* set Pn2 schmitt 1 input (default) */
|
||||
#define _04_PITHLn2_SCHMITT3_ON (0x04U) /* set Pn2 schmitt 3 input */
|
||||
#define _00_PITHLn3_SCHMITT3_OFF (0x00U) /* set Pn3 schmitt 1 input (default) */
|
||||
#define _08_PITHLn3_SCHMITT3_ON (0x08U) /* set Pn3 schmitt 3 input */
|
||||
#define _00_PITHLn4_SCHMITT3_OFF (0x00U) /* set Pn4 schmitt 1 input (default) */
|
||||
#define _10_PITHLn4_SCHMITT3_ON (0x10U) /* set Pn4 schmitt 3 input */
|
||||
#define _00_PITHLn5_SCHMITT3_OFF (0x00U) /* set Pn5 schmitt 1 input (default) */
|
||||
#define _20_PITHLn5_SCHMITT3_ON (0x20U) /* set Pn5 schmitt 3 input */
|
||||
#define _00_PITHLn6_SCHMITT3_OFF (0x00U) /* set Pn6 schmitt 1 input (default) */
|
||||
#define _40_PITHLn6_SCHMITT3_ON (0x40U) /* set Pn6 schmitt 3 input */
|
||||
#define _00_PITHLn7_SCHMITT3_OFF (0x00U) /* set Pn7 schmitt 1 input (default) */
|
||||
#define _80_PITHLn7_SCHMITT3_ON (0x80U) /* set Pn7 schmitt 3 input */
|
||||
|
||||
/*
|
||||
Port Output Mode Register (POMm)
|
||||
*/
|
||||
/* Pmn pin output mode selection (POMmn) */
|
||||
#define _00_POMn0_NCH_OFF (0x00U) /* set Pn0 output normal mode */
|
||||
#define _01_POMn0_NCH_ON (0x01U) /* set Pn0 output N-ch open-drain mode */
|
||||
#define _00_POMn1_NCH_OFF (0x00U) /* set Pn1 output normal mode */
|
||||
#define _02_POMn1_NCH_ON (0x02U) /* set Pn1 output N-ch open-drain mode */
|
||||
#define _00_POMn2_NCH_OFF (0x00U) /* set Pn2 output normal mode */
|
||||
#define _04_POMn2_NCH_ON (0x04U) /* set Pn2 output N-ch open-drain mode */
|
||||
#define _00_POMn3_NCH_OFF (0x00U) /* set Pn3 output normal mode */
|
||||
#define _08_POMn3_NCH_ON (0x08U) /* set Pn3 output N-ch open-drain mode */
|
||||
#define _00_POMn4_NCH_OFF (0x00U) /* set Pn4 output normal mode */
|
||||
#define _10_POMn4_NCH_ON (0x10U) /* set Pn4 output N-ch open-drain mode */
|
||||
#define _00_POMn5_NCH_OFF (0x00U) /* set Pn5 output normal mode */
|
||||
#define _20_POMn5_NCH_ON (0x20U) /* set Pn5 output N-ch open-drain mode */
|
||||
#define _00_POMn6_NCH_OFF (0x00U) /* set Pn6 output normal mode */
|
||||
#define _40_POMn6_NCH_ON (0x40U) /* set Pn6 output N-ch open-drain mode */
|
||||
#define _00_POMn7_NCH_OFF (0x00U) /* set Pn7 output normal mode */
|
||||
#define _80_POMn7_NCH_ON (0x80U) /* set Pn7 output N-ch open-drain mode */
|
||||
|
||||
/*
|
||||
Port Operation Mode Register (PMCm)
|
||||
*/
|
||||
/* Pmn pin digital input buffer selection (PMCmn) */
|
||||
#define _01_PMCn0_NOT_USE (0x01U) /* not use Pn0 digital input */
|
||||
#define _00_PMCn0_DI_ON (0x00U) /* enable Pn0 digital input */
|
||||
#define _02_PMCn1_NOT_USE (0x02U) /* not use Pn1 digital input */
|
||||
#define _00_PMCn1_DI_ON (0x00U) /* enable Pn1 digital input */
|
||||
#define _04_PMCn2_NOT_USE (0x04U) /* not use Pn2 digital input */
|
||||
#define _00_PMCn2_DI_ON (0x00U) /* enable Pn2 digital input */
|
||||
#define _08_PMCn3_NOT_USE (0x08U) /* not use Pn3 digital input */
|
||||
#define _00_PMCn3_DI_ON (0x00U) /* enable Pn3 digital input */
|
||||
#define _10_PMCn4_NOT_USE (0x10U) /* not use Pn4 digital input */
|
||||
#define _00_PMCn4_DI_ON (0x00U) /* enable Pn4 digital input */
|
||||
#define _20_PMCn5_NOT_USE (0x20U) /* not use Pn5 digital input */
|
||||
#define _00_PMCn5_DI_ON (0x00U) /* enable Pn5 digital input */
|
||||
#define _40_PMCn6_NOT_USE (0x40U) /* not use Pn6 digital input */
|
||||
#define _00_PMCn6_DI_ON (0x00U) /* enable Pn6 digital input */
|
||||
#define _80_PMCn7_NOT_USE (0x80U) /* not use Pn7 digital input */
|
||||
#define _00_PMCn7_DI_ON (0x00U) /* enable Pn7 digital input */
|
||||
|
||||
/*
|
||||
Port output slew rate select register (PSRSEL)
|
||||
*/
|
||||
/* P140/PCLBUZ0 pin output mode selection (PSR140) */
|
||||
#define _00_PSR140_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _20_PSR140_SLOW (0x20U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
/* P14/SCK01/SCL01/TO06/TRDIOC0 pin output mode selection (PSR14) */
|
||||
#define _00_PSR14_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _10_PSR14_SLOW (0x10U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
/* P120/SO01/TO07/TRDIOD0 pin output mode selection (PSR120) */
|
||||
#define _00_PSR120_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _08_PSR120_SLOW (0x08U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
/* P30/TO01/TRDIOD1/SNZOUT0 pin output mode selection (PSR30) */
|
||||
#define _00_PSR30_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _04_PSR30_SLOW (0x04U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
/* P12/SO10/TO11/(TRDIOD0)/TXD1/SNZOUT3 pin output mode selection (PSR12) */
|
||||
#define _00_PSR12_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _02_PSR12_SLOW (0x02U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
/* P10/SCK10/TO13/TRJO0/SCL10/LTXD1/CTXD0 pin output mode selection (PSR10) */
|
||||
#define _00_PSR10_NORMAL (0x00U) /* normal mode (5 V/5 ns) */
|
||||
#define _01_PSR10_SLOW (0x01U) /* slow mode (25 V/5 ns (target) (TYP.)) */
|
||||
|
||||
|
||||
/*
|
||||
AD port configuration register (ADPC)
|
||||
*/
|
||||
/* Analog input/digital input switching (ADPC4 - ADPC0) */
|
||||
#define _00_ADPC_DI_OFF (0x00U) /* use P33, P34, P80 - P87, P90 - P92 as analog input */
|
||||
#define _0D_ADPC_DI_ON (0x0DU) /* use P92 as digital input */
|
||||
#define _0C_ADPC_DI_ON (0x0CU) /* use P91 - P92 as digital input */
|
||||
#define _0B_ADPC_DI_ON (0x0BU) /* use P90 - P92 as digital input */
|
||||
#define _0A_ADPC_DI_ON (0x0AU) /* use P87, P90 - P92 as digital input */
|
||||
#define _09_ADPC_DI_ON (0x09U) /* use P86 - P87, P90 - P92 as digital input */
|
||||
#define _08_ADPC_DI_ON (0x08U) /* use P85 - P87, P90 - P92 as digital input */
|
||||
#define _07_ADPC_DI_ON (0x07U) /* use P84 - P87, P90 - P92 as digital input */
|
||||
#define _06_ADPC_DI_ON (0x06U) /* use P83 - P87, P90 - P92 as digital input */
|
||||
#define _05_ADPC_DI_ON (0x05U) /* use P82 - P87, P90 - P92 as digital input */
|
||||
#define _04_ADPC_DI_ON (0x04U) /* use P81 - P87, P90 - P92 as digital input */
|
||||
#define _03_ADPC_DI_ON (0x03U) /* use P80 - P87, P90 - P92 as digital input */
|
||||
#define _02_ADPC_DI_ON (0x02U) /* use P34, P80 - P87, P90 - P92 as digital input */
|
||||
#define _01_ADPC_DI_ON (0x01U) /* use P33, P34, P80 - P87, P90 - P92 as digital input */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
#define _FE_PM0_DEFAULT (0xFEU) /* PM0 default value */
|
||||
#define _E0_PM3_DEFAULT (0xE0U) /* PM3 default value */
|
||||
#define _FC_PM4_DEFAULT (0xFCU) /* PM4 default value */
|
||||
#define _F0_PM6_DEFAULT (0xF0U) /* PM6 default value */
|
||||
#define _F0_PM7_DEFAULT (0xF0U) /* PM7 default value */
|
||||
#define _F8_PM9_DEFAULT (0xF8U) /* PM9 default value */
|
||||
#define _DE_PM12_DEFAULT (0xDEU) /* PM12 default value */
|
||||
#define _FE_PM14_DEFAULT (0xFEU) /* PM14 default value */
|
||||
#define _DE_PMC12_DEFAULT (0xDEU) /* PMC12 default value */
|
||||
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
void R_PORT_Create(void);
|
||||
|
||||
/* Start user code for function. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#endif
|
51
app/r_cg_port_user.c
Normal file
51
app/r_cg_port_user.c
Normal file
@ -0,0 +1,51 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_port_user.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for PORT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_port.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
217
app/r_cg_timer.c
Normal file
217
app/r_cg_timer.c
Normal file
@ -0,0 +1,217 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_timer.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for TAU module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_timer.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Create
|
||||
* Description : This function initializes the TAU0 module.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Create(void)
|
||||
{
|
||||
TAU0EN = 1U; /* supplies input clock */
|
||||
TPS0 = _0000_TAU_CKM0_FCLK_0 | _0000_TAU_CKM1_FCLK_0 | _0000_TAU_CKM2_FCLK_0 | _0000_TAU_CKM3_FCLK_0;
|
||||
/* Stop all channels */
|
||||
TT0 = _0001_TAU_CH0_STOP_TRG_ON | _0002_TAU_CH1_STOP_TRG_ON | _0004_TAU_CH2_STOP_TRG_ON |
|
||||
_0008_TAU_CH3_STOP_TRG_ON | _0010_TAU_CH4_STOP_TRG_ON | _0020_TAU_CH5_STOP_TRG_ON |
|
||||
_0040_TAU_CH6_STOP_TRG_ON | _0080_TAU_CH7_STOP_TRG_ON | _0200_TAU_CH1_H8_STOP_TRG_ON |
|
||||
_0800_TAU_CH3_H8_STOP_TRG_ON;
|
||||
PWMDLY1 = _0000_TAU_PWM_DELAY_CLEAR; /* clear PWM output delay */
|
||||
/* Mask channel 0 interrupt */
|
||||
TMMK00 = 1U; /* disable INTTM00 interrupt */
|
||||
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
||||
/* Mask channel 1 interrupt */
|
||||
TMMK01 = 1U; /* disable INTTM01 interrupt */
|
||||
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
||||
/* Mask channel 1 higher 8 bits interrupt */
|
||||
TMMK01H = 1U; /* disable INTTM01H interrupt */
|
||||
TMIF01H = 0U; /* clear INTTM01H interrupt flag */
|
||||
/* Mask channel 2 interrupt */
|
||||
TMMK02 = 1U; /* disable INTTM02 interrupt */
|
||||
TMIF02 = 0U; /* clear INTTM02 interrupt flag */
|
||||
/* Mask channel 3 interrupt */
|
||||
TMMK03 = 1U; /* disable INTTM03 interrupt */
|
||||
TMIF03 = 0U; /* clear INTTM03 interrupt flag */
|
||||
/* Mask channel 3 higher 8 bits interrupt */
|
||||
TMMK03H = 1U; /* disable INTTM03H interrupt */
|
||||
TMIF03H = 0U; /* clear INTTM03H interrupt flag */
|
||||
/* Mask channel 4 interrupt */
|
||||
TMMK04 = 1U; /* disable INTTM04 interrupt */
|
||||
TMIF04 = 0U; /* clear INTTM04 interrupt flag */
|
||||
/* Mask channel 5 interrupt */
|
||||
TMMK05 = 1U; /* disable INTTM05 interrupt */
|
||||
TMIF05 = 0U; /* clear INTTM05 interrupt flag */
|
||||
/* Mask channel 6 interrupt */
|
||||
TMMK06 = 1U; /* disable INTTM06 interrupt */
|
||||
TMIF06 = 0U; /* clear INTTM06 interrupt flag */
|
||||
/* Mask channel 7 interrupt */
|
||||
TMMK07 = 1U; /* disable INTTM07 interrupt */
|
||||
TMIF07 = 0U; /* clear INTTM07 interrupt flag */
|
||||
/* Set INTTM00 low priority */
|
||||
TMPR100 = 1U;
|
||||
TMPR000 = 1U;
|
||||
/* Set INTTM01 low priority */
|
||||
TMPR101 = 1U;
|
||||
TMPR001 = 1U;
|
||||
/* Channel 0 used as interval timer */
|
||||
TMR00 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
|
||||
_0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED;
|
||||
TDR00 = _7CFF_TAU_TDR00_VALUE;
|
||||
TO0 &= ~_0001_TAU_CH0_OUTPUT_VALUE_1;
|
||||
TOE0 &= ~_0001_TAU_CH0_OUTPUT_ENABLE;
|
||||
/* Channel 1 used as interval timer */
|
||||
TMR01 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_16BITS_MODE |
|
||||
_0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED;
|
||||
TDR01 = _7CFF_TAU_TDR01_VALUE;
|
||||
TOM0 &= ~_0002_TAU_CH1_OUTPUT_COMBIN;
|
||||
TOL0 &= ~_0002_TAU_CH1_OUTPUT_LEVEL_L;
|
||||
TO0 &= ~_0002_TAU_CH1_OUTPUT_VALUE_1;
|
||||
TOE0 &= ~_0002_TAU_CH1_OUTPUT_ENABLE;
|
||||
/* Channel 4 is used as master channel for PWM output function */
|
||||
TMR04 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0800_TAU_COMBINATION_MASTER |
|
||||
_0000_TAU_TRIGGER_SOFTWARE | _0001_TAU_MODE_PWM_MASTER;
|
||||
TDR04 = _7CFF_TAU_TDR04_VALUE;
|
||||
TOM0 &= ~_0010_TAU_CH4_OUTPUT_COMBIN;
|
||||
TOL0 &= ~_0010_TAU_CH4_OUTPUT_LEVEL_L;
|
||||
TO0 &= ~_0010_TAU_CH4_OUTPUT_VALUE_1;
|
||||
TOE0 &= ~_0010_TAU_CH4_OUTPUT_ENABLE;
|
||||
/* Channel 5 is used as slave channel for PWM output function */
|
||||
TMR05 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
|
||||
_0400_TAU_TRIGGER_MASTER_INT | _0009_TAU_MODE_PWM_SLAVE;
|
||||
TDR05 = _3E80_TAU_TDR05_VALUE;
|
||||
TOM0 |= _0020_TAU_CH5_OUTPUT_COMBIN;
|
||||
TOL0 &= ~_0020_TAU_CH5_OUTPUT_LEVEL_L;
|
||||
TO0 &= ~_0020_TAU_CH5_OUTPUT_VALUE_1;
|
||||
PWMDLY1 |= _0000_TO05_OUTPUT_DELAY_0;
|
||||
TOE0 |= _0020_TAU_CH5_OUTPUT_ENABLE;
|
||||
/* Set TO05 pin */
|
||||
P0 &= 0xFEU;
|
||||
PM0 &= 0xFEU;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel0_Start
|
||||
* Description : This function starts TAU0 channel 0 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel0_Start(void)
|
||||
{
|
||||
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
||||
TMMK00 = 0U; /* enable INTTM00 interrupt */
|
||||
TS0 |= _0001_TAU_CH0_START_TRG_ON;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel0_Stop
|
||||
* Description : This function stops TAU0 channel 0 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel0_Stop(void)
|
||||
{
|
||||
TT0 |= _0001_TAU_CH0_STOP_TRG_ON;
|
||||
/* Mask channel 0 interrupt */
|
||||
TMMK00 = 1U; /* disable INTTM00 interrupt */
|
||||
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel1_Start
|
||||
* Description : This function starts TAU0 channel 1 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel1_Start(void)
|
||||
{
|
||||
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
||||
TMMK01 = 0U; /* enable INTTM01 interrupt */
|
||||
TS0 |= _0002_TAU_CH1_START_TRG_ON;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel1_Stop
|
||||
* Description : This function stops TAU0 channel 1 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel1_Stop(void)
|
||||
{
|
||||
TT0 |= _0002_TAU_CH1_STOP_TRG_ON;
|
||||
/* Mask channel 1 interrupt */
|
||||
TMMK01 = 1U; /* disable INTTM01 interrupt */
|
||||
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel4_Start
|
||||
* Description : This function starts TAU0 channel 4 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel4_Start(void)
|
||||
{
|
||||
TOE0 |= _0020_TAU_CH5_OUTPUT_ENABLE;
|
||||
TS0 |= _0010_TAU_CH4_START_TRG_ON | _0020_TAU_CH5_START_TRG_ON;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_TAU0_Channel4_Stop
|
||||
* Description : This function stops TAU0 channel 4 counter.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_TAU0_Channel4_Stop(void)
|
||||
{
|
||||
TT0 |= _0010_TAU_CH4_STOP_TRG_ON | _0020_TAU_CH5_STOP_TRG_ON;
|
||||
TOE0 &= ~_0020_TAU_CH5_OUTPUT_ENABLE;
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
1051
app/r_cg_timer.h
Normal file
1051
app/r_cg_timer.h
Normal file
File diff suppressed because it is too large
Load Diff
79
app/r_cg_timer_user.c
Normal file
79
app/r_cg_timer_user.c
Normal file
@ -0,0 +1,79 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_timer_user.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for TAU module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_timer.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
#include "appTask.h"
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
#pragma interrupt r_tau0_channel0_interrupt(vect=INTTM00)
|
||||
#pragma interrupt r_tau0_channel1_interrupt(vect=INTTM01)
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_tau0_channel0_interrupt
|
||||
* Description : This function is INTTM00 interrupt service routine.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
static void __near r_tau0_channel0_interrupt(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
Timer_Pro();
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_tau0_channel1_interrupt
|
||||
* Description : This function is INTTM01 interrupt service routine.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
static void __near r_tau0_channel1_interrupt(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
39
app/r_cg_userdefine.h
Normal file
39
app/r_cg_userdefine.h
Normal file
@ -0,0 +1,39 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_userdefine.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file includes user definition.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef _USER_DEF_H
|
||||
#define _USER_DEF_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
User definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/* Start user code for function. Do not edit comment generated here */
|
||||
#define RLIN_Master
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#endif
|
78
app/r_cg_wdt.c
Normal file
78
app/r_cg_wdt.c
Normal file
@ -0,0 +1,78 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_wdt.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for WDT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_wdt.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_WDT_Create
|
||||
* Description : This function initializes the watchdogtimer.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_WDT_Create(void)
|
||||
{
|
||||
WDTIMK = 1U; /* disable INTWDTI interrupt */
|
||||
WDTIIF = 0U; /* clear INTWDTI interrupt flag */
|
||||
/* Set INTWDTI low priority */
|
||||
WDTIPR1 = 1U;
|
||||
WDTIPR0 = 1U;
|
||||
WDTIMK = 0U; /* enable INTWDTI interrupt */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_WDT_Restart
|
||||
* Description : This function restarts the watchdog timer.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_WDT_Restart(void)
|
||||
{
|
||||
WDTE = 0xACU; /* restart watchdog timer */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
52
app/r_cg_wdt.h
Normal file
52
app/r_cg_wdt.h
Normal file
@ -0,0 +1,52 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_wdt.h
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for WDT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#ifndef WDT_H
|
||||
#define WDT_H
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions (Register bit)
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Macro definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Typedef definitions
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global functions
|
||||
***********************************************************************************************************************/
|
||||
void R_WDT_Create(void);
|
||||
void R_WDT_Restart(void);
|
||||
|
||||
/* Start user code for function. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#endif
|
64
app/r_cg_wdt_user.c
Normal file
64
app/r_cg_wdt_user.c
Normal file
@ -0,0 +1,64 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_cg_wdt_user.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements device driver for WDT module.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_wdt.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
#pragma interrupt r_wdt_interrupt(vect=INTWDTI)
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: r_wdt_interrupt
|
||||
* Description : This function is INTWDTI interrupt service routine.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
static void __near r_wdt_interrupt(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
89
app/r_main.c
Normal file
89
app/r_main.c
Normal file
@ -0,0 +1,89 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_main.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements main function.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_cgc.h"
|
||||
#include "r_cg_port.h"
|
||||
#include "r_cg_adc.h"
|
||||
#include "r_cg_timer.h"
|
||||
#include "r_cg_wdt.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
#include "appTask.h"
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
void R_MAIN_UserInit(void);
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: main
|
||||
* Description : This function implements main function.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void main(void)
|
||||
{
|
||||
R_MAIN_UserInit();
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
value_init();
|
||||
while (1U)
|
||||
{
|
||||
Apply_task();
|
||||
}
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_MAIN_UserInit
|
||||
* Description : This function adds user code before implementing main function.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_MAIN_UserInit(void)
|
||||
{
|
||||
/* Start user code. Do not edit comment generated here */
|
||||
|
||||
EI();
|
||||
/* End user code. Do not edit comment generated here */
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
93
app/r_systeminit.c
Normal file
93
app/r_systeminit.c
Normal file
@ -0,0 +1,93 @@
|
||||
/***********************************************************************************************************************
|
||||
* DISCLAIMER
|
||||
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
||||
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
* applicable laws, including copyright laws.
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
||||
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
||||
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
||||
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
* following link:
|
||||
* http://www.renesas.com/disclaimer
|
||||
*
|
||||
* Copyright (C) 2012, 2021 Renesas Electronics Corporation. All rights reserved.
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* File Name : r_systeminit.c
|
||||
* Version : CodeGenerator for RL78/F13 V2.03.07.02 [08 Nov 2021]
|
||||
* Device(s) : R5F10AGF
|
||||
* Tool-Chain : CCRL
|
||||
* Description : This file implements system initializing function.
|
||||
* Creation Date: 2024-01-08
|
||||
***********************************************************************************************************************/
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Includes
|
||||
***********************************************************************************************************************/
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_cgc.h"
|
||||
#include "r_cg_port.h"
|
||||
#include "r_cg_adc.h"
|
||||
#include "r_cg_timer.h"
|
||||
#include "r_cg_wdt.h"
|
||||
/* Start user code for include. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Pragma directive
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for pragma. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
Global variables and functions
|
||||
***********************************************************************************************************************/
|
||||
/* Start user code for global. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: R_Systeminit
|
||||
* Description : This function initializes every macro.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void R_Systeminit(void)
|
||||
{
|
||||
/* Set periperal I/O redirection */
|
||||
PIOR0 = 0x00U;
|
||||
PIOR1 = 0x20U;
|
||||
PIOR4 = 0x00U;
|
||||
PIOR5 = 0x00U;
|
||||
PIOR7 = 0x00U;
|
||||
R_CGC_Get_ResetSource();
|
||||
R_CGC_Create();
|
||||
R_PORT_Create();
|
||||
R_ADC_Create();
|
||||
R_TAU0_Create();
|
||||
R_WDT_Create();
|
||||
|
||||
/* Set invalid memory access detection control */
|
||||
IAWCTL = 0x00U;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Function Name: hdwinit
|
||||
* Description : This function initializes hardware setting.
|
||||
* Arguments : None
|
||||
* Return Value : None
|
||||
***********************************************************************************************************************/
|
||||
void hdwinit(void)
|
||||
{
|
||||
DI();
|
||||
R_Systeminit();
|
||||
}
|
||||
|
||||
/* Start user code for adding. Do not edit comment generated here */
|
||||
/* End user code. Do not edit comment generated here */
|
77
app/stkinit.asm
Normal file
77
app/stkinit.asm
Normal file
@ -0,0 +1,77 @@
|
||||
;/**********************************************************************************************************************
|
||||
; * DISCLAIMER
|
||||
; * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
|
||||
; * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
||||
; * applicable laws, including copyright laws.
|
||||
; * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
|
||||
; * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
||||
; * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
|
||||
; * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
|
||||
; * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO
|
||||
; * THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
; * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
|
||||
; * this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
||||
; * following link:
|
||||
; * http://www.renesas.com/disclaimer
|
||||
; *
|
||||
; * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved.
|
||||
; *********************************************************************************************************************/;---------------------------------------------------------------------
|
||||
; _stkinit
|
||||
;
|
||||
; void _stkinit(void __near * stackbss);
|
||||
;
|
||||
; input:
|
||||
; stackbss = AX (#LOWW(_stackend))
|
||||
; output:
|
||||
; NONE
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
; NOTE : THIS IS A TYPICAL EXAMPLE.
|
||||
|
||||
.PUBLIC _stkinit
|
||||
|
||||
.textf .CSEG TEXTF
|
||||
_stkinit:
|
||||
MOVW HL,AX ; stack_end_addr
|
||||
MOV [SP+3],#0x00 ; [SP+0]-[SP+2] for return address
|
||||
MOVW AX,SP
|
||||
SUBW AX,HL ; SUBW AX,#LOWW _@STEND
|
||||
BNH $LSTINIT3 ; goto end
|
||||
SHRW AX,5 ; loop count for 32 byte transfer
|
||||
MOVW BC,AX
|
||||
CLRW AX
|
||||
LSTINIT1:
|
||||
CMPW AX,BC
|
||||
BZ $LSTINIT2
|
||||
MOVW [HL],AX
|
||||
MOVW [HL+2],AX
|
||||
MOVW [HL+4],AX
|
||||
MOVW [HL+6],AX
|
||||
MOVW [HL+8],AX
|
||||
MOVW [HL+10],AX
|
||||
MOVW [HL+12],AX
|
||||
MOVW [HL+14],AX
|
||||
MOVW [HL+16],AX
|
||||
MOVW [HL+18],AX
|
||||
MOVW [HL+20],AX
|
||||
MOVW [HL+22],AX
|
||||
MOVW [HL+24],AX
|
||||
MOVW [HL+26],AX
|
||||
MOVW [HL+28],AX
|
||||
MOVW [HL+30],AX
|
||||
XCHW AX,HL
|
||||
ADDW AX,#0x20
|
||||
XCHW AX,HL
|
||||
DECW BC
|
||||
BR $LSTINIT1
|
||||
LSTINIT2:
|
||||
MOVW AX,SP
|
||||
CMPW AX,HL
|
||||
BZ $LSTINIT3 ; goto end
|
||||
CLRW AX
|
||||
MOVW [HL],AX
|
||||
INCW HL
|
||||
INCW HL
|
||||
BR $LSTINIT2
|
||||
LSTINIT3:
|
||||
RET
|
900
app/user/MotorCtrl.c
Normal file
900
app/user/MotorCtrl.c
Normal file
@ -0,0 +1,900 @@
|
||||
|
||||
#include "MotorCtrl.h"
|
||||
|
||||
#include "hwCtrl.h"
|
||||
#include "PINdef.h"
|
||||
#include "appTask.h"
|
||||
#include "pfdl.h"
|
||||
|
||||
|
||||
uint8_t MotorState[6],MotorStateReal[6];
|
||||
uint16_t MotorHallLoc[6],MotorHardStop1[6],MotorHardStop2[6];
|
||||
uint8_t MotorLearnState[6];
|
||||
uint8_t MotorErr[6];
|
||||
uint16_t current1,current2,current3;
|
||||
|
||||
static uint8_t AutoCalState;
|
||||
|
||||
uint8_t EEL_SAVE_REQUIRE_FLAG;
|
||||
uint16_t EEL_SAVE_Counter;
|
||||
#define OVMOTORKB 1
|
||||
#define OVMOTORZY 2
|
||||
|
||||
uint8_t OC1flag,OC2flag,OC3flag;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t MotorStopLoc1;
|
||||
uint16_t MotorStopLoc2;
|
||||
uint16_t MotorNowLoc;
|
||||
}MOTOR_DATA;
|
||||
|
||||
MOTOR_DATA MotorData[6];
|
||||
uint16_t MemoryLoc[3][6];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t start_flag;
|
||||
MOTOR_DATA MotorData[6];
|
||||
uint16_t MemoryLoc[3][6];
|
||||
uint16_t checksum;
|
||||
uint16_t stop_flag;
|
||||
}MEMORY_DATA;
|
||||
MEMORY_DATA MemoryData;
|
||||
|
||||
uint16_t GetCheckSum(uint16_t * addr,uint8_t len)
|
||||
{
|
||||
uint16_t sum=0;
|
||||
while (len --)
|
||||
{
|
||||
sum += *addr;
|
||||
}
|
||||
sum ^= 0xffff;
|
||||
|
||||
return sum;
|
||||
}
|
||||
#define START_FLAG 0x55aa
|
||||
#define STOP_FLAG 0xaa55
|
||||
void WriteMotorMemory(void)
|
||||
{
|
||||
uint8_t i;
|
||||
if (EEL_SAVE_REQUIRE_FLAG == 0 || EEL_SAVE_Counter > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MemoryData.start_flag = START_FLAG;
|
||||
MemoryData.stop_flag = STOP_FLAG;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MemoryData.MotorData[i].MotorNowLoc = MotorHallLoc[i];
|
||||
MemoryData.MotorData[i].MotorStopLoc1 = MotorHardStop1[i];
|
||||
MemoryData.MotorData[i].MotorStopLoc2 = MotorHardStop2[i];
|
||||
MemoryData.MemoryLoc[0][i] = MemoryLoc[0][i];
|
||||
MemoryData.MemoryLoc[1][i] = MemoryLoc[1][i];
|
||||
MemoryData.MemoryLoc[2][i] = MemoryLoc[2][i];
|
||||
}
|
||||
|
||||
|
||||
MemoryData.checksum = GetCheckSum(&MemoryData.MotorData[0].MotorStopLoc1,36);
|
||||
if(WriteDataflash(&MemoryData,0x000F1000,sizeof(MemoryData)) == 0x11)
|
||||
{
|
||||
EEL_SAVE_REQUIRE_FLAG=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ReadMotorMemory(void)
|
||||
{
|
||||
uint16_t checksum;
|
||||
uint8_t i;
|
||||
ReadFlashData(&MemoryData,0x000F1000,sizeof(MemoryData));
|
||||
checksum = GetCheckSum(&MemoryData.MotorData[0].MotorStopLoc1,36);
|
||||
if (MemoryData.start_flag == START_FLAG && MemoryData.stop_flag == STOP_FLAG && checksum == MemoryData.checksum)//
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MotorHallLoc[i] = MemoryData.MotorData[i].MotorNowLoc;
|
||||
MotorHardStop1[i] = MemoryData.MotorData[i].MotorStopLoc1;
|
||||
MotorHardStop2[i] = MemoryData.MotorData[i].MotorStopLoc2;
|
||||
MemoryLoc[0][i] = MemoryData.MemoryLoc[0][i];
|
||||
MemoryLoc[1][i] = MemoryData.MemoryLoc[1][i];
|
||||
MemoryLoc[2][i] = MemoryData.MemoryLoc[2][i];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MotorHallLoc[i] = 0x8000;
|
||||
MotorHardStop1[i] = 0;
|
||||
MotorHardStop2[i] = 0;
|
||||
MemoryLoc[0][i] = 0;
|
||||
MemoryLoc[1][i] = 0;
|
||||
MemoryLoc[2][i] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MotorValueInit(void)
|
||||
{
|
||||
uint8_t i;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MotorHallLoc[i] = 0x8000;
|
||||
MotorErr[i] = 0;
|
||||
}
|
||||
//ReadMotorMemory();
|
||||
}
|
||||
|
||||
void setMotorState(uint8_t motorid,uint8_t act)
|
||||
{
|
||||
//motorid-=1;
|
||||
if (act <= ACT_XH && motorid < 6)
|
||||
{
|
||||
MotorState[motorid] = act;
|
||||
}
|
||||
}
|
||||
uint16_t MotorTarget[6] = {0};
|
||||
void setMotorTarget(uint8_t motorid,uint16_t target)
|
||||
{
|
||||
|
||||
MotorTarget[motorid] = target;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#define AUTOCAL_STOP 0
|
||||
#define AUTOCAL_START 1
|
||||
#define AUTOCAL_ACT1 2
|
||||
#define AUTOCAL_ACT2 3
|
||||
#define AUTOCAL_END 4
|
||||
|
||||
void StartAutoCal(void)
|
||||
{
|
||||
AutoCalState = AUTOCAL_START;
|
||||
|
||||
}
|
||||
void StopAutoCal(void)
|
||||
{
|
||||
if (AutoCalState != AUTOCAL_STOP)
|
||||
{
|
||||
AutoCalState = AUTOCAL_STOP;
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AutoCalCtrl(void)
|
||||
{
|
||||
static uint16_t autocalcounter[3];
|
||||
static uint8_t MotorArr1state,MotorArr2state,MotorArr3state;
|
||||
static uint8_t wait1,wait2,wait3;
|
||||
uint8_t i;
|
||||
uint32_t temp;
|
||||
switch (AutoCalState)
|
||||
{
|
||||
case AUTOCAL_STOP:
|
||||
MotorArr1state = AUTOCAL_STOP;
|
||||
MotorArr2state = AUTOCAL_STOP;
|
||||
MotorArr3state = AUTOCAL_STOP;
|
||||
return;
|
||||
case AUTOCAL_START:
|
||||
MotorArr1state = 1;
|
||||
MotorArr2state = 1;
|
||||
MotorArr3state = 1;
|
||||
setMotorState(MOTOR1,ACT_XQ);
|
||||
setMotorState(MOTOR3,ACT_XQ);
|
||||
setMotorState(MOTOR5,ACT_XQ);
|
||||
autocalcounter[0] = 0;
|
||||
autocalcounter[1] = 0;
|
||||
autocalcounter[2] = 0;
|
||||
AutoCalState++;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MotorHardStop1[i] = 0;
|
||||
MotorHardStop2[i] = 0;
|
||||
MotorHallLoc[i] = 0x8000;
|
||||
}
|
||||
break;
|
||||
case AUTOCAL_ACT1:
|
||||
if (MotorArr1state == 0 && MotorArr2state == 0 && MotorArr3state == 0)
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
temp = MotorHardStop1[i];
|
||||
temp += MotorHardStop2[i];
|
||||
setMotorTarget(i,temp/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case AUTOCAL_ACT2:
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//1
|
||||
switch (MotorArr1state)
|
||||
{
|
||||
case 1://motor1 xq
|
||||
autocalcounter[0]++;
|
||||
if (MotorHardStop1[MOTOR1] != 0)
|
||||
{
|
||||
MotorArr1state++;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[0] > 3000 || MotorErr[MOTOR1] != 0)
|
||||
{
|
||||
MotorArr1state = 4;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 2://wait
|
||||
wait1++;
|
||||
if (wait1 > 50)
|
||||
{
|
||||
MotorArr1state++;
|
||||
setMotorState(MOTOR1,ACT_XH);
|
||||
autocalcounter[0] = 0;
|
||||
}
|
||||
break;
|
||||
case 3://motor1 xh
|
||||
autocalcounter[0]++;
|
||||
if (MotorHardStop2[MOTOR1] != 0)
|
||||
{
|
||||
MotorArr1state++;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[0] > 3000 || MotorErr[MOTOR1] != 0)
|
||||
{
|
||||
MotorArr1state = 4;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 4://wait
|
||||
wait1++;
|
||||
if (wait1 > 50)
|
||||
{
|
||||
MotorArr1state++;
|
||||
setMotorState(MOTOR2,ACT_XQ);
|
||||
autocalcounter[0] = 0;
|
||||
}
|
||||
break;
|
||||
case 5://motor2 xq
|
||||
autocalcounter[0]++;
|
||||
if (MotorHardStop1[MOTOR2] != 0)
|
||||
{
|
||||
MotorArr1state++;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[0] > 3000 || MotorErr[MOTOR2] != 0)
|
||||
{
|
||||
MotorArr1state = 0;
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 6://wait
|
||||
wait1++;
|
||||
if (wait1 > 50)
|
||||
{
|
||||
MotorArr1state++;
|
||||
setMotorState(MOTOR2,ACT_XH);
|
||||
autocalcounter[0] = 0;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
autocalcounter[0]++;
|
||||
if (MotorHardStop2[MOTOR2] != 0)
|
||||
{
|
||||
MotorArr1state=0;
|
||||
wait1 = 0;
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[0] > 3000 || MotorErr[MOTOR2] != 0)
|
||||
{
|
||||
MotorArr1state = 0;
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//2
|
||||
switch (MotorArr2state)
|
||||
{
|
||||
case 1://motor3 xq
|
||||
autocalcounter[1]++;
|
||||
if (MotorHardStop1[MOTOR3] != 0)
|
||||
{
|
||||
MotorArr2state++;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[1] > 3000 || MotorErr[MOTOR3] != 0)
|
||||
{
|
||||
MotorArr2state = 4;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 2://wait
|
||||
wait2++;
|
||||
if (wait2 > 50)
|
||||
{
|
||||
MotorArr2state++;
|
||||
setMotorState(MOTOR3,ACT_XH);
|
||||
autocalcounter[1] = 0;
|
||||
}
|
||||
break;
|
||||
case 3://motor3 xh
|
||||
autocalcounter[1]++;
|
||||
if (MotorHardStop2[MOTOR3] != 0)
|
||||
{
|
||||
MotorArr2state++;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[1] > 3000 || MotorErr[MOTOR3] != 0)
|
||||
{
|
||||
MotorArr2state = 4;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 4://wait
|
||||
wait2++;
|
||||
if (wait2 > 50)
|
||||
{
|
||||
MotorArr2state++;
|
||||
setMotorState(MOTOR4,ACT_XQ);
|
||||
autocalcounter[1] = 0;
|
||||
}
|
||||
break;
|
||||
case 5://motor4 xq
|
||||
autocalcounter[1]++;
|
||||
if (MotorHardStop1[MOTOR4] != 0)
|
||||
{
|
||||
MotorArr2state++;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[1] > 3000 || MotorErr[MOTOR4] != 0)
|
||||
{
|
||||
MotorArr2state = 0;
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 6://wait
|
||||
wait2++;
|
||||
if (wait2 > 50)
|
||||
{
|
||||
MotorArr2state++;
|
||||
setMotorState(MOTOR4,ACT_XH);
|
||||
autocalcounter[1] = 0;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
autocalcounter[1]++;
|
||||
if (MotorHardStop2[MOTOR4] != 0)
|
||||
{
|
||||
MotorArr2state=0;
|
||||
wait2 = 0;
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[1] > 3000 || MotorErr[MOTOR4] != 0)
|
||||
{
|
||||
MotorArr2state = 0;
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (MotorArr3state)
|
||||
{
|
||||
case 1://motor5 xq
|
||||
autocalcounter[2]++;
|
||||
if (MotorHardStop1[MOTOR5] != 0)
|
||||
{
|
||||
MotorArr3state++;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[2] > 3000 || MotorErr[MOTOR5] != 0)
|
||||
{
|
||||
MotorArr3state = 4;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 2://wait
|
||||
wait3++;
|
||||
if (wait3 > 50)
|
||||
{
|
||||
MotorArr3state++;
|
||||
setMotorState(MOTOR5,ACT_XH);
|
||||
autocalcounter[2] = 0;
|
||||
}
|
||||
break;
|
||||
case 3://motor5 xh
|
||||
autocalcounter[2]++;
|
||||
if (MotorHardStop2[MOTOR5] != 0)
|
||||
{
|
||||
MotorArr3state++;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[2] > 3000 || MotorErr[MOTOR5] != 0)
|
||||
{
|
||||
MotorArr3state = 4;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 4://wait
|
||||
wait3++;
|
||||
if (wait3 > 50)
|
||||
{
|
||||
MotorArr3state++;
|
||||
setMotorState(MOTOR6,ACT_XQ);
|
||||
autocalcounter[2] = 0;
|
||||
}
|
||||
break;
|
||||
case 5://motor6 xq
|
||||
autocalcounter[2]++;
|
||||
if (MotorHardStop1[MOTOR6] != 0)
|
||||
{
|
||||
MotorArr3state++;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[2] > 3000 || MotorErr[MOTOR6] != 0)
|
||||
{
|
||||
MotorArr3state = 0;
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
case 6://wait
|
||||
wait3++;
|
||||
if (wait3 > 50)
|
||||
{
|
||||
MotorArr3state++;
|
||||
setMotorState(MOTOR6,ACT_XH);
|
||||
autocalcounter[2] = 0;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
autocalcounter[2]++;
|
||||
if (MotorHardStop2[MOTOR6] != 0)
|
||||
{
|
||||
MotorArr3state=0;
|
||||
wait3 = 0;
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
}
|
||||
if (autocalcounter[2] > 3000 || MotorErr[MOTOR6] != 0)
|
||||
{
|
||||
MotorArr3state = 0;
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint8_t flagMotorMemoryKeyStart,flagMotorMemoryKeyLongPress,flagKEYM1press;
|
||||
uint16_t countMotorMemoryKeyStart;
|
||||
uint16_t countMotorMemoryKeyLongPress;
|
||||
void MotorMemoryKeyMMPress(void)
|
||||
{
|
||||
|
||||
flagMotorMemoryKeyLongPress = 1;
|
||||
|
||||
countMotorMemoryKeyLongPress = 0;
|
||||
}
|
||||
|
||||
void MotorMemoryKeyMMRelease(void)
|
||||
{
|
||||
if (countMotorMemoryKeyLongPress >= 300)
|
||||
{
|
||||
flagMotorMemoryKeyLongPress = 2;
|
||||
countMotorMemoryKeyLongPress = 500;
|
||||
flagKEYM1press = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
flagMotorMemoryKeyStart = 1;
|
||||
countMotorMemoryKeyStart = 0;
|
||||
flagMotorMemoryKeyLongPress = 0;
|
||||
countMotorMemoryKeyLongPress = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MotorMemoryKeyM1Press(void)
|
||||
{
|
||||
|
||||
}
|
||||
void MotorMemoryKeyM1Release(void)
|
||||
{
|
||||
uint8_t i;
|
||||
if (flagMotorMemoryKeyLongPress == 2)
|
||||
{
|
||||
flagKEYM1press++;
|
||||
if (flagKEYM1press >= 3)
|
||||
{
|
||||
StartAutoCal();
|
||||
}
|
||||
|
||||
}
|
||||
if (flagMotorMemoryKeyStart == 1)
|
||||
{
|
||||
flagMotorMemoryKeyStart = 0;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
|
||||
if (MotorHardStop1[i]!=0 && MotorHardStop2[i]!=0)
|
||||
{
|
||||
MemoryLoc[0][i] = MotorHallLoc[i];
|
||||
}
|
||||
EEL_SAVE_Counter = 1000;
|
||||
EEL_SAVE_REQUIRE_FLAG = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
setMotorTarget(i,MemoryLoc[0][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MotorMemoryKeyM2Press(void)
|
||||
{
|
||||
|
||||
}
|
||||
void MotorMemoryKeyM2Release(void)
|
||||
{
|
||||
uint8_t i;
|
||||
if (flagMotorMemoryKeyStart == 1)
|
||||
{
|
||||
flagMotorMemoryKeyStart = 0;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (MotorHardStop1[i]!=0 && MotorHardStop2[i]!=0)
|
||||
{
|
||||
MemoryLoc[1][i] = MotorHallLoc[i];
|
||||
}
|
||||
}
|
||||
EEL_SAVE_Counter = 1000;
|
||||
EEL_SAVE_REQUIRE_FLAG = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
setMotorTarget(i,MemoryLoc[1][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MotorMemoryKeyM3Press(void)
|
||||
{
|
||||
|
||||
}
|
||||
void MotorMemoryKeyM3Release(void)
|
||||
{
|
||||
uint8_t i;
|
||||
if (flagMotorMemoryKeyStart == 1)
|
||||
{
|
||||
flagMotorMemoryKeyStart = 0;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (MotorHardStop1[i]!=0 && MotorHardStop2[i]!=0)
|
||||
{
|
||||
MemoryLoc[2][i] = MotorHallLoc[i];
|
||||
}
|
||||
}
|
||||
EEL_SAVE_Counter = 1000;
|
||||
EEL_SAVE_REQUIRE_FLAG = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
setMotorTarget(i,MemoryLoc[2][i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MotorCtrl(void)//10ms
|
||||
{
|
||||
uint8_t i;
|
||||
//WriteMotorMemory(); //TODO
|
||||
AutoCalCtrl();
|
||||
if (flagMotorMemoryKeyStart == 1)
|
||||
{
|
||||
countMotorMemoryKeyStart++;
|
||||
if (countMotorMemoryKeyStart > 500)//5S
|
||||
{
|
||||
flagMotorMemoryKeyStart = 0;
|
||||
countMotorMemoryKeyStart = 0;
|
||||
}
|
||||
}
|
||||
if (flagMotorMemoryKeyLongPress == 1 && countMotorMemoryKeyLongPress < 1000)
|
||||
{
|
||||
countMotorMemoryKeyLongPress++;
|
||||
}
|
||||
if (flagMotorMemoryKeyLongPress == 2 && countMotorMemoryKeyLongPress > 0)
|
||||
{
|
||||
countMotorMemoryKeyLongPress--;
|
||||
if (countMotorMemoryKeyLongPress == 0)
|
||||
{
|
||||
flagMotorMemoryKeyLongPress = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (OC1flag == 1)
|
||||
{
|
||||
OC1flag = 0;
|
||||
if (MotorState[0] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[0] = MotorHallLoc[0];
|
||||
}
|
||||
else if (MotorState[0] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[0] = MotorHallLoc[0];
|
||||
}
|
||||
else if (MotorState[1] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[1] = MotorHallLoc[1];
|
||||
}
|
||||
else if (MotorState[1] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[1] = MotorHallLoc[1];
|
||||
}
|
||||
MotorState[MOTOR1] = ACT_NOACT;
|
||||
MotorState[MOTOR2] = ACT_NOACT;
|
||||
}
|
||||
if (OC2flag == 1)
|
||||
{
|
||||
OC2flag = 0;
|
||||
if (MotorState[2] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[2] = MotorHallLoc[2];
|
||||
}
|
||||
else if (MotorState[2] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[2] = MotorHallLoc[2];
|
||||
}
|
||||
else if (MotorState[3] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[3] = MotorHallLoc[3];
|
||||
}
|
||||
else if (MotorState[3] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[3] = MotorHallLoc[3];
|
||||
}
|
||||
MotorState[MOTOR3] = ACT_NOACT;
|
||||
MotorState[MOTOR4] = ACT_NOACT;
|
||||
}
|
||||
if (OC3flag == 1)
|
||||
{
|
||||
OC3flag = 0;
|
||||
if (MotorState[4] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[4] = MotorHallLoc[4];
|
||||
}
|
||||
else if (MotorState[4] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[4] = MotorHallLoc[4];
|
||||
}
|
||||
else if (MotorState[5] == ACT_XQ)
|
||||
{
|
||||
MotorHardStop1[5] = MotorHallLoc[5];
|
||||
}
|
||||
else if (MotorState[5] == ACT_XH)
|
||||
{
|
||||
MotorHardStop2[5] = MotorHallLoc[5];
|
||||
}
|
||||
MotorState[MOTOR5] = ACT_NOACT;
|
||||
MotorState[MOTOR6] = ACT_NOACT;
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
MotorStateReal[i] = MotorState[i];
|
||||
if (MotorState[i] == ACT_NOACT && MotorHardStop1[i] != 0 && MotorHardStop2[i] != 0 )
|
||||
{
|
||||
if (MotorTarget[i]!=0 && MotorHardStop1[i] > MotorTarget[i] && MotorTarget[i] > MotorHardStop2[i])
|
||||
{
|
||||
if (MotorTarget[i] > MotorHallLoc[i]+10)
|
||||
{
|
||||
MotorStateReal[i] = ACT_XQ;
|
||||
}
|
||||
else if (MotorTarget[i] < MotorHallLoc[i]-10)
|
||||
{
|
||||
MotorStateReal[i] = ACT_XH;
|
||||
}
|
||||
else
|
||||
{
|
||||
MotorTarget[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (MotorHardStop1[i] != 0 && MotorHardStop2[i] != 0)
|
||||
{
|
||||
if (MotorHallLoc[i] > (MotorHardStop1[i]-20) && MotorStateReal[i] == ACT_XQ)
|
||||
{
|
||||
MotorStateReal[i] = ACT_NOACT;
|
||||
}
|
||||
if (MotorHallLoc[i] < (MotorHardStop2[i] + 20) && MotorStateReal[i] == ACT_XH)
|
||||
{
|
||||
MotorStateReal[i] = ACT_NOACT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
MotorTarget[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
MOTOR1Ctrl(MotorStateReal[MOTOR1]);
|
||||
MOTOR2Ctrl(MotorStateReal[MOTOR2]);
|
||||
MOTOR3Ctrl(MotorStateReal[MOTOR3]);
|
||||
MOTOR4Ctrl(MotorStateReal[MOTOR4]);
|
||||
MOTOR5Ctrl(MotorStateReal[MOTOR5]);
|
||||
MOTOR6Ctrl(MotorStateReal[MOTOR6]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define OC_10A 100
|
||||
#define OC_500mS 500
|
||||
#define OC_50mS 50
|
||||
|
||||
|
||||
|
||||
void CurrentDetecte(void)
|
||||
{
|
||||
|
||||
static uint16_t OC_Count1=0,OC_Count2=0,OC_Count3 = 0;
|
||||
|
||||
current1 = getAdval(ADCH_RLY3);
|
||||
current2 = getAdval(ADCH_RLY2);
|
||||
current3 = getAdval(ADCH_RLY1);
|
||||
|
||||
if (current1 > 100U && OC1flag == 0)
|
||||
{
|
||||
OC_Count1++;
|
||||
if (OC_Count1 >= 100)
|
||||
{
|
||||
OC_Count1 = 0;
|
||||
OC1flag = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OC_Count1 = 0;
|
||||
}
|
||||
|
||||
if (current2 > 100U && OC2flag == 0)
|
||||
{
|
||||
OC_Count2++;
|
||||
if (OC_Count2 >= 100)
|
||||
{
|
||||
OC_Count2 = 0;
|
||||
OC2flag = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
OC_Count2 = 0;
|
||||
}
|
||||
|
||||
if (current3 > 100U && OC3flag == 0)
|
||||
{
|
||||
OC_Count3++;
|
||||
if (OC_Count3 >= 100)
|
||||
{
|
||||
OC_Count3 = 0;
|
||||
OC3flag = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
OC_Count3 = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OverCurrentPro(uint8_t ovmotor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#define HALLDELAYMAX 2
|
||||
|
||||
uint16_t HallErrorCount[6];
|
||||
void HallDetecte(void)
|
||||
{
|
||||
static uint8_t HallLastState[6],HallDelay[6];
|
||||
uint8_t i,hallstate;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
hallstate = GetIOState(i+1);
|
||||
if (hallstate != HallLastState[i])
|
||||
{
|
||||
HallDelay[i]++;
|
||||
if (HallDelay[i] > HALLDELAYMAX)
|
||||
{
|
||||
if (MotorStateReal[i] == ACT_XQ)
|
||||
{
|
||||
MotorHallLoc[i]++;
|
||||
}
|
||||
else if (MotorStateReal[i] == ACT_XH)
|
||||
{
|
||||
MotorHallLoc[i]--;
|
||||
}
|
||||
HallLastState[i] = hallstate;
|
||||
}
|
||||
HallErrorCount[i] = 0;
|
||||
MotorErr[i] = 0;
|
||||
EEL_SAVE_Counter = 1000;
|
||||
EEL_SAVE_REQUIRE_FLAG = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
HallDelay[i] = 0;
|
||||
if (MotorStateReal[i] != ACT_NOACT)
|
||||
{
|
||||
HallErrorCount[i]++;
|
||||
if (HallErrorCount[i] > 500)
|
||||
{
|
||||
HallErrorCount[i] = 500;
|
||||
MotorErr[i] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (EEL_SAVE_Counter > 0)
|
||||
{
|
||||
EEL_SAVE_Counter--;
|
||||
}
|
||||
|
||||
}
|
37
app/user/MotorCtrl.h
Normal file
37
app/user/MotorCtrl.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef __MOTORCTRL_H__
|
||||
#define __MOTORCTRL_H__
|
||||
|
||||
#include "r_cg_macrodriver.h"
|
||||
|
||||
#define MOTOR1 0
|
||||
#define MOTOR2 1
|
||||
#define MOTOR3 2
|
||||
#define MOTOR4 3
|
||||
#define MOTOR5 4
|
||||
#define MOTOR6 5
|
||||
|
||||
void OverCurrentPro(uint8_t ovmotor);
|
||||
void CurrentDetecte(void);
|
||||
void MotorCtrl(void);
|
||||
void HallDetecte(void);
|
||||
void MotorValueInit(void);
|
||||
|
||||
|
||||
void StartAutoCal(void);
|
||||
void StopAutoCal(void);
|
||||
|
||||
|
||||
|
||||
|
||||
void setMotorState(uint8_t motorid,uint8_t act);
|
||||
|
||||
void MotorMemoryKeyM1Press(void);
|
||||
void MotorMemoryKeyM1Release(void);
|
||||
void MotorMemoryKeyM2Press(void);
|
||||
void MotorMemoryKeyM2Release(void);
|
||||
void MotorMemoryKeyM3Press(void);
|
||||
void MotorMemoryKeyM3Release(void);
|
||||
void MotorMemoryKeyMMPress(void);
|
||||
void MotorMemoryKeyMMRelease(void);
|
||||
|
||||
#endif
|
70
app/user/PINdef.h
Normal file
70
app/user/PINdef.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef __PINDEF_H__
|
||||
#define __PINDEF_H__
|
||||
|
||||
#include "iodefine.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define KEYID_KBXQ 0
|
||||
#define KEYID_KBXH 1
|
||||
#define KEYID_HGXQ 2
|
||||
#define KEYID_HGXH 3
|
||||
#define KEYID_ZDUP 4
|
||||
#define KEYID_ZDDOWN 5
|
||||
#define KEYID_TTUP 6
|
||||
#define KEYID_TTDOWN 7
|
||||
#define KEYID_TP 8
|
||||
#define KEYID_FW 9
|
||||
#define KEYID_SET 10
|
||||
#define KEYID_M1 11
|
||||
#define KEYID_M2 12
|
||||
#define KEYID_M3 13
|
||||
|
||||
#define SIGID_HALL1 14
|
||||
#define SIGID_HALL2 15
|
||||
#define SIGID_HALL3 16
|
||||
#define SIGID_HALL4 17
|
||||
|
||||
|
||||
|
||||
#define IN_HALL1 P6_bit.no0
|
||||
#define IN_HALL2 P6_bit.no1
|
||||
#define IN_HALL3 P6_bit.no2
|
||||
#define IN_HALL4 P6_bit.no3
|
||||
|
||||
#define IN_KEY_KBXH P8_bit.no2
|
||||
#define IN_KEY_HGXH P8_bit.no3
|
||||
#define IN_KEY_ZDDOWN P8_bit.no4
|
||||
#define IN_KEY_TTDOWN P8_bit.no5
|
||||
#define IN_KEY_TTUP P8_bit.no6
|
||||
#define IN_KEY_ZDUP P8_bit.no7
|
||||
#define IN_KEY_HGXQ P9_bit.no1
|
||||
#define IN_KEY_KBXQ P9_bit.no2
|
||||
#define IN_KEY_TP P12_bit.no5
|
||||
#define IN_KEY_FW P12_bit.no0
|
||||
|
||||
|
||||
#define OUT_RLY1P P3_bit.no0//KB
|
||||
#define OUT_RLY1N P14_bit.no0
|
||||
#define OUT_RLY2P P7_bit.no0//HG
|
||||
#define OUT_RLY2N P3_bit.no2
|
||||
#define OUT_RLY3P P13_bit.no0//ZD
|
||||
#define OUT_RLY3N P7_bit.no1
|
||||
#define OUT_RLY4P P7_bit.no2//TT
|
||||
#define OUT_RLY4N P7_bit.no3
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ADCH_JYKEY 3
|
||||
#define ADCH_RLY2 0
|
||||
#define ADCH_RLY1 2
|
||||
#define ADCH_BAT 1
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
424
app/user/appTask.c
Normal file
424
app/user/appTask.c
Normal file
@ -0,0 +1,424 @@
|
||||
/**
|
||||
* @file appTask.c
|
||||
* @author sunbeam
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-11-14
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#include "appTask.h"
|
||||
#include "iodefine.h"
|
||||
#include "r_cg_adc.h"
|
||||
#include "PINdef.h"
|
||||
#include "hwCtrl.h"
|
||||
#include "MotorCtrl.h"
|
||||
#include "RLIN_driver.h"
|
||||
#include "r_cg_wdt.h"
|
||||
#include "r_cg_timer.h"
|
||||
|
||||
static uint8_t EEL_BUF[50];
|
||||
|
||||
unsigned char IGN_Voltage_error_flag, IGN_Voltage_error_count;
|
||||
|
||||
unsigned char Timer_1ms_flag;
|
||||
unsigned char Timer_5ms_flag;
|
||||
unsigned char Timer_10ms_flag;
|
||||
unsigned char Timer_20ms_flag;
|
||||
unsigned char Timer_50ms_flag;
|
||||
unsigned char Timer_1000ms_flag;
|
||||
|
||||
/***************************************************/
|
||||
static unsigned int EEL_SAVE_CNT_DOWN_TIMER;
|
||||
static uint8_t EEL_SAVE_ENABLE;
|
||||
|
||||
MotorStateEE_Type MotorStateEE;
|
||||
MotorStateEE_Type *pEE;
|
||||
|
||||
|
||||
void MotorCtrl(void);
|
||||
void HallDetecte(void);
|
||||
void LIN_Task(void);
|
||||
void TfJr_CtrlTask(void);
|
||||
extern uint8_t OC1flag,OC2flag,OC3flag;
|
||||
uint8_t TfState,JrState;
|
||||
unsigned char keybyte1,keybyte2,keybyte3;
|
||||
|
||||
void Apply_task(void)
|
||||
{
|
||||
//static uint8_t temp;
|
||||
|
||||
if (Timer_1ms_flag == 1)
|
||||
{
|
||||
Timer_1ms_flag = 0;
|
||||
KeyScan();
|
||||
HallDetecte();
|
||||
CurrentDetecte();
|
||||
if (EEL_SAVE_CNT_DOWN_TIMER > 0)
|
||||
{
|
||||
EEL_SAVE_CNT_DOWN_TIMER--;
|
||||
}
|
||||
}
|
||||
if (Timer_5ms_flag == 1)
|
||||
{
|
||||
Timer_5ms_flag = 0;
|
||||
|
||||
KeyPro();
|
||||
}
|
||||
|
||||
if (Timer_10ms_flag == 1)
|
||||
{
|
||||
Timer_10ms_flag = 0;
|
||||
MotorCtrl();
|
||||
LIN_Task();
|
||||
}
|
||||
if (Timer_20ms_flag == 1)
|
||||
{
|
||||
Timer_20ms_flag = 0;
|
||||
//R_WDT_Restart();
|
||||
}
|
||||
if (Timer_50ms_flag == 1)
|
||||
{
|
||||
Timer_50ms_flag = 0;
|
||||
TfJr_CtrlTask();
|
||||
}
|
||||
if (Timer_1000ms_flag == 1)
|
||||
{
|
||||
Timer_1000ms_flag = 0;
|
||||
//temp = !temp;
|
||||
//MOTOR1Ctrl(temp);
|
||||
}
|
||||
|
||||
}
|
||||
extern uint8_t Master_TxData1[];
|
||||
void LIN_Task(void)
|
||||
{
|
||||
static uint8_t lin_sch_count=0;
|
||||
switch (lin_sch_count)
|
||||
{
|
||||
case 0:
|
||||
Master_TxData1[0] = (JrState<<4)|(TfState<<6);
|
||||
Master_TxData1[1] = keybyte3;
|
||||
RLIN_Master_HeaderTransmit(0x80);
|
||||
break;
|
||||
case 1:
|
||||
RLIN_Master_HeaderTransmit(0x99);
|
||||
break;
|
||||
case 2:
|
||||
RLIN_Master_HeaderTransmit(0x61);
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
lin_sch_count = 0;
|
||||
break;
|
||||
}
|
||||
lin_sch_count++;
|
||||
if (lin_sch_count > 2)
|
||||
{
|
||||
lin_sch_count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LIN_Rx_Handle(uint8_t pid,uint8_t *data)
|
||||
{
|
||||
uint8_t id = pid & 0x3f;
|
||||
switch (id)
|
||||
{
|
||||
case 0x21:
|
||||
keybyte3 = data[4];
|
||||
break;
|
||||
case 0x19:
|
||||
//MOTOR1Ctrl(1);
|
||||
keybyte1 = data[0];
|
||||
keybyte2 = data[1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KeyPressLogic(uint8_t keyid)
|
||||
{
|
||||
switch (keyid)
|
||||
{
|
||||
case KEYID_MOTOR1_XQ:
|
||||
setMotorState(MOTOR1,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR1_XH:
|
||||
setMotorState(MOTOR1,ACT_XH);
|
||||
break;
|
||||
case KEYID_MOTOR2_XQ:
|
||||
setMotorState(MOTOR2,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR2_XH:
|
||||
setMotorState(MOTOR2,ACT_XH);
|
||||
break;
|
||||
case KEYID_MOTOR3_XQ:
|
||||
setMotorState(MOTOR3,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR3_XH:
|
||||
setMotorState(MOTOR3,ACT_XH);
|
||||
break;
|
||||
case KEYID_MOTOR4_XQ:
|
||||
setMotorState(MOTOR4,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR4_XH:
|
||||
setMotorState(MOTOR4,ACT_XH);
|
||||
break;
|
||||
case KEYID_MOTOR5_XQ:
|
||||
setMotorState(MOTOR5,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR5_XH:
|
||||
setMotorState(MOTOR5,ACT_XH);
|
||||
break;
|
||||
case KEYID_MOTOR6_XQ:
|
||||
setMotorState(MOTOR6,ACT_XQ);
|
||||
break;
|
||||
case KEYID_MOTOR6_XH:
|
||||
setMotorState(MOTOR6,ACT_XH);
|
||||
break;
|
||||
case KEYID_MM:
|
||||
MotorMemoryKeyMMPress();
|
||||
break;
|
||||
case KEYID_M1:
|
||||
break;
|
||||
case KEYID_M2:
|
||||
break;
|
||||
case KEYID_M3:
|
||||
break;
|
||||
case KEYID_K4:
|
||||
JrState++;
|
||||
TfState = 0;
|
||||
if (JrState > 3)
|
||||
{
|
||||
JrState = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case KEYID_K3:
|
||||
TfState++;
|
||||
JrState = 0;
|
||||
if (TfState > 3)
|
||||
{
|
||||
TfState = 0;
|
||||
}
|
||||
break;
|
||||
case KEYID_K2:
|
||||
break;
|
||||
case KEYID_K1:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void KeyReleaseLogic(uint8_t keyid)
|
||||
{
|
||||
switch (keyid)
|
||||
{
|
||||
case KEYID_MOTOR1_XQ:
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR1_XH:
|
||||
setMotorState(MOTOR1,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR2_XQ:
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR2_XH:
|
||||
setMotorState(MOTOR2,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR3_XQ:
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR3_XH:
|
||||
setMotorState(MOTOR3,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR4_XQ:
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR4_XH:
|
||||
setMotorState(MOTOR4,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR5_XQ:
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR5_XH:
|
||||
setMotorState(MOTOR5,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR6_XQ:
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MOTOR6_XH:
|
||||
setMotorState(MOTOR6,ACT_NOACT);
|
||||
break;
|
||||
case KEYID_MM:
|
||||
MotorMemoryKeyMMRelease();
|
||||
break;
|
||||
case KEYID_M1:
|
||||
MotorMemoryKeyM1Release();
|
||||
break;
|
||||
case KEYID_M2:
|
||||
MotorMemoryKeyM2Release();
|
||||
break;
|
||||
case KEYID_M3:
|
||||
MotorMemoryKeyM3Release();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KeyPro(void)
|
||||
{
|
||||
uint8_t keyid;
|
||||
for (keyid = 0; keyid < KEY_NUM; keyid++)
|
||||
{
|
||||
if (getKeyPressFlag(keyid))
|
||||
{
|
||||
KeyPressLogic(keyid+1);
|
||||
StopAutoCal();
|
||||
}
|
||||
if (getKeyReleaseFlag(keyid))
|
||||
{
|
||||
KeyReleaseLogic(keyid+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void EEL_READ(void)
|
||||
{
|
||||
uint16_t checksum;
|
||||
uint8_t *src,*des,i;
|
||||
//ReadFlashData(EEL_BUF, 0x000F1000, sizeof(MotorStateEE));
|
||||
pEE = (MotorStateEE_Type *)EEL_BUF;
|
||||
checksum = pEE->kbsoft1 + pEE->kbsoft2 + pEE->kbnow + pEE->zysoft1 + pEE->zysoft2 + pEE->zynow;
|
||||
if (pEE ->start == 0x55AA && pEE->stop == 0xAA55 && checksum == pEE->checksum)
|
||||
{
|
||||
des = &MotorStateEE;
|
||||
src = EEL_BUF;
|
||||
for (i = 0; i < sizeof(MotorStateEE); i++)
|
||||
{
|
||||
des[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t SupplyVoltage;
|
||||
void IGN_Voltage_Detect(void)
|
||||
{
|
||||
uint32_t adval;
|
||||
adval = getAdval(ADCH_BAT);
|
||||
SupplyVoltage = (adval*57*5)>>10;
|
||||
if (adval <= 305 )
|
||||
{
|
||||
IGN_Voltage_error_count++;
|
||||
if (IGN_Voltage_error_count >= 250)
|
||||
{
|
||||
IGN_Voltage_error_count = 0;
|
||||
IGN_Voltage_error_flag = 1;
|
||||
}
|
||||
}
|
||||
else if (adval >= 592 )//16.5
|
||||
{
|
||||
IGN_Voltage_error_count++;
|
||||
if (IGN_Voltage_error_count >= 250)
|
||||
{
|
||||
IGN_Voltage_error_count = 0;
|
||||
IGN_Voltage_error_flag = 2;
|
||||
}
|
||||
}
|
||||
else if (adval >= 323 && adval <= 574)
|
||||
{
|
||||
IGN_Voltage_error_count = 0;
|
||||
IGN_Voltage_error_flag = 0;
|
||||
}
|
||||
|
||||
|
||||
if (IGN_Voltage_error_flag != 0)
|
||||
{
|
||||
// TAU0_Channel1_ChangeDuty(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void value_init(void)
|
||||
{
|
||||
R_TAU0_Channel0_Start();
|
||||
R_TAU0_Channel2_Start();
|
||||
|
||||
R_ADC_Start();
|
||||
R_ADC_Set_OperationOn();
|
||||
R_TMR_RJ0_Start();
|
||||
|
||||
|
||||
MotorValueInit();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Timer_Pro(void)
|
||||
{
|
||||
static unsigned int Timer_1ms_tick_count;
|
||||
Timer_1ms_tick_count++;
|
||||
Timer_1ms_flag=1;
|
||||
if(Timer_1ms_tick_count%5==0)
|
||||
{
|
||||
Timer_5ms_flag=1;
|
||||
}
|
||||
if(Timer_1ms_tick_count%10==0)
|
||||
{
|
||||
Timer_10ms_flag=1;
|
||||
}
|
||||
if(Timer_1ms_tick_count%20==0)
|
||||
{
|
||||
Timer_20ms_flag=1;
|
||||
}
|
||||
if(Timer_1ms_tick_count%50==0)
|
||||
{
|
||||
Timer_50ms_flag=1;
|
||||
}
|
||||
if(Timer_1ms_tick_count%1000==0)
|
||||
{
|
||||
Timer_1000ms_flag = 1;
|
||||
}
|
||||
if(Timer_1ms_tick_count>=5000)
|
||||
{
|
||||
Timer_1ms_tick_count=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const uint8_t TfDutyTable[4] = {0,100,80,50};//{0,100,80,50};
|
||||
const uint8_t JrDutyTable[4] = {0,100,80,50};//{0,100,80,50};
|
||||
void TfJr_CtrlTask(void)
|
||||
{
|
||||
if (JrState < 4)
|
||||
{
|
||||
SetJrDuty(JrDutyTable[JrState]);
|
||||
}
|
||||
if (TfState < 4)
|
||||
{
|
||||
SetTfDuty(TfDutyTable[TfState]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
43
app/user/appTask.h
Normal file
43
app/user/appTask.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef _DMK_VF12_03_H
|
||||
#define _DMK_VF12_03_H
|
||||
|
||||
|
||||
#include "r_cg_macrodriver.h"
|
||||
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
|
||||
|
||||
/***********************************************/
|
||||
typedef struct{
|
||||
unsigned int start;
|
||||
unsigned int zysoft1;
|
||||
unsigned int zysoft2;
|
||||
unsigned int zynow;
|
||||
unsigned int kbsoft1;
|
||||
unsigned int kbsoft2;
|
||||
unsigned int kbnow;
|
||||
unsigned int checksum;
|
||||
unsigned int stop;
|
||||
}MotorStateEE_Type;
|
||||
extern MotorStateEE_Type MotorStateEE;
|
||||
|
||||
|
||||
extern unsigned int EEL_SAVE_CNT_DOWN_TIMER;
|
||||
|
||||
|
||||
extern unsigned char Timer_1ms_flag;
|
||||
extern unsigned char Timer_5ms_flag;
|
||||
extern unsigned char Timer_10ms_flag;
|
||||
extern unsigned char Timer_20ms_flag;
|
||||
extern unsigned char Timer_50ms_flag;
|
||||
extern unsigned char Timer_1000ms_flag;
|
||||
|
||||
void KeyPro(void);
|
||||
void value_init(void);
|
||||
void Timer_Pro(void);
|
||||
void Apply_task(void);
|
||||
void EEL_READ(void);
|
||||
void IGN_Voltage_Detect(void);
|
||||
|
||||
#endif
|
28
app/user/buzzer.c
Normal file
28
app/user/buzzer.c
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
void buzzer_init(void)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void buzzer_start(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void buzzer_stop(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void buzzer_task(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
8
app/user/buzzer.h
Normal file
8
app/user/buzzer.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef __BUZZER_H__
|
||||
#define __BUZZER_H__
|
||||
|
||||
#include "r_cg_macrodriver.h"
|
||||
#include "r_cg_userdefine.h"
|
||||
|
||||
#endif
|
||||
|
277
app/user/hwCtrl.c
Normal file
277
app/user/hwCtrl.c
Normal file
@ -0,0 +1,277 @@
|
||||
|
||||
#include "hwCtrl.h"
|
||||
#include "r_cg_port.h"
|
||||
#include "iodefine.h"
|
||||
#include "PINdef.h"
|
||||
#include "r_cg_adc.h"
|
||||
static uint8_t keystate[KEY_NUM] = {0,0,0,0,0,0};
|
||||
static uint8_t keyPressFlag[KEY_NUM] = {0,0,0,0,0,0};
|
||||
static uint8_t keyReleaseFlag[KEY_NUM] = {0,0,0,0,0,0};
|
||||
static uint16_t keydelay[KEY_NUM] = {0,0,0,0,0,0};
|
||||
extern uint16_t g_adval[4];
|
||||
|
||||
#define KEY_DELAY_TIMES 20 //20Ms
|
||||
void ClearKeyState(void)
|
||||
{
|
||||
uint8_t i;
|
||||
for (i = 0; i < KEY_NUM; i++)
|
||||
{
|
||||
keystate[i] = 0;
|
||||
}
|
||||
}
|
||||
void setKeyPressFlag(uint8_t id)
|
||||
{
|
||||
if (id < KEY_NUM)
|
||||
{
|
||||
keyPressFlag[id] = KEY_PRESSED;
|
||||
}
|
||||
}
|
||||
void setKeyReleaseFlag(uint8_t id)
|
||||
{
|
||||
|
||||
if (id < KEY_NUM)
|
||||
{
|
||||
keyReleaseFlag[id] = KEY_PRESSED;
|
||||
}
|
||||
}
|
||||
uint8_t getKeyPressFlag(uint8_t id)
|
||||
{
|
||||
uint8_t retVal = KEY_NOPRESSED;
|
||||
if (id < KEY_NUM)
|
||||
{
|
||||
retVal = keyPressFlag[id];
|
||||
keyPressFlag[id] = KEY_NOPRESSED;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
uint8_t getKeyReleaseFlag(uint8_t id)
|
||||
{
|
||||
uint8_t retVal = KEY_NOPRESSED;
|
||||
if (id < KEY_NUM)
|
||||
{
|
||||
retVal = keyReleaseFlag[id];
|
||||
keyReleaseFlag[id] = KEY_NOPRESSED;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
extern unsigned char keybyte1,keybyte2,keybyte3;
|
||||
void KeyScan(void)
|
||||
{
|
||||
uint8_t i,key,key_nopress;
|
||||
key_nopress = 0;
|
||||
for (i = 0; i < KEY_NUM; i++)
|
||||
{
|
||||
if (i<8)
|
||||
{
|
||||
key = (keybyte1 & 0x01<<i)?1:0;
|
||||
}
|
||||
else if (i<16)
|
||||
{
|
||||
key = (keybyte2 & 0x01<<(i-8))?1:0;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = (keybyte3 & 0x01<<(i-16))?1:0;
|
||||
}
|
||||
//key = GetIOState(i+1);
|
||||
if (key == KEY_PRESSED && keystate[i] == KEY_NOPRESSED)
|
||||
{
|
||||
keydelay[i]++;
|
||||
if (keydelay[i] >= KEY_DELAY_TIMES)
|
||||
{
|
||||
keystate[i] = KEY_PRESSED;
|
||||
setKeyPressFlag(i);
|
||||
}
|
||||
}
|
||||
else if(key == KEY_NOPRESSED)
|
||||
{
|
||||
if (keydelay[i] > 0)
|
||||
{
|
||||
keydelay[i]--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keystate[i] == KEY_PRESSED)
|
||||
{
|
||||
setKeyReleaseFlag(i);
|
||||
}
|
||||
keystate[i] = KEY_NOPRESSED;
|
||||
key_nopress++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t GetIOState(uint8_t keyno)
|
||||
{
|
||||
switch (keyno)
|
||||
{
|
||||
case KEYID_KBXQ:
|
||||
return IN_KEY_KBXQ;
|
||||
case KEYID_KBXH:
|
||||
return IN_KEY_KBXH;
|
||||
|
||||
case SIGID_HALL1:
|
||||
return IN_HALL1;
|
||||
case SIGID_HALL2:
|
||||
return IN_HALL2;
|
||||
case SIGID_HALL3:
|
||||
return IN_HALL3;
|
||||
case SIGID_HALL4:
|
||||
return IN_HALL4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t GetKeyState(uint8_t keyno)
|
||||
{
|
||||
if (keyno > 0 && keyno <= 16)
|
||||
{
|
||||
return keystate[keyno-1];
|
||||
}
|
||||
return KEY_NOPRESSED;
|
||||
}
|
||||
|
||||
#define OUT_OFF 0
|
||||
#define OUT_ON 1
|
||||
|
||||
void MOTOR1Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY1P = OUT_OFF;
|
||||
OUT_RLY1N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY1P = OUT_ON;
|
||||
OUT_RLY1N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY1P = OUT_OFF;
|
||||
OUT_RLY1N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MOTOR2Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY2P = OUT_OFF;
|
||||
OUT_RLY2N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY2P = OUT_ON;
|
||||
OUT_RLY2N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY2P = OUT_OFF;
|
||||
OUT_RLY2N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void MOTOR3Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY3P = OUT_OFF;
|
||||
OUT_RLY3N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY3P = OUT_ON;
|
||||
OUT_RLY3N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY3P = OUT_OFF;
|
||||
OUT_RLY3N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void MOTOR4Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY4P = OUT_OFF;
|
||||
OUT_RLY4N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY4P = OUT_ON;
|
||||
OUT_RLY4N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY4P = OUT_OFF;
|
||||
OUT_RLY4N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void MOTOR5Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY5P = OUT_OFF;
|
||||
OUT_RLY5N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY5P = OUT_ON;
|
||||
OUT_RLY5N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY5P = OUT_OFF;
|
||||
OUT_RLY5N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void MOTOR6Ctrl(uint8_t act)
|
||||
{
|
||||
switch (act)
|
||||
{
|
||||
case ACT_NOACT:
|
||||
OUT_RLY6P = OUT_OFF;
|
||||
OUT_RLY6N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XH:
|
||||
OUT_RLY6P = OUT_ON;
|
||||
OUT_RLY6N = OUT_OFF;
|
||||
break;
|
||||
case ACT_XQ:
|
||||
OUT_RLY6P = OUT_OFF;
|
||||
OUT_RLY6N = OUT_ON;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t getAdval(uint8_t ch)
|
||||
{
|
||||
if (ch < 4)
|
||||
{
|
||||
return g_adval[ch];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
64
app/user/hwCtrl.h
Normal file
64
app/user/hwCtrl.h
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
#ifndef __HWCTRL_H__
|
||||
#define __HWCTRL_H__
|
||||
#include "r_cg_macrodriver.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define KEY_PRESSED 1
|
||||
#define KEY_NOPRESSED 0
|
||||
|
||||
#define KEY_NUM 20
|
||||
|
||||
#define ACT_NOACT 0
|
||||
#define ACT_XQ 1
|
||||
#define ACT_XH 2
|
||||
|
||||
#define KEYID_K1 17
|
||||
#define KEYID_K2 18
|
||||
#define KEYID_K3 19
|
||||
#define KEYID_K4 20
|
||||
|
||||
#define KEYID_MOTOR1_XQ 13
|
||||
#define KEYID_MOTOR1_XH 16
|
||||
#define KEYID_MOTOR2_XQ 14
|
||||
#define KEYID_MOTOR2_XH 15
|
||||
|
||||
#define KEYID_MOTOR3_XQ 9
|
||||
#define KEYID_MOTOR3_XH 12
|
||||
#define KEYID_MOTOR4_XQ 10
|
||||
#define KEYID_MOTOR4_XH 11
|
||||
|
||||
#define KEYID_MOTOR5_XQ 1
|
||||
#define KEYID_MOTOR5_XH 2
|
||||
#define KEYID_MOTOR6_XQ 3
|
||||
#define KEYID_MOTOR6_XH 4
|
||||
#define KEYID_MM 5
|
||||
#define KEYID_M1 8
|
||||
#define KEYID_M2 7
|
||||
#define KEYID_M3 6
|
||||
|
||||
void ad_handle(void);
|
||||
uint16_t getAdval(uint8_t ch);
|
||||
|
||||
void KeyScan(void);
|
||||
void ClearKeyState(void);
|
||||
uint8_t GetKeyState(uint8_t keyno);
|
||||
uint8_t getKeyReleaseFlag(uint8_t id);
|
||||
uint8_t getKeyPressFlag(uint8_t id);
|
||||
uint8_t GetIOState(uint8_t keyno);
|
||||
|
||||
|
||||
|
||||
void MOTOR1Ctrl(uint8_t act);
|
||||
void MOTOR2Ctrl(uint8_t act);
|
||||
void MOTOR3Ctrl(uint8_t act);
|
||||
void MOTOR4Ctrl(uint8_t act);
|
||||
void MOTOR5Ctrl(uint8_t act);
|
||||
void MOTOR6Ctrl(uint8_t act);
|
||||
|
||||
void SetTfDuty(uint8_t duty);
|
||||
void SetJrDuty(uint8_t duty);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user