software_APIs  1.0.0
spi_master.h
Go to the documentation of this file.
1 
4 #ifndef SPI_MASTER_C_HEADER_FILE
5 #define SPI_MASTER_C_HEADER_FILE
6 
7 #ifndef DOXYGEN_SHOULD_SKIP_THIS
8 void spi_start(){reg_spimaster_control = reg_spimaster_control | 0x1;}
9 void spi_stop(){reg_spimaster_control = reg_spimaster_control & 0x2;}
10 char spi_busy(){return reg_spimaster_status & 0x2;}
11 char spi_done(){return reg_spimaster_status & 0x1;}
12 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
13 
20 void MSPI_write(char c){
21  reg_spimaster_wdata = (unsigned long) c;
22  #ifndef ARM
23  reg_spimaster_control = 0x0801;
24  #else
25  spi_start();
26  spi_stop();
27  while(spi_busy());
28  #endif
29 }
34 char MSPI_read(){
35  MSPI_write(0x00);
36  while (reg_spimaster_status != 1);
37  return reg_spimaster_rdata;
38 }
44 void MSPI_enable(bool is_enable){
45  if(is_enable){
46  #ifndef ARM
47  reg_spi_enable = 1;
48  #else
49  reg_wb_enable = reg_wb_enable | 0x20;
50  #endif
51  }else{
52  #ifndef ARM
53  reg_spi_enable = 0;
54  #else
55  reg_wb_enable = reg_wb_enable & 0xFFDF;
56  #endif
57  }
58 }
64 void MSPI_enableCS(bool is_enable){
65  if (is_enable){
66  #ifndef ARM
67  reg_spimaster_cs = 0x10001; // select chip 0
68  #else
69  reg_spimaster_control = reg_spimaster_control | 0x2; //bit 1
70  #endif
71  }else{
72  #ifndef ARM
73  reg_spimaster_cs = 0;
74  #else
75  reg_spimaster_control = reg_spimaster_control & 0x1; //bit 1
76  spi_stop();
77  #endif
78  }
79 }
80 
81 #endif // SPI_MASTER_C_HEADER_FILE
void MSPI_enable(bool is_enable)
Definition: spi_master.h:44
void MSPI_write(char c)
Definition: spi_master.h:20
char MSPI_read()
Definition: spi_master.h:34
void MSPI_enableCS(bool is_enable)
Definition: spi_master.h:64