RIOTOUS handles 95% of the work needed to get an IoT product working with the ESP8266 module. But since every device is unique, a few RIOTOUS functions have to be defined by the user. The following functions need to be defined by the user which are found in RIOTOUS_IO.c unless you download a specific flavour of RIOTOUS that matches your device (such as RIOTOUS PIC16F1516) in which case, RIOTOUS_IO.c has already been defined and you can dive straight into programming an IoT device!
- void interrupt isr(void)
- void riotous_configUART(void)
- void riotous_sendByteUART(unsigned char data)
- void riotous_turnInterruptsOff(void)
- void riotous_turnInterruptsOn(void)
- void riotous_delay(void)
void interrupt isr(void)
RIOTOUS is as interrupt driven as it can possibly be to ensure that there are no infinite loops and/or stalls. When a byte is received over UART, the interrupt service routine must send RIOTOUS framework the received byte by passing the byte to the function riotous_receiveByte(unsigned char byte). For example, the PIC16 would use riotous_receiveByte(RCREG). The interrupt service routine must also handle overflows and framing errors should they occur (PIC devices have a horrible habit of locking up the UART when one of these errors occur).
This function configures the UART module to do the following:
- Clear the UART buffers
- Configure the baud rate to 9600
- Use 8 bits
- Use 1 stop bit
- Use no parity bits
- Use asynchronous transmission
- Configure the I/O pins for UART transmission / reception
- Fire an interrupt upon receiving a UART byte
This delay is imperative for proper ESP8266 communication and should delay for 100ms. This must not disable interrupts and must never be allowed to stall (i.e. use a simple while loop with a decrementing counter if possible).
void riotous_sendByteUART(unsigned char data)
This function needs to send a byte to the UART module for transmission, start the transmission, and wait until the byte has been sent.
This function needs to disable any interrupts from firing (i.e. disable global interrupts). This is crucial for RIOTOUS to function properly as C does not do well with atomic instructions. Turning interrupts off for short periods of time guarantees the framework that data buffers and variables are not being altered by external code.
This function needs to enabled interrupts globally. When RIOTOUS access vital variables, interrupts are disabled and once these sensitive operations have been completed, interrupts are re-enabled with this function.