rt-thread-official/bsp/ls1cdev/libraries/ls1c_spi.h

147 lines
4.6 KiB
C
Raw Normal View History

2017-10-23 17:10:48 +08:00
/*
* File : ls1c_spi.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-10-23 <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> first version
*/
// Ӳ<><D3B2>spi<70>ӿڵ<D3BF>ͷ<EFBFBD>ļ<EFBFBD>
#ifndef __OPENLOONGSON_SPI_H
#define __OPENLOONGSON_SPI_H
// SPIģ<49><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define LS1C_SPI_0 (0)
#define LS1C_SPI_1 (1)
2017-10-23 17:10:48 +08:00
// Ƭѡ
#define LS1C_SPI_CS_0 (0)
#define LS1C_SPI_CS_1 (1)
#define LS1C_SPI_CS_2 (2)
#define LS1C_SPI_CS_3 (3)
// ʱ<>Ӽ<EFBFBD><D3BC>Ժ<EFBFBD><D4BA><EFBFBD>λ
#define SPI_CPOL_1 (1)
#define SPI_CPOL_0 (0)
#define SPI_CPHA_1 (1)
#define SPI_CPHA_0 (0)
// <20>Ĵ<EFBFBD><C4B4><EFBFBD>ƫ<EFBFBD><C6AB>
#define LS1C_SPI_SPCR_OFFSET (0) // <20><><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
#define LS1C_SPI_SPSR_OFFSET (1) // ״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>
#define LS1C_SPI_TxFIFO_OFFSET (2) // <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>ͬ
#define LS1C_SPI_RxFIFO_OFFSET (2) // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB7A2><EFBFBD><EFBFBD><EFBFBD>ݼĴ<DDBC><C4B4><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>ͬ
#define LS1C_SPI_SPER_OFFSET (3) // <20>ⲿ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
#define LS1C_SPI_SFC_PARAM_OFFSET (4) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
#define LS1C_SPI_SFC_SOFTCS_OFFSET (5) // Ƭѡ<C6AC><D1A1><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
#define LS1C_SPI_SFC_TIMING_OFFSET (6) // ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
// <20>Ĵ<EFBFBD><C4B4><EFBFBD>SPCR<43>е<EFBFBD>λ<EFBFBD><CEBB>
#define LS1C_SPI_SPCR_SPIE_BIT (7)
#define LS1C_SPI_SPCR_SPIE_MASK (0x01 << LS1C_SPI_SPCR_SPIE_BIT)
#define LS1C_SPI_SPCR_SPE_BIT (6)
#define LS1C_SPI_SPCR_SPE_MASK (0x01 << LS1C_SPI_SPCR_SPE_BIT)
#define LS1C_SPI_SPCR_CPOL_BIT (3)
#define LS1C_SPI_SPCR_CPOL_MASK (0x01 << LS1C_SPI_SPCR_CPOL_BIT)
#define LS1C_SPI_SPCR_CPHA_BIT (2)
#define LS1C_SPI_SPCR_CPHA_MASK (0x01 << LS1C_SPI_SPCR_CPHA_BIT)
#define LS1C_SPI_SPCR_SPR_BIT (0)
#define LS1C_SPI_SPCR_SPR_MASK (0x03 << LS1C_SPI_SPCR_SPR_BIT)
// <20>Ĵ<EFBFBD><C4B4><EFBFBD>SPSR<53>е<EFBFBD>λ<EFBFBD><CEBB>
#define LS1C_SPI_SPSR_SPIF_BIT (7)
#define LS1C_SPI_SPSR_SPIF_MASK (0x01 << LS1C_SPI_SPSR_SPIF_BIT)
#define LS1C_SPI_SPSR_WCOL_BIT (6)
#define LS1C_SPI_SPSR_WCOL_MASK (0x01 << LS1C_SPI_SPSR_WCOL_BIT)
// <20>Ĵ<EFBFBD><C4B4><EFBFBD>SPER<45>е<EFBFBD>λ<EFBFBD><CEBB>
#define LS1C_SPI_SPER_SPRE_BIT (0)
#define LS1C_SPI_SPER_SPRE_MASK (0x3 << LS1C_SPI_SPER_SPRE_BIT)
// <20>Ĵ<EFBFBD><C4B4><EFBFBD>SFC_SOFTCS<43><53>λ<EFBFBD><CEBB>
#define LS1C_SPI_SFC_SOFTCS_CSN_BIT (4)
#define LS1C_SPI_SFC_SOFTCS_CSN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSN_BIT)
#define LS1C_SPI_SFC_SOFTCS_CSEN_BIT (0)
#define LS1C_SPI_SFC_SOFTCS_CSEN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSEN_BIT)
// <20><><EFBFBD>ͳ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
#define LS1C_SPI_TX_TIMEOUT (20000)
2017-10-23 17:10:48 +08:00
/*
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>SPIģ<EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><EFBFBD><EFBFBD>ַ
* @SPIx SPIģ<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>
*/
inline void *ls1c_spi_get_base(unsigned char SPIx);
2017-10-23 17:10:48 +08:00
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
* @spi_base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @max_hz <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD><EFBFBD><EFBFBD>λhz
2017-10-23 17:10:48 +08:00
*/
void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz);
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ģʽ(ʱ<EFBFBD>Ӽ<EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD><EFBFBD>λ)
* @spi_base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @cpol ʱ<EFBFBD>Ӽ<EFBFBD><EFBFBD><EFBFBD>
* @cpha ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
*/
void ls1c_spi_set_mode(void *spi_base, unsigned char cpol, unsigned char cpha);
2017-10-23 17:10:48 +08:00
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ƬѡΪָ<EFBFBD><EFBFBD>״̬
* @spi_base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @cs Ƭѡ
2017-10-23 17:10:48 +08:00
* @new_status Ƭѡ<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>ȡֵΪ0<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ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<EFBFBD>ģʽ<EFBFBD>ȿ<EFBFBD><EFBFBD>ܲ<EFBFBD>ͬ
* @spi_base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
2017-10-23 17:10:48 +08:00
* @tx_ch <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @ret <EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
unsigned char ls1c_spi_txrx_byte(void *spi_base, unsigned char tx_ch);
2017-10-23 17:10:48 +08:00
/*
* <EFBFBD><EFBFBD>ӡָ<EFBFBD><EFBFBD>SPIģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>мĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @spi_base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
2017-10-23 17:10:48 +08:00
*/
void ls1c_spi_print_all_regs_info(void *spi_base);
2017-10-23 17:10:48 +08:00
#endif