Skip to content

Commit fe63ec9

Browse files
committed
core:siwigsm:Update SDK header files and lib package
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent 5969856 commit fe63ec9

File tree

6 files changed

+132
-37
lines changed

6 files changed

+132
-37
lines changed

cores/siwigsm/siwisdk/include/circbuf.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,30 @@ int circbuf_pop_byte(int handle, unsigned char *data);
5454
* @param handle [in] Handle to circular buffer
5555
* @param data [out] pointer to read buffer
5656
* @param len [in] Length of data to read
57-
* @return On success, returns actual length read, -1 on error
57+
* @return On success, returns actual length read, negative value on error
5858
*/
5959
int circbuf_pop(int handle, unsigned char *data, unsigned int len);
6060

61+
/**
62+
* Peek a byte from head of circular buffer. Subsequent calls
63+
* to this function will lead to same byte unless @ref circbuf_pop or
64+
* @ref circbuf_pop_byte is called.
65+
* @param handle [in] Handle to circular buffer
66+
* @param data [out] Pointer to read buffer
67+
* @return On success, returns actual length read, negative value on error
68+
*/
69+
int circbuf_peek_byte(int handle, unsigned char *data);
70+
71+
/**
72+
* Peek data from start of circular buffer. Data will not be removed
73+
* from buffer unless @ref circbuf_pop or @ref circbuf_pop_byte is called.
74+
* @param handle [in] Handle to circular buffer
75+
* @param data [out] pointer to read buffer
76+
* @param len [in] Length of data to read
77+
* @return On success, returns actual length read, negative value on error
78+
*/
79+
int circbuf_peek(int handle, unsigned char *data, int len);
80+
6181
/**
6282
* Check if buffer is empty
6383
* @param handle [in] Handle to circular buffer

cores/siwigsm/siwisdk/include/hw/spi.h

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,106 @@
77
#define INCLUDE_HW_SPI_H_
88

99
/**
10-
* Max supported Hardware SPI speed
10+
* Max supported Hardware SPI speed (default 10MHz)
1111
*/
12-
#define SPI_MAX_SPEED 10000000U
12+
#define SPI_MAX_SPEED 32000000U
13+
14+
/**
15+
* SPI Modes to configure clock polarity and clock phase.
16+
*
17+
* For more information see https://en.wikipedia.org/wiki/Serial_Peripheral_Interface#Clock_polarity_and_phase
18+
*/
19+
enum spi_mode_e {
20+
SPI_MODE0,/**< Mode 0 (default): CPOL = 0, CPHA = 0 */
21+
SPI_MODE1,/**< Mode 1: CPOL = 0, CPHA = 1 */
22+
SPI_MODE2,/**< Mode 2: CPOL = 1, CPHA = 0 */
23+
SPI_MODE3,/**< Mode 3: CPOL = 1, CPHA = 1 */
24+
};
25+
26+
/**
27+
* SPI byte order to configure shit in/out order of data byte.
28+
*/
29+
enum spi_byteorder_e {
30+
SPI_BYTE_MSB_FIRST,/**< MSB sent first (default) */
31+
SPI_BYTE_LSB_FIRST,/**< LSB sent first */
32+
};
33+
34+
/**
35+
* Chip select mode configures how chip select line is de-asserted during a
36+
* transaction. It only used when hardware chip select is used during
37+
* initialization. See @ref spi_hw_init
38+
*/
39+
enum spi_csmode_e {
40+
SPI_CSMODE_TRANSACTION,/**< CS line de-asserted between each transaction.
41+
This is default behavior of CS line. */
42+
SPI_CSMODE_BYTE, /**< CS line de-asserted after each byte in a
43+
transaction */
44+
};
45+
46+
/**
47+
* Chip select polarity flags
48+
*/
49+
enum spi_cspol_e {
50+
SPI_CSPOL_LOW, /**< Chip select is active low (default) */
51+
SPI_CSPOL_HIGH,/**< Chip select is active high */
52+
};
1353

