An implantable neurostimulator comprising: a battery configured to provide power to the implantable neurostimulator; a battery switch configured to open and remove power from one or more components of the implantable neurostimulator, or close to provide power to each component of the implantable neurostimulator requiring power to operate; and processing circuitry configured to: execute a plurality of firmware modules that are configured to perform respective functions of the implantable neurostimulator, at least two of the plurality of firmware modules being configured to determine whether power is needed for a corresponding hardware component or to perform the respective function during a respective time period and to generate and transmit one or more respective requests based on the determination of whether power is needed for the corresponding hardware component or to perform the respective function during the respective time period; and execute power domain firmware that configures the processing circuitry to: receive the one or more respective requests; determine whether to open the battery switch or to keep the battery switch closed in response to the one or more respective requests; and control the battery switch to open or keep closed in response to the determination. a battery configured to provide power to the implantable neurostimulator; a battery switch configured to open and remove power from one or more components of the implantable neurostimulator, or close to provide power to each component of the implantable neurostimulator requiring power to operate; and processing circuitry configured to: execute a plurality of firmware modules that are configured to perform respective functions of the implantable neurostimulator, at least two of the plurality of firmware modules being configured to determine whether power is needed for a corresponding hardware component or to perform the respective function during a respective time period and to generate and transmit one or more respective requests based on the determination of whether power is needed for the corresponding hardware component or to perform the respective function during the respective time period; and execute power domain firmware that configures the processing circuitry to: receive the one or more respective requests; determine whether to open the battery switch or to keep the battery switch closed in response to the one or more respective requests; and control the battery switch to open or keep closed in response to the determination. execute a plurality of firmware modules that are configured to perform respective functions of the implantable neurostimulator, at least two of the plurality of firmware modules being configured to determine whether power is needed for a corresponding hardware component or to perform the respective function during a respective time period and to generate and transmit one or more respective requests based on the determination of whether power is needed for the corresponding hardware component or to perform the respective function during the respective time period; and execute power domain firmware that configures the processing circuitry to: receive the one or more respective requests; determine whether to open the battery switch or to keep the battery switch closed in response to the one or more respective requests; and control the battery switch to open or keep closed in response to the determination. receive the one or more respective requests; determine whether to open the battery switch or to keep the battery switch closed in response to the one or more respective requests; and control the battery switch to open or keep closed in response to the determination.