Statistics
| Branch: | Tag: | Revision:

mongoose / examples / PIC32 / mqtt_client / firmware / src / cc3100_port.c @ eaef5bd1

History | View | Annotate | Download (1.32 KB)

1
/*
2
 * Copyright (c) 2016 Cesanta Software Limited
3
 * All rights reserved
4
 */
5

    
6
#include "app.h"
7
#include "system/debug/sys_debug.h"
8
#include "simplelink.h"
9
#include "user_params.h"
10

    
11
P_EVENT_HANDLER g_cc3100_IRQ_handler = NULL;
12

    
13
void AssertCS() {
14
  PLIB_PORTS_PinClear(PORTS_ID_0, CS_PORT, CS_PIN);
15
}
16

    
17
void DeassertCS() {
18
  PLIB_PORTS_PinSet(PORTS_ID_0, CS_PORT, CS_PIN);
19
}
20

    
21
void CC3100_enable() {
22
  PLIB_PORTS_PinSet(PORTS_ID_0, HIB_PORT, HIB_PIN);
23
}
24

    
25
void CC3100_disable() {
26
  PLIB_PORTS_PinClear(PORTS_ID_0, HIB_PORT, HIB_PIN);
27
}
28

    
29
Fd_t spi_Open(char *ifName, unsigned long flags) {
30
  CC3100_disable();
31

    
32
  return 0;
33
}
34

    
35
int spi_Write(Fd_t fd, unsigned char *pBuff, int len) {
36
  if (len > 512) {
37
    SYS_PRINT("BUFFER TOO SMALL");
38
    return 0;
39
  }
40

    
41
  AssertCS();
42
  uint8_t dummy[512];
43
  DRV_SPI0_BufferAddWriteRead(pBuff, dummy, len);
44
  DRV_SPI_Tasks(sysObj.spiObjectIdx0);
45
  DeassertCS();
46

    
47
  return len;
48
}
49

    
50
int spi_Read(Fd_t fd, unsigned char *pBuff, int len) {
51
  if (len > 512) {
52
    SYS_PRINT("BUFFER TOO SMALL");
53
    return 0;
54
  }
55
  uint8_t dummy[512];
56
  memset(dummy, 0xFF, len);
57
  AssertCS();
58
  DRV_SPI0_BufferAddWriteRead(dummy, pBuff, len);
59
  DRV_SPI_Tasks(sysObj.spiObjectIdx0);
60
  DeassertCS();
61
  return len;
62
}
63

    
64
int registerInterruptHandler(P_EVENT_HANDLER int_handler, void *pValue) {
65
  (void) pValue;
66
  g_cc3100_IRQ_handler = int_handler;
67
}