1454
#ifdef __cplusplus
1555
extern "C" {
1656
#endif
1757

1858
/**
1959
* Initialize SPI Hardware and setup pinmux
20-
* @param managed_cs [in] Set it TRUE, if application software manages chip select status, FALSE otherwise
21-
* @param clock_hz [in] SPI Clock speed
22-
* @param mode [in] SPI Mode (0-3)
23-
* @return 0 on success, negative on error
60+
* @param int hardware_cs [in] Set it TRUE, if application hardware chip
61+
* select is used and hardware controls chip
62+
* select status, FALSE otherwise
63+
* @return 0 on success, negative on error
2464
*/
25-
int spi_hw_init(int managed_cs, unsigned int clock_hz, int mode);
65+
int spi_hw_init(int hardware_cs);
2666

2767
/**
28-
* SPI Master harware read
29-
* @param buf [out] Pointer to buffer where received data is stored
30-
* @param len [in] Data to read
31-
* @return Length of data read on success, negative on error
68+
* Set/Change SPI clock speed. Default speed is @ref SPI_MAX_SPEED
69+
* @param clock_hz [in] Clock speed in Hz
70+
* @return 0 on success, negative value on error
3271
*/
33-
int spi_hw_read(unsigned char *buf, int len);
72+
int spi_hw_setclock(unsigned long clock_hz);
3473

3574
/**
36-
* SPI Master write
37-
* @param buf [in] Pointer to data buffer to write
38-
* @param len [in] Length of data in buffer
39-
* @return Length of data written on success, negative on error
75+
* Configure SPI clock mode
76+
* @param mode [in] SPI mode, see @ref spi_mode_e
77+
* @return 0 on success, negative value on error
4078
*/
41-
int spi_hw_write(const unsigned char *buf, int len);
79+
int spi_hw_setmode(int mode);
4280

4381
/**
44-
* SPI Master write then read
45-
* @param wrbuf [in] Pointer to data buffer to write
46-
* @param wrlen [in] Length of data to write
47-
* @param rdbuf [out] Pointer to buffer to store data
48-
* @param rdlen [in] Length of data to read
49-
* @return Length of data read on success, negative on error
82+
* Configure SPI byte shift order
83+
* @param byte_order [in] SPI byte order, see @ref spi_byteorder_e
84+
* @return 0 on success, negative value on error
5085
*/
51-
int spi_hw_writeread(const unsigned char *wrbuf, int wrlen, unsigned char *rdbuf, int rdlen);
86+
int spi_hw_setbyteorder(int byte_order);
5287

5388
/**
54-
* Set/Change SPI clock speed
55-
* @param clock_hz [in] Clock speed in Hz
89+
* Configure chip-select line. Only needed when hardware_cs is used
90+
* @param cs_mode [in] Chip select mode, see @ref spi_csmode_e
91+
* @param cs_pol [in] Chip select polarity, see @ref spi_cspol_e
92+
* @return 0 on success, negative value on error
5693
*/
57-
void spi_hw_setclock(unsigned int clock_hz);
94+
int spi_hw_setcsmode(int cs_mode, int cs_pol);
5895

5996
/**
60-
* Get currently set SPI clock speed
61-
* @return Clock speed in Hz
97+
* Perform SPI transaction
98+
* @param wrbuf [in] Pointer to data buffer to write, can be NULL
99+
* if only read operation to be performed
100+
* @param rdbuf [out] Pointer to buffer to store data, can be NULL
101+
* if only write operation to be performed
102+
* @param length [in] Length of data to read/write
103+
* @return Length of data read/write on success, negative on error
62104
*/
63-
unsigned int spi_hw_getclock(void);
105+
int spi_hw_transfer(const unsigned char *wrbuf, unsigned char *rdbuf, int length);
64106

65107
/**
66108
* Release SPI hardware
67-
* @return 0 on success, negative on error
109+
* @return 0 on success, negative on error
68110
*/
69111
int spi_hw_free(void);
70112

cores/siwigsm/siwisdk/include/spifs.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef INC_SPIFS_H_
77
#define INC_SPIFS_H_
88

9+
#include <hw/spi.h>
10+
911
/**
1012
* SPI Flash status
1113
*/
@@ -15,14 +17,19 @@ enum sfstat_e {
1517
SF_STAT_MOUNTED, /**< SPI Flash enabled and filesystem is mounted successfully */
1618
};
1719

20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
1824
/**
1925
* Enable SPI Flash and mount LFS filesystem
20-
* @param gpio_cs [in] GPIO number connected to SPI chip select
21-
* @param speed [in] SPI Speed in KHz (max 10000 KHz)
22-
* @param mode [in] SPI mode
23-
* @return 0 on success, negative value on failure
26+
* @param gpio_cs [in] GPIO number connected to SPI chip select
27+
* @param speed_hz [in] SPI Speed in Hz (max 10MHz)
28+
* @param mode [in] SPI mode
29+
* @param byte_order [in] SPI byte order, see
30+
* @return 0 on success, negative value on failure
2431
*/
25-
int spifs_enable(int gpio_cs, unsigned int speed, int mode);
32+
int spifs_enable(int gpio_cs, unsigned long speed_hz, int mode, int byte_order);
2633

2734
/**
2835
* Disable SPI Flash and unmount LFS filesystem
@@ -36,4 +43,8 @@ int spifs_disable(void);
3643
*/
3744
int spifs_getstatus(void);
3845

46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
3950
#endif /* INC_SPIFS_H_ */

cores/siwigsm/siwisdk/include/sys/ioctl.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@
3434
*/
3535
#define FIOASYNC 0x5452
3636

37+
/**
38+
* Get Next character in read buffer
39+
* without removing it. Multiple call to
40+
* ioctl will result in same character unless
41+
* read() is called
42+
* expects int *
43+
*/
44+
#define TIOCPEEK 0x545C
45+
/**
46+
* Get data from read buffer without removing it.
47+
* expects struct @ref iopeek_t *
48+
*/
49+
#define TIOCPEEKBUF 0x545D
50+
51+
/**
52+
* Peek structure
53+
*/
54+
struct iopeek_t {
55+
void *buf; /** Buffer pointer to store read data */
56+
int len; /** Length of buffer, on return this is updated with actual bytes read */
57+
};
58+
3759
#ifdef __cplusplus
3860
extern "C" {
3961
#endif
-8.22 KB
Binary file not shown.
-8.22 KB
Binary file not shown.

0 commit comments

Comments
 (0)