summaryrefslogtreecommitdiff
path: root/bsp/ls1cdev/libraries/ls1c_spi.h
blob: 8046127de7784e64028e49c99606a055b4ee8e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * 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     ����       first version
 */

// Ӳ��spi�ӿڵ�ͷ�ļ�

#ifndef __OPENLOONGSON_SPI_H
#define __OPENLOONGSON_SPI_H


// SPI���
#define LS1C_SPI_0                      (0)
#define LS1C_SPI_1                      (1)

// Ƭѡ
#define LS1C_SPI_CS_0                   (0)
#define LS1C_SPI_CS_1                   (1)
#define LS1C_SPI_CS_2                   (2)
#define LS1C_SPI_CS_3                   (3)

// ʱ�Ӽ��Ժ���λ
#define SPI_CPOL_1                      (1)
#define SPI_CPOL_0                      (0)
#define SPI_CPHA_1                      (1)
#define SPI_CPHA_0                      (0)


// �Ĵ���ƫ��
#define LS1C_SPI_SPCR_OFFSET                (0)     // ���ƼĴ���
#define LS1C_SPI_SPSR_OFFSET                (1)     // ״̬�Ĵ���
#define LS1C_SPI_TxFIFO_OFFSET              (2)     // ���͵����ݼĴ�������������ݼĴ�����ƫ����ͬ
#define LS1C_SPI_RxFIFO_OFFSET              (2)     // ���յ����ݼĴ������뷢�����ݼĴ�����ƫ����ͬ
#define LS1C_SPI_SPER_OFFSET                (3)     // �ⲿ�Ĵ���
#define LS1C_SPI_SFC_PARAM_OFFSET           (4)     // �������ƼĴ���
#define LS1C_SPI_SFC_SOFTCS_OFFSET          (5)     // Ƭѡ���ƼĴ���
#define LS1C_SPI_SFC_TIMING_OFFSET          (6)     // ʱ����ƼĴ���

// �Ĵ���SPCR�е�λ��
#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)

// �Ĵ���SPSR�е�λ��
#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)

// �Ĵ���SPER�е�λ��
#define LS1C_SPI_SPER_SPRE_BIT              (0)
#define LS1C_SPI_SPER_SPRE_MASK             (0x3 << LS1C_SPI_SPER_SPRE_BIT)

// �Ĵ���SFC_SOFTCS��λ��
#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)

// ���ͳ�ʱ������ֵ
#define LS1C_SPI_TX_TIMEOUT                 (20000)



/*
 * ��ȡָ��SPIģ��Ļ���ַ
 * @SPIx SPIģ��ı��
 */
inline void *ls1c_spi_get_base(unsigned char SPIx);


/*
 * ����ʱ��
 * @spi_base ����ַ
 * @max_hz ���Ƶ�ʣ���λhz
 */
void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz);


/*
 * ����ͨ��ģʽ(ʱ�Ӽ��Ժ���λ)
 * @spi_base ����ַ
 * @cpol ʱ�Ӽ���
 * @cpha ʱ����λ
 */
void ls1c_spi_set_mode(void *spi_base, unsigned char cpol, unsigned char cpha);


/*
 * ����ָ��ƬѡΪָ��״̬
 * @spi_base ����ַ
 * @cs Ƭѡ
 * @new_status Ƭѡ���ŵ���״̬��ȡֵΪ0��1�����ߵ�ƽ��͵�ƽ
 */
void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status);


/*
 * ͨ��ָ��SPI���ͽ���һ���ֽ�
 * ע�⣬�ڶ������ϵͳ�У��˺�����Ҫ���⡣
 * ����֤�ں�ij�����豸�շ�ij���ֽڵĹ����У����ܱ��л�����������ͬʱ���������ͬһ��SPI�����ϵĴ��豸ͨ��
 * ��Ϊ��о1c��ÿ·SPI�Ͽ��ܽ��в�ͬ�Ĵ��豸��ͨ��Ƶ�ʡ�ģʽ�ȿ��ܲ�ͬ
 * @spi_base ����ַ
 * @tx_ch �����͵�����
 * @ret �յ�������
 */
unsigned char ls1c_spi_txrx_byte(void *spi_base, unsigned char tx_ch);


/*
 * ��ӡָ��SPIģ������мĴ�����ֵ
 * @spi_base ����ַ
 */
void ls1c_spi_print_all_regs_info(void *spi_base);




#endif